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 
54 
57 
58 #include <memory>
59 
61 
62 class PFEGammaAlgo {
63 public:
70  typedef std::unordered_map<const PFKFElement*, float> KFValMap;
71 
72  using ClusterMap = std::unordered_map<PFClusterElement const*, std::vector<PFClusterElement const*>>;
73 
74  class GBRForests {
75  public:
77  : ele_(createGBRForest(conf.getParameter<edm::FileInPath>("pf_electronID_mvaWeightFile"))),
78  singleLeg_(createGBRForest(conf.getParameter<edm::FileInPath>("pf_convID_mvaWeightFile"))) {}
79 
80  const std::unique_ptr<const GBRForest> ele_;
81  const std::unique_ptr<const GBRForest> singleLeg_;
82  };
83 
84  struct ProtoEGObject {
86  const PFSCElement* parentSC = nullptr; // if ECAL driven
87  reco::ElectronSeedRef electronSeed; // if there is one
88  // this is a mutable list of clusters
89  // if ECAL driven we take the PF SC and refine it
90  // if Tracker driven we add things to it as we discover more valid clusters
91  std::vector<FlaggedPtr<const PFClusterElement>> ecalclusters;
93  // associations to tracks of various sorts
94  std::vector<PFGSFElement const*> primaryGSFs;
95  std::vector<PFKFElement const*> primaryKFs;
96  std::vector<PFBremElement const*> brems; // these are tangent based brems
97  // for manual brem recovery
98  std::vector<PFGSFElement const*> secondaryGSFs;
99  std::vector<PFKFElement const*> secondaryKFs;
101  // for track-HCAL cluster linking
102  std::vector<PFClusterElement const*> hcalClusters;
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;
114  double mvaConvCut;
115  };
116 
117  struct EgammaObjects {
121  };
122 
123  //constructor
125  GBRForests const& gbrForests,
126  EEtoPSAssociation const& eetops,
127  ESEEIntercalibConstants const& esEEInterCalib,
128  ESChannelStatus const& channelStatus,
129  reco::Vertex const& primaryVertex);
130 
131  // this runs the functions below
133 
134 private:
136 
138 
139  // ------ rewritten basic processing pieces and cleaning algorithms
140 
141  // useful pre-cached mappings:
142  // hopefully we get an enum that lets us just make an array in the future
146  // keep a map of pf indices to the splayed block for convenience
147  // sadly we're mashing together two ways of thinking about the block
148  std::vector<std::vector<FlaggedPtr<const reco::PFBlockElement>>> _splayedblock;
149 
150  // pre-cleaning for the splayed block
151  bool isMuon(const reco::PFBlockElement&);
152  // pre-processing of ECAL clusters near non-primary KF tracks
154 
155  // functions:
156 
157  // build proto eg object using all available unflagged resources in block.
158  // this will be kind of like the old 'SetLinks' but with simplified and
159  // maximally inclusive logic that builds a list of 'refinable' objects
160  // that we will perform operations on to clean/remove as needed
161  void initializeProtoCands(std::list<ProtoEGObject>&);
162 
163  // turn a supercluster into a map of ECAL cluster elements
164  // related to PS cluster elements
167  ClusterMap&);
168 
169  int attachPSClusters(const PFClusterElement*, ClusterMap::mapped_type&);
170 
171  void dumpCurrentRefinableObjects() const;
172 
173  // wax on
174 
175  // the key merging operation, done after building up links
176  void mergeROsByAnyLink(std::list<ProtoEGObject>&);
177 
178  // refining steps you can do with tracks
185  // WARNING! this should be ONLY used after doing the ECAL->track
186  // reverse lookup after the primary linking!
189  // helper function for above
191 
192  // refining steps doing the ECAL -> track piece
193  // this is the factorization of the old PF photon algo stuff
194  // which through arcane means I came to understand was conversion matching
196 
197  // wax off
198 
199  // refining steps remove things from the built-up objects
200  // original bits were for removing bad KF tracks
201  // new (experimental) piece to remove clusters associated to these tracks
202  // behavior determined by bools passed to unlink_KFandECALMatchedToHCAL
205  bool removeFreeECAL = false,
206  bool removeSCECAL = false);
207 
208  // things for building the final candidate and refined SC collections
209  EgammaObjects fillPFCandidates(const std::list<ProtoEGObject>&);
211 
212  // helper functions for that
213 
216 
217  // ------ end of new stuff
218 
220 
223 
225 
226  float evaluateSingleLegMVA(const reco::PFBlockRef& blockref, const reco::Vertex& primaryVtx, unsigned int trackIndex);
227 };
228 
229 #endif
reco::PFCluster::EEtoPSAssociation const & eetops_
Definition: PFEGammaAlgo.h:143
std::vector< PFGSFElement const * > primaryGSFs
Definition: PFEGammaAlgo.h:94
Abstract base class for a PFBlock element (track, cluster...)
float evaluateSingleLegMVA(const reco::PFBlockRef &blockref, const reco::Vertex &primaryVtx, unsigned int trackIndex)
reco::PFCandidateEGammaExtraCollection candidateExtras
Definition: PFEGammaAlgo.h:119
GBRForests const & gbrForests_
Definition: PFEGammaAlgo.h:135
reco::PFBlockElementSuperCluster PFSCElement
Definition: PFEGammaAlgo.h:65
PFEGammaAlgo(const PFEGConfigInfo &, GBRForests const &gbrForests, EEtoPSAssociation const &eetops, ESEEIntercalibConstants const &esEEInterCalib, ESChannelStatus const &channelStatus, reco::Vertex const &primaryVertex)
bool unwrapSuperCluster(const reco::PFBlockElementSuperCluster *, std::vector< FlaggedPtr< const PFClusterElement >> &, ClusterMap &)
std::vector< PFGSFElement const * > secondaryGSFs
Definition: PFEGammaAlgo.h:98
reco::PFBlockRef parentBlock
Definition: PFEGammaAlgo.h:85
void unlinkRefinableObjectKFandECALWithBadEoverP(ProtoEGObject &)
void dumpCurrentRefinableObjects() const
float calculateEleMVA(const ProtoEGObject &, reco::PFCandidateEGammaExtra &) const
reco::PFBlockElementGsfTrack PFGSFElement
Definition: PFEGammaAlgo.h:67
reco::Vertex const & primaryVertex_
Definition: PFEGammaAlgo.h:222
bool isPrimaryTrack(const reco::PFBlockElementTrack &KfEl, const reco::PFBlockElementGsfTrack &GsfEl)
void linkRefinableObjectPrimaryGSFTrackToECAL(ProtoEGObject &)
reco::SuperClusterCollection refinedSuperClusters
Definition: PFEGammaAlgo.h:120
std::map< unsigned int, Link > LinkData
Definition: PFBlock.h:39
std::vector< const PFClusterElement * > electronClusters
Definition: PFEGammaAlgo.h:106
void linkRefinableObjectBremTangentsToECAL(ProtoEGObject &)
reco::PFBlockRef _currentblock
Definition: PFEGammaAlgo.h:144
PFEGConfigInfo const & cfg_
Definition: PFEGammaAlgo.h:221
const std::unique_ptr< const GBRForest > singleLeg_
Definition: PFEGammaAlgo.h:81
void linkRefinableObjectECALToSingleLegConv(ProtoEGObject &)
std::vector< PFKFElement const * > primaryKFs
Definition: PFEGammaAlgo.h:95
void initializeProtoCands(std::list< ProtoEGObject > &)
void linkRefinableObjectPrimaryKFsToSecondaryKFs(ProtoEGObject &)
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
std::vector< PFKFElement const * > secondaryKFs
Definition: PFEGammaAlgo.h:99
reco::PFCluster::EEtoPSAssociation EEtoPSAssociation
Definition: PFEGammaAlgo.h:64
const PFSCElement * parentSC
Definition: PFEGammaAlgo.h:86
std::vector< FlaggedPtr< const PFClusterElement > > ecalclusters
Definition: PFEGammaAlgo.h:91
std::vector< reco::PFCandidateEGammaExtra > PFCandidateEGammaExtraCollection
collection of PFCandidateEGammaExtras
std::vector< PFBremElement const * > brems
Definition: PFEGammaAlgo.h:96
reco::PFBlockElementCluster PFClusterElement
Definition: PFEGammaAlgo.h:69
void linkKFTrackToECAL(PFKFElement const *, ProtoEGObject &)
reco::PFBlockElementBrem PFBremElement
Definition: PFEGammaAlgo.h:66
std::unordered_map< const PFKFElement *, float > KFValMap
Definition: PFEGammaAlgo.h:70
GBRForests(const edm::ParameterSet &conf)
Definition: PFEGammaAlgo.h:76
CommutativePairs< const reco::PFBlockElement * > localMap
Definition: PFEGammaAlgo.h:103
std::unordered_map< PFClusterElement const *, std::vector< PFClusterElement const * > > ClusterMap
Definition: PFEGammaAlgo.h:72
reco::PFBlock::LinkData _currentlinks
Definition: PFEGammaAlgo.h:145
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
bool isMuon(const reco::PFBlockElement &)
void fillExtraInfo(const ProtoEGObject &, reco::PFCandidateEGammaExtra &)
std::vector< std::pair< CaloClusterPtr::key_type, edm::Ptr< PFCluster > > > EEtoPSAssociation
Definition: PFCluster.h:44
reco::ElectronSeedRef electronSeed
Definition: PFEGammaAlgo.h:87
EgammaObjects operator()(const reco::PFBlockRef &block)
reco::PFBlockElementTrack PFKFElement
Definition: PFEGammaAlgo.h:68
reco::PFCandidateCollection candidates
Definition: PFEGammaAlgo.h:118
void linkRefinableObjectGSFTracksToKFs(ProtoEGObject &)
void removeOrLinkECALClustersToKFTracks()
HLT enums.
reco::SuperCluster buildRefinedSuperCluster(const ProtoEGObject &)
EgammaObjects fillPFCandidates(const std::list< ProtoEGObject > &)
void unlinkRefinableObjectKFandECALMatchedToHCAL(ProtoEGObject &, bool removeFreeECAL=false, bool removeSCECAL=false)
std::vector< PFClusterElement const * > hcalClusters
Definition: PFEGammaAlgo.h:102
void mergeROsByAnyLink(std::list< ProtoEGObject > &)
std::vector< std::vector< FlaggedPtr< const reco::PFBlockElement > > > _splayedblock
Definition: PFEGammaAlgo.h:148
PFEnergyCalibration thePFEnergyCalibration_
Definition: PFEGammaAlgo.h:137
int attachPSClusters(const PFClusterElement *, ClusterMap::mapped_type &)
void linkRefinableObjectKFTracksToECAL(ProtoEGObject &)
const std::unique_ptr< const GBRForest > ele_
Definition: PFEGammaAlgo.h:80
void linkRefinableObjectSecondaryKFsToECAL(ProtoEGObject &)
void linkRefinableObjectConvSecondaryKFsToSecondaryKFs(ProtoEGObject &)
primaryVertex
hltOfflineBeamSpot for HLTMON
std::unique_ptr< const GBRForest > createGBRForest(const std::string &weightsFile)
ESChannelStatus const & channelStatus_
Definition: PFEGammaAlgo.h:224
void linkRefinableObjectPrimaryGSFTrackToHCAL(ProtoEGObject &)