1 |
dkralph |
1.4 |
//***************************************************************************************************
|
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 |
khahn |
1.1 |
#include "SelectionStatus.h"
|
16 |
|
|
#include "EventData.h"
|
17 |
|
|
#include "SimpleLepton.h"
|
18 |
|
|
#include "EfficiencyWeightsInterface.h"
|
19 |
dkralph |
1.4 |
#include "ElectronSelection.h"
|
20 |
|
|
#include "MuonSelection.h"
|
21 |
khahn |
1.1 |
#include "IsolationSelection.h"
|
22 |
|
|
#include "SelectionEMU.h"
|
23 |
dkralph |
1.4 |
#include "ReferenceSelection.h"
|
24 |
|
|
#include "Selection.h"
|
25 |
|
|
#include "CommonDefs.h"
|
26 |
khahn |
1.1 |
#include "SelectionDefs.h"
|
27 |
dkralph |
1.4 |
#include "FSR.h"
|
28 |
dkralph |
1.5 |
#include "SelectionFuncs.h"
|
29 |
khahn |
1.1 |
|
30 |
|
|
|
31 |
dkralph |
1.4 |
extern vector<SimpleLepton> failingLeptons;
|
32 |
|
|
extern vector<SimpleLepton> passingLeptons;
|
33 |
dkralph |
1.9 |
extern vector<int> muTrigObjs,eleTrigObjs,muTriggers,eleTriggers;
|
34 |
|
|
extern bitset<TRIGGER_BIG_NUMBER> triggerBits;
|
35 |
khahn |
1.1 |
|
36 |
dkralph |
1.4 |
//--------------------------------------------------------------------------------------------------
|
37 |
|
|
EventData apply_HZZ4L_EMU_selection(ControlFlags &ctrl, // input control
|
38 |
dkralph |
1.9 |
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 |
dkralph |
1.10 |
const mithep::DecayParticleCol *fConversions,
|
46 |
dkralph |
1.9 |
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 |
dkralph |
1.4 |
const mithep::Vertex *,
|
56 |
dkralph |
1.9 |
const mithep::Array<mithep::PFCandidate> *,
|
57 |
dkralph |
1.4 |
const mithep::Array<mithep::PileupEnergyDensity> *,
|
58 |
dkralph |
1.9 |
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 |
dkralph |
1.4 |
//--------------------------------------------------------------------------------------------------
|
79 |
khahn |
1.1 |
{
|
80 |
|
|
|
81 |
|
|
EventData ret;
|
82 |
|
|
unsigned evtfail = 0x0;
|
83 |
|
|
TRandom3 r;
|
84 |
|
|
|
85 |
dkralph |
1.4 |
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 |
khahn |
1.1 |
}
|
101 |
|
|
|
102 |
dkralph |
1.4 |
//***********************************************************
|
103 |
|
|
// Lepton Selection
|
104 |
|
|
//***********************************************************
|
105 |
khahn |
1.1 |
vector<SimpleLepton> lepvec;
|
106 |
dkralph |
1.4 |
vector<const mithep::PFCandidate*> photonsToVeto;
|
107 |
|
|
|
108 |
khahn |
1.1 |
|
109 |
|
|
if( ctrl.debug ) cout << "\tnMuons: " << muonArr->GetEntries() << endl;
|
110 |
|
|
//----------------------------------------------------
|
111 |
dkralph |
1.4 |
for(int i=0; i<muonArr->GetEntries(); i++)
|
112 |
khahn |
1.1 |
{
|
113 |
dkralph |
1.4 |
const mithep::Muon *mu = (mithep::Muon*)((*muonArr)[i]);
|
114 |
khahn |
1.1 |
|
115 |
dkralph |
1.8 |
|
116 |
|
|
SelectionStatus denomSel;
|
117 |
dkralph |
1.13 |
denomSel |= muonPreSelectionNoD0IP(ctrl,mu,vtx,pfCandidates);
|
118 |
dkralph |
1.9 |
if( !denomSel.passPre() ) continue;
|
119 |
dkralph |
1.8 |
|
120 |
khahn |
1.1 |
SelectionStatus musel;
|
121 |
dkralph |
1.4 |
musel |= (*MuonPreSelector)(ctrl,mu,vtx,pfCandidates);
|
122 |
|
|
musel |= (*MuonIDSelector)(ctrl,mu,vtx,pfCandidates );
|
123 |
dkralph |
1.8 |
musel |= (*MuonIsoSelector)(ctrl,mu,vtx,pfCandidates,puEnergyDensity,eraMu,photonsToVeto);
|
124 |
dkralph |
1.4 |
|
125 |
|
|
SimpleLepton tmplep;
|
126 |
|
|
float pt = mu->Pt();
|
127 |
|
|
tmplep.vec.SetPtEtaPhiM(pt,
|
128 |
|
|
mu->Eta(),
|
129 |
|
|
mu->Phi(),
|
130 |
|
|
MUON_MASS);
|
131 |
khahn |
1.1 |
|
132 |
dkralph |
1.4 |
tmplep.type = 13;
|
133 |
|
|
tmplep.index = i;
|
134 |
|
|
tmplep.charge = mu->Charge();
|
135 |
|
|
tmplep.ip3dSig = mu->Ip3dPVSignificance();
|
136 |
|
|
tmplep.is4l = false;
|
137 |
|
|
tmplep.isEB = (fabs(mu->Eta()) < 1.479 ? 1 : 0 );
|
138 |
|
|
tmplep.isLoose = musel.loose();
|
139 |
dkralph |
1.9 |
|
140 |
|
|
bitset<TRIGGER_BIG_NUMBER> hltMatchBits = fillHLTMatchBits( mu->Eta(), mu->Phi(), hltTable, hltObjArr, fTrigObjs);
|
141 |
|
|
tmplep.isTight = testBits(ctrl,triggerBits,muTriggers,hltMatchBits,muTrigObjs);
|
142 |
|
|
|
143 |
dkralph |
1.16 |
tmplep.scID = 0;
|
144 |
|
|
if(triggerBits.test(kHLT_IsoMu24_eta2p1)) tmplep.scID |= 1;
|
145 |
|
|
if(hltMatchBits.test(kHLT_IsoMu24_eta2p1_MuObj)) tmplep.scID |= 2;
|
146 |
|
|
if(triggerBits.test(kHLT_IsoMu24)) tmplep.scID |= 4;
|
147 |
|
|
if(hltMatchBits.test(kHLT_IsoMu24_MuObj)) tmplep.scID |= 8;
|
148 |
dkralph |
1.9 |
|
149 |
dkralph |
1.4 |
tmplep.status = musel;
|
150 |
|
|
tmplep.fsrRecoveryAttempted = false;
|
151 |
dkralph |
1.11 |
tmplep.tightCutsApplied = muon2012CutBasedIDTightVersionWithOldIsoThatWorksOn2011(ctrl,mu,vtx,pfCandidates,puEnergyDensity,eraMu);
|
152 |
dkralph |
1.16 |
tmplep.d0 = mu->HasTrackerTrk() ? mu->TrackerTrk()->D0Corrected(*vtx) : 0;
|
153 |
|
|
tmplep.dz = mu->HasTrackerTrk() ? mu->TrackerTrk()->DzCorrected(*vtx) : 0;
|
154 |
dkralph |
1.14 |
|
155 |
dkralph |
1.4 |
lepvec.push_back(tmplep);
|
156 |
|
|
if( ctrl.debug ) cout << endl;
|
157 |
|
|
}
|
158 |
|
|
|
159 |
|
|
if( ctrl.debug ) { cout << "\tnElectron: " << electronArr->GetEntries() << endl; }
|
160 |
|
|
// --------------------------------------------------------------------------------
|
161 |
|
|
for(int i=0; i<electronArr->GetEntries(); i++)
|
162 |
|
|
{
|
163 |
|
|
const mithep::Electron *ele = (mithep::Electron*)((*electronArr)[i]);
|
164 |
khahn |
1.1 |
|
165 |
dkralph |
1.8 |
SelectionStatus denomSel;
|
166 |
dkralph |
1.13 |
denomSel |= electronPreSelectionNoD0IP(ctrl,ele,vtx);
|
167 |
dkralph |
1.10 |
if( !denomSel.passPre() ) continue;
|
168 |
dkralph |
1.8 |
|
169 |
dkralph |
1.4 |
SelectionStatus elesel;
|
170 |
|
|
elesel |= (*ElectronPreSelector)(ctrl,ele,vtx);
|
171 |
|
|
elesel |= (*ElectronIDSelector)(ctrl,ele,vtx);
|
172 |
dkralph |
1.8 |
elesel |= (*ElectronIsoSelector)(ctrl,ele,vtx,pfCandidates,puEnergyDensity,eraEle,photonsToVeto);
|
173 |
khahn |
1.1 |
|
174 |
dkralph |
1.4 |
SimpleLepton tmplep;
|
175 |
|
|
float pt = ele->Pt();
|
176 |
|
|
tmplep.vec.SetPtEtaPhiM( pt,
|
177 |
|
|
ele->Eta(),
|
178 |
|
|
ele->Phi(),
|
179 |
|
|
ELECTRON_MASS );
|
180 |
khahn |
1.1 |
|
181 |
dkralph |
1.4 |
tmplep.type = 11;
|
182 |
khahn |
1.1 |
tmplep.index = i;
|
183 |
dkralph |
1.4 |
tmplep.charge = ele->Charge();
|
184 |
|
|
tmplep.ip3dSig = ele->Ip3dPVSignificance();
|
185 |
khahn |
1.1 |
tmplep.is4l = false;
|
186 |
dkralph |
1.4 |
tmplep.isEB = ele->IsEB();
|
187 |
dkralph |
1.16 |
// tmplep.scID = ele->SCluster()->GetUniqueID();
|
188 |
dkralph |
1.9 |
|
189 |
|
|
bitset<TRIGGER_BIG_NUMBER> hltMatchBits = fillHLTMatchBits( ele->Eta(), ele->Phi(), hltTable, hltObjArr, fTrigObjs);
|
190 |
|
|
tmplep.isTight = testBits(ctrl,triggerBits,eleTriggers,hltMatchBits,eleTrigObjs);
|
191 |
|
|
|
192 |
dkralph |
1.4 |
tmplep.isLoose = elesel.loose();
|
193 |
|
|
tmplep.status = elesel;
|
194 |
|
|
tmplep.fsrRecoveryAttempted = false;
|
195 |
dkralph |
1.11 |
tmplep.tightCutsApplied = electron2012CutBasedIDMediumVersionThatWorksOn2011(ctrl,ele,vtx,pfCandidates,fConversions,puEnergyDensity,eraEle);
|
196 |
dkralph |
1.16 |
tmplep.d0 = ele->BestTrk()->D0Corrected(*vtx);
|
197 |
|
|
tmplep.dz = ele->BestTrk()->DzCorrected(*vtx);
|
198 |
dkralph |
1.14 |
|
199 |
khahn |
1.1 |
lepvec.push_back(tmplep);
|
200 |
dkralph |
1.4 |
if( ctrl.debug ) cout << endl;
|
201 |
khahn |
1.1 |
}
|
202 |
khahn |
1.3 |
|
203 |
dkralph |
1.4 |
sort( lepvec.begin(), lepvec.end(), SimpleLepton::lep_pt_sort );
|
204 |
|
|
|
205 |
|
|
//********************************************************
|
206 |
|
|
// Step 2: Lepton Cleaning
|
207 |
|
|
//********************************************************
|
208 |
|
|
vector<vector<SimpleLepton>::iterator> electrons_to_erase;
|
209 |
|
|
for (vector<SimpleLepton>::iterator it1=lepvec.begin(); it1 != lepvec.end(); it1++ ) {
|
210 |
|
|
if ( abs(it1->type) != 11 ) continue;
|
211 |
|
|
TVector3 evec = it1->vec.Vect();
|
212 |
|
|
|
213 |
|
|
bool erase_this_electron=false;
|
214 |
|
|
for (vector<SimpleLepton>::iterator it2=lepvec.begin(); it2 != lepvec.end(); it2++ ) {
|
215 |
|
|
if ( it2 == it1 ) continue;
|
216 |
|
|
if ( abs(it2->type) != 13 ) continue;
|
217 |
dkralph |
1.7 |
// if( !(it2->status.looseIDAndPre()) ) continue;
|
218 |
dkralph |
1.4 |
TVector3 mvec = it2->vec.Vect();
|
219 |
khahn |
1.1 |
|
220 |
dkralph |
1.4 |
if ( evec.DrEtaPhi(mvec) < 0.05 ) {
|
221 |
|
|
erase_this_electron=true;
|
222 |
|
|
break;
|
223 |
khahn |
1.1 |
}
|
224 |
dkralph |
1.4 |
}
|
225 |
|
|
if( erase_this_electron )
|
226 |
|
|
electrons_to_erase.push_back(it1);
|
227 |
|
|
}
|
228 |
|
|
for( int i=0; i<electrons_to_erase.size(); i++ ) {
|
229 |
|
|
lepvec.erase(electrons_to_erase[i]);
|
230 |
|
|
}
|
231 |
khahn |
1.1 |
|
232 |
|
|
//********************************************************
|
233 |
dkralph |
1.4 |
// Step 3: Good Leptons
|
234 |
khahn |
1.1 |
//********************************************************
|
235 |
dkralph |
1.4 |
for (int i=0; i<lepvec.size(); i++ ) {
|
236 |
|
|
if( !(lepvec[i].status.loose()) ) {
|
237 |
dkralph |
1.10 |
failingLeptons.push_back(lepvec[i]);
|
238 |
dkralph |
1.4 |
} else {
|
239 |
|
|
passingLeptons.push_back(lepvec[i]);
|
240 |
|
|
}
|
241 |
khahn |
1.1 |
}
|
242 |
dkralph |
1.4 |
|
243 |
khahn |
1.1 |
//******************************************************************************
|
244 |
dkralph |
1.4 |
// W + (OF SS lepton) Selection
|
245 |
khahn |
1.1 |
//******************************************************************************
|
246 |
dkralph |
1.7 |
if(has_ssof_lepton(ctrl)) {
|
247 |
|
|
ret.status.setStatus(SelectionStatus::EVTPASS);
|
248 |
|
|
ret.Z1leptons.push_back(passingLeptons[0]);
|
249 |
|
|
ret.Z1leptons.push_back(passingLeptons[0]);
|
250 |
|
|
ret.Z2leptons.push_back(passingLeptons[0]);
|
251 |
|
|
ret.Z2leptons.push_back(passingLeptons[0]);
|
252 |
|
|
} else {
|
253 |
|
|
ret.status.setStatus(SelectionStatus::FAIL);
|
254 |
khahn |
1.1 |
}
|
255 |
dkralph |
1.7 |
return ret;
|
256 |
dkralph |
1.4 |
}
|
257 |
|
|
//----------------------------------------------------------------------------------------
|
258 |
|
|
bool has_ssof_lepton(ControlFlags &ctrl)
|
259 |
|
|
{
|
260 |
|
|
bool has_ssof=false;
|
261 |
|
|
for(unsigned iw=0; iw<passingLeptons.size(); iw++) {
|
262 |
|
|
SimpleLepton w_lep = passingLeptons[iw];
|
263 |
|
|
//????????????????????????????????????????????????????????????????????????????????????????
|
264 |
|
|
// this is applied in skim (skim also applies ww muon id)
|
265 |
|
|
// if(abs(w_lep.type) == 11) {
|
266 |
|
|
// if( !(w_lep.tightCutsApplied) )
|
267 |
|
|
// continue;
|
268 |
|
|
// }
|
269 |
|
|
//????????????????????????????????????????????????????????????????????????????????????????
|
270 |
|
|
for(unsigned ifake=0; ifake<failingLeptons.size(); ifake++) {
|
271 |
|
|
SimpleLepton fake_lep = failingLeptons[ifake];
|
272 |
|
|
if(abs(fake_lep.type) == abs(w_lep.type)) continue;
|
273 |
|
|
if(fake_lep.charge != w_lep.charge) continue;
|
274 |
|
|
has_ssof = true;
|
275 |
|
|
}
|
276 |
|
|
for(unsigned ipass=0; ipass<passingLeptons.size(); ipass++) {
|
277 |
|
|
if(ipass == iw) continue;
|
278 |
|
|
SimpleLepton pass_lep = passingLeptons[ipass];
|
279 |
|
|
if(abs(pass_lep.type) == abs(w_lep.type)) continue;
|
280 |
|
|
if(pass_lep.charge != w_lep.charge) continue;
|
281 |
|
|
has_ssof = true;
|
282 |
khahn |
1.1 |
}
|
283 |
dkralph |
1.4 |
}
|
284 |
khahn |
1.1 |
|
285 |
dkralph |
1.4 |
return has_ssof;
|
286 |
khahn |
1.1 |
}
|