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.33 by khahn, Sun Jun 3 15:59:56 2012 UTC vs.
Revision 1.43 by khahn, Mon Jun 18 21:02:55 2012 UTC

# Line 40 | Line 40 | using namespace std;
40   #include "MCParticle.h"
41   #include "TriggerMask.h"
42   #include "TriggerTable.h"
43 + #include "TriggerObject.h"
44 + #include "TriggerObjectRel.h"
45   #include "Names.h"
46   #include "BaseMod.h"
47  
# Line 65 | Line 67 | using namespace std;
67   #include "RunLumiRangeMap.h"
68   #include "SampleWeight.h"
69   #include "EfficiencyWeightsInterface.h"
70 + #include "SelectionFuncs.h"
71  
72   #include "SimpleLepton.h"
73  
# Line 94 | Line 97 | vector<bool>   PFnoPUflag;;
97   //----------------------------------------------------------------------------
98   void initPUWeights();
99   double getPUWeight(unsigned npu);
97 void setEra(string, ControlFlags&);
98 void setEffiencyWeights(EventData&, WeightStruct& );
100   void initRunLumiRangeMap();
101 < void initEvtRhoMap(map<unsigned,float> &);
102 < unsigned makePFnoPUArray(mithep::Array<PFCandidate> * fPFCandidates,
103 <                         vector<bool> &pfNoPileUpFlag,
104 <                         const mithep::Array<mithep::Vertex>     * vtxArr );
101 > void setHLTObjectRelations( mithep::Array<mithep::TriggerObject>        *hltObjArr,
102 >                            mithep::Array<mithep::TriggerObjectRel>     *hltRelsArr,
103 >                            vector<string> * fHLTTab,
104 >                            vector<string> * fHLTLab );
105   //----------------------------------------------------------------------------
106  
107  
# Line 225 | Line 226 | int main(int argc, char** argv)
226    TH1F * h_wf11_hpt;
227    if(ctrl.mc) {
228      nt.makeWeightBranch(weights);
229 <    //    nt.makeGenInfoBranch(geninfo);
230 <    initEfficiencyWeights();
229 >    if(ctrl.fillGen ) nt.makeGenInfoBranch(geninfo);
230 >    if(ctrl.efftype != string("WTF?")) initEfficiencyWeights();
231      initPUWeights();
232  
233      // Higgs only, pt reweighting
# Line 247 | Line 248 | int main(int argc, char** argv)
248    initElectronIDMVAV1();
249    initTrigger();
250  
250  // hack
251  initEvtRhoMap(evtrhoMap);
252
251    
252    //
253    // Setup tree I/O
# Line 271 | Line 269 | int main(int argc, char** argv)
269    mithep::TriggerMask                         *trigMask      = new mithep::TriggerMask();
270    mithep::TriggerTable                        *hltTable      = new mithep::TriggerTable();
271    vector<string>                              *hltTableStrings  = new vector<string>();
272 +  vector<string>                              *hltLabelStrings  = new vector<string>();
273 +  mithep::Array<mithep::TriggerObject>        *hltObjArr     = new mithep::Array<mithep::TriggerObject>();
274 +  mithep::Array<mithep::TriggerObjectRel>     *hltRelsArr    = new mithep::Array<mithep::TriggerObjectRel>();
275 +  std::vector<std::string>                    *hltTab        = new vector<string>();
276 +  std::vector<std::string>                    *hltLab        = new vector<string>();
277 +
278  
279    TString fElectronName(Names::gkElectronBrn);
280    TString fMuonName(Names::gkMuonBrn);
# Line 284 | Line 288 | int main(int argc, char** argv)
288    TString fMCEvtInfoName(Names::gkMCEvtInfoBrn);
289    TString fTriggerMaskName(Names::gkHltBitBrn);
290    TString fTriggerTableName(Names::gkHltTableBrn);
291 <  
291 >  TString fTriggerLabelName(Names::gkHltLabelBrn);
292 >  TString fTriggerObjectName(Names::gkHltObjBrn);
293 >  TString fTriggerObjectRelsName(Form("HLTObjectsRelation"));
294 >
295 > //   TString fHLTLabName(Names::gkHltLabelBrn);
296 > //   TString fHLTTabName(Names::gkHltTableBrn);
297 > //   TString fHLTTabNamePub(Form("%sFwk",fHLTTabName.Data()));
298 > //   TString fHLTLabNamePub(Form("%sFwk",fHLTLabName.Data()));
299 > //   TString fObjsNamePub(Form("%sFwk",fTriggerObjectName.Data()));
300 >
301 >
302 >
303    chain->SetBranchAddress(fInfoName,        &info);
304    chain->SetBranchAddress(fElectronName,    &electronArr);
305    chain->SetBranchAddress(fMuonName,        &muonArr);
# Line 298 | Line 313 | int main(int argc, char** argv)
313    chain->SetBranchAddress(fPileupEnergyDensityName, &puDArr);
314    chain->SetBranchAddress(fTrackName, &trkArr);
315    chain->SetBranchAddress(fTriggerMaskName, &trigMask);
316 +  chain->SetBranchAddress(fTriggerObjectName,  &hltObjArr);
317 +  chain->SetBranchAddress(fTriggerObjectRelsName,  &hltRelsArr);
318 +  //  chain->SetBranchAddress(fHLTTabNamePub,  &hltTab);
319 +  //  chain->SetBranchAddress(fHLTLabNamePub,  &hltLab);
320 +
321    cout << "hlttable: " << fTriggerTableName << endl;
322    hltchain->SetBranchAddress(fTriggerTableName, &hltTableStrings);
323 +  hltchain->SetBranchAddress(fTriggerLabelName, &hltLabelStrings);
324  
325    mithep::Vertex              vtx;          // best primary vertex in the event
326  
# Line 319 | Line 340 | int main(int argc, char** argv)
340    int imax = chain->GetEntries();
341    cout << "nEntries: " << imax << endl;
342  
322
343    //
344    // Loop !!!!!!!!!
345    //--------------------------------------------------------------------------------------------------------------
# Line 327 | Line 347 | int main(int argc, char** argv)
347      {
348        chain->GetEntry(ientry);
349        if(!(ientry%1000)) cerr << "entry: " << ientry << endl;
350 +      
351 +      if( ctrl.debug ) {
352 +        cout << "-----------------------------------------------------------------" << endl;
353 +        cout << "-----------------------------------------------------------------" << endl;
354 +        cout << "Run: " << info->RunNum()
355 +             << "\tEvt: " << info->EvtNum()
356 +             << "\tLumi: " << info->LumiSec()
357 +             << endl;
358 +        cout << "-----------------------------------------------------------------" << endl;
359 +      }
360 +
361  
331 #ifdef HACKED_RHOS
332      float rho = evtrhoMap[info->EvtNum()];
333 #endif
362        string fname = string(chain->GetFile()->GetEndpointUrl()->GetFile());
363        setEra( fname, ctrl );
364  
365  
366 +
367        //
368        // pfNoPU
369        //
# Line 384 | Line 413 | int main(int argc, char** argv)
413          if( string(chain->GetFile()->GetEndpointUrl()->GetFile()) != currentFile ) {
414            currentFile = string(chain->GetFile()->GetEndpointUrl()->GetFile());
415            hltchain->SetBranchAddress(fTriggerTableName, &hltTableStrings);
416 +          hltchain->SetBranchAddress(fTriggerLabelName, &hltLabelStrings);
417            hltchain->GetEntry(0);
418            hltTable->Clear();
419            fillTriggerNames(hltTable, hltTableStrings );
420          }
421          if( ctrl.debug ) cout << "file is : " << currentFile  << endl;
422 <        fillTriggerNames( hltTable, trigMask, triggerBits );
422 >        fillTriggerBits( hltTable, trigMask, triggerBits );
423          passes_HLT_MC = true; // passed to apply as extern global, just for sync
424          if( !passHLTMC(triggerBits, info->RunNum(), info->EvtNum(), k2012_MC ) ) {
425            passes_HLT_MC = false;
426          }
427 +
428 +        setHLTObjectRelations( hltObjArr, hltRelsArr, hltTableStrings, hltLabelStrings );
429 +        for( int i=0; i<hltObjArr->GetEntries(); i++ ) {
430 +          const mithep::TriggerObject *to = (*hltObjArr)[i];
431 +          to->Print();
432 +        }
433 +
434 +
435        } else {
436          //
437          // JSON
438          //
439 <        /*
440 <        RunLumiRangeMap::RunLumiPairType rl(info->RunNum(), info->LumiSec());      
441 <        if( !(rlrm.HasRunLumi(rl)) )  {
442 <          if( ctrl.debug ) cout << "\tfails JSON" << endl;
443 <          continue;
439 >        if(!(ctrl.noJSON) ) {
440 >          RunLumiRangeMap::RunLumiPairType rl(info->RunNum(), info->LumiSec());      
441 >          if( !(rlrm.HasRunLumi(rl)) )  {
442 >            if( ctrl.debug ) cout << "fails JSON" << endl;
443 >            continue;
444 >          }
445          }
446 <        */
446 >
447          //
448          // trigger
449          //
450          if( string(chain->GetFile()->GetEndpointUrl()->GetFile()) != currentFile ) {
451            currentFile = string(chain->GetFile()->GetEndpointUrl()->GetFile());
452            hltchain->SetBranchAddress(fTriggerTableName, &hltTableStrings);
453 +          hltchain->SetBranchAddress(fTriggerLabelName, &hltLabelStrings);
454            hltchain->GetEntry(0);
455            hltTable->Clear();
456            fillTriggerNames(hltTable, hltTableStrings );
457          }
458 +
459 +        setHLTObjectRelations( hltObjArr, hltRelsArr, hltTableStrings, hltLabelStrings );
460 +        for( int i=0; i<hltObjArr->GetEntries(); i++ ) {
461 +          const mithep::TriggerObject *to = (*hltObjArr)[i];
462 +          to->Print();
463 +        }
464 +
465          if( ctrl.debug ) cout << "file is : " << currentFile  << endl;
466          /*
467 <        fillTriggerNames( hltTable, trigMask, triggerBits );
467 >        fillTriggerBits( hltTable, trigMask, triggerBits );
468          if( !passHLT(triggerBits, info->RunNum(), info->EvtNum() ) ) {
469            if( ctrl.debug ) cout << "\tfails trigger ... " << endl;
470            continue;
# Line 437 | Line 484 | int main(int argc, char** argv)
484          apply_HZZ4L_reference_selection(ctrl, info,
485                                          vtxArr,
486                                          pfArr,
440 #ifdef HACKED_RHOS
441                                        rho,
442 #else
487                                          puDArr,
444 #endif
488                                          electronArr,
489                                          &electronReferencePreSelection,
490                                          &electronReferenceIDMVASelectionV1,
# Line 477 | Line 520 | int main(int argc, char** argv)
520          fillMassErrors(ret4l,muonArr,electronArr,kinematics);
521          fillEventInfo(info,evtinfo);
522          if( ctrl.mc) {
523 +          if( std::string(ctrl.efftype) != std::string("WTF?")) {
524            setEffiencyWeights(ret4l, weights);
525 +          } else {
526 +            weights.won = weights.woff = 1.;
527 +          }
528             if(ctrl.debug)
529               cout << "w: " << weights.w << "\t"
530                    << "won: " << weights.won << "\t"
# Line 500 | Line 547 | int main(int argc, char** argv)
547          //      if( pass > 3 ) break;
548  
549        } else if( ret4l.status.selectionBits.test(PASS_GOODZ1) &&
550 <                 ret4l.status.selectionBits.to_ulong() < PASS_4L) { // save for fakes ...
551 <        //      if(ctrl.debug) {
550 >                 ret4l.status.selectionBits.to_ulong() < (1UL<<PASS_4L)) { // save for fakes ...
551 >        if(ctrl.debug) {
552            cout << "failingLeptons : " << failingLeptons.size() << endl;
553            for( int f=0; f<failingLeptons.size(); f++ ) {
554              SimpleLepton  l = failingLeptons[f];
# Line 510 | Line 557 | int main(int argc, char** argv)
557                   << "pT: " << l.vec.Pt()  << "\t"
558                   << "eta: " << l.vec.Eta()
559                   << endl;
560 <            //    }
560 >          }
561          }
562          foTree.Fill();
563 +      } else {
564 +        cout << "failing with some other code : " << ret4l.status.selectionBits << endl;
565        }
566      }  
567  
# Line 544 | Line 593 | int main(int argc, char** argv)
593   }
594  
595  
547
548 //----------------------------------------------------------------------------
549 void setEffiencyWeights(EventData & evtdat, WeightStruct & weights )
550 //----------------------------------------------------------------------------
551 {
552  vector<SimpleLepton> lepvec = evtdat.Z1leptons;
553  lepvec.insert(lepvec.end(), evtdat.Z2leptons.begin(), evtdat.Z2leptons.end());
554  double w_offline=-1, werr_offline=0;
555  double w_online=-1, werr_online=0;
556  
557  vector< pair <double,double> > wlegs; // pair here is eff & err
558  vector< pair <float,float> > mvec;  // pair here is eta & pt
559
560  //      vector< pair <float,float> > evec;  // pair here is eta & pt
561  // now deal with medium vs loose
562  vector< pair< bool, pair <float,float> > > evec;  // pair here is eta & pt
563  
564  for( int k=0; k<lepvec.size(); k++ ) {
565    if( abs(lepvec[k].type) == 13 ) {
566      mvec.push_back( std::pair<float,float> (fabs(lepvec[k].vec.Eta()), lepvec[k].vec.Pt()) );
567      wlegs.push_back( muonPerLegOfflineEfficiencyWeight( fabs(lepvec[k].vec.Eta()),
568                                                          lepvec[k].vec.Pt() ) );
569    } else {
570      
571      // now deal with medium vs loose
572      //              evec.push_back( std::pair<float,float> (fabs(lepvec[k].vec.Eta()), lepvec[k].vec.Pt()) );
573      
574      std::pair<float,float> tmppair(fabs(lepvec[k].vec.Eta()), lepvec[k].vec.Pt());
575      evec.push_back( std::pair<bool, std::pair<float,float> > (lepvec[k].isTight, tmppair) );
576      
577      //              wlegs.push_back( elePerLegOfflineEfficiencyWeight(  fabs(lepvec[k].vec.Eta()),
578      //                                                                 lepvec[k].vec.Pt() ) );
579      
580      wlegs.push_back( elePerLegOfflineEfficiencyWeight(  fabs(lepvec[k].vec.Eta()),
581                                                          lepvec[k].vec.Pt(),
582                                                          lepvec[k].isTight ) );
583      
584    }
585  }
586  
587  pair<double,double> offpair = getOfflineEfficiencyWeight( wlegs );
588  weights.woff    = offpair.first;
589  weights.werroff = offpair.second;
590  
591  pair<double,double> onpair  = getOnlineEfficiencyWeight( mvec, evec );
592  weights.won    = onpair.first;
593  weights.werron = onpair.second;
594 }
595
596
596   //----------------------------------------------------------------------------
597   void initRunLumiRangeMap()
598   //----------------------------------------------------------------------------
# Line 607 | Line 606 | void initRunLumiRangeMap()
606    // r11b
607    rlrm.AddJSONFile(std::string("./data/Cert_160404-180252_7TeV_PromptReco_Collisions11_JSON.txt"));  
608    */
609 +
610 +  // 2012 only for now ...
611 +  rlrm.AddJSONFile(std::string("./data/Cert_190456-194479_8TeV_PromptReco_Collisions12_JSON.txt"));  
612 +
613   };
614  
615  
# Line 626 | Line 629 | double getPUWeight(unsigned npu)
629   }
630  
631   //----------------------------------------------------------------------------
632 < void initEvtRhoMap( map<unsigned, float> & evtrhoMap )
632 > void setHLTObjectRelations( mithep::Array<mithep::TriggerObject>    *hltObjArr,
633 >                            mithep::Array<mithep::TriggerObjectRel> *hltRelsArr,
634 >                            vector<string> * fHLTTab,
635 >                            vector<string> * fHLTLab )
636   //----------------------------------------------------------------------------
637   {
632  unsigned evt;
633  float rho;
638  
639 <  cout << "initialzing EvtRhoMap ";
640 <  //FILE * f = fopen("evtrho.dat", "r");
641 <  //  FILE * f = fopen("allrho.cali.uniq.dat", "r");
642 <  FILE * f = fopen("/data/blue/khahn/CMSSW_4_4_2/src/MitHzz4l/allrhoAA.cali.uniq.dat", "r");
643 <  int lcount=0;
644 <  while( fscanf( f, "%u:%f", &evt, &rho ) ) {
645 <    if( feof(f) ) break;
646 <    evtrhoMap[evt] = rho;
647 <    lcount++;
648 <    if( !(lcount%1000) ) cout << "."; flush(cout);
639 >  const int n = hltRelsArr->GetEntries();
640 >  for (int i=0; i<n; ++i) {
641 >    const TriggerObjectRel *rel = hltRelsArr->At(i);
642 >    if (!rel) continue;
643 >
644 > //     const TriggerObjectBase *ob = hltObjArr->At(rel->ObjInd());
645 > //     if (!ob) continue;
646 >
647 >    hltObjArr->At(rel->ObjInd())->SetTrigName(fHLTTab->at(rel->TrgId()).c_str());
648 >    hltObjArr->At(rel->ObjInd())->SetModuleName(fHLTLab->at(rel->ModInd()).c_str());
649 >    hltObjArr->At(rel->ObjInd())->SetFilterName(fHLTLab->at(rel->FilterInd()).c_str());
650 >    if (hltObjArr->At(rel->ObjInd())->TagInd()>=0)
651 >      hltObjArr->At(rel->ObjInd())->SetTagName(fHLTLab->at(hltObjArr->At(rel->ObjInd())->TagInd()).c_str());
652 >    else
653 >      hltObjArr->At(rel->ObjInd())->SetTagName("Unknown");
654    }
655 <  cout << " done" << endl;
647 < }
648 <
649 < //----------------------------------------------------------------------------
650 < unsigned makePFnoPUArray(mithep::Array<PFCandidate> * fPFCandidates,
651 <                         vector<bool> &pfNoPileUpflag,
652 <                         const mithep::Array<mithep::Vertex>      * vtxArr )
653 < //----------------------------------------------------------------------------
654 < {
655 <  for(UInt_t i = 0; i < fPFCandidates->GetEntries(); i++) {
656 <    const PFCandidate *pf = fPFCandidates->At(i);
657 <    assert(pf);
658 <
659 <    if(pf->PFType() == PFCandidate::eHadron) {
660 <      if(pf->HasTrackerTrk() &&
661 <         vtxArr->At(0)->HasTrack(pf->TrackerTrk()) &&
662 <         vtxArr->At(0)->TrackWeight(pf->TrackerTrk()) > 0) {
663 <
664 <        pfNoPileUpflag.push_back(1);
665 <
666 <      } else {
667 <
668 <        Bool_t vertexFound = kFALSE;
669 <        const Vertex *closestVtx = 0;
670 <        Double_t dzmin = 10000;
671 <        
672 <        // loop over vertices
673 <        for(UInt_t j = 0; j < vtxArr->GetEntries(); j++) {
674 <          const Vertex *vtx = vtxArr->At(j);
675 <          assert(vtx);
676 <          
677 <          if(pf->HasTrackerTrk() &&
678 <             vtx->HasTrack(pf->TrackerTrk()) &&
679 <             vtx->TrackWeight(pf->TrackerTrk()) > 0) {
680 <            vertexFound = kTRUE;
681 <            closestVtx = vtx;
682 <            break;
683 <          }
684 <          Double_t dz = fabs(pf->SourceVertex().Z() - vtx->Z());
685 <          if(dz < dzmin) {
686 <            closestVtx = vtx;
687 <            dzmin = dz;
688 <          }
689 <        }
690 <
691 <        //      if(fCheckClosestZVertex) {
692 <        if(1) {
693 <          // Fallback: if track is not associated with any vertex,
694 <          // associate it with the vertex closest in z
695 <          if(vertexFound || closestVtx != vtxArr->At(0)) {
696 <            //      pfPileUp->Add(pf);
697 <            pfNoPileUpflag.push_back(0);
698 <          } else {
699 <            pfNoPileUpflag.push_back(1);
700 <          }
701 <        } else {
702 <          if(vertexFound && closestVtx != vtxArr->At(0)) {
703 <            //      pfPileUp->Add(pf);
704 <            pfNoPileUpflag.push_back(0);
705 <          } else {
706 <            //      PFCandidate * pfNoPileUp->AddNew(); // Ridiculous but that's how it is
707 <            pfNoPileUpflag.push_back(1);
708 <          }
709 <        }
710 <      } //hadron & trk stuff
711 <    } else { // hadron
712 <      //      PFCandidate * ptr = pfNoPileUp->AddNew();
713 <      pfNoPileUpflag.push_back(1);
714 <    }
715 <  } // Loop over PF candidates
716 <
717 <  return pfNoPileUpflag.size();
718 < }
719 <
720 < void setEra(string fname, ControlFlags &ctrl)
721 < {
722 <  if( ctrl.mc && (fname.find("f11-") != string::npos)  ) ctrl.era=2011 ;
723 <  if( ctrl.mc && (fname.find("s12-") != string::npos)  ) ctrl.era=2012 ;
724 <  if( !ctrl.mc && (fname.find("r11-") != string::npos)  ) ctrl.era=2011 ;
725 <  if( !ctrl.mc && (fname.find("r12-") != string::npos)  ) ctrl.era=2012 ;
726 < }
655 > };

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines