CMS 3D CMS Logo

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