test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
VertexFromTrackProducer.cc
Go to the documentation of this file.
2 
6 
8 
13 
14 //using namespace reco;
15 
16 //
17 // constants, enums and typedefs
18 //
19 
20 //
21 // static data member definitions
22 //
23 
24 //
25 // constructors and destructor
26 //
28  trackToken( consumes<edm::View<reco::Track> >(conf.getParameter<edm::InputTag>("trackLabel")) ),
29  candidateToken( consumes<edm::View<reco::RecoCandidate> >(conf.getParameter<edm::InputTag>("trackLabel")) ),
30  triggerFilterElectronsSrc( consumes<trigger::TriggerFilterObjectWithRefs>(conf.getParameter<edm::InputTag>("triggerFilterElectronsSrc")) ),
31  triggerFilterMuonsSrc( consumes<trigger::TriggerFilterObjectWithRefs>(conf.getParameter<edm::InputTag>("triggerFilterMuonsSrc")) ),
32  vertexLabel( consumes<edm::View<reco::Vertex> >(conf.getParameter<edm::InputTag>("vertexLabel")) ),
33  beamSpotLabel( consumes<reco::BeamSpot>(conf.getParameter<edm::InputTag>("beamSpotLabel")) ),
34  fIsRecoCandidate( conf.getParameter<bool>("isRecoCandidate") ),
35  fUseBeamSpot( conf.getParameter<bool>("useBeamSpot") ),
36  fUseVertex( conf.getParameter<bool>("useVertex") ),
37  fUseTriggerFilterElectrons( conf.getParameter<bool>("useTriggerFilterElectrons") ),
38  fUseTriggerFilterMuons( conf.getParameter<bool>("useTriggerFilterMuons") ),
39  fVerbose( conf.getUntrackedParameter<bool>("verbose", false) )
40 {
41  edm::LogInfo("PVDebugInfo")
42  << "Initializing VertexFromTrackProducer" << "\n";
43 
44  produces<reco::VertexCollection>();
45 
46 }
47 
48 
50 
51 //
52 // member functions
53 //
54 
55 // ------------ method called to produce the data ------------
56 void
58 {
59  using namespace edm;
60 
61  std::unique_ptr<reco::VertexCollection> result(new reco::VertexCollection);
63 
64  math::XYZPoint vertexPoint;
65  bool vertexAvailable = false;
66 
67  // get the BeamSpot
68  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
69  iEvent.getByToken(beamSpotLabel,recoBeamSpotHandle);
70  if (recoBeamSpotHandle.isValid()){
71  reco::BeamSpot beamSpot = *recoBeamSpotHandle;
72  vertexPoint = beamSpot.position();
73  }else{
74  edm::LogError("UnusableBeamSpot") << "No beam spot found in Event";
75  }
76 
77  if(fUseVertex)
78  {
79  // get the Vertex
80  edm::Handle<edm::View<reco::Vertex> > recoVertexHandle;
81  iEvent.getByToken(vertexLabel,recoVertexHandle);
82  if ((recoVertexHandle.isValid()) && (recoVertexHandle->size()>0)){
83  reco::Vertex vertex = recoVertexHandle->at(0);
84  vertexPoint = vertex.position();
85  vertexAvailable = true;
86  }else {
87  edm::LogInfo("UnusableVertex")
88  << "No vertex found in Event, beam spot used instaed" << "\n";
89  }
90  }
91 
92  const reco::Track* track = 0;
94  {
96  iEvent.getByToken(candidateToken, candidateHandle);
97  if ((candidateHandle.isValid())&&(candidateHandle->size()>0)){
98  double maxpt=0.;
99  unsigned i_maxpt=0;
100  for (unsigned i = 0; i < candidateHandle->size(); ++i) {
101  double pt=candidateHandle->ptrAt(i)->pt();
102  if(pt>maxpt)
103  {
104  i_maxpt=i;
105  maxpt=pt;
106  }
107  }
108  track = dynamic_cast<const reco::Track*>(candidateHandle->ptrAt(i_maxpt)->bestTrack());
109  }
110  }
111  else if(fUseTriggerFilterElectrons) {
113  iEvent.getByToken(triggerFilterElectronsSrc, triggerfilter);
114  std::vector<reco::ElectronRef> recocandidates;
115  triggerfilter->getObjects(trigger::TriggerElectron,recocandidates);
116  if ((recocandidates.size()>0)){
117  double maxpt=0.;
118  unsigned i_maxpt=0;
119  for (unsigned i = 0; i < recocandidates.size(); ++i) {
120  double pt=recocandidates.at(i)->pt();
121  if(pt>maxpt)
122  {
123  i_maxpt=i;
124  maxpt=pt;
125  }
126  track = dynamic_cast<const reco::Track*>(recocandidates.at(i_maxpt)->bestTrack());
127  }
128  }
129  }
130  else if(fUseTriggerFilterMuons) {
132  iEvent.getByToken(triggerFilterMuonsSrc, triggerfilter);
133  std::vector<reco::RecoChargedCandidateRef> recocandidates;
134  triggerfilter->getObjects(trigger::TriggerMuon,recocandidates);
135  if ((recocandidates.size()>0)){
136  double maxpt=0.;
137  unsigned i_maxpt=0;
138  for (unsigned i = 0; i < recocandidates.size(); ++i) {
139  double pt=recocandidates.at(i)->pt();
140  if(pt>maxpt)
141  {
142  i_maxpt=i;
143  maxpt=pt;
144  }
145  track = dynamic_cast<const reco::Track*>(recocandidates.at(i_maxpt)->bestTrack());
146  }
147  }
148  }
149  else {
151  iEvent.getByToken(trackToken, trackHandle);
152  if ((trackHandle.isValid())&&(trackHandle->size()>0)){
153  double maxpt=0.;
154  unsigned i_maxpt=0;
155  for (unsigned i = 0; i < trackHandle->size(); ++i) {
156  double pt=trackHandle->ptrAt(i)->pt();
157  if(pt>maxpt)
158  {
159  i_maxpt=i;
160  maxpt=pt;
161  }
162  }
163  track = dynamic_cast<const reco::Track*>(&*trackHandle->ptrAt(i_maxpt));
164  }
165  }
166 
167  if(track) {
168  if(fUseBeamSpot || (fUseVertex && vertexAvailable) ) {
169  vertexPoint.SetZ(vertexPoint.z()+track->dz(vertexPoint));
170  }
171  else {
172  vertexPoint.SetZ(track->vz());
173  }
174  }
175  math::Error<3>::type noErrors;
176  reco::Vertex v(vertexPoint, noErrors);
177  vColl.push_back(v);
178 
179  // provide beamspot or primary vertex if no candidate found
180  //if(vColl.size()==0)
181  //{
182  // math::Error<3>::type noErrors;
183  // reco::Vertex v(vertexPoint, noErrors);
184  // vColl.push_back(v);
185  //}
186 
187  if(fVerbose){
188  int ivtx=0;
189  edm::LogInfo("PVDebugInfo")<< "Vertices by VertexFromTrackProducer: \n";
190  for(reco::VertexCollection::const_iterator v=vColl.begin();
191  v!=vColl.end(); ++v){
192  edm::LogInfo("PVDebugInfo")<< "\t"
193  << "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  << " \n ";
201  }
202  }
203 
204 
205  *result = vColl;
206  iEvent.put(std::move(result));
207 
208 }
209 
210 void
212 {
213 
215 
216  desc.add<bool>("isRecoCandidate",false)->setComment("If isRecoCandidate=True \"trackLabel\" is used and assumed to be collection of candidates.\nOtherwise it is assumed that \"trackLabel\" is collection of tracks and is used when useTriggerFilterElectrons=False and useTriggerFilterMuons=False");
217  desc.add<edm::InputTag>("trackLabel",edm::InputTag("hltL3MuonCandidates"))->setComment("Collection of tracks or candidates");
218  desc.add<bool>("useTriggerFilterElectrons",false)->setComment("Use leading electron passing \"triggerFilterElectronsSrc\" filter to determine z vertex position");
219  desc.add<edm::InputTag>("triggerFilterElectronsSrc",edm::InputTag("hltEle20CaloIdVTCaloIsoTTrkIdTTrkIsoL1JetTrackIsoFilter"))->setComment("Name of electron filter");
220  desc.add<bool>("useTriggerFilterMuons",true)->setComment("Use leading muon passing \"triggerFilterMuonsSrc\" filter to determine z vertex position");
221  desc.add<edm::InputTag>("triggerFilterMuonsSrc",edm::InputTag("hltSingleMuIsoL3IsoFiltered15"))->setComment("Name of muon filter");
222  desc.add<bool>("useBeamSpot",true)->setComment("Use beam spot for x/y vertex position");
223  desc.add<edm::InputTag>("beamSpotLabel",edm::InputTag("hltOnlineBeamSpot"))->setComment("Beamspot collection");
224  desc.add<bool>("useVertex",true)->setComment("Use vertex for x/y vertex position (beam spot is used when PV does not exit)");
225  desc.add<edm::InputTag>("vertexLabel",edm::InputTag("hltPixelVertices"))->setComment("Vertex collection");
226 
227  desc.addUntracked<bool>("verbose",false)->setComment("Switch on/off verbosity");
228  descriptions.setComment("This module produces vertex with z-coordinate determined with the highest-Pt lepton track and x/y-coordinates taken from BeamSpot/Vertex");
229  descriptions.add("hltVertexFromTrackProducer",desc);
230 
231 }
int i
Definition: DBlmapReader.cc:9
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
double zError() const
error on z
Definition: Vertex.h:123
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
ErrorD< N >::type type
Definition: Error.h:33
const Point & position() const
position
Definition: Vertex.h:109
const edm::EDGetTokenT< reco::BeamSpot > beamSpotLabel
tuple result
Definition: mps_fire.py:84
const edm::EDGetTokenT< edm::View< reco::RecoCandidate > > candidateToken
const edm::EDGetTokenT< trigger::TriggerFilterObjectWithRefs > triggerFilterElectronsSrc
int iEvent
Definition: GenABIO.cc:230
def move
Definition: eostools.py:510
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isValid() const
Definition: HandleBase.h:75
void setComment(std::string const &value)
double xError() const
error on x
Definition: Vertex.h:119
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
void add(std::string const &label, ParameterSetDescription const &psetDescription)
const edm::EDGetTokenT< edm::View< reco::Track > > trackToken
const edm::EDGetTokenT< trigger::TriggerFilterObjectWithRefs > triggerFilterMuonsSrc
const Point & position() const
position
Definition: BeamSpot.h:62
volatile std::atomic< bool > shutdown_flag false
VertexFromTrackProducer(const edm::ParameterSet &)
double yError() const
error on y
Definition: Vertex.h:121
virtual void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
const edm::EDGetTokenT< edm::View< reco::Vertex > > vertexLabel
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)