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