CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
PFCand_AssoMapAlgos Class Reference

#include <PFCand_AssoMapAlgos.h>

Inheritance diagram for PFCand_AssoMapAlgos:
PF_PU_AssoMapAlgos PFCand_AssoMap

Public Member Functions

std::pair< std::unique_ptr< PFCandToVertexAssMap >, std::unique_ptr< VertexToPFCandAssMap > > createMappings (edm::Handle< reco::PFCandidateCollection > pfCandH, const edm::EventSetup &iSetup)
 
std::unique_ptr< PFCandToVertexAssMapCreatePFCandToVertexMap (edm::Handle< reco::PFCandidateCollection >, const edm::EventSetup &)
 
std::unique_ptr< VertexToPFCandAssMapCreateVertexToPFCandMap (edm::Handle< reco::PFCandidateCollection >, const edm::EventSetup &)
 
void GetInputCollections (edm::Event &, const edm::EventSetup &) override
 
 PFCand_AssoMapAlgos (const edm::ParameterSet &, edm::ConsumesCollector &&)
 
std::unique_ptr< PFCandToVertexAssMapSortPFCandAssociationMap (PFCandToVertexAssMap *, edm::EDProductGetter const *getter)
 
- Public Member Functions inherited from PF_PU_AssoMapAlgos
std::pair< std::unique_ptr< TrackToVertexAssMap >, std::unique_ptr< VertexToTrackAssMap > > createMappings (edm::Handle< reco::TrackCollection > trkcollH, const edm::EventSetup &iSetup)
 
std::unique_ptr< TrackToVertexAssMapCreateTrackToVertexMap (edm::Handle< reco::TrackCollection >, const edm::EventSetup &)
 
std::unique_ptr< VertexToTrackAssMapCreateVertexToTrackMap (edm::Handle< reco::TrackCollection >, const edm::EventSetup &)
 
 PF_PU_AssoMapAlgos (const edm::ParameterSet &, edm::ConsumesCollector &)
 
 PF_PU_AssoMapAlgos (const edm::ParameterSet &iConfig, edm::ConsumesCollector &&iC)
 
std::unique_ptr< TrackToVertexAssMapSortAssociationMap (TrackToVertexAssMap *, edm::Handle< reco::TrackCollection >)
 
virtual ~PF_PU_AssoMapAlgos () noexcept(false)
 

Private Attributes

edm::Handle< reco::BeamSpotbeamspotH
 
edm::ESHandle< MagneticFieldbFieldH
 
int input_MaxNumAssociations_
 
edm::EDGetTokenT< reco::BeamSpottoken_BeamSpot_
 
edm::EDGetTokenT< reco::VertexCollectiontoken_VertexCollection_
 
edm::Handle< reco::VertexCollectionvtxcollH
 

Additional Inherited Members

- Protected Member Functions inherited from PF_PU_AssoMapAlgos
std::vector< reco::VertexRefCreateVertexVector (edm::Handle< reco::VertexCollection >)
 
int DefineQuality (int, int, double)
 
void EraseVertex (std::vector< reco::VertexRef > &, reco::VertexRef)
 
VertexStepPair FindAssociation (const reco::TrackRef &, const std::vector< reco::VertexRef > &, edm::ESHandle< MagneticField >, const edm::EventSetup &, edm::Handle< reco::BeamSpot >, int)
 

Detailed Description

Definition at line 41 of file PFCand_AssoMapAlgos.h.

Constructor & Destructor Documentation

◆ PFCand_AssoMapAlgos()

PFCand_AssoMapAlgos::PFCand_AssoMapAlgos ( const edm::ParameterSet iConfig,
edm::ConsumesCollector &&  iC 
)

Definition at line 14 of file PFCand_AssoMapAlgos.cc.

15  : PF_PU_AssoMapAlgos(iConfig, iC) {
16  input_MaxNumAssociations_ = iConfig.getParameter<int>("MaxNumberOfAssociations");
17 
18  token_VertexCollection_ = iC.consumes<VertexCollection>(iConfig.getParameter<InputTag>("VertexCollection"));
19 
20  token_BeamSpot_ = iC.consumes<BeamSpot>(iConfig.getParameter<InputTag>("BeamSpot"));
21 }

