CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PhiSymmetryCalibration_step2_SM.cc
Go to the documentation of this file.
7 
8 #include "TH2F.h"
9 
10 #include "TH1F.h"
11 #include "TFile.h"
12 
13 #include <filesystem>
14 #include <fstream>
15 
16 using namespace std;
17 
19 
21  : channelStatusToken_(esConsumes()),
22  geometryToken_(esConsumes()),
23  firstpass_(true),
24  statusThreshold_(iConfig.getUntrackedParameter<int>("statusThreshold", 0)),
25  reiteration_(iConfig.getUntrackedParameter<bool>("reiteration", false)),
26  oldcalibfile_(iConfig.getUntrackedParameter<std::string>("oldcalibfile", "EcalIntercalibConstants.xml")),
27  have_initial_miscalib_(iConfig.getUntrackedParameter<bool>("haveInitialMiscalib", false)),
28  initialmiscalibfile_(iConfig.getUntrackedParameter<std::string>("initialmiscalibfile", "InitialMiscalib.xml")) {}
29 
31  if (firstpass_) {
32  setUp(se);
33  firstpass_ = false;
34  }
35 }
36 
38  const auto& chStatus = se.getData(channelStatusToken_);
39 
40  const auto& geometry = se.getData(geometryToken_);
41 
42  barrelCells = geometry.getValidDetIds(DetId::Ecal, EcalBarrel);
43  endcapCells = geometry.getValidDetIds(DetId::Ecal, EcalEndcap);
44 
45  e_.setup(&geometry, &chStatus, statusThreshold_);
46 
47  for (int sign = 0; sign < kSides; sign++) {
48  for (int ieta = 0; ieta < kBarlRings; ieta++) {
49  for (int iphi = 0; iphi < kBarlWedges; iphi++) {
50  int iphi_r = int(iphi / nscx);
51  if (!e_.goodCell_barl[ieta][iphi][sign]) {
52  nBads_barl_SM_[ieta][iphi_r][sign]++;
53  // std::cout << "N BAD CELL " << nBads_barl_SM_[ieta][iphi_r][sign] << endl;
54  }
55  }
56  }
57  }
58 
62  namespace fs = std::filesystem;
64  if (!fs::exists(p))
65  edm::LogError("PhiSym") << "File not found: " << initialmiscalibfile_ << endl;
66 
68  if (ret)
69  edm::LogError("PhiSym") << "Error reading XML files" << endl;
70  } else {
71  for (vector<DetId>::iterator it = barrelCells.begin(); it != barrelCells.end(); ++it) {
72  miscalib_[*it] = 1;
73  }
74 
75  for (vector<DetId>::iterator it = endcapCells.begin(); it != endcapCells.end(); ++it) {
76  miscalib_[*it] = 1;
77  }
78  }
79 
80  // if we are reiterating, read constants from previous iter
81  // if not put them to one
82  if (reiteration_) {
84  namespace fs = std::filesystem;
85  fs::path p(oldcalibfile_.c_str());
86  if (!fs::exists(p))
87  edm::LogError("PhiSym") << "File not found: " << oldcalibfile_ << endl;
88 
90 
91  if (ret)
92  edm::LogError("PhiSym") << "Error reading XML files" << endl;
93  ;
94 
95  } else {
96  for (vector<DetId>::iterator it = barrelCells.begin(); it != barrelCells.end(); ++it)
97  oldCalibs_[*it] = 1;
98 
99  for (vector<DetId>::iterator it = endcapCells.begin(); it != endcapCells.end(); ++it)
100  oldCalibs_[*it] = 1;
101 
102  } // else
103 }
104 
106  for (int ieta = 0; ieta < kBarlRings; ieta++) {
107  for (int iphi = 0; iphi < kBarlWedges; iphi++) {
108  for (int sign = 0; sign < kSides; sign++) {
109  int iphi_r = int(iphi / nscx);
110 
111  etsum_barl_[ieta][iphi][sign] = 0.;
112  nhits_barl_[ieta][iphi][sign] = 0;
113  esum_barl_[ieta][iphi][sign] = 0.;
114  etsum_barl_SM_[ieta][iphi_r][sign] = 0;
115  nBads_barl_SM_[ieta][iphi_r][sign] = 0;
116  epsilon_M_barl_SM_[ieta][iphi_r][sign] = 0;
117  }
118  }
119  etsumMean_barl_SM_[ieta] = 0.;
120  }
121 
122  for (int ix = 0; ix < kEndcWedgesX; ix++) {
123  for (int iy = 0; iy < kEndcWedgesY; iy++) {
124  for (int sign = 0; sign < kSides; sign++) {
125  etsum_endc_[ix][iy][sign] = 0.;
126  nhits_endc_[ix][iy][sign] = 0;
127  esum_endc_[ix][iy][sign] = 0.;
128  }
129  }
130  }
131 
132  readEtSums();
134 }
135 
137  if (firstpass_) {
138  edm::LogError("PhiSym") << "Must process at least one event-Exiting" << endl;
139  return;
140  }
141 
142  // Here the real calculation of constants happens
143 
144  // perform the area correction for endcap etsum
145  // NOT USED ANYMORE
146 
147  /*
148  for (int ix=0; ix<kEndcWedgesX; ix++) {
149  for (int iy=0; iy<kEndcWedgesY; iy++) {
150 
151  int ring = e_.endcapRing_[ix][iy];
152 
153  if (ring!=-1) {
154  for (int sign=0; sign<kSides; sign++) {
155  etsum_endc_uncorr[ix][iy][sign] = etsum_endc_[ix][iy][sign];
156  etsum_endc_[ix][iy][sign]*=meanCellArea_[ring]/cellArea_[ix][iy];
157  }
158  }
159  }
160  }
161  */
162 
163  // ETsum histos, maps and other usefull histos (area,...)
164  // are filled and saved here
165  fillHistos();
166 
167  // write ETsum mean for all rings
168  std::ofstream etsumMean_barl_out("etsumMean_barl.dat", ios::out);
169  for (int ieta = 0; ieta < kBarlRings; ieta++) {
170  etsumMean_barl_out << ieta << " " << etsumMean_barl_[ieta] << endl;
171  }
172  etsumMean_barl_out.close();
173 
174  std::ofstream etsumMean_endc_out("etsumMean_endc.dat", ios::out);
175  for (int ring = 0; ring < kEndcEtaRings; ring++) {
176  etsumMean_endc_out << e_.cellPos_[ring][50].eta() << " " << etsumMean_endc_[ring] << endl;
177  }
178  etsumMean_endc_out.close();
179 
180  // determine barrel calibration constants
181  for (int ieta = 0; ieta < kBarlRings; ieta++) {
182  for (int iphi = 0; iphi < kBarlWedges; iphi++) {
183  for (int sign = 0; sign < kSides; sign++) {
184  // sc
185  int iphi_r = int(iphi / nscx);
186 
187  //if(nBads_barl_SM_[ieta][iphi_r][sign]>0){
188  // std::cout << "ETSUM" << etsum_barl_SM_[ieta][iphi_r][sign] << " " <<ieta << " " << iphi_r << " " << sign << " " << nBads_barl_SM_[ieta][iphi_r][sign]<< endl;
189  //}
190 
191  float epsilon_T_SM = etsum_barl_SM_[ieta][iphi_r][sign] / etsumMean_barl_SM_[ieta] - 1.;
192 
193  epsilon_M_barl_SM_[ieta][iphi_r][sign] = epsilon_T_SM / k_barl_[ieta];
194 
195  if (e_.goodCell_barl[ieta][iphi][sign]) {
196  float etsum = etsum_barl_[ieta][iphi][sign];
197  float epsilon_T = (etsum / etsumMean_barl_[ieta]) - 1.;
198  rawconst_barl[ieta][iphi][sign] = epsilon_T + 1.;
199  epsilon_M_barl[ieta][iphi][sign] = epsilon_T / k_barl_[ieta];
200 
201  } else {
202  rawconst_barl[ieta][iphi][sign] = 1.;
203  epsilon_M_barl[ieta][iphi][sign] = 0.;
204  } //if
205  } //sign
206  } //iphi
207  } //ieta
208 
209  // determine endcap calibration constants
210  for (int ix = 0; ix < kEndcWedgesX; ix++) {
211  for (int iy = 0; iy < kEndcWedgesY; iy++) {
212  for (int sign = 0; sign < kSides; sign++) {
213  int ring = e_.endcapRing_[ix][iy];
214  if (ring != -1 && e_.goodCell_endc[ix][iy][sign]) {
215  float etsum = etsum_endc_[ix][iy][sign];
216  float epsilon_T = (etsum / etsumMean_endc_[ring]) - 1.;
217  rawconst_endc[ix][iy][sign] = epsilon_T + 1.;
218  epsilon_M_endc[ix][iy][sign] = epsilon_T / k_endc_[ring];
219  } else {
220  epsilon_M_endc[ix][iy][0] = 0.;
221  epsilon_M_endc[ix][iy][1] = 0.;
222  rawconst_endc[ix][iy][0] = 1.;
223  rawconst_endc[ix][iy][1] = 1.;
224  } //if
225  } //sign
226  } //iy
227  } //ix
228 
229  // output sc calibration
230  std::fstream scfile("sccalibration.dat", std::ios::out);
231  for (int ieta = 0; ieta < kBarlRings; ++ieta) {
232  for (int iphi_r = 0; iphi_r < int(kBarlWedges / nscx); ++iphi_r) {
233  for (int sign = 0; sign < kSides; sign++) {
234  scfile << ieta << " " << iphi_r << " " << sign << " " << 1 / (1 + epsilon_M_barl_SM_[ieta][iphi_r][sign])
235  << std::endl;
236  }
237  }
238  }
239 
240  std::string newcalibfile("EcalIntercalibConstants_new.xml");
241 
242  TFile ehistof("ehistos.root", "recreate");
243 
244  TH1D ebhisto("eb", "eb", 100, 0., 2.);
245 
246  std::vector<DetId>::const_iterator barrelIt = barrelCells.begin();
247  for (; barrelIt != barrelCells.end(); barrelIt++) {
248  EBDetId eb(*barrelIt);
249  int ieta = abs(eb.ieta()) - 1;
250  int iphi = eb.iphi() - 1;
251  int sign = eb.zside() > 0 ? 1 : 0;
252 
255  newCalibs_[eb] = oldCalibs_[eb] / (1 + epsilon_M_barl[ieta][iphi][sign]);
256 
257  if (e_.goodCell_barl[ieta][iphi][sign]) {
258  ebhisto.Fill(newCalibs_[eb]);
259 
261  miscal_resid_barl_histos[ieta]->Fill(miscalib_[eb] * newCalibs_[eb]);
262  correl_barl_histos[ieta]->Fill(miscalib_[eb], newCalibs_[eb]);
263  }
264 
265  } // barrelit
266 
267  TH1D eehisto("ee", "ee", 100, 0., 2.);
268  std::vector<DetId>::const_iterator endcapIt = endcapCells.begin();
269 
270  for (; endcapIt != endcapCells.end(); endcapIt++) {
271  EEDetId ee(*endcapIt);
272  int ix = ee.ix() - 1;
273  int iy = ee.iy() - 1;
274  int sign = ee.zside() > 0 ? 1 : 0;
275 
276  newCalibs_[ee] = oldCalibs_[ee] / (1 + epsilon_M_endc[ix][iy][sign]);
277 
278  if (e_.goodCell_endc[ix][iy][sign]) {
279  eehisto.Fill(newCalibs_[ee]);
280  miscal_resid_endc_histos[e_.endcapRing_[ix][iy]]->Fill(miscalib_[ee] * newCalibs_[ee]);
281  ;
282 
283  correl_endc_histos[e_.endcapRing_[ix][iy]]->Fill(miscalib_[ee], newCalibs_[ee]);
284  }
285  } //endcapit
286  // Write xml file
287  EcalCondHeader header;
288  header.method_ = "phi symmetry";
289  header.version_ = "0";
290  header.datasource_ = "testdata";
291  header.since_ = 1;
292  header.tag_ = "unknown";
293  header.date_ = "Mar 24 1973";
294 
296 
297  eehisto.Write();
298  ebhisto.Write();
299  ehistof.Close();
300 
302 
303  outResidHistos();
304 }
305 
307  TFile f("CalibHistos.root", "recreate");
308 
309  TH2F barreletamap("barreletamap", "barreletamap", 171, -85, 86, 100, 0., 2.);
310  TH2F barreletamapraw("barreletamapraw", "barreletamapraw", 171, -85, 86, 100, 0., 2.);
311 
312  TH2F barrelmapold("barrelmapold", "barrelmapold", 360, 1., 361., 171, -85., 86.);
313  TH2F barrelmapnew("barrelmapnew", "barrelmapnew", 360, 1., 361., 171, -85., 86.);
314  TH2F barrelmapratio("barrelmapratio", "barrelmapratio", 360, 1., 361., 171, -85., 86.);
315 
316  TH1F rawconst_endc_h("rawconst_endc", "rawconst_endc", 100, 0., 2.);
317  TH1F const_endc_h("const_endc", "const_endc", 100, 0., 2.);
318 
319  TH1F oldconst_endc_h("oldconst_endc", "oldconst_endc;oldCalib;", 200, 0, 2);
320  TH2F newvsraw_endc_h("newvsraw_endc", "newvsraw_endc;rawConst;newCalib", 200, 0, 2, 200, 0, 2);
321 
322  TH2F endcapmapold_plus("endcapmapold_plus", "endcapmapold_plus", 100, 1., 101., 100, 1., 101.);
323  TH2F endcapmapnew_plus("endcapmapnew_plus", "endcapmapnew_plus", 100, 1., 101., 100, 1., 101.);
324  TH2F endcapmapratio_plus("endcapmapratio_plus", "endcapmapratio_plus", 100, 1., 101., 100, 1., 101.);
325 
326  TH2F endcapmapold_minus("endcapmapold_minus", "endcapmapold_minus", 100, 1., 101., 100, 1., 101.);
327  TH2F endcapmapnew_minus("endcapmapnew_minus", "endcapmapnew_minus", 100, 1., 101., 100, 1., 101.);
328  TH2F endcapmapratio_minus("endcapmapratio_minus", "endcapmapratio_minus", 100, 1., 101., 100, 1., 101.);
329 
330  for (int sign = 0; sign < kSides; sign++) {
331  int thesign = sign == 1 ? 1 : -1;
332 
333  for (int ieta = 0; ieta < kBarlRings; ieta++) {
334  for (int iphi = 0; iphi < kBarlWedges; iphi++) {
335  if (e_.goodCell_barl[ieta][iphi][sign]) {
336  EBDetId eb(thesign * (ieta + 1), iphi + 1);
337  //int mod20= (iphi+1)%20;
338  //if (mod20==0 || mod20==1 ||mod20==2) continue; // exclude SM boundaries
339  barreletamap.Fill(ieta * thesign + thesign, newCalibs_[eb]);
340  barreletamapraw.Fill(ieta * thesign + thesign, rawconst_barl[ieta][iphi][sign]);
341 
342  barrelmapold.Fill(iphi + 1, ieta * thesign + thesign, oldCalibs_[eb]);
343  barrelmapnew.Fill(iphi + 1, ieta * thesign + thesign, newCalibs_[eb]);
344  barrelmapratio.Fill(iphi + 1, ieta * thesign + thesign, newCalibs_[eb] / oldCalibs_[eb]);
345  } //if
346  } //iphi
347  } //ieta
348 
349  for (int ix = 0; ix < kEndcWedgesX; ix++) {
350  for (int iy = 0; iy < kEndcWedgesY; iy++) {
351  if (e_.goodCell_endc[ix][iy][sign]) {
352  if (!EEDetId::validDetId(ix + 1, iy + 1, thesign))
353  continue;
354  EEDetId ee(ix + 1, iy + 1, thesign);
355 
356  rawconst_endc_h.Fill(rawconst_endc[ix][iy][sign]);
357  const_endc_h.Fill(newCalibs_[ee]);
358  oldconst_endc_h.Fill(oldCalibs_[ee]);
359  newvsraw_endc_h.Fill(rawconst_endc[ix][iy][sign], newCalibs_[ee]);
360 
361  if (sign == 1) {
362  endcapmapold_plus.Fill(ix + 1, iy + 1, oldCalibs_[ee]);
363  endcapmapnew_plus.Fill(ix + 1, iy + 1, newCalibs_[ee]);
364  endcapmapratio_plus.Fill(ix + 1, iy + 1, newCalibs_[ee] / oldCalibs_[ee]);
365  } else {
366  endcapmapold_minus.Fill(ix + 1, iy + 1, oldCalibs_[ee]);
367  endcapmapnew_minus.Fill(ix + 1, iy + 1, newCalibs_[ee]);
368  endcapmapratio_minus.Fill(ix + 1, iy + 1, newCalibs_[ee] / oldCalibs_[ee]);
369  }
370 
371  } //if
372  } //iy
373  } //ix
374 
375  } // sides
376 
377  barreletamap.Write();
378  barreletamapraw.Write();
379  rawconst_endc_h.Write();
380  const_endc_h.Write();
381  oldconst_endc_h.Write();
382  newvsraw_endc_h.Write();
383  barrelmapold.Write();
384  barrelmapnew.Write();
385  barrelmapratio.Write();
386  endcapmapold_plus.Write();
387  endcapmapnew_plus.Write();
388  endcapmapratio_plus.Write();
389  endcapmapold_minus.Write();
390  endcapmapnew_minus.Write();
391  endcapmapratio_minus.Write();
392 
393  f.Close();
394 }
395 
396 //_____________________________________________________________________________
397 
399  TFile f("PhiSymmetryCalibration.root", "recreate");
400 
401  std::vector<TH1F*> etsum_barl_histos(kBarlRings);
402  std::vector<TH1F*> esum_barl_histos(kBarlRings);
403 
404  // determine ranges of ET sums to get histo bounds and book histos (barrel)
405  for (int ieta = 0; ieta < kBarlRings; ieta++) {
406  float low = 999999.;
407  float high = 0.;
408  float low_e = 999999.;
409  float high_e = 0.;
410 
411  for (int iphi = 0; iphi < kBarlWedges; iphi++) {
412  for (int sign = 0; sign < kSides; sign++) {
413  float etsum = etsum_barl_[ieta][iphi][sign];
414  if (etsum < low && etsum != 0.)
415  low = etsum;
416  if (etsum > high)
417  high = etsum;
418 
419  float esum = esum_barl_[ieta][iphi][sign];
420  if (esum < low_e && esum != 0.)
421  low_e = esum;
422  if (esum > high_e)
423  high_e = esum;
424  }
425  }
426 
427  ostringstream t;
428  t << "etsum_barl_" << ieta + 1;
429  etsum_barl_histos[ieta] = new TH1F(t.str().c_str(), "", 50, low - .2 * low, high + .1 * high);
430  t.str("");
431 
432  t << "esum_barl_" << ieta + 1;
433  esum_barl_histos[ieta] = new TH1F(t.str().c_str(), "", 50, low_e - .2 * low_e, high_e + .1 * high_e);
434  t.str("");
435 
436  // fill barrel ET sum histos
437  etsumMean_barl_[ieta] = 0.;
438  esumMean_barl_[ieta] = 0.;
439 
440  for (int iphi = 0; iphi < kBarlWedges; iphi++) {
441  for (int sign = 0; sign < kSides; sign++) {
442  // mean for the SC
443  int iphi_r = int(iphi / nscx);
444 
445  if (!(iphi % nscx)) {
446  // bad channel correction
447  etsum_barl_SM_[ieta][iphi_r][sign] =
448  etsum_barl_SM_[ieta][iphi_r][sign] * nscx / (nscx - nBads_barl_SM_[ieta][iphi_r][sign]);
449  // std::cout << "ETSUM M " << ieta << " " << iphi_r << " " <<
450  // sign << " " << etsum_barl_SM_[ieta][iphi_r][sign] << " " << nBads_barl_SM_[ieta][iphi_r][sign]<< endl;
451  etsumMean_barl_SM_[ieta] += etsum_barl_SM_[ieta][iphi_r][sign] / (2 * int(kBarlWedges / nscx));
452  }
453  if (e_.goodCell_barl[ieta][iphi][sign]) {
454  float etsum = etsum_barl_[ieta][iphi][sign];
455  float esum = esum_barl_[ieta][iphi][sign];
456  etsum_barl_histos[ieta]->Fill(etsum);
457  esum_barl_histos[ieta]->Fill(esum);
458  etsumMean_barl_[ieta] += etsum;
459 
460  esumMean_barl_[ieta] += esum;
461  }
462  }
463  }
464 
465  etsum_barl_histos[ieta]->Write();
466  esum_barl_histos[ieta]->Write();
467  etsumMean_barl_[ieta] /= (720. - e_.nBads_barl[ieta]);
468  esumMean_barl_[ieta] /= (720. - e_.nBads_barl[ieta]);
469 
470  delete etsum_barl_histos[ieta];
471  delete esum_barl_histos[ieta]; //VS
472  }
473 
474  std::vector<TH1F*> etsum_endc_histos(kEndcEtaRings);
475  std::vector<TH1F*> etsum_endc_uncorr_histos(kEndcEtaRings);
476  std::vector<TH1F*> esum_endc_histos(kEndcEtaRings);
477 
478  std::vector<TH2F*> etsumvsarea_endc_histos(kEndcEtaRings);
479  std::vector<TH2F*> esumvsarea_endc_histos(kEndcEtaRings);
480 
481  // determine ranges of ET sums to get histo bounds and book histos (endcap)
482  for (int ring = 0; ring < kEndcEtaRings; ring++) {
483  float low = FLT_MAX;
484  float low_uncorr = FLT_MAX;
485  float high = 0.;
486  float high_uncorr = 0;
487  float low_e = FLT_MAX;
488  float high_e = 0.;
489  float low_a = 1.;
490  float high_a = 0.;
491  for (int ix = 0; ix < kEndcWedgesX; ix++) {
492  for (int iy = 0; iy < kEndcWedgesY; iy++) {
493  if (e_.endcapRing_[ix][iy] == ring) {
494  for (int sign = 0; sign < kSides; sign++) {
495  float etsum = etsum_endc_[ix][iy][sign];
496  if (etsum < low && etsum != 0.)
497  low = etsum;
498  if (etsum > high)
499  high = etsum;
500 
501  float etsum_uncorr = etsum_endc_uncorr[ix][iy][sign];
502  if (etsum_uncorr < low_uncorr && etsum_uncorr != 0.)
503  low_uncorr = etsum_uncorr;
504  if (etsum_uncorr > high_uncorr)
505  high_uncorr = etsum_uncorr;
506 
507  float esum = esum_endc_[ix][iy][sign];
508  if (esum < low_e && esum != 0.)
509  low_e = esum;
510  if (esum > high_e)
511  high_e = esum;
512 
513  float area = e_.cellArea_[ix][iy];
514  if (area < low_a)
515  low_a = area;
516  if (area > high_a)
517  high_a = area;
518  }
519  }
520  }
521  }
522 
523  ostringstream t;
524  t << "etsum_endc_" << ring + 1;
525  etsum_endc_histos[ring] = new TH1F(t.str().c_str(), "", 50, low - .2 * low, high + .1 * high);
526  t.str("");
527 
528  t << "etsum_endc_uncorr_" << ring + 1;
529  etsum_endc_uncorr_histos[ring] =
530  new TH1F(t.str().c_str(), "", 50, low_uncorr - .2 * low_uncorr, high_uncorr + .1 * high_uncorr);
531  t.str("");
532 
533  t << "esum_endc_" << ring + 1;
534  esum_endc_histos[ring] = new TH1F(t.str().c_str(), "", 50, low_e - .2 * low_e, high_e + .1 * high_e);
535  t.str("");
536 
537  t << "etsumvsarea_endc_" << ring + 1;
538  etsumvsarea_endc_histos[ring] =
539  new TH2F(t.str().c_str(), ";A_{#eta#phi};#Sigma E_{T}", 50, low_a, high_a, 50, low, high);
540  t.str("");
541 
542  t << "esumvsarea_endc_" << ring + 1;
543  esumvsarea_endc_histos[ring] =
544  new TH2F(t.str().c_str(), ";A_{#eta#phi};#Sigma E", 50, low_a, high_a, 50, low_e, high_e);
545  t.str("");
546 
547  // fill endcap ET sum histos
548  etsumMean_endc_[ring] = 0.;
549  esumMean_endc_[ring] = 0.;
550  for (int ix = 0; ix < kEndcWedgesX; ix++) {
551  for (int iy = 0; iy < kEndcWedgesY; iy++) {
552  if (e_.endcapRing_[ix][iy] == ring) {
553  for (int sign = 0; sign < kSides; sign++) {
554  if (e_.goodCell_endc[ix][iy][sign]) {
555  float etsum = etsum_endc_[ix][iy][sign];
556  float esum = esum_endc_[ix][iy][sign];
557  float etsum_uncorr = etsum_endc_uncorr[ix][iy][sign];
558  etsum_endc_histos[ring]->Fill(etsum);
559  etsum_endc_uncorr_histos[ring]->Fill(etsum_uncorr);
560  esum_endc_histos[ring]->Fill(esum);
561 
562  float area = e_.cellArea_[ix][iy];
563  etsumvsarea_endc_histos[ring]->Fill(area, etsum);
564  esumvsarea_endc_histos[ring]->Fill(area, esum);
565 
566  etsumMean_endc_[ring] += etsum;
567  esumMean_endc_[ring] += esum;
568  }
569  }
570  }
571  }
572  }
573 
574  etsum_endc_histos[ring]->Write();
575  etsum_endc_uncorr_histos[ring]->Write();
576  esum_endc_histos[ring]->Write();
577  etsumMean_endc_[ring] /= (float(e_.nRing_[ring] * 2 - e_.nBads_endc[ring]));
578  esumMean_endc_[ring] /= (float(e_.nRing_[ring] * 2 - e_.nBads_endc[ring]));
579  etsumvsarea_endc_histos[ring]->Write();
580  esumvsarea_endc_histos[ring]->Write();
581 
582  delete etsum_endc_histos[ring];
583  delete etsum_endc_uncorr_histos[ring];
584  delete esum_endc_histos[ring];
585  delete etsumvsarea_endc_histos[ring];
586  delete esumvsarea_endc_histos[ring];
587  } //ring
588 
589  // Maps of etsum in EB and EE
590  TH2F barreletamap("barreletamap", "barreletamap", 171, -85, 86, 100, 0, 2);
591  TH2F barrelmap("barrelmap", "barrelmap - #frac{#Sigma E_{T}}{<#Sigma E_{T}>_{0}}", 360, 1, 360, 171, -85, 86);
592  TH2F barrelmap_e("barrelmape", "barrelmape - #frac{#Sigma E}{<#Sigma E>_{0}}", 360, 1, 360, 171, -85, 86);
593  TH2F barrelmap_divided("barrelmapdiv", "barrelmapdivided - #frac{#Sigma E_{T}}{hits}", 360, 1, 360, 171, -85, 86);
594  TH2F barrelmap_e_divided("barrelmapediv", "barrelmapedivided - #frac{#Sigma E}{hits}", 360, 1, 360, 171, -85, 86);
595  TH2F endcmap_plus_corr(
596  "endcapmapplus_corrected", "endcapmapplus - #frac{#Sigma E_{T}}{<#Sigma E_{T}>_{38}}", 100, 1, 101, 100, 1, 101);
597  TH2F endcmap_minus_corr(
598  "endcapmapminus_corrected", "endcapmapminus - #frac{#Sigma E_{T}}{<#Sigma E_{T}>_{38}}", 100, 1, 101, 100, 1, 101);
599  TH2F endcmap_plus_uncorr("endcapmapplus_uncorrected",
600  "endcapmapplus_uncor - #frac{#Sigma E_{T}}{<#Sigma E_{T}>_{38}}",
601  100,
602  1,
603  101,
604  100,
605  1,
606  101);
607  TH2F endcmap_minus_uncorr("endcapmapminus_uncorrected",
608  "endcapmapminus_uncor - #frac{#Sigma E_{T}}{<#Sigma E_{T}>_{38}}",
609  100,
610  1,
611  101,
612  100,
613  1,
614  101);
615  TH2F endcmap_e_plus("endcapmapeplus", "endcapmapeplus - #frac{#Sigma E}{<#Sigma E>_{38}}", 100, 1, 101, 100, 1, 101);
616  TH2F endcmap_e_minus(
617  "endcapmapeminus", "endcapmapeminus - #frac{#Sigma E}{<#Sigma E>_{38}}", 100, 1, 101, 100, 1, 101);
618 
619  for (int sign = 0; sign < kSides; sign++) {
620  int thesign = sign == 1 ? 1 : -1;
621 
622  for (int ieta = 0; ieta < kBarlRings; ieta++) {
623  for (int iphi = 0; iphi < kBarlWedges; iphi++) {
624  if (e_.goodCell_barl[ieta][iphi][sign]) {
625  barrelmap.Fill(iphi + 1, ieta * thesign + thesign, etsum_barl_[ieta][iphi][sign] / etsumMean_barl_[0]);
626  barrelmap_e.Fill(iphi + 1, ieta * thesign + thesign, esum_barl_[ieta][iphi][sign] / esumMean_barl_[0]); //VS
627  if (!nhits_barl_[ieta][iphi][sign])
628  nhits_barl_[ieta][iphi][sign] = 1;
629  barrelmap_divided.Fill(
630  iphi + 1, ieta * thesign + thesign, etsum_barl_[ieta][iphi][sign] / nhits_barl_[ieta][iphi][sign]);
631  barrelmap_e_divided.Fill(
632  iphi + 1, ieta * thesign + thesign, esum_barl_[ieta][iphi][sign] / nhits_barl_[ieta][iphi][sign]); //VS
633  //int mod20= (iphi+1)%20;
634  //if (mod20==0 || mod20==1 ||mod20==2) continue; // exclude SM boundaries
635  barreletamap.Fill(ieta * thesign + thesign, etsum_barl_[ieta][iphi][sign] / etsumMean_barl_[0]);
636  } //if
637  } //iphi
638  } //ieta
639 
640  for (int ix = 0; ix < kEndcWedgesX; ix++) {
641  for (int iy = 0; iy < kEndcWedgesY; iy++) {
642  if (sign == 1) {
643  endcmap_plus_corr.Fill(ix + 1, iy + 1, etsum_endc_[ix][iy][sign] / etsumMean_endc_[38]);
644  endcmap_plus_uncorr.Fill(ix + 1, iy + 1, etsum_endc_uncorr[ix][iy][sign] / etsumMean_endc_[38]);
645  endcmap_e_plus.Fill(ix + 1, iy + 1, esum_endc_[ix][iy][sign] / esumMean_endc_[38]);
646  } else {
647  endcmap_minus_corr.Fill(ix + 1, iy + 1, etsum_endc_[ix][iy][sign] / etsumMean_endc_[38]);
648  endcmap_minus_uncorr.Fill(ix + 1, iy + 1, etsum_endc_uncorr[ix][iy][sign] / etsumMean_endc_[38]);
649  endcmap_e_minus.Fill(ix + 1, iy + 1, esum_endc_[ix][iy][sign] / esumMean_endc_[38]);
650  }
651  } //iy
652  } //ix
653 
654  } //sign
655 
656  barreletamap.Write();
657  barrelmap_divided.Write();
658  barrelmap.Write();
659  barrelmap_e_divided.Write();
660  barrelmap_e.Write();
661  endcmap_plus_corr.Write();
662  endcmap_minus_corr.Write();
663  endcmap_plus_uncorr.Write();
664  endcmap_minus_uncorr.Write();
665  endcmap_e_plus.Write();
666  endcmap_e_minus.Write();
667 
668  vector<TH1F*> etavsphi_endc(kEndcEtaRings);
669  vector<TH1F*> areavsphi_endc(kEndcEtaRings);
670  vector<TH1F*> etsumvsphi_endcp_corr(kEndcEtaRings);
671  vector<TH1F*> etsumvsphi_endcm_corr(kEndcEtaRings);
672  vector<TH1F*> etsumvsphi_endcp_uncorr(kEndcEtaRings);
673  vector<TH1F*> etsumvsphi_endcm_uncorr(kEndcEtaRings);
674  vector<TH1F*> esumvsphi_endcp(kEndcEtaRings);
675  vector<TH1F*> esumvsphi_endcm(kEndcEtaRings);
676 
677  std::vector<TH1F*> deltaeta_histos(kEndcEtaRings);
678  std::vector<TH1F*> deltaphi_histos(kEndcEtaRings);
679 
680  for (int ring = 0; ring < kEndcEtaRings; ++ring) {
681  ostringstream t;
682  t << "etavsphi_endc_" << ring;
683  etavsphi_endc[ring] = new TH1F(t.str().c_str(), t.str().c_str(), e_.nRing_[ring], 0, e_.nRing_[ring]);
684  t.str("");
685 
686  t << "areavsphi_endc_" << ring;
687  areavsphi_endc[ring] = new TH1F(t.str().c_str(), t.str().c_str(), e_.nRing_[ring], 0, e_.nRing_[ring]);
688  t.str("");
689 
690  t << "etsumvsphi_endcp_corr_" << ring;
691  etsumvsphi_endcp_corr[ring] = new TH1F(t.str().c_str(), t.str().c_str(), e_.nRing_[ring], 0, e_.nRing_[ring]);
692  t.str("");
693 
694  t << "etsumvsphi_endcm_corr_" << ring;
695  etsumvsphi_endcm_corr[ring] = new TH1F(t.str().c_str(), t.str().c_str(), e_.nRing_[ring], 0, e_.nRing_[ring]);
696  t.str("");
697 
698  t << "etsumvsphi_endcp_uncorr_" << ring;
699  etsumvsphi_endcp_uncorr[ring] = new TH1F(t.str().c_str(), t.str().c_str(), e_.nRing_[ring], 0, e_.nRing_[ring]);
700  t.str("");
701 
702  t << "etsumvsphi_endcm_uncorr_" << ring;
703  etsumvsphi_endcm_uncorr[ring] = new TH1F(t.str().c_str(), t.str().c_str(), e_.nRing_[ring], 0, e_.nRing_[ring]);
704  t.str("");
705 
706  t << "esumvsphi_endcp_" << ring;
707  esumvsphi_endcp[ring] = new TH1F(t.str().c_str(), t.str().c_str(), e_.nRing_[ring], 0, e_.nRing_[ring]);
708  t.str("");
709 
710  t << "esumvsphi_endcm_" << ring;
711  esumvsphi_endcm[ring] = new TH1F(t.str().c_str(), t.str().c_str(), e_.nRing_[ring], 0, e_.nRing_[ring]);
712  t.str("");
713 
714  t << "deltaeta_" << ring;
715  deltaeta_histos[ring] = new TH1F(t.str().c_str(), "", 50, -.1, .1);
716  t.str("");
717  t << "deltaphi_" << ring;
718  deltaphi_histos[ring] = new TH1F(t.str().c_str(), "", 50, -.1, .1);
719  t.str("");
720  }
721 
722  for (int ix = 0; ix < kEndcWedgesX; ix++) {
723  for (int iy = 0; iy < kEndcWedgesY; iy++) {
724  int ring = e_.endcapRing_[ix][iy];
725  if (ring != -1) {
726  int iphi_endc = -1;
727  for (int ip = 0; ip < e_.nRing_[ring]; ip++) {
728  if (e_.cellPhi_[ix][iy] == e_.phi_endc_[ip][ring])
729  iphi_endc = ip;
730  }
731 
732  if (iphi_endc != -1) {
733  for (int sign = 0; sign < kSides; sign++) {
734  if (e_.goodCell_endc[ix][iy][sign]) {
735  if (sign == 1) {
736  etsumvsphi_endcp_corr[ring]->Fill(iphi_endc, etsum_endc_[ix][iy][sign]);
737  etsumvsphi_endcp_uncorr[ring]->Fill(iphi_endc, etsum_endc_uncorr[ix][iy][sign]);
738  esumvsphi_endcp[ring]->Fill(iphi_endc, esum_endc_[ix][iy][sign]);
739  } else {
740  etsumvsphi_endcm_corr[ring]->Fill(iphi_endc, etsum_endc_[ix][iy][sign]);
741  etsumvsphi_endcm_uncorr[ring]->Fill(iphi_endc, etsum_endc_uncorr[ix][iy][sign]);
742  esumvsphi_endcm[ring]->Fill(iphi_endc, esum_endc_[ix][iy][sign]);
743  }
744  } //if
745  } //sign
746  etavsphi_endc[ring]->Fill(iphi_endc, e_.cellPos_[ix][iy].eta());
747  areavsphi_endc[ring]->Fill(iphi_endc, e_.cellArea_[ix][iy]);
748  } //if iphi_endc
749 
750  } //if ring
751  } //iy
752  } //ix
753 
754  for (int ring = 0; ring < kEndcEtaRings; ++ring) {
755  etavsphi_endc[ring]->Write();
756  areavsphi_endc[ring]->Write();
757  etsumvsphi_endcp_corr[ring]->Write();
758  etsumvsphi_endcm_corr[ring]->Write();
759  etsumvsphi_endcp_uncorr[ring]->Write();
760  etsumvsphi_endcm_uncorr[ring]->Write();
761  esumvsphi_endcp[ring]->Write();
762  esumvsphi_endcm[ring]->Write();
763  deltaeta_histos[ring]->Write();
764  deltaphi_histos[ring]->Write();
765 
766  delete etsumvsphi_endcp_corr[ring];
767  delete etsumvsphi_endcm_corr[ring];
768  delete etsumvsphi_endcp_uncorr[ring];
769  delete etsumvsphi_endcm_uncorr[ring];
770  delete etavsphi_endc[ring];
771  delete areavsphi_endc[ring];
772  delete esumvsphi_endcp[ring];
773  delete esumvsphi_endcm[ring];
774  delete deltaeta_histos[ring];
775  delete deltaphi_histos[ring];
776  }
777 
778  f.Close();
779 }
780 
782  //read in ET sums
783 
784  int ieta, iphi, sign, ix, iy, dummy;
785  double etsum;
786  unsigned int nhits;
787  std::ifstream etsum_barl_in("etsum_barl.dat", ios::in);
788  while (etsum_barl_in >> dummy >> ieta >> iphi >> sign >> etsum >> nhits) {
789  etsum_barl_[ieta][iphi][sign] += etsum;
790  nhits_barl_[ieta][iphi][sign] += nhits;
791 
792  // fill etsums for the SM calibration
793  int iphi_r = int(iphi / nscx);
794  etsum_barl_SM_[ieta][iphi_r][sign] += etsum;
795  // etsum*nscx/(nscx- nBads_barl_SM_[ieta][iphi_r][sign]);
796  // if(nBads_barl_SM_[ieta][iphi_r][sign]>0){
797  // std::cout << "ETSUM" << etsum_barl_SM_[ieta][iphi_r][sign] << " " << nscx << " " << nBads_barl_SM_[ieta][iphi_r][sign]<< endl;
798  // }
799  }
800 
801  std::ifstream etsum_endc_in("etsum_endc.dat", ios::in);
802  while (etsum_endc_in >> dummy >> ix >> iy >> sign >> etsum >> nhits >> dummy) {
803  etsum_endc_[ix][iy][sign] += etsum;
804  nhits_endc_[ix][iy][sign] += nhits;
805  }
806 
807  std::ifstream k_barl_in("k_barl.dat", ios::in);
808  for (int ieta = 0; ieta < kBarlRings; ieta++) {
809  k_barl_in >> dummy >> k_barl_[ieta];
810  }
811 
812  std::ifstream k_endc_in("k_endc.dat", ios::in);
813  for (int ring = 0; ring < kEndcEtaRings; ring++) {
814  k_endc_in >> dummy >> k_endc_[ring];
815  }
816 }
817 
821 
822  for (int ieta = 0; ieta < kBarlRings; ieta++) {
823  ostringstream t1;
824  t1 << "mr_barl_" << ieta + 1;
825  miscal_resid_barl_histos[ieta] = new TH1F(t1.str().c_str(), "", 100, 0., 2.);
826  ostringstream t2;
827  t2 << "co_barl_" << ieta + 1;
828  correl_barl_histos[ieta] = new TH2F(t2.str().c_str(), "", 50, .5, 1.5, 50, .5, 1.5);
829  }
830 
833 
834  for (int ring = 0; ring < kEndcEtaRings; ring++) {
835  ostringstream t1;
836  t1 << "mr_endc_" << ring + 1;
837  miscal_resid_endc_histos[ring] = new TH1F(t1.str().c_str(), "", 100, 0., 2.);
838  ostringstream t2;
839  t2 << "co_endc_" << ring + 1;
840  correl_endc_histos[ring] = new TH2F(t2.str().c_str(), "", 50, .5, 1.5, 50, .5, 1.5);
841  }
842 }
843 
845  // output histograms of residual miscalibrations
846  TFile f("PhiSymmetryCalibration_miscal_resid.root", "recreate");
847  for (int ieta = 0; ieta < 85; ieta++) {
848  miscal_resid_barl_histos[ieta]->Write();
849  correl_barl_histos[ieta]->Write();
850 
851  delete miscal_resid_barl_histos[ieta];
852  delete correl_barl_histos[ieta];
853  }
854 
855  for (int ring = 0; ring < 39; ring++) {
856  miscal_resid_endc_histos[ring]->Write();
857  correl_endc_histos[ring]->Write();
858 
860  delete correl_endc_histos[ring];
861  }
862  f.Close();
863 }
std::string datasource_
tuple ret
prodAgent to be discontinued
static int writeXML(const std::string &filename, const EcalCondHeader &header, const EcalFloatCondObjectContainer &record)
cond::Time_t since_
void setup(const CaloGeometry *geometry, const EcalChannelStatus *chstatus, int statusThreshold)
int ix() const
Definition: EEDetId.h:77
EcalIntercalibConstants miscalib_
initial miscalibration applied if any)
double etsum_barl_[kBarlRings][kBarlWedges][kSides]
int nRing_[kEndcEtaRings]
PhiSymmetryCalibration_step2_SM(const edm::ParameterSet &iConfig)
std::string date_
int nBads_endc[kEndcEtaRings]
static const int kBarlRings
bool goodCell_barl[kBarlRings][kBarlWedges][kSides]
double sign(double x)
unsigned int nhits_endc_[kEndcWedgesX][kEndcWedgesX][kSides]
std::string version_
GlobalPoint cellPos_[kEndcWedgesX][kEndcWedgesY]
double etsum_barl_SM_[kBarlRings][int(kBarlWedges/nscx)][kSides]
bool ev
static const int kSides
Log< level::Error, false > LogError
float epsilon_M_barl[kBarlRings][kBarlWedges][kSides]
int nBads_barl_SM_[kBarlRings][int(kBarlWedges/nscx)][kSides]
double phi_endc_[kMaxEndciPhi][kEndcEtaRings]
static int readXML(const std::string &filename, EcalCondHeader &header, EcalFloatCondObjectContainer &record)
int iphi() const
get the crystal iphi
Definition: EBDetId.h:51
static const int kBarlWedges
bool getData(T &iHolder) const
Definition: EventSetup.h:128
static const int kEndcWedgesX
int endcapRing_[kEndcWedgesX][kEndcWedgesY]
static const int kEndcEtaRings
int zside() const
Definition: EEDetId.h:71
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int iy() const
Definition: EEDetId.h:83
int ieta() const
get the crystal ieta
Definition: EBDetId.h:49
double esum_endc_[kEndcWedgesX][kEndcWedgesX][kSides]
double etsum_endc_[kEndcWedgesX][kEndcWedgesX][kSides]
std::string tag_
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > geometryToken_
double epsilon_M_barl_SM_[kBarlRings][int(kBarlWedges/nscx)][kSides]
const edm::ESGetToken< EcalChannelStatus, EcalChannelStatusRcd > channelStatusToken_
void analyze(const edm::Event &, const edm::EventSetup &) override
float epsilon_M_endc[kEndcWedgesX][kEndcWedgesY][kSides]
std::string method_
float rawconst_barl[kBarlRings][kBarlWedges][kSides]
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
void setUp(const edm::EventSetup &setup)
EcalIntercalibConstants newCalibs_
calib constants that we are going to calculate
double cellPhi_[kEndcWedgesX][kEndcWedgesY]
T eta() const
Definition: PV3DBase.h:73
EcalIntercalibConstants oldCalibs_
the old calibration constants (when reiterating, the last ones derived)
float rawconst_endc[kEndcWedgesX][kEndcWedgesX][kSides]
double cellArea_[kEndcWedgesX][kEndcWedgesY]
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
std::vector< TH1F * > miscal_resid_barl_histos
res miscalib histos
double etsum_endc_uncorr[kEndcWedgesX][kEndcWedgesX][kSides]
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
double esum_barl_[kBarlRings][kBarlWedges][kSides]
unsigned int nhits_barl_[kBarlRings][kBarlWedges][kSides]
int nBads_barl[kBarlRings]
int zside() const
get the z-side of the crystal (1/-1)
Definition: EBDetId.h:45
bool goodCell_endc[kEndcWedgesX][kEndcWedgesX][kSides]
static const int kEndcWedgesY