BOSS 7.1.0
BESIII Offline Software System
Loading...
Searching...
No Matches
DetectorDescription/ROOTGeo/ROOTGeo-00-00-16/src/MdcROOTGeo.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/10 Zhengyun You Peking University
7 * named from MdcGeo to MdcROOTGeo
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/MdcROOTGeo.h"
23
24const int
25MdcROOTGeo::m_kReplica[m_kLayer] = { 40, 44, 48, 56, 64, 72, 80, 80,
26 76, 76, 88, 88, 100, 100, 112, 112, 128, 128, 140, 140,
27 160, 160, 160, 160, 192, 192, 192, 192, 208, 208, 208, 208, 240, 240, 240, 240,
28 256, 256, 256, 256, 288, 288, 288,
29 256, 256, 256, 256, 288, 288, 288 };
30const int
31MdcROOTGeo::m_kiCorrectLayer[m_kCorrectLayer] = {9, 11, 13, 15, 17, 19, 36, 38, 40, 42};
32const int
33//MdcROOTGeo::m_kiCorrectReplica[m_kCorrectLayer] = {38, 44, 50, 56, 65, 71, 127, 127, 144, 143};
34MdcROOTGeo::m_kiCorrectReplica[m_kCorrectLayer] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
35
37{
38 // Default constructor.
39 for (int layer = 0; layer < m_kLayer; layer++) {
40 for (int replica = 0; replica < m_kReplicaMax; replica++) {
41 m_NodeReplica[layer][replica] = 0;
42 m_PhysicalReplica[layer][replica] = 0;
43 }
44 }
45
46 for (int i = 0; i < m_kCorrectLayer; i++) {
47 m_CorrectMap[m_kiCorrectLayer[i]] = m_kiCorrectReplica[i];
48 }
49}
50
52{ }
53
54void
55MdcROOTGeo::InitFromGdml( const char *gdmlFile, const char *setupName )
56{
57 ReadGdml(gdmlFile, setupName);
58 SetNode();
60
61 m_ROOTGeoInit = 1;
62}
63
64void
66{
67 m_Mdc = GetTopVolume();
68 if(!m_Mdc) std::cout << "m_Mdc = 0" << std::endl;
69
70 for (int layer = 0; layer < m_kLayer; layer++) {
71 //std::cout << "Layer " << layer << std::endl;
72 for (int replica = 0; replica < m_kReplica[layer]; replica++) {
73 std::stringstream osname;
74 int rep = replica;
75 if (layer >= 0 && layer < m_kStereoLayerIn) {
76 osname << "pv_" << "logical" << "Mdc" << "Stereo" << "Layer" << layer << "TwistedTubs" << "_" << rep;
77 }
78 else if (layer >= m_kStereoLayerIn && layer < m_kStereoLayerIn + m_kAxialLayerIn) {
79 rep = CorrectReplica(layer, rep);
80 osname << "pv_" << "logical" << "Mdc" << "Axial" << "Layer" << layer << "Replica" << "_" << rep;
81 }
82 else if (layer >= m_kStereoLayerIn + m_kAxialLayerIn &&
83 layer < m_kStereoLayerIn + m_kAxialLayerIn + m_kStereoLayerOut) {
84 osname << "pv_" << "logical" << "Mdc" << "Stereo" << "Layer" << layer << "TwistedTubs" << "_" << rep;
85 }
86 else if (layer >= m_kStereoLayerIn + m_kAxialLayerIn + m_kStereoLayerOut &&
87 layer < m_kStereoLayerIn + m_kAxialLayerIn + m_kStereoLayerOut + m_kAxialLayerOut) {
88 rep = CorrectReplica(layer, rep);
89 osname << "pv_" << "logical" << "Mdc" << "Axial" << "Layer" << layer << "_0" << "Replica" << "_" << rep;
90 }
91 else if (layer >= m_kStereoLayerIn + m_kAxialLayerIn + m_kStereoLayerOut + m_kAxialLayerOut &&
92 layer < m_kLayer) {
93 rep = CorrectReplica(layer, rep);
94 osname << "pv_" << "logical" << "Mdc" << "Axial" << "Layer" << layer - m_kAxialLayerOut << "_1" << "Replica" << "_" << rep;
95 }
96
97 m_NodeReplica[layer][replica] = GetNode( osname.str() );
98 }
99 }
100}
101
102int
103MdcROOTGeo::CorrectReplica(int layer, int replica)
104{
105 int rep = replica;
106 for (intMap::iterator iter = m_CorrectMap.begin(); iter != m_CorrectMap.end(); iter++) {
107 if (layer == (*iter).first ||
108 (layer >= m_kStereoLayerIn + m_kAxialLayerIn + m_kStereoLayerOut + m_kAxialLayerOut &&
109 layer - m_kAxialLayerOut == (*iter).first)) {
110 rep -= (*iter).second;
111 if (rep < 0) rep += m_kReplica[layer];
112 }
113 }
114
115 //std::cout << "layer" << layer << " " << replica << "->" << rep << std::endl;
116 return rep;
117}
118
119void
121{
122 //std::cout << "begin of set defaultvis" << std::endl;
123 int mdcColor = 3;
124 int segmentColor = 0;
125 int hypeColor = 3;
126 int tubeColor = 4;
127 int twistedTubsColor = 3;
128 int replicaColor = 4;
129
130 m_Mdc->SetLineColor(mdcColor);
131 m_Mdc->SetVisibility(0);
132
133 for (int segment = 1; segment <= m_kSegment; segment++) {
134 GetVolumeSegment(segment)->SetLineColor(segmentColor);
135 GetVolumeSegment(segment)->SetVisibility(0);
136 }
137
138 for (int layer =0; layer < m_kLayer; layer++) {
139 if ( (layer >= 0 && layer < m_kStereoLayerIn) ||
140 (layer >= m_kStereoLayerIn + m_kAxialLayerIn &&
141 layer < m_kStereoLayerIn + m_kAxialLayerIn + m_kStereoLayerOut) ) {
142 GetVolumeLayer(layer)->SetLineColor(hypeColor);
143 GetVolumeReplica(layer)->SetLineColor(twistedTubsColor);
144 }
145 else {
146 GetVolumeLayer(layer)->SetLineColor(tubeColor);
147 GetVolumeReplica(layer)->SetLineColor(replicaColor);
148 }
149 GetVolumeLayer(layer)->SetVisibility(0);
150 GetVolumeReplica(layer)->SetVisibility(1);
151 }
152
153 for (int segment = 1; segment <= m_kSegment; segment++) {
154 for (int no = 0; no < 2; no++) {
155 GetSegment(segment, no)->SetVisibility(0);
156 }
157 }
158
159 for (int layer = 0; layer < m_kLayer; layer++) {
160 GetLayer(layer)->SetVisibility(0);
161 for (int replica = 0; replica < m_kReplica[layer]; replica++) {
162 GetReplica(layer, replica)->SetVisibility(0);
163 }
164 }
165
166 //std::cout << "end of set defaultvis" << std::endl;
167}
168
169void
171{
172 for (int segment = 1; segment <= m_kSegment; segment++) {
173 GetVolumeSegment(segment)->SetVisibility(0);
174 }
175
176 for (int layer = 0; layer < m_kLayer; layer++) {
177 GetVolumeLayer(layer)->SetVisibility(1);
178 GetVolumeReplica(layer)->SetVisibility(0);
179 }
180
181 for (int segment = 1; segment <= m_kSegment; segment++) {
182 for (int no = 0; no < 2; no++) {
183 GetSegment(segment, no)->SetVisibility(1);
184 }
185 }
186
187 for (int layer = 0; layer < m_kLayer; layer++) {
188 GetLayer(layer)->SetVisibility(1);
189 for (int replica = 0; replica < m_kReplica[layer]; replica++) {
190 GetReplica(layer, replica)->SetVisibility(0);
191 }
192 }
193}
194
195void
197{
198 for (int segment = 1; segment <= m_kSegment; segment++) {
199 GetVolumeSegment(segment)->SetVisibility(0);
200 }
201
202 for (int layer = 0; layer < m_kLayer; layer++) {
203 GetVolumeLayer(layer)->SetVisibility(0);
204 GetVolumeReplica(layer)->SetVisibility(1);
205 }
206
207 for (int segment = 1; segment <= m_kSegment; segment++) {
208 for (int no = 0; no < 2; no++) {
209 GetSegment(segment, no)->SetVisibility(0);
210 }
211 }
212
213 for (int layer = 0; layer < m_kLayer; layer++) {
214 GetLayer(layer)->SetVisibility(0);
215 for (int replica = 0; replica < m_kReplica[layer]; replica++) {
216 if (replica < m_kReplica[layer]/4) GetReplica(layer, replica)->SetVisibility(0);
217 else GetReplica(layer, replica)->SetVisibility(1);
218 }
219 }
220}
221
222void
224{
225 int twistedTubsColor = 3;
226 int replicaColor = 4;
227
228 if (gGeoManager == 0) std::cout << "Create gGeoManager first" << std::endl;
229 TGeoNode *bes = gGeoManager->GetTopNode();
230 //std::cout << "m_childNo " << m_childNo << std::endl;
231 TGeoNode *mdc = bes->GetDaughter(m_childNo);
232
233 //if(!m_Mdc) std::cout << "m_Mdc = 0" << std::endl;
234
235 for (int layer = 0; layer < m_kLayer; layer++) {
236 TGeoNode *nodeLayer = GetLayer(layer);
237 //std::cout << "Layer " << layer << std::endl;
238 for (int replica = 0; replica < m_kReplica[layer]; replica++) {
239 TGeoNode *nodeReplica = GetReplica(layer, replica);
240 m_PhysicalReplica[layer][replica] = gGeoManager->MakePhysicalNode( TString("/") + bes->GetName() +
241 TString("/") + mdc->GetName() +
242 TString("/") + nodeLayer->GetName() +
243 TString("/") + nodeReplica->GetName());
244 m_PhysicalReplica[layer][replica]->SetVisibility(0);
245 m_PhysicalReplica[layer][replica]->SetIsVolAtt(kFALSE);
246 if ( (layer >= 0 && layer < m_kStereoLayerIn) ||
247 (layer >= m_kStereoLayerIn + m_kAxialLayerIn &&
248 layer < m_kStereoLayerIn + m_kAxialLayerIn + m_kStereoLayerOut) ) {
249 m_PhysicalReplica[layer][replica]->SetLineColor(twistedTubsColor);
250 }
251 else {
252 m_PhysicalReplica[layer][replica]->SetLineColor(replicaColor);
253 }
254 //if (m_PhysicalReplica[layer][replica]->IsVolAttributes()) std::cout << "yes " << std::endl;
255 }
256 }
257}
258
259TGeoVolume*
261{
262 std::stringstream osname;
263 osname << "logical" << "Mdc" << "Segment" << segment;
264 return GetLogicalVolume( osname.str() );
265}
266
267TGeoVolume*
269{
270 std::stringstream osname;
271 if (layer >= 0 && layer < m_kStereoLayerIn) {
272 osname << "logical" << "Mdc" << "Stereo" << "Layer" << layer;
273 }
274 else if (layer >= m_kStereoLayerIn && layer < m_kStereoLayerIn + m_kAxialLayerIn) {
275 osname << "logical" << "Mdc" << "Axial" << "Layer" << layer;
276 }
277 else if (layer >= m_kStereoLayerIn + m_kAxialLayerIn &&
278 layer < m_kStereoLayerIn + m_kAxialLayerIn + m_kStereoLayerOut) {
279 osname << "logical" << "Mdc" << "Stereo" << "Layer" << layer;
280 }
281 else if (layer >= m_kStereoLayerIn + m_kAxialLayerIn + m_kStereoLayerOut &&
282 layer < m_kStereoLayerIn + m_kAxialLayerIn + m_kStereoLayerOut + m_kAxialLayerOut) {
283 osname << "logical" << "Mdc" << "Axial" << "Layer" << layer << "_0";
284 }
285 else if (layer >= m_kStereoLayerIn + m_kAxialLayerIn + m_kStereoLayerOut + m_kAxialLayerOut &&
286 layer < m_kLayer) {
287 osname << "logical" << "Mdc" << "Axial" << "Layer" << layer - m_kAxialLayerOut << "_1";
288 }
289
290 return GetLogicalVolume( osname.str() );
291}
292
293TGeoVolume*
295{
296 std::stringstream osname;
297 if (layer >= 0 && layer < m_kStereoLayerIn) {
298 osname << "logical" << "Mdc" << "Stereo" << "Layer" << layer << "TwistedTubs";
299 }
300 else if (layer >= m_kStereoLayerIn && layer < m_kStereoLayerIn + m_kAxialLayerIn) {
301 osname << "logical" << "Mdc" << "Axial" << "Layer" << layer << "Replica";
302 }
303 else if (layer >= m_kStereoLayerIn + m_kAxialLayerIn &&
304 layer < m_kStereoLayerIn + m_kAxialLayerIn + m_kStereoLayerOut) {
305 osname << "logical" << "Mdc" << "Stereo" << "Layer" << layer << "TwistedTubs";
306 }
307 else if (layer >= m_kStereoLayerIn + m_kAxialLayerIn + m_kStereoLayerOut &&
308 layer < m_kStereoLayerIn + m_kAxialLayerIn + m_kStereoLayerOut + m_kAxialLayerOut) {
309 osname << "logical" << "Mdc" << "Axial" << "Layer" << layer << "_0" << "Replica";
310 }
311 else if (layer >= m_kStereoLayerIn + m_kAxialLayerIn + m_kStereoLayerOut + m_kAxialLayerOut &&
312 layer < m_kLayer) {
313 osname << "logical" << "Mdc" << "Axial" << "Layer" << layer - m_kAxialLayerOut << "_1" << "Replica";
314 }
315
316 return GetLogicalVolume( osname.str() );
317}
318
319TGeoNode*
320MdcROOTGeo::GetSegment( int segment, int no )
321{
322 std::stringstream osname;
323 if (segment == 1 || segment == 2) {
324 osname << "pv_" << "logical" << "Mdc" << "Segment" << segment << "_" << m_kLayer + segment - 1;
325 }
326 else {
327 osname << "pv_" << "logical" << "Mdc" << "Segment" << segment << "_" << m_kLayer + 2 + (segment - 3)*2 + no;
328 }
329
330 return GetNode( osname.str() );
331}
332
333TGeoNode*
335{
336 std::stringstream osname;
337 if (layer >= 0 && layer < m_kStereoLayerIn) {
338 osname << "pv_" << "logical" << "Mdc" << "Stereo" << "Layer" << layer << "_" << layer;
339 }
340 else if (layer >= m_kStereoLayerIn && layer < m_kStereoLayerIn + m_kAxialLayerIn) {
341 osname << "pv_" << "logical" << "Mdc" << "Axial" << "Layer" << layer << "_" << layer;
342 }
343 else if (layer >= m_kStereoLayerIn + m_kAxialLayerIn &&
344 layer < m_kStereoLayerIn + m_kAxialLayerIn + m_kStereoLayerOut) {
345 osname << "pv_" << "logical" << "Mdc" << "Stereo" << "Layer" << layer << "_" << layer;
346 }
347 else if (layer >= m_kStereoLayerIn + m_kAxialLayerIn + m_kStereoLayerOut &&
348 layer < m_kStereoLayerIn + m_kAxialLayerIn + m_kStereoLayerOut + m_kAxialLayerOut) {
349 osname << "pv_" << "logical" << "Mdc" << "Axial" << "Layer" << layer << "_0" << "_"
350 << 2*layer - m_kStereoLayerIn - m_kAxialLayerIn - m_kStereoLayerOut;
351 }
352 else if (layer >= m_kStereoLayerIn + m_kAxialLayerIn + m_kStereoLayerOut + m_kAxialLayerOut &&
353 layer < m_kLayer) {
354 osname << "pv_" << "logical" << "Mdc" << "Axial" << "Layer" << layer - m_kAxialLayerOut << "_1" << "_"
355 << 2*(layer - m_kAxialLayerOut) - m_kStereoLayerIn - m_kAxialLayerIn - m_kStereoLayerOut + 1;
356 }
357
358 //std::cout << osname.str() << std::endl;
359 return GetNode( osname.str() );
360}
361
362TGeoNode*
363MdcROOTGeo::GetReplica( int layer, int replica )
364{
365 if (m_NodeReplica[layer][replica] != 0) {
366 //std::cout << " replica " << layer << " " << replica << " found " << std::endl;
367 return m_NodeReplica[layer][replica];
368 }
369 else {
370 std::cout << "Node: " << "Layer" << layer << "Replica" << replica << " not found" << std::endl;
371 return 0;
372 }
373}
374
375TGeoPhysicalNode*
376MdcROOTGeo::GetPhysicalReplica( int layer, int replica )
377{
378 if (m_PhysicalReplica[layer][replica] != 0) {
379 return m_PhysicalReplica[layer][replica];
380 }
381 else {
382 std::cout << "PhysicalNode: " << "Layer" << layer << "Replica" << replica << " not found" << std::endl;
383 return 0;
384 }
385}
std::string mdc
Definition: CalibModel.cxx:45
const int no
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
TGeoNode * GetSegment(int segment, int no)
Get segment node;.
int CorrectReplica(int layer, int replica)
Correct some axial layer id to copyNo;.
TGeoVolume * GetVolumeLayer(int layer)
Get layer volume;
void SetNode()
Set the pointers to theirs nodes;.
TGeoNode * GetReplica(int layer, int replica)
Get replica node;.
void SetDefaultVis()
Set default visual attributes;.
TGeoVolume * GetVolumeReplica(int layer)
Get replica volume;.
TGeoVolume * GetVolumeSegment(int segment)
Get segment volume;.
TGeoPhysicalNode * GetPhysicalReplica(int layer, int replica)
Get replica physical node;.
void SetPhysicalNode()
Set the pointers to the physical nodes;.
void InitFromGdml(const char *gdmlFile, const char *setupName)
Initialize the instance of ROOTGeo.
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.