From 199ad722e7d3284da6b096bfc1ded222ed5f30d4 Mon Sep 17 00:00:00 2001 From: noepalm Date: Wed, 7 Feb 2024 14:41:57 +0100 Subject: [PATCH] Code checks && code format --- .../plugins/TrackExtenderWithMTD.cc | 79 ++++++++++--------- .../plugins/MtdTracksValidation.cc | 40 ++++++++-- 2 files changed, 74 insertions(+), 45 deletions(-) diff --git a/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc b/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc index 004936e0ac0d4..190a53565c051 100644 --- a/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc +++ b/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc @@ -97,7 +97,7 @@ namespace { class TrackSegments { public: TrackSegments() { - sigmaTofs_.reserve(30); // observed upper limit on nSegments + sigmaTofs_.reserve(30); // observed upper limit on nSegments }; inline uint32_t addSegment(float tPath, float tMom2, float sigmaMom) { @@ -106,12 +106,11 @@ namespace { segmentSigmaMom_.emplace_back(sigmaMom); nSegment_++; - #ifdef EDM_ML_DEBUG +#ifdef EDM_ML_DEBUG LogTrace("TrackExtenderWithMTD") << "addSegment # " << nSegment_ << " s = " << tPath - << " p = " << std::sqrt(tMom2) - << " sigma_p = " << sigmaMom + << " p = " << std::sqrt(tMom2) << " sigma_p = " << sigmaMom << " sigma_p/p = " << sigmaMom / std::sqrt(tMom2) * 100 << " %"; - #endif +#endif return nSegment_; } @@ -123,20 +122,23 @@ namespace { float beta = std::sqrt(1.f - 1.f / gammasq); tof += segmentPathOvc_[iSeg] / beta; - #ifdef EDM_ML_DEBUG - float sigma_tof = segmentPathOvc_[iSeg] * segmentSigmaMom_[iSeg] / (segmentMom2_[iSeg] * sqrt(segmentMom2_[iSeg] + 1/mass_inv2) * mass_inv2); - - LogTrace("TrackExtenderWithMTD") << "TOF Segment # " << iSeg + 1 << std::fixed << std::setw(6) << " p = " << std::sqrt(segmentMom2_[iSeg]) - << "\tdelta(tof) = " << segmentPathOvc_[iSeg] / beta - << "\tsigma_delta(tof) = " << sigma_tof << "\tsigma_tof/delta(tof) = " << sigma_tof / (segmentPathOvc_[iSeg] / beta) * 100 - << "%\ttof = " << tof; - #endif +#ifdef EDM_ML_DEBUG + float sigma_tof = segmentPathOvc_[iSeg] * segmentSigmaMom_[iSeg] / + (segmentMom2_[iSeg] * sqrt(segmentMom2_[iSeg] + 1 / mass_inv2) * mass_inv2); + + LogTrace("TrackExtenderWithMTD") << "TOF Segment # " << iSeg + 1 << std::fixed << std::setw(6) + << " p = " << std::sqrt(segmentMom2_[iSeg]) + << "\tdelta(tof) = " << segmentPathOvc_[iSeg] / beta << std::scientific + << "\tsigma_delta(tof) = " << sigma_tof << std::fixed + << "\tsigma_tof/delta(tof) = " + << sigma_tof / (segmentPathOvc_[iSeg] / beta) * 100 << "%\ttof = " << tof; +#endif } return tof; } - - inline float computeSigmaTof(float mass_inv2) const { + + inline float computeSigmaTof(float mass_inv2) { float sigmatof = 0.; // remove previously calculated sigmaTofs @@ -146,7 +148,8 @@ namespace { // also add diagonal terms to sigmatof float sigma = 0.; for (uint32_t iSeg = 0; iSeg < nSegment_; iSeg++) { - sigma = segmentPathOvc_[iSeg] * segmentSigmaMom_[iSeg] / (segmentMom2_[iSeg] * sqrt(segmentMom2_[iSeg] + 1/mass_inv2) * mass_inv2); + sigma = segmentPathOvc_[iSeg] * segmentSigmaMom_[iSeg] / + (segmentMom2_[iSeg] * sqrt(segmentMom2_[iSeg] + 1 / mass_inv2) * mass_inv2); sigmaTofs_.push_back(sigma); sigmatof += sigma * sigma; @@ -184,7 +187,7 @@ namespace { std::vector segmentPathOvc_; std::vector segmentMom2_; std::vector segmentSigmaMom_; - + std::vector sigmaTofs_; }; @@ -270,7 +273,8 @@ namespace { switch (sigma_choice) { case SigmaTofCalc::kCost: // sigma(t) = sigma(p) * |dt/dp| = sigma(p) * DeltaL/c * m^2 / (p^2 * E) - res = tofpid.pathlength * c_inv * trs.segmentSigmaMom_[trs.nSegment_ - 1] / (magp2 * sqrt(magp2 + 1/mass_inv2) * mass_inv2); + res = tofpid.pathlength * c_inv * trs.segmentSigmaMom_[trs.nSegment_ - 1] / + (magp2 * sqrt(magp2 + 1 / mass_inv2) * mass_inv2); break; case SigmaTofCalc::kSegm: res = trs.computeSigmaTof(mass_inv2); @@ -388,7 +392,7 @@ namespace { validpropagation = false; } pathlength1 += layerpathlength; - + // // sigma(p) using cartesian error // float sigma_p_cartesian = 0; // float p[3] = {(it + 1)->updatedState().globalMomentum().x(), (it + 1)->updatedState().globalMomentum().y(), @@ -406,7 +410,8 @@ namespace { // sigma_p_cartesian = sqrt(sigma_p_cartesian); // sigma(p) using curvilinear error (on q/p) - float sigma_p = sqrt((it + 1)->updatedState().curvilinearError().matrix()(0, 0)) * (it + 1)->updatedState().globalMomentum().mag2(); + float sigma_p = sqrt((it + 1)->updatedState().curvilinearError().matrix()(0, 0)) * + (it + 1)->updatedState().globalMomentum().mag2(); trs.addSegment(layerpathlength, (it + 1)->updatedState().globalMomentum().mag2(), sigma_p); @@ -440,12 +445,10 @@ namespace { << std::setw(14) << tscblPCA.position().perp() << " z_e " << std::fixed << std::setw(14) << tscblPCA.position().z() << " p " << std::fixed << std::setw(14) << tscblPCA.momentum().mag() << " dp " << std::fixed << std::setw(14) - << tscblPCA.momentum().mag() - oldp - << " sigma_p = " << std::fixed << std::setw(14) - << sigma_p - << " sigma_p/p = " << std::fixed << std::setw(14) + << tscblPCA.momentum().mag() - oldp << " sigma_p = " << std::fixed << std::setw(14) + << sigma_p << " sigma_p/p = " << std::fixed << std::setw(14) << sigma_p / tscblPCA.momentum().mag() * 100 << " %"; - + return validpropagation; } @@ -835,8 +838,8 @@ void TrackExtenderWithMTDT::produce(edm::Event& ev, const edm:: LogTrace("TrackExtenderWithMTD") << "TrackExtenderWithMTD: extrapolating track " << itrack << " p/pT = " << track->p() << " " << track->pt() << " eta = " << track->eta(); LogTrace("TrackExtenderWithMTD") << "TrackExtenderWithMTD: sigma_p = " - << sqrt(track->covariance()(0,0)) * track->p2() - << " sigma_p/p = " << sqrt(track->covariance()(0,0)) * track->p() * 100 << " %"; + << sqrt(track->covariance()(0, 0)) * track->p2() + << " sigma_p/p = " << sqrt(track->covariance()(0, 0)) * track->p() * 100 << " %"; float trackVtxTime = 0.f; if (useVertex_) { @@ -913,8 +916,8 @@ void TrackExtenderWithMTDT::produce(edm::Event& ev, const edm:: const auto& trajwithmtd = mtdthits.empty() ? std::vector(1, trajs) : theTransformer->transform(ttrack, thits); float pMap = 0.f, betaMap = 0.f, t0Map = 0.f, sigmat0Map = -1.f, pathLengthMap = -1.f, tmtdMap = 0.f, - sigmatmtdMap = -1.f, tofpiMap = 0.f, tofkMap = 0.f, tofpMap = 0.f, sigmatofpiMap = -1.f, - sigmatofkMap = -1.f, sigmatofpMap = -1.f; + sigmatmtdMap = -1.f, tofpiMap = 0.f, tofkMap = 0.f, tofpMap = 0.f, sigmatofpiMap = -1.f, sigmatofkMap = -1.f, + sigmatofpMap = -1.f; int iMap = -1; for (const auto& trj : trajwithmtd) { @@ -982,10 +985,13 @@ void TrackExtenderWithMTDT::produce(edm::Event& ev, const edm:: npixBarrel.push_back(backtrack.hitPattern().numberOfValidPixelBarrelHits()); npixEndcap.push_back(backtrack.hitPattern().numberOfValidPixelEndcapHits()); LogTrace("TrackExtenderWithMTD") << "TrackExtenderWithMTD: tmtd " << tmtdMap << " +/- " << sigmatmtdMap - << " t0 " << t0Map << " +/- " << sigmat0Map << " tof pi/K/p " - << tofpiMap << "+/-" << fmt::format("{:0.2g}", sigmatofpiMap) << " (" << fmt::format("{:0.2g}", sigmatofpiMap/tofpiMap*100) << "%) " - << tofkMap << "+/-" << fmt::format("{:0.2g}", sigmatofkMap) << " (" << fmt::format("{:0.2g}", sigmatofkMap/tofkMap*100) << "%) " - << tofpMap << "+/-" << fmt::format("{:0.2g}", sigmatofpMap) << " (" << fmt::format("{:0.2g}", sigmatofpMap/tofpMap*100) << "%) "; + << " t0 " << t0Map << " +/- " << sigmat0Map << " tof pi/K/p " << tofpiMap + << "+/-" << fmt::format("{:0.2g}", sigmatofpiMap) << " (" + << fmt::format("{:0.2g}", sigmatofpiMap / tofpiMap * 100) << "%) " << tofkMap + << "+/-" << fmt::format("{:0.2g}", sigmatofkMap) << " (" + << fmt::format("{:0.2g}", sigmatofkMap / tofkMap * 100) << "%) " << tofpMap + << "+/-" << fmt::format("{:0.2g}", sigmatofpMap) << " (" + << fmt::format("{:0.2g}", sigmatofpMap / tofpMap * 100) << "%) "; } else { LogTrace("TrackExtenderWithMTD") << "Error in the MTD track refitting. This should not happen"; } @@ -1305,8 +1311,7 @@ reco::Track TrackExtenderWithMTDT::buildTrack(const reco::Track float& tofp, float& sigmatofpi, float& sigmatofk, - float& sigmatofp - ) const { + float& sigmatofp) const { TrajectoryStateClosestToBeamLine tscbl; bool tsbcl_status = getTrajectoryStateClosestToBeamLine(traj, bs, thePropagator, tscbl); @@ -1437,8 +1442,8 @@ reco::Track TrackExtenderWithMTDT::buildTrack(const reco::Track if (validmtd && validpropagation) { //here add the PID uncertainty for later use in the 1st step of 4D vtx reconstruction - TrackTofPidInfo tofInfo = - computeTrackTofPidInfo(p.mag2(), pathlength, trs, thit, thiterror, 0.f, 0.f, true, TofCalc::kSegm, SigmaTofCalc::kCost); + TrackTofPidInfo tofInfo = computeTrackTofPidInfo( + p.mag2(), pathlength, trs, thit, thiterror, 0.f, 0.f, true, TofCalc::kSegm, SigmaTofCalc::kCost); pathLengthOut = pathlength; // set path length if we've got a timing hit tmtdOut = thit; diff --git a/Validation/MtdValidation/plugins/MtdTracksValidation.cc b/Validation/MtdValidation/plugins/MtdTracksValidation.cc index 67a9635bfeb3b..96a3db5b0ff1c 100644 --- a/Validation/MtdValidation/plugins/MtdTracksValidation.cc +++ b/Validation/MtdValidation/plugins/MtdTracksValidation.cc @@ -433,7 +433,7 @@ void MtdTracksValidation::analyze(const edm::Event& iEvent, const edm::EventSetu meTrackSigmat0SafePid_->Fill(Sigmat0Safe[trackref]); meTrackMVAQual_->Fill(mtdQualMVA[trackref]); - meTrackSigmaTof_[0]->Fill(SigmaTofPi[trackref] * 1e3); //save as ps + meTrackSigmaTof_[0]->Fill(SigmaTofPi[trackref] * 1e3); //save as ps meTrackSigmaTof_[1]->Fill(SigmaTofK[trackref] * 1e3); meTrackSigmaTof_[2]->Fill(SigmaTofP[trackref] * 1e3); meTrackSigmaTofvsP_[0]->Fill(track.p(), SigmaTofPi[trackref] * 1e3); @@ -950,13 +950,37 @@ void MtdTracksValidation::bookHistograms(DQMStore::IBooker& ibook, edm::Run cons meTrackPathLenghtvsEta_ = ibook.bookProfile( "TrackPathLenghtvsEta", "MTD Track pathlength vs MTD track Eta;|#eta|;Pathlength", 100, 0, 3.2, 100.0, 400.0, "S"); - meTrackSigmaTof_[0] = ibook.book1D("TrackSigmaTof_Pion", "Sigma(TOF) for pion hypothesis; #sigma_{t0} [ps]", 100, 0, 50); - meTrackSigmaTof_[1] = ibook.book1D("TrackSigmaTof_Kaon", "Sigma(TOF) for kaon hypothesis; #sigma_{t0} [ps]", 100, 0, 50); - meTrackSigmaTof_[2] = ibook.book1D("TrackSigmaTof_Proton", "Sigma(TOF) for proton hypothesis; #sigma_{t0} [ps]", 100, 0, 50); - - meTrackSigmaTofvsP_[0] = ibook.bookProfile("TrackSigmaTofvsP_Pion", "Sigma(TOF) for pion hypothesis vs p; p [GeV]; #sigma_{t0} [ps]", 20, 0, 10, 0, 50, "S"); - meTrackSigmaTofvsP_[1] = ibook.bookProfile("TrackSigmaTofvsP_Kaon", "Sigma(TOF) for kaon hypothesis vs p; p [GeV]; #sigma_{t0} [ps]", 20, 0, 10, 0, 50, "S"); - meTrackSigmaTofvsP_[2] = ibook.bookProfile("TrackSigmaTofvsP_Proton", "Sigma(TOF) for proton hypothesis vs p; p [GeV]; #sigma_{t0} [ps]", 20, 0, 10, 0, 50, "S"); + meTrackSigmaTof_[0] = + ibook.book1D("TrackSigmaTof_Pion", "Sigma(TOF) for pion hypothesis; #sigma_{t0} [ps]", 100, 0, 50); + meTrackSigmaTof_[1] = + ibook.book1D("TrackSigmaTof_Kaon", "Sigma(TOF) for kaon hypothesis; #sigma_{t0} [ps]", 100, 0, 50); + meTrackSigmaTof_[2] = + ibook.book1D("TrackSigmaTof_Proton", "Sigma(TOF) for proton hypothesis; #sigma_{t0} [ps]", 100, 0, 50); + + meTrackSigmaTofvsP_[0] = ibook.bookProfile("TrackSigmaTofvsP_Pion", + "Sigma(TOF) for pion hypothesis vs p; p [GeV]; #sigma_{t0} [ps]", + 20, + 0, + 10., + 0, + 50., + "S"); + meTrackSigmaTofvsP_[1] = ibook.bookProfile("TrackSigmaTofvsP_Kaon", + "Sigma(TOF) for kaon hypothesis vs p; p [GeV]; #sigma_{t0} [ps]", + 20, + 0, + 10., + 0, + 50., + "S"); + meTrackSigmaTofvsP_[2] = ibook.bookProfile("TrackSigmaTofvsP_Proton", + "Sigma(TOF) for proton hypothesis vs p; p [GeV]; #sigma_{t0} [ps]", + 20, + 0, + 10., + 0, + 50., + "S"); meMVATrackEffPtTot_ = ibook.book1D("MVAEffPtTot", "Pt of tracks associated to LV; track pt [GeV] ", 110, 0., 11.); meMVATrackMatchedEffPtTot_ =