Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
REveJetCone.cxx
Go to the documentation of this file.
1// @(#)root/eve7:$Id$
2// Author: Matevz Tadel, Jochen Thaeder 2009, 2018
3
4/*************************************************************************
5 * Copyright (C) 1995-2019, 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 <ROOT/REveJetCone.hxx>
13#include <ROOT/REveTrans.hxx>
16
17#include "TMath.h"
18#include "TClass.h"
19
20#include <cassert>
21
22using namespace ROOT::Experimental;
23
24/** \class REveJetCone
25\ingroup REve
26Draws a jet cone with leading particle is specified in (eta,phi) and
27cone radius is given.
28
29If Apex is not set, default is (0.,0.,0.)
30In case of cylinder was set, cone is cut at the cylinder edges.
31
32Example :
33~~~ {.cpp}
34 Float_t coneEta = r.Uniform(-0.9, 0.9);
35 Float_t conePhi = r.Uniform(0.0, TwoPi() );
36 Float_t coneRadius = 0.4;
37
38 REveJetCone* jetCone = new REveJetCone("JetCone");
39 jetCone->SetCylinder(250, 250);
40 if (jetCone->AddCone(coneEta, conePhi, coneRadius) != -1)
41 gEve->AddElement(jetCone);
42~~~
43
44#### Implementation notes
45
46REveVector fLimits encodes the following information:
47 - fY, fZ: barrel radius and endcap z-position;
48 if both are 0, fX encodes the spherical radius
49 - fX : scaling for length of the cone
50*/
51
52////////////////////////////////////////////////////////////////////////////////
53/// Constructor.
54
55REveJetCone::REveJetCone(const Text_t* n, const Text_t* t) :
56 REveShape(n, t),
57 fApex(),
58 fLimits(), fThetaC(10),
59 fEta(0), fPhi(0), fDEta(0), fDPhi(0), fNDiv(36)
60{
61 fPickable = true;
63}
64
65////////////////////////////////////////////////////////////////////////////////
66/// Set Number of Divisions
67////////////////////////////////////////////////////////////////////////////////
69{
70 fNDiv = TMath::Max(4, n);
71 if (fNDiv % 4 > 0) { fNDiv += 4 - fNDiv % 4; };
73}
74
75////////////////////////////////////////////////////////////////////////////////
76/// Fill core part of JSON representation.
77
78Int_t REveJetCone::WriteCoreJson(nlohmann::json &j, Int_t rnr_offset)
79{
80 Int_t ret = REveElement::WriteCoreJson(j, rnr_offset);
81
82 j["fMainColor"] = GetFillColor();
83 j["fLineColor"] = GetLineColor();
84 j["fNDiv"] = GetNDiv();
85
86 return ret;
87}
88
89////////////////////////////////////////////////////////////////////////////////
90/// Crates 3D point array for rendering.
91
93{
94 assert(fNDiv > 2);
95
96 const Int_t NP = 1 + fNDiv;
97
98 fRenderData = std::make_unique<REveRenderData>("makeJet", 3 * NP);
99
100 fRenderData->PushV(fApex);
101
102 Float_t angle_step = TMath::TwoPi() / fNDiv;
103 Float_t angle = 0;
104 for (Int_t i = 0; i < fNDiv; ++i, angle += angle_step)
105 {
106 fRenderData->PushV( CalcBaseVec(angle) );
107 }
108}
109
110////////////////////////////////////////////////////////////////////////////////
111/// Compute bounding-box of the data.
112
114{
115 BBoxInit();
121}
122
123////////////////////////////////////////////////////////////////////////////////
124/// Virtual from REveProjectable, returns REveJetConeProjected class.
125
127{
128 return TClass::GetClass<REveJetConeProjected>();
129}
130
131////////////////////////////////////////////////////////////////////////////////
132/// Add jet cone.
133/// parameters are :
134/// - (eta,phi) : of the center/leading particle
135/// - cone_r : cone radius in eta-phi space
136/// - length : length of the cone
137/// - if cylinder is set and length is adapted to cylinder.
138/// - if length is given, it will be used as scalar factor
139/// - if cylinder is not set, length is used as length of the cone
140/// Return 0 on success.
141
143{
144 return AddEllipticCone(eta, phi, cone_r, cone_r, length);
145}
146
147////////////////////////////////////////////////////////////////////////////////
148/// Add jet cone.
149/// parameters are :
150/// - (eta,phi) : of the center/leading particle
151/// - (reta, rphi) : radius of cone in eta-phi space
152/// - length : length of the cone
153/// - if cylinder is set and length is adapted to cylinder.
154/// - if length is given, it will be used as scalar factor
155/// - if cylinder is not set, length is used as length of the cone
156/// Returns 0 on success.
157
159{
160 if (length != 0) fLimits.fX = length;
161
162 if (fLimits.IsZero())
163 return -1;
164
165 fEta = eta; fPhi = phi; fDEta = reta; fDPhi = rphi;
166
167 return 0;
168}
169
170////////////////////////////////////////////////////////////////////////////////
171/// Fill REveVector with eta and phi, magnitude 1.
172
174{
175 using namespace TMath;
176
177 return REveVector(Cos(phi) / CosH(eta), Sin(phi) / CosH(eta), TanH(eta));
178}
179
180////////////////////////////////////////////////////////////////////////////////
181/// Returns point on the base of the cone with given eta and phi.
182
184{
185 using namespace TMath;
186
187 REveVector vec = CalcEtaPhiVec(eta, phi);
188
189 // -- Set length of the contourPoint
190 if (fLimits.fY != 0 && fLimits.fZ != 0)
191 {
192 Float_t theta = vec.Theta();
193 if (theta < fThetaC)
194 vec *= fLimits.fZ / Cos(theta);
195 else if (theta > Pi() - fThetaC)
196 vec *= fLimits.fZ / Cos(theta - Pi());
197 else
198 vec *= fLimits.fY / Sin(theta);
199
200 if (fLimits.fX != 0) vec *= fLimits.fX;
201 }
202 else
203 {
204 vec *= fLimits.fX;
205 }
206
207 return vec;
208}
209
210////////////////////////////////////////////////////////////////////////////////
211/// Returns point on the base of the cone with internal angle alpha:
212/// alpha = 0 -> max eta, alpha = pi/2 -> max phi, ...
213
215{
216 using namespace TMath;
217
218 return CalcBaseVec(fEta + fDEta * Cos(alpha), fPhi + fDPhi * Sin(alpha));
219}
220
221////////////////////////////////////////////////////////////////////////////////
222/// Returns true if the cone is in barrel / endcap transition region.
223
225{
226 using namespace TMath;
227
228 Float_t tm = CalcBaseVec(0).Theta();
229 Float_t tM = CalcBaseVec(Pi()).Theta();
230
231 return (tM > fThetaC && tm < fThetaC) ||
232 (tM > Pi() - fThetaC && tm < Pi() - fThetaC);
233}
234
235
236/** \class REveJetConeProjected
237\ingroup REve
238Projection of REveJetCone.
239*/
240
241////////////////////////////////////////////////////////////////////////////////
242/// Constructor.
243
244REveJetConeProjected::REveJetConeProjected(const std::string& n, const std::string& t) :
245 REveShape(n, t)
246{
247}
248
249////////////////////////////////////////////////////////////////////////////////
250/// Destructor.
251
253{
254}
255
256////////////////////////////////////////////////////////////////////////////////
257/// Crates 3D point array for rendering.
258
260{
261 static const REveException kEH("REveJetConeProjected::BuildRenderData ");
262
264 REveJetCone *C = dynamic_cast<REveJetCone*>(GetProjectable());
265
267 {
268 fRenderData = std::make_unique<REveRenderData>("makeJetProjected", 4);
269
270 std::vector<REveVector> V;
271 V.reserve(4);
272 V.resize(3);
273
275 {
276 V[0] = C->fApex;
277 V[1] = C->CalcBaseVec(TMath::Pi() + TMath::PiOver2());
278 V[2] = C->CalcBaseVec(TMath::PiOver2());
279
280 for (Int_t i = 0; i < 3; ++i)
281 P->ProjectVector(V[i], fDepth);
282 }
283 else // RhoZ
284 {
285 V[0] = C->fApex;
286 V[1] = C->CalcBaseVec(0);
287 V[2] = C->CalcBaseVec(TMath::Pi());
288
289 Float_t tm = V[1].Theta();
290 Float_t tM = V[2].Theta();
291
292 if (tM > C->fThetaC && tm < C->fThetaC) {
293 REveVector v(0, C->fLimits.fY, C->fLimits.fZ);
294
295 V.push_back(C->CalcBaseVec(v.Eta(), C->fPhi));
296 }
297
298 if (tM > TMath::Pi() - C->fThetaC && tm < TMath::Pi() - C->fThetaC) {
299 REveVector v(0, C->fLimits.fY, -C->fLimits.fZ);
300
301 V.push_back(C->CalcBaseVec(v.Eta(), C->fPhi));
302 }
303
304 for (auto &v : V)
306
307 std::sort(V.begin() + 1, V.end(), [](const auto &a, const auto &b) -> bool { return a.Phi() < b.Phi(); });
308 }
309
310 for (auto &v : V)
311 fRenderData->PushV(v);
312 }
313 else
314 {
315 const Int_t NP = 1 + C->fNDiv;
316
317 fRenderData = std::make_unique<REveRenderData>("makeJet", 3 * NP);
318
319 fRenderData->PushV(C->fApex);
320
321 Float_t angle_step = TMath::TwoPi() / C->fNDiv;
322 Float_t angle = 0;
323 for (Int_t i = 0; i < C->fNDiv; ++i, angle += angle_step) {
324 auto tv = C->CalcBaseVec(angle);
325 P->ProjectVector(tv, fDepth);
326 fRenderData->PushV(tv);
327 }
328 }
329}
330
331////////////////////////////////////////////////////////////////////////////////
332/// Compute bounding-box, virtual from TAttBBox.
333
335{
336 BBoxInit();
337
338 REveJetCone *cone = dynamic_cast<REveJetCone*>(fProjectable);
341 v = cone->fApex; proj->ProjectVector(v, fDepth); BBoxCheckPoint(v);
342 v = cone->CalcBaseVec(0); proj->ProjectVector(v, fDepth); BBoxCheckPoint(v);
346}
347
348////////////////////////////////////////////////////////////////////////////////
349/// This is virtual method from base-class REveProjected.
350
352{
353 SetDepthCommon(d, this, fBBox);
354}
355
356////////////////////////////////////////////////////////////////////////////////
357/// This is virtual method from base-class REveProjected.
358
360{
362 CopyVizParams(dynamic_cast<REveElement*>(model));
363}
364
365////////////////////////////////////////////////////////////////////////////////
366/// Re-project the jet-cone.
367
369{
370}
#define d(i)
Definition RSha256.hxx:102
#define b(i)
Definition RSha256.hxx:100
#define a(i)
Definition RSha256.hxx:99
char Text_t
Definition RtypesCore.h:62
@ kGreen
Definition Rtypes.h:66
virtual Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset)
Write core json.
std::unique_ptr< REveRenderData > fRenderData
Externally assigned and controlled user data.
REveException Exception-type thrown by Eve classes.
Definition REveTypes.hxx:40
void SetDepthLocal(Float_t d) override
This is virtual method from base-class REveProjected.
void UpdateProjection() override
Re-project the jet-cone.
void SetProjection(REveProjectionManager *mng, REveProjectable *model) override
This is virtual method from base-class REveProjected.
REveJetConeProjected(const REveJetConeProjected &)=delete
void BuildRenderData() override
Crates 3D point array for rendering.
void ComputeBBox() override
Compute bounding-box, virtual from TAttBBox.
TClass * ProjectedClass(const REveProjection *p) const override
Virtual from REveProjectable, returns REveJetConeProjected class.
Int_t AddCone(Float_t eta, Float_t phi, Float_t cone_r, Float_t length=0)
Add jet cone.
Int_t AddEllipticCone(Float_t eta, Float_t phi, Float_t reta, Float_t rphi, Float_t length=0)
Add jet cone.
void SetNDiv(Int_t n)
Set Number of Divisions.
REveVector CalcBaseVec(Float_t eta, Float_t phi) const
Returns point on the base of the cone with given eta and phi.
Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override
Fill core part of JSON representation.
REveVector CalcEtaPhiVec(Float_t eta, Float_t phi) const
Fill REveVector with eta and phi, magnitude 1.
Bool_t IsInTransitionRegion() const
Returns true if the cone is in barrel / endcap transition region.
void ComputeBBox() override
Compute bounding-box of the data.
void BuildRenderData() override
Crates 3D point array for rendering.
REveProjectionManager * GetManager() const
virtual void SetProjection(REveProjectionManager *mng, REveProjectable *model)
Sets projection manager and reference in the projectable object.
void SetDepthCommon(Float_t d, REveElement *el, Float_t *bbox)
Utility function to update the z-values of the bounding-box.
REveProjectable * GetProjectable() const
REveProjectionManager Manager class for steering of projections and managing projected objects.
REveProjection Base for specific classes that implement non-linear projections.
void ProjectVector(REveVector &v, Float_t d)
Project REveVector.
void CopyVizParams(const REveElement *el) override
Copy visualization parameters from element el.
Definition REveShape.cxx:84
virtual Color_t GetFillColor() const
Definition REveShape.hxx:57
virtual Color_t GetLineColor() const
Definition REveShape.hxx:58
void BBoxCheckPoint(Float_t x, Float_t y, Float_t z)
Definition TAttBBox.h:58
void BBoxInit(Float_t infinity=1e6)
Dynamic Float_t[6] X(min,max), Y(min,max), Z(min,max)
Definition TAttBBox.cxx:29
Float_t * fBBox
Definition TAttBBox.h:20
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:80
const Int_t n
Definition legend1.C:16
REveVectorT< Float_t > REveVector
TMath.
Definition TMathBase.h:35
Short_t Max(Short_t a, Short_t b)
Definition TMathBase.h:212
constexpr Double_t PiOver2()
Definition TMath.h:51
constexpr Double_t Pi()
Definition TMath.h:37
constexpr Double_t TwoPi()
Definition TMath.h:44