CMS 3D CMS Logo

SimplePi0DiscAnalyzer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    SimplePi0DiscAnalyzer
00004 // Class:      SimplePi0DiscAnalyzer
00005 // 
00006 //
00007 // Original Authors:  A. Kyriakis NCSR "Demokritos" Athens
00008 //                    D Maletic, "Vinca" Belgrade
00009 //
00010 //         Created:  Wed Sep 12 13:36:27 CEST 2007
00011 // $Id: SimplePi0DiscAnalyzer.cc,v 1.5 2008/05/16 18:17:36 nancy Exp $
00012 //
00013 //
00014 
00015 
00016 // system include files
00017 #include <memory>
00018 
00019 // user include files
00020 #include "FWCore/Framework/interface/Frameworkfwd.h"
00021 #include "FWCore/Framework/interface/EDAnalyzer.h"
00022 
00023 #include "FWCore/Framework/interface/Event.h"
00024 #include "FWCore/Framework/interface/MakerMacros.h"
00025 
00026 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00027 
00028 #include "DataFormats/EgammaCandidates/interface/Photon.h"
00029 #include "DataFormats/EgammaCandidates/interface/PhotonFwd.h"
00030 
00031 #include "DataFormats/EgammaCandidates/interface/Conversion.h"
00032 #include "DataFormats/EgammaCandidates/interface/ConversionFwd.h"
00033 //#include "DataFormats/EgammaReco/interface/SuperCluster.h"
00034 #include "DataFormats/CaloRecHit/interface/CaloCluster.h"
00035 
00036 #include "DataFormats/EgammaCandidates/interface/PhotonPi0DiscriminatorAssociation.h"
00037 
00038 #include "TFile.h"
00039 #include "TH1F.h"
00040 
00041 using namespace std;
00042 using namespace reco;
00043 using namespace edm;
00044 
00045 //
00046 // class decleration
00047 //
00048 
00049 class SimplePi0DiscAnalyzer : public edm::EDAnalyzer {
00050    public:
00051       explicit SimplePi0DiscAnalyzer(const edm::ParameterSet&);
00052 
00053       ~SimplePi0DiscAnalyzer();
00054 
00055 
00056    private:
00057      
00058      virtual void beginJob(const edm::EventSetup&) ;
00059      virtual void analyze(const edm::Event&, const edm::EventSetup&);
00060      virtual void endJob() ;
00061       // ----------member data ---------------------------
00062         
00063      string photonCollectionProducer_;       
00064      string photonCorrCollectionProducer_;       
00065      string uncorrectedPhotonCollection_;
00066      string correctedPhotonCollection_;
00067 
00068      string outputFile_;
00069      TFile*  rootFile_;
00070 
00071      TH1F* hConv_ntracks_;
00072 
00073      TH1F* hAll_nnout_Assoc_;
00074      TH1F* hAll_nnout_NoConv_Assoc_;
00075      TH1F* hBarrel_nnout_Assoc_;
00076      TH1F* hBarrel_nnout_NoConv_Assoc_;
00077      TH1F* hEndcNoPresh_nnout_Assoc_;
00078      TH1F* hEndcNoPresh_nnout_NoConv_Assoc_;
00079      TH1F* hEndcWithPresh_nnout_Assoc_;
00080      TH1F* hEndcWithPresh_nnout_NoConv_Assoc_;
00081      
00082 };
00083 
00084 SimplePi0DiscAnalyzer::SimplePi0DiscAnalyzer(const edm::ParameterSet& iConfig)
00085 
00086 {
00087 
00088   photonCollectionProducer_ = iConfig.getParameter<string>("phoProducer");
00089   photonCorrCollectionProducer_ = iConfig.getParameter<string>("corrPhoProducer");
00090   uncorrectedPhotonCollection_ = iConfig.getParameter<string>("uncorrectedPhotonCollection");
00091   correctedPhotonCollection_ = iConfig.getParameter<string>("correctedPhotonCollection");
00092 
00093     outputFile_   = iConfig.getParameter<string>("outputFile");
00094 
00095     rootFile_ = TFile::Open(outputFile_.c_str(),"RECREATE"); // open output file to store histograms
00096 
00097 }
00098 
00099 SimplePi0DiscAnalyzer::~SimplePi0DiscAnalyzer()
00100 {
00101    delete rootFile_;
00102 
00103 }
00104 
00105 //
00106 // member functions
00107 //
00108 
00109 // ------------ method called to for each event  ------------
00110 void
00111 SimplePi0DiscAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00112 {
00113   cout << endl;
00114   cout << " -------------- NEW EVENT : Run, Event =  " << iEvent.id() << endl;
00115    
00116   // Get the ConvertedPhotonCollection
00117   Handle<ConversionCollection> convertedPhotonHandle; // get the Converted Photon info
00118   iEvent.getByLabel("conversions", "", convertedPhotonHandle);
00119   const reco::ConversionCollection phoCollection = *(convertedPhotonHandle.product());
00120 
00121   cout << " ---> ConvertedPhotonCollection.size() = " << phoCollection.size() << endl;
00122 
00123   // Get the  corrected  photon collection
00124   Handle<reco::PhotonCollection> correctedPhotonHandle; 
00125   iEvent.getByLabel(photonCorrCollectionProducer_, correctedPhotonCollection_ , correctedPhotonHandle);
00126   const reco::PhotonCollection photons = *(correctedPhotonHandle.product());
00127 
00128   cout <<"----> Photons size: "<< photons.size()<<endl;
00129 
00130   edm::Handle<reco::PhotonPi0DiscriminatorAssociationMap>  map;
00131   iEvent.getByLabel("piZeroDiscriminators","PhotonPi0DiscriminatorAssociationMap",  map);
00132   reco::PhotonPi0DiscriminatorAssociationMap::const_iterator mapIter;
00133 
00134   int PhoInd = 0;
00135 
00136   /*
00137       
00138   for( reco::PhotonCollection::const_iterator  iPho = photons.begin(); iPho != photons.end(); iPho++) { // Loop over Photons
00139           
00140     reco::Photon localPho(*iPho);
00141 
00142     float Photon_eta = localPho.eta(); float Photon_phi = localPho.phi();
00143     cout << "Photon Id = " << PhoInd << " with Energy = " << localPho.energy() 
00144          << " Et = " <<  localPho.energy()*sin(2*atan(exp(-Photon_eta)))
00145          << " Eta = " << Photon_eta << " and Phi = " << Photon_phi << endl;       
00146 
00147     SuperClusterRef it_super = localPho.superCluster(); // get the SC related to the Photon candidate
00148 
00149     bool isPhotConv = false;
00150     int Ntrk_conv = 0;
00151     int Conv_SCE_id = 0;
00152     for( reco::ConversionCollection::const_iterator iCPho = phoCollection.begin(); 
00153          iCPho != phoCollection.end(); iCPho++) { 
00154        SuperClusterRef it_superConv = (*iCPho).superCluster();// get the SC related to the  Converted Photon candidate
00155        if(it_super == it_superConv) { 
00156          isPhotConv = (*iCPho).isConverted(); 
00157          Ntrk_conv = (*iCPho).tracks().size();
00158          break;
00159        }    
00160        Conv_SCE_id++;
00161     } // End of Photon Conversion Loop     
00162     hConv_ntracks_->Fill(Ntrk_conv);
00163     
00164     mapIter = map->find(edm::Ref<reco::PhotonCollection>(correctedPhotonHandle,PhoInd));
00165     float nn = mapIter->val;
00166     if(fabs(Photon_eta) <= 1.442) {
00167        hBarrel_nnout_Assoc_->Fill(nn);
00168        hAll_nnout_Assoc_->Fill(nn);
00169        cout << "AssociationMap Barrel NN = " << nn << endl;
00170        if(isPhotConv) {
00171           hBarrel_nnout_NoConv_Assoc_->Fill(nn);
00172           hAll_nnout_NoConv_Assoc_->Fill(nn);          
00173        } 
00174     } else if( (fabs(Photon_eta) >= 1.556 && fabs(Photon_eta) < 1.65) || fabs(Photon_eta) > 2.5) {     
00175        hEndcNoPresh_nnout_Assoc_->Fill(nn);
00176        hAll_nnout_Assoc_->Fill(nn);
00177        cout << "AssociationMap EndcNoPresh NN = " << nn << endl;
00178        if(isPhotConv) {
00179           hEndcNoPresh_nnout_NoConv_Assoc_->Fill(nn);
00180           hAll_nnout_NoConv_Assoc_->Fill(nn);
00181        }
00182     } else if(fabs(Photon_eta) >= 1.65 && fabs(Photon_eta) <= 2.5 ) {
00183        hEndcWithPresh_nnout_Assoc_->Fill(nn);
00184        hAll_nnout_Assoc_->Fill(nn);
00185        cout << "AssociationMap EndcWithPresh NN = " << nn << endl;
00186        if(isPhotConv) {
00187           hEndcWithPresh_nnout_NoConv_Assoc_->Fill(nn);
00188           hAll_nnout_NoConv_Assoc_->Fill(nn);
00189        }
00190     } 
00191 
00192     PhoInd++;
00193   } // End Loop over Photons
00194 
00195 
00196 
00197   */
00198 
00199 }
00200 
00201 // ------------ method called once each job just before starting event loop  ------------
00202 void SimplePi0DiscAnalyzer::beginJob(const edm::EventSetup&)
00203 {
00204   rootFile_->cd();
00205 
00206   hConv_ntracks_ = new TH1F("nConvTracks","Number of tracks of converted Photons ",10,0.,10);    
00207   hAll_nnout_Assoc_ = new TH1F("All_nnout_Assoc","NNout for All Photons(AssociationMap)",100,0.,1.);
00208   hAll_nnout_NoConv_Assoc_ = new TH1F("All_nnout_NoConv_Assoc","NNout for Unconverted Photons(AssociationMap)",100,0.,1.);
00209   hBarrel_nnout_Assoc_ = new TH1F("barrel_nnout_Assoc","NNout for Barrel Photons(AssociationMap)",100,0.,1.);
00210   hBarrel_nnout_NoConv_Assoc_ = new TH1F("barrel_nnout_NoConv_Assoc","NNout for Barrel Unconverted Photons(AssociationMap)",100,0.,1.);
00211   hEndcNoPresh_nnout_Assoc_ = new TH1F("endcNoPresh_nnout_Assoc","NNout for Endcap NoPresh Photons(AssociationMap)",100,0.,1.);
00212   hEndcNoPresh_nnout_NoConv_Assoc_ = new TH1F("endcNoPresh_nnout_NoConv_Assoc","NNout for Endcap Unconverted NoPresh Photons(AssociationMap)",100,0.,1.);
00213   hEndcWithPresh_nnout_Assoc_ = new TH1F("endcWithPresh_nnout_Assoc","NNout for Endcap WithPresh Photons(AssociationMap)",100,0.,1.);
00214   hEndcWithPresh_nnout_NoConv_Assoc_ = new TH1F("endcWithPresh_nnout_NoConv_Assoc","NNout for Endcap Unconverted WithPresh Photons(AssociationMap)",100,0.,1.);
00215 
00216 }
00217 
00218 // ------------ method called once each job just after ending the event loop  ------------
00219 void 
00220 SimplePi0DiscAnalyzer::endJob() {
00221   rootFile_->cd();
00222 
00223   hConv_ntracks_->Write();
00224 
00225   hAll_nnout_Assoc_->Write();
00226   hAll_nnout_NoConv_Assoc_->Write();
00227   hBarrel_nnout_Assoc_->Write();
00228   hBarrel_nnout_NoConv_Assoc_->Write();
00229   hEndcNoPresh_nnout_Assoc_->Write();
00230   hEndcNoPresh_nnout_NoConv_Assoc_->Write();
00231   hEndcWithPresh_nnout_Assoc_->Write();
00232   hEndcWithPresh_nnout_NoConv_Assoc_->Write();
00233 
00234   rootFile_->Close();
00235 
00236 }
00237 
00238 //define this as a plug-in
00239 DEFINE_FWK_MODULE(SimplePi0DiscAnalyzer);

Generated on Tue Jun 9 17:43:34 2009 for CMSSW by  doxygen 1.5.4