]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TOF/AliTOFDigitMap.cxx
Add classes for TOF Calibration (C.Zampolli)
[u/mrichter/AliRoot.git] / TOF / AliTOFDigitMap.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 ////////////////////////////////////////////////////////////////////////
18 //
19 // AliTOFDigitMap class
20 //
21 // digitmap enables fast check if the pad was already hit
22 // The index of a AliTOFdigit is saved in the each hitmap "cell"
23 // (there is an offset +1, because the index can be zero and 
24 // zero means empty cell. 
25 // In TOF, number of strips varies according plate type, the highest
26 // number is in plate C. For all plates is used this number, so
27 // the size of the digitmap is a little bit greater than necessary, but
28 // it simplifies the access algorithm. 
29 // 
30 //
31 // Author: F. Pierella based on AliTOFHitMap
32 //
33 ////////////////////////////////////////////////////////////////////////
34
35 #include <Riostream.h>
36 #include <TMath.h>
37
38 #include "AliTOFDigitMap.h"
39 #include "AliTOFdigit.h"
40 #include "AliTOFGeometry.h"
41
42
43 #include <TClonesArray.h>
44
45 ClassImp(AliTOFDigitMap)
46
47 AliTOFDigitMap::AliTOFDigitMap()
48 {
49 //
50 // Default ctor
51 //
52   fDigitMap = 0;
53   fDigits = 0;
54
55   fTOFGeometry = new AliTOFGeometry();
56
57 }
58
59 ////////////////////////////////////////////////////////////////////////
60 AliTOFDigitMap::AliTOFDigitMap(TClonesArray *dig, AliTOFGeometry *tofGeom)
61 {
62   //
63   // ctor
64   //  
65   // of course, these constants must not be hardwired
66   // change later
67   
68   fTOFGeometry = tofGeom;
69
70   fNSector = AliTOFGeometry::NSectors();
71   fNplate = AliTOFGeometry::NPlates();
72   fNstrip = fTOFGeometry->NMaxNstrip();
73   fNpx  = AliTOFGeometry::NpadX();
74   fNpz  = AliTOFGeometry::NpadZ();
75   fMaxIndex=fNSector*fNplate*fNstrip*fNpx*fNpz;
76   fDigitMap = new Int_t[fMaxIndex];
77   fDigits =  dig;
78   Clear();
79 }
80
81 ////////////////////////////////////////////////////////////////////////
82 AliTOFDigitMap::AliTOFDigitMap(const AliTOFDigitMap & /*digitMap*/)
83 :TObject()
84 {
85 //
86 // Dummy copy constructor
87 //
88   ;
89
90 }
91
92  
93 ////////////////////////////////////////////////////////////////////////
94 AliTOFDigitMap::~AliTOFDigitMap()
95 {
96 //
97 // Destructor
98 //
99   if (fDigitMap) delete[] fDigitMap;
100
101   fTOFGeometry = 0;
102
103 }
104
105 ////////////////////////////////////////////////////////////////////////
106 void AliTOFDigitMap::Clear(const char *)
107 {
108 //
109 // Clear hitmap
110 //
111     memset(fDigitMap,0,sizeof(int)*fMaxIndex);
112 }
113
114 ////////////////////////////////////////////////////////////////////////
115 Int_t AliTOFDigitMap::CheckedIndex(Int_t *vol) const
116 {
117 //
118 // Return checked indices for vol
119 //
120   Int_t index=
121     vol[0]*fNplate*fNstrip*fNpx*fNpz+             // sector
122     vol[1]*fNstrip*fNpx*fNpz+                     // plate
123     vol[2]*fNpx*fNpz+                             // strip
124     vol[3]*fNpz+                                  // padx
125     vol[4];                                       // padz
126
127     if (index >= fMaxIndex) {
128       Error("AliTOFDigitMap","CheckedIndex - input outside bounds");
129         return -1;
130     } else {
131         return index;
132     }
133 }
134
135 ////////////////////////////////////////////////////////////////////////
136 void  AliTOFDigitMap::SetHit(Int_t *vol, Int_t idigit)
137 {
138 //
139 // Assign digit to pad vol
140 //
141
142 // 0 means empty pad, we need to shift indeces by 1
143     fDigitMap[CheckedIndex(vol)]=idigit+1;
144 }
145
146 ////////////////////////////////////////////////////////////////////////
147 void  AliTOFDigitMap::SetHit(Int_t *vol)
148 {
149 //
150 // Assign last digit to pad vol 
151 //
152
153 // 0 means empty pad, we need to shift indeces by 1
154     fDigitMap[CheckedIndex(vol)]=fDigits->GetLast()+1;
155 }
156
157 ////////////////////////////////////////////////////////////////////////
158 Int_t AliTOFDigitMap::GetHitIndex(Int_t *vol) const
159 {
160 //
161 // Get contents of pad vol
162 //
163
164 // 0 means empty pad, we need to shift indeces by 1
165     return fDigitMap[CheckedIndex(vol)]-1;
166 }
167
168 ////////////////////////////////////////////////////////////////////////
169 TObject* AliTOFDigitMap::GetHit(Int_t *vol) const
170 {
171 //
172 // Get pointer to object at vol
173 // return 0 if vol out of bounds
174     Int_t index=GetHitIndex(vol);
175     return (index <0) ? 0 : fDigits->UncheckedAt(index);
176 }
177
178 ////////////////////////////////////////////////////////////////////////
179 FlagType AliTOFDigitMap::TestHit(Int_t *vol) const
180 {
181 //
182 // Check if hit cell is empty, used or unused
183 //
184     Int_t inf=fDigitMap[CheckedIndex(vol)];
185     if (inf > 0) {
186         return kUsed;
187     } else if (inf == 0) {
188         return kEmpty;
189     } else {
190         return kUnused;
191     }
192 }
193
194 ////////////////////////////////////////////////////////////////////////
195 AliTOFDigitMap & AliTOFDigitMap::operator = (const AliTOFDigitMap & /*rhs*/) 
196 {
197 // Dummy assignment operator
198     return *this;
199 }