4 // Class AliMpMotifSpecial
5 // -----------------------
6 // Class that defines a motif with its unique ID
8 // Included in AliRoot: 2003/05/02
9 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
13 #include "AliMpMotifSpecial.h"
14 #include "AliMpMotifType.h"
15 #include "AliMpIntPair.h"
16 #include "AliMpConstants.h"
18 ClassImp(AliMpMotifSpecial)
22 //______________________________________________________________________________
23 Int_t AliMpMotifSpecial::VectorIndex(const AliMpIntPair& indices) const
25 // transform indices to linear vector index
26 return indices.GetFirst()*GetMotifType()->GetNofPadsY() + indices.GetSecond();
32 //______________________________________________________________________________
33 AliMpMotifSpecial::AliMpMotifSpecial():
35 fPadDimensionsVector(),
36 fPadDimensionsVector2()
38 //default dummy constructor
42 //______________________________________________________________________________
43 AliMpMotifSpecial::AliMpMotifSpecial(const TString &id,
44 AliMpMotifType *motifType)
45 : AliMpVMotif(id,motifType),
46 fPadDimensionsVector(),
47 fPadDimensionsVector2()
50 // Normal constructor.
53 fPadDimensionsVector.resize(motifType->GetNofPadsX()*motifType->GetNofPadsY());
57 fPadDimensionsVector.Expand(motifType->GetNofPadsX()*motifType->GetNofPadsY());
61 //______________________________________________________________________________
62 AliMpMotifSpecial::~AliMpMotifSpecial()
67 fPadDimensionsVector.Delete();
72 //______________________________________________________________________________
74 AliMpMotifSpecial::GetPadDimensions(const AliMpIntPair& localIndices) const
76 // returns the dimensions of pad located at the given indices
77 if (GetMotifType()->HasPad(localIndices))
79 return fPadDimensionsVector[VectorIndex(localIndices)];
82 return *((TVector2*)fPadDimensionsVector[VectorIndex(localIndices)]);
85 Warning("GetPadDimensions","Indices outside limits");
86 return TVector2(0.,0.);
90 //______________________________________________________________________________
91 Int_t AliMpMotifSpecial::GetNofPadDimensions() const
93 // returns number of different pad dimensions in this motif
96 return fPadDimensionsVector2.size();
100 return fPadDimensionsVector2.GetEntriesFast();
104 //______________________________________________________________________________
105 TVector2 AliMpMotifSpecial::GetPadDimensions(Int_t i) const
107 // returns the i-th different pad dimensions
109 if (i<0 || i>GetNofPadDimensions()) {
110 Fatal("GetPadDimensions(i)", "Index outside limits.");
115 return fPadDimensionsVector2[i];
119 return *((TVector2*) fPadDimensionsVector2[i]);
123 //______________________________________________________________________________
124 TVector2 AliMpMotifSpecial::Dimensions() const
126 // gives the dimension of the motif
133 Double_t* tabSizeX = new Double_t[GetMotifType()->GetNofPadsY()];
134 for (j=0;j<GetMotifType()->GetNofPadsY();++j) tabSizeX[j]=0.0;
136 for (i=0;i<GetMotifType()->GetNofPadsX();++i) {
138 for (j=0;j<GetMotifType()->GetNofPadsY();++j) {
139 TVector2 dim = GetPadDimensions(AliMpIntPair(i,j));
141 tabSizeX[j]+=dim.X();
143 if (trSizeY>sizeY) sizeY=trSizeY;
145 for (j=0;j<GetMotifType()->GetNofPadsY();++j) {
146 if (tabSizeX[j]>sizeX) sizeX = tabSizeX[j];
151 return TVector2(sizeX,sizeY);
154 //______________________________________________________________________________
156 AliMpMotifSpecial::PadPositionLocal(const AliMpIntPair& localIndices) const
158 // gives the local position of the pad number (ix,iy)
159 // (0,0 is the center of the motif)
161 TVector2 dim = GetPadDimensions(localIndices);
163 Double_t posX= dim.X();
164 for (Int_t i=0;i<localIndices.GetFirst();++i) {
165 posX+=2.*GetPadDimensions(AliMpIntPair(i,localIndices.GetSecond())).X();
168 Double_t posY= dim.Y();
169 for (Int_t j=0;j<localIndices.GetSecond();++j) {
170 posY+=2.*GetPadDimensions(AliMpIntPair(localIndices.GetFirst(),j)).Y();
173 return TVector2(posX,posY)-Dimensions();
176 //______________________________________________________________________________
177 AliMpIntPair AliMpMotifSpecial::PadIndicesLocal(const TVector2& localPos) const
179 // return the pad indices from a given local position
180 // or AliMpIntPair::Invalid() if this position doesn't correspond to any valid
183 // *SOLEIL* : This code suppose that
184 // 1) all cells have the same size along the Y direction
185 // 2) the column 0 is entierly filled
188 // First : find the j index
189 TVector2 pos = localPos + Dimensions();
193 while (j<GetMotifType()->GetNofPadsY()) {
194 TVector2 padDim = GetPadDimensions(AliMpIntPair(0,j));
200 // Test if it's outside limits
201 if (j==GetMotifType()->GetNofPadsY()){
202 Warning("PadIndicesLocal","The position is outside the motif");
203 return AliMpIntPair::Invalid();
207 // now find the i index, in the j_th row
211 while (i<GetMotifType()->GetNofPadsX()) {
212 TVector2 padDim = GetPadDimensions(AliMpIntPair(i,j));
219 // Test if it's outside limits
221 if (i==GetMotifType()->GetNofPadsX()){
222 Warning("PadIndicesLocal","The position is outside the motif");
223 return AliMpIntPair::Invalid();
226 // then return the found (i,j)
227 return AliMpIntPair(i,j);
229 //______________________________________________________________________________
230 void AliMpMotifSpecial::SetPadDimensions(const AliMpIntPair& localIndices,
231 const TVector2& dimensions)
233 // set the dimensions of the pad located at <localIndices> to the given
236 if ( !GetMotifType()->HasPad(localIndices)){
237 Warning("SetPadDimensions","Pad indices outside limits");
241 // fill the dimensions map vector
243 fPadDimensionsVector[VectorIndex(localIndices)]=dimensions;
245 // fill the vector of different pad dimensions
246 // only if these dimensions are not yet present
247 Bool_t isPresent = false;
248 for (Int_t i=0; i<GetNofPadDimensions(); i++) {
249 if (AliMpConstants::IsEqual(fPadDimensionsVector2[i], dimensions))
253 if (!isPresent) fPadDimensionsVector2.push_back(dimensions);
257 TVector2* dimensionsObj = new TVector2(dimensions);
258 fPadDimensionsVector[VectorIndex(localIndices)]= dimensionsObj;
260 // fill the vector of different pad dimensions
261 // only if these dimensions are not yet present
262 Bool_t isPresent = false;
263 for (Int_t i=0; i<GetNofPadDimensions(); i++) {
264 if (AliMpConstants::IsEqual(*((TVector2*) fPadDimensionsVector2[i]), dimensions))
268 if (!isPresent) fPadDimensionsVector2.Add(dimensionsObj);