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"
37 ClassImp(AliMpMotifSpecial)
41 //______________________________________________________________________________
42 AliMpMotifSpecial::AliMpMotifSpecial():
45 fPadDimensionsVector(),
46 fPadDimensionsVector2()
48 /// Default constructor
52 //______________________________________________________________________________
53 AliMpMotifSpecial::AliMpMotifSpecial(const TString &id,
54 AliMpMotifType *motifType)
55 : AliMpVMotif(id,motifType),
58 fPadDimensionsVector(),
61 fPadDimensionsVector(true),
63 fPadDimensionsVector2()
66 /// Standard constructor.
69 fPadDimensionsVector.resize(motifType->GetNofPadsX()*motifType->GetNofPadsY());
73 //______________________________________________________________________________
74 AliMpMotifSpecial::~AliMpMotifSpecial()
84 //______________________________________________________________________________
85 Int_t AliMpMotifSpecial::VectorIndex(const AliMpIntPair& indices) const
87 /// Transform indices to linear vector index
89 return indices.GetFirst()*GetMotifType()->GetNofPadsY() + indices.GetSecond();
97 #include <Riostream.h>
98 //______________________________________________________________________________
100 AliMpMotifSpecial::GetPadDimensions(const AliMpIntPair& localIndices) const
102 /// Return the dimensions of pad located at the given indices
104 if (GetMotifType()->HasPad(localIndices)) {
106 return fPadDimensionsVector[VectorIndex(localIndices)];
109 if (!fPadDimensionsVector.GetValue(localIndices)) {
110 Warning("GetPadDimensions","Indices outside limits");
111 return TVector2(0.,0.);
114 return *((TVector2*)fPadDimensionsVector.GetValue(localIndices));
118 Warning("GetPadDimensions","Indices outside limits");
119 return TVector2(0.,0.);
123 //______________________________________________________________________________
124 Int_t AliMpMotifSpecial::GetNofPadDimensions() const
126 /// Return number of different pad dimensions in this motif
129 return fPadDimensionsVector2.size();
133 return fPadDimensionsVector2.GetEntriesFast();
137 //______________________________________________________________________________
138 TVector2 AliMpMotifSpecial::GetPadDimensions(Int_t i) const
140 /// Returns the i-th different pad dimensions
142 if (i<0 || i>GetNofPadDimensions()) {
143 AliFatal("Index outside limits.");
148 return fPadDimensionsVector2[i];
152 return *((TVector2*) fPadDimensionsVector2[i]);
156 //______________________________________________________________________________
157 void AliMpMotifSpecial::CalculateDimensions()
159 /// Calculate motif dimensions and keep them in fDimensions data
165 Double_t* tabSizeX = new Double_t[GetMotifType()->GetNofPadsY()];
166 for (j=0;j<GetMotifType()->GetNofPadsY();++j) tabSizeX[j]=0.0;
168 for (i=0;i<GetMotifType()->GetNofPadsX();++i) {
170 for (j=0;j<GetMotifType()->GetNofPadsY();++j) {
171 TVector2 dim = GetPadDimensions(AliMpIntPair(i,j));
173 tabSizeX[j]+=dim.X();
175 if (trSizeY>sizeY) sizeY=trSizeY;
177 for (j=0;j<GetMotifType()->GetNofPadsY();++j) {
178 if (tabSizeX[j]>sizeX) sizeX = tabSizeX[j];
183 fDimensions = TVector2(sizeX,sizeY);
186 //______________________________________________________________________________
187 TVector2 AliMpMotifSpecial::Dimensions() const
189 /// Give the dimension of the motif
194 //______________________________________________________________________________
196 AliMpMotifSpecial::PadPositionLocal(const AliMpIntPair& localIndices) const
198 /// Give the local position of the pad number (ix,iy)
199 /// (0,0 is the center of the motif)
201 TVector2 dim = GetPadDimensions(localIndices);
203 Double_t posX= dim.X();
204 for (Int_t i=0;i<localIndices.GetFirst();++i) {
205 posX+=2.*GetPadDimensions(AliMpIntPair(i,localIndices.GetSecond())).X();
208 Double_t posY= dim.Y();
209 for (Int_t j=0;j<localIndices.GetSecond();++j) {
210 posY+=2.*GetPadDimensions(AliMpIntPair(localIndices.GetFirst(),j)).Y();
213 return TVector2(posX,posY)-Dimensions();
216 //______________________________________________________________________________
217 AliMpIntPair AliMpMotifSpecial::PadIndicesLocal(const TVector2& localPos) const
219 /// Return the pad indices from a given local position
220 /// or AliMpIntPair::Invalid() if this position doesn't correspond to any valid
223 /// *SOLEIL* : This code suppose that
224 /// - 1) all cells have the same size along the Y direction
225 /// - 2) the column 0 is entierly filled
228 // First : find the j index
229 TVector2 pos = localPos + Dimensions();
233 while (j<GetMotifType()->GetNofPadsY()) {
234 TVector2 padDim = GetPadDimensions(AliMpIntPair(0,j));
240 // Test if it's outside limits
241 if (j==GetMotifType()->GetNofPadsY()){
242 Warning("PadIndicesLocal","The position is outside the motif");
243 return AliMpIntPair::Invalid();
247 // now find the i index, in the j_th row
251 while (i<GetMotifType()->GetNofPadsX()) {
252 TVector2 padDim = GetPadDimensions(AliMpIntPair(i,j));
259 // Test if it's outside limits
261 if (i==GetMotifType()->GetNofPadsX()){
262 Warning("PadIndicesLocal","The position is outside the motif");
263 return AliMpIntPair::Invalid();
266 // then return the found (i,j)
267 return AliMpIntPair(i,j);
269 //______________________________________________________________________________
270 void AliMpMotifSpecial::SetPadDimensions(const AliMpIntPair& localIndices,
271 const TVector2& dimensions)
273 /// Set the dimensions of the pad located at \a localIndices to the given
276 if ( !GetMotifType()->HasPad(localIndices)){
277 Warning("SetPadDimensions","Pad indices outside limits");
281 // fill the dimensions map vector
283 fPadDimensionsVector[VectorIndex(localIndices)]=dimensions;
285 // fill the vector of different pad dimensions
286 // only if these dimensions are not yet present
287 Bool_t isPresent = false;
288 for (Int_t i=0; i<GetNofPadDimensions(); i++) {
289 if (AliMpConstants::IsEqual(fPadDimensionsVector2[i], dimensions))
293 if (!isPresent) fPadDimensionsVector2.push_back(dimensions);
297 TVector2* dimensionsObj = new TVector2(dimensions);
298 fPadDimensionsVector.Add(localIndices, dimensionsObj);
300 // fill the vector of different pad dimensions
301 // only if these dimensions are not yet present
302 Bool_t isPresent = false;
303 for (Int_t i=0; i<GetNofPadDimensions(); i++) {
304 if (AliMpConstants::IsEqual(*((TVector2*) fPadDimensionsVector2[i]), dimensions))
308 if (!isPresent) fPadDimensionsVector2.Add(dimensionsObj);