1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 // $MpId: AliMpMotifSpecial.cxx,v 1.12 2006/05/24 13:58:41 ivana Exp $
20 //-----------------------------------------------------------------------------
21 // Class AliMpMotifSpecial
22 // -----------------------
23 // Class that defines a motif with its unique ID
24 // and the motif type.
25 // Included in AliRoot: 2003/05/02
26 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
27 //-----------------------------------------------------------------------------
29 #include "AliMpMotifSpecial.h"
30 #include "AliMpMotifType.h"
31 #include "AliMpIntPair.h"
32 #include "AliMpConstants.h"
37 #include <Riostream.h>
40 ClassImp(AliMpMotifSpecial)
44 //______________________________________________________________________________
45 AliMpMotifSpecial::AliMpMotifSpecial(const TString &id,
46 AliMpMotifType *motifType)
47 : AliMpVMotif(id,motifType),
49 fPadDimensionsVector(),
50 fPadDimensionsVector2()
53 /// Standard constructor.
56 //______________________________________________________________________________
57 AliMpMotifSpecial::AliMpMotifSpecial(TRootIOCtor* ioCtor):
60 fPadDimensionsVector(ioCtor),
61 fPadDimensionsVector2()
63 /// Root IO constructor
67 //______________________________________________________________________________
68 AliMpMotifSpecial::~AliMpMotifSpecial()
78 //______________________________________________________________________________
79 Int_t AliMpMotifSpecial::VectorIndex(const AliMpIntPair& indices) const
81 /// Transform indices to linear vector index
83 return indices.GetFirst()*GetMotifType()->GetNofPadsY() + indices.GetSecond();
91 //______________________________________________________________________________
93 AliMpMotifSpecial::GetPadDimensions(const AliMpIntPair& localIndices) const
95 /// Return the dimensions of pad located at the given indices
97 if (GetMotifType()->HasPadByLocalIndices(localIndices)) {
98 if (!fPadDimensionsVector.GetValue(localIndices)) {
99 Warning("GetPadDimensions","Indices outside limits");
100 return TVector2(0.,0.);
103 return *((TVector2*)fPadDimensionsVector.GetValue(localIndices));
106 Warning("GetPadDimensions","Indices outside limits");
107 return TVector2(0.,0.);
111 //______________________________________________________________________________
112 Int_t AliMpMotifSpecial::GetNofPadDimensions() const
114 /// Return number of different pad dimensions in this motif
116 return fPadDimensionsVector2.GetEntriesFast();
119 //______________________________________________________________________________
120 TVector2 AliMpMotifSpecial::GetPadDimensions(Int_t i) const
122 /// Returns the i-th different pad dimensions
124 if (i<0 || i>GetNofPadDimensions()) {
125 AliFatal("Index outside limits.");
129 return *((TVector2*) fPadDimensionsVector2[i]);
132 //______________________________________________________________________________
133 void AliMpMotifSpecial::CalculateDimensions()
135 /// Calculate motif dimensions and keep them in fDimensions data
141 Double_t* tabSizeX = new Double_t[GetMotifType()->GetNofPadsY()];
142 for (j=0;j<GetMotifType()->GetNofPadsY();++j) tabSizeX[j]=0.0;
144 for (i=0;i<GetMotifType()->GetNofPadsX();++i) {
146 for (j=0;j<GetMotifType()->GetNofPadsY();++j) {
147 TVector2 dim = GetPadDimensions(AliMpIntPair(i,j));
149 tabSizeX[j]+=dim.X();
151 if (trSizeY>sizeY) sizeY=trSizeY;
153 for (j=0;j<GetMotifType()->GetNofPadsY();++j) {
154 if (tabSizeX[j]>sizeX) sizeX = tabSizeX[j];
159 fDimensions = TVector2(sizeX,sizeY);
162 //______________________________________________________________________________
163 TVector2 AliMpMotifSpecial::Dimensions() const
165 /// Give the dimension of the motif
170 //______________________________________________________________________________
172 AliMpMotifSpecial::PadPositionLocal(const AliMpIntPair& localIndices) const
174 /// Give the local position of the pad number (ix,iy)
175 /// (0,0 is the center of the motif)
177 TVector2 dim = GetPadDimensions(localIndices);
179 Double_t posX= dim.X();
180 for (Int_t i=0;i<localIndices.GetFirst();++i) {
181 posX+=2.*GetPadDimensions(AliMpIntPair(i,localIndices.GetSecond())).X();
184 Double_t posY= dim.Y();
185 for (Int_t j=0;j<localIndices.GetSecond();++j) {
186 posY+=2.*GetPadDimensions(AliMpIntPair(localIndices.GetFirst(),j)).Y();
189 return TVector2(posX,posY)-Dimensions();
192 //______________________________________________________________________________
193 AliMpIntPair AliMpMotifSpecial::PadIndicesLocal(const TVector2& localPos) const
195 /// Return the pad indices from a given local position
196 /// or AliMpIntPair::Invalid() if this position doesn't correspond to any valid
199 /// *SOLEIL* : This code suppose that
200 /// - 1) all cells have the same size along the Y direction
201 /// - 2) the column 0 is entierly filled
204 // First : find the j index
205 TVector2 pos = localPos + Dimensions();
209 while (j<GetMotifType()->GetNofPadsY()) {
210 TVector2 padDim = GetPadDimensions(AliMpIntPair(0,j));
216 // Test if it's outside limits
217 if (j==GetMotifType()->GetNofPadsY()){
218 Warning("PadIndicesLocal","The position is outside the motif");
219 return AliMpIntPair::Invalid();
223 // now find the i index, in the j_th row
227 while (i<GetMotifType()->GetNofPadsX()) {
228 TVector2 padDim = GetPadDimensions(AliMpIntPair(i,j));
235 // Test if it's outside limits
237 if (i==GetMotifType()->GetNofPadsX()){
238 Warning("PadIndicesLocal","The position is outside the motif");
239 return AliMpIntPair::Invalid();
242 // then return the found (i,j)
243 return AliMpIntPair(i,j);
245 //______________________________________________________________________________
246 void AliMpMotifSpecial::SetPadDimensions(const AliMpIntPair& localIndices,
247 const TVector2& dimensions)
249 /// Set the dimensions of the pad located at \a localIndices to the given
252 if ( !GetMotifType()->HasPadByLocalIndices(localIndices)){
253 Warning("SetPadDimensions","Pad indices outside limits");
257 // fill the dimensions map vector
258 TVector2* dimensionsObj = new TVector2(dimensions);
259 fPadDimensionsVector.Add(localIndices, dimensionsObj);
261 // fill the vector of different pad dimensions
262 // only if these dimensions are not yet present
263 Bool_t isPresent = false;
264 for (Int_t i=0; i<GetNofPadDimensions(); i++) {
265 if (AliMpConstants::IsEqual(*((TVector2*) fPadDimensionsVector2[i]), dimensions))
269 if (!isPresent) fPadDimensionsVector2.Add(dimensionsObj);