CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalRecHitWorkerRecover.cc
Go to the documentation of this file.
2 
14 
17 
20 
21 
24 {
26  // isolated channel recovery
27  singleRecoveryMethod_ = ps.getParameter<std::string>("singleChannelRecoveryMethod");
28  singleRecoveryThreshold_ = ps.getParameter<double>("singleChannelRecoveryThreshold");
29  killDeadChannels_ = ps.getParameter<bool>("killDeadChannels");
30  recoverEBIsolatedChannels_ = ps.getParameter<bool>("recoverEBIsolatedChannels");
31  recoverEEIsolatedChannels_ = ps.getParameter<bool>("recoverEEIsolatedChannels");
32  recoverEBVFE_ = ps.getParameter<bool>("recoverEBVFE");
33  recoverEEVFE_ = ps.getParameter<bool>("recoverEEVFE");
34  recoverEBFE_ = ps.getParameter<bool>("recoverEBFE");
35  recoverEEFE_ = ps.getParameter<bool>("recoverEEFE");
36 
37  dbStatusToBeExcludedEE_ = ps.getParameter<std::vector<int> >("dbStatusToBeExcludedEE");
38  dbStatusToBeExcludedEB_ = ps.getParameter<std::vector<int> >("dbStatusToBeExcludedEB");
39 
40  logWarningEtThreshold_EB_FE_ = ps.getParameter<double>("logWarningEtThreshold_EB_FE");
41  logWarningEtThreshold_EE_FE_ = ps.getParameter<double>("logWarningEtThreshold_EE_FE");
42 
43  tpDigiToken_ =
44  c.consumes<EcalTrigPrimDigiCollection>(ps.getParameter<edm::InputTag>("triggerPrimitiveDigiCollection"));
45 }
46 
47 
49 {
50 
51  es.get<EcalLaserDbRecord>().get(laser);
54  es.get<EcalMappingRcd>().get(pEcalMapping_);
56  // geometry...
57  es.get<EcalBarrelGeometryRecord>().get("EcalBarrel",pEBGeom_);
58  es.get<EcalEndcapGeometryRecord>().get("EcalEndcap",pEEGeom_);
64  es.get<IdealGeometryRecord>().get(ttMap_);
65  recoveredDetIds_EB_.clear();
66  recoveredDetIds_EE_.clear();
68 }
69 
70 
71 bool
73  const EcalUncalibratedRecHit& uncalibRH,
75 {
76  DetId detId=uncalibRH.id();
77  uint32_t flags = (0xF & uncalibRH.flags());
78 
79  // get laser coefficient
80  //float lasercalib = laser->getLaserCorrection( detId, evt.time());
81 
82  // killDeadChannels_ = true, means explicitely kill dead channels even if the recovered energies are computed in the code
83  // if you don't want to store the recovered energies in the rechit you can produce LogWarnings if logWarningEtThreshold_EB(EE)_FE>0
84  // logWarningEtThreshold_EB(EE)_FE_<0 will not compute the recovered energies at all (faster)
85 
86  if ( killDeadChannels_ ) {
91  ) {
92  EcalRecHit hit( detId, 0., 0., EcalRecHit::kDead );
94  insertRecHit( hit, result); // insert trivial rechit with kDead flag
95  return true;
96  }
97  if ( flags == EcalRecHitWorkerRecover::EB_FE && !recoverEBFE_) {
98  EcalTrigTowerDetId ttDetId( ((EBDetId)detId).tower() );
99  std::vector<DetId> vid = ttMap_->constituentsOf( ttDetId );
100  for ( std::vector<DetId>::const_iterator dit = vid.begin(); dit != vid.end(); ++dit ) {
101  EcalRecHit hit( (*dit), 0., 0., EcalRecHit::kDead );
102  hit.setFlag( EcalRecHit::kDead ) ;
103  insertRecHit( hit, result ); // insert trivial rechit with kDead flag
104  }
105  if(logWarningEtThreshold_EB_FE_<0)return true; // if you don't want log warning just return true
106  }
107  if ( flags == EcalRecHitWorkerRecover::EE_FE && !recoverEEFE_) {
108  EEDetId id( detId );
109  EcalScDetId sc( 1+(id.ix()-1)/5, 1+(id.iy()-1)/5, id.zside() );
110  std::vector<DetId> eeC;
111  for(int dx=1; dx<=5; ++dx){
112  for(int dy=1; dy<=5; ++dy){
113  int ix = (sc.ix()-1)*5 + dx;
114  int iy = (sc.iy()-1)*5 + dy;
115  int iz = sc.zside();
116  if(EEDetId::validDetId(ix, iy, iz)){
117  eeC.push_back(EEDetId(ix, iy, iz));
118  }
119  }
120  }
121  for ( size_t i = 0; i < eeC.size(); ++i ) {
122  EcalRecHit hit( eeC[i], 0., 0., EcalRecHit::kDead );
123  hit.setFlag( EcalRecHit::kDead ) ;
124  insertRecHit( hit, result ); // insert trivial rechit with kDead flag
125  }
126  if(logWarningEtThreshold_EE_FE_<0) return true; // if you don't want log warning just return true
127  }
128  }
129 
130  if ( flags == EcalRecHitWorkerRecover::EB_single ) {
131  // recover as single dead channel
133 
134  // channel recovery. Accepted new RecHit has the flag AcceptRecHit=TRUE
135  bool AcceptRecHit=true;
137 
138  if ( hit.energy() != 0 and AcceptRecHit == true ) {
140  } else {
141  // recovery failed
142  hit.setFlag( EcalRecHit::kDead ) ;
143  }
144  insertRecHit( hit, result );
145 
146  } else if ( flags == EcalRecHitWorkerRecover::EE_single ) {
147  // recover as single dead channel
149 
150  // channel recovery. Accepted new RecHit has the flag AcceptRecHit=TRUE
151  bool AcceptRecHit=true;
153  if ( hit.energy() != 0 and AcceptRecHit == true ) {
155  } else {
156  // recovery failed
157  hit.setFlag( EcalRecHit::kDead ) ;
158  }
159  insertRecHit( hit, result );
160 
161  } else if ( flags == EcalRecHitWorkerRecover::EB_VFE ) {
162  // recover as dead VFE
163  EcalRecHit hit( detId, 0., 0.);
164  hit.setFlag( EcalRecHit::kDead ) ;
165  // recovery not implemented
166  insertRecHit( hit, result );
167  } else if ( flags == EcalRecHitWorkerRecover::EB_FE ) {
168  // recover as dead TT
169 
170  EcalTrigTowerDetId ttDetId( ((EBDetId)detId).tower() );
172  evt.getByToken(tpDigiToken_, pTPDigis);
173  const EcalTrigPrimDigiCollection * tpDigis = 0;
174  tpDigis = pTPDigis.product();
175 
176  EcalTrigPrimDigiCollection::const_iterator tp = tpDigis->find( ttDetId );
177  // recover the whole trigger tower
178  if ( tp != tpDigis->end() ) {
179  //std::vector<DetId> vid = ecalMapping_->dccTowerConstituents( ecalMapping_->DCCid( ttDetId ), ecalMapping_->iTT( ttDetId ) );
180  std::vector<DetId> vid = ttMap_->constituentsOf( ttDetId );
181  float tpEt = ecalScale_.getTPGInGeV( tp->compressedEt(), tp->id() );
182  float tpEtThreshEB = logWarningEtThreshold_EB_FE_;
183  if(tpEt>tpEtThreshEB){
184  edm::LogWarning("EnergyInDeadEB_FE")<<"TP energy in the dead TT = "<<tpEt<<" at "<<ttDetId;
185  }
186  if ( !killDeadChannels_ || recoverEBFE_ ) {
187  // democratic energy sharing
188 
189  for ( std::vector<DetId>::const_iterator dit = vid.begin(); dit != vid.end(); ++dit ) {
190  if (alreadyInserted(*dit)) continue;
191  float theta = ebGeom_->getGeometry(*dit)->getPosition().theta();
192  float tpEt = ecalScale_.getTPGInGeV( tp->compressedEt(), tp->id() );
194  EcalRecHit hit( *dit, tpEt /((float)vid.size()) / sin(theta), 0.);
196  if ( tp->compressedEt() == 0xFF ) hit.setFlag( EcalRecHit::kTPSaturated );
197  if ( tp->sFGVB() ) hit.setFlag( EcalRecHit::kL1SpikeFlag );
198  insertRecHit( hit, result );
199  }
200  }
201  } else {
202  // tp not found => recovery failed
203  std::vector<DetId> vid = ttMap_->constituentsOf( ttDetId );
204  for ( std::vector<DetId>::const_iterator dit = vid.begin(); dit != vid.end(); ++dit ) {
205  if (alreadyInserted(*dit)) continue;
206  EcalRecHit hit( *dit,0., 0. );
207  hit.setFlag( EcalRecHit::kDead ) ;
208  insertRecHit( hit, result );
209  }
210  }
211  }
212  } else if ( flags == EcalRecHitWorkerRecover::EE_FE ) {
213  // Structure for recovery:
214  // ** SC --> EEDetId constituents (eeC) --> associated Trigger Towers (aTT) --> EEDetId constituents (aTTC)
215  // ** energy for a SC EEDetId = [ sum_aTT(energy) - sum_aTTC(energy) ] / N_eeC
216  // .. i.e. the total energy of the TTs covering the SC minus
217  // .. the energy of the recHits in the TTs but not in the SC
218  //std::vector<DetId> vid = ecalMapping_->dccTowerConstituents( ecalMapping_->DCCid( ttDetId ), ecalMapping_->iTT( ttDetId ) );
219  // due to lack of implementation of the EcalTrigTowerDetId ix,iy methods in EE we compute Et recovered energies (in EB we compute E)
220 
221  EEDetId eeId( detId );
222  EcalScDetId sc( (eeId.ix()-1)/5+1, (eeId.iy()-1)/5+1, eeId.zside() );
223  std::set<DetId> eeC;
224  for(int dx=1; dx<=5; ++dx){
225  for(int dy=1; dy<=5; ++dy){
226  int ix = (sc.ix()-1)*5 + dx;
227  int iy = (sc.iy()-1)*5 + dy;
228  int iz = sc.zside();
229  if(EEDetId::validDetId(ix, iy, iz)){
230  EEDetId id(ix, iy, iz);
232  eeC.insert(id);
233  } // check status
234  }
235  }
236  }
237 
239  evt.getByToken(tpDigiToken_, pTPDigis);
240  const EcalTrigPrimDigiCollection * tpDigis = 0;
241  tpDigis = pTPDigis.product();
242 
243  // associated trigger towers
244  std::set<EcalTrigTowerDetId> aTT;
245  for ( std::set<DetId>::const_iterator it = eeC.begin(); it!=eeC.end(); ++it ) {
246  aTT.insert( ttMap_->towerOf( *it ) );
247  }
248  // associated trigger towers: total energy
249  float totE = 0;
250  // associated trigger towers: EEDetId constituents
251  std::set<DetId> aTTC;
252  bool atLeastOneTPSaturated = false;
253  for ( std::set<EcalTrigTowerDetId>::const_iterator it = aTT.begin(); it != aTT.end(); ++it ) {
254  // add the energy of this trigger tower
255  EcalTrigPrimDigiCollection::const_iterator itTP = tpDigis->find( *it );
256  if ( itTP != tpDigis->end() ) {
257 
258  std::vector<DetId> v = ttMap_->constituentsOf( *it );
259 
260  // from the constituents, remove dead channels
261  std::vector<DetId>::iterator ttcons = v.begin();
262  while (ttcons != v.end()){
264  ttcons=v.erase(ttcons);
265  } else {
266  ++ttcons;
267  }
268  }// while
269 
270  if ( itTP->compressedEt() == 0xFF ){ // In the case of a saturated trigger tower, a fraction
271  atLeastOneTPSaturated = true; //of the saturated energy is put in: number of xtals in dead region/total xtals in TT *63.75
272 
273  //Alternative recovery algorithm that I will now investigate.
274  //Estimate energy sums the energy in the working channels, then decides how much energy
275  //to put here depending on that. Duncan 20101203
276 
277  totE += estimateEnergy(itTP->id().ietaAbs(), &result, eeC, v);
278 
279  /*
280  These commented out lines use
281  64GeV*fraction of the TT overlapping the dead FE
282 
283  int count = 0;
284  for (std::vector<DetId>::const_iterator idsit = v.begin(); idsit != v.end(); ++ idsit){
285  std::set<DetId>::const_iterator itFind = eeC.find(*idsit);
286  if (itFind != eeC.end())
287  ++count;
288  }
289  //std::cout << count << ", " << v.size() << std::endl;
290  totE+=((float)count/(float)v.size())* ((it->ietaAbs()>26)?2*ecalScale_.getTPGInGeV( itTP->compressedEt(), itTP->id() ):ecalScale_.getTPGInGeV( itTP->compressedEt(), itTP->id() ));*/
291  }
292  else {totE += ((it->ietaAbs()>26)?2:1)*ecalScale_.getTPGInGeV( itTP->compressedEt(), itTP->id() );}
293 
294 
295  // get the trigger tower constituents
296 
297  if (itTP->compressedEt() == 0){ // If there's no energy in TT, the constituents are removed from the recovery.
298  for (size_t i = 0 ; i < v.size(); ++i)
299  eeC.erase(v[i]);
300  }
301  else if (itTP->compressedEt()!=0xFF){ //If it's saturated the energy has already been determined, so we do not want to subtract any channels
302  for ( size_t j = 0; j < v.size(); ++j ) {
303  aTTC.insert( v[j] );
304  }
305  }
306 
307  }
308  }
309  // remove crystals of dead SC
310  // (this step is not needed if sure that SC crystals are not
311  // in the recHit collection)
312 
313  for ( std::set<DetId>::const_iterator it = eeC.begin(); it != eeC.end(); ++it ) {
314  aTTC.erase(*it);
315  }
316  // compute the total energy for the dead SC
317  const EcalRecHitCollection * hits = &result;
318  for ( std::set<DetId>::const_iterator it = aTTC.begin(); it != aTTC.end(); ++it ) {
319  EcalRecHitCollection::const_iterator jt = hits->find( *it );
320  if ( jt != hits->end() ) {
321  float energy = jt->energy(); // Correct conversion to Et
322  float eta = geo_->getPosition(jt->id()).eta();
323  float pf = 1.0/cosh(eta);
324  //float theta = eeGeom_->getGeometry( *it )->getPosition().theta();
325  // use Et instead of E, consistent with the Et estimation of the associated TT
326  totE -= energy*pf;
327  }
328  }
329 
330 
331  float scEt = totE;
332  float scEtThreshEE = logWarningEtThreshold_EE_FE_;
333  if(scEt>scEtThreshEE){
334  edm::LogWarning("EnergyInDeadEE_FE")<<"TP energy in the dead TT = "<<scEt<<" at "<<sc;
335  }
336 
337  // assign the energy to the SC crystals
338  if ( !killDeadChannels_ || recoverEEFE_ ) { // if eeC is empty, i.e. there are no hits
339  // in the tower, nothing is returned. No negative values from noise.
340  for ( std::set<DetId>::const_iterator it = eeC.begin(); it != eeC.end(); ++it ) {
341 
342  float eta = geo_->getPosition(*it).eta(); //Convert back to E from Et for the recovered hits
343  float pf = 1.0/cosh(eta);
344  EcalRecHit hit( *it, totE / ((float)eeC.size()*pf), 0);
345 
346  if (atLeastOneTPSaturated) hit.setFlag(EcalRecHit::kTPSaturated );
348  insertRecHit( hit, result );
349 
350  }// for
351  }// if
352  }
353  return true;
354 }
355 
356 float EcalRecHitWorkerRecover::estimateEnergy(int ieta, EcalRecHitCollection* hits, const std::set<DetId>& sId, const std::vector<DetId>& vId ) {
357 
358  float xtalE=0;
359  int count = 0;
360  for (std::vector<DetId>::const_iterator vIdit = vId.begin(); vIdit != vId.end(); ++ vIdit){
361  std::set<DetId>::const_iterator sIdit = sId.find(*vIdit);
362  if (sIdit==sId.end()){
363  float energy = hits->find(*vIdit)->energy();
364  float eta = geo_->getPosition(*vIdit).eta();
365  float pf = 1.0/cosh(eta);
366  xtalE += energy*pf;
367  count++;
368  }
369  }
370 
371  if (count==0) { // If there are no overlapping crystals return saturated value.
372 
373  double etsat = tpgscale_.getTPGInGeV(0xFF,
374  ttMap_->towerOf(*vId.begin())); // get saturation value for the first
375  // constituent, for the others it's the same
376 
377  return etsat/cosh(ieta)*(ieta>26?2:1); // account for duplicated TT in EE for ieta>26
378  }
379  else return xtalE*((vId.size()/(float)count) - 1)*(ieta>26?2:1);
380 
381 
382 }
383 
384 
386 {
387  // skip already inserted DetId's and raise a log warning
388  if ( alreadyInserted( hit.id() ) ) {
389  edm::LogWarning("EcalRecHitWorkerRecover") << "DetId already recovered! Skipping...";
390  return;
391  }
392  EcalRecHitCollection::iterator it = collection.find( hit.id() );
393  if ( it == collection.end() ) {
394  // insert the hit in the collection
395  collection.push_back( hit );
396  } else {
397  // overwrite existing recHit
398  *it = hit;
399  }
400  if ( hit.id().subdetId() == EcalBarrel ) {
401  recoveredDetIds_EB_.insert( hit.id() );
402  } else if ( hit.id().subdetId() == EcalEndcap ) {
403  recoveredDetIds_EE_.insert( hit.id() );
404  } else {
405  edm::LogError("EcalRecHitWorkerRecover::InvalidDetId") << "Invalid DetId " << hit.id().rawId();
406  }
407 }
408 
409 
411 {
412  bool res = false;
413  if ( id.subdetId() == EcalBarrel ) {
414  res = ( recoveredDetIds_EB_.find( id ) != recoveredDetIds_EB_.end() );
415  } else if ( id.subdetId() == EcalEndcap ) {
416  res = ( recoveredDetIds_EE_.find( id ) != recoveredDetIds_EE_.end() );
417  } else {
418  edm::LogError("EcalRecHitWorkerRecover::InvalidDetId") << "Invalid DetId " << id.rawId();
419  }
420  return res;
421 }
422 
423 // In the future, this will be used to calibrate the TT energy. There is a dependance on
424 // eta at lower energies that can be corrected for here after more validation.
425 float EcalRecHitWorkerRecover::recCheckCalib(float eTT, int ieta){
426 
427  return eTT;
428 
429 }
430 
431 // return false is the channel has status in the list of statusestoexclude
432 // true otherwise (channel ok)
433 // Careful: this function works on raw (encoded) channel statuses
435  const std::vector<int>& statusestoexclude){
436 
437 
438  if (!chStatus_.isValid())
439  edm::LogError("ObjectNotFound") << "Channel Status not set";
440 
441 
442  EcalChannelStatus::const_iterator chIt = chStatus_->find( id );
443  uint16_t dbStatus = 0;
444  if ( chIt != chStatus_->end() ) {
445  dbStatus = chIt->getEncodedStatusCode();
446  } else {
447  edm::LogError("ObjectNotFound") << "No channel status found for xtal "
448  << id.rawId()
449  << "! something wrong with EcalChannelStatus in your DB? ";
450  }
451 
452  for (std::vector<int>::const_iterator status = statusestoexclude.begin();
453  status!= statusestoexclude.end(); ++status){
454 
455  if ( *status == dbStatus) return false;
456 
457  }
458 
459  return true;
460 }
461 
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
int ix() const
Definition: EEDetId.h:76
bool alreadyInserted(const DetId &id)
void setEventSetup(const edm::EventSetup &evtSetup)
Definition: EcalTPGScale.cc:19
EcalDeadChannelRecoveryAlgos< EEDetId > eeDeadChannelCorrector
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
std::vector< EcalTriggerPrimitiveDigi >::const_iterator const_iterator
Geom::Theta< T > theta() const
std::vector< int > dbStatusToBeExcludedEE_
void push_back(T const &t)
std::vector< Variable::Flags > flags
Definition: MVATrainer.cc:135
void setFlag(int flag)
set the flags (from Flags or ESFlags)
Definition: EcalRecHit.h:168
int zside(DetId const &)
edm::ESHandle< CaloTopology > caloTopology_
double getTPGInGeV(const EcalTriggerPrimitiveDigi &tpDigi)
Definition: EcalTPGScale.cc:24
T eta() const
float recCheckCalib(float energy, int ieta)
void setCaloTopology(const CaloTopology *topology)
const CaloSubdetectorGeometry * eeGeom_
virtual const CaloCellGeometry * getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
Geom::Theta< T > theta() const
Definition: PV3DBase.h:75
void insertRecHit(const EcalRecHit &hit, EcalRecHitCollection &collection)
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
EcalRecHit correct(const DetIdT id, const EcalRecHitCollection &hit_collection, std::string algo, double Sum8Cut, bool *AccFlag)
int ix() const
Definition: EcalScDetId.h:71
edm::ESHandle< CaloSubdetectorGeometry > pEEGeom_
edm::ESHandle< EcalTrigTowerConstituentsMap > ttMap_
tuple result
Definition: query.py:137
int zside() const
Definition: EEDetId.h:70
int j
Definition: DBlmapReader.cc:9
float energy() const
Definition: EcalRecHit.h:68
const GlobalPoint & getPosition(const DetId &id) const
Get the position of a given detector id.
Definition: CaloGeometry.cc:68
int iy() const
Definition: EEDetId.h:82
edm::ESHandle< CaloSubdetectorGeometry > pEBGeom_
float estimateEnergy(int ieta, EcalRecHitCollection *hits, const std::set< DetId > &sId, const std::vector< DetId > &vId)
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
int iy() const
Definition: EcalScDetId.h:77
const CaloSubdetectorGeometry * ebGeom_
std::vector< EcalRecHit >::iterator iterator
const_iterator end() const
Definition: DetId.h:18
DetId id() const
get the id
Definition: EcalRecHit.h:76
T const * product() const
Definition: Handle.h:81
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
edm::EDGetTokenT< EcalTrigPrimDigiCollection > tpDigiToken_
const T & get() const
Definition: EventSetup.h:55
std::vector< Item >::const_iterator const_iterator
std::set< DetId > recoveredDetIds_EE_
T const * product() const
Definition: ESHandle.h:86
int zside() const
Definition: EcalScDetId.h:65
EcalRecHitSimpleAlgo * rechitMaker_
void set(const edm::EventSetup &es)
T eta() const
Definition: PV3DBase.h:76
iterator find(key_type k)
EcalRecHitWorkerRecover(const edm::ParameterSet &, edm::ConsumesCollector &c)
edm::ESHandle< CaloGeometry > caloGeometry_
#define DEFINE_EDM_PLUGIN(factory, type, name)
std::vector< int > dbStatusToBeExcludedEB_
tuple status
Definition: ntuplemaker.py:245
const GlobalPoint & getPosition() const
Returns the position of reference for this cell.
EcalDeadChannelRecoveryAlgos< EBDetId > ebDeadChannelCorrector
edm::ESHandle< EcalChannelStatus > chStatus_
edm::ESHandle< EcalLaserDbService > laser
const EcalElectronicsMapping * ecalMapping_
edm::ESHandle< EcalElectronicsMapping > pEcalMapping_
bool run(const edm::Event &evt, const EcalUncalibratedRecHit &uncalibRH, EcalRecHitCollection &result)
bool checkChannelStatus(const DetId &id, const std::vector< int > &statusestoexclude)
std::set< DetId > recoveredDetIds_EB_