Logo ROOT  
Reference Guide
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/// TGeoOpticalSurface *surf = geom->GetOpticalSurface("surf1");
10/// const char *property = surf=>GetPropertyRef("REFLECTIVITY");
11/// TGeoGDMLMatrix *m = geom->GetGDMLMatrix(property);
12/// Skin surfaces and border surfaces can be retrieved from the TGeoManager object by using:
13/// TObjArray *skin_array = geom->GetListOfSkinSurfaces();
14/// TObjArra8 *border_array = geom->GetListOfBorderSurfaces();
15/// Alternatively accessors by name can also be used: GetSkinSurface(name)/GetBorderSurface(name)
16///
17/// \author Andrei Gheata
18
19#include <cassert>
20#include <TObjArray.h>
21#include <TROOT.h>
22#include <TGeoOpticalSurface.h>
23#include <TGeoManager.h>
24
25double Checksum(TGeoManager *geom)
26{
27 double sum = 0.;
28 TIter next(geom->GetListOfOpticalSurfaces());
30 while ((surf = (TGeoOpticalSurface *)next())) {
31 sum += (double)surf->GetType() + (double)surf->GetModel() + (double)surf->GetFinish() + surf->GetValue();
32 TString name = surf->GetName();
33 sum += (double)name.Hash();
34 name = surf->GetTitle();
35 sum += (double)name.Hash();
36 }
37 return sum;
38}
39
40int testoptical()
41{
42 TString geofile = gROOT->GetTutorialDir() + "/geom/gdml/opticalsurfaces.gdml";
43 geofile.ReplaceAll("\\", "/");
46 printf("=== Importing %s ...\n", geofile.Data());
47 TGeoManager *geom = TGeoManager::Import(geofile);
48 printf("=== List of GDML matrices:\n");
50 printf("=== List of optical surfaces:\n");
52 printf("=== List of skin surfaces:\n");
54 printf("=== List of border surfaces:\n");
56 // Compute some checksum for optical surfaces
57 double checksum1 = Checksum(geom);
58 printf("=== Exporting as .gdml, then importing back\n");
59 geom->Export("tmp.gdml");
60 geom = TGeoManager::Import("tmp.gdml");
61 double checksum2 = Checksum(geom);
62 assert((checksum2 == checksum1) && "Exporting/importing as .gdml not OK");
63 printf("=== Exporting as .root, then importing back\n");
64 geom->Export("tmp.root");
65 geom = TGeoManager::Import("tmp.root");
66 double checksum3 = Checksum(geom);
67 assert((checksum3 == checksum1) && "Exporting/importing as .root not OK");
68 printf("all OK\n");
69 return 0;
70}
double
Definition: Converters.cxx:921
char name[80]
Definition: TGX11.cxx:109
#define gROOT
Definition: TROOT.h:406
virtual void Print(Option_t *option="") const
Default print for collections, calls Print(option, 1).
The manager class for any TGeo geometry.
Definition: TGeoManager.h:43
static void SetExportPrecision(UInt_t prec)
Definition: TGeoManager.h:476
TObjArray * GetListOfSkinSurfaces() const
Definition: TGeoManager.h:499
TObjArray * GetListOfGDMLMatrices() const
Definition: TGeoManager.h:497
virtual Int_t Export(const char *filename, const char *name="", Option_t *option="vg")
Export this geometry to a file.
TObjArray * GetListOfBorderSurfaces() const
Definition: TGeoManager.h:500
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).
TObjArray * GetListOfOpticalSurfaces() const
Definition: TGeoManager.h:498
ESurfaceModel GetModel() const
ESurfaceFinish GetFinish() const
Double_t GetValue() const
ESurfaceType GetType() const
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Basic string class.
Definition: TString.h:131
const char * Data() const
Definition: TString.h:364
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:687
static long int sum(long int i)
Definition: Factory.cxx:2275