Skip to content

Commit 8cad5f1

Browse files
aphecetcheshahor02
authored andcommitted
MCH: add digit noise filtering options
1 parent 9b1f2d5 commit 8cad5f1

File tree

7 files changed

+180
-26
lines changed

7 files changed

+180
-26
lines changed

Detectors/MUON/MCH/DigitFiltering/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# or submit itself to any jurisdiction.
1111

1212
o2_add_library(MCHDigitFiltering
13-
SOURCES src/DigitFilterParam.cxx src/DigitFilteringSpec.cxx
13+
SOURCES src/DigitFilter.cxx src/DigitFilterParam.cxx src/DigitFilteringSpec.cxx
1414
PUBLIC_LINK_LIBRARIES O2::MCHBase O2::Framework O2::SimulationDataFormat)
1515

1616
o2_add_executable(

Detectors/MUON/MCH/DigitFiltering/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,18 @@
55

66
# MCH Digit Filtering
77

8+
```shell
9+
o2-mch-digits-filtering-workflow
10+
```
811

12+
Filter out some digits.
13+
14+
Inputs :
15+
- list of all digits ([Digit](/DataFormats/Detectors/MUON/MCH/include/DataFormatsMCH/Digit.h)) in the current time frame, with the (default) data description `DIGITS` (can be changed with `--input-digits-data-description` option)
16+
- the list of ROF records ([ROFRecord](/DataFormats/Detectors/MUON/MCH/include/DataFormatsMCH/ROFRecord.h)) pointing to the digits associated to each interaction, with the (default) data description `DIGITROFS` (can be changed with `--input-digit-rofs-data-description` option)
17+
18+
Outputs :
19+
- list of digits that pass the filtering criteria (for the moment ADC>0), with the (default) data description `F-DIGITS` (can be changed with `--output-digits-data-description` option)
20+
- list of ROF records corresponding to the digits above, with a (default) data description of `F-DIGITROFS` (can be changed with `--output-digit-rofs-data-description` option)
21+
22+
The exact behavior of the filtering is governed by the [MCHDigitFilterParam](/Detectors/MUON/MCH/DigitFiltering/include/MCHDigitFiltering/DigitFilterParam.h) configurable param, where you can select the minimum ADC value to consider, and whether to select signal (i.e. killing as much background as possible, possibly killing some signal as well) and/or to reject background (while not killing signal).
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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_DIGITFILTER_H_
13+
#define O2_MCH_DIGITFILTERING_DIGITFILTER_H_
14+
15+
#include <functional>
16+
#include "DataFormatsMCH/Digit.h"
17+
18+
namespace o2::mch
19+
{
20+
21+
typedef std::function<bool(const Digit&)> DigitFilter;
22+
23+
DigitFilter createDigitFilter(int minADC, bool rejectBackground, bool selectSignal);
24+
25+
} // namespace o2::mch
26+
27+
#endif

Detectors/MUON/MCH/DigitFiltering/include/MCHDigitFiltering/DigitFilterParam.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ namespace o2::mch
2424
*/
2525
struct DigitFilterParam : public o2::conf::ConfigurableParamHelper<DigitFilterParam> {
2626

27-
bool sanityCheck = false; ///< whether or not to perform some sanity checks on the input digits
28-
uint32_t minADC = 1; ///< digits with an ADC below this value are discarded
29-
27+
bool sanityCheck = false; ///< whether or not to perform some sanity checks on the input digits
28+
uint32_t minADC = 1; ///< digits with an ADC below this value are discarded
29+
bool rejectBackground = false; ///< attempts to reject background (loose background selection, don't kill signal)
30+
bool selectSignal = false; ///< attempts to select only signal (strict background selection, might loose signal)
3031
O2ParamDef(DigitFilterParam, "MCHDigitFilter");
3132
};
3233

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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/DigitFilter.h"
13+
14+
#include "DataFormatsMCH/Digit.h"
15+
#include "MCHDigitFiltering/DigitFilterParam.h"
16+
#include <vector>
17+
#include <functional>
18+
#include <gsl/span>
19+
20+
namespace
21+
{
22+
/** function used to select the signal.
23+
* might cut some signal, the focus here is to kill as
24+
* much background as possible.
25+
*/
26+
double signalCut(double* x, const double* p)
27+
{
28+
double x0 = pow(p[0] / p[2], 1. / p[3]) + p[1];
29+
if (x[0] < x0) {
30+
return p[0];
31+
} else {
32+
return p[2] * pow(x[0] - p[1], p[3]);
33+
}
34+
}
35+
36+
/** function used to reject the background.
37+
* might not kill all background, focus here is ensure
38+
* we're not killing some signal along the way.
39+
*/
40+
double backgroundCut(double* x, const double* p)
41+
{
42+
43+
double x0 = (p[3] * p[2] - p[1] * p[0]) / (p[3] - p[1]);
44+
if (x[0] < x0) {
45+
return p[1] * (x[0] - p[0]);
46+
} else {
47+
return p[3] * (x[0] - p[2]);
48+
}
49+
}
50+
51+
o2::mch::DigitFilter createMinAdcCut(int minADC)
52+
{
53+
return [minADC](const o2::mch::Digit& digit) -> bool {
54+
if (digit.getADC() < minADC) {
55+
return false;
56+
}
57+
return true;
58+
};
59+
}
60+
61+
o2::mch::DigitFilter createRejectBackground()
62+
{
63+
int minNSamplesBackground = 14;
64+
double backgroundParam[4] = {18., 24., -20., 7.0};
65+
66+
auto backgroundCut = [backgroundParam](double* x) {
67+
return ::backgroundCut(x, backgroundParam);
68+
};
69+
70+
return [backgroundCut, minNSamplesBackground](const o2::mch::Digit& digit) -> bool {
71+
double nSample = digit.getNofSamples();
72+
if (digit.getNofSamples() < minNSamplesBackground || digit.getADC() < backgroundCut(&nSample)) {
73+
return false;
74+
}
75+
return true;
76+
};
77+
}
78+
79+
o2::mch::DigitFilter createSelectSignal()
80+
{
81+
int minNSamplesSignal = 17;
82+
double signalParam[4] = {80., 16., 12., 1.2};
83+
84+
auto signalCut = [signalParam](double* x) {
85+
return ::signalCut(x, signalParam);
86+
};
87+
return [signalCut, minNSamplesSignal](const o2::mch::Digit& digit) -> bool {
88+
double nSample = digit.getNofSamples();
89+
if (digit.getNofSamples() < minNSamplesSignal || digit.getADC() < signalCut(&nSample)) {
90+
return false;
91+
}
92+
return true;
93+
};
94+
}
95+
} // namespace
96+
97+
namespace o2::mch
98+
{
99+
DigitFilter createDigitFilter(int minADC, bool rejectBackground, bool selectSignal)
100+
{
101+
std::vector<DigitFilter> parts;
102+
103+
parts.emplace_back(createMinAdcCut(minADC));
104+
if (rejectBackground) {
105+
parts.emplace_back(createRejectBackground());
106+
}
107+
if (selectSignal) {
108+
parts.emplace_back(createSelectSignal());
109+
}
110+
return [parts](const Digit& digit) {
111+
for (const auto& p : parts) {
112+
if (!p(digit)) {
113+
return false;
114+
}
115+
}
116+
return true;
117+
};
118+
}
119+
120+
} // namespace o2::mch

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020
#include "Framework/Task.h"
2121
#include "Framework/WorkflowSpec.h"
2222
#include "MCHBase/SanityCheck.h"
23+
#include "MCHDigitFiltering/DigitFilter.h"
2324
#include "MCHDigitFiltering/DigitFilterParam.h"
2425
#include "SimulationDataFormat/MCCompLabel.h"
2526
#include "SimulationDataFormat/MCTruthContainer.h"
2627
#include <fmt/format.h>
28+
#include <functional>
2729
#include <iostream>
2830
#include <string>
2931
#include <vector>
@@ -41,12 +43,15 @@ class DigitFilteringTask
4143
void init(InitContext& ic)
4244
{
4345
mSanityCheck = DigitFilterParam::Instance().sanityCheck;
44-
mMinADC = DigitFilterParam::Instance().minADC;
45-
}
46-
47-
bool isGoodDigit(const Digit& digit) const
48-
{
49-
return digit.getADC() >= mMinADC;
46+
int minADC = DigitFilterParam::Instance().minADC;
47+
bool rejectBackground = DigitFilterParam::Instance().rejectBackground;
48+
mIsGoodDigit = createDigitFilter(minADC, rejectBackground, false);
49+
// at digit filtering stage it is important to keep the 3rd parameter
50+
// to false in the call above : the idea is to not cut too much
51+
// on the tails of the charge distributions otherwise the clustering
52+
// resolution will suffer.
53+
// That's why we only apply the "reject background" filter, which
54+
// is a loose background cut that does not penalize the signal
5055
}
5156

5257
void run(ProcessingContext& pc)
@@ -84,7 +89,7 @@ class DigitFilteringTask
8489
// filter the digits from the current ROF
8590
for (auto i = 0; i < digits.size(); i++) {
8691
const auto& d = digits[i];
87-
if (isGoodDigit(d)) {
92+
if (mIsGoodDigit(d)) {
8893
oDigits.emplace_back(d);
8994
if (iLabels) {
9095
oLabels->addElements(oLabels->getIndexedSize(), iLabels->getLabels(i + irof.getFirstIdx()));
@@ -119,7 +124,7 @@ class DigitFilteringTask
119124
private:
120125
bool mSanityCheck;
121126
bool mUseMC;
122-
int mMinADC;
127+
DigitFilter mIsGoodDigit;
123128
};
124129

125130
framework::DataProcessorSpec

Detectors/MUON/MCH/Workflow/README.md

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,7 @@ filePath = /home/data/data-de819-ped-raw.raw
8181

8282
## Digit filtering
8383

84-
```shell
85-
o2-mch-digits-filtering-workflow
86-
```
87-
88-
Filter out some digits. For the moment only removes digits that have a null ADC.
89-
90-
Inputs :
91-
- list of all digits ([Digit](/DataFormats/Detectors/MUON/MCH/include/DataFormatsMCH/Digit.h)) in the current time frame, with the (default) data description `DIGITS` (can be changed with `--input-digits-data-description` option)
92-
- the list of ROF records ([ROFRecord](../../../../DataFormats/Detectors/MUON/MCH/include/DataFormatsMCH/ROFRecord.h)) pointing to the digits associated to each interaction, with the (default) data description `DIGITROFS` (can be changed with `--input-digit-rofs-data-description` option)
93-
94-
Outputs :
95-
- list of digits that pass the filtering criteria (for the moment ADC>0), with the (default) data description `F-DIGITS` (can be changed with `--output-digits-data-description` option)
96-
- list of ROF records corresponding to the digits above, with a (default) data description of `F-DIGITROFS` (can be changed with `--output-digit-rofs-data-description` option)
97-
84+
Filter out (i.e. remove) some digits [more...](/Detectors/MUON/MCH/DigitFiltering/README.md)
9885

9986
## Time clustering
10087

0 commit comments

Comments
 (0)