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 <iostream>
45 #include <TH2D.h>
46 
47 #include <list>
48 #include <forward_list>
49 #include <unordered_map>
50 
53 
56 
57 class PFEGammaAlgo {
58  public:
65  typedef std::pair<const reco::PFBlockElement*,bool> PFFlaggedElement;
66  typedef std::pair<const PFSCElement*,bool> PFSCFlaggedElement;
67  typedef std::pair<const PFBremElement*,bool> PFBremFlaggedElement;
68  typedef std::pair<const PFGSFElement*,bool> PFGSFFlaggedElement;
69  typedef std::pair<const PFKFElement*,bool> PFKFFlaggedElement;
70  typedef std::pair<const PFClusterElement*,bool> PFClusterFlaggedElement;
71  typedef std::unordered_map<unsigned int, std::vector<unsigned int> > AsscMap;
72  typedef std::vector<std::pair<const reco::PFBlockElement*,
73  const reco::PFBlockElement*> > ElementMap;
74  typedef std::unordered_map<const PFGSFElement*,
75  std::vector<PFKFFlaggedElement> > GSFToTrackMap;
76  typedef std::unordered_map<const PFClusterElement*,
77  std::vector<PFClusterFlaggedElement> > ClusterMap;
78  typedef std::unordered_map<const PFKFElement*,
79  float > KFValMap;
80 
81  struct ProtoEGObject {
83  const PFSCElement* parentSC = nullptr; // if ECAL driven
84  reco::ElectronSeedRef electronSeed; // if there is one
85  // this is a mutable list of clusters
86  // if ECAL driven we take the PF SC and refine it
87  // if Tracker driven we add things to it as we discover more valid clusters
88  std::vector<PFClusterFlaggedElement> ecalclusters;
89  ClusterMap ecal2ps;
90  // associations to tracks of various sorts
91  std::vector<PFGSFFlaggedElement> primaryGSFs;
92  GSFToTrackMap boundKFTracks;
93  std::vector<PFKFFlaggedElement> primaryKFs;
94  std::vector<PFBremFlaggedElement> brems; // these are tangent based brems
95  // for manual brem recovery
96  std::vector<PFGSFFlaggedElement> secondaryGSFs;
97  std::vector<PFKFFlaggedElement> secondaryKFs;
99  // for track-HCAL cluster linking
100  std::vector<PFClusterFlaggedElement> hcalClusters;
101  ElementMap localMap;
102  // cluster closest to the gsf track(s), primary kf if none for gsf
103  // last brem tangent cluster if neither of those work
104  std::vector<const PFClusterElement*> electronClusters;
106  };
107 
108  struct PFEGConfigInfo {
109  double mvaEleCut;
110  std::shared_ptr<PFEnergyCalibration> thePFEnergyCalibration;
113  double mvaConvCut;
115  };
116 
117  //constructor
119 
120  void setEEtoPSAssociation(EEtoPSAssociation const& eetops) { eetops_ = &eetops; }
121 
123  cfg_.thePFEnergyCalibration->initAlphaGamma_ESplanes_fromDB(esEEInterCalib);
124  }
125 
126  void setESChannelStatus(const ESChannelStatus* channelStatus){
127  channelStatus_ = channelStatus;
128  }
129 
130  void setPhotonPrimaryVtx(const reco::Vertex& primary){
131  cfg_.primaryVtx = & primary;
132  }
133 
134  //get PFCandidate collection
136 
137  //get the PFCandidateExtra (for all candidates)
139 
140  //get refined SCs
142 
143  // this runs the functions below
145  const reco::PFBlockRef& block);
146 
147 private:
148 
149 
150  // ------ rewritten basic processing pieces and cleaning algorithms
151  // the output collections
155 
156  // useful pre-cached mappings:
157  // hopefully we get an enum that lets us just make an array in the future
161  // keep a map of pf indices to the splayed block for convenience
162  // sadly we're mashing together two ways of thinking about the block
163  std::vector<std::vector<PFFlaggedElement> > _splayedblock;
164 
165  // pre-cleaning for the splayed block
166  bool isMuon(const reco::PFBlockElement&);
167  // pre-processing of ECAL clusters near non-primary KF tracks
169 
170  // candidate collections:
171  // this starts off as an inclusive list of prototype objects built from
172  // supercluster/ecal-driven seeds and tracker driven seeds in a block
173  // it is then refined through by various cleanings, determining the energy
174  // flow.
175  // use list for constant-time removals
176  std::list<ProtoEGObject> _refinableObjects;
177 
178  // functions:
179 
180  // build proto eg object using all available unflagged resources in block.
181  // this will be kind of like the old 'SetLinks' but with simplified and
182  // maximally inclusive logic that builds a list of 'refinable' objects
183  // that we will perform operations on to clean/remove as needed
184  void initializeProtoCands(std::list<ProtoEGObject>&);
185 
186  // turn a supercluster into a map of ECAL cluster elements
187  // related to PS cluster elements
189  std::vector<PFClusterFlaggedElement>&,
190  ClusterMap&);
191 
192  int attachPSClusters(const PFClusterElement*,
193  ClusterMap::mapped_type&);
194 
195 
196  void dumpCurrentRefinableObjects() const;
197 
198  // wax on
199 
200  // the key merging operation, done after building up links
201  void mergeROsByAnyLink(std::list<ProtoEGObject>&);
202 
203  // refining steps you can do with tracks
210  // WARNING! this should be ONLY used after doing the ECAL->track
211  // reverse lookup after the primary linking!
214  // helper function for above
215  void linkKFTrackToECAL(const PFKFFlaggedElement&, ProtoEGObject&);
216 
217  // refining steps doing the ECAL -> track piece
218  // this is the factorization of the old PF photon algo stuff
219  // which through arcane means I came to understand was conversion matching
221  ProtoEGObject&);
222 
223  // wax off
224 
225  // refining steps remove things from the built-up objects
226  // original bits were for removing bad KF tracks
227  // new (experimental) piece to remove clusters associated to these tracks
228  // behavior determined by bools passed to unlink_KFandECALMatchedToHCAL
231  bool removeFreeECAL = false,
232  bool removeSCECAL = false);
233 
234 
235  // things for building the final candidate and refined SC collections
237  const std::list<ProtoEGObject>&,
241 
242  // helper functions for that
243 
245  const ProtoEGObject&,
247  void fillExtraInfo(const ProtoEGObject&,
249 
250  // ------ end of new stuff
251 
252 
253 
254 
255  bool isPrimaryTrack(const reco::PFBlockElementTrack& KfEl,
256  const reco::PFBlockElementGsfTrack& GsfEl);
257 
259 
260  const char *mvaWeightFile_;
261 
263 
265  const reco::PFBlockRef& blockref,
266  const reco::Vertex& primaryVtx,
267  unsigned int trackIndex);
268 };
269 
270 #endif
std::unordered_map< unsigned int, std::vector< unsigned int > > AsscMap
Definition: PFEGammaAlgo.h:71
Abstract base class for a PFBlock element (track, cluster...)
std::vector< PFClusterFlaggedElement > ecalclusters
Definition: PFEGammaAlgo.h:88
const char * mvaWeightFile_
Definition: PFEGammaAlgo.h:260
reco::PFBlockElementSuperCluster PFSCElement
Definition: PFEGammaAlgo.h:60
reco::SuperClusterCollection refinedscs_
Definition: PFEGammaAlgo.h:154
reco::SuperClusterCollection & getRefinedSCs()
Definition: PFEGammaAlgo.h:141
reco::PFBlockRef parentBlock
Definition: PFEGammaAlgo.h:82
void unlinkRefinableObjectKFandECALWithBadEoverP(ProtoEGObject &)
std::unordered_map< const PFKFElement *, float > KFValMap
Definition: PFEGammaAlgo.h:79
std::pair< const PFClusterElement *, bool > PFClusterFlaggedElement
Definition: PFEGammaAlgo.h:70
std::vector< std::pair< const reco::PFBlockElement *, const reco::PFBlockElement * > > ElementMap
Definition: PFEGammaAlgo.h:73
std::shared_ptr< PFEnergyCalibration > thePFEnergyCalibration
Definition: PFEGammaAlgo.h:110
std::map< unsigned int, Link > LinkData
Definition: PFBlock.h:46
std::vector< PFClusterFlaggedElement > hcalClusters
Definition: PFEGammaAlgo.h:100
reco::PFBlockElementGsfTrack PFGSFElement
Definition: PFEGammaAlgo.h:62
bool isPrimaryTrack(const reco::PFBlockElementTrack &KfEl, const reco::PFBlockElementGsfTrack &GsfEl)
void setPhotonPrimaryVtx(const reco::Vertex &primary)
Definition: PFEGammaAlgo.h:130
void linkRefinableObjectPrimaryGSFTrackToECAL(ProtoEGObject &)
void linkRefinableObjectECALToSingleLegConv(const pfEGHelpers::HeavyObjectCache *hoc, ProtoEGObject &)
std::vector< const PFClusterElement * > electronClusters
Definition: PFEGammaAlgo.h:104
std::vector< std::vector< PFFlaggedElement > > _splayedblock
Definition: PFEGammaAlgo.h:163
std::pair< const PFGSFElement *, bool > PFGSFFlaggedElement
Definition: PFEGammaAlgo.h:68
void linkRefinableObjectBremTangentsToECAL(ProtoEGObject &)
const reco::Vertex * primaryVtx
Definition: PFEGammaAlgo.h:114
void setEEtoPSAssociation(EEtoPSAssociation const &eetops)
Definition: PFEGammaAlgo.h:120
reco::PFBlockRef _currentblock
Definition: PFEGammaAlgo.h:159
std::pair< const reco::PFBlockElement *, bool > PFFlaggedElement
Definition: PFEGammaAlgo.h:65
std::pair< const PFSCElement *, bool > PFSCFlaggedElement
Definition: PFEGammaAlgo.h:66
PFEGConfigInfo cfg_
Definition: PFEGammaAlgo.h:258
void setAlphaGamma_ESplanes_fromDB(const ESEEIntercalibConstants *esEEInterCalib)
Definition: PFEGammaAlgo.h:122
std::vector< PFKFFlaggedElement > secondaryKFs
Definition: PFEGammaAlgo.h:97
void dumpCurrentRefinableObjects() const
void initializeProtoCands(std::list< ProtoEGObject > &)
void linkRefinableObjectPrimaryKFsToSecondaryKFs(ProtoEGObject &)
bool unwrapSuperCluster(const reco::PFBlockElementSuperCluster *, std::vector< PFClusterFlaggedElement > &, ClusterMap &)
reco::PFCandidateEGammaExtraCollection & getEGExtra()
Definition: PFEGammaAlgo.h:138
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
std::vector< PFGSFFlaggedElement > secondaryGSFs
Definition: PFEGammaAlgo.h:96
reco::PFCluster::EEtoPSAssociation EEtoPSAssociation
Definition: PFEGammaAlgo.h:59
PFEGammaAlgo(const PFEGConfigInfo &)
const PFSCElement * parentSC
Definition: PFEGammaAlgo.h:83
std::vector< reco::PFCandidateEGammaExtra > PFCandidateEGammaExtraCollection
collection of PFCandidateEGammaExtras
std::vector< PFBremFlaggedElement > brems
Definition: PFEGammaAlgo.h:94
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:75
std::list< ProtoEGObject > _refinableObjects
Definition: PFEGammaAlgo.h:176
reco::PFBlockElementCluster PFClusterElement
Definition: PFEGammaAlgo.h:64
reco::PFBlockElementBrem PFBremElement
Definition: PFEGammaAlgo.h:61
reco::PFCandidateEGammaExtraCollection outcandsextra_
Definition: PFEGammaAlgo.h:153
void linkKFTrackToECAL(const PFKFFlaggedElement &, ProtoEGObject &)
reco::PFCandidateCollection & getCandidates()
Definition: PFEGammaAlgo.h:135
reco::PFBlock::LinkData _currentlinks
Definition: PFEGammaAlgo.h:160
void buildAndRefineEGObjects(const pfEGHelpers::HeavyObjectCache *hoc, const reco::PFBlockRef &block)
reco::PFCluster::EEtoPSAssociation const * eetops_
Definition: PFEGammaAlgo.h:158
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
bool isMuon(const reco::PFBlockElement &)
void fillExtraInfo(const ProtoEGObject &, reco::PFCandidateEGammaExtra &)
float calculateEleMVA(const pfEGHelpers::HeavyObjectCache *hoc, const ProtoEGObject &, reco::PFCandidateEGammaExtra &) const
reco::ElectronSeedRef electronSeed
Definition: PFEGammaAlgo.h:84
float evaluateSingleLegMVA(const pfEGHelpers::HeavyObjectCache *hoc, const reco::PFBlockRef &blockref, const reco::Vertex &primaryVtx, unsigned int trackIndex)
reco::PFBlockElementTrack PFKFElement
Definition: PFEGammaAlgo.h:63
void linkRefinableObjectGSFTracksToKFs(ProtoEGObject &)
std::vector< PFKFFlaggedElement > primaryKFs
Definition: PFEGammaAlgo.h:93
std::unordered_map< const PFClusterElement *, std::vector< PFClusterFlaggedElement > > ClusterMap
Definition: PFEGammaAlgo.h:77
void fillPFCandidates(const pfEGHelpers::HeavyObjectCache *hoc, const std::list< ProtoEGObject > &, reco::PFCandidateCollection &, reco::PFCandidateEGammaExtraCollection &)
void removeOrLinkECALClustersToKFTracks()
reco::SuperCluster buildRefinedSuperCluster(const ProtoEGObject &)
void unlinkRefinableObjectKFandECALMatchedToHCAL(ProtoEGObject &, bool removeFreeECAL=false, bool removeSCECAL=false)
std::pair< const PFKFElement *, bool > PFKFFlaggedElement
Definition: PFEGammaAlgo.h:69
void mergeROsByAnyLink(std::list< ProtoEGObject > &)
int attachPSClusters(const PFClusterElement *, ClusterMap::mapped_type &)
void linkRefinableObjectKFTracksToECAL(ProtoEGObject &)
void linkRefinableObjectSecondaryKFsToECAL(ProtoEGObject &)
void linkRefinableObjectConvSecondaryKFsToSecondaryKFs(ProtoEGObject &)
reco::PFCandidateCollection outcands_
Definition: PFEGammaAlgo.h:152
std::vector< PFGSFFlaggedElement > primaryGSFs
Definition: PFEGammaAlgo.h:91
std::pair< const PFBremElement *, bool > PFBremFlaggedElement
Definition: PFEGammaAlgo.h:67
const ESChannelStatus * channelStatus_
Definition: PFEGammaAlgo.h:262
void setESChannelStatus(const ESChannelStatus *channelStatus)
Definition: PFEGammaAlgo.h:126
void linkRefinableObjectPrimaryGSFTrackToHCAL(ProtoEGObject &)