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