Skip to content
Snippets Groups Projects

CAD conversion tools and procedure

Merged Eoin Clerkin requested to merge e.clerkin/cbmroot:CAD2ROOT into master
All threads resolved!
Files
7
/* Copyright (C) 2018-2021 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
/* Copyright (C) 2018-2023 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
SPDX-License-Identifier: GPL-3.0-only
Authors: Florian Uhlig [committer] */
Authors: Florian Uhlig [committer], Eoin Clerkin */
#include "CbmGeometryUtils.h"
@@ -408,5 +408,80 @@ namespace Cbm
covYY = rc10 * r10 + rc11 * r11;
}
/* 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;
};
} // namespace GeometryUtils
} // namespace Cbm
Loading