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