1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //_________________________________________________________________________//
19 //_________________________________________________________________________//
21 #include "AliESDTOFCluster.h"
22 #include "TClonesArray.h"
23 #include "AliESDEvent.h"
25 ClassImp(AliESDTOFCluster)
27 //_________________________________________________________________________
28 AliESDTOFCluster::AliESDTOFCluster(Int_t clID) :
38 for(Int_t i=kMaxHits;i--;) fHitIndex[i] = -1;
39 for(Int_t i=kMaxMatches;i--;) fMatchIndex[i] = -1;
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*) :
52 // Constructor of AliESDTOFCluster object
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;
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 ) :
70 // Constructor of AliESDTOFCluster object
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;
79 //_________________________________________________________________________
80 AliESDTOFCluster::AliESDTOFCluster(const AliESDTOFCluster & source) :
81 AliVTOFcluster(source),
83 fNTOFhits(source.fNTOFhits),
84 fStatus(source.fStatus),
85 fNmatchableTracks(source.fNmatchableTracks)
88 // copy ctor for AliESDTOFCluster object
91 SetEvent(source.GetEvent());
93 for(Int_t i=kMaxHits;i--;) fHitIndex[i] = source.fHitIndex[i];
94 for(Int_t i=kMaxMatches;i--;) fMatchIndex[i] = source.fMatchIndex[i];
98 //_________________________________________________________________________
99 AliESDTOFCluster & AliESDTOFCluster::operator=(const AliESDTOFCluster & source)
104 if (this == &source) return *this;
105 AliVTOFcluster::operator=(source);
107 fNTOFhits = source.fNTOFhits;
108 fStatus = source.fStatus;
109 fNmatchableTracks = source.fNmatchableTracks;
111 for(Int_t i=kMaxHits;i--;) fHitIndex[i] = source.fHitIndex[i];
112 for(Int_t i=kMaxMatches;i--;) fMatchIndex[i] = source.fMatchIndex[i];
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])
121 // update cluster info by new track
122 // AliInfo(Form("TOF %d %d",fNmatchableTracks,fNTOFhits));
124 if(fNmatchableTracks >= kMaxMatches) return 2; // max number reached
126 // check if the track is not already stored
127 for (Int_t ii=fNmatchableTracks; ii--;) if (trackIndex==GetTrackIndex(ii)) return 1;
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;
140 //_________________________________________________________________________
141 void AliESDTOFCluster::AddESDTOFHitIndex(Int_t hitID)
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
149 //_________________________________________________________________________
150 void AliESDTOFCluster::AddTOFhit(AliESDTOFHit *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++;
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 )
170 //_________________________________________________________________________
171 Int_t AliESDTOFCluster::GetClusterIndex(int ihit) const
173 AliESDTOFHit* hit = GetTOFHit(ihit);
174 return hit ? hit->GetClusterIndex() : -1;
177 //_________________________________________________________________________
178 Int_t AliESDTOFCluster::GetTOFchannel(int ihit) const
180 AliESDTOFHit* hit = GetTOFHit(ihit);
181 return hit ? hit->GetTOFchannel() : -1;
184 //_________________________________________________________________________
185 Float_t AliESDTOFCluster::GetTime(int ihit) const
187 AliESDTOFHit* hit = GetTOFHit(ihit);
188 return hit ? hit->GetTime() : 0;
191 //_________________________________________________________________________
192 Float_t AliESDTOFCluster::GetTimeRaw(Int_t ihit) const
194 AliESDTOFHit* hit = GetTOFHit(ihit);
195 return hit ? hit->GetTimeRaw() : 0;
198 //_________________________________________________________________________
199 Float_t AliESDTOFCluster::GetTOT(Int_t ihit) const
201 AliESDTOFHit* hit = GetTOFHit(ihit);
202 return hit ? hit->GetTOT() : 0;
205 //_________________________________________________________________________
206 Float_t AliESDTOFCluster::GetTOFsignalToT(Int_t ihit) const
208 AliESDTOFHit* hit = GetTOFHit(ihit);
209 return hit ? hit->GetTOT() : 0; // RS: Why signalTot and TOT are the same?
212 //_________________________________________________________________________
213 Int_t AliESDTOFCluster::GetLabel(Int_t i,Int_t ihit) const
215 AliESDTOFHit* hit = GetTOFHit(ihit);
216 if (!hit || i>=3) return -999;
217 return hit->GetTOFLabel(i);
220 //_________________________________________________________________________
221 Int_t AliESDTOFCluster::GetDeltaBC(Int_t ihit) const
223 AliESDTOFHit* hit = GetTOFHit(ihit);
224 return hit ? hit->GetDeltaBC() : 0;
227 //_________________________________________________________________________
228 Int_t AliESDTOFCluster::GetL0L1Latency(Int_t ihit) const
230 AliESDTOFHit* hit = GetTOFHit(ihit);
231 return hit ? hit->GetL0L1Latency() : 0;
234 //_________________________________________________________________________
235 Bool_t AliESDTOFCluster::GetStatus() const
238 AliInfo("No AliESDEvent available here!");
244 //_________________________________________________________________________
245 Float_t AliESDTOFCluster::GetZ() const
247 AliESDTOFHit* hit = GetTOFHit(0);
248 return hit ? hit->GetZ() : 0;
251 //_________________________________________________________________________
252 Float_t AliESDTOFCluster::GetPhi() const
254 AliESDTOFHit* hit = GetTOFHit(0);
255 return hit ? hit->GetPhi() : 0;
258 //_________________________________________________________________________
259 Float_t AliESDTOFCluster::GetR() const
261 AliESDTOFHit* hit = GetTOFHit(0);
262 return hit ? hit->GetR() : 0;
265 //_________________________________________________________________________
266 Int_t AliESDTOFCluster::GetNMatchableTracks() const
268 return fNmatchableTracks;
271 //_________________________________________________________________________
272 Int_t AliESDTOFCluster::GetNTOFhits() const
277 //_________________________________________________________________________
278 Int_t AliESDTOFCluster::GetTrackIndex(Int_t i) const
280 AliESDTOFMatch* match = 0;
281 return (i<fNmatchableTracks && (match=GetTOFMatch(i))) ? match->GetTrackIndex() : -999;
284 //_________________________________________________________________________
285 Float_t AliESDTOFCluster::GetDistanceInStripPlane(Int_t i) const
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);
295 //_________________________________________________________________________
296 Float_t AliESDTOFCluster::GetDx(Int_t i) const
298 AliESDTOFMatch* match = 0;
299 return (i<fNmatchableTracks && (match=GetTOFMatch(i))) ? match->GetDx() : -999;
300 } // distance, X component
302 //_________________________________________________________________________
303 Float_t AliESDTOFCluster::GetDy(Int_t i) const
305 AliESDTOFMatch* match = 0;
306 return (i<fNmatchableTracks && (match=GetTOFMatch(i))) ? match->GetDy() : -999;
307 } // distance, Y component
309 //_________________________________________________________________________
310 Float_t AliESDTOFCluster::GetDz(Int_t i) const
312 AliESDTOFMatch* match = 0;
313 return (i<fNmatchableTracks && (match=GetTOFMatch(i))) ? match->GetDz() : -999;
314 } // distance, Z component
316 //_________________________________________________________________________
317 Float_t AliESDTOFCluster::GetLength(Int_t i) const
319 AliESDTOFMatch* match = 0;
320 return (i<fNmatchableTracks && (match=GetTOFMatch(i))) ? match->GetTrackLength() : -999.;
321 } // reconstructed track length at TOF
323 //_________________________________________________________________________
324 Double_t AliESDTOFCluster::GetIntegratedTime(Int_t iPart,Int_t i) const
326 AliESDTOFMatch* match = 0;
327 return (i<fNmatchableTracks && (match=GetTOFMatch(i))) ? match->GetIntegratedTimes(iPart) : -999.;
328 } // reconstructed track length at TOF
330 //_________________________________________________________________________
331 void AliESDTOFCluster::Print(const Option_t*) const
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);
343 for (int it=0;it<fNmatchableTracks;it++) {
344 AliESDTOFMatch* mt = GetTOFMatch(it);
353 //_________________________________________________________________________
354 AliESDTOFHit* AliESDTOFCluster::GetTOFHit(Int_t i) const
356 return fEvent ? ((AliESDTOFHit *) ((AliESDEvent *) GetEvent())->GetESDTOFHits()->At(fHitIndex[i])):0;
359 //_________________________________________________________________________
360 AliESDTOFMatch* AliESDTOFCluster::GetTOFMatch(Int_t i) const
362 return fEvent ? ((AliESDTOFMatch *) ((AliESDEvent *) GetEvent())->GetESDTOFMatches()->At(fMatchIndex[i])) : 0;
365 //_________________________________________________________________________
366 void AliESDTOFCluster::SuppressMatchedTrack(Int_t id)
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];
377 TClonesArray* arrMatch = ((AliESDEvent *)GetEvent())->GetESDTOFMatches();
378 int last = arrMatch->GetEntriesFast()-1;
379 AliESDTOFMatch* mtcL = (AliESDTOFMatch*)arrMatch->At(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
387 arrMatch->RemoveAt(last);
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);
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);
407 arrHits->RemoveAt(last--);
413 //_________________________________________________________________________
414 void AliESDTOFCluster::ReplaceHitID(int oldID, int newID)
416 // replace the reference to hit from oldID by newID
417 for (int it=fNTOFhits;it--;) {
418 if (fHitIndex[it]==oldID) {
425 //_________________________________________________________________________
426 void AliESDTOFCluster::ReplaceMatchID(int oldID, int newID)
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;
437 //_________________________________________________________________________
438 void AliESDTOFCluster::ReplaceMatchedTrackID(int oldID, int newID)
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);
450 //_________________________________________________________________________
451 void AliESDTOFCluster::FixSelfReferences(int oldID, int newID)
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);
459 for (int it=fNTOFhits;it--;) {
460 AliESDTOFHit* hit = GetTOFHit(it);
461 if (hit) hit->SetESDTOFClusterIndex(newID);