#define skim_athena_cxx #include "skim_athena.h" #include "myvar.hpp" #include #include using namespace std; skim_athena::skim_athena(TChain *t) { fChain = t; fCurrent = -1; newchain = 0; newtree = 0; } skim_athena::~skim_athena() { //delete newtree; } void skim_athena::Notify() { ::SetLeaves(fChain); if (newchain==0) { newchain = (TChain *)(fChain)->CloneTree(0); newtree = newchain->GetTree(); } ::SetCloneLeaves(newchain); } int skim_athena::LoadTree(int entry) { // Set the environment to read one entry if (!fChain) return -5; Int_t centry = fChain->LoadTree(entry); if (centry < 0) return centry; if (fChain->IsA() != TChain::Class()) return centry; TChain *chain = (TChain*)fChain; if (chain->GetTreeNumber() != fCurrent) { fCurrent = chain->GetTreeNumber(); this->Notify(); } return centry; } void skim_athena::analyze(char *newfilename) { // flag whether running on data or mc bool data = true; // bool data = false; if ( data ) { fChain->SetBranchStatus("*",0); fChain->SetBranchStatus("Track",1); fChain->SetBranchStatus("MET",1); fChain->SetBranchStatus("EM",1); fChain->SetBranchStatus("Diem",1); fChain->SetBranchStatus("MU",1); fChain->SetBranchStatus("Dimu",1); fChain->SetBranchStatus("Jet1",1); fChain->SetBranchStatus("Jet2",1); fChain->SetBranchStatus("Jet3",1); fChain->SetBranchStatus("Vtx",1); fChain->SetBranchStatus("Svtx",1); fChain->SetBranchStatus("Run",1); fChain->SetBranchStatus("MCinfo",1); fChain->SetBranchStatus("MCparticle",1); fChain->SetBranchStatus("MCvtx",1); fChain->SetBranchStatus("Trigger",1); fChain->SetBranchStatus("Trigger.fUniqueID",1); fChain->SetBranchStatus("Trigger.fBits",1); fChain->SetBranchStatus("Trigger.fString",1); fChain->SetBranchStatus("L1names",1); fChain->SetBranchStatus("L1names.fUniqueID",1); fChain->SetBranchStatus("L1names.fBits",1); fChain->SetBranchStatus("L1names.fString",1); fChain->SetBranchStatus("L2names",1); fChain->SetBranchStatus("L2names.fUniqueID",1); fChain->SetBranchStatus("L2names.fBits",1); fChain->SetBranchStatus("L2names.fString",1); fChain->SetBranchStatus("L1",1); fChain->SetBranchStatus("L2",1); fChain->SetBranchStatus("L3",1); fChain->SetBranchStatus("L3eletoolnames",1); fChain->SetBranchStatus("L3eletoolnames.fUniqueID",1); fChain->SetBranchStatus("L3eletoolnames.fBits",1); fChain->SetBranchStatus("L3eletoolnames.fString",1); fChain->SetBranchStatus("L3jettoolnames",1); fChain->SetBranchStatus("L3jettoolnames.fUniqueID",1); fChain->SetBranchStatus("L3jettoolnames.fBits",1); fChain->SetBranchStatus("L3jettoolnames.fString",1); } int nentries = fChain->GetEntries(); cout << "Total number of events in this dataset = " << nentries << endl; // int nentries = 100; int nselected = 0; // int badrun_count = 0; // int highlum_count = 0; // Create a new file + a clone of old tree in new file newfile = new TFile(newfilename, "recreate"); // Keep track of processing time time_t StartTime = time((time_t*)NULL); for (int i=0; iClear(); l1names->Clear(); l2names->Clear(); l3eletoolnames->Clear(); l3jettoolnames->Clear(); fChain->GetEntry(i); if (i<1) cout << "Start time = " << ctime(&StartTime) << endl; if ( i%10000==0 && i>0 ) cout << i << " events processed and "<< nselected <<" events selected at " << ctime(&daTod) << endl; // some internal counters int num_tight_elec = 0; int num_tight_elec_track_match = 0; if ( data ) { for (int iem = 0; iem < ems.nem; iem++) { // if ( ems.emf[iem]>0.9 // && ems.iso[iem]<0.15 // && fabs(ems.deteta[iem])<=3.2 // && (ems.chi7[iem]<50.0 || ems.chi8[iem]<50.0) // && ems.pt[iem]>10 // && ems.trkflag[iem]) // num_tight_elec++; if ( ems.emf[iem]>0.9 && ems.iso[iem]<0.15 && ( (ems.chi7[iem]<12.0 && fabs(ems.deteta[iem])<=1.1) || (ems.chi7[iem]<18.0 && fabs(ems.deteta[iem])>=1.5 && fabs(ems.deteta[iem])<=2.5) ) && ems.pt[iem]>20 ) num_tight_elec++; if ( ems.emf[iem]>0.9 && ems.iso[iem]<0.15 && ( (ems.chi7[iem]<12.0 && fabs(ems.deteta[iem])<=1.1) || (ems.chi7[iem]<18.0 && fabs(ems.deteta[iem])>=1.5 && fabs(ems.deteta[iem])<=2.5) ) && ems.pt[iem]>20 && ems.trkflag[iem]) num_tight_elec_track_match++; } // Tight Electron with Track Match // if ( num_tight_elec>0) { if ( num_tight_elec>1 && num_tight_elec_track_match>0) { newchain->Fill(); nselected++; } } } time_t StopTime = time((time_t*)NULL); cout << " Start time = " << ctime(&StartTime) << endl; cout << " Stop time = " << ctime(&StopTime) << endl; cout << nselected << " events selected out of " << nentries << endl; newfile->cd(); newchain->Write(); newfile->Close(); } //-----------------------------------------------------------------------------------------