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
PrimaryVertexProducerAlgorithm Class Reference

#include <RecoVertex/PrimaryVertexProducerAlgorithm/src/PrimaryVertexProducerAlgorithm.cc>

Inheritance diagram for PrimaryVertexProducerAlgorithm:
VertexReconstructor

Public Member Functions

virtual
PrimaryVertexProducerAlgorithm
clone () const
 
 PrimaryVertexProducerAlgorithm (const edm::ParameterSet &)
 
virtual std::vector
< TransientVertex
vertices (const std::vector< reco::TransientTrack > &tracks) const
 
virtual std::vector
< TransientVertex
vertices (const std::vector< reco::TransientTrack > &tracks, const reco::BeamSpot &beamSpot) const
 
 ~PrimaryVertexProducerAlgorithm ()
 
- Public Member Functions inherited from VertexReconstructor
 VertexReconstructor ()
 
virtual std::vector
< TransientVertex
vertices (const std::vector< reco::TransientTrack > &primaries, const std::vector< reco::TransientTrack > &tracks, const reco::BeamSpot &spot) const
 
virtual ~VertexReconstructor ()
 

Private Attributes

bool fapply_finder
 
bool fFailsafe
 
double fMinNdof
 
bool fUseBeamConstraint
 
bool fVerbose
 
edm::ParameterSet theConfig
 
KalmanTrimmedVertexFinder theFinder
 
VertexFitter< 5 > * theFitter
 
TrackClusterizerInZtheTrackClusterizer
 
TrackFilterForPVFindingBasetheTrackFilter
 
VertexCompatibleWithBeam theVertexSelector
 

Detailed Description

Description: finds primary vertices, compatible with the beam line

Implementation: <Notes on="" implementation>="">

Definition at line 36 of file PrimaryVertexProducerAlgorithm.h.

Constructor & Destructor Documentation

PrimaryVertexProducerAlgorithm::PrimaryVertexProducerAlgorithm ( const edm::ParameterSet conf)
explicit

Definition at line 22 of file PrimaryVertexProducerAlgorithm.cc.

References algorithm(), fapply_finder, fFailsafe, fMinNdof, fUseBeamConstraint, fVerbose, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), KalmanTrimmedVertexFinder::setParameters(), theFinder, theFitter, theTrackClusterizer, and theTrackFilter.

Referenced by clone().

