CMS 3D CMS Logo

EcalDetIdToBeRecoveredProducer.cc
Go to the documentation of this file.
1 
32 
33 #include <csignal>
34 #include <set>
35 #include <sys/types.h>
36 
38 public:
40  void produce(edm::Event& evt, const edm::EventSetup& es) final;
41  void beginRun(edm::Run const& run, const edm::EventSetup& es) final;
42  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
43 
44 private:
45  //edm::InputTag eeUncalibRecHitCollection_; // secondary name given to collection of EE uncalib rechits
46  //std::string eeRechitCollection_; // secondary name to be given to EE collection of hits
47 
54  /*
55  * InputTag for collections
56  */
57  // SRP collections
60 
61  // Integrity for xtal data
65 
66  // Integrity for xtal data - EE specific (to be rivisited towards EB+EE common collection)
70 
71  // Integrity Errors
74 
75  /*
76  * output collections
77  */
82 };
83 
85  ecalMappingToken_ = esConsumes<EcalElectronicsMapping, EcalMappingRcd, edm::Transition::BeginRun>();
86  channelStatusToken_ = esConsumes<EcalChannelStatusMap, EcalChannelStatusRcd, edm::Transition::BeginRun>();
87  ttMapToken_ = esConsumes<EcalTrigTowerConstituentsMap, IdealGeometryRecord, edm::Transition::BeginRun>();
88  // SRP collections
89  ebSrFlagToken_ = consumes<EBSrFlagCollection>(ps.getParameter<edm::InputTag>("ebSrFlagCollection"));
90  eeSrFlagToken_ = consumes<EESrFlagCollection>(ps.getParameter<edm::InputTag>("eeSrFlagCollection"));
91 
92  // Integrity for xtal data
93  ebIntegrityGainErrorsToken_ = consumes<EBDetIdCollection>(ps.getParameter<edm::InputTag>("ebIntegrityGainErrors"));
95  consumes<EBDetIdCollection>(ps.getParameter<edm::InputTag>("ebIntegrityGainSwitchErrors"));
96  ebIntegrityChIdErrorsToken_ = consumes<EBDetIdCollection>(ps.getParameter<edm::InputTag>("ebIntegrityChIdErrors"));
97 
98  // Integrity for xtal data - EE specific (to be rivisited towards EB+EE common collection)
99  eeIntegrityGainErrorsToken_ = consumes<EEDetIdCollection>(ps.getParameter<edm::InputTag>("eeIntegrityGainErrors"));
101  consumes<EEDetIdCollection>(ps.getParameter<edm::InputTag>("eeIntegrityGainSwitchErrors"));
102  eeIntegrityChIdErrorsToken_ = consumes<EEDetIdCollection>(ps.getParameter<edm::InputTag>("eeIntegrityChIdErrors"));
103 
104  // Integrity Errors
106  consumes<EcalElectronicsIdCollection>(ps.getParameter<edm::InputTag>("integrityTTIdErrors"));
108  consumes<EcalElectronicsIdCollection>(ps.getParameter<edm::InputTag>("integrityBlockSizeErrors"));
109 
110  // output collections
111  ebDetIdCollection_ = ps.getParameter<std::string>("ebDetIdToBeRecovered");
112  eeDetIdCollection_ = ps.getParameter<std::string>("eeDetIdToBeRecovered");
113  ttDetIdCollection_ = ps.getParameter<std::string>("ebFEToBeRecovered");
114  scDetIdCollection_ = ps.getParameter<std::string>("eeFEToBeRecovered");
115 
116  produces<std::set<EBDetId>>(ebDetIdCollection_);
117  produces<std::set<EEDetId>>(eeDetIdCollection_);
118  produces<std::set<EcalTrigTowerDetId>>(ttDetIdCollection_);
119  produces<std::set<EcalScDetId>>(scDetIdCollection_);
120 }
121 
124  ecalMapping_ = pEcalMapping.product();
125 
127  chStatus_ = pChStatus.product();
128 
130 }
131 
132 // fuction return true if "coll" have "item"
133 template <typename CollT, typename ItemT>
134 bool include(const CollT& coll, const ItemT& item) {
135  typename CollT::const_iterator res = std::find(coll.begin(), coll.end(), item);
136  return (res != coll.end());
137 }
138 
140  std::vector<edm::Handle<EBDetIdCollection>> ebDetIdColls;
141  std::vector<edm::Handle<EEDetIdCollection>> eeDetIdColls;
142  std::vector<edm::Handle<EcalElectronicsIdCollection>> ttColls;
143 
144  auto ebDetIdToRecover = std::make_unique<std::set<EBDetId>>(); // isolated channels to be recovered
145  auto eeDetIdToRecover = std::make_unique<std::set<EEDetId>>(); // isolated channels to be recovered
146  auto ebTTDetIdToRecover = std::make_unique<std::set<EcalTrigTowerDetId>>(); // tt to be recovered
147  auto eeSCDetIdToRecover = std::make_unique<std::set<EcalScDetId>>(); // sc to be recovered
148 
149  /*
150  * get collections
151  */
152 
153  // Selective Readout Flags
155  ev.getByToken(ebSrFlagToken_, ebSrFlags);
156 
158  ev.getByToken(eeSrFlagToken_, eeSrFlags);
159 
160  // Integrity errors
163 
164  ebDetIdColls.push_back(ebIntegrityGainErrors);
165 
168  ebDetIdColls.push_back(ebIntegrityGainSwitchErrors);
169 
172  ebDetIdColls.push_back(ebIntegrityChIdErrors);
173 
176  eeDetIdColls.push_back(eeIntegrityGainErrors);
177 
180  eeDetIdColls.push_back(eeIntegrityGainSwitchErrors);
181 
184  eeDetIdColls.push_back(eeIntegrityChIdErrors);
185 
188  ttColls.push_back(integrityTTIdErrors);
189 
192  ttColls.push_back(integrityBlockSizeErrors);
193 
194  /*
195  * get regions of interest from SRP
196  */
197  // -- Barrel
198  EBDetIdCollection ebSrpDetId;
199  EcalTrigTowerDetIdCollection ebSrpTTDetId;
200  for (EBSrFlagCollection::const_iterator it = ebSrFlags->begin(); it != ebSrFlags->end(); ++it) {
201  const int flag = it->value();
203  const EcalTrigTowerDetId ttId = it->id();
204  ebSrpTTDetId.push_back(ttId);
205 
206  const std::vector<DetId> vid = ttMap_->constituentsOf(ttId);
207 
208  for (std::vector<DetId>::const_iterator itId = vid.begin(); itId != vid.end(); ++itId) {
209  ebSrpDetId.push_back(*itId);
210  }
211  }
212  }
213  // -- Endcap
214  EEDetIdCollection eeSrpDetId;
215  //EcalTrigTowerDetIdCollection eeSrpTTDetId;
216  for (EESrFlagCollection::const_iterator it = eeSrFlags->begin(); it != eeSrFlags->end(); ++it) {
217  const int flag = it->value();
219  //EcalTrigTowerDetId ttId = it->id();
220  //eeSrpTTDetId.push_back( ttId );
221  const EcalScDetId scId(it->id());
222  // not clear how to get the vector of DetId constituents of a SC...
224  //std::vector<DetId> vid = ecalMapping_->dccTowerConstituents( eId.dccId(), eId.towerId() );
225  std::vector<DetId> vid;
226  for (int dx = 1; dx <= 5; ++dx) {
227  for (int dy = 1; dy <= 5; ++dy) {
228  const int ix = (scId.ix() - 1) * 5 + dx;
229  const int iy = (scId.iy() - 1) * 5 + dy;
230  const int iz = scId.zside();
231  if (EEDetId::validDetId(ix, iy, iz)) {
232  vid.push_back(EEDetId(ix, iy, iz));
233  }
234  }
235  }
237  //std::vector<DetId> vid = ttMap_->constituentsOf( ttId );
238  for (std::vector<DetId>::const_iterator itId = vid.begin(); itId != vid.end(); ++itId) {
239  eeSrpDetId.push_back(*itId);
240  }
241  }
242  }
243  // SRP switched off: get the list from the DB
244  if (ebSrFlags->empty()) {
245  }
246  // SRP switched off: get the list from the DB
247  if (eeSrFlags->empty()) {
248  }
249 
250  /*
251  * get OR of integrity error collections
252  * in interesting regions flagged by SRP
253  * and insert them in the list of DetId to recover
254  */
255  // -- Barrel
256  for (std::vector<edm::Handle<EBDetIdCollection>>::const_iterator it = ebDetIdColls.begin(); it != ebDetIdColls.end();
257  ++it) {
258  const EBDetIdCollection* idc = it->product();
259  for (EBDetIdCollection::const_iterator jt = idc->begin(); jt != idc->end(); ++jt)
260  if (include(ebSrpDetId, *jt))
261  ebDetIdToRecover->insert(*jt);
262  }
263  // -- Endcap
264  for (std::vector<edm::Handle<EEDetIdCollection>>::const_iterator it = eeDetIdColls.begin(); it != eeDetIdColls.end();
265  ++it) {
266  const EEDetIdCollection* idc = it->product();
267  for (EEDetIdCollection::const_iterator jt = idc->begin(); jt != idc->end(); ++jt)
268  if (include(eeSrpDetId, *jt))
269  eeDetIdToRecover->insert(*jt);
270  }
271 
272  /*
273  * find isolated dead channels (from DB info) --> chStatus 10, 11, 12
274  * and group of dead channels w/ trigger(from DB info) --> chStatus 13
275  * in interesting regions flagged by SRP
276  */
277  // -- Barrel
278  for (EBDetIdCollection::const_iterator itId = ebSrpDetId.begin(); itId != ebSrpDetId.end(); ++itId) {
280  if (chit != chStatus_->end()) {
281  const int flag = (*chit).getStatusCode();
282  if (flag >= 10 && flag <= 12) { // FIXME -- avoid hardcoded values...
283  ebDetIdToRecover->insert(*itId);
284  } else if (flag == 13 || flag == 14) { // FIXME -- avoid hardcoded values...
285  ebTTDetIdToRecover->insert((*itId).tower());
286  }
287  } else {
288  edm::LogError("EcalDetIdToBeRecoveredProducer") << "No channel status found for xtal " << (*itId).rawId()
289  << "! something wrong with EcalChannelStatus in your DB? ";
290  }
291  }
292  // -- Endcap
293  for (EEDetIdCollection::const_iterator itId = eeSrpDetId.begin(); itId != eeSrpDetId.end(); ++itId) {
295  if (chit != chStatus_->end()) {
296  int flag = (*chit).getStatusCode();
297  if (flag >= 10 && flag <= 12) { // FIXME -- avoid hardcoded values...
298  eeDetIdToRecover->insert(*itId);
299  } else if (flag == 13 || flag == 14) { // FIXME -- avoid hardcoded values...
300  eeSCDetIdToRecover->insert(
301  EcalScDetId(1 + ((*itId).ix() - 1) / 5, 1 + ((*itId).iy() - 1) / 5, (*itId).zside()));
302  }
303  } else {
304  edm::LogError("EcalDetIdToBeRecoveredProducer") << "No channel status found for xtal " << (*itId).rawId()
305  << "! something wrong with EcalChannelStatus in your DB? ";
306  }
307  }
308 
309  // loop over electronics id associated with TT and SC
310  for (size_t t = 0; t < ttColls.size(); ++t) {
311  const EcalElectronicsIdCollection& coll = *(ttColls[t]);
312 
313  for (size_t i = 0; i < coll.size(); ++i) {
314  const EcalElectronicsId elId = coll[i];
315  const EcalSubdetector subdet = elId.subdet();
316  const DetId detId = ecalMapping_->getDetId(elId);
317 
318  if (subdet == EcalBarrel) { // elId pointing to TT
319  // get list of crystals corresponding to TT
321  const std::vector<DetId>& vid = ttMap_->constituentsOf(ttId);
322 
323  for (size_t j = 0; j < vid.size(); ++j) {
324  const EBDetId ebdi(vid[j]);
325  if (include(ebSrpDetId, ebdi)) {
326  ebDetIdToRecover->insert(ebdi);
327  ebTTDetIdToRecover->insert(ebdi.tower());
328  }
329  }
330  } else if (subdet == EcalEndcap) { // elId pointing to SC
331  // extract list of crystals corresponding to SC
332  const EcalScDetId scId(detId);
333  std::vector<DetId> vid;
334  for (int dx = 1; dx <= 5; ++dx) {
335  for (int dy = 1; dy <= 5; ++dy) {
336  const int ix = (scId.ix() - 1) * 5 + dx;
337  const int iy = (scId.iy() - 1) * 5 + dy;
338  const int iz = scId.zside();
339  if (EEDetId::validDetId(ix, iy, iz))
340  vid.push_back(EEDetId(ix, iy, iz));
341  }
342  }
343 
344  for (size_t j = 0; j < vid.size(); ++j) {
345  const EEDetId eedi(vid[i]);
346  if (include(eeSrpDetId, eedi)) {
347  eeDetIdToRecover->insert(eedi);
348  eeSCDetIdToRecover->insert(EcalScDetId(eedi));
349  }
350  }
351  } else
352  edm::LogWarning("EcalDetIdToBeRecoveredProducer")
353  << "Incorrect EcalSubdetector = " << subdet << " in EcalElectronicsIdCollection collection ";
354  }
355  }
356 
357  // return the collections
358  ev.put(std::move(ebDetIdToRecover), ebDetIdCollection_);
359  ev.put(std::move(eeDetIdToRecover), eeDetIdCollection_);
360  ev.put(std::move(ebTTDetIdToRecover), ttDetIdCollection_);
361  ev.put(std::move(eeSCDetIdToRecover), scDetIdCollection_);
362 }
363 
366  desc.add<edm::InputTag>("ebIntegrityChIdErrors", edm::InputTag("ecalDigis", "EcalIntegrityChIdErrors"));
367  desc.add<std::string>("ebDetIdToBeRecovered", "ebDetId");
368  desc.add<edm::InputTag>("integrityTTIdErrors", edm::InputTag("ecalDigis", "EcalIntegrityTTIdErrors"));
369  desc.add<edm::InputTag>("eeIntegrityGainErrors", edm::InputTag("ecalDigis", "EcalIntegrityGainErrors"));
370  desc.add<std::string>("ebFEToBeRecovered", "ebFE");
371  desc.add<edm::InputTag>("ebIntegrityGainErrors", edm::InputTag("ecalDigis", "EcalIntegrityGainErrors"));
372  desc.add<std::string>("eeDetIdToBeRecovered", "eeDetId");
373  desc.add<edm::InputTag>("eeIntegrityGainSwitchErrors", edm::InputTag("ecalDigis", "EcalIntegrityGainSwitchErrors"));
374  desc.add<edm::InputTag>("eeIntegrityChIdErrors", edm::InputTag("ecalDigis", "EcalIntegrityChIdErrors"));
375  desc.add<edm::InputTag>("ebIntegrityGainSwitchErrors", edm::InputTag("ecalDigis", "EcalIntegrityGainSwitchErrors"));
376  desc.add<edm::InputTag>("ebSrFlagCollection", edm::InputTag("ecalDigis"));
377  desc.add<std::string>("eeFEToBeRecovered", "eeFE");
378  desc.add<edm::InputTag>("integrityBlockSizeErrors", edm::InputTag("ecalDigis", "EcalIntegrityBlockSizeErrors"));
379  desc.add<edm::InputTag>("eeSrFlagCollection", edm::InputTag("ecalDigis"));
380  descriptions.add("ecalDetIdToBeRecovered", desc);
381 }
382 
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
int zside() const
Definition: EcalScDetId.h:64
std::vector< DetId > constituentsOf(const EcalTrigTowerDetId &id) const
Get the constituent detids for this tower id.
Ecal readout channel identification [32:20] Unused (so far) [19:13] DCC id [12:6] tower [5:3] strip [...
static const int SRF_FORCED_MASK
Definition: EcalSrFlag.h:29
edm::EDGetTokenT< EcalElectronicsIdCollection > integrityBlockSizeErrorsToken_
std::vector< T >::const_iterator const_iterator
edm::ESGetToken< EcalTrigTowerConstituentsMap, IdealGeometryRecord > ttMapToken_
void push_back(T const &t)
Definition: EDCollection.h:61
edm::EDGetTokenT< EBDetIdCollection > ebIntegrityGainErrorsToken_
edm::EDGetTokenT< EcalElectronicsIdCollection > integrityTTIdErrorsToken_
Log< level::Error, false > LogError
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
unsigned ttId(DetId const &, EcalElectronicsMapping const *)
Definition: Electron.h:6
EcalTrigTowerDetId towerOf(const DetId &id) const
Get the tower id for this det id (or null if not known)
T const * product() const
Definition: ESHandle.h:86
edm::EDGetTokenT< EEDetIdCollection > eeIntegrityGainSwitchErrorsToken_
void produce(edm::Event &evt, const edm::EventSetup &es) final
static const int SRF_FULL
Definition: EcalSrFlag.h:24
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const_iterator begin() const
EcalDetIdToBeRecoveredProducer(const edm::ParameterSet &ps)
int iy() const
Definition: EcalScDetId.h:76
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
edm::EDGetTokenT< EBSrFlagCollection > ebSrFlagToken_
edm::EDGetTokenT< EBDetIdCollection > ebIntegrityGainSwitchErrorsToken_
const_iterator find(uint32_t rawId) const
edm::EDGetTokenT< EEDetIdCollection > eeIntegrityChIdErrorsToken_
EcalSubdetector subdet() const
get the subdet
const_iterator begin() const
Definition: EDCollection.h:118
const_iterator end() const
Definition: DetId.h:17
edm::ESHandle< EcalTrigTowerConstituentsMap > ttMap_
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
std::vector< Item >::const_iterator const_iterator
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::ESGetToken< EcalElectronicsMapping, EcalMappingRcd > ecalMappingToken_
size_type size() const
Definition: EDCollection.h:83
edm::EDGetTokenT< EEDetIdCollection > eeIntegrityGainErrorsToken_
bool include(const CollT &coll, const ItemT &item)
edm::EDGetTokenT< EESrFlagCollection > eeSrFlagToken_
void beginRun(edm::Run const &run, const edm::EventSetup &es) final
EcalTrigTowerDetId tower() const
get the HCAL/trigger iphi of this crystal
Definition: EBDetId.h:57
const_iterator end() const
edm::EDGetTokenT< EBDetIdCollection > ebIntegrityChIdErrorsToken_
Log< level::Warning, false > LogWarning
const EcalElectronicsMapping * ecalMapping_
const_iterator end() const
Definition: EDCollection.h:123
EcalSubdetector
def move(src, dest)
Definition: eostools.py:511
DetId getDetId(const EcalElectronicsId &id) const
Get the detid given an electronicsId.
Definition: Run.h:45
edm::ESGetToken< EcalChannelStatusMap, EcalChannelStatusRcd > channelStatusToken_
std::vector< T >::const_iterator const_iterator
Definition: EDCollection.h:19
int ix() const
Definition: EcalScDetId.h:70