Line data Source code
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.12 2006/05/24 13:58:41 ivana Exp $
18 : // Category: motif
19 :
20 : //-----------------------------------------------------------------------------
21 : // Class AliMpMotifSpecial
22 : // -----------------------
23 : // Class that defines a motif with its unique ID
24 : // and the motif type.
25 : // Included in AliRoot: 2003/05/02
26 : // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
27 : //-----------------------------------------------------------------------------
28 :
29 : #include "AliMpMotifSpecial.h"
30 : #include "AliMpMotifType.h"
31 : #include "AliMpEncodePair.h"
32 : #include "AliMpConstants.h"
33 :
34 : #include "AliLog.h"
35 :
36 : #include <TString.h>
37 : #include <Riostream.h>
38 : #include <TVector2.h>
39 :
40 : /// \cond CLASSIMP
41 18 : ClassImp(AliMpMotifSpecial)
42 : /// \endcond
43 :
44 : Int_t AliMpMotifSpecial::fgkPadDimensions2Size = 5;
45 :
46 : //______________________________________________________________________________
47 : AliMpMotifSpecial::AliMpMotifSpecial(const TString &id,
48 : AliMpMotifType *motifType)
49 27 : : AliMpVMotif(id,motifType),
50 27 : fDimensionX(0.),
51 27 : fDimensionY(0.),
52 27 : fPadDimensionsVector(),
53 27 : fNofPadDimensions2(0),
54 27 : fPadDimensions2X(fgkPadDimensions2Size),
55 27 : fPadDimensions2Y(fgkPadDimensions2Size)
56 :
57 135 : {
58 : /// Standard constructor.
59 54 : }
60 :
61 : //______________________________________________________________________________
62 : AliMpMotifSpecial::AliMpMotifSpecial(TRootIOCtor* ioCtor):
63 0 : AliMpVMotif(),
64 0 : fDimensionX(0.),
65 0 : fDimensionY(0.),
66 0 : fPadDimensionsVector(ioCtor),
67 0 : fNofPadDimensions2(),
68 0 : fPadDimensions2X(),
69 0 : fPadDimensions2Y()
70 0 : {
71 : /// Root IO constructor
72 0 : }
73 :
74 :
75 : //______________________________________________________________________________
76 : AliMpMotifSpecial::~AliMpMotifSpecial()
77 108 : {
78 : /// Destructor
79 54 : }
80 :
81 :
82 : //
83 : // public methods
84 : //
85 :
86 : //______________________________________________________________________________
87 : void
88 : AliMpMotifSpecial::GetPadDimensionsByIndices(MpPair_t localIndices,
89 : Double_t& dx, Double_t& dy) const
90 : {
91 : /// Return the dimensions of pad located at the given indices
92 :
93 202728 : GetPadDimensionsByIndices(AliMp::PairFirst(localIndices),
94 67576 : AliMp::PairSecond(localIndices),
95 : dx, dy);
96 67576 : }
97 :
98 : //______________________________________________________________________________
99 : void
100 : AliMpMotifSpecial::GetPadDimensionsByIndices(Int_t ixLocal, Int_t iyLocal,
101 : Double_t& dx, Double_t& dy) const
102 : {
103 : /// Return the dimensions of pad located at the given indices
104 :
105 1373950 : if ( GetMotifType()->HasPadByLocalIndices(ixLocal, iyLocal) ) {
106 686975 : if (!fPadDimensionsVector.GetValue(ixLocal, iyLocal)) {
107 0 : Warning("GetPadDimensionsByIndices","Indices outside limits");
108 0 : dx = 0.;
109 0 : dy = 0.;
110 0 : }
111 : else {
112 686975 : dx = ((TVector2*)fPadDimensionsVector.GetValue(ixLocal, iyLocal))->X();
113 686975 : dy = ((TVector2*)fPadDimensionsVector.GetValue(ixLocal, iyLocal))->Y();
114 : }
115 : }
116 : else {
117 0 : Warning("GetPadDimensionsByIndices","Indices outside limits");
118 0 : dx = 0.;
119 0 : dy = 0.;
120 : }
121 686975 : }
122 :
123 : //______________________________________________________________________________
124 : Int_t AliMpMotifSpecial::GetNofPadDimensions() const
125 : {
126 : /// Return number of different pad dimensions in this motif
127 :
128 5766 : return fNofPadDimensions2;
129 : }
130 :
131 : //______________________________________________________________________________
132 : Double_t AliMpMotifSpecial::GetPadDimensionX(Int_t i) const
133 : {
134 : /// Returns the i-th different pad dimensions
135 :
136 0 : if ( i < 0 || i > fNofPadDimensions2 ) {
137 0 : AliFatal("Index outside limits.");
138 0 : return 0;
139 : }
140 :
141 0 : return fPadDimensions2X[i];
142 0 : }
143 :
144 : //______________________________________________________________________________
145 : Double_t AliMpMotifSpecial::GetPadDimensionY(Int_t i) const
146 : {
147 : /// Returns the i-th different pad dimensions
148 :
149 0 : if ( i < 0 || i > fNofPadDimensions2 ) {
150 0 : AliFatal("Index outside limits.");
151 0 : return 0;
152 : }
153 :
154 0 : return fPadDimensions2Y[i];
155 0 : }
156 :
157 : //______________________________________________________________________________
158 : void AliMpMotifSpecial::CalculateDimensions()
159 : {
160 : /// Calculate motif dimensions and keep them in fDimensionX/Y data
161 :
162 : Int_t i,j;
163 54 : fDimensionY = 0.;
164 27 : fDimensionX = 0.;
165 :
166 27 : Double_t* tabSizeX = new Double_t[GetMotifType()->GetNofPadsY()];
167 :
168 414 : for ( j=0; j<GetMotifType()->GetNofPadsY(); ++j ) tabSizeX[j]=0.0;
169 :
170 678 : for ( i=0; i<GetMotifType()->GetNofPadsX(); ++i ) {
171 : Double_t trSizeY=0.;
172 2832 : for ( j=0; j<GetMotifType()->GetNofPadsY(); ++j ) {
173 1104 : Double_t dimx, dimy;
174 1104 : GetPadDimensionsByIndices(i,j, dimx, dimy);
175 1104 : trSizeY += dimy;
176 1104 : tabSizeX[j] += dimx;
177 1104 : }
178 339 : if ( trSizeY > fDimensionY ) fDimensionY = trSizeY;
179 : }
180 :
181 414 : for ( j=0; j<GetMotifType()->GetNofPadsY(); ++j ) {
182 207 : if ( tabSizeX[j] > fDimensionX ) fDimensionX = tabSizeX[j];
183 : }
184 :
185 54 : delete [] tabSizeX;
186 27 : }
187 :
188 : //______________________________________________________________________________
189 : Double_t AliMpMotifSpecial::DimensionX() const
190 : {
191 : /// Give the dimension of the motif
192 :
193 137204 : return fDimensionX;
194 : }
195 :
196 : //______________________________________________________________________________
197 : Double_t AliMpMotifSpecial::DimensionY() const
198 : {
199 : /// Give the dimension of the motif
200 :
201 136204 : return fDimensionY;
202 : }
203 :
204 : //______________________________________________________________________________
205 : void
206 : AliMpMotifSpecial::PadPositionLocal(MpPair_t localIndices,
207 : Double_t& posx, Double_t& posy) const
208 : {
209 : /// Give the local position of the pad number (ix,iy)
210 : /// (0,0 is the center of the motif)
211 :
212 202728 : return PadPositionLocal(AliMp::PairFirst(localIndices),
213 67576 : AliMp::PairSecond(localIndices),
214 : posx, posy);
215 :
216 : }
217 :
218 : //______________________________________________________________________________
219 : void
220 : AliMpMotifSpecial::PadPositionLocal(Int_t ixLocal, Int_t iyLocal,
221 : Double_t& posx, Double_t& posy) const
222 : {
223 : /// Give the local position of the pad number (ix,iy)
224 : /// (0,0 is the center of the motif)
225 :
226 135152 : Double_t dx0, dy0;
227 67576 : GetPadDimensionsByIndices(ixLocal, iyLocal, dx0, dy0);
228 :
229 67576 : posx = dx0;
230 908008 : for ( Int_t i=0 ;i<ixLocal; ++i ) {
231 386428 : Double_t dxi, dyi;
232 386428 : GetPadDimensionsByIndices(i, iyLocal, dxi, dyi);
233 386428 : posx += 2.*dxi;
234 386428 : }
235 :
236 67576 : posy = dy0;
237 463328 : for ( Int_t j=0; j<iyLocal; ++j ) {
238 164088 : Double_t dxi, dyi;
239 164088 : GetPadDimensionsByIndices(ixLocal, j, dxi, dyi);
240 164088 : posy += 2.*dyi;
241 164088 : }
242 :
243 67576 : posx -= DimensionX();
244 67576 : posy -= DimensionY();
245 67576 : }
246 :
247 : //______________________________________________________________________________
248 : MpPair_t
249 : AliMpMotifSpecial::PadIndicesLocal(Double_t localPosX, Double_t localPosY) const
250 : {
251 : /// Return the pad indices from a given local position
252 : /// or -1 if this position doesn't correspond to any valid
253 : /// connection
254 : ///
255 : /// *SOLEIL* : This code suppose that
256 : /// - 1) all cells have the same size along the Y direction
257 : /// - 2) the column 0 is entierly filled
258 :
259 :
260 : // First : find the j index
261 : Int_t j=0;
262 120 : Double_t y = localPosY + DimensionY();
263 :
264 120 : while (j<GetMotifType()->GetNofPadsY()) {
265 60 : Double_t padDimX, padDimY;
266 60 : GetPadDimensionsByIndices(0, j, padDimX, padDimY);
267 60 : y -= 2.*padDimY;
268 120 : if ( y < 0. ) break;
269 0 : j++;
270 60 : }
271 :
272 : // Test if it's outside limits
273 60 : if (j==GetMotifType()->GetNofPadsY()){
274 0 : Warning("PadIndicesLocal","The position is outside the motif");
275 0 : return -1;
276 : }
277 :
278 :
279 : // now find the i index, in the j_th row
280 : Int_t i=0;
281 60 : Double_t x = localPosX + DimensionX();
282 :
283 176 : while (i<GetMotifType()->GetNofPadsX()) {
284 116 : Double_t padDimX, padDimY;
285 116 : GetPadDimensionsByIndices(i, j, padDimX, padDimY);
286 116 : x -= 2.*padDimX;
287 176 : if ( x < 0. ) break;
288 56 : i++;
289 172 : }
290 :
291 :
292 : // Test if it's outside limits
293 :
294 60 : if (i==GetMotifType()->GetNofPadsX()){
295 0 : Warning("PadIndicesLocal","The position is outside the motif");
296 0 : return -1;
297 : }
298 :
299 : // then return the found (i,j)
300 60 : return AliMp::Pair(i,j);
301 60 : }
302 :
303 : //______________________________________________________________________________
304 : void AliMpMotifSpecial::SetPadDimensions(MpPair_t localIndices,
305 : Double_t dx, Double_t dy)
306 : {
307 : /// Set the dimensions of the pad located at \a localIndices to the given
308 : /// \a dimensions
309 :
310 0 : SetPadDimensions(AliMp::PairFirst(localIndices),
311 0 : AliMp::PairSecond(localIndices), dx, dy);
312 0 : }
313 :
314 : //______________________________________________________________________________
315 : void AliMpMotifSpecial::SetPadDimensions(Int_t ixLocal, Int_t iyLocal,
316 : Double_t dx, Double_t dy)
317 : {
318 : /// Set the dimensions of the pad located at \a localIndices to the given
319 : /// \a dimensions
320 :
321 2208 : if ( ! GetMotifType()->HasPadByLocalIndices(ixLocal, iyLocal) ) {
322 0 : Warning("SetPadDimensions","Pad indices outside limits");
323 0 : return;
324 : }
325 :
326 : // fill the dimensions map vector
327 1104 : TVector2* dimensionsObj = new TVector2(dx, dy);
328 1104 : fPadDimensionsVector.Add(ixLocal, iyLocal, dimensionsObj);
329 :
330 : // fill the vector of different pad dimensions
331 : // only if these dimensions are not yet present
332 : Bool_t isPresent = false;
333 5766 : for (Int_t i=0; i<GetNofPadDimensions(); i++) {
334 1779 : if ( AliMpConstants::IsEqual(
335 1779 : fPadDimensions2X[i], fPadDimensions2Y[i], dx, dy) )
336 1050 : isPresent = true;
337 : }
338 :
339 1104 : if (!isPresent) {
340 54 : fPadDimensions2X.AddAt(dx, fNofPadDimensions2);
341 54 : fPadDimensions2Y.AddAt(dy, fNofPadDimensions2++);
342 54 : }
343 2208 : }
|