]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/tracking-ca/AliTPCtrackerCA.cxx
added offline wrapper for HLT TPC CA tracker (Sergey)
[u/mrichter/AliRoot.git] / HLT / TPCLib / tracking-ca / AliTPCtrackerCA.cxx
1 // $Id$
2 //***************************************************************************
3 // This file is property of and copyright by the ALICE HLT Project          * 
4 // ALICE Experiment at CERN, All rights reserved.                           *
5 //                                                                          *
6 // Primary Authors: Sergey Gorbunov <sergey.gorbunov@kip.uni-heidelberg.de> *
7 //                  Ivan Kisel <kisel@kip.uni-heidelberg.de>                *
8 //                  for The ALICE HLT Project.                              *
9 //                                                                          *
10 // Permission to use, copy, modify and distribute this software and its     *
11 // documentation strictly for non-commercial purposes is hereby granted     *
12 // without fee, provided that the above copyright notice appears in all     *
13 // copies and that both the copyright notice and this permission notice     *
14 // appear in the supporting documentation. The authors make no claims       *
15 // about the suitability of this software for any purpose. It is            *
16 // provided "as is" without express or implied warranty.                    *
17 //***************************************************************************
18
19 #include "AliTPCtrackerCA.h"
20
21 #include <TTree.h>
22 #include <Riostream.h>
23 #include "AliCluster.h"
24 #include "AliTPCClustersRow.h"
25 #include "AliTPCParam.h"
26 #include "AliRun.h"
27 #include "AliRunLoader.h"
28 #include "AliStack.h"
29
30 #include "AliHLTTPCCATracker.h"
31 #include "AliHLTTPCCAGBHit.h"
32 #include "AliHLTTPCCAGBTracker.h"
33 #include "AliHLTTPCCAGBTrack.h"
34 #include "AliHLTTPCCAMCTrack.h"
35 #include "AliHLTTPCCAOutTrack.h"
36 #include "AliHLTTPCCAPerformance.h"
37 #include "AliHLTTPCCAParam.h"
38
39 #include "TMath.h"
40 #include "AliTPCLoader.h"
41 #include "AliTPC.h"
42 #include "AliTPCclusterMI.h"
43 #include "AliTPCTransform.h"
44 #include "AliTPCcalibDB.h"
45 #include "AliTPCReconstructor.h"
46 #include "AliTPCtrack.h"
47 #include "AliESDtrack.h"
48 #include "AliESDEvent.h"
49
50
51 ClassImp(AliTPCtrackerCA)
52
53 AliTPCtrackerCA::AliTPCtrackerCA()
54   :AliTracker(),fParam(0), fClusters(0), fNClusters(0), fHLTTracker(0),fHLTPerformance(0),fDoHLTPerformance(0)
55 {
56   //* default constructor
57 }
58
59 AliTPCtrackerCA::AliTPCtrackerCA(const AliTPCtrackerCA &):
60   AliTracker(),fParam(0), fClusters(0), fNClusters(0), fHLTTracker(0),fHLTPerformance(0),fDoHLTPerformance(0)
61 {
62   //* dummy
63 }
64
65 AliTPCtrackerCA & AliTPCtrackerCA::operator=(const AliTPCtrackerCA& )
66 {
67   //* dummy 
68   return *this;
69 }
70
71
72 AliTPCtrackerCA::~AliTPCtrackerCA() 
73 {
74   //* destructor
75   if( fClusters ) delete[] fClusters;
76   if( fHLTTracker ) delete fHLTTracker;
77   if( fHLTPerformance ) delete fHLTPerformance;
78 }
79
80 AliTPCtrackerCA::AliTPCtrackerCA(const AliTPCParam *par): 
81   AliTracker(),fParam(par), fClusters(0), fNClusters(0), fHLTTracker(0), fHLTPerformance(0),fDoHLTPerformance(0)
82 {
83   //* constructor
84
85   DoHLTPerformance() = 0;
86
87   fHLTTracker = new AliHLTTPCCAGBTracker;
88   fHLTTracker->SetNSlices( fParam->GetNSector()/2 );
89
90   if( fDoHLTPerformance ){
91     fHLTPerformance = new AliHLTTPCCAPerformance;
92     fHLTPerformance->SetTracker( fHLTTracker );
93   }
94
95   for( int iSlice=0; iSlice<fHLTTracker->NSlices(); iSlice++ ){
96   
97     Double_t bz = AliTracker::GetBz();
98
99     Double_t inRmin = fParam->GetInnerRadiusLow();
100     //Double_t inRmax = fParam->GetInnerRadiusUp();
101     //Double_t outRmin = fParam->GetOuterRadiusLow(); 
102     Double_t outRmax = fParam->GetOuterRadiusUp();
103     Double_t plusZmin = 0.0529937; 
104     Double_t plusZmax = 249.778; 
105     Double_t minusZmin = -249.645; 
106     Double_t minusZmax = -0.0799937; 
107     Double_t dalpha = 0.349066;
108     Double_t alpha = 0.174533 + dalpha*iSlice;
109     
110     Bool_t zPlus = (iSlice<18 );
111     Double_t zMin =  zPlus ?plusZmin :minusZmin;
112     Double_t zMax =  zPlus ?plusZmax :minusZmax;
113     //TPCZmin = -249.645, ZMax = 249.778    
114     //Double_t rMin =  inRmin;
115     //Double_t rMax =  outRmax;
116         
117     Double_t padPitch = 0.4;
118     Double_t sigmaZ = 0.228808;
119
120     Int_t NRows = fParam->GetNRowLow()+fParam->GetNRowUp();
121
122     Double_t rowX[200];
123     for( Int_t irow=0; irow<fParam->GetNRowLow(); irow++){
124       rowX[irow] = fParam->GetPadRowRadiiLow(irow);
125     }     
126     for( Int_t irow=0; irow<fParam->GetNRowUp(); irow++){
127       rowX[fParam->GetNRowLow()+irow] = fParam->GetPadRowRadiiUp(irow);
128     }      
129     AliHLTTPCCAParam param;
130     param.Initialize( iSlice, NRows, rowX, alpha, dalpha,
131                       inRmin, outRmax, zMin, zMax, padPitch, sigmaZ, bz );
132     param.YErrorCorrection() = .33;//1;
133     param.ZErrorCorrection() = .33;//2;
134     param.MaxTrackMatchDRow() = 5;
135     param.TrackConnectionFactor() = 5.;
136     fHLTTracker->Slices()[iSlice].Initialize( param ); 
137   }
138 }
139
140
141
142 Int_t AliTPCtrackerCA::LoadClusters (TTree * tree)
143
144   fNClusters = 0;
145   if( fClusters ) delete[] fClusters;
146
147   fHLTTracker->StartEvent();
148   if( fDoHLTPerformance ) fHLTPerformance->StartEvent();
149
150   if( !fParam ) return 1;
151
152   // load mc tracks
153   if( fDoHLTPerformance ){
154     if( !gAlice ) return 0;
155     AliRunLoader *rl = gAlice->GetRunLoader(); 
156     if( !rl ) return 0;
157     rl->LoadKinematics();
158     AliStack *stack = rl->Stack();
159     if( !stack ) return 0 ;
160
161     fHLTPerformance->SetNMCTracks( stack->GetNtrack() );
162     
163     for( Int_t itr=0; itr<stack->GetNtrack(); itr++ ){
164       TParticle *part = stack->Particle(itr);
165       fHLTPerformance->ReadMCTrack( itr, part );
166     }
167   }   
168   
169   TBranch * br = tree->GetBranch("Segment");
170   if( !br ) return 1;
171
172   AliTPCClustersRow *clrow = new AliTPCClustersRow;
173   clrow->SetClass("AliTPCclusterMI");
174   clrow->SetArray(0);
175   clrow->GetArray()->ExpandCreateFast(10000);
176   
177   br->SetAddress(&clrow);
178   
179   //
180   Int_t NEnt=Int_t(tree->GetEntries());
181
182   fNClusters = 0;
183   for (Int_t i=0; i<NEnt; i++) {
184     br->GetEntry(i);
185     Int_t sec,row;
186     fParam->AdjustSectorRow(clrow->GetID(),sec,row);
187     fNClusters += clrow->GetArray()->GetEntriesFast();
188   }
189
190   fClusters = new AliTPCclusterMI [fNClusters];
191   fHLTTracker->SetNHits( fNClusters );
192   if( fDoHLTPerformance ) fHLTPerformance->SetNHits( fNClusters );
193   int ind=0;
194   for (Int_t i=0; i<NEnt; i++) {
195     br->GetEntry(i);
196     Int_t sec,row;
197     fParam->AdjustSectorRow(clrow->GetID(),sec,row);
198     int NClu = clrow->GetArray()->GetEntriesFast();
199     Double_t x = fParam->GetPadRowRadii(sec,row);
200     for (Int_t icl=0; icl<NClu; icl++){
201       Int_t lab0 = -1;
202       Int_t lab1 = -1;
203       Int_t lab2 = -1;
204       AliTPCclusterMI* cluster = (AliTPCclusterMI*)(clrow->GetArray()->At(icl));
205       if( !cluster ) continue;
206       lab0 = cluster->GetLabel(0);
207       lab1 = cluster->GetLabel(1);
208       lab2 = cluster->GetLabel(2);
209
210       AliTPCTransform *transform = AliTPCcalibDB::Instance()->GetTransform() ;
211       if (!transform) {
212         AliFatal("Tranformations not in calibDB");
213       }
214       Double_t xx[3]={cluster->GetRow(),cluster->GetPad(),cluster->GetTimeBin()};
215       Int_t id[1]={cluster->GetDetector()};
216       transform->Transform(xx,id,0,1);  
217       //if (!AliTPCReconstructor::GetRecoParam()->GetBYMirror()){
218       if (cluster->GetDetector()%36>17){
219         xx[1]*=-1;
220       }
221       //}
222
223       cluster->SetX(xx[0]);
224       cluster->SetY(xx[1]);
225       cluster->SetZ(xx[2]);
226
227       TGeoHMatrix  *mat = fParam->GetClusterMatrix(cluster->GetDetector());
228       Double_t pos[3]= {cluster->GetX(),cluster->GetY(),cluster->GetZ()};
229       Double_t posC[3]={cluster->GetX(),cluster->GetY(),cluster->GetZ()};
230       if (mat) mat->LocalToMaster(pos,posC);
231       else{
232         // chack Loading of Geo matrices from GeoManager - TEMPORARY FIX
233       }
234       cluster->SetX(posC[0]);
235       cluster->SetY(posC[1]);
236       cluster->SetZ(posC[2]);
237
238       Double_t y = cluster->GetY();
239       Double_t z = cluster->GetZ();        
240
241       if( sec>=36 ){
242         sec = sec - 36;
243         row = row + fParam->GetNRowLow(); 
244       }
245       
246       Int_t index = ind++;
247       fClusters[index] = *cluster;
248       fHLTTracker->ReadHit( x, y, z, 
249                             TMath::Sqrt(cluster->GetSigmaY2()), TMath::Sqrt(cluster->GetSigmaZ2()), 
250                             index, sec, row );
251       if( fDoHLTPerformance ) fHLTPerformance->ReadHitLabel(index, lab0, lab1, lab2 );
252     }
253   }
254   delete clrow;
255   return 0;
256 }
257
258 AliCluster * AliTPCtrackerCA::GetCluster(Int_t index) const
259 {
260   return &(fClusters[index]);
261 }
262
263 Int_t AliTPCtrackerCA::Clusters2Tracks( AliESDEvent *event )
264 {
265   //cout<<"Start of AliTPCtrackerCA"<<endl;
266
267   fHLTTracker->FindTracks();
268   if( fDoHLTPerformance ) fHLTPerformance->Performance();
269
270   if( event ){
271    
272     for( Int_t itr=0; itr<fHLTTracker->NTracks(); itr++ ){
273       AliTPCtrack tTPC;
274       AliHLTTPCCAGBTrack &tCA = fHLTTracker->Tracks()[itr];
275       AliHLTTPCCATrackParam &par = tCA.Param(); 
276
277       par.GetExtParam( tTPC, tCA.Alpha(), fHLTTracker->Slices()[0].Param().Bz() );
278       
279       tTPC.SetMass(0.13957);
280       int nhits = tCA.NHits();
281       if( nhits>kMaxRow ) nhits = kMaxRow;
282       tTPC.SetNumberOfClusters(nhits);
283       for( Int_t ih=0; ih<nhits; ih++ ){
284         Int_t index = fHLTTracker->TrackHits()[tCA.FirstHitRef()+ih];
285         Int_t ext_index = fHLTTracker->Hits()[index].ID();
286         tTPC.SetClusterIndex(ih, ext_index);
287       }
288       CookLabel(&tTPC,0.1);     
289       {
290         Double_t xTPC=83.65;
291         if (tTPC.AliExternalTrackParam::PropagateTo(xTPC,5)) {    
292           Double_t y=tTPC.GetY();
293           Double_t ymax=xTPC*TMath::Tan(1.74532920122146606e-01); 
294           if (y > ymax) {
295             if (tTPC.Rotate(2*1.74532920122146606e-01)) tTPC.AliExternalTrackParam::PropagateTo(xTPC,5);
296           } else if (y <-ymax) {
297             if (tTPC.Rotate(-2*1.74532920122146606e-01)) tTPC.AliExternalTrackParam::PropagateTo(xTPC,5);
298           }         
299         }
300       }
301
302       AliESDtrack tESD;
303       tESD.UpdateTrackParams( &(tTPC),AliESDtrack::kTPCin);
304       //tESD.SetStatus( AliESDtrack::kTPCrefit );
305       //tESD.SetTPCPoints(tTPC.GetPoints());
306       //tESD.myTPC = tTPC;
307       event->AddTrack(&tESD);
308     }
309   }
310
311   //cout<<"End of AliTPCtrackerCA"<<endl;
312   return 0;
313 }
314
315
316 Int_t AliTPCtrackerCA::RefitInward (AliESDEvent *)
317
318   //* not implemented yet
319   return 0; 
320 }
321
322 Int_t AliTPCtrackerCA::PropagateBack(AliESDEvent *)
323
324   //* not implemented yet
325   return 0; 
326 }