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