]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpGraphContext.cxx
In mapping:
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpGraphContext.cxx
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
16 // $Id$
17 // $MpId: AliMpGraphContext.cxx,v 1.11 2006/05/24 13:58:32 ivana Exp $
18 // Category: graphics
19
20 //-----------------------------------------------------------------------------
21 // Class AliMpGraphContext
22 // -----------------------
23 // Class describing a the correspondance between a given area
24 // in pad, and a zone of real (cm) position
25 // Included in AliRoot: 2003/05/02
26 // Author: David GUEZ, IPN Orsay
27 //-----------------------------------------------------------------------------
28
29 #include "AliMpGraphContext.h"
30
31 /// \cond CLASSIMP
32 ClassImp(AliMpGraphContext)
33 /// \endcond
34
35 AliMpGraphContext* AliMpGraphContext::fgInstance = 0;
36 TObjArray          AliMpGraphContext::fgStack;
37 Int_t              AliMpGraphContext::fgStackSize = 0;
38
39 //_____________________________________________________________________________
40 AliMpGraphContext::AliMpGraphContext():
41   TObject(),
42   fColor(20),
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 {
48 /// Default constructor (private)
49 }
50
51 //_____________________________________________________________________________
52 AliMpGraphContext::AliMpGraphContext(const AliMpGraphContext& right) 
53   : TObject(right),
54     fColor(right.fColor),
55     fPadPosition(right.fPadPosition),
56     fPadDimensions(right.fPadDimensions),
57     fRealPosition(right.fRealPosition),
58     fRealDimensions(right.fRealDimensions)     
59 {
60 /// Copy constructor
61 }
62
63 //_____________________________________________________________________________
64 AliMpGraphContext& 
65 AliMpGraphContext::operator=(const AliMpGraphContext& right)
66 {
67 /// Protected assignment operator
68
69   // check assignment to self
70   if (this == &right) return *this;
71
72   fColor = right.fColor;
73   fPadPosition = right.fPadPosition;
74   fPadDimensions = right.fPadDimensions;
75   fRealPosition = right.fRealPosition;
76   fRealDimensions = right.fRealDimensions;
77     
78   return *this;  
79 }    
80
81 //_____________________________________________________________________________
82 AliMpGraphContext *AliMpGraphContext::Instance()
83 {
84   /// Return or create a unique instance of this class
85   
86   if (fgInstance) return fgInstance;
87   fgInstance = new AliMpGraphContext;
88   return fgInstance;
89 }
90
91 //_____________________________________________________________________________
92 TVector2 AliMpGraphContext::RealToPad(const TVector2 &position) const
93 {
94   /// Transform a real position into its equivalent position in the pad
95   
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
111 //_____________________________________________________________________________
112 void AliMpGraphContext::RealToPad(const TVector2 &position,
113                               const TVector2 &dimensions,
114                               TVector2 &padPosition,
115                               TVector2 &padDimensions) const
116 {
117   /// Transform the real area (position,dimensions) to
118   /// its equivalent pad area
119
120   padPosition = RealToPad(position);
121   padDimensions = 
122     TVector2(dimensions.X()*fPadDimensions.X()/fRealDimensions.X(),
123              dimensions.Y()*fPadDimensions.Y()/fRealDimensions.Y());
124
125 }
126
127 //_____________________________________________________________________________
128 void AliMpGraphContext::SetPadPosForReal(const TVector2 &position,
129                                      const TVector2 &dimensions)
130 {
131   /// Set the pad area from the actual one
132   /// corresponding to the given real area.
133
134   RealToPad(position,dimensions,fPadPosition,fPadDimensions);
135 }
136
137 //_____________________________________________________________________________
138 void AliMpGraphContext::Push() const
139 {
140   /// Store the current configuration
141
142   AliMpGraphContext *save = new AliMpGraphContext(*this);
143
144   fgStack.AddAt(save, fgStackSize++);
145 }
146
147 //_____________________________________________________________________________
148 void AliMpGraphContext::Pop()
149 {
150 /// Pop an object from the stack.
151
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   }
160 }