Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:58:01

0001 #include "CalibCalorimetry/EcalTPGTools/interface/EcalTPGScale.h"
0002 
0003 #include "FWCore/Framework/interface/ESHandle.h"
0004 
0005 EcalTPGScale::Tokens::Tokens(edm::ConsumesCollector c)
0006     : physConstToken_(c.esConsumes<EcalTPGPhysicsConst, EcalTPGPhysicsConstRcd>()),
0007       lutGrpToken_(c.esConsumes<EcalTPGLutGroup, EcalTPGLutGroupRcd>()),
0008       lutMapToken_(c.esConsumes<EcalTPGLutIdMap, EcalTPGLutIdMapRcd>()) {}
0009 
0010 EcalTPGScale::EcalTPGScale(Tokens const& tokens, const edm::EventSetup& evtSetup)
0011     : phys_(evtSetup.getData(tokens.physConstToken_)),
0012       lutGrp_(evtSetup.getData(tokens.lutGrpToken_)),
0013       lut_(evtSetup.getData(tokens.lutMapToken_))
0014 
0015 {}
0016 
0017 double EcalTPGScale::getTPGInGeV(const EcalTriggerPrimitiveDigi& tpDigi) const {
0018   const EcalTrigTowerDetId& towerId = tpDigi.id();
0019   int ADC = tpDigi.compressedEt();
0020   return getTPGInGeV(ADC, towerId);
0021 }
0022 
0023 double EcalTPGScale::getTPGInGeV(unsigned int ADC, const EcalTrigTowerDetId& towerId) const {
0024   // 1. get lsb
0025 
0026   const EcalTPGPhysicsConstMap& physMap = phys_.getMap();
0027   uint32_t eb = DetId(DetId::Ecal, EcalBarrel).rawId();
0028   uint32_t ee = DetId(DetId::Ecal, EcalEndcap).rawId();
0029   EcalTPGPhysicsConstMapIterator it = physMap.end();
0030   if (towerId.subDet() == EcalBarrel)
0031     it = physMap.find(eb);
0032   else if (towerId.subDet() == EcalEndcap)
0033     it = physMap.find(ee);
0034   double lsb10bits = 0.;
0035   if (it != physMap.end()) {
0036     EcalTPGPhysicsConst::Item item = it->second;
0037     lsb10bits = item.EtSat / 1024.;
0038   }
0039 
0040   // 2. linearized TPG
0041   return lsb10bits * getLinearizedTPG(ADC, towerId);
0042 }
0043 
0044 unsigned int EcalTPGScale::getLinearizedTPG(unsigned int ADC, const EcalTrigTowerDetId& towerId) const {
0045   int tpg10bits = 0;
0046 
0047   const EcalTPGGroups::EcalTPGGroupsMap& lutGrpMap = lutGrp_.getMap();
0048   EcalTPGGroups::EcalTPGGroupsMapItr itgrp = lutGrpMap.find(towerId.rawId());
0049   uint32_t lutGrp = 999;
0050   if (itgrp != lutGrpMap.end())
0051     lutGrp = itgrp->second;
0052 
0053   const EcalTPGLutIdMap::EcalTPGLutMap& lutMap = lut_.getMap();
0054   EcalTPGLutIdMap::EcalTPGLutMapItr itLut = lutMap.find(lutGrp);
0055   if (itLut != lutMap.end()) {
0056     const unsigned int* lut = (itLut->second).getLut();
0057     for (unsigned int i = 0; i < 1024; i++)
0058       if (ADC == (0xff & lut[i])) {
0059         tpg10bits = i;
0060         break;
0061       }
0062   }
0063 
0064   return tpg10bits;
0065 }
0066 
0067 unsigned int EcalTPGScale::getTPGInADC(double energy, const EcalTrigTowerDetId& towerId) const {
0068   unsigned int tpgADC = 0;
0069 
0070   // 1. get lsb
0071 
0072   const EcalTPGPhysicsConstMap& physMap = phys_.getMap();
0073 
0074   uint32_t eb = DetId(DetId::Ecal, EcalBarrel).rawId();
0075   uint32_t ee = DetId(DetId::Ecal, EcalEndcap).rawId();
0076   EcalTPGPhysicsConstMapIterator it = physMap.end();
0077   if (towerId.subDet() == EcalBarrel)
0078     it = physMap.find(eb);
0079   else if (towerId.subDet() == EcalEndcap)
0080     it = physMap.find(ee);
0081   double lsb10bits = 0.;
0082   if (it != physMap.end()) {
0083     EcalTPGPhysicsConst::Item item = it->second;
0084     lsb10bits = item.EtSat / 1024.;
0085   }
0086 
0087   // 2. get compressed look-up table
0088 
0089   const EcalTPGGroups::EcalTPGGroupsMap& lutGrpMap = lutGrp_.getMap();
0090   EcalTPGGroups::EcalTPGGroupsMapItr itgrp = lutGrpMap.find(towerId);
0091   uint32_t lutGrp = 0;
0092   if (itgrp != lutGrpMap.end())
0093     lutGrp = itgrp->second;
0094 
0095   const EcalTPGLutIdMap::EcalTPGLutMap& lutMap = lut_.getMap();
0096   EcalTPGLutIdMap::EcalTPGLutMapItr itLut = lutMap.find(lutGrp);
0097   if (itLut != lutMap.end()) {
0098     const unsigned int* lut = (itLut->second).getLut();
0099     if (lsb10bits > 0) {
0100       int tpgADC10b = int(energy / lsb10bits + 0.5);
0101       if (tpgADC10b >= 0 && tpgADC10b < 1024)
0102         tpgADC = (0xff & lut[tpgADC10b]);
0103       if (tpgADC10b >= 1024)
0104         tpgADC = 0xff;
0105     }
0106   }
0107 
0108   return tpgADC;
0109 }