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