ATLAS Offline Software
Loading...
Searching...
No Matches
TForwardElectronIsEMSelector.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3*/
4
5/********************************************************************
6
7NAME: TForwardElectronIsEMSelector.cxx
8PACKAGE: PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools
9
10*********************************************************************/
11
13#include <cmath>
14
16 const char* name)
17 : asg::AsgMessaging(std::string(name))
18 , m_isEMMask(0)
19 , // All will pass if not specified
20 // @brief cluster eta range */
22 ,
23 // @brief matching to photon (not necessarily conversion--the name is
24 // historical) */
25 // m_cutPositionVxp_ForwardElectron(0),
26 // @brief cluster leakage o the hadronic calorimeter */
28 ,
29 // @brief Et <0 */
31 ,
32 // @brief energy ratio in 2nd sampling (e.g E237/E277) */
34 ,
35 // @brief energy ratio in 2nd sampling (e.g E233/E237) */
37 ,
38 // @brief width in the second sampling (e.g Weta2) */
40 ,
41 // @brief energy fraction in the third layer */
43 ,
44 // @brief cluster eta range */
45 m_cutNameBinEta_ForwardElectron("BinEta_ForwardElectron")
46 ,
47 // @brief matching to photon (not necessarily conversion--the name is
48 // historical) */
49 // m_cutNameVxp_ForwardElectron("Vxp_ForwardElectron"),
50 // @brief cluster leakage into the hadronic calorimeter */
51 m_cutNameSECONDLAMBDA_ForwardElectron("SECONDLAMBDA_ForwardElectron")
52 ,
53 // @brief shower width weighted by distance from the maximum one */
54 m_cutNameLATERAL_ForwardElectron("LATERAL_ForwardElectron")
55 ,
56 // @brief difference between max and 2nd max in strips */
57 m_cutNameLONGITUDINAL_ForwardElectron("LONGITUDINAL_ForwardElectron")
58 ,
59 // @brief B layer hit */
60 m_cutNameCELLMAXFRAC_ForwardElectron("CELLMAXFRAC_ForwardElectron")
61 ,
62 // @brief number of Pixel hits */
63 m_cutNameSECONDR_ForwardElectron("SECONDR_ForwardElectron")
64 ,
65 // @brief number of Pixel and SCT hits */
66 m_cutNameCENTERLAMBDA_ForwardElectron("CENTERLAMBDA_ForwardElectron")
67{
74}
75
76// ====================================================================
78
79//=============================================================================
80// Initialize this selector tool
81//=============================================================================
82StatusCode
84{
85
86 StatusCode sc(StatusCode::SUCCESS);
87
88 // --------------------------------------------------------------------------
89 // Register the cuts and check that the registration worked:
90 // NOTE: THE ORDER IS IMPORTANT!!! Cut0 corresponds to bit 0, Cut1 to bit
91 // 1,...
92
93 // @brief cluster eta range, bit 0 */
95 m_cutNameBinEta_ForwardElectron, "Electron within eta range");
97 sc = StatusCode::FAILURE;
98
99 // @brief matching to photon (not necessarily conversion--the name is
100 // historical), but 1 */ m_cutPositionVxp_ForwardElectron =
101 // m_acceptInfo.addCut(m_cutNameVxp_ForwardElectron, "Electron matches a
102 // photon with AR > LOOSE");
103 // if (m_cutPositionVxp_ForwardElectron < 0) sc = StatusCode::FAILURE;
104
105 // @brief cluster leakage into the hadronic calorimeter, bit 2 */
107 m_cutNameSECONDLAMBDA_ForwardElectron, "secondLambda < Cut");
109 sc = StatusCode::FAILURE;
110
111 // @brief et < 0 bit 3 */
113 m_acceptInfo.addCut(m_cutNameLATERAL_ForwardElectron, "lateral <0 Cut");
115 sc = StatusCode::FAILURE;
116
117 // @brief energy ratio in 2nd sampling (i.e. E237/E277), bit 4 */
119 m_cutNameLONGITUDINAL_ForwardElectron, "longitudinal <Cut");
121 sc = StatusCode::FAILURE;
122
123 // @brief energy ratio in 2nd sampling (i.e. E233/E237), bit 5 */
125 m_acceptInfo.addCut(m_cutNameCELLMAXFRAC_ForwardElectron, "fracMax > Cut");
127 sc = StatusCode::FAILURE;
128
129 // @brief width in the second sampling (i.e. Weta2), bit 6 */
131 m_acceptInfo.addCut(m_cutNameSECONDR_ForwardElectron, "SecondR < Cut");
133 sc = StatusCode::FAILURE;
134
135 // @brief energy fraction in the third layer, bit 7 */
137 m_cutNameCENTERLAMBDA_ForwardElectron, "CenterLambda < Cut");
139 sc = StatusCode::FAILURE;
140
141 if (sc == StatusCode::FAILURE) {
143 "Exceeded the number of allowed cuts in TForwardElectronIsEMSelector");
144 }
145
146 return sc;
147}
148
151{
152 asg::AcceptData acceptData(&m_acceptInfo);
153 for (int i = 0; i < 7; i++) {
154 const unsigned int mask = (0x1 << i) & m_isEMMask;
155 acceptData.setCutResult(i, (isEM & mask) == 0);
156 }
157 ATH_MSG_DEBUG("acceptData " << (bool)acceptData);
158 return acceptData;
159}
160
161// ======================================================================
162unsigned int
164 // eta position in second sampling
165 float eta,
166 // transverse energy in calorimeter (using eta position in second sampling)
167 float nvtx,
168 // E(3*3) in 2nd sampling 233
169 float secondLambda,
170 // E(3*7) in 2nd sampling
171 float lateral,
172 // transverse energy in 1st scintillator of hadronic calorimeter
173 float longitudinal,
174 // E(min) in strips (emin)
175 float fracMax,
176 // total shower width in 1st sampling
177 float centerLambda,
178 // fraction of energy reconstructed in the 3rd sampling
179 float secondR,
180 // the starting isEM (should be 0 if new)
181 unsigned int iflag) const
182{
183 // modifiy et when dealing with trigger
184 // to be sure that it will take the correct bin (VD)
185 std::vector<int> bins = findNvtxEtaBin(nvtx, eta);
186 int ibin_nvtx = bins.at(0);
187 int ibin_eta = bins.at(1);
188 int ibin_combined = bins.at(2);
189
190 // check eta range
191 if (eta < 2.5) {
192 iflag |= (0x1 << egammaPID::BinEta_ForwardElectron);
193 ATH_MSG_DEBUG("Fail eta");
194 }
195
196 // check if index is defined
197 if (ibin_eta >= 0 && ibin_nvtx >= 0 && ibin_combined >= 0) {
198
199 // check secondR
201 if (secondR >= m_cutSECONDR_ForwardElectron[ibin_combined]) {
202 iflag |= (0x1 << egammaPID::SECONDR_ForwardElectron);
203 ATH_MSG_DEBUG("Fail SecondR "
204 << secondR << " > "
205 << m_cutSECONDR_ForwardElectron[ibin_combined]);
206 }
207 }
208 // check secondlambda
210 if (secondLambda >= m_cutSECONDLAMBDA_ForwardElectron[ibin_combined]) {
212 ATH_MSG_DEBUG("Fail SecondLambda "
213 << secondLambda << " > "
214 << m_cutSECONDLAMBDA_ForwardElectron[ibin_combined]);
215 }
216 }
217 // ---------
218 // check lateral
220 if (lateral >= m_cutLATERAL_ForwardElectron[ibin_combined]) {
221 iflag |= (0x1 << egammaPID::LATERAL_ForwardElectron);
222 ATH_MSG_DEBUG("Fail LATERAL "
223 << lateral << " > "
224 << m_cutLATERAL_ForwardElectron[ibin_combined]);
225 }
226 }
227 // check longitudinal
229 if (longitudinal >= m_cutLONGITUDINAL_ForwardElectron[ibin_combined]) {
231 ATH_MSG_DEBUG("Fail Longitudinal "
232 << longitudinal << " > "
233 << m_cutLONGITUDINAL_ForwardElectron[ibin_combined]);
234 }
235 }
236 // check fracMax
238 if (fracMax < m_cutCELLMAXFRAC_ForwardElectron[ibin_combined]) {
240 ATH_MSG_DEBUG("Fail fracMax "
241 << fracMax << " < "
242 << m_cutCELLMAXFRAC_ForwardElectron[ibin_combined]);
243 }
244 }
245 // check CENTERLAMBDA
247 if (centerLambda >= m_cutCENTERLAMBDA_ForwardElectron[ibin_combined]) {
249 ATH_MSG_DEBUG("Fail CENTERLAMBDA "
250 << centerLambda << " > "
251 << m_cutCENTERLAMBDA_ForwardElectron[ibin_combined]);
252 }
253 }
254 }
255
256 return iflag;
257}
258
259std::vector<int>
261{
262 // Try to figure out in which bin we belong
263 int ibin_nvtx = -1;
264 // loop on nvtx range
265 if (!m_cutVxp_ForwardElectron.empty()) {
266 for (unsigned int ibinNVTX = 0; ibinNVTX < m_cutVxp_ForwardElectron.size();
267 ++ibinNVTX) {
268 if (ibinNVTX == 0) {
269 if (nvtx < m_cutVxp_ForwardElectron[ibinNVTX]) {
270 ibin_nvtx = ibinNVTX;
271 }
272 } else if (ibinNVTX > 0 && ibinNVTX < m_cutVxp_ForwardElectron.size()) {
273 if (nvtx >= m_cutVxp_ForwardElectron[ibinNVTX - 1] &&
274 nvtx < m_cutVxp_ForwardElectron[ibinNVTX]) {
275 ibin_nvtx = ibinNVTX;
276 }
277 } else if (ibinNVTX == m_cutVxp_ForwardElectron.size()) {
278 if (nvtx >= m_cutVxp_ForwardElectron[ibinNVTX - 1]) {
279 ibin_nvtx = ibinNVTX;
280 }
281 }
282 }
283 }
284 int ibin_eta = -1;
285 // loop on eta range
286 for (unsigned int ibinEta = 0; ibinEta < m_cutBinEta_ForwardElectron.size();
287 ++ibinEta) {
288 if (ibinEta == 0) {
289 if (eta < m_cutBinEta_ForwardElectron[ibinEta]) {
290 ibin_eta = ibinEta;
291 }
292 } else if (ibinEta > 0 && ibinEta < m_cutBinEta_ForwardElectron.size()) {
293 if (eta >= m_cutBinEta_ForwardElectron[ibinEta - 1] &&
294 eta < m_cutBinEta_ForwardElectron[ibinEta]) {
295 ibin_eta = ibinEta;
296 }
297 } else if (ibinEta == m_cutBinEta_ForwardElectron.size()) {
298 if (eta >= m_cutBinEta_ForwardElectron[ibinEta - 1]) {
299 ibin_eta = ibinEta;
300 }
301 }
302 }
303
304 // int ibin_combined = ibin_nvtx*m_cutBinEta_ForwardElectron.size()+ibin_eta;
305 int ibin_combined = -1;
306 if (ibin_eta == 2) {
307 ibin_combined = ibin_nvtx * ibin_eta - 1;
308 } else if (ibin_eta == 1) {
309 ibin_combined = 2 * (ibin_nvtx * ibin_eta - 1);
310 } else {
311 ATH_MSG_INFO(" Not posible ");
312 }
313 // int ibin_combined = ibin_nvtx*ibin_eta-1;
314 // check the bin number
315 std::vector<int> bins{ ibin_nvtx, ibin_eta, ibin_combined };
316 return bins;
317}
318
319// ==============================================================
320
321template<typename T>
322bool
324 int choice) const
325{
326 // check vector size
327 // 0 : size should be 1
328 // 1 : vs etaNB
329 // 2 : vs etaTRTNB
330 // 3 : vs etNB
331 // 4 : vs combinedNB
332 // 5 : vs combinedTRTNB
333
334 // if size of vector is 0 it means cut is not defined
335 if (vec.empty())
336 return false;
337
338 unsigned int etaNB = m_cutBinEta_ForwardElectron.size();
339 unsigned int etaTRTNB = 1;
340 unsigned int etNB = m_cutVxp_ForwardElectron.size();
341 // unsigned int etTRTNB = 1;
342 unsigned int combinedNB = 0;
343 unsigned int combinedTRTNB = 0;
344
345 if (etNB > 1) {
346 // combinedNB = etaNB * (etNB+1);
347 combinedNB = (etaNB - 1) * (etNB - 1);
348 } else {
349 combinedNB = etaNB;
350 }
351
352 combinedTRTNB = etaTRTNB;
353
354 // check if size is 1 (give choice 0)
355 if (choice == 0) {
356 if (vec.size() != 1) {
357 ATH_MSG_ERROR("choice 0 vector size is " << vec.size() << " but needs 1");
358 return false;
359 }
360 }
361
362 // check if size is etaNB
363 if (choice == 1) {
364 if (vec.size() != etaNB) {
365 ATH_MSG_ERROR("choice 1 vector size is " << vec.size() << " but needs "
366 << etaNB);
367 return false;
368 }
369 }
370 // check if size is etaTRTNB
371 if (choice == 2) {
372 if (vec.size() != etaTRTNB) {
373 ATH_MSG_ERROR("choice 2 vector size is " << vec.size() << " but needs "
374 << etaTRTNB);
375 return false;
376 }
377 }
378
379 // check if size is etNB
380 if (choice == 3) {
381 if (vec.size() != etNB) {
382 ATH_MSG_ERROR("choice 3 vector size is " << vec.size() << " but needs "
383 << etNB);
384 return false;
385 }
386 }
387
388 // check if size is combinedNB
389 if (choice == 4) {
390 if (vec.size() != combinedNB) {
391 ATH_MSG_ERROR("choice 4 vector size is " << vec.size() << " but needs "
392 << combinedNB);
393 return false;
394 }
395 }
396
397 // check if size is etaTRTNB
398 if (choice == 5) {
399 if (vec.size() != combinedTRTNB) {
400 ATH_MSG_ERROR("choice 5 vector size is " << vec.size() << " but needs "
401 << combinedTRTNB);
402 return false;
403 }
404 }
405 return true;
406}
407
408template bool
410 const std::vector<float>& vec,
411 int choice) const;
412template bool
414 int choice) const;
Scalar eta() const
pseudorapidity method
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
std::vector< size_t > vec
static Double_t sc
static const std::vector< std::string > bins
asg::AcceptData fillAccept(unsigned int isEM) const
std::vector< float > m_cutLONGITUDINAL_ForwardElectron
cut on longitudinal
std::vector< float > m_cutCELLMAXFRAC_ForwardElectron
cut on maxFrac
unsigned int calocuts_electrons(float eta, float nvtx, float secondLambda, float lateral, float longitudinal, float fracMax, float centerLambda, float secondR, unsigned int iflag) const
bool checkVar(const std::vector< T > &vec, int choice) const
TForwardElectronIsEMSelector(const char *name="TForwardElectronIsEMSelector")
Standard constructor.
std::vector< float > m_cutLATERAL_ForwardElectron
cut on lateral
std::vector< float > m_cutCENTERLAMBDA_ForwardElectron
cut on centerlambda
std::vector< float > m_cutBinEta_ForwardElectron
range of eta bins for e-ID
unsigned int m_isEMMask
which subset of cuts to apply
std::vector< int > findNvtxEtaBin(float nvtx, double eta) const
std::vector< float > m_cutSECONDR_ForwardElectron
cut values for cut on secondR
StatusCode initialize()
Initialize this class.
std::vector< float > m_cutSECONDLAMBDA_ForwardElectron
cut on secondlambda
~TForwardElectronIsEMSelector()
Standard destructor.
std::vector< float > m_cutVxp_ForwardElectron
range of NPV bins for e-ID
void setCutResult(const std::string &cutName, bool cutResult)
Set the result of a cut, based on the cut name (safer)
Definition AcceptData.h:134
AsgMessaging(const std::string &name)
Constructor with a name.
STL class.
@ LONGITUDINAL_ForwardElectron
Longitudinal shape moment.
@ CENTERLAMBDA_ForwardElectron
center lambda shape moment
@ SECONDR_ForwardElectron
secondR shape moment
@ CELLMAXFRAC_ForwardElectron
cell max frac shape moment
@ LATERAL_ForwardElectron
lateral shape moment
@ SECONDLAMBDA_ForwardElectron
second lambda shape moment
@ BinEta_ForwardElectron
cluster eta range
STL namespace.