CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Member Functions | Private Attributes
PrimaryVertexProducer Class Reference

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

Inheritance diagram for PrimaryVertexProducer:
edm::stream::EDProducer<> edm::stream::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Classes

struct  algo
 

Public Member Functions

edm::ParameterSet config () const
 
 PrimaryVertexProducer (const edm::ParameterSet &)
 
virtual void produce (edm::Event &, const edm::EventSetup &)
 
 ~PrimaryVertexProducer ()
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
- Public Member Functions inherited from edm::stream::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDProducerBase ()
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (const std::string &iProcessName, std::vector< const char * > &oModuleLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Attributes

std::vector< algoalgorithms
 
edm::EDGetTokenT< reco::BeamSpotbsToken
 
bool fVerbose
 
edm::ParameterSet theConfig
 
TrackClusterizerInZtheTrackClusterizer
 
TrackFilterForPVFindingBasetheTrackFilter
 
edm::EDGetTokenT
< reco::TrackCollection
trkToken
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
typedef CacheContexts< T...> CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T...> HasAbility
 
typedef
CacheTypes::LuminosityBlockCache 
LuminosityBlockCache
 
typedef
LuminosityBlockContextT
< LuminosityBlockCache,
RunCache, GlobalCache
LuminosityBlockContext
 
typedef
CacheTypes::LuminosityBlockSummaryCache 
LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache,
GlobalCache
RunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 
- Public Types inherited from edm::stream::EDProducerBase
typedef EDProducerAdaptorBase ModuleType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::stream::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Description: steers tracker primary vertex reconstruction and storage

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

Definition at line 54 of file PrimaryVertexProducer.h.

Constructor & Destructor Documentation

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

Definition at line 20 of file PrimaryVertexProducer.cc.

References HLT_25ns14e33_v1_cff::algorithm, algorithms, bsToken, edm::ParameterSet::exists(), PrimaryVertexProducer::algo::fitter, fVerbose, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), PrimaryVertexProducer::algo::label, PrimaryVertexProducer::algo::minNdof, AlCaHLTBitMon_QueryRunRegistry::string, theTrackClusterizer, theTrackFilter, trkToken, PrimaryVertexProducer::algo::useBeamConstraint, HLT_25ns14e33_v1_cff::vertexCollections, and PrimaryVertexProducer::algo::vertexSelector.

