]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/TPCbase/AliTPCLaserTrack.cxx
fix the double free in TPC (online) calibration
[u/mrichter/AliRoot.git] / TPC / TPCbase / AliTPCLaserTrack.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 //                                                                        //
18 // Surveyed Laser Track positions                                         //
19 // the position and direction information are stored in                   //
20 // the AliExternalTrackParam base class                                   //
21 // This class extends this information by identification parameters       //
22 /*
23
24 //Dump positions to a tree:
25 AliTPCLaserTrack::LoadTracks();
26 TObjArray *arr=AliTPCLaserTrack::GetTracks();
27 TTreeSRedirector *s=new TTreeSRedirector("LaserTracks.root");
28 TIter next(arr);
29 TObject *o=0x0;
30 while ( (o=next()) ) (*s) << "tracks" << "l.=" << o << "\n";
31 delete s;
32
33 //draw something
34 TFile f("LaserTracks.root");
35 TTree *tracks=(TTree*)f.Get("tracks");
36 tracks->Draw("fVecGY.fElements:fVecGX.fElements");
37
38  tracks->Draw("fVecGY.fElements:fVecGX.fElements>>h(500,-250,250,500,-250,250)","fId<7")
39 */
40 //                                                                        //
41 ////////////////////////////////////////////////////////////////////////////
42
43
44 #include <TObjArray.h>
45 #include <TFile.h>
46 #include <TString.h>
47 #include <TSystem.h>
48
49 #include "AliLog.h"
50 #include "AliCDBManager.h"
51 #include "AliCDBEntry.h"
52 #include "AliCDBPath.h"
53 #include "AliTPCLaserTrack.h"
54 #include "AliTPCROC.h"
55
56 ClassImp(AliTPCLaserTrack)
57
58 TObjArray *AliTPCLaserTrack::fgArrLaserTracks=0x0;
59
60 AliTPCLaserTrack::AliTPCLaserTrack() :
61   AliExternalTrackParam(),
62   fId(-1),
63   fSide(-1),
64   fRod(-1),
65   fBundle(-1),
66   fBeam(-1),
67   fRayLength(0),
68   fVecSec(0),       // points vectors - sector
69   fVecP2(0),       // points vectors - snp
70   fVecPhi(0),       // points vectors - global phi
71   fVecGX(0),       // points vectors - globalX
72   fVecGY(0),       // points vectors - globalY
73   fVecGZ(0),       // points vectors - globalZ
74   fVecLX(0),       // points vectors - localX
75   fVecLY(0),       // points vectors - localY
76   fVecLZ(0)        // points vectors - localZ
77 {
78   //
79 //   // Default constructor
80   //
81
82 }
83
84 AliTPCLaserTrack::AliTPCLaserTrack(const AliTPCLaserTrack &ltr) :
85   AliExternalTrackParam(ltr),
86   fId(ltr.fId),
87   fSide(ltr.fSide),
88   fRod(ltr.fRod),
89   fBundle(ltr.fBundle),
90   fBeam(ltr.fBeam),
91   fRayLength(ltr.fRayLength),
92   fVecSec(0),       // points vectors - sector
93   fVecP2(0),       // points vectors - snp
94   fVecPhi(0),       // points vectors - global phi
95   fVecGX(0),       // points vectors - globalX
96   fVecGY(0),       // points vectors - globalY
97   fVecGZ(0),       // points vectors - globalZ
98   fVecLX(0),       // points vectors - localX
99   fVecLY(0),       // points vectors - localY
100   fVecLZ(0)        // points vectors - localZ
101 {
102   //
103   // Default constructor
104   //
105   fVecSec=new TVectorD(*ltr.fVecSec);       // points vectors - sector
106   fVecP2 =new TVectorD(*ltr.fVecP2);       // points vectors - snp
107   fVecPhi=new TVectorD(*ltr.fVecPhi);       // points vectors - global phi
108   fVecGX =new TVectorD(*ltr.fVecGX);       // points vectors - globalX
109   fVecGY =new TVectorD(*ltr.fVecGY);       // points vectors - globalY
110   fVecGZ =new TVectorD(*ltr.fVecGZ);       // points vectors - globalZ
111   fVecLX =new TVectorD(*ltr.fVecLX);       // points vectors - localX
112   fVecLY =new TVectorD(*ltr.fVecLY);       // points vectors - localY
113   fVecLZ =new TVectorD(*ltr.fVecLZ);       // points vectors - localY
114
115 }
116
117 AliTPCLaserTrack::AliTPCLaserTrack(const Int_t id, const Int_t side, const Int_t rod,
118                      const Int_t bundle, const Int_t beam,
119                      Double_t x, Double_t alpha,
120                      const Double_t param[5],
121                      const Double_t covar[15], const Float_t rayLength) :
122   AliExternalTrackParam(x,alpha,param,covar),
123   fId(id),
124   fSide(side),
125   fRod(rod),
126   fBundle(bundle),
127   fBeam(beam),
128   fRayLength(rayLength),
129   fVecSec(new TVectorD(159)),       // points vectors - sector
130   fVecP2(new TVectorD(159)),       // points vectors - snp
131   fVecPhi(new TVectorD(159)),       // points vectors - global phi
132   fVecGX(new TVectorD(159)),       // points vectors - globalX
133   fVecGY(new TVectorD(159)),       // points vectors - globalY
134   fVecGZ(new TVectorD(159)),       // points vectors - globalZ
135   fVecLX(new TVectorD(159)),       // points vectors - localX
136   fVecLY(new TVectorD(159)),       // points vectors - localY
137   fVecLZ(new TVectorD(159))        // points vectors - localZ
138
139 {
140   //
141   // create laser track from arguments
142   //
143   
144 }
145 //_____________________________________________________________________
146 AliTPCLaserTrack& AliTPCLaserTrack::operator = (const  AliTPCLaserTrack &source)
147 {
148   //
149   // assignment operator
150   //
151   if (&source == this) return *this;
152   new (this) AliTPCLaserTrack(source);
153   
154   return *this;
155 }
156
157
158 AliTPCLaserTrack::~AliTPCLaserTrack(){
159   //
160   // destructor
161   //
162   delete fVecSec;      //                - sector numbers  
163   delete fVecP2;       //                - P2  
164   delete fVecPhi;       // points vectors - global phi
165   delete fVecGX;       // points vectors - globalX
166   delete fVecGY;       // points vectors - globalY
167   delete fVecGZ;       // points vectors - globalZ
168   delete fVecLX;       // points vectors - localX
169   delete fVecLY;       // points vectors - localY
170   delete fVecLZ;       // points vectors - localZ
171 }
172
173 void AliTPCLaserTrack::LoadTracks()
174 {
175   //
176   // Load all design positions from file into the static array fgArrLaserTracks
177   //
178   
179   if ( fgArrLaserTracks ) return;
180   TObjArray *arrLaserTracks = 0x0;
181   
182   AliCDBManager *man=AliCDBManager::Instance();
183   if (!man->GetDefaultStorage() && gSystem->Getenv("ALICE_ROOT")) man->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
184   if (man->GetDefaultStorage()){
185     if (man->GetRun()<0) man->SetRun(0);
186     AliCDBEntry *entry=man->Get(AliCDBPath("TPC/Calib/LaserTracks"));
187     if (!entry) return;
188     arrLaserTracks = (TObjArray*)entry->GetObject();
189     entry->SetOwner(kTRUE);
190   } else {
191     if (!gSystem->AccessPathName("LaserTracks.root")){
192       TFile f("LaserTracks.root");
193       arrLaserTracks=(TObjArray*)f.Get("arrLaserTracks");
194       f.Close();
195     }
196   }
197   if ( !arrLaserTracks ) {
198 //      AliWarning(Form("Could not get laser position data from file: '%s'",fgkDataFileName));
199     return;
200   }
201   
202   arrLaserTracks->SetOwner();
203   
204   fgArrLaserTracks = new TObjArray(fgkNLaserTracks);
205   fgArrLaserTracks->SetOwner();
206   for (Int_t itrack=0; itrack<fgkNLaserTracks; itrack++){
207     AliTPCLaserTrack *ltr = (AliTPCLaserTrack*)arrLaserTracks->At(itrack);
208     if ( !ltr ){
209 //          AliWarning(Form("No informatino found for Track %d!",itrack));
210       continue;
211     }
212     ltr->UpdatePoints();
213     fgArrLaserTracks->AddAt(new AliTPCLaserTrack(*ltr),itrack);
214   }
215
216   //do not delete - the entry is cached in the OCDB manager and is cleaned up there
217   //delete arrLaserTracks;
218 }
219
220
221 void AliTPCLaserTrack::UpdatePoints(){
222   //
223   // update track points
224   //
225   const Double_t kMaxSnp=0.97;
226   AliTPCROC* roc = AliTPCROC::Instance();
227   //
228   //
229   if (!fVecSec){
230     fVecSec=new TVectorD(159);
231     fVecP2 =new TVectorD(159);       //                - P2  
232     fVecPhi=new TVectorD(159);       //                - Phi
233     fVecGX=new TVectorD(159);       // points vectors - globalX
234     fVecGY=new TVectorD(159);       // points vectors - globalY
235     fVecGZ=new TVectorD(159);       // points vectors - globalZ
236     fVecLX=new TVectorD(159);       // points vectors - localX
237     fVecLY=new TVectorD(159);       // points vectors - localY
238     fVecLZ=new TVectorD(159);       // points vectors - localZ
239
240   }
241   for (Int_t irow=158; irow>=0; irow--){
242     (*fVecSec)[irow]= -1;       //                -
243     (*fVecP2)[irow] = 0;       //                - P2  -snp
244     (*fVecPhi)[irow]= 0;       //                - global phi
245     (*fVecGX)[irow] = 0;       // points vectors - globalX
246     (*fVecGY)[irow] = 0;       // points vectors - globalY
247     (*fVecGZ)[irow] = 0;       // points vectors - globalZ
248     (*fVecLX)[irow] = 0;       // points vectors - localX
249     (*fVecLY)[irow] = 0;       // points vectors - localY
250     (*fVecLZ)[irow] = 0;       // points vectors - localZ
251
252   }
253   Double_t gxyz[3];
254   Double_t lxyz[3];
255   AliTPCLaserTrack*ltrp=new AliTPCLaserTrack(*this);  //make temporary track
256
257   for (Int_t irow=158; irow>=0; irow--){
258     UInt_t srow = irow;
259     Int_t sector=0;
260    
261     if (srow >=roc->GetNRows(0)) {
262       srow-=roc->GetNRows(0);
263       sector=36    ;
264     }
265     lxyz[0]= roc->GetPadRowRadii(sector,srow);
266     if (!ltrp->PropagateTo(lxyz[0],5)) break;
267     ltrp->GetXYZ(gxyz);
268     //
269     Double_t alpha=TMath::ATan2(gxyz[1],gxyz[0]);
270     if (alpha<0) alpha+=2*TMath::Pi();
271     sector      +=TMath::Nint(-0.5+9*alpha/TMath::Pi());
272     if (gxyz[2]<0) sector+=18;
273     Double_t salpha   = TMath::Pi()*(sector+0.5)/9.;    
274     if (!ltrp->Rotate(salpha)) break;
275     if (!ltrp->PropagateTo(lxyz[0],5)) break;
276     if (TMath::Abs(ltrp->GetSnp())>kMaxSnp) break;
277     ltrp->GetXYZ(gxyz);
278     lxyz[1]=ltrp->GetY();
279     lxyz[2]=ltrp->GetZ();
280     (*fVecSec)[irow]= sector;
281     (*fVecP2)[irow] = ltrp->GetSnp();                 //                - P2  -snp
282     (*fVecPhi)[irow]= TMath::ATan2(gxyz[1],gxyz[0]);  //                - global phi
283     (*fVecGX)[irow] = gxyz[0];       // points vectors - globalX
284     (*fVecGY)[irow] = gxyz[1];       // points vectors - globalY
285     (*fVecGZ)[irow] = gxyz[2];       // points vectors - globalZ
286     (*fVecLX)[irow] = lxyz[0];       // points vectors - localX
287     (*fVecLY)[irow] = lxyz[1];       // points vectors - localY
288     (*fVecLZ)[irow] = lxyz[2];       // points vectors - localZ
289
290   }
291   delete ltrp;  // delete temporary track
292 }
293
294 Int_t AliTPCLaserTrack::IdentifyTrack(AliExternalTrackParam *track, Int_t side)
295 {
296   //
297   // Find the laser track which is corresponding closest to 'track'
298   // return its id
299   //
300   // 
301   const  Float_t   kMaxdphi=0.2;
302   const  Float_t   kMaxdphiP=0.05;
303   const  Float_t   kMaxdz=40;
304
305   if ( !fgArrLaserTracks ) LoadTracks();
306   TObjArray *arrTracks = GetTracks();
307   Double_t lxyz0[3];
308   Double_t lxyz1[3];
309   Double_t pxyz0[3];
310   Double_t pxyz1[3];
311   track->GetXYZ(lxyz0);
312   track->GetDirection(pxyz0);
313   //
314   Float_t mindist=10; // maxima minimal distance
315   Int_t id = -1;
316   for (Int_t itrack=0; itrack<fgkNLaserTracks; itrack++){    
317     AliTPCLaserTrack *ltr = (AliTPCLaserTrack*)arrTracks->UncheckedAt(itrack);
318     if (side>=0) if (ltr->GetSide()!=side) continue;
319     Double_t * kokot = (Double_t*)ltr->GetParameter();
320     kokot[4]=-0.0000000001;
321     //
322     ltr->GetXYZ(lxyz1);
323     if (TMath::Abs(lxyz1[2]-lxyz0[2])>kMaxdz) continue;
324     // phi position
325     Double_t phi0 = TMath::ATan2(lxyz0[1],lxyz0[0]);
326     Double_t phi1 = TMath::ATan2(lxyz1[1],lxyz1[0]);
327     if (TMath::Abs(phi0-phi1)>kMaxdphi) continue;
328     // phi direction
329     ltr->GetDirection(pxyz1);
330     Float_t direction= pxyz0[0]*pxyz1[0] + pxyz0[1]*pxyz1[1] + pxyz0[2]*pxyz1[2];
331     Float_t distdir = (1-TMath::Abs(direction))*90.; //distance at entrance
332     if (1-TMath::Abs(direction)>kMaxdphiP)
333       continue;
334     //
335     Float_t dist=0;
336     dist+=TMath::Abs(lxyz1[0]-lxyz0[0]);
337     dist+=TMath::Abs(lxyz1[1]-lxyz0[1]);
338     //    dist+=TMath::Abs(lxyz1[2]-lxyz0[2]); //z is not used for distance calculation
339     dist+=distdir;
340     //    
341     if (id<0)  {
342       id =itrack; 
343       mindist=dist; 
344       continue;
345     }
346     if (dist>mindist) continue;
347     id = itrack;
348     mindist=dist;
349   }
350   return id;
351 }
352