From 3df72eb36690d76b7ee06aaaaf4d73a406f37da9 Mon Sep 17 00:00:00 2001 From: mmusich Date: Wed, 2 Aug 2023 14:50:48 +0200 Subject: [PATCH 1/6] add unbalance histograms for pointing angle --- DQMOffline/Alignment/interface/DiMuonVertexMonitor.h | 2 ++ DQMOffline/Alignment/src/DiMuonVertexMonitor.cc | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/DQMOffline/Alignment/interface/DiMuonVertexMonitor.h b/DQMOffline/Alignment/interface/DiMuonVertexMonitor.h index 567f538a80db9..f79003a9f051c 100644 --- a/DQMOffline/Alignment/interface/DiMuonVertexMonitor.h +++ b/DQMOffline/Alignment/interface/DiMuonVertexMonitor.h @@ -76,6 +76,8 @@ class DiMuonVertexMonitor : public DQMEDAnalyzer { MonitorElement *hCosPhi3D_; MonitorElement *hCosPhiInv_; MonitorElement *hCosPhiInv3D_; + MonitorElement *hCosPhiUnbalance_; + MonitorElement *hCosPhi3DUnbalance_; MonitorElement *hInvMass_; MonitorElement *hCutFlow_; diff --git a/DQMOffline/Alignment/src/DiMuonVertexMonitor.cc b/DQMOffline/Alignment/src/DiMuonVertexMonitor.cc index b55a78a39eadb..ad9979c813e8f 100644 --- a/DQMOffline/Alignment/src/DiMuonVertexMonitor.cc +++ b/DQMOffline/Alignment/src/DiMuonVertexMonitor.cc @@ -91,6 +91,8 @@ void DiMuonVertexMonitor::bookHistograms(DQMStore::IBooker& iBooker, edm::Run co hCosPhi3D_ = iBooker.book1D("CosPhi3D", fmt::sprintf("%s;cos(#phi_{3D});%s", histTit, ps), 50, -1., 1.); hCosPhiInv_ = iBooker.book1D("CosPhiInv", fmt::sprintf("%s;inverted cos(#phi_{xy});%s", histTit, ps), 50, -1., 1.); hCosPhiInv3D_ = iBooker.book1D("CosPhiInv3D", fmt::sprintf("%s;inverted cos(#phi_{3D});%s", histTit, ps), 50, -1., 1.); + hCosPhiUnbalance_ = iBooker.book1D("CosPhiUnbalance", fmt::sprintf("%s;cos(#phi_{xy}) unbalance;#Delta%s", histTit, ps), 50, -1.,1.); + hCosPhi3DUnbalance_ = iBooker.book1D("CosPhi3DUnbalance", fmt::sprintf("%s;cos(#phi_{3D}) unbalance;#Delta%s", histTit, ps), 50, -1., 1.); hdxy_ = iBooker.book1D("dxy", fmt::sprintf("%s;muon track d_{xy}(PV) [#mum];muon tracks", histTit), 150, -300, 300); hdz_ = iBooker.book1D("dz", fmt::sprintf("%s;muon track d_{z}(PV) [#mum];muon tracks", histTit), 150, -300, 300); @@ -252,6 +254,12 @@ void DiMuonVertexMonitor::analyze(const edm::Event& iEvent, const edm::EventSetu // inverted hCosPhiInv_->Fill(-cosphi); hCosPhiInv3D_->Fill(-cosphi3D); + + // unbalance + hCosPhiUnbalance_->Fill(cosphi, 1.); + hCosPhiUnbalance_->Fill(-cosphi, -1.); + hCosPhi3DUnbalance_->Fill(cosphi3D, 1.); + hCosPhi3DUnbalance_->Fill(-cosphi3D, -1.); } } else { edm::LogWarning("DiMuonVertexMonitor") << "hardest primary vertex in the event is not valid!"; From 4bd3e49792c0a85412e7134876b5accba82445d4 Mon Sep 17 00:00:00 2001 From: mmusich Date: Fri, 4 Aug 2023 13:45:55 +0200 Subject: [PATCH 2/6] fix logic for using closest vertex and add more 2D monitoring plots --- .../Alignment/interface/DiMuonVertexMonitor.h | 21 ++++ .../Alignment/src/DiMuonVertexMonitor.cc | 109 +++++++++++++++++- 2 files changed, 127 insertions(+), 3 deletions(-) diff --git a/DQMOffline/Alignment/interface/DiMuonVertexMonitor.h b/DQMOffline/Alignment/interface/DiMuonVertexMonitor.h index f79003a9f051c..b6c1737c7c493 100644 --- a/DQMOffline/Alignment/interface/DiMuonVertexMonitor.h +++ b/DQMOffline/Alignment/interface/DiMuonVertexMonitor.h @@ -15,6 +15,7 @@ #include // user includes +#include "DQMOffline/Alignment/interface/DiLeptonPlotHelpers.h" #include "DQMServices/Core/interface/DQMEDAnalyzer.h" #include "DQMServices/Core/interface/DQMStore.h" #include "FWCore/Framework/interface/Event.h" @@ -81,6 +82,26 @@ class DiMuonVertexMonitor : public DQMEDAnalyzer { MonitorElement *hInvMass_; MonitorElement *hCutFlow_; + // 2D histograms of pointing angle vs variable + edm::ParameterSet CosPhi3DConfiguration_; + DiLepPlotHelp::PlotsVsKinematics CosPhi3DPlots_ = DiLepPlotHelp::PlotsVsKinematics(DiLepPlotHelp::MM); + + // 2D histograms of 3D PV-SV distance vs variable + edm::ParameterSet SVDistConfiguration_; + DiLepPlotHelp::PlotsVsKinematics SVDistPlots_ = DiLepPlotHelp::PlotsVsKinematics(DiLepPlotHelp::MM); + + // 2D histograms of 3D PV-SV distance significance vs variable + edm::ParameterSet SVDistSigConfiguration_; + DiLepPlotHelp::PlotsVsKinematics SVDistSigPlots_ = DiLepPlotHelp::PlotsVsKinematics(DiLepPlotHelp::MM); + + // 2D histograms of PV-SV transverse distance vs variable + edm::ParameterSet SVDist3DConfiguration_; + DiLepPlotHelp::PlotsVsKinematics SVDist3DPlots_ = DiLepPlotHelp::PlotsVsKinematics(DiLepPlotHelp::MM); + + // 2D histograms of PV-SV transverse distance significance vs variable + edm::ParameterSet SVDist3DSigConfiguration_; + DiLepPlotHelp::PlotsVsKinematics SVDist3DSigPlots_ = DiLepPlotHelp::PlotsVsKinematics(DiLepPlotHelp::MM); + // impact parameters information MonitorElement *hdxy_; MonitorElement *hdz_; diff --git a/DQMOffline/Alignment/src/DiMuonVertexMonitor.cc b/DQMOffline/Alignment/src/DiMuonVertexMonitor.cc index ad9979c813e8f..8fc14b3c3af70 100644 --- a/DQMOffline/Alignment/src/DiMuonVertexMonitor.cc +++ b/DQMOffline/Alignment/src/DiMuonVertexMonitor.cc @@ -33,7 +33,12 @@ DiMuonVertexMonitor::DiMuonVertexMonitor(const edm::ParameterSet& iConfig) motherName_(iConfig.getParameter("decayMotherName")), MEFolderName_(iConfig.getParameter("FolderName")), useClosestVertex_(iConfig.getParameter("useClosestVertex")), - maxSVdist_(iConfig.getParameter("maxSVdist")) { + maxSVdist_(iConfig.getParameter("maxSVdist")), + CosPhi3DConfiguration_(iConfig.getParameter("CosPhi3DConfig")), + SVDistConfiguration_(iConfig.getParameter("SVDistConfig")), + SVDistSigConfiguration_(iConfig.getParameter("SVDistSigConfig")), + SVDist3DConfiguration_(iConfig.getParameter("SVDist3DConfig")), + SVDist3DSigConfiguration_(iConfig.getParameter("SVDist3DSigConfig")) { if (motherName_.find('Z') != std::string::npos) { massLimits_ = std::make_pair(50., 120); } else if (motherName_.find("J/#psi") != std::string::npos) { @@ -103,6 +108,26 @@ void DiMuonVertexMonitor::bookHistograms(DQMStore::IBooker& iBooker, edm::Run co hIP2dsig_ = iBooker.book1D("IP2Dsig", fmt::sprintf("%s;muon track IP_{2D} significance;muon tracks", histTit), 100, 0., 5.); hIP3dsig_ = iBooker.book1D("IP3Dsig", fmt::sprintf("%s;muon track IP_{3D} significance;muon tracks", histTit), 100, 0., 5.); // clang-format on + + // now book the cosphi3D plots vs kinematics + iBooker.setCurrentFolder(MEFolderName_ + "/DiMuonVertexMonitor/CosPhi3DPlots"); + CosPhi3DPlots_.bookFromPSet(iBooker, CosPhi3DConfiguration_); + + // now book the PV-SV distance plots vs kinematics + iBooker.setCurrentFolder(MEFolderName_ + "/DiMuonVertexMonitor/SVDistPlots"); + SVDistPlots_.bookFromPSet(iBooker, SVDistConfiguration_); + + // now book the PV-SV distance significance plots vs kinematics + iBooker.setCurrentFolder(MEFolderName_ + "/DiMuonVertexMonitor/SVDistSigPlots"); + SVDistSigPlots_.bookFromPSet(iBooker, SVDistSigConfiguration_); + + // now book the PV-SV 3D distance plots vs kinematics + iBooker.setCurrentFolder(MEFolderName_ + "/DiMuonVertexMonitor/SVDist3DPlots"); + SVDist3DPlots_.bookFromPSet(iBooker, SVDist3DConfiguration_); + + // now book the PV-SV 3D distance significance plots vs kinematics + iBooker.setCurrentFolder(MEFolderName_ + "/DiMuonVertexMonitor/SVDist3DSigPlots"); + SVDist3DSigPlots_.bookFromPSet(iBooker, SVDist3DSigConfiguration_); } void DiMuonVertexMonitor::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { @@ -175,9 +200,10 @@ void DiMuonVertexMonitor::analyze(const edm::Event& iEvent, const edm::EventSetu reco::Vertex theMainVtx; if (!useClosestVertex_ || theClosestVertex == nullptr) { - theMainVtx = *theClosestVertex; - } else { + // if the closest vertex is not available, or explicitly not chosen theMainVtx = vertexHandle.product()->front(); + } else { + theMainVtx = *theClosestVertex; } const math::XYZPoint theMainVtxPos(theMainVtx.position().x(), theMainVtx.position().y(), theMainVtx.position().z()); @@ -239,6 +265,14 @@ void DiMuonVertexMonitor::analyze(const edm::Event& iEvent, const edm::EventSetu hSVDist3DErr_->Fill(dist3D_err * cmToum); hSVDist3DSig_->Fill(distance3D / dist3D_err); + // creat the pair of TLorentVectors used to make the plos + std::pair tktk_p4 = std::make_pair(p4_tplus, p4_tminus); + + SVDistPlots_.fillPlots(distance * cmToum, tktk_p4); + SVDistSigPlots_.fillPlots(distance / dist_err, tktk_p4); + SVDist3DPlots_.fillPlots(distance3D * cmToum, tktk_p4); + SVDist3DSigPlots_.fillPlots(distance3D / dist3D_err, tktk_p4); + // cut on the PV - SV distance if (distance * cmToum < maxSVdist_) { double cosphi = (ZpT.x() * deltaVtx.x() + ZpT.y() * deltaVtx.y()) / @@ -260,6 +294,9 @@ void DiMuonVertexMonitor::analyze(const edm::Event& iEvent, const edm::EventSetu hCosPhiUnbalance_->Fill(-cosphi, -1.); hCosPhi3DUnbalance_->Fill(cosphi3D, 1.); hCosPhi3DUnbalance_->Fill(-cosphi3D, -1.); + + // fill the cos(phi3D) plots + CosPhi3DPlots_.fillPlots(cosphi3D, tktk_p4); } } else { edm::LogWarning("DiMuonVertexMonitor") << "hardest primary vertex in the event is not valid!"; @@ -303,6 +340,72 @@ void DiMuonVertexMonitor::fillDescriptions(edm::ConfigurationDescriptions& descr desc.add("decayMotherName", "Z"); desc.add("useClosestVertex", true); desc.add("maxSVdist", 50.); + + { + edm::ParameterSetDescription psCosPhi3D; + psCosPhi3D.add("name", "CosPhi3D"); + psCosPhi3D.add("title", "cos(#phi_{3D})"); + psCosPhi3D.add("yUnits", ""); + psCosPhi3D.add("NxBins", 24); + psCosPhi3D.add("NyBins", 50); + psCosPhi3D.add("ymin", -1.); + psCosPhi3D.add("ymax", 1.); + psCosPhi3D.add("maxDeltaEta", 3.7); + desc.add("CosPhi3DConfig", psCosPhi3D); + } + + { + edm::ParameterSetDescription psSVDist; + psSVDist.add("name", "SVDist"); + psSVDist.add("title", "PV-SV distance"); + psSVDist.add("yUnits", "[#mum]"); + psSVDist.add("NxBins", 24); + psSVDist.add("NyBins", 100); + psSVDist.add("ymin", 0.); + psSVDist.add("ymax", 300.); + psSVDist.add("maxDeltaEta", 3.7); + desc.add("SVDistConfig", psSVDist); + } + + { + edm::ParameterSetDescription psSVDistSig; + psSVDistSig.add("name", "SVDistSig"); + psSVDistSig.add("title", "PV-SV distance significance"); + psSVDistSig.add("yUnits", "[#mum]"); + psSVDistSig.add("NxBins", 24); + psSVDistSig.add("NyBins", 100); + psSVDistSig.add("ymin", 0.); + psSVDistSig.add("ymax", 5.); + psSVDistSig.add("maxDeltaEta", 3.7); + desc.add("SVDistSigConfig", psSVDistSig); + } + + { + edm::ParameterSetDescription psSVDist3D; + psSVDist3D.add("name", "SVDist3D"); + psSVDist3D.add("title", "PV-SV 3D distance"); + psSVDist3D.add("yUnits", "[#mum]"); + psSVDist3D.add("NxBins", 24); + psSVDist3D.add("NyBins", 100); + psSVDist3D.add("ymin", 0.); + psSVDist3D.add("ymax", 300.); + psSVDist3D.add("maxDeltaEta", 3.7); + desc.add("SVDist3DConfig", psSVDist3D); + } + + { + edm::ParameterSetDescription psSVDist3DSig; + psSVDist3DSig.add("name", "SVDist3DSig"); + psSVDist3DSig.add("title", "PV-SV 3D distance significance"); + psSVDist3DSig.add("yUnits", "[#mum]"); + psSVDist3DSig.add("NxBins", 24); + psSVDist3DSig.add("NyBins", 100); + psSVDist3DSig.add("ymin", 0.); + psSVDist3DSig.add("ymax", 5.); + psSVDist3DSig.add("maxDeltaEta", 3.7); + desc.add("SVDist3DSigConfig", psSVDist3DSig); + } + descriptions.addWithDefaultLabel(desc); } From c8fcc3e1963a4f87f13cd853899442c03f682cfb Mon Sep 17 00:00:00 2001 From: mmusich Date: Fri, 4 Aug 2023 14:13:38 +0200 Subject: [PATCH 3/6] propagate more configuration changes for DiMuonVertexMonitor in ALCARECOTkAlDQM_cff --- .../Alignment/python/ALCARECOTkAlDQM_cff.py | 14 ++++- .../python/DiMuonVertexMonitor_cfi.py | 52 ++++++++++++++++++- 2 files changed, 63 insertions(+), 3 deletions(-) diff --git a/DQMOffline/Alignment/python/ALCARECOTkAlDQM_cff.py b/DQMOffline/Alignment/python/ALCARECOTkAlDQM_cff.py index 17b5359da7f0d..1f61d6dfadb88 100644 --- a/DQMOffline/Alignment/python/ALCARECOTkAlDQM_cff.py +++ b/DQMOffline/Alignment/python/ALCARECOTkAlDQM_cff.py @@ -164,7 +164,12 @@ decayMotherName = "J/#psi", vertices = 'offlinePrimaryVertices', FolderName = "AlCaReco/"+__selectionName, - maxSVdist = 50 + maxSVdist = 50, + CosPhi3DConfig = dict(maxDeltaEta = 1.3), + SVDistConfig = dict(maxDeltaEta = 1.3), + SVDistSigConfig = dict(maxDeltaEta = 1.3), + SVDist3DConfig = dict(maxDeltaEta = 1.3), + SVDist3DSigConfig = dict(maxDeltaEta = 1.3) ) ALCARECOTkAlJpsiMassBiasDQM = DQMOffline.Alignment.DiMuonMassBiasMonitor_cfi.DiMuonMassBiasMonitor.clone( @@ -234,7 +239,12 @@ decayMotherName = "#Upsilon", vertices = 'offlinePrimaryVertices', FolderName = "AlCaReco/"+__selectionName, - maxSVdist = 50 + maxSVdist = 50, + CosPhi3DConfig = dict(maxDeltaEta = 1.6), + SVDistConfig = dict(maxDeltaEta = 1.6), + SVDistSigConfig = dict(maxDeltaEta = 1.6), + SVDist3DConfig = dict(maxDeltaEta = 1.6), + SVDist3DSigConfig = dict(maxDeltaEta = 1.6) ) ALCARECOTkAlUpsilonMassBiasDQM = DQMOffline.Alignment.DiMuonMassBiasMonitor_cfi.DiMuonMassBiasMonitor.clone( diff --git a/DQMOffline/Alignment/python/DiMuonVertexMonitor_cfi.py b/DQMOffline/Alignment/python/DiMuonVertexMonitor_cfi.py index 7c30903ae51cb..97619766cb643 100644 --- a/DQMOffline/Alignment/python/DiMuonVertexMonitor_cfi.py +++ b/DQMOffline/Alignment/python/DiMuonVertexMonitor_cfi.py @@ -6,4 +6,54 @@ decayMotherName = cms.string('Z'), vertices = cms.InputTag('offlinePrimaryVertices'), FolderName = cms.string('DiMuonVertexMonitor'), - maxSVdist = cms.double(50)) + maxSVdist = cms.double(50), + CosPhi3DConfig = cms.PSet( + name = cms.string('CosPhi3D'), + title = cms.string('cos(#phi_{3D})'), + yUnits = cms.string(''), + NxBins = cms.int32(24), + NyBins = cms.int32(50), + ymin = cms.double(-1), + ymax = cms.double(1), + maxDeltaEta = cms.double(3.7) + ), + SVDistConfig = cms.PSet( + name = cms.string('SVDist'), + title = cms.string('PV-SV distance'), + yUnits = cms.string('[#mum]'), + NxBins = cms.int32(24), + NyBins = cms.int32(100), + ymin = cms.double(0), + ymax = cms.double(300), + maxDeltaEta = cms.double(3.7) + ), + SVDistSigConfig = cms.PSet( + name = cms.string('SVDistSig'), + title = cms.string('PV-SV distance significance'), + yUnits = cms.string('[#mum]'), + NxBins = cms.int32(24), + NyBins = cms.int32(100), + ymin = cms.double(0), + ymax = cms.double(5), + maxDeltaEta = cms.double(3.7) + ), + SVDist3DConfig = cms.PSet( + name = cms.string('SVDist3D'), + title = cms.string('PV-SV 3D distance'), + yUnits = cms.string('[#mum]'), + NxBins = cms.int32(24), + NyBins = cms.int32(100), + ymin = cms.double(0), + ymax = cms.double(300), + maxDeltaEta = cms.double(3.7) + ), + SVDist3DSigConfig = cms.PSet( + name = cms.string('SVDist3DSig'), + title = cms.string('PV-SV 3D distance significance'), + yUnits = cms.string('[#mum]'), + NxBins = cms.int32(24), + NyBins = cms.int32(100), + ymin = cms.double(0), + ymax = cms.double(5), + maxDeltaEta = cms.double(3.7) + )) From 476c3b49bfd2162036e0853a990c18614c8d31d4 Mon Sep 17 00:00:00 2001 From: mmusich Date: Tue, 10 Oct 2023 12:59:00 +0200 Subject: [PATCH 4/6] realign DiMuonVertexValidation to DiMuonVertexMonitor --- .../plugins/DiMuonVertexValidation.cc | 91 +++++++++++++++++-- 1 file changed, 82 insertions(+), 9 deletions(-) diff --git a/Alignment/OfflineValidation/plugins/DiMuonVertexValidation.cc b/Alignment/OfflineValidation/plugins/DiMuonVertexValidation.cc index 2ff26edea16cf..53b0021ee111e 100644 --- a/Alignment/OfflineValidation/plugins/DiMuonVertexValidation.cc +++ b/Alignment/OfflineValidation/plugins/DiMuonVertexValidation.cc @@ -70,12 +70,14 @@ class DiMuonVertexValidation : public edm::one::EDAnalyzer pTthresholds_; float maxSVdist_; @@ -146,6 +148,7 @@ static constexpr float mumass2 = 0.105658367 * 0.105658367; //mu mass squared ( // DiMuonVertexValidation::DiMuonVertexValidation(const edm::ParameterSet& iConfig) : useReco_(iConfig.getParameter("useReco")), + useClosestVertex_(iConfig.getParameter("useClosestVertex")), pTthresholds_(iConfig.getParameter>("pTThresholds")), maxSVdist_(iConfig.getParameter("maxSVdist")), CosPhiConfiguration_(iConfig.getParameter("CosPhiConfig")), @@ -269,6 +272,14 @@ void DiMuonVertexValidation::analyze(const edm::Event& iEvent, const edm::EventS } } +#ifdef EDM_ML_DEBUG + for (const auto& track : myTracks) { + edm::LogVerbatim("DiMuonVertexValidation") << __PRETTY_FUNCTION__ << " pT: " << track->pt() << " GeV" + << " , pT error: " << track->ptError() << " GeV" + << " , eta: " << track->eta() << " , phi: " << track->phi() << std::endl; + } +#endif + LogDebug("DiMuonVertexValidation") << "selected tracks: " << myTracks.size() << std::endl; const TransientTrackBuilder* theB = &iSetup.getData(ttbESToken_); @@ -288,6 +299,17 @@ void DiMuonVertexValidation::analyze(const edm::Event& iEvent, const edm::EventS TLorentzVector p4_tplus(tplus->px(), tplus->py(), tplus->pz(), sqrt((tplus->p() * tplus->p()) + mumass2)); TLorentzVector p4_tminus(tminus->px(), tminus->py(), tminus->pz(), sqrt((tminus->p() * tminus->p()) + mumass2)); +#ifdef EDM_ML_DEBUG + // Define a lambda function to convert TLorentzVector to a string + auto tLorentzVectorToString = [](const TLorentzVector& vector) { + return std::to_string(vector.Px()) + " " + std::to_string(vector.Py()) + " " + std::to_string(vector.Pz()) + " " + + std::to_string(vector.E()); + }; + + edm::LogVerbatim("DiMuonVertexValidation") << "mu+" << tLorentzVectorToString(p4_tplus) << std::endl; + edm::LogVerbatim("DiMuonVertexValidation") << "mu-" << tLorentzVectorToString(p4_tminus) << std::endl; +#endif + const auto& Zp4 = p4_tplus + p4_tminus; float track_invMass = Zp4.M(); hTrackInvMass_->Fill(track_invMass); @@ -323,25 +345,41 @@ void DiMuonVertexValidation::analyze(const edm::Event& iEvent, const edm::EventS // fill the VtxProb plots VtxProbPlots.fillPlots(SVProb, tktk_p4); + math::XYZPoint MainVertex(0, 0, 0); + const reco::Vertex* theClosestVertex = nullptr; // get collection of reconstructed vertices from event edm::Handle vertexHandle = iEvent.getHandle(vertexToken_); - - math::XYZPoint MainVertex(0, 0, 0); - reco::Vertex TheMainVertex = vertexHandle.product()->front(); - if (vertexHandle.isValid()) { const reco::VertexCollection* vertices = vertexHandle.product(); - if ((*vertices).at(0).isValid()) { - auto theMainVtx = (*vertices).at(0); - MainVertex.SetXYZ(theMainVtx.position().x(), theMainVtx.position().y(), theMainVtx.position().z()); - } + theClosestVertex = this->findClosestVertex(aTransientVertex, vertices); + } else { + edm::LogWarning("DiMuonVertexMonitor") << "invalid vertex collection encountered Skipping event!"; + return; } + reco::Vertex TheMainVertex; + if (!useClosestVertex_ || theClosestVertex == nullptr) { + // if the closest vertex is not available, or explicitly not chosen + TheMainVertex = vertexHandle.product()->front(); + } else { + TheMainVertex = *theClosestVertex; + } + + MainVertex.SetXYZ(TheMainVertex.position().x(), TheMainVertex.position().y(), TheMainVertex.position().z()); const math::XYZPoint myVertex( aTransientVertex.position().x(), aTransientVertex.position().y(), aTransientVertex.position().z()); const math::XYZPoint deltaVtx( MainVertex.x() - myVertex.x(), MainVertex.y() - myVertex.y(), MainVertex.z() - myVertex.z()); +#ifdef EDM_ML_DEBUG + edm::LogVerbatim("DiMuonVertexValidation") + << "mm vertex position:" << aTransientVertex.position().x() << "," << aTransientVertex.position().y() << "," + << aTransientVertex.position().z(); + + edm::LogVerbatim("DiMuonVertexValidation") << "main vertex position:" << TheMainVertex.position().x() << "," + << TheMainVertex.position().y() << "," << TheMainVertex.position().z(); +#endif + if (TheMainVertex.isValid()) { // Z Vertex distance in the xy plane @@ -391,6 +429,11 @@ void DiMuonVertexValidation::analyze(const edm::Event& iEvent, const edm::EventS hCosPhi_->Fill(cosphi); hCosPhi3D_->Fill(cosphi3D); +#ifdef EDM_ML_DEBUG + edm::LogVerbatim("DiMuonVertexValidation") + << "distance " << distance * cmToum << " cosphi3D:" << cosphi3D << std::endl; +#endif + // fill the cosphi plots CosPhiPlots.fillPlots(cosphi, tktk_p4); @@ -489,6 +532,35 @@ void DiMuonVertexValidation::endJob() { } } +// compute the closest vertex to di-lepton ------------------------------------ +const reco::Vertex* DiMuonVertexValidation::findClosestVertex(const TransientVertex aTransVtx, + const reco::VertexCollection* vertices) const { + reco::Vertex* defaultVtx = nullptr; + + if (!aTransVtx.isValid()) + return defaultVtx; + + // find the closest vertex to the secondary vertex in 3D + VertexDistance3D vertTool3D; + float minD = 9999.; + int closestVtxIndex = 0; + int counter = 0; + for (const auto& vtx : *vertices) { + double dist3D = vertTool3D.distance(aTransVtx, vtx).value(); + if (dist3D < minD) { + minD = dist3D; + closestVtxIndex = counter; + } + counter++; + } + + if ((*vertices).at(closestVtxIndex).isValid()) { + return &(vertices->at(closestVtxIndex)); + } else { + return defaultVtx; + } +} + // ------------ method fills 'descriptions' with the allowed parameters for the module ------------ void DiMuonVertexValidation::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { edm::ParameterSetDescription desc; @@ -503,6 +575,7 @@ void DiMuonVertexValidation::fillDescriptions(edm::ConfigurationDescriptions& de desc.add("tracks", edm::InputTag("generalTracks")); desc.add("vertices", edm::InputTag("offlinePrimaryVertices")); desc.add>("pTThresholds", {30., 10.}); + desc.add("useClosestVertex", true); desc.add("maxSVdist", 50.); { From 19349a128cb5e0a9b1107e4f557c30073bda869c Mon Sep 17 00:00:00 2001 From: mmusich Date: Tue, 10 Oct 2023 12:59:18 +0200 Subject: [PATCH 5/6] update Alignment/OfflineValidation/test/DiMuonVertexValidation_cfg.py --- .../test/DiMuonVertexValidation_cfg.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Alignment/OfflineValidation/test/DiMuonVertexValidation_cfg.py b/Alignment/OfflineValidation/test/DiMuonVertexValidation_cfg.py index db6378f119b13..186800262e0bd 100644 --- a/Alignment/OfflineValidation/test/DiMuonVertexValidation_cfg.py +++ b/Alignment/OfflineValidation/test/DiMuonVertexValidation_cfg.py @@ -96,6 +96,17 @@ def best_match(rcd): elif options.era=='2018': print("===> running era 2018") process = cms.Process('Analysis',eras.Run2_2018) +elif options.era=='2022': + print("===> running era 2022") + process = cms.Process('Analysis',eras.Run3) +elif options.era=='2023': + print("===> running era 2023") + process = cms.Process('Analysis',eras.Run3_2023) + +################################################################### +# Set the process to run multi-threaded +################################################################### +process.options.numberOfThreads = 8 # import of standard configurations process.load('Configuration.StandardSequences.Services_cff') From 6d05bd79352148d9862e55fe7e1b0cade5eac54a Mon Sep 17 00:00:00 2001 From: mmusich Date: Tue, 10 Oct 2023 13:00:07 +0200 Subject: [PATCH 6/6] add some debug statements in DiMuonVertexMonitor --- .../Alignment/src/DiMuonVertexMonitor.cc | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/DQMOffline/Alignment/src/DiMuonVertexMonitor.cc b/DQMOffline/Alignment/src/DiMuonVertexMonitor.cc index 8fc14b3c3af70..c66efae792820 100644 --- a/DQMOffline/Alignment/src/DiMuonVertexMonitor.cc +++ b/DQMOffline/Alignment/src/DiMuonVertexMonitor.cc @@ -142,6 +142,14 @@ void DiMuonVertexMonitor::analyze(const edm::Event& iEvent, const edm::EventSetu myTracks.emplace_back(&muonTrk); } +#ifdef EDM_ML_DEBUG + for (const auto& track : myTracks) { + edm::LogVerbatim("DiMuonVertexMonitor") << __PRETTY_FUNCTION__ << " pT: " << track->pt() << " GeV" + << " , pT error: " << track->ptError() << " GeV" + << " , eta: " << track->eta() << " , phi: " << track->phi() << std::endl; + } +#endif + const TransientTrackBuilder* theB = &iSetup.getData(ttbESToken_); TransientVertex mumuTransientVtx; std::vector tks; @@ -161,6 +169,17 @@ void DiMuonVertexMonitor::analyze(const edm::Event& iEvent, const edm::EventSetu TLorentzVector p4_tplus(tplus->px(), tplus->py(), tplus->pz(), sqrt((tplus->p() * tplus->p()) + mumass2)); TLorentzVector p4_tminus(tminus->px(), tminus->py(), tminus->pz(), sqrt((tminus->p() * tminus->p()) + mumass2)); +#ifdef EDM_ML_DEBUG + // Define a lambda function to convert TLorentzVector to a string + auto tLorentzVectorToString = [](const TLorentzVector& vector) { + return std::to_string(vector.Px()) + " " + std::to_string(vector.Py()) + " " + std::to_string(vector.Pz()) + " " + + std::to_string(vector.E()); + }; + + edm::LogVerbatim("DiMuonVertexMonitor") << "mu+" << tLorentzVectorToString(p4_tplus) << std::endl; + edm::LogVerbatim("DiMuonVertexMonitor") << "mu-" << tLorentzVectorToString(p4_tminus) << std::endl; +#endif + const auto& Zp4 = p4_tplus + p4_tminus; float track_invMass = Zp4.M(); hInvMass_->Fill(track_invMass); @@ -212,6 +231,14 @@ void DiMuonVertexMonitor::analyze(const edm::Event& iEvent, const edm::EventSetu const math::XYZPoint deltaVtx( theMainVtxPos.x() - myVertex.x(), theMainVtxPos.y() - myVertex.y(), theMainVtxPos.z() - myVertex.z()); +#ifdef EDM_ML_DEBUG + edm::LogVerbatim("DiMuonVertexMonitor") << "mm vertex position:" << mumuTransientVtx.position().x() << "," + << mumuTransientVtx.position().y() << "," << mumuTransientVtx.position().z(); + + edm::LogVerbatim("DiMuonVertexMonitor") << "main vertex position:" << theMainVtx.position().x() << "," + << theMainVtx.position().y() << "," << theMainVtx.position().z(); +#endif + if (theMainVtx.isValid()) { // fill the impact parameter plots for (const auto& track : myTracks) { @@ -289,6 +316,11 @@ void DiMuonVertexMonitor::analyze(const edm::Event& iEvent, const edm::EventSetu hCosPhiInv_->Fill(-cosphi); hCosPhiInv3D_->Fill(-cosphi3D); +#ifdef EDM_ML_DEBUG + edm::LogVerbatim("DiMuonVertexMonitor") + << "distance " << distance * cmToum << " cosphi3D:" << cosphi3D << std::endl; +#endif + // unbalance hCosPhiUnbalance_->Fill(cosphi, 1.); hCosPhiUnbalance_->Fill(-cosphi, -1.);