]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpGraphContext.cxx
Updated det element names (Christian)
[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 // 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
26
27 #include "AliMpGraphContext.h"
28
29 /// \cond CLASSIMP
30 ClassImp(AliMpGraphContext)
31 /// \endcond
32
33 AliMpGraphContext *AliMpGraphContext::fgInstance = 0;
34 AliMpGraphContext::GraphContextVector AliMpGraphContext::fgStack;
35
36 #ifdef WITH_ROOT
37 Int_t              AliMpGraphContext::fgStackSize = 0;
38 #endif
39
40 //_____________________________________________________________________________
41 AliMpGraphContext::AliMpGraphContext():
42   TObject(),
43   fColor(20),
44   fPadPosition(TVector2(0.5,0.5)),
45   fPadDimensions(TVector2(0.49,0.49)),
46   fRealPosition(TVector2(0.,0.)),
47   fRealDimensions(TVector2(1,1))
48 {
49 /// Default constructor (private)
50 }
51
52 //_____________________________________________________________________________
53 AliMpGraphContext::AliMpGraphContext(const AliMpGraphContext& right) 
54   : TObject(right),
55     fColor(right.fColor),
56     fPadPosition(right.fPadPosition),
57     fPadDimensions(right.fPadDimensions),
58     fRealPosition(right.fRealPosition),
59     fRealDimensions(right.fRealDimensions)     
60 {
61 /// Copy constructor
62 }
63
64 //_____________________________________________________________________________
65 AliMpGraphContext& 
66 AliMpGraphContext::operator=(const AliMpGraphContext& right)
67 {
68 /// Protected assignment operator
69
70   // check assignment to self
71   if (this == &right) return *this;
72
73   fColor = right.fColor;
74   fPadPosition = right.fPadPosition;
75   fPadDimensions = right.fPadDimensions;
76   fRealPosition = right.fRealPosition;
77   fRealDimensions = right.fRealDimensions;
78     
79   return *this;  
80 }    
81
82 //_____________________________________________________________________________
83 AliMpGraphContext *AliMpGraphContext::Instance()
84 {
85   /// Return or create a unique instance of this class
86   
87   if (fgInstance) return fgInstance;
88   fgInstance = new AliMpGraphContext;
89   return fgInstance;
90 }
91
92 //_____________________________________________________________________________
93 TVector2 AliMpGraphContext::RealToPad(const TVector2 &position) const
94 {
95   /// Transform a real position into its equivalent position in the pad
96   
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() );
103
104   y-= (fRealPosition.Y()-fRealDimensions.Y());
105   y/=fRealDimensions.Y();
106   y*=fPadDimensions.Y();
107   y+= (fPadPosition.Y()-fPadDimensions.Y() );
108
109   return TVector2(x,y);
110 }
111
112 //_____________________________________________________________________________
113 void AliMpGraphContext::RealToPad(const TVector2 &position,
114                               const TVector2 &dimensions,
115                               TVector2 &padPosition,
116                               TVector2 &padDimensions) const
117 {
118   // Transform the real area (position,dimensions) to
119   // its equivalent pad area
120
121   padPosition = RealToPad(position);
122   padDimensions = 
123     TVector2(dimensions.X()*fPadDimensions.X()/fRealDimensions.X(),
124              dimensions.Y()*fPadDimensions.Y()/fRealDimensions.Y());
125
126 }
127
128 //_____________________________________________________________________________
129 void AliMpGraphContext::SetPadPosForReal(const TVector2 &position,
130                                      const TVector2 &dimensions)
131 {
132   /// Set the pad area from the actual one
133   /// corresponding to the given real area.
134
135   RealToPad(position,dimensions,fPadPosition,fPadDimensions);
136 }
137
138 //_____________________________________________________________________________
139 void AliMpGraphContext::Push() const
140 {
141   /// Store the current configuration
142
143   AliMpGraphContext *save = new AliMpGraphContext(*this);
144
145 #ifdef WITH_STL
146   fgStack.push_back(save);
147 #endif
148
149 #ifdef WITH_ROOT
150   fgStack.AddAt(save, fgStackSize++);
151 #endif
152 }
153
154 //_____________________________________________________________________________
155 void AliMpGraphContext::Pop()
156 {
157 /// Pop an object from the stack.
158
159 #ifdef WITH_STL
160   // restore the last saved configuration
161   if (!fgStack.empty()){
162     AliMpGraphContext *obj = fgStack.back();
163     *this = *obj;
164     fgStack.pop_back();
165     delete obj;
166   }
167 #endif
168
169 #ifdef WITH_ROOT
170   // restore the last saved configuration
171   if ( fgStackSize ){
172     AliMpGraphContext *obj 
173       = (AliMpGraphContext*)fgStack.At(--fgStackSize);
174     *this = *obj;
175     fgStack.RemoveAt(fgStackSize);
176     delete obj;
177   }
178 #endif
179 }