]>
Commit | Line | Data |
---|---|---|
5f91c9e8 | 1 | // $Id$ |
2 | // Category: motif | |
3 | // | |
4 | // Class AliMpMotifSpecial | |
5 | // ----------------------- | |
6 | // Class that defines a motif with its unique ID | |
7 | // and the motif type. | |
dbe945cc | 8 | // Included in AliRoot: 2003/05/02 |
5f91c9e8 | 9 | // Authors: David Guez, Ivana Hrivnacova; IPN Orsay |
10 | ||
2998a151 | 11 | #include <TString.h> |
12 | ||
5f91c9e8 | 13 | #include "AliMpMotifSpecial.h" |
14 | #include "AliMpMotifType.h" | |
15 | #include "AliMpIntPair.h" | |
16 | #include "AliMpConstants.h" | |
17 | ||
18 | ClassImp(AliMpMotifSpecial) | |
19 | ||
20 | ||
21 | // private methods | |
22 | //______________________________________________________________________________ | |
23 | Int_t AliMpMotifSpecial::VectorIndex(const AliMpIntPair& indices) const | |
24 | { | |
25 | // transform indices to linear vector index | |
26 | return indices.GetFirst()*GetMotifType()->GetNofPadsY() + indices.GetSecond(); | |
27 | } | |
28 | ||
29 | ||
5f91c9e8 | 30 | //public methods |
2998a151 | 31 | |
5f91c9e8 | 32 | //______________________________________________________________________________ |
33 | AliMpMotifSpecial::AliMpMotifSpecial(): | |
34 | AliMpVMotif(), | |
35 | fPadDimensionsVector(), | |
36 | fPadDimensionsVector2() | |
37 | { | |
38 | //default dummy constructor | |
39 | } | |
40 | ||
41 | ||
42 | //______________________________________________________________________________ | |
43 | AliMpMotifSpecial::AliMpMotifSpecial(const TString &id, | |
44 | AliMpMotifType *motifType) | |
45 | : AliMpVMotif(id,motifType), | |
46 | fPadDimensionsVector(), | |
47 | fPadDimensionsVector2() | |
48 | ||
49 | { | |
50 | // Normal constructor. | |
51 | ||
f79c58a5 | 52 | #ifdef WITH_STL |
5f91c9e8 | 53 | fPadDimensionsVector.resize(motifType->GetNofPadsX()*motifType->GetNofPadsY()); |
f79c58a5 | 54 | #endif |
55 | ||
56 | #ifdef WITH_ROOT | |
57 | fPadDimensionsVector.Expand(motifType->GetNofPadsX()*motifType->GetNofPadsY()); | |
58 | #endif | |
5f91c9e8 | 59 | } |
60 | ||
2998a151 | 61 | //______________________________________________________________________________ |
62 | AliMpMotifSpecial::~AliMpMotifSpecial() | |
63 | { | |
64 | //destructor | |
f79c58a5 | 65 | |
66 | #ifdef WITH_ROOT | |
67 | fPadDimensionsVector.Delete(); | |
68 | #endif | |
2998a151 | 69 | } |
70 | ||
71 | ||
5f91c9e8 | 72 | //______________________________________________________________________________ |
73 | TVector2 | |
74 | AliMpMotifSpecial::GetPadDimensions(const AliMpIntPair& localIndices) const | |
75 | { | |
76 | // returns the dimensions of pad located at the given indices | |
77 | if (GetMotifType()->HasPad(localIndices)) | |
f79c58a5 | 78 | #ifdef WITH_STL |
5f91c9e8 | 79 | return fPadDimensionsVector[VectorIndex(localIndices)]; |
f79c58a5 | 80 | #endif |
81 | #ifdef WITH_ROOT | |
82 | return *((TVector2*)fPadDimensionsVector[VectorIndex(localIndices)]); | |
83 | #endif | |
5f91c9e8 | 84 | else { |
85 | Warning("GetPadDimensions","Indices outside limits"); | |
86 | return TVector2(0.,0.); | |
87 | } | |
88 | } | |
89 | ||
90 | //______________________________________________________________________________ | |
91 | Int_t AliMpMotifSpecial::GetNofPadDimensions() const | |
92 | { | |
93 | // returns number of different pad dimensions in this motif | |
94 | ||
f79c58a5 | 95 | #ifdef WITH_STL |
5f91c9e8 | 96 | return fPadDimensionsVector2.size(); |
f79c58a5 | 97 | #endif |
98 | ||
99 | #ifdef WITH_ROOT | |
100 | return fPadDimensionsVector2.GetEntriesFast(); | |
101 | #endif | |
5f91c9e8 | 102 | } |
103 | ||
104 | //______________________________________________________________________________ | |
105 | TVector2 AliMpMotifSpecial::GetPadDimensions(Int_t i) const | |
106 | { | |
107 | // returns the i-th different pad dimensions | |
108 | ||
109 | if (i<0 || i>GetNofPadDimensions()) { | |
110 | Fatal("GetPadDimensions(i)", "Index outside limits."); | |
111 | return TVector2(); | |
112 | } | |
113 | ||
f79c58a5 | 114 | #ifdef WITH_STL |
5f91c9e8 | 115 | return fPadDimensionsVector2[i]; |
f79c58a5 | 116 | #endif |
117 | ||
118 | #ifdef WITH_ROOT | |
119 | return *((TVector2*) fPadDimensionsVector2[i]); | |
120 | #endif | |
5f91c9e8 | 121 | } |
122 | ||
123 | //______________________________________________________________________________ | |
124 | TVector2 AliMpMotifSpecial::Dimensions() const | |
125 | { | |
126 | // gives the dimension of the motif | |
127 | ||
128 | ||
129 | Int_t i,j; | |
130 | Double_t sizeY=0.; | |
131 | Double_t sizeX=0.; | |
132 | ||
133 | Double_t* tabSizeX = new Double_t[GetMotifType()->GetNofPadsY()]; | |
134 | for (j=0;j<GetMotifType()->GetNofPadsY();++j) tabSizeX[j]=0.0; | |
135 | ||
136 | for (i=0;i<GetMotifType()->GetNofPadsX();++i) { | |
137 | Double_t trSizeY=0.; | |
138 | for (j=0;j<GetMotifType()->GetNofPadsY();++j) { | |
139 | TVector2 dim = GetPadDimensions(AliMpIntPair(i,j)); | |
140 | trSizeY+=dim.Y(); | |
141 | tabSizeX[j]+=dim.X(); | |
142 | } | |
143 | if (trSizeY>sizeY) sizeY=trSizeY; | |
144 | } | |
145 | for (j=0;j<GetMotifType()->GetNofPadsY();++j) { | |
146 | if (tabSizeX[j]>sizeX) sizeX = tabSizeX[j]; | |
147 | } | |
148 | ||
149 | delete tabSizeX; | |
150 | ||
151 | return TVector2(sizeX,sizeY); | |
152 | } | |
153 | ||
154 | //______________________________________________________________________________ | |
155 | TVector2 | |
156 | AliMpMotifSpecial::PadPositionLocal(const AliMpIntPair& localIndices) const | |
157 | { | |
158 | // gives the local position of the pad number (ix,iy) | |
159 | // (0,0 is the center of the motif) | |
160 | ||
161 | TVector2 dim = GetPadDimensions(localIndices); | |
162 | ||
163 | Double_t posX= dim.X(); | |
164 | for (Int_t i=0;i<localIndices.GetFirst();++i) { | |
165 | posX+=2.*GetPadDimensions(AliMpIntPair(i,localIndices.GetSecond())).X(); | |
166 | } | |
167 | ||
168 | Double_t posY= dim.Y(); | |
169 | for (Int_t j=0;j<localIndices.GetSecond();++j) { | |
170 | posY+=2.*GetPadDimensions(AliMpIntPair(localIndices.GetFirst(),j)).Y(); | |
171 | } | |
172 | ||
173 | return TVector2(posX,posY)-Dimensions(); | |
174 | ||
175 | } | |
176 | //______________________________________________________________________________ | |
177 | AliMpIntPair AliMpMotifSpecial::PadIndicesLocal(const TVector2& localPos) const | |
178 | { | |
179 | // return the pad indices from a given local position | |
180 | // or AliMpIntPair::Invalid() if this position doesn't correspond to any valid | |
181 | // connection | |
182 | ||
183 | // *SOLEIL* : This code suppose that | |
184 | // 1) all cells have the same size along the Y direction | |
185 | // 2) the column 0 is entierly filled | |
186 | ||
187 | ||
188 | // First : find the j index | |
189 | TVector2 pos = localPos + Dimensions(); | |
190 | Int_t j=0; | |
191 | Double_t y=pos.Y(); | |
192 | ||
193 | while (j<GetMotifType()->GetNofPadsY()) { | |
194 | TVector2 padDim = GetPadDimensions(AliMpIntPair(0,j)); | |
195 | y-=2.*padDim.Y(); | |
196 | if (y<0.) break; | |
197 | j++; | |
198 | } | |
199 | ||
200 | // Test if it's outside limits | |
201 | if (j==GetMotifType()->GetNofPadsY()){ | |
202 | Warning("PadIndicesLocal","The position is outside the motif"); | |
203 | return AliMpIntPair::Invalid(); | |
204 | } | |
205 | ||
206 | ||
207 | // now find the i index, in the j_th row | |
208 | Int_t i=0; | |
209 | Double_t x=pos.X(); | |
210 | ||
211 | while (i<GetMotifType()->GetNofPadsX()) { | |
212 | TVector2 padDim = GetPadDimensions(AliMpIntPair(i,j)); | |
213 | x-=2.*padDim.X(); | |
214 | if (x<0.) break; | |
215 | i++; | |
216 | } | |
217 | ||
218 | ||
219 | // Test if it's outside limits | |
220 | ||
221 | if (i==GetMotifType()->GetNofPadsX()){ | |
222 | Warning("PadIndicesLocal","The position is outside the motif"); | |
223 | return AliMpIntPair::Invalid(); | |
224 | } | |
225 | ||
226 | // then return the found (i,j) | |
227 | return AliMpIntPair(i,j); | |
228 | } | |
229 | //______________________________________________________________________________ | |
230 | void AliMpMotifSpecial::SetPadDimensions(const AliMpIntPair& localIndices, | |
231 | const TVector2& dimensions) | |
232 | { | |
233 | // set the dimensions of the pad located at <localIndices> to the given | |
234 | // <dimensions> | |
235 | ||
236 | if ( !GetMotifType()->HasPad(localIndices)){ | |
237 | Warning("SetPadDimensions","Pad indices outside limits"); | |
238 | return; | |
239 | } | |
240 | ||
241 | // fill the dimensions map vector | |
f79c58a5 | 242 | #ifdef WITH_STL |
5f91c9e8 | 243 | fPadDimensionsVector[VectorIndex(localIndices)]=dimensions; |
244 | ||
245 | // fill the vector of different pad dimensions | |
246 | // only if these dimensions are not yet present | |
247 | Bool_t isPresent = false; | |
248 | for (Int_t i=0; i<GetNofPadDimensions(); i++) { | |
249 | if (AliMpConstants::IsEqual(fPadDimensionsVector2[i], dimensions)) | |
250 | isPresent = true; | |
251 | } | |
252 | ||
253 | if (!isPresent) fPadDimensionsVector2.push_back(dimensions); | |
f79c58a5 | 254 | #endif |
255 | ||
256 | #ifdef WITH_ROOT | |
257 | TVector2* dimensionsObj = new TVector2(dimensions); | |
258 | fPadDimensionsVector[VectorIndex(localIndices)]= dimensionsObj; | |
259 | ||
260 | // fill the vector of different pad dimensions | |
261 | // only if these dimensions are not yet present | |
262 | Bool_t isPresent = false; | |
263 | for (Int_t i=0; i<GetNofPadDimensions(); i++) { | |
264 | if (AliMpConstants::IsEqual(*((TVector2*) fPadDimensionsVector2[i]), dimensions)) | |
265 | isPresent = true; | |
266 | } | |
267 | ||
268 | if (!isPresent) fPadDimensionsVector2.Add(dimensionsObj); | |
269 | #endif | |
270 | ||
5f91c9e8 | 271 | } |