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