CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch2/src/RecoEgamma/Examples/plugins/SimplePi0DiscAnalyzer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    RecoEgamma/Examples
00004 // Class:      SimplePi0DiscAnalyzer
00005 //
00013 //
00014 // Original Author:  Aristotelis Kyriakis
00015 //         Created:  May 26 13:22:06 CEST 2009
00016 // $Id: SimplePi0DiscAnalyzer.cc,v 1.11 2010/10/19 17:39:21 wmtan Exp $
00017 //
00018 //
00019 
00020 // user include files
00021 #include "RecoEgamma/Examples/plugins/SimplePi0DiscAnalyzer.h"
00022 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00023 #include "FWCore/Framework/interface/EDAnalyzer.h"
00024 #include "FWCore/Framework/interface/Event.h"
00025 #include "FWCore/Framework/interface/MakerMacros.h"
00026 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00027 #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
00028 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
00029 #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
00030 #include "DataFormats/EgammaReco/interface/BasicClusterFwd.h"
00031 #include "DataFormats/EgammaReco/interface/SuperClusterFwd.h"
00032 #include "DataFormats/EgammaReco/interface/ElectronSeed.h"
00033 #include "DataFormats/EgammaReco/interface/ElectronSeedFwd.h"
00034 #include "DataFormats/JetReco/interface/CaloJetCollection.h"
00035 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
00036 
00037 #include "CLHEP/Units/PhysicalConstants.h"
00038 #include <iostream>
00039 #include "TMath.h"
00040 #include "TFile.h"
00041 #include "TH1F.h"
00042 #include "TH1I.h"
00043 #include "TH2F.h"
00044 #include "TProfile.h"
00045 #include "TTree.h"
00046 #include <iostream>
00047 
00048 using namespace reco;
00049 
00050 SimplePi0DiscAnalyzer::SimplePi0DiscAnalyzer(const edm::ParameterSet& conf)
00051 {
00052 
00053   outputFile_ = conf.getParameter<std::string>("outputFile");
00054   rootFile_ = new TFile(outputFile_.c_str(),"RECREATE");
00055 
00056 
00057   photonCollectionProducer_ = conf.getParameter<std::string>("phoProducer");
00058   photonCollection_ = conf.getParameter<std::string>("photonCollection");
00059 
00060 
00061  
00062 }
00063 
00064 SimplePi0DiscAnalyzer::~SimplePi0DiscAnalyzer()
00065 {
00066 
00067   // do anything here that needs to be done at desctruction time
00068   // (e.g. close files, deallocate resources etc.)
00069    rootFile_->Write();
00070    rootFile_->Close();
00071 }
00072 
00073 void SimplePi0DiscAnalyzer::beginJob(){
00074 
00075   rootFile_->cd();
00076   std::cout << "beginJob() ->  Book the Histograms" << std::endl;
00077   
00078   hConv_ntracks_ = new TH1F("nConvTracks","Number of tracks of converted Photons ",10,0.,10);
00079   hAll_nnout_Assoc_ = new TH1F("All_nnout_Assoc","NNout for All Photons(AssociationMap)",100,0.,1.);
00080   hAll_nnout_NoConv_Assoc_ = new TH1F("All_nnout_NoConv_Assoc","NNout for Unconverted Photons(AssociationMap)",100,0.,1.);
00081   hAll_nnout_NoConv_Assoc_R9_ = new TH1F("All_nnout_NoConv_Assoc_R9","NNout for Unconverted Photons with R9>0.93 (AssociationMap)",100,0.,1.);
00082   hBarrel_nnout_Assoc_ = new TH1F("barrel_nnout_Assoc","NNout for Barrel Photons(AssociationMap)",100,0.,1.);
00083   hBarrel_nnout_NoConv_Assoc_ = new TH1F("barrel_nnout_NoConv_Assoc","NNout for Barrel Unconverted Photons(AssociationMap)",100,0.,1.);
00084   hBarrel_nnout_NoConv_Assoc_R9_ = new TH1F("barrel_nnout_NoConv_Assoc_R9","NNout for Barrel Unconverted Photons with R9>0.93 (AssociationMap)",100,0.,1.);
00085   hEndcNoPresh_nnout_Assoc_ = new TH1F("endcNoPresh_nnout_Assoc","NNout for Endcap NoPresh Photons(AssociationMap)",100,0.,1.);
00086   hEndcNoPresh_nnout_NoConv_Assoc_ = new TH1F("endcNoPresh_nnout_NoConv_Assoc","NNout for Endcap Unconverted NoPresh Photons(AssociationMap)",100,0.,1.);
00087   hEndcNoPresh_nnout_NoConv_Assoc_R9_ = new TH1F("endcNoPresh_nnout_NoConv_Assoc_R9","NNout for Endcap Unconverted NoPresh Photons with R9>0.93 (AssociationMap)",100,0.,1.);
00088   hEndcWithPresh_nnout_Assoc_ = new TH1F("endcWithPresh_nnout_Assoc","NNout for Endcap WithPresh Photons(AssociationMap)",100,0.,1.);
00089   hEndcWithPresh_nnout_NoConv_Assoc_ = new TH1F("endcWithPresh_nnout_NoConv_Assoc","NNout for Endcap Unconverted WithPresh Photons(AssociationMap)",100,0.,1.);
00090   hEndcWithPresh_nnout_NoConv_Assoc_R9_ = new TH1F("endcWithPresh_nnout_NoConv_Assoc_R9","NNout for Endcap Unconverted WithPresh Photons with R9>0.93 (AssociationMap)",100,0.,1.);
00091 
00092 }
00093 
00094 void
00095 SimplePi0DiscAnalyzer::endJob(){
00096 
00097   rootFile_->cd();
00098   std::cout << "endJob() ->  Write the Histograms" << std::endl;
00099   hConv_ntracks_->Write();
00100 
00101   hAll_nnout_Assoc_->Write();
00102   hAll_nnout_NoConv_Assoc_->Write();
00103   hAll_nnout_NoConv_Assoc_R9_->Write();
00104   hBarrel_nnout_Assoc_->Write();
00105   hBarrel_nnout_NoConv_Assoc_->Write();
00106   hBarrel_nnout_NoConv_Assoc_R9_->Write();
00107   hEndcNoPresh_nnout_Assoc_->Write();
00108   hEndcNoPresh_nnout_NoConv_Assoc_->Write();
00109   hEndcNoPresh_nnout_NoConv_Assoc_R9_->Write();
00110   hEndcWithPresh_nnout_Assoc_->Write();
00111   hEndcWithPresh_nnout_NoConv_Assoc_->Write();
00112   hEndcWithPresh_nnout_NoConv_Assoc_R9_->Write();
00113 
00114 }
00115 
00116 void
00117 SimplePi0DiscAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00118 {
00119   std::cout << std::endl;
00120   std::cout << " -------------- NEW EVENT : Run, Event =  " << iEvent.id() << std::endl;
00121 
00122  edm::Handle<reco::PhotonCollection> PhotonHandle;
00123   iEvent.getByLabel(photonCollectionProducer_, photonCollection_ , PhotonHandle);
00124   const reco::PhotonCollection photons = *(PhotonHandle.product());
00125 
00126   std::cout <<"----> Photons size: "<< photons.size()<<std::endl;
00127 
00128   edm::Handle<reco::PhotonPi0DiscriminatorAssociationMap>  map;
00129   iEvent.getByLabel("piZeroDiscriminators","PhotonPi0DiscriminatorAssociationMap",  map);
00130   reco::PhotonPi0DiscriminatorAssociationMap::const_iterator mapIter;
00131 
00132 //  int PhoInd = 0;
00133 
00134   for( reco::PhotonCollection::const_iterator  iPho = photons.begin(); iPho != photons.end(); iPho++) { // Loop over Photons
00135 
00136     reco::Photon localPho(*iPho);
00137 
00138     float Photon_et = localPho.et(); float Photon_eta = localPho.eta(); 
00139     float Photon_phi = localPho.phi(); float Photon_r9 = localPho.r9();
00140     bool isPhotConv  = localPho.hasConversionTracks();
00141 //    std::cout << "Photon Id = " << PhoInd 
00142     std::cout << "Photon Id = " <<  iPho - photons.begin()
00143               << " with Et = " << Photon_et 
00144               << " Eta = " << Photon_eta 
00145               << " Phi = " << Photon_phi 
00146               << " R9 = " << Photon_r9 
00147               << " and conv_id = " << isPhotConv << std::endl;
00148 
00149 
00150     SuperClusterRef it_super = localPho.superCluster(); // get the SC related to the Photon candidate
00151 
00152 //    hConv_ntracks_->Fill(Ntrk_conv);
00153 
00154     float nn = -10;
00155 //    mapIter = map->find(edm::Ref<reco::PhotonCollection>(PhotonHandle,PhoInd));
00156     mapIter = map->find(edm::Ref<reco::PhotonCollection>(PhotonHandle,iPho - photons.begin()));
00157     if(mapIter!=map->end()) {
00158       nn = mapIter->val;
00159     }
00160     if(fabs(it_super->eta()) <= 1.442) {
00161        hBarrel_nnout_Assoc_->Fill(nn);
00162        hAll_nnout_Assoc_->Fill(nn);
00163        std::cout << "AssociationMap Barrel NN = " << nn << std::endl;
00164        if(!isPhotConv) {
00165           hBarrel_nnout_NoConv_Assoc_->Fill(nn);
00166           hAll_nnout_NoConv_Assoc_->Fill(nn);
00167        }
00168        if(Photon_r9>0.93) {
00169           hBarrel_nnout_NoConv_Assoc_R9_->Fill(nn);
00170           hAll_nnout_NoConv_Assoc_R9_->Fill(nn);
00171        }
00172     } else if( (fabs(it_super->eta()) >= 1.556 && fabs(it_super->eta()) < 1.65) || fabs(it_super->eta()) > 2.5) {
00173        hEndcNoPresh_nnout_Assoc_->Fill(nn);
00174        hAll_nnout_Assoc_->Fill(nn);
00175        std::cout << "AssociationMap EndcNoPresh NN = " << nn << std::endl;
00176        if(!isPhotConv) {
00177           hEndcNoPresh_nnout_NoConv_Assoc_->Fill(nn);
00178           hAll_nnout_NoConv_Assoc_->Fill(nn);
00179        }
00180        if(Photon_r9>0.93) {
00181           hEndcNoPresh_nnout_NoConv_Assoc_R9_->Fill(nn);
00182           hAll_nnout_NoConv_Assoc_R9_->Fill(nn);
00183        }       
00184     } else if(fabs(it_super->eta()) >= 1.65 && fabs(it_super->eta()) <= 2.5 ) {
00185        hEndcWithPresh_nnout_Assoc_->Fill(nn);
00186        hAll_nnout_Assoc_->Fill(nn);
00187        std::cout << "AssociationMap EndcWithPresh NN = " << nn << std::endl;
00188        if(!isPhotConv) {
00189           hEndcWithPresh_nnout_NoConv_Assoc_->Fill(nn);
00190           hAll_nnout_NoConv_Assoc_->Fill(nn);
00191        }
00192        if(Photon_r9>0.93) {
00193           hEndcWithPresh_nnout_NoConv_Assoc_R9_->Fill(nn);
00194           hAll_nnout_NoConv_Assoc_R9_->Fill(nn);
00195        }       
00196     }
00197 
00198 
00199 //    PhoInd++;
00200   } // End Loop over Photons
00201 
00202 }
00203 //define this as a plug-in
00204 DEFINE_FWK_MODULE(SimplePi0DiscAnalyzer);
00205