Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
geom_overlaps.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_eve_7
3/// Browse the overlaps and extrusions of a geometry, and look at them in 3D.
4///
5/// The overlap check runs once, over the whole geometry, before the browser starts
6/// serving -- TGeoVolume::CheckOverlaps() is recursive, so checking volumes one at a
7/// time as somebody clicks around both repeats the work and costs seconds per click.
8/// After the single pass the table is instant.
9///
10/// Pick a row and the 3D view shows that overlap and nothing else: the two volumes
11/// (red and yellow, semi-transparent) and the points on the offending surface (cyan).
12/// An overlap belongs to a *logical* volume, so if that volume is placed several times
13/// the pair is drawn at every placement.
14///
15/// \macro_code
16///
17/// \author Alja Mrak-Tadel
18
19#include <ROOT/REveElement.hxx>
21#include <ROOT/REveManager.hxx>
22#include <ROOT/REveScene.hxx>
23#include <ROOT/REveViewer.hxx>
24
25#include "TFile.h"
26#include "TGeoManager.h"
27#include "TKey.h"
28
29#include <cstring>
30#include <iostream>
31
32using namespace ROOT::Experimental;
33
35{
37 if (!f || f->IsZombie()) {
38 std::cerr << "cannot open " << fname << "\n";
39 return nullptr;
40 }
41 TIter next(f->GetListOfKeys());
42 while (auto *key = (TKey *)next())
43 if (!std::strcmp(key->GetClassName(), "TGeoManager"))
44 return dynamic_cast<TGeoManager *>(key->ReadObj());
45 std::cerr << "no TGeoManager in " << fname << "\n";
46 return nullptr;
47}
48
49void geom_overlaps(const char *fname = "http://root.cern/files/cms.root", double precision = 0.001)
50{
51 auto *geom = load_geometry(fname);
52 if (!geom)
53 return;
54
55 auto *eveMng = REveManager::Create();
56 eveMng->AllowMultipleRemoteConnections(false, false);
57
58 auto *table = new REveGeoOverlapTable("Overlaps", "Overlaps and extrusions");
59
60 // Before anything is served: the scan mutates TGeoManager global state and runs
61 // its own thread pool, so it must not race the client threads.
62 std::cout << ">>> checking overlaps (precision " << precision << " cm) ...\n";
63 table->ScanOverlaps(geom, precision);
64 std::cout << ">>> found " << table->GetNumOverlaps() << " overlaps\n";
65
66 // the list lives in its own scene, bound to a viewer named GeoOverlapTable --
67 // that name is what picks the client-side view
68 auto *tableScene = eveMng->SpawnNewScene("Overlap List");
69 tableScene->AddElement(table);
70 auto *tableViewer = eveMng->SpawnNewViewer("GeoOverlapTable", "");
71 tableViewer->AddScene(tableScene);
72
73 // the shapes of whichever row is selected go into the event scene
74 eveMng->GetEventScene()->AddElement(table->GetVizHolder());
75
76 eveMng->Show();
77}
#define f(i)
Definition RSha256.hxx:104
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
The overlaps and extrusions of a geometry, as a flat list plus a 3D view.
A file, usually with extension .root, that stores data and code in the form of serialized objects in ...
Definition TFile.h:130
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
Definition TFile.cxx:3802
The manager class for any TGeo geometry.
Definition TGeoManager.h:46
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition TKey.h:28
Namespace for ROOT features in testing.
Definition TROOT.h:100