49 e_.setup(&(*geoHandle), &(*chStatus), statusThreshold_);
52 if (have_initial_miscalib_) {
54 namespace fs = std::filesystem;
57 edm::LogError(
"PhiSym") <<
"File not found: " << initialmiscalibfile_ << endl;
64 for (vector<DetId>::iterator it = barrelCells.begin(); it != barrelCells.end(); ++it) {
68 for (vector<DetId>::iterator it = endcapCells.begin(); it != endcapCells.end(); ++it) {
77 namespace fs = std::filesystem;
80 edm::LogError(
"PhiSym") <<
"File not found: " << oldcalibfile_ << endl;
89 for (vector<DetId>::iterator it = barrelCells.begin(); it != barrelCells.end(); ++it)
92 for (vector<DetId>::iterator it = endcapCells.begin(); it != endcapCells.end(); ++it)
112 etsum_endc_[ix][iy][
sign] = 0.;
113 nhits_endc_[ix][iy][
sign] = 0;
114 esum_endc_[ix][iy][
sign] = 0.;
125 edm::LogError(
"PhiSym") <<
"Must process at least one event-Exiting" << endl;
136 int ring = e_.endcapRing_[ix][iy];
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];
152 std::ofstream etsumMean_barl_out(
"etsumMean_barl.dat",
ios::out);
154 etsumMean_barl_out <<
ieta <<
" " << etsumMean_barl_[
ieta] << endl;
156 etsumMean_barl_out.close();
158 std::ofstream etsumMean_endc_out(
"etsumMean_endc.dat",
ios::out);
160 etsumMean_endc_out << e_.cellPos_[
ring][50].eta() <<
" " << etsumMean_endc_[
ring] << endl;
162 etsumMean_endc_out.close();
170 float epsilon_T = (etsum / etsumMean_barl_[
ieta]) - 1.;
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];
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.;
201 std::string newcalibfile(
"EcalIntercalibConstants_new.xml");
203 TFile ehistof(
"ehistos.root",
"recreate");
205 TH1D ebhisto(
"eb",
"eb", 100, 0., 2.);
207 std::vector<DetId>::const_iterator barrelIt = barrelCells.begin();
208 for (; barrelIt != barrelCells.end(); barrelIt++) {
216 newCalibs_[eb] = oldCalibs_[eb] / (1 + epsilon_M_barl[
ieta][
iphi][
sign]);
219 ebhisto.Fill(newCalibs_[eb]);
222 miscal_resid_barl_histos[
ieta]->Fill(miscalib_[eb] * newCalibs_[eb]);
223 correl_barl_histos[
ieta]->Fill(miscalib_[eb], newCalibs_[eb]);
228 TH1D eehisto(
"ee",
"ee", 100, 0., 2.);
229 std::vector<DetId>::const_iterator endcapIt = endcapCells.begin();
231 for (; endcapIt != endcapCells.end(); endcapIt++) {
233 int ix = ee.
ix() - 1;
234 int iy = ee.
iy() - 1;
237 newCalibs_[ee] = oldCalibs_[ee] / (1 + epsilon_M_endc[ix][iy][
sign]);
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]);
244 correl_endc_histos[e_.endcapRing_[ix][iy]]->Fill(miscalib_[ee], newCalibs_[ee]);
249 header.method_ =
"phi symmetry";
251 header.datasource_ =
"testdata";
254 header.date_ =
"Mar 24 1973";
262 fillConstantsHistos();
267 std::fstream ebf(
"etsummary_barl.dat",
ios::out);
268 std::fstream eef(
"etsummary_endc.dat",
ios::out);
281 eef << ix <<
" " << iy <<
" " <<
sign <<
" " << etsum_endc_[ix][iy][
sign] << endl;
288 TFile
f(
"CalibHistos.root",
"recreate");
290 TH2F barreletamap(
"barreletamap",
"barreletamap", 171, -85, 86, 100, 0., 2.);
291 TH2F barreletamapraw(
"barreletamapraw",
"barreletamapraw", 171, -85, 86, 100, 0., 2.);
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.);
297 TH1F rawconst_endc_h(
"rawconst_endc",
"rawconst_endc", 100, 0., 2.);
298 TH1F const_endc_h(
"const_endc",
"const_endc", 100, 0., 2.);
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);
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.);
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.);
312 int thesign =
sign == 1 ? 1 : -1;
320 barreletamap.Fill(
ieta * thesign + thesign, newCalibs_[eb]);
321 barreletamapraw.Fill(
ieta * thesign + thesign, rawconst_barl[
ieta][
iphi][
sign]);
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]);
332 if (e_.goodCell_endc[ix][iy][
sign]) {
335 EEDetId ee(ix + 1, iy + 1, thesign);
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]);
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]);
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]);
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();
380 TFile
f(
"PhiSymmetryCalibration.root",
"recreate");
382 std::vector<TH1F*> etsum_barl_histos(
kBarlRings);
383 std::vector<TH1F*> esum_barl_histos(
kBarlRings);
389 float low_e = 999999.;
395 if (etsum <
low && etsum != 0.)
401 if (esum < low_e && esum != 0.)
409 t <<
"etsum_barl_" <<
ieta + 1;
410 etsum_barl_histos[
ieta] =
new TH1F(
t.str().c_str(),
"", 50,
low - .2 *
low,
high + .1 *
high);
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);
418 etsumMean_barl_[
ieta] = 0.;
419 esumMean_barl_[
ieta] = 0.;
425 etsum_barl_histos[
ieta]->Fill(etsum);
426 esum_barl_histos[
ieta]->Fill(esum);
427 etsumMean_barl_[
ieta] += etsum;
428 esumMean_barl_[
ieta] += esum;
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];
451 float low_uncorr = FLT_MAX;
453 float high_uncorr = 0;
454 float low_e = FLT_MAX;
460 if (e_.endcapRing_[ix][iy] ==
ring) {
462 float etsum = etsum_endc_[ix][iy][
sign];
463 if (etsum <
low && etsum != 0.)
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;
474 float esum = esum_endc_[ix][iy][
sign];
475 if (esum < low_e && esum != 0.)
480 float area = e_.cellArea_[ix][iy];
491 t <<
"etsum_endc_" <<
ring + 1;
492 etsum_endc_histos[
ring] =
new TH1F(
t.str().c_str(),
"", 50,
low - .2 *
low,
high + .1 *
high);
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);
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);
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);
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);
515 etsumMean_endc_[
ring] = 0.;
516 esumMean_endc_[
ring] = 0.;
519 if (e_.endcapRing_[ix][iy] ==
ring) {
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);
529 float area = e_.cellArea_[ix][iy];
530 etsumvsarea_endc_histos[
ring]->Fill(
area, etsum);
531 esumvsarea_endc_histos[
ring]->Fill(
area, esum);
533 etsumMean_endc_[
ring] += etsum;
534 esumMean_endc_[
ring] += esum;
541 etsum_endc_histos[
ring]->Write();
542 etsum_endc_uncorr_histos[
ring]->Write();
543 esum_endc_histos[
ring]->Write();
546 etsumvsarea_endc_histos[
ring]->Write();
547 esumvsarea_endc_histos[
ring]->Write();
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];
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}}",
574 TH2F endcmap_minus_uncorr(
"endcapmapminus_uncorrected",
575 "endcapmapminus_uncor - #frac{#Sigma E_{T}}{<#Sigma E_{T}>_{38}}",
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);
587 int thesign =
sign == 1 ? 1 : -1;
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]);
596 barrelmap_divided.Fill(
598 barrelmap_e_divided.Fill(
602 barreletamap.Fill(
ieta * thesign + thesign, etsum_barl_[
ieta][
iphi][
sign] / etsumMean_barl_[0]);
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]);
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]);
623 barreletamap.Write();
624 barrelmap_divided.Write();
626 barrelmap_e_divided.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();
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]);
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]);
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]);
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]);
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]);
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]);
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]);
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]);
681 t <<
"deltaeta_" <<
ring;
682 deltaeta_histos[
ring] =
new TH1F(
t.str().c_str(),
"", 50, -.1, .1);
684 t <<
"deltaphi_" <<
ring;
685 deltaphi_histos[
ring] =
new TH1F(
t.str().c_str(),
"", 50, -.1, .1);
691 int ring = e_.endcapRing_[ix][iy];
694 for (
int ip = 0; ip < e_.nRing_[
ring]; ip++) {
695 if (e_.cellPhi_[ix][iy] == e_.phi_endc_[ip][
ring])
699 if (iphi_endc != -1) {
701 if (e_.goodCell_endc[ix][iy][
sign]) {
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]);
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]);
713 etavsphi_endc[
ring]->Fill(iphi_endc, e_.cellPos_[ix][iy].eta());
714 areavsphi_endc[
ring]->Fill(iphi_endc, e_.cellArea_[ix][iy]);
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();
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];
754 std::ifstream etsum_barl_in(
"etsum_barl.dat",
ios::in);
760 std::ifstream etsum_endc_in(
"etsum_endc.dat",
ios::in);
762 etsum_endc_[ix][iy][
sign] += etsum;
766 std::ifstream k_barl_in(
"k_barl.dat",
ios::in);
771 std::ifstream k_endc_in(
"k_endc.dat",
ios::in);
783 t1 <<
"mr_barl_" <<
ieta + 1;
784 miscal_resid_barl_histos[
ieta] =
new TH1F(
t1.str().c_str(),
"", 100, 0., 2.);
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);
795 t1 <<
"mr_endc_" <<
ring + 1;
796 miscal_resid_endc_histos[
ring] =
new TH1F(
t1.str().c_str(),
"", 100, 0., 2.);
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);
805 TFile
f(
"PhiSymmetryCalibration_miscal_resid.root",
"recreate");
807 miscal_resid_barl_histos[
ieta]->Write();
808 correl_barl_histos[
ieta]->Write();
810 delete miscal_resid_barl_histos[
ieta];
811 delete correl_barl_histos[
ieta];
815 miscal_resid_endc_histos[
ring]->Write();
816 correl_endc_histos[
ring]->Write();
818 delete miscal_resid_endc_histos[
ring];
819 delete correl_endc_histos[
ring];