Skip to content

Commit 0d4bcdd

Browse files
badarotsdavidrohr
authored andcommitted
TPC: multidimensional dE/dx calibration
1 parent ded2f2f commit 0d4bcdd

30 files changed

Lines changed: 1197 additions & 369 deletions

DataFormats/Detectors/TPC/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ o2_add_library(
2727
src/WorkflowHelper.cxx
2828
src/CompressedClusters.cxx
2929
src/TrackCuts.cxx
30+
src/CalibdEdxCorrection.cxx
3031
PUBLIC_LINK_LIBRARIES O2::GPUCommon
3132
O2::SimulationDataFormat
3233
O2::CommonDataFormat
@@ -53,7 +54,8 @@ o2_target_root_dictionary(
5354
include/DataFormatsTPC/ZeroSuppression.h
5455
include/DataFormatsTPC/ZeroSuppressionLinkBased.h
5556
include/DataFormatsTPC/TrackCuts.h
56-
include/DataFormatsTPC/LtrCalibData.h)
57+
include/DataFormatsTPC/LtrCalibData.h
58+
include/DataFormatsTPC/CalibdEdxCorrection.h)
5759

5860
o2_add_test(
5961
ClusterNative
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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+
/// \file CalibdEdxCorrection.h
13+
/// \author Thiago Badaró <thiago.saramela@usp.br>
14+
15+
#ifndef ALICEO2_TPC_CALIBDEDXCORRECTION_H_
16+
#define ALICEO2_TPC_CALIBDEDXCORRECTION_H_
17+
18+
#include "GPUCommonDef.h"
19+
#ifndef GPUCA_ALIGPUCODE
20+
#include <cstddef>
21+
#include <array>
22+
#include <string_view>
23+
#endif
24+
25+
// o2 includes
26+
#include "DataFormatsTPC/Defs.h"
27+
28+
namespace o2::tpc
29+
{
30+
31+
class CalibdEdxCorrection
32+
{
33+
public:
34+
using Params = std::array<float, 6>;
35+
#if !defined(GPUCA_GPUCODE)
36+
CalibdEdxCorrection()
37+
{
38+
clear();
39+
}
40+
CalibdEdxCorrection(std::string_view fileName) { loadFile(fileName); }
41+
#else
42+
CalibdEdxCorrection() CON_DEFAULT;
43+
#endif
44+
~CalibdEdxCorrection() CON_DEFAULT;
45+
46+
GPUd() float getCorrection(const StackID& stack, ChargeType charge, float z = 0, float tgl = 0) const
47+
{
48+
// by default return 1 if no correction was loaded
49+
if (mDims < 0) {
50+
return 1;
51+
}
52+
53+
const auto& p = mParams[stackIndex(stack, charge)];
54+
float corr = p[0];
55+
56+
if (mDims > 0) {
57+
corr += p[1] * z + p[2] * z * z;
58+
if (mDims > 1) {
59+
corr += p[3] * tgl + p[4] * z * tgl + p[5] * tgl * tgl;
60+
}
61+
}
62+
63+
return corr;
64+
}
65+
66+
#if !defined(GPUCA_GPUCODE)
67+
float getChi2(const StackID& stack, ChargeType charge) const
68+
{
69+
return mChi2[stackIndex(stack, charge)];
70+
}
71+
int getDims() const { return mDims; }
72+
73+
void setParams(const StackID& stack, ChargeType charge, const Params& params) { mParams[stackIndex(stack, charge)] = params; }
74+
void setChi2(const StackID& stack, ChargeType charge, float chi2) { mChi2[stackIndex(stack, charge)] = chi2; }
75+
void setDims(int dims) { mDims = dims; }
76+
77+
void clear();
78+
79+
void saveFile(std::string_view fileName) const;
80+
void loadFile(std::string_view fileName);
81+
#endif
82+
83+
private:
84+
GPUd() static size_t stackIndex(const StackID& stack, ChargeType charge)
85+
{
86+
return static_cast<size_t>(stack.index() + charge * SECTORSPERSIDE * SIDES * GEMSTACKSPERSECTOR);
87+
}
88+
89+
std::array<Params, 288> mParams{};
90+
std::array<float, 288> mChi2{};
91+
int mDims{-1}; ///< Fit dimension
92+
};
93+
94+
} // namespace o2::tpc
95+
96+
#endif

DataFormats/Detectors/TPC/include/DataFormatsTPC/Defs.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,25 @@ enum class PadSubset : char {
6565
Region ///< Regions (up to 36*10)
6666
};
6767

68+
// TPC dE/dx charge types
69+
enum ChargeType {
70+
Max = 0,
71+
Tot = 1
72+
};
73+
constexpr unsigned short CHARGETYPES = 2;
74+
75+
/// GEM stack identification
76+
struct StackID {
77+
int sector{};
78+
GEMstack type{};
79+
80+
/// Single number identification for the stacks
81+
GPUdi() int index() const
82+
{
83+
return sector + type * SECTORSPERSIDE * SIDES;
84+
}
85+
};
86+
6887
/// Statistics type
6988
enum class StatisticsType {
7089
GausFit, ///< Use slow gaus fit (better fit stability)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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 "DataFormatsTPC/CalibdEdxCorrection.h"
13+
14+
#include <algorithm>
15+
#include <array>
16+
#include <cstddef>
17+
#include <string_view>
18+
19+
// o2 includes
20+
#include "DataFormatsTPC/Defs.h"
21+
22+
// root includes
23+
#include "TFile.h"
24+
25+
using namespace o2::tpc;
26+
27+
void CalibdEdxCorrection::clear()
28+
{
29+
for (auto& x : mParams) {
30+
std::fill(x.begin(), x.end(), 0.0);
31+
}
32+
std::fill(mChi2.begin(), mChi2.end(), 0.0);
33+
mDims = -1;
34+
}
35+
36+
void CalibdEdxCorrection::saveFile(std::string_view fileName) const
37+
{
38+
std::unique_ptr<TFile> file(TFile::Open(fileName.data(), "recreate"));
39+
file->WriteObject(this, "CalibdEdxCorrection");
40+
}
41+
42+
void CalibdEdxCorrection::loadFile(std::string_view fileName)
43+
{
44+
std::unique_ptr<TFile> file(TFile::Open(fileName.data()));
45+
auto tmp = file->Get<CalibdEdxCorrection>("CalibdEdxCorrection");
46+
if (tmp != nullptr) {
47+
*this = *tmp;
48+
}
49+
}

DataFormats/Detectors/TPC/src/DataFormatsTPCLinkDef.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,6 @@
5555
#pragma link C++ class std::vector<o2::tpc::KrCluster> + ;
5656
#pragma link C++ class o2::tpc::LtrCalibData +;
5757
#pragma link C++ class std::vector<o2::tpc::LtrCalibData> +;
58+
#pragma link C++ class o2::tpc::CalibdEdxCorrection + ;
5859

5960
#endif

Detectors/TPC/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ This is a top page for the TPC detector documentation.
99
<!-- doxy
1010
* \subpage refTPCworkflow
1111
* \subpage refTPCsimulation
12+
* \subpage refTPCcalibration
1213
/doxy -->

Detectors/TPC/calibration/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ o2_add_library(TPCCalibration
3333
src/IDCFourierTransform.cxx
3434
src/RobustAverage.cxx
3535
src/IDCCCDBHelper.cxx
36-
src/dEdxHistos.cxx
3736
src/CalibdEdx.cxx
37+
src/CalibratordEdx.cxx
3838
PUBLIC_LINK_LIBRARIES O2::DataFormatsTPC O2::TPCBase
3939
O2::TPCReconstruction ROOT::Minuit
4040
Microsoft.GSL::GSL
@@ -65,8 +65,8 @@ o2_target_root_dictionary(TPCCalibration
6565
include/TPCCalibration/IDCFourierTransformBase.h
6666
include/TPCCalibration/IDCFourierTransform.h
6767
include/TPCCalibration/IDCCCDBHelper.h
68-
include/TPCCalibration/dEdxHistos.h
69-
include/TPCCalibration/CalibdEdx.h)
68+
include/TPCCalibration/CalibdEdx.h
69+
include/TPCCalibration/CalibratordEdx.h)
7070

7171
o2_add_executable(dcs-sim-workflow
7272
COMPONENT_NAME tpc
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<!-- doxy
2+
\page refTPCcalibrationCalibdEdx dEdx Calibration
3+
/doxy -->
4+
5+
# dEdx Calibration
6+
7+
The workflow `o2-tpc-miptrack-filter` is supposed to run in the EPNs, and will select only the track inside the defined cuts, the selected track in the streamed with the name `TPC/MIPS/0`. The cut values can be changed with these CLI options:
8+
9+
```
10+
--min-momentum (= 0.4)
11+
--max-momentum (= 0.6)
12+
--min-clusters (= 60) Minimum number of cluster in a track.
13+
```
14+
15+
The workflow `o2-tpc-calibratordedx` should run in an aggregation node. It will fill dEdx histograms using the data sended by the `o2-tpc-miptrack-filter`, and will compute corrections for the dE/dx values for every time slot.
16+
17+
```
18+
--tf-per-slot
19+
--max-delay
20+
--min-entries Minimum number of entries per GEM stack to perform a fit
21+
22+
--min-entries-sector Bellow the number of entries per stack every sector will be integrated before the fit
23+
--min-entries-1d Minimum entries per stack to perform a 1D fit, bellow it only calculate the mean
24+
--min-entries-2d Mininum entries per stack to perform a 2D fit
25+
26+
--dedxbins Number of dE/dx bins
27+
--zbins Number of Z bins
28+
--angularbins Number of angular bins, for values like Tgl and Snp
29+
--min-dedx Min. dE/dx value
30+
--max-dedx Max. dE/dx value
31+
32+
--file-dump Save calibration correction to a file
33+
--field Magnetic field in kG, need for track propagations, this value will be overwritten if a grp file is present
34+
```
35+
36+
The workflow `o2-tpc-calibdedx` is similar to `o2-tpc-calibratordedx`, but only compute correction for a single set of data.
37+
38+
## Executing
39+
40+
The full dE/dx calibration workflow can be executed in the following way:
41+
42+
```
43+
o2-tpc-track-reader --disable-mc | o2-tpc-miptrack-filter | o2-tpc-calibrator-dedx --file-dump --min-entries 100 --tf-per-slot 10
44+
```
45+
46+
Where we enabled the option to save the corrections to a file, set the min. entires per time slot to 100 and defined that the time slots should have 10 time frames.
47+
48+
## Simulating EPN workflow
49+
50+
To simulate the EPN/Agregation node topology you can execute the following.
51+
Run the `o2-tpc-miptrack-filter` workflow, it will start listening to `TPC/MIPS/0`, waiting for tracks data to process.
52+
53+
```
54+
o2-dpl-raw-proxy --dataspec A:TPC/MIPS/0 --channel-config "name=readout-proxy,type=pull,method=bind,address=tcp://localhost:30453,rateLogging=1,transport=zeromq" | o2-tpc-calib-dedx
55+
```
56+
57+
Now, in a new shell, start the `o2-tpc-miptrack-filter`.
58+
59+
```
60+
o2-tpc-track-reader --disable-mc | o2-tpc-miptrack-filter | o2-dpl-output-proxy --channel-config "name=downstream,method=connect,address=tcp://localhost:30453,type=push,transport=zeromq" --dataspec downstream:TPC/MIPS -b
61+
```
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!-- doxy
2+
\page refTPCcalibration TPC Calibration
3+
/doxy -->
4+
5+
# TPC Calibration
6+
7+
This is a top page for the TPC calibration documentation.
8+
9+
<!-- doxy
10+
* \subpage refTPCcalibrationCalibdEdx
11+
/doxy -->

0 commit comments

Comments
 (0)