Project
Loading...
Searching...
No Matches
CoordinateTransformer.cxx
Go to the documentation of this file.
1// Copyright 2019-2023 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
13#include <TMath.h>
15#include "TRDBase/Geometry.h"
16
17using namespace o2::trd;
18
19float ChamberSpacePoint::getMCMChannel(int mcmcol) const
20{
22 if (c < 0.0 || c > o2::trd::constants::NADCMCM) {
23 return -1;
24 } else {
25 return c;
26 }
27}
28
29bool ChamberSpacePoint::isInMCM(int detector, int padrow, int mcmcol) const
30{
31 if (detector != mDetector || padrow != mPadrow) {
32 return false;
33 } else {
34 // calculate the channel number in the MCM for the
35 float c = getMCMChannel(mcmcol);
36 if (c < 0.0 || c > o2::trd::constants::NADCMCM) {
37 return false;
38 } else {
39 return true;
40 }
41 }
42}
43
44CoordinateTransformer::CoordinateTransformer()
45 : mGeo(o2::trd::Geometry::instance())
46{
47 mGeo->createPadPlaneArray();
48}
49
50std::array<float, 3> CoordinateTransformer::Local2RCT(int det, float x, float y, float z)
51{
52 std::array<float, 3> rct;
53
54 auto padPlane = mGeo->getPadPlane((det) % 6, (det / 6) % 5);
55
56 // for the z-coordinate, we combine the row number and offset from the padPlane into a single float
57 int row = padPlane->getPadRow(z);
58 if (row == 0 || row == padPlane->getNrows() - 1) {
59 rct[0] = float(row) + padPlane->getPadRowOffsetROC(row, z) / padPlane->getLengthOPad();
60 } else {
61 rct[0] = float(row) + padPlane->getPadRowOffsetROC(row, z) / padPlane->getLengthIPad();
62 }
63
64 // the y-coordinate is calculated directly by the padPlane object
65 rct[1] = padPlane->getPad(y, z);
66
67 // we calculate the time coordinate by hand
68 if (x < -0.35) {
69 // in drift region:
70 // account for offset between anode and cathode wires: add 0.35
71 // convert drift velocity to from cm/us to cm/timebin
72 rct[2] = mT0 - (x + 0.35) / (mVdrift / 10.0);
73 } else {
74 // anode region: very rough guess
75 rct[2] = mT0 - 1.0 + fabs(x);
76 }
77
78 // Correct for Lorentz angle, but only in the drift region. ExB in the anode region causes a small offset (ca. 0.1
79 // pads) that is constant for all clusters in the drift region.
80 rct[1] += (x + 0.35) * mExB;
81 return rct;
82}
83
84std::array<float, 3> CoordinateTransformer::OrigLocal2RCT(int det, float x, float y, float z)
85{
86 std::array<float, 3> rct;
87
88 auto padPlane = mGeo->getPadPlane((det) % 6, (det / 6) % 5);
89
90 // array<double,3> rct;
91
92 double iPadLen = padPlane->getLengthIPad();
93 double oPadLen = padPlane->getLengthOPad();
94 int nRows = padPlane->getNrows();
95
96 double lengthCorr = padPlane->getLengthOPad() / padPlane->getLengthIPad();
97
98 // calculate position based on inner pad length
99 rct[0] = -z / padPlane->getLengthIPad() + padPlane->getNrows() / 2;
100
101 // correct row for outer pad rows
102 if (rct[0] <= 1.0) {
103 rct[0] = 1.0 - (1.0 - rct[0]) * lengthCorr;
104 }
105
106 if (rct[0] >= double(nRows - 1)) {
107 rct[0] = double(nRows - 1) + (rct[0] - double(nRows - 1)) * lengthCorr;
108 }
109
110 // sanity check: is the padrow coordinate reasonable?
111 if (rct[0] < 0.0 || rct[0] > double(nRows)) {
112 std::cout << "ERROR: hit with z=" << z << ", padrow " << rct[0]
113 << " outside of chamber" << std::endl;
114 }
115
116 // simple conversion of pad / local y coordinate
117 // ignore different width of outer pad
118 rct[1] = y / padPlane->getWidthIPad() + 144. / 2.;
119
120 // time coordinate
121 if (x < -0.35) {
122 // drift region
123 rct[2] = mT0 - (x + 0.35) / (mVdrift / 10.0);
124 } else {
125 // anode region: very rough guess
126 rct[2] = mT0 - 1.0 + fabs(x);
127 }
128
129 return rct;
130}
131
133{
134 float x = hit.getLocalT();
135 float y = hit.getLocalC();
136 float z = hit.getLocalR();
137 auto rct = Local2RCT(hit.GetDetectorID(), x, y, z);
138 return o2::trd::ChamberSpacePoint(hit.GetTrackID(), hit.GetDetectorID(), x, y, y, rct, hit.isFromDriftRegion());
139}
140
141namespace o2::trd
142{
143std::ostream& operator<<(std::ostream& os, const ChamberSpacePoint& p)
144{
145 int sector = p.getDetector() / 30;
146 int stack = (p.getDetector() % 30) / 6;
147 int layer = p.getDetector() % 6;
148
149 os << "( " << std::setprecision(5) << p.getX()
150 << " / " << std::setprecision(5) << p.getY()
151 << " / " << std::setprecision(6) << p.getZ() << ") <-> ["
152 << sector << "_" << stack << "_" << layer << " (" << p.getDetector() << ")"
153 << " row " << p.getPadRow()
154 << " pad " << std::setprecision(5) << p.getPadCol() << "]";
155 return os;
156}
157}; // namespace o2::trd
Global TRD definitions and constants.
uint32_t c
Definition RawData.h:2
uint32_t stack
Definition RawData.h:1
uint32_t padrow
Definition RawData.h:5
int GetTrackID() const
Definition BaseHits.h:30
short GetDetectorID() const
Definition BaseHits.h:73
float getX() const
spatial x coordinate of space point
float getMCMChannel(int mcmcol) const
calculate the channel number within the MCM. 0..21 if valid, -1 if not within this MCM
bool isInMCM(int detector, int padrow, int mcmcol) const
int getPadRow() const
pad row within detector of space point
int getDetector() const
detector number corresponding to space point
float getZ() const
spatial z coordinate of space point
float getY() const
spatial y coordinate of space point
float getPadCol() const
pad position (a.k.a. column) within pad row
o2::trd::ChamberSpacePoint MakeSpacePoint(o2::trd::Hit &hit)
std::array< float, 3 > Local2RCT(int det, float x, float y, float z)
float mExB
tan(Lorentz angle): tan(8 deg) ~ 0.140
std::array< float, 3 > OrigLocal2RCT(int det, float x, float y, float z)
float mT0
time offset of start of drift region
float mVdrift
drift velocity in cm/us
float getLocalT() const
Definition Hit.h:34
float getLocalR() const
Definition Hit.h:33
bool isFromDriftRegion() const
Definition Hit.h:28
float getLocalC() const
Definition Hit.h:32
GLint GLenum GLint x
Definition glcorearb.h:403
GLenum GLuint GLint GLint layer
Definition glcorearb.h:1310
GLdouble GLdouble GLdouble z
Definition glcorearb.h:843
constexpr int NADCMCM
the number of ADC channels per MCM
Definition Constants.h:52
constexpr int NCOLMCM
the number of pads per MCM
Definition Constants.h:53
std::ostream & operator<<(std::ostream &stream, const Digit &d)
Definition Digit.cxx:78
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::vector< int > row