CMS 3D CMS Logo

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