CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
eECALMatrix.cc
Go to the documentation of this file.
10 
11 #include <sstream>
12 
13 namespace spr {
14 
15  std::pair<double, bool> energyECAL(const DetId& id,
17  const EcalSeverityLevelAlgo* sevlv,
18  bool testSpike,
19  double tMin,
20  double tMax,
21  bool debug) {
22  std::vector<EcalRecHitCollection::const_iterator> hits;
23  spr::findHit(hitsEC, id, hits, debug);
24 
25  std::ostringstream st1;
26  if (debug)
27  st1 << "Xtal 0x" << std::hex << id() << std::dec;
28  const EcalRecHitCollection* recHitsEC = (hitsEC.isValid()) ? hitsEC.product() : nullptr;
29  bool flag = (!testSpike) ? true : (sevlv->severityLevel(id, (*recHitsEC)) != EcalSeverityLevel::kWeird);
30  double ener(0);
31  for (const auto& hit : hits) {
32  double en(0), tt(0);
33  if (hit != hitsEC->end()) {
34  en = hit->energy();
35  tt = hit->time();
36  }
37  if (debug)
38  st1 << " " << tt << " " << en;
39  if (tt > tMin && tt < tMax)
40  ener += en;
41  }
42  if (debug) {
43  if (!flag)
44  st1 << " detected to be a spike";
45  edm::LogVerbatim("IsoTrack") << st1.str();
46  }
47  return std::pair<double, bool>(ener, flag);
48  }
49 
50  std::pair<double, bool> energyECAL(const std::vector<DetId>& vdets,
52  const EcalSeverityLevelAlgo* sevlv,
53  bool noThrCut,
54  bool testSpike,
55  double eThr,
56  double tMin,
57  double tMax,
58  bool debug) {
59  bool flag(true);
60  double energySum(0.0);
61  for (const auto& id : vdets) {
62  if (id != DetId(0)) {
63  std::pair<double, bool> ecalEn = spr::energyECAL(id, hitsEC, sevlv, testSpike, tMin, tMax, debug);
64  if (!ecalEn.second)
65  flag = false;
66  if ((ecalEn.first > eThr) || noThrCut)
67  energySum += ecalEn.first;
68  }
69  }
70  if (debug)
71  edm::LogVerbatim("IsoTrack") << "energyECAL: energySum = " << energySum << " flag = " << flag;
72  return std::pair<double, bool>(energySum, flag);
73  }
74 
75  std::pair<double, bool> eECALmatrix(const DetId& detId,
78  const EcalChannelStatus& chStatus,
79  const CaloGeometry* geo,
80  const CaloTopology* caloTopology,
81  const EcalSeverityLevelAlgo* sevlv,
82  int ieta,
83  int iphi,
84  double ebThr,
85  double eeThr,
86  double tMin,
87  double tMax,
88  bool debug) {
89  std::vector<DetId> vdets;
90  spr::matrixECALIds(detId, ieta, iphi, geo, caloTopology, vdets, debug);
91  if (debug)
92  edm::LogVerbatim("IsoTrack") << "Inside eECALmatrix " << 2 * ieta + 1 << "X" << 2 * iphi + 1 << " nXtals "
93  << vdets.size();
94  bool flag(true);
95  for (const auto& id : vdets) {
96  if ((id.det() == DetId::Ecal) && (id.subdetId() == EcalBarrel)) {
97  if (sevlv->severityLevel(id, (*hitsEB)) == EcalSeverityLevel::kWeird)
98  flag = false;
99  } else if ((id.det() == DetId::Ecal) && (id.subdetId() == EcalEndcap)) {
100  if (sevlv->severityLevel(id, (*hitsEE)) == EcalSeverityLevel::kWeird)
101  flag = false;
102  }
103  }
104  return std::pair<double, bool>(spr::energyECAL(vdets, hitsEB, hitsEE, ebThr, eeThr, tMin, tMax, debug), flag);
105  }
106 
107  std::pair<double, bool> eECALmatrix(const DetId& detId,
110  const EcalChannelStatus& chStatus,
111  const CaloGeometry* geo,
112  const CaloTopology* caloTopology,
113  const EcalSeverityLevelAlgo* sevlv,
114  const EcalTrigTowerConstituentsMap& ttMap,
115  int ieta,
116  int iphi,
117  double ebThr,
118  double eeThr,
119  double tMin,
120  double tMax,
121  bool debug) {
122  std::vector<DetId> vdets;
123  spr::matrixECALIds(detId, ieta, iphi, geo, caloTopology, vdets, debug);
124  if (debug)
125  edm::LogVerbatim("IsoTrack") << "Inside eECALmatrix " << 2 * ieta + 1 << "X" << 2 * iphi + 1 << " nXtals "
126  << vdets.size();
127 
128  bool flag(true);
129  double energySum = 0.0;
130  for (const auto& id : vdets) {
131  if ((id != DetId(0)) && (id.det() == DetId::Ecal) &&
132  ((id.subdetId() == EcalBarrel) || (id.subdetId() == EcalEndcap))) {
133  double eTower = spr::energyECALTower(id, hitsEB, hitsEE, ttMap, debug);
134  bool ok = (id.subdetId() == EcalBarrel) ? (eTower > ebThr) : (eTower > eeThr);
135  if (debug && (!ok))
136  edm::LogVerbatim("IsoTrack") << "Crystal 0x" << std::hex << id() << std::dec << " Flag " << ok;
137  if (ok) {
138  std::pair<double, bool> ecalEn = (id.subdetId() == EcalBarrel)
139  ? spr::energyECAL(id, hitsEB, sevlv, true, tMin, tMax, debug)
140  : spr::energyECAL(id, hitsEE, sevlv, false, tMin, tMax, debug);
141  if (!ecalEn.second)
142  flag = false;
143  energySum += ecalEn.first;
144  }
145  }
146  }
147  if (debug)
148  edm::LogVerbatim("IsoTrack") << "energyECAL: energySum = " << energySum << " flag = " << flag;
149  return std::pair<double, bool>(energySum, flag);
150  }
151 
152  std::pair<double, bool> eECALmatrix(const HcalDetId& detId,
155  const CaloGeometry* geo,
156  const CaloTowerConstituentsMap* ctmap,
157  const EcalSeverityLevelAlgo* sevlv,
158  double ebThr,
159  double eeThr,
160  double tMin,
161  double tMax,
162  bool debug) {
163  CaloTowerDetId tower = ctmap->towerOf(detId);
164  std::vector<DetId> ids = ctmap->constituentsOf(tower);
165  if (debug) {
166  edm::LogVerbatim("IsoTrack") << "eECALmatrix: " << detId << " belongs to " << tower << " which has " << ids.size()
167  << " constituents";
168  for (unsigned int i = 0; i < ids.size(); ++i) {
169  std::ostringstream st1;
170  st1 << "[" << i << "] " << std::hex << ids[i].rawId() << std::dec;
171  if (ids[i].det() == DetId::Ecal && ids[i].subdetId() == EcalBarrel) {
172  st1 << " " << EBDetId(ids[i]);
173  } else if (ids[i].det() == DetId::Ecal && ids[i].subdetId() == EcalEndcap) {
174  st1 << " " << EEDetId(ids[i]);
175  } else if (ids[i].det() == DetId::Ecal && ids[i].subdetId() == EcalPreshower) {
176  st1 << " " << ESDetId(ids[i]);
177  } else if (ids[i].det() == DetId::Hcal) {
178  st1 << " " << HcalDetId(ids[i]);
179  }
180  edm::LogVerbatim("IsoTrack") << st1.str();
181  }
182  }
183 
184  std::vector<DetId> idEBEE;
185  bool flag(true);
186  for (const auto& id : ids) {
187  if ((id.det() == DetId::Ecal) && (id.subdetId() == EcalBarrel)) {
188  idEBEE.emplace_back(id);
189  if (sevlv->severityLevel(id, (*hitsEB)) == EcalSeverityLevel::kWeird)
190  flag = false;
191  } else if ((id.det() == DetId::Ecal) && (id.subdetId() == EcalEndcap)) {
192  idEBEE.emplace_back(id);
193  if (sevlv->severityLevel(id, (*hitsEE)) == EcalSeverityLevel::kWeird)
194  flag = false;
195  }
196  }
197 
198  if (debug)
199  edm::LogVerbatim("IsoTrack") << "eECALmatrix: with " << idEBEE.size() << " EB+EE hits and "
200  << "spike flag " << flag;
201  double etot = (!idEBEE.empty()) ? spr::energyECAL(idEBEE, hitsEB, hitsEE, ebThr, eeThr, tMin, tMax, debug) : 0;
202  return std::pair<double, bool>(etot, flag);
203  }
204 } // namespace spr
Log< level::Info, true > LogVerbatim
double energyECAL(std::vector< DetId > &vdets, edm::Handle< T > &hitsEB, edm::Handle< T > &hitsEE, double ebThr=-100, double eeThr=-100, double tMin=-500, double tMax=500, bool debug=false)
uint16_t *__restrict__ id
EcalSeverityLevel::SeverityLevel severityLevel(const DetId &id) const
Evaluate status from id use channelStatus from DB.
std::vector< typename T::const_iterator > findHit(edm::Handle< T > &hits, DetId thisDet, bool debug=false)
void matrixECALIds(const DetId &det, int ieta, int iphi, const CaloGeometry *geo, const CaloTopology *caloTopology, std::vector< DetId > &vdets, bool debug=false, bool igNoreTransition=true)
std::vector< DetId > constituentsOf(const CaloTowerDetId &id) const
Get the constituent detids for this tower id ( not yet implemented )
CaloTowerDetId towerOf(const DetId &id) const
Get the tower id for this det id (or null if not known)
bool isValid() const
Definition: HandleBase.h:70
Definition: DetId.h:17
#define debug
Definition: HDRShower.cc:19
T const * product() const
Definition: Handle.h:70
double energySum(const DataFrame &df, int fs, int ls)
double energyECALTower(const DetId &detId, edm::Handle< T > &hitsEB, edm::Handle< T > &hitsEE, const EcalTrigTowerConstituentsMap &ttMap, bool debug=false)
double eECALmatrix(const DetId &detId, edm::Handle< T > &hitsEB, edm::Handle< T > &hitsEE, const CaloGeometry *geo, const CaloTopology *caloTopology, int ieta, int iphi, double ebThr=-100, double eeThr=-100, double tMin=-500, double tMax=500, bool debug=false)