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.26 by khahn, Wed May 23 13:33:15 2012 UTC vs.
Revision 1.37 by dkralph, Wed Jun 13 13:39:12 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"
65 //#include "GlobalDataAndFuncs.h"
66 #include "RunLumiRangeMap.h"
67
62   #include "AngleTuple.h"
63   #include "FOTuple.h"
64  
65 + #include "RunLumiRangeMap.h"
66   #include "SampleWeight.h"
67   #include "EfficiencyWeightsInterface.h"
68  
# Line 99 | Line 94 | vector<bool>   PFnoPUflag;;
94   //----------------------------------------------------------------------------
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::VertexCol     * vtxArr );
103 >                         const mithep::Array<mithep::Vertex>     * vtxArr );
104   //----------------------------------------------------------------------------
105  
106  
# Line 214 | 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 239 | 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));
243 <      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();
252 <  initElectronIDMVA();
253 <  initElectronIsoMVA();
247 >  initElectronIDMVAV1();
248    initTrigger();
249  
250    // hack
# Line 265 | Line 259 | int main(int argc, char** argv)
259    string currentFile("");
260  
261    mithep::EventHeader *info    = new mithep::EventHeader();
268  //  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 <  const mithep::VertexCol              *vtxArr        = 0;//new mithep::Array<mithep::Vertex>();
264 >  mithep::Array<mithep::Vertex>               *vtxArr        = new mithep::Array<mithep::Vertex>();
265    mithep::Array<mithep::PFCandidate>          *pfArr         = new mithep::Array<mithep::PFCandidate>();
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 287 | Line 281 | int main(int argc, char** argv)
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 298 | Line 293 | int main(int argc, char** argv)
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);
# Line 330 | Line 326 | int main(int argc, char** argv)
326    for(UInt_t ientry=0; ientry<imax; ientry++)
327      {
328        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
329        if(!(ientry%1000)) cerr << "entry: " << ientry << endl;
368      //if (!(setPV( ctrl, vtxArr, vtx)) ) continue;
330  
331 <      float rho = evtrhoMap[info->EvtNum()];
331 >      string fname = string(chain->GetFile()->GetEndpointUrl()->GetFile());
332 >      setEra( fname, ctrl );
333 >
334  
335        //
336        // pfNoPU
# Line 382 | Line 345 | int main(int argc, char** argv)
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 = 1;//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++) {
# Line 394 | 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          //
# Line 403 | Line 383 | int main(int argc, char** argv)
383            hltchain->SetBranchAddress(fTriggerTableName, &hltTableStrings);
384            hltchain->GetEntry(0);
385            hltTable->Clear();
386 <          fillTriggerBits(hltTable, hltTableStrings );
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() ) ) {
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 430 | 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          /*
# Line 451 | Line 434 | int main(int argc, char** argv)
434  
435  
436          // reference
437 <        apply_HZZ4L_reference2_selection(ctrl, info,
438 <                                         vtxArr,
439 <                                         pfArr,
440 < #ifdef HACKED_RHOS
441 <                                         rho,
442 < #else
443 <                                         puDArr,
444 < #endif
445 <                                         electronArr,
446 <                                         &electronReferencePreSelection,
447 <                                         &electronReferenceIDMVASelectionV1,
448 <                                         &electronReferenceIsoSelection,
449 <                                         muonArr,
467 <                                         &muonReferencePreSelection,
468 <                                         &muonIDPFSelection,
469 <                                         &muonReferenceIsoSelection);
470 <
471 <      /*
472 <        // evolved
473 <        apply_HZZ4L_reference2_selection(ctrl, info,
474 <                                         vtx,
475 <                                         pfArr,
476 <                                         //rho,
477 <                                         puDArr,
478 <                                         electronArr,
479 <                                         &electronReferencePreSelection,
480 <                                         //&electronPreSelection,
481 <                                         &electronReferenceIDMVASelection,
482 <                                         &electronIsoMVASelection,
483 <                                         muonArr,
484 <                                         &muonReferencePreSelection,
485 <                                         //&muonPreSelection,
486 <                                         &muonIDPFSelection,
487 <                                         &muonIsoMVASelection);
488 <      */
489 <
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 510 | Line 470 | int main(int argc, char** argv)
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) {
515        // fillGenInfo(ginfo,geninfo);
476            setEffiencyWeights(ret4l, weights);
477             if(ctrl.debug)
478               cout << "w: " << weights.w << "\t"
# Line 520 | Line 480 | int main(int argc, char** argv)
480                    << "woff: " << weights.woff << endl;
481          }
482          
483 <        /*
524 <        // only for Higgs < 140
525 <        geninfo.weight *= h_w_hpt->GetBinContent(h_w_hpt->FindBin(geninfo.pt_zz));
526 <        angles.bdt = reader->EvaluateMVA("BDTG");
527 <        */
483 >
484          nt.Fill();
485          
486          cerr  << "PASS:: "
# Line 539 | Line 495 | int main(int argc, char** argv)
495          pass++;
496          //      if( pass > 3 ) break;
497  
498 <      } else if( ret4l.status.selectionBits.test(PASS_GOODZ1) ) { // save for fakes ...
499 <        //      if(ctrl.debug) {
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++ ) {
503              SimpleLepton  l = failingLeptons[f];
# Line 549 | Line 506 | int main(int argc, char** argv)
506                   << "pT: " << l.vec.Pt()  << "\t"
507                   << "eta: " << l.vec.Eta()
508                   << endl;
509 <            //    }
509 >          }
510          }
511          foTree.Fill();
512 +      } else {
513 +        cout << "failing with some other code : " << ret4l.status.selectionBits << endl;
514        }
515      }  
516  
# Line 646 | 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 687 | Line 650 | void initEvtRhoMap( map<unsigned, float>
650  
651   //----------------------------------------------------------------------------
652   unsigned makePFnoPUArray(mithep::Array<PFCandidate> * fPFCandidates,
653 <                     vector<bool> &pfNoPileUpflag,
654 <                     const mithep::VertexCol      * vtxArr )
653 >                         vector<bool> &pfNoPileUpflag,
654 >                         const mithep::Array<mithep::Vertex>      * vtxArr )
655   //----------------------------------------------------------------------------
656   {
657    for(UInt_t i = 0; i < fPFCandidates->GetEntries(); i++) {
# Line 756 | Line 719 | unsigned makePFnoPUArray(mithep::Array<P
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