From 88192bb93027ec0d82c07313834c2a78f379218b Mon Sep 17 00:00:00 2001 From: Bhawani Singh Date: Fri, 1 Sep 2023 12:58:37 +0200 Subject: [PATCH 1/2] [WIP] Adds: O2 DCA histograms in tracks task --- Detectors/TPC/qc/include/TPCQC/Tracks.h | 10 +++++ Detectors/TPC/qc/src/Tracks.cxx | 52 ++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/Detectors/TPC/qc/include/TPCQC/Tracks.h b/Detectors/TPC/qc/include/TPCQC/Tracks.h index 899d0878fa401..b0f08f893668e 100644 --- a/Detectors/TPC/qc/include/TPCQC/Tracks.h +++ b/Detectors/TPC/qc/include/TPCQC/Tracks.h @@ -21,6 +21,8 @@ #include #include #include +#include "CCDB/CcdbApi.h" +#include "CCDB/BasicCCDBManager.h" // root includes #include "TH1.h" @@ -77,6 +79,13 @@ class Tracks mCutMinnCls = nClusterCut; mCutMindEdxTot = dEdxTot; } + + // To set the runNumber + void setRunNumber(int RunNumber) + { + runNumber = RunNumber; + } + // Just for backward compatibility with crrent QC, temporary, will be removed in the next PR /// get 1D histograms std::vector& getHistograms1D() { return mHist1D; } @@ -100,6 +109,7 @@ class Tracks float mCutAbsEta = 1.f; // Eta cut int mCutMinnCls = 60; // minimum N clusters float mCutMindEdxTot = 20.f; // dEdxTot min value + int runNumber = -999; // runNumber std::unordered_map> mMapHist; std::vector mHist1D{}; ///< Initialize vector of 1D histograms std::vector mHist2D{}; ///< Initialize vector of 2D histograms diff --git a/Detectors/TPC/qc/src/Tracks.cxx b/Detectors/TPC/qc/src/Tracks.cxx index 49615c3c786a6..45bc594c21d36 100644 --- a/Detectors/TPC/qc/src/Tracks.cxx +++ b/Detectors/TPC/qc/src/Tracks.cxx @@ -21,13 +21,18 @@ // o2 includes #include "DataFormatsTPC/TrackTPC.h" #include "DataFormatsTPC/dEdxInfo.h" +#include "GPUCommonArray.h" +#include "DetectorsBase/Propagator.h" +#include "DataFormatsParameters/GRPMagField.h" +#include "TGeoManager.h" #include "TPCQC/Tracks.h" #include "TPCQC/Helpers.h" ClassImp(o2::tpc::qc::Tracks); using namespace o2::tpc::qc; - +// DCA histograms +const std::vector types{"A_Pos", "A_Neg", "C_Pos", "C_Neg"}; //______________________________________________________________________________ void Tracks::initializeHistograms() { @@ -78,6 +83,12 @@ void Tracks::initializeHistograms() mMapHist["hPhiAsideRatio"] = std::make_unique("hPhiAsideRatio", "Azimuthal angle, A side, ratio neg./pos. ;phi", 360, 0., 2 * M_PI); mMapHist["hPhiCsideRatio"] = std::make_unique("hPhiCsideRatio", "Azimuthal angle, C side, ratio neg./pos. ;phi", 360, 0., 2 * M_PI); mMapHist["hPtRatio"] = std::make_unique("hPtRatio", "Transverse momentum, ratio neg./pos. ;p_T", logPtBinning.size() - 1, logPtBinning.data()); + + // DCA Histograms + for (const auto type : types) { + mMapHist[fmt::format("hDCAr_{}", type).data()] = std::make_unique(fmt::format("hDCAr_{}", type).data(), fmt::format("DCAr {};phi;DCAr (cm)", type).data(), 360, 0, o2::math_utils::twoPid(), 100, -3., 3.); + mMapHist[fmt::format("hDCAz_{}", type).data()] = std::make_unique(fmt::format("hDCAz_{}", type).data(), fmt::format("DCAz {};phi;DCAr (cm)", type).data(), 360, 0, o2::math_utils::twoPid(), 100, -3., 3.); + } } //______________________________________________________________________________ void Tracks::resetHistograms() @@ -117,6 +128,45 @@ bool Tracks::processTrack(const o2::tpc::TrackTPC& track) mMapHist["hNClustersAfterCuts"]->Fill(nCls); mMapHist["hEta"]->Fill(eta); + auto& ccdbmgr = o2::ccdb::BasicCCDBManager::instance(); + ccdbmgr.setURL("https://alice-ccdb.cern.ch"); + auto runDuration = ccdbmgr.getRunDuration(runNumber); + auto tRun = runDuration.first + (runDuration.second - runDuration.first) / 2; // time stamp for the middle of the run duration + ccdbmgr.setTimestamp(tRun); + + // CTP orbit reset time + auto orbitResetTimeNS = ccdbmgr.get>("CTP/Calib/OrbitReset"); + int64_t orbitResetTimeMS = (*orbitResetTimeNS)[0] * 1e-3; + LOGP(info, "Orbit reset time in MS is {}", orbitResetTimeMS); + + auto geoAligned = ccdbmgr.get("GLO/Config/GeometryAligned"); + auto magField = ccdbmgr.get("GLO/Config/GRPMagField"); + const o2::base::MatLayerCylSet* matLut = o2::base::MatLayerCylSet::rectifyPtrFromFile(ccdbmgr.get("GLO/Param/MatLUT")); + auto propagator = o2::base::Propagator::Instance(); + propagator->setMatLUT(matLut); + //---| propagate to 0,0,0 |--- + o2::gpu::gpustd::array dca; + const o2::math_utils::Point3D refPoint{0, 0, 0}; + //auto propTrack = TrackTPC(track); + o2::track::TrackPar propTrack(track); // Should be cheaper than the one above + bool useThisTrack = true; + if (!propagator->propagateToDCABxByBz(refPoint, propTrack, 0.5, o2::base::Propagator::MatCorrType::USEMatCorrLUT, &dca)) { + useThisTrack = false; + } + ///fine grained propagation most probably not needed + if (!propagator->propagateToDCABxByBz(refPoint, propTrack, 0.005, o2::base::Propagator::MatCorrType::USEMatCorrLUT, &dca)) { + useThisTrack = false; + } + + if (useThisTrack) + { + // ---| fill histos |--- + const int type = (track.getQ2Pt() < 0) + 2 * track.hasCSideClustersOnly(); + const auto phi = o2::math_utils::to02PiGen(track.getPhi()); + mMapHist[fmt::format("hDCAr_{}", types[type]).data()]->Fill(phi, dca[0]); + mMapHist[fmt::format("hDCAz_{}", types[type]).data()]->Fill(phi, dca[1]); + } + if (hasASideOnly == 1) { mMapHist["hPhiAside"]->Fill(phi); } else if (hasCSideOnly == 1) { From 826aae06c18183b22d10974133b1f7e6da62bce6 Mon Sep 17 00:00:00 2001 From: wiechula Date: Mon, 18 Sep 2023 15:40:18 +0200 Subject: [PATCH 2/2] Fix DCA histogramming part + cleanup * Configuration of Propagator must be done outside the code (e.g. QC framework) * map must use std::string as key, instead of std::string_view * remove unnecessary DCAz * simplify code * remove unnecessary includes --- .../Base/include/DetectorsBase/Propagator.h | 5 +- Detectors/TPC/qc/include/TPCQC/Helpers.h | 7 ++- Detectors/TPC/qc/include/TPCQC/Tracks.h | 19 ++---- Detectors/TPC/qc/src/Helpers.cxx | 21 ++++++- Detectors/TPC/qc/src/Tracks.cxx | 62 +++++++------------ 5 files changed, 55 insertions(+), 59 deletions(-) diff --git a/Detectors/Base/include/DetectorsBase/Propagator.h b/Detectors/Base/include/DetectorsBase/Propagator.h index 84cc4b5f30732..2227f2156c401 100644 --- a/Detectors/Base/include/DetectorsBase/Propagator.h +++ b/Detectors/Base/include/DetectorsBase/Propagator.h @@ -34,7 +34,7 @@ namespace parameters { class GRPObject; class GRPMagField; -} +} // namespace parameters namespace dataformats { @@ -45,7 +45,7 @@ namespace field { class MagFieldFast; class MagneticField; -} +} // namespace field namespace gpu { @@ -134,6 +134,7 @@ class PropagatorImpl GPUd() void setGPUField(const o2::gpu::GPUTPCGMPolynomialField* field) { mGPUField = field; } GPUd() const o2::gpu::GPUTPCGMPolynomialField* getGPUField() const { return mGPUField; } GPUd() void setBz(value_type bz) { mBz = bz; } + GPUd() bool hasMagFieldSet() const { return mField != nullptr; } GPUd() void estimateLTFast(o2::track::TrackLTIntegral& lt, const o2::track::TrackParametrization& trc) const; diff --git a/Detectors/TPC/qc/include/TPCQC/Helpers.h b/Detectors/TPC/qc/include/TPCQC/Helpers.h index 9469121bf8f19..23eeb8286104e 100644 --- a/Detectors/TPC/qc/include/TPCQC/Helpers.h +++ b/Detectors/TPC/qc/include/TPCQC/Helpers.h @@ -22,6 +22,7 @@ #include "TH2F.h" #include +#include #include "TPCBase/CalDet.h" namespace o2 @@ -58,6 +59,10 @@ void setStyleHistogram(TH1& histo); void setStyleHistogramsInMap(std::unordered_map>>& mapOfvectors); // set nice style of histograms in a map void setStyleHistogramsInMap(std::unordered_map>& mapOfHisto); +// set nice style of histograms in a map of vectors +void setStyleHistogramsInMap(std::unordered_map>>& mapOfvectors); +// set nice style of histograms in a map +void setStyleHistogramsInMap(std::unordered_map>& mapOfHisto); /// Check if at least one pad in refPedestal and pedestal differs by 3*refNoise to see if new ZS calibration data should be uploaded to the FECs. /// @param refPedestal /// @param refNoise @@ -70,4 +75,4 @@ bool newZSCalib(const o2::tpc::CalDet& refPedestal, const o2::tpc::CalDet } // namespace tpc } // namespace o2 -#endif \ No newline at end of file +#endif diff --git a/Detectors/TPC/qc/include/TPCQC/Tracks.h b/Detectors/TPC/qc/include/TPCQC/Tracks.h index b0f08f893668e..509855673ee48 100644 --- a/Detectors/TPC/qc/include/TPCQC/Tracks.h +++ b/Detectors/TPC/qc/include/TPCQC/Tracks.h @@ -19,19 +19,15 @@ #include #include +#include #include #include -#include "CCDB/CcdbApi.h" -#include "CCDB/BasicCCDBManager.h" // root includes #include "TH1.h" #include "TH1F.h" #include "TH2F.h" -// o2 includes -#include "DataFormatsTPC/Defs.h" - namespace o2 { namespace tpc @@ -80,12 +76,6 @@ class Tracks mCutMindEdxTot = dEdxTot; } - // To set the runNumber - void setRunNumber(int RunNumber) - { - runNumber = RunNumber; - } - // Just for backward compatibility with crrent QC, temporary, will be removed in the next PR /// get 1D histograms std::vector& getHistograms1D() { return mHist1D; } @@ -102,15 +92,14 @@ class Tracks const std::vector& getHistogramRatios1D() const { return mHistRatio1D; } /// get ratios of 1D histograms - std::unordered_map>& getMapHist() { return mMapHist; } - const std::unordered_map>& getMapHist() const { return mMapHist; } + std::unordered_map>& getMapHist() { return mMapHist; } + const std::unordered_map>& getMapHist() const { return mMapHist; } private: float mCutAbsEta = 1.f; // Eta cut int mCutMinnCls = 60; // minimum N clusters float mCutMindEdxTot = 20.f; // dEdxTot min value - int runNumber = -999; // runNumber - std::unordered_map> mMapHist; + std::unordered_map> mMapHist; std::vector mHist1D{}; ///< Initialize vector of 1D histograms std::vector mHist2D{}; ///< Initialize vector of 2D histograms std::vector mHistRatio1D{}; ///< Initialize vector of ratios of 1D histograms diff --git a/Detectors/TPC/qc/src/Helpers.cxx b/Detectors/TPC/qc/src/Helpers.cxx index 3eb2501edc57e..2abf79f93836a 100644 --- a/Detectors/TPC/qc/src/Helpers.cxx +++ b/Detectors/TPC/qc/src/Helpers.cxx @@ -99,6 +99,25 @@ void helpers::setStyleHistogramsInMap(std::unordered_map>>& mapOfvectors) +{ + for (const auto& keyValue : mapOfvectors) { + for (auto& hist : keyValue.second) { + helpers::setStyleHistogram(*hist); + } + } +} + +//______________________________________________________________________________ +void helpers::setStyleHistogramsInMap(std::unordered_map>& mapOfHisto) +{ + for (const auto& keyValue : mapOfHisto) { + helpers::setStyleHistogram(*(keyValue.second)); + } +} + //______________________________________________________________________________ bool helpers::newZSCalib(const o2::tpc::CalDet& refPedestal, const o2::tpc::CalDet& refNoise, const o2::tpc::CalDet& pedestal) { @@ -119,4 +138,4 @@ bool helpers::newZSCalib(const o2::tpc::CalDet& refPedestal, const o2::tp } return false; -} \ No newline at end of file +} diff --git a/Detectors/TPC/qc/src/Tracks.cxx b/Detectors/TPC/qc/src/Tracks.cxx index 45bc594c21d36..878212c1e0429 100644 --- a/Detectors/TPC/qc/src/Tracks.cxx +++ b/Detectors/TPC/qc/src/Tracks.cxx @@ -16,15 +16,12 @@ // root includes #include "TFile.h" -#include "TMathBase.h" // o2 includes #include "DataFormatsTPC/TrackTPC.h" #include "DataFormatsTPC/dEdxInfo.h" #include "GPUCommonArray.h" #include "DetectorsBase/Propagator.h" -#include "DataFormatsParameters/GRPMagField.h" -#include "TGeoManager.h" #include "TPCQC/Tracks.h" #include "TPCQC/Helpers.h" @@ -86,8 +83,7 @@ void Tracks::initializeHistograms() // DCA Histograms for (const auto type : types) { - mMapHist[fmt::format("hDCAr_{}", type).data()] = std::make_unique(fmt::format("hDCAr_{}", type).data(), fmt::format("DCAr {};phi;DCAr (cm)", type).data(), 360, 0, o2::math_utils::twoPid(), 100, -3., 3.); - mMapHist[fmt::format("hDCAz_{}", type).data()] = std::make_unique(fmt::format("hDCAz_{}", type).data(), fmt::format("DCAz {};phi;DCAr (cm)", type).data(), 360, 0, o2::math_utils::twoPid(), 100, -3., 3.); + mMapHist[fmt::format("hDCAr_{}", type).data()] = std::make_unique(fmt::format("hDCAr_{}", type).data(), fmt::format("DCAr {};phi;DCAr (cm)", type).data(), 360, 0, o2::math_utils::twoPid(), 250, -10., 10.); } } //______________________________________________________________________________ @@ -111,7 +107,7 @@ bool Tracks::processTrack(const o2::tpc::TrackTPC& track) const auto hasASideOnly = track.hasASideClustersOnly(); const auto hasCSideOnly = track.hasCSideClustersOnly(); - double absEta = TMath::Abs(eta); + const auto absEta = std::abs(eta); // ===| histogram filling before cuts |=== mMapHist["hNClustersBeforeCuts"]->Fill(nCls); @@ -128,44 +124,30 @@ bool Tracks::processTrack(const o2::tpc::TrackTPC& track) mMapHist["hNClustersAfterCuts"]->Fill(nCls); mMapHist["hEta"]->Fill(eta); - auto& ccdbmgr = o2::ccdb::BasicCCDBManager::instance(); - ccdbmgr.setURL("https://alice-ccdb.cern.ch"); - auto runDuration = ccdbmgr.getRunDuration(runNumber); - auto tRun = runDuration.first + (runDuration.second - runDuration.first) / 2; // time stamp for the middle of the run duration - ccdbmgr.setTimestamp(tRun); - - // CTP orbit reset time - auto orbitResetTimeNS = ccdbmgr.get>("CTP/Calib/OrbitReset"); - int64_t orbitResetTimeMS = (*orbitResetTimeNS)[0] * 1e-3; - LOGP(info, "Orbit reset time in MS is {}", orbitResetTimeMS); - - auto geoAligned = ccdbmgr.get("GLO/Config/GeometryAligned"); - auto magField = ccdbmgr.get("GLO/Config/GRPMagField"); - const o2::base::MatLayerCylSet* matLut = o2::base::MatLayerCylSet::rectifyPtrFromFile(ccdbmgr.get("GLO/Param/MatLUT")); - auto propagator = o2::base::Propagator::Instance(); - propagator->setMatLUT(matLut); - //---| propagate to 0,0,0 |--- + //---| propagate to 0,0,0 |--- + // + // propagator instance must be configured before (LUT, MagField) + auto propagator = o2::base::Propagator::Instance(true); + const int type = (track.getQ2Pt() < 0) + 2 * track.hasCSideClustersOnly(); + auto dcaHist = mMapHist[fmt::format("hDCAr_{}", types[type]).data()].get(); + + if (propagator->getMatLUT() && propagator->hasMagFieldSet()) { + // ---| fill DCA histos |--- o2::gpu::gpustd::array dca; const o2::math_utils::Point3D refPoint{0, 0, 0}; - //auto propTrack = TrackTPC(track); - o2::track::TrackPar propTrack(track); // Should be cheaper than the one above - bool useThisTrack = true; - if (!propagator->propagateToDCABxByBz(refPoint, propTrack, 0.5, o2::base::Propagator::MatCorrType::USEMatCorrLUT, &dca)) { - useThisTrack = false; - } - ///fine grained propagation most probably not needed - if (!propagator->propagateToDCABxByBz(refPoint, propTrack, 0.005, o2::base::Propagator::MatCorrType::USEMatCorrLUT, &dca)) { - useThisTrack = false; + o2::track::TrackPar propTrack(track); + if (propagator->propagateToDCABxByBz(refPoint, propTrack, 2.f, o2::base::Propagator::MatCorrType::USEMatCorrLUT, &dca)) { + const auto phi = o2::math_utils::to02PiGen(track.getPhi()); + dcaHist->Fill(phi, dca[0]); } - - if (useThisTrack) - { - // ---| fill histos |--- - const int type = (track.getQ2Pt() < 0) + 2 * track.hasCSideClustersOnly(); - const auto phi = o2::math_utils::to02PiGen(track.getPhi()); - mMapHist[fmt::format("hDCAr_{}", types[type]).data()]->Fill(phi, dca[0]); - mMapHist[fmt::format("hDCAz_{}", types[type]).data()]->Fill(phi, dca[1]); + } else { + static bool reported = false; + if (!reported) { + LOGP(error, "o2::base::Propagator not properly initialized, MatLUT ({}) and / or Field ({}) missing, will not fill DCA histograms", (void*)propagator->getMatLUT(), (void*)propagator->hasMagFieldSet()); + reported = true; } + dcaHist->SetTitle(fmt::format("DCAr {} o2::base::Propagator not properly initialized", types[type]).data()); + } if (hasASideOnly == 1) { mMapHist["hPhiAside"]->Fill(phi);