CMS 3D CMS Logo

SiPixelPhase1CompareVertexSoA.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 // Package: SiPixelPhase1CompareVertexSoA
3 // Class: SiPixelPhase1CompareVertexSoA
4 //
7 //
8 // Author: Suvankar Roy Chowdhury
9 //
17 // DQM Histograming
23 
25 public:
26  using IndToEdm = std::vector<uint16_t>;
28  ~SiPixelPhase1CompareVertexSoA() override = default;
29  void bookHistograms(DQMStore::IBooker& ibooker, edm::Run const& iRun, edm::EventSetup const& iSetup) override;
30  void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override;
31  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
32 
33 private:
38  const float dzCut_;
50 };
51 
52 //
53 // constructors
54 //
55 
57  : tokenSoAVertexCPU_(consumes<ZVertexHeterogeneous>(iConfig.getParameter<edm::InputTag>("pixelVertexSrcCPU"))),
58  tokenSoAVertexGPU_(consumes<ZVertexHeterogeneous>(iConfig.getParameter<edm::InputTag>("pixelVertexSrcGPU"))),
59  tokenBeamSpot_(consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamSpotSrc"))),
60  topFolderName_(iConfig.getParameter<std::string>("topFolderName")),
61  dzCut_(iConfig.getParameter<double>("dzCut")) {}
62 
63 //
64 // -- Analyze
65 //
67  const auto& vsoaHandleCPU = iEvent.getHandle(tokenSoAVertexCPU_);
68  const auto& vsoaHandleGPU = iEvent.getHandle(tokenSoAVertexGPU_);
69  if (not vsoaHandleCPU or not vsoaHandleGPU) {
70  edm::LogWarning out("SiPixelPhase1CompareTrackSoA");
71  if (not vsoaHandleCPU) {
72  out << "reference (cpu) tracks not found; ";
73  }
74  if (not vsoaHandleGPU) {
75  out << "target (gpu) tracks not found; ";
76  }
77  out << "the comparison will not run.";
78  return;
79  }
80 
81  auto const& vsoaCPU = *vsoaHandleCPU->get();
82  int nVerticesCPU = vsoaCPU.nvFinal;
83  auto const& vsoaGPU = *vsoaHandleGPU->get();
84  int nVerticesGPU = vsoaGPU.nvFinal;
85 
86  auto bsHandle = iEvent.getHandle(tokenBeamSpot_);
87  float x0 = 0., y0 = 0., z0 = 0., dxdz = 0., dydz = 0.;
88  if (!bsHandle.isValid()) {
89  edm::LogWarning("PixelVertexProducer") << "No beamspot found. returning vertexes with (0,0,Z) ";
90  } else {
91  const reco::BeamSpot& bs = *bsHandle;
92  x0 = bs.x0();
93  y0 = bs.y0();
94  z0 = bs.z0();
95  dxdz = bs.dxdz();
96  dydz = bs.dydz();
97  }
98 
99  for (int ivc = 0; ivc < nVerticesCPU; ivc++) {
100  auto sic = vsoaCPU.sortInd[ivc];
101  auto zc = vsoaCPU.zv[sic];
102  auto xc = x0 + dxdz * zc;
103  auto yc = y0 + dydz * zc;
104  zc += z0;
105 
106  auto ndofCPU = vsoaCPU.ndof[sic];
107  auto chi2CPU = vsoaCPU.chi2[sic];
108 
109  const int32_t notFound = -1;
110  int32_t closestVtxidx = notFound;
111  float mindz = dzCut_;
112 
113  for (int ivg = 0; ivg < nVerticesGPU; ivg++) {
114  auto sig = vsoaGPU.sortInd[ivg];
115  auto zgc = vsoaGPU.zv[sig] + z0;
116  auto zDist = std::abs(zc - zgc);
117  //insert some matching condition
118  if (zDist > dzCut_)
119  continue;
120  if (mindz > zDist) {
121  mindz = zDist;
122  closestVtxidx = sig;
123  }
124  }
125  if (closestVtxidx == notFound)
126  continue;
127 
128  auto zg = vsoaGPU.zv[closestVtxidx];
129  auto xg = x0 + dxdz * zg;
130  auto yg = y0 + dydz * zg;
131  zg += z0;
132  auto ndofGPU = vsoaGPU.ndof[closestVtxidx];
133  auto chi2GPU = vsoaGPU.chi2[closestVtxidx];
134 
135  hx_->Fill(xc - x0, xg - x0);
136  hy_->Fill(yc - y0, yg - y0);
137  hz_->Fill(zc, zg);
138  hxdiff_->Fill(xc - xg);
139  hydiff_->Fill(yc - yg);
140  hzdiff_->Fill(zc - zg);
141  hchi2_->Fill(chi2CPU, chi2GPU);
142  hchi2oNdof_->Fill(chi2CPU / ndofCPU, chi2GPU / ndofGPU);
143  hptv2_->Fill(vsoaCPU.ptv2[sic], vsoaGPU.ptv2[closestVtxidx]);
144  hntrks_->Fill(ndofCPU + 1, ndofGPU + 1);
145  }
146  hnVertex_->Fill(nVerticesCPU, nVerticesGPU);
147 }
148 
149 //
150 // -- Book Histograms
151 //
153  edm::Run const& iRun,
154  edm::EventSetup const& iSetup) {
155  ibooker.cd();
157 
158  // FIXME: all the 2D correlation plots are quite heavy in terms of memory consumption, so a as soon as DQM supports either TH2I or THnSparse
159  // these should be moved to a less resource consuming format
160  hnVertex_ = ibooker.book2I("nVertex", "# of Vertex;CPU;GPU", 101, -0.5, 100.5, 101, -0.5, 100.5);
161  hx_ = ibooker.book2I("vx", "Vertez x - Beamspot x;CPU;GPU", 50, -0.1, 0.1, 50, -0.1, 0.1);
162  hy_ = ibooker.book2I("vy", "Vertez y - Beamspot y;CPU;GPU", 50, -0.1, 0.1, 50, -0.1, 0.1);
163  hz_ = ibooker.book2I("vz", "Vertez z;CPU;GPU", 30, -30., 30., 30, -30., 30.);
164  hchi2_ = ibooker.book2I("chi2", "Vertex chi-squared;CPU;GPU", 40, 0., 20., 40, 0., 20.);
165  hchi2oNdof_ = ibooker.book2I("chi2oNdof", "Vertex chi-squared/Ndof;CPU;GPU", 40, 0., 20., 40, 0., 20.);
166  hptv2_ = ibooker.book2I("ptsq", "Vertex p_T squared;CPU;GPU", 200, 0., 200., 200, 0., 200.);
167  hntrks_ = ibooker.book2I("ntrk", "#tracks associated;CPU;GPU", 100, -0.5, 99.5, 100, -0.5, 99.5);
168  hntrks_ = ibooker.book2I("ntrk", "#tracks associated;CPU;GPU", 100, -0.5, 99.5, 100, -0.5, 99.5);
169  hxdiff_ = ibooker.book1D("vxdiff", ";Vertex x difference (CPU - GPU);#entries", 100, -0.001, 0.001);
170  hydiff_ = ibooker.book1D("vydiff", ";Vertex y difference (CPU - GPU);#entries", 100, -0.001, 0.001);
171  hzdiff_ = ibooker.book1D("vzdiff", ";Vertex z difference (CPU - GPU);#entries", 100, -2.5, 2.5);
172 }
173 
175  // monitorpixelVertexSoA
177  desc.add<edm::InputTag>("pixelVertexSrcCPU", edm::InputTag("pixelVerticesSoA@cpu"));
178  desc.add<edm::InputTag>("pixelVertexSrcGPU", edm::InputTag("pixelVerticesSoA@cuda"));
179  desc.add<edm::InputTag>("beamSpotSrc", edm::InputTag("offlineBeamSpot"));
180  desc.add<std::string>("topFolderName", "SiPixelHeterogeneous/PixelVertexCompareSoAGPUvsCPU");
181  desc.add<double>("dzCut", 1.);
182  descriptions.addWithDefaultLabel(desc);
183 }
float dydz
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
const edm::EDGetTokenT< ZVertexHeterogeneous > tokenSoAVertexGPU_
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
float dxdz
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
~SiPixelPhase1CompareVertexSoA() override=default
void Fill(long long x)
void bookHistograms(DQMStore::IBooker &ibooker, edm::Run const &iRun, edm::EventSetup const &iSetup) override
int iEvent
Definition: GenABIO.cc:224
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static const GlobalPoint notFound(0, 0, 0)
const edm::EDGetTokenT< ZVertexHeterogeneous > tokenSoAVertexCPU_
fixed size matrix
HLT enums.
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) override
SiPixelPhase1CompareVertexSoA(const edm::ParameterSet &)
Log< level::Warning, false > LogWarning
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
const edm::EDGetTokenT< reco::BeamSpot > tokenBeamSpot_
MonitorElement * book2I(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:296
Definition: Run.h:45