CMS 3D CMS Logo

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