CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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::auto_ptr
< PFCandToVertexAssMap
CreatePFCandToVertexMap (edm::Handle< reco::PFCandidateCollection >, const edm::EventSetup &)
 
std::auto_ptr
< VertexToPFCandAssMap
CreateVertexToPFCandMap (edm::Handle< reco::PFCandidateCollection >, const edm::EventSetup &)
 
void GetPFCandInputCollections (edm::Event &, const edm::EventSetup &)
 
 PFCand_AssoMapAlgos (const edm::ParameterSet &)
 
void SetMotherPointer (edm::Handle< reco::PFCandidateCollection > &)
 
std::auto_ptr
< PFCandToVertexAssMap
SortPFCandAssociationMap (PFCandToVertexAssMap *)
 
- Public Member Functions inherited from PF_PU_AssoMapAlgos
std::auto_ptr
< TrackToVertexAssMap
CreateTrackToVertexMap (edm::Handle< reco::TrackCollection >, const edm::EventSetup &)
 
std::auto_ptr
< VertexToTrackAssMap
CreateVertexToTrackMap (edm::Handle< reco::TrackCollection >, const edm::EventSetup &)
 
virtual void GetInputCollections (edm::Event &, const edm::EventSetup &)
 
 PF_PU_AssoMapAlgos (const edm::ParameterSet &)
 
std::auto_ptr
< TrackToVertexAssMap
SortAssociationMap (TrackToVertexAssMap *)
 
virtual ~PF_PU_AssoMapAlgos ()
 

Private Attributes

edm::Handle< reco::BeamSpotbeamspotH
 
edm::ESHandle< MagneticFieldbFieldH
 
edm::InputTag input_BeamSpot_
 
int input_MaxNumAssociations_
 
edm::InputTag input_VertexCollection_
 
edm::Handle
< reco::VertexCollection
vtxcollH
 

Additional Inherited Members

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

Detailed Description

Definition at line 34 of file PFCand_AssoMapAlgos.h.

Constructor & Destructor Documentation

PFCand_AssoMapAlgos::PFCand_AssoMapAlgos ( const edm::ParameterSet iConfig)

Definition at line 14 of file PFCand_AssoMapAlgos.cc.

References edm::ParameterSet::getParameter(), input_BeamSpot_, input_MaxNumAssociations_, and input_VertexCollection_.

14  :PF_PU_AssoMapAlgos(iConfig)
15 {
16 
17  input_MaxNumAssociations_ = iConfig.getParameter<int>("MaxNumberOfAssociations");
18 
19  input_VertexCollection_= iConfig.getParameter<InputTag>("VertexCollection");
20 
21  input_BeamSpot_= iConfig.getParameter<InputTag>("BeamSpot");
22 
23 }
T getParameter(std::string const &) const
edm::InputTag input_BeamSpot_
edm::InputTag input_VertexCollection_
PF_PU_AssoMapAlgos(const edm::ParameterSet &)

Member Function Documentation

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

Definition at line 69 of file PFCand_AssoMapAlgos.cc.

References IPTools::absoluteImpactParameter3D(), beamspotH, bFieldH, PF_PU_AssoMapAlgos::CreateVertexVector(), PF_PU_AssoMapAlgos::DefineQuality(), PF_PU_AssoMapAlgos::EraseVertex(), PF_PU_AssoMapAlgos::FindAssociation(), i, input_MaxNumAssociations_, edm::Ref< C, T, F >::isNull(), edm::second(), reco::TransientTrack::setBeamSpot(), reco::TransientTrack::setES(), relval_parameters_module::step, and vtxcollH.

Referenced by PFCand_AssoMap::produce().

