/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/EventDisplay/BesVisLib/BesVisLib-00-04-04/src/BesGeometry.cxx

Go to the documentation of this file.
00001 
00002 #include <iostream>
00003 #include <TGeoManager.h>
00004 #include <TGeoMaterial.h>
00005 #include <TGeoMedium.h>
00006 #include <TGeoVolume.h>
00007 #include <TGeoTube.h>
00008 #include <TGeoArb8.h>
00009 #include <TGeoMatrix.h>
00010 #include <TCanvas.h>
00011 
00012 #include "BesVisLib/BesGeometry.h"
00013 #include "BesVisLib/BesCircle2D.h"
00014 #include "BesVisLib/BesPolygon2D.h"
00015 #include "BesVisLib/Mdc2DWire.h"
00016 
00017 BesGeometry *gBesGeometry = 0;
00018 
00019 using namespace std;
00020 
00021 #ifndef __CINT__
00022 ClassImp(BesGeometry)
00023 #endif
00024 
00025 //_____________________________________________________________________________
00026 
00027 BesGeometry::BesGeometry() : TObject(),
00028         m_Bes(0),
00029         m_BeamPipe(0),
00030         m_Mdc(0),
00031         m_Tof(0),
00032         m_Emc(0),
00033         m_Muc(0),
00034         m_MdcROOTGeo(0),
00035         m_TofROOTGeo(0),
00036         m_EmcROOTGeo(0),
00037         m_MucROOTGeo(0)
00038 {
00039     // Create Bes geometry
00040     if (!gGeoManager) new TGeoManager("BesGeo", "BesGeometry");
00041     else gGeoManager-> ClearPhysicalNodes();
00042 
00043     m_BesR = 2840.0;
00044     m_BesZ = 5680.0;
00045 
00046     m_BeamPipeRMin = 31.5;
00047     m_BeamPipeRMax = 35.8;
00048     m_BeamPipeZ    = 150.0;
00049 }
00050 
00051 
00052 BesGeometry::~BesGeometry()
00053 {
00054     delete m_Bes;
00055     delete m_BeamPipe;
00056 
00057     delete m_MdcROOTGeo;
00058     delete m_TofROOTGeo;
00059     delete m_EmcROOTGeo;
00060     delete m_MucROOTGeo;
00061 }
00062 
00063 void BesGeometry::InitFromGDML(const TString fPath)
00064 {
00065     gGeoManager->SetVisOption(0);  // to show all visible volumes.
00066     gGeoManager->SetVisLevel(5);
00067 
00068     TGeoIdentity *identity = new TGeoIdentity();
00069 
00070     TGeoMaterial *mat = new TGeoMaterial("VOID",0,0,0);
00071     mat->SetTransparency(20);
00072     TGeoMedium   *med = new TGeoMedium("MED",1,mat);
00073     m_Bes = gGeoManager->MakeBox("volBes", med, m_BesR, m_BesR, 0.5*m_BesZ);
00074 
00075     TGeoVolume *topVolume = new TGeoVolume(); // temp top volume for load geometry more than once
00076     gGeoManager->SetTopVolume(topVolume);
00077     gGeoManager->SetTopVolume(m_Bes);
00078 
00079     Int_t iChildNo = 0;
00080     m_MdcROOTGeo = new MdcROOTGeo();
00081     m_MdcROOTGeo->InitFromGDML( (fPath + TString("Mdc.gdml")).Data(), "Mdc" );
00082     cout<<"in BesGeometry construct mdc1"<<endl;
00083     m_Mdc = m_MdcROOTGeo->GetVolumeMdc();
00084     if (m_Mdc)  cout << "Construct Mdc" << endl;
00085     else       cout << "Volume Mdc not found " << endl;
00086     m_Bes->AddNode(m_Mdc, iChildNo, identity);
00087     m_MdcROOTGeo->SetChildNo(iChildNo);//Connect bes with mdc, form physcialnode path.  m_Bes->GetNdaughters()-1
00088 
00089     iChildNo++;
00090     m_TofROOTGeo = new TofROOTGeo();
00091     m_TofROOTGeo->InitFromGDML( (fPath + TString("Tof.gdml")).Data(), "Tof" );
00092     cout<<"construct tof"<<endl;
00093     m_Tof = m_TofROOTGeo->GetVolumeTof();
00094     if (m_Tof)  cout << "Construct Tof" << endl;
00095     else       cout << "Volume Tof not found " << endl;
00096     m_Bes->AddNode(m_Tof, iChildNo, identity);
00097     m_TofROOTGeo->SetChildNo(iChildNo);
00098 
00099     iChildNo++;
00100     m_EmcROOTGeo = new EmcROOTGeo();
00101     m_EmcROOTGeo->InitFromGDML( (fPath + TString("Emc.gdml")).Data(), "Emc" );
00102     m_Emc = m_EmcROOTGeo->GetVolumeEmc();
00103     if (m_Emc)  cout << "Construct Emc" << endl;
00104     else       cout << "Volume Emc not found " << endl;
00105     m_Bes->AddNode(m_Emc, iChildNo, identity);
00106     m_EmcROOTGeo->SetChildNo(iChildNo);
00107 
00108     iChildNo++;
00109     m_MucROOTGeo = new MucROOTGeo();
00110     m_MucROOTGeo->InitFromGDML( (fPath + TString("Muc.gdml")).Data(), "Muc" );
00111     m_Muc = m_MucROOTGeo->GetVolumeMuc();
00112     if (m_Muc)  cout << "Construct Muc" << endl;
00113     else       cout << "Volume Muc not found " << endl;
00114     m_Bes->AddNode(m_Muc, iChildNo, identity);
00115     m_MucROOTGeo->SetChildNo(iChildNo);
00116 
00117     iChildNo++;
00118     Int_t beamPipeColor = 3;
00119     m_BeamPipe = gGeoManager->MakeTube("volBeamPipe", med, m_BeamPipeRMin, m_BeamPipeRMax, m_BeamPipeZ);
00120     m_BeamPipe->SetLineColor(beamPipeColor);
00121     m_Bes->AddNode(m_BeamPipe, iChildNo, identity);
00122 
00123     Int_t nDaughters = m_Bes->GetNodes()->GetEntries();
00124     cout << "volBes contains " << nDaughters  << " nodes : " << endl;
00125     for (Int_t i = 0; i < nDaughters; i++) {
00126         cout << i << " : " << m_Bes->GetNode(i)->GetName() << endl;
00127     }
00128 
00129     InitGeometry();
00130 }
00131 
00132 void BesGeometry::InitFromROOT(TGeoVolume *volBes)
00133 {
00134     gGeoManager->SetVisOption(0);  // to show all visible volumes.
00135     gGeoManager->SetVisLevel(5);
00136 
00137     m_Bes = volBes;
00138     m_BesR = ((TGeoBBox*)m_Bes->GetShape())->GetDX();
00139     m_BesZ = ((TGeoBBox*)m_Bes->GetShape())->GetDZ()*2.0;
00140 
00141     TGeoVolume *topVolume = new TGeoVolume();
00142     gGeoManager->SetTopVolume(topVolume);
00143     gGeoManager->SetTopVolume(m_Bes);
00144 
00145     Int_t nDaughters = m_Bes->GetNodes()->GetEntries();
00146 
00147     //cout << "volBes contains " << nDaughters  << " nodes : " << endl;
00148     //for (Int_t i = 0; i < nDaughters; i++) {
00149     //    cout << i << " : " << m_Bes->GetNode(i)->GetName() << endl;
00150     //}
00151 
00152     Int_t iChildNo = 0;
00153     m_MdcROOTGeo = new MdcROOTGeo();
00154     TGeoNode *nodeMdc = m_Bes->GetNode(iChildNo);
00155     if (nodeMdc) m_Mdc = nodeMdc->GetVolume();
00156     //else cout << "Node logicalMdc not found" << endl;
00157     //if (m_Mdc)  cout << "Set Mdc" << endl;
00158     //else       cout << "Volume Mdc not found " << endl;
00159     m_MdcROOTGeo->InitFromROOT( m_Mdc );
00160     m_MdcROOTGeo->SetChildNo(iChildNo);//Connect bes with mdc, form physcialnode path.  m_Bes->GetNdaughters()-1
00161 
00162     iChildNo++;
00163     m_TofROOTGeo = new TofROOTGeo();
00164     TGeoNode *nodeTof = m_Bes->GetNode(iChildNo);
00165     if (nodeTof) m_Tof = nodeTof->GetVolume();
00166     //else cout << "Node logicalTof not found" << endl;
00167     //if (m_Tof)  cout << "Set Tof" << endl;
00168     //else       cout << "Volume Tof not found " << endl;
00169     m_TofROOTGeo->InitFromROOT( m_Tof );
00170     m_TofROOTGeo->SetChildNo(iChildNo);
00171 
00172     iChildNo++;
00173     m_EmcROOTGeo = new EmcROOTGeo();
00174     TGeoNode *nodeEmc = m_Bes->GetNode(iChildNo);
00175     if (nodeEmc) m_Emc = nodeEmc->GetVolume();
00176     //else cout << "Node logicalEmc not found" << endl;
00177     //if (m_Emc)  cout << "Set Emc" << endl;
00178     //else       cout << "Volume Emc not found " << endl;
00179     m_EmcROOTGeo->InitFromROOT( m_Emc );
00180     m_EmcROOTGeo->SetChildNo(iChildNo);
00181 
00182     iChildNo++;
00183     m_MucROOTGeo = new MucROOTGeo();
00184     TGeoNode *nodeMuc = m_Bes->GetNode(iChildNo);
00185     if (nodeMuc) m_Muc = nodeMuc->GetVolume();
00186     //else cout << "Node logicalMuc not found" << endl;
00187     //if (m_Muc)  cout << "Set Muc" << endl;
00188     //else       cout << "Volume Muc not found " << endl;
00189     m_MucROOTGeo->InitFromROOT( m_Muc );
00190     m_MucROOTGeo->SetChildNo(iChildNo);
00191 
00192     iChildNo++;
00193     TGeoNode *nodeBeamPipe = m_Bes->GetNode(iChildNo);
00194     if (nodeBeamPipe) {
00195         m_BeamPipe = nodeBeamPipe->GetVolume();
00196         m_BeamPipe->SetLineColor(4);
00197     }
00198     //else cout << "Node volBeamPipe not found " << endl;
00199     //cout << "Set beanmpi complete" << endl;
00200     InitGeometry();
00201     //cout << "init root ok" << endl;
00202 }
00203 
00204 void BesGeometry::InitGeometry()
00205 {
00206     gGeoManager->SetDrawExtraPaths();  // draw physical node or not;
00207     gGeoManager->CloseGeometry();
00208     gGeoManager->SetNsegments(20);  // devide a circle to 20 slides
00209 
00210     // PhysicalNode necessary for fast setting node visible or not in an event
00211     // Should be set after gGeoManager closed
00212     m_MdcROOTGeo->SetPhysicalNode();    //here liang
00213     m_TofROOTGeo->SetPhysicalNode();    //here liang
00214     m_EmcROOTGeo->SetPhysicalNode();    //here liang
00215     m_MucROOTGeo->SetPhysicalNode();
00216 
00217     // 2D Geometry initialization should be after SetPhysicalNode();
00218     m_MdcROOTGeo->Init2DGeometry();    //here liang
00219     m_TofROOTGeo->Init2DGeometry();    //here liang
00220     m_EmcROOTGeo->Init2DGeometry();    //here liang
00221     m_MucROOTGeo->Init2DGeometry();
00222 
00223     Double_t  P[3*4] = {0.0};
00224 
00225     // BeamPipe
00226     Double_t beamPipeCenter[3] = {0.0, 0.0, 0.0};
00227     m_BeamPipeXY =
00228       new BesCircle2D("BeamPipe", "BeamPipe", m_BeamPipeRMin, m_BeamPipeRMax, &beamPipeCenter[0]);
00229 
00230     for (Int_t i = 0; i < 4; i++) {
00231         P[3*i]   = 0.0;
00232         if (i == 0 || i == 3) P[3*i+1] = -1.0*m_BeamPipeRMax;
00233         else P[3*i+1] = m_BeamPipeRMax;
00234         if (i == 0 || i == 1) P[3*i+2] = -1.0*m_BeamPipeZ;
00235         else P[3*i+2] = m_BeamPipeZ;
00236     }
00237     m_BeamPipeZR = new BesPolygon2D("BeamPipe", "BeamPipe", 4, &P[0]);
00238 
00239     // Auxiliary line
00240     if (!m_Bes) cout << "BesGeometry:InitGeometry, top volume m_Bes not found" << endl;
00241     TGeoBBox *besShape = (TGeoBBox*)m_Bes->GetShape();
00242     m_BesR = besShape->GetDX();
00243     m_BesZ = besShape->GetDZ()*2.0;
00244     for (Int_t i = 0; i < 4; i++) {
00245         P[3*i]   = 0.0;
00246         if (i == 0 || i == 3) P[3*i+1] = -1.0*m_BesR;
00247         else P[3*i+1] = m_BesR;
00248         if (i == 0 || i == 1) P[3*i+2] = -1.0*m_BesZ;
00249         else P[3*i+2] = m_BesZ;
00250     }
00251 
00252     m_ZRPlaneOnXY = new BesPolygon2D("ZRPlaneOnXY", "ZRPlaneOnXY", 4, &P[0]);
00253     m_ZRPlaneOnXY->SetRotatable(true);
00254     m_ZRPlaneOnXY->SetLineWidth(1);
00255     m_ZRPlaneOnXY->SetLineStyle(3);
00256     m_ZRPlaneOnXY->SetFillStyle(4000);
00257 }
00258 
00259 const char* BesGeometry::GetFilename(const char* RunPeriod)
00260 {
00261     return RunPeriod;
00262 }
00263 
00264 void BesGeometry::SetDefaultVis()
00265 {
00266     m_Bes->SetLineColor(2);
00267     m_Bes->SetVisibility(0);
00268 
00269     m_BeamPipe->SetLineColor(4);
00270     m_BeamPipe->SetVisibility(0);
00271 
00272     m_MdcROOTGeo->SetAllVisible();
00273     m_TofROOTGeo->SetAllVisible();
00274     m_EmcROOTGeo->SetAllVisible();
00275     m_MucROOTGeo->SetAllVisible();
00276 
00277 }
00278 
00279 void BesGeometry::Draw(Option_t *option)
00280 {
00281     //
00282     // BesGeometry draw function
00283     TString opt = option;
00284     opt.ToUpper();
00285 
00286     if ( opt.Contains("3D") ) {
00287         Draw3D();
00288     }
00289     else if ( opt.Contains("XY") ) {
00290         Draw2DXY();
00291     }
00292     else if ( opt.Contains("ZR") ) {
00293         Draw2DZR();
00294     }
00295 }
00296 
00297 void BesGeometry::Draw3D()
00298 {
00299     BesView *view = (BesView*)gPad->GetView();
00300 
00301     if (view && view->GetViewType() == k3DView) {
00302 
00303         if (m_MdcROOTGeo) {
00304             m_MdcROOTGeo->SetVisMdcDetector();
00305             m_MdcROOTGeo->SetVisMdcHits();
00306         }
00307 
00308         if (m_TofROOTGeo) {
00309             m_TofROOTGeo->SetVisTofDetector();
00310             m_TofROOTGeo->SetVisTofHits();
00311         }
00312 
00313         if (m_EmcROOTGeo) {
00314             m_EmcROOTGeo->SetVisEmcDetector();
00315             m_EmcROOTGeo->SetVisEmcHits();
00316         }
00317 
00318         if (m_MucROOTGeo) {
00319             m_MucROOTGeo->SetVisMucDetector();
00320             m_MucROOTGeo->SetVisMucHits();
00321         }
00322     }
00323 
00324     //if (gGeoManager) {
00325     //    cout << "gGeoManager exit" << endl;
00326     //}
00327     //else {
00328     //    cout << "gGeoManager do not exit" << endl;
00329     //}
00330 
00331     //if (m_Bes){
00332     //    cout << "m_Bes address:" << m_Bes << endl;
00333     //}
00334 
00335 
00336     //if (m_Bes) m_Bes->Draw();
00337     //if (view && view->GetVisAxis()) view->ShowAxis();
00338 }
00339 
00340 void BesGeometry::Draw2DXY()
00341 {
00342     BesView *view = (BesView*)gPad->GetView();
00343 
00344     if (view && view->GetVisBeamPipe())    m_BeamPipeXY->Draw();
00345 
00346     if (m_MdcROOTGeo) m_MdcROOTGeo->Draw("XY");
00347     if (m_TofROOTGeo) m_TofROOTGeo->Draw("XY");
00348     if (m_EmcROOTGeo) m_EmcROOTGeo->Draw("XY");
00349     if (m_MucROOTGeo) m_MucROOTGeo->Draw("XY");
00350 
00351     if (view && view->GetVisZRPlaneOnXY()) m_ZRPlaneOnXY->Draw();
00352     if (view && view->GetVisAxis())        view->ShowAxis();
00353 }
00354 
00355 void BesGeometry::Draw2DZR()
00356 {
00357     BesView *view = (BesView*)gPad->GetView();
00358 
00359     if (view && view->GetVisBeamPipe()) m_BeamPipeZR->Draw();
00360 
00361     if (m_MdcROOTGeo) m_MdcROOTGeo->Draw("ZR");
00362     if (m_TofROOTGeo) m_TofROOTGeo->Draw("ZR");
00363     if (m_EmcROOTGeo) m_EmcROOTGeo->Draw("ZR");
00364     if (m_MucROOTGeo) m_MucROOTGeo->Draw("ZR");
00365 
00366     if (view && view->GetVisAxis())     view->ShowAxis();
00367 }

Generated on Tue Nov 29 23:12:04 2016 for BOSS_7.0.2 by  doxygen 1.4.7