Logo ROOT  
Reference Guide
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 
21 THttpServer *serv = nullptr;
22 bool drawing = false;
23 int interval = 2000;
24 
25 void create_geo()
26 {
27  if (gGeoManager) {
28  serv->Unregister(gGeoManager);
29  delete gGeoManager;
30  }
31 
32  new TGeoManager("world", "the simplest geometry");
33 
34  if (serv) {
35  serv->Register("/", gGeoManager);
36  // enable monitoring and
37  // specify item to draw when page is opened
38  // serv->SetItemField("/","_layout","grid2x2");
39  serv->SetItemField("/","_monitoring",Form("%d",interval));
40  serv->SetItemField("/","_drawitem","world");
41  serv->SetItemField("/","_drawopt","tracks");
42  }
43 
44  auto rnd = gRandom;
45 
46  TGeoMaterial *mat = new TGeoMaterial("Vacuum",0,0,0);
47  mat->SetTransparency(50);
48  TGeoMedium *med = new TGeoMedium("Vacuum",1,mat);
49 
50  TGeoVolume *top = gGeoManager->MakeBox("Top",med, 10+5*rnd->Rndm(), 10+5*rnd->Rndm(), 10+5*rnd->Rndm());
52  top->SetFillColor(3);
53 
54  TGeoVolume *in = gGeoManager->MakeBox("In",med, 2.,2.,2.);
55  in->SetFillColor(2);
56  TGeoCombiTrans *tr = new TGeoCombiTrans("tr");
57  double x = -8+16*rnd->Rndm();
58  double y = -8+16*rnd->Rndm();
59  double z = -8+16*rnd->Rndm();
60  tr->SetTranslation (x, y, z);
61  tr->RegisterYourself();
62  top->AddNode(in, 1, tr);
63 
65 
66  top->SetLineColor(kMagenta);
67  if (rnd->Rndm() < 0.5)
68  in->SetLineColor(kGreen);
69  else
70  in->SetLineColor(kBlack);
71 
72  for (int j=0; j<50; j++)
73  {
74  Int_t track_index = gGeoManager->AddTrack(2,22);
75  auto track = gGeoManager->GetTrack(track_index);
76  if (rnd->Rndm() < 0.5)
77  track->SetLineColor(kRed);
78  else
79  track->SetLineColor(kBlue);
80  track->SetLineWidth(2);
81 
82  track->AddPoint(x, y, z, 0);
83  track->AddPoint(-10 + 20*rnd->Rndm(), -10 + 20*rnd->Rndm(), -10 + 20*rnd->Rndm(), 0);
84  }
85 
86  if (drawing) {
87  // add "showtop" option to display top volume in JSROOT
88  // gGeoManager->SetTopVisible();
89 
90  top->Draw();
92  gPad->Modified();
93  gPad->Update();
94  }
95 }
96 
97 
98 void httpgeom()
99 {
100  drawing = false; // to enable canvas drawing
101 
102  serv = new THttpServer("http:8090");
103 
104  TTimer *timer = new TTimer("create_geo()", interval);
105  timer->TurnOn();
106 }
TGeoMedium.h
TGeoCombiTrans
Class describing rotation + translation.
Definition: TGeoMatrix.h:292
TGeoManager::MakeBox
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.
Definition: TGeoManager.cxx:2919
THttpServer::SetItemField
Bool_t SetItemField(const char *fullname, const char *name, const char *value)
Definition: THttpServer.cxx:1250
kGreen
@ kGreen
Definition: Rtypes.h:66
gGeoManager
R__EXTERN TGeoManager * gGeoManager
Definition: TGeoManager.h:602
Form
char * Form(const char *fmt,...)
TGeoManager::CloseGeometry
void CloseGeometry(Option_t *option="d")
Closing geometry implies checking the geometry validity, fixing shapes with negative parameters (run-...
Definition: TGeoManager.cxx:1360
TRandom.h
Int_t
int Int_t
Definition: RtypesCore.h:45
TGeoVolume.h
TGeoVolume::AddNode
virtual void AddNode(TGeoVolume *vol, Int_t copy_no, TGeoMatrix *mat=0, Option_t *option="")
Add a TGeoNode to the list of nodes.
Definition: TGeoVolume.cxx:932
TPad.h
x
Double_t x[n]
Definition: legend1.C:17
TAttLine::SetLineColor
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
TTimer.h
TGeoMaterial
Base class describing materials.
Definition: TGeoMaterial.h:36
TGeoManager::DrawTracks
void DrawTracks(Option_t *option="")
Draw tracks over the geometry, according to option.
Definition: TGeoManager.cxx:1736
TGeoMaterial::SetTransparency
void SetTransparency(Char_t transparency=0)
Definition: TGeoMaterial.h:140
kBlack
@ kBlack
Definition: Rtypes.h:65
TGeoManager::SetTopVolume
void SetTopVolume(TGeoVolume *vol)
Set the top volume and corresponding node as starting point of the geometry.
Definition: TGeoManager.cxx:3398
TTimer
Handles synchronous and a-synchronous timer events.
Definition: TTimer.h:51
kMagenta
@ kMagenta
Definition: Rtypes.h:66
THttpServer
Definition: THttpServer.h:31
TGeoCombiTrans::RegisterYourself
virtual void RegisterYourself()
Register the matrix in the current manager, which will become the owner.
Definition: TGeoMatrix.cxx:1877
THttpServer::Register
Bool_t Register(const char *subfolder, TObject *obj)
Register object in subfolder.
Definition: THttpServer.cxx:1046
TGeoVolume::Draw
virtual void Draw(Option_t *option="")
draw top volume according to option
Definition: TGeoVolume.cxx:1146
TGeoMaterial.h
TGeoTrack.h
gRandom
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
TGeoManager::GetTrack
TVirtualGeoTrack * GetTrack(Int_t index)
Definition: TGeoManager.h:398
y
Double_t y[n]
Definition: legend1.C:17
kRed
@ kRed
Definition: Rtypes.h:66
TGeoManager.h
THttpServer.h
TAttFill::SetFillColor
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:37
TGeoManager::AddTrack
Int_t AddTrack(Int_t id, Int_t pdgcode, TObject *particle=0)
Add a track to the list of tracks.
Definition: TGeoManager.cxx:643
kBlue
@ kBlue
Definition: Rtypes.h:66
TGeoCombiTrans::SetTranslation
void SetTranslation(const TGeoTranslation &tr)
copy the translation component
Definition: TGeoMatrix.cxx:2096
gPad
#define gPad
Definition: TVirtualPad.h:287
THttpServer::Unregister
Bool_t Unregister(TObject *obj)
Unregister object.
Definition: THttpServer.cxx:1056
TGeoMedium
Media are used to store properties related to tracking and which are useful only when using geometry ...
Definition: TGeoMedium.h:24
TTimer::TurnOn
virtual void TurnOn()
Add the timer to the system timer list.
Definition: TTimer.cxx:241
TGeoVolume::SetLineColor
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TGeoVolume.cxx:2036
TGeoManager
The manager class for any TGeo geometry.
Definition: TGeoManager.h:45
TGeoVolume
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
Definition: TGeoVolume.h:49