CMS 3D CMS Logo

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