CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/RecoParticleFlow/PFProducer/interface/PFPhotonAlgo.h

Go to the documentation of this file.
00001 #ifndef PFProducer_PFPhotonAlgo_H
00002 #define PFProducer_PFPhotonAlgo_H
00003 
00004 #include "DataFormats/ParticleFlowReco/interface/PFBlockFwd.h"
00005 #include "DataFormats/ParticleFlowReco/interface/PFBlock.h"
00006 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
00007 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidatePhotonExtra.h"
00008 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidatePhotonExtraFwd.h"
00009 #include "DataFormats/Common/interface/Handle.h"
00010 #include "DataFormats/Common/interface/OrphanHandle.h"
00011 #include "DataFormats/CaloRecHit/interface/CaloCluster.h"
00012 #include "DataFormats/CaloRecHit/interface/CaloClusterFwd.h"
00013 #include "DataFormats/ParticleFlowReco/interface/PFBlockElementGsfTrack.h"
00014 #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
00015 #include "DataFormats/GsfTrackReco/interface/GsfTrackExtra.h"
00016 #include "DataFormats/ParticleFlowReco/interface/PFBlockElementTrack.h"
00017 #include "DataFormats/ParticleFlowReco/interface/PFBlockElementSuperCluster.h"
00018 #include "DataFormats/VertexReco/interface/Vertex.h"
00019 
00020 #include "CondFormats/EgammaObjects/interface/GBRForest.h"
00021 #include "TMVA/Reader.h"
00022 #include <iostream>
00023 #include <TH2D.h>
00024 
00025 class PFEnergyCalibration;
00026 
00027 namespace reco {
00028   class PFCandidate;
00029   class PFCandidateCollectioon;
00030 }
00031 
00032 class PFPhotonAlgo {
00033  public:
00034   
00035   //constructor
00036   PFPhotonAlgo(std::string mvaweightfile,  
00037                double mvaConvCut, 
00038                bool useReg, 
00039                std::string X0_Map,
00040                const reco::Vertex& primary,
00041                const boost::shared_ptr<PFEnergyCalibration>& thePFEnergyCalibration,
00042                double sumPtTrackIsoForPhoton,
00043                double sumPtTrackIsoSlopeForPhoton
00044 ); 
00045 
00046   //destructor
00047   ~PFPhotonAlgo(){delete tmvaReader_;   };
00048 
00049   void setGBRForest(const GBRForest *LCorrForest,
00050                     const GBRForest *GCorrForest,
00051                     const GBRForest *ResForest
00052                     )
00053   {
00054     ReaderLC_=LCorrForest;
00055     ReaderGC_=GCorrForest;
00056     ReaderRes_=ResForest;
00057   }  
00058   
00059   void setGBRForest(
00060                     const GBRForest *LCorrForestEB,
00061                     const GBRForest *LCorrForestEE,
00062                     const GBRForest *GCorrForestBarrel,
00063                     const GBRForest *GCorrForestEndcapHr9,
00064                     const GBRForest *GCorrForestEndcapLr9,
00065                     const GBRForest *PFEcalResolution
00066                     )
00067   {
00068     ReaderLCEB_=LCorrForestEB;
00069     ReaderLCEE_=LCorrForestEE;
00070     ReaderGCEB_=GCorrForestBarrel;
00071     ReaderGCEEhR9_=GCorrForestEndcapHr9;
00072     ReaderGCEElR9_=GCorrForestEndcapLr9;
00073     ReaderRes_=PFEcalResolution;
00074   }  
00075   void setnPU(int nVtx){
00076     nVtx_=nVtx;
00077   }
00078   void setPhotonPrimaryVtx(const reco::Vertex& primary){
00079     primaryVertex_ = & primary;
00080   }
00081   //check candidate validity
00082   bool isPhotonValidCandidate(const reco::PFBlockRef&  blockRef,
00083                               std::vector< bool >&  active,
00084                               std::auto_ptr< reco::PFCandidateCollection > &pfPhotonCandidates,
00085                               std::vector<reco::PFCandidatePhotonExtra>& pfPhotonExtraCandidates,
00086                               std::vector<reco::PFCandidate>& 
00087                               tempElectronCandidates
00088                               //      std::auto_ptr< reco::PFCandidateCollection > &pfElectronCandidates_  
00089                               ){
00090     isvalid_=false;
00091     // RunPFPhoton has to set isvalid_ to TRUE in case it finds a valid candidate
00092     // ... TODO: maybe can be replaced by checking for the size of the CandCollection.....
00093     permElectronCandidates_.clear();
00094     match_ind.clear();
00095     RunPFPhoton(blockRef,
00096                 active,
00097                 pfPhotonCandidates,
00098                 pfPhotonExtraCandidates,
00099                 tempElectronCandidates
00100                 );
00101     int ind=0;
00102     int matches=match_ind.size();
00103     
00104     for ( std::vector<reco::PFCandidate>::const_iterator ec=tempElectronCandidates.begin();   ec != tempElectronCandidates.end(); ++ec){
00105       bool matched=false;
00106       for(int i=0; i<matches; i++)
00107         {
00108           if(ind==match_ind[i])
00109             {
00110               matched=true; 
00111               //std::cout<<"This is matched in .h "<<*ec<<std::endl; 
00112                 break;
00113             }
00114         }
00115       ++ind;
00116       if(matched)continue;
00117       permElectronCandidates_.push_back(*ec);     
00118       //std::cout<<"This is NOT matched in .h "<<*ec<<std::endl; 
00119     }
00120     
00121     match_ind.clear();
00122     
00123     tempElectronCandidates.clear(); 
00124     for ( std::vector<reco::PFCandidate>::const_iterator ec=permElectronCandidates_.begin();   ec != permElectronCandidates_.end(); ++ec)tempElectronCandidates.push_back(*ec);
00125     permElectronCandidates_.clear();
00126     
00127     return isvalid_;
00128   };
00129   
00130 private: 
00131 
00132   enum verbosityLevel {
00133     Silent,
00134     Summary,
00135     Chatty
00136   };
00137   
00138   
00139   bool isvalid_;                               // is set to TRUE when a valid PhotonCandidate is found in a PFBlock
00140   verbosityLevel  verbosityLevel_;            /* Verbosity Level: 
00141                                                   ...............  0: Say nothing at all
00142                                                   ...............  1: Print summary about found PhotonCadidates only
00143                                                   ...............  2: Chatty mode
00144                                               */ 
00145   //FOR SINGLE LEG MVA:                                       
00146   double MVACUT;
00147   bool useReg_;
00148   const reco::Vertex  *  primaryVertex_;
00149   TMVA::Reader *tmvaReader_;
00150   const GBRForest *ReaderLC_;
00151   const GBRForest *ReaderGC_;
00152   const GBRForest *ReaderRes_;
00153   
00154   const GBRForest *ReaderLCEB_;
00155   const GBRForest *ReaderLCEE_;
00156   const GBRForest *ReaderGCEB_;
00157   const GBRForest *ReaderGCEEhR9_;
00158   const GBRForest *ReaderGCEElR9_;
00159   
00160   boost::shared_ptr<PFEnergyCalibration> thePFEnergyCalibration_;
00161   double sumPtTrackIsoForPhoton_;
00162   double sumPtTrackIsoSlopeForPhoton_;
00163   std::vector<int>match_ind;
00164   //std::auto_ptr< reco::PFCandidateCollection > permElectronCandidates_;
00165 
00166   std::vector< reco::PFCandidate >permElectronCandidates_;
00167   float nlost, nlayers;
00168   float chi2, STIP, del_phi,HoverPt, EoverPt, track_pt;
00169   double mvaValue;
00170     //for Cluster Shape Calculations:
00171   float e5x5Map[5][5];
00172   
00173   //For Local Containment Corrections:
00174   float CrysPhi_, CrysEta_,  VtxZ_, ClusPhi_, ClusEta_, 
00175     ClusR9_, Clus5x5ratio_,  PFCrysEtaCrack_, logPFClusE_, e3x3_;
00176   int CrysIPhi_, CrysIEta_;
00177   float CrysX_, CrysY_;
00178   float EB;
00179   //Cluster Shapes:
00180   float eSeed_, e1x3_,e3x1_, e1x5_, e2x5Top_,  e2x5Bottom_, e2x5Left_,  e2x5Right_ ;
00181   float etop_, ebottom_, eleft_, eright_;
00182   float e2x5Max_;
00183   //For Global Corrections:
00184   float PFPhoEta_, PFPhoPhi_, PFPhoR9_, PFPhoR9Corr_, SCPhiWidth_, SCEtaWidth_, PFPhoEt_, RConv_, PFPhoEtCorr_, PFPhoE_, PFPhoECorr_, MustE_, E3x3_;
00185   float dEta_, dPhi_, LowClusE_, RMSAll_, RMSMust_, nPFClus_;
00186   float TotPS1_, TotPS2_;
00187   float nVtx_;
00188   //for Material Map
00189   TH2D* X0_sum;
00190   TH2D* X0_inner;
00191   TH2D* X0_middle;
00192   TH2D* X0_outer;
00193   float x0inner_, x0middle_, x0outer_;
00194   //for PileUP
00195   float excluded_, Mustache_EtRatio_, Mustache_Et_out_;
00196   
00197   std::vector<unsigned int> AddFromElectron_;  
00198   void RunPFPhoton(const reco::PFBlockRef&  blockRef,
00199                    std::vector< bool >& active,
00200 
00201                    std::auto_ptr< reco::PFCandidateCollection > &pfPhotonCandidates,
00202                    std::vector<reco::PFCandidatePhotonExtra>& 
00203                    pfPhotonExtraCandidates,
00204                    //  std::auto_ptr< reco::PFCandidateCollection > 
00205                    //&pfElectronCandidates_
00206                    std::vector<reco::PFCandidate>& 
00207                    tempElectronCandidates
00208                    );
00209 
00210   bool EvaluateSingleLegMVA(const reco::PFBlockRef& blockref, 
00211                             const reco::Vertex& primaryvtx, 
00212                             unsigned int track_index);
00213   
00214   double ClustersPhiRMS(std::vector<reco::CaloCluster>PFClusters, float PFPhoPhi);
00215   float EvaluateLCorrMVA(reco::PFClusterRef clusterRef );
00216   float EvaluateGCorrMVA(reco::PFCandidate, std::vector<reco::CaloCluster>PFClusters);
00217   float EvaluateResMVA(reco::PFCandidate,std::vector<reco::CaloCluster>PFClusters );
00218   std::vector<int> getPFMustacheClus(int nClust, std::vector<float>& ClustEt, std::vector<float>& ClustEta, std::vector<float>& ClustPhi);
00219   void EarlyConversion(
00220                        //std::auto_ptr< reco::PFCandidateCollection > 
00221                        //&pfElectronCandidates_,
00222                        std::vector<reco::PFCandidate>& 
00223                        tempElectronCandidates,
00224                        const reco::PFBlockElementSuperCluster* sc
00225                        );
00226 };
00227 
00228 #endif