]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpMotifSpecial.cxx
- All mapping enums within namespace (AliMp).
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpMotifSpecial.cxx
CommitLineData
dee1d5f1 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
5f91c9e8 16// $Id$
13985652 17// $MpId: AliMpMotifSpecial.cxx,v 1.12 2006/05/24 13:58:41 ivana Exp $
5f91c9e8 18// Category: motif
19//
20// Class AliMpMotifSpecial
21// -----------------------
22// Class that defines a motif with its unique ID
23// and the motif type.
dbe945cc 24// Included in AliRoot: 2003/05/02
5f91c9e8 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
2c605e66 32#include <TString.h>
33
13985652 34/// \cond CLASSIMP
5f91c9e8 35ClassImp(AliMpMotifSpecial)
13985652 36/// \endcond
5f91c9e8 37
38
5f91c9e8 39//______________________________________________________________________________
40AliMpMotifSpecial::AliMpMotifSpecial():
41 AliMpVMotif(),
0471c97b 42 fDimensions(),
5f91c9e8 43 fPadDimensionsVector(),
44 fPadDimensionsVector2()
45{
dee1d5f1 46 /// Default constructor
5f91c9e8 47}
48
49
50//______________________________________________________________________________
51AliMpMotifSpecial::AliMpMotifSpecial(const TString &id,
52 AliMpMotifType *motifType)
53 : AliMpVMotif(id,motifType),
0471c97b 54 fDimensions(),
5006ec94 55#ifdef WITH_STL
5f91c9e8 56 fPadDimensionsVector(),
5006ec94 57#endif
58#ifdef WITH_ROOT
59 fPadDimensionsVector(true),
60#endif
5f91c9e8 61 fPadDimensionsVector2()
62
63{
dee1d5f1 64 /// Standard constructor.
5f91c9e8 65
f79c58a5 66#ifdef WITH_STL
5f91c9e8 67 fPadDimensionsVector.resize(motifType->GetNofPadsX()*motifType->GetNofPadsY());
f79c58a5 68#endif
5f91c9e8 69}
70
2998a151 71//______________________________________________________________________________
72AliMpMotifSpecial::~AliMpMotifSpecial()
73{
dee1d5f1 74 /// Destructor
2998a151 75}
76
77
dee1d5f1 78//
79// private methods
80//
81
82//______________________________________________________________________________
83Int_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
5006ec94 95#include <Riostream.h>
5f91c9e8 96//______________________________________________________________________________
97TVector2
98AliMpMotifSpecial::GetPadDimensions(const AliMpIntPair& localIndices) const
99{
dee1d5f1 100/// Return the dimensions of pad located at the given indices
101
5006ec94 102 if (GetMotifType()->HasPad(localIndices)) {
f79c58a5 103#ifdef WITH_STL
5f91c9e8 104 return fPadDimensionsVector[VectorIndex(localIndices)];
f79c58a5 105#endif
106#ifdef WITH_ROOT
5006ec94 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 }
5f91c9e8 115 else {
116 Warning("GetPadDimensions","Indices outside limits");
117 return TVector2(0.,0.);
118 }
119}
120
121//______________________________________________________________________________
122Int_t AliMpMotifSpecial::GetNofPadDimensions() const
123{
dee1d5f1 124/// Return number of different pad dimensions in this motif
5f91c9e8 125
f79c58a5 126#ifdef WITH_STL
5f91c9e8 127 return fPadDimensionsVector2.size();
f79c58a5 128#endif
129
130#ifdef WITH_ROOT
131 return fPadDimensionsVector2.GetEntriesFast();
132#endif
5f91c9e8 133}
134
135//______________________________________________________________________________
136TVector2 AliMpMotifSpecial::GetPadDimensions(Int_t i) const
137{
dee1d5f1 138/// Returns the i-th different pad dimensions
5f91c9e8 139
140 if (i<0 || i>GetNofPadDimensions()) {
0471c97b 141 AliFatal("Index outside limits.");
5f91c9e8 142 return TVector2();
143 }
144
f79c58a5 145#ifdef WITH_STL
5f91c9e8 146 return fPadDimensionsVector2[i];
f79c58a5 147#endif
148
149#ifdef WITH_ROOT
150 return *((TVector2*) fPadDimensionsVector2[i]);
151#endif
5f91c9e8 152}
153
154//______________________________________________________________________________
d7885370 155void AliMpMotifSpecial::CalculateDimensions()
5f91c9e8 156{
d7885370 157 /// Calculate motif dimensions and keep them in fDimensions data
5f91c9e8 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
5adf3c2a 179 delete [] tabSizeX;
5f91c9e8 180
d7885370 181 fDimensions = TVector2(sizeX,sizeY);
182}
183
184//______________________________________________________________________________
185TVector2 AliMpMotifSpecial::Dimensions() const
186{
187 /// Give the dimension of the motif
188
189 return fDimensions;
5f91c9e8 190}
191
192//______________________________________________________________________________
193TVector2
194AliMpMotifSpecial::PadPositionLocal(const AliMpIntPair& localIndices) const
195{
dee1d5f1 196 /// Give the local position of the pad number (ix,iy)
197 /// (0,0 is the center of the motif)
5f91c9e8 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//______________________________________________________________________________
215AliMpIntPair AliMpMotifSpecial::PadIndicesLocal(const TVector2& localPos) const
216{
dee1d5f1 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
5f91c9e8 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//______________________________________________________________________________
268void AliMpMotifSpecial::SetPadDimensions(const AliMpIntPair& localIndices,
269 const TVector2& dimensions)
270{
13985652 271 /// Set the dimensions of the pad located at \a localIndices to the given
272 /// \a dimensions
5f91c9e8 273
274 if ( !GetMotifType()->HasPad(localIndices)){
275 Warning("SetPadDimensions","Pad indices outside limits");
276 return;
277 }
278
279 // fill the dimensions map vector
f79c58a5 280#ifdef WITH_STL
5f91c9e8 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);
f79c58a5 292#endif
293
294#ifdef WITH_ROOT
295 TVector2* dimensionsObj = new TVector2(dimensions);
5006ec94 296 fPadDimensionsVector.Add(localIndices, dimensionsObj);
f79c58a5 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
5f91c9e8 309}