CMS 3D CMS Logo

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