CMS 3D CMS Logo

SiPixelCompareVertexSoAAlpaka.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 // Package: SiPixelCompareVertexSoAAlpaka
3 // Class: SiPixelCompareVertexSoAAlpaka
4 //
7 //
8 // Author: Suvankar Roy Chowdhury
9 //
17 // DQM Histograming
23 
25 public:
26  using IndToEdm = std::vector<uint16_t>;
28  ~SiPixelCompareVertexSoAAlpaka() 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 
56 // Note tokenSoAVertexDevice_ contains data copied from device to host, hence is a HostCollection
58  : tokenSoAVertexHost_(consumes<ZVertexHost>(iConfig.getParameter<edm::InputTag>("pixelVertexSrcHost"))),
59  tokenSoAVertexDevice_(consumes<ZVertexHost>(iConfig.getParameter<edm::InputTag>("pixelVertexSrcDevice"))),
60  tokenBeamSpot_(consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamSpotSrc"))),
61  topFolderName_(iConfig.getParameter<std::string>("topFolderName")),
62  dzCut_(iConfig.getParameter<double>("dzCut")) {}
63 
64 //
65 // -- Analyze
66 //
68  const auto& vsoaHandleHost = iEvent.getHandle(tokenSoAVertexHost_);
69  const auto& vsoaHandleDevice = iEvent.getHandle(tokenSoAVertexDevice_);
70  if (not vsoaHandleHost or not vsoaHandleDevice) {
71  edm::LogWarning out("SiPixelCompareVertexSoAAlpaka");
72  if (not vsoaHandleHost) {
73  out << "reference (cpu) tracks not found; ";
74  }
75  if (not vsoaHandleDevice) {
76  out << "target (gpu) tracks not found; ";
77  }
78  out << "the comparison will not run.";
79  return;
80  }
81 
82  auto const& vsoaHost = *vsoaHandleHost;
83  int nVerticesHost = vsoaHost.view().nvFinal();
84  auto const& vsoaDevice = *vsoaHandleDevice;
85  int nVerticesDevice = vsoaDevice.view().nvFinal();
86 
87  auto bsHandle = iEvent.getHandle(tokenBeamSpot_);
88  float x0 = 0., y0 = 0., z0 = 0., dxdz = 0., dydz = 0.;
89  if (!bsHandle.isValid()) {
90  edm::LogWarning("SiPixelCompareVertexSoAAlpaka") << "No beamspot found. returning vertexes with (0,0,Z) ";
91  } else {
92  const reco::BeamSpot& bs = *bsHandle;
93  x0 = bs.x0();
94  y0 = bs.y0();
95  z0 = bs.z0();
96  dxdz = bs.dxdz();
97  dydz = bs.dydz();
98  }
99 
100  for (int ivc = 0; ivc < nVerticesHost; ivc++) {
101  auto sic = vsoaHost.view()[ivc].sortInd();
102  auto zc = vsoaHost.view()[sic].zv();
103  auto xc = x0 + dxdz * zc;
104  auto yc = y0 + dydz * zc;
105  zc += z0;
106 
107  auto ndofHost = vsoaHost.view()[sic].ndof();
108  auto chi2Host = vsoaHost.view()[sic].chi2();
109 
110  const int32_t notFound = -1;
111  int32_t closestVtxidx = notFound;
112  float mindz = dzCut_;
113 
114  for (int ivg = 0; ivg < nVerticesDevice; ivg++) {
115  auto sig = vsoaDevice.view()[ivg].sortInd();
116  auto zgc = vsoaDevice.view()[sig].zv() + z0;
117  auto zDist = std::abs(zc - zgc);
118  //insert some matching condition
119  if (zDist > dzCut_)
120  continue;
121  if (mindz > zDist) {
122  mindz = zDist;
123  closestVtxidx = sig;
124  }
125  }
126  if (closestVtxidx == notFound)
127  continue;
128 
129  auto zg = vsoaDevice.view()[closestVtxidx].zv();
130  auto xg = x0 + dxdz * zg;
131  auto yg = y0 + dydz * zg;
132  zg += z0;
133  auto ndofDevice = vsoaDevice.view()[closestVtxidx].ndof();
134  auto chi2Device = vsoaDevice.view()[closestVtxidx].chi2();
135 
136  hx_->Fill(xc - x0, xg - x0);
137  hy_->Fill(yc - y0, yg - y0);
138  hz_->Fill(zc, zg);
139  hxdiff_->Fill(xc - xg);
140  hydiff_->Fill(yc - yg);
141  hzdiff_->Fill(zc - zg);
142  hchi2_->Fill(chi2Host, chi2Device);
143  hchi2oNdof_->Fill(chi2Host / ndofHost, chi2Device / ndofDevice);
144  hptv2_->Fill(vsoaHost.view()[sic].ptv2(), vsoaDevice.view()[closestVtxidx].ptv2());
145  hntrks_->Fill(ndofHost + 1, ndofDevice + 1);
146  }
147  hnVertex_->Fill(nVerticesHost, nVerticesDevice);
148 }
149 
150 //
151 // -- Book Histograms
152 //
154  edm::Run const& iRun,
155  edm::EventSetup const& iSetup) {
156  ibooker.cd();
158 
159  // 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
160  // these should be moved to a less resource consuming format
161  hnVertex_ = ibooker.book2I("nVertex", "# of Vertices;Host;Device", 101, -0.5, 100.5, 101, -0.5, 100.5);
162  hx_ = ibooker.book2I("vx", "Vertez x - Beamspot x;Host;Device", 50, -0.1, 0.1, 50, -0.1, 0.1);
163  hy_ = ibooker.book2I("vy", "Vertez y - Beamspot y;Host;Device", 50, -0.1, 0.1, 50, -0.1, 0.1);
164  hz_ = ibooker.book2I("vz", "Vertez z;Host;Device", 30, -30., 30., 30, -30., 30.);
165  hchi2_ = ibooker.book2I("chi2", "Vertex chi-squared;Host;Device", 40, 0., 20., 40, 0., 20.);
166  hchi2oNdof_ = ibooker.book2I("chi2oNdof", "Vertex chi-squared/Ndof;Host;Device", 40, 0., 20., 40, 0., 20.);
167  hptv2_ = ibooker.book2I("ptsq", "Vertex #sum (p_{T})^{2};Host;Device", 200, 0., 200., 200, 0., 200.);
168  hntrks_ = ibooker.book2I("ntrk", "#tracks associated;Host;Device", 100, -0.5, 99.5, 100, -0.5, 99.5);
169  hntrks_ = ibooker.book2I("ntrk", "#tracks associated;Host;Device", 100, -0.5, 99.5, 100, -0.5, 99.5);
170  hxdiff_ = ibooker.book1D("vxdiff", ";Vertex x difference (Host - Device);#entries", 100, -0.001, 0.001);
171  hydiff_ = ibooker.book1D("vydiff", ";Vertex y difference (Host - Device);#entries", 100, -0.001, 0.001);
172  hzdiff_ = ibooker.book1D("vzdiff", ";Vertex z difference (Host - Device);#entries", 100, -2.5, 2.5);
173 }
174 
176  // monitorpixelVertexSoA
178  desc.add<edm::InputTag>("pixelVertexSrcHost", edm::InputTag("pixelVerticesAlpakaSerial"));
179  desc.add<edm::InputTag>("pixelVertexSrcDevice", edm::InputTag("pixelVerticesAlpaka"));
180  desc.add<edm::InputTag>("beamSpotSrc", edm::InputTag("offlineBeamSpot"));
181  desc.add<std::string>("topFolderName", "SiPixelHeterogeneous/PixelVertexCompareSoADeviceVSHost");
182  desc.add<double>("dzCut", 1.);
183  descriptions.addWithDefaultLabel(desc);
184 }
185 
float dydz
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) override
const edm::EDGetTokenT< reco::BeamSpot > tokenBeamSpot_
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
float dxdz
void bookHistograms(DQMStore::IBooker &ibooker, edm::Run const &iRun, edm::EventSetup const &iSetup) override
void Fill(long long x)
const edm::EDGetTokenT< ZVertexHost > tokenSoAVertexDevice_
int iEvent
Definition: GenABIO.cc:224
~SiPixelCompareVertexSoAAlpaka() override=default
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
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
SiPixelCompareVertexSoAAlpaka(const edm::ParameterSet &)
static const GlobalPoint notFound(0, 0, 0)
const edm::EDGetTokenT< ZVertexHost > tokenSoAVertexHost_
fixed size matrix
HLT enums.
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
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