]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG1/AliESDRecInfo.cxx
Try to get correct calibration object - in meant time the TRD track written to the...
[u/mrichter/AliRoot.git] / PWG1 / AliESDRecInfo.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 //                                                                           //
19 //  Time Projection Chamber                                                  //
20 //  Comparison macro for reconstructed tracks                                  //
21 //  responsible: 
22 //  marian.ivanov@cern.ch                                                    //
23 //
24 //
25
26  
27
28
29
30 //ROOT includes
31 #include "Rtypes.h"
32 //
33 //ALIROOT includes
34 //
35 #include "AliESDtrack.h"
36 #include "AliTracker.h"
37 #include "AliTPCParam.h"
38 #include "AliTrackReference.h"
39 #include "AliTPCParamSR.h"
40 #include "AliESDfriend.h"
41 #include "AliESDtrack.h"
42 #include "AliTPCseed.h"
43 #include "AliITStrackMI.h"
44 #include "AliTRDtrack.h"
45 #include "AliMCInfo.h"
46 #include "AliESDRecInfo.h"
47
48
49
50 ClassImp(AliESDRecInfo)
51
52
53
54
55 AliTPCParam * GetTPCParam(){
56   AliTPCParamSR * par = new AliTPCParamSR;
57   par->Update();
58   return par;
59 }
60
61
62
63
64 AliESDRecInfo::AliESDRecInfo(): 
65   fITSOn(0),           // ITS refitted inward
66   fTRDOn(0),           // ITS refitted inward
67   fDeltaP(0),          //delta of momenta
68   fSign(0),           // sign
69   fReconstructed(0),         //flag if track was reconstructed
70   fFake(0),             // fake track
71   fMultiple(0),         // number of reconstructions
72   fTPCOn(0),           // TPC refitted inward
73   fBestTOFmatch(0),        //best matching between times
74   fESDtrack(0),        // esd track
75   fTrackF(0),      // friend track
76   fTPCtrack(0),        // tpc track
77   fITStrack(0),        // its track
78   fTRDtrack(0)        // trd track  
79 {
80   //
81   //  default constructor
82   //
83 }
84
85
86 AliESDRecInfo::AliESDRecInfo(const AliESDRecInfo& recinfo):
87   TObject(),
88   fITSOn(0),           // ITS refitted inward
89   fTRDOn(0),           // ITS refitted inward
90   fDeltaP(0),          //delta of momenta
91   fSign(0),           // sign
92   fReconstructed(0),         //flag if track was reconstructed
93   fFake(0),             // fake track
94   fMultiple(0),         // number of reconstructions
95   fTPCOn(0),           // TPC refitted inward
96   fBestTOFmatch(0),        //best matching between times
97   fESDtrack(0),        // esd track
98   fTrackF(0),      // friend track
99   fTPCtrack(0),        // tpc track
100   fITStrack(0),        // its track
101   fTRDtrack(0)        // trd track  
102 {
103   //
104   //
105   //
106   memcpy(this,&recinfo, sizeof(recinfo));
107   fESDtrack=0; fTrackF=0; fTPCtrack=0;fITStrack=0;fTRDtrack=0;
108   SetESDtrack(recinfo.GetESDtrack());
109 }
110
111
112 AliESDRecInfo& AliESDRecInfo::operator=(const AliESDRecInfo& info) { 
113   //
114   // Assignment operator
115   //
116   this->~AliESDRecInfo();
117   new (this) AliESDRecInfo(info);
118   return *this;
119 }
120
121
122
123 AliESDRecInfo::~AliESDRecInfo()
124
125 {
126   //
127   //  destructor
128   //
129   if (fESDtrack) { delete fESDtrack; fESDtrack=0;}
130   if (fTrackF)   { delete fTrackF;   fTrackF=0;}
131   if (fTPCtrack) { delete fTPCtrack; fTPCtrack=0;}
132   if (fITStrack) { delete fITStrack; fITStrack=0;}
133   if (fTRDtrack) { delete fTRDtrack; fTRDtrack=0;}
134
135 }
136
137
138
139 void AliESDRecInfo::Reset()
140 {
141   //
142   // reset info
143   //
144   fMultiple =0; 
145   fFake     =0;
146   fReconstructed=0;
147   if (fESDtrack) { delete fESDtrack; fESDtrack=0;}
148   if (fTrackF)   { delete fTrackF;   fTrackF=0;}
149   if (fTPCtrack) { delete fTPCtrack; fTPCtrack=0;}
150   if (fITStrack) { delete fITStrack; fITStrack=0;}
151   if (fTRDtrack) { delete fTRDtrack; fTRDtrack=0;}
152
153
154 void AliESDRecInfo::SetESDtrack(const AliESDtrack *track){
155   //
156   // 
157   //
158   if (fESDtrack) delete fESDtrack;
159   fESDtrack = (AliESDtrack*)track->Clone();
160   if (track->GetFriendTrack()){
161     if (fTrackF) delete fTrackF;
162     fTrackF = (AliESDfriendTrack*)track->GetFriendTrack()->Clone();
163     Int_t icalib=0;
164     TObject *cobject=0;
165     //
166     while (fTrackF->GetCalibObject(icalib)){
167       cobject=fTrackF->GetCalibObject(icalib);
168       if (dynamic_cast<AliTPCseed*>(cobject)){
169         if (fTPCtrack) delete fTPCtrack;
170         fTPCtrack = (AliTPCseed*)(dynamic_cast<AliTPCseed*>(cobject))->Clone();
171       }
172       icalib++;
173     }
174   }
175   
176 }
177
178 void  AliESDRecInfo::UpdatePoints(AliESDtrack*track)
179 {
180   //
181   //
182   Int_t iclusters[200];
183   Float_t density[160];
184   for (Int_t i=0;i<160;i++) density[i]=-1.;
185   fTPCPoints[0]= 160;
186   fTPCPoints[1] = -1;
187   //
188   if (fTPCPoints[0]<fTPCPoints[1]) return;
189   //  Int_t nclusters=track->GetTPCclusters(iclusters);
190
191   Int_t ngood=0;
192   Int_t undeff=0;
193   Int_t nall =0;
194   Int_t range=20;
195   for (Int_t i=0;i<160;i++){
196     Int_t last = i-range;
197     if (nall<range) nall++;
198     if (last>=0){
199       if (iclusters[last]>0&& (iclusters[last]&0x8000)==0) ngood--;
200       if (iclusters[last]==-1) undeff--;
201     }
202     if (iclusters[i]>0&& (iclusters[i]&0x8000)==0)   ngood++;
203     if (iclusters[i]==-1) undeff++;
204     if (nall==range &&undeff<range/2) density[i-range/2] = Float_t(ngood)/Float_t(nall-undeff);
205   }
206   Float_t maxdens=0;
207   Int_t indexmax =0;
208   for (Int_t i=0;i<160;i++){
209     if (density[i]<0) continue;
210     if (density[i]>maxdens){
211       maxdens=density[i];
212       indexmax=i;
213     }
214   }
215   //
216   //max dens point
217   fTPCPoints[3] = maxdens;
218   fTPCPoints[1] = indexmax;
219   //
220   // last point
221   for (Int_t i=indexmax;i<160;i++){
222     if (density[i]<0) continue;
223     if (density[i]<maxdens/2.) {
224       break;
225     }
226     fTPCPoints[2]=i;
227   }
228   //
229   // first point
230   for (Int_t i=indexmax;i>0;i--){
231     if (density[i]<0) continue;
232     if (density[i]<maxdens/2.) {
233       break;
234     }
235     fTPCPoints[0]=i;
236   }
237   //
238   // Density at the last 30 padrows
239   //
240   // 
241   nall  = 0;
242   ngood = 0;
243   for (Int_t i=159;i>0;i--){
244     if (iclusters[i]==-1) continue; //dead zone
245     nall++;
246     if (iclusters[i]>0)   ngood++;
247     if (nall>20) break;
248   }
249   fTPCPoints[4] = Float_t(ngood)/Float_t(nall);
250   //
251   if ((track->GetStatus()&AliESDtrack::kITSrefit)>0) fTPCPoints[0]=-1;
252
253
254 }
255
256 //
257 //
258 void AliESDRecInfo::Update(AliMCInfo* info,AliTPCParam * /*par*/, Bool_t reconstructed)
259 {
260   //
261   //calculates derived variables
262   //  
263   UpdatePoints(fESDtrack);
264   UpdateStatus(info,reconstructed);
265   UpdateITS(info);
266   UpdateTPC(info);
267   UpdateTOF(info);
268 }
269
270
271 void  AliESDRecInfo::UpdateStatus(AliMCInfo* info, Bool_t reconstructed){
272   //
273   // Interpret bit mask flags
274   //
275   for (Int_t i=0;i<4;i++) fStatus[i] =0;
276   fReconstructed = kFALSE;
277   fTPCOn = kFALSE;
278   fITSOn = kFALSE;
279   fTRDOn = kFALSE;  
280   if (reconstructed==kFALSE) return;
281
282   fLabels[0] = info->fLabel;
283   fLabels[1] = info->fPrimPart;
284   fReconstructed = kTRUE;
285   fTPCOn = ((fESDtrack->GetStatus()&AliESDtrack::kTPCrefit)>0) ? kTRUE : kFALSE;
286   fITSOn = ((fESDtrack->GetStatus()&AliESDtrack::kITSrefit)>0) ? kTRUE : kFALSE;
287   fTRDOn = ((fESDtrack->GetStatus()&AliESDtrack::kTRDrefit)>0) ? kTRUE : kFALSE;
288   //
289   //  
290   if ((fESDtrack->GetStatus()&AliESDtrack::kTPCrefit)>0){
291     fStatus[1] =3;
292   }
293   else{
294     if ((fESDtrack->GetStatus()&AliESDtrack::kTPCout)>0){
295       fStatus[1] =2;
296     }
297     else{
298       if ((fESDtrack->GetStatus()&AliESDtrack::kTPCin)>0)
299         fStatus[1]=1;
300     }      
301   }
302   //
303   if ((fESDtrack->GetStatus()&AliESDtrack::kITSout)>0){
304     fStatus[0] =2;
305   }
306   else{
307     if ((fESDtrack->GetStatus()&AliESDtrack::kITSrefit)>0){
308       fStatus[0] =1;
309     }
310     else{
311       fStatus[0]=0;
312     }      
313   }
314   //
315   //
316   if ((fESDtrack->GetStatus()&AliESDtrack::kTRDrefit)>0){
317     fStatus[2] =2;
318   }
319   else{
320     if ((fESDtrack->GetStatus()&AliESDtrack::kTRDout)>0){
321       fStatus[2] =1;
322     }
323   }
324   if ((fESDtrack->GetStatus()&AliESDtrack::kTRDStop)>0){
325     fStatus[2] =10;
326   }   
327 }
328
329 void AliESDRecInfo::UpdateTOF(AliMCInfo* info){
330   //
331   // Update TOF related comparison information
332   //
333   fBestTOFmatch=1000;
334   if (((fESDtrack->GetStatus()&AliESDtrack::kTOFout)>0)){
335     //
336     // best tof match
337     Double_t times[5];
338     fESDtrack->GetIntegratedTimes(times);    
339     for (Int_t i=0;i<5;i++){
340       if ( TMath::Abs(fESDtrack->GetTOFsignal()-times[i]) <TMath::Abs(fBestTOFmatch) ){
341         fBestTOFmatch = fESDtrack->GetTOFsignal()-times[i];
342       }
343     }
344     Int_t toflabel[3];
345     fESDtrack->GetTOFLabel(toflabel);
346     Bool_t toffake=kTRUE;
347     Bool_t tofdaughter=kFALSE;
348     for (Int_t i=0;i<3;i++){
349       if (toflabel[i]<0) continue;      
350       if (toflabel[i]== TMath::Abs(fESDtrack->GetLabel()))  toffake=kFALSE;     
351       if (toflabel[i]==info->fParticle.GetDaughter(0) || (toflabel[i]==info->fParticle.GetDaughter(1))) tofdaughter=kTRUE;  // decay product of original particle
352       fStatus[3]=1;
353     }
354     if (toffake) fStatus[3] =3;       //total fake
355     if (tofdaughter) fStatus[3]=2;    //fake because of decay
356   }else{
357     fStatus[3]=0;
358   }
359 }
360
361
362
363 void AliESDRecInfo::UpdateITS(AliMCInfo* info){
364   //
365   // Update ITS related comparison information
366   //
367   fITSinP0[0]=info->fParticle.Px();
368   fITSinP0[1]=info->fParticle.Py();
369   fITSinP0[2]=info->fParticle.Pz();
370   fITSinP0[3]=info->fParticle.Pt();    
371   //
372   fITSinR0[0]=info->fParticle.Vx();
373   fITSinR0[1]=info->fParticle.Vy();
374   fITSinR0[2]=info->fParticle.Vz();
375   fITSinR0[3] = TMath::Sqrt(fITSinR0[0]*fITSinR0[0]+fITSinR0[1]*fITSinR0[1]);
376   fITSinR0[4] = TMath::ATan2(fITSinR0[1],fITSinR0[0]);
377   //
378   //
379   if (fITSinP0[3]>0.0000001){
380     fITSAngle0[0] = TMath::ATan2(fITSinP0[1],fITSinP0[0]);
381     fITSAngle0[1] = TMath::ATan(fITSinP0[2]/fITSinP0[3]);
382   }
383   if (fITSOn){
384     // ITS 
385     Double_t param[5],x;
386     fESDtrack->GetExternalParameters(x,param);   
387     //    fESDtrack->GetConstrainedExternalParameters(x,param);   
388     Double_t cov[15];
389     fESDtrack->GetExternalCovariance(cov);
390     //fESDtrack->GetConstrainedExternalCovariance(cov);
391     if (TMath::Abs(param[4])<0.0000000001) return;
392     
393     fESDtrack->GetXYZ(fITSinR1);
394     fESDtrack->GetPxPyPz(fITSinP1);
395     fITSinP1[3] = TMath::Sqrt(fITSinP1[0]*fITSinP1[0]+fITSinP1[1]*fITSinP1[1]);
396     //
397     fITSinR1[3] = TMath::Sqrt(fITSinR1[0]*fITSinR1[0]+fITSinR1[1]*fITSinR1[1]);
398     fITSinR1[4] = TMath::ATan2(fITSinR1[1],fITSinR1[0]);
399     //
400     //
401     if (fITSinP1[3]>0.0000001){
402       fITSAngle1[0] = TMath::ATan2(fITSinP1[1],fITSinP1[0]);
403       fITSAngle1[1] = TMath::ATan(fITSinP1[2]/fITSinP1[3]);  
404     }
405     //
406     //
407     fITSDelta[0] = (fITSinR0[4]-fITSinR1[4])*fITSinR1[3];  //delta rfi
408     fITSPools[0] = fITSDelta[0]/TMath::Sqrt(cov[0]);
409     fITSDelta[1] = (fITSinR0[2]-fITSinR1[2]);              //delta z
410     fITSPools[1] = fITSDelta[1]/TMath::Sqrt(cov[2]);
411     fITSDelta[2] = (fITSAngle0[0]-fITSAngle1[0]);
412     fITSPools[2] = fITSDelta[2]/TMath::Sqrt(cov[5]);
413     fITSDelta[3] = (TMath::Tan(fITSAngle0[1])-TMath::Tan(fITSAngle1[1]));
414     fITSPools[3] = fITSDelta[3]/TMath::Sqrt(cov[9]);
415     fITSDelta[4] = (fITSinP0[3]-fITSinP1[3]);    
416     Double_t sign = (param[4]>0) ? 1:-1; 
417     fSign = sign;
418     fITSPools[4] = sign*(1./fITSinP0[3]-1./fITSinP1[3])/TMath::Sqrt(cov[14]);
419   }
420 }
421
422 void AliESDRecInfo::UpdateTPC(AliMCInfo* info){
423   //
424   //
425   // Update TPC related information
426   //
427   AliTrackReference * ref = &(info->fTrackRef);
428   fTPCinR0[0] = info->fTrackRef.X();    
429   fTPCinR0[1] = info->fTrackRef.Y();    
430   fTPCinR0[2] = info->fTrackRef.Z();
431   fTPCinR0[3] = TMath::Sqrt(fTPCinR0[0]*fTPCinR0[0]+fTPCinR0[1]*fTPCinR0[1]);
432   fTPCinR0[4] = TMath::ATan2(fTPCinR0[1],fTPCinR0[0]);
433   //
434   fTPCinP0[0] = ref->Px();
435   fTPCinP0[1] = ref->Py();
436   fTPCinP0[2] = ref->Pz();
437   fTPCinP0[3] = ref->Pt();
438   fTPCinP0[4] = ref->P();
439   fDeltaP     = (ref->P()-info->fParticle.P())/info->fParticle.P();
440   //
441   //
442   if (fTPCinP0[3]>0.0000001){
443     //
444     fTPCAngle0[0] = TMath::ATan2(fTPCinP0[1],fTPCinP0[0]);
445     fTPCAngle0[1] = TMath::ATan(fTPCinP0[2]/fTPCinP0[3]);
446   }
447   //
448   if (fStatus[1]>0 &&info->fNTPCRef>0&&TMath::Abs(fTPCinP0[3])>0.0001){
449     //TPC
450     fESDtrack->GetInnerXYZ(fTPCinR1);
451     fTPCinR1[3] = TMath::Sqrt(fTPCinR1[0]*fTPCinR1[0]+fTPCinR1[1]*fTPCinR1[1]);
452     fTPCinR1[4] = TMath::ATan2(fTPCinR1[1],fTPCinR1[0]);        
453     fESDtrack->GetInnerPxPyPz(fTPCinP1);
454     fTPCinP1[3] = TMath::Sqrt(fTPCinP1[0]*fTPCinP1[0]+fTPCinP1[1]*fTPCinP1[1]);
455     fTPCinP1[4] = TMath::Sqrt(fTPCinP1[3]*fTPCinP1[3]+fTPCinP1[2]*fTPCinP1[2]);
456     //
457     //
458     if (fTPCinP1[3]>0.000000000000001){
459       fTPCAngle1[0] = TMath::ATan2(fTPCinP1[1],fTPCinP1[0]);
460       fTPCAngle1[1] = TMath::ATan(fTPCinP1[2]/fTPCinP1[3]);  
461     }    
462     Double_t cov[15], param[5],x, alpha;
463     fESDtrack->GetInnerExternalCovariance(cov);
464     fESDtrack->GetInnerExternalParameters(alpha, x,param);
465     if (x<50) return ;
466     //
467     fTPCDelta[0] = (fTPCinR0[4]-fTPCinR1[4])*fTPCinR1[3];  //delta rfi
468     fTPCPools[0] = fTPCDelta[0]/TMath::Sqrt(cov[0]);
469     fTPCDelta[1] = (fTPCinR0[2]-fTPCinR1[2]);              //delta z
470     fTPCPools[1] = fTPCDelta[1]/TMath::Sqrt(cov[2]);
471     fTPCDelta[2] = (fTPCAngle0[0]-fTPCAngle1[0]);
472     fTPCPools[2] = fTPCDelta[2]/TMath::Sqrt(cov[5]);
473     fTPCDelta[3] = (TMath::Tan(fTPCAngle0[1])-TMath::Tan(fTPCAngle1[1]));
474     fTPCPools[3] = fTPCDelta[3]/TMath::Sqrt(cov[9]);
475     fTPCDelta[4] = (fTPCinP0[3]-fTPCinP1[3]);
476     Double_t sign = (param[4]>0)? 1.:-1; 
477     fSign =sign;
478     fTPCPools[4] = sign*(1./fTPCinP0[3]-1./fTPCinP1[3])/TMath::Sqrt(TMath::Abs(cov[14]));
479   }
480 }
481
482
483
484
485