CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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)
 
std::unique_ptr
< PFCandToVertexAssMap
CreatePFCandToVertexMap (edm::Handle< reco::PFCandidateCollection >)
 
std::unique_ptr
< VertexToPFCandAssMap
CreateVertexToPFCandMap (edm::Handle< reco::PFCandidateCollection >)
 
void GetInputCollections (edm::Event &, const edm::EventSetup &) override
 
 PFCand_AssoMapAlgos (const edm::ParameterSet &, edm::ConsumesCollector &&)
 
std::unique_ptr
< PFCandToVertexAssMap
SortPFCandAssociationMap (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)
 
std::unique_ptr
< TrackToVertexAssMap
CreateTrackToVertexMap (edm::Handle< reco::TrackCollection >)
 
std::unique_ptr
< VertexToTrackAssMap
CreateVertexToTrackMap (edm::Handle< reco::TrackCollection >)
 
 PF_PU_AssoMapAlgos (const edm::ParameterSet &iConfig, edm::ConsumesCollector &&iC)
 
 PF_PU_AssoMapAlgos (const edm::ParameterSet &, edm::ConsumesCollector &)
 
std::unique_ptr
< TrackToVertexAssMap
SortAssociationMap (TrackToVertexAssMap *, edm::Handle< reco::TrackCollection >)
 
template<typename TREF >
VertexRef TrackWeightAssociation (const TREF &trackRef, const std::vector< reco::VertexRef > &vtxcollV)
 
virtual ~PF_PU_AssoMapAlgos () noexcept(false)
 

Private Attributes

edm::Handle< reco::BeamSpotbeamspotH
 
edm::ESHandle< MagneticFieldbFieldH
 
int input_MaxNumAssociations_
 
edm::EDGetTokenT< reco::BeamSpottoken_BeamSpot_
 
const edm::ESGetToken
< MagneticField,
IdealMagneticFieldRecord
token_bField_
 
const edm::ESGetToken
< GlobalTrackingGeometry,
GlobalTrackingGeometryRecord
token_TrackingGeometry_
 
edm::EDGetTokenT
< reco::VertexCollection
token_VertexCollection_
 
edm::ESHandle
< GlobalTrackingGeometry
trackingGeometryH
 
edm::Handle
< reco::VertexCollection
vtxcollH
 

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 >, edm::ESHandle< GlobalTrackingGeometry >, edm::Handle< reco::BeamSpot >, int)
 

Detailed Description

Definition at line 42 of file PFCand_AssoMapAlgos.h.

Constructor & Destructor Documentation

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

Definition at line 14 of file PFCand_AssoMapAlgos.cc.

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

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 }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
const edm::ESGetToken< GlobalTrackingGeometry, GlobalTrackingGeometryRecord > token_TrackingGeometry_
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > token_bField_
PF_PU_AssoMapAlgos(const edm::ParameterSet &iConfig, edm::ConsumesCollector &&iC)
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::EDGetTokenT< reco::VertexCollection > token_VertexCollection_
edm::EDGetTokenT< reco::BeamSpot > token_BeamSpot_

Member Function Documentation

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

Definition at line 44 of file PFCand_AssoMapAlgos.cc.

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(), quality, edm::second(), reco::TransientTrack::setBeamSpot(), reco::TransientTrack::setTrackingGeometry(), trackingGeometryH, and vtxcollH.

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

