Skip to content
Closed
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
4 changes: 3 additions & 1 deletion Detectors/MUON/MCH/DigitFiltering/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ o2_add_library(MCHDigitFiltering
SOURCES
src/DigitFilter.cxx
src/DigitFilterParam.cxx
src/DigitModifier.cxx
src/DigitModifierParam.cxx
src/DigitFilteringSpec.cxx
PUBLIC_LINK_LIBRARIES
O2::Framework
Expand All @@ -27,4 +29,4 @@ o2_add_executable(
COMPONENT_NAME mch
PUBLIC_LINK_LIBRARIES O2::MCHDigitFiltering)

o2_target_root_dictionary(MCHDigitFiltering HEADERS include/MCHDigitFiltering/DigitFilterParam.h)
o2_target_root_dictionary(MCHDigitFiltering HEADERS include/MCHDigitFiltering/DigitFilterParam.h include/MCHDigitFiltering/DigitModifierParam.h)
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

#ifndef O2_MCH_DIGITFILTERING_DIGITMODIFIER_H_
#define O2_MCH_DIGITFILTERING_DIGITMODIFIER_H_

#include "DataFormatsMCH/Digit.h"
#include <functional>

namespace o2::mch
{
typedef std::function<void(Digit&)> DigitModifier;

DigitModifier createDigitModifier(int runNumber,
bool correctST1Mapping,
bool correctST2Mapping);

} // namespace o2::mch

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

#ifndef O2_MCH_DIGITFILTERING_DIGIT_MODIFIER_PARAM_H_
#define O2_MCH_DIGITFILTERING_DIGIT_MODIFIER_PARAM_H_

#include "CommonUtils/ConfigurableParam.h"
#include "CommonUtils/ConfigurableParamHelper.h"

namespace o2::mch
{

/**
* @class DigitModifierParam
* @brief Configurable parameters for the digit updating
*/
struct DigitModifierParam : public o2::conf::ConfigurableParamHelper<DigitModifierParam> {

bool correctST1Mapping = false; ///< whether or not to apply the mapping fixes to ST1 digits
bool correctST2Mapping = false; ///< whether or not to apply the mapping fixes to ST2 digits

O2ParamDef(DigitModifierParam, "MCHDigitModifier");
};

} // namespace o2::mch

#endif
23 changes: 23 additions & 0 deletions Detectors/MUON/MCH/DigitFiltering/src/DigitFilteringSpec.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include "MCHStatus/StatusMap.h"
#include "MCHDigitFiltering/DigitFilter.h"
#include "MCHDigitFiltering/DigitFilterParam.h"
#include "MCHDigitFiltering/DigitModifier.h"
#include "MCHDigitFiltering/DigitModifierParam.h"
#include "SimulationDataFormat/MCCompLabel.h"
#include "SimulationDataFormat/MCTruthContainer.h"
#include <fmt/format.h>
Expand All @@ -48,6 +50,10 @@ class DigitFilteringTask
mRejectBackground = DigitFilterParam::Instance().rejectBackground;
mStatusMask = DigitFilterParam::Instance().statusMask;
mTimeCalib = DigitFilterParam::Instance().timeOffset;

mCorrectST1Mapping = DigitModifierParam::Instance().correctST1Mapping;
mCorrectST2Mapping = DigitModifierParam::Instance().correctST2Mapping;

auto stop = [this]() {
LOG(info) << "digit filtering duration = "
<< std::chrono::duration<double, std::milli>(mElapsedTime).count() << " ms";
Expand Down Expand Up @@ -82,6 +88,11 @@ class DigitFilteringTask

auto tStart = std::chrono::high_resolution_clock::now();

const auto& tinfo = pc.services().get<o2::framework::TimingInfo>();
if (tinfo.runNumber != 0) {
mRunNumber = tinfo.runNumber;
}

if (mSanityCheck) {
LOGP(info, "performing sanity checks");
auto error = sanityCheck(iRofs, iDigits);
Expand Down Expand Up @@ -114,6 +125,11 @@ class DigitFilteringTask
// the clustering resolution will suffer.
// That's why we only apply the "reject background" filter, which
// is a loose background cut that does not penalize the signal

mDigitModifier = createDigitModifier(mRunNumber,
mCorrectST1Mapping,
mCorrectST2Mapping);

int cursor{0};
for (const auto& irof : iRofs) {
const auto digits = iDigits.subspan(irof.getFirstIdx(), irof.getNEntries());
Expand All @@ -126,6 +142,9 @@ class DigitFilteringTask
if (iLabels) {
oLabels->addElements(oLabels->getIndexedSize(), iLabels->getLabels(i + irof.getFirstIdx()));
}

// modify the digit if needed
mDigitModifier(oDigits.back());
}
}
int nofGoodDigits = oDigits.size() - cursor;
Expand Down Expand Up @@ -160,14 +179,18 @@ class DigitFilteringTask
}

private:
int mRunNumber{0};
bool mRejectBackground{false};
bool mSanityCheck{false};
bool mUseMC{false};
bool mUseStatusMap{false};
int mMinADC{1};
int32_t mTimeCalib{0};
uint32_t mStatusMask{0};
bool mCorrectST1Mapping;
bool mCorrectST2Mapping;
DigitFilter mIsGoodDigit;
DigitModifier mDigitModifier;
std::chrono::duration<double> mElapsedTime{};
};

