CMS 3D CMS Logo

HcalLayerDepthMap.cc
Go to the documentation of this file.
2 
5 #include <algorithm>
6 #include <sstream>
7 
8 //#define EDM_ML_DEBUG
9 
11  subdet_ = 0;
12  ietaMin_ = ietaMax_ = 0;
13  depthMin_ = 99;
14  depthMax_ = -1;
15  dep29C_ = 2;
16  wtl0C_ = 1.;
17 }
18 
20 
21 void HcalLayerDepthMap::initialize(const int subdet,
22  const int ietaMax,
23  const int dep16C,
24  const int dep29C,
25  const double wtl0C,
26  std::vector<int> const& iphi,
27  std::vector<int> const& ieta,
28  std::vector<int> const& layer,
29  std::vector<int> const& depth) {
30  subdet_ = subdet;
31  ietaMin_ = ietaMax_ = ietaMax;
32  dep16C_ = dep16C;
33  dep29C_ = dep29C;
34  wtl0C_ = wtl0C;
35  iphi_.insert(iphi_.end(), iphi.begin(), iphi.end());
36  layer2Depth_.clear();
37  depth2LayerF_.clear();
38  depth2LayerB_.clear();
39  depthMin_ = 99;
40  depthMax_ = -1;
41  for (unsigned int k = 0; k < ieta.size(); ++k) {
42  if (ieta[k] < ietaMin_)
43  ietaMin_ = ieta[k];
44  if (depth[k] < depthMin_)
45  depthMin_ = depth[k];
46  if (depth[k] > depthMax_)
47  depthMax_ = depth[k];
48  }
49  //Assume ieta, layer, depth are in increasing order of ieta and depth
50  for (unsigned int k1 = 0; k1 < ieta.size(); ++k1) {
51  int ietaMin = ieta[k1];
52  int ietaMax = ietaMax_;
53  int layMin = layer[k1];
54  int layMax = (k1 + 1 < ieta.size()) ? (layer[k1 + 1] - 1) : maxLayers_;
55  for (unsigned int k2 = k1 + 1; k2 < ieta.size(); ++k2) {
56  if (ieta[k2] > ieta[k1]) {
57  ietaMax = ieta[k2] - 1;
58  if (k2 == k1 + 1)
59  layMax = maxLayers_;
60  break;
61  }
62  }
63  for (int eta = ietaMin; eta <= ietaMax; ++eta) {
64  depth2LayerF_[std::pair<int, int>(eta, depth[k1])] = layMin;
65  depth2LayerB_[std::pair<int, int>(eta, depth[k1])] = layMax;
66  for (int lay = layMin; lay <= layMax; ++lay)
67  layer2Depth_[std::pair<int, int>(eta, lay)] = depth[k1];
68  }
69  }
70  for (int eta = ietaMin_; eta <= ietaMax_; ++eta) {
71  int dmin(99), dmax(-1);
72  for (auto& itr : layer2Depth_) {
73  if ((itr.first).first == eta) {
74  if ((itr.second) < dmin)
75  dmin = (itr.second);
76  if ((itr.second) > dmax)
77  dmax = (itr.second);
78  }
79  }
80  if (subdet == 2) {
81  if (eta == ietaMin_)
82  dmin = dep16C_;
83  else if (eta == ietaMax_)
84  dmax = dep29C_;
85  }
86  depthsEta_[eta] = std::pair<int, int>(dmin, dmax);
87  }
88 #ifdef EDM_ML_DEBUG
89  std::ostringstream st1;
90  st1 << "HcalLayerDepthMap: Subdet " << subdet_ << " iEta " << ietaMin_ << ":" << ietaMax_ << " depth " << depthMin_
91  << ":" << depthMax_ << "\nMaximum Depth for last HE towers " << dep29C_ << " Layer 0 Weight " << wtl0C_
92  << " iPhi";
93  for (unsigned int k = 0; k < iphi_.size(); ++k)
94  st1 << ":" << iphi_[k];
95  edm::LogVerbatim("HCalGeom") << st1.str();
96  edm::LogVerbatim("HCalGeom") << "Layer2Depth_ with " << layer2Depth_.size() << " elements" << std::endl;
97  for (std::map<std::pair<int, int>, int>::iterator itr = layer2Depth_.begin(); itr != layer2Depth_.end(); ++itr)
98  edm::LogVerbatim("HCalGeom") << "iEta " << (itr->first).first << " Layer " << (itr->first).second << " Depth "
99  << itr->second;
100  edm::LogVerbatim("HCalGeom") << "Depth2LayerFront with " << depth2LayerF_.size() << " elemsts";
101  for (std::map<std::pair<int, int>, int>::iterator itr = depth2LayerF_.begin(); itr != depth2LayerF_.end(); ++itr)
102  edm::LogVerbatim("HCalGeom") << "iEta " << (itr->first).first << " Depth " << (itr->first).second << " Layer "
103  << itr->second;
104  edm::LogVerbatim("HCalGeom") << "Depth2LayerBack with " << depth2LayerB_.size() << " elemets";
105  for (std::map<std::pair<int, int>, int>::iterator itr = depth2LayerB_.begin(); itr != depth2LayerB_.end(); ++itr)
106  edm::LogVerbatim("HCalGeom") << "iEta " << (itr->first).first << " Depth " << (itr->first).second << " Layer "
107  << itr->second;
108  edm::LogVerbatim("HCalGeom") << "DepthsEta_ with " << depthsEta_.size() << " elements";
109  for (std::map<int, std::pair<int, int> >::iterator itr = depthsEta_.begin(); itr != depthsEta_.end(); ++itr)
110  edm::LogVerbatim("HCalGeom") << "iEta " << itr->first << " Depths " << (itr->second).first << ":"
111  << (itr->second).second;
112 #endif
113 }
114 
116  const int subdet, const int ieta, const int iphi, const int zside, const int layer) const {
117  int depth(-1);
118  if (isValid(subdet, iphi, zside)) {
119  std::map<std::pair<int, int>, int>::const_iterator itr = layer2Depth_.find(std::pair<int, int>(ieta, layer));
120  if (itr != layer2Depth_.end())
121  depth = itr->second;
122  }
123 #ifdef EDM_ML_DEBUG
124  edm::LogVerbatim("HCalGeom") << "Debug Info -- getDepth::Input " << subdet << ":" << ieta << ":" << iphi << ":"
125  << zside << ":" << layer << " Output " << depth;
126 #endif
127  return depth;
128 }
129 
130 int HcalLayerDepthMap::getDepth16(const int subdet, const int iphi, const int zside) const {
131  int depth(-1);
132  if (isValid(subdet, iphi, zside))
133  depth = dep16C_;
134 #ifdef EDM_ML_DEBUG
135  edm::LogVerbatim("HCalGeom") << "Debug info -- getDepth16::Input " << subdet << ":" << iphi << ":" << zside
136  << " Output " << depth;
137 #endif
138  return depth;
139 }
140 
141 int HcalLayerDepthMap::getDepthMin(const int subdet, const int iphi, const int zside) const {
142  int depth = (isValid(subdet, iphi, zside)) ? depthMin_ : -1;
143 #ifdef EDM_ML_DEBUG
144  edm::LogVerbatim("HCalGeom") << "Debug info -- getDepthMin::Input " << subdet << ":" << iphi << ":" << zside
145  << " Output " << depth;
146 #endif
147  return depth;
148 }
149 
150 int HcalLayerDepthMap::getDepthMax(const int subdet, const int iphi, const int zside) const {
151  int depth = (isValid(subdet, iphi, zside)) ? depthMax_ : -1;
152 #ifdef EDM_ML_DEBUG
153  edm::LogVerbatim("HCalGeom") << "Debug info -- getDepthMax::Input " << subdet << ":" << iphi << ":" << zside
154  << " Output " << depth;
155 #endif
156  return depth;
157 }
158 
159 int HcalLayerDepthMap::getDepthMax(const int subdet, const int ieta, const int iphi, const int zside) const {
160  int depth = (isValid(subdet, iphi, zside)) ? getDepth(subdet, ieta, iphi, zside, maxLayers_) : -1;
161 #ifdef EDM_ML_DEBUG
162  edm::LogVerbatim("HCalGeom") << "Debug info -- getDepthMax::Input " << subdet << ":" << iphi << ":" << zside
163  << " Output " << depth;
164 #endif
165  return depth;
166 }
167 
168 std::pair<int, int> HcalLayerDepthMap::getDepths(const int eta) const {
169  std::map<int, std::pair<int, int> >::const_iterator itr = depthsEta_.find(eta);
170  if (itr == depthsEta_.end())
171  return std::pair<int, int>(-1, -1);
172  else
173  return itr->second;
174 }
175 
177  const int subdet, const int ieta, const int iphi, const int zside, const int depth) const {
178  int layer(-1);
179  if (isValid(subdet, iphi, zside)) {
180  std::map<std::pair<int, int>, int>::const_iterator itr = depth2LayerF_.find(std::pair<int, int>(ieta, depth));
181  if (itr != depth2LayerF_.end())
182  layer = itr->second;
183  }
184 #ifdef EDM_ML_DEBUG
185  edm::LogVerbatim("HCalGeom") << "Debug info -- getLayerFront::Input " << subdet << ":" << ieta << ":" << iphi << ":"
186  << zside << ":" << depth << " Output " << layer;
187 #endif
188  return layer;
189 }
190 
192  const int subdet, const int ieta, const int iphi, const int zside, const int depth) const {
193  int layer(-1);
194  if (isValid(subdet, iphi, zside)) {
195  std::map<std::pair<int, int>, int>::const_iterator itr = depth2LayerB_.find(std::pair<int, int>(ieta, depth));
196  if (itr != depth2LayerB_.end())
197  layer = itr->second;
198  }
199 #ifdef EDM_ML_DEBUG
200  edm::LogVerbatim("HCalGeom") << "Debug info -- getLayerBack::Input " << subdet << ":" << ieta << ":" << iphi << ":"
201  << zside << ":" << depth << " Output " << layer;
202 #endif
203  return layer;
204 }
205 
207  const int subdet, const int eta, const int phi, const int zside, std::map<int, int>& layers) const {
208  layers.clear();
209  if (isValid(subdet, phi, zside)) {
210  for (const auto& itr : layer2Depth_) {
211  if ((itr.first).first == eta) {
212  layers[((itr.first).second) + 1] = (itr.second);
213  }
214  }
215  }
216 #ifdef EDM_ML_DEBUG
217  edm::LogVerbatim("HCalGeom") << "Debug info -- getLayerDepth::Input " << subdet << ":" << eta << ":" << phi << ":"
218  << zside << " Output " << layers.size() << " entries";
219  std::ostringstream st1;
220  for (std::map<int, int>::iterator itr = layers.begin(); itr != layers.end(); ++itr)
221  st1 << " [" << itr->first << "] " << itr->second;
222  edm::LogVerbatim("HCalGeom") << st1.str();
223 #endif
224 }
225 
226 void HcalLayerDepthMap::getLayerDepth(const int eta, std::map<int, int>& layers) const {
227  layers.clear();
228  if (subdet_ > 0) {
229  for (const auto& itr : layer2Depth_) {
230  if ((itr.first).first == eta) {
231  layers[((itr.first).second) + 1] = (itr.second);
232  }
233  }
234  }
235 #ifdef EDM_ML_DEBUG
236  edm::LogVerbatim("HCalGeom") << "Debug info -- getLayerDepth::Input " << eta << " Output " << layers.size()
237  << " entries";
238  std::ostringstream st1;
239  for (std::map<int, int>::iterator itr = layers.begin(); itr != layers.end(); ++itr)
240  st1 << " [" << itr->first << "] " << itr->second;
241  edm::LogVerbatim("HCalGeom") << st1.str();
242 #endif
243 }
244 
245 int HcalLayerDepthMap::getMaxDepthLastHE(const int subdet, const int iphi, const int zside) const {
246  int depth = isValid(subdet, iphi, zside) ? dep29C_ : -1;
247 #ifdef EDM_ML_DEBUG
248  edm::LogVerbatim("HCalGeom") << "Debug info -- getMaxDepthLastHE::Input " << subdet << ":" << iphi << ":" << zside
249  << " Output " << depth;
250 #endif
251  return depth;
252 }
253 
254 double HcalLayerDepthMap::getLayer0Wt(const int subdet, const int iphi, const int zside) const {
255  double wt = isValid(subdet, iphi, zside) ? wtl0C_ : -1.0;
256 #ifdef EDM_ML_DEBUG
257  edm::LogVerbatim("HCalGeom") << "HcalLayerDepthMap -- getLayer0Wt::Input " << subdet << ":" << iphi << ":" << zside
258  << " Output " << wt;
259 #endif
260  return wt;
261 }
262 
263 bool HcalLayerDepthMap::isValid(const int subdet, const int iphi, const int zside) const {
264  bool flag(false);
265  int kphi = (zside > 0) ? iphi : -iphi;
266  if (subdet == subdet_)
267  flag = (std::find(iphi_.begin(), iphi_.end(), kphi) != iphi_.end());
268  return flag;
269 }
270 
271 int HcalLayerDepthMap::validDet(std::vector<int>& phi) const {
272  phi.insert(phi.end(), iphi_.begin(), iphi_.end());
273  return subdet_;
274 }
double getLayer0Wt(const int subdet, const int iphi, const int zside) const
Log< level::Info, true > LogVerbatim
int getDepth(const int subdet, const int ieta, const int iphi, const int zside, const int layer) const
void initialize(const int subdet, const int ietaMax, const int dep16C, const int dep29C, const double wtl0C, std::vector< int > const &iphi, std::vector< int > const &ieta, std::vector< int > const &layer, std::vector< int > const &depth)
bool isValid(const int det, const int phi, const int zside) const
int getLayerFront(const int subdet, const int ieta, const int iphi, const int zside, const int depth) const
std::map< std::pair< int, int >, int > depth2LayerB_
int zside(DetId const &)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
std::map< std::pair< int, int >, int > layer2Depth_
U second(std::pair< T, U > const &p)
int getMaxDepthLastHE(const int subdet, const int iphi, const int zside) const
std::pair< int, int > getDepths(const int eta) const
std::map< int, std::pair< int, int > > depthsEta_
std::map< std::pair< int, int >, int > depth2LayerF_
int getLayerBack(const int subdet, const int ieta, const int iphi, const int zside, const int depth) const
int getDepthMin(const int subdet, const int iphi, const int zside) const
std::vector< int > iphi_
int getDepthMax(const int subdet, const int iphi, const int zside) const
int getDepth16(const int subdet, const int iphi, const int zside) const
void getLayerDepth(const int subdet, const int ieta, const int iphi, const int zside, std::map< int, int > &layers) const
static const int maxLayers_
int validDet(std::vector< int > &phis) const