CMS 3D CMS Logo

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