CMS 3D CMS Logo

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