CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/Calibration/EcalAlCaRecoProducers/src/AlCaElectronsTest.h

Go to the documentation of this file.
00001 // system include files
00002 #include <memory>
00003 #include <string>
00004 #include <iostream>
00005 #include <algorithm>
00006 
00007 // user include files
00008 #include "FWCore/Framework/interface/Frameworkfwd.h"
00009 #include "FWCore/Framework/interface/EDAnalyzer.h"
00010 #include "FWCore/Framework/interface/Event.h"
00011 #include "FWCore/Framework/interface/EventSetup.h"
00012 #include "FWCore/Framework/interface/MakerMacros.h"
00013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00014 //#include "Calibration/EcalAlCaRecoProducers/interface/AlCaElectronsProducer.h"
00015 #include "DataFormats/EgammaCandidates/interface/SiStripElectron.h"
00016 #include "DataFormats/EgammaCandidates/interface/ElectronFwd.h"
00017 #include "DataFormats/EgammaCandidates/interface/Electron.h"
00018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00019 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00020 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
00021 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00022 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00023 #include "DataFormats/EgammaReco/interface/BasicCluster.h"
00024 
00025 
00026 #include "TFile.h"
00027 #include "TH1.h"
00028 #include "TH2.h"
00029 
00030 #include <Math/VectorUtil.h>
00031 
00032 class AlCaElectronsTest : public edm::EDAnalyzer {
00033   public:
00034     explicit AlCaElectronsTest (const edm::ParameterSet&) ;
00035     ~AlCaElectronsTest () {}
00036      virtual void analyze (const edm::Event& iEvent, 
00037                            const edm::EventSetup& iSetup) ;
00038      virtual void beginJob() ;
00039      virtual void endJob () ;
00040 
00041   private:
00042 
00043      EcalRecHit getMaximum (const EcalRecHitCollection * recHits) ;
00044      void fillAroundBarrel (const EcalRecHitCollection * recHits, int eta, int phi) ;
00045      void fillAroundEndcap (const EcalRecHitCollection * recHits, int ics, int ips) ;
00046 
00047 
00048   private:
00049 
00050     edm::InputTag m_barrelAlCa ;
00051     edm::InputTag m_endcapAlCa ;
00052     std::string   m_outputFileName ;            
00053 
00055     TH2F * m_barrelGlobalCrystalsMap ;
00057     TH2F * m_barrelLocalCrystalsMap ;
00059     TH2F * m_endcapGlobalCrystalsMap ;
00061     TH2F * m_endcapLocalCrystalsMap ;
00063     TH2F * m_barrelGlobalCrystalsEnergy ;
00065     TH2F * m_barrelLocalCrystalsEnergy ;
00067     TH2F * m_endcapGlobalCrystalsEnergy ;
00069     TH2F * m_endcapLocalCrystalsEnergy ;
00071     TH2F * m_barrelGlobalCrystalsEnergyMap ;
00073     TH2F * m_endcapGlobalCrystalsEnergyMap ;
00074 } ;
00075 
00076 
00077 // ----------------------------------------------------------------
00078 
00079 
00080 AlCaElectronsTest::AlCaElectronsTest (const edm::ParameterSet& iConfig) :
00081   m_barrelAlCa (iConfig.getParameter<edm::InputTag> ("alcaBarrelHitCollection")) ,
00082   m_endcapAlCa (iConfig.getParameter<edm::InputTag> ("alcaEndcapHitCollection")) ,
00083   m_outputFileName (iConfig.getUntrackedParameter<std::string>
00084                       ("HistOutFile",std::string ("AlCaElectronsTest.root"))) 
00085 {}
00086 
00087 
00088 // ----------------------------------------------------------------
00089 
00090 
00091 void 
00092 AlCaElectronsTest::beginJob()
00093 {
00094   m_barrelGlobalCrystalsMap = new TH2F ("m_barrelGlobalCrystalsMap","m_barrelGlobalCrystalsMap",171,-85,86,360,0,360) ;
00095   m_barrelLocalCrystalsMap = new TH2F ("m_barrelLocalCrystalsMap","m_barrelLocalCrystalsMap",20,-10,10,20,-10,10) ;
00096   m_endcapGlobalCrystalsMap = new TH2F ("m_endcapGlobalCrystalsMap","m_endcapGlobalCrystalsMap",100,0,100,100,0,100) ;
00097   m_endcapLocalCrystalsMap = new TH2F ("m_endcapLocalCrystalsMap","m_endcapLocalCrystalsMap",20,-10,10,20,-10,10) ;
00098   m_barrelGlobalCrystalsEnergy = new TH2F ("m_barrelGlobalCrystalsEnergy","m_barrelGlobalCrystalsEnergy",171,-85,86,360,0,360) ;
00099   m_barrelLocalCrystalsEnergy = new TH2F ("m_barrelLocalCrystalsEnergy","m_barrelLocalCrystalsEnergy",20,-10,10,20,-10,10) ;
00100   m_endcapGlobalCrystalsEnergy = new TH2F ("m_endcapGlobalCrystalsEnergy","m_endcapGlobalCrystalsEnergy",100,0,100,100,0,100) ;
00101   m_endcapLocalCrystalsEnergy = new TH2F ("m_endcapLocalCrystalsEnergy","m_endcapLocalCrystalsEnergy",20,-10,10,20,-10,10) ;
00102   m_barrelGlobalCrystalsEnergyMap = new TH2F ("m_barrelGlobalCrystalsEnergyMap","m_barrelGlobalCrystalsEnergyMap",171,-85,86,360,0,360) ;
00103   m_endcapGlobalCrystalsEnergyMap = new TH2F ("m_endcapGlobalCrystalsEnergyMap","m_endcapGlobalCrystalsEnergyMap",100,0,100,100,0,100) ;
00104    return ;
00105 }
00106 
00107 
00108 // ----------------------------------------------------------------
00109 
00110 
00111 void 
00112 AlCaElectronsTest::endJob ()
00113 {      
00114    TFile output (m_outputFileName.c_str (),"recreate") ;
00115    m_barrelGlobalCrystalsMap->Write () ;
00116    m_barrelLocalCrystalsMap->Write () ;
00117    m_endcapGlobalCrystalsMap->Write () ;
00118    m_endcapLocalCrystalsMap->Write () ;   
00119    m_barrelGlobalCrystalsEnergy->Write () ;
00120    m_barrelLocalCrystalsEnergy->Write () ;
00121    m_endcapGlobalCrystalsEnergy->Write () ;
00122    m_endcapLocalCrystalsEnergy->Write () ;   
00123    m_barrelGlobalCrystalsEnergyMap->Write () ;
00124    m_endcapGlobalCrystalsEnergyMap->Write () ;
00125    output.Close () ;
00126    //PG save root things
00127    return ;
00128 }
00129 
00130 
00131 // ----------------------------------------------------------------
00132 
00133 
00134 void 
00135 AlCaElectronsTest::analyze (const edm::Event& iEvent, 
00136                             const edm::EventSetup& iSetup)
00137 {
00138   //FIXME replace with msg logger
00139   std::cout << "[AlCaElectronsTest] analysing event " 
00140             << iEvent.id () << std::endl ;
00141 
00142   //PG get the collections  
00143   // get Barrel RecHits
00144   edm::Handle<EBRecHitCollection> barrelRecHitsHandle ;
00145   iEvent.getByLabel (m_barrelAlCa, barrelRecHitsHandle) ;
00146   if (!barrelRecHitsHandle.isValid()) {
00147       std::cerr << "[AlCaElectronsTest] caught std::exception "
00148                 << " in rertieving " << m_barrelAlCa 
00149                 << std::endl ;
00150       return ;
00151   } else {
00152       const EBRecHitCollection* barrelHitsCollection = barrelRecHitsHandle.product () ;
00153       //PG fill the histo with the maximum
00154       EcalRecHit barrelMax = getMaximum (barrelHitsCollection) ;
00155       EBDetId barrelMaxId (barrelMax.id ()) ; 
00156       m_barrelGlobalCrystalsMap->Fill (
00157           barrelMaxId.ieta () ,
00158           barrelMaxId.iphi () 
00159         ) ;
00160       m_barrelGlobalCrystalsEnergy->Fill (
00161           barrelMaxId.ieta () ,
00162           barrelMaxId.iphi () ,
00163           barrelMax.energy ()
00164         ) ;
00165       fillAroundBarrel (
00166           barrelHitsCollection, 
00167           barrelMaxId.ieta (), 
00168           barrelMaxId.iphi ()
00169         ) ;
00170   }
00171   
00172   // get Endcap RecHits
00173   edm::Handle<EERecHitCollection> endcapRecHitsHandle ;
00174   iEvent.getByLabel (m_endcapAlCa,endcapRecHitsHandle) ;
00175   if (!endcapRecHitsHandle.isValid()) {
00176       std::cerr << "[AlCaElectronsTest] caught std::exception " 
00177                 << " in rertieving " << m_endcapAlCa 
00178                 << std::endl ;
00179       return ;
00180   } else {
00181       const EERecHitCollection* endcapHitsCollection = endcapRecHitsHandle.product () ;
00182       //PG fill the histo with the maximum
00183       EcalRecHit endcapMax = getMaximum (endcapHitsCollection) ;
00184       EEDetId endcapMaxId (endcapMax.id ()) ; 
00185       m_endcapGlobalCrystalsMap->Fill (
00186           endcapMaxId.ix () ,
00187           endcapMaxId.iy () 
00188         ) ;
00189       m_endcapGlobalCrystalsEnergy->Fill (
00190           endcapMaxId.ix () ,
00191           endcapMaxId.iy () ,
00192           endcapMax.energy ()
00193         ) ;
00194       fillAroundEndcap (
00195           endcapHitsCollection, 
00196           endcapMaxId.ix (), 
00197           endcapMaxId.iy ()
00198         ) ;
00199   }
00200 }
00201 
00202 
00203 // ----------------------------------------------------------------
00204 
00205 
00206 EcalRecHit
00207 AlCaElectronsTest::getMaximum (const EcalRecHitCollection * recHits) 
00208 {
00209   double energy = 0. ;
00210   EcalRecHit max ;
00211   for (EcalRecHitCollection::const_iterator elem = recHits->begin () ;
00212        elem != recHits->end () ;
00213        ++elem)
00214     {
00215       if (elem->energy () > energy)
00216         {
00217           energy = elem->energy () ;
00218           max = *elem ;
00219         }        
00220     }   
00221   return max ;
00222 }
00223 
00224 
00225 // ----------------------------------------------------------------
00226 
00227 
00228 void
00229 AlCaElectronsTest::fillAroundBarrel (const EcalRecHitCollection * recHits, int eta, int phi)
00230 {
00231   for (EcalRecHitCollection::const_iterator elem = recHits->begin () ;
00232        elem != recHits->end () ;
00233        ++elem)
00234     {
00235       EBDetId elementId = elem->id () ; 
00236       m_barrelLocalCrystalsMap->Fill (
00237         elementId.ieta () - eta ,
00238         elementId.iphi () - phi 
00239       ) ;
00240       m_barrelLocalCrystalsEnergy->Fill (
00241         elementId.ieta () - eta ,
00242         elementId.iphi () - phi ,
00243         elem->energy ()
00244       ) ;
00245      m_barrelGlobalCrystalsEnergyMap->Fill (
00246         elementId.ieta () ,
00247         elementId.iphi () ,
00248         elem->energy ()
00249       ) ;
00250 
00251     }   
00252   return ;
00253 }
00254 
00255 
00256 // ----------------------------------------------------------------
00257 
00258 
00259 void
00260 AlCaElectronsTest::fillAroundEndcap (const EcalRecHitCollection * recHits, int ics, int ips)
00261 {
00262   for (EcalRecHitCollection::const_iterator elem = recHits->begin () ;
00263        elem != recHits->end () ;
00264        ++elem)
00265     {
00266       EEDetId elementId = elem->id () ; 
00267       m_endcapLocalCrystalsMap->Fill (
00268         elementId.ix () - ics ,
00269         elementId.iy () - ips 
00270       ) ;
00271       m_endcapLocalCrystalsEnergy->Fill (
00272         elementId.ix () - ics ,
00273         elementId.iy () - ips ,
00274         elem->energy ()
00275       ) ;
00276       m_endcapGlobalCrystalsEnergyMap->Fill (
00277         elementId.ix () ,
00278         elementId.iy () ,
00279         elem->energy ()
00280       ) ;
00281     }   
00282   return ;
00283 }