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.17 by khahn, Thu May 10 00:14:35 2012 UTC vs.
Revision 1.32 by anlevin, Sat Jun 2 12:17:29 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 48 | Line 50 | using namespace std;
50   #include "MuonSelection.h"
51   #include "ElectronSelection.h"
52   #include "IsolationSelection.h"
51
52 //#include "Selection.h"
53   #include "ReferenceSelection.h"
54  
55   #include "TriggerUtils.h"
# Line 57 | Line 57 | using namespace std;
57   #include "Angles.h"
58   #include "KinematicsStruct.h"
59   #include "InfoStruct.h"
60 < //#include "GenInfoStruct.h"
60 > #include "GenInfoStruct.h"
61   #include "WeightStruct.h"
62   //#include "GlobalDataAndFuncs.h"
63   #include "RunLumiRangeMap.h"
# Line 83 | Line 83 | TH1D * hpu;
83   RunLumiRangeMap rlrm;
84   vector<SimpleLepton> failingLeptons ; // for fake estimation
85   vector<SimpleLepton> passingLeptons;      // for fake estimation
86 + vector<unsigned> cutvec;
87 + vector<vector<unsigned> > zcutvec;
88 + vector<vector<unsigned> > zzcutvec;
89 + map<unsigned,float>       evtrhoMap;
90 + vector<string> cutstrs;
91 + bool passes_HLT_MC;
92 + vector<bool>   PFnoPUflag;;
93  
94   //
95   // prototypes
96   //----------------------------------------------------------------------------
90 bool setPV(ControlFlags,const mithep::Array<mithep::Vertex>*, mithep::Vertex& );
97   void initPUWeights();
98   double getPUWeight(unsigned npu);
99 + void setEra(string, ControlFlags&);
100   void setEffiencyWeights(EventData&, WeightStruct& );
101   void initRunLumiRangeMap();
102 + void initEvtRhoMap(map<unsigned,float> &);
103 + unsigned makePFnoPUArray(mithep::Array<PFCandidate> * fPFCandidates,
104 +                         vector<bool> &pfNoPileUpFlag,
105 +                         const mithep::Array<mithep::Vertex>     * vtxArr );
106   //----------------------------------------------------------------------------
107  
108  
# Line 101 | Line 112 | void initRunLumiRangeMap();
112   int main(int argc, char** argv)
113   //----------------------------------------------------------------------------
114   {
115 +  cutstrs.push_back(string("skim0"));              //0
116 +  cutstrs.push_back(string("skim1"));              //1
117 +  cutstrs.push_back(string("skim2"));              //1
118 +  cutstrs.push_back(string("trigger"));            //2
119 +  // -------------------------------------------------
120 +  cutstrs.push_back(string("Z candidate"));        //3
121 +  cutstrs.push_back(string("good Z1"));            //4
122 +  // -------------------------------------------------
123 +  cutstrs.push_back(string("4l"));                 //5  
124 +  cutstrs.push_back(string("ZZ candidate"));       //6
125 +  cutstrs.push_back(string("good Z2"));            //7
126 +  cutstrs.push_back(string("ZZ 20/10"));           //8
127 +  cutstrs.push_back(string("resonance"));          //9
128 +  cutstrs.push_back(string("m4l>70"));             //10
129 +  cutstrs.push_back(string("m4l>100, mZ2 > 12"));                  //11
130 +
131 +
132 +
133 +
134    string cmsswpath(CMSSW_BASE);
135    cmsswpath.append("/src");
136    std::bitset<1024> triggerBits;
137    vector<vector<string> > inputFiles;
138    inputFiles.push_back(vector<string>());
139    map<string,unsigned> entrymap; // number of unskimmed entries in each file
140 +  for( int i=0; i<cutstrs.size(); i++ ) cutvec.push_back(0);
141 +  for( int i=0; i<2; i++ )  {
142 +    zcutvec.push_back(vector<unsigned>());
143 +    for( int j=0; j<cutstrs.size(); j++ ) zcutvec[i].push_back(0);
144 +  }
145 +  for( int i=0; i<3; i++ )  {
146 +    zzcutvec.push_back(vector<unsigned>());
147 +    for( int j=0; j<cutstrs.size(); j++ ) zzcutvec[i].push_back(0);
148 +  }
149 +
150  
151    //
152    // args
# Line 172 | Line 212 | int main(int argc, char** argv)
212    KinematicsStruct kinematics;
213    InfoStruct evtinfo;
214    WeightStruct weights;
215 <  //  GenInfoStruct geninfo;
215 >  GenInfoStruct geninfo;
216  
217    AngleTuple nt( (const char*)ofname, (const char*)"zznt");
218    nt.makeAngleBranch(angles);
# Line 183 | Line 223 | int main(int argc, char** argv)
223    foTree.makeFailedLeptonBranch(failingLeptons);
224    foTree.makeZLeptonBranch(passingLeptons);
225  
226 <  TH1F * h_w_hpt;
226 >  TH1F * h_wf11_hpt;
227    if(ctrl.mc) {
228      nt.makeWeightBranch(weights);
229 <    //    nt.makeGenInfoBranch(geninfo);
229 >    nt.makeGenInfoBranch(geninfo);
230      initEfficiencyWeights();
231      initPUWeights();
232 <    /*
232 >
233      // Higgs only, pt reweighting
234      if( ctrl.mH <= 140 ) {
235        char wptname[256];
# Line 197 | Line 237 | int main(int argc, char** argv)
237        TFile * f_hpt = new TFile(wptname);
238        f_hpt->Print();
239        sprintf(wptname, "weight_hqt_fehipro_fit_%i", ctrl.mH);
240 <      h_w_hpt  = (TH1F*)(f_hpt->FindObjectAny(wptname));
201 <      h_w_hpt->Print();
240 >      h_wf11_hpt  = (TH1F*)(f_hpt->FindObjectAny(wptname));
241      }
242 <    */
242 >
243    } else {
244      initRunLumiRangeMap();
245    }
# Line 210 | Line 249 | int main(int argc, char** argv)
249    initElectronIDMVA();
250    initElectronIsoMVA();
251    initTrigger();
252 <  
252 >
253 >  // hack
254 >  initEvtRhoMap(evtrhoMap);
255  
256    
257    //
# Line 221 | Line 262 | int main(int argc, char** argv)
262    string currentFile("");
263  
264    mithep::EventHeader *info    = new mithep::EventHeader();
224  //  mithep::TGenInfo    *ginfo  = new mithep::TGenInfo();
265    mithep::Array<mithep::Electron>             *electronArr   = new mithep::Array<mithep::Electron>();
266    mithep::Array<mithep::Muon>                 *muonArr       = new mithep::Array<mithep::Muon>();
267    mithep::Array<mithep::Vertex>               *vtxArr        = new mithep::Array<mithep::Vertex>();
# Line 229 | Line 269 | int main(int argc, char** argv)
269    mithep::Array<mithep::PileupInfo>           *puArr         = new mithep::Array<mithep::PileupInfo>();
270    mithep::Array<mithep::PileupEnergyDensity>  *puDArr        = new mithep::Array<mithep::PileupEnergyDensity>();
271    mithep::Array<mithep::Track>                *trkArr        = new mithep::Array<mithep::Track>();
272 +  mithep::Array<mithep::MCParticle>           *mcArr         = new mithep::Array<mithep::MCParticle>();
273 +  mithep::MCEventInfo                         *mcEvtInfo     = new mithep::MCEventInfo();
274    mithep::TriggerMask                         *trigMask      = new mithep::TriggerMask();
275    mithep::TriggerTable                        *hltTable      = new mithep::TriggerTable();
276    vector<string>                              *hltTableStrings  = new vector<string>();
# Line 241 | Line 283 | int main(int argc, char** argv)
283    TString fPileupInfoName(Names::gkPileupInfoBrn);
284    TString fPileupEnergyDensityName(Names::gkPileupEnergyDensityBrn);
285    TString fTrackName(Names::gkTrackBrn);
286 +  TString fMCParticleName(Names::gkMCPartBrn);
287 +  TString fMCEvtInfoName(Names::gkMCEvtInfoBrn);
288    TString fTriggerMaskName(Names::gkHltBitBrn);
289    TString fTriggerTableName(Names::gkHltTableBrn);
290    
# Line 249 | Line 293 | int main(int argc, char** argv)
293    chain->SetBranchAddress(fMuonName,        &muonArr);
294    chain->SetBranchAddress(fPrimVtxName,     &vtxArr);
295    chain->SetBranchAddress(fPFCandidateName, &pfArr);
296 <  chain->SetBranchAddress(fPileupInfoName,  &puArr);
296 >  if( ctrl.mc ) {
297 >    chain->SetBranchAddress(fPileupInfoName,  &puArr);
298 >    chain->SetBranchAddress(fMCParticleName,  &mcArr);
299 >    chain->SetBranchAddress(fMCEvtInfoName,  &mcEvtInfo);
300 >  }
301    chain->SetBranchAddress(fPileupEnergyDensityName, &puDArr);
302    chain->SetBranchAddress(fTrackName, &trkArr);
303    chain->SetBranchAddress(fTriggerMaskName, &trigMask);
# Line 282 | Line 330 | int main(int argc, char** argv)
330      {
331        chain->GetEntry(ientry);
332        if(!(ientry%1000)) cerr << "entry: " << ientry << endl;
285      if( ientry > 100) break;
286      setPV( ctrl, vtxArr, vtx);
333  
334 + #ifdef HACKED_RHOS
335 +      float rho = evtrhoMap[info->EvtNum()];
336 + #endif
337 +      string fname = string(chain->GetFile()->GetEndpointUrl()->GetFile());
338 +      setEra( fname, ctrl );
339 +
340 +
341 +      //
342 +      // pfNoPU
343 +      //
344 +      //mithep::Array<PFCandidate> pfNoPileUp;
345 +      PFnoPUflag.clear();
346 +      int pfnopu_size = makePFnoPUArray( pfArr, PFnoPUflag, vtxArr );
347 +      assert(pfnopu_size == pfArr->GetEntries());
348  
349        //
350        // data/MC
351        //
352        if(ctrl.mc) {
353          //
354 +        // gen info
355 +        //
356 +        if( ctrl.fillGen )
357 +          fillGenInfo( mcArr, mcEvtInfo, geninfo, ESampleType::kHZZ, ctrl);
358 +
359 +        //
360          // xsec & PU weights
361          //
362          weights.w = getWeight(xstab,entrymap,chain)/ctrl.totalMC;
363 +        cout << "xsec weight: " << weights.w << endl;
364          int npu = -1;
365          for(int i=0;i<puArr->GetEntries();i++) {
366            if(puArr->At(i)->GetBunchCrossing() == 0)
# Line 302 | Line 369 | int main(int argc, char** argv)
369          assert(npu>=0);
370          evtinfo.npu;
371          weights.npuw = getPUWeight(evtinfo.npu);
372 <        //      cout << "weight: " << weights.w << endl;
372 >        
373 >        //
374 >        // pt reweighting for Higgs < 140, F11
375 >        //
376 >        if( ctrl.fillGen ) {
377 >          if( (fname.find("f11-h115zz4l") != string::npos) ||
378 >              (fname.find("f11-h120zz4l") != string::npos) ||
379 >              (fname.find("f11-h130zz4l") != string::npos)  ) {
380 >            weights.w *= h_wf11_hpt->GetBinContent(h_wf11_hpt->FindBin(geninfo.pt_zz));
381 >          }
382 >        }
383 >
384 >        //
385 >        // trigger
386 >        //
387 >        if( string(chain->GetFile()->GetEndpointUrl()->GetFile()) != currentFile ) {
388 >          currentFile = string(chain->GetFile()->GetEndpointUrl()->GetFile());
389 >          hltchain->SetBranchAddress(fTriggerTableName, &hltTableStrings);
390 >          hltchain->GetEntry(0);
391 >          hltTable->Clear();
392 >          fillTriggerNames(hltTable, hltTableStrings );
393 >        }
394 >        if( ctrl.debug ) cout << "file is : " << currentFile  << endl;
395 >        fillTriggerBits( hltTable, trigMask, triggerBits );
396 >        passes_HLT_MC = true; // passed to apply as extern global, just for sync
397 >        if( !passHLTMC(triggerBits, info->RunNum(), info->EvtNum(), k2012_MC ) ) {
398 >          passes_HLT_MC = false;
399 >        }
400        } else {
401          //
402          // JSON
403          //
404 +        /*
405          RunLumiRangeMap::RunLumiPairType rl(info->RunNum(), info->LumiSec());      
406          if( !(rlrm.HasRunLumi(rl)) )  {
407            if( ctrl.debug ) cout << "\tfails JSON" << endl;
408            continue;
409          }
410 +        */
411          //
412          // trigger
413          //
# Line 320 | Line 416 | int main(int argc, char** argv)
416            hltchain->SetBranchAddress(fTriggerTableName, &hltTableStrings);
417            hltchain->GetEntry(0);
418            hltTable->Clear();
419 <          fillTriggerBits(hltTable, hltTableStrings );
419 >          fillTriggerNames(hltTable, hltTableStrings );
420          }
421          if( ctrl.debug ) cout << "file is : " << currentFile  << endl;
422 +        /*
423          fillTriggerBits( hltTable, trigMask, triggerBits );
424          if( !passHLT(triggerBits, info->RunNum(), info->EvtNum() ) ) {
425            if( ctrl.debug ) cout << "\tfails trigger ... " << endl;
426            continue;
427          }
428 +        */
429        }
430  
431        //
# Line 336 | Line 434 | int main(int argc, char** argv)
434        failingLeptons.clear();
435        passingLeptons.clear();
436        EventData ret4l =
437 +
438 +
439 +        // reference
440          apply_HZZ4L_reference_selection(ctrl, info,
441 <                              vtx,
442 <                              pfArr,
443 <                              puDArr,
444 <                              electronArr,
445 <                              &electronReferencePreSelection,
446 <                              &electronReferenceIDMVASelection,
447 <                              &electronReferenceIsoSelection,
448 <                              muonArr,
449 <                              &muonReferencePreSelection,
450 <                              &muonIDPFSelection,
451 <                              &muonReferenceIsoSelection);
452 <        /*
453 <        apply_HZZ4L_reference_selection(ctrl, info,
454 <                              vtx,
455 <                              pfArr,
456 <                              puArr,
457 <                              electronArr,
458 <                              &electronPreSelection,
459 <                              &electronIDMVASelection,
460 <                              &electronIsoMVASelection,
461 <                              muonArr,
462 <                              &muonPreSelection,
463 <                              &muonIDPFSelection,
464 <                              &muonIsoMVASelection);
465 <        */
441 >                                         vtxArr,
442 >                                         pfArr,
443 > #ifdef HACKED_RHOS
444 >                                         rho,
445 > #else
446 >                                         puDArr,
447 > #endif
448 >                                         electronArr,
449 >                                         &electronReferencePreSelection,
450 >                                         &electronReferenceIDMVASelectionV1,
451 >                                         &electronReferenceIsoSelection,
452 >                                         muonArr,
453 >                                         &muonReferencePreSelection,
454 >                                         &muonIDPFSelection,
455 >                                         &muonReferenceIsoSelection);
456 >
457 >      /*
458 >        // evolved
459 >        apply_HZZ4L_reference2_selection(ctrl, info,
460 >                                         vtx,
461 >                                         pfArr,
462 >                                         //rho,
463 >                                         puDArr,
464 >                                         electronArr,
465 >                                         &electronReferencePreSelection,
466 >                                         //&electronPreSelection,
467 >                                         &electronReferenceIDMVASelection,
468 >                                         &electronIsoMVASelection,
469 >                                         muonArr,
470 >                                         &muonReferencePreSelection,
471 >                                         //&muonPreSelection,
472 >                                         &muonIDPFSelection,
473 >                                         &muonIsoMVASelection);
474 >      */
475  
476        if( ctrl.debug ) cout << endl;
477  
478 <      //      cout << "bits: " << ret4l.status.selectionBits << endl;
478 >
479 >      int Z1type=0, Z2type=0;
480 >      if( ret4l.status.selectionBits.to_ulong() >= PASS_ZCANDIDATE ) {
481 >        if( abs(ret4l.Z1leptons[0].type) == 11  ) Z1type = 11;
482 >        if( abs(ret4l.Z1leptons[0].type) == 13  ) Z1type = 13;
483 >      }  
484 >      if( ret4l.status.selectionBits.to_ulong() >= PASS_ZZCANDIDATE ) {
485 >        if( abs(ret4l.Z2leptons[0].type) == 11  ) Z2type = 11;
486 >        if( abs(ret4l.Z2leptons[0].type) == 13  ) Z2type = 13;
487 >      }  
488 >      
489 > #ifdef SYNC
490 >      cout  << "bits: " << ret4l.status.selectionBits  << "\t"
491 >            << "Z1: " << Z1type << "\t"
492 >            << "Z2: " << Z2type << endl;
493 >      cout << endl;
494 > #endif      
495        
496        if( ret4l.status.pass() ) {
497          fillAngles(ret4l,angles);
498          fillKinematics(ret4l,kinematics);
499 +        fillMassErrors(ret4l,muonArr,electronArr,kinematics);
500          fillEventInfo(info,evtinfo);
501          if( ctrl.mc) {
375        // fillGenInfo(ginfo,geninfo);
502            setEffiencyWeights(ret4l, weights);
503             if(ctrl.debug)
504               cout << "w: " << weights.w << "\t"
# Line 380 | Line 506 | int main(int argc, char** argv)
506                    << "woff: " << weights.woff << endl;
507          }
508          
509 <        /*
384 <        // only for Higgs < 140
385 <        geninfo.weight *= h_w_hpt->GetBinContent(h_w_hpt->FindBin(geninfo.pt_zz));
386 <        angles.bdt = reader->EvaluateMVA("BDTG");
387 <        */
509 >
510          nt.Fill();
511          
512          cerr  << "PASS:: "
# Line 399 | Line 521 | int main(int argc, char** argv)
521          pass++;
522          //      if( pass > 3 ) break;
523  
524 <      } else if( ret4l.status.selectionBits.test(PASS_ZCANDIDATE) ) { // save for fakes ...
525 <        cout << "failingLeptons : " << failingLeptons.size() << endl;
526 <        for( int f=0; f<failingLeptons.size(); f++ ) {
527 <          SimpleLepton  l = failingLeptons[f];
528 <          cout << "f: " << f << "\t"
529 <               << "type: " << l.type << "\t"
530 <               << "pT: " << l.vec.Pt()  << "\t"
531 <               << "eta: " << l.vec.Eta()
532 <               << endl;
533 <        }
534 <        /*
413 <        cout << "passingLeptons : " << passingLeptons.GetSize() << endl;
414 <        for( int f=0; f<passingLeptons.GetSize(); f++ ) {
415 <          cout << "f: " << f << "\t"
416 <               << "type: " << passingLeptons.At(f).type << "\t"
417 <               << "pT: " << passingLeptons.At(f).vec.Pt()
418 <               << endl;
524 >      } else if( ret4l.status.selectionBits.test(PASS_GOODZ1) ) { // save for fakes ...
525 >        //      if(ctrl.debug) {
526 >          cout << "failingLeptons : " << failingLeptons.size() << endl;
527 >          for( int f=0; f<failingLeptons.size(); f++ ) {
528 >            SimpleLepton  l = failingLeptons[f];
529 >            cout << "f: " << f << "\t"
530 >                 << "type: " << l.type << "\t"
531 >                 << "pT: " << l.vec.Pt()  << "\t"
532 >                 << "eta: " << l.vec.Eta()
533 >                 << endl;
534 >            //    }
535          }
420        */
421        cout << endl;
536          foTree.Fill();
537        }
538      }  
# Line 427 | Line 541 | int main(int argc, char** argv)
541    foTree.getFile()->cd();
542    foTree.getTree()->Write();
543    nt.WriteClose();
430 }
544  
545 < //----------------------------------------------------------------------------
546 < //
547 < // Get primary vertices
548 < // Assumes primary vertices are ordered by sum-pT^2 (as should be in CMSSW)
549 < // NOTE: if no PV is found from fitting tracks, the beamspot is used
550 < //
551 < //----------------------------------------------------------------------------
552 < bool setPV(ControlFlags ctrl,
553 <           const mithep::Array<mithep::Vertex> * vtxArr,
554 <           mithep::Vertex & vtx)
555 < //----------------------------------------------------------------------------
556 < {
557 <  const Vertex *bestPV = 0;
558 <  float best_sumpt=-1;
559 <
560 <  // good PV requirements
561 <  const UInt_t   fMinNTracksFit = 0;
562 <  const Double_t fMinNdof       = 4;
450 <  const Double_t fMaxAbsZ       = 24;
451 <  const Double_t fMaxRho        = 2;
452 <  
453 <  for(int i=0; i<vtxArr->GetEntries(); ++i) {
454 <    const Vertex *pv = (Vertex*)(vtxArr->At(i));
455 <    if( ctrl.debug ) cout << "vertex :: " << i << "\tntrks: " << pv->NTracks() << endl;
456 <    
457 <    // Select best PV for corrected d0; if no PV passing cuts, the first PV in the collection will be used
458 <    //  if(!pv->IsValid()) continue;
459 <    if(pv->NTracksFit()       < fMinNTracksFit)       continue;
460 <    if(pv->Ndof()                 < fMinNdof)         continue;
461 <    if(fabs(pv->Z()) > fMaxAbsZ)                      continue;
462 <    if(pv->Position().Rho()   > fMaxRho)              continue;    
463 <    
464 <    // take the first ...
465 <    bestPV = pv;
466 <    break;
467 <
468 <    // this never reached ...    
469 <    float tmp_sumpt=0;
470 <    for( int t=0; t<pv->NTracks(); t++ )
471 <      tmp_sumpt += pv->Trk(t)->Pt();
472 <    
473 <    if( tmp_sumpt > best_sumpt  ) {
474 <      bestPV = pv;
475 <      best_sumpt = tmp_sumpt;
476 <      if( ctrl.debug) cout << "new PV set, pt : " << best_sumpt << endl;
477 <    }
545 >  cout << endl;
546 >  cout << endl;
547 >  for( int i=0; i<cutvec.size(); i++ ) {
548 >    cout << "cut: " << i << "\t"
549 >         << "pass: " << cutvec[i];
550 >
551 >    if( i>PASS_TRIGGER&&i<=PASS_GOODZ1 )
552 >      cout << "\t2e: " << zcutvec[0][i]
553 >           << "\t2m: " << zcutvec[1][i];
554 >
555 >    if( i>PASS_ZCANDIDATE )
556 >      cout << "\t4e: " << zzcutvec[0][i]
557 >           << "\t4m: " << zzcutvec[1][i]
558 >           << "\t2e2m: " << zzcutvec[2][i];
559 >
560 >    cout << "\t" << cutstrs[i] << endl;
561 >
562 >    cout << endl;
563    }
564 <  
565 <  if(!bestPV) bestPV = vtxArr->At(0);
481 <  vtx.SetPosition(bestPV->X(),bestPV->Y(),bestPV->Z());
482 <  vtx.SetErrors(bestPV->XErr(),bestPV->YErr(),bestPV->ZErr());
483 <  return true;
484 < };
564 >
565 > }
566  
567  
568  
# Line 564 | Line 645 | double getPUWeight(unsigned npu)
645   {
646    return hpu->GetBinContent(hpu->FindBin(npu));
647   }
648 +
649 + //----------------------------------------------------------------------------
650 + void initEvtRhoMap( map<unsigned, float> & evtrhoMap )
651 + //----------------------------------------------------------------------------
652 + {
653 +  unsigned evt;
654 +  float rho;
655 +
656 +  cout << "initialzing EvtRhoMap ";
657 +  //FILE * f = fopen("evtrho.dat", "r");
658 +  //  FILE * f = fopen("allrho.cali.uniq.dat", "r");
659 +  FILE * f = fopen("/data/blue/khahn/CMSSW_4_4_2/src/MitHzz4l/allrhoAA.cali.uniq.dat", "r");
660 +  int lcount=0;
661 +  while( fscanf( f, "%u:%f", &evt, &rho ) ) {
662 +    if( feof(f) ) break;
663 +    evtrhoMap[evt] = rho;
664 +    lcount++;
665 +    if( !(lcount%1000) ) cout << "."; flush(cout);
666 +  }
667 +  cout << " done" << endl;
668 + }
669 +
670 + //----------------------------------------------------------------------------
671 + unsigned makePFnoPUArray(mithep::Array<PFCandidate> * fPFCandidates,
672 +                         vector<bool> &pfNoPileUpflag,
673 +                         const mithep::Array<mithep::Vertex>      * vtxArr )
674 + //----------------------------------------------------------------------------
675 + {
676 +  for(UInt_t i = 0; i < fPFCandidates->GetEntries(); i++) {
677 +    const PFCandidate *pf = fPFCandidates->At(i);
678 +    assert(pf);
679 +
680 +    if(pf->PFType() == PFCandidate::eHadron) {
681 +      if(pf->HasTrackerTrk() &&
682 +         vtxArr->At(0)->HasTrack(pf->TrackerTrk()) &&
683 +         vtxArr->At(0)->TrackWeight(pf->TrackerTrk()) > 0) {
684 +
685 +        pfNoPileUpflag.push_back(1);
686 +
687 +      } else {
688 +
689 +        Bool_t vertexFound = kFALSE;
690 +        const Vertex *closestVtx = 0;
691 +        Double_t dzmin = 10000;
692 +        
693 +        // loop over vertices
694 +        for(UInt_t j = 0; j < vtxArr->GetEntries(); j++) {
695 +          const Vertex *vtx = vtxArr->At(j);
696 +          assert(vtx);
697 +          
698 +          if(pf->HasTrackerTrk() &&
699 +             vtx->HasTrack(pf->TrackerTrk()) &&
700 +             vtx->TrackWeight(pf->TrackerTrk()) > 0) {
701 +            vertexFound = kTRUE;
702 +            closestVtx = vtx;
703 +            break;
704 +          }
705 +          Double_t dz = fabs(pf->SourceVertex().Z() - vtx->Z());
706 +          if(dz < dzmin) {
707 +            closestVtx = vtx;
708 +            dzmin = dz;
709 +          }
710 +        }
711 +
712 +        //      if(fCheckClosestZVertex) {
713 +        if(1) {
714 +          // Fallback: if track is not associated with any vertex,
715 +          // associate it with the vertex closest in z
716 +          if(vertexFound || closestVtx != vtxArr->At(0)) {
717 +            //      pfPileUp->Add(pf);
718 +            pfNoPileUpflag.push_back(0);
719 +          } else {
720 +            pfNoPileUpflag.push_back(1);
721 +          }
722 +        } else {
723 +          if(vertexFound && closestVtx != vtxArr->At(0)) {
724 +            //      pfPileUp->Add(pf);
725 +            pfNoPileUpflag.push_back(0);
726 +          } else {
727 +            //      PFCandidate * pfNoPileUp->AddNew(); // Ridiculous but that's how it is
728 +            pfNoPileUpflag.push_back(1);
729 +          }
730 +        }
731 +      } //hadron & trk stuff
732 +    } else { // hadron
733 +      //      PFCandidate * ptr = pfNoPileUp->AddNew();
734 +      pfNoPileUpflag.push_back(1);
735 +    }
736 +  } // Loop over PF candidates
737 +
738 +  return pfNoPileUpflag.size();
739 + }
740 +
741 + void setEra(string fname, ControlFlags &ctrl)
742 + {
743 +  if( ctrl.mc && (fname.find("f11-") != string::npos)  ) ctrl.era=2011 ;
744 +  if( ctrl.mc && (fname.find("s12-") != string::npos)  ) ctrl.era=2012 ;
745 +  if( !ctrl.mc && (fname.find("r11-") != string::npos)  ) ctrl.era=2011 ;
746 +  if( !ctrl.mc && (fname.find("r12-") != string::npos)  ) ctrl.era=2012 ;
747 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines