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