]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpMotifSpecial.cxx
Coding conventions corrections only
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpMotifSpecial.cxx
1 // $Id$
2 // Category: motif
3 //
4 // Class AliMpMotifSpecial
5 // -----------------------
6 // Class that defines a motif with its unique ID
7 // and the motif type.
8 //
9 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
10
11 #include <TString.h>
12
13 #include "AliMpMotifSpecial.h"
14 #include "AliMpMotifType.h"
15 #include "AliMpIntPair.h"
16 #include "AliMpConstants.h"
17
18 ClassImp(AliMpMotifSpecial)
19
20
21 // private methods
22 //______________________________________________________________________________
23 Int_t AliMpMotifSpecial::VectorIndex(const AliMpIntPair& indices) const
24 {
25 // transform indices to linear vector index
26   return indices.GetFirst()*GetMotifType()->GetNofPadsY() + indices.GetSecond();
27 }
28
29
30 //public methods
31
32 //______________________________________________________________________________
33 AliMpMotifSpecial::AliMpMotifSpecial():
34   AliMpVMotif(),
35   fPadDimensionsVector(),
36   fPadDimensionsVector2()
37 {
38   //default dummy constructor
39 }
40
41
42 //______________________________________________________________________________
43 AliMpMotifSpecial::AliMpMotifSpecial(const TString &id, 
44                                      AliMpMotifType *motifType)
45   : AliMpVMotif(id,motifType),
46     fPadDimensionsVector(),
47     fPadDimensionsVector2()
48   
49 {
50   // Normal constructor.
51
52   fPadDimensionsVector.resize(motifType->GetNofPadsX()*motifType->GetNofPadsY());
53 }
54
55 //______________________________________________________________________________
56 AliMpMotifSpecial::~AliMpMotifSpecial()
57 {
58   //destructor
59 }
60
61
62 //______________________________________________________________________________
63 TVector2 
64 AliMpMotifSpecial::GetPadDimensions(const AliMpIntPair& localIndices) const
65 {
66 // returns the dimensions of pad located at the given indices
67   if (GetMotifType()->HasPad(localIndices))
68     return fPadDimensionsVector[VectorIndex(localIndices)];
69   else {
70     Warning("GetPadDimensions","Indices outside limits");
71     return TVector2(0.,0.);
72   }
73 }
74
75 //______________________________________________________________________________
76 Int_t AliMpMotifSpecial::GetNofPadDimensions() const
77 {
78 // returns number of different pad dimensions in this motif
79
80   return fPadDimensionsVector2.size();
81 }  
82
83 //______________________________________________________________________________
84 TVector2 AliMpMotifSpecial::GetPadDimensions(Int_t i) const
85 {
86 // returns the i-th different pad dimensions 
87
88   if (i<0 || i>GetNofPadDimensions()) {
89     Fatal("GetPadDimensions(i)", "Index outside limits.");
90     return TVector2();
91   }  
92
93   return fPadDimensionsVector2[i];
94 }  
95
96 //______________________________________________________________________________
97 TVector2 AliMpMotifSpecial::Dimensions() const
98 {
99   // gives the dimension of the motif
100
101
102   Int_t i,j;
103   Double_t sizeY=0.;
104   Double_t sizeX=0.;
105   
106   Double_t* tabSizeX = new Double_t[GetMotifType()->GetNofPadsY()];
107   for (j=0;j<GetMotifType()->GetNofPadsY();++j) tabSizeX[j]=0.0;
108   
109   for (i=0;i<GetMotifType()->GetNofPadsX();++i) {
110     Double_t trSizeY=0.;
111     for (j=0;j<GetMotifType()->GetNofPadsY();++j) {
112       TVector2 dim = GetPadDimensions(AliMpIntPair(i,j));
113       trSizeY+=dim.Y();
114       tabSizeX[j]+=dim.X();
115     }
116     if (trSizeY>sizeY) sizeY=trSizeY;
117   }
118   for (j=0;j<GetMotifType()->GetNofPadsY();++j) {
119     if (tabSizeX[j]>sizeX) sizeX = tabSizeX[j];
120   }
121
122   delete tabSizeX;
123   
124   return TVector2(sizeX,sizeY);
125 }
126
127 //______________________________________________________________________________
128 TVector2 
129 AliMpMotifSpecial::PadPositionLocal(const AliMpIntPair& localIndices) const 
130 {
131   // gives the local position of the pad number (ix,iy)
132   // (0,0 is the center of the motif)
133
134   TVector2 dim = GetPadDimensions(localIndices);
135   
136   Double_t posX= dim.X();
137   for (Int_t i=0;i<localIndices.GetFirst();++i) {
138     posX+=2.*GetPadDimensions(AliMpIntPair(i,localIndices.GetSecond())).X();
139   }
140   
141   Double_t posY= dim.Y();
142   for (Int_t j=0;j<localIndices.GetSecond();++j) {
143     posY+=2.*GetPadDimensions(AliMpIntPair(localIndices.GetFirst(),j)).Y();
144   }
145
146   return TVector2(posX,posY)-Dimensions();
147
148 }
149 //______________________________________________________________________________
150 AliMpIntPair AliMpMotifSpecial::PadIndicesLocal(const TVector2& localPos) const
151 {
152   // return the pad indices from a given local position
153   // or AliMpIntPair::Invalid() if this position doesn't correspond to any valid
154   // connection
155
156   // *SOLEIL* : This code suppose that
157   // 1) all cells have the same size along the Y direction
158   // 2) the column 0 is entierly filled
159     
160
161   // First : find the j index
162   TVector2 pos = localPos + Dimensions();
163   Int_t j=0;
164   Double_t y=pos.Y();
165   
166   while (j<GetMotifType()->GetNofPadsY()) {
167     TVector2 padDim = GetPadDimensions(AliMpIntPair(0,j));
168     y-=2.*padDim.Y();
169     if (y<0.) break;
170     j++;
171   }
172
173   // Test if it's outside limits
174   if (j==GetMotifType()->GetNofPadsY()){
175     Warning("PadIndicesLocal","The position is outside the motif");
176     return AliMpIntPair::Invalid();
177   }
178   
179   
180   // now find the i index, in the j_th row
181   Int_t i=0;
182   Double_t x=pos.X();
183   
184   while (i<GetMotifType()->GetNofPadsX()) {
185     TVector2 padDim = GetPadDimensions(AliMpIntPair(i,j));
186     x-=2.*padDim.X();
187     if (x<0.) break;
188     i++;
189   }
190   
191   
192   // Test if it's outside limits
193
194   if (i==GetMotifType()->GetNofPadsX()){
195     Warning("PadIndicesLocal","The position is outside the motif");
196     return AliMpIntPair::Invalid();
197   }
198    
199   // then return the found (i,j)
200   return AliMpIntPair(i,j);  
201 }
202 //______________________________________________________________________________
203 void AliMpMotifSpecial::SetPadDimensions(const AliMpIntPair& localIndices,
204                                          const TVector2& dimensions)
205 {
206   // set the dimensions of the pad located at <localIndices> to the given
207   // <dimensions>
208   
209   if ( !GetMotifType()->HasPad(localIndices)){
210     Warning("SetPadDimensions","Pad indices outside limits");
211     return;
212   }  
213
214   // fill the dimensions map vector
215   fPadDimensionsVector[VectorIndex(localIndices)]=dimensions;
216   
217   // fill the vector of different pad dimensions
218   // only if these dimensions are not yet present
219   Bool_t isPresent = false;
220   for (Int_t i=0; i<GetNofPadDimensions(); i++) {
221     if (AliMpConstants::IsEqual(fPadDimensionsVector2[i], dimensions)) 
222       isPresent = true;    
223   }    
224   
225   if (!isPresent) fPadDimensionsVector2.push_back(dimensions);
226 }