Logo ROOT  
Reference Guide
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
26/** \class REveJetCone
27\ingroup REve
28Draws a jet cone with leading particle is specified in (eta,phi) and
29cone radius is given.
30
31If Apex is not set, default is (0.,0.,0.)
32In case of cylinder was set, cone is cut at the cylinder edges.
33
34Example :
35~~~ {.cpp}
36 Float_t coneEta = r.Uniform(-0.9, 0.9);
37 Float_t conePhi = r.Uniform(0.0, TwoPi() );
38 Float_t coneRadius = 0.4;
39
40 REveJetCone* jetCone = new REveJetCone("JetCone");
41 jetCone->SetCylinder(250, 250);
42 if (jetCone->AddCone(coneEta, conePhi, coneRadius) != -1)
43 gEve->AddElement(jetCone);
44~~~
45
46#### Implementation notes
47
48REveVector fLimits encodes the following information:
49 - fY, fZ: barrel radius and endcap z-position;
50 if both are 0, fX encodes the spherical radius
51 - fX : scaling for length of the cone
52*/
53
54////////////////////////////////////////////////////////////////////////////////
55/// Constructor.
56
57REveJetCone::REveJetCone(const Text_t* n, const Text_t* t) :
58 REveShape(n, t),
59 fApex(),
60 fLimits(), fThetaC(10),
61 fEta(0), fPhi(0), fDEta(0), fDPhi(0), fNDiv(36)
62{
63 fPickable = true;
65}
66
67////////////////////////////////////////////////////////////////////////////////
68/// Set Number of Divisions
69////////////////////////////////////////////////////////////////////////////////
71{
72 fNDiv = TMath::Max(4, n);
73 if (fNDiv % 4 > 0) { fNDiv += 4 - fNDiv % 4; };
75}
76
77////////////////////////////////////////////////////////////////////////////////
78/// Fill core part of JSON representation.
79
80Int_t REveJetCone::WriteCoreJson(nlohmann::json &j, Int_t rnr_offset)
81{
82 Int_t ret = REveElement::WriteCoreJson(j, rnr_offset);
83
84 j["fMainColor"] = GetFillColor();
85 j["fLineColor"] = GetLineColor();
86 j["fNDiv"] = GetNDiv();
87
88 return ret;
89}
90
91////////////////////////////////////////////////////////////////////////////////
92/// Crates 3D point array for rendering.
93
95{
96 assert(fNDiv > 2);
97
98 const Int_t NP = 1 + fNDiv;
99
100 fRenderData = std::make_unique<REveRenderData>("makeJet", 3 * NP);
101
102 fRenderData->PushV(fApex);
103
104 Float_t angle_step = TMath::TwoPi() / fNDiv;
105 Float_t angle = 0;
106 for (Int_t i = 0; i < fNDiv; ++i, angle += angle_step)
107 {
108 fRenderData->PushV( CalcBaseVec(angle) );
109 }
110}
111
112////////////////////////////////////////////////////////////////////////////////
113/// Compute bounding-box of the data.
114
116{
117 BBoxInit();
123}
124
125////////////////////////////////////////////////////////////////////////////////
126/// Virtual from REveProjectable, returns REveJetConeProjected class.
127
129{
130 return TClass::GetClass<REveJetConeProjected>();
131}
132
133////////////////////////////////////////////////////////////////////////////////
134/// Add jet cone.
135/// parameters are :
136/// - (eta,phi) : of the center/leading particle
137/// - cone_r : cone radius in eta-phi space
138/// - length : length of the cone
139/// - if cylinder is set and length is adapted to cylinder.
140/// - if length is given, it will be used as scalar factor
141/// - if cylinder is not set, length is used as length of the cone
142/// Return 0 on success.
143
145{
146 return AddEllipticCone(eta, phi, cone_r, cone_r, length);
147}
148
149////////////////////////////////////////////////////////////////////////////////
150/// Add jet cone.
151/// parameters are :
152/// - (eta,phi) : of the center/leading particle
153/// - (reta, rphi) : radius of cone 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/// Returns 0 on success.
159
161{
162 if (length != 0) fLimits.fX = length;
163
164 if (fLimits.IsZero())
165 return -1;
166
167 fEta = eta; fPhi = phi; fDEta = reta; fDPhi = rphi;
168
169 return 0;
170}
171
172////////////////////////////////////////////////////////////////////////////////
173/// Fill REveVector with eta and phi, magnitude 1.
174
176{
177 using namespace TMath;
178
179 return REveVector(Cos(phi) / CosH(eta), Sin(phi) / CosH(eta), TanH(eta));
180}
181
182////////////////////////////////////////////////////////////////////////////////
183/// Returns point on the base of the cone with given eta and phi.
184
186{
187 using namespace TMath;
188
189 REveVector vec = CalcEtaPhiVec(eta, phi);
190
191 // -- Set length of the contourPoint
192 if (fLimits.fY != 0 && fLimits.fZ != 0)
193 {
194 Float_t theta = vec.Theta();
195 if (theta < fThetaC)
196 vec *= fLimits.fZ / Cos(theta);
197 else if (theta > Pi() - fThetaC)
198 vec *= fLimits.fZ / Cos(theta - Pi());
199 else
200 vec *= fLimits.fY / Sin(theta);
201
202 if (fLimits.fX != 0) vec *= fLimits.fX;
203 }
204 else
205 {
206 vec *= fLimits.fX;
207 }
208
209 return vec;
210}
211
212////////////////////////////////////////////////////////////////////////////////
213/// Returns point on the base of the cone with internal angle alpha:
214/// alpha = 0 -> max eta, alpha = pi/2 -> max phi, ...
215
217{
218 using namespace TMath;
219
220 return CalcBaseVec(fEta + fDEta * Cos(alpha), fPhi + fDPhi * Sin(alpha));
221}
222
223////////////////////////////////////////////////////////////////////////////////
224/// Returns true if the cone is in barrel / endcap transition region.
225
227{
228 using namespace TMath;
229
230 Float_t tm = CalcBaseVec(0).Theta();
231 Float_t tM = CalcBaseVec(Pi()).Theta();
232
233 return (tM > fThetaC && tm < fThetaC) ||
234 (tM > Pi() - fThetaC && tm < Pi() - fThetaC);
235}
236
237
238/** \class REveJetConeProjected
239\ingroup REve
240Projection of REveJetCone.
241*/
242
243////////////////////////////////////////////////////////////////////////////////
244/// Constructor.
245
246REveJetConeProjected::REveJetConeProjected(const std::string& n, const std::string& t) :
247 REveShape(n, t)
248{
249}
250
251////////////////////////////////////////////////////////////////////////////////
252/// Destructor.
253
255{
256}
257
258////////////////////////////////////////////////////////////////////////////////
259/// Crates 3D point array for rendering.
260
262{
263 static const REveException kEH("REveJetConeProjected::BuildRenderData ");
264
266 REveJetCone *C = dynamic_cast<REveJetCone*>(GetProjectable());
267
268 fRenderData = std::make_unique<REveRenderData>("makeJetProjected", 4);
269
270 std::vector<REveVector> V;
271 V.reserve(4);
272 V.resize(3);
273
274 switch (P->GetType())
275 {
277 {
278 V[0] = C->fApex;
279 V[1] = C->CalcBaseVec(TMath::Pi() + TMath::PiOver2());
280 V[2] = C->CalcBaseVec(TMath::PiOver2());
281
282 for (Int_t i = 0; i < 3; ++i)
283 P->ProjectVector(V[i], fDepth);
284
285 break;
286 }
287
289 {
290 V[0] = C->fApex;
291 V[1] = C->CalcBaseVec(0);
292 V[2] = C->CalcBaseVec(TMath::Pi());
293
294 Float_t tm = V[1].Theta();
295 Float_t tM = V[2].Theta();
296
297 if (tM > C->fThetaC && tm < C->fThetaC)
298 {
299 REveVector v(0, C->fLimits.fY, C->fLimits.fZ);
300
301 V.push_back(C->CalcBaseVec(v.Eta(), C->fPhi));
302 }
303
304 if (tM > TMath::Pi() - C->fThetaC && tm < TMath::Pi() - C->fThetaC)
305 {
306 REveVector v(0, C->fLimits.fY, -C->fLimits.fZ);
307
308 V.push_back(C->CalcBaseVec(v.Eta(), C->fPhi));
309 }
310
311 for (auto &v : V) P->ProjectVector(v, fDepth);
312
313 std::sort(V.begin() + 1, V.end(),
314 [](const auto& a, const auto &b) -> bool
315 { return a.Phi() < b.Phi(); });
316
317 break;
318 }
319
320 default:
321 throw kEH + "Unsupported projection type.";
322 }
323
324 for (auto &v : V) fRenderData->PushV(v);
325}
326
327////////////////////////////////////////////////////////////////////////////////
328/// Compute bounding-box, virtual from TAttBBox.
329
331{
332 BBoxInit();
333
334 REveJetCone *cone = dynamic_cast<REveJetCone*>(fProjectable);
337 v = cone->fApex; proj->ProjectVector(v, fDepth); BBoxCheckPoint(v);
338 v = cone->CalcBaseVec(0); proj->ProjectVector(v, fDepth); BBoxCheckPoint(v);
342}
343
344////////////////////////////////////////////////////////////////////////////////
345/// This is virtual method from base-class REveProjected.
346
348{
349 SetDepthCommon(d, this, fBBox);
350}
351
352////////////////////////////////////////////////////////////////////////////////
353/// This is virtual method from base-class REveProjected.
354
356{
358 CopyVizParams(dynamic_cast<REveElement*>(model));
359}
360
361////////////////////////////////////////////////////////////////////////////////
362/// Re-project the jet-cone.
363
365{
366}
#define d(i)
Definition: RSha256.hxx:102
#define b(i)
Definition: RSha256.hxx:100
int Int_t
Definition: RtypesCore.h:45
char Text_t
Definition: RtypesCore.h:62
bool Bool_t
Definition: RtypesCore.h:63
float Float_t
Definition: RtypesCore.h:57
@ 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.
Definition: REveElement.hxx:98
REveException Exception-type thrown by Eve classes.
Definition: REveTypes.hxx:41
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.
Definition: REveJetCone.cxx:70
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.
Definition: REveJetCone.cxx:80
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.
Definition: REveJetCone.cxx:94
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:86
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
Definition: REveVector.hxx:119
static double P[]
static double C[]
double Pi()
Mathematical constants.
Definition: Math.h:88
TMath.
Definition: TMathBase.h:35
Double_t CosH(Double_t)
Definition: TMath.h:655
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:212
constexpr Double_t PiOver2()
Definition: TMath.h:51
Double_t TanH(Double_t)
Definition: TMath.h:659
Double_t Cos(Double_t)
Definition: TMath.h:643
constexpr Double_t Pi()
Definition: TMath.h:37
Double_t Sin(Double_t)
Definition: TMath.h:639
constexpr Double_t TwoPi()
Definition: TMath.h:44
Definition: civetweb.c:2228
auto * a
Definition: textangle.C:12