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