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
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Public Attributes

edm::InputTag beamSpotLabel
 
edm::InputTag trackLabel
 
edm::InputTag triggerFilterElectronsSrc
 
edm::InputTag triggerFilterMuonsSrc
 
edm::InputTag 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 37 of file VertexFromTrackProducer.h.

Constructor & Destructor Documentation

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

Definition at line 33 of file VertexFromTrackProducer.cc.

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

34  : theConfig(conf)
35 {
36  edm::LogInfo("PVDebugInfo")
37  << "Initializing VertexFromTrackProducer" << "\n";
38  fVerbose = conf.getUntrackedParameter<bool>("verbose", false);
39  trackLabel = conf.getParameter<edm::InputTag>("trackLabel");
40  fIsRecoCandidate = conf.getParameter<bool>("isRecoCandidate");
41  fUseBeamSpot = conf.getParameter<bool>("useBeamSpot");
42  fUseVertex = conf.getParameter<bool>("useVertex");
43  fUseTriggerFilterElectrons = conf.getParameter<bool>("useTriggerFilterElectrons");
44  fUseTriggerFilterMuons = conf.getParameter<bool>("useTriggerFilterMuons");
45  triggerFilterElectronsSrc = conf.getParameter<edm::InputTag>("triggerFilterElectronsSrc");
46  triggerFilterMuonsSrc = conf.getParameter<edm::InputTag>("triggerFilterMuonsSrc");
47  vertexLabel = conf.getParameter<edm::InputTag>("vertexLabel");
48  beamSpotLabel = conf.getParameter<edm::InputTag>("beamSpotLabel");
49 
50  produces<reco::VertexCollection>();
51 
52 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
VertexFromTrackProducer::~VertexFromTrackProducer ( )

Definition at line 55 of file VertexFromTrackProducer.cc.

55 {}

Member Function Documentation

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

Definition at line 45 of file VertexFromTrackProducer.h.

References theConfig.

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

Implements edm::EDProducer.

Definition at line 63 of file VertexFromTrackProducer.cc.

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

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

Member Data Documentation

edm::InputTag VertexFromTrackProducer::beamSpotLabel

Definition at line 50 of file VertexFromTrackProducer.h.

Referenced by produce(), and VertexFromTrackProducer().

bool VertexFromTrackProducer::fIsRecoCandidate
private

Definition at line 54 of file VertexFromTrackProducer.h.

Referenced by produce(), and VertexFromTrackProducer().

bool VertexFromTrackProducer::fUseBeamSpot
private

Definition at line 55 of file VertexFromTrackProducer.h.

Referenced by produce(), and VertexFromTrackProducer().

bool VertexFromTrackProducer::fUseTriggerFilterElectrons
private

Definition at line 57 of file VertexFromTrackProducer.h.

Referenced by produce(), and VertexFromTrackProducer().

bool VertexFromTrackProducer::fUseTriggerFilterMuons
private

Definition at line 57 of file VertexFromTrackProducer.h.

Referenced by produce(), and VertexFromTrackProducer().

bool VertexFromTrackProducer::fUseVertex
private

Definition at line 56 of file VertexFromTrackProducer.h.

Referenced by produce(), and VertexFromTrackProducer().

bool VertexFromTrackProducer::fVerbose
private

Definition at line 59 of file VertexFromTrackProducer.h.

Referenced by produce(), and VertexFromTrackProducer().

edm::ParameterSet VertexFromTrackProducer::theConfig
private

Definition at line 58 of file VertexFromTrackProducer.h.

Referenced by config().

edm::InputTag VertexFromTrackProducer::trackLabel

Definition at line 46 of file VertexFromTrackProducer.h.

Referenced by produce(), and VertexFromTrackProducer().

edm::InputTag VertexFromTrackProducer::triggerFilterElectronsSrc

Definition at line 47 of file VertexFromTrackProducer.h.

Referenced by produce(), and VertexFromTrackProducer().

edm::InputTag VertexFromTrackProducer::triggerFilterMuonsSrc

Definition at line 48 of file VertexFromTrackProducer.h.

Referenced by produce(), and VertexFromTrackProducer().

edm::InputTag VertexFromTrackProducer::vertexLabel

Definition at line 49 of file VertexFromTrackProducer.h.

Referenced by produce(), and VertexFromTrackProducer().