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.19 by khahn, Thu May 10 22:36:12 2012 UTC vs.
Revision 1.37 by dkralph, Wed Jun 13 13:39:12 2012 UTC

# Line 37 | 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 49 | Line 50 | using namespace std;
50   #include "MuonSelection.h"
51   #include "ElectronSelection.h"
52   #include "IsolationSelection.h"
53 <
53 < //#include "Selection.h"
54 < //#include "ReferenceSelection.h"
55 < #include "ReferenceSelection2.h"
53 > #include "ReferenceSelection.h"
54  
55   #include "TriggerUtils.h"
56   #include "PassHLT.h"
57   #include "Angles.h"
58   #include "KinematicsStruct.h"
59   #include "InfoStruct.h"
60 < //#include "GenInfoStruct.h"
60 > #include "GenInfoStruct.h"
61   #include "WeightStruct.h"
64 //#include "GlobalDataAndFuncs.h"
65 #include "RunLumiRangeMap.h"
66
62   #include "AngleTuple.h"
63   #include "FOTuple.h"
64  
65 + #include "RunLumiRangeMap.h"
66   #include "SampleWeight.h"
67   #include "EfficiencyWeightsInterface.h"
68  
# Line 90 | Line 86 | 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   //----------------------------------------------------------------------------
97 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 111 | Line 112 | int main(int argc, char** argv)
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"));        //2
119 <  cutstrs.push_back(string("good Z1"));            //3
118 >  cutstrs.push_back(string("Z candidate"));        //3
119 >  cutstrs.push_back(string("good Z1"));            //4
120    // -------------------------------------------------
121 <  cutstrs.push_back(string("4l"));                 //4
122 <  cutstrs.push_back(string("ZZ candidate"));       //5
123 <  cutstrs.push_back(string("good Z2"));            //6
124 <  cutstrs.push_back(string("ZZ 20/10"));           //7
125 <  cutstrs.push_back(string("resonance"));          //8
126 <  cutstrs.push_back(string("m4l>70"));             //9
127 <  cutstrs.push_back(string("m4l>100"));            //10
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  
# Line 132 | Line 135 | int main(int argc, char** argv)
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<11; i++ ) cutvec.push_back(0);
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<11; j++ ) zcutvec[i].push_back(0);
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<11; j++ ) zzcutvec[i].push_back(0);
145 >    for( int j=0; j<cutstrs.size(); j++ ) zzcutvec[i].push_back(0);
146    }
147  
148  
# Line 207 | 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 232 | 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));
236 <      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();
245 <  initElectronIDMVA();
246 <  initElectronIsoMVA();
247 >  initElectronIDMVAV1();
248    initTrigger();
249  
250    // hack
# Line 258 | Line 259 | int main(int argc, char** argv)
259    string currentFile("");
260  
261    mithep::EventHeader *info    = new mithep::EventHeader();
261  //  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 266 | 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 278 | 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 286 | Line 290 | int main(int argc, char** argv)
290    chain->SetBranchAddress(fMuonName,        &muonArr);
291    chain->SetBranchAddress(fPrimVtxName,     &vtxArr);
292    chain->SetBranchAddress(fPFCandidateName, &pfArr);
293 <  if( ctrl.mc ) 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 319 | Line 327 | int main(int argc, char** argv)
327      {
328        chain->GetEntry(ientry);
329        if(!(ientry%1000)) cerr << "entry: " << ientry << endl;
322      setPV( ctrl, vtxArr, vtx);
330  
331 <      cout << "origrho: " << puDArr->At(0)->Rho()
332 <           << "\torigrholoweta: " << puDArr->At(0)->RhoLowEta()
333 <           << endl;
331 >      string fname = string(chain->GetFile()->GetEndpointUrl()->GetFile());
332 >      setEra( fname, ctrl );
333 >
334  
335 +      //
336 +      // pfNoPU
337 +      //
338 +      //mithep::Array<PFCandidate> pfNoPileUp;
339 +      PFnoPUflag.clear();
340 +      int pfnopu_size = makePFnoPUArray( pfArr, PFnoPUflag, vtxArr );
341 +      assert(pfnopu_size == pfArr->GetEntries());
342  
343        //
344        // data/MC
345        //
346        if(ctrl.mc) {
347          //
348 +        // gen info
349 +        //
350 +        if( ctrl.fillGen )
351 +          fillGenInfo( mcArr, mcEvtInfo, geninfo, ESampleType::kHZZ, ctrl);
352 +
353 +        //
354          // xsec & PU weights
355          //
356 <        //      weights.w = getWeight(xstab,entrymap,chain)/ctrl.totalMC;
356 >        weights.w = getWeight(xstab,entrymap,chain)/ctrl.totalMC;
357 >        cout << "xsec weight: " << weights.w << endl;
358          int npu = -1;
359          for(int i=0;i<puArr->GetEntries();i++) {
360            if(puArr->At(i)->GetBunchCrossing() == 0)
# Line 342 | Line 363 | int main(int argc, char** argv)
363          assert(npu>=0);
364          evtinfo.npu;
365          weights.npuw = getPUWeight(evtinfo.npu);
366 <        //      cout << "weight: " << weights.w << endl;
366 >        
367 >        //
368 >        // pt reweighting for Higgs < 140, F11
369 >        //
370 >        if( ctrl.fillGen ) {
371 >          if( (fname.find("f11-h115zz4l") != string::npos) ||
372 >              (fname.find("f11-h120zz4l") != string::npos) ||
373 >              (fname.find("f11-h130zz4l") != string::npos)  ) {
374 >            weights.w *= h_wf11_hpt->GetBinContent(h_wf11_hpt->FindBin(geninfo.pt_zz));
375 >          }
376 >        }
377 >
378 >        //
379 >        // trigger
380 >        //
381 >        if( string(chain->GetFile()->GetEndpointUrl()->GetFile()) != currentFile ) {
382 >          currentFile = string(chain->GetFile()->GetEndpointUrl()->GetFile());
383 >          hltchain->SetBranchAddress(fTriggerTableName, &hltTableStrings);
384 >          hltchain->GetEntry(0);
385 >          hltTable->Clear();
386 >          fillTriggerNames(hltTable, hltTableStrings );
387 >        }
388 >        if( ctrl.debug ) cout << "file is : " << currentFile  << endl;
389 >        fillTriggerBits( hltTable, trigMask, triggerBits );
390 >        passes_HLT_MC = true; // passed to apply as extern global, just for sync
391 >        if( !passHLTMC(triggerBits, info->RunNum(), info->EvtNum(), k2012_MC ) ) {
392 >          passes_HLT_MC = false;
393 >        }
394        } else {
395          //
396          // JSON
397          //
398 <        /*
399 <        RunLumiRangeMap::RunLumiPairType rl(info->RunNum(), info->LumiSec());      
400 <        if( !(rlrm.HasRunLumi(rl)) )  {
401 <          if( ctrl.debug ) cout << "\tfails JSON" << endl;
402 <          continue;
398 >        // if(!(ctrl.noJSON) ) {
399 >        cout << "noJSON flag not in Control Flags" << endl;
400 >        assert(0);
401 >          RunLumiRangeMap::RunLumiPairType rl(info->RunNum(), info->LumiSec());      
402 >          if( !(rlrm.HasRunLumi(rl)) )  {
403 >            if( ctrl.debug ) cout << "\tfails JSON" << endl;
404 >            continue;
405 >          // }
406          }
407 <        */
407 >
408          //
409          // trigger
410          //
# Line 362 | Line 413 | int main(int argc, char** argv)
413            hltchain->SetBranchAddress(fTriggerTableName, &hltTableStrings);
414            hltchain->GetEntry(0);
415            hltTable->Clear();
416 <          fillTriggerBits(hltTable, hltTableStrings );
416 >          fillTriggerNames(hltTable, hltTableStrings );
417          }
418          if( ctrl.debug ) cout << "file is : " << currentFile  << endl;
419 +        /*
420          fillTriggerBits( hltTable, trigMask, triggerBits );
421          if( !passHLT(triggerBits, info->RunNum(), info->EvtNum() ) ) {
422            if( ctrl.debug ) cout << "\tfails trigger ... " << endl;
423            continue;
424          }
425 +        */
426        }
427  
428        //
# Line 378 | Line 431 | int main(int argc, char** argv)
431        failingLeptons.clear();
432        passingLeptons.clear();
433        EventData ret4l =
381        apply_HZZ4L_reference2_selection(ctrl, info,
382                                         vtx,
383                                         pfArr,
384                                         //                           evtrhoMap[info->EvtNum()],
385                                         puDArr,
386                                         electronArr,
387                                         &electronReferencePreSelection,
388                                         &electronReferenceIDMVASelection,
389                                         &electronReferenceIsoSelection,
390                                         muonArr,
391                                         &muonReferencePreSelection,
392                                         &muonIDPFSelection,
393                                         &muonReferenceIsoSelection);
394        /*
395        apply_HZZ4L_reference_selection(ctrl, info,
396                              vtx,
397                              pfArr,
398                              puArr,
399                              electronArr,
400                              &electronPreSelection,
401                              &electronIDMVASelection,
402                              &electronIsoMVASelection,
403                              muonArr,
404                              &muonPreSelection,
405                              &muonIDPFSelection,
406                              &muonIsoMVASelection);
407        */
434  
435 +
436 +        // reference
437 +        apply_HZZ4L_reference_selection(ctrl, info,
438 +                                        vtxArr,
439 +                                        pfArr,
440 +                                        puDArr,
441 +                                        electronArr,
442 +                                        &electronReferencePreSelection,
443 +                                        &electronReferenceIDMVASelectionV1,
444 +                                        &electronReferenceIsoSelection,
445 +                                        muonArr,
446 +                                        &muonReferencePreSelection,
447 +                                        &muonIDPFSelection,
448 +                                        &muonReferenceIsoSelection);
449 +      
450        if( ctrl.debug ) cout << endl;
451  
452  
# Line 419 | Line 460 | int main(int argc, char** argv)
460          if( abs(ret4l.Z2leptons[0].type) == 13  ) Z2type = 13;
461        }  
462        
463 + #ifdef SYNC
464        cout  << "bits: " << ret4l.status.selectionBits  << "\t"
465              << "Z1: " << Z1type << "\t"
466              << "Z2: " << Z2type << endl;
467        cout << endl;
468 <                      
468 > #endif      
469        
470        if( ret4l.status.pass() ) {
471          fillAngles(ret4l,angles);
472          fillKinematics(ret4l,kinematics);
473 +        fillMassErrors(ret4l,muonArr,electronArr,kinematics);
474          fillEventInfo(info,evtinfo);
475          if( ctrl.mc) {
433        // fillGenInfo(ginfo,geninfo);
476            setEffiencyWeights(ret4l, weights);
477             if(ctrl.debug)
478               cout << "w: " << weights.w << "\t"
# Line 438 | Line 480 | int main(int argc, char** argv)
480                    << "woff: " << weights.woff << endl;
481          }
482          
483 <        /*
442 <        // only for Higgs < 140
443 <        geninfo.weight *= h_w_hpt->GetBinContent(h_w_hpt->FindBin(geninfo.pt_zz));
444 <        angles.bdt = reader->EvaluateMVA("BDTG");
445 <        */
483 >
484          nt.Fill();
485          
486          cerr  << "PASS:: "
# Line 457 | Line 495 | int main(int argc, char** argv)
495          pass++;
496          //      if( pass > 3 ) break;
497  
498 <      } else if( ret4l.status.selectionBits.test(PASS_ZCANDIDATE) ) { // save for fakes ...
498 >      } else if( ret4l.status.selectionBits.test(PASS_GOODZ1) &&
499 >                 ret4l.status.selectionBits.to_ulong() < (1UL<<PASS_4L)) { // save for fakes ...
500          if(ctrl.debug) {
501            cout << "failingLeptons : " << failingLeptons.size() << endl;
502            for( int f=0; f<failingLeptons.size(); f++ ) {
# Line 470 | Line 509 | int main(int argc, char** argv)
509            }
510          }
511          foTree.Fill();
512 +      } else {
513 +        cout << "failing with some other code : " << ret4l.status.selectionBits << endl;
514        }
515      }  
516  
# Line 484 | Line 525 | int main(int argc, char** argv)
525      cout << "cut: " << i << "\t"
526           << "pass: " << cutvec[i];
527  
528 <    if( i>1&&i<=3 )
528 >    if( i>PASS_TRIGGER&&i<=PASS_GOODZ1 )
529        cout << "\t2e: " << zcutvec[0][i]
530             << "\t2m: " << zcutvec[1][i];
531  
532 <    if( i>3 )
532 >    if( i>PASS_ZCANDIDATE )
533        cout << "\t4e: " << zzcutvec[0][i]
534             << "\t4m: " << zzcutvec[1][i]
535             << "\t2e2m: " << zzcutvec[2][i];
# Line 500 | Line 541 | int main(int argc, char** argv)
541  
542   }
543  
503 //----------------------------------------------------------------------------
504 //
505 // Get primary vertices
506 // Assumes primary vertices are ordered by sum-pT^2 (as should be in CMSSW)
507 // NOTE: if no PV is found from fitting tracks, the beamspot is used
508 //
509 //----------------------------------------------------------------------------
510 bool setPV(ControlFlags ctrl,
511           const mithep::Array<mithep::Vertex> * vtxArr,
512           mithep::Vertex & vtx)
513 //----------------------------------------------------------------------------
514 {
515  const Vertex *bestPV = 0;
516  float best_sumpt=-1;
517
518  // good PV requirements
519  const UInt_t   fMinNTracksFit = 0;
520  const Double_t fMinNdof       = 4;
521  const Double_t fMaxAbsZ       = 24;
522  const Double_t fMaxRho        = 2;
523  
524  for(int i=0; i<vtxArr->GetEntries(); ++i) {
525    const Vertex *pv = (Vertex*)(vtxArr->At(i));
526    if( ctrl.debug ) cout << "vertex :: " << i << "\tntrks: " << pv->NTracks() << endl;
527    
528    // Select best PV for corrected d0; if no PV passing cuts, the first PV in the collection will be used
529    //  if(!pv->IsValid()) continue;
530    if(pv->NTracksFit()       < fMinNTracksFit)       continue;
531    if(pv->Ndof()                 < fMinNdof)         continue;
532    if(fabs(pv->Z()) > fMaxAbsZ)                      continue;
533    if(pv->Position().Rho()   > fMaxRho)              continue;    
534    
535    // take the first ...
536    bestPV = pv;
537    break;
538
539    // this never reached ...    
540    float tmp_sumpt=0;
541    for( int t=0; t<pv->NTracks(); t++ )
542      tmp_sumpt += pv->Trk(t)->Pt();
543    
544    if( tmp_sumpt > best_sumpt  ) {
545      bestPV = pv;
546      best_sumpt = tmp_sumpt;
547      if( ctrl.debug) cout << "new PV set, pt : " << best_sumpt << endl;
548    }
549  }
550  
551  if(!bestPV) bestPV = vtxArr->At(0);
552  vtx.SetPosition(bestPV->X(),bestPV->Y(),bestPV->Z());
553  vtx.SetErrors(bestPV->XErr(),bestPV->YErr(),bestPV->ZErr());
554  return true;
555 };
556
544  
545  
546   //----------------------------------------------------------------------------
# Line 618 | Line 605 | void initRunLumiRangeMap()
605    // r11b
606    rlrm.AddJSONFile(std::string("./data/Cert_160404-180252_7TeV_PromptReco_Collisions11_JSON.txt"));  
607    */
608 +
609 +  // 2012 only for now ...
610 +  rlrm.AddJSONFile(std::string("./data/Cert_190456-194479_8TeV_PromptReco_Collisions12_JSON.txt"));  
611 +
612   };
613  
614  
# Line 643 | Line 634 | void initEvtRhoMap( map<unsigned, float>
634    unsigned evt;
635    float rho;
636  
637 <  FILE * f = fopen("evtrho.dat", "r");
637 >  cout << "initialzing EvtRhoMap ";
638 >  //FILE * f = fopen("evtrho.dat", "r");
639 >  //  FILE * f = fopen("allrho.cali.uniq.dat", "r");
640 >  FILE * f = fopen("/data/blue/khahn/CMSSW_4_4_2/src/MitHzz4l/allrhoAA.cali.uniq.dat", "r");
641 >  int lcount=0;
642    while( fscanf( f, "%u:%f", &evt, &rho ) ) {
643 +    if( feof(f) ) break;
644      evtrhoMap[evt] = rho;
645 +    lcount++;
646 +    if( !(lcount%1000) ) cout << "."; flush(cout);
647    }
648 <  
648 >  cout << " done" << endl;
649 > }
650 >
651 > //----------------------------------------------------------------------------
652 > unsigned makePFnoPUArray(mithep::Array<PFCandidate> * fPFCandidates,
653 >                         vector<bool> &pfNoPileUpflag,
654 >                         const mithep::Array<mithep::Vertex>      * vtxArr )
655 > //----------------------------------------------------------------------------
656 > {
657 >  for(UInt_t i = 0; i < fPFCandidates->GetEntries(); i++) {
658 >    const PFCandidate *pf = fPFCandidates->At(i);
659 >    assert(pf);
660 >
661 >    if(pf->PFType() == PFCandidate::eHadron) {
662 >      if(pf->HasTrackerTrk() &&
663 >         vtxArr->At(0)->HasTrack(pf->TrackerTrk()) &&
664 >         vtxArr->At(0)->TrackWeight(pf->TrackerTrk()) > 0) {
665 >
666 >        pfNoPileUpflag.push_back(1);
667 >
668 >      } else {
669 >
670 >        Bool_t vertexFound = kFALSE;
671 >        const Vertex *closestVtx = 0;
672 >        Double_t dzmin = 10000;
673 >        
674 >        // loop over vertices
675 >        for(UInt_t j = 0; j < vtxArr->GetEntries(); j++) {
676 >          const Vertex *vtx = vtxArr->At(j);
677 >          assert(vtx);
678 >          
679 >          if(pf->HasTrackerTrk() &&
680 >             vtx->HasTrack(pf->TrackerTrk()) &&
681 >             vtx->TrackWeight(pf->TrackerTrk()) > 0) {
682 >            vertexFound = kTRUE;
683 >            closestVtx = vtx;
684 >            break;
685 >          }
686 >          Double_t dz = fabs(pf->SourceVertex().Z() - vtx->Z());
687 >          if(dz < dzmin) {
688 >            closestVtx = vtx;
689 >            dzmin = dz;
690 >          }
691 >        }
692 >
693 >        //      if(fCheckClosestZVertex) {
694 >        if(1) {
695 >          // Fallback: if track is not associated with any vertex,
696 >          // associate it with the vertex closest in z
697 >          if(vertexFound || closestVtx != vtxArr->At(0)) {
698 >            //      pfPileUp->Add(pf);
699 >            pfNoPileUpflag.push_back(0);
700 >          } else {
701 >            pfNoPileUpflag.push_back(1);
702 >          }
703 >        } else {
704 >          if(vertexFound && closestVtx != vtxArr->At(0)) {
705 >            //      pfPileUp->Add(pf);
706 >            pfNoPileUpflag.push_back(0);
707 >          } else {
708 >            //      PFCandidate * pfNoPileUp->AddNew(); // Ridiculous but that's how it is
709 >            pfNoPileUpflag.push_back(1);
710 >          }
711 >        }
712 >      } //hadron & trk stuff
713 >    } else { // hadron
714 >      //      PFCandidate * ptr = pfNoPileUp->AddNew();
715 >      pfNoPileUpflag.push_back(1);
716 >    }
717 >  } // Loop over PF candidates
718 >
719 >  return pfNoPileUpflag.size();
720 > }
721 >
722 > void setEra(string fname, ControlFlags &ctrl)
723 > {
724 >  if( ctrl.mc && (fname.find("f11-") != string::npos)  ) ctrl.era=2011 ;
725 >  if( ctrl.mc && (fname.find("s12-") != string::npos)  ) ctrl.era=2012 ;
726 >  if( !ctrl.mc && (fname.find("r11-") != string::npos)  ) ctrl.era=2011 ;
727 >  if( !ctrl.mc && (fname.find("r12-") != string::npos)  ) ctrl.era=2012 ;
728   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines