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.11 by khahn, Mon Oct 17 16:23:43 2011 UTC vs.
Revision 1.16 by khahn, Mon Nov 7 05:28:06 2011 UTC

# Line 7 | Line 7
7   #include "HZZLikelihoodElectronSelection.h"
8   #include "HZZBDTElectronSelection.h"
9   #include "RunLumiRangeMap.h"
10 + #include "EfficiencyWeightsInterface.h"
11  
12   RunLumiRangeMap rlrm;
13 + TH1D * hpu;
14  
15 +
16 + // #include "TH2D.h"
17 + // extern TH2D * h_mu_eff_idiso_2011a;
18 + // extern TH2D * h_mu_eff_idiso_s11;
19 + // extern TH2D * h_mu_effdata_trigger_doublemu7_2011a;
20 + // extern TH2D * h_mu_effdata_trigger_doublemu13_8_leading_2011a;
21 + // extern TH2D * h_mu_effdata_trigger_doublemu13_8_trailing_2011a;
22 +
23 + // unsigned getGenChannel(mithep::TGenInfo * ginfo) {
24 + //   int gchannel=-1;
25 + //   if( abs(ginfo->id_1_a) == EGenType::kElectron && abs(ginfo->id_1_b) == EGenType::kElectron )  gchannel=0;
26 + //   else if( abs(ginfo->id_1_a) == EGenType::kMuon && abs(ginfo->id_1_b) == EGenType::kMuon ) gchannel=1;
27 + //   else if( (abs(ginfo->id_1_a) == EGenType::kElectron && abs(ginfo->id_1_b) == EGenType::kMuon) ||
28 + //         (abs(ginfo->id_1_a) == EGenType::kMuon && abs(ginfo->id_1_b) == EGenType::kElectron) ) gchannel=2;
29 +  
30 + //   return gchannel;
31 + // };
32 +
33   void initRunLumiRangeMap() {
34    rlrm.AddJSONFile(std::string("./data/Cert_136033-149442_7TeV_Apr21ReReco_Collisions10_JSON.txt"));
35    //  rlrm.AddJSONFile(std::string("./data/Cert_160404-173244_7TeV_PromptReco_Collisions11_JSON_v2.txt"));
36    rlrm.AddJSONFile(std::string("./data/Cert_160404-178078_7TeV_PromptReco_Collisions11_JSON.txt"));
37    rlrm.AddJSONFile(std::string("./data/Cert_160404-163869_7TeV_May10ReReco_Collisions11_JSON_v3.txt"));  
38    rlrm.AddJSONFile(std::string("./data/Cert_170249-172619_7TeV_ReReco5Aug_Collisions11_JSON.txt"));  
39 +  TFile * puf = new TFile("data/PileupReweighting.Summer11DYmm_To_Run2011A.root");
40 +  hpu = (TH1D*)(puf->Get("puWeights"));
41 + };
42 +
43 + void initRunLumiRangeMap(RunLumiRangeMap &rlrm) {
44 +  cout << "adding JSONS ... "  << endl;
45 +  rlrm.AddJSONFile(std::string("./data/Cert_136033-149442_7TeV_Apr21ReReco_Collisions10_JSON.txt"));
46 +  //  rlrm.AddJSONFile(std::string("./data/Cert_160404-173244_7TeV_PromptReco_Collisions11_JSON_v2.txt"));
47 +  rlrm.AddJSONFile(std::string("./data/Cert_160404-178078_7TeV_PromptReco_Collisions11_JSON.txt"));
48 +  rlrm.AddJSONFile(std::string("./data/Cert_160404-163869_7TeV_May10ReReco_Collisions11_JSON_v3.txt"));  
49 +  rlrm.AddJSONFile(std::string("./data/Cert_170249-172619_7TeV_ReReco5Aug_Collisions11_JSON.txt"));  
50   };
51  
52 + // unsigned fails_HZZ4L_selection(ControlFlags &ctrl,           // input control
53 + //                             mithep::TEventInfo *info,     // input event inof
54 + //                             TClonesArray *electronArr,    // input electrons
55 + //                             TClonesArray *muonArr,        // input muons
56 + //                             double eventweight,           // weight
57 + //                             TTree * passtuple ) {
58 +
59 + //   fails_HZZ4L_selection( ctrl, info, electronArr, muonArr, eventweight, passtuple, NULL );
60 +
61 + // };
62 +
63 +
64 +
65 + // unsigned fails_HZZ4L_selection(ControlFlags &ctrl,           // input control
66 + //                             mithep::TEventInfo *info,     // input event inof
67 + //                             TClonesArray *electronArr,    // input electrons
68 + //                             TClonesArray *muonArr,        // input muons
69 + //                             double eventweight,           // weight
70 + //                             LabVectors  *l ) {
71 +
72 + //   fails_HZZ4L_selection( ctrl, info, electronArr, muonArr, eventweight, NULL, l );
73 +
74 + // };
75 +
76 +
77   unsigned fails_HZZ4L_selection(ControlFlags &ctrl,           // input control
78 <                               mithep::TEventInfo *info,     // input event inof
78 >                               mithep::TGenInfo *ginfo ,     // input gen info
79 >                               mithep::TEventInfo *info,     // input event info
80                                 TClonesArray *electronArr,    // input electrons
81                                 TClonesArray *muonArr,        // input muons
82                                 double eventweight,           // weight
83                                 TTree * passtuple ) {
84  
85 <  fails_HZZ4L_selection( ctrl, info, electronArr, muonArr, eventweight, passtuple, NULL );
85 >  fails_HZZ4L_selection( ctrl, info, electronArr, muonArr, eventweight, passtuple, NULL, NULL );
86  
87   };
88  
89   unsigned fails_HZZ4L_selection(ControlFlags &ctrl,           // input control
90 <                               mithep::TEventInfo *info,     // input event inof
90 >                               mithep::TEventInfo *info,     // input event info
91                                 TClonesArray *electronArr,    // input electrons
92                                 TClonesArray *muonArr,        // input muons
93                                 double eventweight,           // weight
94 <                               LabVectors  *l ) {
95 <
96 <  fails_HZZ4L_selection( ctrl, info, electronArr, muonArr, eventweight, NULL, l );
97 <
41 < };
94 >                               TTree * passtuple,
95 >                               LabVectors * l ) {
96 >  fails_HZZ4L_selection( ctrl, info, electronArr, muonArr, eventweight, passtuple, l, NULL );
97 > }
98  
99  
100   unsigned fails_HZZ4L_selection(ControlFlags &ctrl,           // input control
101 <                               mithep::TEventInfo *info,     // input event inof
101 >                               mithep::TEventInfo *info,     // input event info
102                                 TClonesArray *electronArr,    // input electrons
103                                 TClonesArray *muonArr,        // input muons
104                                 double eventweight,           // weight
105                                 TTree * passtuple,
106 <                               LabVectors * l) {       // output ntuple
106 >                               LabVectors * l=NULL,
107 >                               TClonesArray *jetArr=NULL ) {       // output ntuple
108  
109    unsigned evtfail = 0x0;
110 +  unsigned gchannel=0xdeaddead;
111 +
112 + //   if( ctrl.mc && ginfo != NULL ) {
113 + //     gchannel = getGenChannel(ginfo);
114 + //   }
115  
116  
117    if( ctrl.debug ) {
# Line 59 | Line 121 | unsigned fails_HZZ4L_selection(ControlFl
121           << endl;
122    }
123  
124 +  unsigned npu; double npuw;
125    if( !ctrl.mc ) {
126      // not accounting for overlap atm
127      RunLumiRangeMap::RunLumiPairType rl(info->runNum, info->lumiSec);      
# Line 67 | Line 130 | unsigned fails_HZZ4L_selection(ControlFl
130        evtfail |= (1<<EVTFAIL_JSON);
131        return evtfail;
132      }
133 +  } else {
134 +    npu = info->nPU;
135 +    npuw = hpu->GetBinContent(hpu->FindBin(npu));
136    }
137    
138    
# Line 78 | Line 144 | unsigned fails_HZZ4L_selection(ControlFl
144    //********************************************************
145    if( !ctrl.mc ) {
146      //  if( !(passHLT(info->triggerBits, info->runNum, channel) )  ) {
147 <    if( !(passHLT(info->triggerBits, info->runNum, 999) )  ) {
148 <      evtfail |= (1<<EVTFAIL_TRIGGER);
149 <      return evtfail;
150 <    }  
147 > //     if( !(passHLT(info->triggerBits, info->runNum, 999) )  ) {
148 > //       evtfail |= (1<<EVTFAIL_TRIGGER);
149 > //       return evtfail;
150 > //     }        
151    } else {
152      if( !(passHLTMC(info->triggerBits)) ) {
153        evtfail |= (1<<EVTFAIL_TRIGGER);
# Line 109 | Line 175 | unsigned fails_HZZ4L_selection(ControlFl
175      const mithep::TMuon *mu = (mithep::TMuon*)((*muonArr)[i]);      
176      unsigned muonfail;
177      if( ctrl.muSele == "ksWW" )
178 <      muonfail = passMuonSelection(mu);
178 >      muonfail = passKSMuonSelection(mu);
179      else
180        muonfail = passMuonSelectionZZ(mu);
181      if( ctrl.debug ) {
# Line 120 | Line 186 | unsigned fails_HZZ4L_selection(ControlFl
186      }
187      if ( !muonfail ) {
188        SimpleLepton tmplep;
189 <      tmplep.vec.SetPtEtaPhiM(mu->pt,
189 >
190 >      float pt = mu->pt;
191 >      if( ctrl.do_escale_up   ) pt*=(1.01);
192 >      if( ctrl.do_escale_down ) pt*=(0.99);
193 >
194 >      tmplep.vec.SetPtEtaPhiM(pt,
195                                mu->eta,
196                                mu->phi,
197                                105.658369e-3);
198 +
199        tmplep.type    = 13;
200        tmplep.index   = i;
201        tmplep.charge  = mu->q;
# Line 146 | Line 218 | unsigned fails_HZZ4L_selection(ControlFl
218    for(Int_t i=0; i<electronArr->GetEntries(); i++) {
219      const mithep::TElectron *ele = (mithep::TElectron*)((*electronArr)[i]);
220  
221 +    if( !(isEleFO(ctrl,ele) ) ) continue;
222 +    if( ele->pt < 7 ) continue; //move this to ID
223 +
224      Bool_t isMuonOverlap = kFALSE;
225      for (int k=0; k<lepvec.size(); ++k) {
226        TVector3 tmplep;
# Line 167 | Line 242 | unsigned fails_HZZ4L_selection(ControlFl
242          unsigned failsCICMedium = failsCicSelection(ctrl, ele, ciccuts_medium, ctrl.kinematics);
243          ciccuts_loose = getCiCCuts("loose");
244          unsigned failsCICLoose = failsCicSelection(ctrl, ele, ciccuts_loose, ctrl.kinematics);
245 <        failsCIC = ( failsCICLoose | failsCICMedium );
245 >        failsCIC = ( failsCICLoose > 0 && failsCICMedium > 0 );
246          if( !failsCICMedium ) isEleTight=1;
247        }
248        else {
# Line 190 | Line 265 | unsigned fails_HZZ4L_selection(ControlFl
265        if( ctrl.eleSeleScheme == "mediumloose" ) {
266          unsigned failsBDTMedium = failsBDTSelection(ctrl,"medium",ele);
267          unsigned failsBDTLoose  = failsBDTSelection(ctrl,"loose",ele);
268 <        failsBDT = ( failsBDTLoose | failsBDTMedium );
268 >        failsBDT = ( failsBDTLoose > 0 && failsBDTMedium > 0 );
269          if( !failsBDTMedium ) isEleTight=1;
270        } else {
271          failsBDT = failsBDTSelection(ctrl,"tight",ele);
# Line 198 | Line 273 | unsigned fails_HZZ4L_selection(ControlFl
273        }
274        FAIL = failsBDT;
275      }
201    unsigned  failsSi=0;
202    if(ctrl.eleSele=="si") {
203      failsSi = failsSiMVAElectronSelection(ctrl, ele, 0.95, ctrl.kinematics);
204      FAIL = failsSi;
205    }
206
207
276  
277  
278      if( ctrl.debug ){
# Line 221 | Line 289 | unsigned fails_HZZ4L_selection(ControlFl
289      }
290      if ( !FAIL && !isMuonOverlap ) {
291        SimpleLepton tmplep;
292 <      tmplep.vec.SetPtEtaPhiM( ele->pt,
292 >
293 >      float pt = ele->pt;
294 >      if( ctrl.do_escale_up   ) pt*=(1.02);
295 >      if( ctrl.do_escale_down ) pt*=(0.98);
296 >
297 >      tmplep.vec.SetPtEtaPhiM( pt,
298                                 ele->eta,
299                                 ele->phi,
300                                 0.51099892e-3 );
# Line 244 | Line 317 | unsigned fails_HZZ4L_selection(ControlFl
317    
318    sort( lepvec.begin(), lepvec.end(), SimpleLepton::lep_pt_sort );
319  
320 +  for( int i=0; i<lepvec.size(); i++ ) {
321 +    //
322 +    //  check for a matched btagged jet
323 +    //
324 +    lepvec[i].tche = -1;
325 +    lepvec[i].tchp = -1;
326 +    lepvec[i].csv = -1;
327 +    lepvec[i].csvMva = -1;
328 +
329 +    if( jetArr != NULL ) {
330 +      for(int k=0; k<jetArr->GetEntries(); k++) {
331 +        const mithep::TJet *jet = (mithep::TJet*)((*jetArr)[k]);      
332 +        TVector3 jvec;
333 +        jvec.SetPtEtaPhi(jet->pt, jet->eta, jet->phi);
334 +        if( jvec.DrEtaPhi( lepvec[i].vec.Vect()) < 0.2 ) {
335 +          lepvec[i].tche = jet->tche;
336 +          lepvec[i].tchp = jet->tchp;
337 +          lepvec[i].csv = jet->csv;
338 +          lepvec[i].csvMva = jet->csvMva;
339 +        }
340 +      }
341 +    }
342 +  }
343 +
344    int nmu=0, nele=0;
345    for( int i=0; i<lepvec.size(); i++ ) {
346      if( abs(lepvec[i].type) == 11 ) nele++;
# Line 500 | Line 597 | unsigned fails_HZZ4L_selection(ControlFl
597  
598              if( abs(lepvec[i].type) == 13 ) {
599  
600 +              /*
601                float reliso = lepvec[i].isoPF03/lepvec[i].vec.Pt();
602 <              if( lepvec[i].isEB && lepvec[i].vec.Pt() > 20 && reliso > PFISO_MU_TIGHT_EB_HIGHPT ) {  //0.13
602 >              if( lepvec[i].isEB && lepvec[i].vec.Pt() > 20 && reliso > PFISO_MU_LOOSE_EB_HIGHPT ) {  //0.13
603                  failiso = true;
604                  break;
605                }
606 <              if( lepvec[i].isEB && lepvec[i].vec.Pt() < 20 && reliso > PFISO_MU_TIGHT_EB_LOWPT ) { //0.06
606 >              if( lepvec[i].isEB && lepvec[i].vec.Pt() < 20 && reliso > PFISO_MU_LOOSE_EB_LOWPT ) { //0.06
607                  failiso = true;
608                  break;
609                }
610 <              if( !(lepvec[i].isEB) && lepvec[i].vec.Pt() > 20 && reliso > PFISO_MU_TIGHT_EE_HIGHPT ) { //0.09
610 >              if( !(lepvec[i].isEB) && lepvec[i].vec.Pt() > 20 && reliso > PFISO_MU_LOOSE_EE_HIGHPT ) { //0.09
611                  failiso = true;
612                  break;
613                }
614 <              if( !(lepvec[i].isEB) && lepvec[i].vec.Pt() < 20 && reliso > PFISO_MU_TIGHT_EE_LOWPT ) { //0.05
614 >              if( !(lepvec[i].isEB) && lepvec[i].vec.Pt() < 20 && reliso > PFISO_MU_LOOSE_EE_LOWPT ) { //0.05
615                  failiso = true;
616                  break;
617                }
618 +              */
619              }
620            }  
621          } else if ( ctrl.isoScheme == "pairwise" ) {
# Line 653 | Line 752 | unsigned fails_HZZ4L_selection(ControlFl
752            //      continue;
753          }
754          
755 <        int channel;
755 >        unsigned channel;
756          if( lepvec[Z1LeptonMinusIndex].type == 11 && lepvec[Z2LeptonMinusIndex].type == 11 ) channel=0;
757          if( lepvec[Z1LeptonMinusIndex].type == 13 && lepvec[Z2LeptonMinusIndex].type == 13 ) channel=1;
758          if( (lepvec[Z1LeptonMinusIndex].type == 11 && lepvec[Z2LeptonMinusIndex].type == 13) ||
759              (lepvec[Z1LeptonMinusIndex].type == 13 && lepvec[Z2LeptonMinusIndex].type == 11)) channel=2;
760          
761  
762 +        double w_offline=-1, werr_offline=0;
763 +        double w_online=-1, werr_online=0;
764  
765 +        if( ctrl.mc ) {
766 +
767 +          vector< pair <double,double> > wlegs; // pair here is eff & err
768 +          vector< pair <float,float> > mvec;  // pair here is eta & pt
769 +          // now deal with medium vs loose
770 +          //      vector< pair <float,float> > evec;  // pair here is eta & pt
771 +          vector< pair< bool, pair <float,float> > > evec;  // pair here is eta & pt
772 +
773 +          for( int k=0; k<lepvec.size(); k++ ) {
774 +            if( !(lepvec[k].is4l) ) continue;
775 +            if( abs(lepvec[k].type) == 13 ) {
776 +              mvec.push_back( std::pair<float,float> (fabs(lepvec[k].vec.Eta()), lepvec[k].vec.Pt()) );
777 +              wlegs.push_back( muonPerLegOfflineEfficiencyWeight( fabs(lepvec[k].vec.Eta()),
778 +                                                                  lepvec[k].vec.Pt() ) );
779 +            } else {
780 +
781 +              // now deal with medium vs loose
782 +              //              evec.push_back( std::pair<float,float> (fabs(lepvec[k].vec.Eta()), lepvec[k].vec.Pt()) );
783 +
784 +              std::pair<float,float> tmppair(fabs(lepvec[k].vec.Eta()), lepvec[k].vec.Pt());
785 +              evec.push_back( std::pair<bool, std::pair<float,float> > (lepvec[k].isTight, tmppair) );
786 +
787 +              wlegs.push_back( elePerLegOfflineEfficiencyWeight(  fabs(lepvec[k].vec.Eta()),
788 +                                                                 lepvec[k].vec.Pt() ) );
789 +            }
790 +          }
791 +
792 +          pair<double,double> offpair = getOfflineEfficiencyWeight( wlegs );
793 +          w_offline    = offpair.first;
794 +          werr_offline = offpair.second;
795 +
796 +          pair<double,double> onpair  = getOnlineEfficiencyWeight( mvec, evec );
797 +          w_online    = onpair.first;
798 +          werr_online = onpair.second;
799 +
800 +        } // if mc
801 +
802 +
803 +        if( l != NULL ) {
804 +          l->vec4l  = ZZSystem;
805 +          l->vecz1  = Z1Candidate;
806 +          l->vecz2  = Z2Candidate;
807 +          l->vecl1p = lepvec[Z1LeptonPlusIndex].vec;
808 +          l->vecl1m = lepvec[Z1LeptonMinusIndex].vec;
809 +          l->vecl2p = lepvec[Z2LeptonPlusIndex].vec;
810 +          l->vecl2m = lepvec[Z2LeptonMinusIndex].vec;
811 +        }
812          if( passtuple != NULL ) {
813            unsigned run   = info->runNum;
814            unsigned evt   = info->evtNum;
# Line 673 | Line 821 | unsigned fails_HZZ4L_selection(ControlFl
821            float pt4l     = ZZSystem.Pt() ;
822            unsigned tZ1   = abs(lepvec[Z1LeptonMinusIndex].type);
823            unsigned tZ2   = abs(lepvec[Z2LeptonMinusIndex].type);
824 +          float l3tche   = lepvec[Z2LeptonMinusIndex].tche;
825 +          float l4tche   = lepvec[Z2LeptonPlusIndex].tche;
826 +          float l3tchp   = lepvec[Z2LeptonMinusIndex].tchp;
827 +          float l4tchp   = lepvec[Z2LeptonPlusIndex].tchp;
828 +          float l3csv    = lepvec[Z2LeptonMinusIndex].csv;
829 +          float l4csv    = lepvec[Z2LeptonPlusIndex].csv;
830 +          float l3csvMva = lepvec[Z2LeptonMinusIndex].csvMva;
831 +          float l4csvMva = lepvec[Z2LeptonPlusIndex].csvMva;
832 +
833 +
834 +          passtuple->SetBranchAddress("channel",  &channel);
835            passtuple->SetBranchAddress("run",  &run);
836            passtuple->SetBranchAddress("evt",  &evt);
837            passtuple->SetBranchAddress("lumi", &lumi);
# Line 683 | Line 842 | unsigned fails_HZZ4L_selection(ControlFl
842            passtuple->SetBranchAddress("m4l",  &m4l);
843            passtuple->SetBranchAddress("pt4l", &pt4l);
844            passtuple->SetBranchAddress("w",    &w);
845 +          if( ctrl.mc ) {
846 +            passtuple->SetBranchAddress("woff", &w_offline );
847 +            passtuple->SetBranchAddress("werroff", &werr_offline );
848 +            passtuple->SetBranchAddress("won", &w_online );
849 +            passtuple->SetBranchAddress("werron", &werr_online );
850 +            passtuple->SetBranchAddress("npu", &npu );
851 +            passtuple->SetBranchAddress("npuw", &npuw );
852 +            passtuple->SetBranchAddress("gchannel",  &gchannel);
853 +          }
854 +          if( ctrl.btag ) {
855 +          passtuple->SetBranchAddress("l3tche",    &l3tche);
856 +          passtuple->SetBranchAddress("l4tche",    &l4tche);
857 +          passtuple->SetBranchAddress("l3tchp",    &l3tchp);
858 +          passtuple->SetBranchAddress("l4tchp",    &l4tchp);
859 +          passtuple->SetBranchAddress("l3csv",     &l3csv);
860 +          passtuple->SetBranchAddress("l4csv",     &l4csv);
861 +          passtuple->SetBranchAddress("l3csvMva",  &l3csvMva);
862 +          passtuple->SetBranchAddress("l4csvMva",  &l4csvMva);
863 +          }
864 +
865            passtuple->Fill( );
866          }
867  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines