#include #include #include #include #include #include void make_subsample3(void) { TChain *fChain = new TChain("tsm"); //fChain->Add("/work/eowyn-clued0/noeding/ROOT/zee60_130/data/diem/0/D0ChunkAnalyze.root"); fChain->Add("/work/eowyn-clued0/noeding/ROOT/zee60_130/data/diem/1/D0ChunkAnalyze.root"); //fChain->Add("/work/eowyn-clued0/noeding/ROOT/zee60_130/data/diem/2/D0ChunkAnalyze.root"); //fChain->Add("/work/eowyn-clued0/noeding/ROOT/zee60_130/data/diem/3/D0ChunkAnalyze.root"); //fChain->Add("/work/eowyn-clued0/noeding/ROOT/zee60_130/data/diem/4/D0ChunkAnalyze.root"); TFile *newfile = new TFile("zee60_130_subsample.root","recreate"); TTree* newtree = get_new_tree(fChain); //(TTree*)fChain->CopyTree("LETM_Nelectron>1"); newfile->Write(); newfile->Close(); } TTree* get_new_tree(TChain *ch) { TTree *tree = ch->CloneTree(0); TTree *fTree = ch; if (tree == 0) return 0; Int_t firstentry=0; //Int_t nentries= (Int_t) ch->GetTree()->GetEntriesFast();//fTree->GetEntries(); Int_t nentries= (Int_t) fTree->GetEntries(); cout << nentries << endl; Int_t entry,entryNumber; // Compile selection expression if there is one TTreeFormula *select = 0; // no need to interfer with fSelect since we // handle the loop explicitly below and can call // UpdateFormulaLeaves ourselves. select = new TTreeFormula("Selection","LETM_Nelectron",fTree); select2 = new TTreeFormula("Selection","LETM_pT[0]",fTree); select3 = new TTreeFormula("Selection3","LETM_pT[1]",fTree); //if (select) { // Int_t ndata = select->GetNdata(); // if (ndata) LETM_Nelectron = select->EvalInstance(); // else continue; // cout << "em: " << LETM_Nelectron << endl; //} //TTreeFormula *select2 = new TTreeFormula("Selection2","LETM_pT[0]>12.",fTree); //fFormulaList->Add(select); //if (strlen(selection)) { // select = new TTreeFormula("Selection",selection,fTree); // if (!select || !select->GetNdim()) { delete select; } // fFormulaList->Add(select); //} //loop on the specified entries Int_t tnumber = -1; cout << "hallo" << endl; cout << firstentry << endl; cout << nentries << endl; for (entry=firstentry;entryGetEntryNumber(entry); if (entryNumber < 0) break; //cout << "a"<LoadTree(entryNumber); if (localEntry < 0) break; //cout <<"b"<GetTreeNumber()) { tnumber = fTree->GetTreeNumber(); if (select) select->UpdateFormulaLeaves(); } //cout << "before select"<GetNdata(); cout << "ndata: " << ndata << endl; if (ndata) LETM_Nelectron = select->EvalInstance(); else continue; cout << "nr: " << LETM_Nelectron << endl; if (LETM_Nelectron>=2) { if(select2) { Int_t ndata = select2->GetNdata(); if (ndata) LETM_pT[0] = select2->EvalInstance(); else continue; } cout << "em1: " << LETM_pT[0] << endl; if(select3) { Int_t ndata = select3->GetNdata(); if (ndata) LETM_pT[1] = select3->EvalInstance(); else continue; } cout << "em2: " << LETM_pT[1] << endl; if (LETM_pT[0]>12. && LETM_pT[1]>12.) keep=kTRUE; } } if (!keep) continue; fTree->GetEntry(entryNumber); tree->Fill(); } cout << "for loop done" << endl; //fFormulaList->Clear(); return tree; }