44  {
45  unique_ptr<PFCandToVertexAssMap> pfcand2vertex(new PFCandToVertexAssMap(vtxcollH, pfCandH));
46  unique_ptr<VertexToPFCandAssMap> vertex2pfcand(new VertexToPFCandAssMap(pfCandH, vtxcollH));
47 
48  int num_vertices = vtxcollH->size();
49  if (num_vertices < input_MaxNumAssociations_)
50  input_MaxNumAssociations_ = num_vertices;
51  vector<VertexRef> vtxColl_help;
53  vtxColl_help = CreateVertexVector(vtxcollH);
54 
55  for (unsigned i = 0; i < pfCandH->size(); i++) {
56  PFCandidateRef candref(pfCandH, i);
57 
59  vtxColl_help = CreateVertexVector(vtxcollH);
60 
61  VertexPfcQuality VtxPfcQual;
62 
63  TrackRef PFCtrackref = candref->trackRef();
64 
65  if (PFCtrackref.isNull()) {
66  for (int assoc_ite = 0; assoc_ite < input_MaxNumAssociations_; ++assoc_ite) {
67  int quality = -1 - assoc_ite;
68 
69  // Insert the best vertex and the pair of track and the quality of this association in the map
70  pfcand2vertex->insert(vtxColl_help.at(0), make_pair(candref, quality));
71  vertex2pfcand->insert(candref, make_pair(vtxColl_help.at(0), quality));
72 
73  //cleanup only if multiple iterations are made
74  if (input_MaxNumAssociations_ > 1)
75  PF_PU_AssoMapAlgos::EraseVertex(vtxColl_help, vtxColl_help.at(0));
76  }
77 
78  } else {
79  TransientTrack transtrk(PFCtrackref, &(*bFieldH));
80  transtrk.setBeamSpot(*beamspotH);
81  transtrk.setTrackingGeometry(trackingGeometryH);
82 
83  for (int assoc_ite = 0; assoc_ite < input_MaxNumAssociations_; ++assoc_ite) {
84  VertexStepPair assocVtx =
85  FindAssociation(PFCtrackref, vtxColl_help, bFieldH, trackingGeometryH, beamspotH, assoc_ite);
86  int step = assocVtx.second;
87  double distance = (IPTools::absoluteImpactParameter3D(transtrk, *(assocVtx.first))).second.value();
88 
89  int quality = DefineQuality(assoc_ite, step, distance);
90 
91  // Insert the best vertex and the pair of track and the quality of this association in the map
92  pfcand2vertex->insert(assocVtx.first, make_pair(candref, quality));
93  vertex2pfcand->insert(candref, make_pair(assocVtx.first, quality));
94 
95  //cleanup only if multiple iterations are made
96  if (input_MaxNumAssociations_ > 2)
97  PF_PU_AssoMapAlgos::EraseVertex(vtxColl_help, assocVtx.first);
98  }
99 
100  } //check PFCtrackref.isNull
101 
102  } //i on pfCandH
103 
104  return {std::move(pfcand2vertex), std::move(vertex2pfcand)};
105 }
int DefineQuality(int, int, double)
std::pair< reco::VertexRef, PFCandQualityPair > VertexPfcQuality
VertexStepPair FindAssociation(const reco::TrackRef &, const std::vector< reco::VertexRef > &, edm::ESHandle< MagneticField >, edm::ESHandle< GlobalTrackingGeometry >, edm::Handle< reco::BeamSpot >, int)
std::pair< bool, Measurement1D > absoluteImpactParameter3D(const reco::TransientTrack &transientTrack, const reco::Vertex &vertex)
Definition: IPTools.cc:38
edm::ESHandle< GlobalTrackingGeometry > trackingGeometryH
string quality
std::pair< reco::VertexRef, int > VertexStepPair
U second(std::pair< T, U > const &p)
def move
Definition: eostools.py:511
edm::AssociationMap< edm::OneToManyWithQuality< reco::VertexCollection, reco::PFCandidateCollection, int > > PFCandToVertexAssMap
edm::AssociationMap< edm::OneToManyWithQuality< reco::PFCandidateCollection, reco::VertexCollection, int > > VertexToPFCandAssMap
edm::Handle< reco::BeamSpot > beamspotH
bool isNull() const
Checks for null.
Definition: Ref.h:235
std::vector< reco::VertexRef > CreateVertexVector(edm::Handle< reco::VertexCollection >)
edm::ESHandle< MagneticField > bFieldH
void EraseVertex(std::vector< reco::VertexRef > &, reco::VertexRef)
edm::Handle< reco::VertexCollection > vtxcollH
step
Definition: StallMonitor.cc:98
std::unique_ptr< PFCandToVertexAssMap > PFCand_AssoMapAlgos::CreatePFCandToVertexMap ( edm::Handle< reco::PFCandidateCollection pfCandH)

