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 #ifdef __GXX_EXPERIMENTAL_CXX0X__
49  else if(clusteringAlgorithm == "DA_vect") {
50  theTrackClusterizer = new DAClusterizerInZ_vect(conf.getParameter<edm::ParameterSet>("TkClusParameters").getParameter<edm::ParameterSet>("TkDAClusParameters"));
51  }
52 #endif
53 
54 
55  else{
56  throw VertexException("PrimaryVertexProducerAlgorithm: unknown clustering algorithm: " + clusteringAlgorithm);
57  }
58 
59 
60  // select and configure the vertex fitters
61  if (conf.exists("vertexCollections")){
62  std::vector<edm::ParameterSet> vertexCollections =conf.getParameter< std::vector<edm::ParameterSet> >("vertexCollections");
63 
64  for( std::vector< edm::ParameterSet >::const_iterator algoconf = vertexCollections.begin(); algoconf != vertexCollections.end(); algoconf++){
65 
67  std::string fitterAlgorithm = algoconf->getParameter<std::string>("algorithm");
68  if (fitterAlgorithm=="KalmanVertexFitter") {
69  algorithm.fitter= new KalmanVertexFitter();
70  } else if( fitterAlgorithm=="AdaptiveVertexFitter") {
71  algorithm.fitter= new AdaptiveVertexFitter();
72  } else {
73  throw VertexException("PrimaryVertexProducerAlgorithm: unknown algorithm: " + fitterAlgorithm);
74  }
75  algorithm.label = algoconf->getParameter<std::string>("label");
76  algorithm.minNdof = algoconf->getParameter<double>("minNdof");
77  algorithm.useBeamConstraint=algoconf->getParameter<bool>("useBeamConstraint");
78  algorithm.vertexSelector=new VertexCompatibleWithBeam(VertexDistanceXY(), algoconf->getParameter<double>("maxDistanceToBeam"));
79  algorithms.push_back(algorithm);
80 
81  }
82  }else{
83  edm::LogWarning("MisConfiguration")<<"this module's configuration has changed, please update to have a vertexCollections=cms.VPSet parameter.";
84 
86  std::string fitterAlgorithm = conf.getParameter<std::string>("algorithm");
87  if (fitterAlgorithm=="KalmanVertexFitter") {
88  algorithm.fitter= new KalmanVertexFitter();
89  } else if( fitterAlgorithm=="AdaptiveVertexFitter") {
90  algorithm.fitter= new AdaptiveVertexFitter();
91  } else {
92  throw VertexException("PrimaryVertexProducerAlgorithm: unknown algorithm: " + fitterAlgorithm);
93  }
94  algorithm.label = "";
95  algorithm.minNdof = conf.getParameter<double>("minNdof");
96  algorithm.useBeamConstraint=conf.getParameter<bool>("useBeamConstraint");
97 
98  algorithm.vertexSelector=new VertexCompatibleWithBeam(VertexDistanceXY(), conf.getParameter<edm::ParameterSet>("PVSelParameters").getParameter<double>("maxDistanceToBeam"));
99 
100  algorithms.push_back(algorithm);
101  }
102 
103 }
104 
105 
107 {
108  if (theTrackFilter) delete theTrackFilter;
110  for( std::vector <algo>::const_iterator algorithm=algorithms.begin(); algorithm!=algorithms.end(); algorithm++){
111  if (algorithm->fitter) delete algorithm->fitter;
112  if (algorithm->vertexSelector) delete algorithm->vertexSelector;
113  }
114 }
115 
116 
117 
118 
119 
120 //
121 // member functions
122 //
123 
124 // obsolete method, unfortunately required through inheritance from VertexReconstructor
125 std::vector<TransientVertex>
126 PrimaryVertexProducerAlgorithm::vertices(const std::vector<reco::TransientTrack> & tracks) const
127 {
128 
129  throw VertexException("PrimaryVertexProducerAlgorithm: cannot make a Primary Vertex without a beam spot" );
130 
131  return std::vector<TransientVertex>();
132 }
133 
134 
135 std::vector<TransientVertex>
136 PrimaryVertexProducerAlgorithm::vertices(const std::vector<reco::TransientTrack> & t_tks,
137  const reco::BeamSpot & beamSpot,
138  const std::string& label
139  ) const
140 {
141 
142 
143 
144 
145 
146  bool validBS = true;
147  VertexState beamVertexState(beamSpot);
148  if ( (beamVertexState.error().cxx() <= 0.) ||
149  (beamVertexState.error().cyy() <= 0.) ||
150  (beamVertexState.error().czz() <= 0.) ) {
151  validBS = false;
152  edm::LogError("UnusableBeamSpot") << "Beamspot with invalid errors "<<beamVertexState.error().matrix();
153  }
154 
155 
156 // // get RECO tracks from the event
157 // // `tks` can be used as a ptr to a reco::TrackCollection
158 // edm::Handle<reco::TrackCollection> tks;
159 // iEvent.getByLabel(trackLabel, tks);
160 
161 
162  // select tracks
163  std::vector<reco::TransientTrack> seltks = theTrackFilter->select( t_tks );
164 
165 
166  // clusterize tracks in Z
167  std::vector< std::vector<reco::TransientTrack> > clusters = theTrackClusterizer->clusterize(seltks);
168  if (fVerbose){std::cout << " clustering returned "<< clusters.size() << " clusters from " << seltks.size() << " selected tracks" <<std::endl;}
169 
170 
171  // vertex fits
172  for( std::vector <algo>::const_iterator algorithm=algorithms.begin(); algorithm!=algorithms.end(); algorithm++){
173  if ( ! (algorithm->label == label) )continue;
174 
175  //std::auto_ptr<reco::VertexCollection> result(new reco::VertexCollection);
176  // reco::VertexCollection vColl;
177 
178 
179  std::vector<TransientVertex> pvs;
180  for (std::vector< std::vector<reco::TransientTrack> >::const_iterator iclus
181  = clusters.begin(); iclus != clusters.end(); iclus++) {
182 
183 
185  if( algorithm->useBeamConstraint && validBS &&((*iclus).size()>1) ){
186 
187  v = algorithm->fitter->vertex(*iclus, beamSpot);
188 
189  }else if( !(algorithm->useBeamConstraint) && ((*iclus).size()>1) ) {
190 
191  v = algorithm->fitter->vertex(*iclus);
192 
193  }// else: no fit ==> v.isValid()=False
194 
195 
196  if (fVerbose){
197  if (v.isValid()) std::cout << "x,y,z=" << v.position().x() <<" " << v.position().y() << " " << v.position().z() << std::endl;
198  else std::cout <<"Invalid fitted vertex\n";
199  }
200 
201  if (v.isValid()
202  && (v.degreesOfFreedom()>=algorithm->minNdof)
203  && (!validBS || (*(algorithm->vertexSelector))(v,beamVertexState))
204  ) pvs.push_back(v);
205  }// end of cluster loop
206 
207  if(fVerbose){
208  std::cout << "PrimaryVertexProducerAlgorithm::vertices candidates =" << pvs.size() << std::endl;
209  }
210 
211 
212 
213 
214 
215  // sort vertices by pt**2 vertex (aka signal vertex tagging)
216  if(pvs.size()>1){
217  sort(pvs.begin(), pvs.end(), VertexHigherPtSquared());
218  }
219 
220  return pvs;
221  }
222 
223  std::vector<TransientVertex> dummy;
224  return dummy;//avoid compiler warning, should never be here
225 }
226 
227 
228 
229 
230 
231 
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.
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 &)
tuple conf
Definition: dbtoconf.py:185
TrackFilterForPVFindingBase * theTrackFilter
tuple tracks
Definition: testEve_cfg.py:39
GlobalError error() const
Definition: VertexState.h:55
tuple cout
Definition: gather_cfg.py:121
T x() const
Definition: PV3DBase.h:62
bool isValid() const