]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpGraphContext.cxx
STL=>ROOT for the mapping package. AliMpContainers.h for the compilation option WITH_...
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpGraphContext.cxx
1 // $Id$
2 // Category: graphics
3 //
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 //
9 // Author: David GUEZ, IPN Orsay
10
11 #include "AliMpGraphContext.h"
12
13 ClassImp(AliMpGraphContext)
14
15 AliMpGraphContext *AliMpGraphContext::fgInstance = 0;
16 GraphContextVector AliMpGraphContext::fgStack;
17 #ifdef WITH_ROOT
18 Int_t              AliMpGraphContext::fgStackSize = 0;
19 #endif
20
21 // private constructor
22 AliMpGraphContext::AliMpGraphContext():
23   TObject(),
24   fPadPosition(TVector2(0.5,0.5)),
25   fPadDimensions(TVector2(0.49,0.49)),
26   fRealPosition(TVector2(0.,0.)),
27   fRealDimensions(TVector2(1,1))
28 {
29   fColor = 20;
30   // default constructor (private)
31 }
32 AliMpGraphContext *AliMpGraphContext::Instance()
33 {
34   // return or create a unique instance of this class
35   if (fgInstance) return fgInstance;
36   fgInstance = new AliMpGraphContext;
37   return fgInstance;
38 }
39
40 TVector2 AliMpGraphContext::RealToPad(const TVector2 &position) const
41 {
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() );
49
50   y-= (fRealPosition.Y()-fRealDimensions.Y());
51   y/=fRealDimensions.Y();
52   y*=fPadDimensions.Y();
53   y+= (fPadPosition.Y()-fPadDimensions.Y() );
54
55   return TVector2(x,y);
56 }
57
58
59
60 void AliMpGraphContext::RealToPad(const TVector2 &position,
61                               const TVector2 &dimensions,
62                               TVector2 &padPosition,
63                               TVector2 &padDimensions) const
64 {
65   // transform the real area (position,dimensions) to
66   // its equivalent pad area
67   padPosition = RealToPad(position);
68   padDimensions = 
69     TVector2(dimensions.X()*fPadDimensions.X()/fRealDimensions.X(),
70              dimensions.Y()*fPadDimensions.Y()/fRealDimensions.Y());
71
72 }
73 void AliMpGraphContext::SetPadPosForReal(const TVector2 &position,
74                                      const TVector2 &dimensions)
75 {
76   // Set the pad area from the actual one
77   // corresponding to the given real area.
78   RealToPad(position,dimensions,fPadPosition,fPadDimensions);
79 }
80 void AliMpGraphContext::Push() const
81 {
82   // Store the current configuration
83   AliMpGraphContext *save = new AliMpGraphContext(*this);
84
85 #ifdef WITH_STL
86   fgStack.push_back(save);
87 #endif
88
89 #ifdef WITH_ROOT
90   fgStack.AddAt(save, fgStackSize++);
91 #endif
92 }
93 void AliMpGraphContext::Pop()
94 {
95 #ifdef WITH_STL
96   // restore the last saved configuration
97   if (!fgStack.empty()){
98     AliMpGraphContext *obj = fgStack.back();
99     *this = *obj;
100     fgStack.pop_back();
101     delete obj;
102   }
103 #endif
104
105 #ifdef WITH_ROOT
106   // restore the last saved configuration
107   if ( fgStackSize ){
108     AliMpGraphContext *obj 
109       = (AliMpGraphContext*)fgStack.At(--fgStackSize);
110     *this = *obj;
111     fgStack.RemoveAt(fgStackSize);
112     delete obj;
113   }
114 #endif
115 }