CMS 3D CMS Logo

EcalRecHitWorkerRecover.cc
Go to the documentation of this file.
1 
35 
36 #include <vector>
37 
39 public:
41 
42  void set(const edm::EventSetup& es) override;
43  bool run(const edm::Event& evt, const EcalUncalibratedRecHit& uncalibRH, EcalRecHitCollection& result) override;
44 
45 protected:
47  float recCheckCalib(float energy, int ieta);
48  bool alreadyInserted(const DetId& id);
49  float estimateEnergy(int ieta,
51  const std::set<DetId>& sId,
52  const std::vector<DetId>& vId,
53  const EcalTPGScale& tpgscale);
54  bool checkChannelStatus(const DetId& id, const std::vector<int>& statusestoexclude);
55 
58 
59  // isolated dead channels
66 
71 
78 
79  // list of channel statuses for which recovery in EE should
80  // not be attempted
81  std::vector<int> dbStatusToBeExcludedEE_;
82  std::vector<int> dbStatusToBeExcludedEB_;
83 
84  const edm::EventSetup* eventSetup_ = nullptr;
85  // dead FE
92 
94 
101  std::unique_ptr<EcalRecHitSimpleAlgo> rechitMaker_;
102 
103  std::set<DetId> recoveredDetIds_EB_;
104  std::set<DetId> recoveredDetIds_EE_;
105 
107 
110 };
111 
113  : EcalRecHitWorkerBaseClass(ps, c), ecalScaleTokens_(c), tpgscaleTokens_(c) {
114  rechitMaker_ = std::make_unique<EcalRecHitSimpleAlgo>();
115  // isolated channel recovery
116  singleRecoveryMethod_ = ps.getParameter<std::string>("singleChannelRecoveryMethod");
117  singleRecoveryThreshold_ = ps.getParameter<double>("singleChannelRecoveryThreshold");
118  sum8RecoveryThreshold_ = ps.getParameter<double>("sum8ChannelRecoveryThreshold");
119  killDeadChannels_ = ps.getParameter<bool>("killDeadChannels");
120  recoverEBIsolatedChannels_ = ps.getParameter<bool>("recoverEBIsolatedChannels");
121  recoverEEIsolatedChannels_ = ps.getParameter<bool>("recoverEEIsolatedChannels");
122  recoverEBVFE_ = ps.getParameter<bool>("recoverEBVFE");
123  recoverEEVFE_ = ps.getParameter<bool>("recoverEEVFE");
124  recoverEBFE_ = ps.getParameter<bool>("recoverEBFE");
125  recoverEEFE_ = ps.getParameter<bool>("recoverEEFE");
133 
134  dbStatusToBeExcludedEE_ = ps.getParameter<std::vector<int> >("dbStatusToBeExcludedEE");
135  dbStatusToBeExcludedEB_ = ps.getParameter<std::vector<int> >("dbStatusToBeExcludedEB");
136 
137  logWarningEtThreshold_EB_FE_ = ps.getParameter<double>("logWarningEtThreshold_EB_FE");
138  logWarningEtThreshold_EE_FE_ = ps.getParameter<double>("logWarningEtThreshold_EE_FE");
139 
140  tpDigiToken_ =
141  c.consumes<EcalTrigPrimDigiCollection>(ps.getParameter<edm::InputTag>("triggerPrimitiveDigiCollection"));
142 
145 }
146 
152  // geometry...
159  recoveredDetIds_EB_.clear();
160  recoveredDetIds_EE_.clear();
161  eventSetup_ = &es;
162 }
163 
165  const EcalUncalibratedRecHit& uncalibRH,
167  DetId detId = uncalibRH.id();
168  uint32_t flags = (0xF & uncalibRH.flags());
169 
170  // get laser coefficient
171  //float lasercalib = laser->getLaserCorrection( detId, evt.time());
172 
173  // killDeadChannels_ = true, means explicitely kill dead channels even if the recovered energies are computed in the code
174  // if you don't want to store the recovered energies in the rechit you can produce LogWarnings if logWarningEtThreshold_EB(EE)_FE>0
175  // logWarningEtThreshold_EB(EE)_FE_<0 will not compute the recovered energies at all (faster)
176 
177  if (killDeadChannels_) {
183  hit.setFlag(EcalRecHit::kDead);
184  insertRecHit(hit, result); // insert trivial rechit with kDead flag
185  return true;
186  }
188  EcalTrigTowerDetId ttDetId(((EBDetId)detId).tower());
189  std::vector<DetId> vid = ttMap_->constituentsOf(ttDetId);
190  for (std::vector<DetId>::const_iterator dit = vid.begin(); dit != vid.end(); ++dit) {
191  EcalRecHit hit((*dit), 0., 0., EcalRecHit::kDead);
192  hit.setFlag(EcalRecHit::kDead);
193  insertRecHit(hit, result); // insert trivial rechit with kDead flag
194  }
196  return true; // if you don't want log warning just return true
197  }
199  EEDetId id(detId);
200  EcalScDetId sc(1 + (id.ix() - 1) / 5, 1 + (id.iy() - 1) / 5, id.zside());
201  std::vector<DetId> eeC;
202  for (int dx = 1; dx <= 5; ++dx) {
203  for (int dy = 1; dy <= 5; ++dy) {
204  int ix = (sc.ix() - 1) * 5 + dx;
205  int iy = (sc.iy() - 1) * 5 + dy;
206  int iz = sc.zside();
207  if (EEDetId::validDetId(ix, iy, iz)) {
208  eeC.push_back(EEDetId(ix, iy, iz));
209  }
210  }
211  }
212  for (size_t i = 0; i < eeC.size(); ++i) {
213  EcalRecHit hit(eeC[i], 0., 0., EcalRecHit::kDead);
214  hit.setFlag(EcalRecHit::kDead);
215  insertRecHit(hit, result); // insert trivial rechit with kDead flag
216  }
218  return true; // if you don't want log warning just return true
219  }
220  }
221 
223  // recover as single dead channel
225 
226  // channel recovery. Accepted new RecHit has the flag AcceptRecHit=TRUE
227  bool AcceptRecHit = true;
228  float ebEn = ebDeadChannelCorrector.correct(
231 
232  if (hit.energy() != 0 and AcceptRecHit == true) {
234  } else {
235  // recovery failed
236  hit.setFlag(EcalRecHit::kDead);
237  }
239 
241  // recover as single dead channel
243 
244  // channel recovery. Accepted new RecHit has the flag AcceptRecHit=TRUE
245  bool AcceptRecHit = true;
246  float eeEn = eeDeadChannelCorrector.correct(
249  if (hit.energy() != 0 and AcceptRecHit == true) {
251  } else {
252  // recovery failed
253  hit.setFlag(EcalRecHit::kDead);
254  }
256 
257  } else if (flags == EcalRecHitWorkerRecover::EB_VFE) {
258  // recover as dead VFE
259  EcalRecHit hit(detId, 0., 0.);
260  hit.setFlag(EcalRecHit::kDead);
261  // recovery not implemented
263  } else if (flags == EcalRecHitWorkerRecover::EB_FE) {
264  // recover as dead TT
265 
266  EcalTrigTowerDetId ttDetId(((EBDetId)detId).tower());
268  evt.getByToken(tpDigiToken_, pTPDigis);
269  const EcalTrigPrimDigiCollection* tpDigis = nullptr;
270  tpDigis = pTPDigis.product();
271 
273  // recover the whole trigger tower
274  if (tp != tpDigis->end()) {
276  //std::vector<DetId> vid = ecalMapping_->dccTowerConstituents( ecalMapping_->DCCid( ttDetId ), ecalMapping_->iTT( ttDetId ) );
277  std::vector<DetId> vid = ttMap_->constituentsOf(ttDetId);
278  float tpEt = ecalScale.getTPGInGeV(tp->compressedEt(), tp->id());
279  float tpEtThreshEB = logWarningEtThreshold_EB_FE_;
280  if (tpEt > tpEtThreshEB) {
281  edm::LogWarning("EnergyInDeadEB_FE") << "TP energy in the dead TT = " << tpEt << " at " << ttDetId;
282  }
284  // democratic energy sharing
285 
286  for (std::vector<DetId>::const_iterator dit = vid.begin(); dit != vid.end(); ++dit) {
287  if (alreadyInserted(*dit))
288  continue;
289  float theta = ebGeom_->getGeometry(*dit)->getPosition().theta();
290  float tpEt = ecalScale.getTPGInGeV(tp->compressedEt(), tp->id());
292  EcalRecHit hit(*dit, tpEt / ((float)vid.size()) / sin(theta), 0.);
294  if (tp->compressedEt() == 0xFF)
295  hit.setFlag(EcalRecHit::kTPSaturated);
296  if (tp->sFGVB())
297  hit.setFlag(EcalRecHit::kL1SpikeFlag);
299  }
300  }
301  } else {
302  // tp not found => recovery failed
303  std::vector<DetId> vid = ttMap_->constituentsOf(ttDetId);
304  for (std::vector<DetId>::const_iterator dit = vid.begin(); dit != vid.end(); ++dit) {
305  if (alreadyInserted(*dit))
306  continue;
307  EcalRecHit hit(*dit, 0., 0.);
308  hit.setFlag(EcalRecHit::kDead);
310  }
311  }
312  }
313  } else if (flags == EcalRecHitWorkerRecover::EE_FE) {
314  // Structure for recovery:
315  // ** SC --> EEDetId constituents (eeC) --> associated Trigger Towers (aTT) --> EEDetId constituents (aTTC)
316  // ** energy for a SC EEDetId = [ sum_aTT(energy) - sum_aTTC(energy) ] / N_eeC
317  // .. i.e. the total energy of the TTs covering the SC minus
318  // .. the energy of the recHits in the TTs but not in the SC
319  //std::vector<DetId> vid = ecalMapping_->dccTowerConstituents( ecalMapping_->DCCid( ttDetId ), ecalMapping_->iTT( ttDetId ) );
320  // due to lack of implementation of the EcalTrigTowerDetId ix,iy methods in EE we compute Et recovered energies (in EB we compute E)
321 
322  EEDetId eeId(detId);
323  EcalScDetId sc((eeId.ix() - 1) / 5 + 1, (eeId.iy() - 1) / 5 + 1, eeId.zside());
324  std::set<DetId> eeC;
325  for (int dx = 1; dx <= 5; ++dx) {
326  for (int dy = 1; dy <= 5; ++dy) {
327  int ix = (sc.ix() - 1) * 5 + dx;
328  int iy = (sc.iy() - 1) * 5 + dy;
329  int iz = sc.zside();
330  if (EEDetId::validDetId(ix, iy, iz)) {
331  EEDetId id(ix, iy, iz);
333  eeC.insert(id);
334  } // check status
335  }
336  }
337  }
338 
340  evt.getByToken(tpDigiToken_, pTPDigis);
341  const EcalTrigPrimDigiCollection* tpDigis = nullptr;
342  tpDigis = pTPDigis.product();
343 
344  // associated trigger towers
345  std::set<EcalTrigTowerDetId> aTT;
346  for (std::set<DetId>::const_iterator it = eeC.begin(); it != eeC.end(); ++it) {
347  aTT.insert(ttMap_->towerOf(*it));
348  }
349 
352  // associated trigger towers: total energy
353  float totE = 0;
354  // associated trigger towers: EEDetId constituents
355  std::set<DetId> aTTC;
356  bool atLeastOneTPSaturated = false;
357  for (std::set<EcalTrigTowerDetId>::const_iterator it = aTT.begin(); it != aTT.end(); ++it) {
358  // add the energy of this trigger tower
360  if (itTP != tpDigis->end()) {
361  std::vector<DetId> v = ttMap_->constituentsOf(*it);
362 
363  // from the constituents, remove dead channels
364  std::vector<DetId>::iterator ttcons = v.begin();
365  while (ttcons != v.end()) {
367  ttcons = v.erase(ttcons);
368  } else {
369  ++ttcons;
370  }
371  } // while
372 
373  if (itTP->compressedEt() == 0xFF) { // In the case of a saturated trigger tower, a fraction
374  atLeastOneTPSaturated =
375  true; //of the saturated energy is put in: number of xtals in dead region/total xtals in TT *63.75
376 
377  //Alternative recovery algorithm that I will now investigate.
378  //Estimate energy sums the energy in the working channels, then decides how much energy
379  //to put here depending on that. Duncan 20101203
380 
381  totE += estimateEnergy(itTP->id().ietaAbs(), &result, eeC, v, tpgscale);
382 
383  /*
384  These commented out lines use
385  64GeV*fraction of the TT overlapping the dead FE
386 
387  int count = 0;
388  for (std::vector<DetId>::const_iterator idsit = v.begin(); idsit != v.end(); ++ idsit){
389  std::set<DetId>::const_iterator itFind = eeC.find(*idsit);
390  if (itFind != eeC.end())
391  ++count;
392  }
393  //std::cout << count << ", " << v.size() << std::endl;
394  totE+=((float)count/(float)v.size())* ((it->ietaAbs()>26)?2*ecalScale_.getTPGInGeV( itTP->compressedEt(), itTP->id() ):ecalScale_.getTPGInGeV( itTP->compressedEt(), itTP->id() ));*/
395  } else {
396  totE += ((it->ietaAbs() > 26) ? 2 : 1) * ecalScale.getTPGInGeV(itTP->compressedEt(), itTP->id());
397  }
398 
399  // get the trigger tower constituents
400 
401  if (itTP->compressedEt() == 0) { // If there's no energy in TT, the constituents are removed from the recovery.
402  for (size_t i = 0; i < v.size(); ++i)
403  eeC.erase(v[i]);
404  } else if (itTP->compressedEt() != 0xFF) {
405  //If it's saturated the energy has already been determined, so we do not want to subtract any channels
406  for (size_t j = 0; j < v.size(); ++j) {
407  aTTC.insert(v[j]);
408  }
409  }
410  }
411  }
412  // remove crystals of dead SC
413  // (this step is not needed if sure that SC crystals are not
414  // in the recHit collection)
415 
416  for (std::set<DetId>::const_iterator it = eeC.begin(); it != eeC.end(); ++it) {
417  aTTC.erase(*it);
418  }
419  // compute the total energy for the dead SC
420  const EcalRecHitCollection* hits = &result;
421  for (std::set<DetId>::const_iterator it = aTTC.begin(); it != aTTC.end(); ++it) {
423  if (jt != hits->end()) {
424  float energy = jt->energy(); // Correct conversion to Et
425  float eta = geo_->getPosition(jt->id()).eta();
426  float pf = 1.0 / cosh(eta);
427  // use Et instead of E, consistent with the Et estimation of the associated TT
428  totE -= energy * pf;
429  }
430  }
431 
432  float scEt = totE;
433  float scEtThreshEE = logWarningEtThreshold_EE_FE_;
434  if (scEt > scEtThreshEE) {
435  edm::LogWarning("EnergyInDeadEE_FE") << "TP energy in the dead TT = " << scEt << " at " << sc;
436  }
437 
438  // assign the energy to the SC crystals
439  if (!killDeadChannels_ || recoverEEFE_) { // if eeC is empty, i.e. there are no hits
440  // in the tower, nothing is returned. No negative values from noise.
441  for (std::set<DetId>::const_iterator it = eeC.begin(); it != eeC.end(); ++it) {
442  float eta = geo_->getPosition(*it).eta(); //Convert back to E from Et for the recovered hits
443  float pf = 1.0 / cosh(eta);
444  EcalRecHit hit(*it, totE / ((float)eeC.size() * pf), 0);
445 
446  if (atLeastOneTPSaturated)
447  hit.setFlag(EcalRecHit::kTPSaturated);
450 
451  } // for
452  } // if
453  }
454  return true;
455 }
456 
459  const std::set<DetId>& sId,
460  const std::vector<DetId>& vId,
461  const EcalTPGScale& tpgscale) {
462  float xtalE = 0;
463  int count = 0;
464  for (std::vector<DetId>::const_iterator vIdit = vId.begin(); vIdit != vId.end(); ++vIdit) {
465  std::set<DetId>::const_iterator sIdit = sId.find(*vIdit);
466  if (sIdit == sId.end()) {
467  float energy = hits->find(*vIdit)->energy();
468  float eta = geo_->getPosition(*vIdit).eta();
469  float pf = 1.0 / cosh(eta);
470  xtalE += energy * pf;
471  count++;
472  }
473  }
474 
475  if (count == 0) { // If there are no overlapping crystals return saturated value.
476 
477  double etsat = tpgscale.getTPGInGeV(0xFF,
478  ttMap_->towerOf(*vId.begin())); // get saturation value for the first
479  // constituent, for the others it's the same
480 
481  return etsat / cosh(ieta) * (ieta > 26 ? 2 : 1); // account for duplicated TT in EE for ieta>26
482  } else
483  return xtalE * ((vId.size() / (float)count) - 1) * (ieta > 26 ? 2 : 1);
484 }
485 
487  // skip already inserted DetId's and raise a log warning
488  if (alreadyInserted(hit.id())) {
489  edm::LogWarning("EcalRecHitWorkerRecover") << "DetId already recovered! Skipping...";
490  return;
491  }
493  if (it == collection.end()) {
494  // insert the hit in the collection
495  collection.push_back(hit);
496  } else {
497  // overwrite existing recHit
498  *it = hit;
499  }
500  if (hit.id().subdetId() == EcalBarrel) {
501  recoveredDetIds_EB_.insert(hit.id());
502  } else if (hit.id().subdetId() == EcalEndcap) {
503  recoveredDetIds_EE_.insert(hit.id());
504  } else {
505  edm::LogError("EcalRecHitWorkerRecover::InvalidDetId") << "Invalid DetId " << hit.id().rawId();
506  }
507 }
508 
510  bool res = false;
511  if (id.subdetId() == EcalBarrel) {
512  res = (recoveredDetIds_EB_.find(id) != recoveredDetIds_EB_.end());
513  } else if (id.subdetId() == EcalEndcap) {
514  res = (recoveredDetIds_EE_.find(id) != recoveredDetIds_EE_.end());
515  } else {
516  edm::LogError("EcalRecHitWorkerRecover::InvalidDetId") << "Invalid DetId " << id.rawId();
517  }
518  return res;
519 }
520 
521 // In the future, this will be used to calibrate the TT energy. There is a dependance on
522 // eta at lower energies that can be corrected for here after more validation.
523 float EcalRecHitWorkerRecover::recCheckCalib(float eTT, int ieta) { return eTT; }
524 
525 // return false is the channel has status in the list of statusestoexclude
526 // true otherwise (channel ok)
527 // Careful: this function works on raw (encoded) channel statuses
528 bool EcalRecHitWorkerRecover::checkChannelStatus(const DetId& id, const std::vector<int>& statusestoexclude) {
529  if (!chStatus_.isValid())
530  edm::LogError("ObjectNotFound") << "Channel Status not set";
531 
533  uint16_t dbStatus = 0;
534  if (chIt != chStatus_->end()) {
535  dbStatus = chIt->getEncodedStatusCode();
536  } else {
537  edm::LogError("ObjectNotFound") << "No channel status found for xtal " << id.rawId()
538  << "! something wrong with EcalChannelStatus in your DB? ";
539  }
540 
541  for (std::vector<int>::const_iterator status = statusestoexclude.begin(); status != statusestoexclude.end();
542  ++status) {
543  if (*status == dbStatus)
544  return false;
545  }
546 
547  return true;
548 }
549 
edm::ESGetToken< CaloSubdetectorGeometry, EcalBarrelGeometryRecord > pEBGeomToken_
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
const edm::EventSetup * eventSetup_
float estimateEnergy(int ieta, EcalRecHitCollection *hits, const std::set< DetId > &sId, const std::vector< DetId > &vId, const EcalTPGScale &tpgscale)
int zside() const
Definition: EcalScDetId.h:64
bool alreadyInserted(const DetId &id)
bool run(const edm::Event &evt, const EcalUncalibratedRecHit &uncalibRH, EcalRecHitCollection &result) override
std::vector< DetId > constituentsOf(const EcalTrigTowerDetId &id) const
Get the constituent detids for this tower id.
EcalDeadChannelRecoveryAlgos< EEDetId > eeDeadChannelCorrector
edm::ESGetToken< EcalElectronicsMapping, EcalMappingRcd > pEcalMappingToken_
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeometryToken_
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
T eta() const
Definition: PV3DBase.h:73
T const * product() const
Definition: Handle.h:70
int ix() const
Definition: EEDetId.h:77
std::vector< T >::const_iterator const_iterator
std::vector< int > dbStatusToBeExcludedEE_
edm::ESGetToken< EcalLaserDbService, EcalLaserDbRecord > laserToken_
edm::ESHandle< EcalElectronicsMapping > pEcalMapping_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:528
edm::ESGetToken< EcalChannelStatus, EcalChannelStatusRcd > chStatusToken_
int zside(DetId const &)
edm::ESHandle< CaloTopology > caloTopology_
EcalTPGScale::Tokens tpgscaleTokens_
Log< level::Error, false > LogError
float recCheckCalib(float energy, int ieta)
void setCaloTopology(const CaloTopology *topology)
Definition: Electron.h:6
EcalTrigTowerDetId towerOf(const DetId &id) const
Get the tower id for this det id (or null if not known)
void insertRecHit(const EcalRecHit &hit, EcalRecHitCollection &collection)
EcalTPGScale::Tokens ecalScaleTokens_
std::unique_ptr< EcalRecHitSimpleAlgo > rechitMaker_
T const * product() const
Definition: ESHandle.h:86
EcalChannelStatusMap EcalChannelStatus
GlobalPoint getPosition(const DetId &id) const
Get the position of a given detector id.
Definition: CaloGeometry.cc:50
edm::ESHandle< EcalTrigTowerConstituentsMap > ttMap_
void setParameters(const edm::ParameterSet &ps)
edm::ESHandle< CaloSubdetectorGeometry > pEBGeom_
int iy() const
Definition: EcalScDetId.h:76
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
virtual std::shared_ptr< const CaloCellGeometry > getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
const CaloSubdetectorGeometry * ebGeom_
std::vector< EcalRecHit >::iterator iterator
unsigned int id
const_iterator end() const
ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t ix(uint32_t id)
Definition: DetId.h:17
void set(const edm::EventSetup &es) override
edm::ESGetToken< EcalTrigTowerConstituentsMap, IdealGeometryRecord > ttMapToken_
int zside() const
Definition: EEDetId.h:71
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
edm::EDGetTokenT< EcalTrigPrimDigiCollection > tpDigiToken_
std::vector< Item >::const_iterator const_iterator
double getTPGInGeV(const EcalTriggerPrimitiveDigi &tpDigi) const
Definition: EcalTPGScale.cc:17
iterator find(key_type k)
EcalRecHitWorkerRecover(const edm::ParameterSet &, edm::ConsumesCollector &c)
edm::ESHandle< CaloGeometry > caloGeometry_
ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t iy(uint32_t id)
#define DEFINE_EDM_PLUGIN(factory, type, name)
std::vector< int > dbStatusToBeExcludedEB_
float correct(const DetIdT id, const EcalRecHitCollection &hit_collection, std::string algo, double single8Cut, double sum8Cut, bool *accFlag)
edm::ESGetToken< CaloTopology, CaloTopologyRecord > caloTopologyToken_
Log< level::Warning, false > LogWarning
EcalDeadChannelRecoveryAlgos< EBDetId > ebDeadChannelCorrector
Geom::Theta< T > theta() const
edm::ESHandle< EcalChannelStatus > chStatus_
edm::ESHandle< EcalLaserDbService > laser
const EcalElectronicsMapping * ecalMapping_
bool checkChannelStatus(const DetId &id, const std::vector< int > &statusestoexclude)
int iy() const
Definition: EEDetId.h:83
int ix() const
Definition: EcalScDetId.h:70