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