4 // Class AliMpGraphContext
5 // -----------------------
6 // Class describing a the correspondance between a given area
7 // in pad, and a zone of real (cm) position
8 // Included in AliRoot: 2003/05/02
9 // Author: David GUEZ, IPN Orsay
13 #include "AliMpGraphContext.h"
15 ClassImp(AliMpGraphContext)
17 AliMpGraphContext *AliMpGraphContext::fgInstance = 0;
18 GraphContextVector AliMpGraphContext::fgStack;
20 Int_t AliMpGraphContext::fgStackSize = 0;
23 //_____________________________________________________________________________
24 AliMpGraphContext::AliMpGraphContext():
26 fPadPosition(TVector2(0.5,0.5)),
27 fPadDimensions(TVector2(0.49,0.49)),
28 fRealPosition(TVector2(0.,0.)),
29 fRealDimensions(TVector2(1,1))
31 // private constructor
34 // default constructor (private)
37 //_____________________________________________________________________________
38 AliMpGraphContext::AliMpGraphContext(const AliMpGraphContext& right)
41 // protected copy constructor
43 Fatal("AliMpGraphContext", "Copy constructor not provided.");
46 //_____________________________________________________________________________
48 AliMpGraphContext::operator=(const AliMpGraphContext& right)
50 // protected assignement operator
52 // check assignement to self
53 if (this == &right) return *this;
55 Fatal("operator =", "Assignement operator not provided.");
60 //_____________________________________________________________________________
61 AliMpGraphContext *AliMpGraphContext::Instance()
63 // return or create a unique instance of this class
64 if (fgInstance) return fgInstance;
65 fgInstance = new AliMpGraphContext;
69 //_____________________________________________________________________________
70 TVector2 AliMpGraphContext::RealToPad(const TVector2 &position) const
72 // transform a real position into its equivalent position in the pad
73 Double_t x=position.X();
74 Double_t y=position.Y();
75 x-= (fRealPosition.X()-fRealDimensions.X());
76 x/=fRealDimensions.X();
77 x*=fPadDimensions.X();
78 x+= (fPadPosition.X()-fPadDimensions.X() );
80 y-= (fRealPosition.Y()-fRealDimensions.Y());
81 y/=fRealDimensions.Y();
82 y*=fPadDimensions.Y();
83 y+= (fPadPosition.Y()-fPadDimensions.Y() );
88 //_____________________________________________________________________________
89 void AliMpGraphContext::RealToPad(const TVector2 &position,
90 const TVector2 &dimensions,
91 TVector2 &padPosition,
92 TVector2 &padDimensions) const
94 // transform the real area (position,dimensions) to
95 // its equivalent pad area
96 padPosition = RealToPad(position);
98 TVector2(dimensions.X()*fPadDimensions.X()/fRealDimensions.X(),
99 dimensions.Y()*fPadDimensions.Y()/fRealDimensions.Y());
103 //_____________________________________________________________________________
104 void AliMpGraphContext::SetPadPosForReal(const TVector2 &position,
105 const TVector2 &dimensions)
107 // Set the pad area from the actual one
108 // corresponding to the given real area.
109 RealToPad(position,dimensions,fPadPosition,fPadDimensions);
112 //_____________________________________________________________________________
113 void AliMpGraphContext::Push() const
115 // Store the current configuration
116 AliMpGraphContext *save = new AliMpGraphContext(*this);
119 fgStack.push_back(save);
123 fgStack.AddAt(save, fgStackSize++);
127 //_____________________________________________________________________________
128 void AliMpGraphContext::Pop()
130 // Pops object from the stack.
132 // restore the last saved configuration
133 if (!fgStack.empty()){
134 AliMpGraphContext *obj = fgStack.back();
142 // restore the last saved configuration
144 AliMpGraphContext *obj
145 = (AliMpGraphContext*)fgStack.At(--fgStackSize);
147 fgStack.RemoveAt(fgStackSize);