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