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():
43 fPadPosition(TVector2(0.5,0.5)),
44 fPadDimensions(TVector2(0.49,0.49)),
45 fRealPosition(TVector2(0.,0.)),
46 fRealDimensions(TVector2(1,1))
48 /// Private constructor
51 // default constructor (private)
54 //_____________________________________________________________________________
55 AliMpGraphContext::AliMpGraphContext(const AliMpGraphContext& right)
58 fPadPosition(right.fPadPosition),
59 fPadDimensions(right.fPadDimensions),
60 fRealPosition(right.fRealPosition),
61 fRealDimensions(right.fRealDimensions)
66 //_____________________________________________________________________________
68 AliMpGraphContext::operator=(const AliMpGraphContext& right)
70 /// Protected assignment operator
72 // check assignment to self
73 if (this == &right) return *this;
75 fColor = right.fColor;
76 fPadPosition = right.fPadPosition;
77 fPadDimensions = right.fPadDimensions;
78 fRealPosition = right.fRealPosition;
79 fRealDimensions = right.fRealDimensions;
84 //_____________________________________________________________________________
85 AliMpGraphContext *AliMpGraphContext::Instance()
87 /// Return or create a unique instance of this class
89 if (fgInstance) return fgInstance;
90 fgInstance = new AliMpGraphContext;
94 //_____________________________________________________________________________
95 TVector2 AliMpGraphContext::RealToPad(const TVector2 &position) const
97 /// Transform a real position into its equivalent position in the pad
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() );
106 y-= (fRealPosition.Y()-fRealDimensions.Y());
107 y/=fRealDimensions.Y();
108 y*=fPadDimensions.Y();
109 y+= (fPadPosition.Y()-fPadDimensions.Y() );
111 return TVector2(x,y);
114 //_____________________________________________________________________________
115 void AliMpGraphContext::RealToPad(const TVector2 &position,
116 const TVector2 &dimensions,
117 TVector2 &padPosition,
118 TVector2 &padDimensions) const
120 // Transform the real area (position,dimensions) to
121 // its equivalent pad area
123 padPosition = RealToPad(position);
125 TVector2(dimensions.X()*fPadDimensions.X()/fRealDimensions.X(),
126 dimensions.Y()*fPadDimensions.Y()/fRealDimensions.Y());
130 //_____________________________________________________________________________
131 void AliMpGraphContext::SetPadPosForReal(const TVector2 &position,
132 const TVector2 &dimensions)
134 /// Set the pad area from the actual one
135 /// corresponding to the given real area.
137 RealToPad(position,dimensions,fPadPosition,fPadDimensions);
140 //_____________________________________________________________________________
141 void AliMpGraphContext::Push() const
143 /// Store the current configuration
145 AliMpGraphContext *save = new AliMpGraphContext(*this);
148 fgStack.push_back(save);
152 fgStack.AddAt(save, fgStackSize++);
156 //_____________________________________________________________________________
157 void AliMpGraphContext::Pop()
159 /// Pop an object from the stack.
162 // restore the last saved configuration
163 if (!fgStack.empty()){
164 AliMpGraphContext *obj = fgStack.back();
172 // restore the last saved configuration
174 AliMpGraphContext *obj
175 = (AliMpGraphContext*)fgStack.At(--fgStackSize);
177 fgStack.RemoveAt(fgStackSize);