ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitHzz4l/Selection/src/applySelection.cc
(Generate patch)

Comparing UserCode/MitHzz4l/Selection/src/applySelection.cc (file contents):
Revision 1.49 by khahn, Fri Jun 22 03:10:32 2012 UTC vs.
Revision 1.56 by anlevin, Fri Oct 12 12:26:12 2012 UTC

# Line 53 | Line 53 | using namespace std;
53   #include "ParseArgs.h"
54   #include "MuonSelection.h"
55   #include "ElectronSelection.h"
56 + #include "ElectronMomentumCorrection.h"
57   #include "IsolationSelection.h"
58   #include "ReferenceSelection.h"
59  
# Line 91 | Line 92 | vector<vector<unsigned> > zcutvec;
92   vector<vector<unsigned> > zzcutvec;
93   map<unsigned,float>       evtrhoMap;
94   vector<string> cutstrs;
95 < bool passes_HLT_MC;
95 > bool passes_HLT_MC,passes_HLT;
96   vector<bool>   PFnoPUflag;;
97  
98   //
# Line 100 | Line 101 | vector<bool>   PFnoPUflag;;
101   void initRunLumiRangeMap(ControlFlags &ctrl);
102   //----------------------------------------------------------------------------
103  
103
104   //
105   // MAIN
106   //----------------------------------------------------------------------------
# Line 166 | Line 166 | int main(int argc, char** argv)
166    //--------------------------------------------------------------------------------------------------------------
167    TChain * chain = new TChain("Events");
168    TChain * hltchain = new TChain("HLT");
169 +  TChain * runchain = new TChain(Names::gkRunTreeName);
170  
171    string fname;
172    unsigned total_unskimmed=0;
# Line 179 | Line 180 | int main(int argc, char** argv)
180        total_unskimmed += entrymap[string(fname.c_str())];
181        chain->AddFile(fname.c_str());
182        hltchain->AddFile(fname.c_str());
183 +      runchain->AddFile(fname.c_str());
184      }
185    } else {
186      cout << "adding inputfile : " << ctrl.inputfile.c_str() << endl;
# Line 188 | Line 190 | int main(int argc, char** argv)
190      total_unskimmed += unsk_ents;
191      chain->AddFile(ctrl.inputfile.c_str());
192      hltchain->AddFile(ctrl.inputfile.c_str());
193 +    runchain->AddFile(ctrl.inputfile.c_str());
194    }
195    // // write the total number of unskimmed events that went into making this output file to a text file
196 <  // writeEntries(ctrl,total_unskimmed);
196 >  writeEntries(ctrl,total_unskimmed);
197  
198    const char * ofname;
199    if( strcmp( ctrl.outputfile.c_str(), "") ) {
# Line 221 | Line 224 | int main(int argc, char** argv)
224  
225    
226    FOTuple foTree( nt.getFile(), (const char*)"FOtree");
227 +  foTree.makeInfoBranch(evtinfo);
228    foTree.makeFailedLeptonBranch(failingLeptons);
229    foTree.makePassedLeptonBranch(passingLeptons);
230  
# Line 228 | Line 232 | int main(int argc, char** argv)
232    if(ctrl.mc) {
233      nt.makeWeightBranch(weights);
234      if(ctrl.fillGen ) nt.makeGenInfoBranch(geninfo);
235 <    initEfficiencyWeights();
235 >    //initEfficiencyWeights();
236      initPUWeights();
237  
238      // Higgs only, pt reweighting
# Line 242 | Line 246 | int main(int argc, char** argv)
246      }
247  
248    } else {
249 <    initRunLumiRangeMap();
249 >    initRunLumiRangeMap(ctrl);
250    }
251  
252    //  initMuonIDMVA();
253    initElectronIDMVAV1();
254    initTrigger();
255 +  ElectronMomentumCorrection electron_mom_corr;
256 +  electron_mom_corr.initialize_regression("../EGamma/EGammaAnalysisTools/data/eleEnergyRegWeights_V1.root");
257 +  TrigInfo ti;
258 +  initAnalysisTriggers(ti);
259  
260    //
261    // Setup tree I/O
# Line 257 | Line 265 | int main(int argc, char** argv)
265    string currentFile("");
266  
267    UInt_t fNMaxTriggers = 1024;
268 <  mithep::EventHeader *info    = new mithep::EventHeader();
268 >  mithep::EventHeader                         *info          = new mithep::EventHeader();
269    mithep::Array<mithep::PFMet>                *metArr        = new mithep::Array<mithep::PFMet>();
270    mithep::Array<mithep::Electron>             *electronArr   = new mithep::Array<mithep::Electron>();
271    mithep::Array<mithep::Muon>                 *muonArr       = new mithep::Array<mithep::Muon>();
# Line 278 | Line 286 | int main(int argc, char** argv)
286    std::vector<std::string>                    *hltLab        = new vector<string>();
287    TriggerObjectsTable                         *fTrigObjs     = new TriggerObjectsTable(hltTable,fNMaxTriggers);
288  
289 +  RunInfo                                     *runInfo       = new RunInfo();
290  
291    TString fElectronName(Names::gkElectronBrn);
292    TString fMuonName(Names::gkMuonBrn);
# Line 327 | Line 336 | int main(int argc, char** argv)
336    hltchain->SetBranchAddress(fTriggerTableName, &hltTableStrings);
337    hltchain->SetBranchAddress(fTriggerLabelName, &hltLabelStrings);
338  
339 +  runchain->SetBranchAddress(Names::gkRunInfoBrn, &runInfo);
340 +
341    mithep::Vertex              vtx;          // best primary vertex in the event
342  
343    //  ginfo = NULL;
# Line 341 | Line 352 | int main(int argc, char** argv)
352    // only 1 HLT table / file ???
353    hltchain->GetEntry(0);
354  
355 <  int imax = chain->GetEntries();
356 <  cout << "nEntries: " << imax << endl;
355 >  int imax;
356 >  //-1 means process all of the events
357 >  if(ctrl.n_events_to_process != -2 && ctrl.n_events_to_process != -1){
358 >    if(ctrl.n_events_to_process > chain->GetEntries()){
359 >      cerr << "error: n_events_to_process is larger than chain->GetEntries()" << endl;
360 >      return 1;
361 >    }
362 >    imax = ctrl.n_events_to_process;
363 >  }
364 >  else
365 >    imax = chain->GetEntries();
366 >
367 >  cout << "number of events to process: " << imax << endl;
368  
369    //
370    // Loop !!!!!!!!!
371    //--------------------------------------------------------------------------------------------------------------
372 +  int lastHltEntry=-2;
373    for(UInt_t ientry=0; ientry<imax; ientry++)
374      {
375        chain->GetEntry(ientry);
# Line 359 | Line 382 | int main(int argc, char** argv)
382               << "\tEvt: " << info->EvtNum()
383               << "\tLumi: " << info->LumiSec()
384               << endl;
385 +        cerr << "Run: " << info->RunNum()
386 +             << "\tEvt: " << info->EvtNum()
387 +             << "\tLumi: " << info->LumiSec()
388 +             << endl;
389          cout << "-----------------------------------------------------------------" << endl;
390        }
391  
392 <
392 >      runchain->GetEvent(info->RunEntry());
393 >      hltchain->GetEntry(runInfo->HltEntry());
394 >      hltTable->Clear();
395 >      fillTriggerNames(hltTable, hltTableStrings );
396 >      if(ctrl.debug && (lastHltEntry != runInfo->HltEntry())) hltTable->Print();
397 >      lastHltEntry = runInfo->HltEntry();
398 >      fillTriggerBits( hltTable, trigMask, triggerBits );
399 >      setHLTObjectRelations( hltObjArr, hltRelsArr, hltTableStrings, hltLabelStrings, fTrigObjs );
400 >      // printTriggerObjs( hltTable, fTrigObjs);
401 >      
402        string fname = string(chain->GetFile()->GetEndpointUrl()->GetFile());
403        if(ctrl.debug) cout << "era is " << ctrl.era << endl;
404        if( ctrl.era == 0  ) {
# Line 379 | Line 415 | int main(int argc, char** argv)
415        assert(pfnopu_size == pfArr->GetEntries());
416  
417        //
418 +      // trigger
419 +      //
420 +      if( string(chain->GetFile()->GetEndpointUrl()->GetFile()) != currentFile ) {
421 +        currentFile = string(chain->GetFile()->GetEndpointUrl()->GetFile());
422 +      }
423 +      if( ctrl.debug ) cout << "file is : " << currentFile  << endl;
424 +
425 +      //
426        // data/MC
427        //
428        if(ctrl.mc) {
# Line 410 | Line 454 | int main(int argc, char** argv)
454            }
455          }
456  
457 <        //
414 <        // trigger
415 <        //
416 <        if( string(chain->GetFile()->GetEndpointUrl()->GetFile()) != currentFile ) {
417 <          currentFile = string(chain->GetFile()->GetEndpointUrl()->GetFile());
418 <          hltchain->SetBranchAddress(fTriggerTableName, &hltTableStrings);
419 <          hltchain->SetBranchAddress(fTriggerLabelName, &hltLabelStrings);
420 <          hltchain->GetEntry(0);
421 <          hltTable->Clear();
422 <          fillTriggerNames(hltTable, hltTableStrings );
423 <        }
424 <        if( ctrl.debug ) cout << "file is : " << currentFile  << endl;
425 <        fillTriggerBits( hltTable, trigMask, triggerBits );
457 >        // trigger
458          passes_HLT_MC = true; // passed to apply as extern global, just for sync
459          if( !passHLTMC(triggerBits, info->RunNum(), info->EvtNum(), k2012_MC ) ) {
460            passes_HLT_MC = false;
461          }
462  
431        setHLTObjectRelations( hltObjArr, hltRelsArr, hltTableStrings, hltLabelStrings, fTrigObjs );
432
463        } else {
464          //
465          // JSON
# Line 442 | Line 472 | int main(int argc, char** argv)
472            }
473          }
474          
445        //
475          // trigger
476 <        //
477 <        if( string(chain->GetFile()->GetEndpointUrl()->GetFile()) != currentFile ) {
478 <          currentFile = string(chain->GetFile()->GetEndpointUrl()->GetFile());
479 <          hltchain->SetBranchAddress(fTriggerTableName, &hltTableStrings);
451 <          hltchain->SetBranchAddress(fTriggerLabelName, &hltLabelStrings);
452 <          hltchain->GetEntry(0);
453 <          hltTable->Clear();
454 <          fillTriggerNames(hltTable, hltTableStrings );
455 <        }
456 <
457 <        setHLTObjectRelations( hltObjArr, hltRelsArr, hltTableStrings, hltLabelStrings, fTrigObjs );
476 >        passes_HLT = true;
477 >        //if( !passHLT(ctrl, triggerBits,ti,info->RunNum()) ) {
478 >        //  passes_HLT = false;
479 >        //}
480  
459        if( ctrl.debug ) cout << "file is : " << currentFile  << endl;
460        /*
461        fillTriggerBits( hltTable, trigMask, triggerBits );
462        if( !passHLT(triggerBits, info->RunNum(), info->EvtNum() ) ) {
463          if( ctrl.debug ) cout << "\tfails trigger ... " << endl;
464          continue;
465        }
466        */
481        }
482  
483        //
# Line 501 | Line 515 | int main(int argc, char** argv)
515          if( abs(ret4l.Z2leptons[0].type) == 13  ) Z2type = 13;
516        }  
517        
504 #ifdef SYNC
505      if(ctrl.debug)
506        cout  << "bits: " << ret4l.status.selectionBits  << "\t"
507              << "Z1: " << Z1type << "\t"
508              << "Z2: " << Z2type << endl << endl;
509 #endif      
510      
518        if( ret4l.status.pass() ) {
519          fillAngles(ret4l,angles);
520          fillKinematics(ret4l,kinematics);
# Line 515 | Line 522 | int main(int argc, char** argv)
522          TLorentzVector pfmet; pfmet.SetPxPyPzE(metArr->At(0)->Mex(),metArr->At(0)->Mey(),0,0);
523          fillEventInfo( info, pfmet, evtinfo, ctrl.mc ? getNPU(puArr) : 0);
524          if( ctrl.mc) {
525 <          //      if( std::string(ctrl.efftype) != std::string("WTF?")) {
519 <            setEffiencyWeights(ctrl.era, ret4l, weights);
520 <            //    } else {
521 <            //      weights.won = weights.woff = 1.;
522 <            //    }
525 >          //setEffiencyWeights(ctrl.era, ret4l, triggerBits, hltTable, hltObjArr, fTrigObjs, weights);
526            if(ctrl.debug)
527              cout << "w: " << weights.w << "\t"
528                   << "npuw: " << weights.npuw << "\t"
# Line 555 | Line 558 | int main(int argc, char** argv)
558                   << endl;
559            }
560          }
561 +        TLorentzVector pfmet; pfmet.SetPxPyPzE(metArr->At(0)->Mex(),metArr->At(0)->Mey(),0,0);
562 +        fillEventInfo( info, pfmet, evtinfo, ctrl.mc ? getNPU(puArr) : 0);
563          foTree.Fill();
564        } else {
565          if(ctrl.debug)
566            cout << "failing with some other code : " << ret4l.status.selectionBits << endl;
567        }
568 <    }  
568 >      if(ctrl.debug)
569 >        cout << "passes HLT: " << passes_HLT << endl;
570 >    }
571  
572    
573    foTree.getFile()->cd();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines