CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CSCCrosstalkConditions.cc
Go to the documentation of this file.
1 #include <fstream>
2 
4 
6 
7  float mean,min,minchi;
8  int seed;
9  int old_chamber_id,old_strip,new_chamber_id,new_strip;
10  float old_slope_right,old_slope_left,old_intercept_right;
11  float old_intercept_left, old_chi2_right,old_chi2_left;
12  std::vector<int> old_cham_id;
13  std::vector<int> old_strips;
14  std::vector<float> old_slope_r;
15  std::vector<float> old_intercept_r;
16  std::vector<float> old_chi2_r;
17  std::vector<float> old_slope_l;
18  std::vector<float> old_intercept_l;
19  std::vector<float> old_chi2_l;
20  float new_slope_right,new_slope_left,new_intercept_right;
21  float new_intercept_left, new_chi2_right,new_chi2_left;
22  std::vector<int> new_cham_id;
23  std::vector<int> new_strips;
24  std::vector<float> new_slope_r;
25  std::vector<float> new_intercept_r;
26  std::vector<float> new_chi2_r;
27  std::vector<float> new_slope_l;
28  std::vector<float> new_intercept_l;
29  std::vector<float> new_chi2_l;
30 
31 
32 
33  const CSCDetId& detId = CSCDetId();
34  CSCcrosstalk * cncrosstalk = new CSCcrosstalk();
35 
36  int max_istrip,id_layer,max_ring,max_cham;
37  unsigned int old_nrlines=0;
38  unsigned int new_nrlines=0;
39  seed = 10000;
40  srand(seed);
41  mean=-0.0009, min=0.035, minchi=1.5;
42 
43  //endcap=1 to 2,station=1 to 4, ring=1 to 4,chamber=1 to 36,layer=1 to 6
44  std::ifstream olddata;
45  olddata.open("old_xtalk.dat",std::ios::in);
46  if(!olddata) {
47  std::cerr <<"Error: old_xtalk.dat -> no such file!"<< std::endl;
48  exit(1);
49  }
50 
51  while (!olddata.eof() ) {
52  olddata >> old_chamber_id >> old_strip >> old_slope_right >> old_intercept_right >> old_chi2_right >> old_slope_left >> old_intercept_left >> old_chi2_left ;
53  old_cham_id.push_back(old_chamber_id);
54  old_strips.push_back(old_strip);
55  old_slope_r.push_back(old_slope_right);
56  old_slope_l.push_back(old_slope_left);
57  old_intercept_r.push_back(old_intercept_right);
58  old_intercept_l.push_back(old_intercept_left);
59  old_chi2_r.push_back(old_chi2_right);
60  old_chi2_l.push_back(old_chi2_left);
61  old_nrlines++;
62  }
63  olddata.close();
64 
65  std::ifstream newdata;
66  newdata.open("new_xtalk.txt",std::ios::in);
67  if(!newdata) {
68  std::cerr <<"Error: new_xtalk.dat -> no such file!"<< std::endl;
69  exit(1);
70  }
71 
72  while (!newdata.eof() ) {
73  newdata >> new_chamber_id >> new_strip >> new_slope_right >> new_intercept_right >> new_chi2_right >> new_slope_left >> new_intercept_left >> new_chi2_left ;
74  new_cham_id.push_back(new_chamber_id);
75  new_strips.push_back(new_strip);
76  new_slope_r.push_back(new_slope_right);
77  new_slope_l.push_back(new_slope_left);
78  new_intercept_r.push_back(new_intercept_right);
79  new_intercept_l.push_back(new_intercept_left);
80  new_chi2_r.push_back(new_chi2_right);
81  new_chi2_l.push_back(new_chi2_left);
82  new_nrlines++;
83  }
84  newdata.close();
85 
86  for(int iendcap=detId.minEndcapId(); iendcap<=detId.maxEndcapId(); iendcap++){
87  for(int istation=detId.minStationId() ; istation<=detId.maxStationId(); istation++){
88  max_ring=detId.maxRingId();
89  //station 4 ring 4 not there(36 chambers*2 missing)
90  //3 rings max this way of counting (ME1a & b)
91  if(istation==1) max_ring=3;
92  if(istation==2) max_ring=2;
93  if(istation==3) max_ring=2;
94  if(istation==4) max_ring=1;
95 
96  for(int iring=detId.minRingId(); iring<=max_ring; iring++){
97  max_istrip=80;
98  max_cham=detId.maxChamberId();
99  if(istation==1 && iring==1) max_cham=36;
100  if(istation==1 && iring==2) max_cham=36;
101  if(istation==1 && iring==3) max_cham=36;
102  if(istation==2 && iring==1) max_cham=18;
103  if(istation==2 && iring==2) max_cham=36;
104  if(istation==3 && iring==1) max_cham=18;
105  if(istation==3 && iring==2) max_cham=36;
106  if(istation==4 && iring==1) max_cham=18;
107  //station 1 ring 3 has 64 strips per layer instead of 80(minus & plus side!!!)
108 
109  for(int ichamber=detId.minChamberId(); ichamber<=max_cham; ichamber++){
110 
111  for(int ilayer=detId.minLayerId(); ilayer<=detId.maxLayerId(); ilayer++){
112  //station 1 ring 3 has 64 strips per layer instead of 80
113  if(istation==1 && iring==3) max_istrip=64;
114 
115  std::vector<CSCcrosstalk::Item> itemvector;
116  itemvector.resize(max_istrip);
117  id_layer = 100000*iendcap + 10000*istation + 1000*iring + 10*ichamber + ilayer;
118 
119  for(int istrip=0;istrip<max_istrip;istrip++){
120  //create fake values
121  itemvector[istrip].xtalk_slope_right=-((double)rand()/((double)(RAND_MAX)+(double)(1)))/10000+mean;
122  itemvector[istrip].xtalk_intercept_right=((double)rand()/((double)(RAND_MAX)+(double)(1)))/100+min;
123  itemvector[istrip].xtalk_chi2_right=((double)rand()/((double)(RAND_MAX)+(double)(1)))+minchi;
124  itemvector[istrip].xtalk_slope_left=-((double)rand()/((double)(RAND_MAX)+(double)(1)))/10000+mean;
125  itemvector[istrip].xtalk_intercept_left=((double)rand()/((double)(RAND_MAX)+(double)(1)))/100+min;
126  itemvector[istrip].xtalk_chi2_left=((double)rand()/((double)(RAND_MAX)+(double)(1)))+minchi;
127  cncrosstalk->crosstalk[id_layer]=itemvector;
128 
129  if(istrip==0){
130  itemvector[istrip].xtalk_slope_right=-((double)rand()/((double)(RAND_MAX)+(double)(1)))/10000+mean;
131  itemvector[istrip].xtalk_intercept_right=((double)rand()/((double)(RAND_MAX)+(double)(1)))/100+min;
132  itemvector[istrip].xtalk_chi2_right=((double)rand()/((double)(RAND_MAX)+(double)(1)))+minchi;
133  itemvector[istrip].xtalk_slope_left=0.0;
134  itemvector[istrip].xtalk_intercept_left=0.0;
135  itemvector[istrip].xtalk_chi2_left=0.0;
136  cncrosstalk->crosstalk[id_layer]=itemvector;
137  }
138 
139  if(istrip==79){
140  itemvector[istrip].xtalk_slope_right=0.0;
141  itemvector[istrip].xtalk_intercept_right=0.0;
142  itemvector[istrip].xtalk_chi2_right=0.0;
143  itemvector[istrip].xtalk_slope_left=-((double)rand()/((double)(RAND_MAX)+(double)(1)))/10000+mean;
144  itemvector[istrip].xtalk_intercept_left=((double)rand()/((double)(RAND_MAX)+(double)(1)))/100+min;
145  itemvector[istrip].xtalk_chi2_left=((double)rand()/((double)(RAND_MAX)+(double)(1)))+minchi;
146  cncrosstalk->crosstalk[id_layer]=itemvector;
147  }
148  }
149  }
150  }
151  }
152  }
153 
154  //overwrite fakes with old values from DB
155  int istrip = 0;
156  std::vector<CSCcrosstalk::Item> itemvector;
157  itemvector.resize(80);
158 
159  for(unsigned int mystrip=0; mystrip<old_nrlines-1; mystrip++){
160  if(old_strips[mystrip]==0) istrip = 0;
161  itemvector[istrip].xtalk_slope_right=old_slope_r[mystrip];
162  itemvector[istrip].xtalk_intercept_right=old_intercept_r[mystrip];
163  itemvector[istrip].xtalk_chi2_right=old_chi2_r[mystrip];
164  itemvector[istrip].xtalk_slope_left=old_slope_l[mystrip];
165  itemvector[istrip].xtalk_intercept_left=old_intercept_l[mystrip];
166  itemvector[istrip].xtalk_chi2_left=old_chi2_l[mystrip];
167  cncrosstalk->crosstalk[old_cham_id[mystrip]]=itemvector;
168  istrip++;
169  }
170 
171 
172  itemvector.resize(64);
173  for(unsigned int mystrip=0; mystrip<old_nrlines-1; mystrip++){
174  if(old_strips[mystrip]==0) istrip = 0;
175  if(old_cham_id[mystrip] >= 113000 && old_cham_id[mystrip] <= 113999){
176  itemvector[istrip].xtalk_slope_right=old_slope_r[mystrip];
177  itemvector[istrip].xtalk_intercept_right=old_intercept_r[mystrip];
178  itemvector[istrip].xtalk_chi2_right=old_chi2_r[mystrip];
179  itemvector[istrip].xtalk_slope_left=old_slope_l[mystrip];
180  itemvector[istrip].xtalk_intercept_left=old_intercept_l[mystrip];
181  itemvector[istrip].xtalk_chi2_left=old_chi2_l[mystrip];
182  cncrosstalk->crosstalk[old_cham_id[mystrip]]=itemvector;
183  istrip++;
184  }
185  }
186 
187  itemvector.resize(64);
188  for(unsigned int mystrip=0; mystrip<old_nrlines-1; mystrip++){
189  if(old_strips[mystrip]==0) istrip = 0;
190  if(old_cham_id[mystrip] >= 213000 && old_cham_id[mystrip] <= 213999){
191  itemvector[istrip].xtalk_slope_right=old_slope_r[mystrip];
192  itemvector[istrip].xtalk_intercept_right=old_intercept_r[mystrip];
193  itemvector[istrip].xtalk_chi2_right=old_chi2_r[mystrip];
194  itemvector[istrip].xtalk_slope_left=old_slope_l[mystrip];
195  itemvector[istrip].xtalk_intercept_left=old_intercept_l[mystrip];
196  itemvector[istrip].xtalk_chi2_left=old_chi2_l[mystrip];
197  cncrosstalk->crosstalk[old_cham_id[mystrip]]=itemvector;
198  istrip++;
199  }
200  }
201 
202  //overwrite old values with ones from new runs
203  itemvector.resize(80);
204  for(unsigned int mystrip=0; mystrip<new_nrlines-1; mystrip++){
205  if(new_strips[mystrip]==0) istrip = 0;
206  itemvector[istrip].xtalk_slope_right=new_slope_r[mystrip];
207  itemvector[istrip].xtalk_intercept_right=new_intercept_r[mystrip];
208  itemvector[istrip].xtalk_chi2_right=new_chi2_r[mystrip];
209  itemvector[istrip].xtalk_slope_left=new_slope_l[mystrip];
210  itemvector[istrip].xtalk_intercept_left=new_intercept_l[mystrip];
211  itemvector[istrip].xtalk_chi2_left=new_chi2_l[mystrip];
212  cncrosstalk->crosstalk[new_cham_id[mystrip]]=itemvector;
213  istrip++;
214  }
215 
216  itemvector.resize(64);
217  for(unsigned int mystrip=0; mystrip<new_nrlines-1; mystrip++){
218  if(new_strips[mystrip]==0) istrip = 0;
219  if(new_cham_id[mystrip] >= 113000 && new_cham_id[mystrip] <= 113999){
220  itemvector[istrip].xtalk_slope_right=new_slope_r[mystrip];
221  itemvector[istrip].xtalk_intercept_right=new_intercept_r[mystrip];
222  itemvector[istrip].xtalk_chi2_right=new_chi2_r[mystrip];
223  itemvector[istrip].xtalk_slope_left=new_slope_l[mystrip];
224  itemvector[istrip].xtalk_intercept_left=new_intercept_l[mystrip];
225  itemvector[istrip].xtalk_chi2_left=new_chi2_l[mystrip];
226  cncrosstalk->crosstalk[new_cham_id[mystrip]]=itemvector;
227  istrip++;
228  }
229  }
230 
231  itemvector.resize(64);
232  for(unsigned int mystrip=0; mystrip<new_nrlines-1; mystrip++){
233  if(new_strips[mystrip]==0) istrip = 0;
234  if(new_cham_id[mystrip] >= 213000 && new_cham_id[mystrip] <= 213999){
235  itemvector[istrip].xtalk_slope_right=new_slope_r[mystrip];
236  itemvector[istrip].xtalk_intercept_right=new_intercept_r[mystrip];
237  itemvector[istrip].xtalk_chi2_right=new_chi2_r[mystrip];
238  itemvector[istrip].xtalk_slope_left=new_slope_l[mystrip];
239  itemvector[istrip].xtalk_intercept_left=new_intercept_l[mystrip];
240  itemvector[istrip].xtalk_chi2_left=new_chi2_l[mystrip];
241  cncrosstalk->crosstalk[new_cham_id[mystrip]]=itemvector;
242  istrip++;
243  }
244  }
245  }
246 
247  return cncrosstalk;
248 
249 }
250 
251 
253 {
254  //the following line is needed to tell the framework what
255  // data is being produced
257  // added by Zhen (changed since 1_2_0)
259  findingRecord<CSCcrosstalkRcd>();
260  //now do what ever other initialization is needed
261 }
262 
263 
265 {
266 
267  // do anything here that needs to be done at desctruction time
268  // (e.g. close files, deallocate resources etc.)
269  delete cnCrosstalk;
270 }
271 
272 
273 //
274 // member functions
275 //
276 
277 // ------------ method called to produce the data ------------
280 {
281  // Added by Zhen, need a new object so to not be deleted at exit
282  CSCcrosstalk* mydata=new CSCcrosstalk( *cnCrosstalk );
283 
284  return mydata;
285 
286 }
287 
289  edm::ValidityInterval & oValidity)
290  {
292 
293  }
294 
295 
ReturnType produceCrosstalk(const CSCcrosstalkRcd &)
static int minRingId()
Definition: CSCDetId.h:242
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
#define min(a, b)
Definition: mlp_lapack.h:161
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
CrosstalkMap crosstalk
Definition: CSCcrosstalk.h:26
static int minChamberId()
Definition: CSCDetId.h:244
static const IOVSyncValue & beginOfTime()
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &)
static int minStationId()
Definition: CSCDetId.h:240
static int maxEndcapId()
Definition: CSCDetId.h:239
static int minLayerId()
Definition: CSCDetId.h:246
static int maxChamberId()
Definition: CSCDetId.h:245
CSCCrosstalkConditions(const edm::ParameterSet &)
Signal rand(Signal arg)
Definition: vlib.cc:442
static int maxLayerId()
Definition: CSCDetId.h:247
static CSCcrosstalk * prefillCrosstalk()