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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
#include "CondTools/Hcal/interface/HcalPedestalWidthsCheck.h"
HcalPedestalWidthsCheck::HcalPedestalWidthsCheck(edm::ParameterSet const& ps) {
outfile = ps.getUntrackedParameter<std::string>("outFile", "null");
dumprefs = ps.getUntrackedParameter<std::string>("dumpRefWidthsTo", "null");
dumpupdate = ps.getUntrackedParameter<std::string>("dumpUpdateWidthsTo", "null");
checkemapflag = ps.getUntrackedParameter<bool>("checkEmap", false);
validateflag = ps.getUntrackedParameter<bool>("validateWidths", false);
epsilon = ps.getUntrackedParameter<double>("deltaW", 0);
m_tok1 = esConsumes<HcalPedestalWidths, HcalPedestalWidthsRcd>(edm::ESInputTag("", "update"));
m_tok2 = esConsumes<HcalPedestalWidths, HcalPedestalWidthsRcd>(edm::ESInputTag("", "reference"));
m_tokmap = esConsumes<HcalElectronicsMap, HcalElectronicsMapRcd>(edm::ESInputTag("", "reference"));
}
HcalPedestalWidthsCheck::~HcalPedestalWidthsCheck() {}
void HcalPedestalWidthsCheck::analyze(const edm::Event& ev, const edm::EventSetup& es) {
using namespace edm::eventsetup;
// get fake pedestals from file ("new pedestals")
const HcalPedestalWidths* myNewPeds = &es.getData(m_tok1);
// get DB pedestals from Frontier/OrcoX ("reference")
const HcalPedestalWidths* myRefPeds = &es.getData(m_tok2);
// get e-map from reference
const HcalElectronicsMap* myRefEMap = &es.getData(m_tokmap);
// dump pedestals:
if (dumpupdate != "null") {
std::ofstream outStream(dumpupdate.c_str());
std::cout << "--- Dumping PedestalWidths - update ---" << std::endl;
HcalDbASCIIIO::dumpObject(outStream, (*myNewPeds));
}
if (dumprefs != "null") {
std::ofstream outStream2(dumprefs.c_str());
std::cout << "--- Dumping PedestalWidths - reference ---" << std::endl;
HcalDbASCIIIO::dumpObject(outStream2, (*myRefPeds));
}
// first get the list of all channels from the update
std::vector<DetId> listNewChan = myNewPeds->getAllChannels();
// go through list of valid channels from reference, look up if pedestals exist for update
// push back into new vector the corresponding updated pedestals,
// or if it doesn't exist, the reference
HcalPedestalWidths* resultPeds = new HcalPedestalWidths(myRefPeds->topo(), myRefPeds->isADC());
std::vector<DetId> listRefChan = myRefPeds->getAllChannels();
std::vector<DetId>::iterator cell;
if (validateflag) {
for (std::vector<DetId>::iterator it = listRefChan.begin(); it != listRefChan.end(); it++) {
DetId mydetid = *it;
cell = std::find(listNewChan.begin(), listNewChan.end(), mydetid);
if (cell == listNewChan.end()) // not present in new list, take old pedestals
{
throw cms::Exception("DataDoesNotMatch") << "Value not found in reference" << std::endl;
} else // present in new list, take new pedestals
{
const HcalPedestalWidth* first = myNewPeds->getValues(mydetid);
const HcalPedestalWidth* second = myRefPeds->getValues(mydetid);
const float* newwidth = first->getValues();
const float* oldwidth = second->getValues();
if ((*newwidth != *oldwidth) || (*(newwidth + 1) != *(oldwidth + 1)) || (*(newwidth + 2) != *(oldwidth + 2)) ||
(*(newwidth + 3) != *(oldwidth + 3)) || (*(newwidth + 4) != *(oldwidth + 4)) ||
(*(newwidth + 5) != *(oldwidth + 5)) || (*(newwidth + 6) != *(oldwidth + 6)) ||
(*(newwidth + 7) != *(oldwidth + 7)) || (*(newwidth + 8) != *(oldwidth + 8)) ||
(*(newwidth + 9) != *(oldwidth + 9))) {
throw cms::Exception("DataDoesNotMatch") << "Values are not identical" << std::endl;
}
listNewChan.erase(cell); // fix 25.02.08
}
}
std::cout << "These are identical" << std::endl;
}
if (epsilon != 0) {
for (std::vector<DetId>::iterator it = listRefChan.begin(); it != listRefChan.end(); it++) {
DetId mydetid = *it;
cell = std::find(listNewChan.begin(), listNewChan.end(), mydetid);
if (cell == listNewChan.end()) // not present in new list, take old pedestals
{
throw cms::Exception("DataDoesNotMatch") << "Value not found in reference" << std::endl;
} else // present in new list, take new pedestals
{
const HcalPedestalWidth* first = myNewPeds->getValues(mydetid);
const HcalPedestalWidth* second = myRefPeds->getValues(mydetid);
const float* newwidth = first->getValues();
const float* oldwidth = second->getValues();
if (fabs(*newwidth - *oldwidth) > epsilon || fabs(*(newwidth + 1) - *(oldwidth + 1)) > epsilon ||
fabs(*(newwidth + 2) - *(oldwidth + 2)) > epsilon || fabs(*(newwidth + 3) - *(oldwidth + 3)) > epsilon ||
fabs(*(newwidth + 4) - *(oldwidth + 4)) > epsilon || fabs(*(newwidth + 5) - *(oldwidth + 5)) > epsilon ||
fabs(*(newwidth + 6) - *(oldwidth + 6)) > epsilon || fabs(*(newwidth + 7) - *(oldwidth + 7)) > epsilon ||
fabs(*(newwidth + 8) - *(oldwidth + 8)) > epsilon || fabs(*(newwidth + 9) - *(oldwidth + 9)) > epsilon) {
throw cms::Exception("DataDoesNotMatch") << "Values differ by more than deltaW" << std::endl;
}
listNewChan.erase(cell); // fix 25.02.08
}
}
std::cout << "These are identical" << std::endl;
}
if (outfile != "null") {
for (std::vector<DetId>::iterator it = listRefChan.begin(); it != listRefChan.end(); it++) {
DetId mydetid = *it;
cell = std::find(listNewChan.begin(), listNewChan.end(), mydetid);
if (cell == listNewChan.end()) // not present in new list, take old pedestals
{
const HcalPedestalWidth* mywidth = myRefPeds->getValues(mydetid);
std::cout << "o";
resultPeds->addValues(*mywidth);
} else // present in new list, take new pedestals
{
const HcalPedestalWidth* mywidth = myNewPeds->getValues(mydetid);
std::cout << "n";
resultPeds->addValues(*mywidth);
listNewChan.erase(cell); // fix 25.02.08
}
}
for (std::vector<DetId>::iterator it = listNewChan.begin(); it != listNewChan.end(); it++) // fix 25.02.08
{
DetId mydetid = *it;
const HcalPedestalWidth* mywidth = myNewPeds->getValues(mydetid);
std::cout << "N";
resultPeds->addValues(*mywidth);
}
// dump the resulting list of pedestals into a file
std::ofstream outStream3(outfile.c_str());
std::cout << "--- Dumping PedestalWidths - the combined ones ---" << std::endl;
HcalDbASCIIIO::dumpObject(outStream3, (*resultPeds));
}
std::cout << std::endl;
if (checkemapflag) {
std::vector<DetId> listResult = resultPeds->getAllChannels();
// get the e-map list of channels
std::vector<HcalGenericDetId> listEMap = myRefEMap->allPrecisionId();
// look up if emap channels are all present in pedestals, if not then cerr
for (std::vector<HcalGenericDetId>::const_iterator it = listEMap.begin(); it != listEMap.end(); it++) {
DetId mydetid = DetId(it->rawId());
if (std::find(listResult.begin(), listResult.end(), mydetid) == listResult.end()) {
std::cout << "Conditions not found for DetId = " << HcalGenericDetId(it->rawId()) << std::endl;
}
}
}
}
//vecDetId HcalPedestalWidthsCheck::getMissingDetIds(vector<HcalPedestalWidths> & myPedestalWidths)
//{
// HcalGeometry myHcalGeometry;
// // get the valid detid from the various subdetectors
// vecDetId validHB = myHcalGeometry.getValidDetIds(Hcal,HcalBarrel); // check these numbers
// vecDetId validHE = myHcalGeometry.getValidDetIds(Hcal,HcalEndcap);
// vecDetId validHF = myHcalGeometry.getValidDetIds(Hcal,HcalForward);
// vecDetId validHO = myHcalGeometry.getValidDetIds(Hcal,HcalOuter);
// vecDetId validZDC = myHcalGeometry.getValidDetIds(Calo,2);
//
// // check if everything is there in pedestals
//
//
//}
DEFINE_FWK_MODULE(HcalPedestalWidthsCheck);
|