1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 // $MpId: AliMpMotifSpecial.cxx,v 1.12 2006/05/24 13:58:41 ivana Exp $
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 //-----------------------------------------------------------------------------
29 #include "AliMpMotifSpecial.h"
30 #include "AliMpMotifType.h"
31 #include "AliMpEncodePair.h"
32 #include "AliMpConstants.h"
37 #include <Riostream.h>
41 ClassImp(AliMpMotifSpecial)
44 Int_t AliMpMotifSpecial::fgkPadDimensions2Size = 5;
46 //______________________________________________________________________________
47 AliMpMotifSpecial::AliMpMotifSpecial(const TString &id,
48 AliMpMotifType *motifType)
49 : AliMpVMotif(id,motifType),
52 fPadDimensionsVector(),
53 fNofPadDimensions2(0),
54 fPadDimensions2X(fgkPadDimensions2Size),
55 fPadDimensions2Y(fgkPadDimensions2Size)
58 /// Standard constructor.
61 //______________________________________________________________________________
62 AliMpMotifSpecial::AliMpMotifSpecial(TRootIOCtor* ioCtor):
66 fPadDimensionsVector(ioCtor),
71 /// Root IO constructor
75 //______________________________________________________________________________
76 AliMpMotifSpecial::~AliMpMotifSpecial()
86 //______________________________________________________________________________
88 AliMpMotifSpecial::GetPadDimensionsByIndices(MpPair_t localIndices,
89 Double_t& dx, Double_t& dy) const
91 /// Return the dimensions of pad located at the given indices
93 GetPadDimensionsByIndices(AliMp::PairFirst(localIndices),
94 AliMp::PairSecond(localIndices),
98 //______________________________________________________________________________
100 AliMpMotifSpecial::GetPadDimensionsByIndices(Int_t ixLocal, Int_t iyLocal,
101 Double_t& dx, Double_t& dy) const
103 /// Return the dimensions of pad located at the given indices
105 if ( GetMotifType()->HasPadByLocalIndices(ixLocal, iyLocal) ) {
106 if (!fPadDimensionsVector.GetValue(ixLocal, iyLocal)) {
107 Warning("GetPadDimensionsByIndices","Indices outside limits");
112 dx = ((TVector2*)fPadDimensionsVector.GetValue(ixLocal, iyLocal))->X();
113 dy = ((TVector2*)fPadDimensionsVector.GetValue(ixLocal, iyLocal))->Y();
117 Warning("GetPadDimensionsByIndices","Indices outside limits");
123 //______________________________________________________________________________
124 Int_t AliMpMotifSpecial::GetNofPadDimensions() const
126 /// Return number of different pad dimensions in this motif
128 return fNofPadDimensions2;
131 //______________________________________________________________________________
132 Double_t AliMpMotifSpecial::GetPadDimensionX(Int_t i) const
134 /// Returns the i-th different pad dimensions
136 if ( i < 0 || i > fNofPadDimensions2 ) {
137 AliFatal("Index outside limits.");
141 return fPadDimensions2X[i];
144 //______________________________________________________________________________
145 Double_t AliMpMotifSpecial::GetPadDimensionY(Int_t i) const
147 /// Returns the i-th different pad dimensions
149 if ( i < 0 || i > fNofPadDimensions2 ) {
150 AliFatal("Index outside limits.");
154 return fPadDimensions2Y[i];
157 //______________________________________________________________________________
158 void AliMpMotifSpecial::CalculateDimensions()
160 /// Calculate motif dimensions and keep them in fDimensionX/Y data
166 Double_t* tabSizeX = new Double_t[GetMotifType()->GetNofPadsY()];
168 for ( j=0; j<GetMotifType()->GetNofPadsY(); ++j ) tabSizeX[j]=0.0;
170 for ( i=0; i<GetMotifType()->GetNofPadsX(); ++i ) {
172 for ( j=0; j<GetMotifType()->GetNofPadsY(); ++j ) {
174 GetPadDimensionsByIndices(i,j, dimx, dimy);
178 if ( trSizeY > fDimensionY ) fDimensionY = trSizeY;
181 for ( j=0; j<GetMotifType()->GetNofPadsY(); ++j ) {
182 if ( tabSizeX[j] > fDimensionX ) fDimensionX = tabSizeX[j];
188 //______________________________________________________________________________
189 Double_t AliMpMotifSpecial::DimensionX() const
191 /// Give the dimension of the motif
196 //______________________________________________________________________________
197 Double_t AliMpMotifSpecial::DimensionY() const
199 /// Give the dimension of the motif
204 //______________________________________________________________________________
206 AliMpMotifSpecial::PadPositionLocal(MpPair_t localIndices,
207 Double_t& posx, Double_t& posy) const
209 /// Give the local position of the pad number (ix,iy)
210 /// (0,0 is the center of the motif)
212 return PadPositionLocal(AliMp::PairFirst(localIndices),
213 AliMp::PairSecond(localIndices),
218 //______________________________________________________________________________
220 AliMpMotifSpecial::PadPositionLocal(Int_t ixLocal, Int_t iyLocal,
221 Double_t& posx, Double_t& posy) const
223 /// Give the local position of the pad number (ix,iy)
224 /// (0,0 is the center of the motif)
227 GetPadDimensionsByIndices(ixLocal, iyLocal, dx0, dy0);
230 for ( Int_t i=0 ;i<ixLocal; ++i ) {
232 GetPadDimensionsByIndices(i, iyLocal, dxi, dyi);
237 for ( Int_t j=0; j<iyLocal; ++j ) {
239 GetPadDimensionsByIndices(ixLocal, j, dxi, dyi);
243 posx -= DimensionX();
244 posy -= DimensionY();
247 //______________________________________________________________________________
249 AliMpMotifSpecial::PadIndicesLocal(Double_t localPosX, Double_t localPosY) const
251 /// Return the pad indices from a given local position
252 /// or -1 if this position doesn't correspond to any valid
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
260 // First : find the j index
262 Double_t y = localPosY + DimensionY();
264 while (j<GetMotifType()->GetNofPadsY()) {
265 Double_t padDimX, padDimY;
266 GetPadDimensionsByIndices(0, j, padDimX, padDimY);
272 // Test if it's outside limits
273 if (j==GetMotifType()->GetNofPadsY()){
274 Warning("PadIndicesLocal","The position is outside the motif");
279 // now find the i index, in the j_th row
281 Double_t x = localPosX + DimensionX();
283 while (i<GetMotifType()->GetNofPadsX()) {
284 Double_t padDimX, padDimY;
285 GetPadDimensionsByIndices(i, j, padDimX, padDimY);
292 // Test if it's outside limits
294 if (i==GetMotifType()->GetNofPadsX()){
295 Warning("PadIndicesLocal","The position is outside the motif");
299 // then return the found (i,j)
300 return AliMp::Pair(i,j);
303 //______________________________________________________________________________
304 void AliMpMotifSpecial::SetPadDimensions(MpPair_t localIndices,
305 Double_t dx, Double_t dy)
307 /// Set the dimensions of the pad located at \a localIndices to the given
310 SetPadDimensions(AliMp::PairFirst(localIndices),
311 AliMp::PairSecond(localIndices), dx, dy);
314 //______________________________________________________________________________
315 void AliMpMotifSpecial::SetPadDimensions(Int_t ixLocal, Int_t iyLocal,
316 Double_t dx, Double_t dy)
318 /// Set the dimensions of the pad located at \a localIndices to the given
321 if ( ! GetMotifType()->HasPadByLocalIndices(ixLocal, iyLocal) ) {
322 Warning("SetPadDimensions","Pad indices outside limits");
326 // fill the dimensions map vector
327 TVector2* dimensionsObj = new TVector2(dx, dy);
328 fPadDimensionsVector.Add(ixLocal, iyLocal, dimensionsObj);
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++) {
334 if ( AliMpConstants::IsEqual(
335 fPadDimensions2X[i], fPadDimensions2Y[i], dx, dy) )
340 fPadDimensions2X.AddAt(dx, fNofPadDimensions2);
341 fPadDimensions2Y.AddAt(dy, fNofPadDimensions2++);