]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TOF/AliTOFHitMap.cxx
iostream.h replaced by Riostream.h
[u/mrichter/AliRoot.git] / TOF / AliTOFHitMap.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.5  2002/10/14 14:57:42  hristov
19 Merging the VirtualMC branch to the main development branch (HEAD)
20
21 Revision 1.3.6.1  2002/07/24 11:07:40  alibrary
22 Updating VirtualMC
23
24 Revision 1.4  2002/07/24 09:38:28  vicinanz
25 Fixed (ininfluential) bug on TestHit method
26
27 Revision 1.3  2001/12/19 09:33:32  hristov
28 Index corrected
29
30 Revision 1.2  2001/11/22 11:30:30  hristov
31 Correct log field
32
33 Revision 1.1  2001/11/22 11:22:51  hristov
34 Updated version of TOF digitization, N^2 problem solved (J.Chudoba)
35
36 */
37
38 ////////////////////////////////////////////////////////////////////////
39 //
40 // AliTOFHitMap class
41 //
42 // hitmap enables fast check if the pad was already hit
43 // The index of a AliTOFSDigit is saved in the each hitmap "cell"
44 // (there is an offset +1, because the index can be zero and 
45 // zero means empty cell. 
46 // In TOF, number of strips varies according plate type, the highest
47 // number is in plate C. For all plates is used this number, so
48 // the size of the hitmap is a little bit greater than necessary, but
49 // it simplifies the access algorithm. 
50 // 
51 //
52 // Author: Jiri Chudoba (CERN), based on AliMUONHitMap
53 //
54 ////////////////////////////////////////////////////////////////////////
55
56 #include <Riostream.h>
57 #include <TMath.h>
58
59 #include "AliTOFHitMap.h"
60 #include "AliTOFSDigit.h"
61 #include "AliTOFConstants.h"
62
63
64 #include <TClonesArray.h>
65
66 ClassImp(AliTOFHitMap)
67
68 AliTOFHitMap::AliTOFHitMap()
69 {
70 //
71 // Default ctor
72 //
73   fHitMap = 0;
74   fSDigits = 0;
75 }
76
77 ////////////////////////////////////////////////////////////////////////
78 AliTOFHitMap::AliTOFHitMap(TClonesArray *dig)
79 {
80 //
81 // ctor
82 //
83
84 // of course, these constants must not be hardwired
85 // change later
86
87   fNSector = AliTOFConstants::fgkNSectors;
88   fNplate = AliTOFConstants::fgkNPlates;
89   fNstrip = AliTOFConstants::fgkNStripC;
90   fNpx  = AliTOFConstants::fgkNpadX;
91   fNpy  = AliTOFConstants::fgkNpadZ;
92   fMaxIndex=fNSector*fNplate*fNstrip*fNpx*fNpy;
93   fHitMap = new Int_t[fMaxIndex];
94   fSDigits =  dig;
95   Clear();
96 }
97
98 ////////////////////////////////////////////////////////////////////////
99 AliTOFHitMap::AliTOFHitMap(const AliTOFHitMap & hitMap)
100 {
101 //
102 // Dummy copy constructor
103 //
104     ;
105 }
106
107  
108 ////////////////////////////////////////////////////////////////////////
109 AliTOFHitMap::~AliTOFHitMap()
110 {
111 //
112 // Destructor
113 //
114     if (fHitMap) delete[] fHitMap;
115 }
116
117 ////////////////////////////////////////////////////////////////////////
118 void AliTOFHitMap::Clear(const char *)
119 {
120 //
121 // Clear hitmap
122 //
123     memset(fHitMap,0,sizeof(int)*fMaxIndex);
124 }
125
126 ////////////////////////////////////////////////////////////////////////
127 Int_t AliTOFHitMap::CheckedIndex(Int_t *vol) const
128 {
129 //
130 // Return checked indices for vol
131 //
132   Int_t index=
133     (vol[0]-1)*fNplate*fNstrip*fNpx*fNpy+             // sector
134     (vol[1]-1)*fNstrip*fNpx*fNpy+                     // plate
135     (vol[2]-1)*fNpx*fNpy+                             // strip
136     (vol[3]-1)*fNpy+                                  // padx
137     (vol[4]-1);                                        // pady (=padz)
138
139     if (index >= fMaxIndex) {
140       Error("AliTOFHitMap","CheckedIndex - input outside bounds");
141         return -1;
142     } else {
143         return index;
144     }
145 }
146
147 ////////////////////////////////////////////////////////////////////////
148 void  AliTOFHitMap::SetHit(Int_t *vol, Int_t idigit)
149 {
150 //
151 // Assign digit to pad vol
152 //
153
154 // 0 means empty pad, we need to shift indeces by 1
155     fHitMap[CheckedIndex(vol)]=idigit+1;
156 }
157
158 ////////////////////////////////////////////////////////////////////////
159 void  AliTOFHitMap::SetHit(Int_t *vol)
160 {
161 //
162 // Assign last digit to pad vol 
163 //
164
165 // 0 means empty pad, we need to shift indeces by 1
166     fHitMap[CheckedIndex(vol)]=fSDigits->GetLast()+1;
167 }
168
169 ////////////////////////////////////////////////////////////////////////
170 Int_t AliTOFHitMap::GetHitIndex(Int_t *vol) const
171 {
172 //
173 // Get contents of pad vol
174 //
175
176 // 0 means empty pad, we need to shift indeces by 1
177     return fHitMap[CheckedIndex(vol)]-1;
178 }
179
180 ////////////////////////////////////////////////////////////////////////
181 TObject* AliTOFHitMap::GetHit(Int_t *vol) const
182 {
183 //
184 // Get pointer to object at vol
185 // return 0 if vol out of bounds
186     Int_t index=GetHitIndex(vol);
187     return (index <0) ? 0 : fSDigits->UncheckedAt(index);
188 }
189
190 ////////////////////////////////////////////////////////////////////////
191 FlagType AliTOFHitMap::TestHit(Int_t *vol) const
192 {
193 //
194 // Check if hit cell is empty, used or unused
195 //
196     Int_t inf=fHitMap[CheckedIndex(vol)];
197     if (inf > 0) {
198         return kUsed;
199     } else if (inf == 0) {
200         return kEmpty;
201     } else {
202         return kUnused;
203     }
204 }
205
206 ////////////////////////////////////////////////////////////////////////
207 AliTOFHitMap & AliTOFHitMap::operator = (const AliTOFHitMap & rhs) 
208 {
209 // Dummy assignment operator
210     return *this;
211 }
212
213
214
215
216