Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
25 double Checksum(TGeoManager *geom)
26 {
27  double sum = 0.;
28  TIter next(geom->GetListOfOpticalSurfaces());
29  TGeoOpticalSurface *surf;
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 
40 int testoptical()
41 {
42  TString geofile = gROOT->GetTutorialDir() + "/geom/gdml/opticalsurfaces.gdml";
43  geofile.ReplaceAll("\\", "/");
44  TGeoManager::SetExportPrecision(8);
45  TGeoManager::SetVerboseLevel(0);
46  printf("=== Importing %s ...\n", geofile.Data());
47  TGeoManager *geom = TGeoManager::Import(geofile);
48  printf("=== List of GDML matrices:\n");
49  geom->GetListOfGDMLMatrices()->Print();
50  printf("=== List of optical surfaces:\n");
51  geom->GetListOfOpticalSurfaces()->Print();
52  printf("=== List of skin surfaces:\n");
53  geom->GetListOfSkinSurfaces()->Print();
54  printf("=== List of border surfaces:\n");
55  geom->GetListOfBorderSurfaces()->Print();
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 }