CMS 3D CMS Logo

PrimaryVertexMonitor.cc
Go to the documentation of this file.
1 // user includes
8 
9 // ROOT includes
10 #include "TMath.h"
11 
12 // system includes
13 #include <fmt/format.h>
14 
15 using namespace reco;
16 using namespace edm;
17 
19  : vertexInputTag_(pSet.getParameter<InputTag>("vertexLabel")),
20  beamSpotInputTag_(pSet.getParameter<InputTag>("beamSpotLabel")),
21  vertexToken_(consumes<reco::VertexCollection>(vertexInputTag_)),
22  scoreToken_(consumes<VertexScore>(vertexInputTag_)),
23  beamspotToken_(consumes<reco::BeamSpot>(beamSpotInputTag_)),
24  conf_(pSet),
25  TopFolderName_(pSet.getParameter<std::string>("TopFolderName")),
26  AlignmentLabel_(pSet.getParameter<std::string>("AlignmentLabel")),
27  ndof_(pSet.getParameter<int>("ndof")),
28  useHPfoAlignmentPlots_(pSet.getParameter<bool>("useHPforAlignmentPlots")),
29  errorPrinted_(false),
30  nbvtx(nullptr),
31  bsX(nullptr),
32  bsY(nullptr),
33  bsZ(nullptr),
34  bsSigmaZ(nullptr),
35  bsDxdz(nullptr),
36  bsDydz(nullptr),
37  bsBeamWidthX(nullptr),
38  bsBeamWidthY(nullptr),
39  bsType(nullptr),
40  sumpt(nullptr),
41  ntracks(nullptr),
42  weight(nullptr),
43  chi2ndf(nullptr),
44  chi2prob(nullptr),
45  phi_pt1(nullptr),
46  eta_pt1(nullptr),
47  phi_pt10(nullptr),
48  eta_pt10(nullptr),
49  dxy2(nullptr) {}
50 
51 // -- BeginRun
52 //---------------------------------------------------------------------------------//
54  std::string dqmLabel = "";
55 
56  //
57  // Book all histograms.
58  //
59 
60  // get the store
62  iBooker.setCurrentFolder(dqmLabel);
63 
64  // xPos = iBooker.book1D ("xPos","x Coordinate" ,100, -0.1, 0.1);
65  auto maxPU = conf_.getParameter<double>("PUMax");
66  nbvtx = iBooker.book1D("vtxNbr", "Reconstructed Vertices in Event", maxPU, -0.5, maxPU - 0.5);
67  nbgvtx = iBooker.book1D("goodvtxNbr", "Reconstructed Good Vertices in Event", maxPU, -0.5, maxPU - 0.5);
68 
69  // to be configured each year...
70  auto vposx = conf_.getParameter<double>("Xpos");
71  auto vposy = conf_.getParameter<double>("Ypos");
72 
73  nbtksinvtx[0] = iBooker.book1D("otherVtxTrksNbr", "Reconstructed Tracks in Vertex (other Vtx)", 40, -0.5, 99.5);
74  ntracksVsZ[0] = iBooker.bookProfile(
75  "otherVtxTrksVsZ", "Reconstructed Tracks in Vertex (other Vtx) vs Z", 80, -20., 20., 50, 0, 100, "");
76  ntracksVsZ[0]->setAxisTitle("z-bs", 1);
77  ntracksVsZ[0]->setAxisTitle("#tracks", 2);
78 
79  score[0] = iBooker.book1D("otherVtxScore", "sqrt(score) (other Vtx)", 100, 0., 400.);
80  trksWeight[0] = iBooker.book1D("otherVtxTrksWeight", "Total weight of Tracks in Vertex (other Vtx)", 40, 0, 100.);
81  vtxchi2[0] = iBooker.book1D("otherVtxChi2", "#chi^{2} (other Vtx)", 100, 0., 200.);
82  vtxndf[0] = iBooker.book1D("otherVtxNdf", "ndof (other Vtx)", 100, 0., 200.);
83  vtxprob[0] = iBooker.book1D("otherVtxProb", "#chi^{2} probability (other Vtx)", 100, 0., 1.);
84  nans[0] = iBooker.book1D("otherVtxNans", "Illegal values for x,y,z,xx,xy,xz,yy,yz,zz (other Vtx)", 9, 0.5, 9.5);
85 
86  nbtksinvtx[1] = iBooker.book1D("tagVtxTrksNbr", "Reconstructed Tracks in Vertex (tagged Vtx)", 100, -0.5, 99.5);
87  ntracksVsZ[1] = iBooker.bookProfile(
88  "tagVtxTrksVsZ", "Reconstructed Tracks in Vertex (tagged Vtx) vs Z", 80, -20., 20., 50, 0, 100, "");
89  ntracksVsZ[1]->setAxisTitle("z-bs", 1);
90  ntracksVsZ[1]->setAxisTitle("#tracks", 2);
91 
92  score[1] = iBooker.book1D("tagVtxScore", "sqrt(score) (tagged Vtx)", 100, 0., 400.);
93  trksWeight[1] = iBooker.book1D("tagVtxTrksWeight", "Total weight of Tracks in Vertex (tagged Vtx)", 100, 0, 100.);
94  vtxchi2[1] = iBooker.book1D("tagVtxChi2", "#chi^{2} (tagged Vtx)", 100, 0., 200.);
95  vtxndf[1] = iBooker.book1D("tagVtxNdf", "ndof (tagged Vtx)", 100, 0., 200.);
96  vtxprob[1] = iBooker.book1D("tagVtxProb", "#chi^{2} probability (tagged Vtx)", 100, 0., 1.);
97  nans[1] = iBooker.book1D("tagVtxNans", "Illegal values for x,y,z,xx,xy,xz,yy,yz,zz (tagged Vtx)", 9, 0.5, 9.5);
98 
99  xrec[0] = iBooker.book1D("otherPosX", "Position x Coordinate (other Vtx)", 100, vposx - 0.1, vposx + 0.1);
100  yrec[0] = iBooker.book1D("otherPosY", "Position y Coordinate (other Vtx)", 100, vposy - 0.1, vposy + 0.1);
101  zrec[0] = iBooker.book1D("otherPosZ", "Position z Coordinate (other Vtx)", 100, -20., 20.);
102  xDiff[0] = iBooker.book1D("otherDiffX", "X distance from BeamSpot (other Vtx)", 100, -500, 500);
103  yDiff[0] = iBooker.book1D("otherDiffY", "Y distance from BeamSpot (other Vtx)", 100, -500, 500);
104  xerr[0] = iBooker.book1D("otherErrX", "Uncertainty x Coordinate (other Vtx)", 100, 0., 100);
105  yerr[0] = iBooker.book1D("otherErrY", "Uncertainty y Coordinate (other Vtx)", 100, 0., 100);
106  zerr[0] = iBooker.book1D("otherErrZ", "Uncertainty z Coordinate (other Vtx)", 100, 0., 100);
107  xerrVsTrks[0] = iBooker.book2D(
108  "otherErrVsWeightX", "Uncertainty x Coordinate vs. track weight (other Vtx)", 100, 0, 100., 100, 0., 100);
109  yerrVsTrks[0] = iBooker.book2D(
110  "otherErrVsWeightY", "Uncertainty y Coordinate vs. track weight (other Vtx)", 100, 0, 100., 100, 0., 100);
111  zerrVsTrks[0] = iBooker.book2D(
112  "otherErrVsWeightZ", "Uncertainty z Coordinate vs. track weight (other Vtx)", 100, 0, 100., 100, 0., 100);
113 
114  xrec[1] = iBooker.book1D("tagPosX", "Position x Coordinate (tagged Vtx)", 100, vposx - 0.1, vposx + 0.1);
115  yrec[1] = iBooker.book1D("tagPosY", "Position y Coordinate (tagged Vtx)", 100, vposy - 0.1, vposy + 0.1);
116  zrec[1] = iBooker.book1D("tagPosZ", "Position z Coordinate (tagged Vtx)", 100, -20., 20.);
117  xDiff[1] = iBooker.book1D("tagDiffX", "X distance from BeamSpot (tagged Vtx)", 100, -500, 500);
118  yDiff[1] = iBooker.book1D("tagDiffY", "Y distance from BeamSpot (tagged Vtx)", 100, -500, 500);
119  xerr[1] = iBooker.book1D("tagErrX", "Uncertainty x Coordinate (tagged Vtx)", 100, 0., 100);
120  yerr[1] = iBooker.book1D("tagErrY", "Uncertainty y Coordinate (tagged Vtx)", 100, 0., 100);
121  zerr[1] = iBooker.book1D("tagErrZ", "Uncertainty z Coordinate (tagged Vtx)", 100, 0., 100);
122  xerrVsTrks[1] = iBooker.book2D(
123  "tagErrVsWeightX", "Uncertainty x Coordinate vs. track weight (tagged Vtx)", 100, 0, 100., 100, 0., 100);
124  yerrVsTrks[1] = iBooker.book2D(
125  "tagErrVsWeightY", "Uncertainty y Coordinate vs. track weight (tagged Vtx)", 100, 0, 100., 100, 0., 100);
126  zerrVsTrks[1] = iBooker.book2D(
127  "tagErrVsWeightZ", "Uncertainty z Coordinate vs. track weight (tagged Vtx)", 100, 0, 100., 100, 0., 100);
128 
129  type[0] = iBooker.book1D("otherType", "Vertex type (other Vtx)", 3, -0.5, 2.5);
130  type[1] = iBooker.book1D("tagType", "Vertex type (tagged Vtx)", 3, -0.5, 2.5);
131  for (int i = 0; i < 2; ++i) {
132  type[i]->setBinLabel(1, "Valid, real");
133  type[i]->setBinLabel(2, "Valid, fake");
134  type[i]->setBinLabel(3, "Invalid");
135  }
136 
137  // get the store
139  iBooker.setCurrentFolder(dqmLabel);
140 
141  bsX = iBooker.book1D("bsX", "BeamSpot x0", 100, vposx - 0.1, vposx + 0.1);
142  bsY = iBooker.book1D("bsY", "BeamSpot y0", 100, vposy - 0.1, vposy + 0.1);
143  bsZ = iBooker.book1D("bsZ", "BeamSpot z0", 100, -2., 2.);
144  bsSigmaZ = iBooker.book1D("bsSigmaZ", "BeamSpot sigmaZ", 100, 0., 10.);
145  bsDxdz = iBooker.book1D("bsDxdz", "BeamSpot dxdz", 100, -0.0003, 0.0003);
146  bsDydz = iBooker.book1D("bsDydz", "BeamSpot dydz", 100, -0.0003, 0.0003);
147  bsBeamWidthX = iBooker.book1D("bsBeamWidthX", "BeamSpot BeamWidthX", 500, 0., 15.);
148  bsBeamWidthY = iBooker.book1D("bsBeamWidthY", "BeamSpot BeamWidthY", 500, 0., 15.);
149  bsType = iBooker.book1D("bsType", "BeamSpot type", 4, -1.5, 2.5);
150  bsType->setBinLabel(1, "Unknown");
151  bsType->setBinLabel(2, "Fake");
152  bsType->setBinLabel(3, "LHC");
153  bsType->setBinLabel(4, "Tracker");
154 
155  // get the store
157  iBooker.setCurrentFolder(dqmLabel);
158 
159  int TKNoBin = conf_.getParameter<int>("TkSizeBin");
160  double TKNoMin = conf_.getParameter<double>("TkSizeMin");
161  double TKNoMax = conf_.getParameter<double>("TkSizeMax");
162 
163  int DxyBin = conf_.getParameter<int>("DxyBin");
164  double DxyMin = conf_.getParameter<double>("DxyMin");
165  double DxyMax = conf_.getParameter<double>("DxyMax");
166 
167  int PhiBin = conf_.getParameter<int>("PhiBin");
168  double PhiMin = conf_.getParameter<double>("PhiMin");
169  double PhiMax = conf_.getParameter<double>("PhiMax");
170 
171  int EtaBin = conf_.getParameter<int>("EtaBin");
172  double EtaMin = conf_.getParameter<double>("EtaMin");
173  double EtaMax = conf_.getParameter<double>("EtaMax");
174 
175  ntracks = iBooker.book1D("ntracks", "number of PV tracks (p_{T} > 1 GeV)", TKNoBin, TKNoMin, TKNoMax);
176  ntracks->setAxisTitle("Number of PV Tracks (p_{T} > 1 GeV) per Event", 1);
177  ntracks->setAxisTitle("Number of Event", 2);
178 
179  weight = iBooker.book1D("weight", "weight of PV tracks (p_{T} > 1 GeV)", 100, 0., 1.);
180  weight->setAxisTitle("weight of PV Tracks (p_{T} > 1 GeV) per Event", 1);
181  weight->setAxisTitle("Number of Event", 2);
182 
183  sumpt = iBooker.book1D("sumpt", "#Sum p_{T} of PV tracks (p_{T} > 1 GeV)", 100, -0.5, 249.5);
184  chi2ndf = iBooker.book1D("chi2ndf", "PV tracks (p_{T} > 1 GeV) #chi^{2}/ndof", 100, 0., 20.);
185  chi2prob = iBooker.book1D("chi2prob", "PV tracks (p_{T} > 1 GeV) #chi^{2} probability", 100, 0., 1.);
186 
187  dxy2 = iBooker.book1D("dxyzoom", "PV tracks (p_{T} > 1 GeV) d_{xy} (#mum)", DxyBin, DxyMin / 5., DxyMax / 5.);
188 
189  phi_pt1 = iBooker.book1D("phi_pt1", "PV tracks (p_{T} > 1 GeV) #phi; PV tracks #phi;#tracks", PhiBin, PhiMin, PhiMax);
190  eta_pt1 = iBooker.book1D("eta_pt1", "PV tracks (p_{T} > 1 GeV) #eta; PV tracks #eta;#tracks", EtaBin, EtaMin, EtaMax);
191  phi_pt10 =
192  iBooker.book1D("phi_pt10", "PV tracks (p_{T} > 10 GeV) #phi; PV tracks #phi;#tracks", PhiBin, PhiMin, PhiMax);
193  eta_pt10 =
194  iBooker.book1D("eta_pt10", "PV tracks (p_{T} > 10 GeV) #phi; PV tracks #eta;#tracks", EtaBin, EtaMin, EtaMax);
195 
196  // initialize and book the monitors;
197  dxy_pt1.varname_ = "xy";
198  dxy_pt1.pTcut_ = 1.f;
199  dxy_pt1.bookIPMonitor(iBooker, conf_);
200 
201  dxy_pt10.varname_ = "xy";
202  dxy_pt10.pTcut_ = 10.f;
203  dxy_pt10.bookIPMonitor(iBooker, conf_);
204 
205  dz_pt1.varname_ = "z";
206  dz_pt1.pTcut_ = 1.f;
207  dz_pt1.bookIPMonitor(iBooker, conf_);
208 
209  dz_pt10.varname_ = "z";
210  dz_pt10.pTcut_ = 10.f;
211  dz_pt10.bookIPMonitor(iBooker, conf_);
212 }
213 
215  int VarBin = config.getParameter<int>(fmt::format("D{}Bin", varname_));
216  double VarMin = config.getParameter<double>(fmt::format("D{}Min", varname_));
217  double VarMax = config.getParameter<double>(fmt::format("D{}Max", varname_));
218 
219  PhiBin_ = config.getParameter<int>("PhiBin");
220  PhiMin_ = config.getParameter<double>("PhiMin");
221  PhiMax_ = config.getParameter<double>("PhiMax");
222  int PhiBin2D = config.getParameter<int>("PhiBin2D");
223 
224  EtaBin_ = config.getParameter<int>("EtaBin");
225  EtaMin_ = config.getParameter<double>("EtaMin");
226  EtaMax_ = config.getParameter<double>("EtaMax");
227  int EtaBin2D = config.getParameter<int>("EtaBin2D");
228 
229  // 1D variables
230 
231  IP_ = iBooker.book1D(fmt::format("d{}_pt{}", varname_, pTcut_),
232  fmt::format("PV tracks (p_{{T}} > {} GeV) d_{{{}}} (#mum)", pTcut_, varname_),
233  VarBin,
234  VarMin,
235  VarMax);
236 
237  IPErr_ = iBooker.book1D(fmt::format("d{}Err_pt{}", varname_, pTcut_),
238  fmt::format("PV tracks (p_{{T}} > {} GeV) d_{{{}}} error (#mum)", pTcut_, varname_),
239  100,
240  0.,
241  (varname_.find("xy") != std::string::npos) ? 2000. : 10000.);
242 
243  IPPull_ = iBooker.book1D(
244  fmt::format("d{}Pull_pt{}", varname_, pTcut_),
245  fmt::format("PV tracks (p_{{T}} > {} GeV) d_{{{}}}/#sigma_{{d_{{{}}}}}", pTcut_, varname_, varname_),
246  100,
247  -5.,
248  5.);
249 
250  // profiles
251 
252  IPVsPhi_ = iBooker.bookProfile(fmt::format("d{}VsPhi_pt{}", varname_, pTcut_),
253  fmt::format("PV tracks (p_{{T}} > {}) d_{{{}}} VS track #phi", pTcut_, varname_),
254  PhiBin_,
255  PhiMin_,
256  PhiMax_,
257  VarBin,
258  VarMin,
259  VarMax,
260  "");
261  IPVsPhi_->setAxisTitle("PV track (p_{T} > 1 GeV) #phi", 1);
262  IPVsPhi_->setAxisTitle(fmt::format("PV tracks (p_{{T}} > {} GeV) d_{{{}}} (#mum)", pTcut_, varname_), 2);
263 
264  IPVsEta_ = iBooker.bookProfile(fmt::format("d{}VsEta_pt{}", varname_, pTcut_),
265  fmt::format("PV tracks (p_{{T}} > {}) d_{{{}}} VS track #eta", pTcut_, varname_),
266  EtaBin_,
267  EtaMin_,
268  EtaMax_,
269  VarBin,
270  VarMin,
271  VarMax,
272  "");
273  IPVsEta_->setAxisTitle("PV track (p_{T} > 1 GeV) #eta", 1);
274  IPVsEta_->setAxisTitle(fmt::format("PV tracks (p_{{T}} > {} GeV) d_{{{}}} (#mum)", pTcut_, varname_), 2);
275 
276  IPErrVsPhi_ =
277  iBooker.bookProfile(fmt::format("d{}ErrVsPhi_pt{}", varname_, pTcut_),
278  fmt::format("PV tracks (p_{{T}} > {}) d_{{{}}} error VS track #phi", pTcut_, varname_),
279  PhiBin_,
280  PhiMin_,
281  PhiMax_,
282  VarBin,
283  0.,
284  (varname_.find("xy") != std::string::npos) ? 100. : 200.,
285  "");
286  IPErrVsPhi_->setAxisTitle("PV track (p_{T} > 1 GeV) #phi", 1);
287  IPErrVsPhi_->setAxisTitle(fmt::format("PV tracks (p_{{T}} > {} GeV) d_{{{}}} error (#mum)", pTcut_, varname_), 2);
288 
289  IPErrVsEta_ =
290  iBooker.bookProfile(fmt::format("d{}ErrVsEta_pt{}", varname_, pTcut_),
291  fmt::format("PV tracks (p_{{T}} > {}) d_{{{}}} error VS track #eta", pTcut_, varname_),
292  EtaBin_,
293  EtaMin_,
294  EtaMax_,
295  VarBin,
296  0.,
297  (varname_.find("xy") != std::string::npos) ? 100. : 200.,
298  "");
299  IPErrVsEta_->setAxisTitle("PV track (p_{T} > 1 GeV) #eta", 1);
300  IPErrVsEta_->setAxisTitle(fmt::format("PV tracks (p_{{T}} > {} GeV) d_{{{}}} error (#mum)", pTcut_, varname_), 2);
301 
302  // 2D profiles
303 
304  IPVsEtaVsPhi_ = iBooker.bookProfile2D(
305  fmt::format("d{}VsEtaVsPhi_pt{}", varname_, pTcut_),
306  fmt::format("PV tracks (p_{{T}} > {}) d_{{{}}} VS track #eta VS track #phi", pTcut_, varname_),
307  EtaBin2D,
308  EtaMin_,
309  EtaMax_,
310  PhiBin2D,
311  PhiMin_,
312  PhiMax_,
313  VarBin,
314  VarMin,
315  VarMax,
316  "");
317  IPVsEtaVsPhi_->setAxisTitle("PV track (p_{T} > 1 GeV) #eta", 1);
318  IPVsEtaVsPhi_->setAxisTitle("PV track (p_{T} > 1 GeV) #phi", 2);
319  IPVsEtaVsPhi_->setAxisTitle(fmt::format("PV tracks (p_{{T}} > {} GeV) d_{{{}}} (#mum)", pTcut_, varname_), 3);
320 
322  fmt::format("d{}ErrVsEtaVsPhi_pt{}", varname_, pTcut_),
323  fmt::format("PV tracks (p_{{T}} > {}) d_{{{}}} error VS track #eta VS track #phi", pTcut_, varname_),
324  EtaBin2D,
325  EtaMin_,
326  EtaMax_,
327  PhiBin2D,
328  PhiMin_,
329  PhiMax_,
330  VarBin,
331  0.,
332  (varname_.find("xy") != std::string::npos) ? 100. : 200.,
333  "");
334  IPErrVsEtaVsPhi_->setAxisTitle("PV track (p_{T} > 1 GeV) #eta", 1);
335  IPErrVsEtaVsPhi_->setAxisTitle("PV track (p_{T} > 1 GeV) #phi", 2);
336  IPErrVsEtaVsPhi_->setAxisTitle(fmt::format("PV tracks (p_{{T}} > {} GeV) d_{{{}}} error (#mum)", pTcut_, varname_),
337  3);
338 }
339 
342  iEvent.getByToken(vertexToken_, recVtxs);
343 
344  Handle<VertexScore> scores;
345  iEvent.getByToken(scoreToken_, scores);
346 
347  edm::Handle<reco::BeamSpot> beamSpotHandle;
348  iEvent.getByToken(beamspotToken_, beamSpotHandle);
349 
350  //
351  // check for absent products and simply "return" in that case
352  //
353  if (recVtxs.isValid() == false || beamSpotHandle.isValid() == false) {
354  edm::LogWarning("PrimaryVertexMonitor")
355  << " Some products not available in the event: VertexCollection " << vertexInputTag_ << " " << recVtxs.isValid()
356  << " BeamSpot " << beamSpotInputTag_ << " " << beamSpotHandle.isValid() << ". Skipping plots for this event";
357  return;
358  }
359 
360  // check upfront that refs to track are (likely) to be valid
361  {
362  bool ok = true;
363  for (const auto& v : *recVtxs) {
364  if (v.tracksSize() > 0) {
365  const auto& ref = v.trackRefAt(0);
366  if (ref.isNull() || !ref.isAvailable()) {
367  if (!errorPrinted_)
368  edm::LogWarning("PrimaryVertexMonitor")
369  << "Skipping vertex collection: " << vertexInputTag_
370  << " since likely the track collection the vertex has refs pointing to is missing (at least the first "
371  "TrackBaseRef is null or not available)";
372  else
373  errorPrinted_ = true;
374  ok = false;
375  }
376  }
377  }
378  if (!ok)
379  return;
380  }
381 
382  BeamSpot beamSpot = *beamSpotHandle;
383 
384  nbvtx->Fill(recVtxs->size() * 1.);
385  int ng = 0;
386  for (auto const& vx : (*recVtxs))
387  if (vx.isValid() && !vx.isFake() && vx.ndof() >= ndof_)
388  ++ng;
389  nbgvtx->Fill(ng * 1.);
390 
391  if (scores.isValid() && !(*scores).empty()) {
392  auto pvScore = (*scores).get(0);
393  score[1]->Fill(std::sqrt(pvScore));
394  for (unsigned int i = 1; i < (*scores).size(); ++i)
395  score[0]->Fill(std::sqrt((*scores).get(i)));
396  }
397 
398  // fill PV tracks MEs (as now, for alignment)
399  if (!recVtxs->empty()) {
400  vertexPlots(recVtxs->front(), beamSpot, 1);
401  pvTracksPlots(recVtxs->front());
402 
403  for (reco::VertexCollection::const_iterator v = recVtxs->begin() + 1; v != recVtxs->end(); ++v)
404  vertexPlots(*v, beamSpot, 0);
405  }
406 
407  // Beamline plots:
408  bsX->Fill(beamSpot.x0());
409  bsY->Fill(beamSpot.y0());
410  bsZ->Fill(beamSpot.z0());
411  bsSigmaZ->Fill(beamSpot.sigmaZ());
412  bsDxdz->Fill(beamSpot.dxdz());
413  bsDydz->Fill(beamSpot.dydz());
414  bsBeamWidthX->Fill(beamSpot.BeamWidthX() * cmToUm);
415  bsBeamWidthY->Fill(beamSpot.BeamWidthY() * cmToUm);
416  bsType->Fill(beamSpot.type());
417 }
418 
420  if (!v.isValid())
421  return;
422  if (v.isFake())
423  return;
424 
425  if (v.tracksSize() == 0) {
426  ntracks->Fill(0);
427  return;
428  }
429 
430  const math::XYZPoint myVertex(v.position().x(), v.position().y(), v.position().z());
431 
432  size_t nTracks = 0;
433  float sumPT = 0.;
434 
435  for (reco::Vertex::trackRef_iterator t = v.tracks_begin(); t != v.tracks_end(); t++) {
436  bool isHighPurity = (**t).quality(reco::TrackBase::highPurity);
437  if (!isHighPurity && useHPfoAlignmentPlots_)
438  continue;
439 
440  float pt = (**t).pt();
441  if (pt < 1.)
442  continue;
443 
444  nTracks++;
445 
446  float eta = (**t).eta();
447  float phi = (**t).phi();
448 
449  float w = v.trackWeight(*t);
450  float chi2NDF = (**t).normalizedChi2();
451  float chi2Prob = TMath::Prob((**t).chi2(), (int)(**t).ndof());
452  float Dxy = (**t).dxy(myVertex) * cmToUm;
453  float Dz = (**t).dz(myVertex) * cmToUm;
454  float DxyErr = (**t).dxyError() * cmToUm;
455  float DzErr = (**t).dzError() * cmToUm;
456 
457  sumPT += pt * pt;
458 
459  // fill MEs
460  phi_pt1->Fill(phi);
461  eta_pt1->Fill(eta);
462 
463  weight->Fill(w);
464  chi2ndf->Fill(chi2NDF);
465  chi2prob->Fill(chi2Prob);
466  dxy2->Fill(Dxy);
467 
468  // dxy pT>1
469 
470  dxy_pt1.IP_->Fill(Dxy);
471  dxy_pt1.IPVsPhi_->Fill(phi, Dxy);
472  dxy_pt1.IPVsEta_->Fill(eta, Dxy);
473  dxy_pt1.IPVsEtaVsPhi_->Fill(eta, phi, Dxy);
474 
475  dxy_pt1.IPErr_->Fill(DxyErr);
476  dxy_pt1.IPPull_->Fill(Dxy / DxyErr);
477  dxy_pt1.IPErrVsPhi_->Fill(phi, DxyErr);
478  dxy_pt1.IPErrVsEta_->Fill(eta, DxyErr);
479  dxy_pt1.IPErrVsEtaVsPhi_->Fill(eta, phi, DxyErr);
480 
481  // dz pT>1
482 
483  dz_pt1.IP_->Fill(Dz);
484  dz_pt1.IPVsPhi_->Fill(phi, Dz);
485  dz_pt1.IPVsEta_->Fill(eta, Dz);
487 
488  dz_pt1.IPErr_->Fill(DzErr);
489  dz_pt1.IPPull_->Fill(Dz / DzErr);
490  dz_pt1.IPErrVsPhi_->Fill(phi, DzErr);
491  dz_pt1.IPErrVsEta_->Fill(eta, DzErr);
492  dz_pt1.IPErrVsEtaVsPhi_->Fill(eta, phi, DzErr);
493 
494  if (pt < 10.)
495  continue;
496 
497  phi_pt10->Fill(phi);
498  eta_pt10->Fill(eta);
499 
500  // dxy pT>10
501 
502  dxy_pt10.IP_->Fill(Dxy);
503  dxy_pt10.IPVsPhi_->Fill(phi, Dxy);
504  dxy_pt10.IPVsEta_->Fill(eta, Dxy);
506 
507  dxy_pt10.IPErr_->Fill(DxyErr);
508  dxy_pt10.IPPull_->Fill(Dxy / DxyErr);
509  dxy_pt10.IPErrVsPhi_->Fill(phi, DxyErr);
510  dxy_pt10.IPErrVsEta_->Fill(eta, DxyErr);
511  dxy_pt10.IPErrVsEtaVsPhi_->Fill(eta, phi, DxyErr);
512 
513  // dxz pT>10
514 
515  dz_pt10.IP_->Fill(Dz);
516  dz_pt10.IPVsPhi_->Fill(phi, Dz);
517  dz_pt10.IPVsEta_->Fill(eta, Dz);
519 
520  dz_pt10.IPErr_->Fill(DzErr);
521  dz_pt10.IPPull_->Fill(Dz / DzErr);
522  dz_pt10.IPErrVsPhi_->Fill(phi, DzErr);
523  dz_pt10.IPErrVsEta_->Fill(eta, DzErr);
524  dz_pt10.IPErrVsEtaVsPhi_->Fill(eta, phi, DzErr);
525  }
526  ntracks->Fill(float(nTracks));
527  sumpt->Fill(sumPT);
528 }
529 
531  if (i < 0 || i > 1)
532  return;
533  if (!v.isValid())
534  type[i]->Fill(2.);
535  else if (v.isFake())
536  type[i]->Fill(1.);
537  else
538  type[i]->Fill(0.);
539 
540  if (v.isValid() && !v.isFake()) {
541  float weight = 0;
542  for (reco::Vertex::trackRef_iterator t = v.tracks_begin(); t != v.tracks_end(); t++)
543  weight += v.trackWeight(*t);
544  trksWeight[i]->Fill(weight);
545  nbtksinvtx[i]->Fill(v.tracksSize());
546  ntracksVsZ[i]->Fill(v.position().z() - beamSpot.z0(), v.tracksSize());
547 
548  vtxchi2[i]->Fill(v.chi2());
549  vtxndf[i]->Fill(v.ndof());
550  vtxprob[i]->Fill(ChiSquaredProbability(v.chi2(), v.ndof()));
551 
552  xrec[i]->Fill(v.position().x());
553  yrec[i]->Fill(v.position().y());
554  zrec[i]->Fill(v.position().z());
555 
556  float xb = beamSpot.x0() + beamSpot.dxdz() * (v.position().z() - beamSpot.z0());
557  float yb = beamSpot.y0() + beamSpot.dydz() * (v.position().z() - beamSpot.z0());
558  xDiff[i]->Fill((v.position().x() - xb) * cmToUm);
559  yDiff[i]->Fill((v.position().y() - yb) * cmToUm);
560 
561  xerr[i]->Fill(v.xError() * cmToUm);
562  yerr[i]->Fill(v.yError() * cmToUm);
563  zerr[i]->Fill(v.zError() * cmToUm);
564  xerrVsTrks[i]->Fill(weight, v.xError() * cmToUm);
565  yerrVsTrks[i]->Fill(weight, v.yError() * cmToUm);
566  zerrVsTrks[i]->Fill(weight, v.zError() * cmToUm);
567 
568  nans[i]->Fill(1., edm::isNotFinite(v.position().x()) * 1.);
569  nans[i]->Fill(2., edm::isNotFinite(v.position().y()) * 1.);
570  nans[i]->Fill(3., edm::isNotFinite(v.position().z()) * 1.);
571 
572  int index = 3;
573  for (int k = 0; k != 3; k++) {
574  for (int j = k; j != 3; j++) {
575  index++;
576  nans[i]->Fill(index * 1., edm::isNotFinite(v.covariance(k, j)) * 1.);
577  // in addition, diagonal element must be positive
578  if (j == k && v.covariance(k, j) < 0) {
579  nans[i]->Fill(index * 1., 1.);
580  }
581  }
582  }
583  }
584 }
585 
588  desc.add<std::string>("TopFolderName", "OfflinePV");
589  desc.add<std::string>("AlignmentLabel", "Alignment");
590  desc.add<int>("ndof", 4);
591  desc.add<bool>("useHPforAlignmentPlots", true);
592  desc.add<InputTag>("vertexLabel", edm::InputTag("offlinePrimaryVertices"));
593  desc.add<InputTag>("beamSpotLabel", edm::InputTag("offlineBeamSpot"));
594  desc.add<double>("PUMax", 80.0);
595  desc.add<double>("Xpos", 0.1);
596  desc.add<double>("Ypos", 0.0);
597  desc.add<int>("TkSizeBin", 100);
598  desc.add<double>("TkSizeMin", -0.5);
599  desc.add<double>("TkSizeMax", 499.5);
600  desc.add<int>("DxyBin", 100);
601  desc.add<double>("DxyMin", -5000.0);
602  desc.add<double>("DxyMax", 5000.0);
603  desc.add<int>("DzBin", 100);
604  desc.add<double>("DzMin", -2000.0);
605  desc.add<double>("DzMax", 2000.0);
606  desc.add<int>("PhiBin", 32);
607  desc.add<double>("PhiMin", -M_PI);
608  desc.add<double>("PhiMax", M_PI);
609  desc.add<int>("EtaBin", 26);
610  desc.add<double>("EtaMin", 2.5);
611  desc.add<double>("EtaMax", -2.5);
612  desc.add<int>("PhiBin2D", 12);
613  desc.add<int>("EtaBin2D", 8);
614  descriptions.addWithDefaultLabel(desc);
615 }
616 
617 //define this as a plug-in
MonitorElement * xerrVsTrks[2]
const std::string AlignmentLabel_
MonitorElement * xerr[2]
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
MonitorElement * vtxndf[2]
MonitorElement * bookProfile2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, double lowZ, double highZ, char const *option="s", FUNC onbooking=NOOP())
Definition: DQMStore.h:485
void pvTracksPlots(const reco::Vertex &v)
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
dqm::reco::MonitorElement * IPErrVsEta_
void vertexPlots(const reco::Vertex &v, const reco::BeamSpot &beamSpot, int i)
T w() const
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
MonitorElement * bsSigmaZ
MonitorElement * eta_pt1
const edm::EDGetTokenT< reco::BeamSpot > beamspotToken_
const std::string dqmLabel
dqm::reco::MonitorElement * IPPull_
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
Definition: weight.py:1
MonitorElement * chi2ndf
Definition: config.py:1
dqm::reco::MonitorElement * IPVsEtaVsPhi_
std::string const & label() const
Definition: InputTag.h:36
void bookIPMonitor(DQMStore::IBooker &, const edm::ParameterSet &)
MonitorElement * xDiff[2]
const edm::InputTag vertexInputTag_
dqm::reco::MonitorElement * IP_
MonitorElement * ntracksVsZ[2]
const edm::EDGetTokenT< VertexScore > scoreToken_
MonitorElement * zerrVsTrks[2]
MonitorElement * nans[2]
void Fill(long long x)
MonitorElement * phi_pt10
int iEvent
Definition: GenABIO.cc:224
dqm::reco::MonitorElement * IPVsEta_
dqm::reco::MonitorElement * IPErrVsPhi_
MonitorElement * yerrVsTrks[2]
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
MonitorElement * bookProfile(TString const &name, TString const &title, int nchX, double lowX, double highX, int, double lowY, double highY, char const *option="s", FUNC onbooking=NOOP())
Definition: DQMStore.h:408
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
MonitorElement * zerr[2]
T sqrt(T t)
Definition: SSEVec.h:19
MonitorElement * yrec[2]
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
dqm::reco::MonitorElement * IPErr_
float ChiSquaredProbability(double chiSquared, double nrDOF)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
MonitorElement * zrec[2]
MonitorElement * vtxchi2[2]
virtual void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
MonitorElement * eta_pt10
dqm::reco::MonitorElement * IPErrVsEtaVsPhi_
#define M_PI
MonitorElement * chi2prob
const edm::ParameterSet conf_
const std::string TopFolderName_
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
MonitorElement * nbtksinvtx[2]
dqm::reco::MonitorElement * IPVsPhi_
MonitorElement * phi_pt1
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:221
static constexpr int cmToUm
bool isValid() const
Definition: HandleBase.h:70
MonitorElement * yerr[2]
fixed size matrix
HLT enums.
void analyze(const edm::Event &, const edm::EventSetup &) override
MonitorElement * xrec[2]
MonitorElement * vtxprob[2]
const edm::EDGetTokenT< reco::VertexCollection > vertexToken_
MonitorElement * ntracks
Log< level::Warning, false > LogWarning
MonitorElement * bsBeamWidthY
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
MonitorElement * score[2]
MonitorElement * yDiff[2]
std::vector< TrackBaseRef >::const_iterator trackRef_iterator
The iteratator for the vector<TrackRef>
Definition: Vertex.h:38
MonitorElement * trksWeight[2]
PrimaryVertexMonitor(const edm::ParameterSet &pSet)
Definition: Run.h:45
MonitorElement * bsBeamWidthX
virtual void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
const edm::InputTag beamSpotInputTag_