References edm::ParameterSet::getParameter(), input_MaxNumAssociations_, token_BeamSpot_, and token_VertexCollection_.

Member Function Documentation

◆ createMappings()

std::pair< std::unique_ptr< PFCandToVertexAssMap >, std::unique_ptr< VertexToPFCandAssMap > > PFCand_AssoMapAlgos::createMappings ( edm::Handle< reco::PFCandidateCollection pfCandH,
const edm::EventSetup iSetup 
)

Definition at line 43 of file PFCand_AssoMapAlgos.cc.

43  {
44  unique_ptr<PFCandToVertexAssMap> pfcand2vertex(new PFCandToVertexAssMap(vtxcollH, pfCandH));
45  unique_ptr<VertexToPFCandAssMap> vertex2pfcand(new VertexToPFCandAssMap(pfCandH, vtxcollH));
46 
47  int num_vertices = vtxcollH->size();
48  if (num_vertices < input_MaxNumAssociations_)
49  input_MaxNumAssociations_ = num_vertices;
50  vector<VertexRef> vtxColl_help;
52  vtxColl_help = CreateVertexVector(vtxcollH);
53 
54  for (unsigned i = 0; i < pfCandH->size(); i++) {
55  PFCandidateRef candref(pfCandH, i);
56 
58  vtxColl_help = CreateVertexVector(vtxcollH);
59 
60  VertexPfcQuality VtxPfcQual;
61 
62  TrackRef PFCtrackref = candref->trackRef();
63 
64  if (PFCtrackref.isNull()) {
65  for (int assoc_ite = 0; assoc_ite < input_MaxNumAssociations_; ++assoc_ite) {
66  int quality = -1 - assoc_ite;
67 
68  // Insert the best vertex and the pair of track and the quality of this association in the map
69  pfcand2vertex->insert(vtxColl_help.at(0), make_pair(candref, quality));
70  vertex2pfcand->insert(candref, make_pair(vtxColl_help.at(0), quality));
71 
72  //cleanup only if multiple iterations are made
74  PF_PU_AssoMapAlgos::EraseVertex(vtxColl_help, vtxColl_help.at(0));
75  }
76 
77  } else {
78  TransientTrack transtrk(PFCtrackref, &(*bFieldH));
79  transtrk.setBeamSpot(*beamspotH);
80  transtrk.setES(iSetup);
81 
82  for (int assoc_ite = 0; assoc_ite < input_MaxNumAssociations_; ++assoc_ite) {
83  VertexStepPair assocVtx = FindAssociation(PFCtrackref, vtxColl_help, bFieldH, iSetup, beamspotH, assoc_ite);
84  int step = assocVtx.second;
85  double distance = (IPTools::absoluteImpactParameter3D(transtrk, *(assocVtx.first))).second.value();
86 
87  int quality = DefineQuality(assoc_ite, step, distance);
88 
89  // Insert the best vertex and the pair of track and the quality of this association in the map
90  pfcand2vertex->insert(assocVtx.first, make_pair(candref, quality));
91  vertex2pfcand->insert(candref, make_pair(assocVtx.first, quality));
92 
93  //cleanup only if multiple iterations are made
95  PF_PU_AssoMapAlgos::EraseVertex(vtxColl_help, assocVtx.first);
96  }
97 
98  } //check PFCtrackref.isNull
99 
100  } //i on pfCandH
101 
102  return {std::move(pfcand2vertex), std::move(vertex2pfcand)};
103 }

References IPTools::absoluteImpactParameter3D(), beamspotH, bFieldH, PF_PU_AssoMapAlgos::CreateVertexVector(), PF_PU_AssoMapAlgos::DefineQuality(), HLT_FULL_cff::distance, PF_PU_AssoMapAlgos::EraseVertex(), PF_PU_AssoMapAlgos::FindAssociation(), mps_fire::i, input_MaxNumAssociations_, edm::Ref< C, T, F >::isNull(), eostools::move(), qcdUeDQM_cfi::quality, edm::second(), reco::TransientTrack::setBeamSpot(), reco::TransientTrack::setES(), and vtxcollH.

Referenced by CreatePFCandToVertexMap(), CreateVertexToPFCandMap(), and PFCand_AssoMap::produce().

