CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/src/Calibration/EcalCalibAlgos/interface/ZeeCalibration.h

Go to the documentation of this file.
00001 #ifndef CALIBRATION_ECALCALIBALGOS_ZEECALIBRATION
00002 #define CALIBRATION_ECALCALIBALGOS_ZEECALIBRATION
00003 
00004 // -*- C++ -*-
00005 //
00006 // Package:    ZeeCalibration
00007 // Class:      ZeeCalibration
00008 // 
00016 //
00017 // $Id: ZeeCalibration.h,v 1.15 2012/02/09 08:01:42 eulisse Exp $
00018 //
00019 //
00020 
00021 
00022 // system include files
00023 #include <memory>
00024 #include <vector>
00025 #include <map>
00026 
00027 // user include files
00028 #include "FWCore/Framework/interface/LooperFactory.h"
00029 #include "FWCore/Framework/interface/ESProducerLooper.h"
00030 #include "FWCore/Framework/interface/ESHandle.h"
00031 #include "FWCore/Framework/interface/Frameworkfwd.h"
00032 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00033 #include "FWCore/Framework/interface/EDProducer.h"
00034 #include "FWCore/Framework/interface/Event.h"
00035 #include "FWCore/Framework/interface/EventSetup.h"
00036 #include "FWCore/Framework/interface/ESHandle.h"
00037 
00038 #include "Calibration/Tools/interface/ZIterativeAlgorithmWithFit.h"
00039 #include "Calibration/Tools/interface/CalibElectron.h"
00040 
00041 #include "Calibration/EcalCalibAlgos/interface/ZeePlots.h"
00042 #include "Calibration/EcalCalibAlgos/interface/ZeeRescaleFactorPlots.h"
00043 
00044 #include "CondFormats/EcalObjects/interface/EcalIntercalibConstants.h"
00045 #include "CondFormats/DataRecord/interface/EcalIntercalibConstantsRcd.h"
00046 
00047 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00048 #include "DataFormats/DetId/interface/DetId.h"
00049 
00050 #include "TTree.h"
00051 #include "TFile.h"
00052 #include "TGraph.h"
00053 #include "TGraphErrors.h"
00054 #include "TH1.h"
00055 #include "TH2.h"
00056 
00057 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
00058 #include "DataFormats/EgammaCandidates/interface/ElectronFwd.h"
00059 #include "DataFormats/EgammaCandidates/interface/Electron.h"
00060 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
00061 #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
00062 
00063 #include "FWCore/Framework/interface/Event.h"
00064 #include "FWCore/Framework/interface/EDAnalyzer.h"
00065 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00066 
00067 #include<vector>
00068 #include<string>
00069 
00070 // class declaration
00071 //
00072 
00073 class ZeeCalibration : public edm::ESProducerLooper {
00074    
00075  public:
00076   
00078   ZeeCalibration( const edm::ParameterSet& iConfig );
00079   
00081   ~ZeeCalibration();
00082   
00084   virtual void produce(edm::Event&, const edm::EventSetup&) {};
00085   
00087   virtual void beginOfJob();
00088   
00090   virtual void endOfJob();
00091   
00093   virtual void startingNewLoop( unsigned int iLoop );
00094   
00096   virtual Status endOfLoop( const edm::EventSetup&, unsigned int iLoop );
00097 
00099   virtual Status duringLoop( const edm::Event&, const edm::EventSetup& );
00100   
00102   virtual boost::shared_ptr<EcalIntercalibConstants> produceEcalIntercalibConstants( const EcalIntercalibConstantsRcd& iRecord );
00103 
00104  private:
00105 
00106 /*   ElectronEnergyCorrector myCorrector; */
00107 /*   ElectronClassification myClassificator; */
00108 
00109   double fEtaBarrelBad(double scEta) const;
00110   double fEtaBarrelGood(double scEta) const;
00111   double fEtaEndcapBad(double scEta) const;
00112   double fEtaEndcapGood(double scEta) const;
00113 
00114   int ringNumberCorrector(int k);
00115   double getEtaCorrection(const reco::GsfElectron*);
00116 
00117  \
00118   void fillEleInfo(std::vector<HepMC::GenParticle*>& a, std::map<HepMC::GenParticle*,const reco::GsfElectron*>& b);
00119   void fillMCInfo(HepMC::GenParticle* mcele);
00120 
00121   void fillMCmap(const std::vector<const reco::GsfElectron*>* electronCollection, const std::vector<HepMC::GenParticle*>& mcEle,std::map<HepMC::GenParticle*,const reco::GsfElectron*>& myMCmap);
00122   //  void fillMCmap(const reco::ElectronCollection* electronCollection, const std::vector<HepMC::GenParticle*>& mcEle,std::map<HepMC::GenParticle*,const reco::Electron*>& myMCmap);
00123   
00124   float EvalDPhi(float Phi,float Phi_ref);
00125   float EvalDR(float Eta,float Eta_ref,float Phi,float Phi_ref);
00126 
00127 
00128   void bookHistograms();
00129 
00130   void resetVariables();
00131 
00132   void resetHistograms();
00133 
00134   void printStatistics();
00135 
00136   std::pair<DetId, double> getHottestDetId(std::vector<std::pair<DetId, float> > mySCRecHits, const EBRecHitCollection* ebhits , const EERecHitCollection* eehits);
00137 
00138   bool xtalIsOnModuleBorder( EBDetId myEBDetId );
00139 
00140   float computeCoefficientDistanceAtIteration( float v1[250], float v2[250], int size);
00141 
00142   //  float Calculate_SigmaEtaEta(const reco::SuperCluster &passedCluster);
00143 
00144   // ----------member data ---------------------------
00145 
00146 
00147   TTree* myTree;
00148 
00149   std::string outputFileName_;
00150   
00151   std::string rechitProducer_;
00152   std::string rechitCollection_;
00153   std::string erechitProducer_;
00154   std::string erechitCollection_;
00155   std::string scProducer_;
00156   std::string scCollection_;
00157  
00158   std::string scIslandProducer_;
00159   std::string scIslandCollection_;
00160   
00161   std::string mcProducer_;
00162   std::string calibMode_;
00163 
00164   std::string electronProducer_;
00165   std::string electronCollection_;
00166   
00167   std::string RecalibBarrelHits_;
00168   
00169   unsigned int etaBins_;
00170   unsigned int etBins_;
00171 
00172   double etaMin_;
00173   double etMin_;
00174   double etaMax_;
00175   double etMax_;
00176 
00177   std::string barrelfile_;
00178   std::string endcapfile_;
00179 
00180   double minInvMassCut_;
00181   double maxInvMassCut_;
00182   double mass; 
00183 
00184   float mass4tree;
00185   float massDiff4tree;
00186 
00187   int read_events;
00188   
00189   int loopFlag_;
00190   
00191   float calibCoeff[nMaxChannels];
00192   float NewCalibCoeff[nMaxChannels];
00193   float calibCoeffError[nMaxChannels];
00194    float initCalibCoeff[nMaxChannels];
00195 
00196   boost::shared_ptr<EcalIntercalibConstants> ical;
00197   
00198   ZIterativeAlgorithmWithFit* theAlgorithm_;
00199 
00200   ZeePlots* myZeePlots_;
00201   ZeeRescaleFactorPlots* myZeeRescaleFactorPlots_;
00202 
00203   // steering parameters
00204   
00205   edm::ParameterSet theParameterSet;
00206 
00207   //  TGraph* graph;
00208 
00209   TH1F* h1_eventsBeforeEWKSelection_;
00210   TH1F* h1_eventsAfterEWKSelection_;
00211 
00212   TH1F* h1_eventsBeforeBorderSelection_;
00213   TH1F* h1_eventsAfterBorderSelection_;
00214 
00215 
00216   TH2F* h2_fEtaBarrelGood_;
00217   TH2F* h2_fEtaBarrelBad_;
00218   TH2F* h2_fEtaEndcapGood_;
00219   TH2F* h2_fEtaEndcapBad_;
00220   TH1F* h1_nEleReco_;
00221   TH1F* h1_eleClasses_;
00222 
00223   TH1F* h_eleEffEta[2];
00224   TH1F* h_eleEffPhi[2];
00225   TH1F* h_eleEffPt[2];
00226 
00227   TH1F* h1_seedOverSC_;
00228   TH1F* h1_preshowerOverSC_;
00229 
00230   TH1F* h1_zMassResol_;
00231   TH1F* h1_zEtaResol_;
00232   TH1F* h1_zPhiResol_;
00233   TH1F* h1_reco_ZMass_;
00234 
00235   TH1F* h1_reco_ZMassCorr_;
00236   TH1F* h1_reco_ZMassCorrBB_;
00237   TH1F* h1_reco_ZMassCorrEE_;
00238   TH1F* h1_reco_ZMassGood_;
00239   TH1F* h1_reco_ZMassBad_;
00240   TH1F* h1_ZCandMult_;
00241   TH1F* h1_RMin_;
00242   TH1F* h1_RMinZ_;
00243   TH1F* h1_eleERecoOverEtrue_;
00244 
00245   TH1F* h1_eleEtaResol_;
00246   TH1F* h1_elePhiResol_;
00247 
00248   TH1F* h_eleEffEta_[2];
00249   TH1F* h_eleEffPhi_[2];
00250   TH1F* h_eleEffPt_[2];
00251   TH1F* h_ESCEtrue_[25];
00252   TH2F* h_ESCEtrueVsEta_[25];
00253 
00254   TH1F* h_ESCcorrEtrue_[25];
00255   TH2F* h_ESCcorrEtrueVsEta_[25];
00256 
00257   TH2F* h2_coeffVsEta_;
00258   TH2F* h2_coeffVsEtaGrouped_;
00259   TH2F* h2_zMassVsLoop_;
00260   TH2F* h2_zMassDiffVsLoop_;
00261   TH2F* h2_zWidthVsLoop_;
00262   TH2F* h2_coeffVsLoop_;
00263 
00264   TH2F* h2_miscalRecal_;
00265   //  TH2F* h2_miscalRecalParz_[25];
00266   TH1F* h1_mc_;
00267   TH1F* h1_mcParz_[25];
00268   /*
00269   TH1F* h_DiffZMassDistr_[25];  
00270   TH1F* h_ZMassDistr_[25];  
00271   */
00272   TH2F* h2_residualSigma_;
00273   TH2F* h2_miscalRecalEB_;
00274   //TH2F* h2_miscalRecalEBParz_[25];
00275   TH1F* h1_mcEB_;
00276   TH1F* h1_mcEBParz_[25];
00277   TH2F* h2_miscalRecalEE_;
00278   //TH2F* h2_miscalRecalEEParz_[25];
00279   TH1F* h1_mcEE_;
00280   TH1F* h1_mcEEParz_[25];
00281 
00282   TH2F* h2_chi2_[25];
00283   TH2F* h2_iterations_[25];
00284 
00285   TH2F * h2_xtalRecalibCoeffBarrel_[25];
00286   TH2F * h2_xtalRecalibCoeffEndcapMinus_[25];
00287   TH2F * h2_xtalRecalibCoeffEndcapPlus_[25];
00288   
00289   TH2F* h2_xtalMiscalibCoeffBarrel_;
00290   TH2F* h2_xtalMiscalibCoeffEndcapMinus_;
00291   TH2F* h2_xtalMiscalibCoeffEndcapPlus_;
00292 
00293   TH1F* h1_weightSumMeanBarrel_;
00294   TH1F* h1_weightSumMeanEndcap_;
00295 
00296   TH1F* h1_occupancyVsEta_;
00297   TH1F* h1_occupancyVsEtaGold_;
00298   TH1F* h1_occupancyVsEtaSilver_;
00299   TH1F* h1_occupancyVsEtaCrack_;
00300   TH1F* h1_occupancyVsEtaShower_;
00301   TH1F* h1_occupancy_;
00302   TH1F* h1_occupancyBarrel_;
00303   TH1F* h1_occupancyEndcap_;
00304   
00305   TH1F* h1_electronCosTheta_TK_;
00306   TH1F* h1_electronCosTheta_SC_;
00307   TH1F* h1_electronCosTheta_SC_TK_;
00308 
00309   TH1F* h1_borderElectronClassification_;
00310 
00311 
00312   Int_t BBZN,EBZN,EEZN,BBZN_gg,EBZN_gg,EEZN_gg,BBZN_tt,EBZN_tt,EEZN_tt,BBZN_t0,EBZN_t0,EEZN_t0;
00313   Int_t NEVT, MCZBB, MCZEB, MCZEE;
00314 
00315   TFile* outputFile_;
00316       
00317   unsigned int theMaxLoops;     // Number of loops to loop
00318  
00319   bool wantEtaCorrection_;
00320 
00321   unsigned int electronSelection_; 
00322 
00323   double loopArray[50];
00324   double sigmaArray[50];
00325   double sigmaErrorArray[50];
00326   double coefficientDistanceAtIteration[50];
00327 
00328   int BARREL_ELECTRONS_BEFORE_BORDER_CUT;
00329   int BARREL_ELECTRONS_AFTER_BORDER_CUT;
00330 
00331   int TOTAL_ELECTRONS_IN_BARREL;
00332   int TOTAL_ELECTRONS_IN_ENDCAP;
00333 
00334   int GOLDEN_ELECTRONS_IN_BARREL;
00335   int GOLDEN_ELECTRONS_IN_ENDCAP;
00336 
00337   int SILVER_ELECTRONS_IN_BARREL;
00338   int SILVER_ELECTRONS_IN_ENDCAP;
00339 
00340   int SHOWER_ELECTRONS_IN_BARREL;
00341   int SHOWER_ELECTRONS_IN_ENDCAP;
00342 
00343   int CRACK_ELECTRONS_IN_BARREL;
00344   int CRACK_ELECTRONS_IN_ENDCAP;
00345 
00346 
00347   edm::InputTag hlTriggerResults_;
00348 
00349   unsigned int  nEvents_;           // number of events processed
00350 
00351   unsigned int  nWasRun_;           // # where at least one HLT was run
00352   unsigned int  nAccept_;           // # of accepted events
00353   unsigned int  nErrors_;           // # where at least one HLT had error
00354 
00355   std::vector<unsigned int> hlWasRun_; // # where HLT[i] was run
00356   std::vector<unsigned int> hlAccept_; // # of events accepted by HLT[i]
00357   std::vector<unsigned int> hlErrors_; // # of events with error in HLT[i]
00358 
00359   std::vector<std::string>  hlNames_;  // name of each HLT algorithm
00360   bool init_;                          // vectors initialised or not
00361 
00362   Int_t              triggerCount;
00363   char              aTriggerNames[200][30];
00364   bool              aTriggerResults[200];
00365 
00366   Int_t              hltCount;
00367   char              aHLTNames[6000];
00368   Int_t              hltNamesLen;
00369   TString              aNames[200];
00370   bool              aHLTResults[200];
00371 
00372   bool              isfirstcall_;
00373   
00374 };
00375 #endif