ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitHzz4l/NonMCBackground/src/SelectionEMU.cc
Revision: 1.1
Committed: Tue Feb 14 01:30:21 2012 UTC (13 years, 3 months ago) by khahn
Content type: text/plain
Branch: MAIN
Log Message:
Z->tautau for low pt eles

File Contents

# User Rev Content
1 khahn 1.1 #include "SelectionStatus.h"
2     #include "EventData.h"
3     #include "SimpleLepton.h"
4     #include "EfficiencyWeightsInterface.h"
5    
6     #include "HZZBDTElectronSelection.h"
7     #include "IsolationSelection.h"
8     #include "PassHLT.h"
9     #include "SelectionEMU.h"
10    
11     #include "ExternData.h"
12     #include "SelectionDefs.h"
13    
14    
15    
16     // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
17     // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
18     EventData apply_EMU_selection(ControlFlags &ctrl, // input control
19     mithep::TEventInfo *info, // input event info
20     TClonesArray *electronArr, // input electrons
21     SelectionStatus (*ElectronPreSelector)( ControlFlags &, const mithep::TElectron*),
22     SelectionStatus (*ElectronIDSelector)( ControlFlags &, const mithep::TElectron*),
23     SelectionStatus (*ElectronIsoSelector)( ControlFlags &, const mithep::TElectron*),
24     TClonesArray *muonArr, // input muons
25     SelectionStatus (*MuonPreSelector)( ControlFlags &, const mithep::TMuon*),
26     SelectionStatus (*MuonIDSelector)( ControlFlags &, const mithep::TMuon*),
27     SelectionStatus (*MuonIsoSelector)( ControlFlags &, const mithep::TMuon*) )
28     // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
29     // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30     {
31    
32     EventData ret;
33     unsigned evtfail = 0x0;
34     TRandom3 r;
35    
36     if( ctrl.debug ) {
37     cout << "Run: " << info->runNum
38     << "\tEvt: " << info->evtNum
39     << "\tLumi: " << info->lumiSec
40     << endl;
41     }
42    
43     if( !ctrl.mc ) {
44     // not accounting for overlap atm
45     RunLumiRangeMap::RunLumiPairType rl(info->runNum, info->lumiSec);
46     if( !(rlrm.HasRunLumi(rl)) ) {
47     if( ctrl.debug ) cout << "\tfails JSON" << endl;
48     ret.status.setStatus(0);
49     return ret;
50     }
51     }
52    
53    
54     //********************************************************
55     // Trigger
56     //********************************************************
57     if( !ctrl.mc ) {
58     //if( !(passHLT(info->triggerBits, info->runNum, channel) ) ) {
59     // if( !(passHLT(info->triggerBits, info->runNum, 999) ) ) {
60     // if( ctrl.debug ) cout << "\tfails trigger" << endl;
61     // evtfail |= (1<<EVTFAIL_TRIGGER);
62     // ret.status.setStatus(0);
63     // return ret;
64     // }
65     }
66     if( ctrl.debug ) {
67     cout << "presel nlep: " << muonArr->GetEntries() + electronArr->GetEntries()
68     << "\tnmuon: " << muonArr->GetEntries()
69     << "\tnelectron: " << electronArr->GetEntries()
70     << endl;
71     }
72    
73     //********************************************************
74     // Lepton Selection
75     //********************************************************
76     vector<SimpleLepton> lepvec;
77     if( muonArr->GetEntries() != 1 && electronArr->GetEntries() != 1 ) {
78     ret.status.setStatus(0);
79     return ret;
80     }
81    
82     //
83     if( ctrl.debug ) cout << "\tnMuons: " << muonArr->GetEntries() << endl;
84     //----------------------------------------------------
85     for(Int_t i=0; i<muonArr->GetEntries(); i++)
86     {
87     const mithep::TMuon *mu = (mithep::TMuon*)((*muonArr)[i]);
88    
89     SelectionStatus musel;
90     if(ctrl.debug) cout << "musel.status before anything: " << musel.getStatus() << endl;
91     musel |= (*MuonPreSelector)(ctrl,mu);
92     if(ctrl.debug) cout << "musel.status after presel: " << musel.getStatus() << endl;
93     musel |= (*MuonIDSelector)(ctrl,mu);
94     if(ctrl.debug) cout << "musel.status after ID: " << musel.getStatus() << endl;
95     musel |= (*MuonIsoSelector)(ctrl,mu);
96     if(ctrl.debug) cout << "musel.status after iso: " << musel.getStatus() << endl;
97    
98     if( ctrl.debug ) {
99     cout << "muon:: pt: " << mu->pt
100     << "\teta: " << mu->eta
101     << "\tisorel: " << mu->pfIso03/mu->pt
102     << "\tstatus: " << hex << musel.getStatus() << dec
103     << endl;
104     }
105    
106     if ( musel.pass() ) {
107    
108     SimpleLepton tmplep;
109     float pt = mu->pt;
110     tmplep.vecorig->SetPtEtaPhiM(pt,
111     mu->eta,
112     mu->phi,
113     MUON_MASS);
114    
115     if( ctrl.do_escale_up ) {
116     pt=scale_smear_muon_Up(pt, 1, r);
117     }
118     if( ctrl.do_escale_down ) {
119     pt=scale_smear_muon_Down(pt, 1, r);
120     }
121    
122     tmplep.vec->SetPtEtaPhiM(pt,
123     mu->eta,
124     mu->phi,
125     MUON_MASS);
126    
127     tmplep.type = 13;
128     tmplep.index = i;
129     tmplep.charge = mu->q;
130     tmplep.isoTrk = mu->trkIso03;
131     tmplep.isoEcal = mu->emIso03;
132     tmplep.isoHcal = mu->hadIso03;
133     tmplep.isoPF03 = mu->pfIso03;
134     tmplep.isoPF04 = mu->pfIso04;
135     tmplep.ip3dSig = mu->ip3dSig;
136     tmplep.is4l = false;
137     tmplep.isEB = (fabs(mu->eta) < 1.479 ? 1 : 0 );
138     tmplep.isTight = musel.tight();
139     tmplep.isLoose = musel.loose();
140     lepvec.push_back(tmplep);
141     if( ctrl.debug ) { cout << "muon passes ... " << endl;}
142     }
143     // }
144     }
145    
146    
147    
148     //
149     if( ctrl.debug ) { cout << "\tnElectron: " << electronArr->GetEntries() << endl; }
150     // --------------------------------------------------------------------------------
151     for(Int_t i=0; i<electronArr->GetEntries(); i++)
152     {
153     const mithep::TElectron *ele = (mithep::TElectron*)((*electronArr)[i]);
154    
155     Bool_t isMuonOverlap = kFALSE;
156     for (int k=0; k<lepvec.size(); ++k) {
157     TVector3 tmplep;
158     tmplep.SetPtEtaPhi(ele->pt, ele->eta, ele->phi);
159     if ( lepvec[k].isLoose && lepvec[k].type == 13 && lepvec[k].vec->Vect().DrEtaPhi(tmplep) < 0.1 ) {
160     if( ctrl.debug ) cout << "-----> isMuonOverlap! " << endl;
161     isMuonOverlap = kTRUE;
162     break;
163     }
164     }
165    
166     SelectionStatus elesel;
167     elesel |= (*ElectronPreSelector)(ctrl,ele);
168     elesel |= (*ElectronIDSelector)(ctrl,ele);
169     elesel |= (*ElectronIsoSelector)(ctrl,ele);
170     if( elesel.getStatus() == SelectionStatus::PRESELECTION )
171     elesel.setStatus(SelectionStatus::LOOSESELECTION);
172    
173     if( ctrl.debug ){
174     cout << "\tscEt: " << ele->scEt
175     << "\tscEta: " << ele->scEta
176     << "\tncluster: " << ele->ncluster
177     << "\tisorel: " << ele->pfIso04/ele->pt
178     << "\tstatus: " << hex << elesel.getStatus() << dec
179     << endl;
180     }
181    
182     if ( elesel.pass() && !isMuonOverlap )
183     {
184     SimpleLepton tmplep;
185    
186     float pt = ele->pt;
187     tmplep.vecorig->SetPtEtaPhiM( pt,
188     ele->eta,
189     ele->phi,
190     ELECTRON_MASS );
191    
192     if( ctrl.do_escale ) {
193     pt=scale_smear_electron(pt, ele->isEB, r);
194     }
195     if( ctrl.do_escale_up ) {
196     pt=scale_smear_electron_Up(pt, ele->isEB, r);
197     }
198     if( ctrl.do_escale_down ) {
199     pt=scale_smear_electron_Down(pt, ele->isEB, r);
200     }
201    
202    
203     tmplep.vec->SetPtEtaPhiM( pt,
204     ele->eta,
205     ele->phi,
206     ELECTRON_MASS );
207    
208     tmplep.type = 11;
209     tmplep.index = i;
210     tmplep.charge = ele->q;
211     tmplep.isoTrk = ele->trkIso03;
212     tmplep.isoEcal = ele->emIso03;
213     tmplep.isoHcal = ele->hadIso03;
214     tmplep.isoPF03 = ele->pfIso03;
215     tmplep.isoPF04 = ele->pfIso04;
216     tmplep.ip3dSig = ele->ip3dSig;
217     tmplep.is4l = false;
218     tmplep.isEB = ele->isEB;
219     tmplep.scID = ele->scID;
220     tmplep.isTight = elesel.tight();
221     tmplep.isLoose = elesel.pass();
222     lepvec.push_back(tmplep);
223     if( ctrl.debug ) { cout << "\telectron passes ... " << endl; }
224     }
225     }
226    
227    
228     //********************************************************
229     // Dump Stuff
230     //********************************************************
231     sort( lepvec.begin(), lepvec.end(), SimpleLepton::lep_pt_sort );
232     int nmu=0, nele=0;
233     for( int i=0; i<lepvec.size(); i++ ) {
234     if(ctrl.debug) cout << "lepvec :: index: " << i
235     << "\tpt: " << lepvec[i].vec->Pt()
236     << "\ttype: " << lepvec[i].type
237     << endl;
238     if( abs(lepvec[i].type) == 11 ) nele++;
239     else nmu++;
240     }
241     if( ctrl.debug ) {
242     cout << "postsel nlep: " << lepvec.size()
243     << "\tnmuon: " << nmu
244     << "\tnelectron: " << nele
245     << endl;
246     }
247    
248    
249     //******************************************************************************
250     // Selection
251     //******************************************************************************
252     float bestMass=-1; int best_mu_index=-1, best_ele_index=-1;
253     for(int i = 0; i < lepvec.size(); ++i) { // get a tight muon
254     if( abs(lepvec[i].type) != 13 ) continue;
255     if( !(lepvec[i].isTight) ) continue;
256     if( lepvec[i].vec->Pt() < 20 ) continue;
257     if( ctrl.debug ) cout << "got a muon, index: " << i << endl;
258    
259     for(int j = 0; j<lepvec.size(); ++j) { // get a loose electron
260     if( j == i ) continue;
261     if( abs(lepvec[j].type) != 11 ) continue;
262     if( !(lepvec[j].isLoose) ) continue;
263     // if (lepvec[i].charge == lepvec[j].charge) continue;
264     if (lepvec[i].charge != lepvec[j].charge) continue;
265     if( ctrl.debug ) cout << "got a electron, index: " << j << endl;
266    
267     float tmpMass = ( *(lepvec[i].vec) + *(lepvec[j].vec) ).M();
268     if( ctrl.debug ) cout << "tmp vs best :: " << tmpMass << "," << bestMass << endl;
269     if( tmpMass > bestMass ) {
270     bestMass = tmpMass;
271     best_mu_index=i;
272     best_ele_index=j;
273     }
274    
275     }
276     }
277    
278     if( bestMass > 0 ) {
279     if( ctrl.debug ) cout << "EMU candidate, mass : " << bestMass << endl;
280     if( lepvec[best_ele_index].isTight )
281     ret.status.setStatus(SelectionStatus::TIGHTSELECTION);
282     else
283     ret.status.setStatus(SelectionStatus::LOOSESELECTION);
284     ret.Z1leptons.push_back(lepvec[best_mu_index]);
285     ret.Z1leptons.push_back(lepvec[best_ele_index]);
286     ret.Z2leptons.push_back(lepvec[best_mu_index]);
287     ret.Z2leptons.push_back(lepvec[best_ele_index]);
288     return ret;
289     }
290    
291     ret.status.setStatus(0);
292     return ret;
293    
294     }
295    
296