From d783fe2ff800bd67d15bc969e5e22cf79a94950f Mon Sep 17 00:00:00 2001 From: Henrique Zanoli Date: Tue, 17 Nov 2020 09:44:22 +0100 Subject: [PATCH 1/4] Update Impact Parameter in qa Task --- Analysis/Tasks/qaTask.cxx | 415 +++++++++++++++++++++++++++++++------- 1 file changed, 338 insertions(+), 77 deletions(-) diff --git a/Analysis/Tasks/qaTask.cxx b/Analysis/Tasks/qaTask.cxx index b6c2b0a641a16..0a7e6a34742cc 100644 --- a/Analysis/Tasks/qaTask.cxx +++ b/Analysis/Tasks/qaTask.cxx @@ -18,11 +18,12 @@ #include "Framework/HistogramRegistry.h" #include "Analysis/trackUtilities.h" #include "ReconstructionDataFormats/DCA.h" -#include "Analysis/MC.h" -#include -#include +#include "TH1D.h" + #include +#include +#include "boost/algorithm/string.hpp" namespace o2fw = o2::framework; namespace o2exp = o2::framework::expressions; @@ -45,14 +46,19 @@ double ConvertPhiRange(double phi) /// Determines the impact parameter and its error for a given track. /// \param track the track to get the impact parameter from. /// \param primaryVertex the primary vertex of th collision. -/// \param impactParameter variable to save the impact parameter in micrometers. -/// \param impactParameterError variable to save the impact parameter error in micrometers. +/// \param impactParameterRPhi variable to save the impact parameter (in r phi) in micrometers. +/// \param impactParameterRPhiError variable to save the impact parameter (in r phi) error in micrometers. +/// \param impactParameterZ variable to save the impact parameter (in Z) in micrometers. +/// \param impactParameterZError variable to save the impact parameter (in Z) error in micrometers. template -bool GetImpactParameterAndError(const Track& track, const o2df::VertexBase& primaryVertex, double& impactParameter, - double& impactParameterError) +bool GetImpactParameterAndError(const Track& track, const o2df::VertexBase& primaryVertex, double& impactParameterRPhi, + double& impactParameterRPhiError, double& impactParameterZ, + double& impactParameterErrorZ) { - impactParameter = -999.; - impactParameterError = -999.; + impactParameterRPhi = -999.; + impactParameterRPhiError = -999.; + impactParameterZ = -999; + impactParameterErrorZ = -999; o2df::DCA dca; // FIXME: get this from CCDB @@ -60,82 +66,262 @@ bool GetImpactParameterAndError(const Track& track, const o2df::VertexBase& prim auto trackParameter = getTrackParCov(track); bool propagate = trackParameter.propagateToDCA(primaryVertex, magneticField, &dca); + constexpr float conversion_to_micrometer = 1000; if (propagate) { - impactParameter = 1000 * dca.getY(); - impactParameterError = 1000 * std::sqrt(dca.getSigmaY2()); + impactParameterRPhi = conversion_to_micrometer * dca.getY(); + impactParameterRPhiError = conversion_to_micrometer * std::sqrt(dca.getSigmaY2()); + impactParameterZ = conversion_to_micrometer * dca.getZ(); + impactParameterErrorZ = conversion_to_micrometer * std::sqrt(dca.getSigmaZ2()); } return propagate; } } // namespace track_utils +namespace o2::qa +{ + +/// Class to abstract the naming of a particular feature. It can help you to build the histogram +/// labels in a consistent way, and can generate the titles. You can also pass the +/// plotWithMatplotlib when constructing it to make the labels friendly to matplotlib. +class Feature +{ + public: + Feature() = default; + Feature(std::string name, std::string unit) : mName(std::move(name)), mUnit(std::move(unit)){}; + + std::string MCRaw() const { return mName + "^{MC}"; }; + std::string RecRaw() const { return mName + "^{Rec}"; }; + std::string UnitRaw() const { return mUnit; }; + std::string NameRaw() const { return mName; }; + + std::string Name() const { return mName + UnitFormatted(); }; + std::string MC() const { return MCRaw() + UnitFormatted(); }; + std::string Rec() const { return RecRaw() + UnitFormatted(); }; + + std::string MCRecDiff() const { return MCRaw() + " - " + RecRaw() + UnitFormatted(); }; + std::string RelativeMCRecDiff() const { return "(" + MCRaw() + " - " + RecRaw() + ")/(" + RecRaw() + ")"; }; + + std::string UnitFormatted() const + { + if (UnitRaw().empty()) { + return ""; + } + return " [" + UnitRaw() + "]"; + }; + + private: + const bool mPlotWithMatplotlib{false}; + const std::string mName; + const std::string mUnit; +}; + +/// Handle consistent naming of the histograms in the task and adds the possibility to make the +/// histogram titles friendly to matplotlib. +class Features +{ + public: + Features(bool plotWithMatplotlib = false, std::string countsLabel = "Counts") + : mPlotWithMatplotlib(plotWithMatplotlib), mCountLabel(countsLabel){}; + + const std::string& CountsLabel() const { return mCountLabel; } + bool PlotWithMatplotlib() const { return mPlotWithMatplotlib; } + + /// Given a string with the content of the X title, builds the title field for the histogram using + /// an empty title and the string that represents the number of counts. + std::string Title1D(const std::string& xAxis) const + { + return RemoveExtraMathSymbols(";" + xAxis + ";" + CountsLabel()); + } + + /// Given a string with the content of the X and Y titles, builds the title field for the + /// histogram using an empty title and the string that represents the number of counts. + std::string Title2D(const std::string& xAxis, const std::string& yAxis) const + { + return RemoveExtraMathSymbols(";" + xAxis + ";" + yAxis + ";" + CountsLabel()); + } + + /// Returns the symbol used to give math commands: \ for matplotlib and # for ROOT. + std::string MathSymbol() const + { + if (PlotWithMatplotlib()) { + return "\\"; + } + return "#"; + } + + /// Returns the symbol used to start/end math text: $ for matplotlib and nothing for ROOT. + std::string MathDelimiter() const + { + if (PlotWithMatplotlib()) { + return "$"; + } + return ""; + } + /// Tags that this text should be displayed in math mode using the correct MathDelimiter. + std::string MathText(const std::string& text) const { return MathDelimiter() + text + MathDelimiter(); } + + std::string RemoveExtraMathSymbols(std::string text) const + { + if (!PlotWithMatplotlib()) + return text; + + boost::replace_all(text, MathDelimiter() + MathDelimiter(), ""); + return text; + } + + private: + const bool mPlotWithMatplotlib; + const std::string mCountLabel; +}; + +class QAFeatures : public Features +{ + public: + QAFeatures(bool plotWithMatplotlib = false, std::string countsLabel = "Counts") + : Features(plotWithMatplotlib, countsLabel), + mTrackMultiplicity("Track Multiplicity", ""), + mEta(MathText(MathSymbol() + "eta"), ""), + mPhi{MathText(MathSymbol() + "varphi"), "rad"}, + mPt(MathText("p_{T}"), "GeV/c"), + mVertexX("X", "cm"), + mVertexY("Y", "cm"), + mVertexZ("Z", "cm"), + mImpactParameterRPhi("Impact Parameter r" + MathText(MathSymbol() + "varphi"), + MathText(MathSymbol() + "mu") + "m"), + mImpactParameterRPhiError("Impact Parameter Error r" + MathText(MathSymbol() + "varphi"), + MathText(MathSymbol() + "mu") + "m"), + mImpactParameterZ("Impact Parameter Z", MathText(MathSymbol() + "mu") + "m"), + mImpactParameterZError("Impact Parameter Z Error ", MathText("mu") + "m"){}; + + const Feature& Eta() const { return mEta; } + const Feature& Phi() const { return mPhi; } + const Feature& Pt() const { return mPt; } + const Feature& VertexX() const { return mVertexX; } + const Feature& VertexY() const { return mVertexY; } + const Feature& VertexZ() const { return mVertexZ; } + const Feature& TrackMultiplicity() const { return mTrackMultiplicity; } + const Feature& ImpactParameterRPhi() const { return mImpactParameterRPhi; } + const Feature& ImpactParameterRPhiError() const { return mImpactParameterRPhiError; } + const Feature& ImpactParameterZ() const { return mImpactParameterZ; } + const Feature& ImpactParameterZError() const { return mImpactParameterZError; } + + private: + const Feature mTrackMultiplicity; + const Feature mEta; + const Feature mPhi; + const Feature mPt; + const Feature mVertexX; + const Feature mVertexY; + const Feature mVertexZ; + const Feature mImpactParameterRPhi; + const Feature mImpactParameterRPhiError; + const Feature mImpactParameterZ; + const Feature mImpactParameterZError; +}; +} // namespace o2::qa + /// Task to QA global observables of the event struct QAGlobalObservables { - std::array collisionPositionRange = {-20., 20.}; - std::array numberOfTracksRange = {0, 2000}; + o2fw::Configurable histogramAxisForMatplotlib{ + "histogramAxisForMatplotlib", false, "Sets the histograms title to be friendly to matplotlib instead of ROOT"}; + o2::qa::QAFeatures qa = o2::qa::QAFeatures(histogramAxisForMatplotlib); o2fw::Configurable nBinsNumberOfTracks{"nBinsNumberOfTracks", 2000, "Number of bins fot the Number of Tracks"}; - o2fw::Configurable nBinsVertexPosition{"nBinsPt", 100, "Number of bins for the Vertex Position"}; - o2fw::OutputObj hCollisionX{ - TH1F("collisionX", "; X [cm];Counts", nBinsVertexPosition, collisionPositionRange[0], collisionPositionRange[1])}; + std::array collisionZRange = {-20., 20.}; + std::array collisionXYRange = {-0.01, 0.01}; + + std::array numberOfTracksRange = {0, 400}; + + o2fw::OutputObj eventCount{TH1D("eventCount", qa.Title1D("").c_str(), 2, 0, 2)}; + o2fw::HistogramRegistry histograms{"HistogramsGlobalQA"}; + + void init(o2fw::InitContext&) + { + histograms.add("collision/collisionX", qa.Title1D(qa.VertexX().Name()).c_str(), o2fw::kTH1D, + {{nBinsVertexPosition, collisionXYRange[0], collisionXYRange[1]}}); - o2fw::OutputObj hCollisionY{ - TH1F("collisionY", "; Y [cm];Counts", nBinsVertexPosition, collisionPositionRange[0], collisionPositionRange[1])}; + histograms.add("collision/collisionY", qa.Title1D(qa.VertexY().Name()).c_str(), o2fw::kTH1D, + {{nBinsVertexPosition, collisionXYRange[0], collisionXYRange[1]}}); - o2fw::OutputObj hCollisionZ{ - TH1F("collisionZ", "; Z [cm];Counts", nBinsVertexPosition, collisionPositionRange[0], collisionPositionRange[1])}; + histograms.add("collision/collisionZ", qa.Title1D(qa.VertexZ().Name()).c_str(), o2fw::kTH1D, + {{nBinsVertexPosition, collisionZRange[0], collisionZRange[1]}}); - o2fw::OutputObj hNumberOfTracks{TH1F("NumberOfTracks", "; Number of Tracks;Counts", nBinsNumberOfTracks, - numberOfTracksRange[0], numberOfTracksRange[1])}; + histograms.add("multiplicity/numberOfTracks", qa.Title1D(qa.TrackMultiplicity().Name()).c_str(), o2fw::kTH1D, + {{nBinsNumberOfTracks, numberOfTracksRange[0], numberOfTracksRange[1]}}); + } void process(const o2::aod::Collision& collision, const o2::aod::Tracks& tracks) { - hCollisionX->Fill(collision.posX()); - hCollisionY->Fill(collision.posY()); - hCollisionZ->Fill(collision.posZ()); + eventCount->Fill(0); + histograms.fill("collision/collisionX", collision.posX()); + histograms.fill("collision/collisionY", collision.posY()); + histograms.fill("collision/collisionZ", collision.posZ()); int nTracks(0); for (const auto& track : tracks) { nTracks++; } - hNumberOfTracks->Fill(nTracks); + + histograms.fill("multiplicity/numberOfTracks", nTracks); } }; /// Task to QA the kinematic properties of the tracks struct QATrackingKine { + o2fw::Configurable histogramAxisForMatplotlib{ + "histogramAxisForMatplotlib", false, "Sets the histograms title to be friendly to matplotlib instead of ROOT"}; + o2::qa::QAFeatures qa = o2::qa::QAFeatures(histogramAxisForMatplotlib); o2fw::Configurable nBinsPt{"nBinsPt", 100, "Number of bins for Pt"}; std::array ptRange = {0, 10.}; + o2fw::Configurable nBinsPhi{"nBinsPhi", 100, "Number of bins for Phi"}; + o2fw::Configurable nBinsEta{"nBinsEta", 100, "Number of bins for the eta histogram."}; std::array etaRange = {-6, 6}; - o2fw::OutputObj hPt{TH1F("pt", ";p_{T} [GeV];Counts", nBinsPt, ptRange[0], ptRange[1])}; - o2fw::OutputObj hEta{TH1F("eta", ";#eta;Counts", nBinsEta, etaRange[0], etaRange[1])}; - o2fw::OutputObj hPhi{TH1F("phi", ";#varphi [rad];Counts", nBinsPhi, 0, 2 * M_PI)}; + o2fw::HistogramRegistry histos{"HistogramsKineQA"}; + + void init(o2fw::InitContext&) + { + histos.add("tracking/pt", qa.Title1D(qa.Pt().Name()).c_str(), o2fw::kTH1D, {{nBinsPt, ptRange[0], ptRange[1]}}); + histos.add("tracking/eta", qa.Title1D(qa.Eta().NameRaw()).c_str(), o2fw::kTH1D, + {{nBinsEta, etaRange[0], etaRange[1]}}); + histos.add("tracking/phi", qa.Title1D(qa.Phi().Name()).c_str(), o2fw::kTH1D, {{nBinsPhi, 0, 2 * M_PI}}); + } void process(const o2::aod::Track& track) { - hEta->Fill(track.eta()); - hPhi->Fill(track.phi()); - hPt->Fill(track.pt()); + histos.fill("tracking/eta", track.eta()); + histos.fill("tracking/pt", track.pt()); + histos.fill("tracking/phi", track.phi()); } }; /// Task to evaluate the tracking resolution (Pt, Eta, Phi and impact parameter) struct QATrackingResolution { - o2fw::Configurable nBinsPtTrack{"nBinsPtTrack", 100, "Number of bins for the transverse momentum"}; + o2fw::Configurable setupHistogramAxisForMatplotlib{ + "setupHistogramAxisForMatplotlib", false, "Sets the histograms title to be friendly to matplotlib instead of ROOT"}; + o2::qa::QAFeatures qa = o2::qa::QAFeatures(setupHistogramAxisForMatplotlib); + + o2fw::Configurable nBinsPt{"nBinsPt", 100, "Number of bins for the transverse momentum"}; std::array ptRange = {0, 10.}; o2fw::Configurable nBinsEta{"nBinsEta", 400, "Number of bins for the pseudorapidity"}; - std::array etaRange = {-6, 6}; + std::array etaRange = {-3, 3}; + + o2fw::Configurable nBinsPhi{"nBinsPhi", 100, "Number of bins for Phi"}; + std::array phiRange = {0, 2 * M_PI}; o2fw::Configurable nBinsDeltaPt{"nBinsDeltaPt", 400, "Number of bins for the transverse momentum differences"}; + std::array deltaPtRange = {-0.5, 0.5}; - o2fw::Configurable nBinsDeltaPhi{"nBinsPhi", 100, "Number of bins for the azimuthal angle differences"}; + o2fw::Configurable nBinsDeltaPhi{"nBinsDeltaPhi", 100, "Number of bins for the azimuthal angle differences"}; + std::array deltaPhiRange = {-0.1, 0.1}; o2fw::Configurable nBinsDeltaEta{"nBinsDeltaEta", 100, "Number of bins for the pseudorapidity differences"}; + std::array deltaEtaRange = {-0.1, 0.1}; o2fw::Configurable nBinsImpactParameter{"nBinsImpactParameter", 1000, "Number of bins for the Impact parameter"}; @@ -143,38 +329,100 @@ struct QATrackingResolution { std::array impactParameterResolutionRange = {0, 1000}; // micrometer // Registry of histograms - o2fw::HistogramRegistry histos{"Histos", {}, o2fw::OutputObjHandlingPolicy::AnalysisObject}; + o2fw::HistogramRegistry histos{"HistogramsTrackingResolutionQA"}; void init(o2fw::InitContext&) { // Eta - histos.add("Eta/etaDiffMCReco", ";#eta_{MC} - #eta_{Rec}", o2fw::kTH1F, - {{nBinsDeltaEta, -2, 2}}); - histos.add("Eta/etaDiffMCRecoVsEtaMC", ";#eta_{MC} - #eta_{Rec};#eta_{MC}", o2fw::kTH2F, - {{nBinsDeltaEta, -2, 2}, {nBinsEta, etaRange[0], etaRange[1]}}); - histos.add("Eta/etaDiffMCRecoVsEtaReco", ";#eta_{MC} - #eta_{Rec};#eta_{Rec}", o2fw::kTH2F, - {{nBinsDeltaEta, -2, 2}, {nBinsEta, etaRange[0], etaRange[1]}}); + histos.add("eta/etaDiffMCReco", qa.Title1D(qa.Eta().MCRecDiff()).c_str(), o2fw::kTH1D, + {{nBinsDeltaEta, deltaEtaRange[0], deltaEtaRange[1]}}); + + histos.add("eta/etaDiffMCRecoVsEtaMC", qa.Title2D(qa.Eta().MCRecDiff(), qa.Eta().MC()).c_str(), o2fw::kTH2D, + {{nBinsDeltaEta, deltaEtaRange[0], deltaEtaRange[1]}, {nBinsEta, etaRange[0], etaRange[1]}}); + + histos.add("eta/etaDiffMCRecoVsEtaReco", qa.Title2D(qa.Eta().MCRecDiff(), qa.Eta().Rec()).c_str(), o2fw::kTH2D, + {{nBinsDeltaEta, deltaEtaRange[0], deltaEtaRange[1]}, {nBinsEta, etaRange[0], etaRange[1]}}); + // Phi - histos.add("Phi/phiDiffMCRec", ";#varphi_{MC} - #varphi_{Rec} [rad]", o2fw::kTH1F, - {{nBinsDeltaPhi, -M_PI, M_PI}}); + histos.add("phi/phiDiffMCRec", qa.Title1D(qa.Phi().MCRecDiff()).c_str(), o2fw::kTH1D, + {{nBinsDeltaPhi, deltaPhiRange[0], deltaPhiRange[1]}}); + // Pt - histos.add("Pt/ptDiffMCRec", ";p_{T}_{MC} - p_{T}_{Rec} [GeV/c]", o2fw::kTH1F, - {{nBinsDeltaPt, -2., 2.}}); - histos.add("Pt/ptResolution", ";(p_{T}_{MC} - p_{T}_{Rec})/(p_{T}_{Rec})", o2fw::kTH1F, - {{nBinsDeltaPt, -2., 2.}}); - histos.add("Pt/ptResolutionVsPt", ";p_{T} [GeV/c];(p_{T}_{MC} - p_{T}_{Rec})/(p_{T}_{Rec})", o2fw::kTH2F, - {{nBinsPtTrack, ptRange[0], ptRange[1]}, {nBinsDeltaPt, 0, 2.}}); - histos.add("Pt/ptResolutionVsEta", ";#eta;(p_{T}_{MC} - p_{T}_{Rec})/(p_{T}_{Rec})", o2fw::kTH2F, - {{nBinsEta, -4., 4.}, {nBinsDeltaPt, -2., 2.}}); + histos.add("pt/ptDiffMCRec", qa.Title1D(qa.Pt().MCRecDiff()).c_str(), o2fw::kTH1D, + {{nBinsDeltaPt, deltaPtRange[0], deltaPtRange[1]}}); + + histos.add("pt/ptResolution", qa.Title1D(qa.Pt().RelativeMCRecDiff()).c_str(), o2fw::kTH1D, + {{nBinsDeltaPt, -1., 1.}}); + + histos.add("pt/ptResolutionVsPt", qa.Title2D(qa.Pt().Rec(), qa.Pt().RelativeMCRecDiff()).c_str(), o2fw::kTH2D, + {{nBinsPt, ptRange[0], ptRange[1]}, {nBinsDeltaPt, 0., deltaPtRange[1]}}); + + histos.add("pt/ptResolutionVsEta", qa.Title2D(qa.Eta().Rec(), qa.Pt().RelativeMCRecDiff()).c_str(), o2fw::kTH2D, + {{nBinsEta, etaRange[0], etaRange[1]}, {nBinsDeltaPt, 0., deltaPtRange[1]}}); + + histos.add("pt/ptResolutionVsPhi", qa.Title2D(qa.Phi().Rec(), qa.Pt().RelativeMCRecDiff()).c_str(), o2fw::kTH2D, + {{nBinsPhi, phiRange[0], phiRange[1]}, {nBinsDeltaPt, 0., deltaPtRange[1]}}); + // Impact parameters - histos.add("ImpactParameter/impactParameterVsPt", ";p_{T} [GeV/c];Impact Parameter [{#mu}m]", o2fw::kTH2F, - {{nBinsPtTrack, ptRange[0], ptRange[1]}, {nBinsImpactParameter, impactParameterRange[0], impactParameterRange[1]}}); - histos.add("ImpactParameter/impactParameterVsEta", "#eta;Impact Parameter [{#mu}m]", o2fw::kTH2F, - {{nBinsEta, etaRange[0], etaRange[1]}, {nBinsImpactParameter, impactParameterRange[0], impactParameterRange[1]}}); - histos.add("ImpactParameter/impactParameterErrorVsPt", ";p_{T} [GeV/c];Impact Parameter Error [#mum]", o2fw::kTH2F, - {{nBinsPtTrack, ptRange[0], ptRange[1]}, {nBinsImpactParameter, impactParameterRange[0], impactParameterRange[1]}}); - histos.add("ImpactParameter/impactParameterErrorVsEta", ";#eta;Impact Parameter Error [#mum]", o2fw::kTH2F, - {{nBinsEta, etaRange[0], etaRange[1]}, {nBinsImpactParameter, 0, impactParameterRange[1]}}); + histos.add( + "impactParameter/impactParameterRPhiVsPt", qa.Title2D(qa.Pt().Rec(), qa.ImpactParameterRPhi().Name()).c_str(), + o2fw::kTH2D, + {{nBinsPt, ptRange[0], ptRange[1]}, {nBinsImpactParameter, impactParameterRange[0], impactParameterRange[1]}}); + + histos.add( + "impactParameter/impactParameterRPhiVsEta", qa.Title2D(qa.Eta().Rec(), qa.ImpactParameterRPhi().Name()).c_str(), + o2fw::kTH2D, + {{nBinsEta, etaRange[0], etaRange[1]}, {nBinsImpactParameter, impactParameterRange[0], impactParameterRange[1]}}); + + histos.add( + "impactParameter/impactParameterRPhiVsPhi", qa.Title2D(qa.Phi().Rec(), qa.ImpactParameterRPhi().Name()).c_str(), + o2fw::kTH2D, + {{nBinsPhi, phiRange[0], phiRange[1]}, {nBinsImpactParameter, impactParameterRange[0], impactParameterRange[1]}}); + + histos.add("impactParameter/impactParameterErrorRPhiVsPt", + qa.Title2D(qa.Pt().Rec(), qa.ImpactParameterRPhiError().Name()).c_str(), o2fw::kTH2D, + {{nBinsPt, ptRange[0], ptRange[1]}, + {nBinsImpactParameter, impactParameterResolutionRange[0], impactParameterResolutionRange[1]}}); + + histos.add("impactParameter/impactParameterErrorRPhiVsEta", + qa.Title2D(qa.Eta().Rec(), qa.ImpactParameterRPhiError().Name()).c_str(), o2fw::kTH2D, + {{nBinsEta, etaRange[0], etaRange[1]}, + {nBinsImpactParameter, impactParameterResolutionRange[0], impactParameterResolutionRange[1]}}); + + histos.add("impactParameter/impactParameterErrorRPhiVsPhi", + qa.Title2D(qa.Phi().Rec(), qa.ImpactParameterRPhiError().Name()).c_str(), o2fw::kTH2D, + {{nBinsPhi, phiRange[0], phiRange[1]}, + {nBinsImpactParameter, impactParameterResolutionRange[0], impactParameterResolutionRange[1]}}); + + histos.add( + "impactParameter/impactParameterZVsPt", qa.Title2D(qa.Pt().Rec(), qa.ImpactParameterZ().Name()).c_str(), + o2fw::kTH2D, + {{nBinsPt, ptRange[0], ptRange[1]}, {nBinsImpactParameter, impactParameterRange[0], impactParameterRange[1]}}); + + histos.add( + "impactParameter/impactParameterZVsEta", qa.Title2D(qa.Eta().Rec(), qa.ImpactParameterZ().Name()).c_str(), + o2fw::kTH2D, + {{nBinsEta, etaRange[0], etaRange[1]}, {nBinsImpactParameter, impactParameterRange[0], impactParameterRange[1]}}); + + histos.add( + "impactParameter/impactParameterZVsPhi", qa.Title2D(qa.Phi().Rec(), qa.ImpactParameterZ().Name()).c_str(), + o2fw::kTH2D, + {{nBinsPhi, phiRange[0], phiRange[1]}, {nBinsImpactParameter, impactParameterRange[0], impactParameterRange[1]}}); + + histos.add("impactParameter/impactParameterErrorZVsPt", + qa.Title2D(qa.Pt().Rec(), qa.ImpactParameterZError().Name()).c_str(), o2fw::kTH2D, + {{nBinsPt, ptRange[0], ptRange[1]}, + {nBinsImpactParameter, impactParameterResolutionRange[0], impactParameterResolutionRange[1]}}); + + histos.add( + "impactParameter/impactParameterErrorZVsEta", + qa.Title2D(qa.Eta().Rec(), qa.ImpactParameterZError().Name()).c_str(), o2fw::kTH2D, + {{nBinsEta, etaRange[0], etaRange[1]}, {nBinsImpactParameter, impactParameterRange[0], impactParameterRange[1]}}); + + histos.add( + "impactParameter/impactParameterErrorZVsPhi", + qa.Title2D(qa.Phi().Rec(), qa.ImpactParameterZError().Name()).c_str(), o2fw::kTH2D, + {{nBinsPhi, phiRange[0], phiRange[1]}, {nBinsImpactParameter, impactParameterRange[0], impactParameterRange[1]}}); } void process(const o2::soa::Join::iterator& collision, @@ -185,32 +433,45 @@ struct QATrackingResolution { for (const auto& track : tracks) { const double deltaPt = track.label().pt() - track.pt(); - histos.fill("Pt/ptDiffMCRec", deltaPt); + histos.fill("pt/ptDiffMCRec", deltaPt); const double deltaPtOverPt = deltaPt / track.pt(); - histos.fill("Pt/ptResolution", deltaPtOverPt); - histos.fill("Pt/ptResolutionVsPt", track.pt(), abs(deltaPtOverPt)); - histos.fill("Pt/ptResolutionVsEta", track.eta(), abs(deltaPtOverPt)); + + histos.fill("pt/ptResolution", deltaPtOverPt); + histos.fill("pt/ptResolutionVsPt", track.pt(), std::abs(deltaPtOverPt)); + histos.fill("pt/ptResolutionVsEta", track.eta(), std::abs(deltaPtOverPt)); + histos.fill("pt/ptResolutionVsPhi", track.phi(), std::abs(deltaPtOverPt)); const double deltaEta = track.label().eta() - track.eta(); - histos.fill("Eta/etaDiffMCReco", deltaEta); - histos.fill("Eta/etaDiffMCRecoVsEtaMC", deltaEta, track.label().eta()); - histos.fill("Eta/etaDiffMCRecoVsEtaReco", deltaEta, track.eta()); + histos.fill("eta/etaDiffMCReco", deltaEta); + histos.fill("eta/etaDiffMCRecoVsEtaMC", deltaEta, track.label().eta()); + histos.fill("eta/etaDiffMCRecoVsEtaReco", deltaEta, track.eta()); - const auto deltaPhi = track_utils::ConvertPhiRange(track.label().phi() - track.phi()); - histos.fill("Phi/phiDiffMCRec", deltaPhi); + const double deltaPhi = track_utils::ConvertPhiRange(track.label().phi() - track.phi()); + histos.fill("phi/phiDiffMCRec", deltaPhi); - double impactParameter{-999.}; - double impactParameterError{-999.}; + double impactParameterRPhi{-999.}, impactParameterRPhiError{-999.}; + double impactParameterZ{-999.}, impactParameterErrorZ{-999.}; - const bool propagate = - track_utils::GetImpactParameterAndError(track, primaryVertex, impactParameter, impactParameterError); + const bool propagate = track_utils::GetImpactParameterAndError( + track, primaryVertex, impactParameterRPhi, impactParameterRPhiError, impactParameterZ, impactParameterErrorZ); if (propagate) { - histos.fill("ImpactParameter/impactParameterVsPt", track.pt(), impactParameter); - histos.fill("ImpactParameter/impactParameterVsEta", track.eta(), impactParameter); - histos.fill("ImpactParameter/impactParameterErrorVsPt", track.pt(), impactParameterError); - histos.fill("ImpactParameter/impactParameterErrorVsEta", track.eta(), impactParameterError); + histos.fill("impactParameter/impactParameterRPhiVsPt", track.pt(), impactParameterRPhi); + histos.fill("impactParameter/impactParameterRPhiVsEta", track.eta(), impactParameterRPhi); + histos.fill("impactParameter/impactParameterRPhiVsPhi", track.phi(), impactParameterRPhi); + + histos.fill("impactParameter/impactParameterZVsPt", track.pt(), impactParameterZ); + histos.fill("impactParameter/impactParameterZVsEta", track.eta(), impactParameterZ); + histos.fill("impactParameter/impactParameterZVsPhi", track.phi(), impactParameterZ); + + histos.fill("impactParameter/impactParameterErrorRPhiVsPt", track.pt(), impactParameterRPhiError); + histos.fill("impactParameter/impactParameterErrorRPhiVsEta", track.eta(), impactParameterRPhiError); + histos.fill("impactParameter/impactParameterErrorRPhiVsPhi", track.phi(), impactParameterRPhiError); + + histos.fill("impactParameter/impactParameterErrorZVsPt", track.pt(), impactParameterErrorZ); + histos.fill("impactParameter/impactParameterErrorZVsEta", track.eta(), impactParameterErrorZ); + histos.fill("impactParameter/impactParameterErrorZVsPhi", track.phi(), impactParameterErrorZ); } } } From 2321d10465dfcd8afc13919adee631831d62b9bb Mon Sep 17 00:00:00 2001 From: Henrique Zanoli Date: Thu, 19 Nov 2020 10:33:49 +0100 Subject: [PATCH 2/4] Remove matplotlib options --- Analysis/Tasks/qaTask.cxx | 337 +++++++++++++++----------------------- 1 file changed, 136 insertions(+), 201 deletions(-) diff --git a/Analysis/Tasks/qaTask.cxx b/Analysis/Tasks/qaTask.cxx index 0a7e6a34742cc..580269b0f17e8 100644 --- a/Analysis/Tasks/qaTask.cxx +++ b/Analysis/Tasks/qaTask.cxx @@ -23,6 +23,7 @@ #include #include +#include #include "boost/algorithm/string.hpp" namespace o2fw = o2::framework; @@ -77,31 +78,49 @@ bool GetImpactParameterAndError(const Track& track, const o2df::VertexBase& prim } } // namespace track_utils -namespace o2::qa +namespace o2::qa::features { /// Class to abstract the naming of a particular feature. It can help you to build the histogram -/// labels in a consistent way, and can generate the titles. You can also pass the -/// plotWithMatplotlib when constructing it to make the labels friendly to matplotlib. +/// labels in a consistent way and generate the titles. class Feature { public: Feature() = default; - Feature(std::string name, std::string unit) : mName(std::move(name)), mUnit(std::move(unit)){}; + Feature(std::string name, std::string unit = "") : mName(std::move(name)), mUnit(std::move(unit)){}; + /// Returns the feature tagged as MC with no unit. Example: p_{T}^{MC}. std::string MCRaw() const { return mName + "^{MC}"; }; + + /// Returns the feature tagged as Reconstructed with no unit. Example: p_{T}^{Rec}. std::string RecRaw() const { return mName + "^{Rec}"; }; + + /// Returns the unit with no brackets. Example: GeV/c. std::string UnitRaw() const { return mUnit; }; + + /// Returns the name with no units. Example: p_{T}. std::string NameRaw() const { return mName; }; - std::string Name() const { return mName + UnitFormatted(); }; - std::string MC() const { return MCRaw() + UnitFormatted(); }; - std::string Rec() const { return RecRaw() + UnitFormatted(); }; + /// Returns the name with the unit. Example: p_{T} [Gev/c]. + std::string Name() const { return mName + Unit(); }; + + /// Returns the name tagged as MC with the unit. Example: p_{T}^{MC} [Gev/c]. + std::string MC() const { return MCRaw() + Unit(); }; + + /// Returns the name tagged as Reconstructed with the unit. Example: p_{T}^{Rec} [Gev/c] + std::string Rec() const { return RecRaw() + Unit(); }; + + /// Returns the name difference between the MC and reconstructed with the unit. + /// Example: p_{T}^{MC} - p_{T}^{Rec} [Gev/c] + std::string MCRecDiff() const { return MCRaw() + " - " + RecRaw() + Unit(); }; - std::string MCRecDiff() const { return MCRaw() + " - " + RecRaw() + UnitFormatted(); }; - std::string RelativeMCRecDiff() const { return "(" + MCRaw() + " - " + RecRaw() + ")/(" + RecRaw() + ")"; }; + /// Returns the name difference between the MC and reconstructed divided by the reconstructed. + /// For example: (p_{T}^{MC} - p_{T}^{Rec})/p_{T}^{Rec} + std::string RelativeMCRecDiff() const { return "(" + MCRaw() + " - " + RecRaw() + ")/" + RecRaw(); }; - std::string UnitFormatted() const + /// Returns the unit formatted to be used in the axis. If no unit is present, returns an empty value. + /// Example: [GeV/c] + std::string Unit() const { if (UnitRaw().empty()) { return ""; @@ -109,123 +128,37 @@ class Feature return " [" + UnitRaw() + "]"; }; + operator std::string() { return Name(); } + private: - const bool mPlotWithMatplotlib{false}; const std::string mName; const std::string mUnit; }; -/// Handle consistent naming of the histograms in the task and adds the possibility to make the -/// histogram titles friendly to matplotlib. -class Features -{ - public: - Features(bool plotWithMatplotlib = false, std::string countsLabel = "Counts") - : mPlotWithMatplotlib(plotWithMatplotlib), mCountLabel(countsLabel){}; - - const std::string& CountsLabel() const { return mCountLabel; } - bool PlotWithMatplotlib() const { return mPlotWithMatplotlib; } - - /// Given a string with the content of the X title, builds the title field for the histogram using - /// an empty title and the string that represents the number of counts. - std::string Title1D(const std::string& xAxis) const - { - return RemoveExtraMathSymbols(";" + xAxis + ";" + CountsLabel()); - } - - /// Given a string with the content of the X and Y titles, builds the title field for the - /// histogram using an empty title and the string that represents the number of counts. - std::string Title2D(const std::string& xAxis, const std::string& yAxis) const - { - return RemoveExtraMathSymbols(";" + xAxis + ";" + yAxis + ";" + CountsLabel()); - } - - /// Returns the symbol used to give math commands: \ for matplotlib and # for ROOT. - std::string MathSymbol() const - { - if (PlotWithMatplotlib()) { - return "\\"; - } - return "#"; - } - - /// Returns the symbol used to start/end math text: $ for matplotlib and nothing for ROOT. - std::string MathDelimiter() const - { - if (PlotWithMatplotlib()) { - return "$"; - } - return ""; - } - /// Tags that this text should be displayed in math mode using the correct MathDelimiter. - std::string MathText(const std::string& text) const { return MathDelimiter() + text + MathDelimiter(); } - - std::string RemoveExtraMathSymbols(std::string text) const - { - if (!PlotWithMatplotlib()) - return text; - - boost::replace_all(text, MathDelimiter() + MathDelimiter(), ""); - return text; - } - - private: - const bool mPlotWithMatplotlib; - const std::string mCountLabel; -}; - -class QAFeatures : public Features +/// Makes a title for an histogram +std::string MakeTitle(std::vector axisTitles, const std::string& counts = "Counts") { - public: - QAFeatures(bool plotWithMatplotlib = false, std::string countsLabel = "Counts") - : Features(plotWithMatplotlib, countsLabel), - mTrackMultiplicity("Track Multiplicity", ""), - mEta(MathText(MathSymbol() + "eta"), ""), - mPhi{MathText(MathSymbol() + "varphi"), "rad"}, - mPt(MathText("p_{T}"), "GeV/c"), - mVertexX("X", "cm"), - mVertexY("Y", "cm"), - mVertexZ("Z", "cm"), - mImpactParameterRPhi("Impact Parameter r" + MathText(MathSymbol() + "varphi"), - MathText(MathSymbol() + "mu") + "m"), - mImpactParameterRPhiError("Impact Parameter Error r" + MathText(MathSymbol() + "varphi"), - MathText(MathSymbol() + "mu") + "m"), - mImpactParameterZ("Impact Parameter Z", MathText(MathSymbol() + "mu") + "m"), - mImpactParameterZError("Impact Parameter Z Error ", MathText("mu") + "m"){}; - - const Feature& Eta() const { return mEta; } - const Feature& Phi() const { return mPhi; } - const Feature& Pt() const { return mPt; } - const Feature& VertexX() const { return mVertexX; } - const Feature& VertexY() const { return mVertexY; } - const Feature& VertexZ() const { return mVertexZ; } - const Feature& TrackMultiplicity() const { return mTrackMultiplicity; } - const Feature& ImpactParameterRPhi() const { return mImpactParameterRPhi; } - const Feature& ImpactParameterRPhiError() const { return mImpactParameterRPhiError; } - const Feature& ImpactParameterZ() const { return mImpactParameterZ; } - const Feature& ImpactParameterZError() const { return mImpactParameterZError; } + axisTitles.push_back(counts); + return boost::algorithm::join(axisTitles, ";"); +} - private: - const Feature mTrackMultiplicity; - const Feature mEta; - const Feature mPhi; - const Feature mPt; - const Feature mVertexX; - const Feature mVertexY; - const Feature mVertexZ; - const Feature mImpactParameterRPhi; - const Feature mImpactParameterRPhiError; - const Feature mImpactParameterZ; - const Feature mImpactParameterZError; -}; -} // namespace o2::qa +Feature Eta("#eta"); +Feature TrackMultiplicity("Track Multiplicity"); +Feature Phi{"#varphi", "rad"}; +Feature Pt("p_{T}", "GeV/c"); +Feature VertexX("X", "cm"); +Feature VertexY("Y", "cm"); +Feature VertexZ("Z", "cm"); +Feature ImpactParameterRPhi("Impact Parameter r#varphi", "#mum"); +Feature ImpactParameterRPhiError("Impact Parameter Error r#varphi", "#mum"); +Feature ImpactParameterZ("Impact Parameter Z", "#mum"); +Feature ImpactParameterZError("Impact Parameter Z Error", "#mum"); +} // namespace o2::qa::features + +namespace qafeat = o2::qa::features; /// Task to QA global observables of the event struct QAGlobalObservables { - o2fw::Configurable histogramAxisForMatplotlib{ - "histogramAxisForMatplotlib", false, "Sets the histograms title to be friendly to matplotlib instead of ROOT"}; - o2::qa::QAFeatures qa = o2::qa::QAFeatures(histogramAxisForMatplotlib); - o2fw::Configurable nBinsNumberOfTracks{"nBinsNumberOfTracks", 2000, "Number of bins fot the Number of Tracks"}; o2fw::Configurable nBinsVertexPosition{"nBinsPt", 100, "Number of bins for the Vertex Position"}; @@ -234,21 +167,21 @@ struct QAGlobalObservables { std::array numberOfTracksRange = {0, 400}; - o2fw::OutputObj eventCount{TH1D("eventCount", qa.Title1D("").c_str(), 2, 0, 2)}; + o2fw::OutputObj eventCount{TH1D("eventCount", qafeat::MakeTitle({"Selected Events"}).c_str(), 2, 0, 2)}; o2fw::HistogramRegistry histograms{"HistogramsGlobalQA"}; void init(o2fw::InitContext&) { - histograms.add("collision/collisionX", qa.Title1D(qa.VertexX().Name()).c_str(), o2fw::kTH1D, + histograms.add("collision/collisionX", qafeat::MakeTitle({qafeat::VertexX}).c_str(), o2fw::kTH1D, {{nBinsVertexPosition, collisionXYRange[0], collisionXYRange[1]}}); - histograms.add("collision/collisionY", qa.Title1D(qa.VertexY().Name()).c_str(), o2fw::kTH1D, + histograms.add("collision/collisionY", qafeat::MakeTitle({qafeat::VertexY}).c_str(), o2fw::kTH1D, {{nBinsVertexPosition, collisionXYRange[0], collisionXYRange[1]}}); - histograms.add("collision/collisionZ", qa.Title1D(qa.VertexZ().Name()).c_str(), o2fw::kTH1D, + histograms.add("collision/collisionZ", qafeat::MakeTitle({qafeat::VertexZ}).c_str(), o2fw::kTH1D, {{nBinsVertexPosition, collisionZRange[0], collisionZRange[1]}}); - histograms.add("multiplicity/numberOfTracks", qa.Title1D(qa.TrackMultiplicity().Name()).c_str(), o2fw::kTH1D, + histograms.add("multiplicity/numberOfTracks", qafeat::MakeTitle({qafeat::TrackMultiplicity}).c_str(), o2fw::kTH1D, {{nBinsNumberOfTracks, numberOfTracksRange[0], numberOfTracksRange[1]}}); } @@ -270,9 +203,6 @@ struct QAGlobalObservables { /// Task to QA the kinematic properties of the tracks struct QATrackingKine { - o2fw::Configurable histogramAxisForMatplotlib{ - "histogramAxisForMatplotlib", false, "Sets the histograms title to be friendly to matplotlib instead of ROOT"}; - o2::qa::QAFeatures qa = o2::qa::QAFeatures(histogramAxisForMatplotlib); o2fw::Configurable nBinsPt{"nBinsPt", 100, "Number of bins for Pt"}; std::array ptRange = {0, 10.}; @@ -285,10 +215,11 @@ struct QATrackingKine { void init(o2fw::InitContext&) { - histos.add("tracking/pt", qa.Title1D(qa.Pt().Name()).c_str(), o2fw::kTH1D, {{nBinsPt, ptRange[0], ptRange[1]}}); - histos.add("tracking/eta", qa.Title1D(qa.Eta().NameRaw()).c_str(), o2fw::kTH1D, + histos.add("tracking/pt", qafeat::MakeTitle({qafeat::Pt}).c_str(), o2fw::kTH1D, + {{nBinsPt, ptRange[0], ptRange[1]}}); + histos.add("tracking/eta", qafeat::MakeTitle({qafeat::Eta.NameRaw()}).c_str(), o2fw::kTH1D, {{nBinsEta, etaRange[0], etaRange[1]}}); - histos.add("tracking/phi", qa.Title1D(qa.Phi().Name()).c_str(), o2fw::kTH1D, {{nBinsPhi, 0, 2 * M_PI}}); + histos.add("tracking/phi", qafeat::MakeTitle({qafeat::Phi}).c_str(), o2fw::kTH1D, {{nBinsPhi, 0, 2 * M_PI}}); } void process(const o2::aod::Track& track) @@ -301,20 +232,18 @@ struct QATrackingKine { /// Task to evaluate the tracking resolution (Pt, Eta, Phi and impact parameter) struct QATrackingResolution { - o2fw::Configurable setupHistogramAxisForMatplotlib{ - "setupHistogramAxisForMatplotlib", false, "Sets the histograms title to be friendly to matplotlib instead of ROOT"}; - o2::qa::QAFeatures qa = o2::qa::QAFeatures(setupHistogramAxisForMatplotlib); - - o2fw::Configurable nBinsPt{"nBinsPt", 100, "Number of bins for the transverse momentum"}; - std::array ptRange = {0, 10.}; + std::vector ptBins = {0, 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.10, 0.12, + 0.14, 0.16, 0.18, 0.2, 0.225, 0.25, 0.275, 0.3, 0.35, 0.4, 0.45, 0.5, + 0.6, 0.7, 0.8, 0.9, 1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 2.5, 3.0, + 3.5, 4., 5., 6., 8., 10., 15., 20., 30., 50., 100.}; - o2fw::Configurable nBinsEta{"nBinsEta", 400, "Number of bins for the pseudorapidity"}; + o2fw::Configurable nBinsEta{"nBinsEta", 60, "Number of bins for the pseudorapidity"}; std::array etaRange = {-3, 3}; - o2fw::Configurable nBinsPhi{"nBinsPhi", 100, "Number of bins for Phi"}; + o2fw::Configurable nBinsPhi{"nBinsPhi", 50, "Number of bins for Phi"}; std::array phiRange = {0, 2 * M_PI}; - o2fw::Configurable nBinsDeltaPt{"nBinsDeltaPt", 400, "Number of bins for the transverse momentum differences"}; + o2fw::Configurable nBinsDeltaPt{"nBinsDeltaPt", 100, "Number of bins for the transverse momentum differences"}; std::array deltaPtRange = {-0.5, 0.5}; o2fw::Configurable nBinsDeltaPhi{"nBinsDeltaPhi", 100, "Number of bins for the azimuthal angle differences"}; @@ -333,96 +262,102 @@ struct QATrackingResolution { void init(o2fw::InitContext&) { + // Histogram axis definitions + + o2fw::AxisSpec ptAxis{ptBins}; + o2fw::AxisSpec deltaPtAxis{nBinsDeltaPt, deltaPtRange[0], deltaPtRange[1]}; + o2fw::AxisSpec deltaPtRelativeAxis{nBinsDeltaPt, deltaPtRange[0], deltaPtRange[1]}; + o2fw::AxisSpec deltaPtAbsoluteRelativeAxis{nBinsDeltaPt, 0., deltaPtRange[1]}; + + o2fw::AxisSpec etaAxis{nBinsEta, etaRange[0], etaRange[1]}; + o2fw::AxisSpec deltaEtaAxis{nBinsDeltaEta, deltaEtaRange[0], deltaEtaRange[1]}; + + o2fw::AxisSpec phiAxis{nBinsPhi, phiRange[0], phiRange[1]}; + o2fw::AxisSpec deltaPhiAxis{nBinsDeltaPhi, deltaPhiRange[0], deltaPhiRange[1]}; + + o2fw::AxisSpec impactParRPhiAxis{nBinsImpactParameter, impactParameterRange[0], impactParameterRange[1]}; + o2fw::AxisSpec impactParRPhiErrorAxis{nBinsImpactParameter, impactParameterResolutionRange[0], + impactParameterResolutionRange[1]}; + + o2fw::AxisSpec impactParZAxis{nBinsImpactParameter, impactParameterRange[0], impactParameterRange[1]}; + o2fw::AxisSpec impactParZErrorAxis{nBinsImpactParameter, impactParameterResolutionRange[0], + impactParameterResolutionRange[1]}; + // Eta - histos.add("eta/etaDiffMCReco", qa.Title1D(qa.Eta().MCRecDiff()).c_str(), o2fw::kTH1D, - {{nBinsDeltaEta, deltaEtaRange[0], deltaEtaRange[1]}}); + histos.add("eta/etaDiffMCReco", qafeat::MakeTitle({qafeat::Eta.MCRecDiff()}).c_str(), o2fw::kTH1D, {deltaEtaAxis}); - histos.add("eta/etaDiffMCRecoVsEtaMC", qa.Title2D(qa.Eta().MCRecDiff(), qa.Eta().MC()).c_str(), o2fw::kTH2D, - {{nBinsDeltaEta, deltaEtaRange[0], deltaEtaRange[1]}, {nBinsEta, etaRange[0], etaRange[1]}}); + histos.add("eta/etaDiffMCRecoVsEtaMC", qafeat::MakeTitle({qafeat::Eta.MCRecDiff(), qafeat::Eta.MC()}).c_str(), + o2fw::kTH2D, {deltaEtaAxis, etaAxis}); - histos.add("eta/etaDiffMCRecoVsEtaReco", qa.Title2D(qa.Eta().MCRecDiff(), qa.Eta().Rec()).c_str(), o2fw::kTH2D, - {{nBinsDeltaEta, deltaEtaRange[0], deltaEtaRange[1]}, {nBinsEta, etaRange[0], etaRange[1]}}); + histos.add("eta/etaDiffMCRecoVsEtaReco", qafeat::MakeTitle({qafeat::Eta.MCRecDiff(), qafeat::Eta.Rec()}).c_str(), + o2fw::kTH2D, {deltaEtaAxis, etaAxis}); // Phi - histos.add("phi/phiDiffMCRec", qa.Title1D(qa.Phi().MCRecDiff()).c_str(), o2fw::kTH1D, - {{nBinsDeltaPhi, deltaPhiRange[0], deltaPhiRange[1]}}); + histos.add("phi/phiDiffMCRec", qafeat::MakeTitle({qafeat::Phi.MCRecDiff()}).c_str(), o2fw::kTH1D, {deltaPhiAxis}); // Pt - histos.add("pt/ptDiffMCRec", qa.Title1D(qa.Pt().MCRecDiff()).c_str(), o2fw::kTH1D, - {{nBinsDeltaPt, deltaPtRange[0], deltaPtRange[1]}}); + histos.add("pt/ptDiffMCRec", qafeat::MakeTitle({qafeat::Pt.MCRecDiff()}).c_str(), o2fw::kTH1D, {deltaPtAxis}); - histos.add("pt/ptResolution", qa.Title1D(qa.Pt().RelativeMCRecDiff()).c_str(), o2fw::kTH1D, - {{nBinsDeltaPt, -1., 1.}}); + histos.add("pt/ptResolution", qafeat::MakeTitle({qafeat::Pt.RelativeMCRecDiff()}).c_str(), o2fw::kTH1D, + {deltaPtRelativeAxis}); - histos.add("pt/ptResolutionVsPt", qa.Title2D(qa.Pt().Rec(), qa.Pt().RelativeMCRecDiff()).c_str(), o2fw::kTH2D, - {{nBinsPt, ptRange[0], ptRange[1]}, {nBinsDeltaPt, 0., deltaPtRange[1]}}); + histos.add("pt/ptResolutionVsPt", qafeat::MakeTitle({qafeat::Pt.Rec(), qafeat::Pt.RelativeMCRecDiff()}).c_str(), + o2fw::kTH2D, {ptAxis, deltaPtAbsoluteRelativeAxis}); - histos.add("pt/ptResolutionVsEta", qa.Title2D(qa.Eta().Rec(), qa.Pt().RelativeMCRecDiff()).c_str(), o2fw::kTH2D, - {{nBinsEta, etaRange[0], etaRange[1]}, {nBinsDeltaPt, 0., deltaPtRange[1]}}); + histos.add("pt/ptResolutionVsEta", qafeat::MakeTitle({qafeat::Eta.Rec(), qafeat::Pt.RelativeMCRecDiff()}).c_str(), + o2fw::kTH2D, {etaAxis, deltaPtAbsoluteRelativeAxis}); - histos.add("pt/ptResolutionVsPhi", qa.Title2D(qa.Phi().Rec(), qa.Pt().RelativeMCRecDiff()).c_str(), o2fw::kTH2D, - {{nBinsPhi, phiRange[0], phiRange[1]}, {nBinsDeltaPt, 0., deltaPtRange[1]}}); + histos.add("pt/ptResolutionVsPhi", qafeat::MakeTitle({qafeat::Phi.Rec(), qafeat::Pt.RelativeMCRecDiff()}).c_str(), + o2fw::kTH2D, {phiAxis, deltaPtAbsoluteRelativeAxis}); // Impact parameters - histos.add( - "impactParameter/impactParameterRPhiVsPt", qa.Title2D(qa.Pt().Rec(), qa.ImpactParameterRPhi().Name()).c_str(), - o2fw::kTH2D, - {{nBinsPt, ptRange[0], ptRange[1]}, {nBinsImpactParameter, impactParameterRange[0], impactParameterRange[1]}}); + histos.add("impactParameter/impactParameterRPhiVsPt", + qafeat::MakeTitle({qafeat::Pt.Rec(), qafeat::ImpactParameterRPhi}).c_str(), o2fw::kTH2D, + {ptAxis, impactParRPhiAxis}); - histos.add( - "impactParameter/impactParameterRPhiVsEta", qa.Title2D(qa.Eta().Rec(), qa.ImpactParameterRPhi().Name()).c_str(), - o2fw::kTH2D, - {{nBinsEta, etaRange[0], etaRange[1]}, {nBinsImpactParameter, impactParameterRange[0], impactParameterRange[1]}}); + histos.add("impactParameter/impactParameterRPhiVsEta", + qafeat::MakeTitle({qafeat::Eta.Rec(), qafeat::ImpactParameterRPhi}).c_str(), o2fw::kTH2D, + {etaAxis, impactParRPhiAxis}); - histos.add( - "impactParameter/impactParameterRPhiVsPhi", qa.Title2D(qa.Phi().Rec(), qa.ImpactParameterRPhi().Name()).c_str(), - o2fw::kTH2D, - {{nBinsPhi, phiRange[0], phiRange[1]}, {nBinsImpactParameter, impactParameterRange[0], impactParameterRange[1]}}); + histos.add("impactParameter/impactParameterRPhiVsPhi", + qafeat::MakeTitle({qafeat::Phi.Rec(), qafeat::ImpactParameterRPhi}).c_str(), o2fw::kTH2D, + {phiAxis, impactParRPhiAxis}); histos.add("impactParameter/impactParameterErrorRPhiVsPt", - qa.Title2D(qa.Pt().Rec(), qa.ImpactParameterRPhiError().Name()).c_str(), o2fw::kTH2D, - {{nBinsPt, ptRange[0], ptRange[1]}, - {nBinsImpactParameter, impactParameterResolutionRange[0], impactParameterResolutionRange[1]}}); + qafeat::MakeTitle({qafeat::Pt.Rec(), qafeat::ImpactParameterRPhiError}).c_str(), o2fw::kTH2D, + {ptAxis, impactParRPhiErrorAxis}); histos.add("impactParameter/impactParameterErrorRPhiVsEta", - qa.Title2D(qa.Eta().Rec(), qa.ImpactParameterRPhiError().Name()).c_str(), o2fw::kTH2D, - {{nBinsEta, etaRange[0], etaRange[1]}, - {nBinsImpactParameter, impactParameterResolutionRange[0], impactParameterResolutionRange[1]}}); + qafeat::MakeTitle({qafeat::Eta.Rec(), qafeat::ImpactParameterRPhiError}).c_str(), o2fw::kTH2D, + {etaAxis, impactParRPhiErrorAxis}); histos.add("impactParameter/impactParameterErrorRPhiVsPhi", - qa.Title2D(qa.Phi().Rec(), qa.ImpactParameterRPhiError().Name()).c_str(), o2fw::kTH2D, - {{nBinsPhi, phiRange[0], phiRange[1]}, - {nBinsImpactParameter, impactParameterResolutionRange[0], impactParameterResolutionRange[1]}}); + qafeat::MakeTitle({qafeat::Phi.Rec(), qafeat::ImpactParameterRPhiError}).c_str(), o2fw::kTH2D, + {phiAxis, impactParRPhiErrorAxis}); - histos.add( - "impactParameter/impactParameterZVsPt", qa.Title2D(qa.Pt().Rec(), qa.ImpactParameterZ().Name()).c_str(), - o2fw::kTH2D, - {{nBinsPt, ptRange[0], ptRange[1]}, {nBinsImpactParameter, impactParameterRange[0], impactParameterRange[1]}}); + histos.add("impactParameter/impactParameterZVsPt", + qafeat::MakeTitle({qafeat::Pt.Rec(), qafeat::ImpactParameterZ}).c_str(), o2fw::kTH2D, + {ptAxis, impactParZAxis}); - histos.add( - "impactParameter/impactParameterZVsEta", qa.Title2D(qa.Eta().Rec(), qa.ImpactParameterZ().Name()).c_str(), - o2fw::kTH2D, - {{nBinsEta, etaRange[0], etaRange[1]}, {nBinsImpactParameter, impactParameterRange[0], impactParameterRange[1]}}); + histos.add("impactParameter/impactParameterZVsEta", + qafeat::MakeTitle({qafeat::Eta.Rec(), qafeat::ImpactParameterZ}).c_str(), o2fw::kTH2D, + {etaAxis, impactParZAxis}); - histos.add( - "impactParameter/impactParameterZVsPhi", qa.Title2D(qa.Phi().Rec(), qa.ImpactParameterZ().Name()).c_str(), - o2fw::kTH2D, - {{nBinsPhi, phiRange[0], phiRange[1]}, {nBinsImpactParameter, impactParameterRange[0], impactParameterRange[1]}}); + histos.add("impactParameter/impactParameterZVsPhi", + qafeat::MakeTitle({qafeat::Phi.Rec(), qafeat::ImpactParameterZ}).c_str(), o2fw::kTH2D, + {phiAxis, impactParZAxis}); histos.add("impactParameter/impactParameterErrorZVsPt", - qa.Title2D(qa.Pt().Rec(), qa.ImpactParameterZError().Name()).c_str(), o2fw::kTH2D, - {{nBinsPt, ptRange[0], ptRange[1]}, - {nBinsImpactParameter, impactParameterResolutionRange[0], impactParameterResolutionRange[1]}}); - - histos.add( - "impactParameter/impactParameterErrorZVsEta", - qa.Title2D(qa.Eta().Rec(), qa.ImpactParameterZError().Name()).c_str(), o2fw::kTH2D, - {{nBinsEta, etaRange[0], etaRange[1]}, {nBinsImpactParameter, impactParameterRange[0], impactParameterRange[1]}}); - - histos.add( - "impactParameter/impactParameterErrorZVsPhi", - qa.Title2D(qa.Phi().Rec(), qa.ImpactParameterZError().Name()).c_str(), o2fw::kTH2D, - {{nBinsPhi, phiRange[0], phiRange[1]}, {nBinsImpactParameter, impactParameterRange[0], impactParameterRange[1]}}); + qafeat::MakeTitle({qafeat::Pt.Rec(), qafeat::ImpactParameterZError}).c_str(), o2fw::kTH2D, + {ptAxis, impactParZErrorAxis}); + + histos.add("impactParameter/impactParameterErrorZVsEta", + qafeat::MakeTitle({qafeat::Eta.Rec(), qafeat::ImpactParameterZError}).c_str(), o2fw::kTH2D, + {etaAxis, impactParZErrorAxis}); + + histos.add("impactParameter/impactParameterErrorZVsPhi", + qafeat::MakeTitle({qafeat::Phi.Rec(), qafeat::ImpactParameterZError}).c_str(), o2fw::kTH2D, + {phiAxis, impactParZErrorAxis}); } void process(const o2::soa::Join::iterator& collision, From 15db0479e37a9769f192327b45c47d6a7cacff16 Mon Sep 17 00:00:00 2001 From: Henrique Zanoli Date: Thu, 19 Nov 2020 17:57:27 +0100 Subject: [PATCH 3/4] Move qa task to PWGHF --- Analysis/Tasks/CMakeLists.txt | 4 ---- Analysis/Tasks/PWGHF/CMakeLists.txt | 5 +++++ Analysis/Tasks/{ => PWGHF}/qaTask.cxx | 0 3 files changed, 5 insertions(+), 4 deletions(-) rename Analysis/Tasks/{ => PWGHF}/qaTask.cxx (100%) diff --git a/Analysis/Tasks/CMakeLists.txt b/Analysis/Tasks/CMakeLists.txt index 44ce185982209..37006fd177484 100644 --- a/Analysis/Tasks/CMakeLists.txt +++ b/Analysis/Tasks/CMakeLists.txt @@ -32,10 +32,6 @@ o2_add_dpl_workflow(trackqa PUBLIC_LINK_LIBRARIES O2::Framework O2::AnalysisDataModel O2::AnalysisCore COMPONENT_NAME Analysis) -o2_add_dpl_workflow(qatask - SOURCES qaTask.cxx - PUBLIC_LINK_LIBRARIES O2::Framework O2::AnalysisDataModel O2::AnalysisCore - COMPONENT_NAME Analysis) o2_add_dpl_workflow(pid-tof SOURCES pidTOF.cxx diff --git a/Analysis/Tasks/PWGHF/CMakeLists.txt b/Analysis/Tasks/PWGHF/CMakeLists.txt index 934b0800e2bb2..16e4180937401 100644 --- a/Analysis/Tasks/PWGHF/CMakeLists.txt +++ b/Analysis/Tasks/PWGHF/CMakeLists.txt @@ -8,6 +8,11 @@ # granted to it by virtue of its status as an Intergovernmental Organization or # submit itself to any jurisdiction. +o2_add_dpl_workflow(qatask + SOURCES qaTask.cxx + PUBLIC_LINK_LIBRARIES O2::Framework O2::AnalysisDataModel O2::AnalysisCore + COMPONENT_NAME Analysis) + o2_add_dpl_workflow(hf-track-index-skims-creator SOURCES HFTrackIndexSkimsCreator.cxx PUBLIC_LINK_LIBRARIES O2::Framework O2::AnalysisDataModel O2::AnalysisCore O2::DetectorsVertexing ROOT::EG diff --git a/Analysis/Tasks/qaTask.cxx b/Analysis/Tasks/PWGHF/qaTask.cxx similarity index 100% rename from Analysis/Tasks/qaTask.cxx rename to Analysis/Tasks/PWGHF/qaTask.cxx From ad071201d12678fb4d5187c4a1a86776ad78550d Mon Sep 17 00:00:00 2001 From: Henrique Zanoli Date: Thu, 19 Nov 2020 17:57:56 +0100 Subject: [PATCH 4/4] Fix title formating --- Analysis/Tasks/PWGHF/qaTask.cxx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Analysis/Tasks/PWGHF/qaTask.cxx b/Analysis/Tasks/PWGHF/qaTask.cxx index 580269b0f17e8..b819dcacd6118 100644 --- a/Analysis/Tasks/PWGHF/qaTask.cxx +++ b/Analysis/Tasks/PWGHF/qaTask.cxx @@ -139,7 +139,7 @@ class Feature std::string MakeTitle(std::vector axisTitles, const std::string& counts = "Counts") { axisTitles.push_back(counts); - return boost::algorithm::join(axisTitles, ";"); + return ";" + boost::algorithm::join(axisTitles, ";"); } Feature Eta("#eta"); @@ -159,7 +159,7 @@ namespace qafeat = o2::qa::features; /// Task to QA global observables of the event struct QAGlobalObservables { - o2fw::Configurable nBinsNumberOfTracks{"nBinsNumberOfTracks", 2000, "Number of bins fot the Number of Tracks"}; + o2fw::Configurable nBinsNumberOfTracks{"nBinsNumberOfTracks", 2000, "Number of bins for the Number of Tracks"}; o2fw::Configurable nBinsVertexPosition{"nBinsPt", 100, "Number of bins for the Vertex Position"}; std::array collisionZRange = {-20., 20.}; @@ -232,10 +232,10 @@ struct QATrackingKine { /// Task to evaluate the tracking resolution (Pt, Eta, Phi and impact parameter) struct QATrackingResolution { - std::vector ptBins = {0, 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.10, 0.12, - 0.14, 0.16, 0.18, 0.2, 0.225, 0.25, 0.275, 0.3, 0.35, 0.4, 0.45, 0.5, - 0.6, 0.7, 0.8, 0.9, 1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 2.5, 3.0, - 3.5, 4., 5., 6., 8., 10., 15., 20., 30., 50., 100.}; + std::vector ptBins = {0, 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.10, 0.12, + 0.14, 0.16, 0.18, 0.2, 0.225, 0.25, 0.275, 0.3, 0.35, 0.4, 0.45, 0.5, + 0.6, 0.7, 0.8, 0.9, 1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 2.5, 3.0, + 3.5, 4., 5., 6., 8., 10., 15., 20., 30., 50., 100.}; o2fw::Configurable nBinsEta{"nBinsEta", 60, "Number of bins for the pseudorapidity"}; std::array etaRange = {-3, 3};