Project
Loading...
Searching...
No Matches
AlignableDetectorTPC.cxx
Go to the documentation of this file.
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
15
19#include "Align/Controller.h"
20#include "Align/AlignConfig.h"
25#include <TMath.h>
26#include <TGeoManager.h>
27#include "GPUO2Interface.h"
29#include "GPUParam.inc"
30
31namespace o2
32{
33namespace align
34{
35using namespace TMath;
36
37//____________________________________________
42
43//____________________________________________
45{
46 // define fictious TPC envelope and sector volumes
47 AlignableVolume* volTPC = nullptr;
48 int labDet = getDetLabel();
49 const int NSectors = o2::tpc::constants::MAXSECTOR / 2;
50
51 addVolume(volTPC = new AlignableVolume("TPC_envelope", getDetLabel(), mController));
52 volTPC->setDummyEnvelope();
53
54 for (int isec = 0; isec < o2::tpc::constants::MAXSECTOR; isec++) {
55 int isecSide = isec % NSectors;
56 const char* symname = Form("TPC/sec%02d", isec);
58 sector->setParent(volTPC);
59 addVolume(sector);
60 }
61}
62
63//____________________________________________
64void AlignableDetectorTPC::Print(const Option_t* opt) const
65{
66 // print info
68}
69
70//____________________________________________
71int AlignableDetectorTPC::processPoints(GIndex gid, int npntCut, bool inv)
72{
73 // Extract the points corresponding to this detector, recalibrate/realign them to the
74 // level of the "starting point" for the alignment/calibration session.
75 // If inv==true, the track propagates in direction of decreasing tracking X
76 // (i.e. upper leg of cosmic track)
77 //
78 const auto& algConf = AlignConfig::Instance();
79 const auto recoData = mController->getRecoContainer();
80 const auto& trk = recoData->getTrack<o2::tpc::TrackTPC>(gid);
81 gsl::span<const unsigned char> TPCShMap = recoData->clusterShMapTPC;
82
83 int nClus = trk.getNClusters();
84 if (nClus < npntCut) {
85 return -1;
86 }
87 int npointsIni = mNPoints;
88 auto prop = o2::base::Propagator::Instance(); // float version!
89 constexpr float TAN10 = 0.17632698;
90 const auto clusterIdxStruct = recoData->getTPCTracksClusterRefs();
91 const auto clusterNativeAccess = recoData->inputsTPCclusters->clusterIndex;
92 bool fail = false;
93 auto algTrack = mController->getAlgTrack();
94
95 o2::track::TrackParCov trkParam = inv ? trk : trk.getOuterParam(); // we refit outer param inward
96 trkParam.resetCovariance();
97 float bzkG = prop->getNominalBz(), qptB5Scale = std::abs(bzkG) > 0.1 ? std::abs(bzkG) / 5.006680f : 1.f;
98 float q2pt2 = trkParam.getQ2Pt() * trkParam.getQ2Pt(), q2pt2Wgh = q2pt2 * qptB5Scale * qptB5Scale;
99 float err2 = (100.f + q2pt2Wgh) / (1.f + q2pt2Wgh) * q2pt2; // -> 100 for high pTs, -> 1 for low pTs.
100 trkParam.setCov(err2, 14); // 100% error
101
102 int direction = inv ? -1 : 1;
103 int start = inv ? nClus - 1 : 0;
104 int stop = inv ? -1 : nClus;
105 const o2::tpc::ClusterNative* cl = nullptr;
106 uint8_t sector, row = 0, currentSector = 0, currentRow = 0;
107 short clusterState = 0, nextState;
109 bool stopLoop = false;
110 int npoints = 0;
111 for (int i = start; i != stop; i += cl ? 0 : direction) {
112 float x, y, z, xTmp, yTmp, zTmp, charge = 0.f;
113 int clusters = 0;
114 double combRow = 0;
115
116 while (true) {
117 if (!cl) {
118 auto clTmp = &trk.getCluster(clusterIdxStruct, i, clusterNativeAccess, sector, row);
119 if (row < algConf.minTPCPadRow) {
120 if (!inv) { // inward refit: all other clusters padrow will be <= minumum (with outward refit the following clusters have a chance to be accepted)
121 stopLoop = true;
122 }
123 break;
124 } else if (row > algConf.maxTPCPadRow) {
125 if (inv) { // outward refit: all other clusters padrow will be >= maximum (with inward refit the following clusters have a chance to be accepted)
126 stopLoop = true;
127 }
128 break;
129 }
130 if (algConf.discardEdgePadrows > 0 && getDistanceToStackEdge(row) < algConf.discardEdgePadrows) {
131 if (i + direction != stop) {
132 i += direction;
133 continue;
134 } else {
135 stopLoop = true;
136 break;
137 }
138 }
139 mController->getTPCCorrMaps()->Transform(sector, row, clTmp->getPad(), clTmp->getTime(), xTmp, yTmp, zTmp, tOffset);
140 if (algConf.discardSectorEdgeDepth > 0) {
141 if (std::abs(yTmp) + algConf.discardSectorEdgeDepth > xTmp * TAN10) {
142 if (i + direction != stop) {
143 i += direction;
144 continue;
145 } else {
146 stopLoop = true;
147 break;
148 }
149 }
150 }
151
152 cl = clTmp;
153 nextState = TPCShMap[cl - clusterNativeAccess.clustersLinear];
154 }
155 if (clusters == 0 || (sector == currentSector && std::abs(row - currentRow) < algConf.maxTPCRowsCombined)) {
156 if (clusters == 1) {
157 x *= charge;
158 y *= charge;
159 z *= charge;
160 combRow *= charge;
161 }
162 if (clusters == 0) {
163 x = xTmp;
164 y = yTmp;
165 z = zTmp;
166 // mController->getTPCCorrMaps()->Transform(sector, row, cl->getPad(), cl->getTime(), x, y, z, tOffset);
167 currentRow = row;
168 currentSector = sector;
169 charge = cl->qTot;
170 clusterState = nextState;
171 combRow = row;
172 LOGP(debug, "starting a supercluster at row {} of sector {} -> {},{},{}", currentRow, currentSector, x, y, z);
173 } else {
174 // float xx, yy, zz;
175 // mController->getTPCCorrMaps()->Transform(sector, row, cl->getPad(), cl->getTime(), xx, yy, zz, tOffset);
176 x += xTmp * cl->qTot;
177 y += yTmp * cl->qTot;
178 z += zTmp * cl->qTot;
179 combRow += row * cl->qTot;
180 charge += cl->qTot;
181 clusterState |= nextState;
182 npntCut--;
183 LOGP(debug, "merging cluster #{} at row {} to a supercluster starting at row {} ", clusters + 1, row, currentRow);
184 }
185 cl = nullptr;
186 clusters++;
187 if (i + direction != stop) {
188 i += direction;
189 continue;
190 }
191 }
192 break;
193 }
194 if (stopLoop) {
195 break;
196 }
197 if (clusters == 0) {
198 continue;
199 } else if (clusters > 1) {
200 x /= charge;
201 y /= charge;
202 z /= charge;
203 currentRow = combRow / charge;
204 LOGP(debug, "Combined cluster of {} subclusters: row {} , {},{},{}", clusters, currentRow, x, y, z);
205 }
206
207 if (!trkParam.rotate(math_utils::detail::sector2Angle<float>(currentSector)) || !prop->PropagateToXBxByBz(trkParam, x, algConf.maxSnp)) {
208 break;
209 }
210 if (!npoints) {
211 trkParam.setZ(z);
212 }
213
214 auto* sectSensor = (AlignableSensorTPC*)getSensor(currentSector);
215 const auto* sysE = sectSensor->getAddError(); // additional syst error
216
219 mController->getTPCParam()->GetClusterErrors2(sector, currentRow, z, trkParam.getSnp(), trkParam.getTgl(), -1.f, 0.f, 0.f, c[0], c[2]); // TODO: Note this disables occupancy / charge components of the error estimation
220 mController->getTPCParam()->UpdateClusterError2ByState(clusterState, c[0], c[2]);
221 int nrComb = std::abs(row - currentRow) + 1;
222 if (nrComb > 1) {
223 float fact = 1. / std::sqrt(nrComb);
224 c[0] *= fact;
225 c[2] *= fact;
226 }
227 if (sysE[0] > 0.f) {
228 c[0] += sysE[0] * sysE[0];
229 }
230 if (sysE[1] > 0.f) {
231 c[2] += sysE[1] * sysE[1];
232 }
233
234 if (!trkParam.update(p, c)) {
235 break;
236 }
237
238 auto& pnt = algTrack->addDetectorPoint();
239 pnt.setYZErrTracking(c[0], c[1], c[2]);
240 if (getUseErrorParam()) { // errors will be calculated just before using the point in the fit, using track info
241 pnt.setNeedUpdateFromTrack();
242 }
243 pnt.setXYZTracking(x, y, z);
244 pnt.setSensor(sectSensor);
245 pnt.setAlphaSens(sectSensor->getAlpTracking());
246 pnt.setXSens(sectSensor->getXTracking());
247 pnt.setDetID(mDetID);
248 pnt.setSID(sectSensor->getSID());
249 pnt.setContainsMeasurement();
250 pnt.setInvDir(inv);
251 pnt.init();
252 npoints++;
253 }
254 if (npoints < npntCut) {
255 algTrack->suppressLastPoints(npoints);
256 mNPoints = npointsIni;
257 npoints = -1;
258 }
259 mNPoints += npoints;
260
261 return npoints;
262}
263
264} // namespace align
265} // namespace o2
Configuration file for global alignment.
TPC detector wrapper.
TPC fake sensor (sector)
Base class of alignable volume.
Steering class for the global alignment.
Wrapper container for different reconstructed object types.
int16_t charge
Definition RawEventData.h:5
int32_t i
uint32_t c
Definition RawData.h:2
std::ostringstream debug
Helper class to obtain TPC clusters / digits / labels from DPL.
int getDistanceToStackEdge(int padrow) const
void Print(const Option_t *opt="") const final
int processPoints(GIndex gid, int npntCut, bool inv) final
AlignableSensor * getSensor(int id) const
virtual void addVolume(AlignableVolume *vol)
void Print(const Option_t *opt="") const override
const double * getAddError() const
void setDummyEnvelope(bool v=true)
void setParent(AlignableVolume *par)
const o2::globaltracking::RecoContainer * getRecoContainer() const
Definition Controller.h:200
AlignmentTrack * getAlgTrack() const
Definition Controller.h:198
const o2::gpu::GPUParam * getTPCParam() const
Definition Controller.h:288
o2::gpu::CorrectionMapsHelper * getTPCCorrMaps()
Definition Controller.h:276
Controller * mController
Definition DOFSet.h:73
static int getSensID(o2::detectors::DetID detid, int sensid)
GPUd() value_type estimateLTFast(o2 static GPUd() float estimateLTIncrement(const o2 PropagatorImpl * Instance(bool uninitialized=false)
Definition Propagator.h:143
Static class with identifiers, bitmasks and names for ALICE detectors.
Definition DetID.h:58
GLint GLenum GLint x
Definition glcorearb.h:403
GLint y
Definition glcorearb.h:270
GLuint start
Definition glcorearb.h:469
GLdouble GLdouble GLdouble z
Definition glcorearb.h:843
constexpr double LHCBunchSpacingMUS
std::array< T, N > array
void align(gsl::span< ElinkEncoder< BareFormat, CHARGESUM > > elinks)
constexpr int MAXSECTOR
Definition Constants.h:28
TrackParCovF TrackParCov
Definition Track.h:33
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
const U & getTrack(int src, int id) const
std::vector< Cluster > clusters
std::vector< int > row