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