CMS 3D CMS Logo

RPCCalibSetUp.cc
Go to the documentation of this file.
11 
12 #include <cmath>
13 #include <cstdlib>
14 #include <cstring>
15 #include <fstream>
16 #include <iostream>
17 #include <map>
18 #include <sstream>
19 #include <string>
20 #include <utility>
21 #include <vector>
22 
23 using namespace std;
24 
26  _mapDetIdNoise.clear();
27  _mapDetIdEff.clear();
28  _bxmap.clear();
29  _mapDetClsMap.clear();
30 
31  //------------------------ Noise Reading ----------------------------
32 
33  edm::FileInPath fp1 = ps.getParameter<edm::FileInPath>("noisemapfile");
34  std::ifstream _infile1(fp1.fullPath().c_str(), std::ios::in);
35 
36  std::vector<float> vnoise;
37 
38  int rpcdetid = 0;
39  std::string buff;
40 
41  std::vector<std::string> words;
42 
43  int count = 0;
44  while (getline(_infile1, buff, '\n')) {
45  words.clear();
46  vnoise.clear();
47 
48  stringstream ss;
49  std::string chname;
50  ss << buff;
51  ss >> chname >> rpcdetid;
52 
53  std::string::size_type pos = 0, prev_pos = 0;
54 
55  while ((pos = buff.find(" ", pos)) != string::npos) {
56  words.push_back(buff.substr(prev_pos, pos - prev_pos));
57  prev_pos = ++pos;
58  }
59  words.push_back(buff.substr(prev_pos, pos - prev_pos));
60 
61  for (unsigned int i = 2; i < words.size(); ++i) {
62  float value = atof(((words)[i]).c_str());
63  vnoise.push_back(value);
64  }
65 
66  _mapDetIdNoise.insert(make_pair(static_cast<uint32_t>(rpcdetid), vnoise));
67 
68  count++;
69  }
70  _infile1.close();
71 
72  //------------------------ Eff Reading ----------------------------
73 
74  edm::FileInPath fp2 = ps.getParameter<edm::FileInPath>("effmapfile");
75  std::ifstream _infile2(fp2.fullPath().c_str(), std::ios::in);
76 
77  std::vector<float> veff;
78  rpcdetid = 0;
79 
80  while (getline(_infile2, buff, '\n')) {
81  words.clear();
82  veff.clear();
83 
84  stringstream ss;
85  std::string chname;
86  ss << buff;
87  ss >> chname >> rpcdetid;
88 
89  std::string::size_type pos = 0, prev_pos = 0;
90  while ((pos = buff.find(" ", pos)) != string::npos) {
91  words.push_back(buff.substr(prev_pos, pos - prev_pos));
92  prev_pos = ++pos;
93  }
94  words.push_back(buff.substr(prev_pos, pos - prev_pos));
95 
96  for (unsigned int i = 2; i < words.size(); ++i) {
97  float value = atof(((words)[i]).c_str());
98  veff.push_back(value);
99  }
100  _mapDetIdEff.insert(make_pair(static_cast<uint32_t>(rpcdetid), veff));
101  }
102  _infile2.close();
103 
104  //---------------------- Timing reading ------------------------------------
105 
106  edm::FileInPath fp3 = ps.getParameter<edm::FileInPath>("timingMap");
107  std::ifstream _infile3(fp3.fullPath().c_str(), std::ios::in);
108 
109  uint32_t detUnit = 0;
110  float timing = 0.;
111  while (!_infile3.eof()) {
112  _infile3 >> detUnit >> timing;
113  _bxmap[RPCDetId(detUnit)] = timing;
114  }
115  _infile3.close();
116 
117  //---------------------- Cluster size --------------------------------------
118 
119  edm::FileInPath fp4 = ps.getParameter<edm::FileInPath>("clsmapfile");
120  std::ifstream _infile4(fp4.fullPath().c_str(), ios::in);
121 
122  string buffer;
123  double sum = 0;
124  unsigned int counter = 1;
125  unsigned int row = 1;
126  std::vector<double> sum_clsize;
127 
128  while (_infile4 >> buffer) {
129  const char *buffer1 = buffer.c_str();
130  double dato = atof(buffer1);
131  sum += dato;
132  sum_clsize.push_back(sum);
133 
134  if (counter == row * 20) {
135  _clsMap[row] = sum_clsize;
136  row++;
137  sum = 0;
138  sum_clsize.clear();
139  }
140  counter++;
141  }
142  _infile4.close();
143 
144  //---------------------- Cluster size Chamber by Chamber -------------------
145 
146  edm::FileInPath fp5 = ps.getParameter<edm::FileInPath>("clsidmapfile");
147  std::ifstream _infile5(fp5.fullPath().c_str(), ios::in);
148 
149  std::vector<double> vClsDistrib;
150  rpcdetid = 0;
151 
152  while (getline(_infile5, buff, '\n')) {
153  words.clear();
154  vClsDistrib.clear();
155 
156  stringstream ss1;
157  ss1 << buff;
158  ss1 >> rpcdetid;
159 
160  std::string::size_type pos = 0, prev_pos = 0;
161  while ((pos = buff.find(" ", pos)) != string::npos) {
162  words.push_back(buff.substr(prev_pos, pos - prev_pos));
163  prev_pos = ++pos;
164  }
165  words.push_back(buff.substr(prev_pos, pos - prev_pos));
166 
167  float clusterSizeSumData(0.);
168 
169  for (unsigned int i = 1; i < words.size(); ++i) {
170  float value = atof(((words)[i]).c_str());
171 
172  clusterSizeSumData += value;
173  vClsDistrib.push_back(clusterSizeSumData);
174  if (!(i % 20)) {
175  clusterSizeSumData = 0.;
176  }
177  }
178  if (vClsDistrib.size() != 100) {
179  throw cms::Exception("DataCorrupt") << "Exception comming from RPCCalibSetUp - cluster size - a wrong "
180  "format "
181  << std::endl;
182  }
183  _mapDetClsMap.insert(make_pair(static_cast<uint32_t>(rpcdetid), vClsDistrib));
184  std::cout << "_mapDetClsMap.size()\t" << _mapDetClsMap.size() << std::endl;
185  }
186 
187  _infile5.close();
188 }
189 
190 std::vector<float> RPCCalibSetUp::getNoise(uint32_t id) {
191  map<uint32_t, std::vector<float>>::iterator iter = _mapDetIdNoise.find(id);
192  if (iter == _mapDetIdNoise.end()) {
193  throw cms::Exception("DataCorrupt") << "Exception comming from RPCCalibSetUp - no noise information for "
194  "DetId\t"
195  << id << std::endl;
196  }
197  return (iter->second);
198 }
199 
200 std::vector<float> RPCCalibSetUp::getEff(uint32_t id) {
201  map<uint32_t, std::vector<float>>::iterator iter = _mapDetIdEff.find(id);
202  if (iter == _mapDetIdEff.end()) {
203  throw cms::Exception("DataCorrupt") << "Exception comming from RPCCalibSetUp - no efficiency information "
204  "for DetId\t"
205  << id << std::endl;
206  }
207  if ((iter->second).size() != 96) {
208  throw cms::Exception("DataCorrupt") << "Exception comming from RPCCalibSetUp - efficiency information in a "
209  "wrong format for DetId\t"
210  << id << std::endl;
211  }
212  return iter->second;
213 }
214 
215 float RPCCalibSetUp::getTime(uint32_t id) {
216  RPCDetId rpcid(id);
217 
218  std::map<RPCDetId, float>::iterator iter = _bxmap.find(rpcid);
219  if (iter == _bxmap.end()) {
220  throw cms::Exception("DataCorrupt") << "Exception comming from RPCCalibSetUp - no timing information for "
221  "rpcid.rawId()\t"
222  << rpcid.rawId() << std::endl;
223  }
224  return iter->second;
225 }
226 
227 std::map<int, std::vector<double>> RPCCalibSetUp::getClsMap() {
228  if (_clsMap.size() != 5) {
229  throw cms::Exception("DataCorrupt") << "Exception comming from RPCCalibSetUp - cluster size - a wrong "
230  "format "
231  << std::endl;
232  }
233  return _clsMap;
234 }
235 
236 std::vector<double> RPCCalibSetUp::getCls(uint32_t id) {
237  std::map<uint32_t, std::vector<double>>::iterator iter = _mapDetClsMap.find(id);
238  if (iter == _mapDetClsMap.end()) {
239  throw cms::Exception("DataCorrupt") << "Exception comming from RPCCalibSetUp - no cluster size information "
240  "for DetId\t"
241  << id << std::endl;
242  }
243  if ((iter->second).size() != 100) {
244  throw cms::Exception("DataCorrupt") << "Exception comming from RPCCalibSetUp - cluster size information in "
245  "a wrong format for DetId\t"
246  << id << std::endl;
247  }
248  return iter->second;
249 }
250 
counter
Definition: counter.py:1
Handle.h
mps_fire.i
i
Definition: mps_fire.py:428
EDProducer.h
ESHandle.h
RPCCalibSetUp::~RPCCalibSetUp
virtual ~RPCCalibSetUp()
Definition: RPCCalibSetUp.cc:251
RPCDetId
Definition: RPCDetId.h:16
gather_cfg.cout
cout
Definition: gather_cfg.py:144
pos
Definition: PixelAliasList.h:18
RPCCalibSetUp::getNoise
std::vector< float > getNoise(uint32_t id)
Definition: RPCCalibSetUp.cc:190
edmScanValgrind.buffer
buffer
Definition: edmScanValgrind.py:171
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
edm::FileInPath
Definition: FileInPath.h:64
trigger::size_type
uint16_t size_type
Definition: TriggerTypeDefs.h:18
Service.h
submitPVResolutionJobs.count
count
Definition: submitPVResolutionJobs.py:352
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
RPCDetId.h
edm::ParameterSet
Definition: ParameterSet.h:47
RPCCalibSetUp::getTime
float getTime(uint32_t id)
Definition: RPCCalibSetUp.cc:215
Event.h
recoMuon::in
Definition: RecoMuonEnumerators.h:6
value
Definition: value.py:1
RPCCalibSetUp.h
ecalMatacq_cfi.timing
timing
Definition: ecalMatacq_cfi.py:26
std
Definition: JetResolutionObject.h:76
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
relativeConstraints.value
value
Definition: relativeConstraints.py:53
Exception
Definition: hltDiff.cc:246
EventSetup.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
ParameterSet.h
MuonGeometryRecord.h
RPCCalibSetUp::getEff
std::vector< float > getEff(uint32_t id)
Definition: RPCCalibSetUp.cc:200
RPCCalibSetUp::RPCCalibSetUp
RPCCalibSetUp(const edm::ParameterSet &ps)
Definition: RPCCalibSetUp.cc:25
edm::FileInPath::fullPath
std::string fullPath() const
Definition: FileInPath.cc:163
RPCCalibSetUp::getCls
std::vector< double > getCls(uint32_t id)
Definition: RPCCalibSetUp.cc:236
RPCCalibSetUp::getClsMap
std::map< int, std::vector< double > > getClsMap()
Definition: RPCCalibSetUp.cc:227