CMS 3D CMS Logo

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