1 |
//***************************************************************************************************
|
2 |
//
|
3 |
// selection sync'ed with https://twiki.cern.ch/twiki/bin/viewauth/CMS/HiggsZZ4l2012SummerSync
|
4 |
//
|
5 |
//***************************************************************************************************
|
6 |
|
7 |
// system headers
|
8 |
#include <map>
|
9 |
#include <utility>
|
10 |
|
11 |
// mit headers
|
12 |
#include "Vertex.h"
|
13 |
|
14 |
// 4L stuff
|
15 |
#include "SelectionStatus.h"
|
16 |
#include "EventData.h"
|
17 |
#include "SimpleLepton.h"
|
18 |
#include "EfficiencyWeightsInterface.h"
|
19 |
#include "ElectronSelection.h"
|
20 |
#include "MuonSelection.h"
|
21 |
#include "IsolationSelection.h"
|
22 |
#include "SelectionEMU.h"
|
23 |
#include "ReferenceSelection.h"
|
24 |
#include "Selection.h"
|
25 |
#include "CommonDefs.h"
|
26 |
#include "SelectionDefs.h"
|
27 |
#include "FSR.h"
|
28 |
#include "SelectionFuncs.h"
|
29 |
|
30 |
|
31 |
extern vector<SimpleLepton> failingLeptons;
|
32 |
extern vector<SimpleLepton> passingLeptons;
|
33 |
extern vector<int> muTrigObjs,eleTrigObjs,muTriggers,eleTriggers;
|
34 |
extern bitset<TRIGGER_BIG_NUMBER> triggerBits;
|
35 |
|
36 |
//--------------------------------------------------------------------------------------------------
|
37 |
EventData apply_HZZ4L_EMU_selection(ControlFlags &ctrl, // input control
|
38 |
const mithep::EventHeader *info, // input event info
|
39 |
mithep::TriggerTable *hltTable,
|
40 |
mithep::Array<mithep::TriggerObject> *hltObjArr,
|
41 |
mithep::TriggerObjectsTable *fTrigObjs,
|
42 |
const mithep::Array<mithep::Vertex> * vtxArr ,
|
43 |
const mithep::Array<mithep::PFCandidate> *pfCandidates,
|
44 |
const mithep::Array<mithep::PileupEnergyDensity> *puEnergyDensity,
|
45 |
const mithep::DecayParticleCol *fConversions,
|
46 |
const mithep::Array<mithep::Electron> *electronArr, // input electrons
|
47 |
SelectionStatus (*ElectronPreSelector)( ControlFlags &,
|
48 |
const mithep::Electron*,
|
49 |
const mithep::Vertex *),
|
50 |
SelectionStatus (*ElectronIDSelector)( ControlFlags &,
|
51 |
const mithep::Electron*,
|
52 |
const mithep::Vertex *),
|
53 |
SelectionStatus (*ElectronIsoSelector)( ControlFlags &,
|
54 |
const mithep::Electron*,
|
55 |
const mithep::Vertex *,
|
56 |
const mithep::Array<mithep::PFCandidate> *,
|
57 |
const mithep::Array<mithep::PileupEnergyDensity> *,
|
58 |
mithep::ElectronTools::EElectronEffectiveAreaTarget,
|
59 |
vector<const mithep::PFCandidate*>),
|
60 |
const mithep::Array<mithep::Muon> *muonArr, // input muons
|
61 |
SelectionStatus (*MuonPreSelector)( ControlFlags &,
|
62 |
const mithep::Muon*,
|
63 |
const mithep::Vertex *,
|
64 |
const mithep::Array<mithep::PFCandidate> *),
|
65 |
SelectionStatus (*MuonIDSelector)( ControlFlags &,
|
66 |
const mithep::Muon*,
|
67 |
// const mithep::Vertex &),
|
68 |
const mithep::Vertex *,
|
69 |
const mithep::Array<mithep::PFCandidate> *),
|
70 |
SelectionStatus (*MuonIsoSelector)( ControlFlags &,
|
71 |
const mithep::Muon*,
|
72 |
const mithep::Vertex *,
|
73 |
const mithep::Array<mithep::PFCandidate> *,
|
74 |
const mithep::Array<mithep::PileupEnergyDensity> *,
|
75 |
mithep::MuonTools::EMuonEffectiveAreaTarget,
|
76 |
vector<const mithep::PFCandidate*>)
|
77 |
)
|
78 |
//--------------------------------------------------------------------------------------------------
|
79 |
{
|
80 |
|
81 |
EventData ret;
|
82 |
unsigned evtfail = 0x0;
|
83 |
TRandom3 r;
|
84 |
|
85 |
failingLeptons.clear();
|
86 |
passingLeptons.clear();
|
87 |
|
88 |
mithep::MuonTools::EMuonEffectiveAreaTarget eraMu;
|
89 |
mithep::ElectronTools::EElectronEffectiveAreaTarget eraEle;
|
90 |
getEATargets(ctrl,eraMu,eraEle);
|
91 |
|
92 |
const mithep::Vertex * vtx;
|
93 |
bool goodVertex = setPV( ctrl, vtxArr, vtx );
|
94 |
if(goodVertex) {
|
95 |
ret.status.selectionBits.flip(PASS_SKIM2);
|
96 |
} else {
|
97 |
if(ctrl.debug) cout << "found bad vertex" << endl;
|
98 |
ret.status.setStatus(SelectionStatus::FAIL);
|
99 |
return ret;
|
100 |
}
|
101 |
|
102 |
//***********************************************************
|
103 |
// Lepton Selection
|
104 |
//***********************************************************
|
105 |
vector<SimpleLepton> lepvec;
|
106 |
vector<const mithep::PFCandidate*> photonsToVeto;
|
107 |
|
108 |
|
109 |
if( ctrl.debug ) cout << "\tnMuons: " << muonArr->GetEntries() << endl;
|
110 |
//----------------------------------------------------
|
111 |
for(int i=0; i<muonArr->GetEntries(); i++)
|
112 |
{
|
113 |
const mithep::Muon *mu = (mithep::Muon*)((*muonArr)[i]);
|
114 |
|
115 |
|
116 |
SelectionStatus denomSel;
|
117 |
denomSel |= muonPreSelectionNoD0IP(ctrl,mu,vtx,pfCandidates);
|
118 |
if( !denomSel.passPre() ) continue;
|
119 |
|
120 |
SelectionStatus musel;
|
121 |
musel |= (*MuonPreSelector)(ctrl,mu,vtx,pfCandidates);
|
122 |
musel |= (*MuonIDSelector)(ctrl,mu,vtx,pfCandidates );
|
123 |
musel |= (*MuonIsoSelector)(ctrl,mu,vtx,pfCandidates,puEnergyDensity,eraMu,photonsToVeto);
|
124 |
|
125 |
SimpleLepton tmplep;
|
126 |
float pt = mu->Pt();
|
127 |
tmplep.vec.SetPtEtaPhiM(pt,
|
128 |
mu->Eta(),
|
129 |
mu->Phi(),
|
130 |
MUON_MASS);
|
131 |
|
132 |
tmplep.type = 13;
|
133 |
tmplep.index = i;
|
134 |
tmplep.charge = mu->Charge();
|
135 |
tmplep.isoTrk = mu->IsoR03SumPt();
|
136 |
tmplep.isoEcal = mu->IsoR03EmEt();
|
137 |
tmplep.isoHcal = mu->IsoR03HadEt();
|
138 |
tmplep.isoPF04 = musel.isoPF04;
|
139 |
tmplep.chisoPF04 = musel.chisoPF04;
|
140 |
tmplep.gaisoPF04 = musel.gaisoPF04;
|
141 |
tmplep.neisoPF04 = musel.neisoPF04;
|
142 |
// tmplep.isoPF03 = computePFMuonIso(mu,vtx,pfCandidates,0.3);
|
143 |
// tmplep.isoPF04 = computePFMuonIso(mu,vtx,pfCandidates,0.4);
|
144 |
tmplep.ip3dSig = mu->Ip3dPVSignificance();
|
145 |
tmplep.is4l = false;
|
146 |
tmplep.isEB = (fabs(mu->Eta()) < 1.479 ? 1 : 0 );
|
147 |
tmplep.isoMVA = musel.isoMVA;
|
148 |
tmplep.isLoose = musel.loose();
|
149 |
|
150 |
bitset<TRIGGER_BIG_NUMBER> hltMatchBits = fillHLTMatchBits( mu->Eta(), mu->Phi(), hltTable, hltObjArr, fTrigObjs);
|
151 |
tmplep.isTight = testBits(ctrl,triggerBits,muTriggers,hltMatchBits,muTrigObjs);
|
152 |
|
153 |
tmplep.bdtfail = 0;
|
154 |
if(triggerBits.test(kHLT_IsoMu24_eta2p1)) tmplep.bdtfail |= 1;
|
155 |
if(hltMatchBits.test(kHLT_IsoMu24_eta2p1_MuObj)) tmplep.bdtfail |= 2;
|
156 |
if(triggerBits.test(kHLT_IsoMu24)) tmplep.bdtfail |= 4;
|
157 |
if(hltMatchBits.test(kHLT_IsoMu24_MuObj)) tmplep.bdtfail |= 8;
|
158 |
|
159 |
tmplep.status = musel;
|
160 |
tmplep.fsrRecoveryAttempted = false;
|
161 |
tmplep.tightCutsApplied = muon2012CutBasedIDTightVersionWithOldIsoThatWorksOn2011(ctrl,mu,vtx,pfCandidates,puEnergyDensity,eraMu);
|
162 |
lepvec.push_back(tmplep);
|
163 |
if( ctrl.debug ) cout << endl;
|
164 |
}
|
165 |
|
166 |
if( ctrl.debug ) { cout << "\tnElectron: " << electronArr->GetEntries() << endl; }
|
167 |
// --------------------------------------------------------------------------------
|
168 |
for(int i=0; i<electronArr->GetEntries(); i++)
|
169 |
{
|
170 |
const mithep::Electron *ele = (mithep::Electron*)((*electronArr)[i]);
|
171 |
|
172 |
SelectionStatus denomSel;
|
173 |
denomSel |= electronPreSelectionNoD0IP(ctrl,ele,vtx);
|
174 |
if( !denomSel.passPre() ) continue;
|
175 |
|
176 |
SelectionStatus elesel;
|
177 |
elesel |= (*ElectronPreSelector)(ctrl,ele,vtx);
|
178 |
elesel |= (*ElectronIDSelector)(ctrl,ele,vtx);
|
179 |
elesel |= (*ElectronIsoSelector)(ctrl,ele,vtx,pfCandidates,puEnergyDensity,eraEle,photonsToVeto);
|
180 |
|
181 |
SimpleLepton tmplep;
|
182 |
float pt = ele->Pt();
|
183 |
tmplep.vec.SetPtEtaPhiM( pt,
|
184 |
ele->Eta(),
|
185 |
ele->Phi(),
|
186 |
ELECTRON_MASS );
|
187 |
|
188 |
tmplep.type = 11;
|
189 |
tmplep.index = i;
|
190 |
tmplep.charge = ele->Charge();
|
191 |
tmplep.isoTrk = ele->TrackIsolationDr03();
|
192 |
tmplep.isoEcal = ele->EcalRecHitIsoDr03();
|
193 |
tmplep.isoHcal = ele->HcalTowerSumEtDr03();
|
194 |
tmplep.isoPF04 = elesel.isoPF04;
|
195 |
tmplep.chisoPF04 = elesel.chisoPF04;
|
196 |
tmplep.gaisoPF04 = elesel.gaisoPF04;
|
197 |
tmplep.neisoPF04 = elesel.neisoPF04;
|
198 |
// tmplep.isoPF03 = computePFEleIso(ele,vtx,pfCandidates,0.3);
|
199 |
// tmplep.isoPF04 = computePFEleIso(ele,vtx,pfCandidates,0.4);
|
200 |
tmplep.ip3dSig = ele->Ip3dPVSignificance();
|
201 |
tmplep.is4l = false;
|
202 |
tmplep.isEB = ele->IsEB();
|
203 |
tmplep.scID = ele->SCluster()->GetUniqueID();
|
204 |
|
205 |
bitset<TRIGGER_BIG_NUMBER> hltMatchBits = fillHLTMatchBits( ele->Eta(), ele->Phi(), hltTable, hltObjArr, fTrigObjs);
|
206 |
tmplep.isTight = testBits(ctrl,triggerBits,eleTriggers,hltMatchBits,eleTrigObjs);
|
207 |
|
208 |
tmplep.isTight = elesel.tight();
|
209 |
tmplep.isLoose = elesel.loose();
|
210 |
tmplep.status = elesel;
|
211 |
tmplep.idMVA = elesel.idMVA;
|
212 |
tmplep.isoMVA = elesel.isoMVA;
|
213 |
tmplep.fsrRecoveryAttempted = false;
|
214 |
tmplep.tightCutsApplied = electron2012CutBasedIDMediumVersionThatWorksOn2011(ctrl,ele,vtx,pfCandidates,fConversions,puEnergyDensity,eraEle);
|
215 |
lepvec.push_back(tmplep);
|
216 |
if( ctrl.debug ) cout << endl;
|
217 |
}
|
218 |
|
219 |
sort( lepvec.begin(), lepvec.end(), SimpleLepton::lep_pt_sort );
|
220 |
|
221 |
//********************************************************
|
222 |
// Step 2: Lepton Cleaning
|
223 |
//********************************************************
|
224 |
vector<vector<SimpleLepton>::iterator> electrons_to_erase;
|
225 |
for (vector<SimpleLepton>::iterator it1=lepvec.begin(); it1 != lepvec.end(); it1++ ) {
|
226 |
if ( abs(it1->type) != 11 ) continue;
|
227 |
TVector3 evec = it1->vec.Vect();
|
228 |
|
229 |
bool erase_this_electron=false;
|
230 |
for (vector<SimpleLepton>::iterator it2=lepvec.begin(); it2 != lepvec.end(); it2++ ) {
|
231 |
if ( it2 == it1 ) continue;
|
232 |
if ( abs(it2->type) != 13 ) continue;
|
233 |
// if( !(it2->status.looseIDAndPre()) ) continue;
|
234 |
TVector3 mvec = it2->vec.Vect();
|
235 |
|
236 |
if ( evec.DrEtaPhi(mvec) < 0.05 ) {
|
237 |
erase_this_electron=true;
|
238 |
break;
|
239 |
}
|
240 |
}
|
241 |
if( erase_this_electron )
|
242 |
electrons_to_erase.push_back(it1);
|
243 |
}
|
244 |
for( int i=0; i<electrons_to_erase.size(); i++ ) {
|
245 |
lepvec.erase(electrons_to_erase[i]);
|
246 |
}
|
247 |
|
248 |
//********************************************************
|
249 |
// Step 3: Good Leptons
|
250 |
//********************************************************
|
251 |
for (int i=0; i<lepvec.size(); i++ ) {
|
252 |
if( !(lepvec[i].status.loose()) ) {
|
253 |
failingLeptons.push_back(lepvec[i]);
|
254 |
} else {
|
255 |
passingLeptons.push_back(lepvec[i]);
|
256 |
}
|
257 |
}
|
258 |
|
259 |
//******************************************************************************
|
260 |
// W + (OF SS lepton) Selection
|
261 |
//******************************************************************************
|
262 |
if(has_ssof_lepton(ctrl)) {
|
263 |
ret.status.setStatus(SelectionStatus::EVTPASS);
|
264 |
ret.Z1leptons.push_back(passingLeptons[0]);
|
265 |
ret.Z1leptons.push_back(passingLeptons[0]);
|
266 |
ret.Z2leptons.push_back(passingLeptons[0]);
|
267 |
ret.Z2leptons.push_back(passingLeptons[0]);
|
268 |
} else {
|
269 |
ret.status.setStatus(SelectionStatus::FAIL);
|
270 |
}
|
271 |
return ret;
|
272 |
}
|
273 |
//----------------------------------------------------------------------------------------
|
274 |
bool has_ssof_lepton(ControlFlags &ctrl)
|
275 |
{
|
276 |
bool has_ssof=false;
|
277 |
for(unsigned iw=0; iw<passingLeptons.size(); iw++) {
|
278 |
SimpleLepton w_lep = passingLeptons[iw];
|
279 |
//????????????????????????????????????????????????????????????????????????????????????????
|
280 |
// this is applied in skim (skim also applies ww muon id)
|
281 |
// if(abs(w_lep.type) == 11) {
|
282 |
// if( !(w_lep.tightCutsApplied) )
|
283 |
// continue;
|
284 |
// }
|
285 |
//????????????????????????????????????????????????????????????????????????????????????????
|
286 |
for(unsigned ifake=0; ifake<failingLeptons.size(); ifake++) {
|
287 |
SimpleLepton fake_lep = failingLeptons[ifake];
|
288 |
if(abs(fake_lep.type) == abs(w_lep.type)) continue;
|
289 |
if(fake_lep.charge != w_lep.charge) continue;
|
290 |
has_ssof = true;
|
291 |
}
|
292 |
for(unsigned ipass=0; ipass<passingLeptons.size(); ipass++) {
|
293 |
if(ipass == iw) continue;
|
294 |
SimpleLepton pass_lep = passingLeptons[ipass];
|
295 |
if(abs(pass_lep.type) == abs(w_lep.type)) continue;
|
296 |
if(pass_lep.charge != w_lep.charge) continue;
|
297 |
has_ssof = true;
|
298 |
}
|
299 |
}
|
300 |
|
301 |
return has_ssof;
|
302 |
}
|