Skip to content

Commit

Permalink
Update plots for sim and reco vertex densities and multiplicity
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiocos committed Oct 21, 2024
1 parent 7373243 commit 442eda9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 43 deletions.
45 changes: 31 additions & 14 deletions Validation/MtdValidation/plugins/Primary4DVertexHarvester.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Primary4DVertexHarvester : public DQMEDHarvester {

private:
void computeEfficiency1D(MonitorElement* num, MonitorElement* den, MonitorElement* result);
void scaleby(MonitorElement* h, double scale);

void incrementME(MonitorElement* base, MonitorElement* toBeAdded);

Expand Down Expand Up @@ -111,6 +112,17 @@ void Primary4DVertexHarvester::computeEfficiency1D(MonitorElement* num, MonitorE
}
}

void Primary4DVertexHarvester::scaleby(MonitorElement* h, double scale) {
double ent = h->getEntries();
for (int ibin = 1; ibin <= h->getNbinsX(); ibin++) {
double eff = h->getBinContent(ibin) * scale;
double bin_err = h->getBinError(ibin) * scale;
h->setBinContent(ibin, eff);
h->setBinError(ibin, bin_err);
}
h->setEntries(ent);
}

// auxiliary method to add 1D MonitorElement toBeAdded to a base ME
void Primary4DVertexHarvester::incrementME(MonitorElement* base, MonitorElement* toBeAdded) {
for (int ibin = 1; ibin <= base->getNbinsX(); ibin++) {
Expand All @@ -130,27 +142,32 @@ void Primary4DVertexHarvester::dqmEndJob(DQMStore::IBooker& ibook, DQMStore::IGe
MonitorElement* meTrackEffEtaTot = igetter.get(folder_ + "EffEtaTot");
MonitorElement* meTrackMatchedTPEffEtaTot = igetter.get(folder_ + "MatchedTPEffEtaTot");
MonitorElement* meTrackMatchedTPEffEtaMtd = igetter.get(folder_ + "MatchedTPEffEtaMtd");
MonitorElement* meRecoVtxVsLineDensity = igetter.get(folder_ + "RecoVtxVsLineDensity");
MonitorElement* meRecVerNumber = igetter.get(folder_ + "RecVerNumber");
MonitorElement* meRecVerZ = igetter.get(folder_ + "recPVZ");
MonitorElement* meRecVerT = igetter.get(folder_ + "recPVT");
MonitorElement* meSimVerNumber = igetter.get(folder_ + "SimVerNumber");
MonitorElement* meSimVerZ = igetter.get(folder_ + "simPVZ");
MonitorElement* meSimVerT = igetter.get(folder_ + "simPVT");

if (!meTrackEffPtTot || !meTrackMatchedTPEffPtTot || !meTrackMatchedTPEffPtMtd || !meTrackEffEtaTot ||
!meTrackMatchedTPEffEtaTot || !meTrackMatchedTPEffEtaMtd || !meRecoVtxVsLineDensity || !meRecVerNumber) {
!meTrackMatchedTPEffEtaTot || !meTrackMatchedTPEffEtaMtd || !meRecVerNumber || !meRecVerZ || !meRecVerT ||
!meSimVerNumber || !meSimVerZ || !meSimVerT) {
edm::LogError("Primary4DVertexHarvester") << "Monitoring histograms not found!" << std::endl;
return;
}

// Normalize line density plot
double nEvt = meRecVerNumber->getEntries();
if (nEvt > 0.) {
nEvt = 1. / nEvt;
double nEntries = meRecoVtxVsLineDensity->getEntries();
for (int ibin = 1; ibin <= meRecoVtxVsLineDensity->getNbinsX(); ibin++) {
double cont = meRecoVtxVsLineDensity->getBinContent(ibin) * nEvt;
double bin_err = meRecoVtxVsLineDensity->getBinError(ibin) * nEvt;
meRecoVtxVsLineDensity->setBinContent(ibin, cont);
meRecoVtxVsLineDensity->setBinError(ibin, bin_err);
}
meRecoVtxVsLineDensity->setEntries(nEntries);
// Normalize z,time multiplicty plots to get correct line densities
double scale = meRecVerNumber->getTH1F()->Integral();
scale = (scale > 0.) ? 1. / scale : 0.;
if (scale > 0.) {
scaleby(meRecVerZ, scale);
scaleby(meRecVerT, scale);
}
scale = meSimVerNumber->getTH1F()->Integral();
scale = (scale > 0.) ? 1. / scale : 0.;
if (scale > 0.) {
scaleby(meSimVerZ, scale);
scaleby(meSimVerT, scale);
}

// --- Book histograms
Expand Down
39 changes: 10 additions & 29 deletions Validation/MtdValidation/plugins/Primary4DVertexValidation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ class Primary4DVertexValidation : public DQMEDAnalyzer {
const double minProbHeavy_;
const double trackweightTh_;
const double mvaTh_;
const std::vector<double> lineDensityPar_;
const reco::RecoToSimCollection* r2s_;
const reco::SimToRecoCollection* s2r_;

Expand Down Expand Up @@ -371,7 +370,9 @@ class Primary4DVertexValidation : public DQMEDAnalyzer {
MonitorElement* meRecVerNumber_;
MonitorElement* meRecPVZ_;
MonitorElement* meRecPVT_;
MonitorElement* meSimVerNumber_;
MonitorElement* meSimPVZ_;
MonitorElement* meSimPVT_;

MonitorElement* meVtxTrackMult_;
MonitorElement* meVtxTrackW_;
Expand Down Expand Up @@ -528,7 +529,6 @@ Primary4DVertexValidation::Primary4DVertexValidation(const edm::ParameterSet& iC
minProbHeavy_(iConfig.getParameter<double>("minProbHeavy")),
trackweightTh_(iConfig.getParameter<double>("trackweightTh")),
mvaTh_(iConfig.getParameter<double>("mvaTh")),
lineDensityPar_(iConfig.getParameter<std::vector<double>>("lineDensityPar")),
pdtToken_(esConsumes<HepPDT::ParticleDataTable, edm::DefaultRecord>()) {
vecPileupSummaryInfoToken_ = consumes<std::vector<PileupSummaryInfo>>(edm::InputTag(std::string("addPileupInfo")));
trackingParticleCollectionToken_ =
Expand Down Expand Up @@ -696,12 +696,12 @@ void Primary4DVertexValidation::bookHistograms(DQMStore::IBooker& ibook,
20,
0,
20);
meRecoVtxVsLineDensity_ =
ibook.book1D("RecoVtxVsLineDensity", "#Reco vertices/mm/event; line density [#vtx/mm/event]", 160, 0., 4.);
meRecVerNumber_ = ibook.book1D("RecVerNumber", "RECO Vertex Number: Number of vertices", 50, 0, 250);
meRecPVZ_ = ibook.book1D("recPVZ", "Weighted #Rec vertices/mm", 400, -20., 20.);
meSimVerNumber_ = ibook.book1D("SimVerNumber", "SIM Vertex Number: Number of vertices", 50, 0, 250);
meRecPVZ_ = ibook.book1D("recPVZ", "#Rec vertices/mm", 400, -20., 20.);
meRecPVT_ = ibook.book1D("recPVT", "#Rec vertices/10 ps", 200, -1., 1.);
meSimPVZ_ = ibook.book1D("simPVZ", "Weighted #Sim vertices/mm", 400, -20., 20.);
meSimPVZ_ = ibook.book1D("simPVZ", "#Sim vertices/mm", 400, -20., 20.);
meSimPVT_ = ibook.book1D("simPVT", "#Sim vertices/10 ps", 200, -1., 1.);

meVtxTrackMult_ = ibook.book1D("VtxTrackMult", "Log10(Vertex track multiplicity)", 80, 0.5, 2.5);
meVtxTrackW_ = ibook.book1D("VtxTrackW", "Vertex track weight (all)", 50, 0., 1.);
Expand Down Expand Up @@ -2599,23 +2599,14 @@ void Primary4DVertexValidation::analyze(const edm::Event& iEvent, const edm::Eve
int other_fake = 0;
int split = 0;

auto puLineDensity = [&](double z) {
// gaussian parameterization of line density vs z, z in cm, parameters in mm
double argl = (z * 10. - lineDensityPar_[1]) / lineDensityPar_[2];
return lineDensityPar_[0] * exp(-0.5 * argl * argl);
};

meRecVerNumber_->Fill(recopv.size());
for (unsigned int ir = 0; ir < recopv.size(); ir++) {
if (recopv.at(ir).ndof > selNdof_) {
meRecoVtxVsLineDensity_->Fill(puLineDensity(recopv.at(ir).z));
meRecPVZ_->Fill(recopv.at(ir).z, 1. / puLineDensity(recopv.at(ir).z));
meRecPVZ_->Fill(recopv.at(ir).z);
if (recopv.at(ir).recVtx->tError() > 0.) {
meRecPVT_->Fill(recopv.at(ir).recVtx->t());
}
LogTrace("Primary4DVertexValidation") << "************* IR: " << ir;
LogTrace("Primary4DVertexValidation")
<< "z: " << recopv.at(ir).z << " corresponding to line density: " << puLineDensity(recopv.at(ir).z);
LogTrace("Primary4DVertexValidation") << "is_real: " << recopv.at(ir).is_real();
LogTrace("Primary4DVertexValidation") << "is_fake: " << recopv.at(ir).is_fake();
LogTrace("Primary4DVertexValidation") << "is_signal: " << recopv.at(ir).is_signal();
Expand Down Expand Up @@ -2646,12 +2637,10 @@ void Primary4DVertexValidation::analyze(const edm::Event& iEvent, const edm::Eve
mePUvsSplitV_->Fill(simpv.size(), split);

// fill vertices histograms here in a new loop
meSimVerNumber_->Fill(simpv.size());
for (unsigned int is = 0; is < simpv.size(); is++) {
// protect against particle guns with very displaced vertices
if (edm::isNotFinite(1. / puLineDensity(simpv.at(is).z))) {
continue;
}
meSimPVZ_->Fill(simpv.at(is).z, 1. / puLineDensity(simpv.at(is).z));
meSimPVZ_->Fill(simpv.at(is).z);
meSimPVT_->Fill(simpv.at(is).t * simUnit_);
if (is == 0 && optionalPlots_) {
meSimPosInSimOrigCollection_->Fill(simpv.at(is).OriginalIndex);
}
Expand Down Expand Up @@ -2788,14 +2777,6 @@ void Primary4DVertexValidation::fillDescriptions(edm::ConfigurationDescriptions&
desc.add<double>("trackweightTh", 0.5);
desc.add<double>("mvaTh", 0.8);
desc.add<double>("minProbHeavy", 0.75);

//lineDensity parameters have been obtained by fitting the distribution of the z position of the vertices,
//using a 200k single mu ptGun sample (gaussian fit)
std::vector<double> lDP;
lDP.push_back(1.87);
lDP.push_back(0.);
lDP.push_back(42.5);
desc.add<std::vector<double>>("lineDensityPar", lDP);
descriptions.add("vertices4DValid", desc);
}

Expand Down

0 comments on commit 442eda9

Please sign in to comment.