Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
httpgeom.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_http
3/// This program creates trivial geometry with several tracks and
4/// configure online monitoring of geometry via THttpServer
5/// Geometry regularly changed by the program and correspondent changes immediately seen in the browser
6///
7/// \macro_code
8///
9/// \author Sergey Linev
10
11#include "THttpServer.h"
12#include "TGeoManager.h"
13#include "TGeoMaterial.h"
14#include "TGeoMedium.h"
15#include "TGeoVolume.h"
16#include "TGeoTrack.h"
17#include "TRandom.h"
18#include "TTimer.h"
19#include "TPad.h"
20
21THttpServer *serv = nullptr;
22bool draw_geometry = false;
23bool set_time_interval = false;
24int interval = 2000;
25
26void create_geo()
27{
28 if (gGeoManager) {
30 delete gGeoManager;
31 }
32
33 new TGeoManager("world", "the simplest geometry");
34
35 if (serv) {
36 serv->Register("/", gGeoManager);
37 // enable monitoring and
38 // specify item to draw when page is opened
39 // serv->SetItemField("/","_layout","grid2x2");
40 serv->SetItemField("/","_monitoring",Form("%d",interval));
41 serv->SetItemField("/","_drawitem","world");
42 serv->SetItemField("/","_drawopt","tracks");
43 }
44
45 auto rnd = gRandom;
46
47 TGeoMaterial *mat = new TGeoMaterial("Vacuum",0,0,0);
48 mat->SetTransparency(50);
49 TGeoMedium *med = new TGeoMedium("Vacuum",1,mat);
50
51 TGeoVolume *top = gGeoManager->MakeBox("Top",med, 10+5*rnd->Rndm(), 10+5*rnd->Rndm(), 10+5*rnd->Rndm());
53 top->SetFillColor(3);
54
55 TGeoVolume *in = gGeoManager->MakeBox("In",med, 2.,2.,2.);
56 in->SetFillColor(2);
57 TGeoCombiTrans *tr = new TGeoCombiTrans("tr");
58 double x = -8+16*rnd->Rndm();
59 double y = -8+16*rnd->Rndm();
60 double z = -8+16*rnd->Rndm();
61 tr->SetTranslation (x, y, z);
62 tr->RegisterYourself();
63 top->AddNode(in, 1, tr);
64
66
67 if (set_time_interval)
68 gGeoManager->SetTminTmax(10, 30); // draw only part of tracks
69
71 if (rnd->Rndm() < 0.5)
73 else
75
76 for (int j = 0; j < 50; j++) {
77 Int_t track_index = gGeoManager->AddTrack(2,22);
78 auto track = gGeoManager->GetTrack(track_index);
79 if (rnd->Rndm() < 0.5)
80 track->SetLineColor(kRed);
81 else
82 track->SetLineColor(kBlue);
83 track->SetLineWidth(2);
84
85 track->AddPoint(x, y, z, 0);
86 double x1 = -10 + 20*rnd->Rndm();
87 double y1 = -10 + 20*rnd->Rndm();
88 double z1 = -10 + 20*rnd->Rndm();
89 if (set_time_interval) {
90 for (int np = 1; np < 40; np++)
91 track->AddPoint(x + (x1-x)/40.*np, y + (y1-y)/40.*np, z + (z1-z)/40*np, np);
92
93 // make endmarker visible
94 track->SetMarkerColor(kGreen);
95 track->SetMarkerSize(1);
96 track->SetMarkerStyle(8);
97 } else {
98 track->AddPoint(x1, y1, z1, 0);
99 }
100 }
101
102 if (draw_geometry) {
103 // add "showtop" option to display top volume in JSROOT
104 // gGeoManager->SetTopVisible();
105
106 top->Draw();
108 gPad->Modified();
109 gPad->Update();
110 }
111}
112
113
114void httpgeom(bool draw = false, bool tm = false)
115{
116 draw_geometry = draw;
117 set_time_interval = tm;
118
119 serv = new THttpServer("http:8090");
120
121 TTimer *timer = new TTimer("create_geo()", interval);
122 timer->TurnOn();
123}
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:60
@ kRed
Definition Rtypes.h:66
@ kBlack
Definition Rtypes.h:65
@ kGreen
Definition Rtypes.h:66
@ kMagenta
Definition Rtypes.h:66
@ kBlue
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 np
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t TPoint TPoint const char y1
R__EXTERN TGeoManager * gGeoManager
R__EXTERN TRandom * gRandom
Definition TRandom.h:73
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2571
#define gPad
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:40
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:44
Class describing rotation + translation.
Definition TGeoMatrix.h:318
void RegisterYourself() override
Register the matrix in the current manager, which will become the owner.
void SetTranslation(const TGeoTranslation &tr)
copy the translation component
The manager class for any TGeo geometry.
Definition TGeoManager.h:46
Int_t AddTrack(Int_t id, Int_t pdgcode, TObject *particle=nullptr)
Add a track to the list of tracks.
TVirtualGeoTrack * GetTrack(Int_t index)
void CloseGeometry(Option_t *option="d")
Closing geometry implies checking the geometry validity, fixing shapes with negative parameters (run-...
TGeoVolume * MakeBox(const char *name, TGeoMedium *medium, Double_t dx, Double_t dy, Double_t dz)
Make in one step a volume pointing to a box shape with given medium.
void SetTopVolume(TGeoVolume *vol)
Set the top volume and corresponding node as starting point of the geometry.
void SetTminTmax(Double_t tmin=0, Double_t tmax=999)
Set time cut interval for drawing tracks.
void DrawTracks(Option_t *option="")
Draw tracks over the geometry, according to option.
Base class describing materials.
void SetTransparency(Char_t transparency=0)
Media are used to store properties related to tracking and which are useful only when using geometry ...
Definition TGeoMedium.h:23
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
Definition TGeoVolume.h:45
virtual TGeoNode * AddNode(TGeoVolume *vol, Int_t copy_no, TGeoMatrix *mat=nullptr, Option_t *option="")
Add a TGeoNode to the list of nodes.
void Draw(Option_t *option="") override
draw top volume according to option
void SetLineColor(Color_t lcolor) override
Set the line color.
Online http server for arbitrary ROOT application.
Definition THttpServer.h:31
Bool_t Register(const char *subfolder, TObject *obj)
Register object in subfolder.
Bool_t Unregister(TObject *obj)
Unregister object.
Bool_t SetItemField(const char *fullname, const char *name, const char *value)
Set item field in sniffer.
Handles synchronous and a-synchronous timer events.
Definition TTimer.h:51
virtual void TurnOn()
Add the timer to the system timer list.
Definition TTimer.cxx:246
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17