From 9cfab8a301803e848e20e0441984c44917fb4fb9 Mon Sep 17 00:00:00 2001 From: Florian Uhlig <f.uhlig@gsi.de> Date: Tue, 15 Feb 2022 11:18:14 +0100 Subject: [PATCH] Fix generation of RICH geometry file Use the correct TGeo unit system. Use TVolume->Export to store the RICH volume in the ROOT file. Add the correct placement matrix according to the shift of the coordinate system. Also create the file needed for the media check. Create all needed materials prior to the import from the gdml file such that they are properly exported to the ROOT file --- macro/rich/Import_GDML_Export_ROOT.c | 106 ++++++++++++++++++++++++--- 1 file changed, 95 insertions(+), 11 deletions(-) diff --git a/macro/rich/Import_GDML_Export_ROOT.c b/macro/rich/Import_GDML_Export_ROOT.c index c4a0a31e69..64ed443c7b 100644 --- a/macro/rich/Import_GDML_Export_ROOT.c +++ b/macro/rich/Import_GDML_Export_ROOT.c @@ -1,30 +1,105 @@ void Import_GDML_Export_ROOT() { - // we need to use latest root version to work with gdml geometry - // system(string("source /usr/local/Cellar/root/6.20.04_1/bin/thisroot.sh").c_str()); - // For v17a geometries one need to use root5, one can use installation on lustre - //"source /cvmfs/fairroot.gsi.de/fairsoft/may16_root5/bin/thisroot.sh" + TString richGeoFilename = "rich_v21a.gdml"; + cout << "Importing '" << richGeoFilename << "'." << endl; - TString richGeoFilename = "rich_v17a_1e_pcarb_bcarb.gdml"; + // Load FairRunSim to ensure the correct unit system + FairRunSim* sim = new FairRunSim(); - TGeoManager* gdml = new TGeoManager("gdml", "FAIRGeom"); + // Since the GDML file does not contain any information about the materials beside the + // material name, the material have to be created prior to the import of the GDML + // geometry from the media.geo file. This is done using the FairRoot tolls - cout << "Importing '" << richGeoFilename << "'." << endl; + // ------- Load media from media file ----------------------------------- + FairGeoLoader* geoLoad = new FairGeoLoader("TGeo", "FairGeoLoader"); + FairGeoInterface* geoFace = geoLoad->getGeoInterface(); + TString geoPath = gSystem->Getenv("VMCWORKDIR"); + TString medFile = geoPath + "/geometry/media.geo"; + geoFace->setMediaFile(medFile); + geoFace->readMedia(); + + // ----------------- Get and create the required media ----------------- + FairGeoMedia* geoMedia = geoFace->getMedia(); + FairGeoBuilder* geoBuild = geoLoad->getGeoBuilder(); + + // ---> CsI + FairGeoMedium* mCsI = geoMedia->getMedium("CsI"); + if (!mCsI) Fatal("Main", "FairMedium CsI not found"); + geoBuild->createMedium(mCsI); + TGeoMedium* CsI = gGeoManager->GetMedium("CsI"); + if (!CsI) Fatal("Main", "Medium CsI not found"); + + // ---> iron + FairGeoMedium* miron = geoMedia->getMedium("iron"); + if (!miron) Fatal("Main", "FairMedium iron not found"); + geoBuild->createMedium(miron); + TGeoMedium* iron = gGeoManager->GetMedium("iron"); + if (!iron) Fatal("Main", "Medium iron not found"); + + // ---> vacuum + FairGeoMedium* mvacuum = geoMedia->getMedium("vacuum"); + if (!mvacuum) Fatal("Main", "FairMedium vacuum not found"); + geoBuild->createMedium(mvacuum); + TGeoMedium* vacuum = gGeoManager->GetMedium("vacuum"); + if (!vacuum) Fatal("Main", "Medium vacuum not found"); + + // ---> kapton + FairGeoMedium* mkapton = geoMedia->getMedium("kapton"); + if (!mkapton) Fatal("Main", "FairMedium kapton not found"); + geoBuild->createMedium(mkapton); + TGeoMedium* kapton = gGeoManager->GetMedium("kapton"); + if (!kapton) Fatal("Main", "Medium kapton not found"); + + // ---> aluminium + FairGeoMedium* mAluminium = geoMedia->getMedium("aluminium"); + if (!mAluminium) Fatal("Main", "FairMedium aluminium not found"); + geoBuild->createMedium(mAluminium); + TGeoMedium* aluminium = gGeoManager->GetMedium("aluminium"); + if (!aluminium) Fatal("Main", "Medium aluminium not found"); + + // ---> PMTglass + FairGeoMedium* mPMTglass = geoMedia->getMedium("PMTglass"); + if (!mPMTglass) Fatal("Main", "FairMedium PMTglass not found"); + geoBuild->createMedium(mPMTglass); + TGeoMedium* PMTglass = gGeoManager->GetMedium("PMTglass"); + if (!PMTglass) Fatal("Main", "Medium PMTglass not found"); + + // ---> RICHglass + FairGeoMedium* mRICHglass = geoMedia->getMedium("RICHglass"); + if (!mRICHglass) Fatal("Main", "FairMedium RICHglass not found"); + geoBuild->createMedium(mRICHglass); + TGeoMedium* RICHglass = gGeoManager->GetMedium("RICHglass"); + if (!RICHglass) Fatal("Main", "Medium RICHglass not found"); + + // ---> RICHgas_CO2_dis + FairGeoMedium* mRICHgas_CO2_dis = geoMedia->getMedium("RICHgas_CO2_dis"); + if (!mRICHgas_CO2_dis) Fatal("Main", "FairMedium RICHgas_CO2_dis not found"); + geoBuild->createMedium(mRICHgas_CO2_dis); + TGeoMedium* RICHgas_CO2_dis = gGeoManager->GetMedium("RICHgas_CO2_dis"); + if (!RICHgas_CO2_dis) Fatal("Main", "Medium RICHgas_CO2_dis not found"); + + // ---> RICHgas_CO2_dis+ + FairGeoMedium* mRICHgas_CO2_disp = geoMedia->getMedium("RICHgas_CO2_dis+"); + if (!mRICHgas_CO2_disp) Fatal("Main", "FairMedium RICHgas_CO2_dis+ not found"); + geoBuild->createMedium(mRICHgas_CO2_disp); + TGeoMedium* RICHgas_CO2_disp = gGeoManager->GetMedium("RICHgas_CO2_dis+"); + if (!RICHgas_CO2_disp) Fatal("Main", "Medium RICHgas_CO2_dis+ not found"); TGDMLParse parser; // Define your input GDML file HERE TGeoVolume* gdmlTop = parser.GDMLReadFile(richGeoFilename); TGeoVolume* rootTop = new TGeoVolumeAssembly("TOP"); + gdmlTop->Print(); gGeoManager->SetTopVolume(rootTop); // Starting from the version v18a position is defined inside the GDML file // Define your position HERE // Z coordinate for v16a = 270, for v17a = 258.75, for v18a = 0. TGeoRotation* rot = new TGeoRotation("rot", 0., 0., 0.); - TGeoCombiTrans* posrot = new TGeoCombiTrans(0., 0., 258.75, rot); // v16a - 270, v17a - 258.75, v18a - 0 + TGeoCombiTrans* posrot = new TGeoCombiTrans(0., 0., 218.75, rot); // v16a - 270, v17a - 258.75, v18a - 0 rootTop->AddNode(gdmlTop, 1, posrot); @@ -47,8 +122,17 @@ void Import_GDML_Export_ROOT() cout << "Exporting '" << richGeoOutFilename << "'." << endl; - // Define you output ROOT file HERE - TFile* outfile = new TFile(richGeoOutFilename, "RECREATE"); - rootTop->Write(); + // Export RICH geometry to the output ROOT file + gdmlTop->Export(richGeoOutFilename); + // Write the transformation matrix into the output file + TFile* outfile = new TFile(richGeoOutFilename, "UPDATE"); + posrot->Write(); outfile->Close(); + + // create medialist for this geometry + TString createmedialist = gSystem->Getenv("VMCWORKDIR"); + createmedialist += "/macro/geometry/create_medialist.C"; + std::cout << "Loading macro " << createmedialist << std::endl; + gROOT->LoadMacro(createmedialist); + gROOT->ProcessLine("create_medialist(\"\", false)"); } -- GitLab