CMS 3D CMS Logo

eHCALMatrix.cc
Go to the documentation of this file.
4 
5 #include <algorithm>
6 #include <iostream>
7 
8 //#define EDM_ML_DEBUG
9 
10 namespace spr {
12  const DetId& det0,
13  std::vector<PCaloHit>& hits,
14  int ieta,
15  int iphi,
16  bool includeHO,
17  double hbThr,
18  double heThr,
19  double hfThr,
20  double hoThr,
21  double tMin,
22  double tMax,
23  bool
24 #ifdef EDM_ML_DEBUG
25  debug
26 #endif
27  ) {
28 
29  HcalDetId hcid0(det0.rawId());
30  HcalDetId hcid(hcid0.subdet(), hcid0.ieta(), hcid0.iphi(), 1);
31  DetId det(hcid.rawId());
32 #ifdef EDM_ML_DEBUG
33  if (debug)
34  std::cout << "Inside eHCALmatrix " << 2 * ieta + 1 << "X" << 2 * iphi + 1 << " Inclusion of HO Flag " << includeHO
35  << std::endl;
36 #endif
37  double energySum(0);
38  std::vector<DetId> dets(1, det);
39  std::vector<DetId> vdets = spr::matrixHCALIds(dets, topology, ieta, iphi, includeHO, false);
40 #ifdef EDM_ML_DEBUG
41  if (debug) {
42  std::cout << "matrixHCALIds::Total number of cells found is " << vdets.size() << std::endl;
43  spr::debugHcalDets(0, vdets);
44  }
45 #endif
46  int khit(0);
47  for (unsigned int i = 0; i < vdets.size(); i++) {
48  std::vector<std::vector<PCaloHit>::const_iterator> hit = spr::findHit(hits, vdets[i]);
49  double energy = 0;
50  int subdet = ((HcalDetId)(vdets[i].rawId())).subdet();
51  double eThr = spr::eHCALThreshold(subdet, hbThr, heThr, hfThr, hoThr);
52  for (unsigned int ihit = 0; ihit < hit.size(); ihit++) {
53  if (hit[ihit] != hits.end()) {
54  khit++;
55 #ifdef EDM_ML_DEBUG
56  if (debug)
57  std::cout << "energyHCAL:: Hit " << khit << " " << (HcalDetId)vdets[i] << " E " << hit[ihit]->energy()
58  << " t " << hit[ihit]->time() << std::endl;
59 #endif
60  if (hit[ihit]->time() > tMin && hit[ihit]->time() < tMax) {
61  energy += hit[ihit]->energy();
62  }
63  }
64  }
65  if (energy > eThr)
66  energySum += energy;
67  }
68 
69 #ifdef EDM_ML_DEBUG
70  if (debug)
71  std::cout << "eHCALmatrix::Total energy " << energySum << std::endl;
72 #endif
73  return energySum;
74  }
75 
76  double eHCALmatrix(const CaloGeometry* geo,
77  const HcalTopology* topology,
78  const DetId& det0,
79  std::vector<PCaloHit>& hits,
80  int ieta,
81  int iphi,
82  HcalDetId& hotCell,
83  bool includeHO,
84  bool debug) {
85  HcalDetId hcid0(det0.rawId());
86  HcalDetId hcid(hcid0.subdet(), hcid0.ieta(), hcid0.iphi(), 1);
87  DetId det(hcid.rawId());
88  std::vector<DetId> dets(1, det);
89  std::vector<DetId> vdets = spr::matrixHCALIds(dets, topology, ieta, iphi, includeHO, debug);
90  hotCell = hcid0;
91 
92  std::vector<std::vector<PCaloHit>::const_iterator> hitlist;
93  for (unsigned int i = 0; i < vdets.size(); i++) {
94  std::vector<std::vector<PCaloHit>::const_iterator> hit = spr::findHit(hits, vdets[i]);
95  hitlist.insert(hitlist.end(), hit.begin(), hit.end());
96  }
97 
98  double energySum(0);
99  for (unsigned int ihit = 0; ihit < hitlist.size(); ihit++)
100  energySum += hitlist[ihit]->energy();
101 
102  // Get hotCell ID
103  dets.clear();
104  std::vector<double> energies;
105  for (unsigned int ihit = 0; ihit < hitlist.size(); ihit++) {
106  double energy = hitlist[ihit]->energy();
107  HcalDetId id0 = HcalDetId(hitlist[ihit]->id());
108  if ((id0.subdet() != HcalOuter) || includeHO) {
109  HcalDetId id1(id0.subdet(), id0.ieta(), id0.iphi(), 1);
110  bool found(false);
111  for (unsigned int idet = 0; idet < dets.size(); ++idet) {
112  if (id1 == HcalDetId(dets[idet])) {
113  energies[idet] += energy;
114  found = true;
115  break;
116  }
117  }
118  if (!found) {
119  dets.push_back(DetId(id1));
120  energies.push_back(energy);
121  }
122  }
123  }
124  double energyMax(-99.);
125  for (unsigned int ihit = 0; ihit < dets.size(); ihit++) {
126  if (energies[ihit] > energyMax) {
127  energyMax = energies[ihit];
128  hotCell = HcalDetId(dets[ihit]);
129  }
130  }
131  return energySum;
132  }
133 
135  std::vector<PCaloHit>& hits,
136  std::vector<std::pair<double, int> >& energyCell,
137  int maxDepth,
138  double hbThr,
139  double heThr,
140  double hfThr,
141  double hoThr,
142  double tMin,
143  double tMax,
144  int depthHE,
145  bool
146 #ifdef EDM_ML_DEBUG
147  debug
148 #endif
149  ) {
150 
151  energyCell.clear();
152  int subdet = detId.subdet();
153  double eThr = spr::eHCALThreshold(subdet, hbThr, heThr, hfThr, hoThr);
154  bool hbhe = (detId.ietaAbs() == 16);
155 #ifdef EDM_ML_DEBUG
156  if (debug)
157  std::cout << "energyHCALCell: input ID " << detId << " MaxDepth " << maxDepth << " Threshold (E) " << eThr
158  << " (T) " << tMin << ":" << tMax << std::endl;
159 #endif
160  for (int i = 0; i < maxDepth; i++) {
161  HcalSubdetector subdet0 = (hbhe) ? ((i + 1 >= depthHE) ? HcalEndcap : HcalBarrel) : detId.subdet();
162  HcalDetId hcid(subdet0, detId.ieta(), detId.iphi(), i + 1);
163  DetId det(hcid.rawId());
164  std::vector<std::vector<PCaloHit>::const_iterator> hit = spr::findHit(hits, det);
165  double energy(0);
166  for (unsigned int ihit = 0; ihit < hit.size(); ++ihit) {
167  if (hit[ihit]->time() > tMin && hit[ihit]->time() < tMax)
168  energy += hit[ihit]->energy();
169 #ifdef EDM_ML_DEBUG
170  if (debug)
171  std::cout << "energyHCALCell:: Hit[" << ihit << "] " << hcid << " E " << hit[ihit]->energy() << " t "
172  << hit[ihit]->time() << std::endl;
173 #endif
174  }
175 #ifdef EDM_ML_DEBUG
176  if (debug)
177  std::cout << "energyHCALCell:: Cell " << hcid << " E " << energy << " from " << hit.size() << " threshold "
178  << eThr << std::endl;
179 #endif
180  if (energy > eThr && !hit.empty()) {
181  energyCell.push_back(std::pair<double, int>(energy, i + 1));
182  }
183  }
184 #ifdef EDM_ML_DEBUG
185  if (debug) {
186  std::cout << "energyHCALCell:: " << energyCell.size() << " entries from " << maxDepth << " depths:";
187  for (unsigned int i = 0; i < energyCell.size(); ++i) {
188  std::cout << " [" << i << "] (" << energyCell[i].first << ":" << energyCell[i].second << ")";
189  }
190  std::cout << std::endl;
191  }
192 #endif
193  }
194 
195  HcalDetId getHotCell(std::vector<HBHERecHitCollection::const_iterator>& hit, bool includeHO, int useRaw, bool) {
196  std::vector<HcalDetId> dets;
197  std::vector<double> energies;
198  for (unsigned int ihit = 0; ihit < hit.size(); ihit++) {
199  double energy = getRawEnergy(hit.at(ihit), useRaw);
200  HcalDetId id0 = hit.at(ihit)->id();
201  if ((id0.subdet() != HcalOuter) || includeHO) {
202  HcalDetId id1(id0.subdet(), id0.ieta(), id0.iphi(), 1);
203  bool found(false);
204  for (unsigned int idet = 0; idet < dets.size(); ++idet) {
205  if (id1 == dets[idet]) {
206  energies[idet] += energy;
207  found = true;
208  break;
209  }
210  }
211  if (!found) {
212  dets.push_back(id1);
213  energies.push_back(energy);
214  }
215  }
216  }
217  double energyMax(-99.);
218  HcalDetId hotCell;
219  for (unsigned int ihit = 0; ihit < dets.size(); ihit++) {
220  if (energies[ihit] > energyMax) {
221  energyMax = energies[ihit];
222  hotCell = dets[ihit];
223  }
224  }
225  return hotCell;
226  }
227 
228  HcalDetId getHotCell(std::vector<std::vector<PCaloHit>::const_iterator>& hit, bool includeHO, int useRaw, bool) {
229  std::vector<HcalDetId> dets;
230  std::vector<double> energies;
231  for (unsigned int ihit = 0; ihit < hit.size(); ihit++) {
232  double energy = hit.at(ihit)->energy();
233  HcalDetId id0 = getRawEnergy(hit.at(ihit), useRaw);
234  if ((id0.subdet() != HcalOuter) || includeHO) {
235  HcalDetId id1(id0.subdet(), id0.ieta(), id0.iphi(), 1);
236  bool found(false);
237  for (unsigned int idet = 0; idet < dets.size(); ++idet) {
238  if (id1 == dets[idet]) {
239  energies[idet] += energy;
240  found = true;
241  break;
242  }
243  }
244  if (!found) {
245  dets.push_back(id1);
246  energies.push_back(energy);
247  }
248  }
249  }
250  double energyMax(-99.);
251  HcalDetId hotCell;
252  for (unsigned int ihit = 0; ihit < dets.size(); ihit++) {
253  if (energies[ihit] > energyMax) {
254  energyMax = energies[ihit];
255  hotCell = dets[ihit];
256  }
257  }
258  return hotCell;
259  }
260 
261  double eHCALThreshold(int subdet, double hbThr, double heThr, double hfThr, double hoThr) {
262  double eThr = hbThr;
263  if (subdet == (int)(HcalEndcap))
264  eThr = heThr;
265  else if (subdet == (int)(HcalForward))
266  eThr = hfThr;
267  else if (subdet == (int)(HcalOuter))
268  eThr = hoThr;
269  return eThr;
270  }
271 } // namespace spr
mps_fire.i
i
Definition: mps_fire.py:428
spr
Definition: CaloConstants.h:6
hit::id
unsigned int id
Definition: SiStripHitEffFromCalibTree.cc:92
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
HcalDetId::iphi
constexpr int iphi() const
get the cell iphi
Definition: HcalDetId.h:157
globals_cff.id1
id1
Definition: globals_cff.py:33
gather_cfg.cout
cout
Definition: gather_cfg.py:144
HcalTopology
Definition: HcalTopology.h:26
DebugInfo.h
spr::getRawEnergy
double getRawEnergy(HBHERecHitCollection::const_iterator hit, int useRaw=0)
Definition: FindDistCone.cc:233
HcalBarrel
Definition: HcalAssistant.h:33
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
spr::getHotCell
HcalDetId getHotCell(std::vector< HBHERecHitCollection::const_iterator > &hit, bool includeHO, int useRaw=0, bool debug=false)
Definition: eHCALMatrix.cc:195
HLT_FULL_cff.maxDepth
maxDepth
Definition: HLT_FULL_cff.py:8732
CastorDataFrameFilter_impl::energySum
double energySum(const DataFrame &df, int fs, int ls)
Definition: CastorDataFrameFilter.cc:22
LEDCalibrationChannels.iphi
iphi
Definition: LEDCalibrationChannels.py:64
DetId
Definition: DetId.h:17
CaloGeometry
Definition: CaloGeometry.h:21
debug
#define debug
Definition: HDRShower.cc:19
spr::energyHCALCell
void energyHCALCell(HcalDetId detId, edm::Handle< T > &hits, std::vector< std::pair< double, int > > &energyCell, int maxDepth=1, double hbThr=-100, double heThr=-100, double hfThr=-100, double hoThr=-100, double tMin=-500, double tMax=500, int useRaw=0, int depthHE=3, bool debug=false)
spr::matrixHCALIds
std::vector< DetId > matrixHCALIds(std::vector< DetId > &dets, const HcalTopology *topology, int ieta, int iphi, bool includeHO=false, bool debug=false)
Definition: MatrixHCALDetIds.cc:15
ecaldqm::topology
const CaloTopology * topology(nullptr)
eHCALMatrix.h
HcalOuter
Definition: HcalAssistant.h:35
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
EDM_ML_DEBUG
#define EDM_ML_DEBUG
Definition: HcalHBHEMuonSimAnalyzer.cc:41
spr::eHCALThreshold
double eHCALThreshold(int subdet, double hbThr=-100, double heThr=-100, double hfThr=-100, double hoThr=-100)
Definition: eHCALMatrix.cc:261
LEDCalibrationChannels.ieta
ieta
Definition: LEDCalibrationChannels.py:63
HcalDetId::ieta
constexpr int ieta() const
get the cell ieta
Definition: HcalDetId.h:155
HcalDetId::subdet
constexpr HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:138
HcalDetId
Definition: HcalDetId.h:12
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
spr::findHit
std::vector< typename T::const_iterator > findHit(edm::Handle< T > &hits, DetId thisDet, bool debug=false)
HcalSubdetector.h
photonIsolationHIProducer_cfi.hbhe
hbhe
Definition: photonIsolationHIProducer_cfi.py:8
HcalSubdetector
HcalSubdetector
Definition: HcalAssistant.h:31
HcalForward
Definition: HcalAssistant.h:36
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
HcalEndcap
Definition: HcalAssistant.h:34
spr::debugHcalDets
void debugHcalDets(unsigned int, std::vector< DetId > &)
Definition: DebugInfo.cc:39
spr::eHCALmatrix
double eHCALmatrix(const HcalTopology *topology, const DetId &det, edm::Handle< T > &hits, int ieta, int iphi, bool includeHO=false, bool algoNew=true, double hbThr=-100, double heThr=-100, double hfThr=-100, double hoThr=-100, double tMin=-500, double tMax=500, int useRaw=0, bool debug=false)
HcalDetId::ietaAbs
constexpr int ietaAbs() const
get the absolute value of the cell ieta
Definition: HcalDetId.h:148
ntuplemaker.time
time
Definition: ntuplemaker.py:310
hit
Definition: SiStripHitEffFromCalibTree.cc:88