00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 using namespace std;
00015
00016 #include <string>
00017 #include <fstream>
00018 #include <iostream>
00019 #include <sstream>
00020 #include <vector>
00021 #include <iomanip>
00022 #include <stdlib.h>
00023 #include <TGeoManager.h>
00024
00025 #include "ROOTGeo/EmcROOTGeo.h"
00026
00027
00028 EmcROOTGeo::EmcROOTGeo()
00029 {
00030
00031 m_kPhiEc = 16;
00032 m_kThetaEc = 35;
00033
00034 for (int part = 0; part < m_kPart; part++) {
00035 for (int phi = 0; phi < m_kPhiBr; phi++) {
00036 for (int theta = 0; theta < m_kThetaBr; theta++) {
00037 m_NodeTheta[part][phi][theta] = 0;
00038 m_PhysicalCrystal[part][phi][theta] = 0;
00039 }
00040 }
00041 }
00042
00043 string GdmlManagementPath = getenv("GDMLMANAGEMENTROOT");
00044 if (GdmlManagementPath == "") cout << "EmcROOTGeo::GdmlManagementPath not set!" << endl;
00045 string GdmlFile = GdmlManagementPath + string("/dat/Emc.gdml");
00046 cout << "Construct Emc from GdmlFile " << GdmlFile << endl;
00047 InitFromGdml( GdmlFile.c_str(), "Emc" );
00048 }
00049
00050 EmcROOTGeo::~EmcROOTGeo()
00051 { }
00052
00053 void
00054 EmcROOTGeo::InitFromGdml( const char *gdmlFile, const char *setupName )
00055 {
00056 ReadGdml(gdmlFile, setupName);
00057 SetNode();
00058
00059
00060 m_ROOTGeoInit = 1;
00061 }
00062
00063 void
00064 EmcROOTGeo::SetNode()
00065 {
00066 m_Emc = GetTopVolume();
00067 if(!m_Emc) {
00068 m_Emc = GetLogicalVolume("logicalEMC");
00069 }
00070 if(!m_Emc) std::cout << "m_Emc = 0" << std::endl;
00071 else cout<<"Find logicalEMC!"<<endl;
00072
00073 for (int part = 0; part < m_kPart; part++) {
00074
00075
00076 int nPhi = (part == 1 ? m_kPhiBr : m_kPhiEc);
00077
00078 for (int phi = 0; phi < nPhi; phi++) {
00079
00080 int nTheta = (part == 1 ? 219 : m_kThetaEc);
00081 TGeoNode *nodePhi = GetPhi(part,phi);
00082
00083
00084 for (int theta = 0; theta < nTheta; theta++) {
00085 string name = nodePhi->GetDaughter(theta)->GetName();
00086 int nthe=-1;
00087 string strthe;
00088 if(name.find("BSCCasing",0)==7) {
00089 strthe = name.substr(16,2);
00090 } else if(name.find("EndCasing",0)==7) {
00091 strthe = name.substr(19,2);
00092 }
00093
00094 istringstream thetaBuf(strthe);
00095 thetaBuf >> nthe;
00096
00097 if(nthe>=0) {
00098 m_NodeTheta[part][phi][nthe] = nodePhi->GetDaughter(theta);
00099 }
00100 }
00101 }
00102 }
00103
00104 }
00105
00106 void
00107 EmcROOTGeo::SetDefaultVis()
00108 {
00109
00110 int emcColor = 2;
00111 int partColor = 2;
00112 int phiColor = 4;
00113 int thetaColor = 4;
00114 int brCrystalColor = 4;
00115 int ecCrystalColor = 7;
00116
00117 m_Emc->SetLineColor(emcColor);
00118 m_Emc->SetVisibility(0);
00119
00120 for (int part = 0; part < m_kPart-1; part++) {
00121 GetVolumePart(part)->SetLineColor(partColor);
00122 int nPhi = (part == 1 ? m_kPhiBr : m_kPhiEc);
00123 for (int phi = 0; phi < nPhi; phi++) {
00124 GetVolumePhi(part, phi)->SetLineColor(phiColor);
00125 GetVolumePhi(part, phi)->SetVisibility(0);
00126 }
00127 if (part == 1) {
00128 for (int theta = 0; theta < m_kThetaBr; theta++) {
00129 GetVolumeTheta(part, 0, theta)->SetLineColor(thetaColor);
00130 GetVolumeTheta(part, 0, theta)->SetVisibility(0);
00131 GetVolumeCrystal(part, 0, theta)->SetLineColor(brCrystalColor);
00132 GetVolumeCrystal(part, 0, theta)->SetVisibility(1);
00133 }
00134 }
00135 else if (part == 0) {
00136 int iPhi[4] = {0,6,8,7};
00137 for (int i = 0; i < 4; i++) {
00138 int phi = iPhi[i];
00139 int nTheta = (part == 1 ? m_kThetaBr : m_kThetaEc);
00140 for (int theta = 0; theta < nTheta; theta++) {
00141 GetVolumeTheta(part, phi, theta)->SetLineColor(thetaColor);
00142 GetVolumeTheta(part, phi, theta)->SetVisibility(0);
00143 GetVolumeCrystal(part, phi, theta)->SetLineColor(ecCrystalColor);
00144 GetVolumeCrystal(part, phi, theta)->SetVisibility(1);
00145 }
00146 }
00147 }
00148 }
00149
00150 for (int part = 0; part < m_kPart; part++) {
00151 GetPart(part)->SetVisibility(0);
00152 int nPhi = (part == 1 ? m_kPhiBr : m_kPhiEc);
00153 for (int phi = 0; phi < nPhi; phi++) {
00154 GetPhi(part, phi)->SetVisibility(0);
00155 int nTheta = (part == 1 ? m_kThetaBr : m_kThetaEc);
00156 for (int theta = 0; theta < nTheta; theta++) {
00157 GetTheta(part, phi, theta)->SetVisibility(0);
00158 GetCrystal(part, phi, theta)->SetVisibility(0);
00159 }
00160 }
00161 }
00162
00163 }
00164
00165 void
00166 EmcROOTGeo::SetAllVisible()
00167 {
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193 for (int part = 0; part < m_kPart; part++) {
00194 GetPart(part)->SetVisibility(0);
00195 int nPhi = (part == 1 ? m_kPhiBr : m_kPhiEc);
00196 for (int phi = 0; phi < nPhi; phi++) {
00197 GetPhi(part, phi)->SetVisibility(0);
00198 int nTheta = (part == 1 ? m_kThetaBr : m_kThetaEc);
00199 for (int theta = 0; theta < nTheta; theta++) {
00200 GetTheta(part, phi, theta)->SetVisibility(0);
00201 GetCrystal(part, phi, theta)->SetVisibility(1);
00202 }
00203 }
00204 }
00205 }
00206
00207 void
00208 EmcROOTGeo::SetQuarterVisible()
00209 {
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233 for (int part = 0; part < m_kPart; part++) {
00234 GetPart(part)->SetVisibility(0);
00235 int nPhi = (part == 1 ? m_kPhiBr : m_kPhiEc);
00236 for (int phi = 0; phi < nPhi; phi++) {
00237 GetPhi(part, phi)->SetVisibility(0);
00238 int nTheta = (part == 1 ? m_kThetaBr : m_kThetaEc);
00239 for (int theta = 0; theta < nTheta; theta++) {
00240 GetTheta(part, phi, theta)->SetVisibility(0);
00241 if ( (part == 1 && (phi >= 0 && phi < nPhi/4)) ||
00242 (part != 1) ) {
00243 GetCrystal(part, phi, theta)->SetVisibility(1);
00244 }
00245 else {
00246 GetCrystal(part, phi, theta)->SetVisibility(0);
00247 }
00248 }
00249 }
00250 }
00251
00252 }
00253
00254 void
00255 EmcROOTGeo::SetPhysicalNode()
00256 {
00257
00258
00259
00260 if (gGeoManager == 0) std::cout << "Create gGeoManager first" << std::endl;
00261 else cout<<"gGeoManager success!"<<endl;
00262
00263 TGeoVolume *volEmc = GetLogicalVolume("logicalEMC");
00264 if(!volEmc) std::cout << "logicalEMC not found !" << std::endl;
00265
00266
00267 float m_BesR = 5200;
00268 float m_BesZ = 5680;
00269 TGeoIdentity *identity = new TGeoIdentity();
00270
00271 TGeoMaterial *mat = new TGeoMaterial("VOID",0,0,0);
00272 TGeoMedium *med = new TGeoMedium("MED",1,mat);
00273 TGeoVolume *m_Bes = gGeoManager->MakeBox("volBes", med,
00274 0.5*m_BesR, 0.5*m_BesR, 0.5*m_BesZ);
00275 gGeoManager->SetTopVolume(m_Bes);
00276 m_Bes->AddNode(volEmc, 0, identity);
00277
00278 SetChildNo(m_Bes->GetNdaughters()-1);
00279
00280 gGeoManager->SetDrawExtraPaths();
00281 gGeoManager->CloseGeometry();
00282 gGeoManager->SetNsegments(20);
00283
00284
00285 TGeoNode *bes = gGeoManager->GetTopNode();
00286 TGeoNode *emc = bes->GetDaughter(0);
00287
00288 for (int part = 0; part < m_kPart; part++) {
00289 TGeoNode *nodePart = GetPart(part);
00290 int nPhi = (part == 1 ? m_kPhiBr : m_kPhiEc);
00291 for (int phi = 0; phi < nPhi; phi++) {
00292 TGeoNode *nodePhi = GetPhi(part, phi);
00293 int nTheta = (part == 1 ? m_kThetaBr : m_kThetaEc);
00294 for (int theta = 0; theta < nTheta; theta++) {
00295
00296 TGeoNode *nodeTheta = GetTheta(part, phi, theta);
00297 TGeoNode *nodeCrystal = GetCrystal(part, phi, theta);
00298 TString strPath = TString("/") + bes->GetName() +
00299 TString("/") + emc->GetName() +
00300 TString("/") + nodePart->GetName() +
00301 TString("/") + nodePhi->GetName() +
00302 TString("/") + nodeTheta->GetName() +
00303 TString("/") + nodeCrystal->GetName();
00304 m_PhysicalCrystal[part][phi][theta] = gGeoManager->MakePhysicalNode(strPath);
00305
00306
00307
00308
00309
00310 }
00311 }
00312 }
00313 }
00314
00315 int
00316 EmcROOTGeo::GetPartNb()
00317 {
00318 int part = m_kPart;
00319
00320 return part;
00321 }
00322
00323 int
00324 EmcROOTGeo::GetThetaNb(int part)
00325 {
00326 int thetaNb = m_kThetaBr;
00327 if (part != 1) thetaNb = m_kThetaEc;
00328
00329 return thetaNb;;
00330 }
00331
00332 int
00333 EmcROOTGeo::GetPhiNb(int part)
00334 {
00335 int phiNb = m_kPhiBr;
00336 if (part != 1) phiNb = m_kPhiEc;
00337
00338 return phiNb;
00339 }
00340
00341 TGeoVolume*
00342 EmcROOTGeo::GetVolumePart( int part )
00343 {
00344
00345 std::stringstream osname;
00346 osname << "logical" << "Emc" << "Part" << part;
00347 if (part == 0 || part == 1) {
00348 return GetLogicalVolume( osname.str() );
00349 }
00350 else {
00351 std::cout << "No volume " << osname.str() << std::endl;
00352 return 0;
00353 }
00354 }
00355
00356 TGeoVolume*
00357 EmcROOTGeo::GetVolumePhi( int part, int phi )
00358 {
00359
00360 std::stringstream osname;
00361 osname << "logical" << "Emc" << "Part" << part << "Phi" << phi;
00362 if ( (part == 0 && phi >= 0 && phi < 16) ||
00363 (part == 1 && phi >= 0 && phi < 120) ) {
00364 return GetLogicalVolume( osname.str() );
00365 }
00366 else {
00367 std::cout << "No volume " << osname.str() << std::endl;
00368 return 0;
00369 }
00370 }
00371
00372 TGeoVolume*
00373 EmcROOTGeo::GetVolumeTheta( int part, int phi, int theta )
00374 {
00375
00376
00377 std::stringstream osname;
00378 if (part == 1 && theta >= 0 && theta < 44) {
00379 osname << "logical" << "Emc" << "Part" << part << "Theta" << theta;
00380 return GetLogicalVolume( osname.str() );
00381 }
00382 else if ( part == 0 && theta >= 0 && theta < 35 &&
00383 (phi == 0 || phi == 6 || phi == 8 || phi == 7) ) {
00384 osname << "logical" << "Emc" << "Part" << part << "Phi" << phi << "Theta" << theta;
00385 return GetLogicalVolume( osname.str() );
00386 }
00387 else {
00388 std::cout << "No volume " << osname.str() << std::endl;
00389 return 0;
00390 }
00391 }
00392
00393 TGeoVolume*
00394 EmcROOTGeo::GetVolumeCrystal( int part, int phi, int theta )
00395 {
00396
00397
00398 std::stringstream osname;
00399 if (part == 1 && theta >= 0 && theta < 44) {
00400 osname << "logical" << "Emc" << "Part" << part << "Theta" << theta << "Crystal";
00401 return GetLogicalVolume( osname.str() );
00402 }
00403 else if ( part == 0 && theta >= 0 && theta < 35 &&
00404 (phi == 0 || phi == 6 || phi == 8 || phi == 7) ) {
00405 osname << "logical" << "Emc" << "Part" << part << "Phi" << phi << "Theta" << theta << "Crystal";
00406 return GetLogicalVolume( osname.str() );
00407 }
00408 else {
00409 std::cout << "No volume " << osname.str() << std::endl;
00410 return 0;
00411 }
00412 }
00413
00414 TGeoNode*
00415 EmcROOTGeo::GetPart( int part )
00416 {
00417 std::stringstream osname;
00418 if(part==1) {
00419 osname << "pv_logicalBSCWorld_2";
00420 } else {
00421 osname << "pv_logicalEndWorld_" << 1-part/2;
00422 }
00423
00424
00425 return GetNode( osname.str() );
00426 }
00427
00428 TGeoNode*
00429 EmcROOTGeo::GetPhi( int part, int phi )
00430 {
00431 int phiNb = -1;
00432 std::stringstream osname;
00433 if(part==1) {
00434 phiNb = 308-phi;
00435 osname << "pv_logicalBSCPhi_" << phiNb;
00436 } else {
00437 if(phi>=0&&phi<6) {
00438 osname << "pv_logicalEndPhi0_" << 15-phi;
00439 } else if(phi>=8&&phi<14) {
00440 osname << "pv_logicalEndPhi0_" << 17-phi;
00441 } else if(phi==6||phi==14) {
00442 osname << "pv_logicalEndPhi1_" << (30-phi)/8;
00443 } else if(phi==7||phi==15) {
00444 osname << "pv_logicalEndPhi2_" << (15-phi)/8;
00445 }
00446 }
00447
00448
00449 return GetNode( osname.str() );
00450 }
00451
00452 TGeoNode*
00453 EmcROOTGeo::GetTheta( int part, int phi, int theta )
00454 {
00455 if (m_NodeTheta[part][phi][theta] != 0) {
00456 return m_NodeTheta[part][phi][theta];
00457 }
00458 else {
00459 std::cout << "Node: " << "Part" << part << "Phi" << phi << "Theta" << theta << " not found" << std::endl;
00460 return 0;
00461 }
00462 }
00463
00464 TGeoNode*
00465 EmcROOTGeo::GetCrystal( int part, int phi, int theta )
00466 {
00467
00468 return GetTheta(part, phi, theta)->GetDaughter(0);
00469 }
00470
00471 TGeoPhysicalNode*
00472 EmcROOTGeo::GetPhysicalCrystal( int part, int phi, int theta )
00473 {
00474 if (m_PhysicalCrystal[part][phi][theta] != 0) {
00475 return m_PhysicalCrystal[part][phi][theta];
00476 }
00477 else {
00478 std::cout << "PhysicalNode: " << "Part" << part << "Phi" << phi << "Theta" << theta << " not found" << std::endl;
00479 return 0;
00480 }
00481 }
00482