-
Notifications
You must be signed in to change notification settings - Fork 3
/
Draw_model.C
102 lines (81 loc) · 3.15 KB
/
Draw_model.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Macro for visualizing, changing color and transparency of volumes using Eve
// Ondrej Lomicky, [email protected]
void RecursiveColor(TGeoVolume *vol, Color_t color)
{
if(!vol) return;
vol->SetLineColor(color);
Int_t nd = vol->GetNdaughters();
for (Int_t i=0; i<nd; i++) {
RecursiveColor(vol->GetNode(i)->GetVolume(),color);
}
}
void RecursiveTransparency(TGeoVolume *vol, double tra){
if(!vol) return;
vol->SetTransparency(tra);
Int_t nd = vol->GetNdaughters();
for (Int_t i=0; i<nd; i++) {
RecursiveTransparency(vol->GetNode(i)->GetVolume(),tra);
}
}
void pfRICHcolor(TGeoVolume *vol){
if(!vol) return;
Int_t nd = vol->GetNdaughters();
for (Int_t i=0; i<nd; i++) {
TGeoVolume *voldaughter = vol->GetNode(i)->GetVolume();
TString volname = voldaughter->GetIconName();
volname.Remove(volname.Index("_shape"));
//Write out all subnodes
//cout << volname << endl;
if (volname.Contains("Mirror")) voldaughter->SetLineColor(kAzure-4);
else if (volname.Contains("QuartzWindow")) voldaughter->SetLineColor(kYellow);
else voldaughter->SetLineColor(kGray+2);
pfRICHcolor(vol->GetNode(i)->GetVolume());
}
}
void Draw_model()
{
TEveManager::Create();
gGeoManager = TGeoManager::Import("geo/detector_geometry.root");
//Default colors
gGeoManager->DefaultColors();
if (gGeoManager == nullptr) return;
//Vector of strings
std::vector<TString> nodes;
//cycle over all nodes
TObjArray* allnodes = gGeoManager->GetTopNode()->GetNodes();
const int nNodes = allnodes->GetEntries();
for(Int_t i=0; i<nNodes;i++) {
TGeoNode *node = (TGeoNode *) allnodes->At(i);
TGeoVolume *vol = node->GetVolume();
TString volname2 = vol->GetIconName();
volname2.Remove(volname2.Index("_shape"));
nodes.push_back(volname2);
//Write out all nodes
//cout << nodes[i] << endl;
}
//RecursiveColor(gGeoManager->GetVolume("PFRICH"), kGreen);
//RecursiveTransparency(gGeoManager->GetVolume("PFRICH"),0);
//Set transparency and colors to all nodes
for (int i = 0; i < nodes.size(); i++)
{
if (nodes[i]=="PFRICH") pfRICHcolor(gGeoManager->GetVolume(nodes[i]));
//if (nodes[i]=="PFRICH") RecursiveColor(gGeoManager->GetVolume(nodes[i]), kMagenta);
//else if (nodes[i]=="EcalEndcapP");
else RecursiveColor(gGeoManager->GetVolume(nodes[i]), 20);
//RecursiveTransparency(gGeoManager->GetVolume(nodes[i]),100);
//if (nodes[i]!="PFRICH") RecursiveColor(gGeoManager->GetVolume(nodes[i]), 20);
}
TEveGeoTopNode *EPIC_Tracker = new TEveGeoTopNode(gGeoManager,gGeoManager->GetTopNode());
EPIC_Tracker->SetVisLevel(100);
gEve->AddGlobalElement(EPIC_Tracker);
gEve->FullRedraw3D(kTRUE);
TGLViewer *viewer = gEve->GetDefaultGLViewer();
viewer->GetClipSet()->SetClipType(TGLClip::EType(1));
viewer->DoDraw();
//Save it to a root file
TFile *f = new TFile("model.root","RECREATE");
f->cd();
gGeoManager->Write();
f->Close();
//////gEve->GetDefaultGLViewer()->SavePicture("test.png");
}