]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONDigitMapA1.cxx
Typo corrected.
[u/mrichter/AliRoot.git] / MUON / AliMUONDigitMapA1.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 // Class AliMUONDigitMapA1
20 // ---------------------------
21 // Implements cluster Map as a 1-dim array
22 // Author: Christian Finck
23
24 #include "AliMUONDigitMapA1.h"
25 #include "AliMUONDigit.h"
26
27 #include "AliLog.h"
28
29 #include <TObjArray.h>
30 #include <TMath.h>
31
32 /// \cond CLASSIMP
33 ClassImp(AliMUONDigitMapA1)
34 /// \endcond
35
36 AliMUONDigitMapA1::AliMUONDigitMapA1() 
37   : fIdDE(0),
38     fNpx(0),
39     fNpy(0),
40     fDigits(0),
41     fMaxIndex(0),
42     fHitMap(0)
43 {
44 /// Default constructor
45
46 }
47 //________________________________________________________________________________
48 AliMUONDigitMapA1::AliMUONDigitMapA1(Int_t idDE, Int_t npx, Int_t npy )
49   : fIdDE(idDE),
50     fNpx(npx),
51     fNpy(npy),
52     fDigits(0),
53     fMaxIndex(fNpx * fNpy + fNpx),
54     fHitMap(new Int_t[fMaxIndex])
55 {
56 /// Standard constructor
57    Clear();
58 }
59
60 //_________________________________
61 AliMUONDigitMapA1::~AliMUONDigitMapA1()
62 {
63 /// Destructor
64     if (fHitMap) delete[] fHitMap;
65 }
66 //______________________________________
67 void AliMUONDigitMapA1::Clear(const char *)
68 {
69 /// Clear hitmap
70     memset(fHitMap,0,sizeof(int)*fMaxIndex);
71 }
72
73 //_________________________________________________________
74 Int_t AliMUONDigitMapA1::CheckedIndex(Int_t ix, Int_t iy) const
75 {
76 /// Return checked indices ix, iy
77   Int_t index =  iy * fNpx + ix;
78     if ( index < 0 || index >= fMaxIndex ) {
79       AliWarning(Form("index outside array idDE %d ix %d iy %d MaxIndex %d index %d Npx %d Npy %d",
80                       fIdDE, ix,iy, fMaxIndex, index, fNpx, fNpy));
81         return  fMaxIndex-1;
82     } else {
83         return index;
84     }
85 }
86 //_____________________________
87 void  AliMUONDigitMapA1::FillHits(TObjArray* digits)
88 {
89 /// Fill hits from digits list  
90     fDigits = digits;
91     Int_t ndigits = fDigits->GetEntriesFast();
92     if (!ndigits) return;
93     AliMUONDigit *dig;
94     for (Int_t ndig = 0; ndig < ndigits; ndig++) {
95         dig = (AliMUONDigit*)fDigits->UncheckedAt(ndig);
96         SetHit(dig->PadX(),dig->PadY(),ndig);
97     }
98 }
99 //___________________________________________________________
100 void  AliMUONDigitMapA1::SetHit(Int_t ix, Int_t iy, Int_t idigit)
101 {
102 /// Assign digit to hit cell ix,iy
103
104     fHitMap[CheckedIndex(ix, iy)] = idigit + 1;
105 }
106 //_______________________________________________
107 void AliMUONDigitMapA1::DeleteHit(Int_t ix, Int_t iy)
108 {
109 /// Delete hit at cell ix,iy
110
111     fHitMap[CheckedIndex(ix, iy)]=0;
112 }
113 //_____________________________________________
114 void AliMUONDigitMapA1::FlagHit(Int_t ix, Int_t iy)
115 {
116 /// Flag hit as used
117     fHitMap[CheckedIndex(ix, iy)]=
118         -TMath::Abs(fHitMap[CheckedIndex(ix, iy)]);
119 }
120 //________________________________________________________
121 Int_t AliMUONDigitMapA1::GetHitIndex(Int_t ix, Int_t iy) const
122 {
123 /// Get absolute value of contents of hit cell ix,iy
124     return TMath::Abs(fHitMap[CheckedIndex(ix, iy)])-1;
125 }
126 //_______________________________________________________
127 TObject* AliMUONDigitMapA1::GetHit(Int_t ix, Int_t iy) const
128 {
129 /// Get pointer to object at hit cell ix, iy
130 /// Force crash if index does not exist ! (Manu)
131     Int_t index = GetHitIndex(ix,iy);
132     return (index <0) ? 0 : fDigits->UncheckedAt(GetHitIndex(ix,iy));
133 }
134 //_________________________________________________
135 FlagType AliMUONDigitMapA1::TestHit(Int_t ix, Int_t iy) const
136 {
137 /// Check if hit cell is empty, used or unused
138
139     Int_t index = CheckedIndex(ix, iy);
140     if (index<0 || index >= fMaxIndex) return kEmpty;
141
142     Int_t inf = fHitMap[index];
143     if (inf < 0) {
144         return kUsed;
145     } else if (inf == 0) {
146         return kEmpty;
147     } else {
148         return kUnused;
149     }
150 }