How can i make a new leaf

Hi experts.
I got a problem when i make a new tree from existed ntp.
I take two leaf qc5 and fmax from 3 each Am_test.ntp, Ba_test.ntp, Cd_test.ntp.
And I also make a branch for qc5 , fmax.

So here is the problem. I want to make a new branch for energy.
The energy is just qc5*calibration factor.
But it doesn’t show the correct histogram.

How can i solve this?

void makeTree()
  TChain * chain1 = new TChain("ntp");
  TChain * chain2 = new TChain("ntp");
  TChain * chain3 = new TChain("ntp");

  float qc5, fmax;
  float  energy =  qc5 * 4.2807603e-3;
  chain1->GetLeaf("pmt11", "qc5")->SetAddress(&qc5);
  chain2->GetLeaf("pmt11", "qc5")->SetAddress(&qc5);
  chain3->GetLeaf("pmt11", "qc5")->SetAddress(&qc5);
  chain1->GetLeaf("pmt11", "fmax")->SetAddress(&fmax);
  chain2->GetLeaf("pmt11", "fmax")->SetAddress(&fmax);
  chain3->GetLeaf("pmt11", "fmax")->SetAddress(&fmax);
  chain1->GetLeaf("pmt11", "energy")->SetAddress(&energy);
  chain2->GetLeaf("pmt11", "energy")->SetAddress(&energy);
  chain3->GetLeaf("pmt11", "energy")->SetAddress(&energy);

  TFile fout("data/tree.root", "recreate");

  TTree * tree1 = new TTree("t1", "t1");
  TTree * tree2 = new TTree("t2", "t2");
  TTree * tree3 = new TTree("t3", "t3");
  tree1->Branch("qc5"   ,   &qc5 );
  tree1->Branch("fmax"  ,   &fmax);
  tree1->Branch("energy", &energy);
  tree2->Branch("qc5"   ,   &qc5 );
  tree2->Branch("fmax"  ,   &fmax);
  tree2->Branch("energy", &energy);
  tree3->Branch("qc5"   ,   &qc5 );
  tree3->Branch("fmax"  ,   &fmax);
  tree3->Branch("energy", &energy);

  int nent1 = chain1->GetEntries();
  for(int i = 0; i < nent1; i++){


  int nent2 = chain2->GetEntries();
  for(int i = 0; i < nent2; i++){



This is what i use the code.

  int nent3 = chain3->GetEntries();
  for(int i = 0; i < nent3; i++){

Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided

after each “chain->GetEntry(i);”, you need “energy = qc5 * 4.2807603e-3;” and then “tree->Fill();

Thanks for reply!
When i use GetLeaf for energy, should i write the qc5 instead of energy?

From your description, the “energy” should be a completely new branch in the “tree”, so it should not exist in the “chain” (but “qc5” should be there, of course).

Than It doesn’t need right?

Thanks! I solve the problem. It was really helful!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.