CMS 3D CMS Logo

ZeeCalibration.cc
Go to the documentation of this file.
1 #include <fstream>
2 #include <iostream>
3 #include <map>
4 #include <stdexcept>
5 #include <string>
6 #include <utility>
7 #include <vector>
8 
9 #include <TBranch.h>
10 #include <TCanvas.h>
11 #include <TF1.h>
12 #include <TFile.h>
13 #include <TGraph.h>
14 #include <TGraphErrors.h>
15 #include <TH1.h>
16 #include <TH2.h>
17 #include <TProfile.h>
18 #include <TRandom.h>
19 #include <TTree.h>
20 
21 #include <CLHEP/Vector/LorentzVector.h>
22 
62 
63 #define MZ 91.1876
64 
65 #define DEBUG 1
66 
68 #ifdef DEBUG
69  std::cout << "[ZeeCalibration] Starting the ctor" << std::endl;
70 #endif
71 
72  theMaxLoops = iConfig.getUntrackedParameter<unsigned int>("maxLoops", 0);
73 
74  wantEtaCorrection_ = iConfig.getUntrackedParameter<bool>("wantEtaCorrection", true);
75 
76  outputFileName_ = iConfig.getParameter<std::string>("outputFile");
77 
78  minInvMassCut_ = iConfig.getUntrackedParameter<double>("minInvMassCut", 70.);
79  maxInvMassCut_ = iConfig.getUntrackedParameter<double>("maxInvMassCut", 110.);
80 
81  rechitProducer_ = iConfig.getParameter<std::string>("rechitProducer");
82  rechitCollection_ = iConfig.getParameter<std::string>("rechitCollection");
83 
84  erechitProducer_ = iConfig.getParameter<std::string>("erechitProducer");
85  erechitCollection_ = iConfig.getParameter<std::string>("erechitCollection");
86 
87  scProducer_ = iConfig.getParameter<std::string>("scProducer");
88  scCollection_ = iConfig.getParameter<std::string>("scCollection");
89 
90  scIslandProducer_ = iConfig.getParameter<std::string>("scIslandProducer");
91  scIslandCollection_ = iConfig.getParameter<std::string>("scIslandCollection");
92 
93  calibMode_ = iConfig.getUntrackedParameter<std::string>("ZCalib_CalibType");
94 
95  mcProducer_ = iConfig.getUntrackedParameter<std::string>("mcProducer", "");
96 
97  electronProducer_ = iConfig.getParameter<std::string>("electronProducer");
98  electronCollection_ = iConfig.getParameter<std::string>("electronCollection");
99 
100  outputFile_ = TFile::Open(outputFileName_.c_str(), "RECREATE"); // open output file to store histograms
101 
102  myTree = new TTree("myTree", "myTree");
103  // myTree->Branch("zMass","zMass", &mass);
104  myTree->Branch("zMass", &mass4tree, "mass/F");
105  myTree->Branch("zMassDiff", &massDiff4tree, "massDiff/F");
106 
107  barrelfile_ = iConfig.getUntrackedParameter<std::string>("initialMiscalibrationBarrel", "");
108  endcapfile_ = iConfig.getUntrackedParameter<std::string>("initialMiscalibrationEndcap", "");
109 
111  iConfig.getUntrackedParameter<unsigned int>("electronSelection", 0); //option for electron selection
112 
113  etaBins_ = iConfig.getUntrackedParameter<unsigned int>("etaBins", 10);
114  etBins_ = iConfig.getUntrackedParameter<unsigned int>("etBins", 10);
115 
116  etaMin_ = iConfig.getUntrackedParameter<double>("etaMin", 0.);
117  etMin_ = iConfig.getUntrackedParameter<double>("etMin", 0.);
118  etaMax_ = iConfig.getUntrackedParameter<double>("etaMax", 3.);
119  etMax_ = iConfig.getUntrackedParameter<double>("etMax", 100.);
120 
121  // new ZeePlots("zeePlots.root");
122  // ZeePlots->bookHistos();
123 
124  //ZeeCalibrationPLots("zeeCalibPlots");
125  //ZeecaPlots->bookHistos(maxsIter);
126 
127  hlTriggerResults_ = iConfig.getParameter<edm::InputTag>("HLTriggerResults");
128 
129  theParameterSet = iConfig;
130  EcalIndexingTools* myIndexTool = nullptr;
131 
132  myIndexTool = EcalIndexingTools::getInstance();
133 
134  myIndexTool->setBinRange(etaBins_, etaMin_, etaMax_, etBins_, etMin_, etMax_);
135 
136  //creating the algorithm
138 
139  // Tell the framework what data is being produced
140  //setWhatProduced(this);
142  findingRecord<EcalIntercalibConstantsRcd>();
143 
144  for (int i = 0; i < 50; i++) {
146  loopArray[i] = -1.;
147  sigmaArray[i] = -1.;
148  sigmaErrorArray[i] = -1.;
149  }
150 
151 #ifdef DEBUG
152  std::cout << "[ZeeCalibration] Done with the ctor" << std::endl;
153 #endif
154 }
155 
157  // if (theAlgorithm_)
158  // delete theAlgorithm_;
159 }
160 
161 //_____________________________________________________________________________
162 // Produce EcalIntercalibConstants
163 std::shared_ptr<EcalIntercalibConstants> ZeeCalibration::produceEcalIntercalibConstants(
164  const EcalIntercalibConstantsRcd& iRecord) {
165  std::cout << "@SUB=ZeeCalibration::produceEcalIntercalibConstants" << std::endl;
166  return ical;
167 }
168 
170 
171 //========================================================================
173  printStatistics();
174 
175  if (calibMode_ != "ETA_ET_MODE") {
177 
178  //Writing out calibration coefficients
179  calibXMLwriter* barrelWriter = new calibXMLwriter(EcalBarrel);
180  for (int ieta = -EBDetId::MAX_IETA; ieta <= EBDetId::MAX_IETA; ++ieta) {
181  if (ieta == 0)
182  continue;
183  for (int iphi = EBDetId::MIN_IPHI; iphi <= EBDetId::MAX_IPHI; ++iphi) {
184  // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
185  if (EBDetId::validDetId(ieta, iphi)) {
186  EBDetId ebid(ieta, iphi);
187  barrelWriter->writeLine(ebid, *(ical->getMap().find(ebid.rawId())));
188  }
189  }
190  }
191 
192  calibXMLwriter* endcapWriter = new calibXMLwriter(EcalEndcap);
193  for (int iX = EEDetId::IX_MIN; iX <= EEDetId::IX_MAX; ++iX) {
194  for (int iY = EEDetId::IY_MIN; iY <= EEDetId::IY_MAX; ++iY) {
195  // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
196  if (EEDetId::validDetId(iX, iY, 1)) {
197  EEDetId eeid(iX, iY, 1);
198  endcapWriter->writeLine(eeid, *(ical->getMap().find(eeid.rawId())));
199  }
200  if (EEDetId::validDetId(iX, iY, -1)) {
201  EEDetId eeid(iX, iY, -1);
202  endcapWriter->writeLine(eeid, *(ical->getMap().find(eeid.rawId())));
203  }
204  }
205  }
206 
207  }
208 
209  std::cout << "Writing histos..." << std::endl;
210  outputFile_->cd();
211 
212  // zeeplts->Write();
213 
216 
219 
221 
225 
226  h1_electronCosTheta_SC_->Write();
227  h1_electronCosTheta_TK_->Write();
229 
230  h1_zMassResol_->Write();
231  h1_zEtaResol_->Write();
232  h1_zPhiResol_->Write();
233  h1_eleEtaResol_->Write();
234  h1_elePhiResol_->Write();
235  h1_seedOverSC_->Write();
236  h1_preshowerOverSC_->Write();
237 
238  for (unsigned int i = 0; i < 25; i++) {
239  if (i < theMaxLoops) {
240  h_ESCEtrueVsEta_[i]->Write();
241  h_ESCEtrue_[i]->Write();
242 
243  h_ESCcorrEtrueVsEta_[i]->Write();
244  h_ESCcorrEtrue_[i]->Write();
245 
246  h2_chi2_[i]->Write();
247  h2_iterations_[i]->Write();
248 
249  // h_DiffZMassDistr_[i]->Write();
250 
251  //h_ZMassDistr_[i]->Write();
252  }
253  }
254 
255  h2_fEtaBarrelGood_->Write();
256  h2_fEtaBarrelBad_->Write();
257  h2_fEtaEndcapGood_->Write();
258  h2_fEtaEndcapBad_->Write();
259  h1_eleClasses_->Write();
260 
261  h_eleEffEta_[0]->Write();
262  h_eleEffPhi_[0]->Write();
263  h_eleEffPt_[0]->Write();
264 
265  h_eleEffEta_[1]->Write();
266  h_eleEffPhi_[1]->Write();
267  h_eleEffPt_[1]->Write();
268 
269  int j = 0;
270 
271  int flag = 0;
272 
273  Double_t mean[25] = {0.};
274  Double_t num[25] = {0.};
275  Double_t meanErr[25] = {0.};
276  Float_t rms[25] = {0.};
277  Float_t tempRms[10][25];
278 
279  for (int ia = 0; ia < 10; ia++) {
280  for (int ib = 0; ib < 25; ib++) {
281  tempRms[ia][ib] = 0.;
282  }
283  }
284 
285  int aa = 0;
286 
287  for (int k = 0; k < theAlgorithm_->getNumberOfChannels(); k++) {
289  bool isNearCrack = false;
290 
291  if (calibMode_ == "RING") {
292  isNearCrack = (abs(ringNumberCorrector(k)) == 1 || abs(ringNumberCorrector(k)) == 25 ||
293  abs(ringNumberCorrector(k)) == 26 || abs(ringNumberCorrector(k)) == 45 ||
294  abs(ringNumberCorrector(k)) == 46 || abs(ringNumberCorrector(k)) == 65 ||
295  abs(ringNumberCorrector(k)) == 66 || abs(ringNumberCorrector(k)) == 85 ||
296  abs(ringNumberCorrector(k)) == 86 || abs(ringNumberCorrector(k)) == 124);
297  }
298 
299  if (k < 85) {
300  if ((k + 1) % 5 != 0) {
301  if (!isNearCrack) {
302  mean[j] += calibCoeff[k];
303  mean[j] += calibCoeff[169 - k];
304 
305  num[j] += 2.;
306 
307  //meanErr[j]+= calibCoeffError[k];
308  //meanErr[j]+= calibCoeffError[169 - k];
309 
310  meanErr[j] += 1. / pow(calibCoeffError[k], 2);
311  meanErr[j] += 1. / pow(calibCoeffError[169 - k], 2);
312 
313  tempRms[aa][j] += calibCoeff[k];
314  aa++;
315  tempRms[aa][j] += calibCoeff[169 - k];
316  aa++;
317  }
318  }
319 
320  else {
321  if (!isNearCrack) {
322  mean[j] += calibCoeff[k];
323  mean[j] += calibCoeff[169 - k];
324 
325  num[j] += 2.;
326 
327  //meanErr[j]+= calibCoeffError[k];
328  //meanErr[j]+= calibCoeffError[169 - k];
329 
330  meanErr[j] += 1. / pow(calibCoeffError[k], 2);
331  meanErr[j] += 1. / pow(calibCoeffError[169 - k], 2);
332 
333  tempRms[aa][j] += calibCoeff[k];
334  aa++;
335  tempRms[aa][j] += calibCoeff[169 - k];
336  aa++;
337  }
338  j++;
339  aa = 0;
340  }
341  }
342  //EE begin
343 
344  if (k >= 170 && k <= 204) {
345  if (flag < 4) {
346  //make groups of 5 Xtals in #eta
347  mean[j] += calibCoeff[k] / 10.;
348  mean[j] += calibCoeff[k + 39] / 10.;
349 
350  meanErr[j] += calibCoeffError[k] / 30.;
351  meanErr[j] += calibCoeffError[k + 39] / 30.;
352 
353  tempRms[aa][j] += calibCoeff[k];
354  aa++;
355  tempRms[aa][j] += calibCoeff[k + 39];
356  aa++;
357 
358  flag++;
359  }
360 
361  else if (flag == 4) {
362  //make groups of 5 Xtals in #eta
363  mean[j] += calibCoeff[k] / 10.;
364  mean[j] += calibCoeff[k + 39] / 10.;
365 
366  meanErr[j] += calibCoeffError[k] / 30.;
367  meanErr[j] += calibCoeffError[k + 39] / 30.;
368 
369  tempRms[aa][j] += calibCoeff[k];
370  aa++;
371  tempRms[aa][j] += calibCoeff[k + 39];
372  aa++;
373 
374  flag = 0;
375  // std::cout<<" index(>85) "<<k<<" j is "<<j<<" mean[j] is "<<mean[j]<<std::endl;
376  j++;
377  aa = 0;
378  }
379  }
380  if (k >= 205 && k <= 208) {
381  mean[j] += calibCoeff[k] / 8.;
382  mean[j] += calibCoeff[k + 39] / 8.;
383 
384  meanErr[j] += calibCoeffError[k] / 30.;
385  meanErr[j] += calibCoeffError[k + 39] / 30.;
386 
387  tempRms[aa][j] += calibCoeff[k];
388  aa++;
389  tempRms[aa][j] += calibCoeff[k + 39];
390  aa++;
391  }
392  //EE end
393 
394  /*
395  for(int jj =0; jj< 25; jj++){
396  if(meanErr[jj] > 0.)
397  std::cout<<" meanErr[jj] before sqrt: "<<meanErr[jj]<<std::endl;
398 
399  meanErr[jj] = 1./sqrt( meanErr[jj] );
400 
401  std::cout<<" meanErr[jj] after sqrt: "<<meanErr[jj]<<std::endl;
402  }
403  */
404 
405  if (!isNearCrack) {
407  h2_miscalRecal_->Fill(initCalibCoeff[k], 1. / calibCoeff[k]);
408  h1_mc_->Fill(initCalibCoeff[k] * calibCoeff[k] - 1.);
409 
410  if (k < 170) {
411  h2_miscalRecalEB_->Fill(initCalibCoeff[k], 1. / calibCoeff[k]);
412  h1_mcEB_->Fill(initCalibCoeff[k] * calibCoeff[k] - 1.);
413  }
414 
415  if (k >= 170) {
416  h2_miscalRecalEE_->Fill(initCalibCoeff[k], 1. / calibCoeff[k]);
417  h1_mcEE_->Fill(initCalibCoeff[k] * calibCoeff[k] - 1.);
418  }
419  }
420  }
421 
422  for (int ic = 0; ic < 17; ic++) {
423  mean[ic] = mean[ic] / num[ic]; //find mean of recalib coeff on group of rings
424  //meanErr[ic] = meanErr[ic] / ( sqrt( num[ic] ) * num[ic] ); //find mean of recalib coeff on group of rings
425  meanErr[ic] = 1. / sqrt(meanErr[ic]); //find mean of recalib coeff on group of rings
426  }
427 
428  //build array of RMS
429  for (int ic = 0; ic < 25; ic++) {
430  for (int id = 0; id < 10; id++) {
431  if (tempRms[id][ic] > 0.) {
432  rms[ic] += (tempRms[id][ic] - mean[j]) * (tempRms[id][ic] - mean[j]);
433  }
434  }
435  rms[ic] /= 10.; //this is approximate
436  rms[ic] = sqrt(rms[ic]);
437  }
438 
439  //build array of RMS
440 
441  Double_t xtalEta[25] = {1.4425, 1.3567, 1.2711, 1.1855, 1.10, 1.01, 0.92, 0.83, 0.7468,
442  0.6612, 0.5756, 0.4897, 0.3985, 0.3117, 0.2250, 0.1384, 0.0487, 1.546,
443  1.651, 1.771, 1.908, 2.071, 2.267, 2.516, 2.8};
444 
445  Double_t zero[25] = {0.026}; //interval/sqrt(12)
446 
447  for (int j = 0; j < 25; j++)
448  h2_coeffVsEtaGrouped_->Fill(xtalEta[j], mean[j]);
449 
450  // for(int sho = 0; sho <25; sho++)
451  //cout<<"xtalEta[j] "<< xtalEta[sho]<<" mean[j] "<<mean[sho]<<" err[j] "<<meanErr[sho]<<std::endl;
452 
453  TProfile* px = h2_coeffVsEta_->ProfileX("coeffVsEtaProfile");
454  px->SetXTitle("Eta channel");
455  px->SetYTitle("recalibCoeff");
456  px->Write();
457 
458  h2_coeffVsEta_->Write();
459  h2_coeffVsEtaGrouped_->Write();
460  h2_zMassVsLoop_->Write();
461  h2_zMassDiffVsLoop_->Write();
462  h2_zWidthVsLoop_->Write();
463  h2_coeffVsLoop_->Write();
464  h2_miscalRecal_->Write();
465  h1_mc_->Write();
466  h2_miscalRecalEB_->Write();
467  h1_mcEB_->Write();
468  h2_miscalRecalEE_->Write();
469  h1_mcEE_->Write();
470 
471  h2_residualSigma_->Write();
472 
474 
475  double weightSumMeanBarrel = 0.;
476  double weightSumMeanEndcap = 0.;
477 
478  for (int iIteration = 0; iIteration < theAlgorithm_->getNumberOfIterations(); iIteration++)
479  for (int iChannel = 0; iChannel < theAlgorithm_->getNumberOfChannels(); iChannel++) {
480  if (iIteration == (theAlgorithm_->getNumberOfIterations() - 1)) {
481  if (iChannel < 170)
482  weightSumMeanBarrel += algoHistos->weightedRescaleFactor[iIteration][iChannel]->Integral() / 170.;
483 
484  if (iChannel >= 170)
485  weightSumMeanEndcap += algoHistos->weightedRescaleFactor[iIteration][iChannel]->Integral() / 78.;
486 
487  h1_occupancyVsEta_->Fill((Double_t)ringNumberCorrector(iChannel),
488  algoHistos->weightedRescaleFactor[iIteration][iChannel]->Integral());
489 
490  h1_occupancy_->Fill(algoHistos->weightedRescaleFactor[iIteration][iChannel]->Integral());
491 
492  if (iChannel < 170)
493  h1_occupancyBarrel_->Fill(algoHistos->weightedRescaleFactor[iIteration][iChannel]->Integral());
494 
495  if (iChannel >= 170)
496  h1_occupancyEndcap_->Fill(algoHistos->weightedRescaleFactor[iIteration][iChannel]->Integral());
497 
498 #ifdef DEBUG
499  std::cout << "Writing weighted integral for channel " << ringNumberCorrector(iChannel) << " ,value "
500  << algoHistos->weightedRescaleFactor[iIteration][iChannel]->Integral() << std::endl;
501 #endif
502  }
503  }
504 
505  // std::cout<<"Done! Closing output file... "<<std::endl;
506 
507  h1_weightSumMeanBarrel_->Fill(weightSumMeanBarrel);
508  h1_weightSumMeanEndcap_->Fill(weightSumMeanEndcap);
509 
510  std::cout << "Weight sum mean on channels in Barrel is :" << weightSumMeanBarrel << std::endl;
511  std::cout << "Weight sum mean on channels in Endcap is :" << weightSumMeanEndcap << std::endl;
512 
513  h1_weightSumMeanBarrel_->Write();
514  h1_weightSumMeanEndcap_->Write();
515 
516  h1_occupancyVsEta_->Write();
517  h1_occupancy_->Write();
518  h1_occupancyBarrel_->Write();
519  h1_occupancyEndcap_->Write();
520 
521  myTree->Write();
522 
523  TGraphErrors* graph = new TGraphErrors(25, xtalEta, mean, zero, meanErr);
524  graph->Draw("APL");
525  graph->Write();
526 
527  double zero50[50] = {0.};
528 
529  TGraphErrors* residualSigmaGraph = new TGraphErrors(50, loopArray, sigmaArray, zero50, sigmaErrorArray);
530  residualSigmaGraph->SetName("residualSigmaGraph");
531  residualSigmaGraph->Draw("APL");
532  residualSigmaGraph->Write();
533 
534  TGraphErrors* coefficientDistanceAtIterationGraph =
535  new TGraphErrors(50, loopArray, coefficientDistanceAtIteration, zero50, zero50);
536  coefficientDistanceAtIterationGraph->SetName("coefficientDistanceAtIterationGraph");
537  coefficientDistanceAtIterationGraph->Draw("APL");
538  coefficientDistanceAtIterationGraph->Write();
539 
540  Float_t noError[250] = {0.};
541 
542  Float_t ringInd[250];
543  for (int i = 0; i < 250; i++)
544  ringInd[i] = ringNumberCorrector(i);
545 
546  TGraphErrors* graphCoeff =
547  new TGraphErrors(theAlgorithm_->getNumberOfChannels(), ringInd, calibCoeff, noError, calibCoeffError);
548  graphCoeff->SetName("graphCoeff");
549  graphCoeff->Draw("APL");
550  graphCoeff->Write();
551 
552  // outputFile_->Write();//this automatically writes all histos on file
553 
554  h1_ZCandMult_->Write();
555  h1_reco_ZMass_->Write();
556 
557  h1_reco_ZMassCorr_->Write();
558  h1_reco_ZMassCorrBB_->Write();
559  h1_reco_ZMassCorrEE_->Write();
560 
561  outputFile_->Close();
562 
567 
568  // myZeeRescaleFactorPlots_ = new ZeeRescaleFactorPlots("zeeRescaleFactorPlots.root");
569  //myZeeRescaleFactorPlots_->writeHistograms( theAlgorithm_ );
570 
571  // delete myZeeRescaleFactorPlots_;
572 }
573 
574 //_____________________________________________________________________________
575 // Called at each event
576 //________________________________________
577 
579  using namespace edm;
580 
581 #ifdef DEBUG
582  std::cout << "[ZeeCalibration] Entering duringLoop" << std::endl;
583 #endif
584 
585  // code that used to be in beginJob
586  if (isfirstcall_) {
587  //inizializzare la geometria di ecal
589  iSetup.get<CaloGeometryRecord>().get(pG);
591 
592  myZeePlots_ = new ZeePlots("zeePlots.root");
593  // myZeeRescaleFactorPlots_ = new ZeeRescaleFactorPlots("zeeRescaleFactorPlots.root");
594 
595  // go to *OUR* rootfile and book histograms
596  outputFile_->cd();
597  bookHistograms();
598 
599  std::cout << "[ZeeCalibration::beginOfJob] Histograms booked " << std::endl;
600 
601  loopFlag_ = 0;
602 
603  //Read miscalibration map if requested
604  CaloMiscalibMapEcal* miscalibMap = nullptr;
605  if (!barrelfile_.empty() || !barrelfile_.empty()) {
606  miscalibMap = new CaloMiscalibMapEcal();
607  miscalibMap->prefillMap();
608  }
609 
610  if (!barrelfile_.empty()) {
611  MiscalibReaderFromXMLEcalBarrel barrelreader_(*miscalibMap);
612  barrelreader_.parseXMLMiscalibFile(barrelfile_);
613 #ifdef DEBUG
614  std::cout << "[ZeeCalibration::beginOfJob] Parsed EB miscal file" << std::endl;
615 #endif
616  }
617 
618  if (!endcapfile_.empty()) {
619  MiscalibReaderFromXMLEcalEndcap endcapreader_(*miscalibMap);
620  endcapreader_.parseXMLMiscalibFile(endcapfile_);
621 #ifdef DEBUG
622  std::cout << "[ZeeCalibration::beginOfJob] Parsed EE miscal file" << std::endl;
623 #endif
624  }
625 
626  std::cout << " theAlgorithm_->getNumberOfChannels() " << theAlgorithm_->getNumberOfChannels() << std::endl;
627 
629  for (int k = 0; k < theAlgorithm_->getNumberOfChannels(); k++) {
630  calibCoeff[k] = 1.;
631  calibCoeffError[k] = 0.;
632 
633  std::vector<DetId> ringIds;
634 
635  if (calibMode_ == "RING")
637 
638  if (calibMode_ == "MODULE")
640 
641  if (calibMode_ == "ABS_SCALE" || calibMode_ == "ETA_ET_MODE")
643 
644  if (miscalibMap) {
645  initCalibCoeff[k] = 0.;
646  for (unsigned int iid = 0; iid < ringIds.size(); ++iid) {
647  float miscalib = *(miscalibMap->get().getMap().find(ringIds[iid]));
648  // float miscalib=miscalibMap->get().getMap().find(ringIds[iid])->second; ////////AP
649  initCalibCoeff[k] += miscalib;
650  }
651  initCalibCoeff[k] /= (float)ringIds.size();
652  std::cout << k << " " << initCalibCoeff[k] << " " << ringIds.size() << std::endl;
653  } else {
654  initCalibCoeff[k] = 1.;
655  }
656  }
657 
658  ical = std::make_shared<EcalIntercalibConstants>();
659 
660  for (int k = 0; k < theAlgorithm_->getNumberOfChannels(); k++) {
661  // std::vector<DetId> ringIds = EcalRingCalibrationTools::getDetIdsInRing(k);
662 
663  std::vector<DetId> ringIds;
664 
665  if (calibMode_ == "RING")
667 
668  if (calibMode_ == "MODULE")
670 
671  if (calibMode_ == "ABS_SCALE" || calibMode_ == "ETA_ET_MODE")
673 
674  for (unsigned int iid = 0; iid < ringIds.size(); ++iid) {
675  // ical->setValue( ringIds[iid], 1. * initCalibCoeff[k] );
676 
677  if (ringIds[iid].subdetId() == EcalBarrel) {
678  EBDetId myEBDetId(ringIds[iid]);
679  h2_xtalMiscalibCoeffBarrel_->SetBinContent(
680  myEBDetId.ieta() + 86,
681  myEBDetId.iphi(),
682  *(miscalibMap->get().getMap().find(ringIds[iid]))); //fill TH2 with miscalibCoeff
683  }
684 
685  if (ringIds[iid].subdetId() == EcalEndcap) {
686  EEDetId myEEDetId(ringIds[iid]);
687  if (myEEDetId.zside() < 0)
688  h2_xtalMiscalibCoeffEndcapMinus_->SetBinContent(
689  myEEDetId.ix(),
690  myEEDetId.iy(),
691  *(miscalibMap->get().getMap().find(ringIds[iid]))); //fill TH2 with miscalibCoeff
692 
693  if (myEEDetId.zside() > 0)
694  h2_xtalMiscalibCoeffEndcapPlus_->SetBinContent(
695  myEEDetId.ix(),
696  myEEDetId.iy(),
697  *(miscalibMap->get().getMap().find(ringIds[iid]))); //fill TH2 with miscalibCoeff
698  }
699 
700  ical->setValue(ringIds[iid], *(miscalibMap->get().getMap().find(ringIds[iid])));
701  }
702 
703  read_events = 0;
704  init_ = false;
705  }
706  isfirstcall_ = false;
707  } // if isfirstcall
708 
710 
711  for (unsigned int iHLT = 0; iHLT < 200; ++iHLT) {
712  aHLTResults[iHLT] = false;
713  }
714 
715 #ifdef DEBUG
716  std::cout << "[ZeeCalibration::duringLoop] Done with initializing aHLTresults[] " << std::endl;
717 #endif
718 
719  edm::Handle<edm::TriggerResults> hltTriggerResultHandle;
720  iEvent.getByLabel(hlTriggerResults_, hltTriggerResultHandle);
721 
722  if (!hltTriggerResultHandle.isValid()) {
723  //std::cout << "invalid handle for HLT TriggerResults" << std::endl;
724  } else {
725  hltCount = hltTriggerResultHandle->size();
726 
727  if (loopFlag_ == 0)
728  myZeePlots_->fillHLTInfo(hltTriggerResultHandle);
729 
730 #ifdef DEBUG
731  std::cout << "[ZeeCalibration::duringLoop] Done with myZeePlots_->fillHLTInfo(hltTriggerResultHandle); "
732  << std::endl;
733 #endif
734 
735  for (int i = 0; i < hltCount; i++) {
736  aHLTResults[i] = hltTriggerResultHandle->accept(i);
737 
738  //HLT bit 32 = HLT1Electron
739  //HLT bit 34 = HLT2Electron
740  //HLT bit 35 = HLT2ElectronRelaxed
741  }
742 
743  if (!aHLTResults[32] && !aHLTResults[34] && !aHLTResults[35])
744  return kContinue;
745  }
746 
747 #ifdef DEBUG
748  std::cout << "[ZeeCalibration::duringLoop] End HLT section" << std::endl;
749 #endif
750 
752 
753  std::vector<HepMC::GenParticle*> mcEle;
754 
755  float myGenZMass(-1);
756 
757  if (!mcProducer_.empty()) {
758  //DUMP GENERATED Z MASS - BEGIN
759  Handle<HepMCProduct> hepProd;
760  // iEvent.getByLabel( "source", hepProd ) ;
761  iEvent.getByLabel(mcProducer_, hepProd);
762 
763  const HepMC::GenEvent* myGenEvent = hepProd->GetEvent();
764 
765  if (loopFlag_ == 0)
766  myZeePlots_->fillZMCInfo(&(*myGenEvent));
767 
768 #ifdef DEBUG
769  std::cout << "[ZeeCalibration::duringLoop] Done with myZeePlots_->fillZMCInfo( & (*myGenEvent) ); " << std::endl;
770 #endif
771 
772  for (HepMC::GenEvent::particle_const_iterator p = myGenEvent->particles_begin(); p != myGenEvent->particles_end();
773  ++p) {
774  //return a pointer to MC Z in the event
775  if ((*p)->pdg_id() == 23 && (*p)->status() == 2) {
776  myGenZMass = (*p)->momentum().m();
777  }
778  }
779  //DUMP GENERATED Z MASS - END
780 
781  if (loopFlag_ == 0)
782  myZeePlots_->fillEleMCInfo(&(*myGenEvent));
783 
784  //loop over MC positrons and find the closest MC positron in (eta,phi) phace space - begin
785  HepMC::GenParticle MCele;
786 
787  for (HepMC::GenEvent::particle_const_iterator p = myGenEvent->particles_begin(); p != myGenEvent->particles_end();
788  ++p) {
789  if (abs((*p)->pdg_id()) == 11) {
790  mcEle.push_back((*p));
791  MCele = *(*p);
792  }
793  }
794 
795  if (mcEle.size() == 2 && fabs(mcEle[0]->momentum().eta()) < 2.4 && fabs(mcEle[1]->momentum().eta()) < 2.4) {
796  NEVT++;
797 
798  if (fabs(mcEle[0]->momentum().eta()) < 1.479 && fabs(mcEle[1]->momentum().eta()) < 1.479)
799  MCZBB++;
800 
801  if ((fabs(mcEle[0]->momentum().eta()) > 1.479 && fabs(mcEle[1]->momentum().eta()) < 1.479) ||
802  (fabs(mcEle[0]->momentum().eta()) < 1.479 && fabs(mcEle[1]->momentum().eta()) > 1.479))
803  MCZEB++;
804 
805  if (fabs(mcEle[0]->momentum().eta()) > 1.479 && fabs(mcEle[1]->momentum().eta()) > 1.479)
806  MCZEE++;
807  }
808  }
809 
810  // Get EBRecHits
812  try {
814  } catch (std::exception& ex) {
815  std::cerr << "Error! can't get the product EBRecHitCollection " << std::endl;
816  }
817  const EBRecHitCollection* hits = phits.product(); // get a ptr to the product
818 
819  // Get EERecHits
821  try {
823  } catch (std::exception& ex) {
824  std::cerr << "Error! can't get the product EERecHitCollection " << std::endl;
825  }
826  const EERecHitCollection* ehits = ephits.product(); // get a ptr to the product
827 
828  //Get Hybrid SuperClusters
830  try {
831  iEvent.getByLabel(scProducer_, scCollection_, pSuperClusters);
832  } catch (std::exception& ex) {
833  std::cerr << "Error! can't get the product SuperClusterCollection " << std::endl;
834  }
835  const reco::SuperClusterCollection* scCollection = pSuperClusters.product();
836 
837 #ifdef DEBUG
838  std::cout << "scCollection->size()" << scCollection->size() << std::endl;
839  for (reco::SuperClusterCollection::const_iterator scIt = scCollection->begin(); scIt != scCollection->end(); scIt++) {
840  std::cout << scIt->energy() << std::endl;
841  }
842 #endif
843 
844  //Get Island SuperClusters
845  Handle<reco::SuperClusterCollection> pIslandSuperClusters;
846  try {
847  iEvent.getByLabel(scIslandProducer_, scIslandCollection_, pIslandSuperClusters);
848  } catch (std::exception& ex) {
849  std::cerr << "Error! can't get the product IslandSuperClusterCollection " << std::endl;
850  }
851  const reco::SuperClusterCollection* scIslandCollection = pIslandSuperClusters.product();
852 
853 #ifdef DEBUG
854  std::cout << "scCollection->size()" << scIslandCollection->size() << std::endl;
855 #endif
856 
857  if ((scCollection->size() + scIslandCollection->size()) < 2)
858  return kContinue;
859 
860  // Get Electrons
862  try {
863  iEvent.getByLabel(electronProducer_, electronCollection_, pElectrons);
864  } catch (std::exception& ex) {
865  std::cerr << "Error! can't get the product ElectronCollection " << std::endl;
866  }
868 
869  /*
870  //reco-mc association map
871  std::map<HepMC::GenParticle*,const reco::PixelMatchGsfElectron*> myMCmap;
872 
873  fillMCmap(&(*electronCollection),mcEle,myMCmap);
874 
875  fillEleInfo(mcEle,myMCmap);
876  */
877 
878  if (electronCollection->size() < 2)
879  return kContinue;
880 
881  if (!hits && !ehits) {
882  std::cout << "!hits" << std::endl;
883  return kContinue;
884  }
885 
886  if (hits->empty() && ehits->empty()) {
887  std::cout << "hits->size() == 0" << std::endl;
888  return kContinue;
889  }
890 
891  if (!electronCollection) {
892  std::cout << "!electronCollection" << std::endl;
893  return kContinue;
894  }
895 
896  if (electronCollection->empty()) {
897  std::cout << "electronCollection->size() == 0" << std::endl;
898  return kContinue;
899  }
900 
904 
905  read_events++;
906 
907  // std::cout << "read_events = " << read_events << std::endl;
908 
910 
911 #ifdef DEBUG
912  std::cout << " Starting with myZeePlots_->fillEleInfo(electronCollection); " << std::endl;
913 #endif
914 
915  if (loopFlag_ == 0)
916  myZeePlots_->fillEleInfo(electronCollection);
917 
918 #ifdef DEBUG
919  std::cout << " Done with myZeePlots_->fillEleInfo(electronCollection); " << std::endl;
920 #endif
921 
922  //FILL an electron vector - end
923  //###################################Electron-SC association: begin#####################################################
924  //Filling new ElectronCollection with new SC ref and calibElectron container
925  std::vector<calib::CalibElectron> calibElectrons;
926  //std::map< const calib::CalibElectron* , const reco::SuperCluster* > eleScMap;
927 
928  //#####################################Electron-SC association map: end#####################################################
929  for (unsigned int e_it = 0; e_it != electronCollection->size(); e_it++) {
930  calibElectrons.push_back(calib::CalibElectron(&((*electronCollection)[e_it]), hits, ehits));
931 #ifdef DEBUG
932  std::cout << calibElectrons.back().getRecoElectron()->superCluster()->energy() << " "
933  << calibElectrons.back().getRecoElectron()->energy() << std::endl;
934 #endif
935  // h1_recoEleEnergy_->Fill(calibElectrons.back().getRecoElectron()->superCluster()->energy());
936  }
937  // if (iLoop == 0)
938  //fillCalibElectrons(calibElectrons);
939 
940 #ifdef DEBUG
941  std::cout << "Filled histos" << std::endl;
942 #endif
943 
944  //COMBINATORY FOR Z MASS - begin
945  std::vector<std::pair<calib::CalibElectron*, calib::CalibElectron*> > zeeCandidates;
946  int myBestZ = -1;
947 
948  mass = -1.;
949  double DeltaMinvMin(5000.);
950 
951  if (calibElectrons.size() < 2)
952  return kContinue;
953 
954  for (unsigned int e_it = 0; e_it != calibElectrons.size() - 1; e_it++) {
955  for (unsigned int p_it = e_it + 1; p_it != calibElectrons.size(); p_it++) {
956 #ifdef DEBUG
957  std::cout << e_it << " " << calibElectrons[e_it].getRecoElectron()->charge() << " " << p_it << " "
958  << calibElectrons[p_it].getRecoElectron()->charge() << std::endl;
959 #endif
960  if (calibElectrons[e_it].getRecoElectron()->charge() * calibElectrons[p_it].getRecoElectron()->charge() != -1)
961  continue;
962 
964  std::pair<calib::CalibElectron*, calib::CalibElectron*>(&(calibElectrons[e_it]), &(calibElectrons[p_it])));
965 
966  if (mass < 0)
967  continue;
968 
969 #ifdef DEBUG
970  std::cout << "#######################mass " << mass << std::endl;
971 #endif
972 
973  zeeCandidates.push_back(
974  std::pair<calib::CalibElectron*, calib::CalibElectron*>(&(calibElectrons[e_it]), &(calibElectrons[p_it])));
975  double DeltaMinv = fabs(mass - MZ);
976 
977  if (DeltaMinv < DeltaMinvMin) {
978  DeltaMinvMin = DeltaMinv;
979  myBestZ = zeeCandidates.size() - 1;
980  }
981  }
982  }
983 
984  // h_DeltaZMassDistr_[loopFlag_]->Fill( (mass-MZ) / MZ );
985 
986  // zeeCa->Fill(zeeCandidates);
987  //
988  h1_ZCandMult_->Fill(zeeCandidates.size());
989 
990  if (zeeCandidates.empty() || myBestZ == -1)
991  return kContinue;
992 
993  if (loopFlag_ == 0)
994  myZeePlots_->fillZInfo(zeeCandidates[myBestZ]);
995 
996 #ifdef DEBUG
997  std::cout << "Found ZCandidates " << myBestZ << std::endl;
998 #endif
999 
1000  // h1_zMassResol_ ->Fill(mass-myGenZMass);
1001 
1003 
1004  int class1 = zeeCandidates[myBestZ].first->getRecoElectron()->classification();
1005  int class2 = zeeCandidates[myBestZ].second->getRecoElectron()->classification();
1006 
1007  h1_eleClasses_->Fill(class1);
1008  h1_eleClasses_->Fill(class2);
1009 
1010  std::cout << "BEFORE " << std::endl;
1011 
1012  // myZeePlots_->fillEleClassesPlots( zeeCandidates[myBestZ].first );
1013  //myZeePlots_->fillEleClassesPlots( zeeCandidates[myBestZ].second );
1014 
1015  std::cout << "AFTER " << std::endl;
1016 
1018 
1019  if (class1 < 100)
1020  // h1_Elec_->Fill(1);
1022  if (class1 >= 100)
1024 
1025  if (class2 < 100)
1027  if (class2 >= 100)
1029 
1030  if (class1 == 0)
1032  if (class1 == 100)
1034  if (class1 == 10 || class1 == 20)
1036  if (class1 == 110 || class1 == 120)
1038  if (class1 >= 30 && class1 <= 34)
1040  if (class1 >= 130 && class1 <= 134)
1042  if (class1 == 40)
1044  if (class1 == 140)
1046 
1047  if (class2 == 0)
1049  if (class2 == 100)
1051  if (class2 == 10 || class2 == 20)
1053  if (class2 == 110 || class2 == 120)
1055  if (class2 >= 30 && class2 <= 34)
1057  if (class2 >= 130 && class2 <= 134)
1059  if (class2 == 40)
1061  if (class2 == 140)
1063 
1065 
1067 
1068  DetId firstElehottestDetId =
1070  zeeCandidates[myBestZ].first->getRecoElectron()->superCluster()->seed()->hitsAndFractions(), hits, ehits)
1071  .first;
1072  DetId secondElehottestDetId =
1074  zeeCandidates[myBestZ].second->getRecoElectron()->superCluster()->seed()->hitsAndFractions(), hits, ehits)
1075  .first;
1076 
1077  bool firstElectronIsOnModuleBorder(false);
1078  bool secondElectronIsOnModuleBorder(false);
1079 
1081 
1082  if (class1 < 100) {
1083  if (firstElehottestDetId.subdetId() == EcalBarrel)
1084  firstElectronIsOnModuleBorder = xtalIsOnModuleBorder(firstElehottestDetId);
1085 
1087 
1088  if (firstElehottestDetId.subdetId() == EcalBarrel && !firstElectronIsOnModuleBorder)
1090  }
1091 
1092  if (class2 < 100) {
1093  if (secondElehottestDetId.subdetId() == EcalBarrel)
1094  secondElectronIsOnModuleBorder = xtalIsOnModuleBorder(secondElehottestDetId);
1095 
1097 
1098  if (secondElehottestDetId.subdetId() == EcalBarrel && !secondElectronIsOnModuleBorder)
1100  }
1101 
1102  if (class1 < 100) {
1103  if (firstElehottestDetId.subdetId() == EcalBarrel && firstElectronIsOnModuleBorder) {
1104  h1_borderElectronClassification_->Fill(class1);
1105  return kContinue;
1106  }
1107  }
1108 
1109  if (class2 < 100) {
1110  if (secondElehottestDetId.subdetId() == EcalBarrel && secondElectronIsOnModuleBorder) {
1111  h1_borderElectronClassification_->Fill(class2);
1112  return kContinue;
1113  }
1114  }
1115 
1118 
1119  if (class1 < 100 && class2 < 100) {
1120  BBZN++;
1121  if (class1 == 0 && class2 == 0)
1122  BBZN_gg++;
1123  if (class1 < 21 && class2 < 21)
1124  BBZN_tt++;
1125  if (class1 < 21 || class2 < 21)
1126  BBZN_t0++;
1127  }
1128 
1129  if (class1 >= 100 && class2 >= 100) {
1130  EEZN++;
1131  if (class1 == 100 && class2 == 100)
1132  EEZN_gg++;
1133  if (class1 < 121 && class2 < 121)
1134  EEZN_tt++;
1135  if (class1 < 121 || class2 < 121)
1136  EEZN_t0++;
1137  }
1138 
1139  if ((class1 < 100 && class2 >= 100) || (class2 < 100 && class1 >= 100)) {
1140  EBZN++;
1141  if ((class1 == 0 && class2 == 100) || (class2 == 0 && class1 == 100))
1142  EBZN_gg++;
1143  if ((class1 < 21 && class2 < 121) || (class2 < 21 && class1 < 121))
1144  EBZN_tt++;
1145  if (class2 < 21 || class1 < 21 || class2 < 121 || class1 < 121)
1146  EBZN_t0++;
1147  }
1148 
1150 
1151  if (myBestZ == -1)
1152  return kContinue;
1153 
1154  bool invMassBool = ((mass > minInvMassCut_) && (mass < maxInvMassCut_));
1155 
1156  bool selectionBool = false;
1157  //0 = all electrons (but no crack)
1158 
1160 
1161  float theta1 = 2. * atan(exp(-zeeCandidates[myBestZ].first->getRecoElectron()->superCluster()->eta()));
1162  bool ET_1 = ((zeeCandidates[myBestZ].first->getRecoElectron()->superCluster()->energy() * sin(theta1)) > 20.);
1163 
1164  float theta2 = 2. * atan(exp(-zeeCandidates[myBestZ].second->getRecoElectron()->superCluster()->eta()));
1165  bool ET_2 = ((zeeCandidates[myBestZ].second->getRecoElectron()->superCluster()->energy() * sin(theta2)) > 20.);
1166 
1167  bool HoE_1 = (zeeCandidates[myBestZ].first->getRecoElectron()->hadronicOverEm() < 0.115);
1168  bool HoE_2 = (zeeCandidates[myBestZ].second->getRecoElectron()->hadronicOverEm() < 0.115);
1169 
1170  bool DeltaPhiIn_1 = (zeeCandidates[myBestZ].first->getRecoElectron()->deltaPhiSuperClusterTrackAtVtx() < 0.090);
1171  bool DeltaPhiIn_2 = (zeeCandidates[myBestZ].second->getRecoElectron()->deltaPhiSuperClusterTrackAtVtx() < 0.090);
1172 
1173  bool DeltaEtaIn_1 = (zeeCandidates[myBestZ].first->getRecoElectron()->deltaEtaSuperClusterTrackAtVtx() < 0.0090);
1174  bool DeltaEtaIn_2 = (zeeCandidates[myBestZ].second->getRecoElectron()->deltaEtaSuperClusterTrackAtVtx() < 0.0090);
1175 
1177 
1178  if (!(invMassBool && ET_1 && ET_2 && HoE_1 && HoE_2 && DeltaPhiIn_1 && DeltaPhiIn_2 && DeltaEtaIn_1 && DeltaEtaIn_2))
1179  return kContinue;
1181 
1182  h1_eventsAfterEWKSelection_->Fill(1);
1183 
1185 
1186  int c1st = zeeCandidates[myBestZ].first->getRecoElectron()->classification();
1187  int c2nd = zeeCandidates[myBestZ].second->getRecoElectron()->classification();
1188  if (electronSelection_ == 0)
1189  selectionBool = (myBestZ != -1 && c1st != 40 && c1st != 40 && c2nd != 40 && c2nd != 140);
1190 
1191  //1 = all electrons are Golden, BB or Narrow
1192 
1193  if (electronSelection_ == 1)
1194  selectionBool =
1195  (myBestZ != -1 && (c1st == 0 || c1st == 10 || c1st == 20 || c1st == 100 || c1st == 110 || c1st == 120) &&
1196  (c2nd == 0 || c2nd == 10 || c2nd == 20 || c2nd == 100 || c2nd == 110 || c2nd == 120));
1197 
1198  //2 = all electrons are Golden
1199  if (electronSelection_ == 2)
1200  selectionBool = (myBestZ != -1 && (c1st == 0 || c1st == 100) && (c2nd == 0 || c2nd == 100));
1201  //3 = all electrons are showering
1202  if (electronSelection_ == 3)
1203  selectionBool = (myBestZ != -1 && ((c1st >= 30 && c1st <= 34) || ((c1st >= 130 && c1st <= 134))) &&
1204  ((c2nd >= 30 && c2nd <= 34) || ((c2nd >= 130 && c2nd <= 134)))
1205 
1206  );
1207 
1208  //4 = all Barrel electrons are Golden, BB or Narrow; take all Endcap electrons
1209 
1210  if (electronSelection_ == 4)
1211  selectionBool = (myBestZ != -1 && (
1212 
1213  ((c1st == 0 || c1st == 10 || c1st == 20) && c2nd >= 100 && c2nd != 140)
1214 
1215  ||
1216 
1217  ((c2nd == 0 || c2nd == 10 || c2nd == 20) && c1st >= 100 && c1st != 140)
1218 
1219  ));
1220 
1221  //5 = all Endcap electrons (but no crack)
1222 
1223  if (electronSelection_ == 5)
1224  selectionBool = (myBestZ != -1 && c1st >= 100 && c2nd >= 100 && c1st != 140 && c2nd != 140);
1225 
1226  //6 = all Barrel electrons (but no crack)
1227 
1228  if (electronSelection_ == 6)
1229  selectionBool = (myBestZ != -1 && c1st < 100 && c2nd < 100 && c1st != 40 && c2nd != 40);
1230 
1231  //7 = this eliminates the events which have 1 ele in the Barrel and 1 in the Endcap
1232 
1233  if (electronSelection_ == 7)
1234  selectionBool = (myBestZ != -1 && !(c1st < 100 && c2nd >= 100) && !(c1st >= 100 && c2nd < 100));
1235 
1236  float ele1EnergyCorrection(1.);
1237  float ele2EnergyCorrection(1.);
1238 
1239  if (invMassBool && selectionBool && wantEtaCorrection_) {
1240  ele1EnergyCorrection = getEtaCorrection(zeeCandidates[myBestZ].first->getRecoElectron());
1241  ele2EnergyCorrection = getEtaCorrection(zeeCandidates[myBestZ].second->getRecoElectron());
1242  }
1243 
1244  if (invMassBool && selectionBool) {
1246  ZeeKinematicTools::cosThetaElectrons_SC(zeeCandidates[myBestZ], ele1EnergyCorrection, ele2EnergyCorrection));
1248  ZeeKinematicTools::cosThetaElectrons_TK(zeeCandidates[myBestZ], ele1EnergyCorrection, ele2EnergyCorrection));
1250  ZeeKinematicTools::cosThetaElectrons_SC(zeeCandidates[myBestZ], ele1EnergyCorrection, ele2EnergyCorrection) /
1252  zeeCandidates[myBestZ], ele1EnergyCorrection, ele2EnergyCorrection) -
1253  1.);
1254 
1255  if (!mcProducer_.empty()) {
1256  h1_zMassResol_->Fill(mass - myGenZMass);
1257 
1258  //reco-mc association map - begin
1259 
1260  std::map<HepMC::GenParticle*, const reco::GsfElectron*> myMCmap;
1261 
1262  std::vector<const reco::GsfElectron*> dauElectronCollection;
1263 
1264  dauElectronCollection.push_back(zeeCandidates[myBestZ].first->getRecoElectron());
1265  dauElectronCollection.push_back(zeeCandidates[myBestZ].second->getRecoElectron());
1266 
1267  fillMCmap(&dauElectronCollection, mcEle, myMCmap);
1268  fillEleInfo(mcEle, myMCmap);
1269  //h_DiffZMassDistr_[loopFlag_]->Fill( (mass-myGenZMass) );
1270  }
1271 
1272  //PUT f(eta) IN OUR Zee ALGORITHM
1273  theAlgorithm_->addEvent(zeeCandidates[myBestZ].first,
1274  zeeCandidates[myBestZ].second,
1275  MZ * sqrt(ele1EnergyCorrection * ele2EnergyCorrection));
1276 
1277  h1_reco_ZMass_->Fill(ZeeKinematicTools::calculateZMass_withTK(zeeCandidates[myBestZ]));
1278 
1280  zeeCandidates[myBestZ], ele1EnergyCorrection, ele2EnergyCorrection));
1281 
1282  int c1st = zeeCandidates[myBestZ].first->getRecoElectron()->classification();
1283  int c2nd = zeeCandidates[myBestZ].second->getRecoElectron()->classification();
1284  if (c1st < 100 && c2nd < 100)
1286  zeeCandidates[myBestZ], ele1EnergyCorrection, ele2EnergyCorrection));
1287 
1288  if (c1st >= 100 && c2nd >= 100)
1290  zeeCandidates[myBestZ], ele1EnergyCorrection, ele2EnergyCorrection));
1291 
1293  zeeCandidates[myBestZ], ele1EnergyCorrection, ele2EnergyCorrection);
1294 
1296  zeeCandidates[myBestZ], ele1EnergyCorrection, ele2EnergyCorrection) -
1297  myGenZMass;
1298 
1299  // h_ZMassDistr_[loopFlag_]->Fill(ZeeKinematicTools::calculateZMassWithCorrectedElectrons_withTK(zeeCandidates[myBestZ],ele1EnergyCorrection,ele2EnergyCorrection));
1300 
1301  myTree->Fill();
1302  }
1303 
1304 #ifdef DEBUG
1305  std::cout << "Added event to algorithm" << std::endl;
1306 #endif
1307 
1308  return kContinue;
1309 }
1310 //end of ZeeCalibration::duringLoop
1311 
1312 // Called at beginning of loop
1313 void ZeeCalibration::startingNewLoop(unsigned int iLoop) {
1314  std::cout << "[ZeeCalibration] Starting loop number " << iLoop << std::endl;
1315 
1317 
1318  resetVariables();
1319 
1320  resetHistograms();
1321 
1322 #ifdef DEBUG
1323  std::cout << "[ZeeCalibration] exiting from startingNewLoop" << std::endl;
1324 #endif
1325 }
1326 
1327 // Called at end of loop
1329  double par[3];
1330  double errpar[3];
1331  double zChi2;
1332  int zIters;
1333 
1334  ZIterativeAlgorithmWithFit::gausfit(h1_reco_ZMass_, par, errpar, 2., 2., &zChi2, &zIters);
1335 
1336  h2_zMassVsLoop_->Fill(loopFlag_, par[1]);
1337 
1338  h2_zMassDiffVsLoop_->Fill(loopFlag_, (par[1] - MZ) / MZ);
1339 
1340  h2_zWidthVsLoop_->Fill(loopFlag_, par[2]);
1341 
1343 
1344  std::cout << "[ZeeCalibration] Ending loop " << iLoop << std::endl;
1345  //RUN the algorithm
1347 
1348  const std::vector<float>& optimizedCoefficients = theAlgorithm_->getOptimizedCoefficients();
1349  const std::vector<float>& optimizedCoefficientsError = theAlgorithm_->getOptimizedCoefficientsError();
1350  //const std::vector<float>& weightSum = theAlgorithm_->getWeightSum();
1351  const std::vector<float>& optimizedChi2 = theAlgorithm_->getOptimizedChiSquare();
1352  const std::vector<int>& optimizedIterations = theAlgorithm_->getOptimizedIterations();
1353 
1354  //#ifdef DEBUG
1355  std::cout << "Optimized coefficients " << optimizedCoefficients.size() << std::endl;
1356  //#endif
1357 
1358  // h2_coeffVsLoop_->Fill(loopFlag_, optimizedCoefficients[75]); //show the evolution of just 1 ring coefficient (well chosen...)
1359 
1361  for (unsigned int ieta = 0; ieta < optimizedCoefficients.size(); ieta++) {
1362  NewCalibCoeff[ieta] = calibCoeff[ieta] * optimizedCoefficients[ieta];
1363 
1364  h2_chi2_[loopFlag_]->Fill(ringNumberCorrector(ieta), optimizedChi2[ieta]);
1365  h2_iterations_[loopFlag_]->Fill(ringNumberCorrector(ieta), optimizedIterations[ieta]);
1366  }
1368 
1370  computeCoefficientDistanceAtIteration(calibCoeff, NewCalibCoeff, optimizedCoefficients.size());
1371 
1372  std::cout << "Iteration # : " << loopFlag_ << " CoefficientDistanceAtIteration "
1373  << coefficientDistanceAtIteration[loopFlag_] << std::endl;
1374  std::cout << "size " << optimizedCoefficients.size() << std::endl;
1375 
1376  for (unsigned int ieta = 0; ieta < optimizedCoefficients.size(); ieta++) {
1377  calibCoeff[ieta] *= optimizedCoefficients[ieta];
1379  calibCoeff[ieta] * sqrt(pow(optimizedCoefficientsError[ieta] / optimizedCoefficients[ieta], 2) +
1380  pow(calibCoeffError[ieta] / calibCoeff[ieta], 2));
1381  //calibCoeffError[ieta] = optimizedCoefficientsError[ieta];
1382 
1383 #ifdef DEBUG
1384  std::cout << ieta << " " << optimizedCoefficients[ieta] << std::endl;
1385 #endif
1386 
1387  std::vector<DetId> ringIds;
1388 
1389  if (calibMode_ == "RING")
1391 
1392  if (calibMode_ == "MODULE")
1394 
1395  if (calibMode_ == "ABS_SCALE" || calibMode_ == "ETA_ET_MODE")
1397 
1398  for (unsigned int iid = 0; iid < ringIds.size(); ++iid) {
1399  if (ringIds[iid].subdetId() == EcalBarrel) {
1400  EBDetId myEBDetId(ringIds[iid]);
1401  h2_xtalRecalibCoeffBarrel_[loopFlag_]->SetBinContent(
1402  myEBDetId.ieta() + 86,
1403  myEBDetId.iphi(),
1404  100 * (calibCoeff[ieta] * initCalibCoeff[ieta] - 1.)); //fill TH2 with recalibCoeff
1405  }
1406 
1407  if (ringIds[iid].subdetId() == EcalEndcap) {
1408  EEDetId myEEDetId(ringIds[iid]);
1409  if (myEEDetId.zside() < 0)
1411  myEEDetId.ix(),
1412  myEEDetId.iy(),
1413  100 * (calibCoeff[ieta] * initCalibCoeff[ieta] - 1.)); //fill TH2 with recalibCoeff
1414 
1415  if (myEEDetId.zside() > 0)
1416  h2_xtalRecalibCoeffEndcapPlus_[loopFlag_]->SetBinContent(
1417  myEEDetId.ix(),
1418  myEEDetId.iy(),
1419  100 * (calibCoeff[ieta] * initCalibCoeff[ieta] - 1.)); //fill TH2 with recalibCoeff
1420  }
1421 
1422  ical->setValue(ringIds[iid], *(ical->getMap().find(ringIds[iid])) * optimizedCoefficients[ieta]);
1423  }
1424  }
1425 
1427 
1428  for (int k = 0; k < theAlgorithm_->getNumberOfChannels(); k++) {
1429  bool isNearCrack =
1430  (abs(ringNumberCorrector(k)) == 1 || abs(ringNumberCorrector(k)) == 25 || abs(ringNumberCorrector(k)) == 26 ||
1431  abs(ringNumberCorrector(k)) == 45 || abs(ringNumberCorrector(k)) == 46 || abs(ringNumberCorrector(k)) == 65 ||
1432  abs(ringNumberCorrector(k)) == 66 || abs(ringNumberCorrector(k)) == 85 || abs(ringNumberCorrector(k)) == 86 ||
1433  abs(ringNumberCorrector(k)) == 124);
1434 
1435  if (!isNearCrack) {
1436  // h2_miscalRecalParz_[iLoop]->Fill( initCalibCoeff[k], 1./calibCoeff[k] );
1437  h1_mcParz_[iLoop]->Fill(initCalibCoeff[k] * calibCoeff[k] - 1.);
1438 
1439  if (k < 170) {
1440  //h2_miscalRecalEBParz_[iLoop]->Fill( initCalibCoeff[k], 1./calibCoeff[k] );
1441  h1_mcEBParz_[iLoop]->Fill(initCalibCoeff[k] * calibCoeff[k] - 1.);
1442  }
1443 
1444  if (k >= 170) {
1445  //h2_miscalRecalEEParz_[iLoop]->Fill( initCalibCoeff[k], 1./calibCoeff[k] );
1446  h1_mcEEParz_[iLoop]->Fill(initCalibCoeff[k] * calibCoeff[k] - 1.);
1447  }
1448  }
1449  }
1450 
1452  double parResidual[3];
1453  double errparResidual[3];
1454  double zResChi2;
1455  int zResIters;
1456 
1457  ZIterativeAlgorithmWithFit::gausfit(h1_mcParz_[iLoop], parResidual, errparResidual, 3., 3., &zResChi2, &zResIters);
1458  //h1_mcParz_[iLoop]->Fit("gaus");
1459 
1460  h2_residualSigma_->Fill(loopFlag_ + 1, parResidual[2]);
1461  loopArray[loopFlag_] = loopFlag_ + 1;
1462  sigmaArray[loopFlag_] = parResidual[2];
1463  sigmaErrorArray[loopFlag_] = errparResidual[2];
1464 
1465  std::cout << "Fit on residuals, sigma is " << parResidual[2] << " +/- " << errparResidual[2] << std::endl;
1466 
1468  outputFile_->cd();
1469 
1470  // h2_miscalRecalParz_[iLoop]->Write();
1471  h1_mcParz_[iLoop]->Write();
1472 
1473  //h2_miscalRecalEBParz_[iLoop]->Write();
1474  h1_mcEBParz_[iLoop]->Write();
1475 
1476  //h2_miscalRecalEEParz_[iLoop]->Write();
1477  h1_mcEEParz_[iLoop]->Write();
1481 
1483 
1484  loopFlag_++;
1485 
1486 #ifdef DEBUG
1487  std::cout << " loopFlag_ is " << loopFlag_ << std::endl;
1488 #endif
1489 
1490  if (iLoop == theMaxLoops - 1 || iLoop >= theMaxLoops)
1491  return kStop;
1492  else
1493  return kContinue;
1494 }
1495 
1497  h1_eventsBeforeEWKSelection_ = new TH1F("h1_eventsBeforeEWKSelection", "h1_eventsBeforeEWKSelection", 5, 0, 5);
1498  h1_eventsAfterEWKSelection_ = new TH1F("h1_eventsAfterEWKSelection", "h1_eventsAfterEWKSelection", 5, 0, 5);
1499 
1501  new TH1F("h1_eventsBeforeBorderSelection", "h1_eventsBeforeBorderSelection", 5, 0, 5);
1502  h1_eventsAfterBorderSelection_ = new TH1F("h1_eventsAfterBorderSelection", "h1_eventsAfterBorderSelection", 5, 0, 5);
1503 
1504  h1_seedOverSC_ = new TH1F("h1_seedOverSC", "h1_seedOverSC", 400, 0., 2.);
1505 
1507 
1509  new TH1F("h1_borderElectronClassification", "h1_borderElectronClassification", 55, -5, 50);
1510  h1_preshowerOverSC_ = new TH1F("h1_preshowerOverSC", "h1_preshowerOverSC", 400, 0., 1.);
1511 
1512  h2_fEtaBarrelGood_ = new TH2F("fEtaBarrelGood", "fEtaBarrelGood", 800, -4., 4., 800, 0.8, 1.2);
1513  h2_fEtaBarrelGood_->SetXTitle("Eta");
1514  h2_fEtaBarrelGood_->SetYTitle("1/fEtaBarrelGood");
1515 
1516  h2_fEtaBarrelBad_ = new TH2F("fEtaBarrelBad", "fEtaBarrelBad", 800, -4., 4., 800, 0.8, 1.2);
1517  h2_fEtaBarrelBad_->SetXTitle("Eta");
1518  h2_fEtaBarrelBad_->SetYTitle("1/fEtaBarrelBad");
1519 
1520  h2_fEtaEndcapGood_ = new TH2F("fEtaEndcapGood", "fEtaEndcapGood", 800, -4., 4., 800, 0.8, 1.2);
1521  h2_fEtaEndcapGood_->SetXTitle("Eta");
1522  h2_fEtaEndcapGood_->SetYTitle("1/fEtaEndcapGood");
1523 
1524  h2_fEtaEndcapBad_ = new TH2F("fEtaEndcapBad", "fEtaEndcapBad", 800, -4., 4., 800, 0.8, 1.2);
1525  h2_fEtaEndcapBad_->SetXTitle("Eta");
1526  h2_fEtaEndcapBad_->SetYTitle("1/fEtaEndcapBad");
1527 
1528  for (int i = 0; i < 2; i++) {
1529  char histoName[50];
1530 
1531  sprintf(histoName, "h_eleEffEta_%d", i);
1532  h_eleEffEta_[i] = new TH1F(histoName, histoName, 150, 0., 2.7);
1533  h_eleEffEta_[i]->SetXTitle("|#eta|");
1534 
1535  sprintf(histoName, "h_eleEffPhi_%d", i);
1536  h_eleEffPhi_[i] = new TH1F(histoName, histoName, 400, -4., 4.);
1537  h_eleEffPhi_[i]->SetXTitle("Phi");
1538 
1539  sprintf(histoName, "h_eleEffPt_%d", i);
1540  h_eleEffPt_[i] = new TH1F(histoName, histoName, 200, 0., 200.);
1541  h_eleEffPt_[i]->SetXTitle("p_{T}(GeV/c)");
1542  }
1543 
1545  new TH2F("h2_xtalMiscalibCoeffBarrel", "h2_xtalMiscalibCoeffBarrel", 171, -85, 85, 360, 0, 360);
1547  new TH2F("h2_xtalMiscalibCoeffEndcapMinus", "h2_xtalMiscalibCoeffEndcapMinus", 100, 0, 100, 100, 0, 100);
1549  new TH2F("h2_xtalMiscalibCoeffEndcapPlus", "h2_xtalMiscalibCoeffEndcapPlus", 100, 0, 100, 100, 0, 100);
1550 
1551  h2_xtalMiscalibCoeffBarrel_->SetXTitle("ieta");
1552  h2_xtalMiscalibCoeffBarrel_->SetYTitle("iphi");
1553 
1554  h2_xtalMiscalibCoeffEndcapMinus_->SetXTitle("ix");
1555  h2_xtalMiscalibCoeffEndcapMinus_->SetYTitle("iy");
1556 
1557  for (int i = 0; i < 25; i++) {
1558  char histoName[50];
1559  sprintf(histoName, "h_ESCEtrueVsEta_%d", i);
1560 
1561  h_ESCEtrueVsEta_[i] = new TH2F(histoName, histoName, 150, 0., 2.7, 300, 0., 1.5);
1562  h_ESCEtrueVsEta_[i]->SetXTitle("|#eta|");
1563  h_ESCEtrueVsEta_[i]->SetYTitle("E_{SC,raw}/E_{MC}");
1564 
1565  sprintf(histoName, "h_ESCEtrue_%d", i);
1566 
1567  h_ESCEtrue_[i] = new TH1F(histoName, histoName, 300, 0., 1.5);
1568 
1569  sprintf(histoName, "h2_chi2_%d", i);
1570  h2_chi2_[i] = new TH2F(histoName, histoName, 1000, -150, 150, 1000, -1, 5);
1571 
1572  sprintf(histoName, "h2_iterations_%d", i);
1573  h2_iterations_[i] = new TH2F(histoName, histoName, 1000, -150, 150, 1000, -1, 15);
1574 
1575  sprintf(histoName, "h_ESCcorrEtrueVsEta_%d", i);
1576 
1577  h_ESCcorrEtrueVsEta_[i] = new TH2F(histoName, histoName, 150, 0., 2.7, 300, 0., 1.5);
1578  h_ESCcorrEtrueVsEta_[i]->SetXTitle("|#eta|");
1579  h_ESCcorrEtrueVsEta_[i]->SetYTitle("E_{SC,#eta-corr}/E_{MC}");
1580 
1581  sprintf(histoName, "h_ESCcorrEtrue_%d", i);
1582 
1583  h_ESCcorrEtrue_[i] = new TH1F(histoName, histoName, 300, 0., 1.5);
1584 
1585  sprintf(histoName, "h2_xtalRecalibCoeffBarrel_%d", i);
1586  h2_xtalRecalibCoeffBarrel_[i] = new TH2F(histoName, histoName, 171, -85, 85, 360, 0, 360);
1587 
1588  h2_xtalRecalibCoeffBarrel_[i]->SetXTitle("ieta");
1589  h2_xtalRecalibCoeffBarrel_[i]->SetYTitle("iphi");
1590 
1591  sprintf(histoName, "h2_xtalRecalibCoeffEndcapMinus_%d", i);
1592  h2_xtalRecalibCoeffEndcapMinus_[i] = new TH2F(histoName, histoName, 100, 0, 100, 100, 0, 100);
1593  h2_xtalRecalibCoeffEndcapMinus_[i]->SetXTitle("ix");
1594  h2_xtalRecalibCoeffEndcapMinus_[i]->SetYTitle("iy");
1595 
1596  sprintf(histoName, "h2_xtalRecalibCoeffEndcapPlus_%d", i);
1597  h2_xtalRecalibCoeffEndcapPlus_[i] = new TH2F(histoName, histoName, 100, 0, 100, 100, 0, 100);
1598  h2_xtalRecalibCoeffEndcapPlus_[i]->SetXTitle("ix");
1599  h2_xtalRecalibCoeffEndcapPlus_[i]->SetYTitle("iy");
1600  }
1601 
1602  /*
1603  for (int i=0;i<15;i++)
1604  {
1605 
1606  char histoName[50];
1607 
1608  sprintf(histoName,"h_DiffZMassDistr_%d",i);
1609  h_DiffZMassDistr_[i] = new TH1F(histoName,histoName, 400, -20., 20.);
1610  h_DiffZMassDistr_[i]->SetXTitle("M_{Z, reco} - M_{Z, MC}");
1611  h_DiffZMassDistr_[i]->SetYTitle("events");
1612 
1613  sprintf(histoName,"h_ZMassDistr_%d",i);
1614  h_ZMassDistr_[i] = new TH1F(histoName,histoName, 200, 0., 150.);
1615  h_ZMassDistr_[i]->SetXTitle("RecoZmass (GeV)");
1616  h_ZMassDistr_[i]->SetYTitle("events");
1617 
1618  }
1619  */
1620 
1621  h1_zMassResol_ = new TH1F("zMassResol", "zMassResol", 200, -50., 50.);
1622  h1_zMassResol_->SetXTitle("M_{Z, reco} - M_{Z, MC}");
1623  h1_zMassResol_->SetYTitle("events");
1624 
1625  h1_eleEtaResol_ = new TH1F("eleEtaResol", "eleEtaResol", 100, -0.01, 0.01);
1626  h1_eleEtaResol_->SetXTitle("#eta_{reco} - #eta_{MC}");
1627  h1_eleEtaResol_->SetYTitle("events");
1628 
1629  h1_electronCosTheta_TK_ = new TH1F("electronCosTheta_TK", "electronCosTheta_TK", 100, -1, 1);
1630  h1_electronCosTheta_TK_->SetXTitle("cos #theta_{12}");
1631  h1_electronCosTheta_TK_->SetYTitle("events");
1632 
1633  h1_electronCosTheta_SC_ = new TH1F("electronCosTheta_SC", "electronCosTheta_SC", 100, -1, 1);
1634  h1_electronCosTheta_SC_->SetXTitle("cos #theta_{12}");
1635  h1_electronCosTheta_SC_->SetYTitle("events");
1636 
1637  h1_electronCosTheta_SC_TK_ = new TH1F("electronCosTheta_SC_TK", "electronCosTheta_SC_TK", 200, -0.1, 0.1);
1638  h1_electronCosTheta_SC_TK_->SetXTitle("cos #theta_{12}^{SC}/ cos #theta_{12}^{TK} - 1");
1639  h1_electronCosTheta_SC_TK_->SetYTitle("events");
1640 
1641  h1_elePhiResol_ = new TH1F("elePhiResol", "elePhiResol", 100, -0.01, 0.01);
1642  h1_elePhiResol_->SetXTitle("#phi_{reco} - #phi_{MC}");
1643  h1_elePhiResol_->SetYTitle("events");
1644 
1645  h1_zEtaResol_ = new TH1F("zEtaResol", "zEtaResol", 200, -1., 1.);
1646  h1_zEtaResol_->SetXTitle("#eta_{Z, reco} - #eta_{Z, MC}");
1647  h1_zEtaResol_->SetYTitle("events");
1648 
1649  h1_zPhiResol_ = new TH1F("zPhiResol", "zPhiResol", 200, -1., 1.);
1650  h1_zPhiResol_->SetXTitle("#phi_{Z, reco} - #phi_{Z, MC}");
1651  h1_zPhiResol_->SetYTitle("events");
1652 
1653  h1_nEleReco_ = new TH1F("nEleReco", "Number of reco electrons", 10, -0.5, 10.5);
1654  h1_nEleReco_->SetXTitle("nEleReco");
1655  h1_nEleReco_->SetYTitle("events");
1656 
1657  // h1_occupancyVsEta_ = new TH1F("occupancyVsEta","occupancyVsEta",EcalRingCalibrationTools::N_RING_TOTAL,0,(float)EcalRingCalibrationTools::N_RING_TOTAL);
1658 
1659  h1_occupancyVsEta_ = new TH1F("occupancyVsEta", "occupancyVsEta", 249, -124, 124);
1660  h1_occupancyVsEta_->SetYTitle("Weighted electron statistics");
1661  h1_occupancyVsEta_->SetXTitle("Eta channel");
1662 
1663  h1_weightSumMeanBarrel_ = new TH1F("weightSumMeanBarrel", "weightSumMeanBarrel", 10000, 0, 10000);
1664  h1_weightSumMeanEndcap_ = new TH1F("weightSumMeanEndcap", "weightSumMeanEndcap", 10000, 0, 10000);
1665 
1666  h1_occupancy_ = new TH1F("occupancy", "occupancy", 1000, 0, 10000);
1667  h1_occupancy_->SetXTitle("Weighted electron statistics");
1668 
1669  h1_occupancyBarrel_ = new TH1F("occupancyBarrel", "occupancyBarrel", 1000, 0, 10000);
1670  h1_occupancyBarrel_->SetXTitle("Weighted electron statistics");
1671 
1672  h1_occupancyEndcap_ = new TH1F("occupancyEndcap", "occupancyEndcap", 1000, 0, 10000);
1673  h1_occupancyEndcap_->SetXTitle("Weighted electron statistics");
1674 
1675  h1_eleClasses_ = new TH1F("eleClasses", "eleClasses", 301, -1, 300);
1676  h1_eleClasses_->SetXTitle("classCode");
1677  h1_eleClasses_->SetYTitle("#");
1678 
1680 
1682 
1684 
1686 
1687  h1_ZCandMult_ = new TH1F("ZCandMult", "Multiplicity of Z candidates in one event", 10, -0.5, 10.5);
1688  h1_ZCandMult_->SetXTitle("ZCandMult");
1689 
1690  h1_reco_ZMass_ = new TH1F("reco_ZMass", "Inv. mass of 2 reco Electrons", 200, 0., 150.);
1691  h1_reco_ZMass_->SetXTitle("reco_ZMass (GeV)");
1692  h1_reco_ZMass_->SetYTitle("events");
1693 
1694  h1_reco_ZMassCorr_ = new TH1F("reco_ZMassCorr", "Inv. mass of 2 corrected reco Electrons", 200, 0., 150.);
1695  h1_reco_ZMassCorr_->SetXTitle("reco_ZMass (GeV)");
1696  h1_reco_ZMassCorr_->SetYTitle("events");
1697 
1698  h1_reco_ZMassCorrBB_ = new TH1F("reco_ZMassCorrBB", "Inv. mass of 2 corrected reco Electrons", 200, 0., 150.);
1699  h1_reco_ZMassCorrBB_->SetXTitle("reco_ZMass (GeV)");
1700  h1_reco_ZMassCorrBB_->SetYTitle("events");
1701 
1702  h1_reco_ZMassCorrEE_ = new TH1F("reco_ZMassCorrEE", "Inv. mass of 2 corrected reco Electrons", 200, 0., 150.);
1703  h1_reco_ZMassCorrEE_->SetXTitle("reco_ZMass (GeV)");
1704  h1_reco_ZMassCorrEE_->SetYTitle("events");
1705 
1706  // h2_coeffVsEta_= new TH2F("h2_calibCoeffVsEta","h2_calibCoeffVsEta",EcalRingCalibrationTools::N_RING_TOTAL,0, (double)EcalRingCalibrationTools::N_RING_TOTAL, 200, 0., 2.);
1707 
1708  h2_coeffVsEta_ = new TH2F("h2_calibCoeffVsEta", "h2_calibCoeffVsEta", 249, -124, 125, 200, 0., 2.);
1709  h2_coeffVsEta_->SetXTitle("Eta channel");
1710  h2_coeffVsEta_->SetYTitle("recalibCoeff");
1711 
1713  new TH2F("h2_calibCoeffVsEtaGrouped", "h2_calibCoeffVsEtaGrouped", 200, 0., 3., 200, 0.6, 1.4);
1714  h2_coeffVsEtaGrouped_->SetXTitle("|#eta|");
1715  h2_coeffVsEtaGrouped_->SetYTitle("recalibCoeff");
1716 
1717  h2_zMassVsLoop_ = new TH2F("h2_zMassVsLoop", "h2_zMassVsLoop", 1000, 0, 40, 90, 80., 95.);
1718 
1719  h2_zMassDiffVsLoop_ = new TH2F("h2_zMassDiffVsLoop", "h2_zMassDiffVsLoop", 1000, 0, 40, 100, -1., 1.);
1720  h2_zMassDiffVsLoop_->SetXTitle("Iteration");
1721  h2_zMassDiffVsLoop_->SetYTitle("M_{Z, reco peak} - M_{Z, true}");
1722 
1723  h2_zWidthVsLoop_ = new TH2F("h2_zWidthVsLoop", "h2_zWidthVsLoop", 1000, 0, 40, 100, 0., 10.);
1724 
1725  h2_coeffVsLoop_ = new TH2F("h2_coeffVsLoop", "h2_coeffVsLoop", 1000, 0, 40, 100, 0., 2.);
1726 
1727  h2_residualSigma_ = new TH2F("h2_residualSigma", "h2_residualSigma", 1000, 0, 40, 100, 0., .5);
1728 
1729  h2_miscalRecal_ = new TH2F("h2_miscalRecal", "h2_miscalRecal", 500, 0., 2., 500, 0., 2.);
1730  h2_miscalRecal_->SetXTitle("initCalibCoeff");
1731  h2_miscalRecal_->SetYTitle("1/RecalibCoeff");
1732 
1733  h2_miscalRecalEB_ = new TH2F("h2_miscalRecalEB", "h2_miscalRecalEB", 500, 0., 2., 500, 0., 2.);
1734  h2_miscalRecalEB_->SetXTitle("initCalibCoeff");
1735  h2_miscalRecalEB_->SetYTitle("1/RecalibCoeff");
1736 
1737  h2_miscalRecalEE_ = new TH2F("h2_miscalRecalEE", "h2_miscalRecalEE", 500, 0., 2., 500, 0., 2.);
1738  h2_miscalRecalEE_->SetXTitle("initCalibCoeff");
1739  h2_miscalRecalEE_->SetYTitle("1/RecalibCoeff");
1740 
1741  h1_mc_ = new TH1F("h1_residualMiscalib", "h1_residualMiscalib", 200, -0.2, 0.2);
1742  h1_mcEB_ = new TH1F("h1_residualMiscalibEB", "h1_residualMiscalibEB", 200, -0.2, 0.2);
1743  h1_mcEE_ = new TH1F("h1_residualMiscalibEE", "h1_residualMiscalibEE", 200, -0.2, 0.2);
1744 
1745  for (int i = 0; i < 25; i++) {
1746  char histoName[50];
1747  /*
1748  sprintf(histoName,"h2_miscalRecalParz_%d",i);
1749  h2_miscalRecalParz_[i] = new TH2F(histoName,histoName,500, 0., 2., 500, 0., 2.);
1750  h2_miscalRecalParz_[i]->SetXTitle("initCalibCoeff");
1751  h2_miscalRecalParz_[i]->SetYTitle("1/recalibCoeff");
1752 
1753  sprintf(histoName,"h2_miscalRecalEBParz_%d",i);
1754  h2_miscalRecalEBParz_[i] = new TH2F(histoName,histoName,500, 0., 2., 500, 0., 2.);
1755  h2_miscalRecalEBParz_[i]->SetXTitle("initCalibCoeff");
1756  h2_miscalRecalEBParz_[i]->SetYTitle("1/recalibCoeff");
1757 
1758  sprintf(histoName,"h2_miscalRecalEEParz_%d",i);
1759  h2_miscalRecalEEParz_[i] = new TH2F(histoName,histoName,500, 0., 2., 500, 0., 2.);
1760  h2_miscalRecalEEParz_[i]->SetXTitle("initCalibCoeff");
1761  h2_miscalRecalEEParz_[i]->SetYTitle("1/recalibCoeff");
1762  */
1763 
1764  sprintf(histoName, "h1_residualMiscalibParz_%d", i);
1765  h1_mcParz_[i] = new TH1F(histoName, histoName, 200, -0.2, 0.2);
1766  sprintf(histoName, "h1_residualMiscalibEBParz_%d", i);
1767  h1_mcEBParz_[i] = new TH1F(histoName, histoName, 200, -0.2, 0.2);
1768  sprintf(histoName, "h1_residualMiscalibEEParz_%d", i);
1769  h1_mcEEParz_[i] = new TH1F(histoName, histoName, 200, -0.2, 0.2);
1770  }
1771 }
1772 
1773 double ZeeCalibration::fEtaBarrelBad(double scEta) const {
1774  float p0 = 1.00153e+00;
1775  float p1 = 3.29331e-02;
1776  float p2 = 1.21187e-03;
1777 
1778  double x = (double)fabs(scEta);
1779 
1780  return 1. / (p0 + p1 * x * x + p2 * x * x * x * x);
1781 }
1782 
1783 double ZeeCalibration::fEtaEndcapGood(double scEta) const {
1784  // f(eta) for the first 3 classes (100, 110 and 120)
1785  // Ivica's new corrections 01/06
1786  float p0 = 1.06819e+00;
1787  float p1 = -1.53189e-02;
1788  float p2 = 4.01707e-04;
1789 
1790  double x = (double)fabs(scEta);
1791 
1792  return 1. / (p0 + p1 * x * x + p2 * x * x * x * x);
1793 }
1794 
1795 double ZeeCalibration::fEtaEndcapBad(double scEta) const {
1796  float p0 = 1.17382e+00;
1797  float p1 = -6.52319e-02;
1798  float p2 = 6.26108e-03;
1799 
1800  double x = (double)fabs(scEta);
1801 
1802  return 1. / (p0 + p1 * x * x + p2 * x * x * x * x);
1803 }
1804 
1805 double ZeeCalibration::fEtaBarrelGood(double scEta) const {
1806  float p0 = 9.99782e-01;
1807  float p1 = 1.26983e-02;
1808  float p2 = 2.16344e-03;
1809 
1810  double x = (double)fabs(scEta);
1811 
1812  return 1. / (p0 + p1 * x * x + p2 * x * x * x * x);
1813 }
1814 
1816 
1817 void ZeeCalibration::fillMCmap(const std::vector<const reco::GsfElectron*>* electronCollection,
1818  const std::vector<HepMC::GenParticle*>& mcEle,
1819  std::map<HepMC::GenParticle*, const reco::GsfElectron*>& myMCmap) {
1820  for (unsigned int i = 0; i < mcEle.size(); i++) {
1821  float minDR = 0.1;
1822  const reco::GsfElectron* myMatchEle = nullptr;
1823  for (unsigned int j = 0; j < electronCollection->size(); j++) {
1824  float dr = EvalDR(mcEle[i]->momentum().pseudoRapidity(),
1825  (*(*electronCollection)[j]).eta(),
1826  mcEle[i]->momentum().phi(),
1827  (*(*electronCollection)[j]).phi());
1828  if (dr < minDR) {
1829  myMatchEle = (*electronCollection)[j];
1830  minDR = dr;
1831  }
1832  }
1833  myMCmap.insert(std::pair<HepMC::GenParticle*, const reco::GsfElectron*>(mcEle[i], myMatchEle));
1834  }
1835 }
1836 
1837 float ZeeCalibration::EvalDR(float Eta, float Eta_ref, float Phi, float Phi_ref) {
1838  if (Phi < 0)
1839  Phi = 2 * TMath::Pi() + Phi;
1840  if (Phi_ref < 0)
1841  Phi_ref = 2 * TMath::Pi() + Phi_ref;
1842  float DPhi = Phi - Phi_ref;
1843  if (fabs(DPhi) > TMath::Pi())
1844  DPhi = 2 * TMath::Pi() - fabs(DPhi);
1845 
1846  float DEta = Eta - Eta_ref;
1847 
1848  float DR = sqrt(DEta * DEta + DPhi * DPhi);
1849  return DR;
1850 }
1851 
1852 float ZeeCalibration::EvalDPhi(float Phi, float Phi_ref) {
1853  if (Phi < 0)
1854  Phi = 2 * TMath::Pi() + Phi;
1855  if (Phi_ref < 0)
1856  Phi_ref = 2 * TMath::Pi() + Phi_ref;
1857  return (Phi - Phi_ref);
1858 }
1859 
1860 void ZeeCalibration::fillEleInfo(std::vector<HepMC::GenParticle*>& mcEle,
1861  std::map<HepMC::GenParticle*, const reco::GsfElectron*>& associationMap) {
1862  for (unsigned int i = 0; i < mcEle.size(); i++) {
1863  h_eleEffEta_[0]->Fill(fabs(mcEle[i]->momentum().pseudoRapidity()));
1864  h_eleEffPhi_[0]->Fill(mcEle[i]->momentum().phi());
1865  h_eleEffPt_[0]->Fill(mcEle[i]->momentum().perp());
1866 
1867  std::map<HepMC::GenParticle*, const reco::GsfElectron*>::const_iterator mIter = associationMap.find(mcEle[i]);
1868  if (mIter == associationMap.end())
1869  continue;
1870 
1871  if ((*mIter).second) {
1872  const reco::GsfElectron* myEle = (*mIter).second;
1873 
1874  h_eleEffEta_[1]->Fill(fabs(mcEle[i]->momentum().pseudoRapidity()));
1875  h_eleEffPhi_[1]->Fill(mcEle[i]->momentum().phi());
1876  h_eleEffPt_[1]->Fill(mcEle[i]->momentum().perp());
1877  h1_eleEtaResol_->Fill(myEle->eta() - mcEle[i]->momentum().eta());
1878  h1_elePhiResol_->Fill(myEle->phi() - mcEle[i]->momentum().phi());
1879 
1880  const reco::SuperCluster* mySC = &(*(myEle->superCluster()));
1881  if (/*fabs(mySC->position().eta()) < 2.4*/ true) {
1882  // if(myEle->classification()>=100)std::cout<<"mySC->preshowerEnergy()"<<mySC->preshowerEnergy()<<std::endl;
1883 
1884  h_ESCEtrue_[loopFlag_]->Fill(mySC->energy() / mcEle[i]->momentum().e());
1885  h_ESCEtrueVsEta_[loopFlag_]->Fill(fabs(mySC->position().eta()), mySC->energy() / mcEle[i]->momentum().e());
1886 
1887  double corrSCenergy = (mySC->energy()) / getEtaCorrection(myEle);
1888  h_ESCcorrEtrue_[loopFlag_]->Fill(corrSCenergy / mcEle[i]->momentum().e());
1889  h_ESCcorrEtrueVsEta_[loopFlag_]->Fill(fabs(mySC->position().eta()), corrSCenergy / mcEle[i]->momentum().e());
1890 
1891  // std::vector<DetId> mySCRecHits = mySC->seed()->getHitsByDetId();
1892 
1893  h1_seedOverSC_->Fill(mySC->seed()->energy() / mySC->energy());
1894  h1_preshowerOverSC_->Fill(mySC->preshowerEnergy() / mySC->energy());
1895  }
1896  }
1897  }
1898 }
1899 
1901  int index = -999;
1902 
1903  if (calibMode_ == "RING") {
1904  if (k >= 0 && k <= 84)
1905  index = k - 85;
1906 
1907  if (k >= 85 && k <= 169)
1908  index = k - 84;
1909 
1910  if (k >= 170 && k <= 208)
1911  index = -k + 84;
1912 
1913  if (k >= 209 && k <= 247)
1914  index = k - 123;
1915 
1916  }
1917 
1918  else if (calibMode_ == "MODULE") {
1919  if (k >= 0 && k <= 71)
1920  index = k - 72;
1921 
1922  if (k >= 72 && k <= 143)
1923  index = k - 71;
1924  }
1925  return index;
1926 }
1927 
1929  double correction(1.);
1930 
1931  int c = ele->classification();
1932  if (c == 0 || c == 10 || c == 20)
1933  correction = fEtaBarrelGood(ele->superCluster()->eta());
1934 
1935  if (c == 100 || c == 110 || c == 120)
1936  correction = fEtaEndcapGood(ele->superCluster()->eta());
1937 
1938  if (c == 30 || c == 31 || c == 32 || c == 33 || c == 34)
1939  correction = fEtaBarrelBad(ele->superCluster()->eta());
1940 
1941  if (c == 130 || c == 131 || c == 132 || c == 133 || c == 134)
1942  correction = fEtaEndcapBad(ele->superCluster()->eta());
1943 
1944  return correction;
1945 }
1946 
1947 std::pair<DetId, double> ZeeCalibration::getHottestDetId(const std::vector<std::pair<DetId, float> >& mySCRecHits,
1948  const EBRecHitCollection* ebhits,
1949  const EERecHitCollection* eehits) {
1950  double maxEnergy = -9999.;
1951  const EcalRecHit* hottestRecHit = nullptr;
1952 
1953  std::pair<DetId, double> myPair(DetId(0), -9999.);
1954 
1955  for (std::vector<std::pair<DetId, float> >::const_iterator idIt = mySCRecHits.begin(); idIt != mySCRecHits.end();
1956  idIt++) {
1957  if (idIt->first.subdetId() == EcalBarrel) {
1958  hottestRecHit = &(*(ebhits->find((*idIt).first)));
1959 
1960  if (hottestRecHit == &(*(ebhits->end()))) {
1961  std::cout << "@@@@@@@@@@@@@@@@@@@@@@@@@@@ NO RECHIT FOUND SHOULD NEVER HAPPEN" << std::endl;
1962  continue;
1963  }
1964  } else if (idIt->first.subdetId() == EcalEndcap) {
1965  hottestRecHit = &(*(eehits->find((*idIt).first)));
1966  if (hottestRecHit == &(*(eehits->end()))) {
1967  std::cout << "@@@@@@@@@@@@@@@@@@@@@@@@@@@ NO RECHIT FOUND SHOULD NEVER HAPPEN" << std::endl;
1968  continue;
1969  }
1970  }
1971 
1972  //std::cout<<"[getHottestDetId] hottestRecHit->energy() "<<hottestRecHit->energy()<<std::endl;
1973 
1974  if (hottestRecHit && hottestRecHit->energy() > maxEnergy) {
1975  maxEnergy = hottestRecHit->energy();
1976 
1977  myPair.first = hottestRecHit->id();
1978  myPair.second = maxEnergy;
1979  }
1980 
1981  } //end loop to find hottest RecHit
1982 
1983  //std::cout<<"[ZeeCalibration::getHottestDetId] going to return..."<<std::endl;
1984 
1985  return myPair;
1986 }
1987 
1989  bool myBool(false);
1990 
1991  short ieta = myEBDetId.ieta();
1992  short iphi = myEBDetId.iphi();
1993 
1994  // std::cout<<"[xtalIsOnModuleBorder] ieta: "<<ieta<<" iphi "<<iphi<<std::endl;
1995 
1996  myBool = (abs(ieta) == 1 || abs(ieta) == 25 || abs(ieta) == 26 || abs(ieta) == 45 || abs(ieta) == 46 ||
1997  abs(ieta) == 65 || abs(ieta) == 66 || abs(ieta) == 85);
1998 
1999  for (int i = 0; i < 19; i++) {
2000  if (iphi == (20 * i + 1) || iphi == 20 * i)
2001  myBool = true;
2002  }
2003 
2004  return myBool;
2005 }
2006 
2007 float ZeeCalibration::computeCoefficientDistanceAtIteration(float v1[250], float v2[250], int size) {
2008  float dist(0.);
2009 
2010  for (int i = 0; i < size; i++) {
2011  // std::cout<< "[ZeeCalibration::computeCoefficientDistanceAtIteration] Adding term "<<pow( v1[i]-v2[i], 2 )<<" from v1 "<<v1[i]<<" and v2 "<<v2[i]<<std::endl;
2012 
2013  bool isNearCrack = false;
2014 
2015  if (calibMode_ == "RING") { //exclude non-calibrated rings from computation
2016 
2017  isNearCrack = (abs(ringNumberCorrector(i)) == 1 || abs(ringNumberCorrector(i)) == 25 ||
2018  abs(ringNumberCorrector(i)) == 26 || abs(ringNumberCorrector(i)) == 45 ||
2019  abs(ringNumberCorrector(i)) == 46 || abs(ringNumberCorrector(i)) == 65 ||
2020  abs(ringNumberCorrector(i)) == 66 || abs(ringNumberCorrector(i)) == 85 ||
2021  abs(ringNumberCorrector(i)) == 86 || abs(ringNumberCorrector(i)) == 124);
2022  }
2023 
2024  if (!isNearCrack)
2025  dist += pow(v1[i] - v2[i], 2);
2026  }
2027 
2028  dist = sqrt(dist) / size;
2029 
2030  return dist;
2031 }
2032 
2034  BBZN = 0;
2035  EBZN = 0;
2036  EEZN = 0;
2037  BBZN_gg = 0;
2038  EBZN_gg = 0;
2039  EEZN_gg = 0;
2040 
2041  BBZN_tt = 0;
2042  EBZN_tt = 0;
2043  EEZN_tt = 0;
2044 
2045  BBZN_t0 = 0;
2046  EBZN_t0 = 0;
2047  EEZN_t0 = 0;
2048 
2051 
2060 
2063 
2064  return;
2065 }
2066 
2069  h1_eventsAfterEWKSelection_->Reset();
2070 
2073 
2074  for (int i = 0; i < 2; i++) {
2075  h_eleEffEta_[i]->Reset();
2076  h_eleEffPhi_[i]->Reset();
2077  h_eleEffPt_[i]->Reset();
2078  }
2079 
2080  h1_seedOverSC_->Reset();
2081  h1_preshowerOverSC_->Reset();
2082 
2083  h1_eleEtaResol_->Reset();
2084  h1_elePhiResol_->Reset();
2085 
2086  h1_zMassResol_->Reset();
2087 
2088  h1_electronCosTheta_TK_->Reset();
2089  h1_electronCosTheta_SC_->Reset();
2090  h1_electronCosTheta_SC_TK_->Reset();
2091 
2092  h2_fEtaBarrelGood_->Reset();
2093  h2_fEtaBarrelBad_->Reset();
2094  h2_fEtaEndcapGood_->Reset();
2095  h2_fEtaEndcapBad_->Reset();
2096  h1_eleClasses_->Reset();
2097 
2098  h1_ZCandMult_->Reset();
2099  h1_reco_ZMass_->Reset();
2100  h1_reco_ZMassCorr_->Reset();
2101  h1_reco_ZMassCorrBB_->Reset();
2102  h1_reco_ZMassCorrEE_->Reset();
2103  h1_occupancyVsEta_->Reset();
2104  h1_occupancy_->Reset();
2105  h1_occupancyBarrel_->Reset();
2106  h1_occupancyEndcap_->Reset();
2107 
2108  return;
2109 }
2110 
2112  std::cout << "[ CHECK ON BARREL ELECTRON NUMBER ]"
2113  << " first " << BARREL_ELECTRONS_BEFORE_BORDER_CUT << " second " << TOTAL_ELECTRONS_IN_BARREL << std::endl;
2114 
2115  std::cout << "[ EFFICIENCY OF THE BORDER SELECTION ]"
2117 
2118  std::cout << "[ EFFICIENCY OF THE GOLDEN SELECTION ] BARREL: "
2120  << " ENDCAP: " << (float)GOLDEN_ELECTRONS_IN_ENDCAP / (float)TOTAL_ELECTRONS_IN_ENDCAP << std::endl;
2121 
2122  std::cout << "[ EFFICIENCY OF THE SILVER SELECTION ] BARREL: "
2124  << " ENDCAP: " << (float)SILVER_ELECTRONS_IN_ENDCAP / (float)TOTAL_ELECTRONS_IN_ENDCAP << std::endl;
2125 
2126  std::cout << "[ EFFICIENCY OF THE SHOWER SELECTION ] BARREL: "
2128  << " ENDCAP: " << (float)SHOWER_ELECTRONS_IN_ENDCAP / (float)TOTAL_ELECTRONS_IN_ENDCAP << std::endl;
2129 
2130  std::cout << "[ EFFICIENCY OF THE CRACK SELECTION ] BARREL: "
2132  << " ENDCAP: " << (float)CRACK_ELECTRONS_IN_ENDCAP / (float)TOTAL_ELECTRONS_IN_ENDCAP << std::endl;
2133 
2134  std::ofstream fout("ZeeStatistics.txt");
2135 
2136  if (!fout) {
2137  std::cout << "Cannot open output file.\n";
2138  }
2139 
2140  fout << "ZeeStatistics" << std::endl;
2141 
2142  fout << "##########################RECO#########################" << std::endl;
2143  fout << "##################Zee with Barrel-Barrel electrons: " << BBZN << std::endl;
2144 
2145  fout << "Golden-Golden fraction: " << (float)BBZN_gg / BBZN << " 3-3 fraction is " << (float)BBZN_tt / BBZN
2146  << " 3-whatever fraction is " << (float)BBZN_t0 / BBZN << std::endl;
2147  fout << "##################Zee with Barrel-Endcap electrons: " << EBZN << std::endl;
2148  fout << "Golden-Golden fraction: " << (float)EBZN_gg / EBZN << " 3-3 fraction is " << (float)EBZN_tt / EBZN
2149  << " 3-whatever fraction is " << (float)EBZN_t0 / EBZN << std::endl;
2150  fout << "##################Zee with Endcap-Endcap electrons: " << EEZN << std::endl;
2151  fout << "Golden-Golden fraction: " << (float)EEZN_gg / EEZN << " 3-3 fraction is " << (float)EEZN_tt / EEZN
2152  << " 3-whatever fraction is " << (float)EEZN_t0 / EEZN << std::endl;
2153 
2154  fout << "\n" << std::endl;
2155 
2156  fout << "##########################GEN#########################" << std::endl;
2157  fout << "##################Zee with Barrel-Barrel electrons: " << (float)MCZBB / NEVT << std::endl;
2158  fout << "##################Zee with Barrel-Endcap electrons: " << (float)MCZEB / NEVT << std::endl;
2159  fout << "##################Zee with Endcap-Endcap electrons: " << (float)MCZEE / NEVT << std::endl;
2160 
2161  fout.close();
2162 }
unsigned int etBins_
size
Write out results.
const double Pi
T getParameter(std::string const &) const
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:138
T getUntrackedParameter(std::string const &, T const &) const
const math::XYZPoint & position() const
cluster centroid position
Definition: CaloCluster.h:153
TH2F * h2_fEtaBarrelBad_
TH1F * h1_mcEEParz_[25]
const ZIterativeAlgorithmWithFitPlots * getHistos() const
std::string calibMode_
std::string outputFileName_
static const int MIN_IPHI
Definition: EBDetId.h:135
double fEtaEndcapGood(double scEta) const
double eta() const final
momentum pseudorapidity
void setBinRange(int, double, double, int, double, double)
int ix() const
Definition: EEDetId.h:77
static void setCaloGeometry(const CaloGeometry *geometry)
std::string scIslandCollection_
TH1F * h_eleEffPhi_[2]
std::string electronCollection_
int BARREL_ELECTRONS_AFTER_BORDER_CUT
TH2F * h2_miscalRecal_
TH1F * h1_eventsBeforeEWKSelection_
double fEtaBarrelBad(double scEta) const
float computeCoefficientDistanceAtIteration(float v1[250], float v2[250], int size)
static float calculateZMassWithCorrectedElectrons_withTK(const std::pair< calib::CalibElectron *, calib::CalibElectron * > &aZCandidate, float ele1EnergyCorrection, float ele2EnergyCorrection)
float calibCoeff[250]
const self & getMap() const
static float cosThetaElectrons_TK(const std::pair< calib::CalibElectron *, calib::CalibElectron * > &aZCandidate, float ele1EnergyCorrection, float ele2EnergyCorrection)
void fillEleInfo(const reco::GsfElectronCollection *)
Definition: ZeePlots.cc:220
void fillEleMCInfo(const HepMC::GenEvent *)
Definition: ZeePlots.cc:178
const std::vector< float > & getOptimizedChiSquare() const
unsigned int theMaxLoops
int GOLDEN_ELECTRONS_IN_ENDCAP
void fillZMCInfo(const HepMC::GenEvent *)
Definition: ZeePlots.cc:132
TH1F * h_ESCEtrue_[25]
TH1F * h1_eventsAfterBorderSelection_
edm::InputTag hlTriggerResults_
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
bool accept() const
Has at least one path accepted the event?
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
bool parseXMLMiscalibFile(std::string configFile)
void fillMCmap(const std::vector< const reco::GsfElectron * > *electronCollection, const std::vector< HepMC::GenParticle * > &mcEle, std::map< HepMC::GenParticle *, const reco::GsfElectron * > &myMCmap)
static float calculateZMass_withTK(const std::pair< calib::CalibElectron *, calib::CalibElectron * > &aZCandidate)
const std::vector< float > & getOptimizedCoefficients() const
TH1F * h1_occupancyEndcap_
#define MZ
bool addEvent(calib::CalibElectron *, calib::CalibElectron *, float)
void writeMCEleHistograms()
Definition: ZeePlots.cc:255
Status duringLoop(const edm::Event &, const edm::EventSetup &) override
Called at each event.
TH1F * h1_eventsBeforeBorderSelection_
TH1F * h1_electronCosTheta_SC_
void writeMCZHistograms()
Definition: ZeePlots.cc:122
double fEtaEndcapBad(double scEta) const
static float cosThetaElectrons_SC(const std::pair< calib::CalibElectron *, calib::CalibElectron * > &aZCandidate, float ele1EnergyCorrection, float ele2EnergyCorrection)
TH1F * h1_reco_ZMassCorr_
static void gausfit(TH1F *histoou, double *par, double *errpar, float nsigmalow, float nsigmaup, double *mychi2, int *iterations)
int GOLDEN_ELECTRONS_IN_BARREL
TH2F * h2_coeffVsEtaGrouped_
TH1F * h1_occupancyVsEta_
std::string endcapfile_
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
static std::vector< DetId > getDetIdsInRing(short aRingIndex)
Retrieve the DetIds in a phi-ring.
static const int IX_MIN
Definition: EEDetId.h:290
std::string rechitCollection_
TH1F * h1_occupancyBarrel_
static const int IY_MIN
Definition: EEDetId.h:294
~ZeeCalibration() override
Destructor.
TH2F * h2_miscalRecalEE_
static bool validDetId(int i, int j)
check if a valid index combination
Definition: EBDetId.h:118
float EvalDR(float Eta, float Eta_ref, float Phi, float Phi_ref)
int iphi() const
get the crystal iphi
Definition: EBDetId.h:51
void bookEleHistograms()
Definition: ZeePlots.cc:195
U second(std::pair< T, U > const &p)
TH1F * h1_electronCosTheta_TK_
TH2F * h_ESCcorrEtrueVsEta_[25]
int iEvent
Definition: GenABIO.cc:224
TH2F * h2_fEtaEndcapBad_
std::string rechitProducer_
const EcalIntercalibConstants & get()
int ringNumberCorrector(int k)
std::string scIslandProducer_
int SILVER_ELECTRONS_IN_BARREL
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
void beginOfJob() override
Called at beginning of job.
double sigmaArray[50]
int TOTAL_ELECTRONS_IN_ENDCAP
int BARREL_ELECTRONS_BEFORE_BORDER_CUT
T sqrt(T t)
Definition: SSEVec.h:19
unsigned int size() const
Get number of paths stored.
void fillHLTInfo(edm::Handle< edm::TriggerResults >)
Definition: ZeePlots.cc:299
int SHOWER_ELECTRONS_IN_ENDCAP
static EcalIndexingTools * getInstance()
std::string scProducer_
void writeZHistograms()
Definition: ZeePlots.cc:110
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
int zside() const
Definition: EEDetId.h:71
std::string erechitProducer_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
TH1F * h1_mcEBParz_[25]
float energy() const
Definition: EcalRecHit.h:68
double energy() const
cluster energy
Definition: CaloCluster.h:148
ZIterativeAlgorithmWithFit * theAlgorithm_
int iy() const
Definition: EEDetId.h:83
int ieta() const
get the crystal ieta
Definition: EBDetId.h:49
TH1F * h1_elePhiResol_
unsigned int electronSelection_
bool isValid() const
Definition: HandleBase.h:70
bool xtalIsOnModuleBorder(EBDetId myEBDetId)
TH1F * h1_eleEtaResol_
TH2F * h2_xtalRecalibCoeffBarrel_[25]
double p2[4]
Definition: TauolaWrapper.h:90
float EvalDPhi(float Phi, float Phi_ref)
TH1F * h1_eventsAfterEWKSelection_
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:488
static std::vector< DetId > getDetIdsInModule(short int)
void bookZMCHistograms()
Definition: ZeePlots.cc:50
TH1F * h1_preshowerOverSC_
TH1F * h1_electronCosTheta_SC_TK_
double coefficientDistanceAtIteration[50]
TH1F * h_eleEffPt_[2]
static const int IX_MAX
Definition: EEDetId.h:298
const_iterator end() const
TH2F * h2_zMassDiffVsLoop_
std::string scCollection_
void startingNewLoop(unsigned int iLoop) override
Called at beginning of loop.
Definition: DetId.h:17
TH1F * h1_mcParz_[25]
const std::vector< float > & getOptimizedCoefficientsError() const
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:34
static const int MAX_IPHI
Definition: EBDetId.h:137
DetId id() const
get the id
Definition: EcalRecHit.h:77
ZeePlots * myZeePlots_
T const * product() const
Definition: Handle.h:69
void writeEleHistograms()
Definition: ZeePlots.cc:240
unsigned int etaBins_
edm::ParameterSet theParameterSet
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
TH2F * h2_miscalRecalEB_
Classification classification() const
Definition: GsfElectron.h:722
TH1F * h_ESCcorrEtrue_[25]
std::pair< DetId, double > getHottestDetId(const std::vector< std::pair< DetId, float > > &mySCRecHits, const EBRecHitCollection *ebhits, const EERecHitCollection *eehits)
double loopArray[50]
TH2F * h2_xtalMiscalibCoeffEndcapPlus_
static const int MAX_IETA
Definition: EBDetId.h:136
Status endOfLoop(const edm::EventSetup &, unsigned int iLoop) override
Called at end of loop.
static std::vector< DetId > getDetIdsInECAL()
float initCalibCoeff[250]
int SILVER_ELECTRONS_IN_ENDCAP
std::string mcProducer_
TH1F * h1_reco_ZMassCorrBB_
void writeLine(EBDetId const &, float)
iterator find(key_type k)
T perp() const
Magnitude of transverse component.
virtual std::shared_ptr< EcalIntercalibConstants > produceEcalIntercalibConstants(const EcalIntercalibConstantsRcd &iRecord)
Produce Ecal interCalibrations.
HLT enums.
double p1[4]
Definition: TauolaWrapper.h:89
TH1F * h1_reco_ZMassCorrEE_
TH2F * h2_xtalMiscalibCoeffBarrel_
T get() const
Definition: EventSetup.h:73
TH2F * h2_chi2_[25]
TH2F * h2_coeffVsLoop_
void fillZInfo(std::pair< calib::CalibElectron *, calib::CalibElectron * > myZeeCandidate)
Definition: ZeePlots.cc:100
void fillEleInfo(std::vector< HepMC::GenParticle * > &a, std::map< HepMC::GenParticle *, const reco::GsfElectron * > &b)
SuperClusterRef superCluster() const override
reference to a SuperCluster
Definition: GsfElectron.h:155
const_iterator find(uint32_t rawId) const
std::string barrelfile_
TH1F * h1_weightSumMeanBarrel_
double fEtaBarrelGood(double scEta) const
TH2F * h_ESCEtrueVsEta_[25]
TH2F * h2_zMassVsLoop_
void bookZHistograms()
Definition: ZeePlots.cc:74
static const int IY_MAX
Definition: EEDetId.h:302
TH2F * h2_iterations_[25]
void bookHLTHistograms()
Definition: ZeePlots.cc:270
const CaloClusterPtr & seed() const
seed BasicCluster
Definition: SuperCluster.h:77
ZeeCalibration(const edm::ParameterSet &iConfig)
Constructor.
float NewCalibCoeff[250]
double preshowerEnergy() const
energy deposited in preshower
Definition: SuperCluster.h:61
float calibCoeffError[250]
TH2F * h2_xtalRecalibCoeffEndcapPlus_[25]
int CRACK_ELECTRONS_IN_ENDCAP
int CRACK_ELECTRONS_IN_BARREL
TH2F * h2_fEtaEndcapGood_
TH2F * h2_xtalRecalibCoeffEndcapMinus_[25]
void bookEleMCHistograms()
Definition: ZeePlots.cc:156
std::string electronProducer_
double getEtaCorrection(const reco::GsfElectron *)
double phi() const final
momentum azimuthal angle
bool aHLTResults[200]
TH2F * h2_fEtaBarrelGood_
std::string erechitCollection_
TH1F * h_eleEffEta_[2]
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:30
TH1F * h1_borderElectronClassification_
TH2F * h2_xtalMiscalibCoeffEndcapMinus_
TH2F * h2_zWidthVsLoop_
void endOfJob() override
Called at end of job.
double sigmaErrorArray[50]
TH2F * h2_residualSigma_
int SHOWER_ELECTRONS_IN_BARREL
ib
Definition: cuy.py:662
const std::vector< int > & getOptimizedIterations() const
int TOTAL_ELECTRONS_IN_BARREL
TH1F * h1_weightSumMeanEndcap_
std::shared_ptr< EcalIntercalibConstants > ical