]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpMotifSpecial.cxx
PMD module
[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 "AliMpEncodePair.h"
32 #include "AliMpConstants.h"
33
34 #include "AliLog.h"
35
36 #include <TString.h>
37 #include <Riostream.h>
38 #include <TVector2.h>
39
40 /// \cond CLASSIMP
41 ClassImp(AliMpMotifSpecial)
42 /// \endcond
43
44 Int_t AliMpMotifSpecial::fgkPadDimensions2Size = 5;
45
46 //______________________________________________________________________________
47 AliMpMotifSpecial::AliMpMotifSpecial(const TString &id, 
48                                      AliMpMotifType *motifType)
49   : AliMpVMotif(id,motifType),
50     fDimensionX(0.),
51     fDimensionY(0.),
52     fPadDimensionsVector(),
53     fNofPadDimensions2(0),
54     fPadDimensions2X(fgkPadDimensions2Size),
55     fPadDimensions2Y(fgkPadDimensions2Size)
56   
57 {
58   /// Standard constructor.
59 }
60
61 //______________________________________________________________________________
62 AliMpMotifSpecial::AliMpMotifSpecial(TRootIOCtor* ioCtor):
63   AliMpVMotif(),
64   fDimensionX(0.),
65   fDimensionY(0.),
66   fPadDimensionsVector(ioCtor),
67   fNofPadDimensions2(),
68   fPadDimensions2X(),
69   fPadDimensions2Y()
70 {
71   /// Root IO constructor
72 }
73
74
75 //______________________________________________________________________________
76 AliMpMotifSpecial::~AliMpMotifSpecial()
77 {
78   /// Destructor
79 }
80
81
82 //
83 // public methods
84 //
85
86 //______________________________________________________________________________
87 void 
88 AliMpMotifSpecial::GetPadDimensionsByIndices(MpPair_t localIndices,
89                                     Double_t& dx, Double_t& dy) const
90 {
91 /// Return the dimensions of pad located at the given indices
92
93   GetPadDimensionsByIndices(AliMp::PairFirst(localIndices), 
94                             AliMp::PairSecond(localIndices),
95                             dx, dy);
96 }
97
98 //______________________________________________________________________________
99 void 
100 AliMpMotifSpecial::GetPadDimensionsByIndices(Int_t ixLocal, Int_t iyLocal,
101                                     Double_t& dx, Double_t& dy) const
102 {
103 /// Return the dimensions of pad located at the given indices
104
105   if ( GetMotifType()->HasPadByLocalIndices(ixLocal, iyLocal) ) {
106     if (!fPadDimensionsVector.GetValue(ixLocal, iyLocal)) {
107       Warning("GetPadDimensionsByIndices","Indices outside limits");
108       dx = 0.;
109       dy = 0.;
110     }
111     else {     
112       dx = ((TVector2*)fPadDimensionsVector.GetValue(ixLocal, iyLocal))->X();
113       dy = ((TVector2*)fPadDimensionsVector.GetValue(ixLocal, iyLocal))->Y();
114     }  
115   } 
116   else {
117     Warning("GetPadDimensionsByIndices","Indices outside limits");
118     dx = 0.;
119     dy = 0.;
120   }
121 }
122
123 //______________________________________________________________________________
124 Int_t AliMpMotifSpecial::GetNofPadDimensions() const
125 {
126 /// Return number of different pad dimensions in this motif
127
128   return fNofPadDimensions2;
129 }  
130
131 //______________________________________________________________________________
132 Double_t AliMpMotifSpecial::GetPadDimensionX(Int_t i) const
133 {
134 /// Returns the i-th different pad dimensions 
135
136   if ( i < 0 || i > fNofPadDimensions2 ) {
137     AliFatal("Index outside limits.");
138     return 0;
139   }  
140
141   return fPadDimensions2X[i];
142 }  
143
144 //______________________________________________________________________________
145 Double_t AliMpMotifSpecial::GetPadDimensionY(Int_t i) const
146 {
147 /// Returns the i-th different pad dimensions 
148
149   if ( i < 0 || i > fNofPadDimensions2 ) {
150     AliFatal("Index outside limits.");
151     return 0;
152   }  
153
154   return fPadDimensions2Y[i];
155 }  
156
157 //______________________________________________________________________________
158 void AliMpMotifSpecial::CalculateDimensions()
159 {
160   /// Calculate motif dimensions and keep them in fDimensionX/Y data
161
162   Int_t i,j;
163   fDimensionY = 0.;
164   fDimensionX = 0.;
165   
166   Double_t* tabSizeX = new Double_t[GetMotifType()->GetNofPadsY()];
167   
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       Double_t dimx, dimy;
174       GetPadDimensionsByIndices(i,j, dimx, dimy);
175       trSizeY += dimy;
176       tabSizeX[j] += dimx;
177     }
178     if ( trSizeY > fDimensionY ) fDimensionY = trSizeY;
179   }
180
181   for ( j=0; j<GetMotifType()->GetNofPadsY(); ++j ) {
182     if ( tabSizeX[j] > fDimensionX ) fDimensionX = tabSizeX[j];
183   }
184
185   delete [] tabSizeX;
186 }  
187
188 //______________________________________________________________________________
189 Double_t AliMpMotifSpecial::DimensionX() const
190 {
191   /// Give the dimension of the motif
192
193   return fDimensionX;
194 }
195
196 //______________________________________________________________________________
197 Double_t AliMpMotifSpecial::DimensionY() const
198 {
199   /// Give the dimension of the motif
200
201   return fDimensionY;
202 }
203
204 //______________________________________________________________________________
205 void
206 AliMpMotifSpecial::PadPositionLocal(MpPair_t localIndices,
207                                     Double_t& posx, Double_t& posy) const 
208 {
209   /// Give the local position of the pad number (ix,iy)
210   /// (0,0 is the center of the motif)
211
212   return PadPositionLocal(AliMp::PairFirst(localIndices),
213                           AliMp::PairSecond(localIndices),
214                           posx, posy);
215
216 }
217
218 //______________________________________________________________________________
219 void
220 AliMpMotifSpecial::PadPositionLocal(Int_t ixLocal, Int_t iyLocal,
221                                     Double_t& posx, Double_t& posy) const 
222 {
223   /// Give the local position of the pad number (ix,iy)
224   /// (0,0 is the center of the motif)
225
226   Double_t dx0, dy0;
227   GetPadDimensionsByIndices(ixLocal, iyLocal, dx0, dy0);
228   
229   posx = dx0;
230   for ( Int_t i=0 ;i<ixLocal; ++i ) {
231     Double_t dxi, dyi;
232     GetPadDimensionsByIndices(i, iyLocal, dxi, dyi);
233     posx += 2.*dxi;
234   }
235   
236   posy = dy0;
237   for ( Int_t j=0; j<iyLocal; ++j ) {
238     Double_t dxi, dyi;
239     GetPadDimensionsByIndices(ixLocal, j, dxi, dyi);
240     posy += 2.*dyi;
241   }
242   
243   posx -= DimensionX();
244   posy -= DimensionY();
245 }
246
247 //______________________________________________________________________________
248 MpPair_t 
249 AliMpMotifSpecial::PadIndicesLocal(Double_t localPosX, Double_t localPosY) const
250 {
251   /// Return the pad indices from a given local position
252   /// or -1 if this position doesn't correspond to any valid
253   /// connection
254   ///
255   /// *SOLEIL* : This code suppose that
256   /// - 1) all cells have the same size along the Y direction
257   /// - 2) the column 0 is entierly filled
258     
259
260   // First : find the j index
261   Int_t j=0;
262   Double_t y = localPosY + DimensionY();
263   
264   while (j<GetMotifType()->GetNofPadsY()) {
265     Double_t padDimX, padDimY;
266     GetPadDimensionsByIndices(0, j, padDimX, padDimY);
267     y -= 2.*padDimY;
268     if ( y < 0. ) break;
269     j++;
270   }
271
272   // Test if it's outside limits
273   if (j==GetMotifType()->GetNofPadsY()){
274     Warning("PadIndicesLocal","The position is outside the motif");
275     return -1;
276   }
277   
278   
279   // now find the i index, in the j_th row
280   Int_t i=0;
281   Double_t x = localPosX + DimensionX();
282   
283   while (i<GetMotifType()->GetNofPadsX()) {
284     Double_t padDimX, padDimY;
285     GetPadDimensionsByIndices(i, j, padDimX, padDimY);
286     x -= 2.*padDimX;
287     if ( x < 0. ) break;
288     i++;
289   }
290   
291   
292   // Test if it's outside limits
293
294   if (i==GetMotifType()->GetNofPadsX()){
295     Warning("PadIndicesLocal","The position is outside the motif");
296     return -1;
297   }
298    
299   // then return the found (i,j)
300   return AliMp::Pair(i,j);  
301 }
302
303 //______________________________________________________________________________
304 void AliMpMotifSpecial::SetPadDimensions(MpPair_t localIndices,
305                                          Double_t dx, Double_t dy)
306 {
307   /// Set the dimensions of the pad located at \a localIndices to the given
308   /// \a dimensions
309
310   SetPadDimensions(AliMp::PairFirst(localIndices), 
311                    AliMp::PairSecond(localIndices), dx, dy);  
312 }
313
314 //______________________________________________________________________________
315 void AliMpMotifSpecial::SetPadDimensions(Int_t ixLocal, Int_t iyLocal,
316                                          Double_t dx, Double_t dy)
317 {
318   /// Set the dimensions of the pad located at \a localIndices to the given
319   /// \a dimensions
320   
321   if ( ! GetMotifType()->HasPadByLocalIndices(ixLocal, iyLocal) ) {
322     Warning("SetPadDimensions","Pad indices outside limits");
323     return;
324   }  
325
326   // fill the dimensions map vector
327   TVector2* dimensionsObj = new TVector2(dx, dy);
328   fPadDimensionsVector.Add(ixLocal, iyLocal, dimensionsObj);
329
330   // fill the vector of different pad dimensions
331   // only if these dimensions are not yet present
332   Bool_t isPresent = false;
333   for (Int_t i=0; i<GetNofPadDimensions(); i++) {
334     if ( AliMpConstants::IsEqual(
335             fPadDimensions2X[i], fPadDimensions2Y[i], dx, dy) ) 
336       isPresent = true;    
337   }    
338   
339   if (!isPresent) {
340     fPadDimensions2X.AddAt(dx, fNofPadDimensions2);
341     fPadDimensions2Y.AddAt(dy, fNofPadDimensions2++);
342   }  
343 }