4 // Class AliMpGraphContext
5 // -----------------------
6 // Class describing a the correspondance between a given area
7 // in pad, and a zone of real (cm) position
9 // Author: David GUEZ, IPN Orsay
11 #include "AliMpGraphContext.h"
13 ClassImp(AliMpGraphContext)
15 AliMpGraphContext *AliMpGraphContext::fgInstance = 0;
16 GraphContextVector AliMpGraphContext::fgStack;
18 Int_t AliMpGraphContext::fgStackSize = 0;
21 // private constructor
22 AliMpGraphContext::AliMpGraphContext():
24 fPadPosition(TVector2(0.5,0.5)),
25 fPadDimensions(TVector2(0.49,0.49)),
26 fRealPosition(TVector2(0.,0.)),
27 fRealDimensions(TVector2(1,1))
30 // default constructor (private)
32 AliMpGraphContext *AliMpGraphContext::Instance()
34 // return or create a unique instance of this class
35 if (fgInstance) return fgInstance;
36 fgInstance = new AliMpGraphContext;
40 TVector2 AliMpGraphContext::RealToPad(const TVector2 &position) const
42 // transform a real position into its equivalent position in the pad
43 Double_t x=position.X();
44 Double_t y=position.Y();
45 x-= (fRealPosition.X()-fRealDimensions.X());
46 x/=fRealDimensions.X();
47 x*=fPadDimensions.X();
48 x+= (fPadPosition.X()-fPadDimensions.X() );
50 y-= (fRealPosition.Y()-fRealDimensions.Y());
51 y/=fRealDimensions.Y();
52 y*=fPadDimensions.Y();
53 y+= (fPadPosition.Y()-fPadDimensions.Y() );
60 void AliMpGraphContext::RealToPad(const TVector2 &position,
61 const TVector2 &dimensions,
62 TVector2 &padPosition,
63 TVector2 &padDimensions) const
65 // transform the real area (position,dimensions) to
66 // its equivalent pad area
67 padPosition = RealToPad(position);
69 TVector2(dimensions.X()*fPadDimensions.X()/fRealDimensions.X(),
70 dimensions.Y()*fPadDimensions.Y()/fRealDimensions.Y());
73 void AliMpGraphContext::SetPadPosForReal(const TVector2 &position,
74 const TVector2 &dimensions)
76 // Set the pad area from the actual one
77 // corresponding to the given real area.
78 RealToPad(position,dimensions,fPadPosition,fPadDimensions);
80 void AliMpGraphContext::Push() const
82 // Store the current configuration
83 AliMpGraphContext *save = new AliMpGraphContext(*this);
86 fgStack.push_back(save);
90 fgStack.AddAt(save, fgStackSize++);
93 void AliMpGraphContext::Pop()
96 // restore the last saved configuration
97 if (!fgStack.empty()){
98 AliMpGraphContext *obj = fgStack.back();
106 // restore the last saved configuration
108 AliMpGraphContext *obj
109 = (AliMpGraphContext*)fgStack.At(--fgStackSize);
111 fgStack.RemoveAt(fgStackSize);