CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/RecoEgamma/EgammaTools/plugins/ggPFPhotonAnalyzer.cc

Go to the documentation of this file.
00001 #include "FWCore/Framework/interface/EDAnalyzer.h"
00002 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00003 #include "RecoEgamma/EgammaTools/interface/ggPFPhotonAnalyzer.h"
00004 #include "RecoEcal/EgammaCoreTools/interface/EcalClusterLazyTools.h"
00005 ggPFPhotonAnalyzer::ggPFPhotonAnalyzer(const edm::ParameterSet& iConfig){
00006   PFPhotonTag_=iConfig.getParameter<InputTag>("PFPhotons");
00007   PFElectronTag_=iConfig.getParameter<InputTag>("PFElectrons");
00008   
00009   recoPhotonTag_=iConfig.getParameter<InputTag>("Photons");
00010   ebReducedRecHitCollection_=iConfig.getParameter<InputTag>("ebReducedRecHitCollection");
00011   eeReducedRecHitCollection_=iConfig.getParameter<InputTag>("eeReducedRecHitCollection");
00012   esRecHitCollection_=iConfig.getParameter<InputTag>("esRecHitCollection");
00013   beamSpotCollection_ =iConfig.getParameter<InputTag>("BeamSpotCollection");
00014   pfPartTag_=iConfig.getParameter<InputTag>("PFParticles");
00015   TFile *fgbr1 = new TFile("/afs/cern.ch/work/r/rpatel/public/TMVARegressionBarrelLC.root","READ");
00016   TFile *fgbr2 = new TFile("/afs/cern.ch/work/r/rpatel/public/TMVARegressionEndCapLC.root","READ");
00017   PFLCBarrel_=(const GBRForest*)fgbr1->Get("PFLCorrEB");
00018   PFLCEndcap_=(const GBRForest*)fgbr2->Get("PFLCorrEE");
00019   tf1=new TFile("PF_test.root", "RECREATE");
00020   pf=new TTree("pf", "PFPhotons");
00021   pfclus=new TTree("pflcus", "PFClusters");
00022   pf->Branch("isConv", &isConv_, "isConv/I");
00023   pf->Branch("hasSLConv", &hasSLConv_, "hasSLConv/I");
00024   pf->Branch("isMatch", &isMatch_, "isMatch/I");
00025   pf->Branch("PFPS1", &PFPS1_, "PFPS1/F");
00026   pf->Branch("PFPS2", &PFPS2_, "PFPS2/F");
00027   pf->Branch("MustE", &MustE_, "MustE/F");
00028   pf->Branch("MustEOut", &MustEOut_, "MustEOut/F");
00029   pf->Branch("PFLowCE", &PFLowCE_, "PFLowCE/F"); 
00030   pf->Branch("PFdEta", &PFdEta_, "PFdEta/F");
00031   pf->Branch("PFdPhi", &PFdPhi_, "PFdPhi/F"); 
00032   pf->Branch("PFClusRMS", &PFClusRMS_, "PFClusRMS/F"); 
00033   pf->Branch("PFClusRMSMust", &PFClusRMSMust_, "PFClusRMSMust/F"); 
00034   pf->Branch("VtxZ", &VtxZ_, "VtxZ/F"); 
00035   pf->Branch("VtxZErr", &VtxZErr_, "VtxZErr/F"); 
00036   pf->Branch("PFPhoECorr", &PFPhoECorr_, "PFPhoECorr/F"); 
00037   pf->Branch("recoPFEnergy", &recoPFEnergy_, "recoPFEnergy/F"); 
00038   pf->Branch("SCRawE", &SCRawE_, "SCRawE");
00039 }
00040 
00041 ggPFPhotonAnalyzer::~ggPFPhotonAnalyzer(){}
00042 
00043 void ggPFPhotonAnalyzer::beginRun(const edm::Run & r, const edm::EventSetup & c){
00044   
00045   
00046 }
00047 
00048 void ggPFPhotonAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& es){
00049   Handle<reco::PhotonCollection> PFPhotons;
00050   Handle<reco::PhotonCollection> recoPhotons;
00051   Handle<reco::GsfElectronCollection> PFElectrons;
00052   Handle<reco::PFCandidateCollection>PFParticles;
00053   PhotonCollection::const_iterator iPfPho;
00054   PhotonCollection::const_iterator iPho;
00055   iEvent.getByLabel(PFPhotonTag_, PFPhotons);
00056   iEvent.getByLabel(recoPhotonTag_, recoPhotons);
00057   iEvent.getByLabel(PFElectronTag_,PFElectrons);
00058   iEvent.getByLabel(pfPartTag_,PFParticles);
00059   //for PFPhoton Constructor:
00060   edm::ESHandle<CaloGeometry> pG;
00061   es.get<CaloGeometryRecord>().get(pG);
00062   geomBar_=pG->getSubdetectorGeometry(DetId::Ecal,1);
00063   geomEnd_=pG->getSubdetectorGeometry(DetId::Ecal,2);
00064   edm::Handle<BeamSpot> beamSpotHandle;
00065   edm::Handle<EcalRecHitCollection> EBReducedRecHits;
00066   edm::Handle<EcalRecHitCollection> EEReducedRecHits;
00067   edm::Handle<EcalRecHitCollection> ESRecHits; 
00068   iEvent.getByLabel(beamSpotCollection_    , beamSpotHandle);
00069   iEvent.getByLabel(ebReducedRecHitCollection_, EBReducedRecHits);
00070   iEvent.getByLabel(eeReducedRecHitCollection_, EEReducedRecHits);
00071   iEvent.getByLabel(esRecHitCollection_       , ESRecHits);
00072   iEvent.getByLabel(beamSpotCollection_,beamSpotHandle);
00073   EcalClusterLazyTools lazyToolEcal(iEvent, es, ebReducedRecHitCollection_, eeReducedRecHitCollection_);
00074   for(reco::PhotonCollection::const_iterator iPho = recoPhotons->begin(); iPho!=recoPhotons->end(); ++iPho) {
00075     recoPFEnergy_=0;
00076         
00077     ggPFPhotons ggPFPhoton(*iPho, PFPhotons,
00078                            PFElectrons,
00079                           PFParticles,
00080                            EBReducedRecHits,
00081                            EEReducedRecHits,
00082                            ESRecHits,
00083                            geomBar_,
00084                            geomEnd_,
00085                            beamSpotHandle
00086                            );
00087     if(ggPFPhoton.MatchPFReco()){
00088       isMatch_=1;
00089       
00090       std::pair<float, float>VertexZ=ggPFPhoton.SLPoint();
00091       VtxZ_=VertexZ.first;
00092       VtxZErr_=VertexZ.second;
00093       
00094       if(ggPFPhoton.isConv()){
00095         isConv_=1;
00096       }
00097       else isConv_=0;
00098       if(ggPFPhoton.hasSLConv()){
00099         hasSLConv_=1;
00100       }
00101       else hasSLConv_=0;
00102       
00103       ggPFPhoton.fillPFClusters();
00104       PFPS1_=ggPFPhoton.PFPS1();
00105       PFPS2_=ggPFPhoton.PFPS2();
00106       MustE_=ggPFPhoton.MustE();
00107       MustEOut_=ggPFPhoton.MustEOut();
00108       PFLowCE_=ggPFPhoton.PFLowE();
00109       PFdEta_=ggPFPhoton.PFdEta();
00110       PFdPhi_=ggPFPhoton.PFdPhi();
00111       PFClusRMS_=ggPFPhoton.PFClusRMSTot();
00112       PFClusRMSMust_=ggPFPhoton.PFClusRMSMust();
00113       std::vector<reco::CaloCluster>PFC=ggPFPhoton.PFClusters();
00114       PFPhoECorr_=ggPFPhoton.getPFPhoECorr(PFC, PFLCBarrel_, PFLCEndcap_);
00115     }
00116     else{
00117       isMatch_=0;
00118       std::vector<reco::CaloCluster>PFC;
00119       std::vector<reco::PFCandidatePtr>insideBox;
00120       std::vector<DetId>MatchedRH;
00121       ggPFPhoton.PhotonPFCandMatch(*(iPho->superCluster()), insideBox,PFParticles,PFC, MatchedRH);  
00122       recoPFEnergy_=0;
00123       //cout<<"Inside Box "<<insideBox.size()<<endl;
00124       for(unsigned int i=0; i<PFC.size(); ++i)recoPFEnergy_=recoPFEnergy_+PFC[i].energy();
00125       SCRawE_=iPho->superCluster()->rawEnergy();
00126       //cout<<"PF reconstructed E "<<recoPFEnergy_<<"SC Raw E "<<(*iPho).superCluster()->rawEnergy()<<endl;
00127       PFPS1_=ggPFPhoton.PFPS1();
00128       PFPS2_=ggPFPhoton.PFPS2();
00129       MustE_=ggPFPhoton.MustE();
00130       MustEOut_=ggPFPhoton.MustEOut();
00131       PFLowCE_=ggPFPhoton.PFLowE();
00132       PFdEta_=ggPFPhoton.PFdEta();
00133       PFdPhi_=ggPFPhoton.PFdPhi();
00134       PFClusRMS_=ggPFPhoton.PFClusRMSTot();
00135       PFClusRMSMust_=ggPFPhoton.PFClusRMSMust();
00136     }
00137     pf->Fill();
00138   }
00139   
00140 }
00141 
00142 
00143 void ggPFPhotonAnalyzer::endJob(){
00144   tf1->cd();
00145   pf->Write();
00146   tf1->Write();
00147   tf1->Close();
00148 
00149 }
00150 
00151 
00152 DEFINE_FWK_MODULE(ggPFPhotonAnalyzer);
00153