]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/global/AliFlatESDTrack.cxx
add special constructors for restoring the vtable ptr
[u/mrichter/AliRoot.git] / HLT / global / AliFlatESDTrack.cxx
1 /* $Id$ */
2
3 /**************************************************************************
4  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5  *                                                                        *
6  * Author: The ALICE Off-line Project.                                    *
7  * Contributors are mentioned in the code where appropriate.              *
8  *                                                                        *
9  * Permission to use, copy, modify and distribute this software and its   *
10  * documentation strictly for non-commercial purposes is hereby granted   *
11  * without fee, provided that the above copyright notice appears in all   *
12  * copies and that both the copyright notice and this permission notice   *
13  * appear in the supporting documentation. The authors make no claims     *
14  * about the suitability of this software for any purpose. It is          *
15  * provided "as is" without express or implied warranty.                  *
16  **************************************************************************/
17
18 /**
19  * >> Flat structure representing an ESDTrack <<
20  *
21  * To be used in the online and offline calibration schema.
22  *
23  * Class provides interface methods for 
24  *   - Filling from AliESDtrack and AliExternalTrackParam, as well 
25  *     as clusters from ESD friends (if requested)
26  *   - HLT Filling to be added
27  * 
28  *
29  * Primary Authors : Sergey Gorbunov, Jochen Thaeder, Chiara Zampolli
30  *
31  **************************************************************************/
32
33 #include "TObject.h"
34
35 #include "AliESDEvent.h"
36 #include "AliESDtrack.h"
37 #include "AliESDfriendTrack.h"
38 #include "AliExternalTrackParam.h"
39 #include "AliTPCseed.h"
40 #include "AliTPCclusterMI.h"
41
42 #include "AliFlatESDEvent.h"
43 #include "AliFlatESDTrack.h"
44 #include "Riostream.h"
45
46 // _______________________________________________________________________________________________________
47 AliFlatESDTrack::AliFlatESDTrack() :
48   // Default constructor
49   fTrackParamMask(0),
50   fNTPCClusters(0),
51   fNITSClusters(0),
52
53   fSize(0),
54   fContent() {
55
56 }
57
58 // _______________________________________________________________________________________________________
59 AliFlatESDTrack::AliFlatESDTrack(Bool_t)
60 {
61   //special contructor
62   //use to restore the vtable pointer
63   
64   AliFlatExternalTrackParam* trackParam = GetTrackParamRefitted();
65   if (trackParam) { new (trackParam) AliFlatExternalTrackParam(1); }
66   trackParam = GetTrackParamIp();
67   if (trackParam) { new (trackParam) AliFlatExternalTrackParam(1); }
68   trackParam = GetTrackParamTPCInner();
69   if (trackParam) { new (trackParam) AliFlatExternalTrackParam(1); }
70   trackParam = GetTrackParamOp();
71   if (trackParam) { new (trackParam) AliFlatExternalTrackParam(1); }
72   trackParam = GetTrackParamCp();
73   if (trackParam) { new (trackParam) AliFlatExternalTrackParam(1); }
74   trackParam = GetTrackParamITSOut();
75   if (trackParam) { new (trackParam) AliFlatExternalTrackParam(1); }
76   
77   AliFlatTPCCluster* clusterTPC = GetTPCClusters();
78   for (Int_t i=0; i<GetNumberOfTPCClusters(); i++)
79   {
80     new (clusterTPC) AliFlatTPCCluster(1);
81     clusterTPC += sizeof(AliFlatTPCCluster);
82   }
83 }
84
85 // _______________________________________________________________________________________________________
86 AliFlatESDTrack::AliFlatESDTrack(const AliESDtrack* track, AliESDfriendTrack* friendTrack) :
87   // Constructor
88   fTrackParamMask(0),
89   fNTPCClusters(0),
90   fNITSClusters(0),
91   fSize(0),
92   fContent() {
93   
94   Fill(track, friendTrack);
95 }
96
97 // _______________________________________________________________________________________________________
98 AliFlatESDTrack::~AliFlatESDTrack() {
99   // Destructor
100   
101 }
102
103 // _______________________________________________________________________________________________________
104 ULong64_t AliFlatESDTrack::EstimateSize(Bool_t useESDFriends, Int_t nTPCClusters ) {
105   // Estimate upper limit of the object size
106   // -> Added objects have to be added here as well
107
108   ULong64_t size = sizeof(AliFlatESDTrack) + (6*sizeof(AliFlatExternalTrackParam));
109
110   if (useESDFriends){
111     size += nTPCClusters*sizeof(AliFlatTPCCluster);
112   }
113   return size;
114 }
115
116
117 // _______________________________________________________________________________________________________
118 Int_t AliFlatESDTrack::Fill(const AliESDtrack* track, AliESDfriendTrack* friendTrack){
119   // Fill external track parameters and friendTrack
120
121   fTrackParamMask = 0;
122   fNTPCClusters = 0;
123   fNITSClusters = 0;
124   fSize = 0;
125   
126   if( !track ) return 0;
127
128   const AliExternalTrackParam *itsOut = 0;
129   if (friendTrack) itsOut = friendTrack->GetITSOut();
130
131   Int_t iResult = FillExternalTrackParam( track,
132                                           track->GetInnerParam(),
133                                           track->GetTPCInnerParam(),
134                                           track->GetOuterParam(),
135                                           track->GetConstrainedParam(),
136                                           itsOut );
137   fNITSClusters = track->GetNcls(0);
138
139   // -- Fill clusters from friend track
140   // -------------------------------------------------------
141   if (friendTrack) {
142     //    Printf("DEBUG: Now filling clusters information for the current track");    
143
144     // -- Get seed object
145     TObject* calibObject = NULL;
146     AliTPCseed* seed = NULL;
147     /*
148     for (Int_t idx = 0; (calibObject = friendTrack->GetCalibObject(idx)); ++idx) {      
149       cout<<"Calibration object:"<<endl;
150       std::cout<<calibObject->GetName()<<std::endl;
151       calibObject->Print();
152       cout<<"----------"<<endl;
153     }
154     friendTrack->Print();
155     cout<<"ITS track: "<<(void*)friendTrack->GetITStrack()<<endl;
156     cout<<"TRD track: "<<(void*)friendTrack->GetTRDtrack()<<endl;
157     cout<<"ITS OUT track: "<<(void*)friendTrack->GetITSOut()<<endl;
158     cout<<"ITS indices: ";
159     if( friendTrack->GetITSindices() ){ 
160       for( int i=0; i<friendTrack->GetMaxITScluster(); i++ ) cout<<friendTrack->GetITSindices()[i]<<" "; 
161     }
162     cout<<endl;
163     */
164     for (Int_t idx = 0; (calibObject = friendTrack->GetCalibObject(idx)); ++idx) {
165       if ((seed = dynamic_cast<AliTPCseed*>(calibObject))) break;
166     }
167
168     // -- Fill cluster
169     if (seed) {
170       for (Int_t idxRow = 0; idxRow < 160; idxRow++){
171         AliTPCclusterMI* currentCl = seed->GetClusterPointer(idxRow);
172         if (currentCl) {
173           AliFlatTPCCluster &tmpCl = *GetNextTPCClusterPointer();
174           tmpCl.fX = currentCl->GetX();
175           tmpCl.fY = currentCl->GetY();
176           tmpCl.fZ = currentCl->GetZ();   
177           tmpCl.fPadRow  = idxRow; // TO BE CHECKED IF THIS NEEDED or currentCl->GetRow();
178           tmpCl.fSigmaY2 = currentCl->GetSigmaY2();
179           tmpCl.fSigmaZ2 = currentCl->GetSigmaZ2();
180           tmpCl.fCharge  = currentCl->GetQ();
181           tmpCl.fQMax    = currentCl->GetMax();
182           StoreLastTPCCluster();
183         }
184         //      else
185         //        Printf("DEBUG: No cluster for row %d", idxRow);
186       }
187     }
188
189     /*
190     AliTPCseed* seed = NULL;
191     for (Int_t idx = 0; (calibObject = friendTrack->GetCalibObject(idx)); ++idx) {
192       if ((seed = dynamic_cast<AliTPCseed*>(calibObject))) break;
193     }
194
195     // -- Fill cluster
196     if (seed) {
197       for (Int_t idxRow = 0; idxRow < 160; idxRow++){
198         AliTPCclusterMI* currentCl = seed->GetTPCClusterPointer(idxRow);
199         if (currentCl) {
200           AliFlatTPCCluster &tmpCl = *GetNexTPCClusterPointer();
201           tmpCl.fX = currentCl->GetX();
202           tmpCl.fY = currentCl->GetY();
203           tmpCl.fZ = currentCl->GetZ();   
204           tmpCl.fPadRow  = idxRow; // TO BE CHECKED IF THIS NEEDED or currentCl->GetRow();
205           tmpCl.fSigmaY2 = currentCl->GetSigmaY2();
206           tmpCl.fSigmaZ2 = currentCl->GetSigmaZ2();
207           tmpCl.fCharge  = currentCl->GetQ();
208           tmpCl.fQMax    = currentCl->GetMax();
209           StoreLastTPCCluster();
210         }
211         //      else
212         //        Printf("DEBUG: No cluster for row %d", idxRow);
213       }
214     }
215     */
216
217     //    else
218     //      Printf("DEBUG: No seed object");
219
220     //    Printf("DEBUG: Number of clusters for track = %d", fNTPCClusters);
221
222     // -- Sorting clusters according to user defined function (increasing pad row numbering)
223     std::sort(GetTPCClusters(), GetTPCClusters()+fNTPCClusters, AliFlatTPCCluster::SortClusters);
224   }
225
226   return iResult;
227 }
228
229 // _______________________________________________________________________________________________________
230 Int_t AliFlatESDTrack::FillExternalTrackParam( 
231                                               const AliExternalTrackParam* refittedParam,
232                                               const AliExternalTrackParam* innerParam,
233                                               const AliExternalTrackParam* innerTPC,
234                                               const AliExternalTrackParam* outerParam,
235                                               const AliExternalTrackParam* constrainedParam,
236                                               const AliExternalTrackParam* outerITS
237                                              ){
238   // Fill external track parameters 
239
240   fTrackParamMask = 0;
241   fNTPCClusters = 0;
242   fSize = 0;
243
244   Int_t iResult = 0;
245
246   Byte_t flag = 0x1;
247   iResult = FillExternalTrackParam(refittedParam, flag);
248
249   flag = 0x2;
250   iResult = FillExternalTrackParam(innerParam, flag);
251   
252   flag = 0x4;
253   iResult = FillExternalTrackParam(innerTPC, flag);
254   
255   flag = 0x8;
256   iResult = FillExternalTrackParam(outerParam, flag);
257
258   flag = 0x10;
259   iResult = FillExternalTrackParam(constrainedParam, flag);
260
261   flag = 0x20;
262   iResult = FillExternalTrackParam(outerITS, flag);
263
264   return iResult;
265 }
266
267 // _______________________________________________________________________________________________________
268 Int_t AliFlatESDTrack::FillExternalTrackParam(const AliExternalTrackParam* param, UShort_t flag) {
269   // Fill external track parameters
270
271   if (!param) 
272     return -1;
273
274   //Printf("  DEBUG: CONTENT %d >> %p + 0x%07llx = %p", flag, fContent, fSize, fContent + fSize);
275
276   AliFlatExternalTrackParam * current = reinterpret_cast<AliFlatExternalTrackParam*> (fContent + fSize);
277   current->SetAlpha(param->GetAlpha());
278   current->SetX(param->GetX());
279   current->SetY(param->GetY());
280   current->SetZ(param->GetZ());
281   current->SetSnp(param->GetSnp());
282   current->SetTgl(param->GetTgl());
283   current->SetSigned1Pt(param->GetSigned1Pt());
284   
285   const Double_t *cov = param->GetCovariance();
286   for (Int_t idx = 0; idx <15; ++idx)
287     current->fC[idx] = cov[idx];
288     
289   fTrackParamMask |= flag;
290   fSize += sizeof(AliFlatExternalTrackParam);
291
292   return 0;
293 }
294
295 // _______________________________________________________________________________________________________
296 UInt_t AliFlatESDTrack::CountBits(Byte_t field, UInt_t mask) {
297   // Count bits in field
298   UInt_t count = 0; 
299   UInt_t reg = 0x0; 
300   
301   reg |= field;   
302   reg &= mask;
303   
304   for (count = 0; reg; count++)
305     reg &= reg - 1; 
306
307   return count;
308 }