]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpMotifSpecial.cxx
In AliMpPad:
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpMotifSpecial.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
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  **************************************************************************/
15
16 // $Id$
17 // $MpId: AliMpMotifSpecial.cxx,v 1.12 2006/05/24 13:58:41 ivana Exp $
18 // Category: motif
19
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 //-----------------------------------------------------------------------------
28
29 #include "AliMpMotifSpecial.h"
30 #include "AliMpMotifType.h"
31 #include "AliMpIntPair.h"
32 #include "AliMpConstants.h"
33
34 #include "AliLog.h"
35
36 #include <TString.h>
37
38 /// \cond CLASSIMP
39 ClassImp(AliMpMotifSpecial)
40 /// \endcond
41
42
43 //______________________________________________________________________________
44 AliMpMotifSpecial::AliMpMotifSpecial():
45   AliMpVMotif(),
46   fDimensions(),
47   fPadDimensionsVector(),
48   fPadDimensionsVector2()
49 {
50   /// Default constructor
51 }
52
53
54 //______________________________________________________________________________
55 AliMpMotifSpecial::AliMpMotifSpecial(const TString &id, 
56                                      AliMpMotifType *motifType)
57   : AliMpVMotif(id,motifType),
58     fDimensions(),
59 #ifdef WITH_STL
60     fPadDimensionsVector(),
61 #endif    
62 #ifdef WITH_ROOT
63     fPadDimensionsVector(true),
64 #endif    
65     fPadDimensionsVector2()
66   
67 {
68   /// Standard constructor.
69
70 #ifdef WITH_STL
71   fPadDimensionsVector.resize(motifType->GetNofPadsX()*motifType->GetNofPadsY());
72 #endif  
73 }
74
75 //______________________________________________________________________________
76 AliMpMotifSpecial::~AliMpMotifSpecial()
77 {
78   /// Destructor
79 }
80
81
82 //
83 // private methods
84 //
85
86 //______________________________________________________________________________
87 Int_t AliMpMotifSpecial::VectorIndex(const AliMpIntPair& indices) const
88 {
89 /// Transform indices to linear vector index
90
91   return indices.GetFirst()*GetMotifType()->GetNofPadsY() + indices.GetSecond();
92 }
93
94
95 //
96 // public methods
97 //
98
99 #include <Riostream.h>
100 //______________________________________________________________________________
101 TVector2 
102 AliMpMotifSpecial::GetPadDimensions(const AliMpIntPair& localIndices) const
103 {
104 /// Return the dimensions of pad located at the given indices
105
106   if (GetMotifType()->HasPad(localIndices)) {
107 #ifdef WITH_STL
108     return fPadDimensionsVector[VectorIndex(localIndices)];
109 #endif  
110 #ifdef WITH_ROOT
111     if (!fPadDimensionsVector.GetValue(localIndices)) {
112       Warning("GetPadDimensions","Indices outside limits");
113       return TVector2(0.,0.);
114     }
115     else      
116       return  *((TVector2*)fPadDimensionsVector.GetValue(localIndices));
117 #endif 
118   } 
119   else {
120     Warning("GetPadDimensions","Indices outside limits");
121     return TVector2(0.,0.);
122   }
123 }
124
125 //______________________________________________________________________________
126 Int_t AliMpMotifSpecial::GetNofPadDimensions() const
127 {
128 /// Return number of different pad dimensions in this motif
129
130 #ifdef WITH_STL
131   return fPadDimensionsVector2.size();
132 #endif  
133
134 #ifdef WITH_ROOT
135   return fPadDimensionsVector2.GetEntriesFast();
136 #endif  
137 }  
138
139 //______________________________________________________________________________
140 TVector2 AliMpMotifSpecial::GetPadDimensions(Int_t i) const
141 {
142 /// Returns the i-th different pad dimensions 
143
144   if (i<0 || i>GetNofPadDimensions()) {
145     AliFatal("Index outside limits.");
146     return TVector2();
147   }  
148
149 #ifdef WITH_STL
150   return fPadDimensionsVector2[i];
151 #endif  
152
153 #ifdef WITH_ROOT
154   return *((TVector2*) fPadDimensionsVector2[i]);
155 #endif  
156 }  
157
158 //______________________________________________________________________________
159 void AliMpMotifSpecial::CalculateDimensions()
160 {
161   /// Calculate motif dimensions and keep them in fDimensions data
162
163   Int_t i,j;
164   Double_t sizeY=0.;
165   Double_t sizeX=0.;
166   
167   Double_t* tabSizeX = new Double_t[GetMotifType()->GetNofPadsY()];
168   for (j=0;j<GetMotifType()->GetNofPadsY();++j) tabSizeX[j]=0.0;
169   
170   for (i=0;i<GetMotifType()->GetNofPadsX();++i) {
171     Double_t trSizeY=0.;
172     for (j=0;j<GetMotifType()->GetNofPadsY();++j) {
173       TVector2 dim = GetPadDimensions(AliMpIntPair(i,j));
174       trSizeY+=dim.Y();
175       tabSizeX[j]+=dim.X();
176     }
177     if (trSizeY>sizeY) sizeY=trSizeY;
178   }
179   for (j=0;j<GetMotifType()->GetNofPadsY();++j) {
180     if (tabSizeX[j]>sizeX) sizeX = tabSizeX[j];
181   }
182
183   delete [] tabSizeX;
184   
185   fDimensions = TVector2(sizeX,sizeY);
186 }  
187
188 //______________________________________________________________________________
189 TVector2 AliMpMotifSpecial::Dimensions() const
190 {
191   /// Give the dimension of the motif
192
193   return fDimensions;
194 }
195
196 //______________________________________________________________________________
197 TVector2 
198 AliMpMotifSpecial::PadPositionLocal(const AliMpIntPair& localIndices) const 
199 {
200   /// Give the local position of the pad number (ix,iy)
201   /// (0,0 is the center of the motif)
202
203   TVector2 dim = GetPadDimensions(localIndices);
204   
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();
208   }
209   
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();
213   }
214
215   return TVector2(posX,posY)-Dimensions();
216
217 }
218 //______________________________________________________________________________
219 AliMpIntPair AliMpMotifSpecial::PadIndicesLocal(const TVector2& localPos) const
220 {
221   /// Return the pad indices from a given local position
222   /// or AliMpIntPair::Invalid() if this position doesn't correspond to any valid
223   /// connection
224   ///
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
228     
229
230   // First : find the j index
231   TVector2 pos = localPos + Dimensions();
232   Int_t j=0;
233   Double_t y=pos.Y();
234   
235   while (j<GetMotifType()->GetNofPadsY()) {
236     TVector2 padDim = GetPadDimensions(AliMpIntPair(0,j));
237     y-=2.*padDim.Y();
238     if (y<0.) break;
239     j++;
240   }
241
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();
246   }
247   
248   
249   // now find the i index, in the j_th row
250   Int_t i=0;
251   Double_t x=pos.X();
252   
253   while (i<GetMotifType()->GetNofPadsX()) {
254     TVector2 padDim = GetPadDimensions(AliMpIntPair(i,j));
255     x-=2.*padDim.X();
256     if (x<0.) break;
257     i++;
258   }
259   
260   
261   // Test if it's outside limits
262
263   if (i==GetMotifType()->GetNofPadsX()){
264     Warning("PadIndicesLocal","The position is outside the motif");
265     return AliMpIntPair::Invalid();
266   }
267    
268   // then return the found (i,j)
269   return AliMpIntPair(i,j);  
270 }
271 //______________________________________________________________________________
272 void AliMpMotifSpecial::SetPadDimensions(const AliMpIntPair& localIndices,
273                                          const TVector2& dimensions)
274 {
275   /// Set the dimensions of the pad located at \a localIndices to the given
276   /// \a dimensions
277   
278   if ( !GetMotifType()->HasPad(localIndices)){
279     Warning("SetPadDimensions","Pad indices outside limits");
280     return;
281   }  
282
283   // fill the dimensions map vector
284 #ifdef WITH_STL
285   fPadDimensionsVector[VectorIndex(localIndices)]=dimensions;
286   
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)) 
292       isPresent = true;    
293   }    
294   
295   if (!isPresent) fPadDimensionsVector2.push_back(dimensions);
296 #endif  
297
298 #ifdef WITH_ROOT
299   TVector2* dimensionsObj = new TVector2(dimensions);
300   fPadDimensionsVector.Add(localIndices, dimensionsObj);
301
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)) 
307       isPresent = true;    
308   }    
309   
310   if (!isPresent) fPadDimensionsVector2.Add(dimensionsObj);
311 #endif  
312   
313 }