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
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
269 {
270 fRenderData = std::make_unique<REveRenderData>("makeJetProjected", 4);
271
272 std::vector<REveVector> V;
273 V.reserve(4);
274 V.resize(3);
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 else // RhoZ
286 {
287 V[0] = C->fApex;
288 V[1] = C->CalcBaseVec(0);
289 V[2] = C->CalcBaseVec(TMath::Pi());
290
291 Float_t tm = V[1].Theta();
292 Float_t tM = V[2].Theta();
293
294 if (tM > C->fThetaC && tm < C->fThetaC) {
295 REveVector v(0, C->fLimits.fY, C->fLimits.fZ);
296
297 V.push_back(C->CalcBaseVec(v.Eta(), C->fPhi));
298 }
299
300 if (tM > TMath::Pi() - C->fThetaC && tm < TMath::Pi() - C->fThetaC) {
301 REveVector v(0, C->fLimits.fY, -C->fLimits.fZ);
302
303 V.push_back(C->CalcBaseVec(v.Eta(), C->fPhi));
304 }
305
306 for (auto &v : V)
308
309 std::sort(V.begin() + 1, V.end(), [](const auto &a, const auto &b) -> bool { return a.Phi() < b.Phi(); });
310 }
311
312 for (auto &v : V)
313 fRenderData->PushV(v);
314 }
315 else
316 {
317 const Int_t NP = 1 + C->fNDiv;
318
319 fRenderData = std::make_unique<REveRenderData>("makeJet", 3 * NP);
320
321 fRenderData->PushV(C->fApex);
322
323 Float_t angle_step = TMath::TwoPi() / C->fNDiv;
324 Float_t angle = 0;
325 for (Int_t i = 0; i < C->fNDiv; ++i, angle += angle_step) {
326 auto tv = C->CalcBaseVec(angle);
327 P->ProjectVector(tv, fDepth);
328 fRenderData->PushV(tv);
329 }
330 }
331}
332
333////////////////////////////////////////////////////////////////////////////////
334/// Compute bounding-box, virtual from TAttBBox.
335
337{
338 BBoxInit();
339
340 REveJetCone *cone = dynamic_cast<REveJetCone*>(fProjectable);
343 v = cone->fApex; proj->ProjectVector(v, fDepth); BBoxCheckPoint(v);
344 v = cone->CalcBaseVec(0); proj->ProjectVector(v, fDepth); BBoxCheckPoint(v);
348}
349
350////////////////////////////////////////////////////////////////////////////////
351/// This is virtual method from base-class REveProjected.
352
354{
355 SetDepthCommon(d, this, fBBox);
356}
357
358////////////////////////////////////////////////////////////////////////////////
359/// This is virtual method from base-class REveProjected.
360
362{
364 CopyVizParams(dynamic_cast<REveElement*>(model));
365}
366
367////////////////////////////////////////////////////////////////////////////////
368/// Re-project the jet-cone.
369
371{
372}
#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
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.
std::unique_ptr< REveRenderData > fRenderData
Externally assigned and controlled user data.
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.
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: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:69
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:81
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)
Returns the largest of a and b.
Definition TMathBase.h:250
constexpr Double_t PiOver2()
Definition TMath.h:51
constexpr Double_t Pi()
Definition TMath.h:37
constexpr Double_t TwoPi()
Definition TMath.h:44