Skip to content

Commit

Permalink
Improve handling of MID histograms per local board (#2351)
Browse files Browse the repository at this point in the history
  • Loading branch information
dstocco authored Jun 20, 2024
1 parent 502e54f commit 4c9e420
Show file tree
Hide file tree
Showing 6 changed files with 228 additions and 185 deletions.
85 changes: 52 additions & 33 deletions Modules/MUON/MID/include/MID/DigitsHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#ifndef QC_MODULE_MID_DIGITSHELPER_H
#define QC_MODULE_MID_DIGITSHELPER_H

#include <array>
#include <memory>
#include <string>
#include <vector>
Expand Down Expand Up @@ -50,12 +51,26 @@ class DigitsHelper
/// @return Histogram 2D
TH2F makeStripMapHisto(std::string name, std::string title, int cathode) const;

/// @brief Make 4 histograms with the 2D representation of the fired strips per chamber
/// @param name Base histogram name
/// @param title Base histogram title
/// @param cathode Bending (0) or Non-bending (1) plane
/// @return Array of unique pointer to histograms
std::array<std::unique_ptr<TH2F>, 4> makeStripMapHistos(std::string name, std::string title, int cathode) const;

/// @brief Make the histogram with the 2D representation of the fired boards
/// @param name Histogram name
/// @param title Histogram title
/// @return Histogram 2D
TH2F makeBoardMapHisto(std::string name, std::string title) const;

/// @brief Make 4 histograms with the 2D representation of the fired boards per chamber
/// @param name Base histogram name
/// @param title Base histogram title
/// @param cathode Bending (0) or Non-bending (1) plane
/// @return Array of unique pointer to histograms
std::array<std::unique_ptr<TH2F>, 4> makeBoardMapHistos(std::string name, std::string title) const;

/// @brief Count the number of fired strips
/// @param col Column Data
/// @param cathode Bending (0) or Non-bending (1) plane
Expand All @@ -67,48 +82,52 @@ class DigitsHelper
/// @param histo Pointer to the histogram
void fillStripHisto(const o2::mid::ColumnData& col, TH1* histo) const;

/// @brief Fill the 2D representation of the fired strips/boards from the 1D histogram
/// @param stripHisto Input 1D histogram
/// @param stripHistosB Array with the 2D representation of the fired strips in the bending plane per chamber
/// @param stripHistosNB Array with the 2D representation of the fired strips in the non-bending plane per chamber
/// @param boardHistos Array with the 2D representation of the fired boards per chamber. Last histogram is the sum of the previous four
void fillMapHistos(const TH1* stripHisto, std::array<std::unique_ptr<TH2F>, 4>& stripHistosB, std::array<std::unique_ptr<TH2F>, 4>& stripHistosNB, std::array<std::unique_ptr<TH2F>, 5>& boardHistos) const;
/// @brief Fill the 2D representation of the fired boards from the 1D strip histogram
/// @param histo Input 1D histogram with fired strips
/// @param histosB Array with the 2D representation of the fired boards per chamber. Last histogram is the sum of the previous four
void fillBoardMapHistosFromStrips(const TH1* histo, std::array<std::unique_ptr<TH2F>, 4>& histosB, std::array<std::unique_ptr<TH2F>, 4>& histosNB) const;

/// @brief Fill the 2D representation of the fired strips from the 1D histogram
/// @param stripHisto Input 1D histogram
/// @param stripHistosB Array with the 2D representation of the fired strips in the bending plane per chamber
/// @param stripHistosNB Array with the 2D representation of the fired strips in the non-bending plane per chamber
void fillMapHistos(const TH1* stripHisto, std::array<std::unique_ptr<TH2F>, 4>& stripHistosB, std::array<std::unique_ptr<TH2F>, 4>& stripHistosNB) const;

/// @brief Fill the 2D representation of the fired strips/boards from the 1D histogram for a specific chamber
/// @param stripHisto Input 1D histogram
/// @param stripHistosB 2D representation of the fired strips in the bending plane
/// @param stripHistosNB 2D representation of the fired strips in the non-bending plane
/// @param boardHistos 2D representation of the fired boards per chamber
/// @param chamber Selected chamber
void fillMapHistos(const TH1* stripHisto, TH2* stripHistosB, TH2* stripHistosNB, TH2* boardHistos, int chamber) const;

struct StripInfo {
int deId; ///< Detection element ID
int columnId; ///< Column ID
int lineId; ///< Line ID
int stripId; ///< Strip ID
int cathode; ///< Bending (0) or Non-bending (1) plane
int xwidth; ///< Width X
int ywidth; ///< Width y
/// @param histo Input 1D histogram with fired strips
/// @param histosB Array with the 2D representation of the fired strips in the bending plane per chamber
/// @param histosNB Array with the 2D representation of the fired strips in the non-bending plane per chamber
void fillStripMapHistos(const TH1* histo, std::array<std::unique_ptr<TH2F>, 4>& stripHistosB, std::array<std::unique_ptr<TH2F>, 4>& stripHistosNB) const;

struct MapInfo {
int cathode = 0; ///! Cathode
int chamber = 0; ///! Chamber
std::vector<int> bins{}; ///! Bins in the 2D map histograms
};

struct ColumnInfo {
int firstLine; ///< First line in column
int lastLine; ///< Last line in column
int nStripsNB; ///< Number of strips in the NB plane
int firstLine; ///! First line in column
int lastLine; ///! Last line in column
int nStripsNB; ///! Number of strips in the NB plane
};

private:
std::unordered_map<int, int> mStripsMap{}; ///! Map from id to index
std::vector<StripInfo> mStripsInfo; ///! Strips info
std::unordered_map<int, int> mStripsMap{}; ///! Strip id to strip idx

std::vector<MapInfo> mStripIdxToStripMap{}; ///! Strip index to strip map bins
std::vector<MapInfo> mStripIdxToBoardMap{}; ///! Strip index to board map bins

std::array<ColumnInfo, 72 * 7> mColumnInfo; ///! Column info
void fillMapHistos(const StripInfo& info, TH2* stripHistoB, TH2* stripHistoNB, TH2* boardHisto, int wgt) const;

/// @brief Initializes inner maps
void initMaps();

/// @brief Fills one bin in a quick way
/// @param ibin Bin to fill
/// @param wgt Weight
/// @param histo Histogram to fill
void FillBin(TH1* histo, int ibin, double wgt = 1.) const;

/// @brief Fill the 2D map histogram from the 1D histogram
/// @param histo 1D histogram
/// @param histoMapB 2D map histogram for the bending plane
/// @param histoMapNB 2D map histogram for the non-bending plane
/// @param infoMap Correspondence between histogram bins
void fillMapHistos(const TH1* histo, std::array<std::unique_ptr<TH2F>, 4>& histoMapB, std::array<std::unique_ptr<TH2F>, 4>& histoMapNB, const std::vector<MapInfo>& infoMap) const;

inline int getColumnIdx(int columnId, int deId) const { return 7 * deId + columnId; }
};
Expand Down
4 changes: 3 additions & 1 deletion Modules/MUON/MID/include/MID/DigitsQcTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ class DigitsQcTask final : public TaskInterface
std::array<std::unique_ptr<TH1F>, 5> mMultHitNB{};
std::unique_ptr<TH1F> mMeanMultiHits;

std::array<std::unique_ptr<TH2F>, 5> mLocalBoardsMap{};
std::array<std::unique_ptr<TH2F>, 4> mLocalBoardsMap{};
std::unique_ptr<TH2F> mLocalBoardsMapTot;

std::unique_ptr<TH1F> mHits;

std::array<std::unique_ptr<TH2F>, 4> mBendHitsMap{};
Expand Down
48 changes: 27 additions & 21 deletions Modules/MUON/MID/src/CalibMQcTask.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -44,40 +44,46 @@ void CalibMQcTask::initialize(o2::framework::InitContext& /*ctx*/)
mNoise = std::make_unique<TH1F>(mDigitsHelper.makeStripHisto("MNoiseStrips", "Noise strips"));
getObjectsManager()->startPublishing(mNoise.get());

for (int ich = 0; ich < 4; ++ich) {
mBendNoiseMap[ich] = std::make_unique<TH2F>(mDigitsHelper.makeStripMapHisto(fmt::format("MBendNoiseMap{}", chId[ich]), fmt::format("Bending Noise Map MT{}", chId[ich]), 0));
getObjectsManager()->startPublishing(mBendNoiseMap[ich].get());
mBendNoiseMap = mDigitsHelper.makeStripMapHistos("MBendNoiseMap", "Bending Noise Map", 0);
for (auto& histo : mBendNoiseMap) {
getObjectsManager()->startPublishing(histo.get());
getObjectsManager()->setDefaultDrawOptions(histo.get(), "COLZ");
}

for (int ich = 0; ich < 4; ++ich) {
mNBendNoiseMap[ich] = std::make_unique<TH2F>(mDigitsHelper.makeStripMapHisto(fmt::format("MNBendNoiseMap{}", chId[ich]), fmt::format("Non-Bending Noise Map MT{}", chId[ich]), 1));
getObjectsManager()->startPublishing(mNBendNoiseMap[ich].get());
mNBendNoiseMap = mDigitsHelper.makeStripMapHistos("MNBendNoiseMap", "Non-Bending Noise Map", 1);
for (auto& histo : mNBendNoiseMap) {
getObjectsManager()->startPublishing(histo.get());
getObjectsManager()->setDefaultDrawOptions(histo.get(), "COLZ");
}

mDead = std::make_unique<TH1F>(mDigitsHelper.makeStripHisto("MDeadStrips", "Dead strips"));
getObjectsManager()->startPublishing(mDead.get());

for (int ich = 0; ich < 4; ++ich) {
mBendDeadMap[ich] = std::make_unique<TH2F>(mDigitsHelper.makeStripMapHisto(fmt::format("MBendDeadMap{}", chId[ich]), fmt::format("Bending Dead Map MT{}", chId[ich]), 0));
getObjectsManager()->startPublishing(mBendDeadMap[ich].get());
mBendDeadMap = mDigitsHelper.makeStripMapHistos("MBendDeadMap", "Bending Dead Map", 0);
for (auto& histo : mBendDeadMap) {
getObjectsManager()->startPublishing(histo.get());
getObjectsManager()->setDefaultDrawOptions(histo.get(), "COLZ");
}

for (int ich = 0; ich < 4; ++ich) {
mNBendDeadMap[ich] = std::make_unique<TH2F>(mDigitsHelper.makeStripMapHisto(fmt::format("MNBendDeadMap{}", chId[ich]), fmt::format("Non-Bending Dead Map MT{}", chId[ich]), 1));
getObjectsManager()->startPublishing(mNBendDeadMap[ich].get());
mNBendDeadMap = mDigitsHelper.makeStripMapHistos("MNBendDeadMap", "Non-Bending Dead Map", 1);
for (auto& histo : mNBendDeadMap) {
getObjectsManager()->startPublishing(histo.get());
getObjectsManager()->setDefaultDrawOptions(histo.get(), "COLZ");
}

mBad = std::make_unique<TH1F>(mDigitsHelper.makeStripHisto("MBadStrips", "Bad strips"));
getObjectsManager()->startPublishing(mBad.get());

for (int ich = 0; ich < 4; ++ich) {
mBendBadMap[ich] = std::make_unique<TH2F>(mDigitsHelper.makeStripMapHisto(fmt::format("MBendBadMap{}", chId[ich]), fmt::format("Bending Bad Map MT{}", chId[ich]), 0));
getObjectsManager()->startPublishing(mBendBadMap[ich].get());
mBendBadMap = mDigitsHelper.makeStripMapHistos("MBendBadMap", "Bending Bad Map", 0);
for (auto& histo : mBendBadMap) {
getObjectsManager()->startPublishing(histo.get());
getObjectsManager()->setDefaultDrawOptions(histo.get(), "COLZ");
}

for (int ich = 0; ich < 4; ++ich) {
mNBendBadMap[ich] = std::make_unique<TH2F>(mDigitsHelper.makeStripMapHisto(fmt::format("MNBendBadMap{}", chId[ich]), fmt::format("Non-Bending Bad Map MT{}", chId[ich]), 1));
getObjectsManager()->startPublishing(mNBendBadMap[ich].get());
mNBendBadMap = mDigitsHelper.makeStripMapHistos("MNBendBadMap", "Non-Bending Bad Map", 1);
for (auto& histo : mNBendBadMap) {
getObjectsManager()->startPublishing(histo.get());
getObjectsManager()->setDefaultDrawOptions(histo.get(), "COLZ");
}
}

Expand Down Expand Up @@ -116,9 +122,9 @@ void CalibMQcTask::endOfCycle()
resetDisplayHistos();

// Then fill from the strip histogram
mDigitsHelper.fillMapHistos(mNoise.get(), mBendNoiseMap, mNBendNoiseMap);
mDigitsHelper.fillMapHistos(mDead.get(), mBendDeadMap, mNBendDeadMap);
mDigitsHelper.fillMapHistos(mBad.get(), mBendBadMap, mNBendBadMap);
mDigitsHelper.fillStripMapHistos(mNoise.get(), mBendNoiseMap, mNBendNoiseMap);
mDigitsHelper.fillStripMapHistos(mDead.get(), mBendDeadMap, mNBendDeadMap);
mDigitsHelper.fillStripMapHistos(mBad.get(), mBendBadMap, mNBendBadMap);
}

void CalibMQcTask::endOfActivity(const Activity& /*activity*/)
Expand Down
33 changes: 18 additions & 15 deletions Modules/MUON/MID/src/CalibQcTask.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,18 @@ void CalibQcTask::initialize(o2::framework::InitContext& /*ctx*/)
mNoise = std::make_unique<TH1F>(mDigitsHelper.makeStripHisto("NoiseStrips", "Noise strips"));
getObjectsManager()->startPublishing(mNoise.get());

for (int ich = 0; ich < 4; ++ich) {
mBendNoiseMap[ich] = std::make_unique<TH2F>(mDigitsHelper.makeStripMapHisto(fmt::format("BendNoiseMap{}", chId[ich]), fmt::format("Bending Noise Map MT{}", chId[ich]), 0));
getObjectsManager()->startPublishing(mBendNoiseMap[ich].get());
mBendNoiseMap = mDigitsHelper.makeStripMapHistos("BendNoiseMap", "Bending Noise Map", 0);
for (auto& histo : mBendNoiseMap) {
getObjectsManager()->startPublishing(histo.get());
getObjectsManager()->setDefaultDrawOptions(histo.get(), "COLZ");
}

for (int ich = 0; ich < 4; ++ich) {
mNBendNoiseMap[ich] = std::make_unique<TH2F>(mDigitsHelper.makeStripMapHisto(fmt::format("NBendNoiseMap{}", chId[ich]), fmt::format("Non-Bending Noise Map MT{}", chId[ich]), 1));
getObjectsManager()->startPublishing(mNBendNoiseMap[ich].get());
mNBendNoiseMap = mDigitsHelper.makeStripMapHistos("NBendNoiseMap", "Non-Bending Noise Map", 1);
for (auto& histo : mNBendNoiseMap) {
getObjectsManager()->startPublishing(histo.get());
getObjectsManager()->setDefaultDrawOptions(histo.get(), "COLZ");
}

// Dead strips Histograms ::
for (int ich = 0; ich < 4; ++ich) {
mMultDeadB[ich] = std::make_unique<TH1F>(fmt::format("MultDeadMT{}B", chId[ich]).c_str(), fmt::format("Multiplicity Dead strips - MT{} bending plane", chId[ich]).c_str(), 300, 0, 300);
getObjectsManager()->startPublishing(mMultDeadB[ich].get());
Expand All @@ -79,14 +80,16 @@ void CalibQcTask::initialize(o2::framework::InitContext& /*ctx*/)
mDead = std::make_unique<TH1F>(mDigitsHelper.makeStripHisto("DeadStrips", "Dead strips"));
getObjectsManager()->startPublishing(mDead.get());

for (int ich = 0; ich < 4; ++ich) {
mBendDeadMap[ich] = std::make_unique<TH2F>(mDigitsHelper.makeStripMapHisto(fmt::format("BendDeadMap{}", chId[ich]), fmt::format("Bending Dead Map MT{}", chId[ich]), 0));
getObjectsManager()->startPublishing(mBendDeadMap[ich].get());
mBendDeadMap = mDigitsHelper.makeStripMapHistos("BendDeadMap", "Bending Dead Map", 0);
for (auto& histo : mBendDeadMap) {
getObjectsManager()->startPublishing(histo.get());
getObjectsManager()->setDefaultDrawOptions(histo.get(), "COLZ");
}

for (int ich = 0; ich < 4; ++ich) {
mNBendDeadMap[ich] = std::make_unique<TH2F>(mDigitsHelper.makeStripMapHisto(fmt::format("NBendDeadMap{}", chId[ich]), fmt::format("Non-Bending Dead Map MT{}", chId[ich]), 1));
getObjectsManager()->startPublishing(mNBendDeadMap[ich].get());
mNBendDeadMap = mDigitsHelper.makeStripMapHistos("NBendDeadMap", "Non-Bending Dead Map", 1);
for (auto& histo : mNBendDeadMap) {
getObjectsManager()->startPublishing(histo.get());
getObjectsManager()->setDefaultDrawOptions(histo.get(), "COLZ");
}
}

Expand Down Expand Up @@ -153,8 +156,8 @@ void CalibQcTask::endOfCycle()
resetDisplayHistos();

// Then fill from the strip histogram
mDigitsHelper.fillMapHistos(mNoise.get(), mBendNoiseMap, mNBendNoiseMap);
mDigitsHelper.fillMapHistos(mDead.get(), mBendDeadMap, mNBendDeadMap);
mDigitsHelper.fillStripMapHistos(mNoise.get(), mBendNoiseMap, mNBendNoiseMap);
mDigitsHelper.fillStripMapHistos(mDead.get(), mBendDeadMap, mNBendDeadMap);
}

void CalibQcTask::endOfActivity(const Activity& /*activity*/)
Expand Down
Loading

0 comments on commit 4c9e420

Please sign in to comment.