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.11 2006/05/24 13:58:32 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
27 #include "AliMpGraphContext.h"
30 ClassImp(AliMpGraphContext)
33 AliMpGraphContext *AliMpGraphContext::fgInstance = 0;
34 AliMpGraphContext::GraphContextVector AliMpGraphContext::fgStack;
37 Int_t AliMpGraphContext::fgStackSize = 0;
40 //_____________________________________________________________________________
41 AliMpGraphContext::AliMpGraphContext():
44 fPadPosition(TVector2(0.5,0.5)),
45 fPadDimensions(TVector2(0.49,0.49)),
46 fRealPosition(TVector2(0.,0.)),
47 fRealDimensions(TVector2(1,1))
49 /// Default constructor (private)
52 //_____________________________________________________________________________
53 AliMpGraphContext::AliMpGraphContext(const AliMpGraphContext& right)
56 fPadPosition(right.fPadPosition),
57 fPadDimensions(right.fPadDimensions),
58 fRealPosition(right.fRealPosition),
59 fRealDimensions(right.fRealDimensions)
64 //_____________________________________________________________________________
66 AliMpGraphContext::operator=(const AliMpGraphContext& right)
68 /// Protected assignment operator
70 // check assignment to self
71 if (this == &right) return *this;
73 fColor = right.fColor;
74 fPadPosition = right.fPadPosition;
75 fPadDimensions = right.fPadDimensions;
76 fRealPosition = right.fRealPosition;
77 fRealDimensions = right.fRealDimensions;
82 //_____________________________________________________________________________
83 AliMpGraphContext *AliMpGraphContext::Instance()
85 /// Return or create a unique instance of this class
87 if (fgInstance) return fgInstance;
88 fgInstance = new AliMpGraphContext;
92 //_____________________________________________________________________________
93 TVector2 AliMpGraphContext::RealToPad(const TVector2 &position) const
95 /// Transform a real position into its equivalent position in the pad
97 Double_t x=position.X();
98 Double_t y=position.Y();
99 x-= (fRealPosition.X()-fRealDimensions.X());
100 x/=fRealDimensions.X();
101 x*=fPadDimensions.X();
102 x+= (fPadPosition.X()-fPadDimensions.X() );
104 y-= (fRealPosition.Y()-fRealDimensions.Y());
105 y/=fRealDimensions.Y();
106 y*=fPadDimensions.Y();
107 y+= (fPadPosition.Y()-fPadDimensions.Y() );
109 return TVector2(x,y);
112 //_____________________________________________________________________________
113 void AliMpGraphContext::RealToPad(const TVector2 &position,
114 const TVector2 &dimensions,
115 TVector2 &padPosition,
116 TVector2 &padDimensions) const
118 // Transform the real area (position,dimensions) to
119 // its equivalent pad area
121 padPosition = RealToPad(position);
123 TVector2(dimensions.X()*fPadDimensions.X()/fRealDimensions.X(),
124 dimensions.Y()*fPadDimensions.Y()/fRealDimensions.Y());
128 //_____________________________________________________________________________
129 void AliMpGraphContext::SetPadPosForReal(const TVector2 &position,
130 const TVector2 &dimensions)
132 /// Set the pad area from the actual one
133 /// corresponding to the given real area.
135 RealToPad(position,dimensions,fPadPosition,fPadDimensions);
138 //_____________________________________________________________________________
139 void AliMpGraphContext::Push() const
141 /// Store the current configuration
143 AliMpGraphContext *save = new AliMpGraphContext(*this);
146 fgStack.push_back(save);
150 fgStack.AddAt(save, fgStackSize++);
154 //_____________________________________________________________________________
155 void AliMpGraphContext::Pop()
157 /// Pop an object from the stack.
160 // restore the last saved configuration
161 if (!fgStack.empty()){
162 AliMpGraphContext *obj = fgStack.back();
170 // restore the last saved configuration
172 AliMpGraphContext *obj
173 = (AliMpGraphContext*)fgStack.At(--fgStackSize);
175 fgStack.RemoveAt(fgStackSize);