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