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