70 {
71 
72  auto_ptr<PFCandToVertexAssMap> pfcand2vertex(new PFCandToVertexAssMap());
73 
74  int num_associations = input_MaxNumAssociations_;
75  int num_vertices = vtxcollH->size();
76  if ( num_vertices < num_associations) num_associations = num_vertices;
77 
78  for( unsigned i=0; i<pfCandH->size(); i++ ) {
79 
80  PFCandidateRef candref(pfCandH, i);
81 
82  vector<VertexRef>* vtxColl_help = CreateVertexVector(vtxcollH);
83  StepDistancePairVector distances;
84 
85  VertexPfcQuality VtxPfcQual;
86 
87  TrackRef PFCtrackref = candref->trackRef();
88 
89  if ( PFCtrackref.isNull() ){
90 
91  for ( int assoc_ite = 0; assoc_ite < num_associations; ++assoc_ite ) {
92 
93  int quality = -1 - assoc_ite;
94 
95  // edm::LogInfo("Prtcl2VtxAssociation") << "associating track with PdgId " << candref->pdgId() << ": Pt = " << candref->pt() << ","
96  // << " eta = " << candref->eta() << ", phi = " << candref->phi()
97  // << " to vertex: z = " << vtxColl_help->at(0)->position().z() << " with quality q = " << quality << std::endl;
98 
99  // Insert the best vertex and the pair of track and the quality of this association in the map
100  pfcand2vertex->insert( vtxColl_help->at(0), make_pair(candref, quality) );
101 
102  PF_PU_AssoMapAlgos::EraseVertex(vtxColl_help, vtxColl_help->at(0));
103 
104  }
105 
106  } else {
107 
108  TransientTrack transtrk(PFCtrackref, &(*bFieldH) );
109  transtrk.setBeamSpot(*beamspotH);
110  transtrk.setES(iSetup);
111 
112  for ( int assoc_ite = 0; assoc_ite < num_associations; ++assoc_ite ) {
113 
114  VertexStepPair assocVtx = FindAssociation(PFCtrackref, vtxColl_help, bFieldH, iSetup, beamspotH, assoc_ite);
115  VertexRef associatedVertex = assocVtx.first;
116  int step = assocVtx.second;
117  double distance = ( IPTools::absoluteImpactParameter3D( transtrk, *associatedVertex ) ).second.value();
118 
119  int quality = DefineQuality(distances, step, distance);
120  distances.push_back( make_pair(step, distance) );
121 
122  // edm::LogInfo("Prtcl2VtxAssociation") << "associating track with PdgId " << candref->pdgId() << ": Pt = " << candref->pt() << ","
123  // << " eta = " << candref->eta() << ", phi = " << candref->phi()
124  // << " to vertex: z = " << vtxColl_help->at(0)->position().z() << " with quality q = " << quality << std::endl;
125 
126  // Insert the best vertex and the pair of track and the quality of this association in the map
127  pfcand2vertex->insert( associatedVertex, make_pair(candref, quality) );
128 
129  PF_PU_AssoMapAlgos::EraseVertex(vtxColl_help, associatedVertex);
130 
131  }
132 
133  }
134 
135  delete vtxColl_help;
136 
137  }
138 
139  return pfcand2vertex;
140 
141 }
VertexStepPair FindAssociation(const reco::TrackRef &, std::vector< reco::VertexRef > *, edm::ESHandle< MagneticField >, const edm::EventSetup &, edm::Handle< reco::BeamSpot >, int)
int i
Definition: DBlmapReader.cc:9
std::pair< reco::VertexRef, PFCandQualityPair > VertexPfcQuality
void EraseVertex(std::vector< reco::VertexRef > *, reco::VertexRef)
std::pair< bool, Measurement1D > absoluteImpactParameter3D(const reco::TransientTrack &transientTrack, const reco::Vertex &vertex)
Definition: IPTools.cc:37
edm::AssociationMap< edm::OneToManyWithQuality< reco::VertexCollection, reco::PFCandidateCollection, int > > PFCandToVertexAssMap
std::pair< reco::VertexRef, int > VertexStepPair
U second(std::pair< T, U > const &p)
bool isNull() const
Checks for null.
Definition: Ref.h:247
edm::Handle< reco::BeamSpot > beamspotH
edm::ESHandle< MagneticField > bFieldH
std::vector< reco::VertexRef > * CreateVertexVector(edm::Handle< reco::VertexCollection >)
int DefineQuality(StepDistancePairVector, int, double)
edm::Handle< reco::VertexCollection > vtxcollH
std::vector< StepDistancePair > StepDistancePairVector
std::auto_ptr< VertexToPFCandAssMap > PFCand_AssoMapAlgos::CreateVertexToPFCandMap ( edm::Handle< reco::PFCandidateCollection pfCandH,
const edm::EventSetup iSetup 
)

