From 52331a298bc2e9d9cab762f37b7842ff508f8092 Mon Sep 17 00:00:00 2001
From: Eoin Clerkin <e.clerkin@gsi.de>
Date: Thu, 21 Sep 2023 22:20:18 +0200
Subject: [PATCH] Adds basic creation macro

---
 macro/geometry/cad2root/Create_Geometry.C | 83 +++++++++++++++++++++++
 1 file changed, 83 insertions(+)
 create mode 100644 macro/geometry/cad2root/Create_Geometry.C

diff --git a/macro/geometry/cad2root/Create_Geometry.C b/macro/geometry/cad2root/Create_Geometry.C
new file mode 100644
index 0000000000..4326ebbca0
--- /dev/null
+++ b/macro/geometry/cad2root/Create_Geometry.C
@@ -0,0 +1,83 @@
+/* Copyright (C) 2023 Facility for AntiProton and Ion Research in Europe, Darmstadt
+   SPDX-License-Identifier: GPL-3.0-only
+   Authors: Eoin Clerkin [committer] */
+
+/* Generic macro which creates root geometry from CAD  */
+
+#include "TROOT.h"
+#include "TSystem.h"
+#include "TGeoVolume.h"
+#include "FairGeoLoader.h"
+#include "FairGeoInterface.h"
+#include "TGeoManager.h"
+#include "TGeoSystemOfUnits.h"
+#include "TGeoTube.h"
+
+#include "TFile.h"
+#include "TGeoCompositeShape.h"
+#include "TGeoMaterial.h"
+#include "TGeoMatrix.h"
+#include "TGeoMedium.h"
+#include "TGeoPgon.h"
+#include "TList.h"
+#include "TROOT.h"
+#include "TString.h"
+#include "TSystem.h"
+
+#include <iostream>
+#include <sstream>
+#include <string.h>
+#include <stdbool.h>
+
+#include "CbmDigitize.h" // For CbmBaselibrary
+#include "CbmGeometryUtils.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");
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-- 
GitLab