CMS 3D CMS Logo

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

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

Inheritance diagram for VertexFromTrackProducer:
edm::EDProducer edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

edm::ParameterSet config () const
 
virtual void produce (edm::Event &, const edm::EventSetup &) override
 
 VertexFromTrackProducer (const edm::ParameterSet &)
 
 ~VertexFromTrackProducer ()
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDProducer ()
 
- Public Member Functions inherited from edm::ProducerBase
 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
 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
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Public Attributes

edm::EDGetTokenT< reco::BeamSpotbeamSpotLabel
 
edm::EDGetTokenT< edm::View
< reco::RecoCandidate > > 
candidateToken
 
edm::InputTag trackLabel
 
edm::EDGetTokenT< edm::View
< reco::Track > > 
trackToken
 
edm::EDGetTokenT
< trigger::TriggerFilterObjectWithRefs
triggerFilterElectronsSrc
 
edm::EDGetTokenT
< trigger::TriggerFilterObjectWithRefs
triggerFilterMuonsSrc
 
edm::EDGetTokenT< edm::View
< reco::Vertex > > 
vertexLabel
 

Private Attributes

bool fIsRecoCandidate
 
bool fUseBeamSpot
 
bool fUseTriggerFilterElectrons
 
bool fUseTriggerFilterMuons
 
bool fUseVertex
 
bool fVerbose
 
edm::ParameterSet theConfig
 

Additional Inherited Members

- Public Types inherited from edm::EDProducer
typedef EDProducer ModuleType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Static Public Member Functions inherited from edm::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
- 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: produces a primary vertex extrapolating the track of a candidate on the beam axis

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

Definition at line 44 of file VertexFromTrackProducer.h.

Constructor & Destructor Documentation

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

Definition at line 27 of file VertexFromTrackProducer.cc.

References beamSpotLabel, candidateToken, fIsRecoCandidate, fUseBeamSpot, fUseTriggerFilterElectrons, fUseTriggerFilterMuons, fUseVertex, fVerbose, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), trackLabel, trackToken, triggerFilterElectronsSrc, triggerFilterMuonsSrc, and vertexLabel.

