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.14 by khahn, Sat May 5 21:43:55 2012 UTC vs.
Revision 1.24 by khahn, Mon May 21 22:29:53 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 34 | Line 35 | using namespace std;
35   #include "Vertex.h"
36   #include "PFCandidate.h"
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 48 | 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 57 | Line 62 | using namespace std;
62   #include "InfoStruct.h"
63   //#include "GenInfoStruct.h"
64   #include "WeightStruct.h"
65 < #include "GlobalDataAndFuncs.h"
65 > //#include "GlobalDataAndFuncs.h"
66 > #include "RunLumiRangeMap.h"
67 >
68   #include "AngleTuple.h"
69 + #include "FOTuple.h"
70  
71   #include "SampleWeight.h"
72   #include "EfficiencyWeightsInterface.h"
73  
74 + #include "SimpleLepton.h"
75 +
76   #ifndef CMSSW_BASE
77   #define CMSSW_BASE "../"
78   #endif
79  
80   using namespace mithep;
81  
82 + //
83 + // globals
84 + //----------------------------------------------------------------------------
85 + 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
99   //----------------------------------------------------------------------------
100   bool setPV(ControlFlags,const mithep::Array<mithep::Vertex>*, mithep::Vertex& );
101 + 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 < //=== MAIN =================================================================================================
111 >
112 > //
113 > // MAIN
114 > //----------------------------------------------------------------------------
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,double> entrymap; // number of unskimmed entries in each file
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 99 | Line 165 | int main(int argc, char** argv)
165        return 1;
166      }
167    ctrl.dump();
102  assert( ctrl.mH != 0 );
168  
169  
170  
# Line 116 | Line 181 | int main(int argc, char** argv)
181        if( !(strncmp( fname.c_str(), "#", 1 ) ) ) continue; // skip commented lines
182        cout << "adding inputfile : " << fname.c_str() << endl;
183        entrymap[string(fname.c_str())] = unskimmedEntries(fname.c_str());
184 +      cout << "unskimmed entries: " << entrymap[string(fname.c_str())] << endl;
185        chain->AddFile(fname.c_str());
186        hltchain->AddFile(fname.c_str());
187      }
188    } else {
189      cout << "adding inputfile : " << ctrl.inputfile.c_str() << endl;
190 +    unsigned tmpent = unskimmedEntries(ctrl.inputfile.c_str());
191 +    cout << "tmpent: " << tmpent << endl;
192      entrymap[string(ctrl.inputfile.c_str())] = unskimmedEntries(ctrl.inputfile.c_str());
193 +    cout << "unskimmed entries: " << entrymap[string(ctrl.inputfile.c_str())] << endl;
194      chain->AddFile(ctrl.inputfile.c_str());
195      hltchain->AddFile(ctrl.inputfile.c_str());
196    }
# Line 152 | Line 221 | int main(int argc, char** argv)
221    nt.makeKinematicsBranch(kinematics);
222    nt.makeInfoBranch(evtinfo);
223  
224 +  FOTuple foTree( nt.getFile(), (const char*)"FOtree");
225 +  foTree.makeFailedLeptonBranch(failingLeptons);
226 +  foTree.makeZLeptonBranch(passingLeptons);
227 +
228    TH1F * h_w_hpt;
229    if(ctrl.mc) {
230      nt.makeWeightBranch(weights);
231      //    nt.makeGenInfoBranch(geninfo);
232      initEfficiencyWeights();
233 +    initPUWeights();
234      /*
235      // Higgs only, pt reweighting
236      if( ctrl.mH <= 140 ) {
# Line 178 | Line 252 | int main(int argc, char** argv)
252    initElectronIDMVA();
253    initElectronIsoMVA();
254    initTrigger();
255 <  
256 <  
257 <  //##########################################################################
258 <  // Setup tree I/O
185 <  //##########################################################################
255 >
256 >  // hack
257 >  initEvtRhoMap(evtrhoMap);
258 >
259    
260    //
261 <  // Access samples and fill histograms
261 >  // Setup tree I/O
262 >  //--------------------------------------------------------------------------------------------------------------
263    TFile *inputFile=0;
264    TTree *eventTree=0;  
265    string currentFile("");
266  
193  // Data structures to store info from TTrees
267    mithep::EventHeader *info    = new mithep::EventHeader();
268    //  mithep::TGenInfo    *ginfo  = new mithep::TGenInfo();
269    mithep::Array<mithep::Electron>             *electronArr   = new mithep::Array<mithep::Electron>();
270    mithep::Array<mithep::Muon>                 *muonArr       = new mithep::Array<mithep::Muon>();
271    mithep::Array<mithep::Vertex>               *vtxArr        = new mithep::Array<mithep::Vertex>();
272    mithep::Array<mithep::PFCandidate>          *pfArr         = new mithep::Array<mithep::PFCandidate>();
273 <  mithep::Array<mithep::PileupEnergyDensity>  *puArr         = new mithep::Array<mithep::PileupEnergyDensity>();
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 208 | Line 283 | int main(int argc, char** argv)
283    TString fInfoName(Names::gkEvtHeaderBrn);
284    TString fPrimVtxName(Names::gkPVBrn);
285    TString fPFCandidateName(Names::gkPFCandidatesBrn);
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 218 | Line 295 | int main(int argc, char** argv)
295    chain->SetBranchAddress(fMuonName,        &muonArr);
296    chain->SetBranchAddress(fPrimVtxName,     &vtxArr);
297    chain->SetBranchAddress(fPFCandidateName, &pfArr);
298 <  chain->SetBranchAddress(fPileupEnergyDensityName, &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);
305    cout << "hlttable: " << fTriggerTableName << endl;
# Line 243 | Line 324 | int main(int argc, char** argv)
324    cout << "nEntries: " << imax << endl;
325  
326  
327 <  //##########################################################################
328 <  // Loop !!!!!!!!! should alternate events here and +1 in the training ...
329 <  //##########################################################################
327 >  //
328 >  // Loop !!!!!!!!!
329 >  //--------------------------------------------------------------------------------------------------------------
330    for(UInt_t ientry=0; ientry<imax; ientry++)
331      {
332        chain->GetEntry(ientry);
252      if(!(ientry%1000)) cerr << "entry: " << ientry << endl;
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
383 +      //
384        if(ctrl.mc) {
385 <        weights.w = getWeight(xstab,entrymap,chain);
385 >        //
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)
393 >            npu = puArr->At(i)->GetPU_NumInteractions();
394 >        }
395 >        assert(npu>=0);
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
418 +        //
419 +        /*
420 +        RunLumiRangeMap::RunLumiPairType rl(info->RunNum(), info->LumiSec());      
421 +        if( !(rlrm.HasRunLumi(rl)) )  {
422 +          if( ctrl.debug ) cout << "\tfails JSON" << endl;
423 +          continue;
424 +        }
425 +        */
426 +        //
427 +        // trigger
428 +        //
429          if( string(chain->GetFile()->GetEndpointUrl()->GetFile()) != currentFile ) {
430            currentFile = string(chain->GetFile()->GetEndpointUrl()->GetFile());
431            hltchain->SetBranchAddress(fTriggerTableName, &hltTableStrings);
# Line 264 | 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 );
268      }
269      
270      
271      //
272      // trigger
273      //
274      if( !ctrl.mc ) {
439          if( !passHLT(triggerBits, info->RunNum(), info->EvtNum() ) ) {
440            if( ctrl.debug ) cout << "\tfails trigger ... " << endl;
441            continue;
442          }
443 +        */
444        }
445 <      
445 >
446        //
447        // lepton/kinematic selection ...
448        //
449 +      failingLeptons.clear();
450 +      passingLeptons.clear();
451        EventData ret4l =
452 <        apply_HZZ4L_reference_selection(ctrl, info,
453 <                              vtx,
454 <                              pfArr,
455 <                              puArr,
456 <                              electronArr,
457 <                              &electronReferencePreSelection,
458 <                              &electronReferenceIDMVASelection,
459 <                              &electronReferenceIsoSelection,
460 <                              muonArr,
461 <                              &muonReferencePreSelection,
462 <                              &muonIDPFSelection,
463 <                              &muonReferenceIsoSelection);
452 >
453 >
454 >        // reference
455 >        apply_HZZ4L_reference2_selection(ctrl, info,
456 >                                         vtx,
457 >                                         pfArr,
458 > #ifdef HACKED_RHOS
459 >                                         rho,
460 > #else
461 >                                         puDArr,
462 > #endif
463 >                                         electronArr,
464 >                                         &electronReferencePreSelection,
465 >                                         &electronReferenceIDMVASelection,
466 >                                         &electronReferenceIsoSelection,
467 >                                         muonArr,
468 >                                         &muonReferencePreSelection,
469 >                                         &muonIDPFSelection,
470 >                                         &muonReferenceIsoSelection);
471 >
472 >      /*
473 >        // evolved
474 >        apply_HZZ4L_reference2_selection(ctrl, info,
475 >                                         vtx,
476 >                                         pfArr,
477 >                                         //rho,
478 >                                         puDArr,
479 >                                         electronArr,
480 >                                         &electronReferencePreSelection,
481 >                                         //&electronPreSelection,
482 >                                         &electronReferenceIDMVASelection,
483 >                                         &electronIsoMVASelection,
484 >                                         muonArr,
485 >                                         &muonReferencePreSelection,
486 >                                         //&muonPreSelection,
487 >                                         &muonIDPFSelection,
488 >                                         &muonIsoMVASelection);
489 >      */
490 >
491        if( ctrl.debug ) cout << endl;
492  
493 <      cout << "bits: " << ret4l.status.selectionBits << endl;
493 >
494 >      int Z1type=0, Z2type=0;
495 >      if( ret4l.status.selectionBits.to_ulong() >= PASS_ZCANDIDATE ) {
496 >        if( abs(ret4l.Z1leptons[0].type) == 11  ) Z1type = 11;
497 >        if( abs(ret4l.Z1leptons[0].type) == 13  ) Z1type = 13;
498 >      }  
499 >      if( ret4l.status.selectionBits.to_ulong() >= PASS_ZZCANDIDATE ) {
500 >        if( abs(ret4l.Z2leptons[0].type) == 11  ) Z2type = 11;
501 >        if( abs(ret4l.Z2leptons[0].type) == 13  ) Z2type = 13;
502 >      }  
503 >      
504 > #ifdef SYNC
505 >      cout  << "bits: " << ret4l.status.selectionBits  << "\t"
506 >            << "Z1: " << Z1type << "\t"
507 >            << "Z2: " << Z2type << endl;
508 >      cout << endl;
509 > #endif      
510        
511        if( ret4l.status.pass() ) {
302        
512          fillAngles(ret4l,angles);
513          fillKinematics(ret4l,kinematics);
514          fillEventInfo(info,evtinfo);
515 <        //if(ctrl.mc) fillGenInfo(ginfo,geninfo);
515 >        if( ctrl.mc) {
516 >        // fillGenInfo(ginfo,geninfo);
517 >          setEffiencyWeights(ret4l, weights);
518 >           if(ctrl.debug)
519 >             cout << "w: " << weights.w << "\t"
520 >                  << "won: " << weights.won << "\t"
521 >                  << "woff: " << weights.woff << endl;
522 >        }
523          
524          /*
525          // only for Higgs < 140
# Line 324 | Line 540 | int main(int argc, char** argv)
540          pass++;
541          //      if( pass > 3 ) break;
542  
543 <      }
543 >      } else if( ret4l.status.selectionBits.test(PASS_GOODZ1) ) { // save for fakes ...
544 >        //      if(ctrl.debug) {
545 >          cout << "failingLeptons : " << failingLeptons.size() << endl;
546 >          for( int f=0; f<failingLeptons.size(); f++ ) {
547 >            SimpleLepton  l = failingLeptons[f];
548 >            cout << "f: " << f << "\t"
549 >                 << "type: " << l.type << "\t"
550 >                 << "pT: " << l.vec.Pt()  << "\t"
551 >                 << "eta: " << l.vec.Eta()
552 >                 << endl;
553 >            //    }
554 >        }
555 >        foTree.Fill();
556 >      }
557      }  
558  
559 +  
560 +  foTree.getFile()->cd();
561 +  foTree.getTree()->Write();
562    nt.WriteClose();
563 +
564 +  cout << endl;
565 +  cout << endl;
566 +  for( int i=0; i<cutvec.size(); i++ ) {
567 +    cout << "cut: " << i << "\t"
568 +         << "pass: " << cutvec[i];
569 +
570 +    if( i>PASS_TRIGGER&&i<=PASS_GOODZ1 )
571 +      cout << "\t2e: " << zcutvec[0][i]
572 +           << "\t2m: " << zcutvec[1][i];
573 +
574 +    if( i>PASS_ZCANDIDATE )
575 +      cout << "\t4e: " << zzcutvec[0][i]
576 +           << "\t4m: " << zzcutvec[1][i]
577 +           << "\t2e2m: " << zzcutvec[2][i];
578 +
579 +    cout << "\t" << cutstrs[i] << endl;
580 +
581 +    cout << endl;
582 +  }
583 +
584   }
585  
586   //----------------------------------------------------------------------------
# Line 356 | Line 609 | bool setPV(ControlFlags ctrl,
609      if( ctrl.debug ) cout << "vertex :: " << i << "\tntrks: " << pv->NTracks() << endl;
610      
611      // Select best PV for corrected d0; if no PV passing cuts, the first PV in the collection will be used
612 <    //  if(!pv->IsValid()) continue;
612 >    if(!pv->IsValid())                                continue;
613      if(pv->NTracksFit()       < fMinNTracksFit)       continue;
614      if(pv->Ndof()                 < fMinNdof)         continue;
615      if(fabs(pv->Z()) > fMaxAbsZ)                      continue;
# Line 377 | Line 630 | bool setPV(ControlFlags ctrl,
630        if( ctrl.debug) cout << "new PV set, pt : " << best_sumpt << endl;
631      }
632    }
633 <  
633 >  // sync
634    if(!bestPV) bestPV = vtxArr->At(0);
635 +  //if(!bestPV) return false;
636    vtx.SetPosition(bestPV->X(),bestPV->Y(),bestPV->Z());
637    vtx.SetErrors(bestPV->XErr(),bestPV->YErr(),bestPV->ZErr());
638    return true;
639   };
640 +
641 +
642 +
643 + //----------------------------------------------------------------------------
644 + void setEffiencyWeights(EventData & evtdat, WeightStruct & weights )
645 + //----------------------------------------------------------------------------
646 + {
647 +  vector<SimpleLepton> lepvec = evtdat.Z1leptons;
648 +  lepvec.insert(lepvec.end(), evtdat.Z2leptons.begin(), evtdat.Z2leptons.end());
649 +  double w_offline=-1, werr_offline=0;
650 +  double w_online=-1, werr_online=0;
651 +  
652 +  vector< pair <double,double> > wlegs; // pair here is eff & err
653 +  vector< pair <float,float> > mvec;  // pair here is eta & pt
654 +
655 +  //      vector< pair <float,float> > evec;  // pair here is eta & pt
656 +  // now deal with medium vs loose
657 +  vector< pair< bool, pair <float,float> > > evec;  // pair here is eta & pt
658 +  
659 +  for( int k=0; k<lepvec.size(); k++ ) {
660 +    if( abs(lepvec[k].type) == 13 ) {
661 +      mvec.push_back( std::pair<float,float> (fabs(lepvec[k].vec.Eta()), lepvec[k].vec.Pt()) );
662 +      wlegs.push_back( muonPerLegOfflineEfficiencyWeight( fabs(lepvec[k].vec.Eta()),
663 +                                                          lepvec[k].vec.Pt() ) );
664 +    } else {
665 +      
666 +      // now deal with medium vs loose
667 +      //              evec.push_back( std::pair<float,float> (fabs(lepvec[k].vec.Eta()), lepvec[k].vec.Pt()) );
668 +      
669 +      std::pair<float,float> tmppair(fabs(lepvec[k].vec.Eta()), lepvec[k].vec.Pt());
670 +      evec.push_back( std::pair<bool, std::pair<float,float> > (lepvec[k].isTight, tmppair) );
671 +      
672 +      //              wlegs.push_back( elePerLegOfflineEfficiencyWeight(  fabs(lepvec[k].vec.Eta()),
673 +      //                                                                 lepvec[k].vec.Pt() ) );
674 +      
675 +      wlegs.push_back( elePerLegOfflineEfficiencyWeight(  fabs(lepvec[k].vec.Eta()),
676 +                                                          lepvec[k].vec.Pt(),
677 +                                                          lepvec[k].isTight ) );
678 +      
679 +    }
680 +  }
681 +  
682 +  pair<double,double> offpair = getOfflineEfficiencyWeight( wlegs );
683 +  weights.woff    = offpair.first;
684 +  weights.werroff = offpair.second;
685 +  
686 +  pair<double,double> onpair  = getOnlineEfficiencyWeight( mvec, evec );
687 +  weights.won    = onpair.first;
688 +  weights.werron = onpair.second;
689 + }
690 +
691 +
692 + //----------------------------------------------------------------------------
693 + void initRunLumiRangeMap()
694 + //----------------------------------------------------------------------------
695 + {
696 +  /*
697 +  rlrm.AddJSONFile(std::string("./data/Cert_136033-149442_7TeV_Apr21ReReco_Collisions10_JSON.txt"));
698 +  //  rlrm.AddJSONFile(std::string("./data/Cert_160404-173244_7TeV_PromptReco_Collisions11_JSON_v2.txt"));
699 +  rlrm.AddJSONFile(std::string("./data/Cert_160404-178078_7TeV_PromptReco_Collisions11_JSON.txt"));
700 +  rlrm.AddJSONFile(std::string("./data/Cert_160404-163869_7TeV_May10ReReco_Collisions11_JSON_v3.txt"));  
701 +  rlrm.AddJSONFile(std::string("./data/Cert_170249-172619_7TeV_ReReco5Aug_Collisions11_JSON.txt"));  
702 +  // r11b
703 +  rlrm.AddJSONFile(std::string("./data/Cert_160404-180252_7TeV_PromptReco_Collisions11_JSON.txt"));  
704 +  */
705 + };
706 +
707 +
708 + //----------------------------------------------------------------------------
709 + void initPUWeights()
710 + //----------------------------------------------------------------------------
711 + {
712 +  TFile * puf = new TFile("data/PileupReweighting.Summer11DYmm_To_Full2011.root");
713 +  hpu = (TH1D*)(puf->Get("puWeights"));
714 + }
715 +
716 + //----------------------------------------------------------------------------
717 + double getPUWeight(unsigned npu)
718 + //----------------------------------------------------------------------------
719 + {
720 +  return hpu->GetBinContent(hpu->FindBin(npu));
721 + }
722 +
723 + //----------------------------------------------------------------------------
724 + void initEvtRhoMap( map<unsigned, float> & evtrhoMap )
725 + //----------------------------------------------------------------------------
726 + {
727 +  unsigned evt;
728 +  float rho;
729 +
730 +  cout << "initialzing EvtRhoMap ";
731 +  //FILE * f = fopen("evtrho.dat", "r");
732 +  //  FILE * f = fopen("allrho.cali.uniq.dat", "r");
733 +  FILE * f = fopen("allrhoAA.cali.uniq.dat", "r");
734 +  int lcount=0;
735 +  while( fscanf( f, "%u:%f", &evt, &rho ) ) {
736 +    if( feof(f) ) break;
737 +    evtrhoMap[evt] = rho;
738 +    lcount++;
739 +    if( !(lcount%1000) ) cout << "."; flush(cout);
740 +  }
741 +  cout << " done" << endl;
742 + }
743 +
744 + //----------------------------------------------------------------------------
745 + unsigned makePFnoPUArray(mithep::Array<PFCandidate> * fPFCandidates,
746 +                     vector<bool> &pfNoPileUpflag,
747 +                     mithep::Array<Vertex>      * vtxArr )
748 + //----------------------------------------------------------------------------
749 + {
750 +  for(UInt_t i = 0; i < fPFCandidates->GetEntries(); i++) {
751 +    const PFCandidate *pf = fPFCandidates->At(i);
752 +    assert(pf);
753 +
754 +    if(pf->PFType() == PFCandidate::eHadron) {
755 +      if(pf->HasTrackerTrk() &&
756 +         vtxArr->At(0)->HasTrack(pf->TrackerTrk()) &&
757 +         vtxArr->At(0)->TrackWeight(pf->TrackerTrk()) > 0) {
758 +
759 +        pfNoPileUpflag.push_back(1);
760 +
761 +      } else {
762 +
763 +        Bool_t vertexFound = kFALSE;
764 +        const Vertex *closestVtx = 0;
765 +        Double_t dzmin = 10000;
766 +        
767 +        // loop over vertices
768 +        for(UInt_t j = 0; j < vtxArr->GetEntries(); j++) {
769 +          const Vertex *vtx = vtxArr->At(j);
770 +          assert(vtx);
771 +          
772 +          if(pf->HasTrackerTrk() &&
773 +             vtx->HasTrack(pf->TrackerTrk()) &&
774 +             vtx->TrackWeight(pf->TrackerTrk()) > 0) {
775 +            vertexFound = kTRUE;
776 +            closestVtx = vtx;
777 +            break;
778 +          }
779 +          Double_t dz = fabs(pf->SourceVertex().Z() - vtx->Z());
780 +          if(dz < dzmin) {
781 +            closestVtx = vtx;
782 +            dzmin = dz;
783 +          }
784 +        }
785 +
786 +        //      if(fCheckClosestZVertex) {
787 +        if(1) {
788 +          // Fallback: if track is not associated with any vertex,
789 +          // associate it with the vertex closest in z
790 +          if(vertexFound || closestVtx != vtxArr->At(0)) {
791 +            //      pfPileUp->Add(pf);
792 +            pfNoPileUpflag.push_back(0);
793 +          } else {
794 +            pfNoPileUpflag.push_back(1);
795 +          }
796 +        } else {
797 +          if(vertexFound && closestVtx != vtxArr->At(0)) {
798 +            //      pfPileUp->Add(pf);
799 +            pfNoPileUpflag.push_back(0);
800 +          } else {
801 +            //      PFCandidate * pfNoPileUp->AddNew(); // Ridiculous but that's how it is
802 +            pfNoPileUpflag.push_back(1);
803 +          }
804 +        }
805 +      } //hadron & trk stuff
806 +    } else { // hadron
807 +      //      PFCandidate * ptr = pfNoPileUp->AddNew();
808 +      pfNoPileUpflag.push_back(1);
809 +    }
810 +  } // Loop over PF candidates
811 +
812 +  return pfNoPileUpflag.size();
813 + }
814 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines