StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StDraw3D.h
1 #ifndef STAR_StDraw3D
2 #define STAR_StDraw3D
3 // $Id: StDraw3D.h,v 1.59 2011/10/03 23:55:38 perev Exp $
4 // *-- Author : Valery Fine(fine@bnl.gov) 27/04/2008
5 
6 #include "TObject.h"
7 #include "Gtypes.h"
8 #include "TString.h"
9 #include "TMath.h"
10 #include <map>
11 #include <vector>
12 
13 class TVirtualPad;
14 class TVirtualViewer3D;
15 class TVolume;
17 enum EDraw3DStyle {kVtx
18  ,kPrimaryTrack
19  ,kGlobalTrack
20  ,kUsedHit
21  ,kUnusedHit
22  ,kTrackBegin
23  ,kTrackEnd
24  ,kBarrelStyle=5000
25  ,kUser
26 };
27 
30  private:
31  EDraw3DStyle fType;
32  Color_t fColor;
33  Style_t fSty;
34  Size_t fSiz;
35  public:
36  StDraw3DStyle(EDraw3DStyle typ=kUsedHit
37  , Color_t col = Color_t(-1)
38  , Style_t sty = Style_t(-1)
39  , Size_t siz = Size_t (-1))
40  : fType(typ),fColor(col),fSty(sty),fSiz(siz) {}
41  Color_t Col() const { return fColor;}
42  Style_t Sty() const { return fSty; }
43  Size_t Siz() const { return fSiz; }
44  EDraw3DStyle Type() const { return fType; }
45  Color_t &Col() { return fColor;}
46  Style_t &Sty() { return fSty; }
47  Size_t &Siz() { return fSiz; }
48  EDraw3DStyle &Type() { return fType; }
49  void SetCol(Color_t col) { Col() = col;}
50  void SetSty(Style_t sty) { Sty() = sty;}
51  void SetSiz(Size_t siz) { Siz() = siz;}
52  void SetType(Color_t col, Style_t sty, Size_t siz)
53  { SetCol(col); SetSiz(siz); SetSty(sty); }
54  static Color_t Pt2Color(double pt);
55 };
56 namespace StarRoot {
57 class StEta {
58  protected:
59  double fLambda;
60  double fDLambda1;
61  double fDLambda2;
62  double fEta;
63  double fDEta;
64  protected:
65  StEta &SetAngle(double eta, double dEta);
66  public:
67  StEta(double eta,double dEta);
68  ~StEta(){;}
69  StEta(const StEta &eta);
70  StEta &operator=(const StEta &eta);
71  double Eta() const;
72  double Deta() const;
73  double Lambda() const;
74  double LambdaDeg() const ;
75  static double Lambda(double eta);
76  double dLambda1() const;
77  double dLambda2() const;
78  operator double() const;
79  const StEta operator-(double eta);
80  const StEta operator+(double eta);
81  const StEta operator-(const StEta &eta);
82  const StEta operator+(const StEta &eta);
83 
84  StEta &operator+=(const StEta &eta);
85  StEta &operator+=(double eta);
86  StEta &operator-=(const StEta &eta);
87  StEta &operator-=(double eta);
88 };
89 
90 inline StEta &StEta::SetAngle(double eta, double dEta) {
91  fEta = eta; fDEta = dEta;
92  fLambda = Lambda(eta);
93  fDLambda1 = Lambda(eta-dEta/2);
94  fDLambda2 = Lambda(eta+dEta/2);
95  return *this;
96 }
97 inline double StEta::Lambda() const { return fLambda; }
98 
99 inline double StEta::Lambda(double eta) {
100  return 2*TMath::ATan(TMath::Exp(-eta));
101 }
102 
103 inline StEta::StEta(double eta,double dEta) { SetAngle(eta,dEta); }
104 inline StEta::StEta(const StEta &eta){
105  fLambda = eta.fLambda; fDLambda1 = eta.fDLambda1; fDLambda2 = eta.fDLambda2;
106  fEta = eta.fEta; fDEta = eta.fDEta;
107 }
108 inline StEta &StEta::operator=(const StEta &eta) {
109  fLambda = eta.fLambda; fDLambda1 = eta.fDLambda1; fDLambda2 = eta.fDLambda2;
110  fEta = eta.fEta; fDEta = eta.fDEta;
111  return *this;
112 }
113 inline double StEta::Deta() const { return fDEta; }
114 inline double StEta::Eta() const { return fEta; }
115 inline double StEta::LambdaDeg() const{ return fLambda*TMath::RadToDeg(); }
116 inline double StEta::dLambda1() const { return fDLambda1; }
117 inline double StEta::dLambda2() const { return fDLambda2; }
118 inline StEta::operator double() const { return fLambda; }
119 inline const StEta StEta::operator-(double eta) { return StEta(fEta-eta,fDEta); }
120 inline const StEta StEta::operator+(double eta) { return StEta(fEta+eta,fDEta); }
121 inline const StEta StEta::operator-(const StEta &eta) { return operator-(eta.fEta); }
122 inline const StEta StEta::operator+(const StEta &eta) { return operator+(eta.fEta); }
123 
124 inline StEta &StEta::operator+=(const StEta &eta) { return operator+=(eta.fEta); }
125 inline StEta &StEta::operator+=(double eta) { return SetAngle(fEta+eta,fDEta); }
126 inline StEta &StEta::operator-=(const StEta &eta) { return operator-=(eta.fEta); }
127 inline StEta &StEta::operator-=(double eta) { return SetAngle(fEta-eta,fDEta); }
128 
129 }
130 
131 
132 class view_3D;
133 
136 
140 class StDraw3D : public TObject
166 {
167  private:
168  static int fgDraw_3d_init;
169  std::map<EDraw3DStyle,StDraw3DStyle> fStyles;
170  TVirtualPad *fPad;
171  Color_t fBkColor; // background color
172  TVirtualViewer3D *fViewer;
173  view_3D *fView;
174  TString fDetectorName;
175  StDraw3D *fMaster;
176  TVolume *fTopVolume;
177  Bool_t fWantPad; // create the default pad if none is provided by user?
178  Bool_t fOwnViewer;
179  Bool_t fOwnPad;
180 
181  static Color_t fgColorDefault;
182  static Style_t fgStyDefault;
183  static Size_t fgSizDefault;
184  static Color_t fgBkColor;
185  static Int_t fDrawCanvasCounter;
186  TVirtualPad *InitPad();
187  void SetMaster(StDraw3D *master);
188  void InitViewer();
189  void Redraw();
190 protected:
191  virtual void UpdateViewer(TVirtualPad *pad=0);
192 
193 public:
194  StDraw3D(const char *detectorName="TPC",TVirtualPad *pad = 0);
195  StDraw3D(TVirtualViewer3D *viewer,TVirtualPad *pad);
196  virtual ~StDraw3D();
197  virtual const StDraw3DStyle &AddStyle(EDraw3DStyle type,Color_t col,Style_t sty,Size_t siz);
198  TVirtualPad *Pad() const;
199  TVirtualViewer3D *Viewer() const;
200  virtual void Clear(Option_t *opt="update");
201  virtual TObject *Draw(TObject *o, const char *option="");
202  virtual const TString &DetectorNames() const;
203  virtual void SetDetectors(const char*nameDetectors);
204  virtual void AddDetectors(const char*nameDetectors);
205  virtual void Draw(Option_t *option="") {TObject::Draw(option);}
206  virtual const StDraw3DStyle &Style(EDraw3DStyle type) const;
207  virtual StDraw3DStyle &Style(EDraw3DStyle type);
208  virtual void SetBkColor(Color_t newBkColor);
209 
210  virtual TObject *Draw3D(int n, const float *xyz);
211 
212  virtual TObject *Draw3D(int n, const double *xyz);
213 
214  virtual TObject *Points(int n, const float *xyz
215  , EDraw3DStyle sty);
216 
217  virtual TObject *Points(int n, const double *xyz
218  , EDraw3DStyle sty);
219 
220  virtual TObject *Points(int n, const float *xyz
221  , Color_t col= Color_t(-1)
222  , Style_t sty= Style_t(-1)
223  , Size_t siz = Size_t (-1));
224 
225  virtual TObject *Points(int n, const double *xyz
226  , Color_t col= Color_t(-1)
227  , Style_t sty= Style_t(-1)
228  , Size_t siz = Size_t (-1));
229 
230  virtual TObject *Points(const std::vector<float> &xyz
231  , EDraw3DStyle sty);
232 
233  virtual TObject *Points(const std::vector<double> &xyz
234  , EDraw3DStyle sty);
235 
236  virtual TObject *Points(const std::vector<float> &xyz
237  , Color_t col= Color_t(-1)
238  , Style_t sty= Style_t(-1)
239  , Size_t siz = Size_t (-1));
240 
241  virtual TObject *Points(const std::vector<double> &xyz
242  , Color_t col= Color_t(-1)
243  , Style_t sty= Style_t(-1)
244  , Size_t siz = Size_t (-1));
245 
246  virtual TObject *Point(float x, float y, float z
247  , Color_t col= Color_t(-1)
248  , Style_t sty= Style_t(-1)
249  , Size_t siz = Size_t (-1));
250 
251  virtual TObject *Point(float x, float y, float z
252  , EDraw3DStyle sty);
253 
254  virtual TObject *Line(int n, const double *xyz
255  , Color_t col= Color_t(-1)
256  , Style_t sty= Style_t(-1)
257  , Size_t siz = Size_t (-1));
258 
259  virtual TObject *Line(float x0, float y0, float z0
260  , float x1, float y1, float z1
261  , Color_t col= Color_t(-1)
262  , Style_t sty= Style_t(-1)
263  , Size_t siz = Size_t (-1));
264 
265  virtual TObject *Line(int n, const float *xyz
266  , Color_t col= Color_t(-1)
267  , Style_t sty= Style_t(-1)
268  , Size_t siz = Size_t (-1));
269 
270  virtual TObject *Line(const std::vector<float> &xyz
271  , Color_t col= Color_t(-1)
272  , Style_t sty= Style_t(-1)
273  , Size_t siz = Size_t (-1));
274 
275  virtual TObject *Line(const std::vector<double> &xyz
276  , Color_t col= Color_t(-1)
277  , Style_t sty= Style_t(-1)
278  , Size_t siz = Size_t (-1));
279 
280  virtual TObject *Line(int n, const float *xyz
281  , EDraw3DStyle sty);
282 
283  virtual TObject *Line(int n, const double *xyz
284  , EDraw3DStyle sty);
285 
286  virtual TObject *Line(const std::vector<float> &xyz
287  , EDraw3DStyle sty);
288 
289  virtual TObject *Line(const std::vector<double> &xyz
290  , EDraw3DStyle sty);
291 
292  virtual TObject *Tower(float radius
293  , float lambda, float lambda1, float lambda2
294  , float phi,float dphi
295  , Color_t col,Style_t sty, Size_t siz);
296  virtual TObject *Tower( float radius, float lambda, float phi
297  , float dlambda, float dphi
298  , Color_t col,Style_t sty, Size_t siz);
299  virtual TObject *Tower( float radius, const StarRoot::StEta &eta
300  , float phi, float dphi
301  , Color_t col,Style_t sty, Size_t siz);
302 
303  virtual void Joint(StDraw3D *dsp);
304  virtual void SetModel(TObject *model);
305  virtual void SetComment(const char *cmnt);
306  virtual void AddComment(const char *cmnt);
307  virtual void Print(const char *filename) const ;
308  virtual void Print(const char *filename, const char*type) const ;
309  virtual void Save(const char *filename, const char*type="png") const ;
310  virtual void Update(bool asap=false);
311  virtual void Modified();
312  virtual void UpdateModified();
313  virtual void SetDrawOption(Option_t *option="");
314  virtual void SetFooter(const char *footer);
315  virtual void Animate();
316 
317  void Draw3DTest();
318  static void ShowTest();
319  static void ShowDetectorTest(const char *detectorName="StarDetectorUnfolding");
320 private:
321  void Init();
322 
323  ClassDef(StDraw3D,0);
324 };
325 #endif
virtual void Update(bool asap=false)
Render all items from the current display list onto the screen and refesh the screen immiately if asa...
Definition: StDraw3D.cxx:1109
virtual const StDraw3DStyle & Style(EDraw3DStyle type) const
Return the reference to the predefined StDraw3DStyle object.
Definition: StDraw3D.cxx:482
StDraw3DStyle maps &quot;STAR event&quot; EDraw3DStyle onto ROOT (color,style,size) attributes.
Definition: StDraw3D.h:29
virtual void SetBkColor(Color_t newBkColor)
Set the ROOT color as the widget background.
Definition: StDraw3D.cxx:447
static Color_t Pt2Color(double pt)
Maps the track pt to the STAR StTrack track color code.
Definition: StDraw3D.cxx:78
virtual TObject * Tower(float radius, float lambda, float lambda1, float lambda2, float phi, float dphi, Color_t col, Style_t sty, Size_t siz)
This is an overloaded member function, provided for convenience.
Definition: StDraw3D.cxx:1425
virtual TObject * Line(int n, const double *xyz, Color_t col=Color_t(-1), Style_t sty=Style_t(-1), Size_t siz=Size_t(-1))
This is an overloaded member function, provided for convenience.
Definition: StDraw3D.cxx:807
Class StDraw3D - to draw the 3D primitives like 3D points and 3D lines decorated with the STAR detect...
Definition: StDraw3D.h:165
StDraw3D(const char *detectorName="TPC", TVirtualPad *pad=0)
StDraw3D( const char *detectorName,TVirtualPad *pad) ctor.
Definition: StDraw3D.cxx:248
virtual const TString & DetectorNames() const
Definition: StDraw3D.cxx:331
virtual const StDraw3DStyle & AddStyle(EDraw3DStyle type, Color_t col, Style_t sty, Size_t siz)
Map the predefined style type to the ROOT graphical attributes col color sty style siz size...
Definition: StDraw3D.cxx:469
virtual void SetFooter(const char *footer)
Set the footer (caption) defined by the input footer text string.
Definition: StDraw3D.cxx:1603
virtual TObject * Points(int n, const float *xyz, EDraw3DStyle sty)
This is an overloaded member function, provided for convenience.
Definition: StDraw3D.cxx:596
virtual void SetDetectors(const char *nameDetectors)
Set the list of the detector names to be used as the event &quot;background&quot;.
Definition: StDraw3D.cxx:362
virtual void Save(const char *filename, const char *type="png") const
This is an overloaded member function, provided for convenience.
Definition: StDraw3D.cxx:1059
void Draw3DTest()
The built-in quick test to check the application environment and test the basic methods.
Definition: StDraw3D.cxx:1178
virtual void Print(const char *filename) const
Save the current 3D scene using &quot;wrl&quot; file format.
Definition: StDraw3D.cxx:1032
TVirtualViewer3D * Viewer() const
Definition: StDraw3D.cxx:349
TVirtualPad * Pad() const
Definition: StDraw3D.cxx:341
virtual TObject * Draw3D(int n, const float *xyz)
This is an overloaded member function, provided for convenience.
Definition: StDraw3D.cxx:686
virtual void SetDrawOption(Option_t *option="")
Set the varous drawing option. The method passes the input options to TQtCoinWidget::SetDrawOption me...
Definition: StDraw3D.cxx:1097
Definition: StEta.hh:26
virtual void Clear(Option_t *opt="update")
Remove all objects from the list and update the screen if opt is &quot;update&quot;.
Definition: StDraw3D.cxx:398
virtual void AddDetectors(const char *nameDetectors)
Append the detector names to the list of the event &quot;background&quot; shapes.
Definition: StDraw3D.cxx:382
virtual void Animate()
Animate the viewer from the gdb session.
Definition: StDraw3D.cxx:1624