]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/UPGRADE/AliITSUTrackerGlo.cxx
ca0421cde73e3d4442d25c3da27f38aff5aba69e
[u/mrichter/AliRoot.git] / ITS / UPGRADE / AliITSUTrackerGlo.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /*
17   TO CHECK
18   GetBz usage
19
20  */
21
22 //-------------------------------------------------------------------------
23 //  Implementation of the ITS Upgrade tracker mother class.              
24 //-------------------------------------------------------------------------
25 #include <TTree.h>
26 #include <Riostream.h> 
27 #include <TMath.h>
28
29 #include "AliITSUTrackerGlo.h"
30 #include "AliESDEvent.h"
31 #include "AliESDtrack.h"
32 #include "AliITSURecoDet.h"
33 #include "AliITSURecoSens.h"
34 #include "AliITSUReconstructor.h"
35 #include "AliITSReconstructor.h"
36 #include "AliITSUSeed.h"
37 #include "AliITSUAux.h"
38 using namespace AliITSUAux;
39 using namespace TMath;
40
41
42 ClassImp(AliITSUTrackerGlo)
43 //_________________________________________________________________________
44 AliITSUTrackerGlo::AliITSUTrackerGlo(AliITSUReconstructor* rec)
45 :  fReconstructor(rec)
46   ,fITS(0)
47   ,fCurrMass(kPionMass)
48   ,fSeedsPool("AliITSUSeed",100)
49 {
50   // Default constructor
51   if (rec) Init(rec);
52 }
53
54 //_________________________________________________________________________
55 AliITSUTrackerGlo::~AliITSUTrackerGlo()
56 {
57  // Default destructor
58  //  
59   delete fITS;
60   //
61 }
62
63 //_________________________________________________________________________
64 void AliITSUTrackerGlo::Init(AliITSUReconstructor* rec)
65 {
66   // init with external reconstructor
67   fITS = new AliITSURecoDet(rec->GetGeom(),"ITSURecoInterface");
68   for (int ilr=fITS->GetNLayersActive();ilr--;) {
69     fITS->GetLayerActive(ilr)->SetClusters(rec->GetClusters(ilr));
70   }
71 }
72
73 //_________________________________________________________________________
74 Int_t AliITSUTrackerGlo::Clusters2Tracks(AliESDEvent *esdEv)
75 {
76   //
77   //
78   fITS->ProcessClusters();
79   // select ESD tracks to propagate
80   int nTrESD = esdEv->GetNumberOfTracks();
81   for (int itr=0;itr<nTrESD;itr++) {
82     AliESDtrack *esdTr = esdEv->GetTrack(itr);
83     FindTrack(esdTr);
84   }
85
86   return 0;
87 }
88
89 //_________________________________________________________________________
90 Int_t AliITSUTrackerGlo::PropagateBack(AliESDEvent * /*event*/)
91 {
92   //
93   // To be implemented 
94   //
95   
96  Info("PropagateBack","To be implemented");
97   return 0;
98 }
99
100 //_________________________________________________________________________
101 Int_t AliITSUTrackerGlo::RefitInward(AliESDEvent * /*event*/)
102 {
103   //
104   // To be implemented 
105   //
106   
107   Info("RefitInward","To be implemented");
108   return 0;
109 }
110
111 //_________________________________________________________________________
112 Int_t AliITSUTrackerGlo::LoadClusters(TTree * treeRP)
113 {
114   // read from tree (if pointer provided) or directly from the ITS reco interface
115   //
116   return fReconstructor->LoadClusters(treeRP);
117
118
119 //_________________________________________________________________________
120 void AliITSUTrackerGlo::UnloadClusters()
121 {
122   //
123   // To be implemented 
124   //
125   
126   Info("UnloadClusters","To be implemented");
127
128 //_________________________________________________________________________
129 AliCluster * AliITSUTrackerGlo::GetCluster(Int_t /*index*/) const
130 {
131   //
132   // To be implemented 
133   //
134   
135   Info("GetCluster","To be implemented");
136   return 0x0;
137
138
139 //_________________________________________________________________________
140 Bool_t AliITSUTrackerGlo::NeedToProlong(AliESDtrack* esdTr)
141 {
142   // do we need to match this track to ITS?
143   //
144   static double bz = GetBz();
145   if (!esdTr->IsOn(AliESDtrack::kTPCin) ||
146       esdTr->IsOn(AliESDtrack::kTPCout) ||
147       esdTr->IsOn(AliESDtrack::kITSin)  ||
148       esdTr->GetKinkIndex(0)>0) return kFALSE;
149   //
150   if (esdTr->Pt()<AliITSReconstructor::GetRecoParam()->GetMinPtForProlongation()) return kFALSE;
151   //
152   float dtz[2];
153   esdTr->GetDZ(GetX(),GetY(),GetZ(),bz,dtz); 
154   // if track is not V0 candidata but has large offset wrt IP, reject it. RS TOCHECK
155   if ( !(esdTr->GetV0Index(0)>0 && dtz[0]>AliITSReconstructor::GetRecoParam()->GetMaxDforV0dghtrForProlongation()) 
156        && (Abs(dtz[0])>AliITSReconstructor::GetRecoParam()->GetMaxDForProlongation() ||
157            Abs(dtz[1])>AliITSReconstructor::GetRecoParam()->GetMaxDZForProlongation())) return kFALSE;
158   //
159   return kTRUE;
160 }
161
162 //_________________________________________________________________________
163 void AliITSUTrackerGlo::FindTrack(AliESDtrack* esdTr)
164 {
165   // find prolongaion candidates finding for single seed
166   //
167   if (!NeedToProlong(esdTr)) return;  // are we interested in this track?
168   if (!InitSeed(esdTr))         return;  // initialize prolongations hypotheses tree
169   //
170   double rwData[kNTrData];
171   AliITSURecoSens *hitSens[AliITSURecoSens::kNNeighbors];
172   AliITSUSeed seed0;
173   //
174   for (int ila=fITS->GetNLayersActive();ila--;) {
175     int ilaUp = ila+1;                         // prolong seeds from layer above
176     int nSeedsUp = GetNSeeds(ilaUp);
177     for (int isd=0;isd<nSeedsUp;isd++) {
178       seed0 = *GetSeed(ilaUp,isd);  // copy of the seed on prev.active layer
179       // go till next active layer
180       if (!TransportToLayer(&seed0, fITS->GetLrIDActive(ilaUp), fITS->GetLrIDActive(ila)) ) {
181         //
182         // Check if the seed satisfies to track definition
183         if (NeedToKill(&seed0,kTransportFailed)) KillSeed(ilaUp,isd); 
184         continue; // RS TODO: decide what to do with tracks stopped on higher layers w/o killing
185       }
186       AliITSURecoLayer* lrA = fITS->GetLayerActive(ila);
187       if (!GetRoadWidth(&seed0, ila, rwData)) { // failed to find road width on the layer
188         if (NeedToKill(&seed0,kRWCheckFailed)) KillSeed(ilaUp,isd); 
189         continue;
190       }
191       int nsens = lrA->FindSensors(&rwData[kTrPhi0], hitSens);  // find detectors which may be hit by the track (max 4)
192       //
193       for (int isn=nsens;isn--;) {
194
195
196       }
197       
198     }
199   }
200   //
201 }
202
203 //_________________________________________________________________________
204 Bool_t AliITSUTrackerGlo::InitSeed(AliESDtrack *esdTr)
205 {
206   // int prolongaion candidates finding for single seed
207   fCurrMass = esdTr->GetMass();
208   if (fCurrMass<kPionMass*0.9) fCurrMass = kPionMass; // don't trust to mu, e identification from TPCin
209  
210   return kTRUE;
211   // TO DO
212 }
213
214 //_________________________________________________________________________
215 Bool_t AliITSUTrackerGlo::TransportToLayer(AliITSUSeed* seed, Int_t lFrom, Int_t lTo)
216 {
217   // transport seed from layerFrom to the entrance of layerTo
218   //  
219   const double kToler = 1e-6; // tolerance for layer on-surface check
220   //
221   int dir = lTo > lFrom ? 1:-1;
222   AliITSURecoLayer* lrFr = fITS->GetLayer(lFrom); // this can be 0 when extrapolation from TPC to ITS is requested
223   Bool_t checkFirst = kTRUE;
224   while(lFrom!=lTo) {
225     double curR2 = seed->GetX()*seed->GetX() + seed->GetY()*seed->GetY(); // current radius
226     if (lrFr) {
227       Bool_t doLayer = kTRUE;
228       double xToGo = dir>0 ? lrFr->GetRMax() : lrFr->GetRMin();
229       if (checkFirst) { // do we need to track till the surface of the current layer ?
230         checkFirst = kFALSE;
231         if      (dir>0) { if (curR2-xToGo*xToGo>kToler) doLayer = kFALSE; } // on the surface or outside of the layer
232         else if (dir<0) { if (xToGo*xToGo-curR2>kToler) doLayer = kFALSE; } // on the surface or outside of the layer
233       }
234       if (doLayer) {
235         if (!seed->GetXatLabR(xToGo,xToGo,GetBz(),dir)) return kFALSE;
236         // go via layer to its boundary, applying material correction.
237         if (!PropagateTrackTo(seed,xToGo,fCurrMass, lrFr->GetMaxStep(), kFALSE, -1, 0, kTRUE)) return kFALSE;
238       }
239     }
240     AliITSURecoLayer* lrTo =  fITS->GetLayer( (lFrom+=dir) );
241     if (!lrTo) AliFatal(Form("Layer %d does not exist",lFrom));
242     //
243     // go the entrance of the layer, assuming no materials in between
244     double xToGo = dir>0 ? lrTo->GetRMin() : lrTo->GetRMax();
245     if (seed->GetXatLabR(xToGo,xToGo,GetBz(),dir)) return kFALSE;
246     if (!seed->PropagateTo(xToGo, GetBz())) return kFALSE; // RS: do we need BxByBz?
247     lrFr = lrTo;
248   }
249   return kTRUE;
250   //
251 }
252
253 //_________________________________________________________________________
254 Bool_t AliITSUTrackerGlo::GetRoadWidth(AliITSUSeed* seed, int ilrA, double* rwData)
255 {
256   // calculate road width in terms of phi and z for the track which MUST be on the external radius of the layer
257   // as well as some aux info
258   double bz = GetBz();
259   AliITSURecoLayer* lrA = fITS->GetLayerActive(ilrA);
260   seed->GetXYZ(&rwData[kTrXIn]);    // lab position at the entrance from above
261   //
262   rwData[kTrPhiIn] = ATan2(rwData[kTrYIn],rwData[kTrXIn]);
263   if (!seed->Rotate(rwData[kTrPhiIn])) return kFALSE; // go to the frame of the entry point into the layer
264   double dr  = lrA->GetDR();                          // approximate X dist at the inner radius
265   if (!seed->GetXYZAt(seed->GetX()-dr, bz, rwData + kTrXOut)) {
266     // special case: track does not reach inner radius, might be tangential
267     double r = seed->GetD(0,0,bz);
268     double x;
269     if (!seed->GetXatLabR(r,x,bz,-1)) {
270       AliError(Form("This should not happen: r=%f",r));
271       seed->Print();
272       return kFALSE;
273     }
274     dr = Abs(seed->GetX() - x);
275     if (!seed->GetXYZAt(x, bz, rwData + kTrXOut)) {
276       AliError(Form("This should not happen: x=%f",x));
277       seed->Print();
278       return kFALSE;      
279     }
280   }
281   //
282   rwData[kTrPhiOut] = ATan2(rwData[kTrYOut],rwData[kTrXOut]);
283   double sgy = seed->GetSigmaY2() + dr*seed->GetSigmaSnp2() + AliITSReconstructor::GetRecoParam()->GetSigmaY2(ilrA);
284   double sgz = seed->GetSigmaZ2() + dr*seed->GetSigmaTgl2() + AliITSReconstructor::GetRecoParam()->GetSigmaZ2(ilrA);
285   sgy = Sqrt(sgy)*AliITSReconstructor::GetRecoParam()->GetNSigmaRoadY();
286   sgz = Sqrt(sgz)*AliITSReconstructor::GetRecoParam()->GetNSigmaRoadZ();
287   rwData[kTrPhi0] = 0.5*(rwData[kTrPhiOut]+rwData[kTrPhiIn]);
288   rwData[kTrZ0]   = 0.5*(rwData[kTrZOut]+rwData[kTrPhiIn]);
289   rwData[kTrDPhi] = 0.5*Abs(rwData[kTrPhiOut]-rwData[kTrPhiIn]) + sgy/lrA->GetR();
290   rwData[kTrDZ]   = 0.5*Abs(rwData[kTrZOut]-rwData[kTrPhiIn])   + sgz;
291   //  
292   return kTRUE;
293 }
294
295 //_________________________________________________________________________
296 AliITSUSeed* AliITSUTrackerGlo::NewSeed(const AliITSUSeed* src)
297 {
298   // create new seed, optionally copying from the source
299   return src ? 
300     new(fSeedsPool[fSeedsPool.GetEntriesFast()]) AliITSUSeed(*src) :
301     new(fSeedsPool[fSeedsPool.GetEntriesFast()]) AliITSUSeed();
302 }