]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONHitMapA1.cxx
Proper deletion of arrays (thanks to Rene Brun)
[u/mrichter/AliRoot.git] / MUON / AliMUONHitMapA1.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 /*
17 $Log$
18 Revision 1.9  2001/03/20 13:34:05  egangler
19 Obvious small bug
20
21 Revision 1.8  2001/01/26 21:47:21  morsch
22 Use access functions to AliMUONDigit member data.
23
24 Revision 1.7  2001/01/25 11:43:48  morsch
25 Add a "real" default constructor.
26
27 Revision 1.6  2000/10/06 09:05:42  morsch
28 Correction on upper limits for x- and y- coordinates to make code work with slat chambers.
29
30 Revision 1.5  2000/10/02 21:28:09  fca
31 Removal of useless dependecies via forward declarations
32
33 Revision 1.4  2000/07/13 16:19:44  fca
34 Mainly coding conventions + some small bug fixes
35
36 Revision 1.3  2000/07/03 11:54:57  morsch
37 AliMUONSegmentation and AliMUONHitMap have been replaced by AliSegmentation and AliHitMap in STEER
38 The methods GetPadIxy and GetPadXxy of AliMUONSegmentation have changed name to GetPadI and GetPadC.
39
40 Revision 1.2  2000/06/15 07:58:48  morsch
41 Code from MUON-dev joined
42
43 Revision 1.1.2.2  2000/06/12 07:58:06  morsch
44 include TMath.h
45
46 Revision 1.1.2.1  2000/06/09 22:01:09  morsch
47 Code from AliMUONHitMap.h
48 Most coding rule violations corrected.
49
50 */
51
52 #include "AliMUONHitMapA1.h"
53 #include "AliSegmentation.h"
54 #include "AliMUONResponse.h"
55 #include "AliMUONDigit.h"
56
57 #include <TObjArray.h>
58 #include <TMath.h>
59
60 ClassImp(AliMUONHitMapA1)
61
62     AliMUONHitMapA1::AliMUONHitMapA1()
63 {
64     // Default constructor
65     fNpx          = 0;
66     fNpy          = 0;
67     fMaxIndex     = 0;
68     
69     fHitMap       = 0;
70     fDigits       = 0;
71 }
72
73 AliMUONHitMapA1::AliMUONHitMapA1(AliSegmentation *seg, TObjArray *dig)
74 {
75 // Constructor
76     fNpx  = seg->Npx()+1;
77     fNpy  = seg->Npy()+1;
78     fMaxIndex=2*(fNpx+1)*2*(fNpy+1)+2*fNpy;
79     
80     fHitMap = new Int_t[fMaxIndex];
81     fDigits =  dig;
82     Clear();
83 }
84
85 AliMUONHitMapA1::AliMUONHitMapA1(const AliMUONHitMapA1 & hitMap)
86 {
87 // Dummy copy constructor
88     ;
89 }
90
91  
92 AliMUONHitMapA1::~AliMUONHitMapA1()
93 {
94 // Destructor
95     if (fHitMap) delete[] fHitMap;
96 }
97
98 void AliMUONHitMapA1::Clear(const char *)
99 {
100 // Clear hitmap
101     memset(fHitMap,0,sizeof(int)*fMaxIndex);
102 }
103
104 Int_t AliMUONHitMapA1::CheckedIndex(Int_t ix, Int_t iy) const
105 {
106 // Return checked indices ix, iy
107     Int_t index=2*fNpy*(ix+fNpx)+(iy+fNpy);
108     if (index >= fMaxIndex) {
109         printf("\n \n \n Try to read/write outside array !!!! \n \n %d %d %d %d %d %d",
110                ix,iy, fMaxIndex, index, fNpx, fNpy);
111         return  fMaxIndex-1;
112     } else {
113         return index;
114     }
115 }
116
117         
118 void  AliMUONHitMapA1::FillHits()
119 {
120 // Fill hits from digits list  
121     Int_t ndigits = fDigits->GetEntriesFast();
122     //printf("\n Filling hits into HitMap\n");
123     //printf("FindRawClusters -- ndigits %d \n",ndigits);
124     if (!ndigits) return;
125     AliMUONDigit *dig;
126     for (Int_t ndig=0; ndig<ndigits; ndig++) {
127         dig = (AliMUONDigit*)fDigits->UncheckedAt(ndig);
128         SetHit(dig->PadX(),dig->PadY(),ndig);
129     }
130 }
131
132
133 void  AliMUONHitMapA1::SetHit(Int_t ix, Int_t iy, Int_t idigit)
134 {
135 // Assign digit to hit cell ix,iy
136 //    fHitMap[kMaxNpady*(ix+fNpx)+(iy+fNpy)]=idigit+1;
137     fHitMap[CheckedIndex(ix, iy)]=idigit+1;
138 }
139
140 void AliMUONHitMapA1::DeleteHit(Int_t ix, Int_t iy)
141 {
142 // Delete hit at cell ix,iy
143 //    fHitMap[kMaxNpady*(ix+fNpx)+(iy+fNpy)]=0;
144     fHitMap[CheckedIndex(ix, iy)]=0;
145 }
146
147 void AliMUONHitMapA1::FlagHit(Int_t ix, Int_t iy)
148 {
149 // Flag hit as used
150     fHitMap[CheckedIndex(ix, iy)]=
151         -TMath::Abs(fHitMap[CheckedIndex(ix, iy)]);
152 }
153
154 Int_t AliMUONHitMapA1::GetHitIndex(Int_t ix, Int_t iy) const
155 {
156 // Get absolute value of contents of hit cell ix,iy
157     return TMath::Abs(fHitMap[CheckedIndex(ix, iy)])-1;
158 }
159
160 TObject* AliMUONHitMapA1::GetHit(Int_t ix, Int_t iy) const
161 {
162     // Get pointer to object at hit cell ix, iy
163     // Force crash if index does not exist ! (Manu)
164     Int_t index=GetHitIndex(ix,iy);
165     return (index <0) ? 0 : fDigits->UncheckedAt(GetHitIndex(ix,iy));
166 }
167
168 FlagType AliMUONHitMapA1::TestHit(Int_t ix, Int_t iy)
169 {
170 // Check if hit cell is empty, used or unused
171 //
172     Int_t inf=fHitMap[CheckedIndex(ix, iy)];
173     if (inf < 0) {
174         return kUsed;
175     } else if (inf == 0) {
176         return kEmpty;
177     } else {
178         return kUnused;
179     }
180 }
181
182 AliMUONHitMapA1 & AliMUONHitMapA1::operator = (const AliMUONHitMapA1 & rhs) 
183 {
184 // Dummy assignment operator
185     return *this;
186 }
187
188
189
190
191