◆ CreatePFCandToVertexMap()

std::unique_ptr< PFCandToVertexAssMap > PFCand_AssoMapAlgos::CreatePFCandToVertexMap ( edm::Handle< reco::PFCandidateCollection pfCandH,
const edm::EventSetup iSetup 
)

Definition at line 109 of file PFCand_AssoMapAlgos.cc.

110  {
111  return createMappings(pfCandH, iSetup).first;
112 }

References createMappings().

◆ CreateVertexToPFCandMap()

std::unique_ptr< VertexToPFCandAssMap > PFCand_AssoMapAlgos::CreateVertexToPFCandMap ( edm::Handle< reco::PFCandidateCollection pfCandH,
const edm::EventSetup iSetup 
)

Definition at line 118 of file PFCand_AssoMapAlgos.cc.

119  {
120  return createMappings(pfCandH, iSetup).second;
121 }

References createMappings().

◆ GetInputCollections()

void PFCand_AssoMapAlgos::GetInputCollections ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overridevirtual

Reimplemented from PF_PU_AssoMapAlgos.

Definition at line 27 of file PFCand_AssoMapAlgos.cc.

27  {
29 
30  //get the offline beam spot
31  iEvent.getByToken(token_BeamSpot_, beamspotH);
32 
33  //get the input vertex collection
35 
37 }

References beamspotH, bFieldH, edm::EventSetup::get(), get, PF_PU_AssoMapAlgos::GetInputCollections(), iEvent, token_BeamSpot_, token_VertexCollection_, and vtxcollH.

Referenced by PFCand_AssoMap::produce().

◆ SortPFCandAssociationMap()

std::unique_ptr< PFCandToVertexAssMap > PFCand_AssoMapAlgos::SortPFCandAssociationMap ( PFCandToVertexAssMap pfcvertexassInput,
edm::EDProductGetter const *  getter 
)

Definition at line 127 of file PFCand_AssoMapAlgos.cc.

128  {
129  //create a new PFCandVertexAssMap for the Output which will be sorted
130  unique_ptr<PFCandToVertexAssMap> pfcvertexassOutput(new PFCandToVertexAssMap(getter));
131 
132  //Create and fill a vector of pairs of vertex and the summed (pT)**2 of the pfcandidates associated to the vertex
133  VertexPtsumVector vertexptsumvector;
134 
135  //loop over all vertices in the association map
136  for (PFCandToVertexAssMap::const_iterator assomap_ite = pfcvertexassInput->begin();
137  assomap_ite != pfcvertexassInput->end();
138  assomap_ite++) {
139  const VertexRef assomap_vertexref = assomap_ite->key;
140  const PFCandQualityPairVector pfccoll = assomap_ite->val;
141 
142  float ptsum = 0;
143 
144  PFCandidateRef pfcandref;
145 
146  //get the pfcandidates associated to the vertex and calculate the pT**2
147  for (unsigned int pfccoll_ite = 0; pfccoll_ite < pfccoll.size(); pfccoll_ite++) {
148  pfcandref = pfccoll[pfccoll_ite].first;
149  int quality = pfccoll[pfccoll_ite].second;
150 
151  if ((quality <= 2) && (quality != -1))
152  continue;
153 
154  double man_pT = pfcandref->pt();
155  if (man_pT > 0.)
156  ptsum += man_pT * man_pT;
157  }
158 
159  vertexptsumvector.push_back(make_pair(assomap_vertexref, ptsum));
160  }
161 
162  while (!vertexptsumvector.empty()) {
163  VertexRef vertexref_highestpT;
164  float highestpT = 0.;
165  int highestpT_index = 0;
166 
167  for (unsigned int vtxptsumvec_ite = 0; vtxptsumvec_ite < vertexptsumvector.size(); vtxptsumvec_ite++) {
168  if (vertexptsumvector[vtxptsumvec_ite].second > highestpT) {
169  vertexref_highestpT = vertexptsumvector[vtxptsumvec_ite].first;
170  highestpT = vertexptsumvector[vtxptsumvec_ite].second;
171  highestpT_index = vtxptsumvec_ite;
172  }
173  }
174 
175  //loop over all vertices in the association map
176  for (PFCandToVertexAssMap::const_iterator assomap_ite = pfcvertexassInput->begin();
177  assomap_ite != pfcvertexassInput->end();
178  assomap_ite++) {
179  const VertexRef assomap_vertexref = assomap_ite->key;
180  const PFCandQualityPairVector pfccoll = assomap_ite->val;
181 
182  //if the vertex from the association map the vertex with the highest pT
183  //insert all associated pfcandidates in the output Association Map
184  if (assomap_vertexref == vertexref_highestpT)
185  for (unsigned int pfccoll_ite = 0; pfccoll_ite < pfccoll.size(); pfccoll_ite++)
186  pfcvertexassOutput->insert(assomap_vertexref, pfccoll[pfccoll_ite]);
187  }
188 
189  vertexptsumvector.erase(vertexptsumvector.begin() + highestpT_index);
190  }
191 
192  return pfcvertexassOutput;
193 }

