CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalDetIdToBeRecoveredProducer.cc
Go to the documentation of this file.
2 
5 
8 
10 
13 
17 
18 #include <set>
19 
20 #include <sys/types.h>
21 #include <signal.h>
22 
24 {
25  // SRP collections
26  ebSrFlagCollection_ = ps.getParameter<edm::InputTag>("ebSrFlagCollection");
27  eeSrFlagCollection_ = ps.getParameter<edm::InputTag>("eeSrFlagCollection");
28 
29  // Integrity for xtal data
30  ebIntegrityGainErrorsCollection_ = ps.getParameter<edm::InputTag>("ebIntegrityGainErrors");
31  ebIntegrityGainSwitchErrorsCollection_ = ps.getParameter<edm::InputTag>("ebIntegrityGainSwitchErrors");
32  ebIntegrityChIdErrorsCollection_ = ps.getParameter<edm::InputTag>("ebIntegrityChIdErrors");
33 
34  // Integrity for xtal data - EE specific (to be rivisited towards EB+EE common collection)
35  eeIntegrityGainErrorsCollection_ = ps.getParameter<edm::InputTag>("eeIntegrityGainErrors");
36  eeIntegrityGainSwitchErrorsCollection_ = ps.getParameter<edm::InputTag>("eeIntegrityGainSwitchErrors");
37  eeIntegrityChIdErrorsCollection_ = ps.getParameter<edm::InputTag>("eeIntegrityChIdErrors");
38 
39  // Integrity Errors
40  integrityTTIdErrorsCollection_ = ps.getParameter<edm::InputTag>("integrityTTIdErrors");
41  integrityBlockSizeErrorsCollection_ = ps.getParameter<edm::InputTag>("integrityBlockSizeErrors");
42 
43  // output collections
44  ebDetIdCollection_ = ps.getParameter<std::string>("ebDetIdToBeRecovered");
45  eeDetIdCollection_ = ps.getParameter<std::string>("eeDetIdToBeRecovered");
46  ttDetIdCollection_ = ps.getParameter<std::string>("ebFEToBeRecovered");
47  scDetIdCollection_ = ps.getParameter<std::string>("eeFEToBeRecovered");
48 
49  produces< std::set<EBDetId> >( ebDetIdCollection_ );
50  produces< std::set<EEDetId> >( eeDetIdCollection_ );
51  produces< std::set<EcalTrigTowerDetId> >( ttDetIdCollection_ );
52  produces< std::set<EcalScDetId> >( scDetIdCollection_ );
53 }
54 
55 
57 {
58 }
59 
60 
62 {
64  es.get<EcalMappingRcd>().get(pEcalMapping);
65  ecalMapping_ = pEcalMapping.product();
66 
68  es.get<EcalChannelStatusRcd>().get(pChStatus);
69  chStatus_ = pChStatus.product();
70 
71  es.get<IdealGeometryRecord>().get(ttMap_);
72 }
73 
74 // fuction return true if "coll" have "item"
75 template <typename CollT, typename ItemT>
76 bool include(const CollT& coll, const ItemT& item)
77 {
78  typename CollT::const_iterator res = std::find( coll.begin(), coll.end(), item );
79  return ( res != coll.end() );
80 }
81 
83 {
84  std::vector< edm::Handle<EBDetIdCollection> > ebDetIdColls;
85  std::vector< edm::Handle<EEDetIdCollection> > eeDetIdColls;
86  std::vector< edm::Handle<EcalElectronicsIdCollection> > ttColls;
87 
88  std::auto_ptr< std::set<EBDetId> > ebDetIdToRecover( new std::set<EBDetId> ); // isolated channels to be recovered
89  std::auto_ptr< std::set<EEDetId> > eeDetIdToRecover( new std::set<EEDetId> ); // isolated channels to be recovered
90  std::auto_ptr< std::set<EcalTrigTowerDetId> > ebTTDetIdToRecover( new std::set<EcalTrigTowerDetId> ); // tt to be recovered
91  std::auto_ptr< std::set<EcalScDetId> > eeSCDetIdToRecover( new std::set<EcalScDetId> ); // sc to be recovered
92 
93  /*
94  * get collections
95  */
96 
97  // Selective Readout Flags
99  ev.getByLabel(ebSrFlagCollection_, ebSrFlags );
100  if ( ! ebSrFlags.isValid() ) {
101  edm::LogWarning("EcalDetIdToBeRecoveredProducer: -->") << ebSrFlagCollection_ << " not available";
102  }
104  ev.getByLabel(eeSrFlagCollection_, eeSrFlags );
105  if ( ! eeSrFlags.isValid() ) {
106  edm::LogWarning("EcalDetIdToBeRecoveredProducer: -->") << eeSrFlagCollection_ << " not available";
107  }
108 
109  // Integrity errors
110  edm::Handle<EBDetIdCollection> ebIntegrityGainErrors;
111  ev.getByLabel( ebIntegrityGainErrorsCollection_, ebIntegrityGainErrors );
112  if ( ebIntegrityGainErrors.isValid() ) {
113  ebDetIdColls.push_back( ebIntegrityGainErrors );
114  } else {
115  edm::LogWarning("EcalDetIdToBeRecoveredProducer") << ebIntegrityGainErrorsCollection_ << " not available";
116  }
117  edm::Handle<EBDetIdCollection> ebIntegrityGainSwitchErrors;
118  ev.getByLabel( ebIntegrityGainSwitchErrorsCollection_, ebIntegrityGainSwitchErrors );
119  if ( ebIntegrityGainSwitchErrors.isValid() ) {
120  ebDetIdColls.push_back( ebIntegrityGainSwitchErrors );
121  } else {
122  edm::LogWarning("EcalDetIdToBeRecoveredProducer") << ebIntegrityGainErrorsCollection_ << " not available";
123  }
124  edm::Handle<EBDetIdCollection> ebIntegrityChIdErrors;
125  ev.getByLabel( ebIntegrityChIdErrorsCollection_, ebIntegrityChIdErrors );
126  if ( ebIntegrityChIdErrors.isValid() ) {
127  ebDetIdColls.push_back( ebIntegrityChIdErrors );
128  } else {
129  edm::LogWarning("EcalDetIdToBeRecoveredProducer") << ebIntegrityChIdErrorsCollection_ << " not available";
130  }
131 
132  edm::Handle<EEDetIdCollection> eeIntegrityGainErrors;
133  ev.getByLabel( eeIntegrityGainErrorsCollection_, eeIntegrityGainErrors );
134  if ( eeIntegrityGainErrors.isValid() ) {
135  eeDetIdColls.push_back( eeIntegrityGainErrors );
136  } else {
137  edm::LogWarning("EcalDetIdToBeRecoveredProducer") << eeIntegrityGainErrorsCollection_ << " not available";
138  }
139  edm::Handle<EEDetIdCollection> eeIntegrityGainSwitchErrors;
140  ev.getByLabel( eeIntegrityGainSwitchErrorsCollection_, eeIntegrityGainSwitchErrors );
141  if ( eeIntegrityGainSwitchErrors.isValid() ) {
142  eeDetIdColls.push_back( eeIntegrityGainSwitchErrors );
143  } else {
144  edm::LogWarning("EcalDetIdToBeRecoveredProducer") << eeIntegrityGainErrorsCollection_ << " not available";
145  }
146  edm::Handle<EEDetIdCollection> eeIntegrityChIdErrors;
147  ev.getByLabel( eeIntegrityChIdErrorsCollection_, eeIntegrityChIdErrors );
148  if ( eeIntegrityChIdErrors.isValid() ) {
149  eeDetIdColls.push_back( eeIntegrityChIdErrors );
150  } else {
151  edm::LogWarning("EcalDetIdToBeRecoveredProducer") << eeIntegrityChIdErrorsCollection_ << " not available";
152  }
153 
154  edm::Handle<EcalElectronicsIdCollection> integrityTTIdErrors;
155  ev.getByLabel( integrityTTIdErrorsCollection_, integrityTTIdErrors );
156  if ( integrityTTIdErrors.isValid() ) {
157  ttColls.push_back( integrityTTIdErrors );
158  } else {
159  edm::LogWarning("EcalDetIdToBeRecoveredProducer") << integrityTTIdErrorsCollection_ << " not available";
160  }
161  edm::Handle<EcalElectronicsIdCollection> integrityBlockSizeErrors;
162  ev.getByLabel( integrityBlockSizeErrorsCollection_, integrityBlockSizeErrors );
163  if ( integrityBlockSizeErrors.isValid() ) {
164  ttColls.push_back( integrityBlockSizeErrors );
165  } else {
166  edm::LogWarning("EcalDetIdToBeRecoveredProducer") << integrityBlockSizeErrorsCollection_ << " not available";
167  }
168 
169  /*
170  * get regions of interest from SRP
171  */
172  // -- Barrel
173  EBDetIdCollection ebSrpDetId;
174  EcalTrigTowerDetIdCollection ebSrpTTDetId;
175  for ( EBSrFlagCollection::const_iterator it = ebSrFlags->begin(); it != ebSrFlags->end(); ++it ) {
176  const int flag = it->value();
177  if ( flag == EcalSrFlag::SRF_FULL || ( flag == EcalSrFlag::SRF_FORCED_MASK) ) {
178  const EcalTrigTowerDetId ttId = it->id();
179  ebSrpTTDetId.push_back( ttId );
180  //std::vector<DetId> vid = ecalMapping_->dccTowerConstituents( ttId.iDCC(), ttId.iTT() );
181  const std::vector<DetId> vid = ttMap_->constituentsOf( ttId );
182  //ebSrpDetId.insert( ebSrpDetId.end(), vid.begin(), vid.end() );
183  for ( std::vector<DetId>::const_iterator itId = vid.begin(); itId != vid.end(); ++itId ) {
184  ebSrpDetId.push_back( *itId );
185  }
186  }
187  }
188  // -- Endcap
189  EEDetIdCollection eeSrpDetId;
190  //EcalTrigTowerDetIdCollection eeSrpTTDetId;
191  for ( EESrFlagCollection::const_iterator it = eeSrFlags->begin(); it != eeSrFlags->end(); ++it ) {
192  const int flag = it->value();
193  if ( flag == EcalSrFlag::SRF_FULL || ( flag == EcalSrFlag::SRF_FORCED_MASK) ) {
194  //EcalTrigTowerDetId ttId = it->id();
195  //eeSrpTTDetId.push_back( ttId );
196  const EcalScDetId scId( it->id() );
197  // not clear how to get the vector of DetId constituents of a SC...
199  //std::vector<DetId> vid = ecalMapping_->dccTowerConstituents( eId.dccId(), eId.towerId() );
200  std::vector<DetId> vid;
201  for(int dx=1; dx<=5; ++dx){
202  for(int dy=1; dy<=5; ++dy){
203  const int ix = (scId.ix()-1)*5 + dx;
204  const int iy = (scId.iy()-1)*5 + dy;
205  const int iz = scId.zside();
206  if(EEDetId::validDetId(ix, iy, iz)){
207  vid.push_back(EEDetId(ix, iy, iz));
208  }
209  }
210  }
212  //std::vector<DetId> vid = ttMap_->constituentsOf( ttId );
213  for ( std::vector<DetId>::const_iterator itId = vid.begin(); itId != vid.end(); ++itId ) {
214  eeSrpDetId.push_back( *itId );
215  }
216  }
217  }
218  // SRP switched off: get the list from the DB
219  if ( ebSrFlags->size() == 0 ) {
220  }
221  // SRP switched off: get the list from the DB
222  if ( eeSrFlags->size() == 0 ) {
223  }
224 
225  /*
226  * get OR of integrity error collections
227  * in interesting regions flagged by SRP
228  * and insert them in the list of DetId to recover
229  */
230  // -- Barrel
231  for ( std::vector<edm::Handle<EBDetIdCollection> >::const_iterator it = ebDetIdColls.begin(); it != ebDetIdColls.end(); ++it )
232  {
233  const EBDetIdCollection * idc = it->product();
234  for ( EBDetIdCollection::const_iterator jt = idc->begin(); jt != idc->end(); ++jt )
235  if (include(ebSrpDetId, *jt))
236  ebDetIdToRecover->insert( *jt );
237  }
238  // -- Endcap
239  for ( std::vector<edm::Handle<EEDetIdCollection> >::const_iterator it = eeDetIdColls.begin(); it != eeDetIdColls.end(); ++it )
240  {
241  const EEDetIdCollection * idc = it->product();
242  for ( EEDetIdCollection::const_iterator jt = idc->begin(); jt != idc->end(); ++jt )
243  if (include(eeSrpDetId, *jt))
244  eeDetIdToRecover->insert( *jt );
245  }
246 
247  /*
248  * find isolated dead channels (from DB info) --> chStatus 10, 11, 12
249  * and group of dead channels w/ trigger(from DB info) --> chStatus 13
250  * in interesting regions flagged by SRP
251  */
252  // -- Barrel
253  for ( EBDetIdCollection::const_iterator itId = ebSrpDetId.begin(); itId != ebSrpDetId.end(); ++itId ) {
255  if ( chit != chStatus_->end() ) {
256  const int flag = (*chit).getStatusCode() & 0x001F;
257  if ( flag >= 10 && flag <= 12) { // FIXME -- avoid hardcoded values...
258  ebDetIdToRecover->insert( *itId );
259  } else if ( flag == 13 || flag == 14 ) { // FIXME -- avoid hardcoded values...
260  ebTTDetIdToRecover->insert( (*itId).tower() );
261  }
262  } else {
263  edm::LogError("EcalDetIdToBeRecoveredProducer") << "No channel status found for xtal "
264  << (*itId).rawId()
265  << "! something wrong with EcalChannelStatus in your DB? ";
266  }
267  }
268  // -- Endcap
269  for ( EEDetIdCollection::const_iterator itId = eeSrpDetId.begin(); itId != eeSrpDetId.end(); ++itId ) {
271  if ( chit != chStatus_->end() ) {
272  int flag = (*chit).getStatusCode() & 0x001F;
273  if ( flag >= 10 && flag <= 12) { // FIXME -- avoid hardcoded values...
274  eeDetIdToRecover->insert( *itId );
275  } else if ( flag == 13 || flag == 14 ) { // FIXME -- avoid hardcoded values...
276  eeSCDetIdToRecover->insert( EcalScDetId(1+((*itId).ix()-1)/5,1+((*itId).iy()-1)/5,(*itId).zside()) );
277  }
278  } else {
279  edm::LogError("EcalDetIdToBeRecoveredProducer") << "No channel status found for xtal "
280  << (*itId).rawId()
281  << "! something wrong with EcalChannelStatus in your DB? ";
282  }
283  }
284 
285 
286  // loop over electronics id associated with TT and SC
287  for (size_t t = 0; t < ttColls.size(); ++t) {
288  const EcalElectronicsIdCollection& coll = *(ttColls[t]);
289 
290  for (size_t i = 0; i < coll.size(); ++i)
291  {
292  const EcalElectronicsId elId = coll[i];
293  const EcalSubdetector subdet = elId.subdet();
294  const DetId detId = ecalMapping_->getDetId(elId);
295 
296  if (subdet == EcalBarrel) { // elId pointing to TT
297  // get list of crystals corresponding to TT
298  const EcalTrigTowerDetId ttId( ttMap_->towerOf(detId) );
299  const std::vector<DetId>& vid = ttMap_->constituentsOf(ttId);
300 
301  for (size_t j = 0; j < vid.size(); ++j) {
302  const EBDetId ebdi(vid[j]);
303  if (include(ebSrpDetId, ebdi)) {
304  ebDetIdToRecover->insert(ebdi);
305  ebTTDetIdToRecover->insert(ebdi.tower());
306  }
307  }
308  }
309  else if (subdet == EcalEndcap) { // elId pointing to SC
310  // extract list of crystals corresponding to SC
311  const EcalScDetId scId(detId);
312  std::vector<DetId> vid;
313  for(int dx=1; dx<=5; ++dx) {
314  for(int dy=1; dy<=5; ++dy) {
315  const int ix = (scId.ix()-1)*5 + dx;
316  const int iy = (scId.iy()-1)*5 + dy;
317  const int iz = scId.zside();
318  if(EEDetId::validDetId(ix, iy, iz))
319  vid.push_back(EEDetId(ix, iy, iz));
320  }
321  }
322 
323  for (size_t j = 0; j < vid.size(); ++j) {
324  const EEDetId eedi(vid[i]);
325  if (include(eeSrpDetId, eedi)) {
326  eeDetIdToRecover->insert(eedi);
327  eeSCDetIdToRecover->insert(EcalScDetId(eedi));
328  }
329  }
330  }
331  else
332  edm::LogWarning("EcalDetIdToBeRecoveredProducer")
333  << "Incorrect EcalSubdetector = " << subdet
334  << " in EcalElectronicsIdCollection collection ";
335  }
336  }
337 
338  // return the collections
339  ev.put( ebDetIdToRecover, ebDetIdCollection_ );
340  ev.put( eeDetIdToRecover, eeDetIdCollection_ );
341  ev.put( ebTTDetIdToRecover, ttDetIdCollection_ );
342  ev.put( eeSCDetIdToRecover, scDetIdCollection_ );
343 }
344 
345 
size_type size() const
Definition: EDCollection.h:98
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
long int flag
Definition: mlp_lapack.h:47
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
const_iterator end() const
Definition: EDCollection.h:154
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:30
std::vector< T >::const_iterator const_iterator
void push_back(T const &t)
Definition: EDCollection.h:68
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
virtual void beginRun(edm::Run &run, const edm::EventSetup &es)
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.cc:562
virtual void produce(edm::Event &evt, const edm::EventSetup &es)
int ix() const
Definition: EcalScDetId.h:72
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
static const int SRF_FULL
Definition: EcalSrFlag.h:25
int j
Definition: DBlmapReader.cc:9
EcalTrigTowerDetId tower() const
get the HCAL/trigger iphi of this crystal
Definition: EBDetId.h:52
EcalDetIdToBeRecoveredProducer(const edm::ParameterSet &ps)
bool isValid() const
Definition: HandleBase.h:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
EcalSubdetector subdet() const
get the subdet
int iy() const
Definition: EcalScDetId.h:78
Definition: DetId.h:20
edm::ESHandle< EcalTrigTowerConstituentsMap > ttMap_
const_iterator begin() const
Definition: EDCollection.h:147
JetCorrectorParametersCollection coll
Definition: classes.h:14
const T & get() const
Definition: EventSetup.h:55
std::vector< Item >::const_iterator const_iterator
T const * product() const
Definition: ESHandle.h:62
int zside() const
Definition: EcalScDetId.h:66
DetId getDetId(const EcalElectronicsId &id) const
Get the detid given an electronicsId.
unsigned ttId(const DetId &)
bool include(const CollT &coll, const ItemT &item)
const_iterator find(uint32_t rawId) const
const_iterator end() const
const EcalElectronicsMapping * ecalMapping_
EcalSubdetector
Definition: Run.h:33
std::vector< T >::const_iterator const_iterator
Definition: EDCollection.h:20