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