References edm::AssociationMap< Tag >::begin(), edm::AssociationMap< Tag >::end(), edm::Ref< C, T, F >::key(), qcdUeDQM_cfi::quality, and edm::second().

Referenced by PFCand_AssoMap::produce().

Member Data Documentation

◆ beamspotH

edm::Handle<reco::BeamSpot> PFCand_AssoMapAlgos::beamspotH
private

Definition at line 77 of file PFCand_AssoMapAlgos.h.

Referenced by createMappings(), and GetInputCollections().

◆ bFieldH

edm::ESHandle<MagneticField> PFCand_AssoMapAlgos::bFieldH
private

Definition at line 79 of file PFCand_AssoMapAlgos.h.

Referenced by createMappings(), and GetInputCollections().

◆ input_MaxNumAssociations_

int PFCand_AssoMapAlgos::input_MaxNumAssociations_
private

Definition at line 71 of file PFCand_AssoMapAlgos.h.

Referenced by createMappings(), and PFCand_AssoMapAlgos().

◆ token_BeamSpot_

edm::EDGetTokenT<reco::BeamSpot> PFCand_AssoMapAlgos::token_BeamSpot_
private

Definition at line 76 of file PFCand_AssoMapAlgos.h.

Referenced by GetInputCollections(), and PFCand_AssoMapAlgos().

◆ token_VertexCollection_

edm::EDGetTokenT<reco::VertexCollection> PFCand_AssoMapAlgos::token_VertexCollection_
private

Definition at line 73 of file PFCand_AssoMapAlgos.h.

Referenced by GetInputCollections(), and PFCand_AssoMapAlgos().

◆ vtxcollH

edm::Handle<reco::VertexCollection> PFCand_AssoMapAlgos::vtxcollH
private

Definition at line 74 of file PFCand_AssoMapAlgos.h.

Referenced by createMappings(), and GetInputCollections().

