Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
testoptical.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_geom
3/// Tests importing/exporting optical surfaces from GDML
4///
5/// Optical surfaces, skin surfaces and border surfaces are imported in object arrays
6/// stored by TGeoManager class. Optical surfaces do not store property arrays but point
7/// to GDML matrices describing such properties. One can get the data for such property
8/// like:
9///
10/// ~~~{.cpp}
11/// TGeoOpticalSurface *surf = geom->GetOpticalSurface("surf1");
12/// const char *property = surf=>GetPropertyRef("REFLECTIVITY");
13/// TGeoGDMLMatrix *m = geom->GetGDMLMatrix(property);
14/// ~~~
15///
16/// Skin surfaces and border surfaces can be retrieved from the TGeoManager object by using:
17///
18/// ~~~{.cpp}
19/// TObjArray *skin_array = geom->GetListOfSkinSurfaces();
20/// TObjArra8 *border_array = geom->GetListOfBorderSurfaces();
21/// ~~~
22///
23/// Alternatively accessors by name can also be used: GetSkinSurface(name)/GetBorderSurface(name)
24///
25/// \macro_code
26///
27/// \author Andrei Gheata
28
29#include <cassert>
30#include <TObjArray.h>
31#include <TROOT.h>
32#include <TGeoOpticalSurface.h>
33#include <TGeoManager.h>
34
35double Checksum(TGeoManager *geom)
36{
37 double sum = 0.;
38 TIter next(geom->GetListOfOpticalSurfaces());
40 while ((surf = (TGeoOpticalSurface *)next())) {
41 sum += (double)surf->GetType() + (double)surf->GetModel() + (double)surf->GetFinish() + surf->GetValue();
42 TString name = surf->GetName();
43 sum += (double)name.Hash();
44 name = surf->GetTitle();
45 sum += (double)name.Hash();
46 }
47 return sum;
48}
49
50int testoptical()
51{
52 TString geofile = gROOT->GetTutorialDir() + "/visualisation/geom/gdml/opticalsurfaces.gdml";
53 geofile.ReplaceAll("\\", "/");
56 printf("=== Importing %s ...\n", geofile.Data());
58 printf("=== List of GDML matrices:\n");
59 geom->GetListOfGDMLMatrices()->Print();
60 printf("=== List of optical surfaces:\n");
61 geom->GetListOfOpticalSurfaces()->Print();
62 printf("=== List of skin surfaces:\n");
63 geom->GetListOfSkinSurfaces()->Print();
64 printf("=== List of border surfaces:\n");
65 geom->GetListOfBorderSurfaces()->Print();
66 // Compute some checksum for optical surfaces
67 double checksum1 = Checksum(geom);
68 printf("=== Exporting as .gdml, then importing back\n");
69 geom->Export("tmp.gdml");
70 geom = TGeoManager::Import("tmp.gdml");
71 double checksum2 = Checksum(geom);
72 assert((checksum2 == checksum1) && "Exporting/importing as .gdml not OK");
73 printf("=== Exporting as .root, then importing back\n");
74 geom->Export("tmp.root");
75 geom = TGeoManager::Import("tmp.root");
76 double checksum3 = Checksum(geom);
77 assert((checksum3 == checksum1) && "Exporting/importing as .root not OK");
78 printf("all OK\n");
79 return 0;
80}
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
char name[80]
Definition TGX11.cxx:148
#define gROOT
Definition TROOT.h:417
The manager class for any TGeo geometry.
Definition TGeoManager.h:46
static void SetExportPrecision(UInt_t prec)
static TGeoManager * Import(const char *filename, const char *name="", Option_t *option="")
static function Import a geometry from a gdml or ROOT file
static void SetVerboseLevel(Int_t vl)
Return current verbosity level (static function).
This is a wrapper class to G4OpticalSurface.
Basic string class.
Definition TString.h:138
static uint64_t sum(uint64_t i)
Definition Factory.cxx:2335