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