Definition at line 111 of file PFCand_AssoMapAlgos.cc.

References createMappings().

112  {
113  return createMappings(pfCandH).first;
114 }
std::pair< std::unique_ptr< PFCandToVertexAssMap >, std::unique_ptr< VertexToPFCandAssMap > > createMappings(edm::Handle< reco::PFCandidateCollection > pfCandH)
std::unique_ptr< VertexToPFCandAssMap > PFCand_AssoMapAlgos::CreateVertexToPFCandMap ( edm::Handle< reco::PFCandidateCollection pfCandH)

Definition at line 120 of file PFCand_AssoMapAlgos.cc.

References createMappings().

121  {
122  return createMappings(pfCandH).second;
123 }
std::pair< std::unique_ptr< PFCandToVertexAssMap >, std::unique_ptr< VertexToPFCandAssMap > > createMappings(edm::Handle< reco::PFCandidateCollection > pfCandH)
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.

References beamspotH, bFieldH, edm::Event::getByToken(), edm::EventSetup::getHandle(), PF_PU_AssoMapAlgos::GetInputCollections(), token_BeamSpot_, token_bField_, token_TrackingGeometry_, token_VertexCollection_, trackingGeometryH, and vtxcollH.

Referenced by PFCand_AssoMap::produce().

27  {
29 
30  //get the offline beam spot
32 
33  //get the input vertex collection
35 
38 }
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
const edm::ESGetToken< GlobalTrackingGeometry, GlobalTrackingGeometryRecord > token_TrackingGeometry_
edm::ESHandle< GlobalTrackingGeometry > trackingGeometryH
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > token_bField_
virtual void GetInputCollections(edm::Event &, const edm::EventSetup &)
edm::Handle< reco::BeamSpot > beamspotH
edm::ESHandle< MagneticField > bFieldH
edm::EDGetTokenT< reco::VertexCollection > token_VertexCollection_
edm::Handle< reco::VertexCollection > vtxcollH
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:151
edm::EDGetTokenT< reco::BeamSpot > token_BeamSpot_
std::unique_ptr< PFCandToVertexAssMap > PFCand_AssoMapAlgos::SortPFCandAssociationMap ( PFCandToVertexAssMap pfcvertexassInput,
edm::EDProductGetter const *  getter 
)

Definition at line 129 of file PFCand_AssoMapAlgos.cc.

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

Referenced by PFCand_AssoMap::produce().

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

Member Data Documentation

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

Definition at line 76 of file PFCand_AssoMapAlgos.h.

Referenced by createMappings(), and GetInputCollections().

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

Definition at line 79 of file PFCand_AssoMapAlgos.h.

Referenced by createMappings(), and GetInputCollections().

int PFCand_AssoMapAlgos::input_MaxNumAssociations_
private

Definition at line 70 of file PFCand_AssoMapAlgos.h.

Referenced by createMappings(), and PFCand_AssoMapAlgos().

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

Definition at line 75 of file PFCand_AssoMapAlgos.h.

Referenced by GetInputCollections(), and PFCand_AssoMapAlgos().

const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> PFCand_AssoMapAlgos::token_bField_
private

Definition at line 78 of file PFCand_AssoMapAlgos.h.

Referenced by GetInputCollections().

const edm::ESGetToken<GlobalTrackingGeometry, GlobalTrackingGeometryRecord> PFCand_AssoMapAlgos::token_TrackingGeometry_
private

Definition at line 80 of file PFCand_AssoMapAlgos.h.

Referenced by GetInputCollections().

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

Definition at line 72 of file PFCand_AssoMapAlgos.h.

Referenced by GetInputCollections(), and PFCand_AssoMapAlgos().

edm::ESHandle<GlobalTrackingGeometry> PFCand_AssoMapAlgos::trackingGeometryH
private

Definition at line 81 of file PFCand_AssoMapAlgos.h.

Referenced by createMappings(), and GetInputCollections().

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

Definition at line 73 of file PFCand_AssoMapAlgos.h.

Referenced by createMappings(), and GetInputCollections().