CMS 3D CMS Logo

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