00001 #include "CalibCalorimetry/EcalTPGTools/interface/EcalTPGScale.h" 00002 00003 #include "FWCore/Framework/interface/ESHandle.h" 00004 00005 #include "CondFormats/EcalObjects/interface/EcalTPGLutIdMap.h" 00006 #include "CondFormats/EcalObjects/interface/EcalTPGLutGroup.h" 00007 #include "CondFormats/EcalObjects/interface/EcalTPGPhysicsConst.h" 00008 #include "CondFormats/DataRecord/interface/EcalTPGLutIdMapRcd.h" 00009 #include "CondFormats/DataRecord/interface/EcalTPGLutGroupRcd.h" 00010 #include "CondFormats/DataRecord/interface/EcalTPGPhysicsConstRcd.h" 00011 00012 00013 EcalTPGScale::EcalTPGScale() 00014 { } 00015 00016 EcalTPGScale::~EcalTPGScale() 00017 { } 00018 00019 void EcalTPGScale::setEventSetup(const edm::EventSetup & evtSetup) 00020 { 00021 setup_ = &evtSetup ; 00022 } 00023 00024 double EcalTPGScale::getTPGInGeV(const EcalTriggerPrimitiveDigi & tpDigi) 00025 { 00026 const EcalTrigTowerDetId & towerId = tpDigi.id() ; 00027 int ADC = tpDigi.compressedEt() ; 00028 return getTPGInGeV(ADC, towerId) ; 00029 } 00030 00031 double EcalTPGScale::getTPGInGeV(uint ADC, const EcalTrigTowerDetId & towerId) 00032 { 00033 // 1. get lsb 00034 edm::ESHandle<EcalTPGPhysicsConst> physHandle; 00035 setup_->get<EcalTPGPhysicsConstRcd>().get( physHandle ); 00036 const EcalTPGPhysicsConstMap & physMap = physHandle.product()->getMap() ; 00037 00038 uint32_t eb = DetId(DetId::Ecal,EcalBarrel).rawId() ; 00039 uint32_t ee = DetId(DetId::Ecal,EcalEndcap).rawId() ; 00040 EcalTPGPhysicsConstMapIterator it = physMap.end() ; 00041 if (towerId.subDet() == EcalBarrel) it = physMap.find(eb) ; 00042 else if (towerId.subDet() == EcalEndcap) it = physMap.find(ee) ; 00043 double lsb10bits = 0. ; 00044 if (it != physMap.end()) { 00045 EcalTPGPhysicsConst::Item item = it->second ; 00046 lsb10bits = item.EtSat/1024. ; 00047 } 00048 00049 // 2. linearized TPG 00050 return lsb10bits * getLinearizedTPG(ADC, towerId) ; 00051 00052 } 00053 00054 uint EcalTPGScale::getLinearizedTPG(uint ADC, const EcalTrigTowerDetId & towerId) 00055 { 00056 int tpg10bits = 0 ; 00057 00058 // Get compressed look-up table 00059 edm::ESHandle<EcalTPGLutGroup> lutGrpHandle; 00060 setup_->get<EcalTPGLutGroupRcd>().get( lutGrpHandle ); 00061 const EcalTPGGroups::EcalTPGGroupsMap & lutGrpMap = lutGrpHandle.product()->getMap() ; 00062 EcalTPGGroups::EcalTPGGroupsMapItr itgrp = lutGrpMap.find(towerId.rawId()) ; 00063 uint32_t lutGrp = 999 ; 00064 if (itgrp != lutGrpMap.end()) lutGrp = itgrp->second ; 00065 00066 edm::ESHandle<EcalTPGLutIdMap> lutMapHandle; 00067 setup_->get<EcalTPGLutIdMapRcd>().get( lutMapHandle ); 00068 const EcalTPGLutIdMap::EcalTPGLutMap & lutMap = lutMapHandle.product()->getMap() ; 00069 EcalTPGLutIdMap::EcalTPGLutMapItr itLut = lutMap.find(lutGrp) ; 00070 if (itLut != lutMap.end()) { 00071 const unsigned int * lut = (itLut->second).getLut() ; 00072 for (uint i=0 ; i<1024 ; i++) 00073 if (ADC == (0xff & lut[i])) { 00074 tpg10bits = i ; 00075 break ; 00076 } 00077 } 00078 00079 return tpg10bits ; 00080 } 00081 00082 uint EcalTPGScale::getTPGInADC(double energy, const EcalTrigTowerDetId & towerId) 00083 { 00084 uint tpgADC = 0 ; 00085 00086 // 1. get lsb 00087 edm::ESHandle<EcalTPGPhysicsConst> physHandle; 00088 setup_->get<EcalTPGPhysicsConstRcd>().get( physHandle ); 00089 const EcalTPGPhysicsConstMap & physMap = physHandle.product()->getMap() ; 00090 00091 uint32_t eb = DetId(DetId::Ecal,EcalBarrel).rawId() ; 00092 uint32_t ee = DetId(DetId::Ecal,EcalEndcap).rawId() ; 00093 EcalTPGPhysicsConstMapIterator it = physMap.end() ; 00094 if (towerId.subDet() == EcalBarrel) it = physMap.find(eb) ; 00095 else if (towerId.subDet() == EcalEndcap) it = physMap.find(ee) ; 00096 double lsb10bits = 0. ; 00097 if (it != physMap.end()) { 00098 EcalTPGPhysicsConst::Item item = it->second ; 00099 lsb10bits = item.EtSat/1024. ; 00100 } 00101 00102 // 2. get compressed look-up table 00103 edm::ESHandle<EcalTPGLutGroup> lutGrpHandle; 00104 setup_->get<EcalTPGLutGroupRcd>().get( lutGrpHandle ); 00105 const EcalTPGGroups::EcalTPGGroupsMap & lutGrpMap = lutGrpHandle.product()->getMap() ; 00106 EcalTPGGroups::EcalTPGGroupsMapItr itgrp = lutGrpMap.find(towerId) ; 00107 uint32_t lutGrp = 0 ; 00108 if (itgrp != lutGrpMap.end()) lutGrp = itgrp->second ; 00109 00110 edm::ESHandle<EcalTPGLutIdMap> lutMapHandle; 00111 setup_->get<EcalTPGLutIdMapRcd>().get( lutMapHandle ); 00112 const EcalTPGLutIdMap::EcalTPGLutMap & lutMap = lutMapHandle.product()->getMap() ; 00113 EcalTPGLutIdMap::EcalTPGLutMapItr itLut = lutMap.find(lutGrp) ; 00114 if (itLut != lutMap.end()) { 00115 const unsigned int * lut = (itLut->second).getLut() ; 00116 if (lsb10bits>0) { 00117 int tpgADC10b = int(energy/lsb10bits+0.5) ; 00118 if (tpgADC10b>=0 && tpgADC10b<1024) tpgADC = (0xff & lut[tpgADC10b]) ; 00119 if (tpgADC10b>=1024) tpgADC = 0xff ; 00120 } 00121 } 00122 00123 return tpgADC ; 00124 }