Skip to content

Commit be0e415

Browse files
authored
TRD Tracklet Transformer Workflow (#4790)
1 parent 53cd0b4 commit be0e415

File tree

13 files changed

+522
-2
lines changed

13 files changed

+522
-2
lines changed

DataFormats/Detectors/TRD/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ o2_add_library(DataFormatsTRD
2020
include/DataFormatsTRD/LinkRecord.h
2121
include/DataFormatsTRD/Tracklet64.h
2222
include/DataFormatsTRD/RawData.h
23-
include/DataFormatsTRD/Constants.h)
23+
include/DataFormatsTRD/Constants.h
24+
include/DataFormatsTRD/CalibratedTracklet.h)
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
#ifndef O2_TRD_CALIBRATEDTRACKLET_H
12+
#define O2_TRD_CALIBRATEDTRACKLET_H
13+
14+
#include "DataFormatsTRD/Tracklet64.h"
15+
16+
namespace o2
17+
{
18+
namespace trd
19+
{
20+
21+
// The CalibratedTracklet has been calibrated in x and dy according to a calculated Lorentz Angle and Drift Velocity.
22+
// Tracklet positions in local z direction are reported at the center of the pad-row.
23+
// Pad-tilting correction is performed after tracking.
24+
class CalibratedTracklet : public Tracklet64
25+
{
26+
public:
27+
CalibratedTracklet() = default;
28+
CalibratedTracklet(uint64_t trackletWord, float x, float y, float z, float dy)
29+
: Tracklet64(trackletWord), mx(x), my(y), mz(z), mdy(dy){};
30+
~CalibratedTracklet() = default;
31+
32+
float getX() { return mx; }
33+
float getY() { return my; }
34+
float getZ() { return mz; }
35+
float getDy() { return mdy; }
36+
37+
void setX(float x) { mx = x; }
38+
void setY(float y) { my = y; }
39+
void setZ(float z) { mz = z; }
40+
void setDy(float dy) { mdy = dy; }
41+
42+
private:
43+
float mx;
44+
float my;
45+
float mz;
46+
float mdy;
47+
};
48+
49+
} // namespace trd
50+
} // namespace o2
51+
52+
#endif

DataFormats/Detectors/TRD/include/DataFormatsTRD/Constants.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ constexpr int NROBC1 = 8; // the number of ROBs per C1 chamber
4040
constexpr int NADCMCM = 21; // the number of ADC channels per MCM
4141
constexpr int NCOLMCM = 18; // the number of pads per MCM
4242

43+
constexpr int NBITSTRKLPOS = 11; // number of bits for position in tracklet64 word
44+
constexpr int NBITSTRKLSLOPE = 8; // number of bits for slope in tracklet64 word
45+
constexpr float GRANULARITYTRKLPOS = 1.f / 75; // granularity of position in tracklet64 word in pad-widths
46+
constexpr float GRANULARITYTRKLSLOPE = 1.f / 1000; // granularity of slope in tracklet64 word in pads/timebin
47+
4348
// OS: Should this not be flexible for example in case of Kr calib?
4449
constexpr int TIMEBINS = 30; // the number of time bins
4550

DataFormats/Detectors/TRD/src/DataFormatsTRDLinkDef.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
#pragma link C++ struct o2::trd::TrackletMCMHeader + ;
2222
#pragma link C++ struct o2::trd::TrackletMCMData + ;
2323
#pragma link C++ class o2::trd::Tracklet64 + ;
24+
#pragma link C++ class o2::trd::CalibratedTracklet + ;
2425
#pragma link C++ class std::vector < o2::trd::Tracklet64> + ;
26+
#pragma link C++ class std::vector < o2::trd::CalibratedTracklet> + ;
2527
#pragma link C++ class std::vector < o2::trd::TriggerRecord > +;
2628
#pragma link C++ class std::vector < o2::trd::LinkRecord > +;
2729

