37 #include "TLorentzVector.h" 178 : motherName_(iConfig.getParameter<
std::
string>(
"decayMotherName")),
179 useReco_(iConfig.getParameter<
bool>(
"useReco")),
180 useClosestVertex_(iConfig.getParameter<
bool>(
"useClosestVertex")),
181 pTthresholds_(iConfig.getParameter<
std::
vector<double>>(
"pTThresholds")),
182 maxSVdist_(iConfig.getParameter<double>(
"maxSVdist")),
183 CosPhiConfiguration_(iConfig.getParameter<
edm::
ParameterSet>(
"CosPhiConfig")),
184 CosPhi3DConfiguration_(iConfig.getParameter<
edm::
ParameterSet>(
"CosPhi3DConfig")),
185 VtxProbConfiguration_(iConfig.getParameter<
edm::
ParameterSet>(
"VtxProbConfig")),
186 VtxDistConfiguration_(iConfig.getParameter<
edm::
ParameterSet>(
"VtxDistConfig")),
187 VtxDist3DConfiguration_(iConfig.getParameter<
edm::
ParameterSet>(
"VtxDist3DConfig")),
188 VtxDistSigConfiguration_(iConfig.getParameter<
edm::
ParameterSet>(
"VtxDistSigConfig")),
189 VtxDist3DSigConfiguration_(iConfig.getParameter<
edm::
ParameterSet>(
"VtxDist3DSigConfig")),
190 DiMuMassConfiguration_(iConfig.getParameter<
edm::
ParameterSet>(
"DiMuMassConfig")),
207 edm::LogInfo(
"DiMuonVertexValidation") <<
" Threshold: " << thr <<
" ";
214 }
else if (
motherName_.find(
"J/#psi") != std::string::npos) {
216 }
else if (
motherName_.find(
"#Upsilon") != std::string::npos) {
220 <<
" setting the default for the Z->mm (50.,120.)" << std::endl;
238 std::vector<const reco::Track*> myTracks;
243 std::vector<const reco::Muon*> myGoodMuonVector;
248 if (
t->chi2() /
t->ndof() <= 2.5 &&
t->numberOfValidHits() >= 5 &&
250 myGoodMuonVector.emplace_back(&
muon);
255 LogDebug(
"DiMuonVertexValidation") <<
"myGoodMuonVector size: " << myGoodMuonVector.size() << std::endl;
257 return lhs->
pt() > rhs->pt();
261 for (
const auto&
muon : myGoodMuonVector) {
262 LogDebug(
"DiMuonVertexValidation") <<
"pT: " <<
muon->pt() <<
" ";
264 LogDebug(
"DiMuonVertexValidation") << std::endl;
267 if (myGoodMuonVector.size() < 2)
278 if (myGoodMuonVector[0]->
charge() * myGoodMuonVector[1]->charge() > 0)
281 const auto& m1 = myGoodMuonVector[1]->p4();
282 const auto& m0 = myGoodMuonVector[0]->p4();
283 const auto& mother = m0 + m1;
285 float invMass = mother.M();
289 std::vector<const reco::Muon*> theZMuonVector;
290 theZMuonVector.reserve(2);
291 theZMuonVector.emplace_back(myGoodMuonVector[1]);
292 theZMuonVector.emplace_back(myGoodMuonVector[0]);
296 for (
const auto&
muon : theZMuonVector) {
307 LogDebug(
"DiMuonVertexValidation") <<
"pushing new track: " <<
i << std::endl;
308 myTracks.emplace_back(theMatch);
313 myTracks.emplace_back(&
muon);
318 for (
const auto&
track : myTracks) {
319 edm::LogVerbatim(
"DiMuonVertexValidation") << __PRETTY_FUNCTION__ <<
" pT: " <<
track->pt() <<
" GeV" 320 <<
" , pT error: " <<
track->ptError() <<
" GeV" 321 <<
" , eta: " <<
track->eta() <<
" , phi: " <<
track->phi() << std::endl;
325 LogDebug(
"DiMuonVertexValidation") <<
"selected tracks: " << myTracks.size() << std::endl;
329 std::vector<reco::TransientTrack> tks;
331 if (myTracks.size() != 2)
334 const auto&
t1 = myTracks[1]->momentum();
335 const auto&
t0 = myTracks[0]->momentum();
336 const auto& ditrack =
t1 +
t0;
338 const auto& tplus = myTracks[0]->charge() > 0 ? myTracks[0] : myTracks[1];
339 const auto& tminus = myTracks[0]->charge() < 0 ? myTracks[0] : myTracks[1];
341 TLorentzVector p4_tplus(tplus->px(), tplus->py(), tplus->pz(),
sqrt((tplus->p() * tplus->p()) +
mumass2));
342 TLorentzVector p4_tminus(tminus->px(), tminus->py(), tminus->pz(),
sqrt((tminus->p() * tminus->p()) +
mumass2));
346 auto tLorentzVectorToString = [](
const TLorentzVector&
vector) {
351 edm::LogVerbatim(
"DiMuonVertexValidation") <<
"mu+" << tLorentzVectorToString(p4_tplus) << std::endl;
352 edm::LogVerbatim(
"DiMuonVertexValidation") <<
"mu-" << tLorentzVectorToString(p4_tminus) << std::endl;
355 const auto& Zp4 = p4_tplus + p4_tminus;
356 float track_invMass = Zp4.M();
360 std::pair<TLorentzVector, TLorentzVector> tktk_p4 = std::make_pair(p4_tplus, p4_tminus);
369 for (
const auto&
track : myTracks) {
371 tks.push_back(trajectory);
375 aTransientVertex = kalman.
vertex(tks);
379 LogDebug(
"DiMuonVertexValidation") <<
" vertex prob: " << SVProb << std::endl;
385 LogDebug(
"DiMuonVertexValidation") <<
" vertex norm chi2: " 389 if (!aTransientVertex.
isValid())
405 edm::LogWarning(
"DiMuonVertexMonitor") <<
"invalid vertex collection encountered Skipping event!";
412 theMainVertex = vertexHandle.
product()->front();
414 theMainVertex = *theClosestVertex;
421 mainVtxPos.x() - myVertex.x(), mainVtxPos.y() - myVertex.y(), mainVtxPos.z() - myVertex.z());
425 <<
"mm vertex position:" << aTransientVertex.
position().
x() <<
"," << aTransientVertex.
position().
y() <<
"," 434 for (
const auto&
track : myTracks) {
447 hIP2dsig_->Fill(ip2d.second.significance());
451 LogDebug(
"DiMuonVertexValidation") <<
" after filling the IP histograms " << std::endl;
456 double dist_err = vertTool.
distance(aTransientVertex, theMainVertex).
error();
457 float compatibility = 0.;
460 compatibility = vertTool.
compatibility(aTransientVertex, theMainVertex);
462 LogTrace(
"DiMuonVertexValidation") <<
"caught std::exception " << er.
what() << std::endl;
479 double distance3D = vertTool3D.
distance(aTransientVertex, theMainVertex).
value();
480 double dist3D_err = vertTool3D.
distance(aTransientVertex, theMainVertex).
error();
481 float compatibility3D = 0.;
484 compatibility3D = vertTool3D.
compatibility(aTransientVertex, theMainVertex);
486 LogTrace(
"DiMuonVertexMonitor") <<
"caught std::exception " << er.
what() << std::endl;
500 LogDebug(
"DiMuonVertexValidation") <<
"distance: " <<
distance <<
"+/-" << dist_err << std::endl;
505 double cosphi = (ZpT.x() * deltaVtx.x() + ZpT.y() * deltaVtx.y()) /
506 (
sqrt(ZpT.x() * ZpT.x() + ZpT.y() * ZpT.y()) *
507 sqrt(deltaVtx.x() * deltaVtx.x() + deltaVtx.y() * deltaVtx.y()));
509 double cosphi3D = (Zp.x() * deltaVtx.x() + Zp.y() * deltaVtx.y() + Zp.z() * deltaVtx.z()) /
510 (
sqrt(Zp.x() * Zp.x() + Zp.y() * Zp.y() + Zp.z() * Zp.z()) *
511 sqrt(deltaVtx.x() * deltaVtx.x() + deltaVtx.y() * deltaVtx.y() + deltaVtx.z() * deltaVtx.z()));
513 LogDebug(
"DiMuonVertexValidation") <<
"cos(phi) = " << cosphi << std::endl;
520 <<
"distance " <<
distance *
cmToum <<
" cosphi3D:" << cosphi3D << std::endl;
546 TH1F::SetDefaultSumw2(kTRUE);
547 hSVProb_ =
fs->make<TH1F>(
"VtxProb",
";#mu^{+}#mu^{-} vertex probability;N(#mu#mu pairs)", 100, 0., 1.);
549 auto extractRangeValues = [](
const edm::ParameterSet& PSetConfiguration_) -> std::pair<double, double> {
550 double min = PSetConfiguration_.getParameter<
double>(
"ymin");
551 double max = PSetConfiguration_.getParameter<
double>(
"ymax");
557 ts = fmt::sprintf(
"#chi^{2} of the %s vertex; #chi^{2} of the %s vertex; %s",
motherName_,
motherName_, ps);
558 hSVChi2_ =
fs->make<TH1F>(
"VtxChi2", ts.c_str(), 200, 0., 200.);
560 ts = fmt::sprintf(
"#chi^{2}/ndf of the %s vertex; #chi^{2}/ndf of %s vertex; %s",
motherName_,
motherName_, ps);
561 hSVNormChi2_ =
fs->make<TH1F>(
"VtxNormChi2", ts.c_str(), 100, 0., 20.);
565 hSVDist_ =
fs->make<TH1F>(
"VtxDist",
";PV-#mu^{+}#mu^{-} vertex xy distance [#mum];N(#mu#mu pairs)", 100, svDistRng.first, svDistRng.second);
568 ts = fmt::sprintf(
"%s;PV-%sV xy distance error [#mum];%s", histTit,
motherName_, ps);
569 hSVDistErr_ =
fs->make<TH1F>(
"VtxDistErr", ts.c_str(), 100, 0., 1000.);
573 hSVDistSig_ =
fs->make<TH1F>(
"VtxDistSig",
";PV-#mu^{+}#mu^{-} vertex xy distance signficance;N(#mu#mu pairs)", 100, svDistSigRng.first, svDistSigRng.second);
577 hSVDist3D_ =
fs->make<TH1F>(
"VtxDist3D",
";PV-#mu^{+}#mu^{-} vertex 3D distance [#mum];N(#mu#mu pairs)", 100, svDist3DRng.first, svDist3DRng.second);
579 ts = fmt::sprintf(
"%s;PV-%sV 3D distance error [#mum];%s", histTit,
motherName_, ps);
580 hSVDist3DErr_ =
fs->make<TH1F>(
"VtxDist3DErr", ts.c_str(), 100, 0., 1000.);
584 hSVDist3DSig_ =
fs->make<TH1F>(
"VtxDist3DSig",
";PV-#mu^{+}#mu^{-} vertex 3D distance signficance;N(#mu#mu pairs)", 100, svDist3DSigRng.first, svDist3DSigRng.second);
586 ts = fmt::sprintf(
"compatibility of %s vertex; compatibility of %s vertex; %s",
motherName_,
motherName_, ps);
589 ts = fmt::sprintf(
"3D compatibility of %s vertex;3D compatibility of %s vertex; %s",
motherName_,
motherName_, ps);
594 hInvMass_ =
fs->make<TH1F>(
"InvMass",
";M(#mu#mu) [GeV];N(#mu#mu pairs)", 70., massRng.first, massRng.second);
595 hTrackInvMass_ =
fs->make<TH1F>(
"TkTkInvMass",
";M(tk,tk) [GeV];N(tk tk pairs)", 70., massRng.first, massRng.second);
597 hCosPhi_ =
fs->make<TH1F>(
"CosPhi",
";cos(#phi_{xy});N(#mu#mu pairs)", 50, -1., 1.);
598 hCosPhi3D_ =
fs->make<TH1F>(
"CosPhi3D",
";cos(#phi_{3D});N(#mu#mu pairs)", 50, -1., 1.);
600 hCosPhiInv_ =
fs->make<TH1F>(
"CosPhiInv",
";inverted cos(#phi_{xy});N(#mu#mu pairs)", 50, -1., 1.);
601 hCosPhiInv3D_ =
fs->make<TH1F>(
"CosPhiInv3D",
";inverted cos(#phi_{3D});N(#mu#mu pairs)", 50, -1., 1.);
603 hCosPhiUnbalance_ =
fs->make<TH1F>(
"CosPhiUnbalance", fmt::sprintf(
"%s;cos(#phi_{xy}) unbalance;#Delta%s", histTit, ps).c_str(), 50, -1.,1.);
604 hCosPhi3DUnbalance_ =
fs->make<TH1F>(
"CosPhi3DUnbalance", fmt::sprintf(
"%s;cos(#phi_{3D}) unbalance;#Delta%s", histTit, ps).c_str(), 50, -1., 1.);
606 hdxy_ =
fs->make<TH1F>(
"dxy", fmt::sprintf(
"%s;muon track d_{xy}(PV) [#mum];muon tracks", histTit).c_str(), 150, -300, 300);
607 hdz_ =
fs->make<TH1F>(
"dz", fmt::sprintf(
"%s;muon track d_{z}(PV) [#mum];muon tracks", histTit).c_str(), 150, -300, 300);
608 hdxyErr_ =
fs->make<TH1F>(
"dxyErr", fmt::sprintf(
"%s;muon track err_{dxy} [#mum];muon tracks", histTit).c_str(), 250, 0., 500.);
609 hdzErr_ =
fs->make<TH1F>(
"dzErr", fmt::sprintf(
"%s;muon track err_{dz} [#mum];muon tracks", histTit).c_str(), 250, 0., 500.);
610 hIP2d_ =
fs->make<TH1F>(
"IP2d", fmt::sprintf(
"%s;muon track IP_{2D} [#mum];muon tracks", histTit).c_str(), 150, -300, 300);
611 hIP3d_ =
fs->make<TH1F>(
"IP3d", fmt::sprintf(
"%s;muon track IP_{3D} [#mum];muon tracks", histTit).c_str(), 150, -300, 300);
612 hIP2dsig_ =
fs->make<TH1F>(
"IP2Dsig", fmt::sprintf(
"%s;muon track IP_{2D} significance;muon tracks", histTit).c_str(), 100, 0., 5.);
613 hIP3dsig_ =
fs->make<TH1F>(
"IP3Dsig", fmt::sprintf(
"%s;muon track IP_{3D} significance;muon tracks", histTit).c_str(), 100, 0., 5.);
652 hCutFlow_ =
fs->make<TH1F>(
"hCutFlow",
"cut flow;cut step;events left", 6, -0.5, 5.5);
653 std::string names[6] = {
"Total",
"Mult.",
">pT",
"<eta",
"hasVtx",
"VtxDist"};
654 for (
unsigned int i = 0;
i < 6;
i++) {
672 TH1F::SetDefaultSumw2(kTRUE);
673 const unsigned int nBinsX =
hCosPhi_->GetNbinsX();
674 for (
unsigned int i = 1;
i <= nBinsX;
i++) {
676 float invertedBinContent =
hCosPhi_->GetBinContent(nBinsX + 1 -
i);
677 float invertedBinError =
hCosPhi_->GetBinError(nBinsX + 1 -
i);
682 float invertedBinContent3D =
hCosPhi3D_->GetBinContent(nBinsX + 1 -
i);
683 float invertedBinError3D =
hCosPhi3D_->GetBinError(nBinsX + 1 -
i);
700 int closestVtxIndex = 0;
711 if ((*vertices).at(closestVtxIndex).isValid()) {
712 return &(
vertices->at(closestVtxIndex));
725 ->setComment(
"If useReco is true need to specify the muon tracks, otherwise take the ALCARECO Inner tracks");
732 desc.add<std::vector<double>>(
"pTThresholds", {30., 10.});
733 desc.add<
bool>(
"useClosestVertex",
true);
734 desc.add<
double>(
"maxSVdist", 50.);
741 psDiMuMass.
add<
int>(
"NxBins", 24);
742 psDiMuMass.
add<
int>(
"NyBins", 50);
743 psDiMuMass.
add<
double>(
"ymin", 70.);
744 psDiMuMass.
add<
double>(
"ymax", 120.);
752 psCosPhi.
add<
int>(
"NxBins", 50);
753 psCosPhi.
add<
int>(
"NyBins", 50);
754 psCosPhi.
add<
double>(
"ymin", -1.);
755 psCosPhi.
add<
double>(
"ymax", 1.);
763 psCosPhi3D.
add<
int>(
"NxBins", 50);
764 psCosPhi3D.
add<
int>(
"NyBins", 50);
765 psCosPhi3D.
add<
double>(
"ymin", -1.);
766 psCosPhi3D.
add<
double>(
"ymax", 1.);
774 psVtxProb.
add<
int>(
"NxBins", 50);
775 psVtxProb.
add<
int>(
"NyBins", 50);
776 psVtxProb.
add<
double>(
"ymin", 0);
777 psVtxProb.
add<
double>(
"ymax", 1.);
785 psVtxDist.
add<
int>(
"NxBins", 50);
786 psVtxDist.
add<
int>(
"NyBins", 100);
787 psVtxDist.
add<
double>(
"ymin", 0);
788 psVtxDist.
add<
double>(
"ymax", 300.);
796 psVtxDist3D.
add<
int>(
"NxBins", 50);
797 psVtxDist3D.
add<
int>(
"NyBins", 250);
798 psVtxDist3D.
add<
double>(
"ymin", 0);
799 psVtxDist3D.
add<
double>(
"ymax", 500.);
805 psVtxDistSig.
add<
std::string>(
"title",
"d_{xy}(PV,SV)/#sigma_{dxy}(PV,SV)");
807 psVtxDistSig.
add<
int>(
"NxBins", 50);
808 psVtxDistSig.
add<
int>(
"NyBins", 100);
809 psVtxDistSig.
add<
double>(
"ymin", 0);
810 psVtxDistSig.
add<
double>(
"ymax", 5.);
816 psVtxDist3DSig.
add<
std::string>(
"title",
"d_{3D}(PV,SV)/#sigma_{d3D}(PV,SV)");
818 psVtxDist3DSig.
add<
int>(
"NxBins", 50);
819 psVtxDist3DSig.
add<
int>(
"NyBins", 100);
820 psVtxDist3DSig.
add<
double>(
"ymin", 0);
821 psVtxDist3DSig.
add<
double>(
"ymax", 5.);
DiMuonVertexValidation(const edm::ParameterSet &)
static const std::string kSharedResource
const edm::ParameterSet VtxProbConfiguration_
Log< level::Info, true > LogVerbatim
const edm::ParameterSet DiMuMassConfiguration_
~DiMuonVertexValidation() override
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
T getParameter(std::string const &) const
float totalChiSquared() const
unsigned int eventsAfterVtx
const edm::ParameterSet CosPhi3DConfiguration_
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
double pt() const final
transverse momentum
GlobalPoint position() const
Measurement1D distance(const GlobalPoint &vtx1Position, const GlobalError &vtx1PositionError, const GlobalPoint &vtx2Position, const GlobalError &vtx2PositionError) const override
DiLeptonHelp::Counts myCounts
const edm::ParameterSet CosPhiConfiguration_
void analyze(const edm::Event &, const edm::EventSetup &) override
DiLeptonHelp::PlotsVsDiLeptonRegion InvMassInEtaBins
static constexpr float mumass2
const Point & position() const
position
void fillTH1Plots(const float val, const std::pair< TLorentzVector, TLorentzVector > &momenta)
T const * product() const
DiLeptonHelp::PlotsVsKinematics CosPhiPlots
const edm::ParameterSet VtxDist3DConfiguration_
unsigned int eventsAfterDist
std::vector< Vertex > VertexCollection
collection of Vertex objects
DiLeptonHelp::PlotsVsKinematics VtxDist3DPlots
Log< level::Error, false > LogError
const edm::ParameterSet VtxDist3DSigConfiguration_
std::vector< Vertex > VertexCollection
float degreesOfFreedom() const
const std::string names[nVars_]
DiLeptonHelp::PlotsVsKinematics VtxDist3DSigPlots
static std::string to_string(const XMLCh *ch)
unsigned int eventsAfterEta
CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &tracks) const override
reco::TransientTrack build(const reco::Track *p) const
void bookSet(const TFileDirectory &fs, const TH1 *histo)
const edm::ParameterSet VtxDistSigConfiguration_
DiLeptonHelp::PlotsVsKinematics VtxDistSigPlots
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
static constexpr float cmToum
edm::EDGetTokenT< reco::MuonCollection > muonsToken_
#define DEFINE_FWK_MODULE(type)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const edm::ESGetToken< TransientTrackBuilder, TransientTrackRecord > ttbESToken_
const bool useClosestVertex_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Measurement1D distance(const GlobalPoint &vtx1Position, const GlobalError &vtx1PositionError, const GlobalPoint &vtx2Position, const GlobalError &vtx2PositionError) const override
Log< level::Info, false > LogInfo
std::pair< float, float > massLimits_
TH1F * hCosPhi3DUnbalance_
TH1F * hSVCompatibility3D_
edm::EDGetTokenT< reco::TrackCollection > tracksToken_
DecomposeProduct< arg, typename Div::arg > D
XYZPointD XYZPoint
point in space with cartesian internal representation
DiLeptonHelp::PlotsVsKinematics VtxProbPlots
float compatibility(const GlobalPoint &vtx1Position, const GlobalError &vtx1PositionError, const GlobalPoint &vtx2Position, const GlobalError &vtx2PositionError) const override
const edm::ParameterSet VtxDistConfiguration_
const reco::Vertex * findClosestVertex(const TransientVertex aTransVtx, const reco::VertexCollection *vertices) const
DiLeptonHelp::PlotsVsKinematics CosPhi3DPlots
static std::atomic< unsigned int > counter
unsigned int eventsAfterPt
std::vector< double > pTthresholds_
DiLeptonHelp::PlotsVsKinematics VtxDistPlots
void fillPlots(const float val, const std::pair< TLorentzVector, TLorentzVector > &momenta)
void bookFromPSet(const TFileDirectory &fs, const edm::ParameterSet &hpar)
Log< level::Warning, false > LogWarning
char const * what() const noexcept override
DiLeptonHelp::PlotsVsDiLeptonRegion CosPhi3DInEtaBins
DiLeptonHelp::PlotsVsKinematics ZMassPlots
edm::EDGetTokenT< reco::TrackCollection > alcaRecoToken_
const edm::EDGetTokenT< reco::VertexCollection > vertexToken_
unsigned int eventsAfterMult
const std::string motherName_
bool isValid() const
Tells whether the vertex is valid.
float compatibility(const GlobalPoint &vtx1Position, const GlobalError &vtx1PositionError, const GlobalPoint &vtx2Position, const GlobalError &vtx2PositionError) const override