Definition at line 148 of file PFCand_AssoMapAlgos.cc.

References IPTools::absoluteImpactParameter3D(), beamspotH, bFieldH, PF_PU_AssoMapAlgos::CreateVertexVector(), PF_PU_AssoMapAlgos::DefineQuality(), PF_PU_AssoMapAlgos::EraseVertex(), PF_PU_AssoMapAlgos::FindAssociation(), i, input_MaxNumAssociations_, edm::Ref< C, T, F >::isNull(), edm::second(), reco::TransientTrack::setBeamSpot(), reco::TransientTrack::setES(), relval_parameters_module::step, and vtxcollH.

Referenced by PFCand_AssoMap::produce().

149 {
150 
151  auto_ptr<VertexToPFCandAssMap> vertex2pfcand(new VertexToPFCandAssMap());
152 
153  int num_associations = input_MaxNumAssociations_;
154  int num_vertices = vtxcollH->size();
155  if ( num_vertices < num_associations) num_associations = num_vertices;
156 
157  for( unsigned i=0; i<pfCandH->size(); i++ ) {
158 
159  PFCandidateRef candref(pfCandH, i);
160 
161  vector<VertexRef>* vtxColl_help = CreateVertexVector(vtxcollH);
162  StepDistancePairVector distances;
163 
164  VertexPfcQuality VtxPfcQual;
165 
166  TrackRef PFCtrackref = candref->trackRef();
167 
168  if ( PFCtrackref.isNull() ) {
169 
170  for ( int assoc_ite = 0; assoc_ite < num_associations; ++assoc_ite ) {
171 
172  int quality = -1 - assoc_ite;
173 
174  // edm::LogInfo("Vtx2PrtclAssociation") << "associating track with PdgId " << candref->pdgId() << ": Pt = " << candref->pt() << ","
175  // << " eta = " << candref->eta() << ", phi = " << candref->phi()
176  // << " to vertex: z = " << vtxColl_help->at(0)->position().z() << " with quality q = " << quality << std::endl;
177 
178  // Insert the best vertex and the pair of track and the quality of this association in the map
179  vertex2pfcand->insert( candref, make_pair(vtxColl_help->at(0), quality) );
180 
181  PF_PU_AssoMapAlgos::EraseVertex(vtxColl_help, vtxColl_help->at(0));
182 
183  }
184 
185  } else {
186 
187  TransientTrack transtrk(PFCtrackref, &(*bFieldH) );
188  transtrk.setBeamSpot(*beamspotH);
189  transtrk.setES(iSetup);
190 
191  for ( int assoc_ite = 0; assoc_ite < num_associations; ++assoc_ite ) {
192 
193  VertexStepPair assocVtx = FindAssociation(PFCtrackref, vtxColl_help, bFieldH, iSetup, beamspotH, assoc_ite);
194  VertexRef associatedVertex = assocVtx.first;
195  int step = assocVtx.second;
196  double distance = ( IPTools::absoluteImpactParameter3D( transtrk, *associatedVertex ) ).second.value();
197 
198  int quality = DefineQuality(distances, step, distance);
199  distances.push_back( make_pair(step, distance) );
200 
201  // edm::LogInfo("Vtx2PrtclAssociation") << "associating track with PdgId " << candref->pdgId() << ": Pt = " << candref->pt() << ","
202  // << " eta = " << candref->eta() << ", phi = " << candref->phi()
203  // << " to vertex: z = " << vtxColl_help->at(0)->position().z() << " with quality q = " << quality << std::endl;
204 
205  // Insert the best vertex and the pair of track and the quality of this association in the map
206  vertex2pfcand->insert( candref, make_pair(associatedVertex, quality) );
207 
208  PF_PU_AssoMapAlgos::EraseVertex(vtxColl_help, associatedVertex);
209 
210  }
211 
212  }
213 
214  delete vtxColl_help;
215 
216  }
217 
218  return vertex2pfcand;
219 
220 }
VertexStepPair FindAssociation(const reco::TrackRef &, std::vector< reco::VertexRef > *, edm::ESHandle< MagneticField >, const edm::EventSetup &, edm::Handle< reco::BeamSpot >, int)
int i
Definition: DBlmapReader.cc:9
edm::AssociationMap< edm::OneToManyWithQuality< reco::PFCandidateCollection, reco::VertexCollection, int > > VertexToPFCandAssMap
std::pair< reco::VertexRef, PFCandQualityPair > VertexPfcQuality
void EraseVertex(std::vector< reco::VertexRef > *, reco::VertexRef)
std::pair< bool, Measurement1D > absoluteImpactParameter3D(const reco::TransientTrack &transientTrack, const reco::Vertex &vertex)
Definition: IPTools.cc:37
std::pair< reco::VertexRef, int > VertexStepPair
U second(std::pair< T, U > const &p)
bool isNull() const
Checks for null.
Definition: Ref.h:247
edm::Handle< reco::BeamSpot > beamspotH
edm::ESHandle< MagneticField > bFieldH
std::vector< reco::VertexRef > * CreateVertexVector(edm::Handle< reco::VertexCollection >)
int DefineQuality(StepDistancePairVector, int, double)
edm::Handle< reco::VertexCollection > vtxcollH
std::vector< StepDistancePair > StepDistancePairVector
void PFCand_AssoMapAlgos::GetPFCandInputCollections ( edm::Event iEvent,
const edm::EventSetup iSetup 
)

