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 "AliMpIntPair.h"
32 #include "AliMpConstants.h"
39 ClassImp(AliMpMotifSpecial)
43 //______________________________________________________________________________
44 AliMpMotifSpecial::AliMpMotifSpecial():
47 fPadDimensionsVector(),
48 fPadDimensionsVector2()
50 /// Default constructor
54 //______________________________________________________________________________
55 AliMpMotifSpecial::AliMpMotifSpecial(const TString &id,
56 AliMpMotifType *motifType)
57 : AliMpVMotif(id,motifType),
60 fPadDimensionsVector(),
63 fPadDimensionsVector(true),
65 fPadDimensionsVector2()
68 /// Standard constructor.
71 fPadDimensionsVector.resize(motifType->GetNofPadsX()*motifType->GetNofPadsY());
75 //______________________________________________________________________________
76 AliMpMotifSpecial::~AliMpMotifSpecial()
86 //______________________________________________________________________________
87 Int_t AliMpMotifSpecial::VectorIndex(const AliMpIntPair& indices) const
89 /// Transform indices to linear vector index
91 return indices.GetFirst()*GetMotifType()->GetNofPadsY() + indices.GetSecond();
99 #include <Riostream.h>
100 //______________________________________________________________________________
102 AliMpMotifSpecial::GetPadDimensions(const AliMpIntPair& localIndices) const
104 /// Return the dimensions of pad located at the given indices
106 if (GetMotifType()->HasPad(localIndices)) {
108 return fPadDimensionsVector[VectorIndex(localIndices)];
111 if (!fPadDimensionsVector.GetValue(localIndices)) {
112 Warning("GetPadDimensions","Indices outside limits");
113 return TVector2(0.,0.);
116 return *((TVector2*)fPadDimensionsVector.GetValue(localIndices));
120 Warning("GetPadDimensions","Indices outside limits");
121 return TVector2(0.,0.);
125 //______________________________________________________________________________
126 Int_t AliMpMotifSpecial::GetNofPadDimensions() const
128 /// Return number of different pad dimensions in this motif
131 return fPadDimensionsVector2.size();
135 return fPadDimensionsVector2.GetEntriesFast();
139 //______________________________________________________________________________
140 TVector2 AliMpMotifSpecial::GetPadDimensions(Int_t i) const
142 /// Returns the i-th different pad dimensions
144 if (i<0 || i>GetNofPadDimensions()) {
145 AliFatal("Index outside limits.");
150 return fPadDimensionsVector2[i];
154 return *((TVector2*) fPadDimensionsVector2[i]);
158 //______________________________________________________________________________
159 void AliMpMotifSpecial::CalculateDimensions()
161 /// Calculate motif dimensions and keep them in fDimensions data
167 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) {
173 TVector2 dim = GetPadDimensions(AliMpIntPair(i,j));
175 tabSizeX[j]+=dim.X();
177 if (trSizeY>sizeY) sizeY=trSizeY;
179 for (j=0;j<GetMotifType()->GetNofPadsY();++j) {
180 if (tabSizeX[j]>sizeX) sizeX = tabSizeX[j];
185 fDimensions = TVector2(sizeX,sizeY);
188 //______________________________________________________________________________
189 TVector2 AliMpMotifSpecial::Dimensions() const
191 /// Give the dimension of the motif
196 //______________________________________________________________________________
198 AliMpMotifSpecial::PadPositionLocal(const AliMpIntPair& localIndices) const
200 /// Give the local position of the pad number (ix,iy)
201 /// (0,0 is the center of the motif)
203 TVector2 dim = GetPadDimensions(localIndices);
205 Double_t posX= dim.X();
206 for (Int_t i=0;i<localIndices.GetFirst();++i) {
207 posX+=2.*GetPadDimensions(AliMpIntPair(i,localIndices.GetSecond())).X();
210 Double_t posY= dim.Y();
211 for (Int_t j=0;j<localIndices.GetSecond();++j) {
212 posY+=2.*GetPadDimensions(AliMpIntPair(localIndices.GetFirst(),j)).Y();
215 return TVector2(posX,posY)-Dimensions();
218 //______________________________________________________________________________
219 AliMpIntPair AliMpMotifSpecial::PadIndicesLocal(const TVector2& localPos) const
221 /// Return the pad indices from a given local position
222 /// or AliMpIntPair::Invalid() if this position doesn't correspond to any valid
225 /// *SOLEIL* : This code suppose that
226 /// - 1) all cells have the same size along the Y direction
227 /// - 2) the column 0 is entierly filled
230 // First : find the j index
231 TVector2 pos = localPos + Dimensions();
235 while (j<GetMotifType()->GetNofPadsY()) {
236 TVector2 padDim = GetPadDimensions(AliMpIntPair(0,j));
242 // Test if it's outside limits
243 if (j==GetMotifType()->GetNofPadsY()){
244 Warning("PadIndicesLocal","The position is outside the motif");
245 return AliMpIntPair::Invalid();
249 // now find the i index, in the j_th row
253 while (i<GetMotifType()->GetNofPadsX()) {
254 TVector2 padDim = GetPadDimensions(AliMpIntPair(i,j));
261 // Test if it's outside limits
263 if (i==GetMotifType()->GetNofPadsX()){
264 Warning("PadIndicesLocal","The position is outside the motif");
265 return AliMpIntPair::Invalid();
268 // then return the found (i,j)
269 return AliMpIntPair(i,j);
271 //______________________________________________________________________________
272 void AliMpMotifSpecial::SetPadDimensions(const AliMpIntPair& localIndices,
273 const TVector2& dimensions)
275 /// Set the dimensions of the pad located at \a localIndices to the given
278 if ( !GetMotifType()->HasPad(localIndices)){
279 Warning("SetPadDimensions","Pad indices outside limits");
283 // fill the dimensions map vector
285 fPadDimensionsVector[VectorIndex(localIndices)]=dimensions;
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(fPadDimensionsVector2[i], dimensions))
295 if (!isPresent) fPadDimensionsVector2.push_back(dimensions);
299 TVector2* dimensionsObj = new TVector2(dimensions);
300 fPadDimensionsVector.Add(localIndices, dimensionsObj);
302 // fill the vector of different pad dimensions
303 // only if these dimensions are not yet present
304 Bool_t isPresent = false;
305 for (Int_t i=0; i<GetNofPadDimensions(); i++) {
306 if (AliMpConstants::IsEqual(*((TVector2*) fPadDimensionsVector2[i]), dimensions))
310 if (!isPresent) fPadDimensionsVector2.Add(dimensionsObj);