LCOV - code coverage report
Current view: top level - STEER/ESD - AliESDTOFCluster.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 35 187 18.7 %
Date: 2016-06-14 17:26:59 Functions: 13 44 29.5 %

          Line data    Source code
       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         172 : ClassImp(AliESDTOFCluster)
      26             : 
      27             : //_________________________________________________________________________
      28         180 : AliESDTOFCluster::AliESDTOFCluster(Int_t clID) :
      29         180 :   fID(clID),
      30         180 :   fNTOFhits(0),
      31         180 :   fStatus(0),
      32         180 :   fNmatchableTracks(0)
      33         900 : {
      34             :   //
      35             :   // default ctor
      36             :   //
      37             : 
      38        1800 :   for(Int_t i=kMaxHits;i--;)    fHitIndex[i] = -1;
      39        2880 :   for(Int_t i=kMaxMatches;i--;) fMatchIndex[i] = -1;
      40         360 : }
      41             : 
      42             : //_________________________________________________________________________
      43           0 : 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           0 :   fID(-1),
      47           0 :   fNTOFhits(0),
      48           0 :   fStatus(1),
      49           0 :   fNmatchableTracks(1)
      50           0 : {
      51             :   //
      52             :   // Constructor of AliESDTOFCluster object
      53             :   //
      54             : 
      55             :   // to be replaced with hit creation
      56           0 :   for(Int_t i=kMaxHits;i--;) fHitIndex[i] = -1;
      57           0 :   for(Int_t i=kMaxMatches;i--;) fMatchIndex[i] = -1;
      58             :   //
      59           0 : }
      60             : 
      61             : //_________________________________________________________________________
      62           0 : 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           0 :   fID(-1),
      65           0 :   fNTOFhits(0),
      66           0 :   fStatus(1),
      67           0 :   fNmatchableTracks(0)
      68           0 : {
      69             :   //
      70             :   // Constructor of AliESDTOFCluster object
      71             :   //
      72             : 
      73             :   // to be replaced with hit creation
      74           0 :   for(Int_t i=kMaxHits;i--;) fHitIndex[i] = -1;
      75           0 :   for(Int_t i=kMaxMatches;i--;) fMatchIndex[i] = -1;
      76             : 
      77           0 : }
      78             : 
      79             : //_________________________________________________________________________
      80             : AliESDTOFCluster::AliESDTOFCluster(const AliESDTOFCluster & source) :
      81           0 :   AliVTOFcluster(source),
      82           0 :   fID(source.fID),
      83           0 :   fNTOFhits(source.fNTOFhits),
      84           0 :   fStatus(source.fStatus),
      85           0 :   fNmatchableTracks(source.fNmatchableTracks)
      86           0 : {
      87             :   // 
      88             :   // copy ctor for AliESDTOFCluster object
      89             :   //
      90             : 
      91           0 :   SetEvent(source.GetEvent());
      92             : 
      93           0 :   for(Int_t i=kMaxHits;i--;)    fHitIndex[i] = source.fHitIndex[i];
      94           0 :   for(Int_t i=kMaxMatches;i--;) fMatchIndex[i] = source.fMatchIndex[i];
      95             : 
      96           0 : }
      97             : 
      98             : //_________________________________________________________________________
      99             : AliESDTOFCluster & AliESDTOFCluster::operator=(const AliESDTOFCluster & source)
     100             : {
     101             :   // 
     102             :   // assignment op-r
     103             :   //
     104           0 :   if (this == &source) return *this;
     105           0 :   AliVTOFcluster::operator=(source);
     106           0 :   fID = source.fID;
     107           0 :   fNTOFhits = source.fNTOFhits;
     108           0 :   fStatus = source.fStatus;
     109           0 :   fNmatchableTracks = source.fNmatchableTracks;
     110             : 
     111           0 :   for(Int_t i=kMaxHits;i--;)    fHitIndex[i] = source.fHitIndex[i];
     112           0 :   for(Int_t i=kMaxMatches;i--;) fMatchIndex[i] = source.fMatchIndex[i];
     113             : 
     114           0 :   return *this;
     115           0 : }
     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         426 :   if(fNmatchableTracks >= kMaxMatches) return 2; // max number reached
     125             :   //
     126             :   // check if the track is not already stored
     127         770 :   for (Int_t ii=fNmatchableTracks; ii--;) if (trackIndex==GetTrackIndex(ii)) return 1;
     128             :   //
     129         132 :   const AliESDEvent *event = (AliESDEvent *) GetEvent();
     130         132 :   TClonesArray *matchAr = event->GetESDTOFMatches();
     131         132 :   int ntr = matchAr->GetEntriesFast();
     132         132 :   new((*matchAr)[ntr]) AliESDTOFMatch(trackIndex,expTimes,dX,dY,dZ,length);
     133         132 :   int nmt = fNmatchableTracks++;
     134         132 :   fMatchIndex[nmt] = ntr;
     135             :   //
     136             :   return 0;
     137             :   //
     138         213 : }
     139             : 
     140             : //_________________________________________________________________________
     141             : void AliESDTOFCluster::AddESDTOFHitIndex(Int_t hitID)
     142             : {
     143             :   // register new hit in the cluster
     144         224 :   if(fNTOFhits >= kMaxHits) return;
     145         112 :   int nth = fNTOFhits++;
     146         112 :   fHitIndex[nth] = hitID; // add the hit to the array
     147         224 : }
     148             : 
     149             : //_________________________________________________________________________
     150             : void AliESDTOFCluster::AddTOFhit(AliESDTOFHit *hit)
     151             : {
     152             :   // add new hit
     153           0 :   if(fNTOFhits >= kMaxHits) return;
     154             :   // add the hit to the array
     155           0 :   const AliESDEvent *event = (AliESDEvent *) GetEvent();
     156           0 :   TClonesArray *hitAr = event->GetESDTOFHits();
     157           0 :   int nh = hitAr->GetEntriesFast();
     158           0 :   new((*hitAr)[nh]) AliESDTOFHit(*hit);
     159             :   //   hitN->SetIndex(nh); // RS: why do we need this
     160           0 :   int nth = fNTOFhits++;
     161           0 :   fHitIndex[nth] = nh;
     162             :   //
     163           0 : }
     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           0 : }
     169             : 
     170             : //_________________________________________________________________________
     171             : Int_t AliESDTOFCluster::GetClusterIndex(int ihit) const
     172             : {
     173           0 :   AliESDTOFHit* hit = GetTOFHit(ihit);
     174           0 :   return hit ? hit->GetClusterIndex() : -1;
     175             : } 
     176             : 
     177             : //_________________________________________________________________________
     178             : Int_t AliESDTOFCluster::GetTOFchannel(int ihit) const 
     179             : {
     180           0 :   AliESDTOFHit* hit = GetTOFHit(ihit);
     181           0 :   return hit ? hit->GetTOFchannel() : -1;
     182             : }
     183             : 
     184             : //_________________________________________________________________________
     185             : Float_t AliESDTOFCluster::GetTime(int ihit) const 
     186             : {
     187        3282 :   AliESDTOFHit* hit = GetTOFHit(ihit);
     188        4923 :   return hit ? hit->GetTime() : 0;
     189             : }
     190             : 
     191             : //_________________________________________________________________________
     192             : Float_t AliESDTOFCluster::GetTimeRaw(Int_t ihit) const 
     193             : {
     194           0 :  AliESDTOFHit* hit = GetTOFHit(ihit);
     195           0 :  return hit ? hit->GetTimeRaw() : 0;
     196             : } // TOF raw time
     197             : 
     198             : //_________________________________________________________________________
     199             : Float_t AliESDTOFCluster::GetTOT(Int_t ihit) const 
     200             : {
     201           0 :   AliESDTOFHit* hit = GetTOFHit(ihit);
     202           0 :   return hit ? hit->GetTOT() : 0;
     203             : } // TOF tot
     204             : 
     205             : //_________________________________________________________________________
     206             : Float_t AliESDTOFCluster::GetTOFsignalToT(Int_t ihit) const 
     207             : {
     208           0 :   AliESDTOFHit* hit = GetTOFHit(ihit);
     209           0 :   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        1014 :   AliESDTOFHit* hit = GetTOFHit(ihit);
     216         507 :   if (!hit || i>=3) return -999;
     217         507 :   return hit->GetTOFLabel(i);
     218         507 : }
     219             : 
     220             : //_________________________________________________________________________
     221             : Int_t AliESDTOFCluster::GetDeltaBC(Int_t ihit) const 
     222             : {
     223           0 :   AliESDTOFHit* hit = GetTOFHit(ihit);
     224           0 :   return hit ? hit->GetDeltaBC() : 0;
     225             : }
     226             : 
     227             : //_________________________________________________________________________
     228             : Int_t AliESDTOFCluster::GetL0L1Latency(Int_t ihit) const 
     229             : {
     230           0 :   AliESDTOFHit* hit = GetTOFHit(ihit);  
     231           0 :   return hit ? hit->GetL0L1Latency() : 0;
     232             : }
     233             : 
     234             : //_________________________________________________________________________
     235             : Bool_t AliESDTOFCluster::GetStatus() const 
     236             : {
     237           0 :   if(!fEvent){
     238           0 :     AliInfo("No AliESDEvent available here!");
     239           0 :     return 0;
     240             :   }
     241           0 :   return fStatus;
     242           0 : }
     243             : 
     244             : //_________________________________________________________________________
     245             : Float_t AliESDTOFCluster::GetZ() const 
     246             : {
     247           0 :   AliESDTOFHit* hit = GetTOFHit(0);
     248           0 :   return hit ? hit->GetZ() : 0;
     249             : }
     250             : 
     251             : //_________________________________________________________________________
     252             : Float_t AliESDTOFCluster::GetPhi() const 
     253             : {
     254           0 :   AliESDTOFHit* hit = GetTOFHit(0);
     255           0 :   return hit ? hit->GetPhi() : 0;
     256             : }
     257             : 
     258             : //_________________________________________________________________________
     259             : Float_t AliESDTOFCluster::GetR() const 
     260             : {
     261           0 :   AliESDTOFHit* hit = GetTOFHit(0);
     262           0 :   return hit ? hit->GetR() : 0;
     263             : }
     264             : 
     265             : //_________________________________________________________________________
     266             : Int_t AliESDTOFCluster::GetNMatchableTracks() const 
     267             : {
     268       10188 :   return fNmatchableTracks;
     269             : }
     270             : 
     271             : //_________________________________________________________________________
     272             : Int_t AliESDTOFCluster::GetNTOFhits() const 
     273             : {
     274           0 :   return fNTOFhits;
     275             : }
     276             : 
     277             : //_________________________________________________________________________
     278             : Int_t AliESDTOFCluster::GetTrackIndex(Int_t i) const 
     279             : {
     280             :   AliESDTOFMatch* match = 0;
     281       17710 :   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           0 :   if (i>=fNmatchableTracks || !(match=GetTOFMatch(i))) return -999;
     290           0 :   Double_t dz = match->GetDz();
     291           0 :   Double_t dx = match->GetDx();
     292           0 :   return TMath::Sqrt(dx*dx+dz*dz);
     293           0 : }
     294             : 
     295             : //_________________________________________________________________________
     296             : Float_t AliESDTOFCluster::GetDx(Int_t i)  const 
     297             : {
     298             :   AliESDTOFMatch* match = 0;  
     299           0 :   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           0 :   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           0 :   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        8990 :   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       54800 :   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           0 :   printf("#%5d TOF Cluster %5d of %d Hits, %d Matchable Tracks\n",GetESDID(),fID, fNTOFhits, fNmatchableTracks);
     335           0 :   for (int ih=0;ih<fNTOFhits;ih++) {
     336           0 :     AliESDTOFHit* ht = GetTOFHit(ih);
     337           0 :     if (ht) {
     338           0 :       printf("%d: ",ih);
     339           0 :       ht->Print();
     340           0 :     }
     341             :   }
     342             :   //
     343           0 :   for (int it=0;it<fNmatchableTracks;it++) {
     344           0 :     AliESDTOFMatch* mt = GetTOFMatch(it);
     345           0 :     if (mt) {
     346           0 :       printf("%d: ",it);
     347           0 :       mt->Print();
     348           0 :     }
     349             :   }
     350             :   //
     351           0 : }
     352             : 
     353             : //_________________________________________________________________________
     354             : AliESDTOFHit* AliESDTOFCluster::GetTOFHit(Int_t i) const
     355             : {
     356        8592 :   return fEvent ? ((AliESDTOFHit *) ((AliESDEvent *) GetEvent())->GetESDTOFHits()->At(fHitIndex[i])):0;
     357             : }
     358             : 
     359             : //_________________________________________________________________________
     360             : AliESDTOFMatch* AliESDTOFCluster::GetTOFMatch(Int_t i) const 
     361             : {
     362       65200 :   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           0 :   for (int it=fNmatchableTracks;it--;) {
     370           0 :     AliESDTOFMatch* mtc = GetTOFMatch(it);
     371           0 :     if (mtc->GetTrackIndex()!=id) continue;
     372             :     // need to suprress the match: simply remove reference to it
     373           0 :     int rmID = fMatchIndex[it];
     374           0 :     for (int jt=it+1;jt<fNmatchableTracks;jt++) fMatchIndex[jt-1] = fMatchIndex[jt];
     375           0 :     fNmatchableTracks--;
     376             :     // remove match rmID
     377           0 :     TClonesArray* arrMatch = ((AliESDEvent *)GetEvent())->GetESDTOFMatches();
     378           0 :     int last = arrMatch->GetEntriesFast()-1;
     379           0 :     AliESDTOFMatch* mtcL = (AliESDTOFMatch*)arrMatch->At(last);
     380           0 :     if (rmID!=last) {
     381           0 :       *mtc = *mtcL; // assign the last match to removed slot
     382           0 :       int trID = mtc->GetTrackIndex();
     383           0 :       AliESDtrack* trc = ((AliESDEvent *)GetEvent())->GetTrack(trID);
     384           0 :       trc->ReplaceTOFMatchID(last,rmID); // fix the reference to reassigned match
     385             :       // fix the 
     386           0 :     }
     387           0 :     arrMatch->RemoveAt(last);
     388             :     break;
     389             :   }
     390             :   //
     391           0 :   if (!fNmatchableTracks) { // no matches left, clear all hits: prepare for selfelimination
     392             :     // first remove associated hits
     393           0 :     TClonesArray* arrHits = ((AliESDEvent *)GetEvent())->GetESDTOFHits();
     394           0 :     TClonesArray* arrClus = ((AliESDEvent *)GetEvent())->GetESDTOFClusters();
     395           0 :     int last = arrHits->GetEntriesFast()-1;
     396           0 :     for (;fNTOFhits--;) { // remove hits
     397           0 :       int hID = fHitIndex[int(fNTOFhits)];
     398           0 :       AliESDTOFHit* hit = (AliESDTOFHit*)arrHits->At(hID);
     399           0 :       AliESDTOFHit* hitL = (AliESDTOFHit*)arrHits->At(last);
     400           0 :       if (hID!=last) {
     401           0 :         *hit = *hitL; // assign the last match to removed slot
     402             :         // fix reference on hitL in the owner cluster
     403           0 :         int clID = hit->GetESDTOFClusterIndex();
     404           0 :         AliESDTOFCluster* clusL = (AliESDTOFCluster*)arrClus->At(clID);
     405           0 :         clusL->ReplaceHitID(last,hID);
     406           0 :       }
     407           0 :       arrHits->RemoveAt(last--);
     408             :     }
     409           0 :   }
     410             : 
     411           0 : }
     412             : 
     413             : //_________________________________________________________________________
     414             : void AliESDTOFCluster::ReplaceHitID(int oldID, int newID)
     415             : {
     416             :   // replace the reference to hit from oldID by newID
     417           0 :   for (int it=fNTOFhits;it--;) {
     418           0 :     if (fHitIndex[it]==oldID) {
     419           0 :       fHitIndex[it]=newID;
     420           0 :       return;
     421             :     }
     422             :   }
     423           0 : }
     424             : 
     425             : //_________________________________________________________________________
     426             : void AliESDTOFCluster::ReplaceMatchID(int oldID, int newID)
     427             : {
     428             :   // replace the reference to match from oldID by newID
     429           0 :   for (int it=fNmatchableTracks;it--;) {
     430           0 :     if (fMatchIndex[it]==oldID) {
     431           0 :       fMatchIndex[it]=newID;
     432           0 :       return;
     433             :     }
     434             :   }
     435           0 : }
     436             : 
     437             : //_________________________________________________________________________
     438             : void AliESDTOFCluster::ReplaceMatchedTrackID(int oldID, int newID)
     439             : {
     440             :   // replace the reference to track oldID by newID
     441           0 :   for (int it=fNmatchableTracks;it--;) {
     442           0 :     AliESDTOFMatch* mtc = GetTOFMatch(it);
     443           0 :     if (mtc->GetTrackIndex()!=oldID) continue;
     444           0 :     mtc->SetTrackIndex(newID);
     445           0 :     break;
     446             :   }
     447             :   //
     448           0 : }
     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           0 :   for (int it=fNmatchableTracks;it--;) {
     455           0 :     int trID = GetTOFMatch(it)->GetTrackIndex();
     456           0 :     AliESDtrack* trc = ((AliESDEvent *)GetEvent())->GetTrack(trID);
     457           0 :     trc->ReplaceTOFClusterID(oldID,newID);
     458             :   }
     459           0 :   for (int it=fNTOFhits;it--;) {
     460           0 :     AliESDTOFHit* hit = GetTOFHit(it);
     461           0 :     if (hit) hit->SetESDTOFClusterIndex(newID);
     462             :   }
     463             :   //
     464           0 : }

Generated by: LCOV version 1.11