Definition at line 30 of file PFCand_AssoMapAlgos.cc.

References beamspotH, bFieldH, edm::EventSetup::get(), edm::Event::getByLabel(), PF_PU_AssoMapAlgos::GetInputCollections(), input_BeamSpot_, input_VertexCollection_, and vtxcollH.

Referenced by PFCand_AssoMap::produce().

31 {
32 
34 
35  //get the offline beam spot
37 
38  //get the input vertex collection
40 
41  iSetup.get<IdealMagneticFieldRecord>().get(bFieldH);
42 
43 }
edm::InputTag input_BeamSpot_
edm::InputTag input_VertexCollection_
virtual void GetInputCollections(edm::Event &, const edm::EventSetup &)
edm::Handle< reco::BeamSpot > beamspotH
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
edm::ESHandle< MagneticField > bFieldH
const T & get() const
Definition: EventSetup.h:55
edm::Handle< reco::VertexCollection > vtxcollH
void PFCand_AssoMapAlgos::SetMotherPointer ( edm::Handle< reco::PFCandidateCollection > &  pfCandH)

Definition at line 50 of file PFCand_AssoMapAlgos.cc.

References i.

Referenced by PFCand_AssoMap::produce().

51 {
52 
53  PFCandidateCollection& inCands = (PFCandidateCollection&) *pfCandH;
54 
55  for(unsigned i=0; i<inCands.size(); i++) {
56 
57  const PFCandidatePtr motherPtr( pfCandH, i );
58  inCands[i].setSourceCandidatePtr( motherPtr );
59 
60  }
61 
62 }
int i
Definition: DBlmapReader.cc:9
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
std::auto_ptr< PFCandToVertexAssMap > PFCand_AssoMapAlgos::SortPFCandAssociationMap ( PFCandToVertexAssMap pfcvertexassInput)

Definition at line 227 of file PFCand_AssoMapAlgos.cc.

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

Referenced by PFCand_AssoMap::produce().

