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: AliMpGraphContext.cxx,v 1.11 2006/05/24 13:58:32 ivana Exp $
20 //-----------------------------------------------------------------------------
21 // Class AliMpGraphContext
22 // -----------------------
23 // Class describing a the correspondance between a given area
24 // in pad, and a zone of real (cm) position
25 // Included in AliRoot: 2003/05/02
26 // Author: David GUEZ, IPN Orsay
27 //-----------------------------------------------------------------------------
29 #include "AliMpGraphContext.h"
32 ClassImp(AliMpGraphContext)
35 AliMpGraphContext* AliMpGraphContext::fgInstance = 0;
36 TObjArray AliMpGraphContext::fgStack;
37 Int_t AliMpGraphContext::fgStackSize = 0;
39 //_____________________________________________________________________________
40 AliMpGraphContext::AliMpGraphContext():
43 fPadPosition(TVector2(0.5,0.5)),
44 fPadDimensions(TVector2(0.49,0.49)),
45 fRealPosition(TVector2(0.,0.)),
46 fRealDimensions(TVector2(1,1))
48 /// Default constructor (private)
51 //_____________________________________________________________________________
52 AliMpGraphContext::AliMpGraphContext(const AliMpGraphContext& right)
55 fPadPosition(right.fPadPosition),
56 fPadDimensions(right.fPadDimensions),
57 fRealPosition(right.fRealPosition),
58 fRealDimensions(right.fRealDimensions)
63 //_____________________________________________________________________________
65 AliMpGraphContext::operator=(const AliMpGraphContext& right)
67 /// Protected assignment operator
69 // check assignment to self
70 if (this == &right) return *this;
72 fColor = right.fColor;
73 fPadPosition = right.fPadPosition;
74 fPadDimensions = right.fPadDimensions;
75 fRealPosition = right.fRealPosition;
76 fRealDimensions = right.fRealDimensions;
81 //_____________________________________________________________________________
82 AliMpGraphContext *AliMpGraphContext::Instance()
84 /// Return or create a unique instance of this class
86 if (fgInstance) return fgInstance;
87 fgInstance = new AliMpGraphContext;
91 //_____________________________________________________________________________
92 TVector2 AliMpGraphContext::RealToPad(const TVector2 &position) const
94 /// Transform a real position into its equivalent position in the pad
96 Double_t x=position.X();
97 Double_t y=position.Y();
98 x-= (fRealPosition.X()-fRealDimensions.X());
99 x/=fRealDimensions.X();
100 x*=fPadDimensions.X();
101 x+= (fPadPosition.X()-fPadDimensions.X() );
103 y-= (fRealPosition.Y()-fRealDimensions.Y());
104 y/=fRealDimensions.Y();
105 y*=fPadDimensions.Y();
106 y+= (fPadPosition.Y()-fPadDimensions.Y() );
108 return TVector2(x,y);
111 //_____________________________________________________________________________
112 void AliMpGraphContext::RealToPad(const TVector2 &position,
113 const TVector2 &dimensions,
114 TVector2 &padPosition,
115 TVector2 &padDimensions) const
117 /// Transform the real area (position,dimensions) to
118 /// its equivalent pad area
120 padPosition = RealToPad(position);
122 TVector2(dimensions.X()*fPadDimensions.X()/fRealDimensions.X(),
123 dimensions.Y()*fPadDimensions.Y()/fRealDimensions.Y());
127 //_____________________________________________________________________________
128 void AliMpGraphContext::SetPadPosForReal(const TVector2 &position,
129 const TVector2 &dimensions)
131 /// Set the pad area from the actual one
132 /// corresponding to the given real area.
134 RealToPad(position,dimensions,fPadPosition,fPadDimensions);
137 //_____________________________________________________________________________
138 void AliMpGraphContext::Push() const
140 /// Store the current configuration
142 AliMpGraphContext *save = new AliMpGraphContext(*this);
144 fgStack.AddAt(save, fgStackSize++);
147 //_____________________________________________________________________________
148 void AliMpGraphContext::Pop()
150 /// Pop an object from the stack.
152 // restore the last saved configuration
154 AliMpGraphContext *obj
155 = (AliMpGraphContext*)fgStack.At(--fgStackSize);
157 fgStack.RemoveAt(fgStackSize);