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