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  theMedianVertexCollection(ps.getParameter<edm::InputTag>("medianVertexCollection")),
22  theAdaptiveVertexCollection(ps.getParameter<edm::InputTag>("adaptiveVertexCollection"))
23 {
24  produces<reco::VertexCollection>();
25 }
26 
27 
28 /*****************************************************************************/
30 {
31 }
32 
33 /*****************************************************************************/
35 {
36 }
37 
38 /*****************************************************************************/
40 (edm::Event& ev, const edm::EventSetup& es)
41 {
42 
43  // 1. use best adaptive vertex preferentially
44  // 2. use median vertex in case where adaptive algorithm failed
45  // 3. use beamspot if netither vertexing method succeeds
46 
47  // New vertex collection
48  std::auto_ptr<reco::VertexCollection> newVertexCollection(new reco::VertexCollection);
49 
50  //** Get precise adaptive vertex **/
52  ev.getByLabel(theAdaptiveVertexCollection, vc1);
53  const reco::VertexCollection *vertices1 = vc1.product();
54 
55  if(vertices1->size()==0)
56  LogError("HeavyIonVertexing") << "adaptive vertex collection is empty!" << endl;
57 
58  if(vertices1->begin()->zError()<3) {
59 
60  reco::VertexCollection::const_iterator vertex1 = vertices1->begin();
61  newVertexCollection->push_back(*vertex1);
62 
63  LogInfo("HeavyIonVertexing") << "adaptive vertex:\n vz = ("
64  << vertex1->x() << ", " << vertex1->y() << ", " << vertex1->z() << ")"
65  << "\n error = ("
66  << vertex1->xError() << ", " << vertex1->yError() << ", "
67  << vertex1->zError() << ")" << endl;
68 
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("offlineBeamSpot", beamSpotHandle);
80 
81  if( beamSpotHandle.isValid() )
82  beamSpot = *beamSpotHandle;
83  else
84  LogError("HeavyIonVertexing") << "no beamspot with name: 'offlineBeamSpot'" << 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:44
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:84
math::XYZPoint Point
point in the space
Definition: Vertex.h:40
double BeamWidthX() const
beam width X
Definition: BeamSpot.h:77
bool isValid() const
Definition: HandleBase.h:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:359
virtual void produce(edm::Event &ev, const edm::EventSetup &es)
HIBestVertexProducer(const edm::ParameterSet &ps)
double sigmaZ() const
sigma z
Definition: BeamSpot.h:71
double BeamWidthY() const
beam width Y
Definition: BeamSpot.h:79
T const * product() const
Definition: Handle.h:74
double y0() const
y coordinate
Definition: BeamSpot.h:67
const Point & position() const
position
Definition: BeamSpot.h:63
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
double x0() const
x coordinate
Definition: BeamSpot.h:65