CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RPCSimSetUp.cc
Go to the documentation of this file.
22 
23 #include <cmath>
24 #include <math.h>
25 #include <fstream>
26 #include <sstream>
27 #include <iostream>
28 #include<cstring>
29 #include<string>
30 #include<vector>
31 #include<stdlib.h>
32 #include <utility>
33 #include <map>
34 
35 using namespace std;
36 
38 
39  _mapDetIdNoise.clear();
40  _mapDetIdEff.clear();
41  _bxmap.clear();
42  _clsMap.clear();
43 }
44 
45 void RPCSimSetUp::setRPCSetUp(const std::vector<RPCStripNoises::NoiseItem>& vnoise, const std::vector<float>& vcls){
46 
47  unsigned int counter = 1;
48  unsigned int row = 1;
49  std::vector<double> sum_clsize;
50 
51  for(unsigned int n = 0; n < vcls.size(); ++n){
52 
53  sum_clsize.push_back(vcls[n]);
54 
55  if(counter == row*20) {
56 
57  _clsMap[row] = sum_clsize;
58  row++;
59  sum_clsize.clear();
60  }
61  counter++;
62  }
63 
64  unsigned int n = 0;
65  uint32_t temp = 0;
66  std::vector<float> veff, vvnoise;
67  veff.clear();
68  vvnoise.clear();
69 
70  for(std::vector<RPCStripNoises::NoiseItem>::const_iterator it = vnoise.begin(); it != vnoise.end(); ++it){
71  if(n%96 == 0) {
72  if(n > 0 ){
73  _mapDetIdNoise[temp]= vvnoise;
74  _mapDetIdEff[temp] = veff;
75  _bxmap[RPCDetId(it->dpid)] = it->time;
76 
77  veff.clear();
78  vvnoise.clear();
79  vvnoise.push_back((it->noise));
80  veff.push_back((it->eff));
81  }
82  else if(n == 0 ){
83  vvnoise.push_back((it->noise));
84  veff.push_back((it->eff));
85  _bxmap[RPCDetId(it->dpid)] = it->time;
86  }
87  } else if (n == vnoise.size()-1 ){
88  temp = it->dpid;
89  vvnoise.push_back((it->noise));
90  veff.push_back((it->eff));
91  _mapDetIdNoise[temp]= vvnoise;
92  _mapDetIdEff[temp] = veff;
93  } else {
94  temp = it->dpid;
95  vvnoise.push_back((it->noise));
96  veff.push_back((it->eff));
97  }
98  n++;
99  }
100 }
101 
102 void RPCSimSetUp::setRPCSetUp(const std::vector<RPCStripNoises::NoiseItem>& vnoise, const std::vector<RPCClusterSize::ClusterSizeItem>& vClusterSize){
103 
104  std::vector<RPCClusterSize::ClusterSizeItem>::const_iterator itCls;
105  uint32_t detId;
106  int clsCounter(1);
107  std::vector<double> clsVect;
108 
109  for(itCls = vClusterSize.begin(); itCls != vClusterSize.end(); ++itCls){
110  clsVect.push_back(((double)(itCls->clusterSize)));
111  if((!(clsCounter%120)) && (clsCounter!=0)){
112  detId=itCls->dpid;
113  _mapDetClsMap[detId]=clsVect;
114  clsVect.clear();
115  clsCounter=0;
116  }
117  ++clsCounter;
118  }
119 
120  // the same loop (but till 100) to allow old format to be used
121  for(itCls = vClusterSize.begin(); itCls != vClusterSize.end(); ++itCls){
122  clsVect.push_back(((double)(itCls->clusterSize)));
123  if((!(clsCounter%100)) && (clsCounter!=0)){
124  detId=itCls->dpid;
125  _mapDetClsMapLegacy[detId]=clsVect;
126  clsVect.clear();
127  clsCounter=0;
128  }
129  ++clsCounter;
130  }
131 
132  unsigned int n = 0;
133  uint32_t temp = 0;
134  std::vector<float> veff, vvnoise;
135  veff.clear();
136  vvnoise.clear();
137 
138  for(std::vector<RPCStripNoises::NoiseItem>::const_iterator it = vnoise.begin(); it != vnoise.end(); ++it){
139  if(n%96 == 0) {
140  if(n > 0 ){
141  _mapDetIdNoise[temp]= vvnoise;
142  _mapDetIdEff[temp] = veff;
143  _bxmap[RPCDetId(it->dpid)] = it->time;
144 
145  veff.clear();
146  vvnoise.clear();
147  vvnoise.push_back((it->noise));
148  veff.push_back((it->eff));
149  }
150  else if(n == 0 ){
151  vvnoise.push_back((it->noise));
152  veff.push_back((it->eff));
153  _bxmap[RPCDetId(it->dpid)] = it->time;
154  }
155  } else if (n == vnoise.size()-1 ){
156  temp = it->dpid;
157  vvnoise.push_back((it->noise));
158  veff.push_back((it->eff));
159  _mapDetIdNoise[temp]= vvnoise;
160  _mapDetIdEff[temp] = veff;
161  } else {
162  temp = it->dpid;
163  vvnoise.push_back((it->noise));
164  veff.push_back((it->eff));
165  }
166  n++;
167  }
168 }
169 
170 const std::vector<float>& RPCSimSetUp::getNoise(uint32_t id)
171 {
172  map<uint32_t,std::vector<float> >::iterator iter = _mapDetIdNoise.find(id);
173  if(iter == _mapDetIdNoise.end()){
174  throw cms::Exception("DataCorrupt")
175  << "Exception comming from RPCSimSetUp - no noise information for DetId\t"<<id<< std::endl;
176  }
177  return iter->second;
178 }
179 
180 const std::vector<float>& RPCSimSetUp::getEff(uint32_t id)
181 {
182  map<uint32_t,std::vector<float> >::iterator iter = _mapDetIdEff.find(id);
183  if(iter == _mapDetIdEff.end()){
184  throw cms::Exception("DataCorrupt")
185  << "Exception comming from RPCSimSetUp - no efficiency information for DetId\t"<<id<< std::endl;
186  }
187  if((iter->second).size() != 96){
188  throw cms::Exception("DataCorrupt")
189  << "Exception comming from RPCSimSetUp - efficiency information in a wrong format for DetId\t"<<id<< std::endl;
190  }
191  return iter->second;
192 }
193 
194 float RPCSimSetUp::getTime(uint32_t id)
195 {
196  RPCDetId rpcid(id);
197  std::map<RPCDetId, float>::iterator iter = _bxmap.find(rpcid);
198  if(iter == _bxmap.end()){
199  throw cms::Exception("DataCorrupt")
200  << "Exception comming from RPCSimSetUp - no timing information for rpcid.rawId()\t"<<rpcid.rawId()<< std::endl;
201  }
202  return iter->second;
203 }
204 
205 const std::map< int, std::vector<double> >& RPCSimSetUp::getClsMap()
206 {
207  if(_clsMap.size()!=5){
208  throw cms::Exception("DataCorrupt")
209  << "Exception comming from RPCSimSetUp - cluster size - a wrong format "<< std::endl;
210  }
211  return _clsMap;
212 }
213 
214 
215 //const std::map<int, std::vector<double> >& RPCSimSetUp::getClsMap(uint32_t id)
216 const std::vector<double>& RPCSimSetUp::getCls(uint32_t id) //legacy member function
217 {
218 
219  map<uint32_t,std::vector<double> >::iterator iter = _mapDetClsMapLegacy.find(id);
220  if(iter == _mapDetClsMapLegacy.end()){
221  throw cms::Exception("DataCorrupt")
222  << "Exception comming from RPCSimSetUp - no cluster size information for DetId\t"<<id<< std::endl;
223  }
224  if((iter->second).size() != 100){
225  throw cms::Exception("DataCorrupt")
226  << "Exception comming from RPCSimSetUp - cluster size information in a wrong format for DetId\t"<<id<< std::endl;
227  }
228  return iter->second;
229 }
230 
231 const std::vector<double> & RPCSimSetUp::getAsymmetricClsDistribution(uint32_t id, uint32_t slice){
232 
233  map<uint32_t,std::vector<double> >::const_iterator iter = _mapDetClsMap.find(id);
234  if(iter == _mapDetClsMap.end()){
235  throw cms::Exception("DataCorrupt")
236  << "Exception comming from RPCSimSetUp - no cluster size information for DetId\t"<<id<< std::endl;
237  }
238  if((iter->second).size() != 120){
239  throw cms::Exception("DataCorrupt")
240  << "Exception comming from RPCSimSetUp - cluster size information in a wrong format for DetId\t"<<id<< std::endl;
241  }
242 // return iter->second;
243 
244 std::vector<double> dataForAsymmCls = iter->second;
245  if(slice>4){
246  throw cms::Exception("DataCorrupt")
247  << "Exception comming from RPCSimSetUp - slice variable not in the range"<< std::endl;
248  }
249 
250  _DetClsAsymmetric.clear();
251 
252 
253  vector<double> clsFewStripsDistribution;
254  vector<double> clsDistribution;
255  vector<double> clsAccumulativeDistribution;
256 
257  std::map< int, std::vector<double> > mapSliceVsDistribution;
258 
259  const int slices=5;
260  const int distributionFewStrips=24;
261 
262  double sliceVsFewStripsDistribution[slices][distributionFewStrips];
263 
264  for(int j = 0; j < distributionFewStrips; j++){
265  for(int i = 0; i < slices; i++){
266  sliceVsFewStripsDistribution[i][j]=dataForAsymmCls[j*slices+i];
267  }
268  }
269 
270 double control=0;
271 for(int j = 0 ; j < distributionFewStrips; j++){
272 control+=sliceVsFewStripsDistribution[0][j];
273 }
274 
275 double control1=0;
276  for(int j = 0; j < distributionFewStrips; j++){
277  for(int i = 0; i < slices; i++){
278  control1+=dataForAsymmCls[j*slices+i];
279  }
280  }
281 
282  int i = slice;
283  double sum=0;
284  int counter = 0 ;
285  for(int j = 0; j < distributionFewStrips; j++){
286  counter++;
287  sum+=sliceVsFewStripsDistribution[i][j];
288  if(counter%4==0){
289  _DetClsAsymmetric.push_back(sum);
290  }
291  }
292  return _DetClsAsymmetric;
293 }
294 
295 const std::vector<double> & RPCSimSetUp::getAsymmetryForCls(uint32_t id, uint32_t slice, uint32_t cls){
296 
297  map<uint32_t,std::vector<double> >::const_iterator iter = _mapDetClsMap.find(id);
298  if(iter == _mapDetClsMap.end()){
299  throw cms::Exception("DataCorrupt")
300  << "Exception comming from RPCSimSetUp - no cluster size information for DetId\t"<<id<< std::endl;
301  }
302  if((iter->second).size() != 120){
303  throw cms::Exception("DataCorrupt")
304  << "Exception comming from RPCSimSetUp - cluster size information in a wrong format for DetId\t"<<id<<'\t'<<(iter->second).size()<< std::endl;
305  }
306 
307 std::vector<double> dataForAsymmCls = iter->second;
308 
309 if(slice>4){
310  throw cms::Exception("DataCorrupt")
311  << "Exception comming from RPCSimSetUp - slice variable not in the range"<< std::endl;
312  }
313 
314  _DetAsymmetryForCls.clear();
315 
316  vector<double> clsFewStripsDistribution;
317  vector<double> clsDistribution;
318  vector<double> clsAccumulativeDistribution;
319 vector<double> clsDetAsymmetryForCls;
320  clsDetAsymmetryForCls.clear();
321 
322  std::map< int, std::vector<double> > mapSliceVsDistribution;
323 
324  const int slices=5;
325  const int distributionFewStrips=24;
326 
327  double sliceVsFewStripsDistribution[slices][distributionFewStrips];
328 
329  for(int j = 0; j < distributionFewStrips; j++){
330  for(int i = 0; i < slices; i++){
331  sliceVsFewStripsDistribution[i][j]=dataForAsymmCls[j*slices+i];
332  }
333  }
334 
335  int vector_lenght;
336  switch(cls){
337  case 1: case 3: case 5: vector_lenght =3; break;
338  case 2: case 4: vector_lenght =4; break;
339  case 6: default: vector_lenght = 1; break;
340  }
341 
342  float sum=0;
343  float value;
344  for(int i = 0; i < vector_lenght ; i ++){
345  value = sliceVsFewStripsDistribution[slice][(cls-1)*4+i];
346  clsDetAsymmetryForCls.push_back(value);
347  sum +=value;
348  // std::cout<<"value\t"<<value<<std::endl;
349  // std::cout<<"sum\t"<<sum<<std::endl;
350  }
351 
352  float accum=0;
353  for(int i = clsDetAsymmetryForCls.size()-1; i>-1; i--){
354  accum += clsDetAsymmetryForCls[i];
355  _DetAsymmetryForCls.push_back(accum/sum);
356  }
357 return _DetAsymmetryForCls;
358 }
359 
int i
Definition: DBlmapReader.cc:9
float getTime(uint32_t id)
Definition: RPCSimSetUp.cc:194
RPCSimSetUp(const edm::ParameterSet &ps)
Definition: RPCSimSetUp.cc:37
const std::vector< double > & getAsymmetricClsDistribution(uint32_t id, uint32_t slice)
Definition: RPCSimSetUp.cc:231
const std::vector< float > & getEff(uint32_t id)
Definition: RPCSimSetUp.cc:180
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
const std::vector< float > & getNoise(uint32_t id)
Definition: RPCSimSetUp.cc:170
virtual ~RPCSimSetUp()
Definition: RPCSimSetUp.cc:360
const std::vector< double > & getCls(uint32_t id)
Definition: RPCSimSetUp.cc:216
const std::map< int, std::vector< double > > & getClsMap()
Definition: RPCSimSetUp.cc:205
int j
Definition: DBlmapReader.cc:9
const std::vector< double > & getAsymmetryForCls(uint32_t id, uint32_t slice, uint32_t cls)
Definition: RPCSimSetUp.cc:295
static std::atomic< unsigned int > counter
tuple size
Write out results.
void setRPCSetUp(const std::vector< RPCStripNoises::NoiseItem > &vnoise, const std::vector< float > &vcls)
Definition: RPCSimSetUp.cc:45