ATLAS Offline Software
CaloUtils/src/CaloSamplingHelper.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 
7 #include <algorithm>
8 
9 const std::map<std::string,CaloSampling::CaloSample> CaloSamplingHelper::m_lookUp{
10  {"PreSamplerB", CaloSampling::PreSamplerB},
11  {"EMB1", CaloSampling::EMB1},
12  {"EMB2", CaloSampling::EMB2},
13  {"EMB3", CaloSampling::EMB3},
14  {"PreSamplerE", CaloSampling::PreSamplerE},
15  {"EME1", CaloSampling::EME1},
16  {"EME2", CaloSampling::EME2},
17  {"EME3", CaloSampling::EME3},
18  {"HEC0", CaloSampling::HEC0},
19  {"HEC1", CaloSampling::HEC1},
20  {"HEC2", CaloSampling::HEC2},
21  {"HEC3", CaloSampling::HEC3},
22  {"TileBar0", CaloSampling::TileBar0},
23  {"TileBar1", CaloSampling::TileBar1},
24  {"TileBar2", CaloSampling::TileBar2},
25  {"TileGap1", CaloSampling::TileGap1},
26  {"TileGap2", CaloSampling::TileGap2},
27  {"TileGap3", CaloSampling::TileGap3},
28  {"TileExt0", CaloSampling::TileExt0},
29  {"TileExt1", CaloSampling::TileExt1},
30  {"TileExt2", CaloSampling::TileExt2},
31  {"FCal1", CaloSampling::FCAL0},
32  {"FCal2", CaloSampling::FCAL1},
33  {"FCal3", CaloSampling::FCAL2},
34  {"MiniFCal0", CaloSampling::MINIFCAL0},
35  {"MiniFCal1", CaloSampling::MINIFCAL1},
36  {"MiniFCal2", CaloSampling::MINIFCAL2},
37  {"MiniFCal3", CaloSampling::MINIFCAL3}
38 };
39 
40 const std::string CaloSamplingHelper::m_unknown="Unknown";
41 
43  //Linear search for the value in the std::map m_lookUp.
44  //Slow, but acceptable because:
45  // 1. The map has only 28 entries
46  // 2. It's and integer-comparision
47  // 3. The method is only use for log-output (eg not too often)
48 
49  //Implementation uses a C++11 lambda function
50  //[&theSample] defines the lambda function and says that it depends on the external variable theSampling (captured by reference)
51  //(std::pair<std::string,CaloSampling::CaloSample> i) is the parameter of the function
52  //{return (i.second==theSample);} Is the code of the function
53  auto it=std::find_if(m_lookUp.begin(),m_lookUp.end(),[&theSample](const std::pair<std::string,CaloSampling::CaloSample>& i) {return (i.second==theSample);});
54  if (it==m_lookUp.end())
55  return m_unknown;
56  else
57  return it->first;
58 }
59 
62 {
63  return m_lookUp.find(name) != m_lookUp.end()
64  ? (*m_lookUp.find(name)).second
66 }
67 
68 
69 bool CaloSamplingHelper::getSamplings(const std::vector<CaloCell_ID::SUBCALO>& theCalos,
70  std::vector<CaloSampling::CaloSample>& theSamplings) {
71 
72  const size_t oldSize = theSamplings.size();
73  for (auto fCalo : theCalos) {
74  switch (fCalo)
75  {
76  case CaloCell_ID::LAREM:
77  theSamplings.push_back(CaloSampling::PreSamplerB);
78  theSamplings.push_back(CaloSampling::EMB1);
79  theSamplings.push_back(CaloSampling::EMB2);
80  theSamplings.push_back(CaloSampling::EMB3);
81  theSamplings.push_back(CaloSampling::PreSamplerE);
82  theSamplings.push_back(CaloSampling::EME1);
83  theSamplings.push_back(CaloSampling::EME2);
84  theSamplings.push_back(CaloSampling::EME3);
85  break;
87  theSamplings.push_back(CaloSampling::HEC0);
88  theSamplings.push_back(CaloSampling::HEC1);
89  theSamplings.push_back(CaloSampling::HEC2);
90  theSamplings.push_back(CaloSampling::HEC3);
91  break;
93  theSamplings.push_back(CaloSampling::FCAL0);
94  theSamplings.push_back(CaloSampling::FCAL1);
95  theSamplings.push_back(CaloSampling::FCAL2);
96  break;
97  case CaloCell_ID::TILE:
98  theSamplings.push_back(CaloSampling::TileBar0);
99  theSamplings.push_back(CaloSampling::TileBar1);
100  theSamplings.push_back(CaloSampling::TileBar2);
101  theSamplings.push_back(CaloSampling::TileExt0);
102  theSamplings.push_back(CaloSampling::TileExt1);
103  theSamplings.push_back(CaloSampling::TileExt2);
104  theSamplings.push_back(CaloSampling::TileGap1);
105  theSamplings.push_back(CaloSampling::TileGap2);
106  theSamplings.push_back(CaloSampling::TileGap3);
107  break;
109  theSamplings.push_back(CaloSampling::MINIFCAL0);
110  theSamplings.push_back(CaloSampling::MINIFCAL1);
111  theSamplings.push_back(CaloSampling::MINIFCAL2);
112  theSamplings.push_back(CaloSampling::MINIFCAL3);
113  break;
114  default:
115  break;
116  }
117  }
118  return oldSize < theSamplings.size();
119 }
120 
121 
123  std::vector<CaloSampling::CaloSample>& theSamplings) {
124  const std::vector<CaloCell_ID::SUBCALO> caloVector={theCalo};
125  return getSamplings(caloVector,theSamplings);
126 }
127 
128 
129 bool CaloSamplingHelper::getCalos(const std::vector<CaloSampling::CaloSample>& theSamplings,
130  std::vector<CaloCell_ID::SUBCALO>& theCalos) {
131  const size_t oldSize = theCalos.size();
132  for (auto fSample : theSamplings) {
134  switch ( fSample ) {
136  case CaloSampling::EMB1:
137  case CaloSampling::EMB2:
138  case CaloSampling::EMB3:
140  case CaloSampling::EME1:
141  case CaloSampling::EME2:
142  case CaloSampling::EME3:
143  theCaloId = CaloCell_ID::LAREM;
144  break;
145  case CaloSampling::HEC0:
146  case CaloSampling::HEC1:
147  case CaloSampling::HEC2:
148  case CaloSampling::HEC3:
149  theCaloId = CaloCell_ID::LARHEC;
150  break;
151  case CaloSampling::FCAL0:
152  case CaloSampling::FCAL1:
153  case CaloSampling::FCAL2:
154  theCaloId = CaloCell_ID::LARFCAL;
155  break;
165  theCaloId = CaloCell_ID::TILE;
166  break;
167  case CaloSampling::MINIFCAL0:
168  case CaloSampling::MINIFCAL1:
169  case CaloSampling::MINIFCAL2:
170  case CaloSampling::MINIFCAL3:
171  theCaloId = CaloCell_ID::LARMINIFCAL;
172  break;
173  default:
174  break;
175  }
176  // check if not there yet (actually a std::set would be better than a vector)
177  if ( std::find(theCalos.begin(),theCalos.end(),theCaloId) == theCalos.end()){
178  theCalos.push_back(theCaloId);
179  }
180  }
181  return theCalos.size() > oldSize;
182 }
GetLCDefs::Unknown
@ Unknown
Definition: GetLCDefs.h:21
python.SystemOfUnits.second
int second
Definition: SystemOfUnits.py:120
CaloCell_Base_ID::LARFCAL
@ LARFCAL
Definition: CaloCell_Base_ID.h:46
CaloSamplingHelper::m_lookUp
static const std::map< std::string, CaloSampling::CaloSample > m_lookUp
Definition: CaloUtils/CaloUtils/CaloSamplingHelper.h:55
CaloCell_ID_FCS::TileExt2
@ TileExt2
Definition: FastCaloSim_CaloCell_ID.h:39
constants.EMB1
int EMB1
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:53
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
CaloCell_ID_FCS::TileExt0
@ TileExt0
Definition: FastCaloSim_CaloCell_ID.h:37
CaloCell_ID_FCS::TileBar1
@ TileBar1
Definition: FastCaloSim_CaloCell_ID.h:32
CaloCell_Base_ID::LARMINIFCAL
@ LARMINIFCAL
Definition: CaloCell_Base_ID.h:46
skel.it
it
Definition: skel.GENtoEVGEN.py:423
CaloCell_ID_FCS::FCAL1
@ FCAL1
Definition: FastCaloSim_CaloCell_ID.h:41
CaloCell_Base_ID::LARHEC
@ LARHEC
Definition: CaloCell_Base_ID.h:46
CaloCell_ID_FCS::HEC2
@ HEC2
Definition: FastCaloSim_CaloCell_ID.h:29
CaloCell_ID_FCS::TileGap3
@ TileGap3
Definition: FastCaloSim_CaloCell_ID.h:36
CaloCell_ID_FCS::HEC1
@ HEC1
Definition: FastCaloSim_CaloCell_ID.h:28
constants.EMB2
int EMB2
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:54
lumiFormat.i
int i
Definition: lumiFormat.py:92
CaloSampling::CaloSample
CaloSample
Definition: Calorimeter/CaloGeoHelpers/CaloGeoHelpers/CaloSampling.h:22
CaloCell_ID_FCS::TileBar0
@ TileBar0
Definition: FastCaloSim_CaloCell_ID.h:31
CaloCell_ID_FCS::TileGap2
@ TileGap2
Definition: FastCaloSim_CaloCell_ID.h:35
CaloCell_Base_ID::SUBCALO
SUBCALO
enumeration of sub calorimeters
Definition: CaloCell_Base_ID.h:46
CaloSamplingHelper::getCalos
static bool getCalos(const std::vector< CaloSampling::CaloSample > &theSamplings, std::vector< CaloCell_ID::SUBCALO > &theCalos)
Returns a list of sub-calos for a list of samplings.
Definition: CaloUtils/src/CaloSamplingHelper.cxx:129
constants.EME1
int EME1
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:55
CaloSamplingHelper.h
CaloCell_Base_ID::TILE
@ TILE
Definition: CaloCell_Base_ID.h:46
CaloCell_ID_FCS::TileGap1
@ TileGap1
Definition: FastCaloSim_CaloCell_ID.h:34
CaloSamplingHelper::m_unknown
static const std::string m_unknown
Definition: CaloUtils/CaloUtils/CaloSamplingHelper.h:56
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
CaloCell_ID_FCS::TileExt1
@ TileExt1
Definition: FastCaloSim_CaloCell_ID.h:38
CaloCell_ID_FCS::EME3
@ EME3
Definition: FastCaloSim_CaloCell_ID.h:26
CaloSamplingHelper::getSamplings
static bool getSamplings(const std::vector< CaloCell_ID::SUBCALO > &theCalos, std::vector< CaloSampling::CaloSample > &theSamplings)
Returns a list of samplings enumerators for a list of sub-calos.
Definition: CaloUtils/src/CaloSamplingHelper.cxx:69
CaloCell_ID_FCS::HEC0
@ HEC0
Definition: FastCaloSim_CaloCell_ID.h:27
CaloSamplingHelper::getSamplingName
static const std::string & getSamplingName(const CaloSampling::CaloSample theSample)
Returns a string (name) for each CaloSampling.
Definition: CaloUtils/src/CaloSamplingHelper.cxx:42
CaloCell_ID_FCS::PreSamplerE
@ PreSamplerE
Definition: FastCaloSim_CaloCell_ID.h:23
CaloCell_ID_FCS::PreSamplerB
@ PreSamplerB
Definition: FastCaloSim_CaloCell_ID.h:19
CaloSamplingHelper::getSamplingId
static CaloSampling::CaloSample getSamplingId(const std::string &samplingName)
Returns the CaloSampling::CaloSample enumerator value.
Definition: CaloUtils/src/CaloSamplingHelper.cxx:61
CaloCell_ID_FCS::FCAL2
@ FCAL2
Definition: FastCaloSim_CaloCell_ID.h:42
CaloCell_ID_FCS::HEC3
@ HEC3
Definition: FastCaloSim_CaloCell_ID.h:30
CaloCell_Base_ID::LAREM
@ LAREM
Definition: CaloCell_Base_ID.h:46
CaloCell_Base_ID::NOT_VALID
@ NOT_VALID
Definition: CaloCell_Base_ID.h:46
CaloCell_ID_FCS::FCAL0
@ FCAL0
Definition: FastCaloSim_CaloCell_ID.h:40
CaloCell_ID_FCS::EMB3
@ EMB3
Definition: FastCaloSim_CaloCell_ID.h:22
CaloCell_ID_FCS::TileBar2
@ TileBar2
Definition: FastCaloSim_CaloCell_ID.h:33
constants.EME2
int EME2
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:56