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