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( !(passHLTSingleMuon(info->triggerBits) ) ) {
|
59 |
// if( ctrl.debug ) cout << "\tfails trigger" << endl;
|
60 |
// evtfail |= (1<<EVTFAIL_TRIGGER);
|
61 |
// ret.status.setStatus(0);
|
62 |
// return ret;
|
63 |
// }
|
64 |
// }
|
65 |
if( ctrl.debug ) {
|
66 |
cout << "presel nlep: " << muonArr->GetEntries() + electronArr->GetEntries()
|
67 |
<< "\tnmuon: " << muonArr->GetEntries()
|
68 |
<< "\tnelectron: " << electronArr->GetEntries()
|
69 |
<< endl;
|
70 |
}
|
71 |
|
72 |
//********************************************************
|
73 |
// Lepton Selection
|
74 |
//********************************************************
|
75 |
vector<SimpleLepton> lepvec;
|
76 |
if( muonArr->GetEntries() != 1 && electronArr->GetEntries() != 1 ) {
|
77 |
ret.status.setStatus(0);
|
78 |
return ret;
|
79 |
}
|
80 |
|
81 |
//
|
82 |
if( ctrl.debug ) cout << "\tnMuons: " << muonArr->GetEntries() << endl;
|
83 |
//----------------------------------------------------
|
84 |
for(Int_t i=0; i<muonArr->GetEntries(); i++)
|
85 |
{
|
86 |
const mithep::TMuon *mu = (mithep::TMuon*)((*muonArr)[i]);
|
87 |
|
88 |
SelectionStatus musel;
|
89 |
if(ctrl.debug) cout << "musel.status before anything: " << musel.getStatus() << endl;
|
90 |
musel |= (*MuonPreSelector)(ctrl,mu);
|
91 |
if(ctrl.debug) cout << "musel.status after presel: " << musel.getStatus() << endl;
|
92 |
musel |= (*MuonIDSelector)(ctrl,mu);
|
93 |
if(ctrl.debug) cout << "musel.status after ID: " << musel.getStatus() << endl;
|
94 |
musel |= (*MuonIsoSelector)(ctrl,mu);
|
95 |
if(ctrl.debug) cout << "musel.status after iso: " << musel.getStatus() << endl;
|
96 |
|
97 |
if( ctrl.debug ) {
|
98 |
cout << "muon:: pt: " << mu->pt
|
99 |
<< "\teta: " << mu->eta
|
100 |
<< "\tisorel: " << mu->pfIso03/mu->pt
|
101 |
<< "\tstatus: " << hex << musel.getStatus() << dec
|
102 |
<< endl;
|
103 |
}
|
104 |
|
105 |
if ( musel.pass() ) {
|
106 |
|
107 |
SimpleLepton tmplep;
|
108 |
float pt = mu->pt;
|
109 |
tmplep.vecorig->SetPtEtaPhiM(pt,
|
110 |
mu->eta,
|
111 |
mu->phi,
|
112 |
MUON_MASS);
|
113 |
|
114 |
if( ctrl.do_escale_up ) {
|
115 |
pt=scale_smear_muon_Up(pt, 1, r);
|
116 |
}
|
117 |
if( ctrl.do_escale_down ) {
|
118 |
pt=scale_smear_muon_Down(pt, 1, r);
|
119 |
}
|
120 |
|
121 |
tmplep.vec->SetPtEtaPhiM(pt,
|
122 |
mu->eta,
|
123 |
mu->phi,
|
124 |
MUON_MASS);
|
125 |
|
126 |
tmplep.type = 13;
|
127 |
tmplep.index = i;
|
128 |
tmplep.charge = mu->q;
|
129 |
tmplep.isoTrk = mu->trkIso03;
|
130 |
tmplep.isoEcal = mu->emIso03;
|
131 |
tmplep.isoHcal = mu->hadIso03;
|
132 |
tmplep.isoPF03 = mu->pfIso03;
|
133 |
tmplep.isoPF04 = mu->pfIso04;
|
134 |
tmplep.ip3dSig = mu->ip3dSig;
|
135 |
tmplep.is4l = false;
|
136 |
tmplep.isEB = (fabs(mu->eta) < 1.479 ? 1 : 0 );
|
137 |
tmplep.isTight = musel.tight();
|
138 |
tmplep.isLoose = musel.loose();
|
139 |
lepvec.push_back(tmplep);
|
140 |
if( ctrl.debug ) { cout << "muon passes ... " << endl;}
|
141 |
}
|
142 |
// }
|
143 |
}
|
144 |
|
145 |
|
146 |
|
147 |
//
|
148 |
if( ctrl.debug ) { cout << "\tnElectron: " << electronArr->GetEntries() << endl; }
|
149 |
// --------------------------------------------------------------------------------
|
150 |
for(Int_t i=0; i<electronArr->GetEntries(); i++)
|
151 |
{
|
152 |
const mithep::TElectron *ele = (mithep::TElectron*)((*electronArr)[i]);
|
153 |
|
154 |
Bool_t isMuonOverlap = kFALSE;
|
155 |
for (int k=0; k<lepvec.size(); ++k) {
|
156 |
TVector3 tmplep;
|
157 |
tmplep.SetPtEtaPhi(ele->pt, ele->eta, ele->phi);
|
158 |
if ( abs(lepvec[k].type == 13) && lepvec[k].vec->Vect().DrEtaPhi(tmplep) < 0.15 ) {
|
159 |
if( ctrl.debug ) cout << "-----> isMuonOverlap! " << endl;
|
160 |
isMuonOverlap = kTRUE;
|
161 |
break;
|
162 |
}
|
163 |
}
|
164 |
|
165 |
// kick out non fiducial, low pT eles
|
166 |
if ( ele->pt < 7 || fabs(ele->eta) > 2.5 )
|
167 |
continue;
|
168 |
|
169 |
SelectionStatus elesel;
|
170 |
elesel |= (*ElectronPreSelector)(ctrl,ele);
|
171 |
elesel |= (*ElectronIDSelector)(ctrl,ele);
|
172 |
elesel |= (*ElectronIsoSelector)(ctrl,ele);
|
173 |
|
174 |
// if( elesel.getStatus() & SelectionStatus::PRESELECTION )
|
175 |
// elesel.setStatus(SelectionStatus::LOOSESELECTION);
|
176 |
|
177 |
if( ctrl.debug ){
|
178 |
cout << "\tscEt: " << ele->scEt
|
179 |
<< "\tscEta: " << ele->scEta
|
180 |
<< "\tncluster: " << ele->ncluster
|
181 |
<< "\tisorel: " << ele->pfIso04/ele->pt
|
182 |
<< "\tstatus: " << hex << elesel.getStatus() << dec
|
183 |
<< endl;
|
184 |
}
|
185 |
|
186 |
// if ( elesel.pass() && !isMuonOverlap )
|
187 |
if ( !isMuonOverlap )
|
188 |
{
|
189 |
SimpleLepton tmplep;
|
190 |
|
191 |
float pt = ele->pt;
|
192 |
tmplep.vecorig->SetPtEtaPhiM( pt,
|
193 |
ele->eta,
|
194 |
ele->phi,
|
195 |
ELECTRON_MASS );
|
196 |
|
197 |
if( ctrl.do_escale ) {
|
198 |
pt=scale_smear_electron(pt, ele->isEB, r);
|
199 |
}
|
200 |
if( ctrl.do_escale_up ) {
|
201 |
pt=scale_smear_electron_Up(pt, ele->isEB, r);
|
202 |
}
|
203 |
if( ctrl.do_escale_down ) {
|
204 |
pt=scale_smear_electron_Down(pt, ele->isEB, r);
|
205 |
}
|
206 |
|
207 |
|
208 |
tmplep.vec->SetPtEtaPhiM( pt,
|
209 |
ele->eta,
|
210 |
ele->phi,
|
211 |
ELECTRON_MASS );
|
212 |
|
213 |
tmplep.type = 11;
|
214 |
tmplep.index = i;
|
215 |
tmplep.charge = ele->q;
|
216 |
tmplep.isoTrk = ele->trkIso03;
|
217 |
tmplep.isoEcal = ele->emIso03;
|
218 |
tmplep.isoHcal = ele->hadIso03;
|
219 |
tmplep.isoPF03 = ele->pfIso03;
|
220 |
tmplep.isoPF04 = ele->pfIso04;
|
221 |
tmplep.ip3dSig = ele->ip3dSig;
|
222 |
tmplep.is4l = false;
|
223 |
tmplep.isEB = ele->isEB;
|
224 |
tmplep.scID = ele->scID;
|
225 |
tmplep.isTight = elesel.tight();
|
226 |
tmplep.isLoose = elesel.loose();
|
227 |
// tmplep.isLoose = elesel.pass();
|
228 |
lepvec.push_back(tmplep);
|
229 |
if( ctrl.debug ) { cout << "\telectron passes ... " << endl; }
|
230 |
}
|
231 |
}
|
232 |
|
233 |
|
234 |
//********************************************************
|
235 |
// Dump Stuff
|
236 |
//********************************************************
|
237 |
sort( lepvec.begin(), lepvec.end(), SimpleLepton::lep_pt_sort );
|
238 |
int nmu=0, nele=0;
|
239 |
for( int i=0; i<lepvec.size(); i++ ) {
|
240 |
if(ctrl.debug) cout << "lepvec :: index: " << i
|
241 |
<< "\tpt: " << lepvec[i].vec->Pt()
|
242 |
<< "\ttype: " << lepvec[i].type
|
243 |
<< endl;
|
244 |
if( abs(lepvec[i].type) == 11 ) nele++;
|
245 |
else nmu++;
|
246 |
}
|
247 |
if( ctrl.debug ) {
|
248 |
cout << "postsel nlep: " << lepvec.size()
|
249 |
<< "\tnmuon: " << nmu
|
250 |
<< "\tnelectron: " << nele
|
251 |
<< endl;
|
252 |
}
|
253 |
|
254 |
|
255 |
//******************************************************************************
|
256 |
// Selection
|
257 |
//******************************************************************************
|
258 |
float bestMass=-1; int best_mu_index=-1, best_ele_index=-1;
|
259 |
for(int i = 0; i<lepvec.size(); i++) { // get a tight muon
|
260 |
if( abs(lepvec[i].type) != 13 ) continue;
|
261 |
if( !(lepvec[i].isTight) ) continue;
|
262 |
// if( lepvec[i].vec->Pt() < 35 ) continue;
|
263 |
if( ctrl.debug ) cout << "got a muon, index: " << i << endl;
|
264 |
|
265 |
for(int j = 0; j<lepvec.size(); j++) { // get a loose electron
|
266 |
if( j == i ) continue;
|
267 |
if( abs(lepvec[j].type) != 11 ) continue;
|
268 |
// if( !(lepvec[j].isLoose) ) continue;
|
269 |
// if (lepvec[i].charge == lepvec[j].charge) continue;
|
270 |
if (lepvec[i].charge != lepvec[j].charge) continue;
|
271 |
if( ctrl.debug ) cout << "got a electron, index: " << j << endl;
|
272 |
|
273 |
float tmpMass = ( *(lepvec[i].vec) + *(lepvec[j].vec) ).M();
|
274 |
if( ctrl.debug ) cout << "tmp vs best :: " << tmpMass << "," << bestMass << endl;
|
275 |
if( tmpMass > bestMass ) {
|
276 |
bestMass = tmpMass;
|
277 |
best_mu_index=i;
|
278 |
best_ele_index=j;
|
279 |
}
|
280 |
|
281 |
}
|
282 |
}
|
283 |
|
284 |
if( bestMass > 0 ) {
|
285 |
if( ctrl.debug ) cout << "EMU candidate, mass : " << bestMass << endl;
|
286 |
|
287 |
// if( lepvec[best_ele_index].isTight )
|
288 |
// ret.status.setStatus(SelectionStatus::TIGHTSELECTION);
|
289 |
// else
|
290 |
// ret.status.setStatus(SelectionStatus::LOOSESELECTION);
|
291 |
|
292 |
if( lepvec[best_ele_index].isTight )
|
293 |
ret.status.setStatus(SelectionStatus::TIGHTSELECTION);
|
294 |
if( lepvec[best_ele_index].isLoose )
|
295 |
ret.status.setStatus(SelectionStatus::LOOSESELECTION);
|
296 |
if( !(lepvec[best_ele_index].isTight) && !(lepvec[best_ele_index].isLoose) )
|
297 |
ret.status.setStatus(SelectionStatus::UNDEFINED); // using preselection here to mean that muon
|
298 |
// is good & ele pass neither loose or tight
|
299 |
|
300 |
ret.Z1leptons.push_back(lepvec[best_mu_index]);
|
301 |
ret.Z1leptons.push_back(lepvec[best_ele_index]);
|
302 |
ret.Z2leptons.push_back(lepvec[best_mu_index]);
|
303 |
ret.Z2leptons.push_back(lepvec[best_ele_index]);
|
304 |
return ret;
|
305 |
}
|
306 |
|
307 |
ret.status.setStatus(SelectionStatus::FAIL);
|
308 |
return ret;
|
309 |
|
310 |
}
|
311 |
|
312 |
|