BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
DetectorDescription/ROOTGeo/src/EmcROOTGeo.cxx
Go to the documentation of this file.
1//$id$
2/*
3 * 2004/11/29 Zhengyun You Peking University
4 * Emc Geometry General for EventDisplay
5 *
6 * 2004/12/11 Zhengyun You Peking University
7 * named from EmcGeo to EmcROOTGeo
8 * inherit from class SubDetectorROOTGeo
9 *
10 * 2005/04/04 Zhengyun You Peking University
11 * Emc End geometry added
12 */
13
14using namespace std;
15
16#include "TGeoManager.h"
17#include <fstream>
18#include <iomanip>
19#include <iostream>
20#include <sstream>
21#include <stdlib.h>
22#include <string>
23#include <vector>
24
25#include "ROOTGeo/EmcROOTGeo.h"
26// Ma Qiumei Add
27#include <TError.h>
28
29// #include <TGeoArb8.h>
30
32 // Default constructor.
33 m_kPhiEc = 16;
34 m_kThetaEc = 35;
35
36 for ( int part = 0; part < m_kPart; part++ )
37 {
38 for ( int phi = 0; phi < m_kPhiBr; phi++ )
39 {
40 for ( int theta = 0; theta < m_kThetaBr; theta++ )
41 {
42 m_NodeTheta[part][phi][theta] = 0;
43 m_PhysicalCrystal[part][phi][theta] = 0;
44 }
45 }
46 }
47
48 string GdmlManagementPath = getenv( "GDMLMANAGEMENTDATAROOT" );
49 if ( GdmlManagementPath == "" ) cout << "EmcROOTGeo::GdmlManagementPath not set!" << endl;
50 string GdmlFile = GdmlManagementPath + string( "/dat/Emc.gdml" );
51 cout << "EmcROOTGeo: Construct Emc from GdmlFile " << GdmlFile << endl;
52 InitFromGdml( GdmlFile.c_str(), "Emc" );
53}
54
56
57void EmcROOTGeo::InitFromGdml( const char* gdmlFile, const char* setupName ) {
58 ReadGdml( gdmlFile, setupName );
59 SetNode();
60 // SetDefaultVis();
61
62 m_ROOTGeoInit = 1;
63}
64
66
67 // Ma Qiumei Add for removing Warning Infomations
68 gErrorIgnoreLevel = kFatal;
69
70 m_Emc = GetTopVolume();
71 if ( !m_Emc ) { m_Emc = GetLogicalVolume( "logicalEMC" ); }
72 if ( !m_Emc ) std::cout << "m_Emc = 0" << std::endl;
73 else cout << "Find logicalEMC!" << endl;
74
75 for ( int part = 0; part < m_kPart; part++ )
76 {
77 // TGeoNode *nodePart = GetPart(part);
78 // if(nodePart) cout<<nodePart->GetName()<<endl;
79 int nPhi = ( part == 1 ? m_kPhiBr : m_kPhiEc );
80
81 for ( int phi = 0; phi < nPhi; phi++ )
82 {
83 // total number of daughters in BSCPhi is 215
84 int nTheta = ( part == 1 ? 219 : m_kThetaEc );
85 TGeoNode* nodePhi = GetPhi( part, phi );
86 // if(nodePhi) cout<<nodePhi->GetName()<<endl;
87
88 for ( int theta = 0; theta < nTheta; theta++ )
89 {
90 string name = nodePhi->GetDaughter( theta )->GetName();
91 int nthe = -1;
92 string strthe;
93 if ( name.find( "BSCCasing", 0 ) == 7 ) { strthe = name.substr( 16, 2 ); }
94 else if ( name.find( "EndCasing", 0 ) == 7 ) { strthe = name.substr( 19, 2 ); }
95
96 istringstream thetaBuf( strthe );
97 thetaBuf >> nthe;
98
99 if ( nthe >= 0 ) { m_NodeTheta[part][phi][nthe] = nodePhi->GetDaughter( theta ); }
100 }
101 }
102 }
103 // std::cout << "end of set node" << std::endl;
104}
105
107 // std::cout << "begin of set defaultvis" << std::endl;
108 int emcColor = 2;
109 int partColor = 2;
110 int phiColor = 4;
111 int thetaColor = 4;
112 int brCrystalColor = 4;
113 int ecCrystalColor = 7;
114
115 m_Emc->SetLineColor( emcColor );
116 m_Emc->SetVisibility( 0 );
117
118 for ( int part = 0; part < m_kPart - 1; part++ )
119 {
120 GetVolumePart( part )->SetLineColor( partColor );
121 int nPhi = ( part == 1 ? m_kPhiBr : m_kPhiEc );
122 for ( int phi = 0; phi < nPhi; phi++ )
123 {
124 GetVolumePhi( part, phi )->SetLineColor( phiColor );
125 GetVolumePhi( part, phi )->SetVisibility( 0 );
126 }
127 if ( part == 1 )
128 {
129 for ( int theta = 0; theta < m_kThetaBr; theta++ )
130 {
131 GetVolumeTheta( part, 0, theta )->SetLineColor( thetaColor );
132 GetVolumeTheta( part, 0, theta )->SetVisibility( 0 );
133 GetVolumeCrystal( part, 0, theta )->SetLineColor( brCrystalColor );
134 GetVolumeCrystal( part, 0, theta )->SetVisibility( 1 );
135 }
136 }
137 else if ( part == 0 )
138 {
139 int iPhi[4] = { 0, 6, 8, 7 };
140 for ( int i = 0; i < 4; i++ )
141 {
142 int phi = iPhi[i];
143 int nTheta = ( part == 1 ? m_kThetaBr : m_kThetaEc );
144 for ( int theta = 0; theta < nTheta; theta++ )
145 {
146 GetVolumeTheta( part, phi, theta )->SetLineColor( thetaColor );
147 GetVolumeTheta( part, phi, theta )->SetVisibility( 0 );
148 GetVolumeCrystal( part, phi, theta )->SetLineColor( ecCrystalColor );
149 GetVolumeCrystal( part, phi, theta )->SetVisibility( 1 );
150 }
151 }
152 }
153 }
154
155 for ( int part = 0; part < m_kPart; part++ )
156 {
157 GetPart( part )->SetVisibility( 0 );
158 int nPhi = ( part == 1 ? m_kPhiBr : m_kPhiEc );
159 for ( int phi = 0; phi < nPhi; phi++ )
160 {
161 GetPhi( part, phi )->SetVisibility( 0 );
162 int nTheta = ( part == 1 ? m_kThetaBr : m_kThetaEc );
163 for ( int theta = 0; theta < nTheta; theta++ )
164 {
165 GetTheta( part, phi, theta )->SetVisibility( 0 );
166 GetCrystal( part, phi, theta )->SetVisibility( 0 );
167 }
168 }
169 }
170 // std::cout << "end of set defaultvis" << std::endl;
171}
172
174 /* for (int part = 0; part < m_kPart-1; part++) {
175 int nPhi = (part == 1 ? m_kPhiBr : m_kPhiEc);
176 for (int phi = 0; phi < nPhi; phi++) {
177 GetVolumePhi(part, phi)->SetVisibility(1);
178 }
179 if (part == 1) {
180 for (int theta = 0; theta < m_kThetaBr; theta++) {
181 GetVolumeTheta(part, 0, theta)->SetVisibility(1);
182 GetVolumeCrystal(part, 0, theta)->SetVisibility(0);
183 }
184 }
185 else if (part == 0) {
186 int iPhi[4] = {0,6,8,7};
187 for (int i = 0; i < 4; i++) {
188 int phi = iPhi[i];
189 int nTheta = (part == 1 ? m_kThetaBr : m_kThetaEc);
190 for (int theta = 0; theta < nTheta; theta++) {
191 GetVolumeTheta(part, phi, theta)->SetVisibility(1);
192 GetVolumeCrystal(part, phi, theta)->SetVisibility(0);
193 }
194 }
195 }
196 }
197 */
198
199 for ( int part = 0; part < m_kPart; part++ )
200 {
201 GetPart( part )->SetVisibility( 0 );
202 int nPhi = ( part == 1 ? m_kPhiBr : m_kPhiEc );
203 for ( int phi = 0; phi < nPhi; phi++ )
204 {
205 GetPhi( part, phi )->SetVisibility( 0 );
206 int nTheta = ( part == 1 ? m_kThetaBr : m_kThetaEc );
207 for ( int theta = 0; theta < nTheta; theta++ )
208 {
209 GetTheta( part, phi, theta )->SetVisibility( 0 );
210 GetCrystal( part, phi, theta )->SetVisibility( 1 );
211 }
212 }
213 }
214}
215
217 /* for (int part = 1; part < m_kPart-1; part++) {
218 for (int phi = 1; phi <= m_kPhiBr; phi++) {
219 GetVolumePhi(part, phi)->SetVisibility(0);
220 }
221
222 for (int theta = 1; theta <= m_kThetaBr; theta++) {
223 GetVolumeTheta(part, theta)->SetVisibility(1);
224 GetVolumeCrystal(part, theta)->SetVisibility(0);
225 }
226 }
227
228 for (int part = 1; part < m_kPart-1; part++) {
229 for (int phi = 1; phi <= m_kPhiBr; phi++) {
230 GetPhi(part, phi)->SetVisibility(0);
231 for (int theta = 1; theta <= m_kThetaBr; theta++) {
232 if (phi < m_kPhiBr/4) GetTheta(part, phi, theta)->SetVisibility(0);
233 else GetTheta(part, phi, theta)->SetVisibility(1);
234 GetCrystal(part, phi, theta)->SetVisibility(0);
235 }
236 }
237 }
238 */
239
240 for ( int part = 0; part < m_kPart; part++ )
241 {
242 GetPart( part )->SetVisibility( 0 );
243 int nPhi = ( part == 1 ? m_kPhiBr : m_kPhiEc );
244 for ( int phi = 0; phi < nPhi; phi++ )
245 {
246 GetPhi( part, phi )->SetVisibility( 0 );
247 int nTheta = ( part == 1 ? m_kThetaBr : m_kThetaEc );
248 for ( int theta = 0; theta < nTheta; theta++ )
249 {
250 GetTheta( part, phi, theta )->SetVisibility( 0 );
251 if ( ( part == 1 && ( phi >= 0 && phi < nPhi / 4 ) ) || ( part != 1 ) )
252 { GetCrystal( part, phi, theta )->SetVisibility( 1 ); }
253 else { GetCrystal( part, phi, theta )->SetVisibility( 0 ); }
254 }
255 }
256 }
257}
258
260 // int brCrystalColor = 4;
261 // int ecCrystalColor = 7;
262
263 // Ma Qiumei Add for removing Warning Infomations
264 gErrorIgnoreLevel = kFatal;
265
266 if ( gGeoManager == 0 ) std::cout << "Create gGeoManager first" << std::endl;
267 else cout << "gGeoManager success!" << endl;
268
269 TGeoVolume* volEmc = GetLogicalVolume( "logicalEMC" );
270 if ( !volEmc ) std::cout << "logicalEMC not found !" << std::endl;
271
272 // construct bes world
273 float m_BesR = 5200;
274 float m_BesZ = 5680;
275 TGeoIdentity* identity = new TGeoIdentity();
276
277 TGeoMaterial* mat = new TGeoMaterial( "VOID", 0, 0, 0 );
278 TGeoMedium* med = new TGeoMedium( "MED", 1, mat );
279 TGeoVolume* m_Bes =
280 gGeoManager->MakeBox( "volBes", med, 0.5 * m_BesR, 0.5 * m_BesR, 0.5 * m_BesZ );
281 gGeoManager->SetTopVolume( m_Bes );
282 m_Bes->AddNode( volEmc, 0, identity );
283 // cout<<"Ndaughters="<<m_Bes->GetNdaughters()<<endl;
284 SetChildNo( m_Bes->GetNdaughters() - 1 );
285
286 gGeoManager->SetDrawExtraPaths(); // draw physical node or not;
287 gGeoManager->CloseGeometry();
288 gGeoManager->SetNsegments( 20 );
289
290 TGeoNode* bes = gGeoManager->GetTopNode();
291 TGeoNode* emc = bes->GetDaughter( 0 );
292
293 for ( int part = 0; part < m_kPart; part++ )
294 {
295 TGeoNode* nodePart = GetPart( part );
296 int nPhi = ( part == 1 ? m_kPhiBr : m_kPhiEc );
297 for ( int phi = 0; phi < nPhi; phi++ )
298 {
299 TGeoNode* nodePhi = GetPhi( part, phi );
300 int nTheta = ( part == 1 ? m_kThetaBr : m_kThetaEc );
301 for ( int theta = 0; theta < nTheta; theta++ )
302 {
303 // cout<<part<<"\t"<<phi<<"\t"<<theta<<endl;
304 TGeoNode* nodeTheta = GetTheta( part, phi, theta );
305 TGeoNode* nodeCrystal = GetCrystal( part, phi, theta );
306 TString strPath = TString( "/" ) + bes->GetName() + TString( "/" ) + emc->GetName() +
307 TString( "/" ) + nodePart->GetName() + TString( "/" ) +
308 nodePhi->GetName() + TString( "/" ) + nodeTheta->GetName() +
309 TString( "/" ) + nodeCrystal->GetName();
310 m_PhysicalCrystal[part][phi][theta] = gGeoManager->MakePhysicalNode( strPath );
311
312 // m_PhysicalCrystal[part][phi][theta]->SetVisibility(0);
313 // m_PhysicalCrystal[part][phi][theta]->SetIsVolAtt(kFALSE);
314 // if (part == 1) m_PhysicalCrystal[part][phi][theta]->SetLineColor(brCrystalColor);
315 // else m_PhysicalCrystal[part][phi][theta]->SetLineColor(ecCrystalColor);
316 }
317 }
318 }
319}
320
322 int part = m_kPart;
323
324 return part;
325}
326
327int EmcROOTGeo::GetThetaNb( int part ) {
328 int thetaNb = m_kThetaBr;
329 if ( part != 1 ) thetaNb = m_kThetaEc;
330
331 return thetaNb;
332 ;
333}
334
335int EmcROOTGeo::GetPhiNb( int part ) {
336 int phiNb = m_kPhiBr;
337 if ( part != 1 ) phiNb = m_kPhiEc;
338
339 return phiNb;
340}
341
342TGeoVolume* EmcROOTGeo::GetVolumePart( int part ) {
343 // only part0 and part1 logical volume.
344 std::stringstream osname;
345 osname << "logical"
346 << "Emc"
347 << "Part" << part;
348 if ( part == 0 || part == 1 ) { return GetLogicalVolume( osname.str() ); }
349 else
350 {
351 std::cout << "No volume " << osname.str() << std::endl;
352 return 0;
353 }
354}
355
356TGeoVolume* EmcROOTGeo::GetVolumePhi( int part, int phi ) {
357 // only part0phi0-15, part1phi0-119
358 std::stringstream osname;
359 osname << "logical"
360 << "Emc"
361 << "Part" << part << "Phi" << phi;
362 if ( ( part == 0 && phi >= 0 && phi < 16 ) || ( part == 1 && phi >= 0 && phi < 120 ) )
363 { return GetLogicalVolume( osname.str() ); }
364 else
365 {
366 std::cout << "No volume " << osname.str() << std::endl;
367 return 0;
368 }
369}
370
371TGeoVolume* EmcROOTGeo::GetVolumeTheta( int part, int phi, int theta ) {
372 // part0phi0theta0-34, part0phi6theta0-34, part0phi8theta0-34, part0phi7theta0-34
373 // part1theta0-43
374 std::stringstream osname;
375 if ( part == 1 && theta >= 0 && theta < 44 )
376 {
377 osname << "logical"
378 << "Emc"
379 << "Part" << part << "Theta" << theta;
380 return GetLogicalVolume( osname.str() );
381 }
382 else if ( part == 0 && theta >= 0 && theta < 35 &&
383 ( phi == 0 || phi == 6 || phi == 8 || phi == 7 ) )
384 {
385 osname << "logical"
386 << "Emc"
387 << "Part" << part << "Phi" << phi << "Theta" << theta;
388 return GetLogicalVolume( osname.str() );
389 }
390 else
391 {
392 std::cout << "No volume " << osname.str() << std::endl;
393 return 0;
394 }
395}
396
397TGeoVolume* EmcROOTGeo::GetVolumeCrystal( int part, int phi, int theta ) {
398 // part0phi0theta0-34, part0phi6theta0-34, part0phi8theta0-34, part0phi7theta0-34
399 // part1theta0-43
400 std::stringstream osname;
401 if ( part == 1 && theta >= 0 && theta < 44 )
402 {
403 osname << "logical"
404 << "Emc"
405 << "Part" << part << "Theta" << theta << "Crystal";
406 return GetLogicalVolume( osname.str() );
407 }
408 else if ( part == 0 && theta >= 0 && theta < 35 &&
409 ( phi == 0 || phi == 6 || phi == 8 || phi == 7 ) )
410 {
411 osname << "logical"
412 << "Emc"
413 << "Part" << part << "Phi" << phi << "Theta" << theta << "Crystal";
414 return GetLogicalVolume( osname.str() );
415 }
416 else
417 {
418 std::cout << "No volume " << osname.str() << std::endl;
419 return 0;
420 }
421}
422
423TGeoNode* EmcROOTGeo::GetPart( int part ) {
424 std::stringstream osname;
425 if ( part == 1 ) { osname << "pv_logicalBSCWorld_2"; }
426 else { osname << "pv_logicalEndWorld_" << 1 - part / 2; }
427 // osname << "pv_" << "logical" << "Emc" << "Part" << (part == 2 ? (part -2) : part) << "_"
428 // << part;
429
430 return GetNode( osname.str() );
431}
432
433TGeoNode* EmcROOTGeo::GetPhi( int part, int phi ) {
434 int phiNb = -1;
435 std::stringstream osname;
436 if ( part == 1 )
437 { // barrel
438 phiNb = 308 - phi;
439 osname << "pv_logicalBSCPhi_" << phiNb;
440 }
441 else
442 { // endcap
443 if ( phi >= 0 && phi < 6 ) { osname << "pv_logicalEndPhi0_" << 15 - phi; }
444 else if ( phi >= 8 && phi < 14 ) { osname << "pv_logicalEndPhi0_" << 17 - phi; }
445 else if ( phi == 6 || phi == 14 ) { osname << "pv_logicalEndPhi1_" << ( 30 - phi ) / 8; }
446 else if ( phi == 7 || phi == 15 ) { osname << "pv_logicalEndPhi2_" << ( 15 - phi ) / 8; }
447 }
448 // osname << "pv_" << "logical" << "Emc" << "Part" << (part == 2 ? (part -2) : part) << "Phi"
449 // << phi << "_" << phi;
450
451 return GetNode( osname.str() );
452}
453
454TGeoNode* EmcROOTGeo::GetTheta( int part, int phi, int theta ) {
455 if ( m_NodeTheta[part][phi][theta] != 0 ) { return m_NodeTheta[part][phi][theta]; }
456 else
457 {
458 std::cout << "Node: "
459 << "Part" << part << "Phi" << phi << "Theta" << theta << " not found"
460 << std::endl;
461 return 0;
462 }
463}
464
465TGeoNode* EmcROOTGeo::GetCrystal( int part, int phi, int theta ) {
466 // in fact, br only 44 crystal nodes;
467 return GetTheta( part, phi, theta )->GetDaughter( 0 );
468}
469
470TGeoPhysicalNode* EmcROOTGeo::GetPhysicalCrystal( int part, int phi, int theta ) {
471 if ( m_PhysicalCrystal[part][phi][theta] != 0 )
472 { return m_PhysicalCrystal[part][phi][theta]; }
473 else
474 {
475 std::cout << "PhysicalNode: "
476 << "Part" << part << "Phi" << phi << "Theta" << theta << " not found"
477 << std::endl;
478 return 0;
479 }
480}
TGeoVolume * GetVolumeCrystal(int part, int phi, int theta)
Get crystal volume;.
TGeoNode * GetCrystal(int part, int phi, int theta)
Get crystal one;.
void InitFromGdml(const char *gdmlFile, const char *setupName)
Initialize the instance of ROOTGeo.
TGeoVolume * GetVolumeTheta(int part, int phi, int theta)
Get theta volume;.
TGeoNode * GetTheta(int part, int phi, int theta)
Get theta node;.
TGeoVolume * GetVolumePart(int part)
Get part volume;.
TGeoNode * GetPart(int part)
Get part node;.
void SetDefaultVis()
Set default visual attributes;.
int GetPhiNb(int part)
Get number of phi on part;.
TGeoVolume * GetVolumePhi(int part, int phi)
Get phi volume;.
void SetPhysicalNode()
Set the pointers to the physical nodes;.
void SetNode()
Set the pointers to theirs nodes;.
int GetThetaNb(int part)
Get number of theta on part;.
TGeoNode * GetPhi(int part, int phi)
Get phi node;.
TGeoPhysicalNode * GetPhysicalCrystal(int part, int phi, int theta)
Get crystal physical node;.
void SetQuarterVisible()
Set quater visible;.
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.