]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/ESD/AliESDTOFCluster.cxx
CTP raw data simulation changed to Run2 payload.
[u/mrichter/AliRoot.git] / STEER / ESD / AliESDTOFCluster.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 /* $Id:  $ */
17
18 //_________________________________________________________________________//
19 //_________________________________________________________________________//
20
21 #include "AliESDTOFCluster.h"
22 #include "TClonesArray.h"
23 #include "AliESDEvent.h"
24
25 ClassImp(AliESDTOFCluster)
26
27 //_________________________________________________________________________
28 AliESDTOFCluster::AliESDTOFCluster(Int_t clID) :
29   fID(clID),
30   fNTOFhits(0),
31   fStatus(0),
32   fNmatchableTracks(0)
33 {
34   //
35   // default ctor
36   //
37
38   for(Int_t i=kMaxHits;i--;)    fHitIndex[i] = -1;
39   for(Int_t i=kMaxMatches;i--;) fMatchIndex[i] = -1;
40 }
41
42 //_________________________________________________________________________
43 AliESDTOFCluster::AliESDTOFCluster(Int_t ,Int_t ,Float_t ,Float_t ,Float_t ,Int_t*,Int_t ,Int_t ,
44                                    Bool_t ,Float_t ,Float_t ,Float_t ,
45                                    Int_t ,Float_t ,Float_t ,Float_t ,Float_t ,Double_t*) :
46   fID(-1),
47   fNTOFhits(0),
48   fStatus(1),
49   fNmatchableTracks(1)
50 {
51   //
52   // Constructor of AliESDTOFCluster object
53   //
54
55   // to be replaced with hit creation
56   for(Int_t i=kMaxHits;i--;) fHitIndex[i] = -1;
57   for(Int_t i=kMaxMatches;i--;) fMatchIndex[i] = -1;
58   //
59 }
60
61 //_________________________________________________________________________
62 AliESDTOFCluster::AliESDTOFCluster(Int_t ,Int_t ,Float_t ,Float_t ,Float_t ,Int_t*,Int_t ,Int_t ,
63                                    Bool_t ,Float_t ,Float_t ,Float_t ) :
64   fID(-1),
65   fNTOFhits(0),
66   fStatus(1),
67   fNmatchableTracks(0)
68 {
69   //
70   // Constructor of AliESDTOFCluster object
71   //
72
73   // to be replaced with hit creation
74   for(Int_t i=kMaxHits;i--;) fHitIndex[i] = -1;
75   for(Int_t i=kMaxMatches;i--;) fMatchIndex[i] = -1;
76
77 }
78
79 //_________________________________________________________________________
80 AliESDTOFCluster::AliESDTOFCluster(const AliESDTOFCluster & source) :
81   AliVTOFcluster(source),
82   fID(source.fID),
83   fNTOFhits(source.fNTOFhits),
84   fStatus(source.fStatus),
85   fNmatchableTracks(source.fNmatchableTracks)
86 {
87   // 
88   // copy ctor for AliESDTOFCluster object
89   //
90
91   SetEvent(source.GetEvent());
92
93   for(Int_t i=kMaxHits;i--;)    fHitIndex[i] = source.fHitIndex[i];
94   for(Int_t i=kMaxMatches;i--;) fMatchIndex[i] = source.fMatchIndex[i];
95
96 }
97
98 //_________________________________________________________________________
99 AliESDTOFCluster & AliESDTOFCluster::operator=(const AliESDTOFCluster & source)
100 {
101   // 
102   // assignment op-r
103   //
104   if (this == &source) return *this;
105   AliVTOFcluster::operator=(source);
106   fID = source.fID;
107   fNTOFhits = source.fNTOFhits;
108   fStatus = source.fStatus;
109   fNmatchableTracks = source.fNmatchableTracks;
110
111   for(Int_t i=kMaxHits;i--;)    fHitIndex[i] = source.fHitIndex[i];
112   for(Int_t i=kMaxMatches;i--;) fMatchIndex[i] = source.fMatchIndex[i];
113
114   return *this;
115 }
116
117 //_________________________________________________________________________
118 Int_t AliESDTOFCluster::Update(Int_t trackIndex,Float_t dX,Float_t dY,Float_t dZ,
119                                Float_t length,Double_t expTimes[AliPID::kSPECIESC])
120 {
121   // update cluster info by new track
122   //  AliInfo(Form("TOF %d %d",fNmatchableTracks,fNTOFhits));
123
124   if(fNmatchableTracks >= kMaxMatches) return 2; // max number reached
125   //
126   // check if the track is not already stored
127   for (Int_t ii=fNmatchableTracks; ii--;) if (trackIndex==GetTrackIndex(ii)) return 1;
128   //
129   const AliESDEvent *event = (AliESDEvent *) GetEvent();
130   TClonesArray *matchAr = event->GetESDTOFMatches();
131   int ntr = matchAr->GetEntriesFast();
132   new((*matchAr)[ntr]) AliESDTOFMatch(trackIndex,expTimes,dX,dY,dZ,length);
133   int nmt = fNmatchableTracks++;
134   fMatchIndex[nmt] = ntr;
135   //
136   return 0;
137   //
138 }
139
140 //_________________________________________________________________________
141 void AliESDTOFCluster::AddESDTOFHitIndex(Int_t hitID)
142 {
143   // register new hit in the cluster
144   if(fNTOFhits >= kMaxHits) return;
145   int nth = fNTOFhits++;
146   fHitIndex[nth] = hitID; // add the hit to the array
147 }
148
149 //_________________________________________________________________________
150 void AliESDTOFCluster::AddTOFhit(AliESDTOFHit *hit)
151 {
152   // add new hit
153   if(fNTOFhits >= kMaxHits) return;
154   // add the hit to the array
155   const AliESDEvent *event = (AliESDEvent *) GetEvent();
156   TClonesArray *hitAr = event->GetESDTOFHits();
157   int nh = hitAr->GetEntriesFast();
158   new((*hitAr)[nh]) AliESDTOFHit(*hit);
159   //   hitN->SetIndex(nh); // RS: why do we need this
160   int nth = fNTOFhits++;
161   fHitIndex[nth] = nh;
162   //
163 }
164
165 //_________________________________________________________________________
166 void AliESDTOFCluster::AddTOFhit(Int_t ,Int_t ,Float_t ,Float_t ,Float_t ,Int_t*,Int_t ,Int_t , Bool_t ,Float_t ,Float_t ,Float_t )
167 {
168 }
169
170 //_________________________________________________________________________
171 Int_t AliESDTOFCluster::GetClusterIndex(int ihit) const
172 {
173   AliESDTOFHit* hit = GetTOFHit(ihit);
174   return hit ? hit->GetClusterIndex() : -1;
175
176
177 //_________________________________________________________________________
178 Int_t AliESDTOFCluster::GetTOFchannel(int ihit) const 
179 {
180   AliESDTOFHit* hit = GetTOFHit(ihit);
181   return hit ? hit->GetTOFchannel() : -1;
182 }
183
184 //_________________________________________________________________________
185 Float_t AliESDTOFCluster::GetTime(int ihit) const 
186 {
187   AliESDTOFHit* hit = GetTOFHit(ihit);
188   return hit ? hit->GetTime() : 0;
189 }
190
191 //_________________________________________________________________________
192 Float_t AliESDTOFCluster::GetTimeRaw(Int_t ihit) const 
193 {
194  AliESDTOFHit* hit = GetTOFHit(ihit);
195  return hit ? hit->GetTimeRaw() : 0;
196 } // TOF raw time
197
198 //_________________________________________________________________________
199 Float_t AliESDTOFCluster::GetTOT(Int_t ihit) const 
200 {
201   AliESDTOFHit* hit = GetTOFHit(ihit);
202   return hit ? hit->GetTOT() : 0;
203 } // TOF tot
204
205 //_________________________________________________________________________
206 Float_t AliESDTOFCluster::GetTOFsignalToT(Int_t ihit) const 
207 {
208   AliESDTOFHit* hit = GetTOFHit(ihit);
209   return hit ? hit->GetTOT() : 0; // RS: Why signalTot and TOT are the same?
210 } // TOF tot
211
212 //_________________________________________________________________________
213 Int_t AliESDTOFCluster::GetLabel(Int_t i,Int_t ihit) const 
214 {
215   AliESDTOFHit* hit = GetTOFHit(ihit);
216   if (!hit || i>=3) return -999;
217   return hit->GetTOFLabel(i);
218 }
219
220 //_________________________________________________________________________
221 Int_t AliESDTOFCluster::GetDeltaBC(Int_t ihit) const 
222 {
223   AliESDTOFHit* hit = GetTOFHit(ihit);
224   return hit ? hit->GetDeltaBC() : 0;
225 }
226
227 //_________________________________________________________________________
228 Int_t AliESDTOFCluster::GetL0L1Latency(Int_t ihit) const 
229 {
230   AliESDTOFHit* hit = GetTOFHit(ihit);  
231   return hit ? hit->GetL0L1Latency() : 0;
232 }
233
234 //_________________________________________________________________________
235 Bool_t AliESDTOFCluster::GetStatus() const 
236 {
237   if(!fEvent){
238     AliInfo("No AliESDEvent available here!");
239     return 0;
240   }
241   return fStatus;
242 }
243
244 //_________________________________________________________________________
245 Float_t AliESDTOFCluster::GetZ() const 
246 {
247   AliESDTOFHit* hit = GetTOFHit(0);
248   return hit ? hit->GetZ() : 0;
249 }
250
251 //_________________________________________________________________________
252 Float_t AliESDTOFCluster::GetPhi() const 
253 {
254   AliESDTOFHit* hit = GetTOFHit(0);
255   return hit ? hit->GetPhi() : 0;
256 }
257
258 //_________________________________________________________________________
259 Float_t AliESDTOFCluster::GetR() const 
260 {
261   AliESDTOFHit* hit = GetTOFHit(0);
262   return hit ? hit->GetR() : 0;
263 }
264
265 //_________________________________________________________________________
266 Int_t AliESDTOFCluster::GetNMatchableTracks() const 
267 {
268   return fNmatchableTracks;
269 }
270
271 //_________________________________________________________________________
272 Int_t AliESDTOFCluster::GetNTOFhits() const 
273 {
274   return fNTOFhits;
275 }
276
277 //_________________________________________________________________________
278 Int_t AliESDTOFCluster::GetTrackIndex(Int_t i) const 
279 {
280   AliESDTOFMatch* match = 0;
281   return (i<fNmatchableTracks && (match=GetTOFMatch(i))) ? match->GetTrackIndex() : -999;
282 }
283
284 //_________________________________________________________________________
285 Float_t AliESDTOFCluster::GetDistanceInStripPlane(Int_t i) const 
286 {
287   // distance
288   AliESDTOFMatch* match = 0;
289   if (i>=fNmatchableTracks || !(match=GetTOFMatch(i))) return -999;
290   Double_t dz = match->GetDz();
291   Double_t dx = match->GetDx();
292   return TMath::Sqrt(dx*dx+dz*dz);
293 }
294
295 //_________________________________________________________________________
296 Float_t AliESDTOFCluster::GetDx(Int_t i)  const 
297 {
298   AliESDTOFMatch* match = 0;  
299   return (i<fNmatchableTracks && (match=GetTOFMatch(i))) ? match->GetDx() : -999;
300 } // distance, X component
301
302 //_________________________________________________________________________
303 Float_t AliESDTOFCluster::GetDy(Int_t i)  const 
304 {
305   AliESDTOFMatch* match = 0;  
306   return (i<fNmatchableTracks && (match=GetTOFMatch(i))) ? match->GetDy() : -999;
307 } // distance, Y component
308
309 //_________________________________________________________________________
310 Float_t AliESDTOFCluster::GetDz(Int_t i)  const 
311 {
312   AliESDTOFMatch* match = 0;  
313   return (i<fNmatchableTracks && (match=GetTOFMatch(i))) ? match->GetDz() : -999;
314 } // distance, Z component
315
316 //_________________________________________________________________________
317 Float_t AliESDTOFCluster::GetLength(Int_t i) const 
318 {
319   AliESDTOFMatch* match = 0;  
320   return (i<fNmatchableTracks && (match=GetTOFMatch(i))) ? match->GetTrackLength() : -999.;
321 } // reconstructed track length at TOF
322
323 //_________________________________________________________________________
324 Double_t AliESDTOFCluster::GetIntegratedTime(Int_t iPart,Int_t i) const 
325 {
326   AliESDTOFMatch* match = 0;  
327   return (i<fNmatchableTracks && (match=GetTOFMatch(i))) ? match->GetIntegratedTimes(iPart) : -999.;
328 } // reconstructed track length at TOF
329
330 //_________________________________________________________________________
331 void AliESDTOFCluster::Print(const Option_t*) const
332 {
333   // print full chain
334   printf("#%5d TOF Cluster %5d of %d Hits, %d Matchable Tracks\n",GetESDID(),fID, fNTOFhits, fNmatchableTracks);
335   for (int ih=0;ih<fNTOFhits;ih++) {
336     AliESDTOFHit* ht = GetTOFHit(ih);
337     if (ht) {
338       printf("%d: ",ih);
339       ht->Print();
340     }
341   }
342   //
343   for (int it=0;it<fNmatchableTracks;it++) {
344     AliESDTOFMatch* mt = GetTOFMatch(it);
345     if (mt) {
346       printf("%d: ",it);
347       mt->Print();
348     }
349   }
350   //
351 }
352
353 //_________________________________________________________________________
354 AliESDTOFHit* AliESDTOFCluster::GetTOFHit(Int_t i) const
355 {
356   return fEvent ? ((AliESDTOFHit *) ((AliESDEvent *) GetEvent())->GetESDTOFHits()->At(fHitIndex[i])):0;
357 }
358
359 //_________________________________________________________________________
360 AliESDTOFMatch* AliESDTOFCluster::GetTOFMatch(Int_t i) const 
361 {
362   return fEvent ? ((AliESDTOFMatch *) ((AliESDEvent *) GetEvent())->GetESDTOFMatches()->At(fMatchIndex[i])) : 0;
363 }
364
365 //_________________________________________________________________________
366 void AliESDTOFCluster::SuppressMatchedTrack(Int_t id)
367 {
368   // suppress the reference to track id
369   for (int it=fNmatchableTracks;it--;) {
370     AliESDTOFMatch* mtc = GetTOFMatch(it);
371     if (mtc->GetTrackIndex()!=id) continue;
372     // need to suprress the match: simply remove reference to it
373     int rmID = fMatchIndex[it];
374     for (int jt=it+1;jt<fNmatchableTracks;jt++) fMatchIndex[jt-1] = fMatchIndex[jt];
375     fNmatchableTracks--;
376     // remove match rmID
377     TClonesArray* arrMatch = ((AliESDEvent *)GetEvent())->GetESDTOFMatches();
378     int last = arrMatch->GetEntriesFast()-1;
379     AliESDTOFMatch* mtcL = (AliESDTOFMatch*)arrMatch->At(last);
380     if (rmID!=last) {
381       *mtc = *mtcL; // assign the last match to removed slot
382       int trID = mtc->GetTrackIndex();
383       AliESDtrack* trc = ((AliESDEvent *)GetEvent())->GetTrack(trID);
384       trc->ReplaceTOFMatchID(last,rmID); // fix the reference to reassigned match
385       // fix the 
386     }
387     arrMatch->RemoveAt(last);
388     break;
389   }
390   //
391   if (!fNmatchableTracks) { // no matches left, clear all hits: prepare for selfelimination
392     // first remove associated hits
393     TClonesArray* arrHits = ((AliESDEvent *)GetEvent())->GetESDTOFHits();
394     TClonesArray* arrClus = ((AliESDEvent *)GetEvent())->GetESDTOFClusters();
395     int last = arrHits->GetEntriesFast()-1;
396     for (;fNTOFhits--;) { // remove hits
397       int hID = fHitIndex[int(fNTOFhits)];
398       AliESDTOFHit* hit = (AliESDTOFHit*)arrHits->At(hID);
399       AliESDTOFHit* hitL = (AliESDTOFHit*)arrHits->At(last);
400       if (hID!=last) {
401         *hit = *hitL; // assign the last match to removed slot
402         // fix reference on hitL in the owner cluster
403         int clID = hit->GetESDTOFClusterIndex();
404         AliESDTOFCluster* clusL = (AliESDTOFCluster*)arrClus->At(clID);
405         clusL->ReplaceHitID(last,hID);
406       }
407       arrHits->RemoveAt(last--);
408     }
409   }
410
411 }
412
413 //_________________________________________________________________________
414 void AliESDTOFCluster::ReplaceHitID(int oldID, int newID)
415 {
416   // replace the reference to hit from oldID by newID
417   for (int it=fNTOFhits;it--;) {
418     if (fHitIndex[it]==oldID) {
419       fHitIndex[it]=newID;
420       return;
421     }
422   }
423 }
424
425 //_________________________________________________________________________
426 void AliESDTOFCluster::ReplaceMatchID(int oldID, int newID)
427 {
428   // replace the reference to match from oldID by newID
429   for (int it=fNmatchableTracks;it--;) {
430     if (fMatchIndex[it]==oldID) {
431       fMatchIndex[it]=newID;
432       return;
433     }
434   }
435 }
436
437 //_________________________________________________________________________
438 void AliESDTOFCluster::ReplaceMatchedTrackID(int oldID, int newID)
439 {
440   // replace the reference to track oldID by newID
441   for (int it=fNmatchableTracks;it--;) {
442     AliESDTOFMatch* mtc = GetTOFMatch(it);
443     if (mtc->GetTrackIndex()!=oldID) continue;
444     mtc->SetTrackIndex(newID);
445     break;
446   }
447   //
448 }
449
450 //_________________________________________________________________________
451 void AliESDTOFCluster::FixSelfReferences(int oldID, int newID)
452 {
453   // replace the references (in tracks and hist) to this cluster from oldID by newID  
454   for (int it=fNmatchableTracks;it--;) {
455     int trID = GetTOFMatch(it)->GetTrackIndex();
456     AliESDtrack* trc = ((AliESDEvent *)GetEvent())->GetTrack(trID);
457     trc->ReplaceTOFClusterID(oldID,newID);
458   }
459   for (int it=fNTOFhits;it--;) {
460     AliESDTOFHit* hit = GetTOFHit(it);
461     if (hit) hit->SetESDTOFClusterIndex(newID);
462   }
463   //
464 }