28  : theConfig(conf)
29 {
30  edm::LogInfo("PVDebugInfo")
31  << "Initializing VertexFromTrackProducer" << "\n";
32  fVerbose = conf.getUntrackedParameter<bool>("verbose", false);
33  trackLabel = conf.getParameter<edm::InputTag>("trackLabel");
34  trackToken = consumes<edm::View<reco::Track> >(trackLabel);
35  candidateToken = consumes<edm::View<reco::RecoCandidate> >(trackLabel);
36  fIsRecoCandidate = conf.getParameter<bool>("isRecoCandidate");
37  fUseBeamSpot = conf.getParameter<bool>("useBeamSpot");
38  fUseVertex = conf.getParameter<bool>("useVertex");
39  fUseTriggerFilterElectrons = conf.getParameter<bool>("useTriggerFilterElectrons");
40  fUseTriggerFilterMuons = conf.getParameter<bool>("useTriggerFilterMuons");
41  triggerFilterElectronsSrc = consumes<trigger::TriggerFilterObjectWithRefs>(conf.getParameter<edm::InputTag>("triggerFilterElectronsSrc"));
42  triggerFilterMuonsSrc = consumes<trigger::TriggerFilterObjectWithRefs>(conf.getParameter<edm::InputTag>("triggerFilterMuonsSrc"));
43  vertexLabel = consumes<edm::View<reco::Vertex> >(conf.getParameter<edm::InputTag>("vertexLabel"));
44  beamSpotLabel = consumes<reco::BeamSpot>(conf.getParameter<edm::InputTag>("beamSpotLabel"));
45 
46  produces<reco::VertexCollection>();
47 
48 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
edm::EDGetTokenT< trigger::TriggerFilterObjectWithRefs > triggerFilterElectronsSrc
edm::EDGetTokenT< reco::BeamSpot > beamSpotLabel
edm::EDGetTokenT< edm::View< reco::Vertex > > vertexLabel
edm::EDGetTokenT< edm::View< reco::RecoCandidate > > candidateToken
edm::EDGetTokenT< edm::View< reco::Track > > trackToken
edm::EDGetTokenT< trigger::TriggerFilterObjectWithRefs > triggerFilterMuonsSrc
VertexFromTrackProducer::~VertexFromTrackProducer ( )

Definition at line 51 of file VertexFromTrackProducer.cc.

51 {}

Member Function Documentation

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

Definition at line 52 of file VertexFromTrackProducer.h.

References theConfig.

52 { return theConfig; }
void VertexFromTrackProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overridevirtual

Implements edm::EDProducer.

Definition at line 59 of file VertexFromTrackProducer.cc.

References SiPixelRawToDigiRegional_cfi::beamSpot, beamSpotLabel, candidateToken, gather_cfg::cout, fIsRecoCandidate, fUseBeamSpot, fUseTriggerFilterElectrons, fUseTriggerFilterMuons, fUseVertex, fVerbose, edm::Event::getByToken(), i, edm::HandleBase::isValid(), reco::BeamSpot::position(), reco::Vertex::position(), RecoTauCleanerPlugins::pt, edm::Event::put(), query::result, trackToken, trigger::TriggerElectron, triggerFilterElectronsSrc, triggerFilterMuonsSrc, trigger::TriggerMuon, findQualityFiles::v, vertexLabel, reco::Vertex::xError(), reco::Vertex::yError(), and reco::Vertex::zError().

60 {
61  using namespace edm;
62 
63  std::auto_ptr<reco::VertexCollection> result(new reco::VertexCollection);
65 
66  math::XYZPoint vertexPoint;
67  bool vertexAvailable = false;
68 
69  // get the BeamSpot
70  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
71  iEvent.getByToken(beamSpotLabel,recoBeamSpotHandle);
72  if (recoBeamSpotHandle.isValid()){
73  reco::BeamSpot beamSpot = *recoBeamSpotHandle;
74  vertexPoint = beamSpot.position();
75  }else{
76  edm::LogError("UnusableBeamSpot") << "No beam spot found in Event";
77  }
78 
79  if(fUseVertex)
80  {
81  // get the Vertex
82  edm::Handle<edm::View<reco::Vertex> > recoVertexHandle;
83  iEvent.getByToken(vertexLabel,recoVertexHandle);
84  if ((recoVertexHandle.isValid()) && (recoVertexHandle->size()>0)){
85  reco::Vertex vertex = recoVertexHandle->at(0);
86  vertexPoint = vertex.position();
87  vertexAvailable = true;
88  }else {
89  edm::LogInfo("UnusableVertex")
90  << "No vertex found in Event, beam spot used instaed" << "\n";
91  }
92  }
93 
94  const reco::Track* track = 0;
96  {
98  iEvent.getByToken(candidateToken, candidateHandle);
99  if ((candidateHandle.isValid())&&(candidateHandle->size()>0)){
100  double maxpt=0.;
101  unsigned i_maxpt=0;
102  for (unsigned i = 0; i < candidateHandle->size(); ++i) {
103  double pt=candidateHandle->ptrAt(i)->pt();
104  if(pt>maxpt)
105  {
106  i_maxpt=i;
107  maxpt=pt;
108  }
109  }
110  track = dynamic_cast<const reco::Track*>(candidateHandle->ptrAt(i_maxpt)->bestTrack());
111  }
112  }
113  else if(fUseTriggerFilterElectrons) {
115  iEvent.getByToken(triggerFilterElectronsSrc, triggerfilter);
116  std::vector<reco::ElectronRef> recocandidates;
117  triggerfilter->getObjects(trigger::TriggerElectron,recocandidates);
118  if ((recocandidates.size()>0)){
119  double maxpt=0.;
120  unsigned i_maxpt=0;
121  for (unsigned i = 0; i < recocandidates.size(); ++i) {
122  double pt=recocandidates.at(i)->pt();
123  if(pt>maxpt)
124  {
125  i_maxpt=i;
126  maxpt=pt;
127  }
128  track = dynamic_cast<const reco::Track*>(recocandidates.at(i_maxpt)->bestTrack());
129  }
130  }
131  }
132  else if(fUseTriggerFilterMuons) {
134  iEvent.getByToken(triggerFilterMuonsSrc, triggerfilter);
135  std::vector<reco::RecoChargedCandidateRef> recocandidates;
136  triggerfilter->getObjects(trigger::TriggerMuon,recocandidates);
137  if ((recocandidates.size()>0)){
138  double maxpt=0.;
139  unsigned i_maxpt=0;
140  for (unsigned i = 0; i < recocandidates.size(); ++i) {
141  double pt=recocandidates.at(i)->pt();
142  if(pt>maxpt)
143  {
144  i_maxpt=i;
145  maxpt=pt;
146  }
147  track = dynamic_cast<const reco::Track*>(recocandidates.at(i_maxpt)->bestTrack());
148  }
149  }
150  }
151  else {
153  iEvent.getByToken(trackToken, trackHandle);
154  if ((trackHandle.isValid())&&(trackHandle->size()>0)){
155  double maxpt=0.;
156  unsigned i_maxpt=0;
157  for (unsigned i = 0; i < trackHandle->size(); ++i) {
158  double pt=trackHandle->ptrAt(i)->pt();
159  if(pt>maxpt)
160  {
161  i_maxpt=i;
162  maxpt=pt;
163  }
164  }
165  track = dynamic_cast<const reco::Track*>(&*trackHandle->ptrAt(i_maxpt));
166  }
167  }
168 
169  if(track) {
170  if(fUseBeamSpot || (fUseVertex && vertexAvailable) ) {
171  vertexPoint.SetZ(vertexPoint.z()+track->dz(vertexPoint));
172  }
173  else {
174  vertexPoint.SetZ(track->vz());
175  }
176  }
177  math::Error<3>::type noErrors;
178  reco::Vertex v(vertexPoint, noErrors);
179  vColl.push_back(v);
180 
181  // provide beamspot or primary vertex if no candidate found
182  //if(vColl.size()==0)
183  //{
184  // math::Error<3>::type noErrors;
185  // reco::Vertex v(vertexPoint, noErrors);
186  // vColl.push_back(v);
187  //}
188 
189  if(fVerbose){
190  int ivtx=0;
191  for(reco::VertexCollection::const_iterator v=vColl.begin();
192  v!=vColl.end(); ++v){
193  std::cout << "recvtx "<< ivtx++
194  << " x " << std::setw(6) << v->position().x()
195  << " dx " << std::setw(6) << v->xError()
196  << " y " << std::setw(6) << v->position().y()
197  << " dy " << std::setw(6) << v->yError()
198  << " z " << std::setw(6) << v->position().z()
199  << " dz " << std::setw(6) << v->zError()
200  << std::endl;
201  }
202  }
203 
204 
205  *result = vColl;
206  iEvent.put(result);
207 
208 }
int i
Definition: DBlmapReader.cc:9
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
edm::EDGetTokenT< trigger::TriggerFilterObjectWithRefs > triggerFilterElectronsSrc
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
ErrorD< N >::type type
Definition: Error.h:39
const Point & position() const
position
Definition: Vertex.h:106
edm::EDGetTokenT< reco::BeamSpot > beamSpotLabel
edm::EDGetTokenT< edm::View< reco::Vertex > > vertexLabel
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
tuple result
Definition: query.py:137
edm::EDGetTokenT< edm::View< reco::RecoCandidate > > candidateToken
bool isValid() const
Definition: HandleBase.h:76
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
edm::EDGetTokenT< edm::View< reco::Track > > trackToken
edm::EDGetTokenT< trigger::TriggerFilterObjectWithRefs > triggerFilterMuonsSrc
tuple cout
Definition: gather_cfg.py:121
const Point & position() const
position
Definition: BeamSpot.h:62

Member Data Documentation

edm::EDGetTokenT<reco::BeamSpot> VertexFromTrackProducer::beamSpotLabel

Definition at line 59 of file VertexFromTrackProducer.h.

Referenced by produce(), and VertexFromTrackProducer().

edm::EDGetTokenT<edm::View<reco::RecoCandidate> > VertexFromTrackProducer::candidateToken

Definition at line 55 of file VertexFromTrackProducer.h.

Referenced by produce(), and VertexFromTrackProducer().

bool VertexFromTrackProducer::fIsRecoCandidate
private

Definition at line 63 of file VertexFromTrackProducer.h.

Referenced by produce(), and VertexFromTrackProducer().

bool VertexFromTrackProducer::fUseBeamSpot
private

Definition at line 64 of file VertexFromTrackProducer.h.

Referenced by produce(), and VertexFromTrackProducer().

bool VertexFromTrackProducer::fUseTriggerFilterElectrons
private

Definition at line 66 of file VertexFromTrackProducer.h.

Referenced by produce(), and VertexFromTrackProducer().

bool VertexFromTrackProducer::fUseTriggerFilterMuons
private

Definition at line 66 of file VertexFromTrackProducer.h.

Referenced by produce(), and VertexFromTrackProducer().

bool VertexFromTrackProducer::fUseVertex
private

Definition at line 65 of file VertexFromTrackProducer.h.

Referenced by produce(), and VertexFromTrackProducer().

bool VertexFromTrackProducer::fVerbose
private

Definition at line 68 of file VertexFromTrackProducer.h.

Referenced by produce(), and VertexFromTrackProducer().

edm::ParameterSet VertexFromTrackProducer::theConfig
private

Definition at line 67 of file VertexFromTrackProducer.h.

Referenced by config().

edm::InputTag VertexFromTrackProducer::trackLabel

Definition at line 53 of file VertexFromTrackProducer.h.

Referenced by VertexFromTrackProducer().

edm::EDGetTokenT<edm::View<reco::Track> > VertexFromTrackProducer::trackToken

Definition at line 54 of file VertexFromTrackProducer.h.

Referenced by produce(), and VertexFromTrackProducer().

edm::EDGetTokenT<trigger::TriggerFilterObjectWithRefs> VertexFromTrackProducer::triggerFilterElectronsSrc

Definition at line 56 of file VertexFromTrackProducer.h.

Referenced by produce(), and VertexFromTrackProducer().

edm::EDGetTokenT<trigger::TriggerFilterObjectWithRefs> VertexFromTrackProducer::triggerFilterMuonsSrc

Definition at line 57 of file VertexFromTrackProducer.h.

Referenced by produce(), and VertexFromTrackProducer().

edm::EDGetTokenT<edm::View<reco::Vertex> > VertexFromTrackProducer::vertexLabel

Definition at line 58 of file VertexFromTrackProducer.h.

Referenced by produce(), and VertexFromTrackProducer().