23#include <TGeoManager.h>
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;
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;
71 gErrorIgnoreLevel = kFatal;
77 if(!m_Emc) std::cout <<
"m_Emc = 0" << std::endl;
78 else cout<<
"Find logicalEMC!"<<endl;
80 for (
int part = 0; part < m_kPart; part++) {
83 int nPhi = (part == 1 ? m_kPhiBr : m_kPhiEc);
85 for (
int phi = 0; phi <
nPhi; phi++) {
87 int nTheta = (part == 1 ? 219 : m_kThetaEc);
88 TGeoNode *nodePhi =
GetPhi(part,phi);
91 for (
int theta = 0; theta < nTheta; theta++) {
92 string name = nodePhi->GetDaughter(theta)->GetName();
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);
101 istringstream thetaBuf(strthe);
105 m_NodeTheta[part][phi][nthe] = nodePhi->GetDaughter(theta);
121 int brCrystalColor = 4;
122 int ecCrystalColor = 7;
124 m_Emc->SetLineColor(emcColor);
125 m_Emc->SetVisibility(0);
127 for (
int part = 0; part < m_kPart-1; part++) {
129 int nPhi = (part == 1 ? m_kPhiBr : m_kPhiEc);
130 for (
int phi = 0; phi <
nPhi; phi++) {
135 for (
int theta = 0; theta < m_kThetaBr; theta++) {
142 else if (part == 0) {
143 int iPhi[4] = {0,6,8,7};
144 for (
int i = 0; i < 4; i++) {
146 int nTheta = (part == 1 ? m_kThetaBr : m_kThetaEc);
147 for (
int theta = 0; theta < nTheta; theta++) {
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);
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);
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)) ||
250 GetCrystal(part, phi, theta)->SetVisibility(1);
253 GetCrystal(part, phi, theta)->SetVisibility(0);
268 gErrorIgnoreLevel = kFatal;
270 if (gGeoManager == 0) std::cout <<
"Create gGeoManager first" << std::endl;
271 else cout<<
"gGeoManager success!"<<endl;
274 if(!volEmc) std::cout <<
"logicalEMC not found !" << std::endl;
279 TGeoIdentity *identity =
new TGeoIdentity();
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);
290 gGeoManager->SetDrawExtraPaths();
291 gGeoManager->CloseGeometry();
292 gGeoManager->SetNsegments(20);
295 TGeoNode *
bes = gGeoManager->GetTopNode();
296 TGeoNode *emc =
bes->GetDaughter(0);
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++) {
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);
336 int thetaNb = m_kThetaBr;
337 if (part != 1) thetaNb = m_kThetaEc;
345 int phiNb = m_kPhiBr;
346 if (part != 1) phiNb = m_kPhiEc;
355 std::stringstream osname;
356 osname <<
"logical" <<
"Emc" <<
"Part" << part;
357 if (part == 0 || part == 1) {
361 std::cout <<
"No volume " << osname.str() << std::endl;
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) ) {
377 std::cout <<
"No volume " << osname.str() << std::endl;
387 std::stringstream osname;
388 if (part == 1 && theta >= 0 && theta < 44) {
389 osname <<
"logical" <<
"Emc" <<
"Part" << part <<
"Theta" << theta;
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;
398 std::cout <<
"No volume " << osname.str() << std::endl;
408 std::stringstream osname;
409 if (part == 1 && theta >= 0 && theta < 44) {
410 osname <<
"logical" <<
"Emc" <<
"Part" << part <<
"Theta" << theta <<
"Crystal";
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";
419 std::cout <<
"No volume " << osname.str() << std::endl;
427 std::stringstream osname;
429 osname <<
"pv_logicalBSCWorld_2";
431 osname <<
"pv_logicalEndWorld_" << 1-part/2;
435 return GetNode( osname.str() );
442 std::stringstream osname;
445 osname <<
"pv_logicalBSCPhi_" << phiNb;
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;
459 return GetNode( osname.str() );
465 if (m_NodeTheta[part][phi][theta] != 0) {
466 return m_NodeTheta[part][phi][theta];
469 std::cout <<
"Node: " <<
"Part" << part <<
"Phi" << phi <<
"Theta" << theta <<
" not found" << std::endl;
478 return GetTheta(part, phi, theta)->GetDaughter(0);
484 if (m_PhysicalCrystal[part][phi][theta] != 0) {
485 return m_PhysicalCrystal[part][phi][theta];
488 std::cout <<
"PhysicalNode: " <<
"Part" << part <<
"Phi" << phi <<
"Theta" << theta <<
" not found" << std::endl;
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;.
int GetPartNb()
Get number of part;.
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;.
void SetAllVisible()
Set all visible;.
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 * GetTopVolume()
Get the top(world) volume;.
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.
void SetChildNo(int childNo)