Detectors/TRD/base/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ o2_add_library(TRDBase
2929
src/ChamberNoise.cxx
3030
src/CalOnlineGainTables.cxx
3131
src/Tracklet.cxx
32+
src/TrackletTransformer.cxx
3233
PUBLIC_LINK_LIBRARIES O2::GPUCommon
3334
O2::GPUUtils
3435
O2::DetectorsCommonDataFormats
@@ -63,7 +64,8 @@ o2_target_root_dictionary(TRDBase
6364
include/TRDBase/Calibrations.h
6465
include/TRDBase/ChamberNoise.h
6566
include/TRDBase/CalOnlineGainTables.h
66-
include/TRDBase/Tracklet.h)
67+
include/TRDBase/Tracklet.h
68+
include/TRDBase/TrackletTransformer.h)
6769

6870
o2_add_test(DiffusionCoefficient
6971
SOURCES test/testTRDDiffusionCoefficient.cxx
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
#ifndef O2_TRD_TRACKLETTRANSFORMER_H
12+
#define O2_TRD_TRACKLETTRANSFORMER_H
13+
14+
#include "TRDBase/Geometry.h"
15+
#include "DataFormatsTRD/Tracklet64.h"
16+
#include "DataFormatsTRD/CalibratedTracklet.h"
17+
18+
namespace o2
19+
{
20+
namespace trd
21+
{
22+
23+
class TrackletTransformer
24+
{
25+
public:
26+
TrackletTransformer();
27+
~TrackletTransformer() = default;
28+
29+
float getXCathode() { return mXCathode; }
30+
float getXAnode() { return mXAnode; }
31+
float getXDrift() { return mXDrift; }
32+
float getXtb0() { return mXtb0; }
33+
34+
void setXCathode(float x) { mXCathode = x; }
35+
void setXAnode(float x) { mXAnode = x; }
36+
void setXDrift(float x) { mXDrift = x; }
37+
void setXtb0(float x) { mXtb0 = x; }
38+
39+
void loadPadPlane(int hcid);
40+
41+
float calculateY(int hcid, int column, int position);
42+
43+
float calculateZ(int padrow);
44+
45+
float calculateDy(int slope, double oldLorentzAngle, double lorentzAngle, double driftVRatio);
46+
47+
float calibrateX(double x, double t0Correction);
48+
49+
std::array<float, 3> transformL2T(int hcid, std::array<double, 3> spacePoint);
50+
51+
CalibratedTracklet transformTracklet(Tracklet64 tracklet);
52+
53+
private:
54+
o2::trd::Geometry* mGeo;
55+
const o2::trd::PadPlane* mPadPlane;
56+
57+
float mXCathode;
58+
float mXAnode;
59+
float mXDrift;
60+
float mXtb0;
61+
62+
float mt0Correction;
63+
float mOldLorentzAngle;
64+
float mLorentzAngle;
65+
float mDriftVRatio;
66+
};
67+
68+
} // namespace trd
69+
} // namespace o2
70+
71+
#endif
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
#include "DetectorsBase/GeometryManager.h"
12+
#include "TRDBase/TrackletTransformer.h"
13+
#include "TMath.h"
14+
15+
using namespace o2::trd;
16+
using namespace o2::trd::constants;
17+
18+
TrackletTransformer::TrackletTransformer()
19+
{
20+
o2::base::GeometryManager::loadGeometry();
21+
mGeo = Geometry::instance();
22+
mGeo->createPadPlaneArray();
23+
mGeo->createClusterMatrixArray();
24+
25+
// 3 cm
26+
mXCathode = mGeo->cdrHght();
27+
// 2.221
28+
// mXAnode = mGeo->anodePos();
29+
// 3.35
30+
mXAnode = mGeo->cdrHght() + mGeo->camHght() / 2;
31+
// 2.5
32+
mXDrift = mGeo->cdrHght() - 0.5;
33+
mXtb0 = -100;
34+
35+
// dummy values for testing. This will change in the future when values are pulled from CCDB
36+
mt0Correction = -0.1;
37+
mOldLorentzAngle = 0.16;
38+
mLorentzAngle = -0.14;
39+
mDriftVRatio = 1.1;
40+
}
41+
42+
void TrackletTransformer::loadPadPlane(int hcid)
43+
{
44+
int detector = hcid / 2;
45+
int stack = mGeo->getStack(detector);
46+
int layer = mGeo->getLayer(detector);
47+
mPadPlane = mGeo->getPadPlane(layer, stack);
48+
}
49+
50+
float TrackletTransformer::calculateY(int hcid, int column, int position)
51+
{
52+
double padWidth = mPadPlane->getWidthIPad();
53+
int side = hcid % 2;
54+
55+
// slightly modified TDP eq 16.1 (appended -1 to the end to account for MCM shared pads)
56+
double pad = float(position - (1 << (NBITSTRKLPOS - 1))) * GRANULARITYTRKLPOS + NCOLMCM * (4 * side + column) + 10.5 - 1;
57+
float y = padWidth * (pad - 72);
58+
59+
return y;
60+
}
61+
62+
float TrackletTransformer::calculateZ(int padrow)
63+
{
64+
double rowPos = mPadPlane->getRowPos(padrow);
65+
double rowWidth = mPadPlane->getRowSize(padrow);
66+
double middleRowPos = mPadPlane->getRowPos(mPadPlane->getNrows() / 2);
67+
68+
float z = rowPos - rowWidth / 2. - middleRowPos;
69+
70+
return z;
71+
}
72+
73+
float TrackletTransformer::calculateDy(int slope, double oldLorentzAngle, double lorentzAngle, double driftVRatio)
74+
{
75+
double padWidth = mPadPlane->getWidthIPad();
76+
77+
// temporary dummy value in cm/microsecond
78+
float vDrift = 1.56;
79+
float driftHeight = mGeo->cdrHght();
80+
81+
// dy = slope * nTimeBins * padWidth * GRANULARITYTRKLSLOPE;
82+
// nTimeBins should be number of timebins in drift region. 1 timebin is 100 nanosecond
83+
double rawDy = slope * ((driftHeight / vDrift) / 0.1) * padWidth * GRANULARITYTRKLSLOPE;
84+
85+
// driftDistance = 3.35
86+
float driftDistance = mGeo->cdrHght() + mGeo->camHght();
87+
88+
float cmSlope = rawDy / driftDistance;
89+
90+
double calibratedDy = rawDy - (TMath::Tan(lorentzAngle) * driftDistance);
91+
calibratedDy += (TMath::Tan(oldLorentzAngle) * driftDistance * driftVRatio) + cmSlope * (driftDistance * (1 - driftVRatio));
92+
93+
// ALTERNATIVE METHOD
94+
95+
// double x_anode_hit = driftDistance*driftVRatio/cmSlope;
96+
// double y_anode_hit = driftDistance*driftVRatio;
97+
98+
// double x_Lorentz_drift_hit = TMath::Tan(oldLorentzAngle)*driftDistance*driftVRatio - TMath::Tan(lorentzAngle)*driftDistance;
99+
// double y_Lorentz_drift_hit = driftDistance*driftVRatio - driftDistance;
100+
101+
// double Delta_x_Lorentz_drift_hit = x_anode_hit - x_Lorentz_drift_hit;
102+
// double Delta_y_Lorentz_drift_hit = y_anode_hit - y_Lorentz_drift_hit;
103+
// double impact_angle_rec = TMath::ATan2(Delta_y_Lorentz_drift_hit,Delta_x_Lorentz_drift_hit);
104+
105+
// float calibrationShift = TMath::Tan(impact_angle_rec) * driftDistance;
106+
107+
// LOG(info) << "ORIGINAL: " << calibratedDy;
108+
// LOG(info) << "ALTERNATIVE: " << rawDy + calibrationShift;
109+
110+
return calibratedDy;
111+
}
112+
113+
float TrackletTransformer::calibrateX(double x, double t0Correction)
114+
{
115+
return x += t0Correction;
116+
}
117+
118+
std::array<float, 3> TrackletTransformer::transformL2T(int hcid, std::array<double, 3> point)
119+
{
120+
int detector = hcid / 2;
121+
auto transformationMatrix = mGeo->getMatrixT2L(detector);
122+
123+
ROOT::Math::Impl::Transform3D<double>::Point localPoint(point[0], point[1], point[2]);
124+
auto gobalPoint = transformationMatrix ^ localPoint;
125+
126+
return {(float)gobalPoint.x(), (float)gobalPoint.y(), (float)gobalPoint.z()};
127+
}
128+
129+
CalibratedTracklet TrackletTransformer::transformTracklet(Tracklet64 tracklet)
130+
{
131+
uint64_t trackletWord = tracklet.getTrackletWord();
132+
uint64_t hcid = tracklet.getHCID();
133+
uint64_t padrow = tracklet.getPadRow();
134+
uint64_t column = tracklet.getColumn();
135+
// 0-2048 | units:pad-widths | granularity=1/75 (measured from center pad 10) 1024 is 0/center of pad 10
136+
uint64_t position = tracklet.getPosition();
137+
// 0-127 | units:pads/timebin | granularity=1/1000
138+
uint64_t slope = tracklet.getSlope();
139+
140+
// calculate raw local chamber space point
141+
loadPadPlane(hcid);
142+
float x = getXDrift();
143+
float y = calculateY(hcid, column, position);
144+
float z = calculateZ(padrow);
145+
146+
float dy = calculateDy(slope, mOldLorentzAngle, mLorentzAngle, mDriftVRatio);
147+
float calibratedX = calibrateX(x, mt0Correction);
148+
149+
std::array<float, 3> sectorSpacePoint = transformL2T(hcid, std::array<double, 3>{x, y, z});
150+
151+
LOG(debug) << "x: " << sectorSpacePoint[0] << " | "
152+
<< "y: " << sectorSpacePoint[1] << " | "
153+
<< "z: " << sectorSpacePoint[2];
154+
155+
CalibratedTracklet calibratedTracklet = CalibratedTracklet(trackletWord, sectorSpacePoint[0], sectorSpacePoint[1], sectorSpacePoint[2], dy);
156+
157+
return calibratedTracklet;
158+
}

Detectors/TRD/workflow/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ o2_add_library(TRDWorkflow
1616
src/TRDDigitWriterSpec.cxx
1717
src/TRDDigitReaderSpec.cxx
1818
src/TRDTrackletWriterSpec.cxx
19+
src/TRDCalibratedTrackletWriterSpec.cxx
1920
src/TRDTrackletReaderSpec.cxx
2021
src/TRDTrapRawWriterSpec.cxx
2122
src/TRDTrapSimulatorSpec.cxx
23+
src/TRDTrackletTransformerSpec.cxx
2224
src/TRDGlobalTrackingSpec.cxx
2325
src/TRDTrackWriterSpec.cxx
2426
src/TRDTrackingWorkflow.cxx
@@ -42,6 +44,11 @@ o2_add_executable(global-tracking
4244
SOURCES src/trd-tracking-workflow.cxx
4345
PUBLIC_LINK_LIBRARIES O2::TRDWorkflow)
4446

47+
o2_add_executable(tracklet-transformer
48+
COMPONENT_NAME trd
49+
SOURCES src/TRDTrackletTransformerWorkflow.cxx
50+
PUBLIC_LINK_LIBRARIES O2::TRDWorkflow)
51+
4552

4653
if (OpenMP_CXX_FOUND)
4754
target_compile_definitions(${targetName} PRIVATE WITH_OPENMP)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
#ifndef O2_TRDCALIBRATEDTRACKLETWRITER_H
12+
#define O2_TRDCALIBRATEDTRACKLETWRITER_H
13+
14+
#include "Framework/DataProcessorSpec.h"
15+
16+
namespace o2
17+
{
18+
namespace trd
19+
{
20+
21+
framework::DataProcessorSpec getTRDCalibratedTrackletWriterSpec();
22+
23+
} // end namespace trd
24+
} // end namespace o2
25+
26+
#endif

0 commit comments

Comments
 (0)