SToGS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
BrowserFactory.C
Go to the documentation of this file.
1 
2 
3 #include "TGeoManager.h"
4 #include "TGeoVolume.h"
5 #include "TGeoNode.h"
6 
8 void CollectVolumes(TGeoNode *theDetector, TObjArray &logical_stored, TObjArray &phycical_stored)
9 {
10 
11  TGeoVolume *alogical = theDetector->GetVolume(); TGeoNode *aphysical = 0x0; Bool_t in_the_list;
12 
13  in_the_list = false;
14  for (size_t i = 0; i < phycical_stored.GetEntries() ; i++) {
15  if ( aphysical == phycical_stored[i] ) {
16  in_the_list = true;
17  break;
18  }
19  }
20  if ( !in_the_list ) {
21  phycical_stored.Add(theDetector);
22  }
23  in_the_list = false;
24  for (size_t i = 0; i < logical_stored.GetEntries() ; i++) {
25  if ( alogical == logical_stored[i] ) {
26  in_the_list = true;
27  break;
28  }
29  }
30  if ( !in_the_list ) {
31  logical_stored.Add(alogical);
32  }
33 
34  // recursive call
35  for (size_t i = 0; i < alogical->GetNdaughters(); i++) {
36  aphysical = alogical->GetNode(i);
37  CollectVolumes(aphysical,logical_stored, phycical_stored);
38  }
39 }
40 
42 TGeoVolume *ShowDetector(const char *basename = "DetectorFactory/Scintillators/CParisPW_2", Option_t *opt_draw = "ogl")
43 {
44  TString detname, fullname; TObjArray logical_stored; TObjArray phycical_stored;
45 
46  fullname = basename;
47  fullname += ".gdml";
48  cout << fullname << endl;
49 
50  TGeoManager::Import(fullname.Data()); world = gGeoManager->GetTopVolume();
51  //
52  if ( world == 0x0 ) {
53  std::cout << "\n ***** The detector " << basename << " has not been found in the factory ! ***** " << std::endl;
54  return 0x0;
55  }
56 
57  // collect logical and physical (nodes) volumes
58  CollectVolumes(gGeoManager->GetTopNode(),logical_stored,phycical_stored);
59 
60  fullname = basename; fullname += ".amap"; std::ifstream amap(fullname.Data());
61  if ( amap.is_open() ) {
62 
63  std::string touchable, aline;
64 
65  // logicals
66  getline(amap,aline);
67  while ( amap.good() ) {
68 
69  istringstream decode(aline); TString vname, key_sd, sd, key_color; Float_t r,g,b,a;
70 
71  decode >> vname
72  >> key_color
73  >> r
74  >> g
75  >> b
76  >> a
77  >> key_sd
78  >> sd
79  ;
80 
81  for (size_t i = 0; i < logical_stored.GetEntries(); i++) {
82  TString tmp = logical_stored[i]->GetName();
83  if ( tmp == vname ) {
84  cout << " **** Set Attributes to: " << tmp << " using " << aline << endl;
85 
86  TGeoVolume *alogical = (TGeoVolume *)logical_stored[i];
87 
88  alogical->SetFillColor( TColor::GetColor(r,g,b) );
89  alogical->SetLineColor( TColor::GetColor(r,g,b) );
90  alogical->SetTransparency(100*(1-a));
91  }
92  }
93 
94  getline(amap,aline);
95  }
96  }
97 
98  if ( opt_draw != "-" ) {
99  world->Draw(opt_draw);
100  }
101  gGeoManager->SetVisOption(0);
102 
103  return world;
104 }
105 
107 void ShowInEve(const char *basename = "DetectorFactory/Scintillators/CParisPW_2")
108 {
109  TEveManager::Create();
110 
111  TGeoVolume *world = ShowDetector(basename,"-");
112  TEveGeoTopNode* inn = new TEveGeoTopNode(gGeoManager, gGeoManager->GetTopNode());
113  gEve->AddGlobalElement(inn);
114 
115  gEve->FullRedraw3D(kTRUE);
116 
117  // EClipType not exported to CINT (see TGLUtil.h):
118  // 0 - no clip, 1 - clip plane, 2 - clip box
119  TGLViewer *v = gEve->GetDefaultGLViewer();
120  v->GetClipSet()->SetClipType(1);
121  v->RefreshPadEditor(v);
122 
123  v->CurrentCamera().RotateRad(-.7, 0.5);
124  v->DoDraw();
125 }
126 
128 void RenameSToGSDetector(const char *from, const char *to)
129 {
130  TString t1,t2;
131 
132  t1 = from;
133  t1 += ".gdml";
134  t2 = to;
135  t2 += ".gdml";
136  gSystem->Rename(t1.Data(),t2.Data());
137  t1 = from;
138  t1 += ".amap";
139  t2 = to;
140  t2 += ".amap";
141  gSystem->Rename(t1.Data(),t2.Data());
142  t1 = from;
143  t1 += ".dmap";
144  t2 = to;
145  t2 += ".dmap";
146  gSystem->Rename(t1.Data(),t2.Data());
147 }
148 
149 
150 
151 /*
153 TGeoVolume *GetDetector(const char *basename = "DetectorFactory/Scintillators/CParisPW_2")
154 {
155  TString detname, fullname; TObjArray logical_stored; TObjArray phycical_stored;
156 
157  fullname = basename;
158  fullname += ".gdml";
159  cout << fullname << endl;
160 
161  if ( gGeoManager == 0x0 ) {
162  new TGeoManager("GDMLImport", "Geometry imported from GDML");
163  gGeoManager->SetVisOption(0);
164  }
165 
166  TString cmd = TString::Format("TGDMLParse::StartGDML(\"%s\")", fullname.Data());
167  TGeoVolume* world = (TGeoVolume*)gROOT->ProcessLineFast(cmd);
168  if ( world == 0x0 ) {
169  return 0x0;
170  }
171 
172  // collect logical and physical (nodes) volumes
173  CollectVolumes(world->GetNode(0),logical_stored,phycical_stored);
174 
175  fullname = basename; fullname += ".amap"; std::ifstream amap(fullname.Data());
176  if ( amap.is_open() ) {
177 
178  std::string touchable, aline;
179 
180  // logicals
181  getline(amap,aline);
182  while ( amap.good() ) {
183 
184  istringstream decode(aline); TString vname, key_sd, sd, key_color; Float_t r,g,b,a;
185 
186  decode >> vname
187  >> key_color
188  >> r
189  >> g
190  >> b
191  >> a
192  >> key_sd
193  >> sd
194  ;
195 
196  for (size_t i = 0; i < logical_stored.GetEntries(); i++) {
197  TString tmp = logical_stored[i]->GetName();
198  if ( tmp == vname ) {
199  cout << " **** Set Attributes to: " << tmp << " using " << aline << endl;
200 
201  TGeoVolume *alogical = (TGeoVolume *)logical_stored[i];
202 
203  alogical->SetFillColor( TColor::GetColor(r,g,b) );
204  alogical->SetLineColor( TColor::GetColor(r,g,b) );
205  alogical->SetTransparency(100*(1-a));
206  }
207  }
208 
209  getline(amap,aline);
210  }
211  }
212 
213  return world;
214 }
215 
216 void ShowInEveT()
217 {
218  TEveManager::Create();
219 
220  TGeoVolume *det1 = GetDetector("DetectorFactory/SemiConductors/Ge/ATC");
221  TEveGeoTopNode* inn1 = new TEveGeoTopNode(gGeoManager, det1->GetNode(0));
222  gEve->AddGlobalElement(inn1);
223 
224  TGeoVolume *det2 = GetDetector("DetectorFactory/SemiConductors/Ge/EXOCLOVER_A-AC");
225  TEveGeoTopNode* inn2 = new TEveGeoTopNode(gGeoManager, det2->GetNode(0));
226  gEve->AddGlobalElement(inn2);
227 
228  gEve->FullRedraw3D(kTRUE);
229 
230  // EClipType not exported to CINT (see TGLUtil.h):
231  // 0 - no clip, 1 - clip plane, 2 - clip box
232  TGLViewer *v = gEve->GetDefaultGLViewer();
233  v->GetClipSet()->SetClipType(1);
234  v->RefreshPadEditor(v);
235 
236  v->CurrentCamera().RotateRad(-.7, 0.5);
237  v->DoDraw();
238 }
239 */
240 
241 /*
242 void ExportToROOT(const Char_t *rfilename = "DetectorFactory.root")
243 {
244  // first canvas to draw
245  TFile *f = new TFile(rfilename,"RECREATE");
246  f->cd();
247 
248  // loop and draw
249  TString d_name = allDetectors[0], tmp; Int_t i = 1;
250  do {
251 
252  tmp = d_name;
253  tmp += ".gdml";
254 
255  if ( gSystem->AccessPathName(tmp.Data()) ) { // does not exist
256  d_name = allDetectors[i++];
257  cout << " **** This file does not exist " << d_name << endl;
258  continue;
259  }
260 
261  TGeoVolume *det = LoadOneDetector(d_name.Data());
262  if ( det ) {
263  det->Write();
264  }
265 
266  // next in factory
267  d_name = allDetectors[i++];
268 
269  delete gGeoManager;
270 
271  } while ( d_name != "end" );
272 
273 }
274 
275  */
276 
277 
278 
void CollectVolumes(TGeoNode *theDetector, TObjArray &logical_stored, TObjArray &phycical_stored)
From the Full geometry, extract the logical and physical [nodes] volumes.
Definition: BrowserFactory.C:8
TGeoVolume * ShowDetector(const char *basename="DetectorFactory/Scintillators/CParisPW_2", Option_t *opt_draw="ogl")
Read the detector in the factory and show it in open GL window.
void ShowInEve(const char *basename="DetectorFactory/Scintillators/CParisPW_2")
Read the detector in the factory and show it in Eve.
void RenameSToGSDetector(const char *from, const char *to)
rename the three files