/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/DetectorDescription/ROOTGeo/ROOTGeo-00-00-15/src/EmcROOTGeo.cxx

Go to the documentation of this file.
00001 //$id$
00002 /*
00003  *    2004/11/29   Zhengyun You      Peking University
00004  *                 Emc Geometry General for EventDisplay
00005  *
00006  *    2004/12/11   Zhengyun You      Peking University
00007  *                 named from EmcGeo to EmcROOTGeo
00008  *                 inherit from class SubDetectorROOTGeo
00009  *
00010  *    2005/04/04   Zhengyun You      Peking University
00011  *                 Emc End geometry added
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 //#include <TGeoArb8.h>
00027 
00028 EmcROOTGeo::EmcROOTGeo()
00029 { 
00030   // Default constructor.
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   //SetDefaultVis();
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     //TGeoNode *nodePart = GetPart(part);
00075     //if(nodePart) cout<<nodePart->GetName()<<endl;
00076     int nPhi = (part == 1 ? m_kPhiBr : m_kPhiEc);
00077     
00078     for (int phi = 0; phi < nPhi; phi++) {
00079       //total number of daughters in BSCPhi is 215
00080       int nTheta = (part == 1 ? 219 : m_kThetaEc);
00081       TGeoNode *nodePhi = GetPhi(part,phi);
00082       //if(nodePhi) cout<<nodePhi->GetName()<<endl;
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   //std::cout << "end of set node" << std::endl;
00104 }
00105 
00106 void 
00107 EmcROOTGeo::SetDefaultVis()
00108 {
00109   //std::cout << "begin of set defaultvis" << std::endl;
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   //std::cout << "end of set defaultvis" << std::endl;
00163 }
00164 
00165 void
00166 EmcROOTGeo::SetAllVisible()
00167 {
00168   /*  for (int part = 0; part < m_kPart-1; part++) {
00169     int nPhi = (part == 1 ? m_kPhiBr : m_kPhiEc);
00170     for (int phi = 0; phi < nPhi; phi++) {
00171       GetVolumePhi(part, phi)->SetVisibility(1);
00172     }
00173     if (part == 1) {
00174       for (int theta = 0; theta < m_kThetaBr; theta++) {
00175         GetVolumeTheta(part, 0, theta)->SetVisibility(1);
00176         GetVolumeCrystal(part, 0, theta)->SetVisibility(0);
00177       }
00178     }
00179     else if (part == 0) {
00180       int iPhi[4] = {0,6,8,7};
00181       for (int i = 0; i < 4; i++) {
00182         int phi = iPhi[i];
00183         int nTheta = (part == 1 ? m_kThetaBr : m_kThetaEc);
00184         for (int theta = 0; theta < nTheta; theta++) {
00185           GetVolumeTheta(part, phi, theta)->SetVisibility(1);
00186           GetVolumeCrystal(part, phi, theta)->SetVisibility(0);
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   /*  for (int part = 1; part < m_kPart-1; part++) {
00211     for (int phi = 1; phi <= m_kPhiBr; phi++) {
00212       GetVolumePhi(part, phi)->SetVisibility(0);
00213     }
00214 
00215      for (int theta = 1; theta <= m_kThetaBr; theta++) {
00216        GetVolumeTheta(part, theta)->SetVisibility(1);
00217        GetVolumeCrystal(part, theta)->SetVisibility(0);
00218     }
00219   }
00220 
00221   for (int part = 1; part < m_kPart-1; part++) {
00222     for (int phi = 1; phi <= m_kPhiBr; phi++) {
00223       GetPhi(part, phi)->SetVisibility(0);
00224       for (int theta = 1; theta <= m_kThetaBr; theta++) {
00225         if (phi < m_kPhiBr/4) GetTheta(part, phi, theta)->SetVisibility(0);
00226         else                  GetTheta(part, phi, theta)->SetVisibility(1);
00227         GetCrystal(part, phi, theta)->SetVisibility(0);
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   //int brCrystalColor = 4;
00258   //int ecCrystalColor = 7;
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   //construct bes world
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   //cout<<"Ndaughters="<<m_Bes->GetNdaughters()<<endl;
00278   SetChildNo(m_Bes->GetNdaughters()-1);
00279         
00280   gGeoManager->SetDrawExtraPaths();  // draw physical node or not;
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         //cout<<part<<"\t"<<phi<<"\t"<<theta<<endl;
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         //m_PhysicalCrystal[part][phi][theta]->SetVisibility(0);
00307         //m_PhysicalCrystal[part][phi][theta]->SetIsVolAtt(kFALSE);
00308         //if (part == 1) m_PhysicalCrystal[part][phi][theta]->SetLineColor(brCrystalColor);
00309         //else           m_PhysicalCrystal[part][phi][theta]->SetLineColor(ecCrystalColor);
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   // only part0 and part1 logical volume.
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   // only part0phi0-15, part1phi0-119
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   // part0phi0theta0-34, part0phi6theta0-34, part0phi8theta0-34, part0phi7theta0-34
00376   // part1theta0-43
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   // part0phi0theta0-34, part0phi6theta0-34, part0phi8theta0-34, part0phi7theta0-34
00397   // part1theta0-43
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   //osname << "pv_" << "logical" << "Emc" << "Part" << (part == 2 ? (part -2) : part) << "_" << part; 
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) { //barrel
00434     phiNb = 308-phi;
00435     osname << "pv_logicalBSCPhi_" << phiNb;
00436   } else {  //endcap
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   //osname << "pv_" << "logical" << "Emc" << "Part" << (part == 2 ? (part -2) : part) << "Phi" << phi << "_" << phi; 
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   // in fact, br only 44 crystal nodes;
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 

Generated on Tue Nov 29 22:58:01 2016 for BOSS_7.0.2 by  doxygen 1.4.7