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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
#include "CalibMuon/RPCCalibration/interface/RPCCalibSetUp.h"
#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/MuonDetId/interface/RPCDetId.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "Geometry/Records/interface/MuonGeometryRecord.h"
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
RPCCalibSetUp::RPCCalibSetUp(const edm::ParameterSet &ps) {
_mapDetIdNoise.clear();
_mapDetIdEff.clear();
_bxmap.clear();
_mapDetClsMap.clear();
//------------------------ Noise Reading ----------------------------
edm::FileInPath fp1 = ps.getParameter<edm::FileInPath>("noisemapfile");
std::ifstream _infile1(fp1.fullPath().c_str(), std::ios::in);
std::vector<float> vnoise;
int rpcdetid = 0;
std::string buff;
std::vector<std::string> words;
while (getline(_infile1, buff, '\n')) {
words.clear();
vnoise.clear();
stringstream ss;
std::string chname;
ss << buff;
ss >> chname >> rpcdetid;
std::string::size_type pos = 0, prev_pos = 0;
while ((pos = buff.find(" ", pos)) != string::npos) {
words.push_back(buff.substr(prev_pos, pos - prev_pos));
prev_pos = ++pos;
}
words.push_back(buff.substr(prev_pos, pos - prev_pos));
for (unsigned int i = 2; i < words.size(); ++i) {
float value = atof(((words)[i]).c_str());
vnoise.push_back(value);
}
_mapDetIdNoise.insert(make_pair(static_cast<uint32_t>(rpcdetid), vnoise));
}
_infile1.close();
//------------------------ Eff Reading ----------------------------
edm::FileInPath fp2 = ps.getParameter<edm::FileInPath>("effmapfile");
std::ifstream _infile2(fp2.fullPath().c_str(), std::ios::in);
std::vector<float> veff;
rpcdetid = 0;
while (getline(_infile2, buff, '\n')) {
words.clear();
veff.clear();
stringstream ss;
std::string chname;
ss << buff;
ss >> chname >> rpcdetid;
std::string::size_type pos = 0, prev_pos = 0;
while ((pos = buff.find(" ", pos)) != string::npos) {
words.push_back(buff.substr(prev_pos, pos - prev_pos));
prev_pos = ++pos;
}
words.push_back(buff.substr(prev_pos, pos - prev_pos));
for (unsigned int i = 2; i < words.size(); ++i) {
float value = atof(((words)[i]).c_str());
veff.push_back(value);
}
_mapDetIdEff.insert(make_pair(static_cast<uint32_t>(rpcdetid), veff));
}
_infile2.close();
//---------------------- Timing reading ------------------------------------
edm::FileInPath fp3 = ps.getParameter<edm::FileInPath>("timingMap");
std::ifstream _infile3(fp3.fullPath().c_str(), std::ios::in);
uint32_t detUnit = 0;
float timing = 0.;
while (!_infile3.eof()) {
_infile3 >> detUnit >> timing;
_bxmap[RPCDetId(detUnit)] = timing;
}
_infile3.close();
//---------------------- Cluster size --------------------------------------
edm::FileInPath fp4 = ps.getParameter<edm::FileInPath>("clsmapfile");
std::ifstream _infile4(fp4.fullPath().c_str(), ios::in);
string buffer;
double sum = 0;
unsigned int counter = 1;
unsigned int row = 1;
std::vector<double> sum_clsize;
while (_infile4 >> buffer) {
const char *buffer1 = buffer.c_str();
double dato = atof(buffer1);
sum += dato;
sum_clsize.push_back(sum);
if (counter == row * 20) {
_clsMap[row] = sum_clsize;
row++;
sum = 0;
sum_clsize.clear();
}
counter++;
}
_infile4.close();
//---------------------- Cluster size Chamber by Chamber -------------------
edm::FileInPath fp5 = ps.getParameter<edm::FileInPath>("clsidmapfile");
std::ifstream _infile5(fp5.fullPath().c_str(), ios::in);
std::vector<double> vClsDistrib;
rpcdetid = 0;
while (getline(_infile5, buff, '\n')) {
words.clear();
vClsDistrib.clear();
stringstream ss1;
ss1 << buff;
ss1 >> rpcdetid;
std::string::size_type pos = 0, prev_pos = 0;
while ((pos = buff.find(" ", pos)) != string::npos) {
words.push_back(buff.substr(prev_pos, pos - prev_pos));
prev_pos = ++pos;
}
words.push_back(buff.substr(prev_pos, pos - prev_pos));
float clusterSizeSumData(0.);
for (unsigned int i = 1; i < words.size(); ++i) {
float value = atof(((words)[i]).c_str());
clusterSizeSumData += value;
vClsDistrib.push_back(clusterSizeSumData);
if (!(i % 20)) {
clusterSizeSumData = 0.;
}
}
if (vClsDistrib.size() != 100) {
throw cms::Exception("DataCorrupt") << "Exception comming from RPCCalibSetUp - cluster size - a wrong "
"format "
<< std::endl;
}
_mapDetClsMap.insert(make_pair(static_cast<uint32_t>(rpcdetid), vClsDistrib));
std::cout << "_mapDetClsMap.size()\t" << _mapDetClsMap.size() << std::endl;
}
_infile5.close();
}
std::vector<float> RPCCalibSetUp::getNoise(uint32_t id) {
map<uint32_t, std::vector<float>>::iterator iter = _mapDetIdNoise.find(id);
if (iter == _mapDetIdNoise.end()) {
throw cms::Exception("DataCorrupt") << "Exception comming from RPCCalibSetUp - no noise information for "
"DetId\t"
<< id << std::endl;
}
return (iter->second);
}
std::vector<float> RPCCalibSetUp::getEff(uint32_t id) {
map<uint32_t, std::vector<float>>::iterator iter = _mapDetIdEff.find(id);
if (iter == _mapDetIdEff.end()) {
throw cms::Exception("DataCorrupt") << "Exception comming from RPCCalibSetUp - no efficiency information "
"for DetId\t"
<< id << std::endl;
}
if ((iter->second).size() != 96) {
throw cms::Exception("DataCorrupt") << "Exception comming from RPCCalibSetUp - efficiency information in a "
"wrong format for DetId\t"
<< id << std::endl;
}
return iter->second;
}
float RPCCalibSetUp::getTime(uint32_t id) {
RPCDetId rpcid(id);
std::map<RPCDetId, float>::iterator iter = _bxmap.find(rpcid);
if (iter == _bxmap.end()) {
throw cms::Exception("DataCorrupt") << "Exception comming from RPCCalibSetUp - no timing information for "
"rpcid.rawId()\t"
<< rpcid.rawId() << std::endl;
}
return iter->second;
}
std::map<int, std::vector<double>> RPCCalibSetUp::getClsMap() {
if (_clsMap.size() != 5) {
throw cms::Exception("DataCorrupt") << "Exception comming from RPCCalibSetUp - cluster size - a wrong "
"format "
<< std::endl;
}
return _clsMap;
}
std::vector<double> RPCCalibSetUp::getCls(uint32_t id) {
std::map<uint32_t, std::vector<double>>::iterator iter = _mapDetClsMap.find(id);
if (iter == _mapDetClsMap.end()) {
throw cms::Exception("DataCorrupt") << "Exception comming from RPCCalibSetUp - no cluster size information "
"for DetId\t"
<< id << std::endl;
}
if ((iter->second).size() != 100) {
throw cms::Exception("DataCorrupt") << "Exception comming from RPCCalibSetUp - cluster size information in "
"a wrong format for DetId\t"
<< id << std::endl;
}
return iter->second;
}
RPCCalibSetUp::~RPCCalibSetUp() {}
|