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