CMS 3D CMS Logo

PFPhotonAlgo.h
Go to the documentation of this file.
1 #ifndef PFProducer_PFPhotonAlgo_H
2 #define PFProducer_PFPhotonAlgo_H
3 
19 
21 #include "TMVA/Reader.h"
22 #include <iostream>
23 #include <TH2D.h>
24 
26 
27 namespace reco {
28  class PFCandidate;
29  class PFCandidateCollectioon;
30 }
31 
32 class PFPhotonAlgo {
33  public:
34 
35  //constructor
36  PFPhotonAlgo(std::string mvaweightfile,
37  double mvaConvCut,
38  bool useReg,
40  const reco::Vertex& primary,
41  const boost::shared_ptr<PFEnergyCalibration>& thePFEnergyCalibration,
44 );
45 
46  //destructor
47  ~PFPhotonAlgo(){delete tmvaReader_; };
48 
49  void setGBRForest(const GBRForest *LCorrForest,
50  const GBRForest *GCorrForest,
51  const GBRForest *ResForest
52  )
53  {
54  ReaderLC_=LCorrForest;
55  ReaderGC_=GCorrForest;
56  ReaderRes_=ResForest;
57  }
58 
60  const GBRForest *LCorrForestEB,
61  const GBRForest *LCorrForestEE,
62  const GBRForest *GCorrForestBarrel,
63  const GBRForest *GCorrForestEndcapHr9,
64  const GBRForest *GCorrForestEndcapLr9,
65  const GBRForest *PFEcalResolution
66  )
67  {
68  ReaderLCEB_=LCorrForestEB;
69  ReaderLCEE_=LCorrForestEE;
70  ReaderGCEB_=GCorrForestBarrel;
71  ReaderGCEEhR9_=GCorrForestEndcapHr9;
72  ReaderGCEElR9_=GCorrForestEndcapLr9;
73  ReaderRes_=PFEcalResolution;
74  }
75  void setnPU(int nVtx){
76  nVtx_=nVtx;
77  }
78  void setPhotonPrimaryVtx(const reco::Vertex& primary){
79  primaryVertex_ = & primary;
80  }
81  //check candidate validity
83  std::vector< bool >& active,
84  std::unique_ptr< reco::PFCandidateCollection > &pfPhotonCandidates,
85  std::vector<reco::PFCandidatePhotonExtra>& pfPhotonExtraCandidates,
86  std::vector<reco::PFCandidate>&
87  tempElectronCandidates
88  // std::shared_ptr< reco::PFCandidateCollection > &pfElectronCandidates_
89  ){
90  isvalid_=false;
91  // RunPFPhoton has to set isvalid_ to TRUE in case it finds a valid candidate
92  // ... TODO: maybe can be replaced by checking for the size of the CandCollection.....
93  permElectronCandidates_.clear();
94  match_ind.clear();
95  RunPFPhoton(blockRef,
96  active,
97  pfPhotonCandidates,
98  pfPhotonExtraCandidates,
99  tempElectronCandidates
100  );
101  int ind=0;
102  int matches=match_ind.size();
103 
104  for ( std::vector<reco::PFCandidate>::const_iterator ec=tempElectronCandidates.begin(); ec != tempElectronCandidates.end(); ++ec){
105  bool matched=false;
106  for(int i=0; i<matches; i++)
107  {
108  if(ind==match_ind[i])
109  {
110  matched=true;
111  //std::cout<<"This is matched in .h "<<*ec<<std::endl;
112  break;
113  }
114  }
115  ++ind;
116  if(matched)continue;
117  permElectronCandidates_.push_back(*ec);
118  //std::cout<<"This is NOT matched in .h "<<*ec<<std::endl;
119  }
120 
121  match_ind.clear();
122 
123  tempElectronCandidates.clear();
124  for ( std::vector<reco::PFCandidate>::const_iterator ec=permElectronCandidates_.begin(); ec != permElectronCandidates_.end(); ++ec)tempElectronCandidates.push_back(*ec);
125  permElectronCandidates_.clear();
126 
127  return isvalid_;
128  };
129 
130 private:
131 
135  Chatty
136  };
137 
138 
139  bool isvalid_; // is set to TRUE when a valid PhotonCandidate is found in a PFBlock
140  verbosityLevel verbosityLevel_; /* Verbosity Level:
141  ............... 0: Say nothing at all
142  ............... 1: Print summary about found PhotonCadidates only
143  ............... 2: Chatty mode
144  */
145  //FOR SINGLE LEG MVA:
146  double MVACUT;
147  bool useReg_;
149  TMVA::Reader *tmvaReader_;
153 
159 
160  boost::shared_ptr<PFEnergyCalibration> thePFEnergyCalibration_;
163  std::vector<int>match_ind;
164  //std::auto_ptr< reco::PFCandidateCollection > permElectronCandidates_;
165 
166  std::vector< reco::PFCandidate >permElectronCandidates_;
167  float nlost, nlayers;
168  float chi2, STIP, del_phi,HoverPt, EoverPt, track_pt;
169  double mvaValue;
170  //for Cluster Shape Calculations:
171  float e5x5Map[5][5];
172 
173  //For Local Containment Corrections:
174  float CrysPhi_, CrysEta_, VtxZ_, ClusPhi_, ClusEta_,
175  ClusR9_, Clus5x5ratio_, PFCrysEtaCrack_, logPFClusE_, e3x3_;
176  int CrysIPhi_, CrysIEta_;
177  float CrysX_, CrysY_;
178  float EB;
179  //Cluster Shapes:
180  float eSeed_, e1x3_,e3x1_, e1x5_, e2x5Top_, e2x5Bottom_, e2x5Left_, e2x5Right_ ;
181  float etop_, ebottom_, eleft_, eright_;
182  float e2x5Max_;
183  //For Global Corrections:
184  float PFPhoEta_, PFPhoPhi_, PFPhoR9_, PFPhoR9Corr_, SCPhiWidth_, SCEtaWidth_, PFPhoEt_, RConv_, PFPhoEtCorr_, PFPhoE_, PFPhoECorr_, MustE_, E3x3_;
185  float dEta_, dPhi_, LowClusE_, RMSAll_, RMSMust_, nPFClus_;
186  float TotPS1_, TotPS2_;
187  float nVtx_;
188  //for Material Map
189  TH2D* X0_sum;
190  TH2D* X0_inner;
191  TH2D* X0_middle;
192  TH2D* X0_outer;
193  float x0inner_, x0middle_, x0outer_;
194  //for PileUP
195  float excluded_, Mustache_EtRatio_, Mustache_Et_out_;
196 
197  std::vector<unsigned int> AddFromElectron_;
198  void RunPFPhoton(const reco::PFBlockRef& blockRef,
199  std::vector< bool >& active,
200 
201  std::unique_ptr<reco::PFCandidateCollection> &pfPhotonCandidates,
202  std::vector<reco::PFCandidatePhotonExtra>&
203  pfPhotonExtraCandidates,
204  // std::unique_ptr<reco::PFCandidateCollection>
205  //&pfElectronCandidates_
206  std::vector<reco::PFCandidate>&
207  tempElectronCandidates
208  );
209 
210  bool EvaluateSingleLegMVA(const reco::PFBlockRef& blockref,
211  const reco::Vertex& primaryvtx,
212  unsigned int track_index);
213 
214  double ClustersPhiRMS(const std::vector<reco::CaloCluster>&PFClusters, float PFPhoPhi);
215  float EvaluateLCorrMVA(reco::PFClusterRef clusterRef );
216  float EvaluateGCorrMVA(const reco::PFCandidate&, const std::vector<reco::CaloCluster>& PFClusters);
217  float EvaluateResMVA(const reco::PFCandidate&,const std::vector<reco::CaloCluster>& PFClusters );
218  std::vector<int> getPFMustacheClus(int nClust, std::vector<float>& ClustEt, std::vector<float>& ClustEta, std::vector<float>& ClustPhi);
219  void EarlyConversion(
220  //std::auto_ptr< reco::PFCandidateCollection >
221  //&pfElectronCandidates_,
222  std::vector<reco::PFCandidate>&
223  tempElectronCandidates,
225  );
226 };
227 
228 #endif
const GBRForest * ReaderLCEE_
Definition: PFPhotonAlgo.h:155
bool isPhotonValidCandidate(const reco::PFBlockRef &blockRef, std::vector< bool > &active, std::unique_ptr< reco::PFCandidateCollection > &pfPhotonCandidates, std::vector< reco::PFCandidatePhotonExtra > &pfPhotonExtraCandidates, std::vector< reco::PFCandidate > &tempElectronCandidates)
Definition: PFPhotonAlgo.h:82
void setnPU(int nVtx)
Definition: PFPhotonAlgo.h:75
const GBRForest * ReaderGC_
Definition: PFPhotonAlgo.h:151
verbosityLevel verbosityLevel_
Definition: PFPhotonAlgo.h:140
const GBRForest * ReaderRes_
Definition: PFPhotonAlgo.h:152
std::vector< unsigned int > AddFromElectron_
Definition: PFPhotonAlgo.h:197
const GBRForest * ReaderGCEEhR9_
Definition: PFPhotonAlgo.h:157
std::vector< reco::PFCandidate > permElectronCandidates_
Definition: PFPhotonAlgo.h:166
double mvaValue
Definition: PFPhotonAlgo.h:169
TMVA::Reader * tmvaReader_
Definition: PFPhotonAlgo.h:149
TH2D * X0_outer
Definition: PFPhotonAlgo.h:192
const GBRForest * ReaderLC_
Definition: PFPhotonAlgo.h:150
const GBRForest * ReaderLCEB_
Definition: PFPhotonAlgo.h:154
TH2D * X0_inner
Definition: PFPhotonAlgo.h:190
TH2D * X0_middle
Definition: PFPhotonAlgo.h:191
const reco::Vertex * primaryVertex_
Definition: PFPhotonAlgo.h:148
double sumPtTrackIsoSlopeForPhoton_
Definition: PFPhotonAlgo.h:162
float SCPhiWidth_
Definition: PFPhotonAlgo.h:184
boost::shared_ptr< PFEnergyCalibration > thePFEnergyCalibration_
Definition: PFPhotonAlgo.h:160
const GBRForest * ReaderGCEB_
Definition: PFPhotonAlgo.h:156
void setGBRForest(const GBRForest *LCorrForestEB, const GBRForest *LCorrForestEE, const GBRForest *GCorrForestBarrel, const GBRForest *GCorrForestEndcapHr9, const GBRForest *GCorrForestEndcapLr9, const GBRForest *PFEcalResolution)
Definition: PFPhotonAlgo.h:59
void setGBRForest(const GBRForest *LCorrForest, const GBRForest *GCorrForest, const GBRForest *ResForest)
Definition: PFPhotonAlgo.h:49
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:40
fixed size matrix
float Mustache_EtRatio_
Definition: PFPhotonAlgo.h:195
const GBRForest * ReaderGCEElR9_
Definition: PFPhotonAlgo.h:158
double sumPtTrackIsoForPhoton_
Definition: PFPhotonAlgo.h:161
void setPhotonPrimaryVtx(const reco::Vertex &primary)
Definition: PFPhotonAlgo.h:78
std::vector< int > match_ind
Definition: PFPhotonAlgo.h:163