CMS 3D CMS Logo

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