Skip to content

Commit 905fbcf

Browse files
committed
[MCH] introduce digit modifier in filtering workflow
The digit modifier allows to change the contents of the digits in the filtering step. It is introduced in order to correct some mapping issues in the CTFs already collected, but the interface is general, and in the future it might be used for any kind of digit manipulation, if needed.
1 parent c1509f8 commit 905fbcf

File tree

7 files changed

+249
-1
lines changed

7 files changed

+249
-1
lines changed

Detectors/MUON/MCH/DigitFiltering/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ o2_add_library(MCHDigitFiltering
1313
SOURCES
1414
src/DigitFilter.cxx
1515
src/DigitFilterParam.cxx
16+
src/DigitModifier.cxx
17+
src/DigitModifierParam.cxx
1618
src/DigitFilteringSpec.cxx
1719
PUBLIC_LINK_LIBRARIES
1820
O2::Framework
@@ -27,4 +29,4 @@ o2_add_executable(
2729
COMPONENT_NAME mch
2830
PUBLIC_LINK_LIBRARIES O2::MCHDigitFiltering)
2931

30-
o2_target_root_dictionary(MCHDigitFiltering HEADERS include/MCHDigitFiltering/DigitFilterParam.h)
32+
o2_target_root_dictionary(MCHDigitFiltering HEADERS include/MCHDigitFiltering/DigitFilterParam.h include/MCHDigitFiltering/DigitModifierParam.h)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
#ifndef O2_MCH_DIGITFILTERING_DIGITMODIFIER_H_
13+
#define O2_MCH_DIGITFILTERING_DIGITMODIFIER_H_
14+
15+
#include "DataFormatsMCH/Digit.h"
16+
#include <functional>
17+
18+
namespace o2::mch
19+
{
20+
typedef std::function<void(Digit&)> DigitModifier;
21+
22+
DigitModifier createDigitModifier(int runNumber,
23+
bool correctST1Mapping,
24+
bool correctST2Mapping);
25+
26+
} // namespace o2::mch
27+
28+
#endif
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
#ifndef O2_MCH_DIGITFILTERING_DIGIT_MODIFIER_PARAM_H_
13+
#define O2_MCH_DIGITFILTERING_DIGIT_MODIFIER_PARAM_H_
14+
15+
#include "CommonUtils/ConfigurableParam.h"
16+
#include "CommonUtils/ConfigurableParamHelper.h"
17+
18+
namespace o2::mch
19+
{
20+
21+
/**
22+
* @class DigitModifierParam
23+
* @brief Configurable parameters for the digit updating
24+
*/
25+
struct DigitModifierParam : public o2::conf::ConfigurableParamHelper<DigitModifierParam> {
26+
27+
bool correctST1Mapping = false; ///< whether or not to apply the mapping fixes to ST1 digits
28+
bool correctST2Mapping = false; ///< whether or not to apply the mapping fixes to ST2 digits
29+
30+
O2ParamDef(DigitModifierParam, "MCHDigitModifier");
31+
};
32+
33+
} // namespace o2::mch
34+
35+
#endif

Detectors/MUON/MCH/DigitFiltering/src/DigitFilteringSpec.cxx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include "MCHStatus/StatusMap.h"
2424
#include "MCHDigitFiltering/DigitFilter.h"
2525
#include "MCHDigitFiltering/DigitFilterParam.h"
26+
#include "MCHDigitFiltering/DigitModifier.h"
27+
#include "MCHDigitFiltering/DigitModifierParam.h"
2628
#include "SimulationDataFormat/MCCompLabel.h"
2729
#include "SimulationDataFormat/MCTruthContainer.h"
2830
#include <fmt/format.h>
@@ -48,6 +50,10 @@ class DigitFilteringTask
4850
mRejectBackground = DigitFilterParam::Instance().rejectBackground;
4951
mStatusMask = DigitFilterParam::Instance().statusMask;
5052
mTimeCalib = DigitFilterParam::Instance().timeOffset;
53+
54+
mCorrectST1Mapping = DigitModifierParam::Instance().correctST1Mapping;
55+
mCorrectST2Mapping = DigitModifierParam::Instance().correctST2Mapping;
56+
5157
auto stop = [this]() {
5258
LOG(info) << "digit filtering duration = "
5359
<< std::chrono::duration<double, std::milli>(mElapsedTime).count() << " ms";
@@ -82,6 +88,11 @@ class DigitFilteringTask
8288

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

91+
const auto& tinfo = pc.services().get<o2::framework::TimingInfo>();
92+
if (tinfo.runNumber != 0) {
93+
mRunNumber = tinfo.runNumber;
94+
}
95+
8596
if (mSanityCheck) {
8697
LOGP(info, "performing sanity checks");
8798
auto error = sanityCheck(iRofs, iDigits);
@@ -114,6 +125,11 @@ class DigitFilteringTask
114125
// the clustering resolution will suffer.
115126
// That's why we only apply the "reject background" filter, which
116127
// is a loose background cut that does not penalize the signal
128+
129+
mDigitModifier = createDigitModifier(mRunNumber,
130+
mCorrectST1Mapping,
131+
mCorrectST2Mapping);
132+
117133
int cursor{0};
118134
for (const auto& irof : iRofs) {
119135
const auto digits = iDigits.subspan(irof.getFirstIdx(), irof.getNEntries());
@@ -126,6 +142,9 @@ class DigitFilteringTask
126142
if (iLabels) {
127143
oLabels->addElements(oLabels->getIndexedSize(), iLabels->getLabels(i + irof.getFirstIdx()));
128144
}
145+
146+
// modify the digit if needed
147+
mDigitModifier(oDigits.back());
129148
}
130149
}
131150
int nofGoodDigits = oDigits.size() - cursor;
@@ -160,14 +179,18 @@ class DigitFilteringTask
160179
}
161180

162181
private:
182+
int mRunNumber{0};
163183
bool mRejectBackground{false};
164184
bool mSanityCheck{false};
165185
bool mUseMC{false};
166186
bool mUseStatusMap{false};
167187
int mMinADC{1};
168188
int32_t mTimeCalib{0};
169189
uint32_t mStatusMask{0};
190+
bool mCorrectST1Mapping;
191+
bool mCorrectST2Mapping;
170192
DigitFilter mIsGoodDigit;
193+
DigitModifier mDigitModifier;
171194
std::chrono::duration<double> mElapsedTime{};
172195
};
173196

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
#include "MCHDigitFiltering/DigitModifier.h"
13+
14+
#include "DataFormatsMCH/Digit.h"
15+
#include "MCHRawElecMap/Mapper.h"
16+
#include "MCHMappingInterface/Segmentation.h"
17+
#include <functional>
18+
#include <array>
19+
#include <unordered_map>
20+
21+
namespace
22+
{
23+
/** initialization of the pad remapping table for Station 2 DEs
24+
*/
25+
void initST2PadsRemappingTable(std::unordered_map<int, std::unordered_map<int, int>>& padsRemapping)
26+
{
27+
// Remapping of ST2 DS boards near the rounded part
28+
{
29+
std::array<int, 8> deToRemap{300, 301, 302, 303, 400, 401, 402, 403};
30+
std::array<int, 5> dsToRemap{99, 100, 101, 102, 103};
31+
32+
for (auto deId : deToRemap) {
33+
34+
const o2::mch::mapping::Segmentation& segment = o2::mch::mapping::segmentation(deId);
35+
for (auto dsId : dsToRemap) {
36+
// double loop on DS channels
37+
// 1. find the minimum pad index of the DS board
38+
int padIdMin = -1;
39+
int channelForPadIdMin = -1;
40+
for (int channel = 0; channel < 64; channel++) {
41+
auto padId = segment.findPadByFEE(dsId, int(channel));
42+
if (padIdMin < 0 || padId < padIdMin) {
43+
padIdMin = padId;
44+
channelForPadIdMin = channel;
45+
}
46+
}
47+
48+
// 2. build the re-mapping table
49+
for (int channel = 0; channel < 64; channel++) {
50+
auto padId = segment.findPadByFEE(dsId, int(channel));
51+
if (padId < padIdMin) {
52+
// something is wrong here...
53+
continue;
54+
}
55+
int padIdInDS = padId - padIdMin;
56+
int padColumn = padIdInDS / 16;
57+
int padRow = padIdInDS % 16;
58+
59+
int padIdRemapped = -1;
60+
61+
switch (padColumn) {
62+
case 0:
63+
// shift right by 3 columns
64+
padIdRemapped = padId + 16 * 3;
65+
break;
66+
case 1:
67+
// shift right by 1 column
68+
padIdRemapped = padId + 16;
69+
break;
70+
case 2:
71+
// shift left by 1 column
72+
padIdRemapped = padId - 16;
73+
break;
74+
case 3:
75+
// shift left by 3 columns
76+
padIdRemapped = padId - 16 * 3;
77+
break;
78+
}
79+
80+
padsRemapping[deId][padId] = padIdRemapped;
81+
}
82+
}
83+
}
84+
}
85+
}
86+
87+
o2::mch::DigitModifier createST1MappingCorrector(int /*runNumber*/)
88+
{
89+
return [](o2::mch::Digit& digit) {
90+
return;
91+
};
92+
}
93+
} // namespace
94+
95+
o2::mch::DigitModifier createST2MappingCorrector(int /*runNumber*/)
96+
{
97+
static std::unordered_map<int, std::unordered_map<int, int>> padsRemapping;
98+
99+
if (padsRemapping.empty()) {
100+
initST2PadsRemappingTable(padsRemapping);
101+
}
102+
103+
return [](o2::mch::Digit& digit) {
104+
// Only consider DEs from ST2
105+
if (digit.getDetID() >= 300 && digit.getDetID() < 500) {
106+
// check if the current DE needs some remapping
107+
if (padsRemapping.count(digit.getDetID()) > 0) {
108+
// check if the current padID needs to be remapped
109+
auto& padsRemappingForDe = padsRemapping[digit.getDetID()];
110+
if (padsRemappingForDe.count(digit.getPadID()) > 0) {
111+
// get the corrected padID
112+
int padIDRemapped = padsRemappingForDe[digit.getPadID()];
113+
// update the digit
114+
digit.setPadID(padIDRemapped);
115+
}
116+
}
117+
}
118+
};
119+
}
120+
121+
namespace o2::mch
122+
{
123+
DigitModifier createDigitModifier(int runNumber,
124+
bool correctST1Mapping,
125+
bool correctST2Mapping)
126+
{
127+
std::vector<DigitModifier> parts;
128+
129+
if (correctST1Mapping) {
130+
parts.emplace_back(createST1MappingCorrector(runNumber));
131+
}
132+
if (correctST2Mapping) {
133+
parts.emplace_back(createST2MappingCorrector(runNumber));
134+
}
135+
return [parts](Digit& digit) {
136+
for (const auto& p : parts) {
137+
p(digit);
138+
}
139+
};
140+
}
141+
142+
} // namespace o2::mch
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
#include "MCHDigitFiltering/DigitModifierParam.h"
13+
#include "CommonUtils/ConfigurableParam.h"
14+
15+
O2ParamImpl(o2::mch::DigitModifierParam)

Detectors/MUON/MCH/DigitFiltering/src/MCHDigitFilteringLinkDef.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,7 @@
1818
#pragma link C++ class o2::mch::DigitFilterParam + ;
1919
#pragma link C++ class o2::conf::ConfigurableParamHelper < o2::mch::DigitFilterParam> + ;
2020

21+
#pragma link C++ class o2::mch::DigitModifierParam + ;
22+
#pragma link C++ class o2::conf::ConfigurableParamHelper < o2::mch::DigitModifierParam> + ;
23+
2124
#endif

0 commit comments

Comments
 (0)