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