BOSS 7.0.1
BESIII Offline Software System
Loading...
Searching...
No Matches
DetectorDescription/ROOTGeo/ROOTGeo-00-00-15/src/TofROOTGeo.cxx
Go to the documentation of this file.
1//$id$
2/*
3 * 2004/11/29 Zhengyun You Peking University
4 * Tof Geometry General for EventDisplay
5 *
6 * 2004/12/9 Zhengyun You Peking University
7 * named from TofGeo to TofROOTGeo
8 * inherit from class SubDetectorROOTGeo
9 */
10
11using namespace std;
12
13#include <string>
14#include <fstream>
15#include <iostream>
16#include <sstream>
17#include <vector>
18#include <iomanip>
19
20#include <TGeoManager.h>
21
22#include "ROOTGeo/TofROOTGeo.h"
23
25{
26 // Default constructor.
27 for (int part = 0; part < m_kPart; part++) {
28 for (int scin = 0; scin < m_kAssemblyBr; scin++) {
29 m_NodeScin[part][scin] = 0;
30 m_PhysicalScin[part][scin] = 0;
31 }
32 }
33}
34
36{ }
37
38void
39TofROOTGeo::InitFromGdml( const char *gdmlFile, const char *setupName )
40{
41 ReadGdml(gdmlFile, setupName);
42 SetNode();
44
45 m_ROOTGeoInit = 1;
46}
47
48void
50{
51 m_Tof = GetTopVolume();
52 if(!m_Tof) std::cout << "m_Tof = 0" << std::endl;
53
54 for (int part = 0; part < m_kPart; part++) {
55 int nScin = 0;
56 if (part == 1) nScin = m_kAssemblyBr;
57 else nScin = m_kAssemblyEc;
58 for (int scin = 0; scin < nScin; scin++) {
59 std::stringstream osname;
60 if (part == 0) {
61 osname << "pv_" << "logical" << "Tof" << "ScinEc" << "_" << m_kAssemblyBr + m_kAssemblyEc + scin << "_0";
62 }
63 else if (part == 1) {
64 osname << "pv_" << "logical" << "Tof" << "ScinBr" << "_" << scin << "_0";
65 }
66 else if (part == 2) {
67 osname << "pv_" << "logical" << "Tof" << "ScinEc" << "_" << m_kAssemblyBr + scin << "_0";
68 }
69
70 m_NodeScin[part][scin] = GetNode( osname.str() );
71 }
72 }
73}
74
75void
77{
78 //std::cout << "begin of set defaultvis" << std::endl;
79 int tofColor = 2;
80 int scinColor = 6;
81 int bucketColor = 4;
82
83 m_Tof->SetLineColor(tofColor);
84 m_Tof->SetVisibility(0);
85
86 for (int part = 0; part < m_kPart; part++) {
87 GetVolumeScin(part)->SetLineColor(scinColor);
88 GetVolumeScin(part)->SetVisibility(1);
89 GetVolumeBucket(part)->SetLineColor(bucketColor);
90 GetVolumeBucket(part)->SetVisibility(0);
91
92 int nScin = 0;
93 if (part == 1) nScin = m_kAssemblyBr;
94 else nScin = m_kAssemblyEc;
95 for (int scin = 0; scin < nScin; scin++) {
96 GetScin(part, scin)->SetVisibility(0);
97
98 int nBucket = 0;
99 if (part == 1) nBucket = m_kBucketBr;
100 else nBucket = m_kBucketEc;
101 for (int bucket = 0; bucket < nBucket; bucket++) {
102 GetBucket(part, scin, bucket)->SetVisibility(0);
103 }
104 }
105 }
106 //std::cout << "end of set defaultvis" << std::endl;
107}
108
109void
111{
112 for (int part = 0; part < m_kPart; part++) {
113 GetVolumeScin(part)->SetVisibility(1);
114 GetVolumeBucket(part)->SetVisibility(1);
115
116 int nScin = 0;
117 if (part == 1) nScin = m_kAssemblyBr;
118 else nScin = m_kAssemblyEc;
119 for (int scin = 0; scin < nScin; scin++) {
120 GetScin(part, scin)->SetVisibility(1);
121
122 int nBucket = 0;
123 if (part == 1) nBucket = m_kBucketBr;
124 else nBucket = m_kBucketEc;
125 for (int bucket = 0; bucket < nBucket; bucket++) {
126 GetBucket(part, scin, bucket)->SetVisibility(1);
127 }
128 }
129 }
130}
131
132void
134{
135 for (int part = 0; part < m_kPart; part++) {
136 GetVolumeScin(part)->SetVisibility(1);
137 GetVolumeBucket(part)->SetVisibility(1);
138
139 int nScin = 0;
140 if (part == 1) nScin = m_kAssemblyBr;
141 else nScin = m_kAssemblyEc;
142 for (int scin = 0; scin < nScin; scin++) {
143 if (scin < nScin/4) GetScin(part, scin)->SetVisibility(0);
144 else GetScin(part, scin)->SetVisibility(1);
145
146 int nBucket = 0;
147 if (part == 1) nBucket = m_kBucketBr;
148 else nBucket = m_kBucketEc;
149 for (int bucket = 0; bucket < nBucket; bucket++) {
150 if (scin < nScin/4) GetBucket(part, scin, bucket)->SetVisibility(0);
151 else GetBucket(part, scin, bucket)->SetVisibility(1);
152 }
153 }
154 }
155}
156
157void
159{
160 int scinColor = 6;
161
162 if (gGeoManager == 0) std::cout << "Create gGeoManager first" << std::endl;
163 TGeoNode *bes = gGeoManager->GetTopNode();
164 //std::cout << "m_childNo " << m_childNo << std::endl;
165 TGeoNode *tof = bes->GetDaughter(m_childNo);
166
167 for (int part = 0; part < m_kPart; part++) {
168 int nScin = 0;
169 if (part == 1) nScin = m_kAssemblyBr;
170 else nScin = m_kAssemblyEc;
171 for (int scin = 0; scin < nScin; scin++) {
172 TGeoNode *nodeScin = GetScin(part, scin);
173 m_PhysicalScin[part][scin] = gGeoManager->MakePhysicalNode( TString("/") + bes->GetName() +
174 TString("/") + tof->GetName() +
175 TString("/") + nodeScin->GetName() );
176 m_PhysicalScin[part][scin]->SetVisibility(0);
177 m_PhysicalScin[part][scin]->SetIsVolAtt(kFALSE);
178 m_PhysicalScin[part][scin]->SetLineColor(scinColor);
179 }
180 }
181}
182
183int
185{
186 int nPart = m_kPart;
187 return nPart;
188}
189
190int
192{
193 int nScin = m_kAssemblyBr;
194 if (part != 1) nScin = m_kAssemblyEc;
195 return nScin;
196}
197
198TGeoVolumeAssembly*
200{
201 std::stringstream osname;
202 if (part == 0 || part == 2) {
203 osname << "logical" << "Tof" << "AssemblyEc";
204 }
205 else {
206 if (part == 1) {
207 osname << "logical" << "Tof" << "AssemblyBr";
208 }
209 }
210
211 return GetAssemblyVolume( osname.str() );
212}
213
214TGeoVolume*
216{
217 std::stringstream osname;
218 if (part == 0 || part == 2) {
219 osname << "logical" << "Tof" << "ScinEc";
220 }
221 else {
222 if (part == 1) {
223 osname << "logical" << "Tof" << "ScinBr";
224 }
225 }
226
227 return GetLogicalVolume( osname.str() );
228}
229
230TGeoVolume*
232{
233 std::stringstream osname;
234 if (part == 0 || part == 2) {
235 osname << "logical" << "Tof" << "BucketEc";
236 }
237 else {
238 if (part == 1) {
239 osname << "logical" << "Tof" << "BucketBr";
240 }
241 }
242
243 return GetLogicalVolume( osname.str() );
244}
245
246TGeoNode*
247TofROOTGeo::GetScin( int part, int scin )
248{
249 if (m_NodeScin[part][scin] != 0) {
250 return m_NodeScin[part][scin];
251 }
252 else {
253 std::cout << "Node: " << "Part" << part << "Scin" << scin << " not found" << std::endl;
254 return 0;
255 }
256
257 return m_NodeScin[part][scin];
258}
259
260TGeoNode *
261TofROOTGeo::GetBucket( int part, int scin, int bucket )
262{
263 std::stringstream osname;
264 if (part == 0) {
265 osname << "pv_" << "logical" << "Tof" << "BucketEc" << "_" << m_kAssemblyBr + m_kAssemblyEc + scin << "_1";
266 }
267 else if (part == 1) {
268 osname << "pv_" << "logical" << "Tof" << "BucketBr" << "_" << scin << "_" << bucket+1;
269 }
270 else if (part == 2) {
271 osname << "pv_" << "logical" << "Tof" << "BucketEc" << "_" << m_kAssemblyBr + scin << "_1";
272 }
273
274 return GetNode( osname.str() );
275}
276
277TGeoPhysicalNode*
278TofROOTGeo::GetPhysicalScin( int part, int scin )
279{
280 if (m_PhysicalScin[part][scin] != 0) {
281 return m_PhysicalScin[part][scin];
282 }
283 else {
284 std::cout << "PhysicalNode: " << "Part" << part << "Scin" << scin << " not found" << std::endl;
285 return 0;
286 }
287}
288
TGeoNode * GetNode(const std::string &nn)
Get a node(physical volume) by name;.
TGeoVolume * GetLogicalVolume(const std::string &vn)
Get a logical volume by name;.
void ReadGdml(const char *gdmlFile, const char *setupName)
Initialize the instance of ROOTGeo.
TGeoVolumeAssembly * GetAssemblyVolume(const std::string &an)
Get an assembly by name;.
TGeoVolume * GetVolumeScin(int part)
Get scintillator volume;.
void InitFromGdml(const char *gdmlFile, const char *setupName)
Initialize the instance of ROOTGeo.
TGeoVolume * GetVolumeBucket(int part)
Get bucket volume;.
void SetDefaultVis()
Set default visual attributes;.
TGeoVolumeAssembly * GetVolumeAssembly(int part)
Get assembly volume; part=0,2 for AssemblyEc, 1 for AssemblyBr;
TGeoNode * GetScin(int part, int scin)
Get scintillator node;.
TGeoNode * GetBucket(int part, int scin, int bucket)
Get bucket node, 0 for west bucket, 1 for the east one;.
int GetScinNb(int part)
Get number of scintillators on each part;.
void SetPhysicalNode()
Set the pointers to the physical nodes;.
TGeoPhysicalNode * GetPhysicalScin(int part, int scin)
Get scintillator physical node;.
void SetNode()
Set the pointers to theirs nodes;.