CMS 3D CMS Logo

RPCDBSimSetUp.cc
Go to the documentation of this file.
3 
4 #include <cmath>
5 #include <cmath>
6 #include <fstream>
7 #include <sstream>
8 #include <iostream>
9 #include <cstring>
10 #include <string>
11 #include <vector>
12 #include <cstdlib>
13 #include <utility>
14 #include <map>
15 
16 using namespace std;
17 
19  _mapDetIdNoise.clear();
20  _mapDetIdEff.clear();
21  _bxmap.clear();
22 
23  //------------------------ Noise Reading ----------------------------
24 
25  edm::FileInPath fp1 = ps.getParameter<edm::FileInPath>("noisemapfile");
26  std::ifstream _infile1(fp1.fullPath().c_str(), std::ios::in);
27 
28  std::vector<float> vnoise;
29 
30  int rpcdetid = 0;
32 
33  std::vector<std::string> words;
34 
35  while (getline(_infile1, buff, '\n')) {
36  words.clear();
37  vnoise.clear();
38 
39  stringstream ss;
40  std::string chname;
41  ss << buff;
42  ss >> chname >> rpcdetid;
43 
44  std::string::size_type pos = 0, prev_pos = 0;
45 
46  while ((pos = buff.find(" ", pos)) != string::npos) {
47  words.push_back(buff.substr(prev_pos, pos - prev_pos));
48  prev_pos = ++pos;
49  }
50  words.push_back(buff.substr(prev_pos, pos - prev_pos));
51 
52  for (unsigned int i = 2; i < words.size(); ++i) {
53  float value = atof(((words)[i]).c_str());
54  vnoise.push_back(value);
55  }
56 
57  _mapDetIdNoise.insert(make_pair(static_cast<uint32_t>(rpcdetid), vnoise));
58  }
59  _infile1.close();
60 
61  //------------------------ Eff Reading ----------------------------
62 
63  edm::FileInPath fp2 = ps.getParameter<edm::FileInPath>("effmapfile");
64  _infile2 = new ifstream(fp2.fullPath().c_str(), std::ios::in);
65 
66  std::vector<float> veff;
67  rpcdetid = 0;
68 
69  while (getline(*_infile2, buff, '\n')) {
70  words.clear();
71  veff.clear();
72 
73  stringstream ss;
74  std::string chname;
75  ss << buff;
76  ss >> chname >> rpcdetid;
77 
78  std::string::size_type pos = 0, prev_pos = 0;
79  while ((pos = buff.find(" ", pos)) != string::npos) {
80  words.push_back(buff.substr(prev_pos, pos - prev_pos));
81  prev_pos = ++pos;
82  }
83  words.push_back(buff.substr(prev_pos, pos - prev_pos));
84 
85  for (unsigned int i = 2; i < words.size(); ++i) {
86  float value = atof(((words)[i]).c_str());
87  veff.push_back(value);
88  }
89  _mapDetIdEff.insert(make_pair(static_cast<uint32_t>(rpcdetid), veff));
90  }
91  _infile2->close();
92 
93  //---------------------- Timing reading ------------------------------------
94 
95  edm::FileInPath fp3 = ps.getParameter<edm::FileInPath>("timingMap");
96  _infile3 = new ifstream(fp3.fullPath().c_str(), std::ios::in);
97 
98  uint32_t detUnit = 0;
99  float timing = 0.;
100  while (!_infile3->eof()) {
101  *_infile3 >> detUnit >> timing;
102  _bxmap[RPCDetId(detUnit)] = timing;
103  }
104  _infile3->close();
105 
106  //---------------------- Cluster size --------------------------------------
107 
108  edm::FileInPath fp4 = ps.getParameter<edm::FileInPath>("clsmapfile");
109  _infile4 = new ifstream(fp4.fullPath().c_str(), ios::in);
110 
111  string buffer;
112  double sum = 0;
113  unsigned int counter = 1;
114  unsigned int row = 1;
115  std::vector<double> sum_clsize;
116 
117  while (*_infile4 >> buffer) {
118  const char* buffer1 = buffer.c_str();
119  double dato = atof(buffer1);
120  sum += dato;
121  sum_clsize.push_back(sum);
122 
123  if (counter == row * 20) {
124  _clsMap[row] = sum_clsize;
125  row++;
126  sum = 0;
127  sum_clsize.clear();
128  }
129  counter++;
130  }
131  _infile4->close();
132 }
133 
134 std::vector<float> RPCDBSimSetUp::getNoise(uint32_t id) {
135  map<uint32_t, std::vector<float> >::iterator iter = _mapDetIdNoise.find(id);
136  return (iter->second);
137 }
138 
139 std::vector<float> RPCDBSimSetUp::getEff(uint32_t id) {
140  map<uint32_t, std::vector<float> >::iterator iter = _mapDetIdEff.find(id);
141  return iter->second;
142 }
143 
144 float RPCDBSimSetUp::getTime(uint32_t id) {
145  RPCDetId rpcid(id);
146  std::map<RPCDetId, float>::iterator iter = _bxmap.find(rpcid);
147  return iter->second;
148 }
149 
150 std::map<int, std::vector<double> > RPCDBSimSetUp::getClsMap() { return _clsMap; }
151 
153  delete _infile1;
154  delete _infile2;
155  delete _infile3;
156  delete _infile4;
157 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
std::vector< float > getNoise(uint32_t id)
uint16_t size_type
Definition: value.py:1
std::vector< float > getEff(uint32_t id)
float getTime(uint32_t id)
virtual ~RPCDBSimSetUp()
std::map< int, std::vector< double > > getClsMap()
const std::string & fullPath() const
Definition: FileInPath.cc:144
RPCDBSimSetUp(const edm::ParameterSet &ps)
buff
***.cc ################