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 
11 
13 
17 
18 #include <set>
19 
20 #include <sys/types.h>
21 #include <signal.h>
22 
24 {
25  // SRP collections
26  ebSrFlagToken_ = consumes<EBSrFlagCollection>(ps.getParameter<edm::InputTag>("ebSrFlagCollection"));
27  eeSrFlagToken_ = consumes<EESrFlagCollection>(ps.getParameter<edm::InputTag>("eeSrFlagCollection"));
28 
29  // Integrity for xtal data
30  ebIntegrityGainErrorsToken_ = consumes<EBDetIdCollection>(ps.getParameter<edm::InputTag>("ebIntegrityGainErrors"));
31  ebIntegrityGainSwitchErrorsToken_ = consumes<EBDetIdCollection>(ps.getParameter<edm::InputTag>("ebIntegrityGainSwitchErrors"));
32  ebIntegrityChIdErrorsToken_ = consumes<EBDetIdCollection>(ps.getParameter<edm::InputTag>("ebIntegrityChIdErrors"));
33 
34  // Integrity for xtal data - EE specific (to be rivisited towards EB+EE common collection)
35  eeIntegrityGainErrorsToken_ = consumes<EEDetIdCollection>(ps.getParameter<edm::InputTag>("eeIntegrityGainErrors"));
36  eeIntegrityGainSwitchErrorsToken_ = consumes<EEDetIdCollection>(ps.getParameter<edm::InputTag>("eeIntegrityGainSwitchErrors"));
37  eeIntegrityChIdErrorsToken_ = consumes<EEDetIdCollection>(ps.getParameter<edm::InputTag>("eeIntegrityChIdErrors"));
38 
39  // Integrity Errors
40  integrityTTIdErrorsToken_ = consumes<EcalElectronicsIdCollection>(ps.getParameter<edm::InputTag>("integrityTTIdErrors"));
41  integrityBlockSizeErrorsToken_ = consumes<EcalElectronicsIdCollection>(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.getByToken(ebSrFlagToken_, ebSrFlags );
100 
102  ev.getByToken(eeSrFlagToken_, eeSrFlags );
103 
104  // Integrity errors
106  ev.getByToken( ebIntegrityGainErrorsToken_, ebIntegrityGainErrors );
107 
108  ebDetIdColls.push_back( ebIntegrityGainErrors );
109 
111  ev.getByToken( ebIntegrityGainSwitchErrorsToken_, ebIntegrityGainSwitchErrors );
112  ebDetIdColls.push_back( ebIntegrityGainSwitchErrors );
113 
115  ev.getByToken( ebIntegrityChIdErrorsToken_, ebIntegrityChIdErrors );
116  ebDetIdColls.push_back( ebIntegrityChIdErrors );
117 
119  ev.getByToken( eeIntegrityGainErrorsToken_, eeIntegrityGainErrors );
120  eeDetIdColls.push_back( eeIntegrityGainErrors );
121 
123  ev.getByToken( eeIntegrityGainSwitchErrorsToken_, eeIntegrityGainSwitchErrors );
124  eeDetIdColls.push_back( eeIntegrityGainSwitchErrors );
125 
126 
127 
129  ev.getByToken( eeIntegrityChIdErrorsToken_, eeIntegrityChIdErrors );
130  eeDetIdColls.push_back( eeIntegrityChIdErrors );
131 
132 
133 
134 
136  ev.getByToken( integrityTTIdErrorsToken_, integrityTTIdErrors );
137  ttColls.push_back( integrityTTIdErrors );
138 
140  ev.getByToken( integrityBlockSizeErrorsToken_, integrityBlockSizeErrors );
141  ttColls.push_back( integrityBlockSizeErrors );
142 
143  /*
144  * get regions of interest from SRP
145  */
146  // -- Barrel
147  EBDetIdCollection ebSrpDetId;
148  EcalTrigTowerDetIdCollection ebSrpTTDetId;
149  for ( EBSrFlagCollection::const_iterator it = ebSrFlags->begin(); it != ebSrFlags->end(); ++it ) {
150  const int flag = it->value();
151  if ( flag == EcalSrFlag::SRF_FULL || ( flag == EcalSrFlag::SRF_FORCED_MASK) ) {
152  const EcalTrigTowerDetId ttId = it->id();
153  ebSrpTTDetId.push_back( ttId );
154 
155  const std::vector<DetId> vid = ttMap_->constituentsOf( ttId );
156 
157  for ( std::vector<DetId>::const_iterator itId = vid.begin(); itId != vid.end(); ++itId ) {
158  ebSrpDetId.push_back( *itId );
159  }
160  }
161  }
162  // -- Endcap
163  EEDetIdCollection eeSrpDetId;
164  //EcalTrigTowerDetIdCollection eeSrpTTDetId;
165  for ( EESrFlagCollection::const_iterator it = eeSrFlags->begin(); it != eeSrFlags->end(); ++it ) {
166  const int flag = it->value();
167  if ( flag == EcalSrFlag::SRF_FULL || ( flag == EcalSrFlag::SRF_FORCED_MASK) ) {
168  //EcalTrigTowerDetId ttId = it->id();
169  //eeSrpTTDetId.push_back( ttId );
170  const EcalScDetId scId( it->id() );
171  // not clear how to get the vector of DetId constituents of a SC...
173  //std::vector<DetId> vid = ecalMapping_->dccTowerConstituents( eId.dccId(), eId.towerId() );
174  std::vector<DetId> vid;
175  for(int dx=1; dx<=5; ++dx){
176  for(int dy=1; dy<=5; ++dy){
177  const int ix = (scId.ix()-1)*5 + dx;
178  const int iy = (scId.iy()-1)*5 + dy;
179  const int iz = scId.zside();
180  if(EEDetId::validDetId(ix, iy, iz)){
181  vid.push_back(EEDetId(ix, iy, iz));
182  }
183  }
184  }
186  //std::vector<DetId> vid = ttMap_->constituentsOf( ttId );
187  for ( std::vector<DetId>::const_iterator itId = vid.begin(); itId != vid.end(); ++itId ) {
188  eeSrpDetId.push_back( *itId );
189  }
190  }
191  }
192  // SRP switched off: get the list from the DB
193  if ( ebSrFlags->size() == 0 ) {
194  }
195  // SRP switched off: get the list from the DB
196  if ( eeSrFlags->size() == 0 ) {
197  }
198 
199  /*
200  * get OR of integrity error collections
201  * in interesting regions flagged by SRP
202  * and insert them in the list of DetId to recover
203  */
204  // -- Barrel
205  for ( std::vector<edm::Handle<EBDetIdCollection> >::const_iterator it = ebDetIdColls.begin(); it != ebDetIdColls.end(); ++it )
206  {
207  const EBDetIdCollection * idc = it->product();
208  for ( EBDetIdCollection::const_iterator jt = idc->begin(); jt != idc->end(); ++jt )
209  if (include(ebSrpDetId, *jt))
210  ebDetIdToRecover->insert( *jt );
211  }
212  // -- Endcap
213  for ( std::vector<edm::Handle<EEDetIdCollection> >::const_iterator it = eeDetIdColls.begin(); it != eeDetIdColls.end(); ++it )
214  {
215  const EEDetIdCollection * idc = it->product();
216  for ( EEDetIdCollection::const_iterator jt = idc->begin(); jt != idc->end(); ++jt )
217  if (include(eeSrpDetId, *jt))
218  eeDetIdToRecover->insert( *jt );
219  }
220 
221  /*
222  * find isolated dead channels (from DB info) --> chStatus 10, 11, 12
223  * and group of dead channels w/ trigger(from DB info) --> chStatus 13
224  * in interesting regions flagged by SRP
225  */
226  // -- Barrel
227  for ( EBDetIdCollection::const_iterator itId = ebSrpDetId.begin(); itId != ebSrpDetId.end(); ++itId ) {
229  if ( chit != chStatus_->end() ) {
230  const int flag = (*chit).getStatusCode();
231  if ( flag >= 10 && flag <= 12) { // FIXME -- avoid hardcoded values...
232  ebDetIdToRecover->insert( *itId );
233  } else if ( flag == 13 || flag == 14 ) { // FIXME -- avoid hardcoded values...
234  ebTTDetIdToRecover->insert( (*itId).tower() );
235  }
236  } else {
237  edm::LogError("EcalDetIdToBeRecoveredProducer") << "No channel status found for xtal "
238  << (*itId).rawId()
239  << "! something wrong with EcalChannelStatus in your DB? ";
240  }
241  }
242  // -- Endcap
243  for ( EEDetIdCollection::const_iterator itId = eeSrpDetId.begin(); itId != eeSrpDetId.end(); ++itId ) {
245  if ( chit != chStatus_->end() ) {
246  int flag = (*chit).getStatusCode() ;
247  if ( flag >= 10 && flag <= 12) { // FIXME -- avoid hardcoded values...
248  eeDetIdToRecover->insert( *itId );
249  } else if ( flag == 13 || flag == 14 ) { // FIXME -- avoid hardcoded values...
250  eeSCDetIdToRecover->insert( EcalScDetId(1+((*itId).ix()-1)/5,1+((*itId).iy()-1)/5,(*itId).zside()) );
251  }
252  } else {
253  edm::LogError("EcalDetIdToBeRecoveredProducer") << "No channel status found for xtal "
254  << (*itId).rawId()
255  << "! something wrong with EcalChannelStatus in your DB? ";
256  }
257  }
258 
259 
260  // loop over electronics id associated with TT and SC
261  for (size_t t = 0; t < ttColls.size(); ++t) {
262  const EcalElectronicsIdCollection& coll = *(ttColls[t]);
263 
264  for (size_t i = 0; i < coll.size(); ++i)
265  {
266  const EcalElectronicsId elId = coll[i];
267  const EcalSubdetector subdet = elId.subdet();
268  const DetId detId = ecalMapping_->getDetId(elId);
269 
270  if (subdet == EcalBarrel) { // elId pointing to TT
271  // get list of crystals corresponding to TT
272  const EcalTrigTowerDetId ttId( ttMap_->towerOf(detId) );
273  const std::vector<DetId>& vid = ttMap_->constituentsOf(ttId);
274 
275  for (size_t j = 0; j < vid.size(); ++j) {
276  const EBDetId ebdi(vid[j]);
277  if (include(ebSrpDetId, ebdi)) {
278  ebDetIdToRecover->insert(ebdi);
279  ebTTDetIdToRecover->insert(ebdi.tower());
280  }
281  }
282  }
283  else if (subdet == EcalEndcap) { // elId pointing to SC
284  // extract list of crystals corresponding to SC
285  const EcalScDetId scId(detId);
286  std::vector<DetId> vid;
287  for(int dx=1; dx<=5; ++dx) {
288  for(int dy=1; dy<=5; ++dy) {
289  const int ix = (scId.ix()-1)*5 + dx;
290  const int iy = (scId.iy()-1)*5 + dy;
291  const int iz = scId.zside();
292  if(EEDetId::validDetId(ix, iy, iz))
293  vid.push_back(EEDetId(ix, iy, iz));
294  }
295  }
296 
297  for (size_t j = 0; j < vid.size(); ++j) {
298  const EEDetId eedi(vid[i]);
299  if (include(eeSrpDetId, eedi)) {
300  eeDetIdToRecover->insert(eedi);
301  eeSCDetIdToRecover->insert(EcalScDetId(eedi));
302  }
303  }
304  }
305  else
306  edm::LogWarning("EcalDetIdToBeRecoveredProducer")
307  << "Incorrect EcalSubdetector = " << subdet
308  << " in EcalElectronicsIdCollection collection ";
309  }
310  }
311 
312  // return the collections
313  ev.put( ebDetIdToRecover, ebDetIdCollection_ );
314  ev.put( eeDetIdToRecover, eeDetIdCollection_ );
315  ev.put( ebTTDetIdToRecover, ttDetIdCollection_ );
316  ev.put( eeSCDetIdToRecover, scDetIdCollection_ );
317 }
318 
321  desc.add<edm::InputTag>("ebIntegrityChIdErrors",edm::InputTag("ecalDigis","EcalIntegrityChIdErrors"));
322  desc.add<std::string>("ebDetIdToBeRecovered","ebDetId");
323  desc.add<edm::InputTag>("integrityTTIdErrors",edm::InputTag("ecalDigis","EcalIntegrityTTIdErrors"));
324  desc.add<edm::InputTag>("eeIntegrityGainErrors",edm::InputTag("ecalDigis","EcalIntegrityGainErrors"));
325  desc.add<std::string>("ebFEToBeRecovered","ebFE");
326  desc.add<edm::InputTag>("ebIntegrityGainErrors",edm::InputTag("ecalDigis","EcalIntegrityGainErrors"));
327  desc.add<std::string>("eeDetIdToBeRecovered","eeDetId");
328  desc.add<edm::InputTag>("eeIntegrityGainSwitchErrors",edm::InputTag("ecalDigis","EcalIntegrityGainSwitchErrors"));
329  desc.add<edm::InputTag>("eeIntegrityChIdErrors",edm::InputTag("ecalDigis","EcalIntegrityChIdErrors"));
330  desc.add<edm::InputTag>("ebIntegrityGainSwitchErrors",edm::InputTag("ecalDigis","EcalIntegrityGainSwitchErrors"));
331  desc.add<edm::InputTag>("ebSrFlagCollection",edm::InputTag("ecalDigis"));
332  desc.add<std::string>("eeFEToBeRecovered","eeFE");
333  desc.add<edm::InputTag>("integrityBlockSizeErrors",edm::InputTag("ecalDigis","EcalIntegrityBlockSizeErrors"));
334  desc.add<edm::InputTag>("eeSrFlagCollection",edm::InputTag("ecalDigis"));
335  descriptions.add("ecalDetIdToBeRecovered",desc);
336 }
337 
338 
size_type size() const
Definition: EDCollection.h:97
T getParameter(std::string const &) const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int i
Definition: DBlmapReader.cc:9
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
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_
bool ev
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
unsigned ttId(DetId const &)
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:113
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)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
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
JetCorrectorParametersCollection coll
Definition: classes.h:10
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:86
int zside() const
Definition: EcalScDetId.h:65
void add(std::string const &label, ParameterSetDescription const &psetDescription)
DetId getDetId(const EcalElectronicsId &id) const
Get the detid given an electronicsId.
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