]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpGraphContext.cxx
Previous commit had the bad side-effect of changing the behaviour of Raw QA to comput...
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpGraphContext.cxx
CommitLineData
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
32ClassImp(AliMpGraphContext)
33/// \endcond
34
2294822d 35AliMpGraphContext* AliMpGraphContext::fgInstance = 0;
36TObjArray AliMpGraphContext::fgStack;
f79c58a5 37Int_t AliMpGraphContext::fgStackSize = 0;
5f91c9e8 38
fb1bf5c0 39//_____________________________________________________________________________
5f91c9e8 40AliMpGraphContext::AliMpGraphContext():
41 TObject(),
0471c97b 42 fColor(20),
5f91c9e8 43 fPadPosition(TVector2(0.5,0.5)),
44 fPadDimensions(TVector2(0.49,0.49)),
45 fRealPosition(TVector2(0.,0.)),
46 fRealDimensions(TVector2(1,1))
47{
0471c97b 48/// Default constructor (private)
5f91c9e8 49}
fb1bf5c0 50
51//_____________________________________________________________________________
52AliMpGraphContext::AliMpGraphContext(const AliMpGraphContext& right)
bcf37928 53 : TObject(right),
54 fColor(right.fColor),
55 fPadPosition(right.fPadPosition),
56 fPadDimensions(right.fPadDimensions),
57 fRealPosition(right.fRealPosition),
58 fRealDimensions(right.fRealDimensions)
fb1bf5c0 59{
dee1d5f1 60/// Copy constructor
fb1bf5c0 61}
62
63//_____________________________________________________________________________
64AliMpGraphContext&
65AliMpGraphContext::operator=(const AliMpGraphContext& right)
66{
dee1d5f1 67/// Protected assignment operator
fb1bf5c0 68
dee1d5f1 69 // check assignment to self
fb1bf5c0 70 if (this == &right) return *this;
71
bcf37928 72 fColor = right.fColor;
73 fPadPosition = right.fPadPosition;
74 fPadDimensions = right.fPadDimensions;
75 fRealPosition = right.fRealPosition;
76 fRealDimensions = right.fRealDimensions;
fb1bf5c0 77
78 return *this;
79}
80
81//_____________________________________________________________________________
5f91c9e8 82AliMpGraphContext *AliMpGraphContext::Instance()
83{
dee1d5f1 84 /// Return or create a unique instance of this class
85
5f91c9e8 86 if (fgInstance) return fgInstance;
87 fgInstance = new AliMpGraphContext;
88 return fgInstance;
89}
90
fb1bf5c0 91//_____________________________________________________________________________
5f91c9e8 92TVector2 AliMpGraphContext::RealToPad(const TVector2 &position) const
93{
dee1d5f1 94 /// Transform a real position into its equivalent position in the pad
95
5f91c9e8 96 Double_t x=position.X();
97 Double_t y=position.Y();
98 x-= (fRealPosition.X()-fRealDimensions.X());
99 x/=fRealDimensions.X();
100 x*=fPadDimensions.X();
101 x+= (fPadPosition.X()-fPadDimensions.X() );
102
103 y-= (fRealPosition.Y()-fRealDimensions.Y());
104 y/=fRealDimensions.Y();
105 y*=fPadDimensions.Y();
106 y+= (fPadPosition.Y()-fPadDimensions.Y() );
107
108 return TVector2(x,y);
109}
110
fb1bf5c0 111//_____________________________________________________________________________
5f91c9e8 112void AliMpGraphContext::RealToPad(const TVector2 &position,
113 const TVector2 &dimensions,
114 TVector2 &padPosition,
115 TVector2 &padDimensions) const
116{
f5671fc3 117 /// Transform the real area (position,dimensions) to
118 /// its equivalent pad area
dee1d5f1 119
5f91c9e8 120 padPosition = RealToPad(position);
121 padDimensions =
122 TVector2(dimensions.X()*fPadDimensions.X()/fRealDimensions.X(),
123 dimensions.Y()*fPadDimensions.Y()/fRealDimensions.Y());
124
125}
fb1bf5c0 126
127//_____________________________________________________________________________
5f91c9e8 128void AliMpGraphContext::SetPadPosForReal(const TVector2 &position,
129 const TVector2 &dimensions)
130{
dee1d5f1 131 /// Set the pad area from the actual one
132 /// corresponding to the given real area.
133
5f91c9e8 134 RealToPad(position,dimensions,fPadPosition,fPadDimensions);
135}
fb1bf5c0 136
137//_____________________________________________________________________________
5f91c9e8 138void AliMpGraphContext::Push() const
139{
dee1d5f1 140 /// Store the current configuration
141
5f91c9e8 142 AliMpGraphContext *save = new AliMpGraphContext(*this);
f79c58a5 143
f79c58a5 144 fgStack.AddAt(save, fgStackSize++);
5f91c9e8 145}
fb1bf5c0 146
147//_____________________________________________________________________________
5f91c9e8 148void AliMpGraphContext::Pop()
149{
dee1d5f1 150/// Pop an object from the stack.
151
f79c58a5 152 // restore the last saved configuration
153 if ( fgStackSize ){
154 AliMpGraphContext *obj
155 = (AliMpGraphContext*)fgStack.At(--fgStackSize);
156 *this = *obj;
157 fgStack.RemoveAt(fgStackSize);
158 delete obj;
159 }
5f91c9e8 160}