]>
Commit | Line | Data |
---|---|---|
f53bb550 | 1 | // @(#)root/eve:$Id$ |
2 | // Author: Matevz Tadel 2007 | |
3 | ||
4 | /************************************************************************* | |
5 | * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. * | |
6 | * All rights reserved. * | |
7 | * * | |
8 | * For the licensing terms see $ROOTSYS/LICENSE. * | |
9 | * For the list of contributors see $ROOTSYS/README/CREDITS. * | |
10 | *************************************************************************/ | |
11 | ||
12 | #include "TEveJetCone.h" | |
13 | #include "TEveTrans.h" | |
14 | ||
15 | #include "TBuffer3D.h" | |
16 | #include "TBuffer3DTypes.h" | |
17 | #include "TVirtualPad.h" | |
18 | #include "TVirtualViewer3D.h" | |
19 | ||
6646a7eb | 20 | #include "TMath.h" |
21 | ||
f53bb550 | 22 | //______________________________________________________________________________ |
23 | // Description of TEveJetCone | |
24 | // | |
6646a7eb | 25 | // Draw a jet cone with leading particle is specified in (eta,phi) and cone radius is given |
26 | // If Apex is not set, default is (0.,0.,0.) | |
27 | // In case of cylinder was set, cone is cut at the cylinder edges | |
28 | // example : | |
29 | // | |
30 | // Float_t coneEta = r.Uniform(-0.9, 0.9); | |
31 | // Float_t conePhi = r.Uniform(0.0, TwoPi() ); | |
32 | // Float_t coneRadius = 0.4; | |
33 | // | |
34 | // TEveJetCone* jetCone = new TEveJetCone("JetCone"); | |
35 | // jetCone->SetCylinder( 250., 250. ); | |
36 | // if ( (jetCone->AddCone( coneEta, conePhi, coneRadius ) ) != -1) | |
37 | // gEve->AddElement( jetCone ); | |
38 | // | |
f53bb550 | 39 | |
40 | ClassImp(TEveJetCone) | |
41 | ||
42 | //______________________________________________________________________________ | |
43 | TEveJetCone::TEveJetCone(const Text_t* n, const Text_t* t) : | |
44 | TEveElementList(n, t, kTRUE), | |
45 | TAttBBox(), | |
6646a7eb | 46 | fApex( TEveVector(0.,0.,0.) ), |
47 | fBasePoints(), | |
48 | fCylinderBorder( TEveVector(-1.,0.,-1.) ), | |
49 | fThetaC(0.) | |
f53bb550 | 50 | { |
6646a7eb | 51 | // Constructor. |
f53bb550 | 52 | |
6646a7eb | 53 | fColor = kGreen; |
f53bb550 | 54 | } |
55 | ||
56 | ||
57 | /******************************************************************************/ | |
58 | ||
59 | //______________________________________________________________________________ | |
60 | void TEveJetCone::ComputeBBox() | |
61 | { | |
62 | // Compute bounding-box of the data. | |
63 | ||
64 | BBoxInit(); | |
65 | BBoxCheckPoint(fApex); | |
66 | for (vTEveVector_ci i = fBasePoints.begin(); i != fBasePoints.end(); ++i) | |
67 | { | |
68 | BBoxCheckPoint(*i); | |
69 | } | |
70 | } | |
71 | ||
72 | //______________________________________________________________________________ | |
73 | void TEveJetCone::Paint(Option_t*) | |
74 | { | |
75 | // Paint object. | |
76 | // This is for direct rendering (using TEveJetConeGL class). | |
77 | ||
78 | static const TEveException eh("TEveJetCone::Paint "); | |
79 | ||
80 | if (fRnrSelf == kFALSE) return; | |
81 | ||
82 | TBuffer3D buff(TBuffer3DTypes::kGeneric); | |
83 | ||
84 | // Section kCore | |
85 | buff.fID = this; | |
86 | buff.fColor = GetMainColor(); | |
87 | buff.fTransparency = GetMainTransparency(); | |
88 | if (HasMainTrans()) | |
89 | RefMainTrans().SetBuffer3D(buff); | |
90 | buff.SetSectionsValid(TBuffer3D::kCore); | |
91 | ||
92 | Int_t reqSections = gPad->GetViewer3D()->AddObject(buff); | |
93 | if (reqSections != TBuffer3D::kNone) | |
94 | Error(eh, "only direct GL rendering supported."); | |
95 | } | |
6646a7eb | 96 | |
97 | //______________________________________________________________________________ | |
98 | Int_t TEveJetCone::AddCone( const Float_t& eta, const Float_t& phi, const Float_t& coneRadius, const Float_t& height ) | |
99 | { | |
100 | // Add jet cone | |
101 | // parameters are : | |
102 | // * (eta,phi) : of the center/leading particle | |
103 | // * coneRadius : in eta-phi space | |
104 | // * height : height of the cone | |
105 | // * if cylinder is set and length is adapted to cylinder. | |
106 | // - if height is given, it will be used as scalar factor | |
107 | // * if cylinder is not set, height is used as height of the cone | |
108 | // Return 0 on sucess | |
109 | ||
110 | if ( fCylinderBorder.fZ == -1. && fCylinderBorder.fX == -1. && height == -1 ) | |
111 | return -1; | |
112 | ||
113 | TEveVector coneAxis; | |
114 | FillTEveVectorFromEtaPhi( coneAxis, eta, phi ); | |
115 | ||
116 | Float_t angleRad = 0.; | |
117 | for ( Float_t angle = 0.; angle < 360. ; angle+=5. , angleRad=angle*TMath::Pi()/180 ) { | |
118 | ||
119 | // -- Get Contour point | |
120 | TEveVector contourPoint; | |
121 | FillTEveVectorFromEtaPhi( contourPoint, | |
122 | eta + coneRadius * TMath::Cos(angleRad), | |
123 | phi + coneRadius * TMath::Sin(angleRad) ); | |
124 | ||
125 | // -- Set length of the contourPoint | |
126 | if ( fCylinderBorder.fZ != -1. && fCylinderBorder.fX != -1. ) { | |
127 | if ( contourPoint.Theta() < fThetaC ) | |
128 | contourPoint *= fCylinderBorder.fZ / TMath::Cos( contourPoint.Theta() ) ; | |
129 | else if ( contourPoint.Theta() > ( TMath::Pi() - fThetaC ) ) | |
130 | contourPoint *= fCylinderBorder.fZ / TMath::Cos( contourPoint.Theta() - TMath::Pi() ) ; | |
131 | else | |
132 | contourPoint *= fCylinderBorder.fX / TMath::Sin( contourPoint.Theta() ) ; | |
133 | ||
134 | if ( height != -1 ) contourPoint *= height; | |
135 | } | |
136 | else { | |
137 | contourPoint *= height / GetArcCosConeOpeningAngle( coneAxis, contourPoint ); | |
138 | } | |
139 | ||
140 | // -- Add contourPoint | |
141 | fBasePoints.push_back( contourPoint ); | |
142 | } | |
143 | ||
144 | return 0; | |
145 | } | |
146 | ||
147 | //______________________________________________________________________________ | |
148 | void TEveJetCone::FillTEveVectorFromEtaPhi( TEveVector &vec, const Float_t& eta, const Float_t& phi ) | |
149 | { | |
150 | // Fill TEveVector with eta and phi, with magnitude 1. | |
151 | ||
152 | vec.Set( TMath::Cos(phi) / TMath::CosH(eta), | |
153 | TMath::Sin(phi) / TMath::CosH(eta), | |
154 | TMath::TanH(eta) ); | |
155 | return; | |
156 | } | |
157 | ||
158 | //______________________________________________________________________________ | |
159 | Float_t TEveJetCone::GetArcCosConeOpeningAngle( const TEveVector& axis, const TEveVector& contour ) { | |
160 | // Return the arccos of the opening angle between two eve vectors | |
161 | ||
162 | Float_t arcCos = 0.; | |
163 | ||
164 | Float_t tot2 = axis.Mag2() * contour.Mag2(); | |
165 | if( tot2 > 0. ) { | |
166 | arcCos = axis.Dot( contour )/ TMath::Sqrt( tot2 ); | |
167 | if (arcCos > 1.0) arcCos = 1.0; | |
168 | if (arcCos < -1.0) arcCos = -1.0; | |
169 | } | |
170 | ||
171 | return arcCos; | |
172 | } |