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