00001 #ifndef EcalDQMCommonUtils_H
00002 #define EcalDQMCommonUtils_H
00003
00004 #include <set>
00005 #include <iomanip>
00006
00007 #include "Geometry/EcalMapping/interface/EcalElectronicsMapping.h"
00008 #include "Geometry/CaloTopology/interface/EcalTrigTowerConstituentsMap.h"
00009
00010 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
00011 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00012 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00013 #include "DataFormats/EcalDetId/interface/EcalPnDiodeDetId.h"
00014 #include "DataFormats/EcalDetId/interface/EcalScDetId.h"
00015 #include "DataFormats/EcalDetId/interface/EcalTrigTowerDetId.h"
00016 #include "DataFormats/EcalDetId/interface/EcalElectronicsId.h"
00017 #include "DataFormats/EcalDetId/interface/EcalTriggerElectronicsId.h"
00018
00019 #include "FWCore/Utilities/interface/Exception.h"
00020
00021 namespace ecaldqm {
00022
00023 enum SMName {
00024 kEEm07, kEEm08, kEEm09, kEEm01, kEEm02, kEEm03, kEEm04, kEEm05, kEEm06,
00025 kEBm01, kEBm02, kEBm03, kEBm04, kEBm05, kEBm06, kEBm07, kEBm08, kEBm09,
00026 kEBm10, kEBm11, kEBm12, kEBm13, kEBm14, kEBm15, kEBm16, kEBm17, kEBm18,
00027 kEBp01, kEBp02, kEBp03, kEBp04, kEBp05, kEBp06, kEBp07, kEBp08, kEBp09,
00028 kEBp10, kEBp11, kEBp12, kEBp13, kEBp14, kEBp15, kEBp16, kEBp17, kEBp18,
00029 kEEp07, kEEp08, kEEp09, kEEp01, kEEp02, kEEp03, kEEp04, kEEp05, kEEp06,
00030 kEEmLow = kEEm07, kEEmHigh = kEEm06,
00031 kEEpLow = kEEp07, kEEpHigh = kEEp06,
00032 kEBmLow = kEBm01, kEBmHigh = kEBm18,
00033 kEBpLow = kEBp01, kEBpHigh = kEBp18
00034 };
00035
00036
00037 unsigned dccId(const DetId&);
00038 unsigned dccId(const EcalElectronicsId&);
00039 unsigned dccId(unsigned);
00040
00041 unsigned memDCCIndex(unsigned);
00042
00043
00044 unsigned tccId(const DetId&);
00045 unsigned tccId(const EcalElectronicsId&);
00046
00047
00048 unsigned towerId(const DetId&);
00049 unsigned towerId(const EcalElectronicsId&);
00050
00051 unsigned ttId(const DetId&);
00052 unsigned ttId(const EcalElectronicsId&);
00053
00054 bool isEcalScDetId(const DetId& _id);
00055
00056 unsigned getEEPnDCC(unsigned, unsigned);
00057
00058 unsigned getNSuperCrystals(unsigned);
00059
00060 bool ccuExists(unsigned, unsigned);
00061
00062 const EcalElectronicsMapping* getElectronicsMap();
00063 void setElectronicsMap(const EcalElectronicsMapping*);
00064
00065 const EcalTrigTowerConstituentsMap* getTrigTowerMap();
00066 void setTrigTowerMap(const EcalTrigTowerConstituentsMap*);
00067
00068 void checkElectronicsMap();
00069 void checkTrigTowerMap();
00070 }
00071
00072 namespace ecaldqm {
00073
00074 extern const EcalElectronicsMapping* electronicsMap;
00075 extern const EcalTrigTowerConstituentsMap* trigtowerMap;
00076 extern const std::set<unsigned> dccNoMEM;
00077
00078 inline unsigned dccId(const DetId &_id){
00079 checkElectronicsMap();
00080
00081 unsigned subdet(_id.subdetId());
00082
00083 if(subdet == EcalBarrel) return electronicsMap->DCCid(EBDetId(_id));
00084 else if(subdet == EcalTriggerTower) return electronicsMap->DCCid(EcalTrigTowerDetId(_id));
00085 else if(subdet == EcalEndcap){
00086 if(isEcalScDetId(_id)) return electronicsMap->getDCCandSC(EcalScDetId(_id)).first;
00087 else return electronicsMap->getElectronicsId(EEDetId(_id)).dccId();
00088 }
00089 else if(subdet == EcalLaserPnDiode) return EcalPnDiodeDetId(_id).iDCCId();
00090
00091 throw cms::Exception("InvalidDetId") << "EcalDQMCommonUtils::dccId(" << _id.rawId() << ")" << std::endl;
00092
00093 return 0;
00094 }
00095
00096 inline unsigned dccId(const EcalElectronicsId &_id){
00097 return _id.dccId();
00098 }
00099
00100 inline unsigned dccId(unsigned _index){
00101
00102 unsigned iDCC(0);
00103 unsigned count(0);
00104
00105 while(count <= _index)
00106 if(dccNoMEM.find(iDCC++) == dccNoMEM.end()) count++;
00107
00108 return iDCC;
00109 }
00110
00111 inline unsigned memDCCIndex(unsigned _dccid){
00112 unsigned index(0);
00113 unsigned iDCC(0);
00114
00115 while(iDCC < _dccid)
00116 if(dccNoMEM.find(iDCC++) == dccNoMEM.end()) index++;
00117
00118 index -= 1;
00119
00120 return index;
00121 }
00122
00123 inline unsigned tccId(const DetId &_id){
00124 checkElectronicsMap();
00125
00126 unsigned subdet(_id.subdetId());
00127
00128 if(subdet == EcalBarrel) return electronicsMap->TCCid(EBDetId(_id));
00129 else if(subdet == EcalTriggerTower) return electronicsMap->TCCid(EcalTrigTowerDetId(_id));
00130 else if(subdet == EcalEndcap){
00131 if(isEcalScDetId(_id)) return 0;
00132 else return electronicsMap->getTriggerElectronicsId(EEDetId(_id)).tccId();
00133 }
00134
00135 throw cms::Exception("InvalidDetId") << "EcalDQMCommonUtils::tccId(" << uint32_t(_id) << ")" << std::endl;
00136
00137 return 0;
00138 }
00139
00140 inline unsigned tccId(const EcalElectronicsId &_id){
00141 checkElectronicsMap();
00142
00143 return electronicsMap->getTriggerElectronicsId(_id).tccId();
00144 }
00145
00146
00147 inline unsigned towerId(const DetId &_id){
00148 checkElectronicsMap();
00149
00150 unsigned subdet(_id.subdetId());
00151
00152 if(subdet == EcalBarrel){
00153 return EBDetId(_id).tower().iTT();
00154 }else if(subdet == EcalTriggerTower){
00155 return EcalTrigTowerDetId(_id).iTT();
00156 }else if(subdet == EcalEndcap){
00157 if(isEcalScDetId(_id)) return electronicsMap->getDCCandSC(EcalScDetId(_id)).second;
00158 else return electronicsMap->getElectronicsId(EEDetId(_id)).towerId();
00159 }
00160
00161 throw cms::Exception("InvalidDetId") << "EcalDQMCommonUtils::towerId(" << std::hex << uint32_t(_id) << ")" << std::endl;
00162
00163 return 0;
00164 }
00165
00166 inline unsigned towerId(const EcalElectronicsId &_id){
00167 return _id.towerId();
00168 }
00169
00170 inline unsigned ttId(const DetId& _id){
00171 checkElectronicsMap();
00172
00173 unsigned subdet(_id.subdetId());
00174
00175 if(subdet == EcalBarrel)
00176 return EBDetId(_id).tower().iTT();
00177 else if(subdet == EcalTriggerTower)
00178 return electronicsMap->iTT(EcalTrigTowerDetId(_id));
00179 else if(subdet == EcalEndcap && !isEcalScDetId(_id))
00180 return electronicsMap->getTriggerElectronicsId(_id).ttId();
00181
00182 throw cms::Exception("InvalidDetId") << "EcalDQMCommonUtils::ttId(" << std::hex << uint32_t(_id) << ")" << std::endl;
00183
00184 return 0;
00185 }
00186
00187 inline unsigned ttId(const EcalElectronicsId &_id){
00188 checkElectronicsMap();
00189 return electronicsMap->getTriggerElectronicsId(_id).ttId();
00190 }
00191
00192 inline bool isEcalScDetId(const DetId& _id){
00193 return (_id.subdetId() == EcalEndcap) && ((_id.rawId() >> 15) & 0x1);
00194 }
00195
00196 inline std::string smName(unsigned _dccId){
00197 std::stringstream ss;
00198
00199 unsigned iSM(_dccId - 1);
00200
00201 if(iSM <= kEEmHigh)
00202 ss << "EE-" << std::setw(2) << std::setfill('0') << (((iSM - kEEmLow + 6) % 9) + 1);
00203 else if(iSM <= kEBmHigh)
00204 ss << "EB-" << std::setw(2) << std::setfill('0') << (iSM - kEBmLow + 1);
00205 else if(iSM <= kEBpHigh)
00206 ss << "EB+" << std::setw(2) << std::setfill('0') << (iSM - kEBpLow + 1);
00207 else if(iSM <= kEEpHigh)
00208 ss << "EE+" << std::setw(2) << std::setfill('0') << (((iSM - kEEpLow + 6) % 9) + 1);
00209
00210 return ss.str();
00211 }
00212
00213
00214 inline unsigned getEEPnDCC(unsigned _dee, unsigned _ab){
00215 switch(_dee){
00216 case 1:
00217 if(_ab == 0) return 650;
00218 else return 651;
00219 case 2:
00220 if(_ab == 0) return 605;
00221 else return 606;
00222 case 3:
00223 if(_ab == 0) return 601;
00224 else return 602;
00225 case 4:
00226 if(_ab == 0) return 647;
00227 else return 646;
00228 default:
00229 return 600;
00230 }
00231 }
00232
00233 inline unsigned getNSuperCrystals(unsigned _dccId){
00234
00235 unsigned iSM(_dccId - 1);
00236
00237 if(iSM >= kEBmLow && iSM <= kEBpHigh) return 68;
00238
00239 switch(iSM){
00240 case kEEm05:
00241 case kEEp05:
00242 return 41;
00243 case kEEm07:
00244 case kEEm03:
00245 case kEEp07:
00246 case kEEp03:
00247 return 34;
00248 case kEEm09:
00249 case kEEm01:
00250 case kEEm04:
00251 case kEEm06:
00252 case kEEp09:
00253 case kEEp01:
00254 case kEEp04:
00255 case kEEp06:
00256 return 33;
00257 case kEEm08:
00258 case kEEm02:
00259 case kEEp08:
00260 case kEEp02:
00261 return 32;
00262 default:
00263 return 0;
00264 }
00265
00266 }
00267
00268 inline bool ccuExists(unsigned _dccId, unsigned _towerId){
00269 if(_towerId == 69 || _towerId == 70) return true;
00270 else if((_dccId == 8 || _dccId == 53) && _towerId >= 18 && _towerId <= 24) return false;
00271 else if(_dccId <= kEEmHigh + 1 || _dccId >= kEEpLow + 1){
00272 if(_towerId > getNSuperCrystals(_dccId)) return false;
00273 }
00274
00275 return true;
00276 }
00277
00278 inline const EcalElectronicsMapping* getElectronicsMap(){
00279 checkElectronicsMap();
00280 return electronicsMap;
00281 }
00282
00283 inline void setElectronicsMap(const EcalElectronicsMapping* _map){
00284 if(electronicsMap) return;
00285 electronicsMap = _map;
00286 checkElectronicsMap();
00287 }
00288
00289 inline const EcalTrigTowerConstituentsMap* getTrigTowerMap(){
00290 checkTrigTowerMap();
00291 return trigtowerMap;
00292 }
00293
00294 inline void setTrigTowerMap(const EcalTrigTowerConstituentsMap* _map){
00295 if(trigtowerMap) return;
00296 trigtowerMap = _map;
00297 checkTrigTowerMap();
00298 }
00299
00300 inline void checkElectronicsMap(){
00301 if(!electronicsMap) throw cms::Exception("InvalidCall") << "ElectronicsMapping not initialized" << std::endl;
00302 }
00303
00304 inline void checkTrigTowerMap(){
00305 if(!trigtowerMap) throw cms::Exception("InvalidCall") << "TrigTowerConstituentsMap not initialized" << std::endl;
00306 }
00307
00308 }
00309
00310 #endif