1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
#include "CalibCalorimetry/EcalTPGTools/interface/EcalTPGScale.h"
#include "FWCore/Framework/interface/ESHandle.h"
EcalTPGScale::Tokens::Tokens(edm::ConsumesCollector c)
: physConstToken_(c.esConsumes<EcalTPGPhysicsConst, EcalTPGPhysicsConstRcd>()),
lutGrpToken_(c.esConsumes<EcalTPGLutGroup, EcalTPGLutGroupRcd>()),
lutMapToken_(c.esConsumes<EcalTPGLutIdMap, EcalTPGLutIdMapRcd>()) {}
EcalTPGScale::EcalTPGScale(Tokens const& tokens, const edm::EventSetup& evtSetup)
: phys_(evtSetup.getData(tokens.physConstToken_)),
lutGrp_(evtSetup.getData(tokens.lutGrpToken_)),
lut_(evtSetup.getData(tokens.lutMapToken_))
{}
double EcalTPGScale::getTPGInGeV(const EcalTriggerPrimitiveDigi& tpDigi) const {
const EcalTrigTowerDetId& towerId = tpDigi.id();
int ADC = tpDigi.compressedEt();
return getTPGInGeV(ADC, towerId);
}
double EcalTPGScale::getTPGInGeV(unsigned int ADC, const EcalTrigTowerDetId& towerId) const {
// 1. get lsb
const EcalTPGPhysicsConstMap& physMap = phys_.getMap();
uint32_t eb = DetId(DetId::Ecal, EcalBarrel).rawId();
uint32_t ee = DetId(DetId::Ecal, EcalEndcap).rawId();
EcalTPGPhysicsConstMapIterator it = physMap.end();
if (towerId.subDet() == EcalBarrel)
it = physMap.find(eb);
else if (towerId.subDet() == EcalEndcap)
it = physMap.find(ee);
double lsb10bits = 0.;
if (it != physMap.end()) {
EcalTPGPhysicsConst::Item item = it->second;
lsb10bits = item.EtSat / 1024.;
}
// 2. linearized TPG
return lsb10bits * getLinearizedTPG(ADC, towerId);
}
unsigned int EcalTPGScale::getLinearizedTPG(unsigned int ADC, const EcalTrigTowerDetId& towerId) const {
int tpg10bits = 0;
const EcalTPGGroups::EcalTPGGroupsMap& lutGrpMap = lutGrp_.getMap();
EcalTPGGroups::EcalTPGGroupsMapItr itgrp = lutGrpMap.find(towerId.rawId());
uint32_t lutGrp = 999;
if (itgrp != lutGrpMap.end())
lutGrp = itgrp->second;
const EcalTPGLutIdMap::EcalTPGLutMap& lutMap = lut_.getMap();
EcalTPGLutIdMap::EcalTPGLutMapItr itLut = lutMap.find(lutGrp);
if (itLut != lutMap.end()) {
const unsigned int* lut = (itLut->second).getLut();
for (unsigned int i = 0; i < 1024; i++)
if (ADC == (0xff & lut[i])) {
tpg10bits = i;
break;
}
}
return tpg10bits;
}
unsigned int EcalTPGScale::getTPGInADC(double energy, const EcalTrigTowerDetId& towerId) const {
unsigned int tpgADC = 0;
// 1. get lsb
const EcalTPGPhysicsConstMap& physMap = phys_.getMap();
uint32_t eb = DetId(DetId::Ecal, EcalBarrel).rawId();
uint32_t ee = DetId(DetId::Ecal, EcalEndcap).rawId();
EcalTPGPhysicsConstMapIterator it = physMap.end();
if (towerId.subDet() == EcalBarrel)
it = physMap.find(eb);
else if (towerId.subDet() == EcalEndcap)
it = physMap.find(ee);
double lsb10bits = 0.;
if (it != physMap.end()) {
EcalTPGPhysicsConst::Item item = it->second;
lsb10bits = item.EtSat / 1024.;
}
// 2. get compressed look-up table
const EcalTPGGroups::EcalTPGGroupsMap& lutGrpMap = lutGrp_.getMap();
EcalTPGGroups::EcalTPGGroupsMapItr itgrp = lutGrpMap.find(towerId);
uint32_t lutGrp = 0;
if (itgrp != lutGrpMap.end())
lutGrp = itgrp->second;
const EcalTPGLutIdMap::EcalTPGLutMap& lutMap = lut_.getMap();
EcalTPGLutIdMap::EcalTPGLutMapItr itLut = lutMap.find(lutGrp);
if (itLut != lutMap.end()) {
const unsigned int* lut = (itLut->second).getLut();
if (lsb10bits > 0) {
int tpgADC10b = int(energy / lsb10bits + 0.5);
if (tpgADC10b >= 0 && tpgADC10b < 1024)
tpgADC = (0xff & lut[tpgADC10b]);
if (tpgADC10b >= 1024)
tpgADC = 0xff;
}
}
return tpgADC;
}
|