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