]>
Commit | Line | Data |
---|---|---|
dee1d5f1 | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
15 | ||
5f91c9e8 | 16 | // $Id$ |
13985652 | 17 | // $MpId: AliMpGraphContext.cxx,v 1.11 2006/05/24 13:58:32 ivana Exp $ |
5f91c9e8 | 18 | // Category: graphics |
3d1463c8 | 19 | |
20 | //----------------------------------------------------------------------------- | |
5f91c9e8 | 21 | // Class AliMpGraphContext |
22 | // ----------------------- | |
23 | // Class describing a the correspondance between a given area | |
24 | // in pad, and a zone of real (cm) position | |
dbe945cc | 25 | // Included in AliRoot: 2003/05/02 |
5f91c9e8 | 26 | // Author: David GUEZ, IPN Orsay |
3d1463c8 | 27 | //----------------------------------------------------------------------------- |
5f91c9e8 | 28 | |
29 | #include "AliMpGraphContext.h" | |
30 | ||
13985652 | 31 | /// \cond CLASSIMP |
32 | ClassImp(AliMpGraphContext) | |
33 | /// \endcond | |
34 | ||
5f91c9e8 | 35 | AliMpGraphContext *AliMpGraphContext::fgInstance = 0; |
5006ec94 | 36 | AliMpGraphContext::GraphContextVector AliMpGraphContext::fgStack; |
2c605e66 | 37 | |
f79c58a5 | 38 | #ifdef WITH_ROOT |
39 | Int_t AliMpGraphContext::fgStackSize = 0; | |
40 | #endif | |
5f91c9e8 | 41 | |
fb1bf5c0 | 42 | //_____________________________________________________________________________ |
5f91c9e8 | 43 | AliMpGraphContext::AliMpGraphContext(): |
44 | TObject(), | |
0471c97b | 45 | fColor(20), |
5f91c9e8 | 46 | fPadPosition(TVector2(0.5,0.5)), |
47 | fPadDimensions(TVector2(0.49,0.49)), | |
48 | fRealPosition(TVector2(0.,0.)), | |
49 | fRealDimensions(TVector2(1,1)) | |
50 | { | |
0471c97b | 51 | /// Default constructor (private) |
5f91c9e8 | 52 | } |
fb1bf5c0 | 53 | |
54 | //_____________________________________________________________________________ | |
55 | AliMpGraphContext::AliMpGraphContext(const AliMpGraphContext& right) | |
bcf37928 | 56 | : TObject(right), |
57 | fColor(right.fColor), | |
58 | fPadPosition(right.fPadPosition), | |
59 | fPadDimensions(right.fPadDimensions), | |
60 | fRealPosition(right.fRealPosition), | |
61 | fRealDimensions(right.fRealDimensions) | |
fb1bf5c0 | 62 | { |
dee1d5f1 | 63 | /// Copy constructor |
fb1bf5c0 | 64 | } |
65 | ||
66 | //_____________________________________________________________________________ | |
67 | AliMpGraphContext& | |
68 | AliMpGraphContext::operator=(const AliMpGraphContext& right) | |
69 | { | |
dee1d5f1 | 70 | /// Protected assignment operator |
fb1bf5c0 | 71 | |
dee1d5f1 | 72 | // check assignment to self |
fb1bf5c0 | 73 | if (this == &right) return *this; |
74 | ||
bcf37928 | 75 | fColor = right.fColor; |
76 | fPadPosition = right.fPadPosition; | |
77 | fPadDimensions = right.fPadDimensions; | |
78 | fRealPosition = right.fRealPosition; | |
79 | fRealDimensions = right.fRealDimensions; | |
fb1bf5c0 | 80 | |
81 | return *this; | |
82 | } | |
83 | ||
84 | //_____________________________________________________________________________ | |
5f91c9e8 | 85 | AliMpGraphContext *AliMpGraphContext::Instance() |
86 | { | |
dee1d5f1 | 87 | /// Return or create a unique instance of this class |
88 | ||
5f91c9e8 | 89 | if (fgInstance) return fgInstance; |
90 | fgInstance = new AliMpGraphContext; | |
91 | return fgInstance; | |
92 | } | |
93 | ||
fb1bf5c0 | 94 | //_____________________________________________________________________________ |
5f91c9e8 | 95 | TVector2 AliMpGraphContext::RealToPad(const TVector2 &position) const |
96 | { | |
dee1d5f1 | 97 | /// Transform a real position into its equivalent position in the pad |
98 | ||
5f91c9e8 | 99 | Double_t x=position.X(); |
100 | Double_t y=position.Y(); | |
101 | x-= (fRealPosition.X()-fRealDimensions.X()); | |
102 | x/=fRealDimensions.X(); | |
103 | x*=fPadDimensions.X(); | |
104 | x+= (fPadPosition.X()-fPadDimensions.X() ); | |
105 | ||
106 | y-= (fRealPosition.Y()-fRealDimensions.Y()); | |
107 | y/=fRealDimensions.Y(); | |
108 | y*=fPadDimensions.Y(); | |
109 | y+= (fPadPosition.Y()-fPadDimensions.Y() ); | |
110 | ||
111 | return TVector2(x,y); | |
112 | } | |
113 | ||
fb1bf5c0 | 114 | //_____________________________________________________________________________ |
5f91c9e8 | 115 | void AliMpGraphContext::RealToPad(const TVector2 &position, |
116 | const TVector2 &dimensions, | |
117 | TVector2 &padPosition, | |
118 | TVector2 &padDimensions) const | |
119 | { | |
f5671fc3 | 120 | /// Transform the real area (position,dimensions) to |
121 | /// its equivalent pad area | |
dee1d5f1 | 122 | |
5f91c9e8 | 123 | padPosition = RealToPad(position); |
124 | padDimensions = | |
125 | TVector2(dimensions.X()*fPadDimensions.X()/fRealDimensions.X(), | |
126 | dimensions.Y()*fPadDimensions.Y()/fRealDimensions.Y()); | |
127 | ||
128 | } | |
fb1bf5c0 | 129 | |
130 | //_____________________________________________________________________________ | |
5f91c9e8 | 131 | void AliMpGraphContext::SetPadPosForReal(const TVector2 &position, |
132 | const TVector2 &dimensions) | |
133 | { | |
dee1d5f1 | 134 | /// Set the pad area from the actual one |
135 | /// corresponding to the given real area. | |
136 | ||
5f91c9e8 | 137 | RealToPad(position,dimensions,fPadPosition,fPadDimensions); |
138 | } | |
fb1bf5c0 | 139 | |
140 | //_____________________________________________________________________________ | |
5f91c9e8 | 141 | void AliMpGraphContext::Push() const |
142 | { | |
dee1d5f1 | 143 | /// Store the current configuration |
144 | ||
5f91c9e8 | 145 | AliMpGraphContext *save = new AliMpGraphContext(*this); |
f79c58a5 | 146 | |
147 | #ifdef WITH_STL | |
5f91c9e8 | 148 | fgStack.push_back(save); |
f79c58a5 | 149 | #endif |
150 | ||
151 | #ifdef WITH_ROOT | |
152 | fgStack.AddAt(save, fgStackSize++); | |
153 | #endif | |
5f91c9e8 | 154 | } |
fb1bf5c0 | 155 | |
156 | //_____________________________________________________________________________ | |
5f91c9e8 | 157 | void AliMpGraphContext::Pop() |
158 | { | |
dee1d5f1 | 159 | /// Pop an object from the stack. |
160 | ||
f79c58a5 | 161 | #ifdef WITH_STL |
5f91c9e8 | 162 | // restore the last saved configuration |
163 | if (!fgStack.empty()){ | |
164 | AliMpGraphContext *obj = fgStack.back(); | |
165 | *this = *obj; | |
166 | fgStack.pop_back(); | |
167 | delete obj; | |
168 | } | |
f79c58a5 | 169 | #endif |
170 | ||
171 | #ifdef WITH_ROOT | |
172 | // restore the last saved configuration | |
173 | if ( fgStackSize ){ | |
174 | AliMpGraphContext *obj | |
175 | = (AliMpGraphContext*)fgStack.At(--fgStackSize); | |
176 | *this = *obj; | |
177 | fgStack.RemoveAt(fgStackSize); | |
178 | delete obj; | |
179 | } | |
180 | #endif | |
5f91c9e8 | 181 | } |