]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TPC/Upgrade/AliToyMCReconstruction.cxx
added track ID also for the tracks from ESD input
[u/mrichter/AliRoot.git] / TPC / Upgrade / AliToyMCReconstruction.cxx
CommitLineData
d1cf83f5 1
2#include <TDatabasePDG.h>
3#include <TString.h>
4
5
6#include <AliExternalTrackParam.h>
7#include <AliTPCcalibDB.h>
8#include <AliTPCclusterMI.h>
9#include <AliTPCSpaceCharge3D.h>
10#include <AliTrackerBase.h>
11#include <AliTrackPointArray.h>
12#include <AliLog.h>
13#include <AliTPCParam.h>
14#include <AliTPCROC.h>
15#include <TTreeStream.h>
16
17#include "AliToyMCTrack.h"
18
19#include "AliToyMCReconstruction.h"
20
21
22//____________________________________________________________________________________
23AliToyMCReconstruction::AliToyMCReconstruction() : TObject()
24, fSeedingRow(140)
25, fSeedingDist(10)
26, fClusterType(0)
27, fCorrectionType(kNoCorrection)
28, fDoTrackFit(kTRUE)
29, fUseMaterial(kFALSE)
30, fTime0(-1)
31, fStreamer(0x0)
32, fTree(0x0)
33, fTPCParam(0x0)
34, fSpaceCharge(0x0)
35{
36 //
37 // ctor
38 //
39 fTPCParam=AliTPCcalibDB::Instance()->GetParameters();
40}
41
42//____________________________________________________________________________________
43AliToyMCReconstruction::~AliToyMCReconstruction()
44{
45 //
46 // dtor
47 //
48
49 delete fStreamer;
50 delete fTree;
51}
52
53//____________________________________________________________________________________
54AliExternalTrackParam* AliToyMCReconstruction::GetSeedFromTrack(const AliToyMCTrack * const tr)
55{
56 //
57 // if we don't have a valid time0 informaion (fTime0) available yet
58 // assume we create a seed for the time0 estimate
59 //
60
61 // seed point informaion
62 AliTrackPoint seedPoint[3];
63 const AliTPCclusterMI *seedCluster[3]={0x0,0x0,0x0};
64
65 // number of clusters to loop over
66 const Int_t ncls=(fClusterType==0)?tr->GetNumberOfSpacePoints():tr->GetNumberOfDistSpacePoints();
67
68 UChar_t nextSeedRow=fSeedingRow;
69 Int_t nseeds=0;
70
71 //assumes sorted clusters
72 for (Int_t icl=0;icl<ncls;++icl) {
73 const AliTPCclusterMI *cl=tr->GetSpacePoint(icl);
74 if (fClusterType==1) cl=tr->GetDistortedSpacePoint(icl);
75 if (!cl) continue;
76 // use row in sector
77 const UChar_t row=cl->GetRow() + 63*(cl->GetDetector()>35);
78 // skip clusters without proper pad row
79 if (row>200) continue;
80
81 //check seeding row
82 // if we are in the last row and still miss a seed we use the last row
83 // even if the row spacing will not be equal
84 if (row>=nextSeedRow || icl==ncls-1){
85 seedCluster[nseeds]=cl;
86 SetTrackPointFromCluster(cl, seedPoint[nseeds]);
87 ++nseeds;
88 nextSeedRow+=fSeedingDist;
89
90 if (nseeds==3) break;
91 }
92 }
93
94 // check we really have 3 seeds
95 if (nseeds!=3) {
96 AliError(Form("Seeding failed for parameters %d, %d\n",fSeedingDist,fSeedingRow));
97 return 0x0;
98 }
99
100 // do cluster correction for fCorrectionType:
101 // 0 - no correction
102 // 1 - TPC center
103 // 2 - average eta
104 // 3 - ideal
105 // assign the cluster abs time as z component to all seeds
106 for (Int_t iseed=0; iseed<3; ++iseed) {
107 Float_t xyz[3]={0,0,0};
108 seedPoint[iseed].GetXYZ(xyz);
109 Float_t r=TMath::Sqrt(xyz[0]*xyz[0]+xyz[1]*xyz[1]);
110
111 Int_t sector=seedCluster[iseed]->GetDetector();
112 Int_t sign=1-2*((sector/18)%2);
113
114 if ( (fClusterType == 1) && (fCorrectionType != kNoCorrection) ) {
115 if ( fCorrectionType == kTPCCenter ) xyz[2] = 125.*sign;
116 //!!! TODO: is this the correct association?
117 if ( fCorrectionType == kAverageEta ) xyz[2] = TMath::Tan(45./2.*TMath::DegToRad())*r*sign;
118 if ( fCorrectionType == kIdeal ) xyz[2] = seedCluster[iseed]->GetZ();
119
120 //!!! TODO: to be replaced with the proper correction
121 fSpaceCharge->CorrectPoint(xyz, seedCluster[iseed]->GetDetector());
122 }
123
124 // after the correction set the time bin as z-Position
125 xyz[2]=seedCluster[iseed]->GetTimeBin();
126
127 seedPoint[iseed].SetXYZ(xyz);
128 }
129
130 const Double_t kMaxSnp = 0.85;
131 const Double_t kMass = TDatabasePDG::Instance()->GetParticle("pi+")->Mass();
132
133 AliExternalTrackParam *seed = AliTrackerBase::MakeSeed(seedPoint[0], seedPoint[1], seedPoint[2]);
134 seed->ResetCovariance(10);
135
136 if (fTime0<0){
137 // if fTime0 < 0 we assume that we create a seed for the T0 estimate
138 AliTrackerBase::PropagateTrackTo(seed,0,kMass,5,kTRUE,kMaxSnp,0,kFALSE,kFALSE);
139 if (TMath::Abs(seed->GetX())>3) {
140 printf("Could not propagate track to 0, %.2f, %.2f, %.2f\n",seed->GetX(),seed->GetAlpha(),seed->Pt());
141 }
142 }
143
144 return seed;
145
146}
147
148//____________________________________________________________________________________
149void AliToyMCReconstruction::SetTrackPointFromCluster(const AliTPCclusterMI *cl, AliTrackPoint &p )
150{
151 //
152 // make AliTrackPoint out of AliTPCclusterMI
153 //
154
155 if (!cl) return;
156 // Float_t xyz[3]={0.,0.,0.};
157 // ClusterToSpacePoint(cl,xyz);
158 // cl->GetGlobalCov(cov);
159 //TODO: what to do with the covariance matrix???
160 //TODO: the problem is that it is used in GetAngle in AliTrackPoint
161 //TODO: which is used by AliTrackerBase::MakeSeed to get alpha correct ...
162 //TODO: for the moment simply assign 1 permill squared
163 // in AliTrackPoint the cov is xx, xy, xz, yy, yz, zz
164 // Float_t cov[6]={xyz[0]*xyz[0]*1e-6,xyz[0]*xyz[1]*1e-6,xyz[0]*xyz[2]*1e-6,
165 // xyz[1]*xyz[1]*1e-6,xyz[1]*xyz[2]*1e-6,xyz[2]*xyz[2]*1e-6};
166 // cl->GetGlobalXYZ(xyz);
167 // cl->GetGlobalCov(cov);
168 // voluem ID to add later ....
169 // p.SetXYZ(xyz);
170 // p.SetCov(cov);
171 AliTrackPoint *tp=const_cast<AliTPCclusterMI*>(cl)->MakePoint();
172 p=*tp;
173 delete tp;
174 // cl->Print();
175 // p.Print();
176 p.SetVolumeID(cl->GetDetector());
177 // p.Rotate(p.GetAngle()).Print();
178}
179
180//____________________________________________________________________________________
181void AliToyMCReconstruction::ClusterToSpacePoint(const AliTPCclusterMI *cl, Float_t xyz[3])
182{
183 //
184 // convert the cluster to a space point in global coordinates
185 //
186 if (!cl) return;
187 xyz[0]=cl->GetRow();
188 xyz[1]=cl->GetPad();
189 xyz[2]=cl->GetTimeBin(); // this will not be correct at all
190 Int_t i[3]={0,cl->GetDetector(),cl->GetRow()};
191 // printf("%.2f, %.2f, %.2f - %d, %d, %d\n",xyz[0],xyz[1],xyz[2],i[0],i[1],i[2]);
192 fTPCParam->Transform8to4(xyz,i);
193 // printf("%.2f, %.2f, %.2f - %d, %d, %d\n",xyz[0],xyz[1],xyz[2],i[0],i[1],i[2]);
194 fTPCParam->Transform4to3(xyz,i);
195 // printf("%.2f, %.2f, %.2f - %d, %d, %d\n",xyz[0],xyz[1],xyz[2],i[0],i[1],i[2]);
196 fTPCParam->Transform2to1(xyz,i);
197 // printf("%.2f, %.2f, %.2f - %d, %d, %d\n",xyz[0],xyz[1],xyz[2],i[0],i[1],i[2]);
198}
199
200//____________________________________________________________________________________
201AliExternalTrackParam* AliToyMCReconstruction::GetFittedTrackFromSeed(const AliToyMCTrack *tr, const AliExternalTrackParam *seed)
202{
203 //
204 //
205 //
206
207 // create track
208 AliExternalTrackParam *track = new AliExternalTrackParam(*seed);
209
210 Int_t ncls=(fClusterType == 0)?tr->GetNumberOfSpacePoints():tr->GetNumberOfDistSpacePoints();
211
212 const AliTPCROC * roc = AliTPCROC::Instance();
213
214 const Double_t kRTPC0 = roc->GetPadRowRadii(0,0);
215 const Double_t kRTPC1 = roc->GetPadRowRadii(36,roc->GetNRows(36)-1);
216 const Double_t kMaxSnp = 0.85;
217 const Double_t kMaxR = 500.;
218 const Double_t kMaxZ = 500.;
219
220 // const Double_t kMaxZ0=220;
221// const Double_t kZcut=3;
222
223 const Double_t refX = tr->GetX();
224
225 const Double_t kMass = TDatabasePDG::Instance()->GetParticle("pi+")->Mass();
226
227 // loop over all other points and add to the track
228 for (Int_t ipoint=ncls; ipoint>=0; --ipoint){
229 AliTrackPoint pIn;
230 const AliTPCclusterMI *cl=tr->GetSpacePoint(ipoint);
231 if (fClusterType == 1) cl=tr->GetDistortedSpacePoint(ipoint);
232 SetTrackPointFromCluster(cl, pIn);
233 if (fCorrectionType != kNoCorrection){
234 Float_t xyz[3]={0,0,0};
235 pIn.GetXYZ(xyz);
236 fSpaceCharge->CorrectPoint(xyz, cl->GetDetector());
237 pIn.SetXYZ(xyz);
238 }
239 // rotate the cluster to the local detector frame
240 track->Rotate(((cl->GetDetector()%18)*20+10)*TMath::DegToRad());
241 AliTrackPoint prot = pIn.Rotate(track->GetAlpha()); // rotate to the local frame - non distoted point
242 if (TMath::Abs(prot.GetX())<kRTPC0) continue;
243 if (TMath::Abs(prot.GetX())>kRTPC1) continue;
244 //
245 Bool_t res=kTRUE;
246 if (fUseMaterial) res=AliTrackerBase::PropagateTrackTo(track,prot.GetX(),kMass,5,kFALSE,kMaxSnp);
247 else res=AliTrackerBase::PropagateTrackTo(track,prot.GetX(),kMass,5,kFALSE,kMaxSnp,0,kFALSE,kFALSE);
248
249 if (!res) break;
250
251 if (TMath::Abs(track->GetZ())>kMaxZ) break;
252 if (TMath::Abs(track->GetX())>kMaxR) break;
253// if (TMath::Abs(track->GetZ())<kZcut)continue;
254 //
255 Double_t pointPos[2]={0,0};
256 Double_t pointCov[3]={0,0,0};
257 pointPos[0]=prot.GetY();//local y
258 pointPos[1]=prot.GetZ();//local z
259 pointCov[0]=prot.GetCov()[3];//simay^2
260 pointCov[1]=prot.GetCov()[4];//sigmayz
261 pointCov[2]=prot.GetCov()[5];//sigmaz^2
262
263 if (!track->Update(pointPos,pointCov)) {printf("no update\n"); break;}
264 }
265
266 if (fUseMaterial) AliTrackerBase::PropagateTrackTo2(track,refX,kMass,5.,kTRUE,kMaxSnp);
267 else AliTrackerBase::PropagateTrackTo2(track,refX,kMass,5.,kTRUE,kMaxSnp,0,kFALSE,kFALSE);
268
269 // rotate fittet track to the frame of the original track and propagate to same reference
270 track->Rotate(tr->GetAlpha());
271
272 if (fUseMaterial) AliTrackerBase::PropagateTrackTo2(track,refX,kMass,1.,kFALSE,kMaxSnp);
273 else AliTrackerBase::PropagateTrackTo2(track,refX,kMass,1.,kFALSE,kMaxSnp,0,kFALSE,kFALSE);
274
275 return track;
276}
277
278//____________________________________________________________________________________
279void AliToyMCReconstruction::InitSpaceCharge()
280{
281 //
282 // Init the space charge map
283 //
284
285 TString filename="$ALICE_ROOT/TPC/Calib/maps/SC_NeCO2_eps5_50kHz_precal.root";
286 if (fTree) {
287 TList *l=fTree->GetUserInfo();
288 for (Int_t i=0; i<l->GetEntries(); ++i) {
289 TString s(l->At(i)->GetName());
290 if (s.Contains("SC_")) {
291 filename=s;
292 break;
293 }
294 }
295 }
296
297 printf("Initialising the space charge map using the file: '%s'\n",filename.Data());
298 TFile f(filename.Data());
299 fSpaceCharge=(AliTPCSpaceCharge3D*)f.Get("map");
300
301 // fSpaceCharge = new AliTPCSpaceCharge3D();
302 // fSpaceCharge->SetSCDataFileName("$ALICE_ROOT/TPC/Calib/maps/SC_NeCO2_eps10_50kHz.root");
303 // fSpaceCharge->SetOmegaTauT1T2(0.325,1,1); // Ne CO2
304 // // fSpaceCharge->SetOmegaTauT1T2(0.41,1,1.05); // Ar CO2
305 // fSpaceCharge->InitSpaceCharge3DDistortion();
306
307}
308
309//____________________________________________________________________________________
310Double_t AliToyMCReconstruction::GetVDrift() const
311{
312 //
313 //
314 //
315 return fTPCParam->GetDriftV();
316}
317
318//____________________________________________________________________________________
319Double_t AliToyMCReconstruction::GetZLength(Int_t roc) const
320{
321 //
322 //
323 //
324 if (roc<0 || roc>71) return -1;
325 return fTPCParam->GetZLength(roc);
326}
327
328