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