CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/Calibration/EcalCalibAlgos/src/ElectronCalibrationUniv.cc

Go to the documentation of this file.
00001 
00002 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00003 
00004 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00005 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00006 #include "DataFormats/DetId/interface/DetId.h"
00007 #include "CondFormats/EcalObjects/interface/EcalIntercalibConstants.h"
00008 #include "CondFormats/DataRecord/interface/EcalIntercalibConstantsRcd.h"
00009 #include "Calibration/Tools/interface/calibXMLwriter.h"
00010 #include "Calibration/Tools/interface/CalibrationCluster.h"
00011 #include "Calibration/Tools/interface/HouseholderDecomposition.h"
00012 #include "Calibration/Tools/interface/MinL3Algorithm.h"
00013 #include "Calibration/EcalCalibAlgos/interface/ElectronCalibrationUniv.h"
00014 #include "DataFormats/EgammaCandidates/interface/Electron.h"
00015 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
00016 #include "DataFormats/TrackReco/interface/Track.h"
00017 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00018 #include "DataFormats/TrackReco/interface/TrackExtraFwd.h"
00019 #include "FWCore/Utilities/interface/isFinite.h"
00020 #include "TFile.h"
00021 #include "TH1.h"
00022 #include "TH2.h"
00023 #include "TF1.h"
00024 #include "TRandom.h"
00025 
00026 #include <iostream>
00027 #include <string>
00028 #include <stdexcept>
00029 #include <vector>
00030 
00031 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
00032 #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
00033 
00034 ElectronCalibrationUniv::ElectronCalibrationUniv(const edm::ParameterSet& iConfig)
00035 {
00036 
00037   rootfile_ = iConfig.getParameter<std::string>("rootfile");
00038   EBrecHitLabel_ = iConfig.getParameter< edm::InputTag > ("ebRecHitsLabel");
00039   EErecHitLabel_ = iConfig.getParameter< edm::InputTag > ("eeRecHitsLabel");
00040   electronLabel_ = iConfig.getParameter< edm::InputTag > ("electronLabel");
00041   trackLabel_ = iConfig.getParameter< edm::InputTag > ("trackLabel");
00042   calibAlgo_       = iConfig.getParameter<std::string>("CALIBRATION_ALGO");
00043   keventweight_ = iConfig.getParameter<int>("keventweight");
00044   ClusterSize_ = iConfig.getParameter<int>("Clustersize");
00045   ElePt_ = iConfig.getParameter<double>("ElePt");
00046   maxeta_ = iConfig.getParameter<int>("maxeta");
00047   mineta_ = iConfig.getParameter<int>("mineta");
00048   maxphi_ = iConfig.getParameter<int>("maxphi");
00049   minphi_ = iConfig.getParameter<int>("minphi");
00050   cut1_ = iConfig.getParameter<double>("cut1");
00051   cut2_ = iConfig.getParameter<double>("cut2");
00052   cut3_ = iConfig.getParameter<double>("cut3");
00053   elecclass_ = iConfig.getParameter<int>("elecclass");
00054   numevent_ = iConfig.getParameter<int>("numevent");
00055   miscalibfile_ = iConfig.getParameter<std::string>("miscalibfile");
00056   miscalibfileEndCap_ = iConfig.getParameter<std::string>("miscalibfileEndCap");
00057 
00058   cutEPCalo1_ = iConfig.getParameter<double>("cutEPCaloMin");
00059   cutEPCalo2_ = iConfig.getParameter<double>("cutEPCaloMax");
00060   cutEPin1_ = iConfig.getParameter<double>("cutEPinMin");
00061   cutEPin2_ = iConfig.getParameter<double>("cutEPinMax");
00062   cutCalo1_ = iConfig.getParameter<double>("cutCaloMin");
00063   cutCalo2_ = iConfig.getParameter<double>("cutCaloMax");
00064   
00065   cutESeed_ = iConfig.getParameter<double>("cutESeed");
00066   
00067    
00068 }
00069 
00070 
00071 ElectronCalibrationUniv::~ElectronCalibrationUniv()
00072 {
00073 }
00074 
00075 //========================================================================
00076 void ElectronCalibrationUniv::beginJob() {
00077   //========================================================================
00078   f = new TFile(rootfile_.c_str(),"RECREATE");
00079   f->cd();
00080   EventsAfterCuts = new TH1F("EventsAfterCuts","Events After Cuts",30,0,30);
00081   
00082   // Book histograms 
00083   e9 = new TH1F("e9","E9 energy", 300, 0., 150.);
00084   e25 = new TH1F("e25","E25 energy", 300, 0., 150.);
00085   scE = new TH1F("scE","SC energy", 300, 0., 150.);
00086   trP = new TH1F("trP","Trk momentum", 300, 0., 150.);
00087   EoP = new TH1F("EoP","EoP", 600, 0., 3.);
00088   EoP_all = new TH1F("EoP_all","EoP_all",600, 0., 3.);
00089 
00090   calibs = new TH1F("calib","Calibration constants", 800, 0.5, 2.);
00091   calibsEndCapMinus = new TH1F("calibEndCapMinus","Calibration constants EE-", 800, 0.5, 2.);
00092   calibsEndCapPlus = new TH1F("calibEndCapPlus","Calibration constants EE+", 800, 0.5, 2.);
00093   
00094   e25OverScE = new TH1F("e25OverscE","E25 / SC energy", 400, 0., 2.);
00095   E25oP = new TH1F("E25oP","E25 / P", 750, 0., 1.5);
00096 
00097   Map = new TH2F("Map","Nb Events in Crystal",173 ,-86 ,86,362, 0, 361 );
00098   e9Overe25 = new TH1F("e9Overe25","E9 / E25", 400, 0., 2.);
00099   Map3Dcalib = new TH2F("3Dcalib", "3Dcalib",173 ,-86 ,86,362, 0, 361 );
00100   Map3DcalibEndCapMinus = new TH2F("3DcalibEndCapMinus", "3Dcalib EE-",100 ,0 ,100,100, 0, 100 );
00101   Map3DcalibEndCapPlus = new TH2F("3DcalibEndCapPlus", "3Dcalib EE+",100 ,0 ,100,100, 0, 100 );
00102 
00103   MapCor1 = new TH2F ("MapCor1", "Correlation E25/Pcalo versus E25/Pin",100 ,0. ,5. ,100,0.,5. );
00104   MapCor2 = new TH2F ("MapCor2", "Correlation E25/Pcalo versus E/P",100 ,0. ,5. ,100,0.,5. );
00105   MapCor3 = new TH2F ("MapCor3", "Correlation E25/Pcalo versus Pout/Pin",100 ,0. ,5. ,100,0.,5. );
00106   MapCor4 = new TH2F ("MapCor4", "Correlation E25/Pcalo versus E25/highestP",100 ,0. ,5. ,100,0.,5. );
00107   MapCor5 = new TH2F ("MapCor5", "Correlation E25/Pcalo versus Pcalo/Pout",100 ,0. ,5. ,100,0.,5. );
00108   MapCor6 = new TH2F ("MapCor6", "Correlation Pout/Pin versus E25/Pin",100 ,0. ,5. ,100,0.,5. );
00109   MapCor7 = new TH2F ("MapCor7", "Correlation Pout/Pin versus Pcalo/Pout",100 ,0. ,5. ,100,0.,5. );
00110   MapCor8 = new TH2F ("MapCor8", "Correlation E25/Pin versus Pcalo/Pout",100 ,0. ,5. ,100,0.,5. );
00111   MapCor9 = new TH2F ("MapCor9", "Correlation  E25/Pcalo versus Eseed/Pout",100 ,0. ,5. ,100,0.,5. );
00112   MapCor10 = new TH2F ("MapCor10", "Correlation Eseed/Pout versus Pout/Pin",100 ,0. ,5. ,100,0.,5. );
00113   MapCor11 = new TH2F ("MapCor11", "Correlation Eseed/Pout versus E25/Pin",100 ,0. ,5. ,100,0.,5. );
00114 //   MapCorCalib = new TH2F ("MapCorCalib", "Correlation Miscalibration versus Calibration constants", 500, 0.5,1.5, 500, 0.5, 1.5);
00115 
00116   E25oPvsEta = new TH2F ("E25oPvsEta", "E/P vs Eta", 173, -86, 86, 600, 0.7,1.3);
00117   E25oPvsEtaEndCapMinus = new TH2F ("E25oPvsEtaEndCapMinus", "E/P vs R EE-", 100, 0, 100, 600, 0.7,1.3);
00118   E25oPvsEtaEndCapPlus = new TH2F ("E25oPvsEtaEndCapPlus", "E/P vs R EE+", 100, 0, 100, 600, 0.7,1.3);
00119 
00120   PinMinPout = new TH1F("PinMinPout","(Pin - Pout)/Pin",600,-2.0,2.0);
00121 
00122   calibinter = new TH1F("calibinter", "internal calibration constants", 800 , 0.5,2.);
00123   PinOverPout= new TH1F("PinOverPout", "pinOverpout", 600,0., 3.);
00124   eSeedOverPout= new TH1F("eSeedOverPout", "eSeedOverpout ", 600, 0., 3.);
00125 //   MisCalibs = new TH1F("MisCalibs","Miscalibration constants",800,0.5,2.);
00126 //   RatioCalibs = new TH1F("RatioCalibs","Ratio in Calibration Constants", 800, 0.5, 2.0);
00127 //   DiffCalibs = new TH1F("DiffCalibs", "Difference in Calibration constants", 800, -1.0,1.0);
00128   calibinterEndCapMinus = new TH1F("calibinterEndCapMinus", "internal calibration constants", 800 , 0.5,2.);
00129   calibinterEndCapPlus = new TH1F("calibinterEndCapPlus", "internal calibration constants", 800 , 0.5,2.);
00130 //   MisCalibsEndCapMinus = new TH1F("MisCalibsEndCapMinus","Miscalibration constants",800,0.5,2.);
00131 //   MisCalibsEndCapPlus = new TH1F("MisCalibsEndCapPlus","Miscalibration constants",800,0.5,2.);
00132 //   RatioCalibsEndCapMinus = new TH1F("RatioCalibsEndCapMinus","Ratio in Calibration Constants", 800, 0.5, 2.0);
00133 //   RatioCalibsEndCapPlus = new TH1F("RatioCalibsEndCapPlus","Ratio in Calibration Constants", 800, 0.5, 2.0);
00134 //   DiffCalibsEndCapMinus = new TH1F("DiffCalibsEndCapMinus", "Difference in Calibration constants", 800, -1.0,1.0);
00135 //   DiffCalibsEndCapPlus = new TH1F("DiffCalibsEndCapPlus", "Difference in Calibration constants", 800, -1.0,1.0);
00136   Error1 = new TH1F ("Error1","DeltaP/Pin",800 ,-1.0,1.0 );
00137   Error2 = new TH1F ("Error2","DeltaP/Pout",800 ,-1.0,1.0 );
00138   Error3 = new TH1F ("Error3","DeltaP/Pcalo",800 ,-1.0,1.0 );
00139   eSeedOverPout2= new TH1F("eSeedOverPout2", "eSeedOverpout (No Supercluster)", 600, 0., 4.);
00140   hadOverEm= new TH1F("hadOverEm", "Had/EM distribution", 600, -2., 2.);
00141   
00142   // Book histograms  
00143   Map3DcalibNoCuts = new TH2F("3DcalibNoCuts", "3Dcalib (Before Cuts)",173 ,-86 ,86,362, 0, 361 );
00144   e9NoCuts = new TH1F("e9NoCuts","E9 energy (Before Cuts)",300, 0., 150.);
00145   e25NoCuts = new TH1F("e25NoCuts","E25 energy (Before Cuts)", 300, 0., 150.);
00146   scENoCuts = new TH1F("scENoCuts","SC energy (Before Cuts)", 300, 0., 150.);
00147   trPNoCuts = new TH1F("trPNoCuts","Trk momentum (Before Cuts)", 300, 0., 150.);
00148   EoPNoCuts = new TH1F("EoPNoCuts","EoP (Before Cuts)", 600, 0., 3.);
00149   calibsNoCuts = new TH1F("calibNoCuts","Calibration constants (Before Cuts)", 800, 0., 2.);
00150   e25OverScENoCuts = new TH1F("e25OverscENoCuts","E25 / SC energy (Before Cuts)", 400, 0., 2.);
00151   E25oPNoCuts = new TH1F("E25oPNoCuts","E25 / P (Before Cuts)", 750, 0., 1.5);
00152   MapEndCapMinus = new TH2F("MapEndCapMinus","Nb Events in Crystal (EndCap)",100 ,0 ,100,100, 0, 100 );
00153   MapEndCapPlus = new TH2F("MapEndCapPlus","Nb Events in Crystal (EndCap)",100 ,0 ,100,100, 0, 100 );
00154   e9Overe25NoCuts = new TH1F("e9Overe25NoCuts","E9 / E25 (Before Cuts)", 400, 0., 2.);
00155   PinOverPoutNoCuts = new TH1F("PinOverPoutNoCuts", "pinOverpout (Before Cuts)", 600,0., 3.);
00156   eSeedOverPoutNoCuts = new TH1F(" eSeedOverPoutNoCuts", "eSeedOverpout (Before Cuts) ", 600, 0., 4.);
00157   PinMinPoutNoCuts = new TH1F("PinMinPoutNoCuts","(Pin - Pout)/Pin (Before Cuts)",600,-2.0,2.0);
00158 
00159 //   RatioCalibsNoCuts = new TH1F("RatioCalibsNoCuts","Ratio in Calibration Constants (Before Cuts)", 800, 0.5, 2.0);
00160 //   DiffCalibsNoCuts = new TH1F("DiffCalibsNoCuts", "Difference in Calibration constants (Before Cuts)", 800, -1.0,1.0);
00161    calibinterNoCuts = new TH1F("calibinterNoCuts", "internal calibration constants", 2000 , 0.5,2.);
00162  
00163   MapCor1NoCuts = new TH2F ("MapCor1NoCuts", "Correlation E25/PatCalo versus E25/Pin (Before Cuts)",100 ,0. ,5. ,100,0.,5. );
00164   MapCor2NoCuts = new TH2F ("MapCor2NoCuts", "Correlation E25/PatCalo versus E/P (Before Cuts)",100 ,0. ,5. ,100,0.,5. );
00165   MapCor3NoCuts = new TH2F ("MapCor3NoCuts", "Correlation E25/PatCalo versus Pout/Pin (Before Cuts)",100 ,0. ,5. ,100,0.,5. );
00166   MapCor4NoCuts = new TH2F ("MapCor4NoCuts", "Correlation E25/PatCalo versus E25/highestP (Before Cuts)",100 ,0. ,5. ,100,0.,5. );
00167   MapCor5NoCuts = new TH2F ("MapCor5NoCuts", "Correlation E25/Pcalo versus Pcalo/Pout (Before Cuts)",100 ,0. ,5. ,100,0.,5. );
00168   MapCor6NoCuts = new TH2F ("MapCor6NoCuts", "Correlation Pout/Pin versus E25/Pin (Before Cuts)",100 ,0. ,5. ,100,0.,5. );
00169   MapCor7NoCuts = new TH2F ("MapCor7NoCuts", "Correlation Pout/Pin versus Pcalo/Pout (Before Cuts)",100 ,0. ,5. ,100,0.,5. );
00170   MapCor8NoCuts = new TH2F ("MapCor8NoCuts", "Correlation E25/Pin versus Pcalo/Pout (Before Cuts)",100 ,0. ,5. ,100,0.,5. );
00171   MapCor9NoCuts = new TH2F ("MapCor9NoCuts", "Correlation  E25/Pcalo versus Eseed/Pout (Before Cuts)",100 ,0. ,5. ,100,0.,5. );
00172   MapCor10NoCuts = new TH2F ("MapCor10NoCuts", "Correlation Eseed/Pout versus Pout/Pin (Before Cuts)",100 ,0. ,5. ,100,0.,5. );
00173   MapCor11NoCuts = new TH2F ("MapCor11NoCuts", "Correlation Eseed/Pout versus E25/Pin (Before Cuts)",100 ,0. ,5. ,100,0.,5. );
00174 //   MapCorCalibEndCapMinus = new TH2F ("MapCorCalibEndCapMinus", "Correlation Miscalibration versus Calibration constants (EndCap)",  500, 0.5,1.5, 500, 0.5, 1.5);
00175 //   MapCorCalibEndCapPlus = new TH2F ("MapCorCalibEndCapPlus", "Correlation Miscalibration versus Calibration constants (EndCap)",  500, 0.5,1.5, 500, 0.5, 1.5);
00176 
00177   Error1NoCuts = new TH1F ("Eror1NoCuts","DeltaP/Pin (Before Cuts)",800 ,-1.0,1.0 );
00178   Error2NoCuts = new TH1F ("Error2NoCuts","DeltaP/Pout (Before Cuts)",800 ,-1.0,1.0 );
00179   Error3NoCuts = new TH1F ("Error3NoCuts","DeltaP/Pcalo (Before Cuts)",800 ,-1.0, 1.0);
00180   eSeedOverPout2NoCuts= new TH1F("eSeedOverPout2NoCuts", "eSeedOverpout (No Supercluster, Before Cuts)", 600, 0., 4.);
00181   hadOverEmNoCuts= new TH1F("hadOverEmNoCuts", "Had/EM distribution (Before Cuts)", 600, -2., 2.);
00182 
00183   //Book histograms after ESeed cut
00184   MapCor1ESeed = new TH2F ("MapCor1ESeed", "Correlation E25/Pcalo versus E25/Pin (after Eseed/Pout cut)",100 ,0. ,5. ,100,0.,5. );
00185   MapCor2ESeed = new TH2F ("MapCor2ESeed", "Correlation E25/Pcalo versus E/P (after Eseed/Pout cut)",100 ,0. ,5. ,100,0.,5. );
00186   MapCor3ESeed = new TH2F ("MapCor3ESeed", "Correlation E25/Pcalo versus Pout/Pin (after Eseed/Pout cut)",100 ,0. ,5. ,100,0.,5. );
00187   MapCor4ESeed = new TH2F ("MapCor4ESeed", "Correlation E25/Pcalo versus E25/highestP (after Eseed/Pout cut)",100 ,0. ,5. ,100,0.,5. );
00188   MapCor5ESeed = new TH2F ("MapCor5ESeed", "Correlation E25/Pcalo versus Pcalo/Pout (after Eseed/Pout cut)",100 ,0. ,5. ,100,0.,5. );
00189   MapCor6ESeed = new TH2F ("MapCor6ESeed", "Correlation Pout/Pin versus E25/Pin (after Eseed/Pout cut)",100 ,0. ,5. ,100,0.,5. );
00190   MapCor7ESeed = new TH2F ("MapCor7ESeed", "Correlation Pout/Pin versus Pcalo/Pout (after Eseed/Pout cut)",100 ,0. ,5. ,100,0.,5. );
00191   MapCor8ESeed = new TH2F ("MapCor8ESeed", "Correlation E25/Pin versus Pcalo/Pout (after Eseed/Pout cut)",100 ,0. ,5. ,100,0.,5. );
00192   MapCor9ESeed = new TH2F ("MapCor9ESeed", "Correlation  E25/Pcalo versus Eseed/Pout (after Eseed/Pout cut)",100 ,0. ,5. ,100,0.,5. );
00193   MapCor10ESeed = new TH2F ("MapCor10ESeed", "Correlation Eseed/Pout versus Pout/Pin (after Eseed/Pout cut)",100 ,0. ,5. ,100,0.,5. );
00194   MapCor11ESeed = new TH2F ("MapCor11ESeed", "Correlation Eseed/Pout versus E25/Pin (after Eseed/Pout cut)",100 ,0. ,5. ,100,0.,5. );
00195  
00196   eSeedOverPout2ESeed= new TH1F("eSeedOverPout2ESeed", "eSeedOverpout (No Supercluster, after Eseed/Pout cut)", 600, 0., 4.);
00197 
00198   hadOverEmESeed= new TH1F("hadOverEmESeed", "Had/EM distribution (after Eseed/Pout cut)", 600, -2., 2.);
00199  
00200  //Book histograms without any cut
00201   GeneralMap = new TH2F("GeneralMap","Map without any cuts",173 ,-86 ,86,362, 0, 361 );
00202   GeneralMapEndCapMinus = new TH2F("GeneralMapEndCapMinus","Map without any cuts",100 ,0 ,100,100, 0, 100 );
00203   GeneralMapEndCapPlus = new TH2F("GeneralMapEndCapPlus","Map without any cuts",100 ,0 ,100,100, 0, 100 );
00204   GeneralMapBeforePt = new TH2F("GeneralMapBeforePt","Map without any cuts",173 ,-86 ,86,362, 0, 361 );
00205   GeneralMapEndCapMinusBeforePt = new TH2F("GeneralMapEndCapMinusBeforePt","Map without any cuts",100 ,0 ,100,100, 0, 100 );
00206   GeneralMapEndCapPlusBeforePt = new TH2F("GeneralMapEndCapPlusBeforePt","Map without any cuts",100 ,0 ,100,100, 0, 100 );
00207   
00208   calibClusterSize=ClusterSize_; 
00209   etaMin = int(mineta_);
00210   etaMax = int(maxeta_);
00211   phiMin = int(minphi_);
00212   phiMax = int(maxphi_);
00213   if(calibAlgo_=="L3"){
00214     MyL3Algo1 = new MinL3Algorithm(keventweight_,calibClusterSize, etaMin, etaMax, phiMin, phiMax);
00215   }else{
00216     if(calibAlgo_=="L3Univ"){
00217       UnivL3 = new MinL3AlgoUniv<DetId>(keventweight_);
00218     }else{
00219       if(calibAlgo_=="HH" || calibAlgo_=="HHReg"){
00220         MyHH = new HouseholderDecomposition(calibClusterSize, etaMin,etaMax, phiMin, phiMax); 
00221       }else{
00222         std::cout<<" Name of Algorithm is not recognize "<<calibAlgo_<<" Should be either L3, HH or HHReg. Abort! "<<std::endl;
00223       }
00224     }
00225   }
00226   read_events=0;
00227 }
00228 
00229 //========================================================================
00230 void ElectronCalibrationUniv::beginRun(edm::Run const &, edm::EventSetup const& iSetup) {
00231   //========================================================================
00232   
00233 
00234   //To Deal with Geometry:
00235   iSetup.get<CaloTopologyRecord>().get(theCaloTopology);
00236   
00237 
00238 }
00239 
00240 
00241 //========================================================================
00242 
00243 void
00244 ElectronCalibrationUniv::endJob() {
00245 //========================================================================
00246 
00247   f->cd();
00248   time_t start, end;
00249   time_t cpu_time_used;
00250   start = time(NULL);
00251 
00252   //In order to do only one loop to use properly looper properties, ask only for 1 iterations!
00253   int nIterations =10;
00254  if(calibAlgo_=="L3"){ 
00255    solution = MyL3Algo1->iterate(EventMatrix, MaxCCeta, MaxCCphi, EnergyVector,nIterations);
00256  }else{
00257    if(calibAlgo_=="L3Univ"){ 
00258      //Univsolution= UnivL3->getSolution();
00259      //     std::cout<<" Should derive solution "<<EnergyVector.size()<<std::endl;
00260      Univsolution= UnivL3->iterate(EventMatrix, UnivEventIds, EnergyVector, nIterations);
00261      //std::cout<<" solution size "<<Univsolution.size()<<std::endl;
00262   }else {
00263      if(calibAlgo_=="HH"){
00264        solution = MyHH->iterate(EventMatrix, MaxCCeta, MaxCCphi,EnergyVector,1,false);
00265      }else{
00266        if(calibAlgo_=="HHReg"){
00267          solution = MyHH->runRegional(EventMatrix, MaxCCeta, MaxCCphi,EnergyVector, 2);
00268        }else{ 
00269          std::cout<<" Calibration not run due to problem in Algo Choice..."<<std::endl;
00270          return ;
00271        }
00272      }
00273    }
00274  }
00275    end = time(NULL);
00276    cpu_time_used = end - start;
00277    //     std::cout<<"222 solution size "<<Univsolution.size()<<std::endl;
00278 
00279 
00280   calibXMLwriter write_calibrations;
00281   
00282 //   FILE* MisCalib;
00283 //   //char* calibfile="miscalibfile";
00284 //   MisCalib = fopen(miscalibfile_.c_str(),"r");
00285   
00286 //   int fileStatus=0;
00287 //   int eta=-1;
00288 //   int phi=-1;
00289 //   float coeff=-1;
00290   
00291   
00292    std::map<EBDetId,float> OldCoeff;
00293  
00294 //  while(fileStatus != EOF) {
00295 //    fileStatus = fscanf(MisCalib,"%d %d %f\n",  &eta,&phi,&coeff);
00296 //    if(eta!=-1&&phi!=-1&& coeff!=-1){
00297 //      //     std::cout<<" We have read correctly the coefficient " << coeff << " corresponding to eta "<<eta<<" and  phi "<<phi<<std::endl;
00298 //      OldCoeff.insert(std::make_pair(EBDetId(eta,phi,EBDetId::ETAPHIMODE),coeff )); 
00299 //    }
00300 //  } 
00301  
00302 //  fclose(MisCalib);
00303 //   FILE* MisCalibEndCap;
00304 //   //char* calibfile="miscalibfile";
00305 //   MisCalibEndCap = fopen(miscalibfileEndCap_.c_str(),"r");
00306   
00307 //   int fileStatus2=0;
00308 //   int X=-1;
00309 //   int Y=-1;
00310 //   float coeff2=-1;
00311    std::map<EEDetId,float> OldCoeffEndCap;
00312  
00313 //  while(fileStatus2 != EOF) {
00314 //    fileStatus2 = fscanf(MisCalibEndCap,"%d %d %f\n",  &X,&Y,&coeff2);
00315 //    if(X!=-1&&Y!=-1&& coeff2!=-1){
00316 //      //     std::cout<<" We have read correctly the coefficient " << coeff << " corresponding to eta "<<eta<<" and  phi "<<phi<<std::endl;
00317 //      if(TestEEvalidDetId(X,Y,1)){
00318 //        OldCoeffEndCap.insert(std::make_pair(EEDetId(X,Y,1,EEDetId::XYMODE),coeff2 )); 
00319 //      }
00320 //    }
00321 //  } 
00322  
00323 // fclose(MisCalibEndCap);
00324   std::map<DetId,float>::const_iterator itmap;
00325   for (itmap = Univsolution.begin(); itmap != Univsolution.end(); itmap++){
00326     const DetId Id(itmap->first);
00327      if(Id.subdetId()==1){
00328       const EBDetId IChannelDetId(itmap->first);
00329       if (IChannelDetId.ieta()< mineta_){continue;}
00330       if (IChannelDetId.ieta()> maxeta_){continue;}
00331       if (IChannelDetId.iphi()< minphi_){continue;} 
00332       if (IChannelDetId.iphi()> maxphi_){continue;}
00333 //      float Compare=1;
00334 //      std::map<EBDetId,float>::iterator iter = OldCoeff.find(itmap->first);
00335 //      if( iter != OldCoeff.end() )Compare = iter->second;
00336       Map3Dcalib->Fill(IChannelDetId.ieta(),IChannelDetId.iphi(),itmap->second) ;
00337       calibs->Fill(itmap->second);
00338       //DiffCalibs->Fill(newCalibs[icry]-miscalib[IChannelDetId.ieta()-1][IChannelDetId.iphi()-21]);
00339       //RatioCalibs->Fill(newCalibs[icry]/miscalib[IChannelDetId.ieta()-1][IChannelDetId.iphi()-21]);
00340       if (IChannelDetId.ieta()< mineta_+2){continue;}
00341       if (IChannelDetId.ieta()> maxeta_-2){continue;}
00342       if (IChannelDetId.iphi()< minphi_+2){continue;} 
00343       if (IChannelDetId.iphi()> maxphi_-2){continue;}
00344       write_calibrations.writeLine(IChannelDetId,itmap->second);
00345          calibinter->Fill(itmap->second);
00346 //       MapCorCalib->Fill(itmap->second,Compare);
00347 //       DiffCalibs->Fill(itmap->second-Compare);
00348 //       RatioCalibs->Fill(itmap->second*Compare);
00349     }else{
00350       const EEDetId IChannelDetId(itmap->first);
00351 //       if (IChannelDetId.ix()<0 ){continue;}
00352 //       if (IChannelDetId.ix()>100 ){continue;}
00353 //       if (IChannelDetId.iy()<0 ){continue;} 
00354 //       if (IChannelDetId.iy()>100 ){continue;}
00355 //     std::map<EEDetId,float>::iterator iter = OldCoeffEndCap.find(itmap->first);
00356 //      float Compare=1;
00357 //      if( iter != OldCoeffEndCap.end() )Compare = iter->second;
00358       if(IChannelDetId.zside()<0){
00359         Map3DcalibEndCapMinus->Fill(IChannelDetId.ix(),IChannelDetId.iy(),itmap->second) ;
00360         calibsEndCapMinus->Fill(itmap->second);
00361         calibinterEndCapMinus->Fill(itmap->second);
00362 //      DiffCalibsEndCapMinus->Fill(itmap->second-Compare);
00363 //      RatioCalibsEndCapMinus->Fill(itmap->second*Compare);
00364 //      MapCorCalibEndCapMinus->Fill(itmap->second,Compare);
00365       }else{
00366         Map3DcalibEndCapPlus->Fill(IChannelDetId.ix(),IChannelDetId.iy(),itmap->second) ;
00367         calibsEndCapPlus->Fill(itmap->second);
00368         calibinterEndCapPlus->Fill(itmap->second);
00369 //      DiffCalibsEndCapPlus->Fill(itmap->second-Compare);
00370 //      RatioCalibsEndCapPlus->Fill(itmap->second*Compare);
00371 //      MapCorCalibEndCapPlus->Fill(itmap->second,Compare);
00372       }
00373       write_calibrations.writeLine(IChannelDetId,itmap->second);
00374     }
00375   }
00376   EventsAfterCuts->Write();
00377 
00378   // Book histograms 
00379   e25->Write();
00380   e9->Write();
00381   scE->Write();
00382   trP->Write();
00383   EoP->Write();
00384   EoP_all->Write();
00385   calibs->Write();
00386   calibsEndCapMinus->Write();
00387   calibsEndCapPlus->Write();
00388   e9Overe25->Write();
00389   e25OverScE->Write();
00390   Map->Write();
00391   E25oP->Write();
00392 
00393   PinOverPout->Write();
00394   eSeedOverPout->Write();
00395 //   MisCalibs->Write();
00396 //   RatioCalibs->Write();
00397 //   DiffCalibs->Write();
00398 //   RatioCalibsNoCuts->Write();
00399 //   DiffCalibsNoCuts->Write();
00400 //   MisCalibsEndCapMinus->Write();
00401 //   MisCalibsEndCapPlus->Write();
00402 //   RatioCalibsEndCapMinus->Write();
00403 //   RatioCalibsEndCapPlus->Write();
00404 //   DiffCalibsEndCapMinus->Write();
00405 //   DiffCalibsEndCapPlus->Write();
00406 
00407   e25NoCuts->Write();
00408   e9NoCuts->Write();
00409   scENoCuts->Write();
00410   trPNoCuts->Write();
00411   EoPNoCuts->Write();
00412   calibsNoCuts->Write();
00413   e9Overe25NoCuts->Write();
00414   e25OverScENoCuts->Write();
00415   MapEndCapMinus->Write();
00416   MapEndCapPlus->Write();
00417   E25oPNoCuts->Write();
00418   Map3Dcalib->Write();
00419   Map3DcalibEndCapMinus->Write();
00420   Map3DcalibEndCapPlus->Write();
00421   Map3DcalibNoCuts->Write();
00422   calibinter->Write();
00423   calibinterEndCapMinus->Write();
00424   calibinterEndCapPlus->Write();
00425   calibinterNoCuts->Write();
00426   PinOverPoutNoCuts->Write();
00427   eSeedOverPoutNoCuts->Write();
00428 
00429   GeneralMap->Write();
00430   GeneralMapEndCapMinus->Write();
00431   GeneralMapEndCapPlus->Write();
00432   GeneralMapBeforePt->Write();
00433   GeneralMapEndCapMinusBeforePt->Write();
00434   GeneralMapEndCapPlusBeforePt->Write();
00435 
00436   MapCor1->Write();
00437   MapCor2->Write();
00438   MapCor3->Write();
00439   MapCor4->Write();
00440   MapCor5->Write();
00441   MapCor6->Write();
00442   MapCor7->Write();
00443   MapCor8->Write();
00444   MapCor9->Write();
00445   MapCor10->Write();
00446   MapCor11->Write();
00447   //  MapCorCalib->Write();
00448 
00449   MapCor1NoCuts->Write();
00450   MapCor2NoCuts->Write();
00451   MapCor3NoCuts->Write();
00452   MapCor4NoCuts->Write();
00453   MapCor5NoCuts->Write();
00454   MapCor6NoCuts->Write();
00455   MapCor7NoCuts->Write();
00456   MapCor8NoCuts->Write();
00457   MapCor9NoCuts->Write();
00458   MapCor10NoCuts->Write();
00459   MapCor11NoCuts->Write();
00460 //   MapCorCalibEndCapMinus->Write();
00461 //   MapCorCalibEndCapPlus->Write();
00462 
00463   MapCor1ESeed->Write();
00464   MapCor2ESeed->Write();
00465   MapCor3ESeed->Write();
00466   MapCor4ESeed->Write();
00467   MapCor5ESeed->Write();
00468   MapCor6ESeed->Write();
00469   MapCor7ESeed->Write();
00470   MapCor8ESeed->Write();
00471   MapCor9ESeed->Write();
00472   MapCor10ESeed->Write();
00473   MapCor11ESeed->Write();
00474 
00475   E25oPvsEta->Write();
00476   E25oPvsEtaEndCapMinus->Write();
00477   E25oPvsEtaEndCapPlus->Write();
00478 
00479   PinMinPout->Write(); 
00480   PinMinPoutNoCuts->Write();
00481 
00482   Error1->Write();
00483   Error2->Write();
00484   Error3->Write();
00485   Error1NoCuts->Write();
00486   Error2NoCuts->Write();
00487   Error3NoCuts->Write();
00488 
00489   eSeedOverPout2->Write();
00490   eSeedOverPout2NoCuts->Write();
00491   eSeedOverPout2ESeed->Write();
00492 
00493   hadOverEm->Write();
00494   hadOverEmNoCuts->Write();
00495   hadOverEmESeed->Write();
00496 
00497   f->Write();
00498 
00499   f->Close();
00500 //   if(MyL3Algo1)delete MyL3Algo1; 
00501 //   if(UnivL3)delete UnivL3; 
00502 //   if(MyHH)delete MyHH; 
00503 //  delete f;
00505 
00506   std::cout << " " << std::endl;
00507   std::cout << "************* STATISTICS **************" << std::endl;
00508   std::cout << " Events Studied "<<read_events << std::endl;
00509   std::cout << "Timing info:" << std::endl;
00510   std::cout << "CPU time usage  -- calibrating: " << cpu_time_used << " sec." << std::endl;
00511  
00513 }
00514 
00515 
00516 DetId  ElectronCalibrationUniv::findMaxHit(const std::vector<DetId> & v1,const EBRecHitCollection *EBhits,const EERecHitCollection *EEhits) {
00517   //=================================================================================
00518   
00519   double currEnergy = 0.;
00520   DetId maxHit;
00521   
00522   for( std::vector<DetId>::const_iterator idsIt = v1.begin(); idsIt != v1.end(); ++idsIt) {
00523     if(idsIt->subdetId()==1){
00524      EBRecHitCollection::const_iterator itrechit;
00525       itrechit = EBhits->find(*idsIt);
00526       if(itrechit==EBhits->end()){
00527         std::cout << "ElectronCalibration::findMaxHit: rechit not found! " << (EBDetId)(*idsIt)<<std::endl;
00528         continue;
00529       }
00530       if(itrechit->energy() > currEnergy) {
00531         currEnergy=itrechit->energy();
00532         maxHit= *idsIt;
00533       }
00534     }else{
00535       EERecHitCollection::const_iterator itrechit;
00536       itrechit = EEhits->find(*idsIt);
00537       if(itrechit==EEhits->end()){
00538         std::cout << "ElectronCalibration::findMaxHit: rechit not found! idsIt = " << (EEDetId)(*idsIt)<< std::endl;
00539         continue;
00540       }
00541       
00542       if(itrechit->energy() > currEnergy) {
00543         currEnergy=itrechit->energy();
00544         maxHit= *idsIt;
00545       }
00546     }
00547   }
00548   
00549   return maxHit;
00550   
00551 }
00552 
00553 bool ElectronCalibrationUniv::TestEEvalidDetId(int crystal_ix, int crystal_iy, int iz) {
00554 
00555   bool valid = false;
00556   if (crystal_ix < 1 ||  crystal_ix > 100 ||
00557       crystal_iy < 1 || crystal_iy > 100 || abs(iz) != 1 ) 
00558     { return valid; }
00559   if ( (crystal_ix >= 1 && crystal_ix <= 3 && (crystal_iy <= 40 || crystal_iy > 60) ) ||
00560        (crystal_ix >= 4 && crystal_ix <= 5 && (crystal_iy <= 35 || crystal_iy > 65) ) || 
00561        (crystal_ix >= 6 && crystal_ix <= 8 && (crystal_iy <= 25 || crystal_iy > 75) ) || 
00562        (crystal_ix >= 9 && crystal_ix <= 13 && (crystal_iy <= 20 || crystal_iy > 80) ) || 
00563        (crystal_ix >= 14 && crystal_ix <= 15 && (crystal_iy <= 15 || crystal_iy > 85) ) || 
00564        (crystal_ix >= 16 && crystal_ix <= 20 && (crystal_iy <= 13 || crystal_iy > 87) ) || 
00565        (crystal_ix >= 21 && crystal_ix <= 25 && (crystal_iy <= 8 || crystal_iy > 92) ) || 
00566        (crystal_ix >= 26 && crystal_ix <= 35 && (crystal_iy <= 5 || crystal_iy > 95) ) || 
00567        (crystal_ix >= 36 && crystal_ix <= 39 && (crystal_iy <= 3 || crystal_iy > 97) ) || 
00568        (crystal_ix >= 98 && crystal_ix <= 100 && (crystal_iy <= 40 || crystal_iy > 60) ) ||
00569        (crystal_ix >= 96 && crystal_ix <= 97 && (crystal_iy <= 35 || crystal_iy > 65) ) || 
00570        (crystal_ix >= 93 && crystal_ix <= 95 && (crystal_iy <= 25 || crystal_iy > 75) ) || 
00571        (crystal_ix >= 88 && crystal_ix <= 92 && (crystal_iy <= 20 || crystal_iy > 80) ) || 
00572        (crystal_ix >= 86 && crystal_ix <= 87 && (crystal_iy <= 15 || crystal_iy > 85) ) || 
00573        (crystal_ix >= 81 && crystal_ix <= 85 && (crystal_iy <= 13 || crystal_iy > 87) ) || 
00574        (crystal_ix >= 76 && crystal_ix <= 80 && (crystal_iy <= 8 || crystal_iy > 92) ) || 
00575        (crystal_ix >= 66 && crystal_ix <= 75 && (crystal_iy <= 5 || crystal_iy > 95) ) || 
00576        (crystal_ix >= 62 && crystal_ix <= 65 && (crystal_iy <= 3 || crystal_iy > 97) ) ||
00577        ( (crystal_ix == 40 || crystal_ix == 61) && ( (crystal_iy >= 46 && crystal_iy <= 55 ) || crystal_iy <= 3 || crystal_iy > 97 )) ||
00578        ( (crystal_ix == 41 || crystal_ix == 60) && crystal_iy >= 44 && crystal_iy <= 57 ) ||
00579        ( (crystal_ix == 42 || crystal_ix == 59) && crystal_iy >= 43 && crystal_iy <= 58 ) ||
00580        ( (crystal_ix == 43 || crystal_ix == 58) && crystal_iy >= 42 && crystal_iy <= 59 ) ||
00581        ( (crystal_ix == 44 || crystal_ix == 45 || crystal_ix == 57 || crystal_ix == 56) && crystal_iy >= 41 && crystal_iy <= 60 ) ||
00582        ( crystal_ix >= 46 && crystal_ix <= 55 && crystal_iy >= 40 && crystal_iy <= 61 ) 
00583        )
00584     { return valid; }
00585   valid = true;
00586   return valid;
00587 }
00588 
00589 
00590 //=================================================================================
00591 void
00592 ElectronCalibrationUniv::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00593 {
00594 //=================================================================================
00595    using namespace edm;
00596 
00597   // Get EBRecHits
00598   edm::Handle<EBRecHitCollection> EBphits;
00599   iEvent.getByLabel( EBrecHitLabel_, EBphits);
00600   if (!EBphits.isValid()) {
00601      std::cerr << "Error! can't get the product EBRecHitCollection: " << std::endl;
00602   }
00603    const EBRecHitCollection* EBhits = EBphits.product(); // get a ptr to the product
00604 
00605    // Get EERecHits
00606    edm::Handle<EERecHitCollection> EEphits;
00607 
00608    iEvent.getByLabel( EErecHitLabel_, EEphits);
00609    if (!EEphits.isValid()) {
00610      std::cerr << "Error! can't get the product EERecHitCollection: " << std::endl;
00611    }
00612    const EERecHitCollection* EEhits = EEphits.product(); // get a ptr to the product
00613 
00614   // Get pixelElectrons
00615    edm::Handle<reco::GsfElectronCollection> pElectrons;
00616    iEvent.getByLabel(electronLabel_, pElectrons);
00617    if (!pElectrons.isValid()) {
00618      std::cerr << "Error! can't get the product ElectronCollection: " << std::endl;
00619    }
00620   const reco::GsfElectronCollection* electronCollection = pElectrons.product();
00621   read_events++;
00622   if(read_events%1000 ==0)std::cout << "read_events = " << read_events << std::endl;
00623 
00624   EventsAfterCuts->Fill(1);
00625   if (!EBhits || !EEhits)return;
00626   EventsAfterCuts->Fill(2);
00627   if (EBhits->size() == 0 && EEhits->size() == 0 )     return ;
00628   EventsAfterCuts->Fill(3);
00629   if (!electronCollection)     return ;
00630    EventsAfterCuts->Fill(4); 
00631   if (electronCollection->size() == 0)     return;
00632 
00633 //    ////////////////Need to recalibrate the events (copy code from EcalRecHitRecalib):
00634 
00638 
00639   reco::GsfElectronCollection::const_iterator eleIt = electronCollection->begin();
00640 
00641   reco::GsfElectron highPtElectron;
00642 
00643   float highestElePt=0.;
00644   bool found=false;
00645   for (eleIt=electronCollection->begin(); eleIt!=electronCollection->end(); eleIt++) {
00646 
00647      if(fabs(eleIt->eta())>2.4) continue;
00648      //     if(eleIt->eta()<0.0) continue;
00649       
00650      if(eleIt->pt()>highestElePt) {
00651        highestElePt=eleIt->pt();
00652        highPtElectron = *eleIt;
00653        found =true;
00654        //       std::cout<<" eleIt->pt( "<<eleIt->pt()<<" eleIt->eta() "<<eleIt->eta()<<std::endl;
00655     }
00656 
00657   }
00658   EventsAfterCuts->Fill(5); 
00659   if(!found) return ;
00660   
00661   const reco::SuperCluster & sc = *(highPtElectron.superCluster()) ;
00662   //  if(fabs(sc.eta())>1.479){std::cout<<" SC not in Barrel "<<sc.eta()<<std::endl;;}
00663   //  const std::vector<DetId> & v1 = sc.getHitsByDetId();
00664 
00665       std::vector<DetId> v1;
00666       //Loop to fill the vector of DetIds
00667 for (std::vector<std::pair<DetId,float> >::const_iterator idsIt = sc.hitsAndFractions().begin();
00668        idsIt != sc.hitsAndFractions().end ();++idsIt)
00669   {v1.push_back(idsIt->first);
00670  }
00671 
00672   DetId maxHitId;
00673   
00674   maxHitId = findMaxHit(v1,(EBhits),(EEhits)); 
00675   //maxHitId = findMaxHit(v1,EBhits,EEhits); 
00676   
00677   EventsAfterCuts->Fill(6);
00678   if(maxHitId.null()){std::cout<<" Null "<<std::endl; return ;}
00679 
00680   int maxCC_Eta = 0;
00681   int maxCC_Phi = 0;
00682   int Zside =0 ;
00683   if(maxHitId.subdetId()!=1) {
00684     maxCC_Eta = ((EEDetId)maxHitId).ix();
00685     maxCC_Phi = ((EEDetId)maxHitId).iy();
00686     Zside = ((EEDetId)maxHitId).zside();
00687     //    std::cout<<" ++++++++ Zside "<<Zside<<std::endl;
00688   }else{
00689     maxCC_Eta = ((EBDetId)maxHitId).ieta();
00690     maxCC_Phi = ((EBDetId)maxHitId).iphi();
00691   }
00692 
00693 
00694 
00695 
00696 //   if(maxCC_Eta>maxeta_ ) ;
00697 //   if(maxCC_Eta<mineta_ )  ;
00698 
00699   // number of events per crystal is set
00700 //   eventcrystal[maxCC_Eta][maxCC_Phi]+=1;
00701 //   if(eventcrystal[maxCC_Eta][maxCC_Phi] > numevent_) ;
00702   
00703   
00704   // fill cluster energy
00705   std::vector<float> energy;
00706   float energy3x3=0.;  
00707   float energy5x5=0.;  
00708   //Should be moved to cfg file!
00709   int ClusterSize = ClusterSize_; 
00710   
00711   const CaloSubdetectorTopology* topology=theCaloTopology->getSubdetectorTopology(DetId::Ecal,maxHitId.subdetId());
00712   std::vector<DetId> NxNaroundMax = topology->getWindow(maxHitId,ClusterSize,ClusterSize);
00713   //ToCompute 3x3
00714   std::vector<DetId> S9aroundMax = topology->getWindow(maxHitId,3,3);
00715   
00716   EventsAfterCuts->Fill(7);
00717   if((int)NxNaroundMax.size()!=ClusterSize*ClusterSize)return;
00718   EventsAfterCuts->Fill(8);
00719    if(S9aroundMax.size()!=9)return;
00720  
00721    //   std::cout<<" ******** New Event "<<std::endl;
00722 
00723   EventsAfterCuts->Fill(9);
00724    for (int icry=0;icry<ClusterSize*ClusterSize;icry++){
00725     if (NxNaroundMax[icry].subdetId() == EcalBarrel) {
00726       EBRecHitCollection::const_iterator itrechit;
00727       itrechit = EBhits->find(NxNaroundMax[icry]);
00728       if(itrechit==EBhits->end()){ 
00729         //      std::cout << "EB DetId not in e25" << std::endl;
00730         energy.push_back(0.);
00731         energy5x5 += 0.;
00732         continue;
00733       }
00734       
00735       if (edm::isNotFinite(itrechit->energy())){std::cout<<" nan energy "<<std::endl; return;}    
00736       energy.push_back(itrechit->energy());
00737       energy5x5 += itrechit->energy();
00738       
00739       //Summing in 3x3 to cut later on:    
00740       for (int tt=0;tt<9;tt++){
00741         if(NxNaroundMax[icry]==S9aroundMax[tt])energy3x3+=itrechit->energy();
00742       }
00743     }else{
00744       EERecHitCollection::const_iterator itrechit;
00745       
00746       itrechit = EEhits->find(NxNaroundMax[icry]);
00747       
00748       if(itrechit==EEhits->end()){ 
00749         //      std::cout << "EE DetId not in e25" << std::endl;
00750         //      std::cout<<" ******** putting 0 "<<std::endl;
00751         energy.push_back(0.);
00752         energy5x5 += 0.;
00753         continue;
00754       }
00755       
00756       if (edm::isNotFinite(itrechit->energy())){std::cout<<" nan energy "<<std::endl; return;}
00757       energy.push_back(itrechit->energy());
00758       energy5x5 += itrechit->energy();
00759       
00760       //Summing in 3x3 to cut later on:    
00761       for (int tt=0;tt<9;tt++){
00762         if(NxNaroundMax[icry]==S9aroundMax[tt])energy3x3+=itrechit->energy();
00763       }
00764     }
00765   }
00766   //  if((read_events-50)%10000 ==0)cout << "++++++++++++ENERGY 5x5 " <<  energy5x5 << std::endl;
00767   EventsAfterCuts->Fill(10);
00768   //  std::cout<<" ******** NxNaroundMax.size() "<<NxNaroundMax.size()<<std::endl;
00769   //  std::cout<<" ******** energy.size() "<<energy.size()<<std::endl;
00770   if((int)energy.size()!=ClusterSize*ClusterSize) return ;
00771 
00772   if(maxHitId.subdetId() == EcalBarrel){
00773     GeneralMapBeforePt->Fill(maxCC_Eta,maxCC_Phi);
00774   }else{
00775     if(Zside<0){
00776       GeneralMapEndCapMinusBeforePt->Fill(maxCC_Eta,maxCC_Phi);
00777     }else{
00778       GeneralMapEndCapPlusBeforePt->Fill(maxCC_Eta,maxCC_Phi);
00779     }
00780   }
00781 
00782   EventsAfterCuts->Fill(11);
00783   if(highestElePt<ElePt_)return ;
00784 
00785   if(maxHitId.subdetId() == EcalBarrel){
00786     GeneralMap->Fill(maxCC_Eta,maxCC_Phi);
00787   }else{
00788     if(Zside<0){
00789     GeneralMapEndCapMinus->Fill(maxCC_Eta,maxCC_Phi);
00790     }else{
00791     GeneralMapEndCapPlus->Fill(maxCC_Eta,maxCC_Phi);
00792     }
00793   }
00794 
00795   EventsAfterCuts->Fill(12);
00796    if(highPtElectron.classification()!=elecclass_ && elecclass_!= -1 )   return;
00797 
00798         float Ptrack_in=sqrt( pow(highPtElectron.trackMomentumAtVtx().X(),2) +pow(highPtElectron.trackMomentumAtVtx().Y(),2) + pow(highPtElectron.trackMomentumAtVtx().Z(),2) );
00799         
00800         float UncorrectedPatCalo = sqrt(pow(highPtElectron.trackMomentumAtCalo().X(),2)+pow(highPtElectron.trackMomentumAtCalo().Y(),2)+pow(highPtElectron.trackMomentumAtCalo().Z(),2));
00801         
00802         float Ptrack_out = sqrt( pow(highPtElectron.trackMomentumOut().X(),2)+ pow(highPtElectron.trackMomentumOut().Y(),2)+ pow(highPtElectron.trackMomentumOut().Z(),2) );
00803 
00804         e9NoCuts->Fill(energy3x3); 
00805         e25NoCuts->Fill(energy5x5); 
00806         e9Overe25NoCuts->Fill(energy3x3/energy5x5);
00807         scENoCuts->Fill(sc.energy()); 
00808         
00809         trPNoCuts->Fill(UncorrectedPatCalo); 
00810         
00811         EoPNoCuts->Fill(highPtElectron.eSuperClusterOverP()); 
00812         e25OverScENoCuts->Fill(energy5x5/sc.energy());
00813         
00814         E25oPNoCuts->Fill(energy5x5/UncorrectedPatCalo);
00815         
00816         PinOverPoutNoCuts->Fill( sqrt( pow(highPtElectron.trackMomentumAtVtx().X(),2) +pow(highPtElectron.trackMomentumAtVtx().Y(),2) + pow(highPtElectron.trackMomentumAtVtx().Z(),2) )/sqrt( pow(highPtElectron.trackMomentumOut().X(),2)+ pow(highPtElectron.trackMomentumOut().Y(),2)+ pow(highPtElectron.trackMomentumOut().Z(),2) ) );
00817         eSeedOverPoutNoCuts->Fill(highPtElectron.eSuperClusterOverP());
00818         
00819         MapCor1NoCuts->Fill(energy5x5/UncorrectedPatCalo,energy5x5/Ptrack_in);
00820         MapCor2NoCuts->Fill(energy5x5/UncorrectedPatCalo,highPtElectron.eSuperClusterOverP());
00821         MapCor3NoCuts->Fill(energy5x5/UncorrectedPatCalo,Ptrack_out/Ptrack_in);
00822         MapCor4NoCuts->Fill(energy5x5/UncorrectedPatCalo,energy5x5/highPtElectron.p());
00823         MapCor5NoCuts->Fill(energy5x5/UncorrectedPatCalo,UncorrectedPatCalo/Ptrack_out);
00824         MapCor6NoCuts->Fill(Ptrack_out/Ptrack_in,energy5x5/Ptrack_in);
00825         MapCor7NoCuts->Fill(Ptrack_out/Ptrack_in,UncorrectedPatCalo/Ptrack_out);
00826         MapCor8NoCuts->Fill(energy5x5/Ptrack_in,UncorrectedPatCalo/Ptrack_out);
00827         MapCor9NoCuts->Fill(energy5x5/UncorrectedPatCalo,highPtElectron.eSeedClusterOverPout());
00828         MapCor10NoCuts->Fill(highPtElectron.eSeedClusterOverPout(),Ptrack_out/Ptrack_in);
00829         MapCor11NoCuts->Fill(highPtElectron.eSeedClusterOverPout(),energy5x5/Ptrack_in);
00830         
00831         PinMinPoutNoCuts->Fill((Ptrack_in-Ptrack_out)/Ptrack_in);
00832         
00833         Error1NoCuts-> Fill(highPtElectron.trackMomentumError()/Ptrack_in);
00834         Error2NoCuts->Fill(highPtElectron.trackMomentumError()/Ptrack_out);
00835         Error3NoCuts->Fill(highPtElectron.trackMomentumError()/UncorrectedPatCalo);
00836         eSeedOverPout2NoCuts->Fill(highPtElectron.eSeedClusterOverPout());
00837         
00838         hadOverEmNoCuts->Fill(highPtElectron.hadronicOverEm());
00839 
00840 
00841    //Cuts!
00842    if((energy3x3/energy5x5)<cut1_)return ;
00843    if((Ptrack_out/Ptrack_in)< cut2_  || (Ptrack_out/Ptrack_in)> cut3_ )return;
00844    if((energy5x5/Ptrack_in)< cutEPin1_  || (energy5x5/Ptrack_in)> cutEPin2_ )return;
00845 //    if(!highPtElectron.ecalDriven())return;
00846 //    if(!highPtElectron.passingCutBasedPreselection())return;
00847 
00848 
00849 // //  Apply Pietro cuts:   
00850 //      EventsAfterCuts->Fill(13);
00851 //      //Module 1
00852 //      if(maxHitId.subdetId() == EcalBarrel){
00853 //        //Module 1
00854 //        if(maxCC_Eta <= 25){
00855 //          if(highPtElectron.eSuperClusterOverP()>1.05 || highPtElectron.eSuperClusterOverP()<0.95)return ;
00856 //          if(highPtElectron.eSeedClusterOverPout()>1.4 || highPtElectron.eSeedClusterOverPout()<0.90)return ;
00857 //          if((Ptrack_in- Ptrack_out) / Ptrack_in <-0.05 || (Ptrack_in- Ptrack_out) / Ptrack_in >0.2)return ;
00858 //        }else{
00859 //          //Module 2
00860 //          if( maxCC_Eta > 25&& maxCC_Eta <= 45){
00861 //            if(highPtElectron.eSuperClusterOverP()>1.05 || highPtElectron.eSuperClusterOverP()<0.95)return ;
00862 //            if(highPtElectron.eSeedClusterOverPout()>1.25 || highPtElectron.eSeedClusterOverPout()<0.90)return ;
00863 //            if((Ptrack_in- Ptrack_out) / Ptrack_in <-0.05 || (Ptrack_in- Ptrack_out) / Ptrack_in >0.2)return ;
00864 //          }else{
00865 //          //Module 3
00866 //            if( maxCC_Eta > 45&& maxCC_Eta <= 65){
00867 //              if(highPtElectron.eSuperClusterOverP()>1.05 || highPtElectron.eSuperClusterOverP()<0.95)return ;
00868 //              if(highPtElectron.eSeedClusterOverPout()>1.15 || highPtElectron.eSeedClusterOverPout()<0.90)return ;
00869 //              if((Ptrack_in- Ptrack_out) / Ptrack_in <-0.05 || (Ptrack_in- Ptrack_out) / Ptrack_in >0.15)return ;
00870 //            }else{
00871 //            if( maxCC_Eta > 65&& maxCC_Eta <= 85){
00872 //              if(highPtElectron.eSuperClusterOverP()>1.05 || highPtElectron.eSuperClusterOverP()<0.95)return ;
00873 //              if(highPtElectron.eSeedClusterOverPout()>1.15 || highPtElectron.eSeedClusterOverPout()<0.90)return ;
00874 //              if((Ptrack_in- Ptrack_out) / Ptrack_in <-0.05 || (Ptrack_in- Ptrack_out) / Ptrack_in >0.15)return ;
00875 //            }else{
00876 //              return;
00877 //            }
00878 //            }
00879 //          }
00880 //        }
00881 //      }else{
00882 //        //EndCapMinus Side:
00883 //        //EndCapPlus Side:
00884 //        int iR = sqrt((maxCC_Eta-50)*(maxCC_Eta-50) + (maxCC_Phi-50)*(maxCC_Phi-50));
00885 //        if( iR >= 22&& iR < 27){
00886 //          if(highPtElectron.eSuperClusterOverP()>1.05 || highPtElectron.eSuperClusterOverP()<0.95)return ;
00887 //          if(highPtElectron.eSeedClusterOverPout()>1.15 || highPtElectron.eSeedClusterOverPout()<0.90)return ;
00888 //          if((Ptrack_in- Ptrack_out) / Ptrack_in <-0.05 || (Ptrack_in- Ptrack_out) / Ptrack_in >0.2)return ;
00889 //        }else{
00890 //          if( iR >= 27&& iR < 32){
00891 //            if(highPtElectron.eSuperClusterOverP()>1.1 || highPtElectron.eSuperClusterOverP()<0.95)return ;
00892 //            if(highPtElectron.eSeedClusterOverPout()>1.25 || highPtElectron.eSeedClusterOverPout()<0.90)return ;
00893 //            if((Ptrack_in- Ptrack_out) / Ptrack_in <-0.05 || (Ptrack_in- Ptrack_out) / Ptrack_in >0.2)return ;
00894 //          }else{
00895 //            if( iR >= 32&& iR < 37){
00896 //              if(highPtElectron.eSuperClusterOverP()>1.05 || highPtElectron.eSuperClusterOverP()<0.95)return ;
00897 //              if(highPtElectron.eSeedClusterOverPout()>1.15 || highPtElectron.eSeedClusterOverPout()<0.90)return ;
00898 //              if((Ptrack_in- Ptrack_out) / Ptrack_in <-0.05 || (Ptrack_in- Ptrack_out) / Ptrack_in >0.2)return ;
00899 //            }else{
00900 //              if( iR >= 37&& iR < 42){
00901 //                if(highPtElectron.eSuperClusterOverP()>1.1 || highPtElectron.eSuperClusterOverP()<0.95)return ;
00902 //                if(highPtElectron.eSeedClusterOverPout()>1.15 || highPtElectron.eSeedClusterOverPout()<0.90)return ;
00903 //                if((Ptrack_in- Ptrack_out) / Ptrack_in <-0.05 || (Ptrack_in- Ptrack_out) / Ptrack_in >0.15)return ;
00904 //              }else{
00905 //                if( iR >= 42){
00906 //                  if(highPtElectron.eSuperClusterOverP()>1.05 || highPtElectron.eSuperClusterOverP()<0.95)return ;
00907 //                  if(highPtElectron.eSeedClusterOverPout()>1.15 || highPtElectron.eSeedClusterOverPout()<0.90)return ;
00908 //                if((Ptrack_in- Ptrack_out) / Ptrack_in <-0.05 || (Ptrack_in- Ptrack_out) / Ptrack_in >0.15)return ;
00909 //                }
00910 //              }
00911 //            }
00912 //          }
00913 //        }
00914 //      }
00915         
00916         
00917         if(maxHitId.subdetId() == EcalBarrel){
00918           E25oPvsEta->Fill(maxCC_Eta,energy5x5/UncorrectedPatCalo);
00919         }else{
00920           float Radius = sqrt((maxCC_Eta)*(maxCC_Eta) + (maxCC_Phi)*(maxCC_Phi));
00921           if(Zside<0){
00922             E25oPvsEtaEndCapMinus->Fill(Radius,energy5x5/UncorrectedPatCalo);
00923           }else{
00924             E25oPvsEtaEndCapPlus->Fill(Radius,energy5x5/UncorrectedPatCalo);
00925           }
00926         }
00927         e9->Fill(energy3x3); 
00928         e25->Fill(energy5x5); 
00929         e9Overe25->Fill(energy3x3/energy5x5);
00930         scE->Fill(sc.energy()); 
00931         trP->Fill(UncorrectedPatCalo);
00932         
00933         EoP->Fill(highPtElectron.eSuperClusterOverP()); 
00934         e25OverScE->Fill(energy5x5/sc.energy());
00935         
00936         E25oP->Fill(energy5x5/UncorrectedPatCalo);
00937         
00938         if(maxHitId.subdetId() == EcalBarrel){
00939           Map->Fill(maxCC_Eta,maxCC_Phi);
00940         }else{
00941           if(Zside<0){
00942             MapEndCapMinus->Fill(maxCC_Eta,maxCC_Phi);
00943           }else{
00944             MapEndCapPlus->Fill(maxCC_Eta,maxCC_Phi);
00945           }
00946         }
00947         
00948 
00949         PinOverPout->Fill( sqrt( pow(highPtElectron.trackMomentumAtVtx().X(),2) +pow(highPtElectron.trackMomentumAtVtx().Y(),2) + pow(highPtElectron.trackMomentumAtVtx().Z(),2) )/sqrt( pow(highPtElectron.trackMomentumOut().X(),2)+ pow(highPtElectron.trackMomentumOut().Y(),2)+ pow(highPtElectron.trackMomentumOut().Z(),2) ) );
00950         eSeedOverPout->Fill(highPtElectron.eSuperClusterOverP());
00951         
00952         MapCor1->Fill(energy5x5/UncorrectedPatCalo,energy5x5/Ptrack_in);
00953         MapCor2->Fill(energy5x5/UncorrectedPatCalo,highPtElectron.eSuperClusterOverP());
00954         MapCor3->Fill(energy5x5/UncorrectedPatCalo,Ptrack_out/Ptrack_in);
00955         MapCor4->Fill(energy5x5/UncorrectedPatCalo,energy5x5/highPtElectron.p());
00956         MapCor5->Fill(energy5x5/UncorrectedPatCalo,UncorrectedPatCalo/Ptrack_out);
00957         MapCor6->Fill(Ptrack_out/Ptrack_in,energy5x5/Ptrack_in);
00958         MapCor7->Fill(Ptrack_out/Ptrack_in,UncorrectedPatCalo/Ptrack_out);
00959         MapCor8->Fill(energy5x5/Ptrack_in,UncorrectedPatCalo/Ptrack_out);
00960         MapCor9->Fill(energy5x5/UncorrectedPatCalo,highPtElectron.eSeedClusterOverPout());
00961         MapCor10->Fill(highPtElectron.eSeedClusterOverPout(),Ptrack_out/Ptrack_in);
00962         MapCor11->Fill(highPtElectron.eSeedClusterOverPout(),energy5x5/Ptrack_in);
00963         
00964         PinMinPout->Fill((Ptrack_in-Ptrack_out)/Ptrack_in);
00965         
00966         Error1-> Fill(highPtElectron.trackMomentumError()/Ptrack_in);
00967         Error2->Fill(highPtElectron.trackMomentumError()/Ptrack_out);
00968         Error3->Fill(highPtElectron.trackMomentumError()/UncorrectedPatCalo);
00969         
00970         eSeedOverPout2->Fill(highPtElectron.eSeedClusterOverPout());
00971         hadOverEm->Fill(highPtElectron.hadronicOverEm());
00972   
00973     
00974         UnivEventIds.push_back(NxNaroundMax);
00975         EventMatrix.push_back(energy);
00976         EnergyVector.push_back(UncorrectedPatCalo);
00977    
00978         EventsAfterCuts->Fill(14);
00979     
00980         if(!highPtElectron.ecalDrivenSeed())EventsAfterCuts->Fill(15);
00981 
00982 
00983         return; 
00984 }
00985 
00986 DEFINE_FWK_MODULE(ElectronCalibrationUniv);