Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TEveJetCone.cxx
Go to the documentation of this file.
1 // @(#)root/eve:$Id$
2 // Author: Matevz Tadel, Jochen Thaeder 2009
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 #include "TEveProjectionManager.h"
15 
16 #include "TMath.h"
17 
18 /** \class TEveJetCone
19 \ingroup TEve
20 Draws a jet cone with leading particle is specified in (eta,phi) and
21 cone radius is given.
22 
23 If Apex is not set, default is (0.,0.,0.)
24 In case of cylinder was set, cone is cut at the cylinder edges.
25 
26 Example :
27 ~~~ {.cpp}
28  Float_t coneEta = r.Uniform(-0.9, 0.9);
29  Float_t conePhi = r.Uniform(0.0, TwoPi() );
30  Float_t coneRadius = 0.4;
31 
32  TEveJetCone* jetCone = new TEveJetCone("JetCone");
33  jetCone->SetCylinder(250, 250);
34  if (jetCone->AddCone(coneEta, conePhi, coneRadius) != -1)
35  gEve->AddElement(jetCone);
36 ~~~
37 
38 #### Implementation notes
39 
40 TEveVector fLimits encodes the following information:
41  - fY, fZ: barrel radius and endcap z-position;
42  if both are 0, fX encodes the spherical radius
43  - fX : scaling for length of the cone
44 */
45 
46 ClassImp(TEveJetCone);
47 
48 ////////////////////////////////////////////////////////////////////////////////
49 /// Constructor.
50 
51 TEveJetCone::TEveJetCone(const Text_t* n, const Text_t* t) :
52  TEveShape(n, t),
53  fApex(),
54  fLimits(), fThetaC(10),
55  fEta(0), fPhi(0), fDEta(0), fDPhi(0), fNDiv(72)
56 {
57  fColor = kGreen;
58 }
59 
60 ////////////////////////////////////////////////////////////////////////////////
61 /// Compute bounding-box of the data.
62 
63 void TEveJetCone::ComputeBBox()
64 {
65  BBoxInit();
66  BBoxCheckPoint(fApex);
67  BBoxCheckPoint(CalcBaseVec(0));
68  BBoxCheckPoint(CalcBaseVec(TMath::PiOver2()));
69  BBoxCheckPoint(CalcBaseVec(TMath::Pi()));
70  BBoxCheckPoint(CalcBaseVec(TMath::Pi() + TMath::PiOver2()));
71 }
72 
73 ////////////////////////////////////////////////////////////////////////////////
74 /// Virtual from TEveProjectable, returns TEveJetConeProjected class.
75 
76 TClass* TEveJetCone::ProjectedClass(const TEveProjection*) const
77 {
78  return TEveJetConeProjected::Class();
79 }
80 
81 ////////////////////////////////////////////////////////////////////////////////
82 /// Add jet cone.
83 /// parameters are :
84 /// - (eta,phi) : of the center/leading particle
85 /// - cone_r : cone radius in eta-phi space
86 /// - length : length of the cone
87 /// - if cylinder is set and length is adapted to cylinder.
88 /// - if length is given, it will be used as scalar factor
89 /// - if cylinder is not set, length is used as length of the cone
90 /// Return 0 on success.
91 
92 Int_t TEveJetCone::AddCone(Float_t eta, Float_t phi, Float_t cone_r, Float_t length)
93 {
94  return AddEllipticCone(eta, phi, cone_r, cone_r, length);
95 }
96 
97 ////////////////////////////////////////////////////////////////////////////////
98 /// Add jet cone.
99 /// parameters are :
100 /// - (eta,phi) : of the center/leading particle
101 /// - (reta, rphi) : radius of cone in eta-phi space
102 /// - length : length of the cone
103 /// - if cylinder is set and length is adapted to cylinder.
104 /// - if length is given, it will be used as scalar factor
105 /// - if cylinder is not set, length is used as length of the cone
106 /// Returns 0 on success.
107 
108 Int_t TEveJetCone::AddEllipticCone(Float_t eta, Float_t phi, Float_t reta, Float_t rphi, Float_t length)
109 {
110  using namespace TMath;
111 
112  if (length != 0) fLimits.fX = length;
113 
114  if (fLimits.IsZero())
115  return -1;
116 
117  fEta = eta; fPhi = phi; fDEta = reta; fDPhi = rphi;
118 
119  return 0;
120 }
121 
122 ////////////////////////////////////////////////////////////////////////////////
123 /// Fill TEveVector with eta and phi, magnitude 1.
124 
125 TEveVector TEveJetCone::CalcEtaPhiVec(Float_t eta, Float_t phi) const
126 {
127  using namespace TMath;
128 
129  return TEveVector(Cos(phi) / CosH(eta), Sin(phi) / CosH(eta), TanH(eta));
130 }
131 
132 ////////////////////////////////////////////////////////////////////////////////
133 /// Returns point on the base of the cone with given eta and phi.
134 
135 TEveVector TEveJetCone::CalcBaseVec(Float_t eta, Float_t phi) const
136 {
137  using namespace TMath;
138 
139  TEveVector vec = CalcEtaPhiVec(eta, phi);
140 
141  // -- Set length of the contourPoint
142  if (fLimits.fY != 0 && fLimits.fZ != 0)
143  {
144  Float_t theta = vec.Theta();
145  if (theta < fThetaC)
146  vec *= fLimits.fZ / Cos(theta);
147  else if (theta > Pi() - fThetaC)
148  vec *= fLimits.fZ / Cos(theta - Pi());
149  else
150  vec *= fLimits.fY / Sin(theta);
151 
152  if (fLimits.fX != 0) vec *= fLimits.fX;
153  }
154  else
155  {
156  vec *= fLimits.fX;
157  }
158 
159  return vec;
160 }
161 
162 ////////////////////////////////////////////////////////////////////////////////
163 /// Returns point on the base of the cone with internal angle alpha:
164 /// alpha = 0 -> max eta, alpha = pi/2 -> max phi, ...
165 
166 TEveVector TEveJetCone::CalcBaseVec(Float_t alpha) const
167 {
168  using namespace TMath;
169 
170  return CalcBaseVec(fEta + fDEta * Cos(alpha), fPhi + fDPhi * Sin(alpha));
171 }
172 
173 ////////////////////////////////////////////////////////////////////////////////
174 /// Returns true if the cone is in barrel / endcap transition region.
175 
176 Bool_t TEveJetCone::IsInTransitionRegion() const
177 {
178  using namespace TMath;
179 
180  Float_t tm = CalcBaseVec(0).Theta();
181  Float_t tM = CalcBaseVec(Pi()).Theta();
182 
183  return (tM > fThetaC && tm < fThetaC) ||
184  (tM > Pi() - fThetaC && tm < Pi() - fThetaC);
185 }
186 
187 /** \class TEveJetConeProjected
188 \ingroup TEve
189 Projection of TEveJetCone.
190 */
191 
192 ////////////////////////////////////////////////////////////////////////////////
193 /// Constructor.
194 
195 TEveJetConeProjected::TEveJetConeProjected(const char* n, const char* t) :
196  TEveShape(n, t)
197 {
198 }
199 
200 ////////////////////////////////////////////////////////////////////////////////
201 /// Destructor.
202 
203 TEveJetConeProjected::~TEveJetConeProjected()
204 {
205 }
206 
207 ////////////////////////////////////////////////////////////////////////////////
208 /// Compute bounding-box, virtual from TAttBBox.
209 
210 void TEveJetConeProjected::ComputeBBox()
211 {
212  BBoxInit();
213 
214  TEveJetCone *cone = dynamic_cast<TEveJetCone*>(fProjectable);
215 ////////////////////////////////////////////////////////////////////////////////
216 
217  TEveProjection *proj = GetManager()->GetProjection();
218  TEveVector v;
219  v = cone->fApex; proj->ProjectVector(v, fDepth); BBoxCheckPoint(v);
220  v = cone->CalcBaseVec(0); proj->ProjectVector(v, fDepth); BBoxCheckPoint(v);
221  v = cone->CalcBaseVec(TMath::PiOver2()); proj->ProjectVector(v, fDepth); BBoxCheckPoint(v);
222  v = cone->CalcBaseVec(TMath::Pi()); proj->ProjectVector(v, fDepth); BBoxCheckPoint(v);
223  v = cone->CalcBaseVec(TMath::Pi() + TMath::PiOver2()); proj->ProjectVector(v, fDepth); BBoxCheckPoint(v);
224 }
225 
226 ////////////////////////////////////////////////////////////////////////////////
227 /// This is virtual method from base-class TEveProjected.
228 
229 void TEveJetConeProjected::SetDepthLocal(Float_t d)
230 {
231  SetDepthCommon(d, this, fBBox);
232 }
233 
234 ////////////////////////////////////////////////////////////////////////////////
235 /// This is virtual method from base-class TEveProjected.
236 
237 void TEveJetConeProjected::SetProjection(TEveProjectionManager* mng, TEveProjectable* model)
238 {
239  TEveProjected::SetProjection(mng, model);
240  CopyVizParams(dynamic_cast<TEveElement*>(model));
241 }
242 
243 ////////////////////////////////////////////////////////////////////////////////
244 /// Re-project the jet-cone.
245 
246 void TEveJetConeProjected::UpdateProjection()
247 {
248 }