CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PFEGammaAlgo.h
Go to the documentation of this file.
1 #ifndef PFProducer_PFEGammaAlgo_H
2 #define PFProducer_PFEGammaAlgo_H
3 
4 //
5 // Rewrite for GED integration: Lindsey Gray (FNAL): lagray@fnal.gov
6 //
7 // Original Authors: Fabian Stoeckli: fabian.stoeckli@cern.ch
8 // Nicholas Wardle: nckw@cern.ch
9 // Rishi Patel: rpatel@cern.ch
10 // Josh Bendavid : Josh.Bendavid@cern.ch
11 //
12 
40 #include "TMVA/Reader.h"
41 #include <iostream>
42 #include <TH2D.h>
43 
44 #include <list>
45 #include <forward_list>
46 #include <unordered_map>
47 
50 
51 class PFEGammaAlgo {
52  public:
59  typedef std::pair<const reco::PFBlockElement*,bool> PFFlaggedElement;
60  typedef std::pair<const PFSCElement*,bool> PFSCFlaggedElement;
61  typedef std::pair<const PFBremElement*,bool> PFBremFlaggedElement;
62  typedef std::pair<const PFGSFElement*,bool> PFGSFFlaggedElement;
63  typedef std::pair<const PFKFElement*,bool> PFKFFlaggedElement;
64  typedef std::pair<const PFClusterElement*,bool> PFClusterFlaggedElement;
65  typedef std::unordered_map<unsigned int, std::vector<unsigned int> > AsscMap;
66  typedef std::vector<std::pair<const reco::PFBlockElement*,
68  typedef std::unordered_map<const PFGSFElement*,
69  std::vector<PFKFFlaggedElement> > GSFToTrackMap;
70  typedef std::unordered_map<const PFClusterElement*,
71  std::vector<PFClusterFlaggedElement> > ClusterMap;
72  typedef std::unordered_map<const PFKFElement*,
73  float > KFValMap;
74 
75  struct ProtoEGObject {
78  const PFSCElement* parentSC; // if ECAL driven
79  reco::ElectronSeedRef electronSeed; // if there is one
80  // this is a mutable list of clusters
81  // if ECAL driven we take the PF SC and refine it
82  // if Tracker driven we add things to it as we discover more valid clusters
83  std::vector<PFClusterFlaggedElement> ecalclusters;
85  // associations to tracks of various sorts
86  std::vector<PFGSFFlaggedElement> primaryGSFs;
88  std::vector<PFKFFlaggedElement> primaryKFs;
89  std::vector<PFBremFlaggedElement> brems; // these are tangent based brems
90  // for manual brem recovery
91  std::vector<PFGSFFlaggedElement> secondaryGSFs;
92  std::vector<PFKFFlaggedElement> secondaryKFs;
94  // for track-HCAL cluster linking
95  std::vector<PFClusterFlaggedElement> hcalClusters;
97  // cluster closest to the gsf track(s), primary kf if none for gsf
98  // last brem tangent cluster if neither of those work
99  std::vector<const PFClusterElement*> electronClusters;
101  };
102 
103  struct PFEGConfigInfo {
104  double mvaEleCut;
106  std::shared_ptr<PFSCEnergyCalibration> thePFSCEnergyCalibration;
107  std::shared_ptr<PFEnergyCalibration> thePFEnergyCalibration;
118  unsigned int nTrackIsoForEgammaSC;
121  double mvaConvCut;
122  bool useReg;
127  };
128 
129  //constructor
131  //destructor
133 
135  eetops_ = eetops;
136  }
137 
138  void setnPU(int nVtx){
139  nVtx_=nVtx;
140  }
141  void setPhotonPrimaryVtx(const reco::Vertex& primary){
142  cfg_.primaryVtx = & primary;
143  }
144 
145  void RunPFEG(const reco::PFBlockRef& blockRef,
146  std::vector< bool >& active
147  );
148 
149  //check candidate validity
150  bool isEGValidCandidate(const reco::PFBlockRef& blockRef,
151  std::vector< bool >& active){
152  RunPFEG(blockRef,active);
153  return (egCandidate_.size()>0);
154  };
155 
156  //get PFCandidate collection
158 
159  //get the PFCandidateExtra (for all candidates)
161 
162  //get refined SCs
164 
165 private:
166 
167 
172  };
173 
174  // ------ rewritten basic processing pieces and cleaning algorithms
175  // the output collections
179 
180  // useful pre-cached mappings:
181  // hopefully we get an enum that lets us just make an array in the future
185  // keep a map of pf indices to the splayed block for convenience
186  // sadly we're mashing together two ways of thinking about the block
187  std::vector<std::vector<PFFlaggedElement> > _splayedblock;
189 
190  // pre-cleaning for the splayed block
191  bool isAMuon(const reco::PFBlockElement&);
192  // pre-processing of ECAL clusters near non-primary KF tracks
194 
195  // candidate collections:
196  // this starts off as an inclusive list of prototype objects built from
197  // supercluster/ecal-driven seeds and tracker driven seeds in a block
198  // it is then refined through by various cleanings, determining the energy
199  // flow.
200  // use list for constant-time removals
201  std::list<ProtoEGObject> _refinableObjects;
202  // final list of fully refined objects in this block
204 
205  // functions:
206  // this runs the functions below
208 
209  // build proto eg object using all available unflagged resources in block.
210  // this will be kind of like the old 'SetLinks' but with simplified and
211  // maximally inclusive logic that builds a list of 'refinable' objects
212  // that we will perform operations on to clean/remove as needed
213  void initializeProtoCands(std::list<ProtoEGObject>&);
214 
215  // turn a supercluster into a map of ECAL cluster elements
216  // related to PS cluster elements
218  std::vector<PFClusterFlaggedElement>&,
219  ClusterMap&);
220 
222  ClusterMap::mapped_type&);
223 
224 
225  void dumpCurrentRefinableObjects() const;
226 
227  // wax on
228 
229  // the key merging operation, done after building up links
230  void mergeROsByAnyLink(std::list<ProtoEGObject>&);
231 
232  // refining steps you can do with tracks
239  // WARNING! this should be ONLY used after doing the ECAL->track
240  // reverse lookup after the primary linking!
243  // helper function for above
245 
246  // refining steps doing the ECAL -> track piece
247  // this is the factorization of the old PF photon algo stuff
248  // which through arcane means I came to understand was conversion matching
250 
251  // wax off
252 
253  // refining steps remove things from the built-up objects
254  // original bits were for removing bad KF tracks
255  // new (experimental) piece to remove clusters associated to these tracks
256  // behavior determined by bools passed to unlink_KFandECALMatchedToHCAL
259  bool removeFreeECAL = false,
260  bool removeSCECAL = false);
261 
262 
263  // things for building the final candidate and refined SC collections
264  void fillPFCandidates(const std::list<ProtoEGObject>&,
268 
269  // helper functions for that
270 
271  float calculate_ele_mva(const ProtoEGObject&,
273  void fill_extra_info(const ProtoEGObject&,
275 
276  // ------ end of new stuff
277 
278 
279  unsigned int whichTrackAlgo(const reco::TrackRef& trackRef);
280 
281  bool isPrimaryTrack(const reco::PFBlockElementTrack& KfEl,
282  const reco::PFBlockElementGsfTrack& GsfEl);
283 
284 
285  //std::vector<double> BDToutput_;
286  //std::vector<reco::PFCandidateElectronExtra > electronExtra_;
287  std::vector<bool> lockExtraKf_;
288  std::vector<bool> GsfTrackSingleEcal_;
289  std::vector< std::pair <unsigned int, unsigned int> > fifthStepKfTrack_;
290  std::vector< std::pair <unsigned int, unsigned int> > convGsfTrack_;
291 
293 
294  TMVA::Reader *tmvaReaderEle_;
295 
296  const char *mvaWeightFile_;
297 
298  // New BDT observables
299  // Normalization
301 
302  // Pure Tracking observ.
305  // int nhit_gsf,nhit_kf;
307 
308  // Tracker-Ecal observ.
311  float SigmaEtaEta;
312  //int lateBrem,firstBrem,earlyBrem;
315 
316  bool isvalid_;
317 
318  //const std::vector<reco::GsfElectron> * theGsfElectrons_;
319  //end of data members from PFElectronAlgo
320 
321 
322  //bool isvalid_; // is set to TRUE when a valid PhotonCandidate is found in a PFBlock
323  verbosityLevel verbosityLevel_; /* Verbosity Level:
324  ............... 0: Say nothing at all
325  ............... 1: Print summary about found PhotonCadidates only
326  ............... 2: Chatty mode
327  */
328  //FOR SINGLE LEG MVA:
330  TMVA::Reader *tmvaReader_;
334 
340 
341 // boost::shared_ptr<PFEnergyCalibration> thePFEnergyCalibration_;
344  std::vector<int>match_ind;
345  //std::auto_ptr< reco::PFCandidateCollection > permElectronCandidates_;
346 
347  std::vector< reco::PFCandidate >permElectronCandidates_;
348  float nlost, nlayers;
350  double mvaValue;
351  //for Cluster Shape Calculations:
352  float e5x5Map[5][5];
353 
354  //For Local Containment Corrections:
358  float CrysX_, CrysY_;
359  float EB;
360  //Cluster Shapes:
363  float e2x5Max_;
364  //For Global Corrections:
367  float TotPS1_, TotPS2_;
368  float nVtx_;
369  //for Material Map
370  TH2D* X0_sum;
371  TH2D* X0_inner;
372  TH2D* X0_middle;
373  TH2D* X0_outer;
375  //for PileUP
377 
378  std::vector<unsigned int> AddFromElectron_;
379 
381 // std::vector<reco::CaloCluser> ebeeCluster_;
382 // std::vector<reco::PreshowerCluser> esCluster_;
383 // std::vector<reco::SuperCluser> sCluster_;
385 
386  float EvaluateSingleLegMVA(const reco::PFBlockRef& blockref,
387  const reco::Vertex& primaryvtx,
388  unsigned int track_index);
389 };
390 
391 #endif
float SCEtaWidth_
Definition: PFEGammaAlgo.h:365
float e5x5Map[5][5]
Definition: PFEGammaAlgo.h:352
float EtotBremPinPoutMode
Definition: PFEGammaAlgo.h:309
std::vector< int > match_ind
Definition: PFEGammaAlgo.h:344
std::unordered_map< unsigned int, std::vector< unsigned int > > AsscMap
Definition: PFEGammaAlgo.h:65
double mvaValue
Definition: PFEGammaAlgo.h:350
Abstract base class for a PFBlock element (track, cluster...)
unsigned int whichTrackAlgo(const reco::TrackRef &trackRef)
std::vector< PFClusterFlaggedElement > ecalclusters
Definition: PFEGammaAlgo.h:83
const char * mvaWeightFile_
Definition: PFEGammaAlgo.h:296
reco::PFBlockElementSuperCluster PFSCElement
Definition: PFEGammaAlgo.h:54
reco::PFCandidateEGammaExtraCollection egExtra_
Definition: PFEGammaAlgo.h:384
std::vector< std::pair< unsigned int, unsigned int > > fifthStepKfTrack_
Definition: PFEGammaAlgo.h:289
reco::SuperClusterCollection refinedscs_
Definition: PFEGammaAlgo.h:178
reco::SuperClusterCollection & getRefinedSCs()
Definition: PFEGammaAlgo.h:163
void RunPFEG(const reco::PFBlockRef &blockRef, std::vector< bool > &active)
reco::PFBlockRef parentBlock
Definition: PFEGammaAlgo.h:77
void unlinkRefinableObjectKFandECALWithBadEoverP(ProtoEGObject &)
std::vector< unsigned int > AddFromElectron_
Definition: PFEGammaAlgo.h:378
double sumPtTrackIsoSlopeForPhoton_
Definition: PFEGammaAlgo.h:343
std::unordered_map< const PFKFElement *, float > KFValMap
Definition: PFEGammaAlgo.h:73
float e2x5Bottom_
Definition: PFEGammaAlgo.h:361
float EGsfPoutMode
Definition: PFEGammaAlgo.h:309
std::vector< bool > lockExtraKf_
Definition: PFEGammaAlgo.h:287
std::pair< const PFClusterElement *, bool > PFClusterFlaggedElement
Definition: PFEGammaAlgo.h:64
const reco::Vertex * primaryVertex_
Definition: PFEGammaAlgo.h:329
const GBRForest * ReaderGC_
Definition: PFEGammaAlgo.h:332
std::vector< std::pair< const reco::PFBlockElement *, const reco::PFBlockElement * > > ElementMap
Definition: PFEGammaAlgo.h:67
std::shared_ptr< PFEnergyCalibration > thePFEnergyCalibration
Definition: PFEGammaAlgo.h:107
std::map< unsigned int, Link > LinkData
Definition: PFBlock.h:46
float Mustache_Et_out_
Definition: PFEGammaAlgo.h:376
std::vector< PFClusterFlaggedElement > hcalClusters
Definition: PFEGammaAlgo.h:95
reco::PFBlockElementGsfTrack PFGSFElement
Definition: PFEGammaAlgo.h:56
bool isPrimaryTrack(const reco::PFBlockElementTrack &KfEl, const reco::PFBlockElementGsfTrack &GsfEl)
float DEtaGsfEcalClust
Definition: PFEGammaAlgo.h:310
void setPhotonPrimaryVtx(const reco::Vertex &primary)
Definition: PFEGammaAlgo.h:141
void linkRefinableObjectPrimaryGSFTrackToECAL(ProtoEGObject &)
#define NULL
Definition: scimark2.h:8
const GBRForest * ReaderGCEElR9_
Definition: PFEGammaAlgo.h:339
const GBRForest * ReaderGCEB_
Definition: PFEGammaAlgo.h:337
std::vector< const PFClusterElement * > electronClusters
Definition: PFEGammaAlgo.h:99
std::vector< std::vector< PFFlaggedElement > > _splayedblock
Definition: PFEGammaAlgo.h:187
std::pair< const PFGSFElement *, bool > PFGSFFlaggedElement
Definition: PFEGammaAlgo.h:62
void linkRefinableObjectBremTangentsToECAL(ProtoEGObject &)
TH2D * X0_outer
Definition: PFEGammaAlgo.h:373
const reco::Vertex * primaryVtx
Definition: PFEGammaAlgo.h:124
float Clus5x5ratio_
Definition: PFEGammaAlgo.h:355
reco::PFBlockRef _currentblock
Definition: PFEGammaAlgo.h:183
std::pair< const reco::PFBlockElement *, bool > PFFlaggedElement
Definition: PFEGammaAlgo.h:59
std::pair< const PFSCElement *, bool > PFSCFlaggedElement
Definition: PFEGammaAlgo.h:60
float PFPhoEtCorr_
Definition: PFEGammaAlgo.h:365
float e2x5Right_
Definition: PFEGammaAlgo.h:361
PFEGConfigInfo cfg_
Definition: PFEGammaAlgo.h:292
std::vector< bool > GsfTrackSingleEcal_
Definition: PFEGammaAlgo.h:288
float DPtOverPt_gsf
Definition: PFEGammaAlgo.h:303
const GBRForest * ReaderGCEEhR9_
Definition: PFEGammaAlgo.h:338
void linkRefinableObjectECALToSingleLegConv(ProtoEGObject &)
std::vector< reco::PFCandidate > permElectronCandidates_
Definition: PFEGammaAlgo.h:347
edm::Handle< reco::PFCluster::EEtoPSAssociation > eetops_
Definition: PFEGammaAlgo.h:182
float EvaluateSingleLegMVA(const reco::PFBlockRef &blockref, const reco::Vertex &primaryvtx, unsigned int track_index)
std::vector< PFKFFlaggedElement > secondaryKFs
Definition: PFEGammaAlgo.h:92
float SCPhiWidth_
Definition: PFEGammaAlgo.h:365
void dumpCurrentRefinableObjects() const
void initializeProtoCands(std::list< ProtoEGObject > &)
float Mustache_EtRatio_
Definition: PFEGammaAlgo.h:376
void linkRefinableObjectPrimaryKFsToSecondaryKFs(ProtoEGObject &)
void setnPU(int nVtx)
Definition: PFEGammaAlgo.h:138
bool unwrapSuperCluster(const reco::PFBlockElementSuperCluster *, std::vector< PFClusterFlaggedElement > &, ClusterMap &)
reco::PFCandidateEGammaExtraCollection & getEGExtra()
Definition: PFEGammaAlgo.h:160
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
std::vector< PFGSFFlaggedElement > secondaryGSFs
Definition: PFEGammaAlgo.h:91
reco::PFCluster::EEtoPSAssociation EEtoPSAssociation
Definition: PFEGammaAlgo.h:53
PFEGammaAlgo(const PFEGConfigInfo &)
const PFSCElement * parentSC
Definition: PFEGammaAlgo.h:78
void setEEtoPSAssociation(const edm::Handle< EEtoPSAssociation > &eetops)
Definition: PFEGammaAlgo.h:134
const GBRForest * ReaderLCEB_
Definition: PFEGammaAlgo.h:335
std::vector< reco::PFCandidateEGammaExtra > PFCandidateEGammaExtraCollection
collection of PFCandidateEGammaExtras
std::vector< PFBremFlaggedElement > brems
Definition: PFEGammaAlgo.h:89
std::vector< std::pair< CaloClusterPtr::key_type, edm::Ptr< PFCluster > > > EEtoPSAssociation
Definition: PFCluster.h:50
std::unordered_map< const PFGSFElement *, std::vector< PFKFFlaggedElement > > GSFToTrackMap
Definition: PFEGammaAlgo.h:69
float DPtOverPt_kf
Definition: PFEGammaAlgo.h:303
float dPtOverPt_gsf
Definition: PFEGammaAlgo.h:303
std::list< ProtoEGObject > _refinableObjects
Definition: PFEGammaAlgo.h:201
reco::PFBlockElementCluster PFClusterElement
Definition: PFEGammaAlgo.h:58
float logPFClusE_
Definition: PFEGammaAlgo.h:355
reco::PFBlockElementBrem PFBremElement
Definition: PFEGammaAlgo.h:55
reco::PFCandidateEGammaExtraCollection outcandsextra_
Definition: PFEGammaAlgo.h:177
void linkKFTrackToECAL(const PFKFFlaggedElement &, ProtoEGObject &)
void buildAndRefineEGObjects(const reco::PFBlockRef &block)
reco::PFCandidateCollection & getCandidates()
Definition: PFEGammaAlgo.h:157
reco::PFBlock::LinkData _currentlinks
Definition: PFEGammaAlgo.h:184
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
void fill_extra_info(const ProtoEGObject &, reco::PFCandidateEGammaExtra &)
reco::PFCandidateCollection egCandidate_
Definition: PFEGammaAlgo.h:380
bool isAMuon(const reco::PFBlockElement &)
reco::ElectronSeedRef electronSeed
Definition: PFEGammaAlgo.h:79
float calculate_ele_mva(const ProtoEGObject &, reco::PFCandidateEGammaExtra &)
float PFPhoECorr_
Definition: PFEGammaAlgo.h:365
reco::PFBlockElementTrack PFKFElement
Definition: PFEGammaAlgo.h:57
bool isEGValidCandidate(const reco::PFBlockRef &blockRef, std::vector< bool > &active)
Definition: PFEGammaAlgo.h:150
float SigmaEtaEta
Definition: PFEGammaAlgo.h:311
void linkRefinableObjectGSFTracksToKFs(ProtoEGObject &)
std::vector< std::pair< unsigned int, unsigned int > > convGsfTrack_
Definition: PFEGammaAlgo.h:290
TMVA::Reader * tmvaReaderEle_
Definition: PFEGammaAlgo.h:294
std::vector< PFKFFlaggedElement > primaryKFs
Definition: PFEGammaAlgo.h:88
std::unordered_map< const PFClusterElement *, std::vector< PFClusterFlaggedElement > > ClusterMap
Definition: PFEGammaAlgo.h:71
float EtotPinMode
Definition: PFEGammaAlgo.h:309
std::shared_ptr< PFSCEnergyCalibration > thePFSCEnergyCalibration
Definition: PFEGammaAlgo.h:106
ElementMap _recoveredlinks
Definition: PFEGammaAlgo.h:188
const GBRForest * ReaderLCEE_
Definition: PFEGammaAlgo.h:336
void removeOrLinkECALClustersToKFTracks()
reco::SuperCluster buildRefinedSuperCluster(const ProtoEGObject &)
TH2D * X0_inner
Definition: PFEGammaAlgo.h:371
void unlinkRefinableObjectKFandECALMatchedToHCAL(ProtoEGObject &, bool removeFreeECAL=false, bool removeSCECAL=false)
std::pair< const PFKFElement *, bool > PFKFFlaggedElement
Definition: PFEGammaAlgo.h:63
void mergeROsByAnyLink(std::list< ProtoEGObject > &)
const GBRForest * ReaderRes_
Definition: PFEGammaAlgo.h:333
float PFPhoR9Corr_
Definition: PFEGammaAlgo.h:365
int attachPSClusters(const PFClusterElement *, ClusterMap::mapped_type &)
void linkRefinableObjectKFTracksToECAL(ProtoEGObject &)
TMVA::Reader * tmvaReader_
Definition: PFEGammaAlgo.h:330
void linkRefinableObjectSecondaryKFsToECAL(ProtoEGObject &)
reco::PFCandidateCollection _finalCandidates
Definition: PFEGammaAlgo.h:203
TH2D * X0_middle
Definition: PFEGammaAlgo.h:372
double sumPtTrackIsoForPhoton_
Definition: PFEGammaAlgo.h:342
void linkRefinableObjectConvSecondaryKFsToSecondaryKFs(ProtoEGObject &)
verbosityLevel verbosityLevel_
Definition: PFEGammaAlgo.h:323
reco::PFCandidateCollection outcands_
Definition: PFEGammaAlgo.h:176
void fillPFCandidates(const std::list< ProtoEGObject > &, reco::PFCandidateCollection &, reco::PFCandidateEGammaExtraCollection &)
const GBRForest * ReaderLC_
Definition: PFEGammaAlgo.h:331
std::vector< PFGSFFlaggedElement > primaryGSFs
Definition: PFEGammaAlgo.h:86
std::pair< const PFBremElement *, bool > PFBremFlaggedElement
Definition: PFEGammaAlgo.h:61
void linkRefinableObjectPrimaryGSFTrackToHCAL(ProtoEGObject &)
float PFCrysEtaCrack_
Definition: PFEGammaAlgo.h:355