CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CSCNoiseMatrixConditions.cc
Go to the documentation of this file.
1 #include <fstream>
2 
4 
6 
7  int old_chamber_id,old_strip,new_chamber_id,new_strip;
8  float old_elm33,old_elm34, old_elm44, old_elm35, old_elm45, old_elm55;
9  float old_elm46, old_elm56, old_elm66, old_elm57, old_elm67, old_elm77;
10  std::vector<int> old_cham_id;
11  std::vector<int> old_strips;
12  std::vector<float> old_elem33;
13  std::vector<float> old_elem34;
14  std::vector<float> old_elem44;
15  std::vector<float> old_elem45;
16  std::vector<float> old_elem35;
17  std::vector<float> old_elem55;
18  std::vector<float> old_elem46;
19  std::vector<float> old_elem56;
20  std::vector<float> old_elem66;
21  std::vector<float> old_elem57;
22  std::vector<float> old_elem67;
23  std::vector<float> old_elem77;
24 
25 
26  float new_elm33,new_elm34, new_elm44, new_elm35, new_elm45, new_elm55;
27  float new_elm46, new_elm56, new_elm66, new_elm57, new_elm67, new_elm77;
28  std::vector<int> new_cham_id;
29  std::vector<int> new_strips;
30  std::vector<float> new_elem33;
31  std::vector<float> new_elem34;
32  std::vector<float> new_elem44;
33  std::vector<float> new_elem45;
34  std::vector<float> new_elem35;
35  std::vector<float> new_elem55;
36  std::vector<float> new_elem46;
37  std::vector<float> new_elem56;
38  std::vector<float> new_elem66;
39  std::vector<float> new_elem57;
40  std::vector<float> new_elem67;
41  std::vector<float> new_elem77;
42 
43  const CSCDetId& detId = CSCDetId();
44  CSCNoiseMatrix * cnmatrix = new CSCNoiseMatrix();
45 
46  int max_istrip,id_layer,max_ring,max_cham;
47  unsigned int old_nrlines=0;
48  unsigned int new_nrlines=0;
49 
50  std::ifstream olddata;
51  olddata.open("old_matrix.dat",std::ios::in);
52  if(!olddata) {
53  std::cerr <<"Error: old_matrix.dat -> no such file!"<< std::endl;
54  exit(1);
55  }
56 
57  while (!olddata.eof() ) {
58  olddata >> old_chamber_id >> old_strip >> old_elm33 >> old_elm34 >> old_elm44 >> old_elm35 >> old_elm45 >> old_elm55 >> old_elm46 >> old_elm56 >> old_elm66 >> old_elm57 >> old_elm67 >> old_elm77;
59  old_cham_id.push_back(old_chamber_id);
60  old_strips.push_back(old_strip);
61  old_elem33.push_back(old_elm33);
62  old_elem34.push_back(old_elm34);
63  old_elem44.push_back(old_elm44);
64  old_elem35.push_back(old_elm35);
65  old_elem45.push_back(old_elm45);
66  old_elem55.push_back(old_elm55);
67  old_elem46.push_back(old_elm46);
68  old_elem56.push_back(old_elm56);
69  old_elem66.push_back(old_elm66);
70  old_elem57.push_back(old_elm57);
71  old_elem67.push_back(old_elm67);
72  old_elem77.push_back(old_elm77);
73 
74  old_nrlines++;
75  }
76  olddata.close();
77 
78  std::ifstream newdata;
79  newdata.open("new_matrix.txt",std::ios::in);
80  if(!newdata) {
81  std::cerr <<"Error: new_matrix.txt -> no such file!"<< std::endl;
82  exit(1);
83  }
84 
85  while (!newdata.eof() ) {
86  newdata >> new_chamber_id >> new_strip >> new_elm33 >> new_elm34 >> new_elm44 >> new_elm35 >> new_elm45 >> new_elm55 >> new_elm46 >> new_elm56 >> new_elm66 >> new_elm57 >> new_elm67 >> new_elm77 ;
87  new_cham_id.push_back(new_chamber_id);
88  new_strips.push_back(new_strip);
89  new_elem33.push_back(new_elm33);
90  new_elem34.push_back(new_elm34);
91  new_elem44.push_back(new_elm44);
92  new_elem35.push_back(new_elm35);
93  new_elem45.push_back(new_elm45);
94  new_elem55.push_back(new_elm55);
95  new_elem46.push_back(new_elm46);
96  new_elem56.push_back(new_elm56);
97  new_elem66.push_back(new_elm66);
98  new_elem57.push_back(new_elm57);
99  new_elem67.push_back(new_elm67);
100  new_elem77.push_back(new_elm77);
101  new_nrlines++;
102  }
103  newdata.close();
104 
105 
106 
107  //endcap=1 to 2,station=1 to 4, ring=1 to 4,chamber=1 to 36,layer=1 to 6
108 
109  for(int iendcap=detId.minEndcapId(); iendcap<=detId.maxEndcapId(); iendcap++){
110  for(int istation=detId.minStationId() ; istation<=detId.maxStationId(); istation++){
111  max_ring=detId.maxRingId();
112  //station 4 ring 4 not there(36 chambers*2 missing)
113  //3 rings max this way of counting (ME1a & b)
114  if(istation==1) max_ring=3;
115  if(istation==2) max_ring=2;
116  if(istation==3) max_ring=2;
117  if(istation==4) max_ring=1;
118 
119  for(int iring=detId.minRingId(); iring<=max_ring; iring++){
120  max_istrip=80;
121  max_cham=detId.maxChamberId();
122  if(istation==1 && iring==1) max_cham=36;
123  if(istation==1 && iring==2) max_cham=36;
124  if(istation==1 && iring==3) max_cham=36;
125  if(istation==2 && iring==1) max_cham=18;
126  if(istation==2 && iring==2) max_cham=36;
127  if(istation==3 && iring==1) max_cham=18;
128  if(istation==3 && iring==2) max_cham=36;
129  if(istation==4 && iring==1) max_cham=18;
130 
131  for(int ichamber=detId.minChamberId(); ichamber<=max_cham; ichamber++){
132  for(int ilayer=detId.minLayerId(); ilayer<=detId.maxLayerId(); ilayer++){
133  //station 1 ring 3 has 64 strips per layer instead of 80
134  if(istation==1 && iring==3) max_istrip=64;
135 
136  std::vector<CSCNoiseMatrix::Item> itemvector;
137  itemvector.resize(max_istrip);
138  id_layer = 100000*iendcap + 10000*istation + 1000*iring + 10*ichamber + ilayer;
139 
140  for(int istrip=0;istrip<max_istrip;istrip++){
141 
142  if(istation==1 && iring==1){
143  itemvector[istrip].elem33 = 7.86675;
144  itemvector[istrip].elem34 = 2.07075;
145  itemvector[istrip].elem44 = 6.93875;
146  itemvector[istrip].elem35 = 1.42525;
147  itemvector[istrip].elem45 = 2.51025;
148  itemvector[istrip].elem55 = 7.93975;
149  itemvector[istrip].elem46 = 0.94725;
150  itemvector[istrip].elem56 = 2.39275;
151  itemvector[istrip].elem66 = 6.46475;
152  itemvector[istrip].elem57 = 1.86325;
153  itemvector[istrip].elem67 = 2.08025;
154  itemvector[istrip].elem77 = 6.67975;
155  cnmatrix->matrix[id_layer]=itemvector;
156  }
157 
158  if(istation==1 && iring==2){
159  itemvector[istrip].elem33 = 9.118;
160  itemvector[istrip].elem34 = 3.884;
161  itemvector[istrip].elem44 = 7.771;
162  itemvector[istrip].elem35 = 1.8225;
163  itemvector[istrip].elem45 = 3.7505;
164  itemvector[istrip].elem55 = 8.597;
165  itemvector[istrip].elem46 = 1.651;
166  itemvector[istrip].elem56 = 2.5225;
167  itemvector[istrip].elem66 = 6.583;
168  itemvector[istrip].elem57 = 1.5055;
169  itemvector[istrip].elem67 = 2.733;
170  itemvector[istrip].elem77 = 6.988;
171  cnmatrix->matrix[id_layer]=itemvector;
172  }
173 
174  if(istation==1 && iring==3){
175  itemvector[istrip].elem33 = 9.5245;
176  itemvector[istrip].elem34 = 3.2415;
177  itemvector[istrip].elem44 = 7.6265;
178  itemvector[istrip].elem35 = 1.7225;
179  itemvector[istrip].elem45 = 3.6075;
180  itemvector[istrip].elem55 = 8.7275;
181  itemvector[istrip].elem46 = 1.663;
182  itemvector[istrip].elem56 = 2.592;
183  itemvector[istrip].elem66 = 7.5685;
184  itemvector[istrip].elem57 = 1.7905;
185  itemvector[istrip].elem67 = 2.409;
186  itemvector[istrip].elem77 = 7.1495;
187  cnmatrix->matrix[id_layer]=itemvector;
188  }
189 
190  if(istation==2 && iring==1){
191  itemvector[istrip].elem33 = 9.06825;
192  itemvector[istrip].elem34 = 3.32025;
193  itemvector[istrip].elem44 = 7.52925;
194  itemvector[istrip].elem35 = 3.66125;
195  itemvector[istrip].elem45 = 3.39125;
196  itemvector[istrip].elem55 = 9.97625;
197  itemvector[istrip].elem46 = 1.32725;
198  itemvector[istrip].elem56 = 3.99025;
199  itemvector[istrip].elem66 = 8.10125;
200  itemvector[istrip].elem57 = 2.56456;
201  itemvector[istrip].elem67 = 2.96625;
202  itemvector[istrip].elem77 = 7.30925;
203  cnmatrix->matrix[id_layer]=itemvector;
204  }
205 
206  if(istation==2 &&iring==2){
207  itemvector[istrip].elem33 = 16.7442;
208  itemvector[istrip].elem34 = 7.96925;
209  itemvector[istrip].elem44 = 14.1643;
210  itemvector[istrip].elem35 = 4.67975;
211  itemvector[istrip].elem45 = 8.44075;
212  itemvector[istrip].elem55 = 17.2243;
213  itemvector[istrip].elem46 = 3.68575;
214  itemvector[istrip].elem56 = 7.48825;
215  itemvector[istrip].elem66 = 14.4902;
216  itemvector[istrip].elem57 = 4.4482;
217  itemvector[istrip].elem67 = 6.47875;
218  itemvector[istrip].elem77 = 14.6733;
219  cnmatrix->matrix[id_layer]=itemvector;
220  }
221 
222  if(istation==3 && iring==1){
223  itemvector[istrip].elem33 = 9.3495;
224  itemvector[istrip].elem34 = 3.529;
225  itemvector[istrip].elem44 = 7.8715;
226  itemvector[istrip].elem35 = 3.8155;
227  itemvector[istrip].elem45 = 3.858;
228  itemvector[istrip].elem55 = 10.8205;
229  itemvector[istrip].elem46 = 1.8585;
230  itemvector[istrip].elem56 = 4.445;
231  itemvector[istrip].elem66 = 8.0175;
232  itemvector[istrip].elem57 = 3.29479;
233  itemvector[istrip].elem67 = 3.625;
234  itemvector[istrip].elem77 = 8.3895;
235  cnmatrix->matrix[id_layer]=itemvector;
236  }
237 
238  if(istation==3 && iring==2){
239  itemvector[istrip].elem33 = 13.6193;
240  itemvector[istrip].elem34 = 5.91025;
241  itemvector[istrip].elem44 = 11.3842;
242  itemvector[istrip].elem35 = 3.31775;
243  itemvector[istrip].elem45 = 5.69775;
244  itemvector[istrip].elem55 = 11.6652;
245  itemvector[istrip].elem46 = 2.46175;
246  itemvector[istrip].elem56 = 4.48325;
247  itemvector[istrip].elem66 = 9.95725;
248  itemvector[istrip].elem57 = 2.10561;
249  itemvector[istrip].elem67 = 4.04625;
250  itemvector[istrip].elem77 = 9.51625;
251  cnmatrix->matrix[id_layer]=itemvector;
252  }
253 
254  if(istation==4 && iring==1){
255  itemvector[istrip].elem33 = 10.0;
256  itemvector[istrip].elem34 = 4.0;
257  itemvector[istrip].elem44 = 10.0;
258  itemvector[istrip].elem35 = 3.0;
259  itemvector[istrip].elem45 = 8.0;
260  itemvector[istrip].elem55 = 10.0;
261  itemvector[istrip].elem46 = 2.0;
262  itemvector[istrip].elem56 = 5.0;
263  itemvector[istrip].elem66 = 10.0;
264  itemvector[istrip].elem57 = 3.0;
265  itemvector[istrip].elem67 = 4.0;
266  itemvector[istrip].elem77 = 10.0;
267  cnmatrix->matrix[id_layer]=itemvector;
268  }
269  }
270  }
271  }
272  }
273  }
274  }
275 
276  //overwrite fakes with old values from DB
277  int istrip = 0;
278  std::vector<CSCNoiseMatrix::Item> itemvector;
279  itemvector.resize(80);
280 
281  for(unsigned int mystrip=0; mystrip<old_nrlines-1; mystrip++){
282  if(old_strips[mystrip]==0) istrip = 0;
283  itemvector[istrip].elem33 = old_elem33[mystrip];
284  itemvector[istrip].elem34 = old_elem34[mystrip];
285  itemvector[istrip].elem44 = old_elem44[mystrip];
286  itemvector[istrip].elem35 = old_elem35[mystrip];
287  itemvector[istrip].elem45 = old_elem45[mystrip];
288  itemvector[istrip].elem55 = old_elem55[mystrip];
289  itemvector[istrip].elem46 = old_elem46[mystrip];
290  itemvector[istrip].elem56 = old_elem56[mystrip];
291  itemvector[istrip].elem66 = old_elem66[mystrip];
292  itemvector[istrip].elem57 = old_elem57[mystrip];
293  itemvector[istrip].elem67 = old_elem67[mystrip];
294  itemvector[istrip].elem77 = old_elem77[mystrip];
295  cnmatrix->matrix[old_cham_id[mystrip]]=itemvector;
296  istrip++;
297  }
298 
299 
300  itemvector.resize(64);
301  for(unsigned int mystrip=0; mystrip<old_nrlines-1; mystrip++){
302  if(old_strips[mystrip]==0) istrip = 0;
303  if(old_cham_id[mystrip] >= 113000 && old_cham_id[mystrip] <= 113999){
304  itemvector[istrip].elem33 = old_elem33[mystrip];
305  itemvector[istrip].elem34 = old_elem34[mystrip];
306  itemvector[istrip].elem44 = old_elem44[mystrip];
307  itemvector[istrip].elem35 = old_elem35[mystrip];
308  itemvector[istrip].elem45 = old_elem45[mystrip];
309  itemvector[istrip].elem55 = old_elem55[mystrip];
310  itemvector[istrip].elem46 = old_elem46[mystrip];
311  itemvector[istrip].elem56 = old_elem56[mystrip];
312  itemvector[istrip].elem66 = old_elem66[mystrip];
313  itemvector[istrip].elem57 = old_elem57[mystrip];
314  itemvector[istrip].elem67 = old_elem67[mystrip];
315  itemvector[istrip].elem77 = old_elem77[mystrip];
316  cnmatrix->matrix[old_cham_id[mystrip]]=itemvector;
317  istrip++;
318  }
319  }
320 
321  itemvector.resize(64);
322  for(unsigned int mystrip=0; mystrip<old_nrlines-1; mystrip++){
323  if(old_strips[mystrip]==0) istrip = 0;
324  if(old_cham_id[mystrip] >= 213000 && old_cham_id[mystrip] <= 213999){
325  itemvector[istrip].elem33 = old_elem33[mystrip];
326  itemvector[istrip].elem34 = old_elem34[mystrip];
327  itemvector[istrip].elem44 = old_elem44[mystrip];
328  itemvector[istrip].elem35 = old_elem35[mystrip];
329  itemvector[istrip].elem45 = old_elem45[mystrip];
330  itemvector[istrip].elem55 = old_elem55[mystrip];
331  itemvector[istrip].elem46 = old_elem46[mystrip];
332  itemvector[istrip].elem56 = old_elem56[mystrip];
333  itemvector[istrip].elem66 = old_elem66[mystrip];
334  itemvector[istrip].elem57 = old_elem57[mystrip];
335  itemvector[istrip].elem67 = old_elem67[mystrip];
336  itemvector[istrip].elem77 = old_elem77[mystrip];
337  cnmatrix->matrix[old_cham_id[mystrip]]=itemvector;
338  istrip++;
339  }
340  }
341 
342  //overwrite old values with ones from new runs
343  itemvector.resize(80);
344  for(unsigned int mystrip=0; mystrip<new_nrlines-1; mystrip++){
345  if(new_strips[mystrip]==0) istrip = 0;
346  itemvector[istrip].elem33 = new_elem33[mystrip];
347  itemvector[istrip].elem34 = new_elem34[mystrip];
348  itemvector[istrip].elem44 = new_elem44[mystrip];
349  itemvector[istrip].elem35 = new_elem35[mystrip];
350  itemvector[istrip].elem45 = new_elem45[mystrip];
351  itemvector[istrip].elem55 = new_elem55[mystrip];
352  itemvector[istrip].elem46 = new_elem46[mystrip];
353  itemvector[istrip].elem56 = new_elem56[mystrip];
354  itemvector[istrip].elem66 = new_elem66[mystrip];
355  itemvector[istrip].elem57 = new_elem57[mystrip];
356  itemvector[istrip].elem67 = new_elem67[mystrip];
357  itemvector[istrip].elem77 = new_elem77[mystrip];
358  cnmatrix->matrix[new_cham_id[mystrip]]=itemvector;
359  istrip++;
360  }
361 
362  itemvector.resize(64);
363  for(unsigned int mystrip=0; mystrip<new_nrlines-1; mystrip++){
364  if(new_strips[mystrip]==0) istrip = 0;
365  if(new_cham_id[mystrip] >= 113000 && new_cham_id[mystrip] <= 113999){
366  itemvector[istrip].elem33 = new_elem33[mystrip];
367  itemvector[istrip].elem34 = new_elem34[mystrip];
368  itemvector[istrip].elem44 = new_elem44[mystrip];
369  itemvector[istrip].elem35 = new_elem35[mystrip];
370  itemvector[istrip].elem45 = new_elem45[mystrip];
371  itemvector[istrip].elem55 = new_elem55[mystrip];
372  itemvector[istrip].elem46 = new_elem46[mystrip];
373  itemvector[istrip].elem56 = new_elem56[mystrip];
374  itemvector[istrip].elem66 = new_elem66[mystrip];
375  itemvector[istrip].elem57 = new_elem57[mystrip];
376  itemvector[istrip].elem67 = new_elem67[mystrip];
377  itemvector[istrip].elem77 = new_elem77[mystrip];
378  cnmatrix->matrix[new_cham_id[mystrip]]=itemvector;
379  istrip++;
380  }
381  }
382 
383  itemvector.resize(64);
384  for(unsigned int mystrip=0; mystrip<new_nrlines-1; mystrip++){
385  if(new_strips[mystrip]==0) istrip = 0;
386  if(new_cham_id[mystrip] >= 213000 && new_cham_id[mystrip] <= 213999){
387  itemvector[istrip].elem33 = new_elem33[mystrip];
388  itemvector[istrip].elem34 = new_elem34[mystrip];
389  itemvector[istrip].elem44 = new_elem44[mystrip];
390  itemvector[istrip].elem35 = new_elem35[mystrip];
391  itemvector[istrip].elem45 = new_elem45[mystrip];
392  itemvector[istrip].elem55 = new_elem55[mystrip];
393  itemvector[istrip].elem46 = new_elem46[mystrip];
394  itemvector[istrip].elem56 = new_elem56[mystrip];
395  itemvector[istrip].elem66 = new_elem66[mystrip];
396  itemvector[istrip].elem57 = new_elem57[mystrip];
397  itemvector[istrip].elem67 = new_elem67[mystrip];
398  itemvector[istrip].elem77 = new_elem77[mystrip];
399  cnmatrix->matrix[new_cham_id[mystrip]]=itemvector;
400  istrip++;
401  }
402  }
403  return cnmatrix;
404 
405 }
406 
408 {
409  //the following line is needed to tell the framework what
410  // data is being produced
412  // added by Zhen (changed since 1_2_0)
414  findingRecord<CSCNoiseMatrixRcd>();
415  //now do what ever other initialization is needed
416 }
417 
418 
420 {
421 
422  // do anything here that needs to be done at desctruction time
423  // (e.g. close files, deallocate resources etc.)
424  delete cnMatrix;
425 }
426 
427 
428 //
429 // member functions
430 //
431 
432 // ------------ method called to produce the data ------------
435 {
436  // Added by Zhen, need a new object so to not be deleted at exit
437  CSCNoiseMatrix* mydata=new CSCNoiseMatrix( *cnMatrix );
438 
439  return mydata;
440 
441 }
442 
444  edm::ValidityInterval & oValidity)
445  {
447 
448  }
static int minRingId()
Definition: CSCDetId.h:242
static CSCNoiseMatrix * prefillNoiseMatrix()
static int minEndcapId()
Definition: CSCDetId.h:238
static const IOVSyncValue & endOfTime()
Definition: IOVSyncValue.cc:97
std::pair< Time_t, Time_t > ValidityInterval
Definition: Time.h:19
static int maxStationId()
Definition: CSCDetId.h:241
static int maxRingId()
Definition: CSCDetId.h:243
void setWhatProduced(T *iThis, const es::Label &iLabel=es::Label())
Definition: ESProducer.h:115
static int minChamberId()
Definition: CSCDetId.h:244
static const IOVSyncValue & beginOfTime()
static int minStationId()
Definition: CSCDetId.h:240
static int maxEndcapId()
Definition: CSCDetId.h:239
NoiseMatrixMap matrix
static int minLayerId()
Definition: CSCDetId.h:246
static int maxChamberId()
Definition: CSCDetId.h:245
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &)
ReturnType produceNoiseMatrix(const CSCNoiseMatrixRcd &)
CSCNoiseMatrixConditions(const edm::ParameterSet &)
static int maxLayerId()
Definition: CSCDetId.h:247