diff --git a/core/base/utils/CbmGeometryUtils.cxx b/core/base/utils/CbmGeometryUtils.cxx index 40178940a7f406bd97e30fcf3db97838c6f93718..613eb97f3fae9abd060e5ddb20893bacb5c447f4 100644 --- a/core/base/utils/CbmGeometryUtils.cxx +++ b/core/base/utils/CbmGeometryUtils.cxx @@ -409,82 +409,78 @@ namespace Cbm } + /* Populate a GeoManager with the full media and materials defined to return */ + TGeoManager* pop_TGeoManager(const char* name) + { + + // Use the FairRoot geometry interface to load the media which are already defined + FairGeoLoader* geoLoad = new FairGeoLoader("TGeo", "FairGeoLoader"); + FairGeoInterface* geoFace = geoLoad->getGeoInterface(); + TString geoPath = gSystem->Getenv("VMCWORKDIR"); + TString geoFile = geoPath + "/geometry/media.geo"; + geoFace->setMediaFile(geoFile); + geoFace->readMedia(); + + // Read the required media and create them in the GeoManager + FairGeoMedia* geoMedia = geoFace->getMedia(); + FairGeoBuilder* geoBuild = geoLoad->getGeoBuilder(); + + int num = geoMedia->getListOfMedia()->GetSize(); + FairGeoMedium* med = new FairGeoMedium(); + + for (int i = 0; i < num; i++) { + med = geoMedia->getMedium(geoMedia->getListOfMedia()->At(i)->GetName()); + geoBuild->createMedium(med); + }; + + gGeoManager->SetTitle(name); + + return gGeoManager; + } + + /* Open root file geometry and add it to parent */ + bool add_binary(const char rootFile[], TGeoVolume* top, TGeoMedium* med, Int_t inum, TGeoMatrix* mat) + { + + TFile* file = TFile::Open(rootFile, "OPEN"); + if (file == NULL) { + fprintf(stderr, "Error file %s not opened\n", rootFile); + return false; + } + else { + ((TGeoVolume*) file->Get(file->GetListOfKeys()->First()->GetName()))->SetMedium(med); + top->AddNode((TGeoVolume*) (file->Get(file->GetListOfKeys()->First()->GetName()))->Clone(), inum, mat); + }; + + (top->GetNode(top->GetNodes()->Last()->GetName()))->GetVolume()->SetMedium(med); + file->Close(); + return true; + } + + /* Take in the positional matrix and return it in TGeo format */ + TGeoMatrix* cad_matrix(double XX, double XY, double XZ, double YX, double YY, double YZ, double ZX, double ZY, + double ZZ, double TX, double TY, double TZ) + { + + TGeoHMatrix* hmat = new TGeoHMatrix(); + (hmat->GetRotationMatrix())[0] = XX; + (hmat->GetRotationMatrix())[3] = XY; + (hmat->GetRotationMatrix())[6] = XZ; + + (hmat->GetRotationMatrix())[1] = YX; + (hmat->GetRotationMatrix())[4] = YY; + (hmat->GetRotationMatrix())[7] = YZ; + + (hmat->GetRotationMatrix())[2] = ZX; + (hmat->GetRotationMatrix())[5] = ZY; + (hmat->GetRotationMatrix())[8] = ZZ; + + TGeoRotation* rot = new TGeoRotation(); + rot->SetRotation(*hmat); - /* Populate a GeoManager with the full media and materials defined to return */ - TGeoManager* pop_TGeoManager(const char* name){ - - // Use the FairRoot geometry interface to load the media which are already defined - FairGeoLoader* geoLoad = new FairGeoLoader("TGeo", "FairGeoLoader"); - FairGeoInterface* geoFace = geoLoad->getGeoInterface(); - TString geoPath = gSystem->Getenv("VMCWORKDIR"); - TString geoFile = geoPath + "/geometry/media.geo"; - geoFace->setMediaFile(geoFile); - geoFace->readMedia(); - - // Read the required media and create them in the GeoManager - FairGeoMedia* geoMedia = geoFace->getMedia(); - FairGeoBuilder* geoBuild = geoLoad->getGeoBuilder(); - - int num = geoMedia->getListOfMedia()->GetSize(); - FairGeoMedium* med = new FairGeoMedium(); - - for(int i=0; i<num; i++){ - med = geoMedia->getMedium(geoMedia->getListOfMedia()->At(i)->GetName()); - geoBuild->createMedium(med); - }; - - gGeoManager->SetTitle(name); - - return gGeoManager; - } - -/* Open root file geometry and add it to parent */ -bool add_binary(const char rootFile[], TGeoVolume* top, TGeoMedium* med, Int_t inum, TGeoMatrix* mat){ - - TFile* file = TFile::Open(rootFile,"OPEN"); - if(file==NULL){ - fprintf(stderr,"Error file %s not opened\n", rootFile); - return false; - }else{ - ((TGeoVolume*)file->Get(file->GetListOfKeys()->First()->GetName()))->SetMedium(med); - top->AddNode( - (TGeoVolume *) (file->Get(file->GetListOfKeys()->First()->GetName()))->Clone(), - inum, - mat - ); - }; - - (top->GetNode(top->GetNodes()->Last()->GetName()))->GetVolume()->SetMedium(med); - file->Close(); - return true; -} - -/* Take in the positional matrix and return it in TGeo format */ -TGeoMatrix* cad_matrix( - double XX, double XY, double XZ, - double YX, double YY, double YZ, - double ZX, double ZY, double ZZ, - double TX, double TY, double TZ){ - - TGeoHMatrix* hmat = new TGeoHMatrix(); - (hmat->GetRotationMatrix())[0] = XX; - (hmat->GetRotationMatrix())[3] = XY; - (hmat->GetRotationMatrix())[6] = XZ; - - (hmat->GetRotationMatrix())[1] = YX; - (hmat->GetRotationMatrix())[4] = YY; - (hmat->GetRotationMatrix())[7] = YZ; - - (hmat->GetRotationMatrix())[2] = ZX; - (hmat->GetRotationMatrix())[5] = ZY; - (hmat->GetRotationMatrix())[8] = ZZ; - - TGeoRotation* rot = new TGeoRotation(); - rot->SetRotation(*hmat); - - TGeoCombiTrans* mat = new TGeoCombiTrans(TX/1,TY/1,TZ/1,rot); - return mat; -}; + TGeoCombiTrans* mat = new TGeoCombiTrans(TX / 1, TY / 1, TZ / 1, rot); + return mat; + }; } // namespace GeometryUtils diff --git a/core/base/utils/CbmGeometryUtils.h b/core/base/utils/CbmGeometryUtils.h index 8caf0fae0ee15c3e7a933c75c9349ff0de968948..ee93a8d10af9d082734f4090a49c569012905a46 100644 --- a/core/base/utils/CbmGeometryUtils.h +++ b/core/base/utils/CbmGeometryUtils.h @@ -37,17 +37,14 @@ namespace Cbm /// @param covYY covariance Y,Y void LocalToMasterCovarianceMatrix(const TGeoMatrix& m, Double_t& covXX, Double_t& covXY, Double_t& covYY); - /* Populate a GeoManager with the full media and materials defined to return */ + /* Populate a GeoManager with the full media and materials defined to return */ TGeoManager* pop_TGeoManager(const char* name); -/* Open root file geometry and add it to parent */ -bool add_binary(const char rootFile[], TGeoVolume* top, TGeoMedium* med, Int_t inum, TGeoMatrix* mat); + /* Open root file geometry and add it to parent */ + bool add_binary(const char rootFile[], TGeoVolume* top, TGeoMedium* med, Int_t inum, TGeoMatrix* mat); -TGeoMatrix* cad_matrix( - double XX, double XY, double XZ, - double YX, double YY, double YZ, - double ZX, double ZY, double ZZ, - double TX, double TY, double TZ); + TGeoMatrix* cad_matrix(double XX, double XY, double XZ, double YX, double YY, double YZ, double ZX, double ZY, + double ZZ, double TX, double TY, double TZ); } // namespace GeometryUtils } // namespace Cbm diff --git a/macro/geometry/cad2root/Create_Geometry.C b/macro/geometry/cad2root/Create_Geometry.C index 4326ebbca0f0e06975bc85d69b5dcfb72505f47b..282750eab1d3e77b714a2e04aa17df915f31be7f 100644 --- a/macro/geometry/cad2root/Create_Geometry.C +++ b/macro/geometry/cad2root/Create_Geometry.C @@ -4,21 +4,22 @@ /* Generic macro which creates root geometry from CAD */ -#include "TROOT.h" -#include "TSystem.h" -#include "TGeoVolume.h" -#include "FairGeoLoader.h" +#include "CbmDigitize.h" // For CbmBaselibrary +#include "CbmGeometryUtils.h" + #include "FairGeoInterface.h" -#include "TGeoManager.h" -#include "TGeoSystemOfUnits.h" -#include "TGeoTube.h" +#include "FairGeoLoader.h" #include "TFile.h" #include "TGeoCompositeShape.h" +#include "TGeoManager.h" #include "TGeoMaterial.h" #include "TGeoMatrix.h" #include "TGeoMedium.h" #include "TGeoPgon.h" +#include "TGeoSystemOfUnits.h" +#include "TGeoTube.h" +#include "TGeoVolume.h" #include "TList.h" #include "TROOT.h" #include "TString.h" @@ -26,58 +27,41 @@ #include <iostream> #include <sstream> -#include <string.h> -#include <stdbool.h> -#include "CbmDigitize.h" // For CbmBaselibrary -#include "CbmGeometryUtils.h" +#include <stdbool.h> +#include <string.h> /* Generic macro to create root geometry */ -void Create_Geometry(const char* tag = "bmon_v23a", double Tz=-287.2075){ - using namespace Cbm::GeometryUtils; - - // gGeoManager with full list of materials and media. - TGeoManager* gM = (TGeoManager*) pop_TGeoManager(tag); - - // Create a top volume (assembly) - TGeoVolume* top = new TGeoVolumeAssembly(tag); - gM->SetTopVolume(top); - - int inum=0; - - // Importing of geometries from CAD, via stl and gdml - #include "PARTS.C" - - // Everything else - #include "EXTRAS.C" - - // Writing to disk - char fileName[100]; - strcpy(fileName,tag); - strcat(fileName,".geo.root"); - TFile* output = TFile::Open(fileName,"RECREATE"); - top->Write(); // Write to fileName - TGeoTranslation* mat = new TGeoTranslation(0,0,Tz); - mat->Write(); // Write Translation - output->Close(); - - // End - printf("Successfully completed. \n"); - printf("******************************************************\n"); +void Create_Geometry(const char* tag = "bmon_v23a", double Tz = -287.2075) +{ + using namespace Cbm::GeometryUtils; + + // gGeoManager with full list of materials and media. + TGeoManager* gM = (TGeoManager*) pop_TGeoManager(tag); + + // Create a top volume (assembly) + TGeoVolume* top = new TGeoVolumeAssembly(tag); + gM->SetTopVolume(top); + + int inum = 0; + +// Importing of geometries from CAD, via stl and gdml +#include "PARTS.C" + +// Everything else +#include "EXTRAS.C" + + // Writing to disk + char fileName[100]; + strcpy(fileName, tag); + strcat(fileName, ".geo.root"); + TFile* output = TFile::Open(fileName, "RECREATE"); + top->Write(); // Write to fileName + TGeoTranslation* mat = new TGeoTranslation(0, 0, Tz); + mat->Write(); // Write Translation + output->Close(); + + // End + printf("Successfully completed. \n"); + printf("******************************************************\n"); } - - - - - - - - - - - - - - - - diff --git a/macro/geometry/cad2root/make_TGeoVolumeAssembly.C b/macro/geometry/cad2root/make_TGeoVolumeAssembly.C index acc3dd924ce327f24b2738a0b49c468740d1f152..59350850bd01261f794c5f6147428ec8feb02298 100644 --- a/macro/geometry/cad2root/make_TGeoVolumeAssembly.C +++ b/macro/geometry/cad2root/make_TGeoVolumeAssembly.C @@ -4,22 +4,20 @@ /* Macro converts a gdml script to root binary */ +#include "TGeoVolume.h" #include "TROOT.h" #include "TSystem.h" - -#include "TGeoVolume.h" //#include "TGeoVolumeAssembly.h" -#include "TGeoManager.h" -#include "TGeoSystemOfUnits.h" -#include "TGeoTube.h" - #include "TFile.h" #include "TGeoCompositeShape.h" +#include "TGeoManager.h" #include "TGeoMaterial.h" #include "TGeoMatrix.h" #include "TGeoMedium.h" #include "TGeoPgon.h" +#include "TGeoSystemOfUnits.h" +#include "TGeoTube.h" #include "TList.h" #include "TROOT.h" #include "TString.h" @@ -30,28 +28,28 @@ #include <strings.h> -void make_TGeoVolumeAssembly(const char* gdml_file){ - -char vol_file[200]; -char basename[200]; +void make_TGeoVolumeAssembly(const char* gdml_file) +{ -strcpy(basename,gdml_file); -char* c = strstr(basename,".gdml"); -*c='\0'; + char vol_file[200]; + char basename[200]; -strcpy(vol_file,gdml_file); -strcpy(strstr(vol_file,".gdml"),".root"); + strcpy(basename, gdml_file); + char* c = strstr(basename, ".gdml"); + *c = '\0'; -TGeoManager::Import(gdml_file); + strcpy(vol_file, gdml_file); + strcpy(strstr(vol_file, ".gdml"), ".root"); -TGeoVolumeAssembly* top = (TGeoVolumeAssembly *) gGeoManager->GetTopVolume(); + TGeoManager::Import(gdml_file); -TFile* output_file = TFile::Open(vol_file,"RECREATE"); + TGeoVolumeAssembly* top = (TGeoVolumeAssembly*) gGeoManager->GetTopVolume(); -top->Write(); + TFile* output_file = TFile::Open(vol_file, "RECREATE"); -output_file->Close(); + top->Write(); -printf("Successfully completed. \n"); + output_file->Close(); + printf("Successfully completed. \n"); }