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.18 by khahn, Thu May 10 03:01:17 2012 UTC vs.
Revision 1.23 by khahn, Sun May 20 19:08:59 2012 UTC

# Line 5 | Line 5
5   #include <iostream>                 // standard I/O
6   #include <iomanip>                  // functions to format standard I/O
7   #include <bitset>  
8 + #include <map>  
9   using namespace std;
10  
11   //
# Line 36 | Line 37 | using namespace std;
37   #include "PFCandidateCol.h"
38   #include "PileupInfoCol.h"
39   #include "PileupEnergyDensity.h"
40 + #include "MCParticle.h"
41   #include "TriggerMask.h"
42   #include "TriggerTable.h"
43   #include "Names.h"
# Line 50 | Line 52 | using namespace std;
52   #include "IsolationSelection.h"
53  
54   //#include "Selection.h"
55 < #include "ReferenceSelection.h"
55 > //#include "ReferenceSelection.h"
56 > #include "ReferenceSelection2.h"
57  
58   #include "TriggerUtils.h"
59   #include "PassHLT.h"
# Line 83 | Line 86 | TH1D * hpu;
86   RunLumiRangeMap rlrm;
87   vector<SimpleLepton> failingLeptons ; // for fake estimation
88   vector<SimpleLepton> passingLeptons;      // for fake estimation
89 + vector<unsigned> cutvec;
90 + vector<vector<unsigned> > zcutvec;
91 + vector<vector<unsigned> > zzcutvec;
92 + map<unsigned,float>       evtrhoMap;
93 + vector<string> cutstrs;
94 + bool passes_HLT_MC;
95 + vector<bool>   PFnoPUflag;;
96  
97   //
98   // prototypes
# Line 92 | Line 102 | void initPUWeights();
102   double getPUWeight(unsigned npu);
103   void setEffiencyWeights(EventData&, WeightStruct& );
104   void initRunLumiRangeMap();
105 + void initEvtRhoMap(map<unsigned,float> &);
106 + unsigned makePFnoPUArray(mithep::Array<PFCandidate> * fPFCandidates,
107 +                         vector<bool> &pfNoPileUpFlag,
108 +                         mithep::Array<Vertex>      * vtxArr );
109   //----------------------------------------------------------------------------
110  
111  
# Line 101 | Line 115 | void initRunLumiRangeMap();
115   int main(int argc, char** argv)
116   //----------------------------------------------------------------------------
117   {
118 +  cutstrs.push_back(string("skim0"));              //0
119 +  cutstrs.push_back(string("skim1"));              //1
120 +  cutstrs.push_back(string("trigger"));            //2
121 +  // -------------------------------------------------
122 +  cutstrs.push_back(string("Z candidate"));        //3
123 +  cutstrs.push_back(string("good Z1"));            //4
124 +  // -------------------------------------------------
125 +  cutstrs.push_back(string("4l"));                 //5  
126 +  cutstrs.push_back(string("ZZ candidate"));       //6
127 +  cutstrs.push_back(string("good Z2"));            //7
128 +  cutstrs.push_back(string("ZZ 20/10"));           //8
129 +  cutstrs.push_back(string("resonance"));          //9
130 +  cutstrs.push_back(string("m4l>70"));             //10
131 +  cutstrs.push_back(string("m4l>100"));            //11
132 +
133 +
134 +
135 +
136    string cmsswpath(CMSSW_BASE);
137    cmsswpath.append("/src");
138    std::bitset<1024> triggerBits;
139    vector<vector<string> > inputFiles;
140    inputFiles.push_back(vector<string>());
141    map<string,unsigned> entrymap; // number of unskimmed entries in each file
142 +  for( int i=0; i<cutstrs.size(); i++ ) cutvec.push_back(0);
143 +  for( int i=0; i<2; i++ )  {
144 +    zcutvec.push_back(vector<unsigned>());
145 +    for( int j=0; j<cutstrs.size(); j++ ) zcutvec[i].push_back(0);
146 +  }
147 +  for( int i=0; i<3; i++ )  {
148 +    zzcutvec.push_back(vector<unsigned>());
149 +    for( int j=0; j<cutstrs.size(); j++ ) zzcutvec[i].push_back(0);
150 +  }
151 +
152  
153    //
154    // args
# Line 210 | Line 252 | int main(int argc, char** argv)
252    initElectronIDMVA();
253    initElectronIsoMVA();
254    initTrigger();
255 <  
255 >
256 >  // hack
257 >  initEvtRhoMap(evtrhoMap);
258  
259    
260    //
# Line 229 | Line 273 | int main(int argc, char** argv)
273    mithep::Array<mithep::PileupInfo>           *puArr         = new mithep::Array<mithep::PileupInfo>();
274    mithep::Array<mithep::PileupEnergyDensity>  *puDArr        = new mithep::Array<mithep::PileupEnergyDensity>();
275    mithep::Array<mithep::Track>                *trkArr        = new mithep::Array<mithep::Track>();
276 +  mithep::Array<mithep::MCParticle>           *mcArr         = new mithep::Array<mithep::MCParticle>();
277    mithep::TriggerMask                         *trigMask      = new mithep::TriggerMask();
278    mithep::TriggerTable                        *hltTable      = new mithep::TriggerTable();
279    vector<string>                              *hltTableStrings  = new vector<string>();
# Line 241 | Line 286 | int main(int argc, char** argv)
286    TString fPileupInfoName(Names::gkPileupInfoBrn);
287    TString fPileupEnergyDensityName(Names::gkPileupEnergyDensityBrn);
288    TString fTrackName(Names::gkTrackBrn);
289 +  TString fMCParticleName(Names::gkMCPartBrn);
290    TString fTriggerMaskName(Names::gkHltBitBrn);
291    TString fTriggerTableName(Names::gkHltTableBrn);
292    
# Line 249 | Line 295 | int main(int argc, char** argv)
295    chain->SetBranchAddress(fMuonName,        &muonArr);
296    chain->SetBranchAddress(fPrimVtxName,     &vtxArr);
297    chain->SetBranchAddress(fPFCandidateName, &pfArr);
298 <  if( ctrl.mc ) chain->SetBranchAddress(fPileupInfoName,  &puArr);
298 >  if( ctrl.mc ) {
299 >    chain->SetBranchAddress(fPileupInfoName,  &puArr);
300 >    chain->SetBranchAddress(fMCParticleName,  &mcArr);
301 >  }
302    chain->SetBranchAddress(fPileupEnergyDensityName, &puDArr);
303    chain->SetBranchAddress(fTrackName, &trkArr);
304    chain->SetBranchAddress(fTriggerMaskName, &trigMask);
# Line 281 | Line 330 | int main(int argc, char** argv)
330    for(UInt_t ientry=0; ientry<imax; ientry++)
331      {
332        chain->GetEntry(ientry);
333 +
334 +      /*
335 +      bool found_tau=false;
336 +      if( ctrl.mc) {  // && ctrl.debug
337 +        cout << "nparticles: " << mcArr->GetEntries() << endl;
338 +        cout << "-----------------------------------" << endl;
339 +        for( int i=0; i<mcArr->GetEntries(); i++ ) {
340 +          const mithep::MCParticle *mc = mcArr->At(i);
341 +          cout << "i: " << i << "\t"
342 +               << "id: " << mc->AbsPdgId()
343 +               << endl;
344 +          if( mc->Is(MCParticle::kTau) ) {
345 +            found_tau=true;
346 +          }
347 +        }
348 +      }
349 +      cout << "-----------------------------------" << endl;
350 +      cout << "found tau: " << found_tau << endl;
351 +      */
352 +
353 +      // events that fail bc ele overlaps w/ reco mu
354 +      /*
355 +      if( info->EvtNum() != 67315 &&
356 +          info->EvtNum() != 288693 ) continue;
357 +      */
358 +
359 +      // events where they apparently don't veto electrons ...
360 +      /*
361 +      if( info->EvtNum() != 141713 &&
362 +          info->EvtNum() != 178019 &&
363 +          info->EvtNum() != 60823 &&
364 +          info->EvtNum() != 192795 ) continue;
365 +      */
366 +
367        if(!(ientry%1000)) cerr << "entry: " << ientry << endl;
368        setPV( ctrl, vtxArr, vtx);
369 +      //if (!(setPV( ctrl, vtxArr, vtx)) ) continue;
370  
371 +      float rho = evtrhoMap[info->EvtNum()];
372 +
373 +      //
374 +      // pfNoPU
375 +      //
376 +      //mithep::Array<PFCandidate> pfNoPileUp;
377 +      PFnoPUflag.clear();
378 +      int pfnopu_size = makePFnoPUArray( pfArr, PFnoPUflag, vtxArr );
379 +      assert(pfnopu_size == pfArr->GetEntries());
380  
381        //
382        // data/MC
# Line 293 | Line 386 | int main(int argc, char** argv)
386          // xsec & PU weights
387          //
388          weights.w = getWeight(xstab,entrymap,chain)/ctrl.totalMC;
389 +        cout << "xsec weight: " << weights.w << endl;
390          int npu = -1;
391          for(int i=0;i<puArr->GetEntries();i++) {
392            if(puArr->At(i)->GetBunchCrossing() == 0)
# Line 302 | Line 396 | int main(int argc, char** argv)
396          evtinfo.npu;
397          weights.npuw = getPUWeight(evtinfo.npu);
398          //      cout << "weight: " << weights.w << endl;
399 +        //
400 +        // trigger
401 +        //
402 +        if( string(chain->GetFile()->GetEndpointUrl()->GetFile()) != currentFile ) {
403 +          currentFile = string(chain->GetFile()->GetEndpointUrl()->GetFile());
404 +          hltchain->SetBranchAddress(fTriggerTableName, &hltTableStrings);
405 +          hltchain->GetEntry(0);
406 +          hltTable->Clear();
407 +          fillTriggerBits(hltTable, hltTableStrings );
408 +        }
409 +        if( ctrl.debug ) cout << "file is : " << currentFile  << endl;
410 +        fillTriggerBits( hltTable, trigMask, triggerBits );
411 +        passes_HLT_MC = true; // passed to apply as extern global, just for sync
412 +        if( !passHLTMC(triggerBits, info->RunNum(), info->EvtNum() ) ) {
413 +          passes_HLT_MC = false;
414 +        }
415        } else {
416          //
417          // JSON
# Line 324 | Line 434 | int main(int argc, char** argv)
434            fillTriggerBits(hltTable, hltTableStrings );
435          }
436          if( ctrl.debug ) cout << "file is : " << currentFile  << endl;
437 +        /*
438          fillTriggerBits( hltTable, trigMask, triggerBits );
439          if( !passHLT(triggerBits, info->RunNum(), info->EvtNum() ) ) {
440            if( ctrl.debug ) cout << "\tfails trigger ... " << endl;
441            continue;
442          }
443 +        */
444        }
445  
446        //
# Line 337 | Line 449 | int main(int argc, char** argv)
449        failingLeptons.clear();
450        passingLeptons.clear();
451        EventData ret4l =
452 <        apply_HZZ4L_reference_selection(ctrl, info,
453 <                              vtx,
454 <                              pfArr,
343 <                              puDArr,
344 <                              electronArr,
345 <                              &electronReferencePreSelection,
346 <                              &electronReferenceIDMVASelection,
347 <                              &electronReferenceIsoSelection,
348 <                              muonArr,
349 <                              &muonReferencePreSelection,
350 <                              &muonIDPFSelection,
351 <                              &muonReferenceIsoSelection);
452 >
453 >
454 >        // reference
455          /*
456 <        apply_HZZ4L_reference_selection(ctrl, info,
457 <                              vtx,
458 <                              pfArr,
459 <                              puArr,
460 <                              electronArr,
461 <                              &electronPreSelection,
462 <                              &electronIDMVASelection,
463 <                              &electronIsoMVASelection,
464 <                              muonArr,
465 <                              &muonPreSelection,
466 <                              &muonIDPFSelection,
467 <                              &muonIsoMVASelection);
456 >        apply_HZZ4L_reference2_selection(ctrl, info,
457 >                                         vtx,
458 >                                         pfArr,
459 >                                         //rho,
460 >                                         puDArr,
461 >                                         electronArr,
462 >                                         &electronReferencePreSelection,
463 >                                         &electronReferenceIDMVASelection,
464 >                                         &electronReferenceIsoSelection,
465 >                                         muonArr,
466 >                                         &muonReferencePreSelection,
467 >                                         &muonIDPFSelection,
468 >                                         &muonReferenceIsoSelection);
469          */
470  
471 +        // evolved
472 +        apply_HZZ4L_reference2_selection(ctrl, info,
473 +                                         vtx,
474 +                                         pfArr,
475 +                                         //rho,
476 +                                         puDArr,
477 +                                         electronArr,
478 +                                         &electronReferencePreSelection,
479 +                                         //&electronPreSelection,
480 +                                         &electronReferenceIDMVASelection,
481 +                                         &electronIsoMVASelection,
482 +                                         muonArr,
483 +                                         &muonReferencePreSelection,
484 +                                         //&muonPreSelection,
485 +                                         &muonIDPFSelection,
486 +                                         &muonIsoMVASelection);
487 +
488 +
489        if( ctrl.debug ) cout << endl;
490  
491 <      //      cout << "bits: " << ret4l.status.selectionBits << endl;
491 >
492 >      int Z1type=0, Z2type=0;
493 >      if( ret4l.status.selectionBits.to_ulong() >= PASS_ZCANDIDATE ) {
494 >        if( abs(ret4l.Z1leptons[0].type) == 11  ) Z1type = 11;
495 >        if( abs(ret4l.Z1leptons[0].type) == 13  ) Z1type = 13;
496 >      }  
497 >      if( ret4l.status.selectionBits.to_ulong() >= PASS_ZZCANDIDATE ) {
498 >        if( abs(ret4l.Z2leptons[0].type) == 11  ) Z2type = 11;
499 >        if( abs(ret4l.Z2leptons[0].type) == 13  ) Z2type = 13;
500 >      }  
501 >      
502 > #ifdef SYNC
503 >      cout  << "bits: " << ret4l.status.selectionBits  << "\t"
504 >            << "Z1: " << Z1type << "\t"
505 >            << "Z2: " << Z2type << endl;
506 >      cout << endl;
507 > #endif      
508        
509        if( ret4l.status.pass() ) {
510          fillAngles(ret4l,angles);
# Line 400 | Line 538 | int main(int argc, char** argv)
538          pass++;
539          //      if( pass > 3 ) break;
540  
541 <      } else if( ret4l.status.selectionBits.test(PASS_ZCANDIDATE) ) { // save for fakes ...
542 <        if(ctrl.debug) {
541 >      } else if( ret4l.status.selectionBits.test(PASS_GOODZ1) ) { // save for fakes ...
542 >        //      if(ctrl.debug) {
543            cout << "failingLeptons : " << failingLeptons.size() << endl;
544            for( int f=0; f<failingLeptons.size(); f++ ) {
545              SimpleLepton  l = failingLeptons[f];
# Line 410 | Line 548 | int main(int argc, char** argv)
548                   << "pT: " << l.vec.Pt()  << "\t"
549                   << "eta: " << l.vec.Eta()
550                   << endl;
551 <          }
551 >            //    }
552          }
553          foTree.Fill();
554        }
# Line 420 | Line 558 | int main(int argc, char** argv)
558    foTree.getFile()->cd();
559    foTree.getTree()->Write();
560    nt.WriteClose();
561 +
562 +  cout << endl;
563 +  cout << endl;
564 +  for( int i=0; i<cutvec.size(); i++ ) {
565 +    cout << "cut: " << i << "\t"
566 +         << "pass: " << cutvec[i];
567 +
568 +    if( i>PASS_TRIGGER&&i<=PASS_GOODZ1 )
569 +      cout << "\t2e: " << zcutvec[0][i]
570 +           << "\t2m: " << zcutvec[1][i];
571 +
572 +    if( i>PASS_ZCANDIDATE )
573 +      cout << "\t4e: " << zzcutvec[0][i]
574 +           << "\t4m: " << zzcutvec[1][i]
575 +           << "\t2e2m: " << zzcutvec[2][i];
576 +
577 +    cout << "\t" << cutstrs[i] << endl;
578 +
579 +    cout << endl;
580 +  }
581 +
582   }
583  
584   //----------------------------------------------------------------------------
# Line 448 | Line 607 | bool setPV(ControlFlags ctrl,
607      if( ctrl.debug ) cout << "vertex :: " << i << "\tntrks: " << pv->NTracks() << endl;
608      
609      // Select best PV for corrected d0; if no PV passing cuts, the first PV in the collection will be used
610 <    //  if(!pv->IsValid()) continue;
610 >    if(!pv->IsValid())                                continue;
611      if(pv->NTracksFit()       < fMinNTracksFit)       continue;
612      if(pv->Ndof()                 < fMinNdof)         continue;
613      if(fabs(pv->Z()) > fMaxAbsZ)                      continue;
# Line 469 | Line 628 | bool setPV(ControlFlags ctrl,
628        if( ctrl.debug) cout << "new PV set, pt : " << best_sumpt << endl;
629      }
630    }
631 <  
631 >  // sync
632    if(!bestPV) bestPV = vtxArr->At(0);
633 +  //if(!bestPV) return false;
634    vtx.SetPosition(bestPV->X(),bestPV->Y(),bestPV->Z());
635    vtx.SetErrors(bestPV->XErr(),bestPV->YErr(),bestPV->ZErr());
636    return true;
# Line 557 | Line 717 | double getPUWeight(unsigned npu)
717   {
718    return hpu->GetBinContent(hpu->FindBin(npu));
719   }
720 +
721 + //----------------------------------------------------------------------------
722 + void initEvtRhoMap( map<unsigned, float> & evtrhoMap )
723 + //----------------------------------------------------------------------------
724 + {
725 +  unsigned evt;
726 +  float rho;
727 +
728 +  cout << "initialzing EvtRhoMap ";
729 +  //FILE * f = fopen("evtrho.dat", "r");
730 +  //  FILE * f = fopen("allrho.cali.uniq.dat", "r");
731 +  FILE * f = fopen("allrhoAA.cali.uniq.dat", "r");
732 +  int lcount=0;
733 +  while( fscanf( f, "%u:%f", &evt, &rho ) ) {
734 +    if( feof(f) ) break;
735 +    evtrhoMap[evt] = rho;
736 +    lcount++;
737 +    if( !(lcount%1000) ) cout << "."; flush(cout);
738 +  }
739 +  cout << " done" << endl;
740 + }
741 +
742 + //----------------------------------------------------------------------------
743 + unsigned makePFnoPUArray(mithep::Array<PFCandidate> * fPFCandidates,
744 +                     vector<bool> &pfNoPileUpflag,
745 +                     mithep::Array<Vertex>      * vtxArr )
746 + //----------------------------------------------------------------------------
747 + {
748 +  for(UInt_t i = 0; i < fPFCandidates->GetEntries(); i++) {
749 +    const PFCandidate *pf = fPFCandidates->At(i);
750 +    assert(pf);
751 +
752 +    if(pf->PFType() == PFCandidate::eHadron) {
753 +      if(pf->HasTrackerTrk() &&
754 +         vtxArr->At(0)->HasTrack(pf->TrackerTrk()) &&
755 +         vtxArr->At(0)->TrackWeight(pf->TrackerTrk()) > 0) {
756 +
757 +        pfNoPileUpflag.push_back(1);
758 +
759 +      } else {
760 +
761 +        Bool_t vertexFound = kFALSE;
762 +        const Vertex *closestVtx = 0;
763 +        Double_t dzmin = 10000;
764 +        
765 +        // loop over vertices
766 +        for(UInt_t j = 0; j < vtxArr->GetEntries(); j++) {
767 +          const Vertex *vtx = vtxArr->At(j);
768 +          assert(vtx);
769 +          
770 +          if(pf->HasTrackerTrk() &&
771 +             vtx->HasTrack(pf->TrackerTrk()) &&
772 +             vtx->TrackWeight(pf->TrackerTrk()) > 0) {
773 +            vertexFound = kTRUE;
774 +            closestVtx = vtx;
775 +            break;
776 +          }
777 +          Double_t dz = fabs(pf->SourceVertex().Z() - vtx->Z());
778 +          if(dz < dzmin) {
779 +            closestVtx = vtx;
780 +            dzmin = dz;
781 +          }
782 +        }
783 +
784 +        //      if(fCheckClosestZVertex) {
785 +        if(1) {
786 +          // Fallback: if track is not associated with any vertex,
787 +          // associate it with the vertex closest in z
788 +          if(vertexFound || closestVtx != vtxArr->At(0)) {
789 +            //      pfPileUp->Add(pf);
790 +            pfNoPileUpflag.push_back(0);
791 +          } else {
792 +            pfNoPileUpflag.push_back(1);
793 +          }
794 +        } else {
795 +          if(vertexFound && closestVtx != vtxArr->At(0)) {
796 +            //      pfPileUp->Add(pf);
797 +            pfNoPileUpflag.push_back(0);
798 +          } else {
799 +            //      PFCandidate * pfNoPileUp->AddNew(); // Ridiculous but that's how it is
800 +            pfNoPileUpflag.push_back(1);
801 +          }
802 +        }
803 +      } //hadron & trk stuff
804 +    } else { // hadron
805 +      //      PFCandidate * ptr = pfNoPileUp->AddNew();
806 +      pfNoPileUpflag.push_back(1);
807 +    }
808 +  } // Loop over PF candidates
809 +
810 +  return pfNoPileUpflag.size();
811 + }
812 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines