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
22#include <nlohmann/json.hpp>
23
24using namespace ROOT::Experimental;
25
26namespace {
27
28/// The entry `pos` of n points: the apex, then the base or the projected rim.
29/// The client draws the triangles of a fan from the apex.
30REveRenderData::Entry &NewConeEntry(REveRenderData &rd, size_t n)
31{
32 using RD = REveRenderData;
33 return rd.NewEntry("pos", RD::EType::kF32, 3).Role(RD::ERole::kVertex).Prim(RD::EPrim::kTriangles).Reserve(n);
34}
35
36} // namespace
37
38/** \class REveJetCone
39\ingroup REve
40Draws a jet cone with leading particle is specified in (eta,phi) and
41cone radius is given.
42
43If Apex is not set, default is (0.,0.,0.)
44In case of cylinder was set, cone is cut at the cylinder edges.
45
46Example :
47~~~ {.cpp}
48 Float_t coneEta = r.Uniform(-0.9, 0.9);
49 Float_t conePhi = r.Uniform(0.0, TwoPi() );
50 Float_t coneRadius = 0.4;
51
52 REveJetCone* jetCone = new REveJetCone("JetCone");
53 jetCone->SetCylinder(250, 250);
54 if (jetCone->AddCone(coneEta, conePhi, coneRadius) != -1)
55 gEve->AddElement(jetCone);
56~~~
57
58#### Implementation notes
59
60REveVector fLimits encodes the following information:
61 - fY, fZ: barrel radius and endcap z-position;
62 if both are 0, fX encodes the spherical radius
63 - fX : scaling for length of the cone
64
65The render data is one entry, `pos`, f32 x 3: the apex, then fNDiv points on
66the base, starting at the maximum eta and going round in steps of 2 pi / fNDiv,
67primitive triangles. The client draws the triangles of a fan from the apex,
68the base rim as a line loop and every fourth base point joined to the apex.
69*/
70
71////////////////////////////////////////////////////////////////////////////////
72/// Constructor.
73
74REveJetCone::REveJetCone(const Text_t* n, const Text_t* t) :
75 REveShape(n, t),
76 fApex(),
77 fLimits(), fThetaC(10),
78 fEta(0), fPhi(0), fDEta(0), fDPhi(0), fNDiv(36)
79{
80 fPickable = true;
82}
83
84////////////////////////////////////////////////////////////////////////////////
85/// Set Number of Divisions
86////////////////////////////////////////////////////////////////////////////////
88{
89 fNDiv = TMath::Max(4, n);
90 if (fNDiv % 4 > 0) { fNDiv += 4 - fNDiv % 4; };
92}
93
94////////////////////////////////////////////////////////////////////////////////
95/// Fill core part of JSON representation.
96
97Int_t REveJetCone::WriteCoreJson(nlohmann::json &j, Int_t rnr_offset)
98{
99 Int_t ret = REveElement::WriteCoreJson(j, rnr_offset);
100
101 j["fMainColor"] = GetFillColor();
102 j["fLineColor"] = GetLineColor();
103 j["fNDiv"] = GetNDiv();
104
105 return ret;
106}
107
108////////////////////////////////////////////////////////////////////////////////
109/// Write the render data entry `pos`, see the class description.
110
112{
113 assert(fNDiv > 2);
114
115 fRenderData = std::make_unique<REveRenderData>("makeJet");
116 auto &pos = NewConeEntry(*fRenderData, 1 + fNDiv);
117
118 pos.Push(fApex);
119
120 Float_t angle_step = TMath::TwoPi() / fNDiv;
121 Float_t angle = 0;
122 for (Int_t i = 0; i < fNDiv; ++i, angle += angle_step)
123 {
124 pos.Push(CalcBaseVec(angle));
125 }
126}
127
128////////////////////////////////////////////////////////////////////////////////
129/// Compute bounding-box of the data.
130
140
141////////////////////////////////////////////////////////////////////////////////
142/// Virtual from REveProjectable, returns REveJetConeProjected class.
143
145{
146 return TClass::GetClass<REveJetConeProjected>();
147}
148
149////////////////////////////////////////////////////////////////////////////////
150/// Add jet cone.
151/// parameters are :
152/// - (eta,phi) : of the center/leading particle
153/// - cone_r : cone radius in eta-phi space
154/// - length : length of the cone
155/// - if cylinder is set and length is adapted to cylinder.
156/// - if length is given, it will be used as scalar factor
157/// - if cylinder is not set, length is used as length of the cone
158/// Return 0 on success.
159
161{
162 return AddEllipticCone(eta, phi, cone_r, cone_r, length);
163}
164
165////////////////////////////////////////////////////////////////////////////////
166/// Add jet cone.
167/// parameters are :
168/// - (eta,phi) : of the center/leading particle
169/// - (reta, rphi) : radius of cone in eta-phi space
170/// - length : length of the cone
171/// - if cylinder is set and length is adapted to cylinder.
172/// - if length is given, it will be used as scalar factor
173/// - if cylinder is not set, length is used as length of the cone
174/// Returns 0 on success.
175
177{
178 if (length != 0) fLimits.fX = length;
179
180 if (fLimits.IsZero())
181 return -1;
182
183 fEta = eta; fPhi = phi; fDEta = reta; fDPhi = rphi;
184
185 return 0;
186}
187
188////////////////////////////////////////////////////////////////////////////////
189/// Fill REveVector with eta and phi, magnitude 1.
190
192{
193 using namespace TMath;
194
195 return REveVector(Cos(phi) / CosH(eta), Sin(phi) / CosH(eta), TanH(eta));
196}
197
198////////////////////////////////////////////////////////////////////////////////
199/// Returns point on the base of the cone with given eta and phi.
200
202{
203 using namespace TMath;
204
205 REveVector vec = CalcEtaPhiVec(eta, phi);
206
207 // -- Set length of the contourPoint
208 if (fLimits.fY != 0 && fLimits.fZ != 0)
209 {
210 Float_t theta = vec.Theta();
211 if (theta < fThetaC)
212 vec *= fLimits.fZ / Cos(theta);
213 else if (theta > Pi() - fThetaC)
214 vec *= fLimits.fZ / Cos(theta - Pi());
215 else
216 vec *= fLimits.fY / Sin(theta);
217
218 if (fLimits.fX != 0) vec *= fLimits.fX;
219 }
220 else
221 {
222 vec *= fLimits.fX;
223 }
224
225 return vec;
226}
227
228////////////////////////////////////////////////////////////////////////////////
229/// Returns point on the base of the cone with internal angle alpha:
230/// alpha = 0 -> max eta, alpha = pi/2 -> max phi, ...
231
233{
234 using namespace TMath;
235
236 return CalcBaseVec(fEta + fDEta * Cos(alpha), fPhi + fDPhi * Sin(alpha));
237}
238
239////////////////////////////////////////////////////////////////////////////////
240/// Returns true if the cone is in barrel / endcap transition region.
241
243{
244 using namespace TMath;
245
246 Float_t tm = CalcBaseVec(0).Theta();
247 Float_t tM = CalcBaseVec(Pi()).Theta();
248
249 return (tM > fThetaC && tm < fThetaC) ||
250 (tM > Pi() - fThetaC && tm < Pi() - fThetaC);
251}
252
253/** \class REveJetConeProjected
254\ingroup REve
255Projection of REveJetCone.
256
257The render data is one entry, `pos`, f32 x 3, primitive triangles, the
258projected apex first. In RPhi and RhoZ the rnr_func is makeJetProjected and
259the cone is a triangle of the apex and two rim points; in RhoZ a cone across
260a barrel / endcap transition adds the corner point of that transition, and
261the points after the apex are sorted by phi. In the other projections the
262rnr_func is makeJet and the points are the cone's, the apex and fNDiv base
263points, projected.
264*/
265
266////////////////////////////////////////////////////////////////////////////////
267/// Constructor.
268
269REveJetConeProjected::REveJetConeProjected(const std::string& n, const std::string& t) :
270 REveShape(n, t)
271{
272}
273
274////////////////////////////////////////////////////////////////////////////////
275/// Destructor.
276
280
281////////////////////////////////////////////////////////////////////////////////
282/// Write the render data entry `pos`, see the class description.
283
285{
286 static const REveException kEH("REveJetConeProjected::BuildRenderData ");
287
289 REveJetCone *C = dynamic_cast<REveJetCone*>(GetProjectable());
290 REveTrans mt;
291 const REveTrans *T = GetManager()->GetModelTrans(C, mt);
292
294 std::vector<REveVector> V;
295 V.reserve(4);
296 V.resize(3);
297
299 {
300 V[0] = C->fApex;
301 V[1] = C->CalcBaseVec(TMath::Pi() + TMath::PiOver2());
302 V[2] = C->CalcBaseVec(TMath::PiOver2());
303
304 for (Int_t i = 0; i < 3; ++i)
305 P->ProjectVector(T, V[i], fDepth);
306 }
307 else // RhoZ
308 {
309 V[0] = C->fApex;
310 V[1] = C->CalcBaseVec(0);
311 V[2] = C->CalcBaseVec(TMath::Pi());
312
313 Float_t tm = V[1].Theta();
314 Float_t tM = V[2].Theta();
315
316 if (tM > C->fThetaC && tm < C->fThetaC) {
317 REveVector v(0, C->fLimits.fY, C->fLimits.fZ);
318
319 V.push_back(C->CalcBaseVec(v.Eta(), C->fPhi));
320 }
321
322 if (tM > TMath::Pi() - C->fThetaC && tm < TMath::Pi() - C->fThetaC) {
323 REveVector v(0, C->fLimits.fY, -C->fLimits.fZ);
324
325 V.push_back(C->CalcBaseVec(v.Eta(), C->fPhi));
326 }
327
328 for (auto &v : V)
329 P->ProjectVector(T, v, fDepth);
330
331 std::sort(V.begin() + 1, V.end(), [](const auto &a, const auto &b) -> bool { return a.Phi() < b.Phi(); });
332 }
333
334 fRenderData = std::make_unique<REveRenderData>("makeJetProjected");
335 auto &pos = NewConeEntry(*fRenderData, V.size());
336 for (auto &v : V)
337 pos.Push(v);
338 } else {
339 fRenderData = std::make_unique<REveRenderData>("makeJet");
340 auto &pos = NewConeEntry(*fRenderData, 1 + C->fNDiv);
341
342 REveVector apex = C->fApex;
343 P->ProjectVector(T, apex, fDepth);
344 pos.Push(apex);
345
346 Float_t angle_step = TMath::TwoPi() / C->fNDiv;
347 Float_t angle = 0;
348 for (Int_t i = 0; i < C->fNDiv; ++i, angle += angle_step) {
349 auto tv = C->CalcBaseVec(angle);
350 P->ProjectVector(T, tv, fDepth);
351 pos.Push(tv);
352 }
353 }
354}
355
356////////////////////////////////////////////////////////////////////////////////
357/// Fill the bounding box (virtual from REveElement).
358
360{
361 BBoxInit();
362
363 REveJetCone *cone = dynamic_cast<REveJetCone*>(fProjectable);
365 REveTrans mt;
366 const REveTrans *T = GetManager()->GetModelTrans(cone, mt);
368 v = cone->fApex;
369 proj->ProjectVector(T, v, fDepth);
371 v = cone->CalcBaseVec(0);
372 proj->ProjectVector(T, v, fDepth);
374 v = cone->CalcBaseVec(TMath::PiOver2());
375 proj->ProjectVector(T, v, fDepth);
377 v = cone->CalcBaseVec(TMath::Pi());
378 proj->ProjectVector(T, v, fDepth);
380 v = cone->CalcBaseVec(TMath::Pi() + TMath::PiOver2());
381 proj->ProjectVector(T, v, fDepth);
383}
384
385////////////////////////////////////////////////////////////////////////////////
386/// This is virtual method from base-class REveProjected.
387
392
393////////////////////////////////////////////////////////////////////////////////
394/// This is virtual method from base-class REveProjected.
395
401
402////////////////////////////////////////////////////////////////////////////////
403/// Re-project the jet-cone.
404
#define d(i)
Definition RSha256.hxx:102
#define b(i)
Definition RSha256.hxx:100
#define a(i)
Definition RSha256.hxx:99
char Text_t
General string (char)
Definition RtypesCore.h:77
@ kGreen
Definition Rtypes.h:66
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h length
Option_t Option_t TPoint TPoint angle
virtual Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset)
Write core json.
void BBoxCheckPoint(const REveVector &v)
std::unique_ptr< REveRenderData > fRenderData
! Render data entries for the client's maker, see REveRenderData.
void BBoxInit()
Start filling the bounding box with BBoxCheckPoint(): min at +infinity, max at -infinity,...
REveException Exception-type thrown by Eve classes.
Definition REveTypes.hxx:42
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
Write the render data entry pos, see the class description.
void ComputeBBox() override
Fill the bounding box (virtual from REveElement).
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
Write the render data entry pos, see the class description.
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)
Set the depth and stamp el for a rebuild.
REveProjectable * GetProjectable() const
REveProjectionManager Manager class for steering of projections and managing projected objects.
const REveTrans * GetModelTrans(REveElement *model, REveTrans &t)
Return the matrix that takes the coordinates of model into the frame of this manager,...
REveProjection Base for specific classes that implement non-linear projections.
void ProjectVector(REveVector &v, Float_t d)
Project REveVector.
Entry & Reserve(size_t n_items)
Reserve storage for n_items items of the item size.
Render data of an element: a client maker name and a list of tagged entries, each a typed array with ...
Entry & NewEntry(std::string_view tag, EType type=EType::kF32, int item_size=1)
Create an entry. The reference stays valid for the life of this object.
void CopyVizParams(const REveElement *el) override
Copy visualization parameters from element el.
Definition REveShape.cxx:82
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
const Int_t n
Definition legend1.C:16
Namespace for ROOT features in testing.
Definition TROOT.h:100
REveVectorT< Float_t > REveVector
TMath.
Definition TMathBase.h:35
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Definition TMathBase.h:249
constexpr Double_t PiOver2()
Definition TMath.h:54
constexpr Double_t Pi()
Definition TMath.h:40
constexpr Double_t TwoPi()
Definition TMath.h:47