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