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 // private constructor
19 AliMpGraphContext::AliMpGraphContext():
21 fPadPosition(TVector2(0.5,0.5)),
22 fPadDimensions(TVector2(0.49,0.49)),
23 fRealPosition(TVector2(0.,0.)),
24 fRealDimensions(TVector2(1,1))
27 // default constructor (private)
29 AliMpGraphContext *AliMpGraphContext::Instance()
31 // return or create a unique instance of this class
32 if (fgInstance) return fgInstance;
33 fgInstance = new AliMpGraphContext;
37 TVector2 AliMpGraphContext::RealToPad(const TVector2 &position) const
39 // transform a real position into its equivalent position in the pad
40 Double_t x=position.X();
41 Double_t y=position.Y();
42 x-= (fRealPosition.X()-fRealDimensions.X());
43 x/=fRealDimensions.X();
44 x*=fPadDimensions.X();
45 x+= (fPadPosition.X()-fPadDimensions.X() );
47 y-= (fRealPosition.Y()-fRealDimensions.Y());
48 y/=fRealDimensions.Y();
49 y*=fPadDimensions.Y();
50 y+= (fPadPosition.Y()-fPadDimensions.Y() );
57 void AliMpGraphContext::RealToPad(const TVector2 &position,
58 const TVector2 &dimensions,
59 TVector2 &padPosition,
60 TVector2 &padDimensions) const
62 // transform the real area (position,dimensions) to
63 // its equivalent pad area
64 padPosition = RealToPad(position);
66 TVector2(dimensions.X()*fPadDimensions.X()/fRealDimensions.X(),
67 dimensions.Y()*fPadDimensions.Y()/fRealDimensions.Y());
70 void AliMpGraphContext::SetPadPosForReal(const TVector2 &position,
71 const TVector2 &dimensions)
73 // Set the pad area from the actual one
74 // corresponding to the given real area.
75 RealToPad(position,dimensions,fPadPosition,fPadDimensions);
77 void AliMpGraphContext::Push() const
79 // Store the current configuration
80 AliMpGraphContext *save = new AliMpGraphContext(*this);
81 fgStack.push_back(save);
83 void AliMpGraphContext::Pop()
85 // restore the last saved configuration
86 if (!fgStack.empty()){
87 AliMpGraphContext *obj = fgStack.back();