ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitHzz4l/Selection/src/Selection.cc
(Generate patch)

Comparing UserCode/MitHzz4l/Selection/src/Selection.cc (file contents):
Revision 1.3 by dkralph, Thu Sep 22 18:01:19 2011 UTC vs.
Revision 1.12 by khahn, Sun Oct 23 10:53:01 2011 UTC

# Line 1 | Line 1
1   #include "Selection.h"
2   #include "PassHLT.h"
3 +
4 + #include "SiMVAElectronSelection.h"
5 +
6   #include "HZZCiCElectronSelection.h"
7   #include "HZZLikelihoodElectronSelection.h"
8 + #include "HZZBDTElectronSelection.h"
9   #include "RunLumiRangeMap.h"
10  
11   RunLumiRangeMap rlrm;
12  
13 + unsigned getGenChannel(mithep::TGenInfo * ginfo) {
14 +  int gchannel=-1;
15 +  if( abs(ginfo->id_1_a) == EGenType::kElectron && abs(ginfo->id_1_b) == EGenType::kElectron )  gchannel=0;
16 +  else if( abs(ginfo->id_1_a) == EGenType::kMuon && abs(ginfo->id_1_b) == EGenType::kMuon ) gchannel=1;
17 +  else if( (abs(ginfo->id_1_a) == EGenType::kElectron && abs(ginfo->id_1_b) == EGenType::kMuon) ||
18 +           (abs(ginfo->id_1_a) == EGenType::kMuon && abs(ginfo->id_1_b) == EGenType::kElectron) ) gchannel=2;
19 +  
20 +  return gchannel;
21 + };
22 +
23 +
24   void initRunLumiRangeMap() {
25    rlrm.AddJSONFile(std::string("./data/Cert_136033-149442_7TeV_Apr21ReReco_Collisions10_JSON.txt"));
26 <  rlrm.AddJSONFile(std::string("./data/Cert_160404-173244_7TeV_PromptReco_Collisions11_JSON_v2.txt"));
26 >  //  rlrm.AddJSONFile(std::string("./data/Cert_160404-173244_7TeV_PromptReco_Collisions11_JSON_v2.txt"));
27 >  rlrm.AddJSONFile(std::string("./data/Cert_160404-178078_7TeV_PromptReco_Collisions11_JSON.txt"));
28    rlrm.AddJSONFile(std::string("./data/Cert_160404-163869_7TeV_May10ReReco_Collisions11_JSON_v3.txt"));  
29    rlrm.AddJSONFile(std::string("./data/Cert_170249-172619_7TeV_ReReco5Aug_Collisions11_JSON.txt"));  
30   };
# Line 18 | Line 34 | unsigned fails_HZZ4L_selection(ControlFl
34                                 TClonesArray *electronArr,    // input electrons
35                                 TClonesArray *muonArr,        // input muons
36                                 double eventweight,           // weight
37 <                               TNtuple * passtuple ) {
37 >                               TTree * passtuple ) {
38  
39 <  fails_HZZ4L_selection( ctrl, info, electronArr, muonArr, eventweight, passtuple, NULL );
39 >  fails_HZZ4L_selection( ctrl, NULL, info, electronArr, muonArr, eventweight, passtuple, NULL );
40  
41   };
42  
43 +
44 +
45   unsigned fails_HZZ4L_selection(ControlFlags &ctrl,           // input control
46                                 mithep::TEventInfo *info,     // input event inof
47                                 TClonesArray *electronArr,    // input electrons
# Line 31 | Line 49 | unsigned fails_HZZ4L_selection(ControlFl
49                                 double eventweight,           // weight
50                                 LabVectors  *l ) {
51  
52 <  fails_HZZ4L_selection( ctrl, info, electronArr, muonArr, eventweight, NULL, l );
52 >  fails_HZZ4L_selection( ctrl, NULL, info, electronArr, muonArr, eventweight, NULL, l );
53  
54   };
55  
56  
57   unsigned fails_HZZ4L_selection(ControlFlags &ctrl,           // input control
58 <                               mithep::TEventInfo *info,     // input event inof
58 >                               mithep::TGenInfo *ginfo ,     // input gen info
59 >                               mithep::TEventInfo *info,     // input event info
60 >                               TClonesArray *electronArr,    // input electrons
61 >                               TClonesArray *muonArr,        // input muons
62 >                               double eventweight,           // weight
63 >                               TTree * passtuple ) {
64 >
65 >  fails_HZZ4L_selection( ctrl, ginfo, info, electronArr, muonArr, eventweight, passtuple, NULL );
66 >
67 > };
68 >
69 >
70 > unsigned fails_HZZ4L_selection(ControlFlags &ctrl,           // input control
71 >                               mithep::TGenInfo *ginfo,     // input gen info
72 >                               mithep::TEventInfo *info,     // input event info
73                                 TClonesArray *electronArr,    // input electrons
74                                 TClonesArray *muonArr,        // input muons
75                                 double eventweight,           // weight
76 <                               TNtuple * passtuple,
76 >                               TTree * passtuple,
77                                 LabVectors * l) {       // output ntuple
78  
79    unsigned evtfail = 0x0;
80 +  unsigned gchannel=0xdeaddead;
81 +
82 +  if( ctrl.mc && ginfo != NULL ) {
83 +    gchannel = getGenChannel(ginfo);
84 +  }
85 +
86 +
87 +  if( ctrl.debug ) {
88 +    cout << "Run: " << info->runNum
89 +         << "\tEvt: " << info->evtNum
90 +         << "\tLumi: " << info->lumiSec
91 +         << endl;
92 +  }
93  
94    if( !ctrl.mc ) {
95      // not accounting for overlap atm
96      RunLumiRangeMap::RunLumiPairType rl(info->runNum, info->lumiSec);      
97      if( !(rlrm.HasRunLumi(rl)) )  {
98 +      if( ctrl.debug ) cout << "\tfails JSON" << endl;
99        evtfail |= (1<<EVTFAIL_JSON);
100        return evtfail;
101      }
102    }
103    
104    
105 <  if( ctrl.debug ) {
60 <    cout << "Run: " << info->runNum
61 <         << "\tEvt: " << info->evtNum
62 <         << "\tLumi: " << info->lumiSec
63 <         << endl;
64 <  }
105 >
106    
107    
108    //********************************************************
# Line 98 | Line 139 | unsigned fails_HZZ4L_selection(ControlFl
139    //----------------------------------------------------
140    for(Int_t i=0; i<muonArr->GetEntries(); i++) {
141      const mithep::TMuon *mu = (mithep::TMuon*)((*muonArr)[i]);      
142 <    unsigned muonfail = passMuonSelectionZZ(mu);
142 >    unsigned muonfail;
143 >    if( ctrl.muSele == "ksWW" )
144 >      muonfail = passMuonSelection(mu);
145 >    else
146 >      muonfail = passMuonSelectionZZ(mu);
147      if( ctrl.debug ) {
148        cout << "muon:: pt: " << mu->pt
149             << "\teta: " << mu->eta
# Line 117 | Line 162 | unsigned fails_HZZ4L_selection(ControlFl
162        tmplep.isoTrk  = mu->trkIso03;
163        tmplep.isoEcal = mu->emIso03;
164        tmplep.isoHcal = mu->hadIso03;
165 +      tmplep.isoPF03 = mu->pfIso03;
166 +      tmplep.isoPF04 = mu->pfIso04;
167        tmplep.ip3dSig = mu->ip3dSig;
168        tmplep.is4l    = false;
169        tmplep.isEB    = (fabs(mu->eta) < 1.479 ? 1 : 0 );
# Line 142 | Line 189 | unsigned fails_HZZ4L_selection(ControlFl
189        }
190      }
191  
192 <    unsigned FAIL;
193 <    CICStruct tightcuts = getTightCuts();
194 <    unsigned  failsCIC  = failsCicSelection(ctrl, ele, tightcuts, ctrl.kinematics);
195 <    LikStruct likcuts = getLikCuts(ctrl.lik_cut);
196 <    unsigned  failsLike = failsLikelihoodSelection(ele, likcuts, ctrl.kinematics);
192 >    unsigned FAIL=0, isEleTight=0;
193 >
194 >    unsigned  failsCIC=0;
195 >    CICStruct ciccuts_tight, ciccuts_medium, ciccuts_loose;
196 >    if(ctrl.eleSele=="cic") {
197 >      if( ctrl.eleSeleScheme == "mediumloose" ) {
198 >        ciccuts_medium = getCiCCuts("medium");
199 >        unsigned failsCICMedium = failsCicSelection(ctrl, ele, ciccuts_medium, ctrl.kinematics);
200 >        ciccuts_loose = getCiCCuts("loose");
201 >        unsigned failsCICLoose = failsCicSelection(ctrl, ele, ciccuts_loose, ctrl.kinematics);
202 >        failsCIC = ( failsCICLoose > 0 && failsCICMedium > 0 );
203 >        if( !failsCICMedium ) isEleTight=1;
204 >      }
205 >      else {
206 >        ciccuts_tight = getCiCCuts(ctrl.eleSeleScheme);
207 >        failsCIC = failsCicSelection(ctrl, ele, ciccuts_tight, ctrl.kinematics);
208 >        if( !failsCIC ) isEleTight=1;
209 >      }
210 >      FAIL = failsCIC;
211 >    }
212 >
213 >    LikStruct likcuts;
214 >    unsigned failsLike=0;
215 >    if(ctrl.eleSele=="lik") {
216 >      likcuts = getLikCuts(ctrl.eleSeleScheme);
217 >      failsLike = failsLikelihoodSelection(ele, likcuts, ctrl.kinematics);
218 >      FAIL = failsLike;
219 >    }
220 >    unsigned failsBDT=0;
221 >    if(ctrl.eleSele=="bdt") {
222 >      if( ctrl.eleSeleScheme == "mediumloose" ) {
223 >        unsigned failsBDTMedium = failsBDTSelection(ctrl,"medium",ele);
224 >        unsigned failsBDTLoose  = failsBDTSelection(ctrl,"loose",ele);
225 >        failsBDT = ( failsBDTLoose > 0 && failsBDTMedium > 0 );
226 >        if( !failsBDTMedium ) isEleTight=1;
227 >      } else {
228 >        failsBDT = failsBDTSelection(ctrl,"tight",ele);
229 >        if( !failsBDT ) isEleTight=1;
230 >      }
231 >      FAIL = failsBDT;
232 >    }
233 >    unsigned  failsSi=0;
234 >    if(ctrl.eleSele=="si") {
235 >      failsSi = failsSiMVAElectronSelection(ctrl, ele, 0.95, ctrl.kinematics);
236 >      FAIL = failsSi;
237 >    }
238 >
239 >
240  
151    if ( ctrl.cic ) { FAIL = failsCIC;}
152    else            { FAIL = failsLike; }
241  
242      if( ctrl.debug ){
243        cout << "CIC category: " << cicCategory(ele)
# Line 157 | Line 245 | unsigned fails_HZZ4L_selection(ControlFl
245             << "\tFAIL:  0x"     << hex << FAIL      << dec
246             << "\tfailsCIC:  0x" << hex << failsCIC  << dec
247             << "\tfailsLike: 0x" << hex << failsLike << dec
248 +           << "\tfailsBDT:  0x" << hex << failsBDT << dec
249             << "\tscEt: " << ele->scEt
250             << "\tscEta: " << ele->scEta
251             << "\tncluster: " << ele->ncluster
# Line 174 | Line 263 | unsigned fails_HZZ4L_selection(ControlFl
263        tmplep.isoTrk  = ele->trkIso03;
264        tmplep.isoEcal = ele->emIso03;
265        tmplep.isoHcal = ele->hadIso03;
266 +      tmplep.isoPF03 = ele->pfIso03;
267 +      tmplep.isoPF04 = ele->pfIso04;
268        tmplep.ip3dSig = ele->ip3dSig;
269        tmplep.is4l    = false;
270 +      tmplep.isTight = isEleTight;
271        tmplep.isEB    = ele->isEB;
272        lepvec.push_back(tmplep);
273        if( ctrl.debug ) { cout << "\telectron passes ... " << endl; }
# Line 276 | Line 368 | unsigned fails_HZZ4L_selection(ControlFl
368    Double_t BestZ2Mass = -1;
369    if( ctrl.debug ) cout << "looking for a Z2 ... out of " << lepvec.size() << " leptons" <<endl;
370    for(int i = 0; i < lepvec.size(); ++i) {
371 +    if( abs(lepvec[i].type) == 11 &&
372 +        ctrl.eleSeleScheme == "mediumloose" &&
373 +        !(lepvec[i].isTight) ) continue;
374 +
375      for(int j = i+1; j < lepvec.size(); ++j) {
376 +      if( abs(lepvec[j].type) == 11 &&
377 +          ctrl.eleSeleScheme == "mediumloose" &&
378 +          !(lepvec[j].isTight) ) continue;
379 +
380        //            cout << "i: " << i << "\tj: " << j << endl;
381        if (i == Z1LeptonPlusIndex || i == Z1LeptonMinusIndex) {
382          //            cout << "\ti matches a Z1 index, skipping ..." << endl;
# Line 316 | Line 416 | unsigned fails_HZZ4L_selection(ControlFl
416              if (!(dilepton.M() > 12.0)) continue;
417              if (!(fourLepton.M() > 100.0)) continue;
418  
419 <            
419 >            /*
420              //for 4e and 4mu, require at least 1 of the other opp sign lepton pairs have mass > 12
421              if (fabs(lepvec[i].type) == fabs(lepvec[Z1LeptonPlusIndex].type)) {
422                TLorentzVector pair1 = Z1LeptonPlus+leptonMinus;
# Line 324 | Line 424 | unsigned fails_HZZ4L_selection(ControlFl
424                if( ctrl.debug ) cout << "pair1: " << pair1.M() << "\tpair2: "<< pair2.M() << endl;
425                if (!(pair1.M() > 12 || pair2.M() > 12)) continue;
426              }
427 <            
427 >            */
428 >
429              //Disambiguiation is done by choosing the pair with the largest ptMax and largest ptMin
430              if (Z2LeptonPlusIndex < 0) {
431                if (lepvec[i].charge > 0) {
# Line 403 | Line 504 | unsigned fails_HZZ4L_selection(ControlFl
504          //***************************************************************
505          bool failiso=false;
506  
507 <        /*
407 <        int i,j;
408 <        i=Z1LeptonPlusIndex;
409 <        j=Z1LeptonMinusIndex;
410 <        float RIso1 = (lepvec[i].isoTrk+lepvec[i].isoEcal+lepvec[i].isoHcal)/lepvec[i].vec.Pt();
411 <        float RIso2 = (lepvec[j].isoTrk+lepvec[j].isoEcal+lepvec[j].isoHcal)/lepvec[j].vec.Pt();
412 <        float comboIso12 = RIso1 + RIso2;
413 <        i=Z2LeptonPlusIndex;
414 <        j=Z2LeptonMinusIndex;
415 <        float RIso3 = (lepvec[i].isoTrk+lepvec[i].isoEcal+lepvec[i].isoHcal)/lepvec[i].vec.Pt();
416 <        float RIso4 = (lepvec[j].isoTrk+lepvec[j].isoEcal+lepvec[j].isoHcal)/lepvec[j].vec.Pt();
417 <        float comboIso34 = RIso3 + RIso4;
418 <        if( comboIso12 > 0.35 || comboIso34 > 0.35 ) {
419 <              failiso = true;
420 <        }
421 <        */
507 >        if( ctrl.isoScheme == "pf" ) {
508  
509 <        float rho = info->rho;
510 <        for( int i=0; i<lepvec.size(); i++ ) {
511 <          if( !(lepvec[i].is4l) ) continue;
509 >          for( int i=0; i<lepvec.size(); i++ ) {
510 >
511 >            if( !(lepvec[i].is4l) ) continue;
512 >
513 >            if( abs(lepvec[i].type) == 11 ) {
514 >              float reliso = lepvec[i].isoPF04/lepvec[i].vec.Pt();
515 >              if( lepvec[i].isEB && lepvec[i].vec.Pt() > 20 && reliso > PFISO_ELE_LOOSE_EB_HIGHPT ) {
516 >                failiso = true;
517 >                break;
518 >              }
519 >              if( lepvec[i].isEB && lepvec[i].vec.Pt() < 20 && reliso > PFISO_ELE_LOOSE_EB_LOWPT ) {
520 >                failiso = true;
521 >                break;
522 >              }
523 >              if( !(lepvec[i].isEB) && lepvec[i].vec.Pt() > 20 && reliso > PFISO_ELE_LOOSE_EE_HIGHPT ) {
524 >                failiso = true;
525 >                break;
526 >              }
527 >              if( !(lepvec[i].isEB) && lepvec[i].vec.Pt() < 20 && reliso > PFISO_ELE_LOOSE_EE_LOWPT ) {
528 >                failiso = true;
529 >                break;
530 >              }
531 >            }
532 >
533 >            if( abs(lepvec[i].type) == 13 ) {
534 >
535 >              float reliso = lepvec[i].isoPF03/lepvec[i].vec.Pt();
536 >              if( lepvec[i].isEB && lepvec[i].vec.Pt() > 20 && reliso > PFISO_MU_LOOSE_EB_HIGHPT ) {  //0.13
537 >                failiso = true;
538 >                break;
539 >              }
540 >              if( lepvec[i].isEB && lepvec[i].vec.Pt() < 20 && reliso > PFISO_MU_LOOSE_EB_LOWPT ) { //0.06
541 >                failiso = true;
542 >                break;
543 >              }
544 >              if( !(lepvec[i].isEB) && lepvec[i].vec.Pt() > 20 && reliso > PFISO_MU_LOOSE_EE_HIGHPT ) { //0.09
545 >                failiso = true;
546 >                break;
547 >              }
548 >              if( !(lepvec[i].isEB) && lepvec[i].vec.Pt() < 20 && reliso > PFISO_MU_LOOSE_EE_LOWPT ) { //0.05
549 >                failiso = true;
550 >                break;
551 >              }
552 >            }
553 >          }  
554 >        } else if ( ctrl.isoScheme == "pairwise" ) {
555 >          float rho = info->rho;
556 >          for( int i=0; i<lepvec.size(); i++ ) {
557 >            if( !(lepvec[i].is4l) ) continue;
558              float effArea_ecal_i, effArea_hcal_i;
559              if( lepvec[i].isEB ) {
560                if( lepvec[i].type == 11 ) {
# Line 498 | Line 630 | unsigned fails_HZZ4L_selection(ControlFl
630                  //            break;
631                }
632              }
633 +          }
634          }
635 +
636 +
637          if( failiso ) {
638            evtfail |= ( 1<<EVTFAIL_ISOLATION );
639            return evtfail;
# Line 550 | Line 685 | unsigned fails_HZZ4L_selection(ControlFl
685            //      continue;
686          }
687          
688 <        int channel;
688 >        unsigned channel;
689          if( lepvec[Z1LeptonMinusIndex].type == 11 && lepvec[Z2LeptonMinusIndex].type == 11 ) channel=0;
690          if( lepvec[Z1LeptonMinusIndex].type == 13 && lepvec[Z2LeptonMinusIndex].type == 13 ) channel=1;
691          if( (lepvec[Z1LeptonMinusIndex].type == 11 && lepvec[Z2LeptonMinusIndex].type == 13) ||
692              (lepvec[Z1LeptonMinusIndex].type == 13 && lepvec[Z2LeptonMinusIndex].type == 11)) channel=2;
693          
694  
695 <        
695 >
696          if( passtuple != NULL ) {
697 <          passtuple->Fill( info->runNum,
698 <                           info->evtNum,
699 <                           info->lumiSec,
700 <                           channel,
701 <                           Z1Candidate.M(),
702 <                           Z2Candidate.M(),
703 <                           ZZSystem.M(),
704 <                           ZZSystem.Pt(),
705 <                           eventweight);
697 >          unsigned run   = info->runNum;
698 >          unsigned evt   = info->evtNum;
699 >          unsigned lumi  = info->lumiSec;
700 >          unsigned chan  = channel;
701 >          double   w     = eventweight;
702 >          float mZ1      = Z1Candidate.M() ;
703 >          float mZ2      = Z2Candidate.M() ;
704 >          float m4l      = ZZSystem.M() ;
705 >          float pt4l     = ZZSystem.Pt() ;
706 >          unsigned tZ1   = abs(lepvec[Z1LeptonMinusIndex].type);
707 >          unsigned tZ2   = abs(lepvec[Z2LeptonMinusIndex].type);
708 >          passtuple->SetBranchAddress("channel",  &channel);
709 >          passtuple->SetBranchAddress("run",  &run);
710 >          passtuple->SetBranchAddress("evt",  &evt);
711 >          passtuple->SetBranchAddress("lumi", &lumi);
712 >          passtuple->SetBranchAddress("mZ1",  &mZ1);
713 >          passtuple->SetBranchAddress("mZ2",  &mZ2);
714 >          passtuple->SetBranchAddress("tZ1",  &tZ1);
715 >          passtuple->SetBranchAddress("tZ2",  &tZ2);
716 >          passtuple->SetBranchAddress("m4l",  &m4l);
717 >          passtuple->SetBranchAddress("pt4l", &pt4l);
718 >          passtuple->SetBranchAddress("w",    &w);
719 >          if( ctrl.mc )           passtuple->SetBranchAddress("gchannel",  &gchannel);
720 >          passtuple->Fill( );
721          }
722  
723          if( ctrl.debug ) cout  << "run: " << info->runNum  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines