TTree copy

Hello,

I would like to copy a TTree into another TTree, only selecting some events and changing column wise branches to row wise branches (I would like one entry per candidate instead of one entry per event).
Here is an example of the code I’m using:

  Float_t         B_m[100];   //[N_candidate]
  MCTruth->SetBranchAddress("B_m", B_m);
  gpeak->Branch("B_m", B_m, "B_m/F");
  Double_t  nsig =  MCTruth->GetEntries();
  for(Int_t j=0; j<nsig; j++) {
       MCTruth->GetEvent(j);    
       for(Int_t i=0; i<N_candidate; ++i)
       {
          if(Mum_muonID[i]>100 && Mup_muonID[i]>100)    {         //some cuts
             gpeak->Fill();
          }
       }
  }

The problem is that the tree “gpeak” is always filled with the first candidate of the event.
Do you have any solution to this ?

Thanks,
Justine

Maybe: Int_t counter = 0; for(Int_t i=0; i<N_candidate; ++i) { if(Mum_muonID[i]>100 && Mup_muonID[i]>100) { //some cuts B_m[0] = B_m[counter]; gpeak->Fill(); ++counter; } }
Philippe.

Hi Philippe,

Your proposal works, but the problem is that I have ~100 variables to fill :frowning:

Justine