Expand Down
142 changes: 142 additions & 0 deletions Detectors/MUON/MCH/DigitFiltering/src/DigitModifier.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

#include "MCHDigitFiltering/DigitModifier.h"

#include "DataFormatsMCH/Digit.h"
#include "MCHRawElecMap/Mapper.h"
#include "MCHMappingInterface/Segmentation.h"
#include <functional>
#include <array>
#include <unordered_map>

namespace
{
/** initialization of the pad remapping table for Station 2 DEs
*/
void initST2PadsRemappingTable(std::unordered_map<int, std::unordered_map<int, int>>& padsRemapping)
{
// Remapping of ST2 DS boards near the rounded part
{
std::array<int, 8> deToRemap{300, 301, 302, 303, 400, 401, 402, 403};
std::array<int, 5> dsToRemap{99, 100, 101, 102, 103};

for (auto deId : deToRemap) {

const o2::mch::mapping::Segmentation& segment = o2::mch::mapping::segmentation(deId);
for (auto dsId : dsToRemap) {
// double loop on DS channels
// 1. find the minimum pad index of the DS board
int padIdMin = -1;
int channelForPadIdMin = -1;
for (int channel = 0; channel < 64; channel++) {
auto padId = segment.findPadByFEE(dsId, int(channel));
if (padIdMin < 0 || padId < padIdMin) {
padIdMin = padId;
channelForPadIdMin = channel;
}
}

// 2. build the re-mapping table
for (int channel = 0; channel < 64; channel++) {
auto padId = segment.findPadByFEE(dsId, int(channel));
if (padId < padIdMin) {
// something is wrong here...
continue;
}
int padIdInDS = padId - padIdMin;
int padColumn = padIdInDS / 16;
int padRow = padIdInDS % 16;

int padIdRemapped = -1;

switch (padColumn) {
case 0:
// shift right by 3 columns
padIdRemapped = padId + 16 * 3;
break;
case 1:
// shift right by 1 column
padIdRemapped = padId + 16;
break;
case 2:
// shift left by 1 column
padIdRemapped = padId - 16;
break;
case 3:
// shift left by 3 columns
padIdRemapped = padId - 16 * 3;
break;
}

padsRemapping[deId][padId] = padIdRemapped;
}
}
}
}
}

o2::mch::DigitModifier createST1MappingCorrector(int /*runNumber*/)
{
return [](o2::mch::Digit& digit) {
return;
};
}
} // namespace

o2::mch::DigitModifier createST2MappingCorrector(int /*runNumber*/)
{
static std::unordered_map<int, std::unordered_map<int, int>> padsRemapping;

if (padsRemapping.empty()) {
initST2PadsRemappingTable(padsRemapping);
}

return [](o2::mch::Digit& digit) {
// Only consider DEs from ST2
if (digit.getDetID() >= 300 && digit.getDetID() < 500) {
// check if the current DE needs some remapping
if (padsRemapping.count(digit.getDetID()) > 0) {
// check if the current padID needs to be remapped
auto& padsRemappingForDe = padsRemapping[digit.getDetID()];
if (padsRemappingForDe.count(digit.getPadID()) > 0) {
// get the corrected padID
int padIDRemapped = padsRemappingForDe[digit.getPadID()];
// update the digit
digit.setPadID(padIDRemapped);
}
}
}
};
}

namespace o2::mch
{
DigitModifier createDigitModifier(int runNumber,
bool correctST1Mapping,
bool correctST2Mapping)
{
std::vector<DigitModifier> parts;

if (correctST1Mapping) {
parts.emplace_back(createST1MappingCorrector(runNumber));
}
if (correctST2Mapping) {
parts.emplace_back(createST2MappingCorrector(runNumber));
}
return [parts](Digit& digit) {
for (const auto& p : parts) {
p(digit);
}
};
}

} // namespace o2::mch
15 changes: 15 additions & 0 deletions Detectors/MUON/MCH/DigitFiltering/src/DigitModifierParam.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

#include "MCHDigitFiltering/DigitModifierParam.h"
#include "CommonUtils/ConfigurableParam.h"

O2ParamImpl(o2::mch::DigitModifierParam)
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@
#pragma link C++ class o2::mch::DigitFilterParam + ;
#pragma link C++ class o2::conf::ConfigurableParamHelper < o2::mch::DigitFilterParam> + ;

#pragma link C++ class o2::mch::DigitModifierParam + ;
#pragma link C++ class o2::conf::ConfigurableParamHelper < o2::mch::DigitModifierParam> + ;

#endif