#define TupleTransformer_cxx #include "TupleTransformer.h" #include #include #include #include void TupleTransformer::Loop() { // In a ROOT session, you can do: // Root > .L TupleTransformer.C // Root > TupleTransformer t // Root > t.GetEntry(12); // Fill t data members with entry number 12 // Root > t.Show(); // Show values of entry 12 // Root > t.Show(16); // Read and show values of entry 16 // Root > t.Loop(); // Loop on all entries // // This is the loop skeleton where: // jentry is the global entry number in the chain // ientry is the entry number in the current Tree // Note that the argument to GetEntry must be: // jentry for TChain::GetEntry // ientry for TTree::GetEntry and TBranch::GetEntry // // To read only selected branches, Insert statements like: // METHOD1: // fChain->SetBranchStatus("*",0); // disable all branches // fChain->SetBranchStatus("branchname",1); // activate branchname // METHOD2: replace line // fChain->GetEntry(jentry); //read all branches //by b_branchname->GetEntry(ientry); //read only this branch if (fChain == 0) return; TFile *oldfile = new TFile("CTRL.root"); TTree *oldtree = (TTree*)oldfile->Get("ak5/ProcessedTree"); TFile *newfile = new TFile("ResultTuple.root","recreate"); newfile->mkdir("ak5"); newfile->cd("ak5"); // TTree *newtree = fChain->GetTree()->CloneTree(0); // This gives seg fault oldtree->SetBranchStatus("*",1); TTree *newtree = oldtree->CloneTree(0); Int_t my_EvtHdr__mRun=0; TBranch *my_b_events_EvtHdr__mRun; newtree->SetBranchAddress("EvtHdr_.mRun",&my_EvtHdr__mRun,&my_b_events_EvtHdr__mRun); newtree->SetBranchStatus("*",1); float myVariable = 0; newtree->Branch("MyBranch",&myVariable,"value/F"); Long64_t nentries = fChain->GetEntriesFast(); Long64_t nbytes = 0, nb = 0; nentries = 100; for (Long64_t jentry=0; jentryGetEntry(jentry); nbytes += nb; // if (Cut(ientry) < 0) continue; // This works alright: myVariable = jentry; //But this not: my_EvtHdr__mRun = jentry; newtree->Fill(); } newtree->Write(); newtree->AutoSave("Overwrite"); newfile->Close(); }