21  :theConfig(conf)
22 {
23 
24  fVerbose = conf.getUntrackedParameter<bool>("verbose", false);
25  trkToken = consumes<reco::TrackCollection>(conf.getParameter<edm::InputTag>("TrackLabel"));
26  bsToken = consumes<reco::BeamSpot>(conf.getParameter<edm::InputTag>("beamSpotLabel"));
27 
28  // select and configure the track selection
29  std::string trackSelectionAlgorithm=conf.getParameter<edm::ParameterSet>("TkFilterParameters").getParameter<std::string>("algorithm");
30  if(trackSelectionAlgorithm=="filter"){
31  theTrackFilter= new TrackFilterForPVFinding( conf.getParameter<edm::ParameterSet>("TkFilterParameters") );
32  }else if (trackSelectionAlgorithm=="filterWithThreshold"){
34  }else{
35  throw VertexException("PrimaryVertexProducerAlgorithm: unknown track selection algorithm: " + trackSelectionAlgorithm);
36  }
37 
38 
39  // select and configure the track clusterizer
40  std::string clusteringAlgorithm=conf.getParameter<edm::ParameterSet>("TkClusParameters").getParameter<std::string>("algorithm");
41  if (clusteringAlgorithm=="gap"){
42  theTrackClusterizer = new GapClusterizerInZ(conf.getParameter<edm::ParameterSet>("TkClusParameters").getParameter<edm::ParameterSet>("TkGapClusParameters"));
43  }else if(clusteringAlgorithm=="DA"){
44  theTrackClusterizer = new DAClusterizerInZ(conf.getParameter<edm::ParameterSet>("TkClusParameters").getParameter<edm::ParameterSet>("TkDAClusParameters"));
45  }
46  // provide the vectorized version of the clusterizer, if supported by the build
47 #ifdef __GXX_EXPERIMENTAL_CXX0X__
48  else if(clusteringAlgorithm == "DA_vect") {
49  theTrackClusterizer = new DAClusterizerInZ_vect(conf.getParameter<edm::ParameterSet>("TkClusParameters").getParameter<edm::ParameterSet>("TkDAClusParameters"));
50  }
51 #endif
52 
53 
54  else{
55  throw VertexException("PrimaryVertexProducerAlgorithm: unknown clustering algorithm: " + clusteringAlgorithm);
56  }
57 
58 
59  // select and configure the vertex fitters
60  if (conf.exists("vertexCollections")){
61  std::vector<edm::ParameterSet> vertexCollections =conf.getParameter< std::vector<edm::ParameterSet> >("vertexCollections");
62 
63  for( std::vector< edm::ParameterSet >::const_iterator algoconf = vertexCollections.begin(); algoconf != vertexCollections.end(); algoconf++){
64 
66  std::string fitterAlgorithm = algoconf->getParameter<std::string>("algorithm");
67  if (fitterAlgorithm=="KalmanVertexFitter") {
68  algorithm.fitter= new KalmanVertexFitter();
69  } else if( fitterAlgorithm=="AdaptiveVertexFitter") {
70  algorithm.fitter= new AdaptiveVertexFitter();
71  } else {
72  throw VertexException("PrimaryVertexProducerAlgorithm: unknown algorithm: " + fitterAlgorithm);
73  }
74  algorithm.label = algoconf->getParameter<std::string>("label");
75  algorithm.minNdof = algoconf->getParameter<double>("minNdof");
76  algorithm.useBeamConstraint=algoconf->getParameter<bool>("useBeamConstraint");
77  algorithm.vertexSelector=new VertexCompatibleWithBeam(VertexDistanceXY(), algoconf->getParameter<double>("maxDistanceToBeam"));
78  algorithms.push_back(algorithm);
79 
80  produces<reco::VertexCollection>(algorithm.label);
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  produces<reco::VertexCollection>(algorithm.label);
102  }
103 
104 
105 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
edm::ParameterSet theConfig
edm::EDGetTokenT< reco::BeamSpot > bsToken
Common base class.
edm::EDGetTokenT< reco::TrackCollection > trkToken
TrackClusterizerInZ * theTrackClusterizer
bool exists(std::string const &parameterName) const
checks if a parameter exists
TrackFilterForPVFindingBase * theTrackFilter
std::vector< algo > algorithms
PrimaryVertexProducer::~PrimaryVertexProducer ( )

Definition at line 108 of file PrimaryVertexProducer.cc.

References HLT_25ns14e33_v1_cff::algorithm, algorithms, theTrackClusterizer, and theTrackFilter.

108  {
109  if (theTrackFilter) delete theTrackFilter;
111  for( std::vector <algo>::const_iterator algorithm=algorithms.begin(); algorithm!=algorithms.end(); algorithm++){
112  if (algorithm->fitter) delete algorithm->fitter;
113  if (algorithm->vertexSelector) delete algorithm->vertexSelector;
114  }
115 }
TrackClusterizerInZ * theTrackClusterizer
TrackFilterForPVFindingBase * theTrackFilter
std::vector< algo > algorithms

Member Function Documentation

edm::ParameterSet PrimaryVertexProducer::config ( void  ) const
inline

Definition at line 62 of file PrimaryVertexProducer.h.

References theConfig.

62 { return theConfig; }
edm::ParameterSet theConfig
void PrimaryVertexProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
virtual

Implements edm::stream::EDProducerBase.

Definition at line 119 of file PrimaryVertexProducer.cc.

References HLT_25ns14e33_v1_cff::algorithm, algorithms, SiPixelRawToDigiRegional_cfi::beamSpot, bsToken, TrackClusterizerInZ::clusterize(), HLT_25ns14e33_v1_cff::clusters, gather_cfg::cout, GlobalErrorBase< T, ErrorWeightType >::cxx(), GlobalErrorBase< T, ErrorWeightType >::cyy(), GlobalErrorBase< T, ErrorWeightType >::czz(), TransientVertex::degreesOfFreedom(), VertexState::error(), fVerbose, edm::EventSetup::get(), edm::Event::getByToken(), edm::HandleBase::isValid(), TransientVertex::isValid(), GlobalErrorBase< T, ErrorWeightType >::matrix(), reco::BeamSpot::position(), TransientVertex::position(), edm::Event::put(), query::result, reco::BeamSpot::rotatedCovariance3D(), TrackFilterForPVFindingBase::select(), python.multivaluedict::sort(), theTrackClusterizer, theTrackFilter, trkToken, findQualityFiles::v, PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

120 {
121 
122  // get the BeamSpot, it will alwys be needed, even when not used as a constraint
124  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
125  iEvent.getByToken(bsToken,recoBeamSpotHandle);
126  if (recoBeamSpotHandle.isValid()){
127  beamSpot = *recoBeamSpotHandle;
128  }else{
129  edm::LogError("UnusableBeamSpot") << "No beam spot available from EventSetup";
130  }
131 
132  bool validBS = true;
133  VertexState beamVertexState(beamSpot);
134  if ( (beamVertexState.error().cxx() <= 0.) ||
135  (beamVertexState.error().cyy() <= 0.) ||
136  (beamVertexState.error().czz() <= 0.) ) {
137  validBS = false;
138  edm::LogError("UnusableBeamSpot") << "Beamspot with invalid errors "<<beamVertexState.error().matrix();
139  }
140 
141 
142  // get RECO tracks from the event
143  // `tks` can be used as a ptr to a reco::TrackCollection
145  iEvent.getByToken(trkToken, tks);
146 
147 
148  // interface RECO tracks to vertex reconstruction
150  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder",theB);
151  std::vector<reco::TransientTrack> t_tks = (*theB).build(tks, beamSpot);
152  if(fVerbose) {std::cout << "RecoVertex/PrimaryVertexProducer"
153  << "Found: " << t_tks.size() << " reconstructed tracks" << "\n";
154  }
155 
156 
157  // select tracks
158  std::vector<reco::TransientTrack> && seltks = theTrackFilter->select( t_tks );
159 
160 
161  // clusterize tracks in Z
162  std::vector< std::vector<reco::TransientTrack> > && clusters = theTrackClusterizer->clusterize(seltks);
163  if (fVerbose){std::cout << " clustering returned "<< clusters.size() << " clusters from " << seltks.size() << " selected tracks" <<std::endl;}
164 
165 
166  // vertex fits
167  for( std::vector <algo>::const_iterator algorithm=algorithms.begin(); algorithm!=algorithms.end(); algorithm++){
168 
169 
170  std::auto_ptr<reco::VertexCollection> result(new reco::VertexCollection);
171  reco::VertexCollection & vColl = (*result);
172 
173 
174  std::vector<TransientVertex> pvs;
175  for (std::vector< std::vector<reco::TransientTrack> >::const_iterator iclus
176  = clusters.begin(); iclus != clusters.end(); iclus++) {
177 
178 
180  if( algorithm->useBeamConstraint && validBS &&((*iclus).size()>1) ){
181 
182  v = algorithm->fitter->vertex(*iclus, beamSpot);
183 
184  }else if( !(algorithm->useBeamConstraint) && ((*iclus).size()>1) ) {
185 
186  v = algorithm->fitter->vertex(*iclus);
187 
188  }// else: no fit ==> v.isValid()=False
189 
190 
191  if (fVerbose){
192  if (v.isValid()) std::cout << "x,y,z=" << v.position().x() <<" " << v.position().y() << " " << v.position().z() << std::endl;
193  else std::cout <<"Invalid fitted vertex\n";
194  }
195 
196  if (v.isValid()
197  && (v.degreesOfFreedom()>=algorithm->minNdof)
198  && (!validBS || (*(algorithm->vertexSelector))(v,beamVertexState))
199  ) pvs.push_back(v);
200  }// end of cluster loop
201 
202  if(fVerbose){
203  std::cout << "PrimaryVertexProducerAlgorithm::vertices candidates =" << pvs.size() << std::endl;
204  }
205 
206 
207  if (clusters.size()>2 && clusters.size() > 2*pvs.size())
208  edm::LogWarning("PrimaryVertexProducer") << "more than half of candidate vertices lost " << pvs.size() << ' ' << clusters.size();
209 
210  if (pvs.empty() && seltks.size()>5)
211  edm::LogWarning("PrimaryVertexProducer") << "no vertex found with " << seltks.size() << " tracks and " << clusters.size() <<" vertex-candidates";
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 
219 
220  // convert transient vertices returned by the theAlgo to (reco) vertices
221  for (std::vector<TransientVertex>::const_iterator iv = pvs.begin();
222  iv != pvs.end(); iv++) {
223  reco::Vertex v = *iv;
224  vColl.push_back(v);
225  }
226 
227  if (vColl.empty()) {
228  GlobalError bse(beamSpot.rotatedCovariance3D());
229  if ( (bse.cxx() <= 0.) ||
230  (bse.cyy() <= 0.) ||
231  (bse.czz() <= 0.) ) {
233  we(0,0)=10000; we(1,1)=10000; we(2,2)=10000;
234  vColl.push_back(reco::Vertex(beamSpot.position(), we,0.,0.,0));
235  if(fVerbose){
236  std::cout <<"RecoVertex/PrimaryVertexProducer: "
237  << "Beamspot with invalid errors "<<bse.matrix()<<std::endl;
238  std::cout << "Will put Vertex derived from dummy-fake BeamSpot into Event.\n";
239  }
240  } else {
241  vColl.push_back(reco::Vertex(beamSpot.position(),
242  beamSpot.rotatedCovariance3D(),0.,0.,0));
243  if(fVerbose){
244  std::cout <<"RecoVertex/PrimaryVertexProducer: "
245  << " will put Vertex derived from BeamSpot into Event.\n";
246  }
247  }
248  }
249 
250  if(fVerbose){
251  int ivtx=0;
252  for(reco::VertexCollection::const_iterator v=vColl.begin();
253  v!=vColl.end(); ++v){
254  std::cout << "recvtx "<< ivtx++
255  << "#trk " << std::setw(3) << v->tracksSize()
256  << " chi2 " << std::setw(4) << v->chi2()
257  << " ndof " << std::setw(3) << v->ndof()
258  << " x " << std::setw(6) << v->position().x()
259  << " dx " << std::setw(6) << v->xError()
260  << " y " << std::setw(6) << v->position().y()
261  << " dy " << std::setw(6) << v->yError()
262  << " z " << std::setw(6) << v->position().z()
263  << " dz " << std::setw(6) << v->zError()
264  << std::endl;
265  }
266  }
267 
268  iEvent.put(result, algorithm->label);
269  }
270 
271 }
edm::EDGetTokenT< reco::BeamSpot > bsToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
double zError() const
error on z
Definition: Vertex.h:118
edm::EDGetTokenT< reco::TrackCollection > trkToken
TrackClusterizerInZ * theTrackClusterizer
T y() const
Definition: PV3DBase.h:63
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
const Point & position() const
position
Definition: Vertex.h:106
virtual std::vector< std::vector< reco::TransientTrack > > clusterize(const std::vector< reco::TransientTrack > &tracks) const =0
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepSym< double, 3 > > AlgebraicSymMatrix33
float degreesOfFreedom() const
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
GlobalPoint position() const
T z() const
Definition: PV3DBase.h:64
tuple result
Definition: query.py:137
double chi2() const
chi-squares
Definition: Vertex.h:95
TrackFilterForPVFindingBase * theTrackFilter
virtual std::vector< reco::TransientTrack > select(const std::vector< reco::TransientTrack > &tracks) const =0
bool isValid() const
Definition: HandleBase.h:75
double ndof() const
Definition: Vertex.h:102
double xError() const
error on x
Definition: Vertex.h:114
const T & get() const
Definition: EventSetup.h:56
std::vector< algo > algorithms
tuple cout
Definition: gather_cfg.py:121
const Point & position() const
position
Definition: BeamSpot.h:62
Covariance3DMatrix rotatedCovariance3D() const
Definition: BeamSpot.cc:78
T x() const
Definition: PV3DBase.h:62
bool isValid() const
double yError() const
error on y
Definition: Vertex.h:116
size_t tracksSize() const
number of tracks
Definition: Vertex.cc:34

Member Data Documentation

std::vector< algo > PrimaryVertexProducer::algorithms
private

Definition at line 78 of file PrimaryVertexProducer.h.

Referenced by PrimaryVertexProducer(), produce(), and ~PrimaryVertexProducer().

edm::EDGetTokenT<reco::BeamSpot> PrimaryVertexProducer::bsToken
private

Definition at line 82 of file PrimaryVertexProducer.h.

Referenced by PrimaryVertexProducer(), and produce().

bool PrimaryVertexProducer::fVerbose
private

Definition at line 81 of file PrimaryVertexProducer.h.

Referenced by PrimaryVertexProducer(), and produce().

edm::ParameterSet PrimaryVertexProducer::theConfig
private

Definition at line 80 of file PrimaryVertexProducer.h.

Referenced by config().

TrackClusterizerInZ* PrimaryVertexProducer::theTrackClusterizer
private

Definition at line 67 of file PrimaryVertexProducer.h.

Referenced by PrimaryVertexProducer(), produce(), and ~PrimaryVertexProducer().

TrackFilterForPVFindingBase* PrimaryVertexProducer::theTrackFilter
private

Definition at line 66 of file PrimaryVertexProducer.h.

Referenced by PrimaryVertexProducer(), produce(), and ~PrimaryVertexProducer().

edm::EDGetTokenT<reco::TrackCollection> PrimaryVertexProducer::trkToken
private

Definition at line 83 of file PrimaryVertexProducer.h.

Referenced by PrimaryVertexProducer(), and produce().