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.9 2005/09/26 16:11:20 ivana Exp $
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
29 #include "AliMpMotifSpecial.h"
30 #include "AliMpMotifType.h"
31 #include "AliMpIntPair.h"
32 #include "AliMpConstants.h"
34 ClassImp(AliMpMotifSpecial)
37 //______________________________________________________________________________
38 AliMpMotifSpecial::AliMpMotifSpecial():
40 fPadDimensionsVector(),
41 fPadDimensionsVector2()
43 /// Default constructor
47 //______________________________________________________________________________
48 AliMpMotifSpecial::AliMpMotifSpecial(const TString &id,
49 AliMpMotifType *motifType)
50 : AliMpVMotif(id,motifType),
52 fPadDimensionsVector(),
55 fPadDimensionsVector(true),
57 fPadDimensionsVector2()
60 /// Standard constructor.
63 fPadDimensionsVector.resize(motifType->GetNofPadsX()*motifType->GetNofPadsY());
67 //______________________________________________________________________________
68 AliMpMotifSpecial::~AliMpMotifSpecial()
78 //______________________________________________________________________________
79 Int_t AliMpMotifSpecial::VectorIndex(const AliMpIntPair& indices) const
81 /// Transform indices to linear vector index
83 return indices.GetFirst()*GetMotifType()->GetNofPadsY() + indices.GetSecond();
91 #include <Riostream.h>
92 //______________________________________________________________________________
94 AliMpMotifSpecial::GetPadDimensions(const AliMpIntPair& localIndices) const
96 /// Return the dimensions of pad located at the given indices
98 if (GetMotifType()->HasPad(localIndices)) {
100 return fPadDimensionsVector[VectorIndex(localIndices)];
103 if (!fPadDimensionsVector.GetValue(localIndices)) {
104 Warning("GetPadDimensions","Indices outside limits");
105 return TVector2(0.,0.);
108 return *((TVector2*)fPadDimensionsVector.GetValue(localIndices));
112 Warning("GetPadDimensions","Indices outside limits");
113 return TVector2(0.,0.);
117 //______________________________________________________________________________
118 Int_t AliMpMotifSpecial::GetNofPadDimensions() const
120 /// Return number of different pad dimensions in this motif
123 return fPadDimensionsVector2.size();
127 return fPadDimensionsVector2.GetEntriesFast();
131 //______________________________________________________________________________
132 TVector2 AliMpMotifSpecial::GetPadDimensions(Int_t i) const
134 /// Returns the i-th different pad dimensions
136 if (i<0 || i>GetNofPadDimensions()) {
137 Fatal("GetPadDimensions(i)", "Index outside limits.");
142 return fPadDimensionsVector2[i];
146 return *((TVector2*) fPadDimensionsVector2[i]);
150 //______________________________________________________________________________
151 TVector2 AliMpMotifSpecial::Dimensions() const
153 /// Give the dimension of the motif
160 Double_t* tabSizeX = new Double_t[GetMotifType()->GetNofPadsY()];
161 for (j=0;j<GetMotifType()->GetNofPadsY();++j) tabSizeX[j]=0.0;
163 for (i=0;i<GetMotifType()->GetNofPadsX();++i) {
165 for (j=0;j<GetMotifType()->GetNofPadsY();++j) {
166 TVector2 dim = GetPadDimensions(AliMpIntPair(i,j));
168 tabSizeX[j]+=dim.X();
170 if (trSizeY>sizeY) sizeY=trSizeY;
172 for (j=0;j<GetMotifType()->GetNofPadsY();++j) {
173 if (tabSizeX[j]>sizeX) sizeX = tabSizeX[j];
178 return TVector2(sizeX,sizeY);
181 //______________________________________________________________________________
183 AliMpMotifSpecial::PadPositionLocal(const AliMpIntPair& localIndices) const
185 /// Give the local position of the pad number (ix,iy)
186 /// (0,0 is the center of the motif)
188 TVector2 dim = GetPadDimensions(localIndices);
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();
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();
200 return TVector2(posX,posY)-Dimensions();
203 //______________________________________________________________________________
204 AliMpIntPair AliMpMotifSpecial::PadIndicesLocal(const TVector2& localPos) const
206 /// Return the pad indices from a given local position
207 /// or AliMpIntPair::Invalid() if this position doesn't correspond to any valid
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
215 // First : find the j index
216 TVector2 pos = localPos + Dimensions();
220 while (j<GetMotifType()->GetNofPadsY()) {
221 TVector2 padDim = GetPadDimensions(AliMpIntPair(0,j));
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();
234 // now find the i index, in the j_th row
238 while (i<GetMotifType()->GetNofPadsX()) {
239 TVector2 padDim = GetPadDimensions(AliMpIntPair(i,j));
246 // Test if it's outside limits
248 if (i==GetMotifType()->GetNofPadsX()){
249 Warning("PadIndicesLocal","The position is outside the motif");
250 return AliMpIntPair::Invalid();
253 // then return the found (i,j)
254 return AliMpIntPair(i,j);
256 //______________________________________________________________________________
257 void AliMpMotifSpecial::SetPadDimensions(const AliMpIntPair& localIndices,
258 const TVector2& dimensions)
260 /// Set the dimensions of the pad located at <localIndices> to the given
263 if ( !GetMotifType()->HasPad(localIndices)){
264 Warning("SetPadDimensions","Pad indices outside limits");
268 // fill the dimensions map vector
270 fPadDimensionsVector[VectorIndex(localIndices)]=dimensions;
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))
280 if (!isPresent) fPadDimensionsVector2.push_back(dimensions);
284 TVector2* dimensionsObj = new TVector2(dimensions);
285 fPadDimensionsVector.Add(localIndices, dimensionsObj);
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))
295 if (!isPresent) fPadDimensionsVector2.Add(dimensionsObj);