]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpGraphContext.cxx
Slats mapping files in Bending
[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 // Included in AliRoot: 2003/05/02
9 // Author: David GUEZ, IPN Orsay
10
11 #include <TError.h>
12
13 #include "AliMpGraphContext.h"
14
15 ClassImp(AliMpGraphContext)
16
17 AliMpGraphContext *AliMpGraphContext::fgInstance = 0;
18 GraphContextVector AliMpGraphContext::fgStack;
19 #ifdef WITH_ROOT
20 Int_t              AliMpGraphContext::fgStackSize = 0;
21 #endif
22
23 //_____________________________________________________________________________
24 AliMpGraphContext::AliMpGraphContext():
25   TObject(),
26   fPadPosition(TVector2(0.5,0.5)),
27   fPadDimensions(TVector2(0.49,0.49)),
28   fRealPosition(TVector2(0.,0.)),
29   fRealDimensions(TVector2(1,1))
30 {
31 // private constructor
32
33   fColor = 20;
34   // default constructor (private)
35 }
36
37 //_____________________________________________________________________________
38 AliMpGraphContext::AliMpGraphContext(const AliMpGraphContext& right) 
39   : TObject(right) 
40 {
41 // protected copy constructor
42
43   Fatal("AliMpGraphContext", "Copy constructor not provided.");
44 }
45
46 //_____________________________________________________________________________
47 AliMpGraphContext& 
48 AliMpGraphContext::operator=(const AliMpGraphContext& right)
49 {
50 // protected assignement operator
51
52   // check assignement to self
53   if (this == &right) return *this;
54
55   Fatal("operator =", "Assignement operator not provided.");
56     
57   return *this;  
58 }    
59
60 //_____________________________________________________________________________
61 AliMpGraphContext *AliMpGraphContext::Instance()
62 {
63   // return or create a unique instance of this class
64   if (fgInstance) return fgInstance;
65   fgInstance = new AliMpGraphContext;
66   return fgInstance;
67 }
68
69 //_____________________________________________________________________________
70 TVector2 AliMpGraphContext::RealToPad(const TVector2 &position) const
71 {
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() );
79
80   y-= (fRealPosition.Y()-fRealDimensions.Y());
81   y/=fRealDimensions.Y();
82   y*=fPadDimensions.Y();
83   y+= (fPadPosition.Y()-fPadDimensions.Y() );
84
85   return TVector2(x,y);
86 }
87
88 //_____________________________________________________________________________
89 void AliMpGraphContext::RealToPad(const TVector2 &position,
90                               const TVector2 &dimensions,
91                               TVector2 &padPosition,
92                               TVector2 &padDimensions) const
93 {
94   // transform the real area (position,dimensions) to
95   // its equivalent pad area
96   padPosition = RealToPad(position);
97   padDimensions = 
98     TVector2(dimensions.X()*fPadDimensions.X()/fRealDimensions.X(),
99              dimensions.Y()*fPadDimensions.Y()/fRealDimensions.Y());
100
101 }
102
103 //_____________________________________________________________________________
104 void AliMpGraphContext::SetPadPosForReal(const TVector2 &position,
105                                      const TVector2 &dimensions)
106 {
107   // Set the pad area from the actual one
108   // corresponding to the given real area.
109   RealToPad(position,dimensions,fPadPosition,fPadDimensions);
110 }
111
112 //_____________________________________________________________________________
113 void AliMpGraphContext::Push() const
114 {
115   // Store the current configuration
116   AliMpGraphContext *save = new AliMpGraphContext(*this);
117
118 #ifdef WITH_STL
119   fgStack.push_back(save);
120 #endif
121
122 #ifdef WITH_ROOT
123   fgStack.AddAt(save, fgStackSize++);
124 #endif
125 }
126
127 //_____________________________________________________________________________
128 void AliMpGraphContext::Pop()
129 {
130 // Pops object from the stack.
131 #ifdef WITH_STL
132   // restore the last saved configuration
133   if (!fgStack.empty()){
134     AliMpGraphContext *obj = fgStack.back();
135     *this = *obj;
136     fgStack.pop_back();
137     delete obj;
138   }
139 #endif
140
141 #ifdef WITH_ROOT
142   // restore the last saved configuration
143   if ( fgStackSize ){
144     AliMpGraphContext *obj 
145       = (AliMpGraphContext*)fgStack.At(--fgStackSize);
146     *this = *obj;
147     fgStack.RemoveAt(fgStackSize);
148     delete obj;
149   }
150 #endif
151 }