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