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