ATLAS Offline Software
Loading...
Searching...
No Matches
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
10
11const 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
42const 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
63CaloSamplingHelper::getSamplingId(const std::string& name)
64{
65 return m_lookUp.find(name) != m_lookUp.end()
66 ? (*m_lookUp.find(name)).second
67 : CaloSampling::Unknown;
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) {
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;
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
122bool 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
127bool 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}
CaloCell_Base_ID::SUBCALO SUBCALO
Definition CaloCell_ID.h:50
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.
static const std::map< std::string, CaloSampling::CaloSample > m_lookUp
static CaloSampling::CaloSample getSamplingId(const std::string &samplingName)
Returns the CaloSampling::CaloSample enumerator value.
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.
static const std::string & getSamplingName(const CaloSampling::CaloSample theSample)
Returns a string (name) for each CaloSampling.