CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalDQMCommonUtils.h
Go to the documentation of this file.
1 #ifndef EcalDQMCommonUtils_H
2 #define EcalDQMCommonUtils_H
3 
4 #include <set>
5 #include <iomanip>
6 
9 
18 
20 
21 namespace ecaldqm {
22 
23  enum SMName {
33  kEBpLow = kEBp01, kEBpHigh = kEBp18
34  };
35 
36  // returns DCC ID (1 - 54)
37  unsigned dccId(const DetId&);
38  unsigned dccId(const EcalElectronicsId&);
39  unsigned dccId(unsigned); // convert from dccId skipping DCCs without MEM
40 
41  unsigned memDCCIndex(unsigned); // reverse conversion
42 
43  // returns TCC ID (1 - 108)
44  unsigned tccId(const DetId&);
45  unsigned tccId(const EcalElectronicsId&);
46 
47  // returns the data tower id - pass only
48  unsigned towerId(const DetId&);
49  unsigned towerId(const EcalElectronicsId&);
50 
51  unsigned ttId(const DetId&);
52  unsigned ttId(const EcalElectronicsId&);
53 
54  bool isEcalScDetId(const DetId& _id);
55 
56  unsigned getEEPnDCC(unsigned, unsigned);
57 
58  unsigned getNSuperCrystals(unsigned);
59 
60  bool ccuExists(unsigned, unsigned);
61 
64 
67 
68  void checkElectronicsMap();
69  void checkTrigTowerMap();
70 }
71 
72 namespace ecaldqm {
73 
76  extern const std::set<unsigned> dccNoMEM;
77 
78  inline unsigned dccId(const DetId &_id){
80 
81  unsigned subdet(_id.subdetId());
82 
83  if(subdet == EcalBarrel) return electronicsMap->DCCid(EBDetId(_id));
84  else if(subdet == EcalTriggerTower) return electronicsMap->DCCid(EcalTrigTowerDetId(_id));
85  else if(subdet == EcalEndcap){
86  if(isEcalScDetId(_id)) return electronicsMap->getDCCandSC(EcalScDetId(_id)).first;
87  else return electronicsMap->getElectronicsId(EEDetId(_id)).dccId();
88  }
89  else if(subdet == EcalLaserPnDiode) return EcalPnDiodeDetId(_id).iDCCId();
90 
91  throw cms::Exception("InvalidDetId") << "EcalDQMCommonUtils::dccId(" << _id.rawId() << ")" << std::endl;
92 
93  return 0;
94  }
95 
96  inline unsigned dccId(const EcalElectronicsId &_id){
97  return _id.dccId();
98  }
99 
100  inline unsigned dccId(unsigned _index){
101  // for DCCs with no MEM - map the index in an array of DCCs with no MEM to the DCC ID
102  unsigned iDCC(0);
103  unsigned count(0);
104 
105  while(count <= _index)
106  if(dccNoMEM.find(iDCC++) == dccNoMEM.end()) count++;
107 
108  return iDCC;
109  }
110 
111  inline unsigned memDCCIndex(unsigned _dccid){
112  unsigned index(0);
113  unsigned iDCC(0);
114 
115  while(iDCC < _dccid)
116  if(dccNoMEM.find(iDCC++) == dccNoMEM.end()) index++;
117 
118  index -= 1;
119 
120  return index;
121  }
122 
123  inline unsigned tccId(const DetId &_id){
125 
126  unsigned subdet(_id.subdetId());
127 
128  if(subdet == EcalBarrel) return electronicsMap->TCCid(EBDetId(_id));
129  else if(subdet == EcalTriggerTower) return electronicsMap->TCCid(EcalTrigTowerDetId(_id));
130  else if(subdet == EcalEndcap){
131  if(isEcalScDetId(_id)) return 0; // incompatible
133  }
134 
135  throw cms::Exception("InvalidDetId") << "EcalDQMCommonUtils::tccId(" << uint32_t(_id) << ")" << std::endl;
136 
137  return 0;
138  }
139 
140  inline unsigned tccId(const EcalElectronicsId &_id){
142 
144  }
145 
146 
147  inline unsigned towerId(const DetId &_id){
149 
150  unsigned subdet(_id.subdetId());
151 
152  if(subdet == EcalBarrel){
153  return EBDetId(_id).tower().iTT();
154  }else if(subdet == EcalTriggerTower){
155  return EcalTrigTowerDetId(_id).iTT();
156  }else if(subdet == EcalEndcap){
157  if(isEcalScDetId(_id)) return electronicsMap->getDCCandSC(EcalScDetId(_id)).second;
158  else return electronicsMap->getElectronicsId(EEDetId(_id)).towerId();
159  }
160 
161  throw cms::Exception("InvalidDetId") << "EcalDQMCommonUtils::towerId(" << std::hex << uint32_t(_id) << ")" << std::endl;
162 
163  return 0;
164  }
165 
166  inline unsigned towerId(const EcalElectronicsId &_id){
167  return _id.towerId();
168  }
169 
170  inline unsigned ttId(const DetId& _id){
172 
173  unsigned subdet(_id.subdetId());
174 
175  if(subdet == EcalBarrel)
176  return EBDetId(_id).tower().iTT();
177  else if(subdet == EcalTriggerTower)
178  return electronicsMap->iTT(EcalTrigTowerDetId(_id));
179  else if(subdet == EcalEndcap && !isEcalScDetId(_id))
181 
182  throw cms::Exception("InvalidDetId") << "EcalDQMCommonUtils::ttId(" << std::hex << uint32_t(_id) << ")" << std::endl;
183 
184  return 0;
185  }
186 
187  inline unsigned ttId(const EcalElectronicsId &_id){
190  }
191 
192  inline bool isEcalScDetId(const DetId& _id){
193  return (_id.subdetId() == EcalEndcap) && ((_id.rawId() >> 15) & 0x1);
194  }
195 
196  inline std::string smName(unsigned _dccId){
197  std::stringstream ss;
198 
199  unsigned iSM(_dccId - 1);
200 
201  if(iSM <= kEEmHigh)
202  ss << "EE-" << std::setw(2) << std::setfill('0') << (((iSM - kEEmLow + 6) % 9) + 1);
203  else if(iSM <= kEBmHigh)
204  ss << "EB-" << std::setw(2) << std::setfill('0') << (iSM - kEBmLow + 1);
205  else if(iSM <= kEBpHigh)
206  ss << "EB+" << std::setw(2) << std::setfill('0') << (iSM - kEBpLow + 1);
207  else if(iSM <= kEEpHigh)
208  ss << "EE+" << std::setw(2) << std::setfill('0') << (((iSM - kEEpLow + 6) % 9) + 1);
209 
210  return ss.str();
211  }
212 
213  // numbers from CalibCalorimetry/EcalLaserAnalyzer/src/MEEEGeom.cc
214  inline unsigned getEEPnDCC(unsigned _dee, unsigned _ab){
215  switch(_dee){
216  case 1: // EE+F -> FEDs 649-653/0
217  if(_ab == 0) return 650;
218  else return 651;
219  case 2: // EE+N -> FEDs 604-608/0
220  if(_ab == 0) return 605;
221  else return 606;
222  case 3: // EE-N -> FEDs 601-603, 608/1, 609
223  if(_ab == 0) return 601;
224  else return 602;
225  case 4: // EE-F -> FEDs 646-648, 653/1, 654
226  if(_ab == 0) return 647;
227  else return 646;
228  default:
229  return 600;
230  }
231  }
232 
233  inline unsigned getNSuperCrystals(unsigned _dccId){
234 
235  unsigned iSM(_dccId - 1);
236 
237  if(iSM >= kEBmLow && iSM <= kEBpHigh) return 68;
238 
239  switch(iSM){
240  case kEEm05:
241  case kEEp05:
242  return 41;
243  case kEEm07:
244  case kEEm03:
245  case kEEp07:
246  case kEEp03:
247  return 34;
248  case kEEm09:
249  case kEEm01:
250  case kEEm04:
251  case kEEm06:
252  case kEEp09:
253  case kEEp01:
254  case kEEp04:
255  case kEEp06:
256  return 33;
257  case kEEm08:
258  case kEEm02:
259  case kEEp08:
260  case kEEp02:
261  return 32;
262  default:
263  return 0;
264  }
265 
266  }
267 
268  inline bool ccuExists(unsigned _dccId, unsigned _towerId){
269  if(_towerId == 69 || _towerId == 70) return true;
270  else if((_dccId == 8 || _dccId == 53) && _towerId >= 18 && _towerId <= 24) return false;
271  else if(_dccId <= kEEmHigh + 1 || _dccId >= kEEpLow + 1){
272  if(_towerId > getNSuperCrystals(_dccId)) return false;
273  }
274 
275  return true;
276  }
277 
280  return electronicsMap;
281  }
282 
283  inline void setElectronicsMap(const EcalElectronicsMapping* _map){
284  if(electronicsMap) return;
285  electronicsMap = _map;
287  }
288 
291  return trigtowerMap;
292  }
293 
295  if(trigtowerMap) return;
296  trigtowerMap = _map;
298  }
299 
300  inline void checkElectronicsMap(){
301  if(!electronicsMap) throw cms::Exception("InvalidCall") << "ElectronicsMapping not initialized" << std::endl;
302  }
303 
304  inline void checkTrigTowerMap(){
305  if(!trigtowerMap) throw cms::Exception("InvalidCall") << "TrigTowerConstituentsMap not initialized" << std::endl;
306  }
307 
308 }
309 
310 #endif
unsigned memDCCIndex(unsigned)
const EcalElectronicsMapping * getElectronicsMap()
void setTrigTowerMap(const EcalTrigTowerConstituentsMap *)
int tccId() const
get the DCC (Ecal Local DCC value not global one) id
const EcalElectronicsMapping * electronicsMap
unsigned getEEPnDCC(unsigned, unsigned)
Ecal readout channel identification [32:20] Unused (so far) [19:13] DCC id [12:6] tower [5:3] strip [...
const EcalTrigTowerConstituentsMap * trigtowerMap
std::string smName(unsigned _dccId)
int towerId() const
get the tower id
unsigned dccId(const DetId &)
int iTT(const EcalTrigTowerDetId &id) const
returns the index of a Trigger Tower within its TCC.
bool ccuExists(unsigned, unsigned)
std::pair< int, int > getDCCandSC(EcalScDetId id) const
void checkTrigTowerMap()
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
int TCCid(const EBDetId &id) const
returns the TCCid of an EBDetId
void setElectronicsMap(const EcalElectronicsMapping *)
unsigned towerId(const DetId &)
EcalElectronicsId getElectronicsId(const DetId &id) const
Get the electronics id for this det id.
int ttId() const
get the tower id
EcalTriggerElectronicsId getTriggerElectronicsId(const DetId &id) const
Get the trigger electronics id for this det id.
EcalTrigTowerDetId tower() const
get the HCAL/trigger iphi of this crystal
Definition: EBDetId.h:59
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
int iDCCId() const
get the DCCId
int dccId() const
get the DCC (Ecal Local DCC value not global one) id
bool isEcalScDetId(const DetId &_id)
const std::set< unsigned > dccNoMEM
Definition: DetId.h:18
unsigned getNSuperCrystals(unsigned)
int DCCid(const EBDetId &id) const
returns the DCC of an EBDetId
const EcalTrigTowerConstituentsMap * getTrigTowerMap()
unsigned tccId(const DetId &)
unsigned ttId(const DetId &)
void checkElectronicsMap()
int iTT() const
sequential index within one DCC