CMS 3D CMS Logo

SiPixelCompareVertices.cc
Go to the documentation of this file.
1 // TODO: change file name to SiPixelCompareVerticesSoA.cc when CUDA code is removed
2 
3 // -*- C++ -*-
4 // Package: SiPixelCompareVertices
5 // Class: SiPixelCompareVertices
6 //
9 //
10 // Author: Suvankar Roy Chowdhury
11 //
19 // DQM Histograming
26 
27 // TODO: change class name to SiPixelCompareVerticesSoA when CUDA code is removed
29 public:
30  using IndToEdm = std::vector<uint16_t>;
32  ~SiPixelCompareVertices() override = default;
33  void bookHistograms(DQMStore::IBooker& ibooker, edm::Run const& iRun, edm::EventSetup const& iSetup) override;
34  void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override;
35  // analyzeSeparate is templated to accept distinct types of SoAs
36  // The default use case is to use vertices from Alpaka reconstructed on CPU and GPU;
37  template <typename U, typename V>
38  void analyzeSeparate(U tokenRef, V tokenTar, const edm::Event& iEvent);
39  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
40 
41 private:
42  // these two are both on Host but originally they have been produced on Host or on Device
47  const float dzCut_;
59 };
60 
61 //
62 // constructors
63 //
64 
66  : tokenSoAVertexReferenceSoA_(
67  consumes<ZVertexHost>(iConfig.getParameter<edm::InputTag>("pixelVertexReferenceSoA"))),
68  tokenSoAVertexTargetSoA_(consumes<ZVertexHost>(iConfig.getParameter<edm::InputTag>("pixelVertexTargetSoA"))),
69  tokenBeamSpot_(consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamSpotSrc"))),
70  topFolderName_(iConfig.getParameter<std::string>("topFolderName")),
71  dzCut_(iConfig.getParameter<double>("dzCut")) {}
72 
73 template <typename U, typename V>
74 void SiPixelCompareVertices::analyzeSeparate(U tokenRef, V tokenTar, const edm::Event& iEvent) {
75  const auto& vsoaHandleRef = iEvent.getHandle(tokenRef);
76  const auto& vsoaHandleTar = iEvent.getHandle(tokenTar);
77 
78  if (not vsoaHandleRef or not vsoaHandleTar) {
79  edm::LogWarning out("SiPixelCompareVertices");
80  if (not vsoaHandleRef) {
81  out << "reference vertices not found; ";
82  }
83  if (not vsoaHandleTar) {
84  out << "Refget vertices not found; ";
85  }
86  out << "the comparison will not run.";
87  return;
88  }
89 
90  auto const& vsoaRef = *vsoaHandleRef;
91  int nVerticesRef = vsoaRef.view().nvFinal();
92  auto const& vsoaTar = *vsoaHandleTar;
93  int nVerticesTar = vsoaTar.view().nvFinal();
94 
95  auto bsHandle = iEvent.getHandle(tokenBeamSpot_);
96  float x0 = 0., y0 = 0., z0 = 0., dxdz = 0., dydz = 0.;
97  if (!bsHandle.isValid()) {
98  edm::LogWarning("SiPixelCompareVertices") << "No beamspot found. returning vertexes with (0,0,Z) ";
99  } else {
100  const reco::BeamSpot& bs = *bsHandle;
101  x0 = bs.x0();
102  y0 = bs.y0();
103  z0 = bs.z0();
104  dxdz = bs.dxdz();
105  dydz = bs.dydz();
106  }
107 
108  for (int ivc = 0; ivc < nVerticesRef; ivc++) {
109  auto sic = vsoaRef.view()[ivc].sortInd();
110  auto zc = vsoaRef.view()[sic].zv();
111  auto xc = x0 + dxdz * zc;
112  auto yc = y0 + dydz * zc;
113  zc += z0;
114 
115  auto ndofRef = vsoaRef.view()[sic].ndof();
116  auto chi2Ref = vsoaRef.view()[sic].chi2();
117 
118  const int32_t notFound = -1;
119  int32_t closestVtxidx = notFound;
120  float mindz = dzCut_;
121 
122  for (int ivg = 0; ivg < nVerticesTar; ivg++) {
123  auto sig = vsoaTar.view()[ivg].sortInd();
124  auto zgc = vsoaTar.view()[sig].zv() + z0;
125  auto zDist = std::abs(zc - zgc);
126  //insert some matching condition
127  if (zDist > dzCut_)
128  continue;
129  if (mindz > zDist) {
130  mindz = zDist;
131  closestVtxidx = sig;
132  }
133  }
134  if (closestVtxidx == notFound)
135  continue;
136 
137  auto zg = vsoaTar.view()[closestVtxidx].zv();
138  auto xg = x0 + dxdz * zg;
139  auto yg = y0 + dydz * zg;
140  zg += z0;
141  auto ndofTar = vsoaTar.view()[closestVtxidx].ndof();
142  auto chi2Tar = vsoaTar.view()[closestVtxidx].chi2();
143 
144  hx_->Fill(xc - x0, xg - x0);
145  hy_->Fill(yc - y0, yg - y0);
146  hz_->Fill(zc, zg);
147  hxdiff_->Fill(xc - xg);
148  hydiff_->Fill(yc - yg);
149  hzdiff_->Fill(zc - zg);
150  hchi2_->Fill(chi2Ref, chi2Tar);
151  hchi2oNdof_->Fill(chi2Ref / ndofRef, chi2Tar / ndofTar);
152  hptv2_->Fill(vsoaRef.view()[sic].ptv2(), vsoaTar.view()[closestVtxidx].ptv2());
153  hntrks_->Fill(ndofRef + 1, ndofTar + 1);
154  }
155  hnVertex_->Fill(nVerticesRef, nVerticesTar);
156 }
157 
158 //
159 // -- Analyze
160 //
162  // The default use case is to use vertices from Alpaka reconstructed on CPU and GPU;
163  // The function is left templated if any other cases need to be added
165 }
166 
167 //
168 // -- Book Histograms
169 //
171  edm::Run const& iRun,
172  edm::EventSetup const& iSetup) {
173  ibooker.cd();
175 
176  // 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
177  // these should be moved to a less resource consuming format
178  hnVertex_ = ibooker.book2I("nVertex", "# of Vertices;Reference;Target", 101, -0.5, 100.5, 101, -0.5, 100.5);
179  hx_ = ibooker.book2I("vx", "Vertez x - Beamspot x;Reference;Target", 50, -0.1, 0.1, 50, -0.1, 0.1);
180  hy_ = ibooker.book2I("vy", "Vertez y - Beamspot y;Reference;Target", 50, -0.1, 0.1, 50, -0.1, 0.1);
181  hz_ = ibooker.book2I("vz", "Vertez z;Reference;Target", 30, -30., 30., 30, -30., 30.);
182  hchi2_ = ibooker.book2I("chi2", "Vertex chi-squared;Reference;Target", 40, 0., 20., 40, 0., 20.);
183  hchi2oNdof_ = ibooker.book2I("chi2oNdof", "Vertex chi-squared/Ndof;Reference;Target", 40, 0., 20., 40, 0., 20.);
184  hptv2_ = ibooker.book2I("ptsq", "Vertex #sum (p_{T})^{2};Reference;Target", 200, 0., 200., 200, 0., 200.);
185  hntrks_ = ibooker.book2I("ntrk", "#tracks associated;Reference;Target", 100, -0.5, 99.5, 100, -0.5, 99.5);
186  hntrks_ = ibooker.book2I("ntrk", "#tracks associated;Reference;Target", 100, -0.5, 99.5, 100, -0.5, 99.5);
187  hxdiff_ = ibooker.book1D("vxdiff", ";Vertex x difference (Reference - Target);#entries", 100, -0.001, 0.001);
188  hydiff_ = ibooker.book1D("vydiff", ";Vertex y difference (Reference - Target);#entries", 100, -0.001, 0.001);
189  hzdiff_ = ibooker.book1D("vzdiff", ";Vertex z difference (Reference - Target);#entries", 100, -2.5, 2.5);
190 }
191 
193  // monitorpixelVertexSoA
195  desc.add<edm::InputTag>("pixelVertexReferenceSoA", edm::InputTag("pixelVerticesAlpakaSerial"));
196  desc.add<edm::InputTag>("pixelVertexTargetSoA", edm::InputTag("pixelVerticesAlpaka"));
197  desc.add<edm::InputTag>("beamSpotSrc", edm::InputTag("offlineBeamSpot"));
198  desc.add<std::string>("topFolderName", "SiPixelHeterogeneous/PixelVertexCompareSoADeviceVSHost");
199  desc.add<double>("dzCut", 1.);
200  descriptions.addWithDefaultLabel(desc);
201 }
202 
203 // TODO: change module name to SiPixelCompareVerticesSoA when CUDA code is removed
float dydz
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
const std::string topFolderName_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
float dxdz
SiPixelCompareVertices(const edm::ParameterSet &)
const edm::EDGetTokenT< reco::BeamSpot > tokenBeamSpot_
std::vector< uint16_t > IndToEdm
void Fill(long long x)
int iEvent
Definition: GenABIO.cc:224
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t V
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
const edm::EDGetTokenT< ZVertexHost > tokenSoAVertexTargetSoA_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void analyzeSeparate(U tokenRef, V tokenTar, const edm::Event &iEvent)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const edm::EDGetTokenT< ZVertexHost > tokenSoAVertexReferenceSoA_
static const GlobalPoint notFound(0, 0, 0)
fixed size matrix
HLT enums.
void bookHistograms(DQMStore::IBooker &ibooker, edm::Run const &iRun, edm::EventSetup const &iSetup) override
Log< level::Warning, false > LogWarning
~SiPixelCompareVertices() override=default
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:305
void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) override
Definition: Run.h:45