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 // 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
27 #include "AliMpMotifSpecial.h"
28 #include "AliMpMotifType.h"
29 #include "AliMpIntPair.h"
30 #include "AliMpConstants.h"
35 ClassImp(AliMpMotifSpecial)
39 //______________________________________________________________________________
40 AliMpMotifSpecial::AliMpMotifSpecial():
43 fPadDimensionsVector(),
44 fPadDimensionsVector2()
46 /// Default constructor
50 //______________________________________________________________________________
51 AliMpMotifSpecial::AliMpMotifSpecial(const TString &id,
52 AliMpMotifType *motifType)
53 : AliMpVMotif(id,motifType),
56 fPadDimensionsVector(),
59 fPadDimensionsVector(true),
61 fPadDimensionsVector2()
64 /// Standard constructor.
67 fPadDimensionsVector.resize(motifType->GetNofPadsX()*motifType->GetNofPadsY());
71 //______________________________________________________________________________
72 AliMpMotifSpecial::~AliMpMotifSpecial()
82 //______________________________________________________________________________
83 Int_t AliMpMotifSpecial::VectorIndex(const AliMpIntPair& indices) const
85 /// Transform indices to linear vector index
87 return indices.GetFirst()*GetMotifType()->GetNofPadsY() + indices.GetSecond();
95 #include <Riostream.h>
96 //______________________________________________________________________________
98 AliMpMotifSpecial::GetPadDimensions(const AliMpIntPair& localIndices) const
100 /// Return the dimensions of pad located at the given indices
102 if (GetMotifType()->HasPad(localIndices)) {
104 return fPadDimensionsVector[VectorIndex(localIndices)];
107 if (!fPadDimensionsVector.GetValue(localIndices)) {
108 Warning("GetPadDimensions","Indices outside limits");
109 return TVector2(0.,0.);
112 return *((TVector2*)fPadDimensionsVector.GetValue(localIndices));
116 Warning("GetPadDimensions","Indices outside limits");
117 return TVector2(0.,0.);
121 //______________________________________________________________________________
122 Int_t AliMpMotifSpecial::GetNofPadDimensions() const
124 /// Return number of different pad dimensions in this motif
127 return fPadDimensionsVector2.size();
131 return fPadDimensionsVector2.GetEntriesFast();
135 //______________________________________________________________________________
136 TVector2 AliMpMotifSpecial::GetPadDimensions(Int_t i) const
138 /// Returns the i-th different pad dimensions
140 if (i<0 || i>GetNofPadDimensions()) {
141 AliFatal("Index outside limits.");
146 return fPadDimensionsVector2[i];
150 return *((TVector2*) fPadDimensionsVector2[i]);
154 //______________________________________________________________________________
155 void AliMpMotifSpecial::CalculateDimensions()
157 /// Calculate motif dimensions and keep them in fDimensions data
163 Double_t* tabSizeX = new Double_t[GetMotifType()->GetNofPadsY()];
164 for (j=0;j<GetMotifType()->GetNofPadsY();++j) tabSizeX[j]=0.0;
166 for (i=0;i<GetMotifType()->GetNofPadsX();++i) {
168 for (j=0;j<GetMotifType()->GetNofPadsY();++j) {
169 TVector2 dim = GetPadDimensions(AliMpIntPair(i,j));
171 tabSizeX[j]+=dim.X();
173 if (trSizeY>sizeY) sizeY=trSizeY;
175 for (j=0;j<GetMotifType()->GetNofPadsY();++j) {
176 if (tabSizeX[j]>sizeX) sizeX = tabSizeX[j];
181 fDimensions = TVector2(sizeX,sizeY);
184 //______________________________________________________________________________
185 TVector2 AliMpMotifSpecial::Dimensions() const
187 /// Give the dimension of the motif
192 //______________________________________________________________________________
194 AliMpMotifSpecial::PadPositionLocal(const AliMpIntPair& localIndices) const
196 /// Give the local position of the pad number (ix,iy)
197 /// (0,0 is the center of the motif)
199 TVector2 dim = GetPadDimensions(localIndices);
201 Double_t posX= dim.X();
202 for (Int_t i=0;i<localIndices.GetFirst();++i) {
203 posX+=2.*GetPadDimensions(AliMpIntPair(i,localIndices.GetSecond())).X();
206 Double_t posY= dim.Y();
207 for (Int_t j=0;j<localIndices.GetSecond();++j) {
208 posY+=2.*GetPadDimensions(AliMpIntPair(localIndices.GetFirst(),j)).Y();
211 return TVector2(posX,posY)-Dimensions();
214 //______________________________________________________________________________
215 AliMpIntPair AliMpMotifSpecial::PadIndicesLocal(const TVector2& localPos) const
217 /// Return the pad indices from a given local position
218 /// or AliMpIntPair::Invalid() if this position doesn't correspond to any valid
221 /// *SOLEIL* : This code suppose that
222 /// - 1) all cells have the same size along the Y direction
223 /// - 2) the column 0 is entierly filled
226 // First : find the j index
227 TVector2 pos = localPos + Dimensions();
231 while (j<GetMotifType()->GetNofPadsY()) {
232 TVector2 padDim = GetPadDimensions(AliMpIntPair(0,j));
238 // Test if it's outside limits
239 if (j==GetMotifType()->GetNofPadsY()){
240 Warning("PadIndicesLocal","The position is outside the motif");
241 return AliMpIntPair::Invalid();
245 // now find the i index, in the j_th row
249 while (i<GetMotifType()->GetNofPadsX()) {
250 TVector2 padDim = GetPadDimensions(AliMpIntPair(i,j));
257 // Test if it's outside limits
259 if (i==GetMotifType()->GetNofPadsX()){
260 Warning("PadIndicesLocal","The position is outside the motif");
261 return AliMpIntPair::Invalid();
264 // then return the found (i,j)
265 return AliMpIntPair(i,j);
267 //______________________________________________________________________________
268 void AliMpMotifSpecial::SetPadDimensions(const AliMpIntPair& localIndices,
269 const TVector2& dimensions)
271 /// Set the dimensions of the pad located at \a localIndices to the given
274 if ( !GetMotifType()->HasPad(localIndices)){
275 Warning("SetPadDimensions","Pad indices outside limits");
279 // fill the dimensions map vector
281 fPadDimensionsVector[VectorIndex(localIndices)]=dimensions;
283 // fill the vector of different pad dimensions
284 // only if these dimensions are not yet present
285 Bool_t isPresent = false;
286 for (Int_t i=0; i<GetNofPadDimensions(); i++) {
287 if (AliMpConstants::IsEqual(fPadDimensionsVector2[i], dimensions))
291 if (!isPresent) fPadDimensionsVector2.push_back(dimensions);
295 TVector2* dimensionsObj = new TVector2(dimensions);
296 fPadDimensionsVector.Add(localIndices, dimensionsObj);
298 // fill the vector of different pad dimensions
299 // only if these dimensions are not yet present
300 Bool_t isPresent = false;
301 for (Int_t i=0; i<GetNofPadDimensions(); i++) {
302 if (AliMpConstants::IsEqual(*((TVector2*) fPadDimensionsVector2[i]), dimensions))
306 if (!isPresent) fPadDimensionsVector2.Add(dimensionsObj);