ATLAS Offline Software
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 
7 NAME: TForwardElectronIsEMSelector.cxx
8 PACKAGE: 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 */
21  m_cutPositionBinEta_ForwardElectron(0)
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 */
27  m_cutPositionSECONDLAMBDA_ForwardElectron(0)
28  ,
29  // @brief Et <0 */
30  m_cutPositionLATERAL_ForwardElectron(0)
31  ,
32  // @brief energy ratio in 2nd sampling (e.g E237/E277) */
33  m_cutPositionLONGITUDINAL_ForwardElectron(0)
34  ,
35  // @brief energy ratio in 2nd sampling (e.g E233/E237) */
36  m_cutPositionCELLMAXFRAC_ForwardElectron(0)
37  ,
38  // @brief width in the second sampling (e.g Weta2) */
39  m_cutPositionSECONDR_ForwardElectron(0)
40  ,
41  // @brief energy fraction in the third layer */
42  m_cutPositionCENTERLAMBDA_ForwardElectron(0)
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 //=============================================================================
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 */
94  m_cutPositionBinEta_ForwardElectron = m_acceptInfo.addCut(
95  m_cutNameBinEta_ForwardElectron, "Electron within eta range");
96  if (m_cutPositionBinEta_ForwardElectron < 0)
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 */
106  m_cutPositionSECONDLAMBDA_ForwardElectron = m_acceptInfo.addCut(
107  m_cutNameSECONDLAMBDA_ForwardElectron, "secondLambda < Cut");
108  if (m_cutPositionSECONDLAMBDA_ForwardElectron < 0)
109  sc = StatusCode::FAILURE;
110 
111  // @brief et < 0 bit 3 */
112  m_cutPositionLATERAL_ForwardElectron =
113  m_acceptInfo.addCut(m_cutNameLATERAL_ForwardElectron, "lateral <0 Cut");
114  if (m_cutPositionLATERAL_ForwardElectron < 0)
115  sc = StatusCode::FAILURE;
116 
117  // @brief energy ratio in 2nd sampling (i.e. E237/E277), bit 4 */
118  m_cutPositionLONGITUDINAL_ForwardElectron = m_acceptInfo.addCut(
119  m_cutNameLONGITUDINAL_ForwardElectron, "longitudinal <Cut");
120  if (m_cutPositionLONGITUDINAL_ForwardElectron < 0)
121  sc = StatusCode::FAILURE;
122 
123  // @brief energy ratio in 2nd sampling (i.e. E233/E237), bit 5 */
124  m_cutPositionCELLMAXFRAC_ForwardElectron =
125  m_acceptInfo.addCut(m_cutNameCELLMAXFRAC_ForwardElectron, "fracMax > Cut");
126  if (m_cutPositionCELLMAXFRAC_ForwardElectron < 0)
127  sc = StatusCode::FAILURE;
128 
129  // @brief width in the second sampling (i.e. Weta2), bit 6 */
130  m_cutPositionSECONDR_ForwardElectron =
131  m_acceptInfo.addCut(m_cutNameSECONDR_ForwardElectron, "SecondR < Cut");
132  if (m_cutPositionSECONDR_ForwardElectron < 0)
133  sc = StatusCode::FAILURE;
134 
135  // @brief energy fraction in the third layer, bit 7 */
136  m_cutPositionCENTERLAMBDA_ForwardElectron = m_acceptInfo.addCut(
137  m_cutNameCENTERLAMBDA_ForwardElectron, "CenterLambda < Cut");
138  if (m_cutPositionCENTERLAMBDA_ForwardElectron < 0)
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 // ======================================================================
162 unsigned 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
200  if (checkVar(m_cutSECONDR_ForwardElectron, 4)) {
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
209  if (checkVar(m_cutSECONDLAMBDA_ForwardElectron, 4)) {
210  if (secondLambda >= m_cutSECONDLAMBDA_ForwardElectron[ibin_combined]) {
211  iflag |= (0x1 << egammaPID::SECONDLAMBDA_ForwardElectron);
212  ATH_MSG_DEBUG("Fail SecondLambda "
213  << secondLambda << " > "
214  << m_cutSECONDLAMBDA_ForwardElectron[ibin_combined]);
215  }
216  }
217  // ---------
218  // check lateral
219  if (checkVar(m_cutLATERAL_ForwardElectron, 4)) {
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
228  if (checkVar(m_cutLONGITUDINAL_ForwardElectron, 4)) {
229  if (longitudinal >= m_cutLONGITUDINAL_ForwardElectron[ibin_combined]) {
230  iflag |= (0x1 << egammaPID::LONGITUDINAL_ForwardElectron);
231  ATH_MSG_DEBUG("Fail Longitudinal "
232  << longitudinal << " > "
233  << m_cutLONGITUDINAL_ForwardElectron[ibin_combined]);
234  }
235  }
236  // check fracMax
237  if (checkVar(m_cutCELLMAXFRAC_ForwardElectron, 4)) {
238  if (fracMax < m_cutCELLMAXFRAC_ForwardElectron[ibin_combined]) {
239  iflag |= (0x1 << egammaPID::CELLMAXFRAC_ForwardElectron);
240  ATH_MSG_DEBUG("Fail fracMax "
241  << fracMax << " < "
242  << m_cutCELLMAXFRAC_ForwardElectron[ibin_combined]);
243  }
244  }
245  // check CENTERLAMBDA
246  if (checkVar(m_cutCENTERLAMBDA_ForwardElectron, 4)) {
247  if (centerLambda >= m_cutCENTERLAMBDA_ForwardElectron[ibin_combined]) {
248  iflag |= (0x1 << egammaPID::CENTERLAMBDA_ForwardElectron);
249  ATH_MSG_DEBUG("Fail CENTERLAMBDA "
250  << centerLambda << " > "
251  << m_cutCENTERLAMBDA_ForwardElectron[ibin_combined]);
252  }
253  }
254  }
255 
256  return iflag;
257 }
258 
259 std::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 
321 template<typename T>
322 bool
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 
408 template bool
409 Root::TForwardElectronIsEMSelector::checkVar<float>(
410  const std::vector<float>& vec,
411  int choice) const;
412 template bool
413 Root::TForwardElectronIsEMSelector::checkVar<int>(const std::vector<int>& vec,
414  int choice) const;
Root::TForwardElectronIsEMSelector::fillAccept
asg::AcceptData fillAccept(unsigned int isEM) const
Definition: TForwardElectronIsEMSelector.cxx:150
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
egammaPID::BinEta_ForwardElectron
@ BinEta_ForwardElectron
cluster eta range
Definition: egammaPIDdefs.h:618
python.App.bins
bins
Definition: App.py:410
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
egammaPID::LATERAL_ForwardElectron
@ LATERAL_ForwardElectron
lateral shape moment
Definition: egammaPIDdefs.h:622
Root::TForwardElectronIsEMSelector::m_cutPositionLATERAL_ForwardElectron
int m_cutPositionLATERAL_ForwardElectron
Definition: TForwardElectronIsEMSelector.h:131
Root::TForwardElectronIsEMSelector::m_cutPositionCELLMAXFRAC_ForwardElectron
int m_cutPositionCELLMAXFRAC_ForwardElectron
Definition: TForwardElectronIsEMSelector.h:133
asg
Definition: DataHandleTestTool.h:28
Root::TForwardElectronIsEMSelector::m_cutPositionLONGITUDINAL_ForwardElectron
int m_cutPositionLONGITUDINAL_ForwardElectron
Definition: TForwardElectronIsEMSelector.h:132
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
Root::TForwardElectronIsEMSelector::calocuts_electrons
unsigned int calocuts_electrons(float eta, float nvtx, float secondLambda, float lateral, float longitudinal, float fracMax, float centerLambda, float secondR, unsigned int iflag) const
Definition: TForwardElectronIsEMSelector.cxx:163
egammaPID::LONGITUDINAL_ForwardElectron
@ LONGITUDINAL_ForwardElectron
Longitudinal shape moment.
Definition: egammaPIDdefs.h:624
python.utils.AtlRunQueryLookup.mask
string mask
Definition: AtlRunQueryLookup.py:460
Root::TForwardElectronIsEMSelector::m_cutPositionSECONDR_ForwardElectron
int m_cutPositionSECONDR_ForwardElectron
Definition: TForwardElectronIsEMSelector.h:134
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
Root::TForwardElectronIsEMSelector::TForwardElectronIsEMSelector
TForwardElectronIsEMSelector(const char *name="TForwardElectronIsEMSelector")
Standard constructor.
Definition: TForwardElectronIsEMSelector.cxx:15
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
egammaPID::CELLMAXFRAC_ForwardElectron
@ CELLMAXFRAC_ForwardElectron
cell max frac shape moment
Definition: egammaPIDdefs.h:626
lumiFormat.i
int i
Definition: lumiFormat.py:92
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
egammaPID::CENTERLAMBDA_ForwardElectron
@ CENTERLAMBDA_ForwardElectron
center lambda shape moment
Definition: egammaPIDdefs.h:630
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
Root::TForwardElectronIsEMSelector::m_cutPositionCENTERLAMBDA_ForwardElectron
int m_cutPositionCENTERLAMBDA_ForwardElectron
Definition: TForwardElectronIsEMSelector.h:135
TForwardElectronIsEMSelector.h
Root::TForwardElectronIsEMSelector::initialize
StatusCode initialize()
Initialize this class.
Definition: TForwardElectronIsEMSelector.cxx:83
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
asg::AcceptData::setCutResult
void setCutResult(const std::string &cutName, bool cutResult)
Set the result of a cut, based on the cut name (safer)
Definition: AcceptData.h:134
python.AtlRunQueryAMI.choice
int choice
Definition: AtlRunQueryAMI.py:210
Root::TForwardElectronIsEMSelector::m_cutPositionSECONDLAMBDA_ForwardElectron
int m_cutPositionSECONDLAMBDA_ForwardElectron
Definition: TForwardElectronIsEMSelector.h:130
Root::TForwardElectronIsEMSelector::findNvtxEtaBin
std::vector< int > findNvtxEtaBin(float nvtx, double eta) const
Definition: TForwardElectronIsEMSelector.cxx:260
Root::TForwardElectronIsEMSelector::checkVar
bool checkVar(const std::vector< T > &vec, int choice) const
Definition: TForwardElectronIsEMSelector.cxx:323
Root::TForwardElectronIsEMSelector::~TForwardElectronIsEMSelector
~TForwardElectronIsEMSelector()
Standard destructor.
egammaPID::SECONDLAMBDA_ForwardElectron
@ SECONDLAMBDA_ForwardElectron
second lambda shape moment
Definition: egammaPIDdefs.h:620
asg::AcceptData
Definition: AcceptData.h:30
egammaPID::SECONDR_ForwardElectron
@ SECONDR_ForwardElectron
secondR shape moment
Definition: egammaPIDdefs.h:628