CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PrimaryVertexProducerAlgorithm.cc
Go to the documentation of this file.
3 
9 
13 
18 
19 
21  :theConfig(conf)
22 {
23 
24  fVerbose = conf.getUntrackedParameter<bool>("verbose", false);
25  trackLabel = conf.getParameter<edm::InputTag>("TrackLabel");
26  beamSpotLabel = conf.getParameter<edm::InputTag>("beamSpotLabel");
27 
28 
29  // select and configure the track selection
30  std::string trackSelectionAlgorithm=conf.getParameter<edm::ParameterSet>("TkFilterParameters").getParameter<std::string>("algorithm");
31  if(trackSelectionAlgorithm=="filter"){
32  theTrackFilter= new TrackFilterForPVFinding( conf.getParameter<edm::ParameterSet>("TkFilterParameters") );
33  }else if (trackSelectionAlgorithm=="filterWithThreshold"){
35  }else{
36  throw VertexException("PrimaryVertexProducerAlgorithm: unknown track selection algorithm: " + trackSelectionAlgorithm);
37  }
38 
39 
40  // select and configure the track clusterizer
41  std::string clusteringAlgorithm=conf.getParameter<edm::ParameterSet>("TkClusParameters").getParameter<std::string>("algorithm");
42  if (clusteringAlgorithm=="gap"){
43  theTrackClusterizer = new GapClusterizerInZ(conf.getParameter<edm::ParameterSet>("TkClusParameters").getParameter<edm::ParameterSet>("TkGapClusParameters"));
44  }else if(clusteringAlgorithm=="DA"){
45  theTrackClusterizer = new DAClusterizerInZ(conf.getParameter<edm::ParameterSet>("TkClusParameters").getParameter<edm::ParameterSet>("TkDAClusParameters"));
46  }
47  // provide the vectorized version of the clusterizer, if supported by the build
48  else if(clusteringAlgorithm == "DA_vect") {
49  theTrackClusterizer = new DAClusterizerInZ_vect(conf.getParameter<edm::ParameterSet>("TkClusParameters").getParameter<edm::ParameterSet>("TkDAClusParameters"));
50  }
51 
52 
53  else{
54  throw VertexException("PrimaryVertexProducerAlgorithm: unknown clustering algorithm: " + clusteringAlgorithm);
55  }
56 
57 
58  // select and configure the vertex fitters
59  if (conf.exists("vertexCollections")){
60  std::vector<edm::ParameterSet> vertexCollections =conf.getParameter< std::vector<edm::ParameterSet> >("vertexCollections");
61 
62  for( std::vector< edm::ParameterSet >::const_iterator algoconf = vertexCollections.begin(); algoconf != vertexCollections.end(); algoconf++){
63 
65  std::string fitterAlgorithm = algoconf->getParameter<std::string>("algorithm");
66  if (fitterAlgorithm=="KalmanVertexFitter") {
67  algorithm.fitter= new KalmanVertexFitter();
68  } else if( fitterAlgorithm=="AdaptiveVertexFitter") {
69  algorithm.fitter= new AdaptiveVertexFitter();
70  } else {
71  throw VertexException("PrimaryVertexProducerAlgorithm: unknown algorithm: " + fitterAlgorithm);
72  }
73  algorithm.label = algoconf->getParameter<std::string>("label");
74  algorithm.minNdof = algoconf->getParameter<double>("minNdof");
75  algorithm.useBeamConstraint=algoconf->getParameter<bool>("useBeamConstraint");
76  algorithm.vertexSelector=new VertexCompatibleWithBeam(VertexDistanceXY(), algoconf->getParameter<double>("maxDistanceToBeam"));
77  algorithms.push_back(algorithm);
78 
79  }
80  }else{
81  edm::LogWarning("MisConfiguration")<<"this module's configuration has changed, please update to have a vertexCollections=cms.VPSet parameter.";
82 
84  std::string fitterAlgorithm = conf.getParameter<std::string>("algorithm");
85  if (fitterAlgorithm=="KalmanVertexFitter") {
86  algorithm.fitter= new KalmanVertexFitter();
87  } else if( fitterAlgorithm=="AdaptiveVertexFitter") {
88  algorithm.fitter= new AdaptiveVertexFitter();
89  } else {
90  throw VertexException("PrimaryVertexProducerAlgorithm: unknown algorithm: " + fitterAlgorithm);
91  }
92  algorithm.label = "";
93  algorithm.minNdof = conf.getParameter<double>("minNdof");
94  algorithm.useBeamConstraint=conf.getParameter<bool>("useBeamConstraint");
95 
96  algorithm.vertexSelector=new VertexCompatibleWithBeam(VertexDistanceXY(), conf.getParameter<edm::ParameterSet>("PVSelParameters").getParameter<double>("maxDistanceToBeam"));
97 
98  algorithms.push_back(algorithm);
99  }
100 
101 }
102 
103 
105 {
106  if (theTrackFilter) delete theTrackFilter;
108  for( std::vector <algo>::const_iterator algorithm=algorithms.begin(); algorithm!=algorithms.end(); algorithm++){
109  if (algorithm->fitter) delete algorithm->fitter;
110  if (algorithm->vertexSelector) delete algorithm->vertexSelector;
111  }
112 }
113 
114 
115 
116 
117 
118 //
119 // member functions
120 //
121 
122 // obsolete method, unfortunately required through inheritance from VertexReconstructor
123 std::vector<TransientVertex>
124 PrimaryVertexProducerAlgorithm::vertices(const std::vector<reco::TransientTrack> & tracks) const
125 {
126 
127  throw VertexException("PrimaryVertexProducerAlgorithm: cannot make a Primary Vertex without a beam spot" );
128 
129  return std::vector<TransientVertex>();
130 }
131 
132 
133 std::vector<TransientVertex>
134 PrimaryVertexProducerAlgorithm::vertices(const std::vector<reco::TransientTrack> & t_tks,
135  const reco::BeamSpot & beamSpot,
136  const std::string& label
137  ) const
138 {
139 
140 
141 
142 
143 
144  bool validBS = true;
145  VertexState beamVertexState(beamSpot);
146  if ( (beamVertexState.error().cxx() <= 0.) ||
147  (beamVertexState.error().cyy() <= 0.) ||
148  (beamVertexState.error().czz() <= 0.) ) {
149  validBS = false;
150  edm::LogError("UnusableBeamSpot") << "Beamspot with invalid errors "<<beamVertexState.error().matrix();
151  }
152 
153 
154 // // get RECO tracks from the event
155 // // `tks` can be used as a ptr to a reco::TrackCollection
156 // edm::Handle<reco::TrackCollection> tks;
157 // iEvent.getByLabel(trackLabel, tks);
158 
159 
160  // select tracks
161  std::vector<reco::TransientTrack> seltks = theTrackFilter->select( t_tks );
162 
163 
164  // clusterize tracks in Z
165  std::vector< std::vector<reco::TransientTrack> > clusters = theTrackClusterizer->clusterize(seltks);
166  if (fVerbose){std::cout << " clustering returned "<< clusters.size() << " clusters from " << seltks.size() << " selected tracks" <<std::endl;}
167 
168 
169  // vertex fits
170  for( std::vector <algo>::const_iterator algorithm=algorithms.begin(); algorithm!=algorithms.end(); algorithm++){
171  if ( ! (algorithm->label == label) )continue;
172 
173  //std::auto_ptr<reco::VertexCollection> result(new reco::VertexCollection);
174  // reco::VertexCollection vColl;
175 
176 
177  std::vector<TransientVertex> pvs;
178  for (std::vector< std::vector<reco::TransientTrack> >::const_iterator iclus
179  = clusters.begin(); iclus != clusters.end(); iclus++) {
180 
181 
183  if( algorithm->useBeamConstraint && validBS &&((*iclus).size()>1) ){
184 
185  v = algorithm->fitter->vertex(*iclus, beamSpot);
186 
187  }else if( !(algorithm->useBeamConstraint) && ((*iclus).size()>1) ) {
188 
189  v = algorithm->fitter->vertex(*iclus);
190 
191  }// else: no fit ==> v.isValid()=False
192 
193 
194  if (fVerbose){
195  if (v.isValid()) std::cout << "x,y,z=" << v.position().x() <<" " << v.position().y() << " " << v.position().z() << std::endl;
196  else std::cout <<"Invalid fitted vertex\n";
197  }
198 
199  if (v.isValid()
200  && (v.degreesOfFreedom()>=algorithm->minNdof)
201  && (!validBS || (*(algorithm->vertexSelector))(v,beamVertexState))
202  ) pvs.push_back(v);
203  }// end of cluster loop
204 
205  if(fVerbose){
206  std::cout << "PrimaryVertexProducerAlgorithm::vertices candidates =" << pvs.size() << std::endl;
207  }
208 
209 
210 
211 
212 
213  // sort vertices by pt**2 vertex (aka signal vertex tagging)
214  if(pvs.size()>1){
215  sort(pvs.begin(), pvs.end(), VertexHigherPtSquared());
216  }
217 
218  return pvs;
219  }
220 
221  std::vector<TransientVertex> dummy;
222  return dummy;//avoid compiler warning, should never be here
223 }
224 
225 
226 
227 
228 
229 
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
Common base class.
const AlgebraicSymMatrix33 & matrix() const
T y() const
Definition: PV3DBase.h:63
bool exists(std::string const &parameterName) const
checks if a parameter exists
virtual std::vector< std::vector< reco::TransientTrack > > clusterize(const std::vector< reco::TransientTrack > &tracks) const =0
virtual std::vector< TransientVertex > vertices(const std::vector< reco::TransientTrack > &tracks) const
float degreesOfFreedom() const
GlobalPoint position() const
T z() const
Definition: PV3DBase.h:64
virtual std::vector< reco::TransientTrack > select(const std::vector< reco::TransientTrack > &tracks) const =0
PrimaryVertexProducerAlgorithm(const edm::ParameterSet &)
TrackFilterForPVFindingBase * theTrackFilter
tuple tracks
Definition: testEve_cfg.py:39
GlobalError error() const
Definition: VertexState.h:55
tuple cout
Definition: gather_cfg.py:145
T x() const
Definition: PV3DBase.h:62
bool isValid() const