228 {
229 
230  //create a new PFCandVertexAssMap for the Output which will be sorted
231  auto_ptr<PFCandToVertexAssMap> pfcvertexassOutput(new PFCandToVertexAssMap() );
232 
233  //Create and fill a vector of pairs of vertex and the summed (pT)**2 of the pfcandidates associated to the vertex
234  VertexPtsumVector vertexptsumvector;
235 
236  //loop over all vertices in the association map
237  for(PFCandToVertexAssMap::const_iterator assomap_ite=pfcvertexassInput->begin(); assomap_ite!=pfcvertexassInput->end(); assomap_ite++){
238 
239  const VertexRef assomap_vertexref = assomap_ite->key;
240  const PFCandQualityPairVector pfccoll = assomap_ite->val;
241 
242  float ptsum = 0;
243 
244  PFCandidateRef pfcandref;
245 
246  //get the pfcandidates associated to the vertex and calculate the pT**2
247  for(unsigned int pfccoll_ite=0; pfccoll_ite<pfccoll.size(); pfccoll_ite++){
248 
249  pfcandref = pfccoll[pfccoll_ite].first;
250  int quality = pfccoll[pfccoll_ite].second;
251 
252  if ( (quality<=2) && (quality!=-1) ) continue;
253 
254  double man_pT = pfcandref->pt();
255  if(man_pT>0.) ptsum+=man_pT*man_pT;
256 
257  }
258 
259  vertexptsumvector.push_back(make_pair(assomap_vertexref,ptsum));
260 
261  }
262 
263  while (vertexptsumvector.size()!=0){
264 
265  VertexRef vertexref_highestpT;
266  float highestpT = 0.;
267  int highestpT_index = 0;
268 
269  for(unsigned int vtxptsumvec_ite=0; vtxptsumvec_ite<vertexptsumvector.size(); vtxptsumvec_ite++){
270 
271  if(vertexptsumvector[vtxptsumvec_ite].second>highestpT){
272 
273  vertexref_highestpT = vertexptsumvector[vtxptsumvec_ite].first;
274  highestpT = vertexptsumvector[vtxptsumvec_ite].second;
275  highestpT_index = vtxptsumvec_ite;
276 
277  }
278 
279  }
280 
281  //loop over all vertices in the association map
282  for(PFCandToVertexAssMap::const_iterator assomap_ite=pfcvertexassInput->begin(); assomap_ite!=pfcvertexassInput->end(); assomap_ite++){
283 
284  const VertexRef assomap_vertexref = assomap_ite->key;
285  const PFCandQualityPairVector pfccoll = assomap_ite->val;
286 
287  //if the vertex from the association map the vertex with the highest pT
288  //insert all associated pfcandidates in the output Association Map
289  if (assomap_vertexref==vertexref_highestpT) {
290  for(unsigned int pfccoll_ite=0; pfccoll_ite<pfccoll.size(); pfccoll_ite++) {
291  pfcvertexassOutput->insert(assomap_vertexref,pfccoll[pfccoll_ite]);
292  }
293  }
294 
295  }
296 
297  vertexptsumvector.erase(vertexptsumvector.begin()+highestpT_index);
298 
299  }
300 
301  return pfcvertexassOutput;
302 
303 }
const_iterator end() const
last iterator over the map (read only)
edm::AssociationMap< edm::OneToManyWithQuality< reco::VertexCollection, reco::PFCandidateCollection, int > > PFCandToVertexAssMap
U second(std::pair< T, U > const &p)
std::vector< VertexPtsumPair > VertexPtsumVector
std::vector< PFCandQualityPair > PFCandQualityPairVector
key_type key() const
Accessor for product key.
Definition: Ref.h:266
const_iterator begin() const
first iterator over the map (read only)

Member Data Documentation

edm::Handle<reco::BeamSpot> PFCand_AssoMapAlgos::beamspotH
private
edm::ESHandle<MagneticField> PFCand_AssoMapAlgos::bFieldH
private
edm::InputTag PFCand_AssoMapAlgos::input_BeamSpot_
private

Definition at line 67 of file PFCand_AssoMapAlgos.h.

Referenced by GetPFCandInputCollections(), and PFCand_AssoMapAlgos().

int PFCand_AssoMapAlgos::input_MaxNumAssociations_
private
edm::InputTag PFCand_AssoMapAlgos::input_VertexCollection_
private

Definition at line 64 of file PFCand_AssoMapAlgos.h.

Referenced by GetPFCandInputCollections(), and PFCand_AssoMapAlgos().

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