CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HIBestVertexProducer.cc
Go to the documentation of this file.
2 
7 
12 
13 #include <algorithm>
14 #include <iostream>
15 using namespace std;
16 using namespace edm;
17 
18 /*****************************************************************************/
20 (const edm::ParameterSet& ps) : theConfig(ps),
21  theBeamSpotTag(ps.getParameter<edm::InputTag>("beamSpotLabel")),
22  theMedianVertexCollection(ps.getParameter<edm::InputTag>("medianVertexCollection")),
23  theAdaptiveVertexCollection(ps.getParameter<edm::InputTag>("adaptiveVertexCollection"))
24 {
25  produces<reco::VertexCollection>();
26 }
27 
28 
29 /*****************************************************************************/
31 {
32 }
33 
34 /*****************************************************************************/
36 {
37 }
38 
39 /*****************************************************************************/
41 (edm::Event& ev, const edm::EventSetup& es)
42 {
43 
44  // 1. use best adaptive vertex preferentially
45  // 2. use median vertex in case where adaptive algorithm failed
46  // 3. use beamspot if netither vertexing method succeeds
47 
48  // New vertex collection
49  std::auto_ptr<reco::VertexCollection> newVertexCollection(new reco::VertexCollection);
50 
51  //** Get precise adaptive vertex **/
53  ev.getByLabel(theAdaptiveVertexCollection, vc1);
54  const reco::VertexCollection *vertices1 = vc1.product();
55 
56  if(vertices1->size()==0)
57  LogError("HeavyIonVertexing") << "adaptive vertex collection is empty!" << endl;
58 
59  if(vertices1->begin()->zError()<3) {
60 
61  reco::VertexCollection::const_iterator vertex1 = vertices1->begin();
62  newVertexCollection->push_back(*vertex1);
63 
64  LogInfo("HeavyIonVertexing") << "adaptive vertex:\n vz = ("
65  << vertex1->x() << ", " << vertex1->y() << ", " << vertex1->z() << ")"
66  << "\n error = ("
67  << vertex1->xError() << ", " << vertex1->yError() << ", "
68  << vertex1->zError() << ")" << endl;
69  } else {
70 
71  //** Get fast median vertex **/
73  ev.getByLabel(theMedianVertexCollection, vc2);
74  const reco::VertexCollection * vertices2 = vc2.product();
75 
76  //** Get beam spot position and error **/
78  edm::Handle<reco::BeamSpot> beamSpotHandle;
79  ev.getByLabel(theBeamSpotTag, beamSpotHandle);
80 
81  if( beamSpotHandle.isValid() )
82  beamSpot = *beamSpotHandle;
83  else
84  LogError("HeavyIonVertexing") << "no beamspot with name: '" << theBeamSpotTag << "'" << endl;
85 
86  if(vertices2->size() > 0) {
87 
88  reco::VertexCollection::const_iterator vertex2 = vertices2->begin();
90  err(0,0)=pow(beamSpot.BeamWidthX(),2);
91  err(1,1)=pow(beamSpot.BeamWidthY(),2);
92  err(2,2)=pow(vertex2->zError(),2);
93  reco::Vertex newVertex(reco::Vertex::Point(beamSpot.x0(),beamSpot.y0(),vertex2->z()),
94  err, 0, 1, 1);
95  newVertexCollection->push_back(newVertex);
96 
97  LogInfo("HeavyIonVertexing") << "median vertex + beamspot: \n position = ("
98  << newVertex.x() << ", " << newVertex.y() << ", " << newVertex.z() << ")"
99  << "\n error = ("
100  << newVertex.xError() << ", " << newVertex.yError() << ", "
101  << newVertex.zError() << ")" << endl;
102 
103  } else {
104 
106  err(0,0)=pow(beamSpot.BeamWidthX(),2);
107  err(1,1)=pow(beamSpot.BeamWidthY(),2);
108  err(2,2)=pow(beamSpot.sigmaZ(),2);
109  reco::Vertex newVertex(beamSpot.position(),
110  err, 0, 0, 1);
111  newVertexCollection->push_back(newVertex);
112 
113  LogInfo("HeavyIonVertexing") << "beam spot: \n position = ("
114  << newVertex.x() << ", " << newVertex.y() << ", " << newVertex.z() << ")"
115  << "\n error = ("
116  << newVertex.xError() << ", " << newVertex.yError() << ", "
117  << newVertex.zError() << ")" << endl;
118 
119  }
120 
121  }
122 
123  // put new vertex collection into event
124  ev.put(newVertexCollection);
125 
126 }
127 
T getParameter(std::string const &) const
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:43
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
math::XYZPoint Point
point in the space
Definition: Vertex.h:39
double BeamWidthX() const
beam width X
Definition: BeamSpot.h:86
bool isValid() const
Definition: HandleBase.h:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
virtual void produce(edm::Event &ev, const edm::EventSetup &es)
HIBestVertexProducer(const edm::ParameterSet &ps)
double sigmaZ() const
sigma z
Definition: BeamSpot.h:80
double BeamWidthY() const
beam width Y
Definition: BeamSpot.h:88
T const * product() const
Definition: Handle.h:81
double y0() const
y coordinate
Definition: BeamSpot.h:66
const Point & position() const
position
Definition: BeamSpot.h:62
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
double x0() const
x coordinate
Definition: BeamSpot.h:64