24  : theConfig(conf),
26  conf.getParameter<edm::ParameterSet>("PVSelParameters").getParameter<double>("maxDistanceToBeam"))
27 {
28  edm::LogInfo("PVDebugInfo")
29  << "PVSelParameters::maxDistanceToBeam = "
30  << conf.getParameter<edm::ParameterSet>("PVSelParameters").getParameter<double>("maxDistanceToBeam") << "\n";
31 
32 
33  fUseBeamConstraint = conf.getParameter<bool>("useBeamConstraint");
34  fVerbose = conf.getUntrackedParameter<bool>("verbose", false);
35  fMinNdof = conf.getParameter<double>("minNdof");
36  fFailsafe = true; //conf.getUntrackedParameter<bool>("failsafe",true);
37 
38 
39  // select and configure the track selection
40  std::string trackSelectionAlgorithm=conf.getParameter<edm::ParameterSet>("TkFilterParameters").getParameter<std::string>("algorithm");
41  if(trackSelectionAlgorithm=="filter"){
42  theTrackFilter= new TrackFilterForPVFinding( conf.getParameter<edm::ParameterSet>("TkFilterParameters") );
43  }else if (trackSelectionAlgorithm=="filterWithThreshold"){
45  }else{
46  throw VertexException("PrimaryVertexProducerAlgorithm: unknown track selection algorithm: " + trackSelectionAlgorithm);
47  }
48 
49 
50  // select and configure the track clusterizer
51  std::string clusteringAlgorithm=conf.getParameter<edm::ParameterSet>("TkClusParameters").getParameter<std::string>("algorithm");
52  if (clusteringAlgorithm=="gap"){
53  theTrackClusterizer = new GapClusterizerInZ(conf.getParameter<edm::ParameterSet>("TkClusParameters").getParameter<edm::ParameterSet>("TkGapClusParameters"));
54  }else if(clusteringAlgorithm=="DA"){
55  theTrackClusterizer = new DAClusterizerInZ(conf.getParameter<edm::ParameterSet>("TkClusParameters").getParameter<edm::ParameterSet>("TkDAClusParameters"));
56  }else{
57  throw VertexException("PrimaryVertexProducerAlgorithm: unknown clustering algorithm: " + clusteringAlgorithm);
58  }
59 
60  // select and configure the vertex fitter
61  std::string algorithm = conf.getParameter<std::string>("algorithm");
62  fapply_finder = false;
63  if (algorithm == "TrimmedKalmanFinder") {
64  fapply_finder = true;
65  theFinder.setParameters(conf.getParameter<edm::ParameterSet>("VtxFinderParameters"));
66  } else if (algorithm=="KalmanVertexFitter") {
68  } else if( algorithm=="AdaptiveVertexFitter") {
70  } else {
71  throw VertexException("PrimaryVertexProducerAlgorithm: unknown algorithm: " + algorithm);
72  }
73 
74  edm::LogInfo("PVDebugInfo")
75  << "Using " << algorithm << "\n";
76  edm::LogInfo("PVDebugInfo")
77  << "beam-constraint " << fUseBeamConstraint << "\n";
78 
79  edm::LogInfo("PVDebugInfo")
80  << "PV producer algorithm initialization: done" << "\n";
81 
82 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
< trclass="colgroup">< tdclass="colgroup"colspan=5 > Ecal cluster collections</td ></tr >< tr >< td >< ahref="classreco_1_1BasicCluster.html"> reco::BasicCluster</a ></td >< td >< ahref="DataFormats_EgammaReco.html"> reco::BasicClusterCollection</a ></td >< td >< ahref="#"> hybridSuperClusters</a ></td >< tdclass="description"> Basic clusters reconstructed with hybrid algorithm(barrel only)</td >< td >S.Rahatlou</td ></tr >< tr >< td >< a href
Common base class.
void setParameters(const edm::ParameterSet &)
TrackFilterForPVFindingBase * theTrackFilter
PrimaryVertexProducerAlgorithm::~PrimaryVertexProducerAlgorithm ( )

Definition at line 85 of file PrimaryVertexProducerAlgorithm.cc.

References theFitter, theTrackClusterizer, and theTrackFilter.

86 {
87  if (theFitter) delete theFitter;
88  if (theTrackFilter) delete theTrackFilter;
90 }
TrackFilterForPVFindingBase * theTrackFilter

Member Function Documentation

virtual PrimaryVertexProducerAlgorithm* PrimaryVertexProducerAlgorithm::clone ( void  ) const
inlinevirtual

Clone method

Implements VertexReconstructor.

Definition at line 55 of file PrimaryVertexProducerAlgorithm.h.

References PrimaryVertexProducerAlgorithm().

55  {
56  return new PrimaryVertexProducerAlgorithm(*this);
57  }
PrimaryVertexProducerAlgorithm(const edm::ParameterSet &)
std::vector< TransientVertex > PrimaryVertexProducerAlgorithm::vertices ( const std::vector< reco::TransientTrack > &  tracks) const
virtual

Find primary vertices

Implements VertexReconstructor.

Definition at line 99 of file PrimaryVertexProducerAlgorithm.cc.

100 {
101 
102  throw VertexException("PrimaryVertexProducerAlgorithm: cannot make a Primary Vertex without a beam spot constraint " );
103 
104  /* std::cout<< "PrimaryVertexProducer::vertices> Obsolete function, using dummy beamspot " << std::endl;
105  reco::BeamSpot dummyBeamSpot;
106  dummyBeamSpot.dummy();
107  return vertices(tracks,dummyBeamSpot); */
108  return std::vector<TransientVertex>();
109 }
Common base class.
std::vector< TransientVertex > PrimaryVertexProducerAlgorithm::vertices ( const std::vector< reco::TransientTrack > &  t,
const reco::BeamSpot  
) const
virtual

Reconstruct vertices, exploiting the beamspot constraint for the primary vertex

Reimplemented from VertexReconstructor.

Definition at line 113 of file PrimaryVertexProducerAlgorithm.cc.

References TrackClusterizerInZ::clusterize(), gather_cfg::cout, GlobalErrorBase< T, ErrorWeightType >::cxx(), GlobalErrorBase< T, ErrorWeightType >::cyy(), GlobalErrorBase< T, ErrorWeightType >::czz(), TransientVertex::degreesOfFreedom(), VertexState::error(), fapply_finder, fFailsafe, fMinNdof, fUseBeamConstraint, fVerbose, i, TransientVertex::isValid(), GlobalErrorBase< T, ErrorWeightType >::matrix(), TransientVertex::position(), TrackFilterForPVFindingBase::select(), VertexHigherPtSquared::sumPtSquared(), theFinder, theFitter, theTrackClusterizer, theTrackFilter, theVertexSelector, v, VertexFitter< N >::vertex(), KalmanTrimmedVertexFinder::vertices(), PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

115 {
116  bool validBS = true;
117  VertexState beamVertexState(beamSpot);
118  if ( (beamVertexState.error().cxx() <= 0.) ||
119  (beamVertexState.error().cyy() <= 0.) ||
120  (beamVertexState.error().czz() <= 0.) ) {
121  validBS = false;
122  edm::LogError("UnusableBeamSpot") << "Beamspot with invalid errors "<<beamVertexState.error().matrix();
123  }
124 
125  if ( fapply_finder) {
126  return theFinder.vertices( tracks );
127  }
128  std::vector<TransientVertex> pvs;
129 
130 
131  // select tracks
132  std::vector<TransientTrack> seltks = theTrackFilter->select( tracks );
133 
134 
135  // clusterize tracks in Z
136  std::vector< std::vector<reco::TransientTrack> > clusters = theTrackClusterizer->clusterize(seltks);
137  if (fVerbose){std::cout << " clustering returned "<< clusters.size() << " clusters from " << seltks.size() << " selected tracks" <<std::endl;}
138 
139 
140  // look for primary vertices in each cluster
141  std::vector<TransientVertex> pvCand;
142  int nclu=0;
143  for (std::vector< std::vector<reco::TransientTrack> >::const_iterator iclus
144  = clusters.begin(); iclus != clusters.end(); iclus++) {
145 
146 
148  if( fUseBeamConstraint && validBS &&((*iclus).size()>1) ){
149  if (fVerbose){std::cout << " constrained fit with "<< (*iclus).size() << " tracks" <<std::endl;}
150  v = theFitter->vertex(*iclus, beamSpot);
151  if (v.isValid() && (v.degreesOfFreedom()>=fMinNdof)) pvCand.push_back(v);
152 
153  if (fVerbose){
154  if (v.isValid()) std::cout << "x,y,z=" << v.position().x() <<" " << v.position().y() << " " << v.position().z() << std::endl;
155  else std::cout <<"Invalid fitted vertex\n";
156  }
157 
158  }else if((*iclus).size()>1){
159  if (fVerbose){std::cout << " unconstrained fit with "<< (*iclus).size() << " tracks" << std::endl;}
160 
161  v = theFitter->vertex(*iclus);
162  if (v.isValid() && (v.degreesOfFreedom()>=fMinNdof)) pvCand.push_back(v);
163 
164  if (fVerbose){
165  if (v.isValid()) std::cout << "x,y,z=" << v.position().x() <<" " << v.position().y() << " " << v.position().z() << std::endl;
166  else std::cout <<"Invalid fitted vertex\n";
167  }
168 
169  }
170 
171  nclu++;
172 
173  }// end of cluster loop
174 
175  if(fVerbose){
176  std::cout << "PrimaryVertexProducerAlgorithm::vertices candidates =" << pvCand.size() << std::endl;
177  }
178 
179 
180 
181  // select vertices compatible with beam
182  int npv=0;
183  for (std::vector<TransientVertex>::const_iterator ipv = pvCand.begin();
184  ipv != pvCand.end(); ipv++) {
185  if(fVerbose){
186  std::cout << "PrimaryVertexProducerAlgorithm::vertices cand " << npv++ << " sel=" <<
187  (validBS && theVertexSelector(*ipv,beamVertexState)) << " z=" << ipv->position().z() << std::endl;
188  }
189  if (!validBS || theVertexSelector(*ipv,beamVertexState)) pvs.push_back(*ipv);
190  }
191 
192 
193  if(pvs.size()>0){
194 
195  // sort vertices by pt**2 vertex (aka signal vertex tagging)
196  // sort(pvs.begin(), pvs.end(), VertexHigherPtSquared());
197 
198  // avoid re-evaluating sumptsquared for each comparison
200  std::vector< std::pair< double , unsigned int > > ptsqpv;
201  for(unsigned int i=0; i<pvs.size(); i++){ ptsqpv.push_back( std::make_pair(V.sumPtSquared(pvs.at(i)), i));}
202  std::stable_sort(ptsqpv.begin(), ptsqpv.end());
203  std::vector<TransientVertex> pvsorted( pvs.size());
204  for(unsigned int i=0; i<pvs.size(); i++){ pvsorted.push_back(pvs.at(ptsqpv[i].second));}
205  return pvsorted;
206 
207  }else{
208 
209  if ( fFailsafe
210  && (seltks.size()>1)
211  && ( (clusters.size()!=1) || ( (clusters.size()==1) && (clusters.begin()->size()<seltks.size())) )
212  )
213  {
214  // if no vertex was found, try fitting all selected tracks, unless this has already been tried
215  // in low/no pile-up situations with low multiplicity vertices, this can recover vertices lost in clustering
216  // with very small zSep. Only makes sense when used with a robust fitter, like the AdaptiveVertexFitter
218  if( fUseBeamConstraint && validBS ){
219  v = theFitter->vertex(seltks, beamSpot);
220  }else{
221  v = theFitter->vertex(seltks);
222  }
223  if (fVerbose){ std::cout << "PrimaryVertexProducerAlgorithm: failsafe vertex "
224  <<" tracks=" << seltks.size()
225  <<" valid()=" << v.isValid() << " ndof()=" << v.degreesOfFreedom()
226  <<" selected="<< theVertexSelector(v,beamVertexState) << std::endl; }
227  if ( v.isValid() && (v.degreesOfFreedom()>=fMinNdof) && (theVertexSelector(v,beamVertexState)) ) pvs.push_back(v);
228  }
229 
230  }
231 
232 
233  return pvs;
234 
235 }
int i
Definition: DBlmapReader.cc:9
virtual std::vector< TransientVertex > vertices(const std::vector< reco::TransientTrack > &tracks) const
T y() const
Definition: PV3DBase.h:62
virtual std::vector< std::vector< reco::TransientTrack > > clusterize(const std::vector< reco::TransientTrack > &tracks) const =0
virtual CachingVertex< N > vertex(const std::vector< reco::TransientTrack > &tracks) const =0
float degreesOfFreedom() const
GlobalPoint position() const
T z() const
Definition: PV3DBase.h:63
virtual std::vector< reco::TransientTrack > select(const std::vector< reco::TransientTrack > &tracks) const =0
TrackFilterForPVFindingBase * theTrackFilter
double sumPtSquared(const reco::Vertex &v) const
tuple tracks
Definition: testEve_cfg.py:39
tuple cout
Definition: gather_cfg.py:121
T x() const
Definition: PV3DBase.h:61
bool isValid() const
mathSSE::Vec4< T > v

Member Data Documentation

bool PrimaryVertexProducerAlgorithm::fapply_finder
private

Definition at line 72 of file PrimaryVertexProducerAlgorithm.h.

Referenced by PrimaryVertexProducerAlgorithm(), and vertices().

bool PrimaryVertexProducerAlgorithm::fFailsafe
private

Definition at line 73 of file PrimaryVertexProducerAlgorithm.h.

Referenced by PrimaryVertexProducerAlgorithm(), and vertices().

double PrimaryVertexProducerAlgorithm::fMinNdof
private

Definition at line 70 of file PrimaryVertexProducerAlgorithm.h.

Referenced by PrimaryVertexProducerAlgorithm(), and vertices().

bool PrimaryVertexProducerAlgorithm::fUseBeamConstraint
private

Definition at line 69 of file PrimaryVertexProducerAlgorithm.h.

Referenced by PrimaryVertexProducerAlgorithm(), and vertices().

bool PrimaryVertexProducerAlgorithm::fVerbose
private

Definition at line 68 of file PrimaryVertexProducerAlgorithm.h.

Referenced by PrimaryVertexProducerAlgorithm(), and vertices().

edm::ParameterSet PrimaryVertexProducerAlgorithm::theConfig
private

Definition at line 62 of file PrimaryVertexProducerAlgorithm.h.

KalmanTrimmedVertexFinder PrimaryVertexProducerAlgorithm::theFinder
private

Definition at line 65 of file PrimaryVertexProducerAlgorithm.h.

Referenced by PrimaryVertexProducerAlgorithm(), and vertices().

VertexFitter<5>* PrimaryVertexProducerAlgorithm::theFitter
private
TrackClusterizerInZ* PrimaryVertexProducerAlgorithm::theTrackClusterizer
private
TrackFilterForPVFindingBase* PrimaryVertexProducerAlgorithm::theTrackFilter
private
VertexCompatibleWithBeam PrimaryVertexProducerAlgorithm::theVertexSelector
private

Definition at line 66 of file PrimaryVertexProducerAlgorithm.h.

Referenced by vertices().