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.24 by khahn, Mon May 21 22:29:53 2012 UTC vs.
Revision 1.29 by khahn, Thu May 24 17:56:51 2012 UTC

# Line 50 | Line 50 | using namespace std;
50   #include "MuonSelection.h"
51   #include "ElectronSelection.h"
52   #include "IsolationSelection.h"
53 <
54 < //#include "Selection.h"
55 < //#include "ReferenceSelection.h"
56 < #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"
62   //#include "GlobalDataAndFuncs.h"
63   #include "RunLumiRangeMap.h"
# Line 97 | Line 94 | vector<bool>   PFnoPUflag;;
94   //
95   // prototypes
96   //----------------------------------------------------------------------------
100 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 <                         mithep::Array<Vertex>      * vtxArr );
105 >                         const mithep::Array<mithep::Vertex>     * vtxArr );
106   //----------------------------------------------------------------------------
107  
108  
# Line 117 | Line 114 | int main(int argc, char** argv)
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
# Line 128 | Line 126 | int main(int argc, char** argv)
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"));            //11
129 >  cutstrs.push_back(string("m4l>100, mZ2 > 12"));                  //11
130  
131  
132  
# Line 214 | 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 225 | 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 239 | 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));
243 <      h_w_hpt->Print();
240 >      h_wf11_hpt  = (TH1F*)(f_hpt->FindObjectAny(wptname));
241      }
242 <    */
242 >
243    } else {
244      initRunLumiRangeMap();
245    }
# Line 265 | Line 262 | int main(int argc, char** argv)
262    string currentFile("");
263  
264    mithep::EventHeader *info    = new mithep::EventHeader();
268  //  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 274 | Line 270 | int main(int argc, char** argv)
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 287 | Line 284 | int main(int argc, char** argv)
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 298 | Line 296 | int main(int argc, char** argv)
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);
# Line 330 | Line 329 | int main(int argc, char** argv)
329    for(UInt_t ientry=0; ientry<imax; ientry++)
330      {
331        chain->GetEntry(ientry);
333
334      /*
335      bool found_tau=false;
336      if( ctrl.mc) {  // && ctrl.debug
337        cout << "nparticles: " << mcArr->GetEntries() << endl;
338        cout << "-----------------------------------" << endl;
339        for( int i=0; i<mcArr->GetEntries(); i++ ) {
340          const mithep::MCParticle *mc = mcArr->At(i);
341          cout << "i: " << i << "\t"
342               << "id: " << mc->AbsPdgId()
343               << endl;
344          if( mc->Is(MCParticle::kTau) ) {
345            found_tau=true;
346          }
347        }
348      }
349      cout << "-----------------------------------" << endl;
350      cout << "found tau: " << found_tau << endl;
351      */
352
353      // events that fail bc ele overlaps w/ reco mu
354      /*
355      if( info->EvtNum() != 67315 &&
356          info->EvtNum() != 288693 ) continue;
357      */
358
359      // events where they apparently don't veto electrons ...
360      /*
361      if( info->EvtNum() != 141713 &&
362          info->EvtNum() != 178019 &&
363          info->EvtNum() != 60823 &&
364          info->EvtNum() != 192795 ) continue;
365      */
366
332        if(!(ientry%1000)) cerr << "entry: " << ientry << endl;
368      setPV( ctrl, vtxArr, vtx);
369      //if (!(setPV( ctrl, vtxArr, vtx)) ) continue;
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
# Line 383 | Line 351 | int main(int argc, char** argv)
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;
# Line 395 | 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          //
# Line 409 | Line 394 | int main(int argc, char** argv)
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() ) ) {
397 >        if( !passHLTMC(triggerBits, info->RunNum(), info->EvtNum(), k2012_MC ) ) {
398            passes_HLT_MC = false;
399          }
400        } else {
# Line 452 | Line 437 | int main(int argc, char** argv)
437  
438  
439          // reference
440 <        apply_HZZ4L_reference2_selection(ctrl, info,
441 <                                         vtx,
440 >        apply_HZZ4L_reference_selection(ctrl, info,
441 >                                         vtxArr,
442                                           pfArr,
443   #ifdef HACKED_RHOS
444                                           rho,
# Line 462 | Line 447 | int main(int argc, char** argv)
447   #endif
448                                           electronArr,
449                                           &electronReferencePreSelection,
450 <                                         &electronReferenceIDMVASelection,
450 >                                         &electronReferenceIDMVASelectionV1,
451                                           &electronReferenceIsoSelection,
452                                           muonArr,
453                                           &muonReferencePreSelection,
# Line 521 | Line 506 | int main(int argc, char** argv)
506                    << "woff: " << weights.woff << endl;
507          }
508          
509 <        /*
525 <        // only for Higgs < 140
526 <        geninfo.weight *= h_w_hpt->GetBinContent(h_w_hpt->FindBin(geninfo.pt_zz));
527 <        angles.bdt = reader->EvaluateMVA("BDTG");
528 <        */
509 >
510          nt.Fill();
511          
512          cerr  << "PASS:: "
# Line 583 | Line 564 | int main(int argc, char** argv)
564  
565   }
566  
586 //----------------------------------------------------------------------------
587 //
588 // Get primary vertices
589 // Assumes primary vertices are ordered by sum-pT^2 (as should be in CMSSW)
590 // NOTE: if no PV is found from fitting tracks, the beamspot is used
591 //
592 //----------------------------------------------------------------------------
593 bool setPV(ControlFlags ctrl,
594           const mithep::Array<mithep::Vertex> * vtxArr,
595           mithep::Vertex & vtx)
596 //----------------------------------------------------------------------------
597 {
598  const Vertex *bestPV = 0;
599  float best_sumpt=-1;
600
601  // good PV requirements
602  const UInt_t   fMinNTracksFit = 0;
603  const Double_t fMinNdof       = 4;
604  const Double_t fMaxAbsZ       = 24;
605  const Double_t fMaxRho        = 2;
606  
607  for(int i=0; i<vtxArr->GetEntries(); ++i) {
608    const Vertex *pv = (Vertex*)(vtxArr->At(i));
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;
613    if(pv->NTracksFit()       < fMinNTracksFit)       continue;
614    if(pv->Ndof()                 < fMinNdof)         continue;
615    if(fabs(pv->Z()) > fMaxAbsZ)                      continue;
616    if(pv->Position().Rho()   > fMaxRho)              continue;    
617    
618    // take the first ...
619    bestPV = pv;
620    break;
621
622    // this never reached ...    
623    float tmp_sumpt=0;
624    for( int t=0; t<pv->NTracks(); t++ )
625      tmp_sumpt += pv->Trk(t)->Pt();
626    
627    if( tmp_sumpt > best_sumpt  ) {
628      bestPV = pv;
629      best_sumpt = tmp_sumpt;
630      if( ctrl.debug) cout << "new PV set, pt : " << best_sumpt << endl;
631    }
632  }
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
567  
568  
569   //----------------------------------------------------------------------------
# Line 730 | Line 656 | void initEvtRhoMap( map<unsigned, float>
656    cout << "initialzing EvtRhoMap ";
657    //FILE * f = fopen("evtrho.dat", "r");
658    //  FILE * f = fopen("allrho.cali.uniq.dat", "r");
659 <  FILE * f = fopen("allrhoAA.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;
# Line 743 | Line 669 | void initEvtRhoMap( map<unsigned, float>
669  
670   //----------------------------------------------------------------------------
671   unsigned makePFnoPUArray(mithep::Array<PFCandidate> * fPFCandidates,
672 <                     vector<bool> &pfNoPileUpflag,
673 <                     mithep::Array<Vertex>      * vtxArr )
672 >                         vector<bool> &pfNoPileUpflag,
673 >                         const mithep::Array<mithep::Vertex>      * vtxArr )
674   //----------------------------------------------------------------------------
675   {
676    for(UInt_t i = 0; i < fPFCandidates->GetEntries(); i++) {
# Line 812 | Line 738 | unsigned makePFnoPUArray(mithep::Array<P
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