BOSS 7.1.2
BESIII Offline Software System
Loading...
Searching...
No Matches
BesGeometry.cxx
Go to the documentation of this file.
1
2#include <iostream>
3#include <TGeoManager.h>
4#include <TGeoMaterial.h>
5#include <TGeoMedium.h>
6#include <TGeoVolume.h>
7#include <TGeoTube.h>
8#include <TGeoArb8.h>
9#include <TGeoMatrix.h>
10#include <TCanvas.h>
11
15#include "BesVisLib/Mdc2DWire.h"
16
18
19using namespace std;
20
21#ifndef __CINT__
23#endif
24
25//_____________________________________________________________________________
26
27BesGeometry::BesGeometry() : TObject(),
28 m_Bes(0),
29 m_BeamPipe(0),
30 m_Mdc(0),
31 m_Tof(0),
32 m_Emc(0),
33 m_Muc(0),
34 m_MdcROOTGeo(0),
35 m_TofROOTGeo(0),
36 m_EmcROOTGeo(0),
37 m_MucROOTGeo(0)
38{
39 // Create Bes geometry
40 if (!gGeoManager) new TGeoManager("BesGeo", "BesGeometry");
41 else gGeoManager-> ClearPhysicalNodes();
42
43 m_BesR = 2840.0;
44 m_BesZ = 5680.0;
45
46 m_BeamPipeRMin = 31.5;
47 m_BeamPipeRMax = 35.8;
48 m_BeamPipeZ = 150.0;
49 m_BeamPipeColor = 922; //Long Peixun's update: Set Beampipe's color
50}
51
52
54{
55 delete m_Bes;
56 delete m_BeamPipe;
57
58 delete m_MdcROOTGeo;
59 delete m_TofROOTGeo;
60 delete m_EmcROOTGeo;
61 delete m_MucROOTGeo;
62}
63
64void BesGeometry::InitFromGDML(const TString fPath, bool mrpc, bool cgem)
65{
66 gGeoManager->SetVisOption(0); // to show all visible volumes.
67 gGeoManager->SetVisLevel(5);
68
69 TGeoIdentity *identity = new TGeoIdentity();
70
71 TGeoMaterial *mat = new TGeoMaterial("VOID",0,0,0);
72 mat->SetTransparency(20);
73 TGeoMedium *med = new TGeoMedium("MED",1,mat);
74 m_Bes = gGeoManager->MakeBox("volBes", med, m_BesR, m_BesR, 0.5*m_BesZ);
75
76 TGeoVolume *topVolume = new TGeoVolume(); // temp top volume for load geometry more than once
77 gGeoManager->SetTopVolume(topVolume);
78 gGeoManager->SetTopVolume(m_Bes);
79
80 Int_t iChildNo = 0;
81 m_MdcROOTGeo = new MdcROOTGeo(false);
82 m_MdcROOTGeo->InitFromGDML( (fPath + TString("Mdc.gdml")).Data(), "Default" ); //Long Peixun's update: "Mdc"->"Default"
83 cout<<"in BesGeometry construct mdc1"<<endl;
84 m_Mdc = m_MdcROOTGeo->GetVolumeMdc();
85 if (m_Mdc) cout << "Construct Mdc" << endl;
86 else cout << "Volume Mdc not found " << endl;
87 m_Bes->AddNode(m_Mdc, iChildNo, identity);
88 m_MdcROOTGeo->SetChildNo(iChildNo);//Connect bes with mdc, form physcialnode path. m_Bes->GetNdaughters()-1
89
90 iChildNo++;
91 m_TofROOTGeo = new TofROOTGeo();
92
93 //Long Peixun's update: Judge MRPC flag and load relevant Tof GDML
94 if (mrpc)
95 m_TofROOTGeo->InitFromGDML( (fPath + TString("Tof_mrpc.gdml")).Data(), "Default" ); //Huang Shuhui's update: for Tof_mrpc
96 else
97 m_TofROOTGeo->InitFromGDML( (fPath + TString("Tof.gdml")).Data(), "Default" ); //Long Peixun's update: "Tof"->"Default"
98
99 cout<<"construct tof"<<endl;
100 m_Tof = m_TofROOTGeo->GetVolumeTof();
101 if (m_Tof) cout << "Construct Tof" << endl;
102 else cout << "Volume Tof not found " << endl;
103 m_Bes->AddNode(m_Tof, iChildNo, identity);
104 m_TofROOTGeo->SetChildNo(iChildNo);
105
106 iChildNo++;
107 m_EmcROOTGeo = new EmcROOTGeo();
108 m_EmcROOTGeo->InitFromGDML( (fPath + TString("Emc.gdml")).Data(), "Default" ); //Long Peixun's update: "Emc"->"Default"
109 m_Emc = m_EmcROOTGeo->GetVolumeEmc();
110 if (m_Emc) cout << "Construct Emc" << endl;
111 else cout << "Volume Emc not found " << endl;
112 m_Bes->AddNode(m_Emc, iChildNo, identity);
113 m_EmcROOTGeo->SetChildNo(iChildNo);
114
115 iChildNo++;
116 m_MucROOTGeo = new MucROOTGeo();
117 m_MucROOTGeo->InitFromGDML( (fPath + TString("Muc.gdml")).Data(), "Default" ); //Long Peixun's update: "Muc"->"Default"
118 m_Muc = m_MucROOTGeo->GetVolumeMuc();
119 if (m_Muc) cout << "Construct Muc" << endl;
120 else cout << "Volume Muc not found " << endl;
121 m_Bes->AddNode(m_Muc, iChildNo, identity);
122 m_MucROOTGeo->SetChildNo(iChildNo);
123
124 iChildNo++;
125 Int_t beamPipeColor = m_BeamPipeColor; //Long Peixun's update: Blue -> m_BeamPipeColor
126 m_BeamPipe = gGeoManager->MakeTube("volBeamPipe", med, m_BeamPipeRMin, m_BeamPipeRMax, m_BeamPipeZ);
127 m_BeamPipe->SetLineColor(beamPipeColor);
128 m_Bes->AddNode(m_BeamPipe, iChildNo, identity);
129
130 Int_t nDaughters = m_Bes->GetNodes()->GetEntries();
131 cout << "volBes contains " << nDaughters << " nodes : " << endl;
132 for (Int_t i = 0; i < nDaughters; i++) {
133 cout << i << " : " << m_Bes->GetNode(i)->GetName() << endl;
134 }
135
136 InitGeometry();
137}
138
139void BesGeometry::InitFromROOT(TGeoVolume *volBes)
140{
141 gGeoManager->SetVisOption(0); // to show all visible volumes.
142 gGeoManager->SetVisLevel(5);
143
144 m_Bes = volBes;
145 m_BesR = ((TGeoBBox*)m_Bes->GetShape())->GetDX();
146 m_BesZ = ((TGeoBBox*)m_Bes->GetShape())->GetDZ()*2.0;
147
148 TGeoVolume *topVolume = new TGeoVolume();
149 gGeoManager->SetTopVolume(topVolume);
150 gGeoManager->SetTopVolume(m_Bes);
151
152 Int_t nDaughters = m_Bes->GetNodes()->GetEntries();
153
154 //cout << "volBes contains " << nDaughters << " nodes : " << endl;
155 //for (Int_t i = 0; i < nDaughters; i++) {
156 // cout << i << " : " << m_Bes->GetNode(i)->GetName() << endl;
157 //}
158
159 Int_t iChildNo = 0;
160 m_MdcROOTGeo = new MdcROOTGeo(false);
161 TGeoNode *nodeMdc = m_Bes->GetNode(iChildNo);
162 if (nodeMdc) m_Mdc = nodeMdc->GetVolume();
163 //else cout << "Node logicalMdc not found" << endl;
164 //if (m_Mdc) cout << "Set Mdc" << endl;
165 //else cout << "Volume Mdc not found " << endl;
166 m_MdcROOTGeo->InitFromROOT( m_Mdc );
167 m_MdcROOTGeo->SetChildNo(iChildNo);//Connect bes with mdc, form physcialnode path. m_Bes->GetNdaughters()-1
168
169 iChildNo++;
170 m_TofROOTGeo = new TofROOTGeo();
171 TGeoNode *nodeTof = m_Bes->GetNode(iChildNo);
172 if (nodeTof) m_Tof = nodeTof->GetVolume();
173 //else cout << "Node logicalTof not found" << endl;
174 //if (m_Tof) cout << "Set Tof" << endl;
175 //else cout << "Volume Tof not found " << endl;
176 m_TofROOTGeo->InitFromROOT( m_Tof );
177 m_TofROOTGeo->SetChildNo(iChildNo);
178
179 iChildNo++;
180 m_EmcROOTGeo = new EmcROOTGeo();
181 TGeoNode *nodeEmc = m_Bes->GetNode(iChildNo);
182 if (nodeEmc) m_Emc = nodeEmc->GetVolume();
183 //else cout << "Node logicalEmc not found" << endl;
184 //if (m_Emc) cout << "Set Emc" << endl;
185 //else cout << "Volume Emc not found " << endl;
186 m_EmcROOTGeo->InitFromROOT( m_Emc );
187 m_EmcROOTGeo->SetChildNo(iChildNo);
188
189 iChildNo++;
190 m_MucROOTGeo = new MucROOTGeo();
191 TGeoNode *nodeMuc = m_Bes->GetNode(iChildNo);
192 if (nodeMuc) m_Muc = nodeMuc->GetVolume();
193 //else cout << "Node logicalMuc not found" << endl;
194 //if (m_Muc) cout << "Set Muc" << endl;
195 //else cout << "Volume Muc not found " << endl;
196 m_MucROOTGeo->InitFromROOT( m_Muc );
197 m_MucROOTGeo->SetChildNo(iChildNo);
198
199 iChildNo++;
200 TGeoNode *nodeBeamPipe = m_Bes->GetNode(iChildNo);
201 if (nodeBeamPipe) {
202 m_BeamPipe = nodeBeamPipe->GetVolume();
203 m_BeamPipe->SetLineColor(m_BeamPipeColor); //Long Peixun's update: Blue -> m_BeamPipeColor
204 }
205 //else cout << "Node volBeamPipe not found " << endl;
206 //cout << "Set beanmpi complete" << endl;
207
208 InitGeometry();
209 //cout << "init root ok" << endl;
210}
211
213{
214 gGeoManager->SetDrawExtraPaths(); // draw physical node or not;
215 gGeoManager->CloseGeometry();
216 gGeoManager->SetNsegments(20); // devide a circle to 20 slides
217
218 // PhysicalNode necessary for fast setting node visible or not in an event
219 // Should be set after gGeoManager closed
220 m_MdcROOTGeo->SetPhysicalNode(); //here liang
221 m_TofROOTGeo->SetPhysicalNode(); //here liang
222 m_EmcROOTGeo->SetPhysicalNode(); //here liang
223 m_MucROOTGeo->SetPhysicalNode();
224
225 //Long Peixun's update: Build BeamPipe's PhysicalNode to display 3D view
226 m_phyBeamPipe = gGeoManager->MakePhysicalNode(TString("/") + m_Bes->GetName() + TString("_1/") + m_BeamPipe->GetName() + TString("_4"));
227 m_phyBeamPipe->SetVisibility(0);
228 m_phyBeamPipe->SetIsVolAtt(kFALSE);
229 m_phyBeamPipe->SetLineColor(m_BeamPipeColor); //Long Peixun's update: Blue -> m_BeamPipeColor
230
231 // 2D Geometry initialization should be after SetPhysicalNode();
232 //Long Peixun's update: Change initialization order of subdetectors can avoid a strange bug in Mdc2DWire::DistancetoPrimitive()
233 //Mdc, Tof, Emu, Muc -> Tof, Mdc, Emc, Muc
234 m_TofROOTGeo->Init2DGeometry(); //here liang
235 m_MdcROOTGeo->Init2DGeometry(); //here liang
236 m_EmcROOTGeo->Init2DGeometry(); //here liang
237 m_MucROOTGeo->Init2DGeometry();
238
239 Double_t P[3*4] = {0.0};
240
241 // BeamPipe
242 Double_t beamPipeCenter[3] = {0.0, 0.0, 0.0};
243 m_BeamPipeXY =
244 new BesCircle2D("BeamPipe", "BeamPipe", m_BeamPipeRMin, m_BeamPipeRMax, &beamPipeCenter[0]);
245
246 for (Int_t i = 0; i < 4; i++) {
247 P[3*i] = 0.0;
248 if (i == 0 || i == 3) P[3*i+1] = -1.0*m_BeamPipeRMax;
249 else P[3*i+1] = m_BeamPipeRMax;
250 if (i == 0 || i == 1) P[3*i+2] = -1.0*m_BeamPipeZ;
251 else P[3*i+2] = m_BeamPipeZ;
252 }
253 m_BeamPipeZR = new BesPolygon2D("BeamPipe", "BeamPipe", 4, &P[0]);
254 m_BeamPipeZR->SetRotatable(true); //Long Peixun's update: BeamPipe rectangle should not rotate when phi is changed
255
256 // Auxiliary line
257 if (!m_Bes) cout << "BesGeometry:InitGeometry, top volume m_Bes not found" << endl;
258 TGeoBBox *besShape = (TGeoBBox*)m_Bes->GetShape();
259 m_BesR = besShape->GetDX();
260 m_BesZ = besShape->GetDZ()*2.0;
261 for (Int_t i = 0; i < 4; i++) {
262 P[3*i] = 0.0;
263 if (i == 0 || i == 3) P[3*i+1] = -1.0*m_BesR;
264 else P[3*i+1] = m_BesR;
265 if (i == 0 || i == 1) P[3*i+2] = -1.0*m_BesZ;
266 else P[3*i+2] = m_BesZ;
267 }
268
269 m_ZRPlaneOnXY = new BesPolygon2D("ZRPlaneOnXY", "ZRPlaneOnXY", 4, &P[0]);
270 m_ZRPlaneOnXY->SetRotatable(true);
271 m_ZRPlaneOnXY->SetLineWidth(1);
272 m_ZRPlaneOnXY->SetLineStyle(3);
273 m_ZRPlaneOnXY->SetFillStyle(4000);
274}
275
276const char* BesGeometry::GetFilename(const char* RunPeriod)
277{
278 return RunPeriod;
279}
280
282{
283 m_Bes->SetLineColor(2);
284 m_Bes->SetVisibility(0);
285
286 m_BeamPipe->SetLineColor(m_BeamPipeColor); //Long Peixun's update: Blue -> m_BeamPipeColor
287 m_BeamPipe->SetVisibility(0);
288
289 //Long Peixun's update: Annotate useless code
290 // m_MdcROOTGeo->SetAllVisible();
291 // m_TofROOTGeo->SetAllVisible();
292 // m_EmcROOTGeo->SetAllVisible();
293 // m_MucROOTGeo->SetAllVisible();
294}
295
296//Long Peixun's update: Reset color
298{
299 m_MdcROOTGeo->SetPhysicalDefaultVis();
300 m_TofROOTGeo->SetPhysicalDefaultVis();
301 m_EmcROOTGeo->SetPhysicalDefaultVis();
302 m_MucROOTGeo->SetPhysicalDefaultVis();
303}
304
305void BesGeometry::Draw(Option_t *option)
306{
307 //
308 // BesGeometry draw function
309 TString opt = option;
310 opt.ToUpper();
311
312 if ( opt.Contains("3D") ) {
313 Draw3D();
314 }
315 else if ( opt.Contains("XY") ) {
316 Draw2DXY();
317 }
318 else if ( opt.Contains("ZR") ) {
319 Draw2DZR();
320 }
321}
322
324{
325 BesView *view = dynamic_cast<BesView*>(gPad->GetView());
326
327 if (view && view->GetViewType() == k3DView)
328 {
329 //Long Peixun's update: Draw Detector 3D
330 m_BeamPipe->AppendPad();
331
332 //Long Peixun's update: Set BeamPipe 3D visibility
333 if (view->GetVisBeamPipe()) m_phyBeamPipe->SetVisibility(1);
334 else m_phyBeamPipe->SetVisibility(0);
335
336 if (m_MdcROOTGeo) {
337 m_MdcROOTGeo->SetVisMdcDetector();
338 m_MdcROOTGeo->SetPhysicalDefaultVis(); //Long Peixun's update: Reset Color
339 m_MdcROOTGeo->SetVisMdcHits();
340 }
341
342 if (m_TofROOTGeo) {
343 m_TofROOTGeo->SetVisTofDetector();
344 m_TofROOTGeo->SetPhysicalDefaultVis(); //Long Peixun's update: Reset Color
345 m_TofROOTGeo->SetVisTofHits();
346 }
347
348 if (m_EmcROOTGeo) {
349 m_EmcROOTGeo->SetVisEmcDetector();
350 m_EmcROOTGeo->SetPhysicalDefaultVis(); //Long Peixun's update: Reset Color
351 m_EmcROOTGeo->SetVisEmcHits();
352 }
353
354 if (m_MucROOTGeo) {
355 m_MucROOTGeo->SetVisMucDetector();
356 m_MucROOTGeo->SetPhysicalDefaultVis(); //Long Peixun's update: Reset Color
357 m_MucROOTGeo->SetVisMucHits();
358 }
359 }
360
361 //if (gGeoManager) {
362 // cout << "gGeoManager exit" << endl;
363 //}
364 //else {
365 // cout << "gGeoManager do not exit" << endl;
366 //}
367
368 //if (m_Bes){
369 // cout << "m_Bes address:" << m_Bes << endl;
370 //}
371
372
373 //if (m_Bes) m_Bes->Draw();
374 //if (view && view->GetVisAxis()) view->ShowAxis();
375}
376
378{
379 BesView *view = dynamic_cast<BesView*>(gPad->GetView());
380 //Long Peixun's update: Judge view before draw
381 if (view)
382 {
383 if (view->GetVisBeamPipe()) m_BeamPipeXY->Draw();
384 if (m_MdcROOTGeo) m_MdcROOTGeo->Draw("XY");
385 if (m_TofROOTGeo) m_TofROOTGeo->Draw("XY");
386 if (m_EmcROOTGeo) m_EmcROOTGeo->Draw("XY");
387 if (m_MucROOTGeo) m_MucROOTGeo->Draw("XY");
388 if (view->GetVisZRPlaneOnXY()) m_ZRPlaneOnXY->Draw();
389 if (view->GetVisAxis()) view->ShowAxis();
390 }
391}
392
394{
395 BesView *view = dynamic_cast<BesView*>(gPad->GetView());
396 //Long Peixun's update: Judge view before draw
397 if (view)
398 {
399 if (view->GetVisBeamPipe()) m_BeamPipeZR->Draw();
400 if (m_MdcROOTGeo) m_MdcROOTGeo->Draw("ZR");
401 if (m_TofROOTGeo) m_TofROOTGeo->Draw("ZR");
402 if (m_EmcROOTGeo) m_EmcROOTGeo->Draw("ZR");
403 if (m_MucROOTGeo) m_MucROOTGeo->Draw("ZR");
404 if (view->GetVisAxis()) view->ShowAxis();
405 }
406}
BesGeometry * gBesGeometry
ClassImp(BesGeometry) BesGeometry
@ k3DView
Definition BesStatus.h:17
double P(RecMdcKalTrack *trk)
virtual void Draw(Option_t *option="")
virtual void InitGeometry()
virtual void SetDefaultVis()
virtual ~BesGeometry()
virtual void Draw2DXY()
const char * GetFilename(const char *RunPeriod)
virtual void InitFromGDML(const TString fPath, bool mrpc=false, bool cgem=false)
virtual void SetPhysicalDefaultVis()
virtual void Draw(Option_t *option="3D")
virtual void Draw2DZR()
virtual void InitFromROOT(TGeoVolume *volBes)
virtual void Draw3D()
void SetRotatable(Bool_t input)
virtual void Draw(Option_t *option="")
virtual void ShowAxis()
Definition BesTView.h:178
Bool_t GetVisAxis()
Definition BesView.h:175
Bool_t GetVisBeamPipe()
Definition BesView.h:173
EBESViewType GetViewType()
Definition BesView.h:71
Bool_t GetVisZRPlaneOnXY()
Definition BesView.h:174
void SetVisEmcDetector()
Set Emc detector visibility;.
void SetPhysicalDefaultVis()
Set default physical node attributes;.
void InitFromROOT(TGeoVolume *vol)
Initialize ROOTGeo from TGeoVolume logicalEmc.
void InitFromGDML(const char *gdmlFile, const char *setupName)
Initialize ROOTGeo from GDML.
void SetPhysicalNode()
Set the pointers to the physical nodes;.
void InitFromROOT(TGeoVolume *vol)
Initialize ROOTGeo from TGeoVolume logicalMdc.
void SetVisMdcDetector()
Set Mdc default detector visibility;.
void SetPhysicalDefaultVis()
Set default physical node attributes;.
void SetPhysicalNode()
Set the pointers to the physical nodes;.
void InitFromGDML(const char *gdmlFile, const char *setupName)
Initialize ROOTGeo from GDML.
void SetPhysicalNode()
Set the pointers to the physical nodes;.
void SetVisMucDetector()
Set Muc detector visibility;.
void InitFromGDML(const char *gdmlFile, const char *setupName)
Initialize ROOTGeo from GDML.
void InitFromROOT(TGeoVolume *vol)
Initialize ROOTGeo from TGeoVolume logicalMuc.
void InitFromROOT(TGeoVolume *vol)
Initialize ROOTGeo from TGeoVolume logicalTof.
void InitFromGDML(const char *gdmlFile, const char *setupName)
Initialize ROOTGeo from GDML.
void SetVisTofDetector()
Set Tof detector visibility;.
void SetPhysicalNode()
Set the pointers to the physical nodes;.