Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Detectors/MUON/MCH/GlobalMapping/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ o2_add_library(MCHGlobalMapping
PUBLIC_LINK_LIBRARIES O2::MCHRawElecMap
O2::MCHMappingInterface
O2::MCHConditions
O2::Framework
PRIVATE_LINK_LIBRARIES O2::MCHConstants)

o2_target_root_dictionary(MCHGlobalMapping
Expand Down
27 changes: 22 additions & 5 deletions Detectors/MUON/MCH/GlobalMapping/src/DsIndex.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
#include "MCHGlobalMapping/DsIndex.h"

#include <map>
#include <stdexcept>
#include <vector>

#include "Framework/Logger.h"
#include "MCHMappingInterface/Segmentation.h"

namespace o2::mch
Expand All @@ -38,12 +41,16 @@ uint8_t numberOfDualSampaChannels(DsIndex dsIndex)
auto dsId = det.dsId();
auto deId = det.deId();
const auto& seg = o2::mch::mapping::segmentation(deId);
seg.bending().forEachPadInDualSampa(dsId, [&nch](int /*catPadIndex*/) { ++nch; });
seg.nonBending().forEachPadInDualSampa(dsId, [&nch](int /*catPadIndex*/) { ++nch; });
seg.forEachPadInDualSampa(dsId, [&nch](int /*dePadIndex*/) { ++nch; });
channelsPerDS.emplace_back(nch);
}
}
return channelsPerDS[dsIndex];
if (dsIndex < o2::mch::NumberOfDualSampas) {
return channelsPerDS[dsIndex];
} else {
LOGP(error, "invalid Dual Sampa index: {}", dsIndex);
}
return 0;
}

std::map<uint32_t, uint16_t> buildDetId2DsIndexMap()
Expand Down Expand Up @@ -72,13 +79,23 @@ std::map<uint32_t, uint16_t> buildDetId2DsIndexMap()
DsIndex getDsIndex(const o2::mch::raw::DsDetId& dsDetId)
{
static std::map<uint32_t, uint16_t> m = buildDetId2DsIndexMap();
return m[encode(dsDetId)];
try {
return m.at(encode(dsDetId));
} catch (const std::exception&) {
LOGP(error, "invalid Dual Sampa Id: {}", raw::asString(dsDetId));
}
return NumberOfDualSampas;
}

o2::mch::raw::DsDetId getDsDetId(DsIndex dsIndex)
{
static std::map<uint16_t, uint32_t> m = inverseMap(buildDetId2DsIndexMap());
return raw::decodeDsDetId(m[dsIndex]);
try {
return raw::decodeDsDetId(m.at(dsIndex));
} catch (const std::exception&) {
LOGP(error, "invalid Dual Sampa index: {}", dsIndex);
}
return raw::DsDetId(0, 0);
}

} // namespace o2::mch
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ CathodeSegmentation::CathodeSegmentation(
{
fillRtree();
for (auto dualSampaId : mDualSampaIds) {
mDualSampaId2CatPadIndices.emplace(dualSampaId, getCatPadIndices(dualSampaId));
mDualSampaId2CatPadIndices.emplace(dualSampaId, catPadIndices(dualSampaId));
}
}

std::vector<int> CathodeSegmentation::getCatPadIndices(int dualSampaId) const
std::vector<int> CathodeSegmentation::catPadIndices(int dualSampaId) const
{
std::vector<int> pi;

Expand All @@ -147,6 +147,15 @@ std::vector<int> CathodeSegmentation::getCatPadIndices(int dualSampaId) const
return pi;
}

std::vector<int> CathodeSegmentation::getCatPadIndices(int dualSampaId) const
{
auto it = mDualSampaId2CatPadIndices.find(dualSampaId);
if (it == mDualSampaId2CatPadIndices.end()) {
return {};
}
return it->second;
}

std::vector<int> CathodeSegmentation::getCatPadIndices(double xmin, double ymin,
double xmax,
double ymax) const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class CathodeSegmentation
std::vector<std::pair<float, float>> padSizes);

/// Return the list of catPadIndices for the pads of the given dual sampa.
std::vector<int> getCatPadIndices(int dualSampaIds) const;
std::vector<int> getCatPadIndices(int dualSampaId) const;

/// Return the list of catPadIndices for the pads contained in the box
/// {xmin,ymin,xmax,ymax}.
Expand Down Expand Up @@ -105,6 +105,8 @@ class CathodeSegmentation

double squaredDistance(int catPadIndex, double x, double y) const;

std::vector<int> catPadIndices(int dualSampaId) const;

private:
int mSegType;
bool mIsBendingPlane;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class Segmentation
* Validity of the returned value can be tested using isValid()
*/
///@{
/** Find the pads at position (x,y) (in cm).
/** Find the pads at position (x,y) (in cm).
Returns true is the bpad and nbpad has been filled with a valid dePadIndex,
false otherwise (if position is outside the segmentation area).
@param bpad the dePadIndex of the bending pad at position (x,y)
Expand Down Expand Up @@ -116,16 +116,19 @@ class Segmentation
template <typename CALLABLE>
void forEachPad(CALLABLE&& func) const;

template <typename CALLABLE>
void forEachPadInDualSampa(int dualSampaId, CALLABLE&& func) const;

template <typename CALLABLE>
void forEachNeighbouringPad(int dePadIndex, CALLABLE&& func) const;

template <typename CALLABLE>
void forEachPadInArea(double xmin, double ymin, double xmax, double ymax, CALLABLE&& func) const;
///@}

/** @name Access to individual cathode segmentations.
* Not needed in most cases.
*/
/** @name Access to individual cathode segmentations.
* Not needed in most cases.
*/
///@{
const CathodeSegmentation& bending() const;
const CathodeSegmentation& nonBending() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,20 @@ void Segmentation::forEachPad(CALLABLE&& func) const
});
}

template <typename CALLABLE>
void Segmentation::forEachPadInDualSampa(int dualSampaId, CALLABLE&& func) const
{
bool isBending = dualSampaId < 1024;
if (isBending) {
mBending.forEachPadInDualSampa(dualSampaId, func);
} else {
int offset{mPadIndexOffset};
mNonBending.forEachPadInDualSampa(dualSampaId, [&offset, &func](int catPadIndex) {
func(catPadIndex + offset);
});
}
}

template <typename CALLABLE>
void Segmentation::forEachPadInArea(double xmin, double ymin, double xmax, double ymax, CALLABLE&& func) const
{
Expand Down