1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 // $MpId: AliMpGraphContext.cxx,v 1.8 2005/09/26 16:06:36 ivana Exp $
20 // Class AliMpGraphContext
21 // -----------------------
22 // Class describing a the correspondance between a given area
23 // in pad, and a zone of real (cm) position
24 // Included in AliRoot: 2003/05/02
25 // Author: David GUEZ, IPN Orsay
29 #include "AliMpGraphContext.h"
31 ClassImp(AliMpGraphContext)
33 AliMpGraphContext *AliMpGraphContext::fgInstance = 0;
34 AliMpGraphContext::GraphContextVector AliMpGraphContext::fgStack;
36 Int_t AliMpGraphContext::fgStackSize = 0;
39 //_____________________________________________________________________________
40 AliMpGraphContext::AliMpGraphContext():
42 fPadPosition(TVector2(0.5,0.5)),
43 fPadDimensions(TVector2(0.49,0.49)),
44 fRealPosition(TVector2(0.,0.)),
45 fRealDimensions(TVector2(1,1))
47 /// Private constructor
50 // default constructor (private)
53 //_____________________________________________________________________________
54 AliMpGraphContext::AliMpGraphContext(const AliMpGraphContext& right)
57 fPadPosition(right.fPadPosition),
58 fPadDimensions(right.fPadDimensions),
59 fRealPosition(right.fRealPosition),
60 fRealDimensions(right.fRealDimensions)
65 //_____________________________________________________________________________
67 AliMpGraphContext::operator=(const AliMpGraphContext& right)
69 /// Protected assignment operator
71 // check assignment to self
72 if (this == &right) return *this;
74 fColor = right.fColor;
75 fPadPosition = right.fPadPosition;
76 fPadDimensions = right.fPadDimensions;
77 fRealPosition = right.fRealPosition;
78 fRealDimensions = right.fRealDimensions;
83 //_____________________________________________________________________________
84 AliMpGraphContext *AliMpGraphContext::Instance()
86 /// Return or create a unique instance of this class
88 if (fgInstance) return fgInstance;
89 fgInstance = new AliMpGraphContext;
93 //_____________________________________________________________________________
94 TVector2 AliMpGraphContext::RealToPad(const TVector2 &position) const
96 /// Transform a real position into its equivalent position in the pad
98 Double_t x=position.X();
99 Double_t y=position.Y();
100 x-= (fRealPosition.X()-fRealDimensions.X());
101 x/=fRealDimensions.X();
102 x*=fPadDimensions.X();
103 x+= (fPadPosition.X()-fPadDimensions.X() );
105 y-= (fRealPosition.Y()-fRealDimensions.Y());
106 y/=fRealDimensions.Y();
107 y*=fPadDimensions.Y();
108 y+= (fPadPosition.Y()-fPadDimensions.Y() );
110 return TVector2(x,y);
113 //_____________________________________________________________________________
114 void AliMpGraphContext::RealToPad(const TVector2 &position,
115 const TVector2 &dimensions,
116 TVector2 &padPosition,
117 TVector2 &padDimensions) const
119 // Transform the real area (position,dimensions) to
120 // its equivalent pad area
122 padPosition = RealToPad(position);
124 TVector2(dimensions.X()*fPadDimensions.X()/fRealDimensions.X(),
125 dimensions.Y()*fPadDimensions.Y()/fRealDimensions.Y());
129 //_____________________________________________________________________________
130 void AliMpGraphContext::SetPadPosForReal(const TVector2 &position,
131 const TVector2 &dimensions)
133 /// Set the pad area from the actual one
134 /// corresponding to the given real area.
136 RealToPad(position,dimensions,fPadPosition,fPadDimensions);
139 //_____________________________________________________________________________
140 void AliMpGraphContext::Push() const
142 /// Store the current configuration
144 AliMpGraphContext *save = new AliMpGraphContext(*this);
147 fgStack.push_back(save);
151 fgStack.AddAt(save, fgStackSize++);
155 //_____________________________________________________________________________
156 void AliMpGraphContext::Pop()
158 /// Pop an object from the stack.
161 // restore the last saved configuration
162 if (!fgStack.empty()){
163 AliMpGraphContext *obj = fgStack.back();
171 // restore the last saved configuration
173 AliMpGraphContext *obj
174 = (AliMpGraphContext*)fgStack.At(--fgStackSize);
176 fgStack.RemoveAt(fgStackSize);