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.35 by khahn, Tue Jun 5 19:35:48 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"
64
62   #include "AngleTuple.h"
63   #include "FOTuple.h"
64  
65 + #include "RunLumiRangeMap.h"
66   #include "SampleWeight.h"
67   #include "EfficiencyWeightsInterface.h"
68  
# Line 83 | Line 81 | TH1D * hpu;
81   RunLumiRangeMap rlrm;
82   vector<SimpleLepton> failingLeptons ; // for fake estimation
83   vector<SimpleLepton> passingLeptons;      // for fake estimation
84 + vector<unsigned> cutvec;
85 + vector<vector<unsigned> > zcutvec;
86 + vector<vector<unsigned> > zzcutvec;
87 + map<unsigned,float>       evtrhoMap;
88 + vector<string> cutstrs;
89 + bool passes_HLT_MC;
90 + vector<bool>   PFnoPUflag;;
91  
92   //
93   // prototypes
94   //----------------------------------------------------------------------------
90 bool setPV(ControlFlags,const mithep::Array<mithep::Vertex>*, mithep::Vertex& );
95   void initPUWeights();
96   double getPUWeight(unsigned npu);
97 + void setEra(string, ControlFlags&);
98   void setEffiencyWeights(EventData&, WeightStruct& );
99   void initRunLumiRangeMap();
100 + void initEvtRhoMap(map<unsigned,float> &);
101 + unsigned makePFnoPUArray(mithep::Array<PFCandidate> * fPFCandidates,
102 +                         vector<bool> &pfNoPileUpFlag,
103 +                         const mithep::Array<mithep::Vertex>     * vtxArr );
104   //----------------------------------------------------------------------------
105  
106  
# Line 101 | Line 110 | void initRunLumiRangeMap();
110   int main(int argc, char** argv)
111   //----------------------------------------------------------------------------
112   {
113 +  cutstrs.push_back(string("skim0"));              //0
114 +  cutstrs.push_back(string("skim1"));              //1
115 +  cutstrs.push_back(string("skim2"));              //1
116 +  cutstrs.push_back(string("trigger"));            //2
117 +  // -------------------------------------------------
118 +  cutstrs.push_back(string("Z candidate"));        //3
119 +  cutstrs.push_back(string("good Z1"));            //4
120 +  // -------------------------------------------------
121 +  cutstrs.push_back(string("4l"));                 //5  
122 +  cutstrs.push_back(string("ZZ candidate"));       //6
123 +  cutstrs.push_back(string("good Z2"));            //7
124 +  cutstrs.push_back(string("ZZ 20/10"));           //8
125 +  cutstrs.push_back(string("resonance"));          //9
126 +  cutstrs.push_back(string("m4l>70"));             //10
127 +  cutstrs.push_back(string("m4l>100, mZ2 > 12"));                  //11
128 +
129 +
130 +
131 +
132    string cmsswpath(CMSSW_BASE);
133    cmsswpath.append("/src");
134    std::bitset<1024> triggerBits;
135    vector<vector<string> > inputFiles;
136    inputFiles.push_back(vector<string>());
137    map<string,unsigned> entrymap; // number of unskimmed entries in each file
138 +  for( int i=0; i<cutstrs.size(); i++ ) cutvec.push_back(0);
139 +  for( int i=0; i<2; i++ )  {
140 +    zcutvec.push_back(vector<unsigned>());
141 +    for( int j=0; j<cutstrs.size(); j++ ) zcutvec[i].push_back(0);
142 +  }
143 +  for( int i=0; i<3; i++ )  {
144 +    zzcutvec.push_back(vector<unsigned>());
145 +    for( int j=0; j<cutstrs.size(); j++ ) zzcutvec[i].push_back(0);
146 +  }
147 +
148  
149    //
150    // args
# Line 172 | Line 210 | int main(int argc, char** argv)
210    KinematicsStruct kinematics;
211    InfoStruct evtinfo;
212    WeightStruct weights;
213 <  //  GenInfoStruct geninfo;
213 >  GenInfoStruct geninfo;
214  
215    AngleTuple nt( (const char*)ofname, (const char*)"zznt");
216    nt.makeAngleBranch(angles);
217    nt.makeKinematicsBranch(kinematics);
218    nt.makeInfoBranch(evtinfo);
219  
220 +  
221    FOTuple foTree( nt.getFile(), (const char*)"FOtree");
222    foTree.makeFailedLeptonBranch(failingLeptons);
223 <  foTree.makeZLeptonBranch(passingLeptons);
223 >  foTree.makePassedLeptonBranch(passingLeptons);
224  
225 <  TH1F * h_w_hpt;
225 >  TH1F * h_wf11_hpt;
226    if(ctrl.mc) {
227      nt.makeWeightBranch(weights);
228 <    //    nt.makeGenInfoBranch(geninfo);
228 >    if(ctrl.fillGen ) nt.makeGenInfoBranch(geninfo);
229      initEfficiencyWeights();
230      initPUWeights();
231 <    /*
231 >
232      // Higgs only, pt reweighting
233      if( ctrl.mH <= 140 ) {
234        char wptname[256];
# Line 197 | Line 236 | int main(int argc, char** argv)
236        TFile * f_hpt = new TFile(wptname);
237        f_hpt->Print();
238        sprintf(wptname, "weight_hqt_fehipro_fit_%i", ctrl.mH);
239 <      h_w_hpt  = (TH1F*)(f_hpt->FindObjectAny(wptname));
201 <      h_w_hpt->Print();
239 >      h_wf11_hpt  = (TH1F*)(f_hpt->FindObjectAny(wptname));
240      }
241 <    */
241 >
242    } else {
243      initRunLumiRangeMap();
244    }
245  
246    //  initMuonIDMVA();
247 <  initMuonIsoMVA();
210 <  initElectronIDMVA();
211 <  initElectronIsoMVA();
247 >  initElectronIDMVAV1();
248    initTrigger();
249 <  
249 >
250 >  // hack
251 >  initEvtRhoMap(evtrhoMap);
252  
253    
254    //
# Line 221 | Line 259 | int main(int argc, char** argv)
259    string currentFile("");
260  
261    mithep::EventHeader *info    = new mithep::EventHeader();
224  //  mithep::TGenInfo    *ginfo  = new mithep::TGenInfo();
262    mithep::Array<mithep::Electron>             *electronArr   = new mithep::Array<mithep::Electron>();
263    mithep::Array<mithep::Muon>                 *muonArr       = new mithep::Array<mithep::Muon>();
264    mithep::Array<mithep::Vertex>               *vtxArr        = new mithep::Array<mithep::Vertex>();
# Line 229 | Line 266 | int main(int argc, char** argv)
266    mithep::Array<mithep::PileupInfo>           *puArr         = new mithep::Array<mithep::PileupInfo>();
267    mithep::Array<mithep::PileupEnergyDensity>  *puDArr        = new mithep::Array<mithep::PileupEnergyDensity>();
268    mithep::Array<mithep::Track>                *trkArr        = new mithep::Array<mithep::Track>();
269 +  mithep::Array<mithep::MCParticle>           *mcArr         = new mithep::Array<mithep::MCParticle>();
270 +  mithep::MCEventInfo                         *mcEvtInfo     = new mithep::MCEventInfo();
271    mithep::TriggerMask                         *trigMask      = new mithep::TriggerMask();
272    mithep::TriggerTable                        *hltTable      = new mithep::TriggerTable();
273    vector<string>                              *hltTableStrings  = new vector<string>();
# Line 241 | Line 280 | int main(int argc, char** argv)
280    TString fPileupInfoName(Names::gkPileupInfoBrn);
281    TString fPileupEnergyDensityName(Names::gkPileupEnergyDensityBrn);
282    TString fTrackName(Names::gkTrackBrn);
283 +  TString fMCParticleName(Names::gkMCPartBrn);
284 +  TString fMCEvtInfoName(Names::gkMCEvtInfoBrn);
285    TString fTriggerMaskName(Names::gkHltBitBrn);
286    TString fTriggerTableName(Names::gkHltTableBrn);
287    
# Line 249 | Line 290 | int main(int argc, char** argv)
290    chain->SetBranchAddress(fMuonName,        &muonArr);
291    chain->SetBranchAddress(fPrimVtxName,     &vtxArr);
292    chain->SetBranchAddress(fPFCandidateName, &pfArr);
293 <  chain->SetBranchAddress(fPileupInfoName,  &puArr);
293 >  if( ctrl.mc ) {
294 >    chain->SetBranchAddress(fPileupInfoName,  &puArr);
295 >    chain->SetBranchAddress(fMCParticleName,  &mcArr);
296 >    chain->SetBranchAddress(fMCEvtInfoName,  &mcEvtInfo);
297 >  }
298    chain->SetBranchAddress(fPileupEnergyDensityName, &puDArr);
299    chain->SetBranchAddress(fTrackName, &trkArr);
300    chain->SetBranchAddress(fTriggerMaskName, &trigMask);
# Line 282 | Line 327 | int main(int argc, char** argv)
327      {
328        chain->GetEntry(ientry);
329        if(!(ientry%1000)) cerr << "entry: " << ientry << endl;
330 <      if( ientry > 100) break;
331 <      setPV( ctrl, vtxArr, vtx);
330 >
331 >      //if( info->EvtNum() != 217998 ) continue;
332 >      //      if( info->EvtNum() != 238893 ) continue;
333 >      //      if( info->EvtNum() != 289066 ) continue;
334 >
335 >      string fname = string(chain->GetFile()->GetEndpointUrl()->GetFile());
336 >      setEra( fname, ctrl );
337  
338  
339        //
340 +      // pfNoPU
341 +      //
342 +      //mithep::Array<PFCandidate> pfNoPileUp;
343 +      PFnoPUflag.clear();
344 +      int pfnopu_size = makePFnoPUArray( pfArr, PFnoPUflag, vtxArr );
345 +      assert(pfnopu_size == pfArr->GetEntries());
346 +
347 +      //
348        // data/MC
349        //
350        if(ctrl.mc) {
351          //
352 +        // gen info
353 +        //
354 +        if( ctrl.fillGen )
355 +          fillGenInfo( mcArr, mcEvtInfo, geninfo, ESampleType::kHZZ, ctrl);
356 +
357 +        //
358          // xsec & PU weights
359          //
360          weights.w = getWeight(xstab,entrymap,chain)/ctrl.totalMC;
361 +        cout << "xsec weight: " << weights.w << endl;
362          int npu = -1;
363          for(int i=0;i<puArr->GetEntries();i++) {
364            if(puArr->At(i)->GetBunchCrossing() == 0)
# Line 302 | Line 367 | int main(int argc, char** argv)
367          assert(npu>=0);
368          evtinfo.npu;
369          weights.npuw = getPUWeight(evtinfo.npu);
370 <        //      cout << "weight: " << weights.w << endl;
370 >        
371 >        //
372 >        // pt reweighting for Higgs < 140, F11
373 >        //
374 >        if( ctrl.fillGen ) {
375 >          if( (fname.find("f11-h115zz4l") != string::npos) ||
376 >              (fname.find("f11-h120zz4l") != string::npos) ||
377 >              (fname.find("f11-h130zz4l") != string::npos)  ) {
378 >            weights.w *= h_wf11_hpt->GetBinContent(h_wf11_hpt->FindBin(geninfo.pt_zz));
379 >          }
380 >        }
381 >
382 >        //
383 >        // trigger
384 >        //
385 >        if( string(chain->GetFile()->GetEndpointUrl()->GetFile()) != currentFile ) {
386 >          currentFile = string(chain->GetFile()->GetEndpointUrl()->GetFile());
387 >          hltchain->SetBranchAddress(fTriggerTableName, &hltTableStrings);
388 >          hltchain->GetEntry(0);
389 >          hltTable->Clear();
390 >          fillTriggerNames(hltTable, hltTableStrings );
391 >        }
392 >        if( ctrl.debug ) cout << "file is : " << currentFile  << endl;
393 >        fillTriggerBits( hltTable, trigMask, triggerBits );
394 >        passes_HLT_MC = true; // passed to apply as extern global, just for sync
395 >        if( !passHLTMC(triggerBits, info->RunNum(), info->EvtNum(), k2012_MC ) ) {
396 >          passes_HLT_MC = false;
397 >        }
398        } else {
399          //
400          // JSON
401          //
402 +        /*
403          RunLumiRangeMap::RunLumiPairType rl(info->RunNum(), info->LumiSec());      
404          if( !(rlrm.HasRunLumi(rl)) )  {
405            if( ctrl.debug ) cout << "\tfails JSON" << endl;
406            continue;
407          }
408 +        */
409          //
410          // trigger
411          //
# Line 320 | Line 414 | int main(int argc, char** argv)
414            hltchain->SetBranchAddress(fTriggerTableName, &hltTableStrings);
415            hltchain->GetEntry(0);
416            hltTable->Clear();
417 <          fillTriggerBits(hltTable, hltTableStrings );
417 >          fillTriggerNames(hltTable, hltTableStrings );
418          }
419          if( ctrl.debug ) cout << "file is : " << currentFile  << endl;
420 +        /*
421          fillTriggerBits( hltTable, trigMask, triggerBits );
422          if( !passHLT(triggerBits, info->RunNum(), info->EvtNum() ) ) {
423            if( ctrl.debug ) cout << "\tfails trigger ... " << endl;
424            continue;
425          }
426 +        */
427        }
428  
429        //
# Line 336 | Line 432 | int main(int argc, char** argv)
432        failingLeptons.clear();
433        passingLeptons.clear();
434        EventData ret4l =
339        apply_HZZ4L_reference_selection(ctrl, info,
340                              vtx,
341                              pfArr,
342                              puDArr,
343                              electronArr,
344                              &electronReferencePreSelection,
345                              &electronReferenceIDMVASelection,
346                              &electronReferenceIsoSelection,
347                              muonArr,
348                              &muonReferencePreSelection,
349                              &muonIDPFSelection,
350                              &muonReferenceIsoSelection);
351        /*
352        apply_HZZ4L_reference_selection(ctrl, info,
353                              vtx,
354                              pfArr,
355                              puArr,
356                              electronArr,
357                              &electronPreSelection,
358                              &electronIDMVASelection,
359                              &electronIsoMVASelection,
360                              muonArr,
361                              &muonPreSelection,
362                              &muonIDPFSelection,
363                              &muonIsoMVASelection);
364        */
435  
436 +
437 +        // reference
438 +        apply_HZZ4L_reference_selection(ctrl, info,
439 +                                        vtxArr,
440 +                                        pfArr,
441 +                                        puDArr,
442 +                                        electronArr,
443 +                                        &electronReferencePreSelection,
444 +                                        &electronReferenceIDMVASelectionV1,
445 +                                        &electronReferenceIsoSelection,
446 +                                        muonArr,
447 +                                        &muonReferencePreSelection,
448 +                                        &muonIDPFSelection,
449 +                                        &muonReferenceIsoSelection);
450 +      
451        if( ctrl.debug ) cout << endl;
452  
453 <      //      cout << "bits: " << ret4l.status.selectionBits << endl;
453 >
454 >      int Z1type=0, Z2type=0;
455 >      if( ret4l.status.selectionBits.to_ulong() >= PASS_ZCANDIDATE ) {
456 >        if( abs(ret4l.Z1leptons[0].type) == 11  ) Z1type = 11;
457 >        if( abs(ret4l.Z1leptons[0].type) == 13  ) Z1type = 13;
458 >      }  
459 >      if( ret4l.status.selectionBits.to_ulong() >= PASS_ZZCANDIDATE ) {
460 >        if( abs(ret4l.Z2leptons[0].type) == 11  ) Z2type = 11;
461 >        if( abs(ret4l.Z2leptons[0].type) == 13  ) Z2type = 13;
462 >      }  
463 >      
464 > #ifdef SYNC
465 >      cout  << "bits: " << ret4l.status.selectionBits  << "\t"
466 >            << "Z1: " << Z1type << "\t"
467 >            << "Z2: " << Z2type << endl;
468 >      cout << endl;
469 > #endif      
470        
471        if( ret4l.status.pass() ) {
472          fillAngles(ret4l,angles);
473          fillKinematics(ret4l,kinematics);
474 +        fillMassErrors(ret4l,muonArr,electronArr,kinematics);
475          fillEventInfo(info,evtinfo);
476          if( ctrl.mc) {
375        // fillGenInfo(ginfo,geninfo);
477            setEffiencyWeights(ret4l, weights);
478             if(ctrl.debug)
479               cout << "w: " << weights.w << "\t"
# Line 380 | Line 481 | int main(int argc, char** argv)
481                    << "woff: " << weights.woff << endl;
482          }
483          
484 <        /*
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 <        */
484 >
485          nt.Fill();
486          
487          cerr  << "PASS:: "
# Line 399 | Line 496 | int main(int argc, char** argv)
496          pass++;
497          //      if( pass > 3 ) break;
498  
499 <      } else if( ret4l.status.selectionBits.test(PASS_ZCANDIDATE) ) { // save for fakes ...
500 <        cout << "failingLeptons : " << failingLeptons.size() << endl;
501 <        for( int f=0; f<failingLeptons.size(); f++ ) {
502 <          SimpleLepton  l = failingLeptons[f];
503 <          cout << "f: " << f << "\t"
504 <               << "type: " << l.type << "\t"
505 <               << "pT: " << l.vec.Pt()  << "\t"
506 <               << "eta: " << l.vec.Eta()
507 <               << endl;
499 >      } else if( ret4l.status.selectionBits.test(PASS_GOODZ1) &&
500 >                 ret4l.status.selectionBits.to_ulong() < PASS_4L) { // save for fakes ...
501 >        //      if(ctrl.debug) {
502 >          cout << "failingLeptons : " << failingLeptons.size() << endl;
503 >          for( int f=0; f<failingLeptons.size(); f++ ) {
504 >            SimpleLepton  l = failingLeptons[f];
505 >            cout << "f: " << f << "\t"
506 >                 << "type: " << l.type << "\t"
507 >                 << "pT: " << l.vec.Pt()  << "\t"
508 >                 << "eta: " << l.vec.Eta()
509 >                 << endl;
510 >            //    }
511          }
412        /*
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;
419        }
420        */
421        cout << endl;
512          foTree.Fill();
513        }
514      }  
# Line 427 | Line 517 | int main(int argc, char** argv)
517    foTree.getFile()->cd();
518    foTree.getTree()->Write();
519    nt.WriteClose();
430 }
520  
521 < //----------------------------------------------------------------------------
522 < //
523 < // Get primary vertices
524 < // Assumes primary vertices are ordered by sum-pT^2 (as should be in CMSSW)
525 < // NOTE: if no PV is found from fitting tracks, the beamspot is used
526 < //
527 < //----------------------------------------------------------------------------
528 < bool setPV(ControlFlags ctrl,
529 <           const mithep::Array<mithep::Vertex> * vtxArr,
530 <           mithep::Vertex & vtx)
531 < //----------------------------------------------------------------------------
532 < {
533 <  const Vertex *bestPV = 0;
534 <  float best_sumpt=-1;
535 <
536 <  // good PV requirements
537 <  const UInt_t   fMinNTracksFit = 0;
538 <  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 <    }
521 >  cout << endl;
522 >  cout << endl;
523 >  for( int i=0; i<cutvec.size(); i++ ) {
524 >    cout << "cut: " << i << "\t"
525 >         << "pass: " << cutvec[i];
526 >
527 >    if( i>PASS_TRIGGER&&i<=PASS_GOODZ1 )
528 >      cout << "\t2e: " << zcutvec[0][i]
529 >           << "\t2m: " << zcutvec[1][i];
530 >
531 >    if( i>PASS_ZCANDIDATE )
532 >      cout << "\t4e: " << zzcutvec[0][i]
533 >           << "\t4m: " << zzcutvec[1][i]
534 >           << "\t2e2m: " << zzcutvec[2][i];
535 >
536 >    cout << "\t" << cutstrs[i] << endl;
537 >
538 >    cout << endl;
539    }
540 <  
541 <  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 < };
540 >
541 > }
542  
543  
544  
# Line 564 | Line 621 | double getPUWeight(unsigned npu)
621   {
622    return hpu->GetBinContent(hpu->FindBin(npu));
623   }
624 +
625 + //----------------------------------------------------------------------------
626 + void initEvtRhoMap( map<unsigned, float> & evtrhoMap )
627 + //----------------------------------------------------------------------------
628 + {
629 +  unsigned evt;
630 +  float rho;
631 +
632 +  cout << "initialzing EvtRhoMap ";
633 +  //FILE * f = fopen("evtrho.dat", "r");
634 +  //  FILE * f = fopen("allrho.cali.uniq.dat", "r");
635 +  FILE * f = fopen("/data/blue/khahn/CMSSW_4_4_2/src/MitHzz4l/allrhoAA.cali.uniq.dat", "r");
636 +  int lcount=0;
637 +  while( fscanf( f, "%u:%f", &evt, &rho ) ) {
638 +    if( feof(f) ) break;
639 +    evtrhoMap[evt] = rho;
640 +    lcount++;
641 +    if( !(lcount%1000) ) cout << "."; flush(cout);
642 +  }
643 +  cout << " done" << endl;
644 + }
645 +
646 + //----------------------------------------------------------------------------
647 + unsigned makePFnoPUArray(mithep::Array<PFCandidate> * fPFCandidates,
648 +                         vector<bool> &pfNoPileUpflag,
649 +                         const mithep::Array<mithep::Vertex>      * vtxArr )
650 + //----------------------------------------------------------------------------
651 + {
652 +  for(UInt_t i = 0; i < fPFCandidates->GetEntries(); i++) {
653 +    const PFCandidate *pf = fPFCandidates->At(i);
654 +    assert(pf);
655 +
656 +    if(pf->PFType() == PFCandidate::eHadron) {
657 +      if(pf->HasTrackerTrk() &&
658 +         vtxArr->At(0)->HasTrack(pf->TrackerTrk()) &&
659 +         vtxArr->At(0)->TrackWeight(pf->TrackerTrk()) > 0) {
660 +
661 +        pfNoPileUpflag.push_back(1);
662 +
663 +      } else {
664 +
665 +        Bool_t vertexFound = kFALSE;
666 +        const Vertex *closestVtx = 0;
667 +        Double_t dzmin = 10000;
668 +        
669 +        // loop over vertices
670 +        for(UInt_t j = 0; j < vtxArr->GetEntries(); j++) {
671 +          const Vertex *vtx = vtxArr->At(j);
672 +          assert(vtx);
673 +          
674 +          if(pf->HasTrackerTrk() &&
675 +             vtx->HasTrack(pf->TrackerTrk()) &&
676 +             vtx->TrackWeight(pf->TrackerTrk()) > 0) {
677 +            vertexFound = kTRUE;
678 +            closestVtx = vtx;
679 +            break;
680 +          }
681 +          Double_t dz = fabs(pf->SourceVertex().Z() - vtx->Z());
682 +          if(dz < dzmin) {
683 +            closestVtx = vtx;
684 +            dzmin = dz;
685 +          }
686 +        }
687 +
688 +        //      if(fCheckClosestZVertex) {
689 +        if(1) {
690 +          // Fallback: if track is not associated with any vertex,
691 +          // associate it with the vertex closest in z
692 +          if(vertexFound || closestVtx != vtxArr->At(0)) {
693 +            //      pfPileUp->Add(pf);
694 +            pfNoPileUpflag.push_back(0);
695 +          } else {
696 +            pfNoPileUpflag.push_back(1);
697 +          }
698 +        } else {
699 +          if(vertexFound && closestVtx != vtxArr->At(0)) {
700 +            //      pfPileUp->Add(pf);
701 +            pfNoPileUpflag.push_back(0);
702 +          } else {
703 +            //      PFCandidate * pfNoPileUp->AddNew(); // Ridiculous but that's how it is
704 +            pfNoPileUpflag.push_back(1);
705 +          }
706 +        }
707 +      } //hadron & trk stuff
708 +    } else { // hadron
709 +      //      PFCandidate * ptr = pfNoPileUp->AddNew();
710 +      pfNoPileUpflag.push_back(1);
711 +    }
712 +  } // Loop over PF candidates
713 +
714 +  return pfNoPileUpflag.size();
715 + }
716 +
717 + void setEra(string fname, ControlFlags &ctrl)
718 + {
719 +  if( ctrl.mc && (fname.find("f11-") != string::npos)  ) ctrl.era=2011 ;
720 +  if( ctrl.mc && (fname.find("s12-") != string::npos)  ) ctrl.era=2012 ;
721 +  if( !ctrl.mc && (fname.find("r11-") != string::npos)  ) ctrl.era=2011 ;
722 +  if( !ctrl.mc && (fname.find("r12-") != string::npos)  ) ctrl.era=2012 ;
723 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines