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 
9 
10 #include <algorithm>
11 #include <iostream>
12 using namespace std;
13 using namespace edm;
14 
15 /*****************************************************************************/
17 (const edm::ParameterSet& ps) : theConfig(ps),
18  theBeamSpotTag(consumes<reco::BeamSpot>(ps.getParameter<edm::InputTag>("beamSpotLabel"))),
19  theMedianVertexCollection(consumes<reco::VertexCollection>(ps.getParameter<edm::InputTag>("medianVertexCollection"))),
20  theAdaptiveVertexCollection(consumes<reco::VertexCollection>(ps.getParameter<edm::InputTag>("adaptiveVertexCollection")))
21 {
22  produces<reco::VertexCollection>();
23 }
24 
25 
26 /*****************************************************************************/
28 {
29 }
30 
31 /*****************************************************************************/
33 {
34 }
35 
36 /*****************************************************************************/
39 {
40 
41  // 1. use best adaptive vertex preferentially
42  // 2. use median vertex in case where adaptive algorithm failed
43  // 3. use beamspot if netither vertexing method succeeds
44 
45  // New vertex collection
46  std::auto_ptr<reco::VertexCollection> newVertexCollection(new reco::VertexCollection);
47 
48  //** Get precise adaptive vertex **/
50  ev.getByToken(theAdaptiveVertexCollection, vc1);
51  const reco::VertexCollection *vertices1 = vc1.product();
52 
53  if(vertices1->size()==0)
54  LogError("HeavyIonVertexing") << "adaptive vertex collection is empty!" << endl;
55 
56  if(vertices1->begin()->zError()<3) {
57 
58  reco::VertexCollection::const_iterator vertex1 = vertices1->begin();
59  newVertexCollection->push_back(*vertex1);
60 
61  LogInfo("HeavyIonVertexing") << "adaptive vertex:\n vz = ("
62  << vertex1->x() << ", " << vertex1->y() << ", " << vertex1->z() << ")"
63  << "\n error = ("
64  << vertex1->xError() << ", " << vertex1->yError() << ", "
65  << vertex1->zError() << ")" << endl;
66  } else {
67 
68  //** Get fast median vertex **/
70  ev.getByToken(theMedianVertexCollection, vc2);
71  const reco::VertexCollection * vertices2 = vc2.product();
72 
73  //** Get beam spot position and error **/
75  edm::Handle<reco::BeamSpot> beamSpotHandle;
76  ev.getByToken(theBeamSpotTag, beamSpotHandle);
77 
78  if( beamSpotHandle.isValid() )
79  beamSpot = *beamSpotHandle;
80  else
81  LogError("HeavyIonVertexing") << "no beamspot found " << endl;
82 
83  if(vertices2->size() > 0) {
84 
85  reco::VertexCollection::const_iterator vertex2 = vertices2->begin();
87  err(0,0)=pow(beamSpot.BeamWidthX(),2);
88  err(1,1)=pow(beamSpot.BeamWidthY(),2);
89  err(2,2)=pow(vertex2->zError(),2);
90  reco::Vertex newVertex(reco::Vertex::Point(beamSpot.x0(),beamSpot.y0(),vertex2->z()),
91  err, 0, 1, 1);
92  newVertexCollection->push_back(newVertex);
93 
94  LogInfo("HeavyIonVertexing") << "median vertex + beamspot: \n position = ("
95  << newVertex.x() << ", " << newVertex.y() << ", " << newVertex.z() << ")"
96  << "\n error = ("
97  << newVertex.xError() << ", " << newVertex.yError() << ", "
98  << newVertex.zError() << ")" << endl;
99 
100  } else {
101 
103  err(0,0)=pow(beamSpot.BeamWidthX(),2);
104  err(1,1)=pow(beamSpot.BeamWidthY(),2);
105  err(2,2)=pow(beamSpot.sigmaZ(),2);
106  reco::Vertex newVertex(beamSpot.position(),
107  err, 0, 0, 1);
108  newVertexCollection->push_back(newVertex);
109 
110  LogInfo("HeavyIonVertexing") << "beam spot: \n position = ("
111  << newVertex.x() << ", " << newVertex.y() << ", " << newVertex.z() << ")"
112  << "\n error = ("
113  << newVertex.xError() << ", " << newVertex.yError() << ", "
114  << newVertex.zError() << ")" << endl;
115 
116  }
117 
118  }
119 
120  // put new vertex collection into event
121  ev.put(newVertexCollection);
122 
123 }
124 
T getParameter(std::string const &) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
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
bool ev
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
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:75
virtual void produce(edm::Event &ev, const edm::EventSetup &es)
HIBestVertexProducer(const edm::ParameterSet &ps)
T const * product() const
Definition: Handle.h:81
double sigmaZ() const
sigma z
Definition: BeamSpot.h:80
double BeamWidthY() const
beam width Y
Definition: BeamSpot.h:88
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