06e743914860a3a582209c9dd789f715701eeb01
[u/mrichter/AliRoot.git] / MUON / AliMUONTrackHit.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 // Reconstructed track hit
21 // in
22 // ALICE
23 // dimuon
24 // spectrometer
25 //
26 ///////////////////////////////////////////////////////
27
28 #include "AliMUONTrackHit.h" 
29 #include "AliMUONHitForRec.h" 
30 #include "AliLog.h" 
31
32 ClassImp(AliMUONTrackHit) // Class implementation in ROOT context
33
34   //__________________________________________________________________________
35 AliMUONTrackHit::AliMUONTrackHit()
36   : TObject(),
37     fTrackParam(),
38     fHitForRecPtr(0x0),
39     fNextTrackHitWithSameHitForRec(0x0),
40     fPrevTrackHitWithSameHitForRec(0x0)
41 {
42 /// Default constructor
43
44 }
45   //__________________________________________________________________________
46 AliMUONTrackHit::AliMUONTrackHit (const AliMUONTrackHit& theMUONTrackHit)
47   : TObject(theMUONTrackHit),
48     fTrackParam(theMUONTrackHit.fTrackParam),
49     fHitForRecPtr(theMUONTrackHit.fHitForRecPtr),
50     fNextTrackHitWithSameHitForRec(theMUONTrackHit.fNextTrackHitWithSameHitForRec),
51     fPrevTrackHitWithSameHitForRec(theMUONTrackHit.fPrevTrackHitWithSameHitForRec)
52 {
53 /// Copy constructor
54
55 }
56   //__________________________________________________________________________
57 AliMUONTrackHit & AliMUONTrackHit::operator=(const AliMUONTrackHit& theMUONTrackHit)
58 {
59 /// Assignment operator
60
61   // check assignement to self
62   if (this == &theMUONTrackHit)
63     return *this;
64
65   // base class assignement
66   TObject::operator=(theMUONTrackHit);
67
68   fTrackParam                    =  theMUONTrackHit.fTrackParam;
69   fHitForRecPtr                  =  theMUONTrackHit.fHitForRecPtr;
70   fNextTrackHitWithSameHitForRec = theMUONTrackHit.fNextTrackHitWithSameHitForRec;
71   fPrevTrackHitWithSameHitForRec = theMUONTrackHit.fPrevTrackHitWithSameHitForRec;
72
73   return *this;
74
75 }
76   //__________________________________________________________________________
77 AliMUONTrackHit::AliMUONTrackHit(AliMUONHitForRec* Hit)
78   : TObject(),
79     fTrackParam(),
80     fHitForRecPtr(Hit),
81     fNextTrackHitWithSameHitForRec(0x0),
82     fPrevTrackHitWithSameHitForRec(0x0)
83 {
84 /// Constructor from the HitForRec pointed to by "Hit"
85
86   // links from/to HitForRec
87   if (Hit->GetNTrackHits() == 0) {
88     fPrevTrackHitWithSameHitForRec = NULL;
89     Hit->SetFirstTrackHitPtr(this);
90   }
91   else {
92     fPrevTrackHitWithSameHitForRec = Hit->GetLastTrackHitPtr();
93     fNextTrackHitWithSameHitForRec = NULL;
94   }
95   Hit->SetLastTrackHitPtr(this);
96   fNextTrackHitWithSameHitForRec = NULL;
97   Hit->SetNTrackHits(Hit->GetNTrackHits() + 1);
98 }
99   //__________________________________________________________________________
100 AliMUONTrackHit::~AliMUONTrackHit()
101 {
102 /// Destructor
103 /// Update links between HitForRec's and TrackHit's
104 /// connected to the current TrackHit being removed.
105
106   AliMUONHitForRec *hit = fHitForRecPtr; // pointer to HitForRec
107   // remove current TrackHit in HitForRec links
108   if (this == hit->GetFirstTrackHitPtr())
109     hit->SetFirstTrackHitPtr(fNextTrackHitWithSameHitForRec); // if first
110   if (this == hit->GetLastTrackHitPtr())
111     hit->SetLastTrackHitPtr(fPrevTrackHitWithSameHitForRec); // if last
112   hit->SetNTrackHits(hit->GetNTrackHits() - 1); // decrement NTrackHits of hit
113   // update link to next TrackHit of previous TrackHit
114   if (fPrevTrackHitWithSameHitForRec != NULL)
115     fPrevTrackHitWithSameHitForRec->
116       SetNextTrackHitWithSameHitForRec(fNextTrackHitWithSameHitForRec);
117   // update link to previous TrackHit of next TrackHit
118   if (fNextTrackHitWithSameHitForRec)
119     fNextTrackHitWithSameHitForRec->
120       SetPrevTrackHitWithSameHitForRec(fPrevTrackHitWithSameHitForRec);
121   // to be checked thoroughly !!!!
122   // with Root counter of AliMUONTrackHit objects,
123   // with loop over all these links after the update
124 }
125
126   //__________________________________________________________________________
127 Int_t AliMUONTrackHit::Compare(const TObject* TrackHit) const
128 {
129 /// "Compare" function to sort with decreasing Z (spectro. muon Z <0).
130 /// Returns 1 (0, -1) if Z of current TrackHit
131 /// is smaller than (equal to, larger than) Z of TrackHit
132
133   if (fHitForRecPtr->GetZ() <
134       ((AliMUONTrackHit*)TrackHit)->fHitForRecPtr->GetZ()) return(1);
135   else if (fHitForRecPtr->GetZ() ==
136            ((AliMUONTrackHit*)TrackHit)->fHitForRecPtr->GetZ()) return( 0);
137   else return(-1);
138 }