ENDIF replaced by endif (compilation problems)
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpGraphContext.cxx
CommitLineData
5f91c9e8 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
13ClassImp(AliMpGraphContext)
14
15AliMpGraphContext *AliMpGraphContext::fgInstance = 0;
16GraphContextVector AliMpGraphContext::fgStack;
f79c58a5 17#ifdef WITH_ROOT
18Int_t AliMpGraphContext::fgStackSize = 0;
19#endif
5f91c9e8 20
21// private constructor
22AliMpGraphContext::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}
32AliMpGraphContext *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
40TVector2 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
60void 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}
73void 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}
80void AliMpGraphContext::Push() const
81{
82 // Store the current configuration
83 AliMpGraphContext *save = new AliMpGraphContext(*this);
f79c58a5 84
85#ifdef WITH_STL
5f91c9e8 86 fgStack.push_back(save);
f79c58a5 87#endif
88
89#ifdef WITH_ROOT
90 fgStack.AddAt(save, fgStackSize++);
91#endif
5f91c9e8 92}
93void AliMpGraphContext::Pop()
94{
f79c58a5 95#ifdef WITH_STL
5f91c9e8 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 }
f79c58a5 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
5f91c9e8 115}