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
PFEGammaAlgo::linkRefinableObjectPrimaryGSFTrackToECAL
void linkRefinableObjectPrimaryGSFTrackToECAL(ProtoEGObject &)
Definition: PFEGammaAlgo.cc:1222
PFEGammaAlgo::mergeROsByAnyLink
void mergeROsByAnyLink(std::list< ProtoEGObject > &)
Definition: PFEGammaAlgo.cc:1079
Handle.h
PFEGammaAlgo::_splayedblock
std::vector< std::vector< FlaggedPtr< const reco::PFBlockElement > > > _splayedblock
Definition: PFEGammaAlgo.h:148
PFEGammaAlgo::PFGSFElement
reco::PFBlockElementGsfTrack PFGSFElement
Definition: PFEGammaAlgo.h:67
PFEGammaAlgo::ProtoEGObject::ecal2ps
ClusterMap ecal2ps
Definition: PFEGammaAlgo.h:92
PFEGammaAlgo::linkRefinableObjectConvSecondaryKFsToSecondaryKFs
void linkRefinableObjectConvSecondaryKFsToSecondaryKFs(ProtoEGObject &)
Definition: PFEGammaAlgo.cc:1397
PFEGammaAlgo::ProtoEGObject::parentSC
const PFSCElement * parentSC
Definition: PFEGammaAlgo.h:86
GsfTrackExtra.h
PFEGammaAlgo::ProtoEGObject::electronSeed
reco::ElectronSeedRef electronSeed
Definition: PFEGammaAlgo.h:87
PFBlockElementCluster.h
PFCandidate.h
PFEGammaAlgo::EgammaObjects
Definition: PFEGammaAlgo.h:117
PFEGammaAlgo::cfg_
PFEGConfigInfo const & cfg_
Definition: PFEGammaAlgo.h:221
reco::SuperCluster
Definition: SuperCluster.h:18
PFEGammaAlgo::ProtoEGObject::brems
std::vector< PFBremElement const * > brems
Definition: PFEGammaAlgo.h:96
PFEGammaAlgo::channelStatus_
ESChannelStatus const & channelStatus_
Definition: PFEGammaAlgo.h:224
FlaggedPtr.h
edm
HLT enums.
Definition: AlignableModifier.h:19
GBRForestTools.h
reco::PFBlockElementSuperCluster
Cluster Element.
Definition: PFBlockElementSuperCluster.h:15
PFEGammaAlgo::linkRefinableObjectECALToSingleLegConv
void linkRefinableObjectECALToSingleLegConv(ProtoEGObject &)
Definition: PFEGammaAlgo.cc:1420
PFEGammaAlgo::ProtoEGObject::electronClusters
std::vector< const PFClusterElement * > electronClusters
Definition: PFEGammaAlgo.h:106
PFEGammaAlgo::EgammaObjects::candidates
reco::PFCandidateCollection candidates
Definition: PFEGammaAlgo.h:118
PFEGammaAlgo::PFEGConfigInfo::applyCrackCorrections
bool applyCrackCorrections
Definition: PFEGammaAlgo.h:112
PFEGammaAlgo::PFEGConfigInfo::mvaEleCut
double mvaEleCut
Definition: PFEGammaAlgo.h:111
PFEGammaAlgo::ProtoEGObject::secondaryGSFs
std::vector< PFGSFElement const * > secondaryGSFs
Definition: PFEGammaAlgo.h:98
PFEGammaAlgo::ProtoEGObject::nBremsWithClusters
int nBremsWithClusters
Definition: PFEGammaAlgo.h:107
PFEGammaAlgo::gbrForests_
GBRForests const & gbrForests_
Definition: PFEGammaAlgo.h:135
createGBRForest
std::unique_ptr< const GBRForest > createGBRForest(const std::string &weightsFile)
Definition: GBRForestTools.cc:244
PFEGammaAlgo::ProtoEGObject::ecalclusters
std::vector< FlaggedPtr< const PFClusterElement > > ecalclusters
Definition: PFEGammaAlgo.h:91
PFEGammaAlgo::ProtoEGObject::localMap
CommutativePairs< const reco::PFBlockElement * > localMap
Definition: PFEGammaAlgo.h:103
PFEGammaAlgo::evaluateSingleLegMVA
float evaluateSingleLegMVA(const reco::PFBlockRef &blockref, const reco::Vertex &primaryVtx, unsigned int trackIndex)
Definition: PFEGammaAlgo.cc:459
GBRForest.h
PFBlockElementBrem.h
reco::PFCandidateEGammaExtra
Definition: PFCandidateEGammaExtra.h:25
reco::PFCandidateEGammaExtraCollection
std::vector< reco::PFCandidateEGammaExtra > PFCandidateEGammaExtraCollection
collection of PFCandidateEGammaExtras
Definition: PFCandidateEGammaExtraFwd.h:12
edm::Ref< PFBlockCollection >
PFEGammaAlgo::unlinkRefinableObjectKFandECALWithBadEoverP
void unlinkRefinableObjectKFandECALWithBadEoverP(ProtoEGObject &)
Definition: PFEGammaAlgo.cc:1893
CommutativePairs< const reco::PFBlockElement * >
PFCandidatePhotonExtraFwd.h
BeamMonitor_cff.primaryVertex
primaryVertex
hltOfflineBeamSpot for HLTMON
Definition: BeamMonitor_cff.py:7
reco::SuperClusterCollection
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
Definition: SuperClusterFwd.h:9
PFEGammaAlgo::ProtoEGObject::primaryGSFs
std::vector< PFGSFElement const * > primaryGSFs
Definition: PFEGammaAlgo.h:94
PFEnergyCalibration.h
PFEGammaAlgo::PFBremElement
reco::PFBlockElementBrem PFBremElement
Definition: PFEGammaAlgo.h:66
PFEGammaAlgo::primaryVertex_
reco::Vertex const & primaryVertex_
Definition: PFEGammaAlgo.h:222
PFEGammaAlgo::isPrimaryTrack
bool isPrimaryTrack(const reco::PFBlockElementTrack &KfEl, const reco::PFBlockElementGsfTrack &GsfEl)
Definition: PFEGammaAlgo.cc:2038
PFCandidatePhotonExtra.h
PFEnergyCalibration
Definition: PFEnergyCalibration.h:42
PFEGammaAlgo::calculateEleMVA
float calculateEleMVA(const ProtoEGObject &, reco::PFCandidateEGammaExtra &) const
Definition: PFEGammaAlgo.cc:1603
OrphanHandle.h
PFEGammaAlgo::PFClusterElement
reco::PFBlockElementCluster PFClusterElement
Definition: PFEGammaAlgo.h:69
PFCandidateElectronExtraFwd.h
PFEGammaAlgo::GBRForests::ele_
const std::unique_ptr< const GBRForest > ele_
Definition: PFEGammaAlgo.h:80
PFEGammaAlgo::ClusterMap
std::unordered_map< PFClusterElement const *, std::vector< PFClusterElement const * > > ClusterMap
Definition: PFEGammaAlgo.h:72
PFEGammaAlgo::KFValMap
std::unordered_map< const PFKFElement *, float > KFValMap
Definition: PFEGammaAlgo.h:70
PFCluster.h
PFEGammaAlgo::GBRForests::GBRForests
GBRForests(const edm::ParameterSet &conf)
Definition: PFEGammaAlgo.h:76
CaloClusterFwd.h
PFEGammaAlgo::_currentblock
reco::PFBlockRef _currentblock
Definition: PFEGammaAlgo.h:144
reco::PFBlockElementBrem
Track Element.
Definition: PFBlockElementBrem.h:17
PFEGammaAlgo::fillExtraInfo
void fillExtraInfo(const ProtoEGObject &, reco::PFCandidateEGammaExtra &)
Definition: PFEGammaAlgo.cc:1767
GsfElectron.h
PFEGammaAlgo::linkRefinableObjectBremTangentsToECAL
void linkRefinableObjectBremTangentsToECAL(ProtoEGObject &)
Definition: PFEGammaAlgo.cc:1332
PFEGammaAlgo::EgammaObjects::candidateExtras
reco::PFCandidateEGammaExtraCollection candidateExtras
Definition: PFEGammaAlgo.h:119
Vertex.h
PFEGammaAlgo::ProtoEGObject::hcalClusters
std::vector< PFClusterElement const * > hcalClusters
Definition: PFEGammaAlgo.h:102
PFEGammaAlgo::linkRefinableObjectGSFTracksToKFs
void linkRefinableObjectGSFTracksToKFs(ProtoEGObject &)
Definition: PFEGammaAlgo.cc:1159
GsfElectronFwd.h
PFEGammaAlgo::ProtoEGObject::singleLegConversionMvaMap
KFValMap singleLegConversionMvaMap
Definition: PFEGammaAlgo.h:100
edm::ParameterSet
Definition: ParameterSet.h:47
PFEGammaAlgo::PFEGConfigInfo
Definition: PFEGammaAlgo.h:110
PFEGammaAlgo::PFKFElement
reco::PFBlockElementTrack PFKFElement
Definition: PFEGammaAlgo.h:68
PFEGammaAlgo::initializeProtoCands
void initializeProtoCands(std::list< ProtoEGObject > &)
Definition: PFEGammaAlgo.cc:655
PFEGammaAlgo::linkRefinableObjectPrimaryKFsToSecondaryKFs
void linkRefinableObjectPrimaryKFsToSecondaryKFs(ProtoEGObject &)
Definition: PFEGammaAlgo.cc:1191
FlaggedPtr
Definition: FlaggedPtr.h:5
ESChannelStatus.h
PFBlockElementSuperCluster.h
PFEGammaAlgo::GBRForests::singleLeg_
const std::unique_ptr< const GBRForest > singleLeg_
Definition: PFEGammaAlgo.h:81
PFEGammaAlgo::removeOrLinkECALClustersToKFTracks
void removeOrLinkECALClustersToKFTracks()
Definition: PFEGammaAlgo.cc:1000
GsfTrack.h
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
PFEGammaAlgo::attachPSClusters
int attachPSClusters(const PFClusterElement *, ClusterMap::mapped_type &)
Definition: PFEGammaAlgo.cc:901
groupFilesInBlocks.block
block
Definition: groupFilesInBlocks.py:150
PFEGammaAlgo::linkRefinableObjectKFTracksToECAL
void linkRefinableObjectKFTracksToECAL(ProtoEGObject &)
Definition: PFEGammaAlgo.cc:1286
PFEGammaAlgo::EEtoPSAssociation
reco::PFCluster::EEtoPSAssociation EEtoPSAssociation
Definition: PFEGammaAlgo.h:64
ESEEIntercalibConstants.h
PFEGammaAlgo::linkRefinableObjectSecondaryKFsToECAL
void linkRefinableObjectSecondaryKFsToECAL(ProtoEGObject &)
Definition: PFEGammaAlgo.cc:1450
reco::PFBlock::LinkData
std::map< unsigned int, Link > LinkData
Definition: PFBlock.h:39
ESCondObjectContainer
Definition: ESCondObjectContainer.h:11
PFEGammaAlgo::GBRForests
Definition: PFEGammaAlgo.h:74
PFCandidateEGammaExtraFwd.h
reco::PFBlockElement
Abstract base class for a PFBlock element (track, cluster...)
Definition: PFBlockElement.h:26
PFBlockFwd.h
PFBlock.h
reco::PFCluster::EEtoPSAssociation
std::vector< std::pair< CaloClusterPtr::key_type, edm::Ptr< PFCluster > > > EEtoPSAssociation
Definition: PFCluster.h:44
PFEGammaAlgo::ProtoEGObject::primaryKFs
std::vector< PFKFElement const * > primaryKFs
Definition: PFEGammaAlgo.h:95
reco::PFBlockElementGsfTrack
Track Element.
Definition: PFBlockElementGsfTrack.h:18
PFEGammaAlgo::EgammaObjects::refinedSuperClusters
reco::SuperClusterCollection refinedSuperClusters
Definition: PFEGammaAlgo.h:120
CommutativePairs.h
PFEGammaAlgo::linkKFTrackToECAL
void linkKFTrackToECAL(PFKFElement const *, ProtoEGObject &)
Definition: PFEGammaAlgo.cc:1295
PFEGammaAlgo::ProtoEGObject::lateBrem
int lateBrem
Definition: PFEGammaAlgo.h:107
PFEGammaAlgo::linkRefinableObjectPrimaryGSFTrackToHCAL
void linkRefinableObjectPrimaryGSFTrackToHCAL(ProtoEGObject &)
Definition: PFEGammaAlgo.cc:1265
PFEGammaAlgo::ProtoEGObject::secondaryKFs
std::vector< PFKFElement const * > secondaryKFs
Definition: PFEGammaAlgo.h:99
PFCandidateEGammaExtra.h
reco::PFBlockElementCluster
Cluster Element.
Definition: PFBlockElementCluster.h:16
PFEGammaAlgo::_currentlinks
reco::PFBlock::LinkData _currentlinks
Definition: PFEGammaAlgo.h:145
reco::PFCandidateCollection
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
Definition: PFCandidateFwd.h:12
reco::PFBlockElementTrack
Track Element.
Definition: PFBlockElementTrack.h:17
PFEGammaAlgo::ProtoEGObject::firstBrem
int firstBrem
Definition: PFEGammaAlgo.h:107
PFEGammaAlgo::isMuon
bool isMuon(const reco::PFBlockElement &)
Definition: PFEGammaAlgo.cc:505
PFEGammaAlgo::PFEGConfigInfo::mvaConvCut
double mvaConvCut
Definition: PFEGammaAlgo.h:114
PFEGammaAlgo::ProtoEGObject::parentBlock
reco::PFBlockRef parentBlock
Definition: PFEGammaAlgo.h:85
PFEGammaAlgo::eetops_
reco::PFCluster::EEtoPSAssociation const & eetops_
Definition: PFEGammaAlgo.h:143
PFEGammaAlgo::PFSCElement
reco::PFBlockElementSuperCluster PFSCElement
Definition: PFEGammaAlgo.h:65
PFEGammaAlgo
Definition: PFEGammaAlgo.h:62
ESEEIntercalibConstants
Definition: ESEEIntercalibConstants.h:7
PFEGammaAlgo::unwrapSuperCluster
bool unwrapSuperCluster(const reco::PFBlockElementSuperCluster *, std::vector< FlaggedPtr< const PFClusterElement >> &, ClusterMap &)
Definition: PFEGammaAlgo.cc:776
ParameterSet.h
PFEGammaAlgo::operator()
EgammaObjects operator()(const reco::PFBlockRef &block)
Definition: PFEGammaAlgo.cc:527
PFEGammaAlgo::PFEGammaAlgo
PFEGammaAlgo(const PFEGConfigInfo &, GBRForests const &gbrForests, EEtoPSAssociation const &eetops, ESEEIntercalibConstants const &esEEInterCalib, ESChannelStatus const &channelStatus, reco::Vertex const &primaryVertex)
Definition: PFEGammaAlgo.cc:445
PFEGammaAlgo::dumpCurrentRefinableObjects
void dumpCurrentRefinableObjects() const
Definition: PFEGammaAlgo.cc:931
PFEGammaAlgo::ProtoEGObject
Definition: PFEGammaAlgo.h:84
PFBlockElementGsfTrack.h
PFBlockElementTrack.h
PFEGammaAlgo::buildRefinedSuperCluster
reco::SuperCluster buildRefinedSuperCluster(const ProtoEGObject &)
Definition: PFEGammaAlgo.cc:1788
PFEGammaAlgo::fillPFCandidates
EgammaObjects fillPFCandidates(const std::list< ProtoEGObject > &)
Definition: PFEGammaAlgo.cc:1468
PFEGammaAlgo::unlinkRefinableObjectKFandECALMatchedToHCAL
void unlinkRefinableObjectKFandECALMatchedToHCAL(ProtoEGObject &, bool removeFreeECAL=false, bool removeSCECAL=false)
Definition: PFEGammaAlgo.cc:1966
reco::Vertex
Definition: Vertex.h:35
PFEGammaAlgo::PFEGConfigInfo::produceEGCandsWithNoSuperCluster
bool produceEGCandsWithNoSuperCluster
Definition: PFEGammaAlgo.h:113
PFCandidateElectronExtra.h
PFCandidateFwd.h
ElectronSeed.h
CaloCluster.h
PFEGammaAlgo::thePFEnergyCalibration_
PFEnergyCalibration thePFEnergyCalibration_
Definition: PFEGammaAlgo.h:137