Skip to content

Commit

Permalink
provide 1D projections from 2D GPU vs CPU scatter plots
Browse files Browse the repository at this point in the history
  • Loading branch information
mmusich committed Jan 9, 2023
1 parent 218cbd4 commit 6a143cc
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 3 deletions.
6 changes: 4 additions & 2 deletions DQM/SiPixelHeterogeneous/plugins/SiPixelCompareTrackSoA.cc
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ void SiPixelCompareTrackSoA<T>::analyze(const edm::Event& iEvent, const edm::Eve
nLooseAndAboveTracksCPU_matchedGPU++;

hchi2_->Fill(tsoaCPU.chi2(it), tsoaGPU.chi2(closestTkidx));
hCharge_->Fill(tsoaCPU.charge(it), tsoaGPU.charge(closestTkidx));
hnHits_->Fill(tsoaCPU.nHits(it), tsoaGPU.nHits(closestTkidx));
hnLayers_->Fill(tsoaCPU.nLayers(it), tsoaGPU.nLayers(closestTkidx));
hpt_->Fill(tsoaCPU.pt(it), tsoaGPU.pt(closestTkidx));
Expand All @@ -217,7 +218,8 @@ void SiPixelCompareTrackSoA<T>::analyze(const edm::Event& iEvent, const edm::Eve
hz_->Fill(tsoaCPU.zip(it), tsoaGPU.zip(closestTkidx));
htip_->Fill(tsoaCPU.tip(it), tsoaGPU.tip(closestTkidx));
hptdiffMatched_->Fill(tsoaCPU.pt(it) - tsoaGPU.pt(closestTkidx));
hCurvdiffMatched_->Fill((tsoaCPU.charge(it) / tsoaCPU.pt(it)) - (tsoaGPU.charge(closestTkidx) / tsoaGPU.pt(closestTkidx)));
hCurvdiffMatched_->Fill((tsoaCPU.charge(it) / tsoaCPU.pt(it)) -
(tsoaGPU.charge(closestTkidx) / tsoaGPU.pt(closestTkidx)));
hetadiffMatched_->Fill(etacpu - tsoaGPU.eta(closestTkidx));
hphidiffMatched_->Fill(reco::deltaPhi(phicpu, tsoaGPU.phi(closestTkidx)));
hzdiffMatched_->Fill(tsoaCPU.zip(it) - tsoaGPU.zip(closestTkidx));
Expand All @@ -242,7 +244,7 @@ void SiPixelCompareTrackSoA<T>::bookHistograms(DQMStore::IBooker& iBook,

// clang-format off
std::string toRep = "Number of tracks";
// 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
// FIXME: all the 2D correlation plots are quite heavy in terms of memory consumption, so a as soon as DQM supports THnSparse
// these should be moved to a less resource consuming format
hnTracks_ = iBook.book2I("nTracks", fmt::sprintf("%s per event; CPU; GPU",toRep), 501, -0.5, 500.5, 501, -0.5, 500.5);
hnLooseAndAboveTracks_ = iBook.book2I("nLooseAndAboveTracks", fmt::sprintf("%s (quality #geq loose) per event; CPU; GPU",toRep), 501, -0.5, 500.5, 501, -0.5, 500.5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "FWCore/Framework/interface/MakerMacros.h"

// for string manipulations
#include <fmt/printf.h>

class SiPixelTrackComparisonHarvester : public DQMEDHarvester {
public:
explicit SiPixelTrackComparisonHarvester(const edm::ParameterSet&);
~SiPixelTrackComparisonHarvester() override = default;
void dqmEndJob(DQMStore::IBooker& ibooker, DQMStore::IGetter& igetter) override;

void project2DalongDiagonal(MonitorElement* input2D, DQMStore::IBooker& ibooker);
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

private:
Expand Down Expand Up @@ -45,6 +49,56 @@ void SiPixelTrackComparisonHarvester::dqmEndJob(DQMStore::IBooker& ibooker, DQMS

hpt_eta_matchRatio->divide(hpt_eta_tkAllCPUmatched, hpt_eta_tkAllCPU, 1., 1., "B");
hphi_z_matchRatio->divide(hphi_z_tkAllCPUmatched, hphi_z_tkAllCPU, 1., 1., "B");

// now create the 1D projection from the 2D histograms
std::vector<std::string> listOfMEsToProject = {"nTracks",
"nLooseAndAboveTracks",
"nLooseAndAboveTracks_matched",
"nRecHits",
"nLayers",
"nChi2ndof",
"charge",
"pt",
"eta",
"phi",
"z",
"tip"};
for (const auto& me : listOfMEsToProject) {
MonitorElement* input2D = igetter.get(topFolder_ + "/" + me);
this->project2DalongDiagonal(input2D, ibooker);
}
}

void SiPixelTrackComparisonHarvester::project2DalongDiagonal(MonitorElement* input2D,
DQMStore::IBooker& ibooker) {
if (input2D == nullptr) {
edm::LogError("SiPixelTrackComparisonHarvester")
<< "MEs needed for diagonal projection are not found in the input file. Skipping.";
return;
}

ibooker.cd();
ibooker.setCurrentFolder(topFolder_ + "/projectedDifferences");
const auto& h_name = fmt::sprintf("%s_proj", input2D->getName());
const auto& h_title = fmt::sprintf(";%s CPU -GPU difference", input2D->getTitle());
const auto& span = (input2D->getAxisMax() - input2D->getAxisMin());
const auto& b_w = span / input2D->getNbinsX();
const auto& nbins = ((input2D->getNbinsX() % 2) == 0) ? input2D->getNbinsX() + 1 : input2D->getNbinsX();

MonitorElement* diagonalized = ibooker.book1D(h_name, h_title, nbins, -span / 2., span / 2.);

// collect all the entry on each diagonal of the 2D histogram
for (int i = 1; i <= input2D->getNbinsX(); i++) {
for (int j = 1; j <= input2D->getNbinsY(); j++) {
diagonalized->Fill((i - j) * b_w, input2D->getBinContent(i, j));
}
}

// zero the error on the bin as it's sort of meaningless for the way we fill it
// by collecting the entry on each diagonal
for (int bin = 1; bin <= diagonalized->getNbinsX(); bin++) {
diagonalized->setBinError(bin, 0.f);
}
}

#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
Expand Down

0 comments on commit 6a143cc

Please sign in to comment.