PF_PU_AssoMapAlgos::CreateVertexVector
std::vector< reco::VertexRef > CreateVertexVector(edm::Handle< reco::VertexCollection >)
Definition: PF_PU_AssoMapAlgos.cc:248
PFCand_AssoMapAlgos::token_VertexCollection_
edm::EDGetTokenT< reco::VertexCollection > token_VertexCollection_
Definition: PFCand_AssoMapAlgos.h:73
mps_fire.i
i
Definition: mps_fire.py:428
VertexPfcQuality
std::pair< reco::VertexRef, PFCandQualityPair > VertexPfcQuality
Definition: PFCand_AssoMapAlgos.h:36
step
step
Definition: StallMonitor.cc:94
PFCand_AssoMapAlgos::token_BeamSpot_
edm::EDGetTokenT< reco::BeamSpot > token_BeamSpot_
Definition: PFCand_AssoMapAlgos.h:76
edm::Ref::isNull
bool isNull() const
Checks for null.
Definition: Ref.h:235
IPTools::absoluteImpactParameter3D
std::pair< bool, Measurement1D > absoluteImpactParameter3D(const reco::TransientTrack &transientTrack, const reco::Vertex &vertex)
Definition: IPTools.cc:38
PF_PU_AssoMapAlgos::GetInputCollections
virtual void GetInputCollections(edm::Event &, const edm::EventSetup &)
Definition: PF_PU_AssoMapAlgos.cc:59
reco::VertexCollection
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
PFCand_AssoMapAlgos::createMappings
std::pair< std::unique_ptr< PFCandToVertexAssMap >, std::unique_ptr< VertexToPFCandAssMap > > createMappings(edm::Handle< reco::PFCandidateCollection > pfCandH, const edm::EventSetup &iSetup)
Definition: PFCand_AssoMapAlgos.cc:43
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:222
VertexPtsumVector
std::vector< VertexPtsumPair > VertexPtsumVector
Definition: PF_PU_AssoMapAlgos.h:81
edm::Ref< PFCandidateCollection >
IdealMagneticFieldRecord
Definition: IdealMagneticFieldRecord.h:11
edm::AssociationMap::end
const_iterator end() const
last iterator over the map (read only)
Definition: AssociationMap.h:171
VertexToPFCandAssMap
edm::AssociationMap< edm::OneToManyWithQuality< reco::PFCandidateCollection, reco::VertexCollection, int > > VertexToPFCandAssMap
Definition: PFCand_AssoMapAlgos.h:31
edm::EventSetup::get
T get() const
Definition: EventSetup.h:80
PF_PU_AssoMapAlgos::EraseVertex
void EraseVertex(std::vector< reco::VertexRef > &, reco::VertexRef)
Definition: PF_PU_AssoMapAlgos.cc:262
reco::BeamSpot
Definition: BeamSpot.h:21
edm::ConsumesCollector::consumes
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: ConsumesCollector.h:55
PFCandQualityPairVector
std::vector< PFCandQualityPair > PFCandQualityPairVector
Definition: PFCand_AssoMapAlgos.h:34
PF_PU_AssoMapAlgos::FindAssociation
VertexStepPair FindAssociation(const reco::TrackRef &, const std::vector< reco::VertexRef > &, edm::ESHandle< MagneticField >, const edm::EventSetup &, edm::Handle< reco::BeamSpot >, int)
Definition: PF_PU_AssoMapAlgos.cc:718
PF_PU_AssoMapAlgos::DefineQuality
int DefineQuality(int, int, double)
Definition: PF_PU_AssoMapAlgos.cc:811
iEvent
int iEvent
Definition: GenABIO.cc:224
get
#define get
PFCand_AssoMapAlgos::bFieldH
edm::ESHandle< MagneticField > bFieldH
Definition: PFCand_AssoMapAlgos.h:79
eostools.move
def move(src, dest)
Definition: eostools.py:511
reco::TransientTrack
Definition: TransientTrack.h:19
PFCandToVertexAssMap
edm::AssociationMap< edm::OneToManyWithQuality< reco::VertexCollection, reco::PFCandidateCollection, int > > PFCandToVertexAssMap
Definition: PFCand_AssoMapAlgos.h:29
qcdUeDQM_cfi.quality
quality
Definition: qcdUeDQM_cfi.py:31
edm::AssociationMap::begin
const_iterator begin() const
first iterator over the map (read only)
Definition: AssociationMap.h:169
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
PFCand_AssoMapAlgos::vtxcollH
edm::Handle< reco::VertexCollection > vtxcollH
Definition: PFCand_AssoMapAlgos.h:74
edm::Ref::key
key_type key() const
Accessor for product key.
Definition: Ref.h:250
PFCand_AssoMapAlgos::beamspotH
edm::Handle< reco::BeamSpot > beamspotH
Definition: PFCand_AssoMapAlgos.h:77
PFCand_AssoMapAlgos::input_MaxNumAssociations_
int input_MaxNumAssociations_
Definition: PFCand_AssoMapAlgos.h:71
PF_PU_AssoMapAlgos::PF_PU_AssoMapAlgos
PF_PU_AssoMapAlgos(const edm::ParameterSet &iConfig, edm::ConsumesCollector &&iC)
Definition: PF_PU_AssoMapAlgos.h:86
VertexStepPair
std::pair< reco::VertexRef, int > VertexStepPair
Definition: PF_PU_AssoMapAlgos.h:76
HLT_FULL_cff.distance
distance
Definition: HLT_FULL_cff.py:7733
edm::AssociationMap::const_iterator
const iterator
Definition: AssociationMap.h:76
edm::InputTag
Definition: InputTag.h:15