CMS 3D CMS Logo

HIBestVertexProducer.cc
Go to the documentation of this file.
2 
9 
10 
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(consumes<reco::BeamSpot>(ps.getParameter<edm::InputTag>("beamSpotLabel"))),
22  theMedianVertexCollection(consumes<reco::VertexCollection>(ps.getParameter<edm::InputTag>("medianVertexCollection"))),
23  theAdaptiveVertexCollection(consumes<reco::VertexCollection>(ps.getParameter<edm::InputTag>("adaptiveVertexCollection"))),
24  theUseFinalAdaptiveVertexCollection(ps.getParameter<bool>("useFinalAdaptiveVertexCollection"))
25 {
26  if(theUseFinalAdaptiveVertexCollection){
27  theFinalAdaptiveVertexCollection = consumes<reco::VertexCollection>(ps.getParameter<edm::InputTag>("finalAdaptiveVertexCollection"));
28  }
29  produces<reco::VertexCollection>();
30 }
31 
32 
33 /*****************************************************************************/
35 {
36 }
37 
38 /*****************************************************************************/
41  desc.add<InputTag>("beamSpotLabel", edm::InputTag("offlineBeamSpot"));
42  desc.add<InputTag>("adaptiveVertexCollection", edm::InputTag("hiBestAdaptiveVertex"));
43  desc.add<InputTag>("medianVertexCollection", edm::InputTag("hiPixelMedianVertex"));
44  desc.add<bool>("useFinalAdaptiveVertexCollection", false);
45  desc.add<InputTag>("finalAdaptiveVertexCollection", edm::InputTag("hiBestOfflinePrimaryVertex"));
46 
47  descriptions.add("hiSelectedPixelVertex", desc);
48 }
49 
50 /*****************************************************************************/
52 {
53 }
54 
55 /*****************************************************************************/
58 {
59 
60  // 1. use best adaptive vertex preferentially
61  // 2. use median vertex in case where adaptive algorithm failed
62  // 3. use beamspot if netither vertexing method succeeds
63 
64  // New vertex collection
65  auto newVertexCollection = std::make_unique<reco::VertexCollection>();
66 
67  //** Get precise adaptive vertex **/
69  ev.getByToken(theAdaptiveVertexCollection, vc1);
70  const reco::VertexCollection *vertices1 = vc1.product();
71 
72  if(vertices1->empty())
73  LogError("HeavyIonVertexing") << "adaptive vertex collection is empty!" << endl;
74 
75 //** Final vertex collection if needed **//
76  const double maxZError = 3.0; //any vtx with error > this number is considered no good
77  bool hasFinalVertex = false;
78  if(theUseFinalAdaptiveVertexCollection){
80  ev.getByToken(theFinalAdaptiveVertexCollection, vc0);
81  const reco::VertexCollection *vertices0 = vc0.product();
82  if(vertices0->empty())
83  LogInfo("HeavyIonVertexing") << "final adaptive vertex collection is empty!" << endl;
84 
85  //if using final vertex and has a good vertex, use it
86  if(vertices0->begin()->zError() < maxZError){
87  hasFinalVertex = true;
88  auto const& vertex0 = vertices0->front();
89  newVertexCollection->push_back(vertex0);
90  LogInfo("HeavyIonVertexing") << "adaptive vertex:\n vz = ("
91  << vertex0.x() << ", " << vertex0.y() << ", " << vertex0.z() << ")"
92  << "\n error = ("
93  << vertex0.xError() << ", " << vertex0.yError() << ", "
94  << vertex0.zError() << ")" << endl;
95  }
96  }
97 
98  //otherwise use the pixel track adaptive vertex if it is good
99  if(!hasFinalVertex){
100  if(vertices1->begin()->zError() < maxZError) {
101 
102  reco::VertexCollection::const_iterator vertex1 = vertices1->begin();
103  newVertexCollection->push_back(*vertex1);
104 
105  LogInfo("HeavyIonVertexing") << "adaptive vertex:\n vz = ("
106  << vertex1->x() << ", " << vertex1->y() << ", " << vertex1->z() << ")"
107  << "\n error = ("
108  << vertex1->xError() << ", " << vertex1->yError() << ", "
109  << vertex1->zError() << ")" << endl;
110  } else {
111 
112  //** Get fast median vertex **/
114  ev.getByToken(theMedianVertexCollection, vc2);
115  const reco::VertexCollection * vertices2 = vc2.product();
116 
117  //** Get beam spot position and error **/
119  edm::Handle<reco::BeamSpot> beamSpotHandle;
120  ev.getByToken(theBeamSpotTag, beamSpotHandle);
121 
122  if( beamSpotHandle.isValid() )
123  beamSpot = *beamSpotHandle;
124  else
125  LogError("HeavyIonVertexing") << "no beamspot found " << endl;
126 
127  if(!vertices2->empty()) {
128 
129  reco::VertexCollection::const_iterator vertex2 = vertices2->begin();
131  err(0,0)=pow(beamSpot.BeamWidthX(),2);
132  err(1,1)=pow(beamSpot.BeamWidthY(),2);
133  err(2,2)=pow(vertex2->zError(),2);
134  reco::Vertex newVertex(reco::Vertex::Point(beamSpot.x0(),beamSpot.y0(),vertex2->z()),
135  err, 0, 1, 1);
136  newVertexCollection->push_back(newVertex);
137 
138  LogInfo("HeavyIonVertexing") << "median vertex + beamspot: \n position = ("
139  << newVertex.x() << ", " << newVertex.y() << ", " << newVertex.z() << ")"
140  << "\n error = ("
141  << newVertex.xError() << ", " << newVertex.yError() << ", "
142  << newVertex.zError() << ")" << endl;
143 
144  } else {
145 
147  err(0,0)=pow(beamSpot.BeamWidthX(),2);
148  err(1,1)=pow(beamSpot.BeamWidthY(),2);
149  err(2,2)=pow(beamSpot.sigmaZ(),2);
150  reco::Vertex newVertex(beamSpot.position(),
151  err, 0, 0, 1);
152  newVertexCollection->push_back(newVertex);
153 
154  LogInfo("HeavyIonVertexing") << "beam spot: \n position = ("
155  << newVertex.x() << ", " << newVertex.y() << ", " << newVertex.z() << ")"
156  << "\n error = ("
157  << newVertex.xError() << ", " << newVertex.yError() << ", "
158  << newVertex.zError() << ")" << endl;
159 
160  }
161 
162  }
163  }
164 
165  // put new vertex collection into event
166  ev.put(std::move(newVertexCollection));
167 
168 }
169 
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:136
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
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
void produce(edm::Event &ev, const edm::EventSetup &es) override
math::XYZPoint Point
point in the space
Definition: Vertex.h:39
double BeamWidthX() const
beam width X
Definition: BeamSpot.h:86
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isValid() const
Definition: HandleBase.h:74
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
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
void add(std::string const &label, ParameterSetDescription const &psetDescription)
HLT enums.
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
def move(src, dest)
Definition: eostools.py:510
double x0() const
x coordinate
Definition: BeamSpot.h:64