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