diff --git a/external/InstallGeometry.cmake b/external/InstallGeometry.cmake
index 3d9d01342a388c8fa103e21fca49d0e112716ec6..5a759060de65e531d64faebf36a57a7e958a32f6 100644
--- a/external/InstallGeometry.cmake
+++ b/external/InstallGeometry.cmake
@@ -1,4 +1,4 @@
-set(GEOMETRY_VERSION 149fccc1c705facf407b56bcb255706fc563d4b2)
+set(GEOMETRY_VERSION 99319732d04191397dc8cd19ad963aaa86ffc075)
 
 set(GEOMETRY_SRC_URL "https://git.cbm.gsi.de/CbmSoft/cbmroot_geometry.git")
 
diff --git a/external/InstallInput.cmake b/external/InstallInput.cmake
index 700ba619fa8723ed0ddafddfc42b099d37249a55..05dc8f1feb8a56b5a349d41760641cc8524c2db8 100644
--- a/external/InstallInput.cmake
+++ b/external/InstallInput.cmake
@@ -1,4 +1,4 @@
-set(INPUT_VERSION 4adb32f264b04a8fb19532d14ff0dbe72af7c095)
+set(INPUT_VERSION 21433d7ba368f516d3665fbb9381d5ec2624d39d)
 
 set(INPUT_SRC_URL "https://git.cbm.gsi.de/CbmSoft/cbmroot_input.git")
 
diff --git a/external/InstallParameter.cmake b/external/InstallParameter.cmake
index b361ab952b9a57ed05ec8164bc96d956054d7335..69ba11575536f4a8739fe33efefe34165b3452c0 100644
--- a/external/InstallParameter.cmake
+++ b/external/InstallParameter.cmake
@@ -1,4 +1,4 @@
-set(PARAMETER_VERSION a74866722d4dae15a370aea0399349a2bb1024d6)
+set(PARAMETER_VERSION 816ea7d6984c2826442d1662627a19a56629b461)
 
 set(PARAMETER_SRC_URL "https://git.cbm.gsi.de/CbmSoft/cbmroot_parameter.git")
 
diff --git a/macro/geometry/README.md b/macro/geometry/README.md
index 0270e920d61dc2557625de07075ce84755f33fc8..eda01b2fc7d53746fb357076a897887518bdd13d 100644
--- a/macro/geometry/README.md
+++ b/macro/geometry/README.md
@@ -6,9 +6,9 @@ files which contain a TGeoManager.
 
 ## Scan Geometry (scan_geometry.C)
 
-Scan geometry travels through the root geometry hierachy of a typical root geometry binary and outputs standard information regarding the node to the screen. There are several options, some of which are commented out in the file, which allows the easy comparison of root binaries. A GRAPHVIZ file named geo.gv is also output to the working directory.
+Scan geometry travels through the root geometry hierarchy of a typical root geometry binary and outputs standard information regarding the node to the screen. There are several options, some of which are commented out in the file, which allows the easy comparison of root binaries. A GRAPHVIZ file named geo.gv is also output to the working directory.
 
-### Examing Text
+### Examining Text
 
 A typical use may be
 
@@ -22,15 +22,15 @@ to look at output on screen. To save this output to a file, something like
 root -l -q '~/cbmroot/macro/geometry/scan_geometry.C("tof_v20a_1h.geo.root")' 2>&1 1>tof_v20a_1h
 ```
 
-Outputing two files may be compared with standard unix diff such as
+Outputting two files may be compared with standard UNIX diff such as
 
 ```
 diff -y -W 200 tof_v20a_1h tof_v20b_1h | less
 ```
 
-### Examining Graphical Represetation
+### Examining Graphical Representation
 
-Sometimes, especially if the output is very large, it can be more insighted, to get the overall picture to look at a graph tree of the volumes in a geometry instead. This can be done for a single detector or indeed the whole experimental setup, e.g. test.geo.root To make a pdf graph, a basic graph may be made with a command like
+Sometimes, especially if the output is very large, it can be more insightful, to get the overall picture to look at a graph tree of the volumes in a geometry instead. This can be done for a single detector or indeed the whole experimental setup, e.g. test.geo.root To make a pdf graph, a basic graph may be made with a command like
 
 ```
 sed -n '2,$p' geo.gv | head -n -1 | sort | uniq -c | awk 'BEGIN{print "digraph {"}{printf "%s -> %s [label=\"%d\"]\n", $2, $4, $1}END{print "}"}' > geo2.gv
@@ -45,7 +45,7 @@ The macro compares the media information at execution time with the media
 information assigned to the nodes when building the detector system
 geometry. The macro is executed automatically in the CbmRoot test suite for
 all tested setups.
-If needed it can be executed also manually as decribed in the following.
+If needed it can be executed also manually as described in the following.
 If the CbmRoot run time environment is set and a geometry file
 for a CBM setup is available the macro is used  in the following way
 
@@ -54,7 +54,7 @@ root -l $VMCWORKDIR/macro/geometry/check_media.C'("setup_name")'
 The setup_name is the name of the setup used during the simulation to create
 the geometry file.
 
-This macro to check the sanity odf the full geometry is/was needed due to
+This macro to check the sanity of the full geometry is/was needed due to
 the way we build the complete CBM geometry from independent geometries of the
 several detector systems.
 When building the complete geometry it happened that the media information
@@ -107,7 +107,7 @@ To achieve this some preparatory work is needed.
 ## print_medialist.C
 
 The macro can be used to print the information which is stored in the *geometrycheck.root
-files. The output is a list of all stored nodes with the corresponing media
+files. The output is a list of all stored nodes with the corresponding media
 name. To use the macro do
 
 root -l $VMCWORKDIR/macro/geometry/print_medialist.C\(\"$VMCWORKDIR/input/geometry_check/sts_v19a_geometrycheck.root\"\)
@@ -127,19 +127,34 @@ output file example.txt
 
 ## costum_setup.sh
 
+Intended for inspection of geometry setups. At the user risk, it may also work for simulation. 
+Generates a costum-setup file for the CBM experiemnt. User is prompted which subsystem and its configuration to include. 
+The scripts only works for default geometries and is not intended to switch between geometry versions. 
+For detectors which are placed on railsystems the user will be prompted as to specify its distance to the target.
+Specifying a variable like PSD_INCLUDE=1 will skip question relating to including the PSD, allowing a user to predefine a configuration skip.
+
+Suggested command to create costum setup file:  
+
+   sh costum-setup.sh
+
+Creates the run_transport_costum.C and run_reco_costum.C to use the setup_sis100_auto instead of setup_sis100_electron as default.
+
+Questions may be skipped by specifying to include a subsystem MAG_INCLUDE=1 or exclude MAG_INCLUDE=0. To a limited extent some subsystem
+detectors may be specified such as MAG_TAG="v20a".
+
 ---
 
 ## switch_defaults.sh
 
 This script switches between official and trial versions of the CBMROOT geometries. This
-is intended for use by a expert user, who will remember to swith back to the official
-geometry relase (currently APR21) once the specific use case has ended. Current options
+is intended for use by a expert user, who will remember to switch back to the official
+geometry release (currently APR21) once the specific use case has ended. Current options
 include This script switches between official and trial versions of the CBMROOT geometries. This
-is intended for use by a knowledgable user, who will remember to swith back to the official
-geometry relase (currently APR21) once the specific use case has ended. Current options
+is intended for use by a knowledgeable user, who will remember to switch back to the official
+geometry release (currently APR21) once the specific use case has ended. Current options
 include
 
 * APR20 - (previous 2020 default geometries. Run old defaults with the new CBMROOT software.)
 * APR21 - (current 2021 default geometries. This is the official release geometries.
-* TEST  - (Geoemtries shift such that the center of the magnet is the origin of the CBM exp.)
+* TEST  - (Geometries shift such that the center of the magnet is the origin of the CBM exp.)
 
diff --git a/macro/geometry/switch_defaults.sh b/macro/geometry/switch_defaults.sh
index fae0ffdf5c0aff457bb0c95c9735ea73f37f83b1..d907a52ebf0b9357c901cf5973c4b7c5e4d8ff23 100644
--- a/macro/geometry/switch_defaults.sh
+++ b/macro/geometry/switch_defaults.sh
@@ -32,8 +32,8 @@ APR21_GEOTAG="875439f929577d678b86bbc243b8f99a094fd31c"
 APR21_PARATAG="fc62e1c9f2a67109e45389ed93537a7d08973ce2"
 
 # TAG FOR NEW EXPERIMENTAL GEOMETRIES. NEXT SOFTWARE RELEASE CANDIDATES
-TEST_GEOTAG="114c7830dc6b8460a8527844aa253ec0c33b414d"
-TEST_PARATAG="21bed5c5e746efdb63b696f4053b9e5f65f940a8"
+TEST_GEOTAG="ac089a58dd6ba97ebd2253be7e72f08c46679083"
+TEST_PARATAG="a80c596bae4181fdad663140d5249d09c2bac1ff"
 
 # GEOMETRY AMD PARAMETER GIT REPOSITORY
 GIT_GEOREPO="https://git.cbm.gsi.de/e.clerkin/cbmroot_geometry.git"
@@ -80,7 +80,7 @@ if (echo "${CONFIRMATION}" | sed -n '/^Yes$/!{q10}')
 then
 	echo "Yes typed!"
 	
-	sed -i 's/Double_t[[:space:]]targetZpos.*$/Double_t targetZpos = '${TARGET_Z_POS}'/' ${RUN_SRC_DIR}/run_tra_file.C;	
+	sed -i 's/Double_t[[:space:]]targetZpos.*$/Double_t targetZpos = '${TARGET_Z_POS}';/' ${RUN_SRC_DIR}/run_tra_file.C;	
 
 # Geometry Repostiory
 	cd ${GEO_SRC_DIR}
diff --git a/macro/much/CMakeLists.txt b/macro/much/CMakeLists.txt
index 1c8232fd9384842a51c61ec34e42758138729840..6635ca7e7b46a02ff21b40a63eda9966955cdcd3 100644
--- a/macro/much/CMakeLists.txt
+++ b/macro/much/CMakeLists.txt
@@ -13,7 +13,7 @@ Set(NumEvents 3)
 
 # --- Transport of UrQMD events
 Set(testname much_transport)
-add_test(${testname} ${MACRO_DIR}/run_transport.sh ${NumEvents} \"sis100_muon_lmvm\" \"muons\")
+add_test(${testname} ${MACRO_DIR}/run_transport.sh ${NumEvents} \"sis100_muon_lmvm_APR21\" \"muons\")
 SET_TESTS_PROPERTIES(${testname} PROPERTIES TIMEOUT "1200")
 SET_TESTS_PROPERTIES(${testname} PROPERTIES PASS_REGULAR_EXPRESSION "TestPassed;All ok")
 set_tests_properties(${testname} PROPERTIES FIXTURES_SETUP fixture_much_digi)
@@ -28,7 +28,7 @@ set_tests_properties(${testname} PROPERTIES FIXTURES_SETUP fixture_much_reco)
 
 # --- Reconstruction, event-by-event
 Set(testname much_reco_event)
-add_test(${testname} ${MACRO_DIR}/run_reco_event.sh ${NumEvents} \"muons\" \"sis100_muon_lmvm\" 1 1)
+add_test(${testname} ${MACRO_DIR}/run_reco_event.sh ${NumEvents} \"muons\" \"sis100_muon_lmvm_APR21\" 1 1)
 SET_TESTS_PROPERTIES(${testname} PROPERTIES TIMEOUT "1200")
 SET_TESTS_PROPERTIES(${testname} PROPERTIES PASS_REGULAR_EXPRESSION "TestPassed;All ok")
 set_tests_properties(${testname} PROPERTIES FIXTURES_REQUIRED fixture_much_reco)
diff --git a/macro/much/geometry/create_MUCH_geometry_v20c_jpsi.C b/macro/much/geometry/create_MUCH_geometry_v20c_jpsi.C
new file mode 100644
index 0000000000000000000000000000000000000000..6025b8db80ded1a23a699710176f02422a976107
--- /dev/null
+++ b/macro/much/geometry/create_MUCH_geometry_v20c_jpsi.C
@@ -0,0 +1,803 @@
+/* Copyright (C) 2020 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
+   SPDX-License-Identifier: GPL-3.0-only
+   Authors: Florian Uhlig [committer] */
+
+//
+// \file create_MUCH_geometry_v20c
+// @Author: Omveer Singh , Partha Pratim Bhaduri & Ekata Nandy
+
+
+// \brief Generates MUCH geometry in Root format.
+//#########################################################################################################################################
+// The first absorber is 28 cm low density carbon (density 1.7 g/cm^3) + 30 cm concrete.
+// The shield inside the first absorber is composed of 28 cm of Al + 30 cm of lead. Rest are made of Iron.
+// For first absorber, the opening angle of the hole in the shield is decreased from 2.9 to 2.5 degrees for first absorber.
+// The Al shields in the absorbers 2-5 have same thickness as the absorbers. The beam pipe passes through the cylindrical hole inside the shields.
+// First two stations (1,2) made up of GEM and last two stations (3,4) made up of RPC.
+// 10 mm thick Aluminium plates is used for support and cooling in the GEM modules.
+// Drift and read-out PCBs (copper coated G10 plates) have been inserted for realistic material budget for both GEM and RPC modules.
+// 5th absorber of 100 cm thick iron block (monolithic configuration)
+// 60*60*100 cm3 aluminium box with a cylindrical opening of 50 cm in diameter is used for shielding in the 5th absorber
+//###########################################################################################################################################
+
+// in root all sizes are given in cm
+
+
+#include "TClonesArray.h"
+#include "TDatime.h"
+#include "TFile.h"
+#include "TGeoBBox.h"
+#include "TGeoCompositeShape.h"
+#include "TGeoCone.h"
+#include "TGeoManager.h"
+#include "TGeoMaterial.h"
+#include "TGeoMatrix.h"
+#include "TGeoMedium.h"
+#include "TGeoPgon.h"
+#include "TGeoTube.h"
+#include "TGeoVolume.h"
+#include "TGeoXtru.h"
+#include "TList.h"
+#include "TMath.h"
+#include "TObjArray.h"
+#include "TRandom3.h"
+#include "TString.h"
+#include "TSystem.h"
+
+#include <cassert>
+#include <fstream>
+#include <iostream>
+#include <stdexcept>
+
+
+// Name of output file with geometry
+const TString tagVersion  = "_v20c";
+const TString subVersion  = "_sis100_1m_jpsi";
+const TString geoVersion  = "much";  // + tagVersion + subVersion;
+const TString FileNameSim = geoVersion + tagVersion + subVersion + ".geo.root";
+const TString FileNameGeo = geoVersion + tagVersion + subVersion + "_geo.root";
+//const TString FileNameInfo = geoVersion +  tagVersion + subVersion+".geo.info";
+
+// Names of the different used materials which are used to build the modules
+// The materials are defined in the global media.geo file
+const TString KeepingVolumeMedium = "air";
+const TString L                   = "MUCHlead";
+const TString I                   = "MUCHiron";
+const TString activemedium        = "MUCHargon";
+const TString spacermedium        = "MUCHnoryl";
+const TString LDcarbon            = "MUCHcarbonLD";   //Low density Carbon for Ist Abs
+const TString Concrete            = "MUCHconcrete";   //Concrete for Ist Abs
+const TString Al                  = "MUCHaluminium";  //Al for cooling & support purpose
+const TString copper              = "MUCHcopper";
+const TString g10                 = "MUCHG10";
+const TString RPCm                = "MUCHRPCgas";
+const TString RPCg                = "MUCHRPCglass";
+
+// Universal input parameters
+
+Double_t fMuchZ1           = 125.0;  // MuchCave Zin position [cm]
+Double_t fAcceptanceTanMin = 0.1;    // Acceptance tangent min
+Double_t fAcceptanceTanMax = 0.466;  // Acceptance tangent max
+
+//************************************************************
+
+
+// Input parameters for absorbers
+//***********************************************************
+const Int_t fAbs       = 5;
+const Int_t fNabs      = 7;  // Number of absorber pieces
+TString AbsMaterial[7] = {"LD Graphite", "LD Graphite", "Concrete", "Iron", "Iron", "Iron", "Iron"};
+// Absorber Zin position [cm] in the cave reference frame
+Double_t fAbsorberZ1[7] = {0, 16, 28, 90, 140, 190, 250};
+// Absorber thickness [cm]
+Double_t fAbsorberLz[7] = {16, 12, 30, 20, 20, 30, 100};
+Double_t safetyrad[7]   = {0.0, 0.0, 0.0, 30.0, 30.0, 30.0, 30.0};
+
+
+// Input parameters for MUCH stations
+//********************************************
+
+const Int_t fNst = 4;  // Number of stations
+// Sector-type module parameters
+// Number of sectors per layer (should be even for symmetry)
+// Needs to be fixed with actual numbers
+Int_t fNSectorsPerLayer[4]  = {16, 20, 18, 20};
+Double_t fActiveLzSector[4] = {0.3, 0.3, 0.2, 0.2};  // Active volume thickness [cm]
+Double_t fFrameLzSector[4]  = {.3, .3, 1., 1.};      // Frame thickness [cm]
+Double_t fRpcGlassDz[4]     = {0.0, 0.0, 0.2, 0.2};  //Rpc Glass thickness [cm]
+Double_t fSpacerR           = 2.0;                   // Spacer width in R [cm]
+Double_t fSpacerPhi         = 2.0;                   // Spacer width in Phi [cm]
+Double_t fOverlapR          = 2.0;                   // Overlap in R direction [cm]
+
+// Station Zceneter [cm] in  the cave reference frame
+
+Double_t fStationZ0[4] = {75, 125, 175, 235};
+Int_t fNlayers[4]      = {3, 3, 3, 3};  // Number of layers
+Int_t fDetType[4]      = {3, 3, 4, 4};  // Detector type
+Double_t fLayersDz[4]  = {10, 10, 10, 10};
+Double_t fSupportLz[4] = {1., 1., .2, .2};  //1 cm Al (cooling + support)
+Double_t fDriftDz      = 0.0035;            //35 micron copper Drift
+Double_t fG10Dz        = 0.3;               // 3 mm G10
+
+// Input parameters for beam pipe shielding
+// spans from 2.9 degree to 5.1 degree
+//Inner radius is tan(2.9) + 2 cm, extra 20 mm for clamp connection
+
+const Int_t fNshs                    = 6;
+TString ShMaterial[6]                = {"Al", "Pb", "Al", "Al", "Al", "Al"};
+Double_t fShieldZin[6]               = {125, 153.0, 215.0, 265.0, 315.0, 375.0};
+Double_t fShieldLz[6]                = {28, 30, 20, 20, 30, 100};
+Double_t fShield_AcceptanceTanMin[5] = {0.043, 0.043, 0.051, 0.051, 0.051};  // Acceptance tangent min for shield
+Double_t fShield_AcceptanceTanMax[5] = {0.1, 0.1, 0.1, 0.1, 0.1};            // Acceptance tangent max for shield
+//For the 5th absorber, a cylinder of diameter 50 cm and Z 100 cm is used.
+
+//***********************************************************
+
+// some global variables
+TGeoManager* gGeoMan = NULL;         // Pointer to TGeoManager instance
+TGeoVolume* gModules[fNabs];         // Global storage for module types
+TGeoVolume* gModules_shield[fNshs];  // Global storage for module types
+TGeoVolume* gModules_station[fNst];  // Global storage for module types
+
+// Forward declarations
+void create_materials_from_media_file();
+TGeoVolume* CreateAbsorbers(int iabs);
+TGeoVolume* CreateShields(int ishield);
+TGeoVolume* CreateStations(int ist);
+TGeoVolume* CreateLayers(int istn, int ily);
+
+
+fstream infoFile;
+void create_MUCH_geometry_v20c_jpsi()
+{
+
+
+  // -------   Open info file   -----------------------------------------------
+  TString infoFileName = FileNameSim;
+  infoFileName.ReplaceAll("root", "info");
+  infoFile.open(infoFileName.Data(), fstream::out);
+  infoFile << "MUCH geometry created with create_MUCH_geometry_v20c_jpsi.C" << endl << endl;
+  infoFile << "Global Variables: " << endl;
+  infoFile << "MuchCave Zin position = " << fMuchZ1 << " cm " << endl;
+  infoFile << "Acceptance tangent min = " << fAcceptanceTanMin << endl;
+  infoFile << "Acceptance tangent max = " << fAcceptanceTanMax << endl;
+
+  // Load needed material definition from media.geo file
+  create_materials_from_media_file();
+
+  // Get the GeoManager for later usage
+  gGeoMan = (TGeoManager*) gROOT->FindObject("FAIRGeom");
+  gGeoMan->SetVisLevel(10);
+
+  // Create the top volume
+  TGeoBBox* topbox = new TGeoBBox("", 1000., 1000., 2000.);
+  TGeoVolume* top  = new TGeoVolume("top", topbox, gGeoMan->GetMedium("air"));
+  gGeoMan->SetTopVolume(top);
+
+  TString topName = geoVersion + tagVersion + subVersion;
+
+  TGeoVolume* much = new TGeoVolumeAssembly(topName);
+  top->AddNode(much, 1);
+
+  TGeoVolume* absr = new TGeoVolumeAssembly("absorber");
+  much->AddNode(absr, 1);
+
+  TGeoVolume* shld = new TGeoVolumeAssembly("shield");
+  much->AddNode(shld, 1);
+
+  TGeoVolume* sttn = new TGeoVolumeAssembly("station");
+  much->AddNode(sttn, 1);
+
+  infoFile << endl;
+  infoFile << "                     Absorbers " << endl;
+  infoFile << "                    -----------" << endl;
+  infoFile << "Total No. of Absorbers: " << fAbs << endl;
+  infoFile << "First abosrber is divided into two halves." << endl;
+  infoFile << "First half inserted inside the Dipole Magnet." << endl;
+  infoFile << "Second half is made of Low Density Graphite + Concrete." << endl;
+  infoFile << "Total No. of Pieces: " << fNabs << endl;
+  infoFile << endl;
+  infoFile << "AbsPieces   Position[cm]   Thickness[cm]        Material" << endl;
+  infoFile << "--------------------------------------------------------------" << endl;
+
+  for (Int_t iabs = 0; iabs < fNabs; iabs++) {
+
+
+    gModules[iabs] = CreateAbsorbers(iabs);
+
+    absr->AddNode(gModules[iabs], iabs);
+  }
+
+
+  infoFile << endl;
+  infoFile << "                     Shielding " << endl;
+  infoFile << "                    -----------" << endl;
+  infoFile << "No. of Shields: " << fNshs << endl;
+  infoFile << "Inside the Abs I, Shielding divided into two parts." << endl;
+  infoFile << endl;
+  infoFile << "Shield No.   Z_In[cm]  Z_Out[cm]  R_In[cm]  R_Out[cm]   Material" << endl;
+  infoFile << "--------------------------------------------------------------" << endl;
+  for (Int_t ishi = 0; ishi < fNshs; ishi++) {
+
+
+    gModules_shield[ishi] = CreateShields(ishi);
+
+    shld->AddNode(gModules_shield[ishi], ishi);
+  }
+
+  infoFile << endl;
+  infoFile << "                     Stations " << endl;
+  infoFile << "                    ----------" << endl;
+  infoFile << "No. of Stations: " << fNst << endl;
+  infoFile << "First two stations (1,2) are made up of GEM and last two "
+              "stations (3,4) are made up of RPC."
+           << endl;
+  infoFile << "10 mm thick Al plates are used for support and cooling in the "
+              "GEM modules."
+           << endl;
+  infoFile << "2 mm thick Aluminum plates are used for support in the RPC "
+              "modules behind the active area. 10 mm thick Aluminium at the "
+              "boundaries as the frame."
+           << endl;
+  infoFile << "Drift and read-out PCBs (copper coated G10 plates) inserted for "
+              "realistic material budget for both GEM and RPC modules."
+           << endl;
+  infoFile << "#Station   #Layers     Z[cm] #Sectors ActiveLz[cm]" << endl;
+  infoFile << "--------------------------------------------------------------" << endl;
+  for (Int_t istn = 0; istn < fNst; istn++) {  // 4 Stations
+
+
+    gModules_station[istn] = CreateStations(istn);
+
+    sttn->AddNode(gModules_station[istn], istn);
+  }
+
+  gGeoMan->CloseGeometry();
+  gGeoMan->CheckOverlaps(0.0000001);
+  gGeoMan->PrintOverlaps();
+
+  gGeoMan->CheckOverlaps(0.0001, "s");
+  gGeoMan->PrintOverlaps();
+
+
+  much->Export(FileNameSim);  // an alternative way of writing the much
+
+  TFile* outfile                  = new TFile(FileNameSim, "UPDATE");
+  TGeoTranslation* much_placement = new TGeoTranslation("much_trans", 0., 0., -40.);
+  much_placement->Write();
+  outfile->Close();
+
+  outfile = new TFile(FileNameGeo, "RECREATE");
+  gGeoMan->Write();  // use this if you want GeoManager format in the output
+  outfile->Close();
+
+  //  top->Draw("ogl");
+  infoFile.close();
+}
+
+void create_materials_from_media_file()
+{
+  // 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();
+
+  FairGeoMedium* air = geoMedia->getMedium(KeepingVolumeMedium);
+  geoBuild->createMedium(air);
+
+  FairGeoMedium* MUCHiron = geoMedia->getMedium(I);
+  geoBuild->createMedium(MUCHiron);
+
+  FairGeoMedium* MUCHlead = geoMedia->getMedium(L);
+  geoBuild->createMedium(MUCHlead);
+
+  FairGeoMedium* MUCHargon = geoMedia->getMedium(activemedium);
+  geoBuild->createMedium(MUCHargon);
+
+  FairGeoMedium* MUCHnoryl = geoMedia->getMedium(spacermedium);
+  geoBuild->createMedium(MUCHnoryl);
+
+  FairGeoMedium* MUCHsupport = geoMedia->getMedium(Al);
+  geoBuild->createMedium(MUCHsupport);
+
+  FairGeoMedium* MUCHcarbonLD = geoMedia->getMedium(LDcarbon);
+  geoBuild->createMedium(MUCHcarbonLD);
+
+  FairGeoMedium* MUCHconcrete = geoMedia->getMedium(Concrete);
+  geoBuild->createMedium(MUCHconcrete);
+
+  FairGeoMedium* copperplate = geoMedia->getMedium(copper);
+  geoBuild->createMedium(copperplate);
+
+  FairGeoMedium* g10plate = geoMedia->getMedium(g10);  //G10
+  geoBuild->createMedium(g10plate);
+
+  FairGeoMedium* RPCmedium = geoMedia->getMedium(RPCm);
+  geoBuild->createMedium(RPCmedium);
+
+  FairGeoMedium* RPCmaterial = geoMedia->getMedium(RPCg);
+  geoBuild->createMedium(RPCmaterial);
+}
+
+
+TGeoVolume* CreateShields(int ish)
+{
+
+
+  TGeoMedium* iron      = gGeoMan->GetMedium(I);
+  TGeoMedium* lead      = gGeoMan->GetMedium(L);
+  TGeoMedium* Aluminium = gGeoMan->GetMedium(Al);
+
+  TString name                    = Form("shieldblock%d", ish);
+  TGeoVolumeAssembly* shieldblock = new TGeoVolumeAssembly(name);
+
+  TString conename_sh  = Form("conesh_%d", ish);
+  TString box_sh       = Form("boxsh_%d", ish);
+  TString tube_sh      = Form("tubesh_%d", ish);
+  TString ShapeName_sh = Form("Shield_%d", ish);
+
+
+  Double_t dz       = fShieldLz[ish] / 2.0;
+  Double_t globalZ1 = fShieldZin[ish];
+  Double_t globalZ2 = fShieldZin[ish] + 2 * dz;
+
+
+  Double_t rmin1 = globalZ1 * fShield_AcceptanceTanMin[ish] + 2.0;
+  Double_t rmax1 = globalZ1 * fShield_AcceptanceTanMax[ish] - 0.0001;
+  Double_t rmin2 = globalZ2 * fShield_AcceptanceTanMin[ish] + 2.0;
+  Double_t rmax2 = globalZ2 * fShield_AcceptanceTanMax[ish] - 0.0001;
+
+  if (ish < 5) {
+    infoFile << "   " << ish << "\t\t" << globalZ1 << "\t  " << globalZ2 << "\t" << rmin1 << "\t   " << rmax1 << "\t  "
+             << ShMaterial[ish] << endl;
+  }
+  else {
+    infoFile << "   " << ish << "\t\t" << globalZ1 << "\t  " << globalZ2 << "\t"
+             << "25.000"
+             << "\t   "
+             << "25.000"
+             << "\t  " << ShMaterial[ish] << endl;
+  }  //For the 5th absorber, a cylinder of diameter 50 cm is placed for the beam pipe.
+
+  if (ish == 0) {
+
+    TGeoCone* sh       = new TGeoCone(conename_sh, dz, rmin1, rmax1, rmin2, rmax2);
+    TGeoVolume* shield = new TGeoVolume("shield", sh, Aluminium);
+
+    shield->SetLineColor(7);
+    shield->SetTransparency(2);
+    TGeoTranslation* sh_trans = new TGeoTranslation("", 0., 0., globalZ1 + dz);
+    shieldblock->AddNode(shield, ish, sh_trans);
+  }
+
+  if (ish == 1) {
+    TGeoCone* sh       = new TGeoCone(conename_sh, dz, rmin1, rmax1, rmin2, rmax2);
+    TGeoVolume* shield = new TGeoVolume("shield", sh, lead);
+
+    shield->SetLineColor(kMagenta);
+    shield->SetTransparency(2);
+    TGeoTranslation* sh_trans = new TGeoTranslation("", 0., 0., globalZ1 + dz);
+    shieldblock->AddNode(shield, ish, sh_trans);
+  }
+
+  if (ish > 1 && ish < 5) {
+
+
+    TGeoCone* sh       = new TGeoCone(conename_sh, dz, rmin1, rmax1, rmin2, rmax2);
+    TGeoVolume* shield = new TGeoVolume("shield", sh, Aluminium);
+
+    shield->SetLineColor(kBlack);
+    shield->SetTransparency(2);
+    TGeoTranslation* sh_trans = new TGeoTranslation("", 0., 0., globalZ1 + dz);
+    shieldblock->AddNode(shield, ish, sh_trans);
+  }
+
+  //...............5th absorber ...............
+  if (ish == 5) {
+    TGeoBBox* box1                   = new TGeoBBox(box_sh, 30. + 0.000001, 30. + 0.000001, 50.);
+    TGeoTube* sh                     = new TGeoTube(tube_sh, 0., 25.0, 50.0);
+    TString expression_sh            = box_sh + "-" + tube_sh;
+    TGeoCompositeShape* shSupport_sh = new TGeoCompositeShape(ShapeName_sh, expression_sh);
+    TGeoVolume* SH                   = new TGeoVolume("shield", shSupport_sh, Aluminium);
+    TGeoTranslation* SH_trans        = new TGeoTranslation("", 0., 0., globalZ1 + dz);
+    SH->SetLineColor(kBlack);
+    SH->SetTransparency(2);
+    shieldblock->AddNode(SH, ish, SH_trans);
+  }
+
+  //...........................................
+
+
+  return shieldblock;
+}
+
+
+TGeoVolume* CreateAbsorbers(int i)
+{
+
+  //...........5th absorber dimensions...//
+  TVector3 posfifthabsorber;
+  Double_t x = 250.0;
+  Double_t y = 250.0;
+  Double_t z = 50.0;
+  //........5th absorber shielding dimensions........//
+  Double_t sh_x = 30.0;
+  Double_t sh_y = 30.0;
+  Double_t sh_z = 50.0;
+  //......................................//
+
+  TGeoMedium* graphite  = gGeoMan->GetMedium(LDcarbon);
+  TGeoMedium* iron      = gGeoMan->GetMedium(I);
+  TGeoMedium* concrete  = gGeoMan->GetMedium(Concrete);
+  TGeoMedium* Aluminium = gGeoMan->GetMedium(Al);
+
+  TString name                 = Form("absblock%d", i);
+  TGeoVolumeAssembly* absblock = new TGeoVolumeAssembly(name);
+
+  TString pipename = Form("beampipe_%d", i);
+  TString conename = Form("cone_%d", i);
+  TString BoxName  = Form("Box_%d", i);
+  TString BoxName1 = Form("Box1_%d", i);
+  TString BoxName2 = Form("Box2_%d", i);
+  TString BoxName3 = Form("Box3_%d", i);
+
+  TString supportShapeName = Form("Support_%d", i);
+  TString TrapName         = Form("Trap_%d", i);
+
+  Double_t dz        = fAbsorberLz[i] / 2.0;
+  Double_t globalZ1  = fAbsorberZ1[i] + fMuchZ1;
+  Double_t globalPos = globalZ1 + dz;
+  Double_t globalZ2  = fAbsorberZ1[i] + 2 * dz + fMuchZ1;
+
+  Double_t rmin1 = globalZ1 * fAcceptanceTanMin;
+  Double_t rmin2 = globalZ2 * fAcceptanceTanMin;
+  Double_t rmax1 = globalZ1 * fAcceptanceTanMax + safetyrad[i];
+  Double_t rmax2 = globalZ2 * fAcceptanceTanMax + safetyrad[i];  //
+
+  infoFile << "   " << i + 1 << "\t\t" << globalPos << "\t\t" << 2 * dz << "\t\t" << AbsMaterial[i] << endl;
+
+  // 1st part of 1st absorber LD Carbon
+  //dimensions are hardcoded
+  if (i == 0) {
+    printf("absorber %d \n", i);
+
+    TGeoTrd2* trap                = new TGeoTrd2(TrapName, 70.0, 70.0, 46.0, 71.0, dz);
+    TGeoCone* tube                = new TGeoCone(pipename, dz + 0.001, 0., rmin1, 0., rmin2);
+    TString expression            = TrapName + "-" + pipename;
+    TGeoCompositeShape* shSupport = new TGeoCompositeShape(supportShapeName, expression);
+    TGeoVolume* abs0              = new TGeoVolume("absorber", shSupport, graphite);
+    abs0->SetLineColor(kRed);
+    abs0->SetTransparency(0);
+    TGeoTranslation* abs0_trans = new TGeoTranslation("", 0., 0., globalZ1 + dz);
+    absblock->AddNode(abs0, i, abs0_trans);
+  }
+
+
+  // 2rd part of 1st absorber box (LD Carbon)
+  if (i == 1) {
+    printf("absorber %d \n", i);
+    TGeoBBox* box                 = new TGeoBBox(BoxName, 130.0, 125.0, dz);
+    TGeoCone* tube                = new TGeoCone(pipename, dz + 0.001, 0., rmin1, 0., rmin2);
+    TString expression            = BoxName + "-" + pipename;
+    TGeoCompositeShape* shSupport = new TGeoCompositeShape(supportShapeName, expression);
+
+    TGeoVolume* abs1 = new TGeoVolume("absorber", shSupport, graphite);
+    abs1->SetLineColor(kRed);
+    abs1->SetTransparency(0);
+    TGeoTranslation* abs1_trans = new TGeoTranslation("", 0., 0., globalZ1 + dz);
+    absblock->AddNode(abs1, i, abs1_trans);
+  }
+
+  // 3th part of 1st absorber box (Conc)
+  if (i == 2) {
+    printf("absorber %d \n", i);
+    TGeoBBox* box                 = new TGeoBBox(BoxName, 130.0, 125.0, dz);
+    TGeoCone* tube                = new TGeoCone(pipename, dz + 0.001, 0., rmin1, 0., rmin2);
+    TString expression            = BoxName + "-" + pipename;
+    TGeoCompositeShape* shSupport = new TGeoCompositeShape(supportShapeName, expression);
+
+    TGeoVolume* abs1 = new TGeoVolume("absorber", shSupport, concrete);
+    abs1->SetLineColor(kViolet);
+    abs1->SetTransparency(0);
+    TGeoTranslation* abs1_trans = new TGeoTranslation("", 0., 0., globalZ1 + dz);
+    absblock->AddNode(abs1, i, abs1_trans);
+  }
+
+
+  //rest of the absorbers
+  if (i > 2 && i < 6) {
+    TGeoBBox* box                 = new TGeoBBox(BoxName, rmax2, rmax2, dz);
+    TGeoCone* tube                = new TGeoCone(pipename, dz + 0.001, 0., rmin1, 0., rmin2);
+    TString expression            = BoxName + "-" + pipename;
+    TGeoCompositeShape* shSupport = new TGeoCompositeShape(supportShapeName, expression);
+
+    TGeoVolume* abs2 = new TGeoVolume("absorber", shSupport, iron);
+
+    abs2->SetLineColor(kBlue);
+    abs2->SetTransparency(2);
+
+
+    TGeoTranslation* abs_trans = new TGeoTranslation("", 0., 0., globalZ1 + dz);
+    absblock->AddNode(abs2, i, abs_trans);
+  }
+
+
+  //..............5th absorber...............................//
+  if (i == 6) {
+    printf("absorber %d \n", i);
+    TGeoBBox* box                 = new TGeoBBox(BoxName, x, y, z);
+    TGeoBBox* box1                = new TGeoBBox(BoxName1, sh_x + 0.00001, sh_y + 0.00001, sh_z);
+    TGeoTube* sh                  = new TGeoTube(BoxName3, 0., 25., 50.0);
+    TString expression            = BoxName + "-" + BoxName1;  //+"-"+BoxName2;
+    TGeoCompositeShape* shSupport = new TGeoCompositeShape(supportShapeName, expression);
+    TGeoVolume* abs1              = new TGeoVolume("absorber", shSupport, iron);
+    TGeoTranslation* abs1_trans   = new TGeoTranslation("", 0., 0., globalZ1 + dz);
+    abs1->SetLineColor(kBlue);
+    absblock->AddNode(abs1, i, abs1_trans);
+  }
+  //.........................................................//
+  return absblock;
+}
+
+TGeoVolume* CreateStations(int ist)
+{
+
+  TString stationName = Form("muchstation%02i", ist + 1);
+
+  TGeoVolumeAssembly* station = new TGeoVolumeAssembly(stationName);  //, shStation, air);
+
+  TGeoVolume* gLayer[4];
+
+  for (int ii = 0; ii < 3; ii++) {  // 3 Layers
+
+    gLayer[ii] = CreateLayers(ist, ii);
+    station->AddNode(gLayer[ii], ii);
+  }
+
+  return station;
+}
+
+
+TGeoVolume* CreateLayers(int istn, int ily)
+{
+
+  TString layerName           = Form("muchstation%02ilayer%i", istn + 1, ily + 1);
+  TGeoVolumeAssembly* volayer = new TGeoVolumeAssembly(layerName);
+
+
+  Double_t stGlobalZ0 = fStationZ0[istn] + fMuchZ1;  //z position of station center (midplane) [cm]
+  Double_t stDz       = ((fNlayers[istn] - 1) * fLayersDz[istn] + fSupportLz[istn] + 2 * fActiveLzSector[istn]) / 2.;
+  Double_t stGlobalZ2 = stGlobalZ0 + stDz;
+  Double_t stGlobalZ1 = stGlobalZ0 - stDz;
+
+  Double_t rmin = stGlobalZ1 * fAcceptanceTanMin;
+  Double_t rmax = stGlobalZ2 * fAcceptanceTanMax;
+
+
+  Double_t layerZ0       = (ily - (fNlayers[istn] - 1) / 2.) * fLayersDz[istn];
+  Double_t layerGlobalZ0 = layerZ0 + stGlobalZ0;
+  Double_t SupportDz     = fSupportLz[istn] / 2.;
+  Double_t RpcGlassDz    = fActiveLzSector[istn] / 2. + fRpcGlassDz[istn] / 2.;
+  Double_t driftDz       = RpcGlassDz + fRpcGlassDz[istn] / 2 + fDriftDz / 2.;
+  Double_t g10Dz         = driftDz + fDriftDz / 2. + fG10Dz / 2.;
+  Double_t moduleZ       = fSupportLz[istn] / 2. + fActiveLzSector[istn] / 2. + fRpcGlassDz[istn] + fDriftDz + fG10Dz;
+  Double_t RpcGlassZIn   = moduleZ - RpcGlassDz;
+  Double_t RpcGlassZOut  = moduleZ + RpcGlassDz;
+  Double_t driftZIn      = moduleZ - driftDz;
+  Double_t driftZOut     = moduleZ + driftDz;
+  Double_t g10ZIn        = moduleZ - g10Dz;
+  Double_t g10ZOut       = moduleZ + g10Dz;
+
+
+  Double_t phi0 = TMath::Pi() / fNSectorsPerLayer[istn];  // azimuthal half widh of each module
+  Double_t ymin = rmin + fSpacerR;
+  Double_t ymax = rmax;
+
+  //define the dimensions of the trapezoidal module
+  Double_t dy  = (ymax - ymin) / 2.;                                      //y (length)
+  Double_t dx1 = ymin * TMath::Tan(phi0) + fOverlapR / TMath::Cos(phi0);  // large x
+  Double_t dx2 = ymax * TMath::Tan(phi0) + fOverlapR / TMath::Cos(phi0);  // small x
+  Double_t dz  = fActiveLzSector[istn] / 2.;                              // thickness
+
+  //define the spacer dimensions
+  Double_t tg   = (dx2 - dx1) / 2 / dy;
+  Double_t dd1  = fSpacerPhi * tg;
+  Double_t dd2  = fSpacerPhi * sqrt(1 + tg * tg);
+  Double_t sdx1 = dx1 + dd2 - dd1 - 0.1;  // 0.1 cm to avoid overlaps
+  Double_t sdx2 = dx2 + dd2 + dd1;
+  Double_t sdy  = dy + fSpacerR;
+  // Double_t sdz  = dz-0.1;
+  Double_t sdz = fFrameLzSector[istn] / 2.;
+
+  //define Additional material as realistic GEM module
+  Double_t dz_sD = fDriftDz / 2.;  //35 micron copper Drift
+  Double_t dz_sG = fG10Dz / 2.;    // 3mm G10
+
+
+  infoFile << "   " << istn + 1 << "\t      " << ily + 1 << "\t\t" << layerGlobalZ0 << "\t" << fNSectorsPerLayer[istn]
+           << "\t" << fActiveLzSector[istn] << endl;
+
+
+  // Aluminum Plate (Cooling + Support)
+  TString supportAlName = Form("shStation%02iSupportAl", istn + 1);
+  TGeoTube* shSupportAl = new TGeoTube(supportAlName, rmin, rmax, SupportDz);
+
+  TString supportName1 = Form("muchstation%02ilayer%isupportAl", istn + 1, ily + 1);
+  TGeoMedium* coolMat  = gGeoMan->GetMedium(Al);
+
+  TGeoVolume* voSupport1 = new TGeoVolume(supportName1, shSupportAl, coolMat);
+  voSupport1->SetLineColor(kCyan);
+
+  TGeoTranslation* support_trans1 = new TGeoTranslation("supportName1", 0, 0, layerGlobalZ0);
+  volayer->AddNode(voSupport1, 0, support_trans1);
+
+  Double_t pos[9];
+
+  Int_t iMod = 0;
+  for (Int_t iSide = 0; iSide < 2; iSide++) {
+
+    // Now start adding the GEM modules
+    for (Int_t iModule = 0; iModule < fNSectorsPerLayer[istn]; iModule++) {
+
+      Double_t phi  = 2 * phi0 * (iModule + 0.5);  // add 0.5 to not overlap with y-axis for left-right layer separation
+      Bool_t isBack = iModule % 2;
+      Char_t cside  = (isBack == 1) ? 'b' : 'f';
+
+      // correct the x, y positions
+      pos[0] = -(ymin + dy) * sin(phi);
+      pos[1] = (ymin + dy) * cos(phi);
+
+      // different z positions for odd/even modules
+      pos[2] = (isBack ? 1 : -1) * moduleZ + layerGlobalZ0;
+      pos[3] = (isBack ? 1 : -1) * RpcGlassZIn + layerGlobalZ0;
+      pos[4] = (isBack ? 1 : -1) * RpcGlassZOut + layerGlobalZ0;
+      pos[5] = (isBack ? 1 : -1) * driftZIn + layerGlobalZ0;
+      pos[6] = (isBack ? 1 : -1) * driftZOut + layerGlobalZ0;
+      pos[7] = (isBack ? 1 : -1) * g10ZIn + layerGlobalZ0;
+      pos[8] = (isBack ? 1 : -1) * g10ZOut + layerGlobalZ0;
+
+      //cout<<pos[2]<<"  "<<pos[3]<<"  "<<pos[4]<<"  "<<pos[5]<<"   "<<pos[6]<<"   "<<pos[7]<<"     "<<pos[8]<<endl;
+      if (iSide != isBack) continue;
+      if (iModule != 0) iMod = iModule / 2;
+
+
+      TGeoMedium* argon        = gGeoMan->GetMedium(activemedium);  // active medium
+      TGeoMedium* noryl        = gGeoMan->GetMedium(spacermedium);  // spacer medium
+      TGeoMedium* SpacerRpc    = gGeoMan->GetMedium(Al);            // spacer medium
+      TGeoMedium* copperplate  = gGeoMan->GetMedium(copper);        // copper Drift medium
+      TGeoMedium* g10plate     = gGeoMan->GetMedium(g10);           // G10 medium
+      TGeoMedium* RPCglassmat  = gGeoMan->GetMedium(RPCg);          // RPC Glass
+      TGeoMedium* RPCgasmedium = gGeoMan->GetMedium(RPCm);          // RPC Gas
+
+
+      // Define and place the trapezoidal GEM module in X-Y plane
+      TGeoVolume *voActive, *voRPCback, *voRPCFront;
+      TGeoTrap* shape = new TGeoTrap(sdz, 0, 0, dy, dx1, dx2, 0, dy, dx1, dx2, 0);
+      shape->SetName(Form("shStation%02iLayer%i%cModule%03iFrameNoHole", istn, ily, cside, iModule));
+
+      TGeoTrap* shapeActive = new TGeoTrap(dz, 0, 0, dy, dx1, dx2, 0, dy, dx1, dx2, 0);
+      shapeActive->SetName(Form("shStation%02iLayer%i%cModule%03iActiveNoHole", istn, ily, cside, iModule));
+
+      if (istn < 2) {  //GEM
+        TString activeName = Form("muchstation%02ilayer%i%cactive%03igasArgon", istn + 1, ily + 1, cside, iMod + 1);
+        voActive           = new TGeoVolume(activeName, shapeActive, argon);
+        voActive->SetLineColor(kGreen);
+      }
+      else {  //RPC Active
+        TString activeName = Form("muchstation%02ilayer%i%cactive%03irpcgas", istn + 1, ily + 1, cside, iMod + 1);
+        voActive           = new TGeoVolume(activeName, shapeActive, RPCgasmedium);
+        voActive->SetLineColor(kRed);
+
+        //RPC Glass Front
+        TGeoTrap* shapeRPCfront = new TGeoTrap(dz, 0, 0, dy, dx1, dx2, 0, dy, dx1, dx2, 0);
+        shapeRPCfront->SetName(Form("shStation%02iLayer%i%cModule%03iNoHoleFront", istn, ily, cside, iModule));
+        TString NameFront = Form("muchstation%02ilayer%i%c%03irpcglassFront", istn + 1, ily + 1, cside, iMod + 1);
+        voRPCFront        = new TGeoVolume(NameFront, shapeRPCfront, RPCglassmat);
+        voRPCFront->SetLineColor(kRed);
+
+        //RPC Glass Back
+        TGeoTrap* shapeRPCback = new TGeoTrap(dz, 0, 0, dy, dx1, dx2, 0, dy, dx1, dx2, 0);
+        shapeRPCback->SetName(Form("shStation%02iLayer%i%cModule%03iNoHoleback", istn, ily, cside, iModule));
+        TString Nameback = Form("muchstation%02ilayer%i%c%03irpcglassback", istn + 1, ily + 1, cside, iMod + 1);
+        voRPCback        = new TGeoVolume(Nameback, shapeRPCback, RPCglassmat);
+        voRPCback->SetLineColor(kRed);
+      }
+
+
+      TGeoTrap *Drift[2], *G10[2], *Al;
+      TString DriftName[2], G10Name[2], AlName;
+      TGeoVolume *voDrift[2], *voG10[2];
+
+      for (int iPos = 0; iPos < 2; iPos++) {
+        Char_t cpos = (iPos == 0) ? 'i' : 'o';
+        // Define and place copper drift & G10
+        if (istn < 2) {  //GEM
+          Drift[iPos] = new TGeoTrap(dz_sD, 0, phi, sdy, sdx1, sdx2, 0, sdy, sdx1, sdx2, 0);
+          G10[iPos]   = new TGeoTrap(dz_sG, 0, phi, sdy, sdx1, sdx2, 0, sdy, sdx1, sdx2, 0);
+        }
+        else {  //RPC
+          Drift[iPos] = new TGeoTrap(dz_sD, 0, phi, dy, dx1, dx2, 0, dy, dx1, dx2, 0);
+          G10[iPos]   = new TGeoTrap(dz_sG, 0, phi, dy, dx1, dx2, 0, dy, dx1, dx2, 0);
+        }
+        Drift[iPos]->SetName(Form("shStation%02iLayer%i%cModule%03i%cDrift", istn, ily, cside, iModule, cpos));
+        DriftName[iPos] =
+          Form("muchstation%02ilayer%i%cside%03i%ccopperDrift", istn + 1, ily + 1, cside, iMod + 1, cpos);
+        voDrift[iPos] = new TGeoVolume(DriftName[iPos], Drift[iPos], copperplate);
+        voDrift[iPos]->SetLineColor(kRed);
+
+        G10[iPos]->SetName(Form("shStation%02iLayer%i%cModule%03i%cG10", istn, ily, cside, iModule, cpos));
+        G10Name[iPos] = Form("muchstation%02ilayer%i%cside%03i%cG10", istn + 1, ily + 1, cside, iMod + 1, cpos);
+        voG10[iPos]   = new TGeoVolume(G10Name[iPos], G10[iPos], g10plate);
+        voG10[iPos]->SetLineColor(28);
+      }
+
+
+      // Define the trapezoidal spacers
+      TGeoTrap* shapeFrame = new TGeoTrap(sdz, 0, 0, sdy, sdx1, sdx2, 0, sdy, sdx1, sdx2, 0);
+      shapeFrame->SetName(Form("shStation%02iLayer%i%cModule%03iFullFrameNoHole", istn, ily, cside, iModule));
+      TString expression;
+      if (istn < 2) {  //GEM
+        expression = Form("shStation%02iLayer%i%cModule%03iFullFrameNoHole-"
+                          "shStation%02iLayer%i%cModule%03iActiveNoHole",
+                          istn, ily, cside, iModule, istn, ily, cside, iModule);
+      }
+      else {  //RPC
+        expression = Form("shStation%02iLayer%i%cModule%03iFullFrameNoHole-"
+                          "shStation%02iLayer%i%cModule%03iFrameNoHole",
+                          istn, ily, cside, iModule, istn, ily, cside, iModule);
+      }
+      TGeoCompositeShape* shFrame = new TGeoCompositeShape(
+        Form("shStation%02iLayer%i%cModule%03iFinalFrameNoHole", istn, ily, cside, iModule), expression);
+      TString frameName = Form("muchstation%02ilayer%i%cframe%03i", istn + 1, ily + 1, cside, iMod + 1);
+      TGeoVolume* voFrame;
+      if (istn < 2) {
+        voFrame = new TGeoVolume(frameName, shFrame, noryl);  // add a name to the frame
+      }
+      else {
+        voFrame = new TGeoVolume(frameName, shFrame, SpacerRpc);  // add a name to the frame
+      }
+      voFrame->SetLineColor(kMagenta);
+
+
+      // Calculate the phi angle of the sector where it has to be placed
+      Double_t angle = 180. / TMath::Pi() * phi;  // convert angle phi from rad to deg
+
+
+      TGeoRotation* r2 = new TGeoRotation("r2");
+      //rotate in the vertical plane (per to z axis) with angle
+      r2->RotateZ(angle);
+
+
+      TGeoTranslation* trans[10];
+      TGeoHMatrix* incline_mod[10];
+
+      for (int i = 0; i < 8; i++) {
+        trans[i] = new TGeoTranslation("", pos[0], pos[1], pos[i + 2]);
+
+        incline_mod[i]    = new TGeoHMatrix("");
+        (*incline_mod[i]) = (*trans[i]) * (*r2);
+      }
+
+      volayer->AddNode(voActive, iMod, incline_mod[0]);  // add active volume
+      volayer->AddNode(voFrame, iMod, incline_mod[0]);   // add spacer
+      if (istn > 1) {
+        volayer->AddNode(voRPCFront, iMod, incline_mod[1]);  //Rpc Glass In
+        volayer->AddNode(voRPCback, iMod, incline_mod[2]);   //Rpc Glass Out
+      }
+
+      volayer->AddNode(voDrift[0], iMod, incline_mod[3]);  //Drift In
+      volayer->AddNode(voDrift[1], iMod, incline_mod[4]);  //Drift Out
+      volayer->AddNode(voG10[0], iMod, incline_mod[5]);    //G10 In
+      volayer->AddNode(voG10[1], iMod, incline_mod[6]);    //G10 Out
+    }
+  }
+
+  return volayer;
+}
diff --git a/macro/much/geometry/create_MUCH_geometry_v20c_lmvm.C b/macro/much/geometry/create_MUCH_geometry_v20c_lmvm.C
new file mode 100644
index 0000000000000000000000000000000000000000..3d8d42298ae74e2bbd5fc450af2c03713677e929
--- /dev/null
+++ b/macro/much/geometry/create_MUCH_geometry_v20c_lmvm.C
@@ -0,0 +1,742 @@
+/* Copyright (C) 2020 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
+   SPDX-License-Identifier: GPL-3.0-only
+   Authors: Florian Uhlig [committer] */
+
+//
+// \file create_MUCH_geometry_v20c
+// @Author: Omveer Singh , Partha Pratim Bhaduri & Ekata Nandy
+
+
+// \brief Generates MUCH geometry in Root format.
+//#########################################################################################################################################
+// The first absorber is 28 cm low density carbon (density 1.78 g/cm^3) + 30 cm concrete.
+// The shield inside the first absorber is composed of 28 cm of Al + 30 cm of lead. Rest are made of Iron.
+// For first absorber, the opening angle of the hole in the shield is decreased from 2.9 to 2.5 degrees for first absorber.
+// The Al shields in the absorbers 2-5 have same thickness as the absorbers. The beam pipe passes through the cylindrical hole inside the shields.
+// First two stations (1,2) made up of GEM and last two stations (3,4) made up of RPC.
+// 10 mm thick Aluminium plates is used for support and cooling in the GEM modules.
+// Drift and read-out PCBs (copper coated G10 plates) have been inserted for realistic material budget for both GEM and RPC modules.
+//###########################################################################################################################################
+
+// in root all sizes are given in cm
+
+
+#include "TClonesArray.h"
+#include "TDatime.h"
+#include "TFile.h"
+#include "TGeoBBox.h"
+#include "TGeoCompositeShape.h"
+#include "TGeoCone.h"
+#include "TGeoManager.h"
+#include "TGeoMaterial.h"
+#include "TGeoMatrix.h"
+#include "TGeoMedium.h"
+#include "TGeoPgon.h"
+#include "TGeoTube.h"
+#include "TGeoVolume.h"
+#include "TGeoXtru.h"
+#include "TList.h"
+#include "TMath.h"
+#include "TObjArray.h"
+#include "TRandom3.h"
+#include "TString.h"
+#include "TSystem.h"
+
+#include <cassert>
+#include <fstream>
+#include <iostream>
+#include <stdexcept>
+
+
+// Name of output file with geometry
+const TString tagVersion  = "_v20c";
+const TString subVersion  = "_sis100_1m_lmvm";
+const TString geoVersion  = "much";  // + tagVersion + subVersion;
+const TString FileNameSim = geoVersion + tagVersion + subVersion + ".geo.root";
+const TString FileNameGeo = geoVersion + tagVersion + subVersion + "_geo.root";
+//const TString FileNameInfo = geoVersion +  tagVersion + subVersion+".geo.info";
+
+// Names of the different used materials which are used to build the modules
+// The materials are defined in the global media.geo file
+const TString KeepingVolumeMedium = "air";
+const TString L                   = "MUCHlead";
+const TString I                   = "MUCHiron";
+const TString activemedium        = "MUCHargon";
+const TString spacermedium        = "MUCHnoryl";
+const TString LDcarbon            = "MUCHcarbonLD";   //Low density Carbon for Ist Abs
+const TString Concrete            = "MUCHconcrete";   //Concrete for Ist Abs
+const TString Al                  = "MUCHaluminium";  //Al for cooling & support purpose
+const TString copper              = "MUCHcopper";
+const TString g10                 = "MUCHG10";
+const TString RPCm                = "MUCHRPCgas";
+const TString RPCg                = "MUCHRPCglass";
+
+// Universal input parameters
+
+Double_t fMuchZ1           = 125.0;  // MuchCave Zin position [cm]
+Double_t fAcceptanceTanMin = 0.1;    // Acceptance tangent min
+Double_t fAcceptanceTanMax = 0.466;  // Acceptance tangent max
+
+//************************************************************
+
+
+// Input parameters for absorbers
+//***********************************************************
+const Int_t fAbs       = 4;
+const Int_t fNabs      = 6;  // Number of absorber pieces
+TString AbsMaterial[6] = {"LD Graphite", "LD Graphite", "Concrete", "Iron", "Iron", "Iron"};
+// Absorber Zin position [cm] in the cave reference frame
+Double_t fAbsorberZ1[6] = {0, 16, 28, 90, 140, 190};
+// Absorber thickness [cm]
+Double_t fAbsorberLz[6] = {16, 12, 30, 20, 20, 30};
+Double_t safetyrad[6]   = {0.0, 0.0, 0.0, 30.0, 30.0, 30.0};
+
+
+// Input parameters for MUCH stations
+//********************************************
+
+const Int_t fNst = 4;  // Number of stations
+// Sector-type module parameters
+// Number of sectors per layer (should be even for symmetry)
+// Needs to be fixed with actual numbers
+Int_t fNSectorsPerLayer[4]  = {16, 20, 18, 20};
+Double_t fActiveLzSector[4] = {0.3, 0.3, 0.2, 0.2};  // Active volume thickness [cm]
+Double_t fFrameLzSector[4]  = {.3, .3, 1., 1.};      // Frame thickness [cm]
+Double_t fRpcGlassDz[4]     = {0.0, 0.0, 0.2, 0.2};  //Rpc Glass thickness [cm]
+Double_t fSpacerR           = 2.0;                   // Spacer width in R [cm]
+Double_t fSpacerPhi         = 2.0;                   // Spacer width in Phi [cm]
+Double_t fOverlapR          = 2.0;                   // Overlap in R direction [cm]
+
+// Station Zceneter [cm] in  the cave reference frame
+
+Double_t fStationZ0[4] = {75, 125, 175, 235};
+Int_t fNlayers[4]      = {3, 3, 3, 3};  // Number of layers
+Int_t fDetType[4]      = {3, 3, 4, 4};  // Detector type
+Double_t fLayersDz[4]  = {10, 10, 10, 10};
+Double_t fSupportLz[4] = {1., 1., .2, .2};  //1 cm Al (cooling + support)
+Double_t fDriftDz      = 0.0035;            //35 micron copper Drift
+Double_t fG10Dz        = 0.3;               // 3 mm G10
+
+// Input parameters for beam pipe shielding
+// spans from 2.9 degree to 5.1 degree
+//Inner radius is tan(2.9) + 2 cm, extra 20 mm for clamp connection
+
+const Int_t fNshs                    = 5;
+TString ShMaterial[5]                = {"Al", "Pb", "Al", "Al", "Al"};
+Double_t fShieldZin[5]               = {125, 153.0, 215.0, 265.0, 315.0};
+Double_t fShieldLz[5]                = {28, 30, 20, 20, 30};
+Double_t fShield_AcceptanceTanMin[5] = {0.043, 0.043, 0.051, 0.051, 0.051};  // Acceptance tangent min for shield
+Double_t fShield_AcceptanceTanMax[5] = {0.1, 0.1, 0.1, 0.1, 0.1};            // Acceptance tangent max for shield
+
+
+//***********************************************************
+
+// some global variables
+TGeoManager* gGeoMan = NULL;         // Pointer to TGeoManager instance
+TGeoVolume* gModules[fNabs];         // Global storage for module types
+TGeoVolume* gModules_shield[fNshs];  // Global storage for module types
+TGeoVolume* gModules_station[fNst];  // Global storage for module types
+
+// Forward declarations
+void create_materials_from_media_file();
+TGeoVolume* CreateAbsorbers(int iabs);
+TGeoVolume* CreateShields(int ishield);
+TGeoVolume* CreateStations(int ist);
+TGeoVolume* CreateLayers(int istn, int ily);
+
+
+fstream infoFile;
+void create_MUCH_geometry_v20c_lmvm()
+{
+
+
+  // -------   Open info file   -----------------------------------------------
+  TString infoFileName = FileNameSim;
+  infoFileName.ReplaceAll("root", "info");
+  infoFile.open(infoFileName.Data(), fstream::out);
+  infoFile << "MUCH geometry created with create_MUCH_geometry_v20c_lmvm.C" << endl << endl;
+  infoFile << "Global Variables: " << endl;
+  infoFile << "MuchCave Zin position = " << fMuchZ1 << " cm " << endl;
+  infoFile << "Acceptance tangent min = " << fAcceptanceTanMin << endl;
+  infoFile << "Acceptance tangent max = " << fAcceptanceTanMax << endl;
+
+  // Load needed material definition from media.geo file
+  create_materials_from_media_file();
+
+  // Get the GeoManager for later usage
+  gGeoMan = (TGeoManager*) gROOT->FindObject("FAIRGeom");
+  gGeoMan->SetVisLevel(10);
+
+  // Create the top volume
+  TGeoBBox* topbox = new TGeoBBox("", 1000., 1000., 2000.);
+  TGeoVolume* top  = new TGeoVolume("top", topbox, gGeoMan->GetMedium("air"));
+  gGeoMan->SetTopVolume(top);
+
+  TString topName = geoVersion + tagVersion + subVersion;
+
+  TGeoVolume* much = new TGeoVolumeAssembly(topName);
+  top->AddNode(much, 1);
+
+  TGeoVolume* absr = new TGeoVolumeAssembly("absorber");
+  much->AddNode(absr, 1);
+
+  TGeoVolume* shld = new TGeoVolumeAssembly("shield");
+  much->AddNode(shld, 1);
+
+  TGeoVolume* sttn = new TGeoVolumeAssembly("station");
+  much->AddNode(sttn, 1);
+
+  infoFile << endl;
+  infoFile << "                     Absorbers " << endl;
+  infoFile << "                    -----------" << endl;
+  infoFile << "Total No. of Absorbers: " << fAbs << endl;
+  infoFile << "First abosrber is divided into two halves." << endl;
+  infoFile << "First half inserted inside the Dipole Magnet." << endl;
+  infoFile << "Second half is made of Low Density Graphite + Concrete." << endl;
+  infoFile << "Total No. of Pieces: " << fNabs << endl;
+  infoFile << endl;
+  infoFile << "AbsPieces   Position[cm]   Thickness[cm]        Material" << endl;
+  infoFile << "--------------------------------------------------------------" << endl;
+
+  for (Int_t iabs = 0; iabs < fNabs; iabs++) {
+
+    gModules[iabs] = CreateAbsorbers(iabs);
+
+    absr->AddNode(gModules[iabs], iabs);
+  }
+
+
+  infoFile << endl;
+  infoFile << "                     Shielding " << endl;
+  infoFile << "                    -----------" << endl;
+  infoFile << "No. of Shields: " << fNshs << endl;
+  infoFile << "Inside the Abs I, Shielding divided into two parts." << endl;
+  infoFile << endl;
+  infoFile << "Shield No.   Z_In[cm]  Z_Out[cm]  R_In[cm]  R_Out[cm]   Material" << endl;
+  infoFile << "--------------------------------------------------------------" << endl;
+  for (Int_t ishi = 0; ishi < fNshs; ishi++) {
+
+    gModules_shield[ishi] = CreateShields(ishi);
+
+    shld->AddNode(gModules_shield[ishi], ishi);
+  }
+
+  infoFile << endl;
+  infoFile << "                     Stations " << endl;
+  infoFile << "                    ----------" << endl;
+  infoFile << "No. of Stations: " << fNst << endl;
+  infoFile << "First two stations (1,2) are made up of GEM and last two "
+              "stations (3,4) are made up of RPC."
+           << endl;
+  infoFile << "10 mm thick Al plates are used for support and cooling in the "
+              "GEM modules."
+           << endl;
+  infoFile << "2 mm thick Aluminum plates are used for support in the RPC "
+              "modules behind the active area. 10 mm thick Aluminium at the "
+              "boundaries as the frame."
+           << endl;
+  infoFile << "Drift and read-out PCBs (copper coated G10 plates) inserted for "
+              "realistic material budget for both GEM and RPC modules."
+           << endl;
+  infoFile << "#Station   #Layers     Z[cm] #Sectors ActiveLz[cm]" << endl;
+  infoFile << "--------------------------------------------------------------" << endl;
+  for (Int_t istn = 0; istn < fNst; istn++) {  // 4 Stations
+
+
+    gModules_station[istn] = CreateStations(istn);
+
+    sttn->AddNode(gModules_station[istn], istn);
+  }
+
+  gGeoMan->CloseGeometry();
+  gGeoMan->CheckOverlaps(0.0000001);
+  gGeoMan->PrintOverlaps();
+
+  gGeoMan->CheckOverlaps(0.0001, "s");
+  gGeoMan->PrintOverlaps();
+
+
+  much->Export(FileNameSim);  // an alternative way of writing the much
+
+  TFile* outfile                  = new TFile(FileNameSim, "UPDATE");
+  TGeoTranslation* much_placement = new TGeoTranslation("much_trans", 0., 0., -40.0);
+  much_placement->Write();
+  outfile->Close();
+
+  outfile = new TFile(FileNameGeo, "RECREATE");
+  gGeoMan->Write();  // use this if you want GeoManager format in the output
+  outfile->Close();
+
+  //top->Draw("ogl");
+  infoFile.close();
+}
+
+void create_materials_from_media_file()
+{
+  // 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();
+
+  FairGeoMedium* air = geoMedia->getMedium(KeepingVolumeMedium);
+  geoBuild->createMedium(air);
+
+  FairGeoMedium* MUCHiron = geoMedia->getMedium(I);
+  geoBuild->createMedium(MUCHiron);
+
+  FairGeoMedium* MUCHlead = geoMedia->getMedium(L);
+  geoBuild->createMedium(MUCHlead);
+
+  FairGeoMedium* MUCHargon = geoMedia->getMedium(activemedium);
+  geoBuild->createMedium(MUCHargon);
+
+  FairGeoMedium* MUCHnoryl = geoMedia->getMedium(spacermedium);
+  geoBuild->createMedium(MUCHnoryl);
+
+  FairGeoMedium* MUCHsupport = geoMedia->getMedium(Al);
+  geoBuild->createMedium(MUCHsupport);
+
+  FairGeoMedium* MUCHcarbonLD = geoMedia->getMedium(LDcarbon);
+  geoBuild->createMedium(MUCHcarbonLD);
+
+  FairGeoMedium* MUCHconcrete = geoMedia->getMedium(Concrete);
+  geoBuild->createMedium(MUCHconcrete);
+
+  FairGeoMedium* copperplate = geoMedia->getMedium(copper);
+  geoBuild->createMedium(copperplate);
+
+  FairGeoMedium* g10plate = geoMedia->getMedium(g10);  //G10
+  geoBuild->createMedium(g10plate);
+
+  FairGeoMedium* RPCmedium = geoMedia->getMedium(RPCm);
+  geoBuild->createMedium(RPCmedium);
+
+  FairGeoMedium* RPCmaterial = geoMedia->getMedium(RPCg);
+  geoBuild->createMedium(RPCmaterial);
+}
+
+
+TGeoVolume* CreateShields(int ish)
+{
+
+
+  TGeoMedium* iron      = gGeoMan->GetMedium(I);
+  TGeoMedium* lead      = gGeoMan->GetMedium(L);
+  TGeoMedium* Aluminium = gGeoMan->GetMedium(Al);
+
+  TString name                    = Form("shieldblock%d", ish);
+  TGeoVolumeAssembly* shieldblock = new TGeoVolumeAssembly(name);
+
+  TString conename_sh = Form("conesh_%d", ish);
+
+
+  Double_t dz       = fShieldLz[ish] / 2.0;
+  Double_t globalZ1 = fShieldZin[ish];
+  Double_t globalZ2 = fShieldZin[ish] + 2 * dz;
+
+
+  Double_t rmin1 = globalZ1 * fShield_AcceptanceTanMin[ish] + 2.0;
+  Double_t rmax1 = globalZ1 * fShield_AcceptanceTanMax[ish] - 0.0001;
+  Double_t rmin2 = globalZ2 * fShield_AcceptanceTanMin[ish] + 2.0;
+  Double_t rmax2 = globalZ2 * fShield_AcceptanceTanMax[ish] - 0.0001;
+
+  infoFile << "   " << ish << "\t\t" << globalZ1 << "\t  " << globalZ2 << "\t" << rmin1 << "\t   " << rmax1 << "\t  "
+           << ShMaterial[ish] << endl;
+
+  if (ish == 0) {
+
+    TGeoCone* sh       = new TGeoCone(conename_sh, dz, rmin1, rmax1, rmin2, rmax2);
+    TGeoVolume* shield = new TGeoVolume("shield", sh, Aluminium);
+
+    shield->SetLineColor(7);
+    shield->SetTransparency(2);
+    TGeoTranslation* sh_trans = new TGeoTranslation("", 0., 0., globalZ1 + dz);
+    shieldblock->AddNode(shield, ish, sh_trans);
+  }
+
+  if (ish == 1) {
+    TGeoCone* sh       = new TGeoCone(conename_sh, dz, rmin1, rmax1, rmin2, rmax2);
+    TGeoVolume* shield = new TGeoVolume("shield", sh, lead);
+
+    shield->SetLineColor(kMagenta);
+    shield->SetTransparency(2);
+    TGeoTranslation* sh_trans = new TGeoTranslation("", 0., 0., globalZ1 + dz);
+    shieldblock->AddNode(shield, ish, sh_trans);
+  }
+
+  if (ish > 1) {
+
+
+    TGeoCone* sh       = new TGeoCone(conename_sh, dz, rmin1, rmax1, rmin2, rmax2);
+    TGeoVolume* shield = new TGeoVolume("shield", sh, Aluminium);
+
+    shield->SetLineColor(kBlack);
+    shield->SetTransparency(2);
+    TGeoTranslation* sh_trans = new TGeoTranslation("", 0., 0., globalZ1 + dz);
+    shieldblock->AddNode(shield, ish, sh_trans);
+  }
+
+
+  return shieldblock;
+}
+
+
+TGeoVolume* CreateAbsorbers(int i)
+{
+
+  TGeoMedium* graphite  = gGeoMan->GetMedium(LDcarbon);
+  TGeoMedium* iron      = gGeoMan->GetMedium(I);
+  TGeoMedium* concrete  = gGeoMan->GetMedium(Concrete);
+  TGeoMedium* Aluminium = gGeoMan->GetMedium(Al);
+
+  TString name                 = Form("absblock%d", i);
+  TGeoVolumeAssembly* absblock = new TGeoVolumeAssembly(name);
+
+  TString pipename         = Form("beampipe_%d", i);
+  TString conename         = Form("cone_%d", i);
+  TString BoxName          = Form("Box_%d", i);
+  TString supportShapeName = Form("Support_%d", i);
+  TString TrapName         = Form("Trap_%d", i);
+
+  Double_t dz        = fAbsorberLz[i] / 2.0;
+  Double_t globalZ1  = fAbsorberZ1[i] + fMuchZ1;
+  Double_t globalPos = globalZ1 + dz;
+  Double_t globalZ2  = fAbsorberZ1[i] + 2 * dz + fMuchZ1;
+
+  Double_t rmin1 = globalZ1 * fAcceptanceTanMin;
+  Double_t rmin2 = globalZ2 * fAcceptanceTanMin;
+  Double_t rmax1 = globalZ1 * fAcceptanceTanMax + safetyrad[i];
+  Double_t rmax2 = globalZ2 * fAcceptanceTanMax + safetyrad[i];  //
+
+  infoFile << "   " << i + 1 << "\t\t" << globalPos << "\t\t" << 2 * dz << "\t\t" << AbsMaterial[i] << endl;
+
+  // 1st part of 1st absorber LD Carbon
+  //dimensions are hardcoded
+  if (i == 0) {
+    printf("absorber %d \n", i);
+
+    TGeoTrd2* trap                = new TGeoTrd2(TrapName, 70.0, 70.0, 46.0, 71.0, dz);
+    TGeoCone* tube                = new TGeoCone(pipename, dz + 0.001, 0., rmin1, 0., rmin2);
+    TString expression            = TrapName + "-" + pipename;
+    TGeoCompositeShape* shSupport = new TGeoCompositeShape(supportShapeName, expression);
+    TGeoVolume* abs0              = new TGeoVolume("absorber", shSupport, graphite);
+    abs0->SetLineColor(kRed);
+    abs0->SetTransparency(0);
+    TGeoTranslation* abs0_trans = new TGeoTranslation("", 0., 0., globalZ1 + dz);
+    absblock->AddNode(abs0, i, abs0_trans);
+  }
+
+
+  // 2rd part of 1st absorber box (LD Carbon)
+  if (i == 1) {
+    printf("absorber %d \n", i);
+    TGeoBBox* box                 = new TGeoBBox(BoxName, 130.0, 125.0, dz);
+    TGeoCone* tube                = new TGeoCone(pipename, dz + 0.001, 0., rmin1, 0., rmin2);
+    TString expression            = BoxName + "-" + pipename;
+    TGeoCompositeShape* shSupport = new TGeoCompositeShape(supportShapeName, expression);
+
+    TGeoVolume* abs1 = new TGeoVolume("absorber", shSupport, graphite);
+    abs1->SetLineColor(kRed);
+    abs1->SetTransparency(0);
+    TGeoTranslation* abs1_trans = new TGeoTranslation("", 0., 0., globalZ1 + dz);
+    absblock->AddNode(abs1, i, abs1_trans);
+  }
+
+  // 3th part of 1st absorber box (Conc)
+  if (i == 2) {
+    printf("absorber %d \n", i);
+    TGeoBBox* box                 = new TGeoBBox(BoxName, 130.0, 125.0, dz);
+    TGeoCone* tube                = new TGeoCone(pipename, dz + 0.001, 0., rmin1, 0., rmin2);
+    TString expression            = BoxName + "-" + pipename;
+    TGeoCompositeShape* shSupport = new TGeoCompositeShape(supportShapeName, expression);
+
+    TGeoVolume* abs1 = new TGeoVolume("absorber", shSupport, concrete);
+    abs1->SetLineColor(kViolet);
+    abs1->SetTransparency(0);
+    TGeoTranslation* abs1_trans = new TGeoTranslation("", 0., 0., globalZ1 + dz);
+    absblock->AddNode(abs1, i, abs1_trans);
+  }
+
+
+  //rest of the absorbers
+  if (i > 2) {
+    TGeoBBox* box                 = new TGeoBBox(BoxName, rmax2, rmax2, dz);
+    TGeoCone* tube                = new TGeoCone(pipename, dz + 0.001, 0., rmin1, 0., rmin2);
+    TString expression            = BoxName + "-" + pipename;
+    TGeoCompositeShape* shSupport = new TGeoCompositeShape(supportShapeName, expression);
+
+    TGeoVolume* abs2 = new TGeoVolume("absorber", shSupport, iron);
+
+    abs2->SetLineColor(kBlue);
+    abs2->SetTransparency(2);
+
+
+    TGeoTranslation* abs_trans = new TGeoTranslation("", 0., 0., globalZ1 + dz);
+    absblock->AddNode(abs2, i, abs_trans);
+  }
+
+  return absblock;
+}
+
+TGeoVolume* CreateStations(int ist)
+{
+
+  TString stationName = Form("muchstation%02i", ist + 1);
+
+  TGeoVolumeAssembly* station = new TGeoVolumeAssembly(stationName);  //, shStation, air);
+
+  TGeoVolume* gLayer[4];
+
+  for (int ii = 0; ii < 3; ii++) {  // 3 Layers
+
+    gLayer[ii] = CreateLayers(ist, ii);
+    station->AddNode(gLayer[ii], ii);
+  }
+
+  return station;
+}
+
+
+TGeoVolume* CreateLayers(int istn, int ily)
+{
+
+  TString layerName           = Form("muchstation%02ilayer%i", istn + 1, ily + 1);
+  TGeoVolumeAssembly* volayer = new TGeoVolumeAssembly(layerName);
+
+
+  Double_t stGlobalZ0 = fStationZ0[istn] + fMuchZ1;  //z position of station center (midplane) [cm]
+  Double_t stDz       = ((fNlayers[istn] - 1) * fLayersDz[istn] + fSupportLz[istn] + 2 * fActiveLzSector[istn]) / 2.;
+  Double_t stGlobalZ2 = stGlobalZ0 + stDz;
+  Double_t stGlobalZ1 = stGlobalZ0 - stDz;
+
+  Double_t rmin = stGlobalZ1 * fAcceptanceTanMin;
+  Double_t rmax = stGlobalZ2 * fAcceptanceTanMax;
+
+
+  Double_t layerZ0       = (ily - (fNlayers[istn] - 1) / 2.) * fLayersDz[istn];
+  Double_t layerGlobalZ0 = layerZ0 + stGlobalZ0;
+  Double_t SupportDz     = fSupportLz[istn] / 2.;
+  Double_t RpcGlassDz    = fActiveLzSector[istn] / 2. + fRpcGlassDz[istn] / 2.;
+  Double_t driftDz       = RpcGlassDz + fRpcGlassDz[istn] / 2 + fDriftDz / 2.;
+  Double_t g10Dz         = driftDz + fDriftDz / 2. + fG10Dz / 2.;
+  Double_t moduleZ       = fSupportLz[istn] / 2. + fActiveLzSector[istn] / 2. + fRpcGlassDz[istn] + fDriftDz + fG10Dz;
+  Double_t RpcGlassZIn   = moduleZ - RpcGlassDz;
+  Double_t RpcGlassZOut  = moduleZ + RpcGlassDz;
+  Double_t driftZIn      = moduleZ - driftDz;
+  Double_t driftZOut     = moduleZ + driftDz;
+  Double_t g10ZIn        = moduleZ - g10Dz;
+  Double_t g10ZOut       = moduleZ + g10Dz;
+
+
+  Double_t phi0 = TMath::Pi() / fNSectorsPerLayer[istn];  // azimuthal half widh of each module
+  Double_t ymin = rmin + fSpacerR;
+  Double_t ymax = rmax;
+
+  //define the dimensions of the trapezoidal module
+  Double_t dy  = (ymax - ymin) / 2.;                                      //y (length)
+  Double_t dx1 = ymin * TMath::Tan(phi0) + fOverlapR / TMath::Cos(phi0);  // large x
+  Double_t dx2 = ymax * TMath::Tan(phi0) + fOverlapR / TMath::Cos(phi0);  // small x
+  Double_t dz  = fActiveLzSector[istn] / 2.;                              // thickness
+
+  //define the spacer dimensions
+  Double_t tg   = (dx2 - dx1) / 2 / dy;
+  Double_t dd1  = fSpacerPhi * tg;
+  Double_t dd2  = fSpacerPhi * sqrt(1 + tg * tg);
+  Double_t sdx1 = dx1 + dd2 - dd1 - 0.1;  // 0.1 cm to avoid overlaps
+  Double_t sdx2 = dx2 + dd2 + dd1;
+  Double_t sdy  = dy + fSpacerR;
+  // Double_t sdz  = dz-0.1;
+  Double_t sdz = fFrameLzSector[istn] / 2.;
+
+  //define Additional material as realistic GEM module
+  Double_t dz_sD = fDriftDz / 2.;  //35 micron copper Drift
+  Double_t dz_sG = fG10Dz / 2.;    // 3mm G10
+
+
+  infoFile << "   " << istn + 1 << "\t      " << ily + 1 << "\t\t" << layerGlobalZ0 << "\t" << fNSectorsPerLayer[istn]
+           << "\t" << fActiveLzSector[istn] << endl;
+
+
+  // Aluminum Plate (Cooling + Support)
+  TString supportAlName = Form("shStation%02iSupportAl", istn + 1);
+  TGeoTube* shSupportAl = new TGeoTube(supportAlName, rmin, rmax, SupportDz);
+
+  TString supportName1 = Form("muchstation%02ilayer%isupportAl", istn + 1, ily + 1);
+  TGeoMedium* coolMat  = gGeoMan->GetMedium(Al);
+
+  TGeoVolume* voSupport1 = new TGeoVolume(supportName1, shSupportAl, coolMat);
+  voSupport1->SetLineColor(kCyan);
+
+  TGeoTranslation* support_trans1 = new TGeoTranslation("supportName1", 0, 0, layerGlobalZ0);
+  volayer->AddNode(voSupport1, 0, support_trans1);
+
+  Double_t pos[9];
+
+  Int_t iMod = 0;
+  for (Int_t iSide = 0; iSide < 2; iSide++) {
+
+    // Now start adding the GEM modules
+    for (Int_t iModule = 0; iModule < fNSectorsPerLayer[istn]; iModule++) {
+
+      Double_t phi  = 2 * phi0 * (iModule + 0.5);  // add 0.5 to not overlap with y-axis for left-right layer separation
+      Bool_t isBack = iModule % 2;
+      Char_t cside  = (isBack == 1) ? 'b' : 'f';
+
+      // correct the x, y positions
+      pos[0] = -(ymin + dy) * sin(phi);
+      pos[1] = (ymin + dy) * cos(phi);
+
+      // different z positions for odd/even modules
+      pos[2] = (isBack ? 1 : -1) * moduleZ + layerGlobalZ0;
+      pos[3] = (isBack ? 1 : -1) * RpcGlassZIn + layerGlobalZ0;
+      pos[4] = (isBack ? 1 : -1) * RpcGlassZOut + layerGlobalZ0;
+      pos[5] = (isBack ? 1 : -1) * driftZIn + layerGlobalZ0;
+      pos[6] = (isBack ? 1 : -1) * driftZOut + layerGlobalZ0;
+      pos[7] = (isBack ? 1 : -1) * g10ZIn + layerGlobalZ0;
+      pos[8] = (isBack ? 1 : -1) * g10ZOut + layerGlobalZ0;
+
+      //cout<<pos[2]<<"  "<<pos[3]<<"  "<<pos[4]<<"  "<<pos[5]<<"   "<<pos[6]<<"   "<<pos[7]<<"     "<<pos[8]<<endl;
+      if (iSide != isBack) continue;
+      if (iModule != 0) iMod = iModule / 2;
+
+
+      TGeoMedium* argon        = gGeoMan->GetMedium(activemedium);  // active medium
+      TGeoMedium* noryl        = gGeoMan->GetMedium(spacermedium);  // spacer medium
+      TGeoMedium* SpacerRpc    = gGeoMan->GetMedium(Al);            // spacer medium
+      TGeoMedium* copperplate  = gGeoMan->GetMedium(copper);        // copper Drift medium
+      TGeoMedium* g10plate     = gGeoMan->GetMedium(g10);           // G10 medium
+      TGeoMedium* RPCglassmat  = gGeoMan->GetMedium(RPCg);          // RPC Glass
+      TGeoMedium* RPCgasmedium = gGeoMan->GetMedium(RPCm);          // RPC Gas
+
+
+      // Define and place the trapezoidal GEM module in X-Y plane
+      TGeoVolume *voActive, *voRPCback, *voRPCFront;
+      TGeoTrap* shape = new TGeoTrap(sdz, 0, 0, dy, dx1, dx2, 0, dy, dx1, dx2, 0);
+      shape->SetName(Form("shStation%02iLayer%i%cModule%03iFrameNoHole", istn, ily, cside, iModule));
+
+      TGeoTrap* shapeActive = new TGeoTrap(dz, 0, 0, dy, dx1, dx2, 0, dy, dx1, dx2, 0);
+      shapeActive->SetName(Form("shStation%02iLayer%i%cModule%03iActiveNoHole", istn, ily, cside, iModule));
+
+      if (istn < 2) {  //GEM
+        TString activeName = Form("muchstation%02ilayer%i%cactive%03igasArgon", istn + 1, ily + 1, cside, iMod + 1);
+        voActive           = new TGeoVolume(activeName, shapeActive, argon);
+        voActive->SetLineColor(kGreen);
+      }
+      else {  //RPC Active
+        TString activeName = Form("muchstation%02ilayer%i%cactive%03irpcgas", istn + 1, ily + 1, cside, iMod + 1);
+        voActive           = new TGeoVolume(activeName, shapeActive, RPCgasmedium);
+        voActive->SetLineColor(kRed);
+
+        //RPC Glass Front
+        TGeoTrap* shapeRPCfront = new TGeoTrap(dz, 0, 0, dy, dx1, dx2, 0, dy, dx1, dx2, 0);
+        shapeRPCfront->SetName(Form("shStation%02iLayer%i%cModule%03iNoHoleFront", istn, ily, cside, iModule));
+        TString NameFront = Form("muchstation%02ilayer%i%c%03irpcglassFront", istn + 1, ily + 1, cside, iMod + 1);
+        voRPCFront        = new TGeoVolume(NameFront, shapeRPCfront, RPCglassmat);
+        voRPCFront->SetLineColor(kRed);
+
+        //RPC Glass Back
+        TGeoTrap* shapeRPCback = new TGeoTrap(dz, 0, 0, dy, dx1, dx2, 0, dy, dx1, dx2, 0);
+        shapeRPCback->SetName(Form("shStation%02iLayer%i%cModule%03iNoHoleback", istn, ily, cside, iModule));
+        TString Nameback = Form("muchstation%02ilayer%i%c%03irpcglassback", istn + 1, ily + 1, cside, iMod + 1);
+        voRPCback        = new TGeoVolume(Nameback, shapeRPCback, RPCglassmat);
+        voRPCback->SetLineColor(kRed);
+      }
+
+
+      TGeoTrap *Drift[2], *G10[2], *Al;
+      TString DriftName[2], G10Name[2], AlName;
+      TGeoVolume *voDrift[2], *voG10[2];
+
+      for (int iPos = 0; iPos < 2; iPos++) {
+        Char_t cpos = (iPos == 0) ? 'i' : 'o';
+        // Define and place copper drift & G10
+        if (istn < 2) {  //GEM
+          Drift[iPos] = new TGeoTrap(dz_sD, 0, phi, sdy, sdx1, sdx2, 0, sdy, sdx1, sdx2, 0);
+          G10[iPos]   = new TGeoTrap(dz_sG, 0, phi, sdy, sdx1, sdx2, 0, sdy, sdx1, sdx2, 0);
+        }
+        else {  //RPC
+          Drift[iPos] = new TGeoTrap(dz_sD, 0, phi, dy, dx1, dx2, 0, dy, dx1, dx2, 0);
+          G10[iPos]   = new TGeoTrap(dz_sG, 0, phi, dy, dx1, dx2, 0, dy, dx1, dx2, 0);
+        }
+        Drift[iPos]->SetName(Form("shStation%02iLayer%i%cModule%03i%cDrift", istn, ily, cside, iModule, cpos));
+        DriftName[iPos] =
+          Form("muchstation%02ilayer%i%cside%03i%ccopperDrift", istn + 1, ily + 1, cside, iMod + 1, cpos);
+        voDrift[iPos] = new TGeoVolume(DriftName[iPos], Drift[iPos], copperplate);
+        voDrift[iPos]->SetLineColor(kRed);
+
+        G10[iPos]->SetName(Form("shStation%02iLayer%i%cModule%03i%cG10", istn, ily, cside, iModule, cpos));
+        G10Name[iPos] = Form("muchstation%02ilayer%i%cside%03i%cG10", istn + 1, ily + 1, cside, iMod + 1, cpos);
+        voG10[iPos]   = new TGeoVolume(G10Name[iPos], G10[iPos], g10plate);
+        voG10[iPos]->SetLineColor(28);
+      }
+
+
+      // Define the trapezoidal spacers
+      TGeoTrap* shapeFrame = new TGeoTrap(sdz, 0, 0, sdy, sdx1, sdx2, 0, sdy, sdx1, sdx2, 0);
+      shapeFrame->SetName(Form("shStation%02iLayer%i%cModule%03iFullFrameNoHole", istn, ily, cside, iModule));
+      TString expression;
+      if (istn < 2) {  //GEM
+        expression = Form("shStation%02iLayer%i%cModule%03iFullFrameNoHole-"
+                          "shStation%02iLayer%i%cModule%03iActiveNoHole",
+                          istn, ily, cside, iModule, istn, ily, cside, iModule);
+      }
+      else {  //RPC
+        expression = Form("shStation%02iLayer%i%cModule%03iFullFrameNoHole-"
+                          "shStation%02iLayer%i%cModule%03iFrameNoHole",
+                          istn, ily, cside, iModule, istn, ily, cside, iModule);
+      }
+      TGeoCompositeShape* shFrame = new TGeoCompositeShape(
+        Form("shStation%02iLayer%i%cModule%03iFinalFrameNoHole", istn, ily, cside, iModule), expression);
+      TString frameName = Form("muchstation%02ilayer%i%cframe%03i", istn + 1, ily + 1, cside, iMod + 1);
+      TGeoVolume* voFrame;
+      if (istn < 2) {
+        voFrame = new TGeoVolume(frameName, shFrame, noryl);  // add a name to the frame
+      }
+      else {
+        voFrame = new TGeoVolume(frameName, shFrame, SpacerRpc);  // add a name to the frame
+      }
+      voFrame->SetLineColor(kMagenta);
+
+
+      // Calculate the phi angle of the sector where it has to be placed
+      Double_t angle = 180. / TMath::Pi() * phi;  // convert angle phi from rad to deg
+
+
+      TGeoRotation* r2 = new TGeoRotation("r2");
+      //rotate in the vertical plane (per to z axis) with angle
+      r2->RotateZ(angle);
+
+
+      TGeoTranslation* trans[10];
+      TGeoHMatrix* incline_mod[10];
+
+      for (int i = 0; i < 8; i++) {
+        trans[i] = new TGeoTranslation("", pos[0], pos[1], pos[i + 2]);
+
+        incline_mod[i]    = new TGeoHMatrix("");
+        (*incline_mod[i]) = (*trans[i]) * (*r2);
+      }
+
+      volayer->AddNode(voActive, iMod, incline_mod[0]);  // add active volume
+      volayer->AddNode(voFrame, iMod, incline_mod[0]);   // add spacer
+      if (istn > 1) {
+        volayer->AddNode(voRPCFront, iMod, incline_mod[1]);  //Rpc Glass In
+        volayer->AddNode(voRPCback, iMod, incline_mod[2]);   //Rpc Glass Out
+      }
+
+      volayer->AddNode(voDrift[0], iMod, incline_mod[3]);  //Drift In
+      volayer->AddNode(voDrift[1], iMod, incline_mod[4]);  //Drift Out
+      volayer->AddNode(voG10[0], iMod, incline_mod[5]);    //G10 In
+      volayer->AddNode(voG10[1], iMod, incline_mod[6]);    //G10 Out
+    }
+  }
+
+  return volayer;
+}
diff --git a/macro/passive/create_bpipe_geometry_v16e_1e.C b/macro/passive/create_bpipe_geometry_v16e_1e.C
new file mode 100644
index 0000000000000000000000000000000000000000..c98c375163b2acaa9b90670b2ed42b6865623ca1
--- /dev/null
+++ b/macro/passive/create_bpipe_geometry_v16e_1e.C
@@ -0,0 +1,384 @@
+/* Copyright (C) 2014-2017 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
+   SPDX-License-Identifier: GPL-3.0-only
+   Authors: Andrey Chernogorov, David Emschermann [committer] */
+
+/******************************************************************************
+ ** Creation of beam pipe geometry in ROOT format (TGeo).
+ **
+ ** @file create_bpipe_geometry_v16b_1e.C
+ ** @author Andrey Chernogorov <a.chernogorov@gsi.de>
+ ** @date 04.06.2014
+ **
+ ** pipe_v16e s a shifted by 40cm version of v16b
+ ** pipe v16b_1e is actually identical to v14q and can be reused in the hadron setup
+ **
+ ** SIS-100
+ ** pipe_v14l = pipe_v14f + fixed sizes of vacuum chamber for mvd_v14a
+ **
+ ** The beam pipe is composed of aluminium with a thickness proportional to the
+ ** diameter (D(z)mm/60). It is placed directly into the cave as mother volume.
+ ** The beam pipe consists of few sections excluding RICH section(1700-3700mm) 
+ ** because it is part of the RICH geometry. Each section has a PCON shape 
+ ** (including windows). There are two windows: first one @ 220mm with R600mm 
+ ** and 0.7mm thickness, second one of iron @ 6000mm with R600mm and 0.2mm 
+ ** thickness. The STS section is composed of cylinder D(z=220-500mm)=36mm and 
+ ** cone (z=500-1700mm). All sections of the beam pipe with conical shape have 
+ ** half opening angle 2.5deg. The PSD section of the beam pipe is missing 
+ ** because it is planned that it will be part of PSD geometry.
+ *****************************************************************************/
+
+
+#include "TGeoManager.h"
+
+#include <iomanip>
+#include <iostream>
+
+
+using namespace std;
+
+
+// -------------   Steering variables       -----------------------------------
+// ---> Beam pipe material name
+TString pipeMediumName = "aluminium";  // "beryllium" "carbon"
+// ----------------------------------------------------------------------------
+
+
+// -------------   Other global variables   -----------------------------------
+// ---> Macros name to info file
+TString macrosname = "create_bpipe_geometry_v16e_1e.C";
+// ---> Geometry file name (output)
+TString rootFileName = "pipe_v16e_1e.geo.root";
+// ---> Geometry name
+TString pipeName = "pipe_v16e_1e";
+// ----------------------------------------------------------------------------
+
+TGeoVolume* MakePipe(Int_t iPart, Int_t nSects, Double_t* z, Double_t* rin, Double_t* rout, TGeoMedium* medium,
+                     fstream* infoFile);
+
+TGeoVolume* MakeVacuum(Int_t iPart, Int_t nSects, Double_t* z, Double_t* rin, Double_t* rout, TGeoMedium* medium,
+                       fstream* infoFile);
+
+// ============================================================================
+// ======                         Main function                           =====
+// ============================================================================
+
+void create_bpipe_geometry_v16e_1e()
+{
+  // -----   Define beam pipe sections   --------------------------------------
+  /** For v16e_1e:   **/
+  TString pipe1name         = "pipe1 - vacuum chamber";
+  const Int_t nSects1       = 6;
+  Double_t z1[nSects1]      = {-50., -5., -5., 230.17, 230.17, 230.87};  // mm
+  Double_t rin1[nSects1]    = {25., 25., 400., 400., 110., 110.};
+  Double_t rout1[nSects1]   = {25.7, 25.7, 400.7, 400.7, 400.7, 130.7};
+  TString pipe2name         = "pipe2 - first window @ 220mm, h=0.7mm, R=600mm";
+  const Int_t nSects2       = 7;
+  Double_t z2[nSects2]      = {220., 220.7, 221.45, 223.71, 227.49, 230.17, 230.87};  // mm
+  Double_t rin2[nSects2]    = {18., 18., 30., 60., 90., 105.86, 110.};
+  Double_t rout2[nSects2]   = {18., 28.69, 39.3, 65.55, 94.14, 110., 110.};
+  TString pipevac1name      = "pipevac1";
+  const Int_t nSects01      = 10;
+  Double_t z01[nSects01]    = {-50., -5., -5., 220., 220., 220.7, 221.45, 223.71, 227.49, 230.17};  // mm
+  Double_t rin01[nSects01]  = {0., 0., 0., 0., 18., 28.69, 39.3, 65.55, 94.14, 110.};
+  Double_t rout01[nSects01] = {25., 25., 400., 400., 400., 400., 400., 400., 400., 400.};
+
+  // tan (2.5) *  30 cm = 1.310 cm
+  // tan (2.5) *  40 cm = 1.746 cm
+  // tan (2.5) *  50 cm = 2.183 cm
+  // tan (2.5) *  60 cm = 2.620 cm
+  // tan (2.5) *  70 cm = 3.056 cm
+  // tan (2.5) *  80 cm = 3.493 cm
+  // tan (2.5) *  90 cm = 3.929 cm
+  // tan (2.5) * 100 cm = 4.366 cm
+
+  TString pipe3name       = "pipe3 - STS section";
+  const Int_t nSects3     = 3;
+  Double_t z3[nSects3]    = {220., 500., 1250.};  // mm
+  Double_t rout3[nSects3] = {18., 18., 55.};
+  Double_t rin3[nSects3];
+  for (Int_t i = 0; i < nSects3; i++) {
+    rin3[i] = rout3[i] - rout3[i] / 30.;
+  }
+  TString pipevac3name     = "pipevac3";
+  const Int_t nSects03     = nSects3;
+  Double_t z03[nSects03]   = {220., 500., 1250.};  // mm
+  Double_t rin03[nSects03] = {0., 0., 0.};
+  Double_t rout03[nSects03];
+  for (Int_t i = 0; i < nSects03; i++) {
+    rout03[i] = rin3[i];
+  }
+
+  TString pipe4name       = "pipe4 - STS to RICH junction";
+  const Int_t nSects4     = 2;
+  Double_t z4[nSects4]    = {1250., 1700.};  // mm
+  Double_t rout4[nSects4] = {55., 74.2};
+  Double_t rin4[nSects4];
+  for (Int_t i = 0; i < nSects4; i++) {
+    rin4[i] = rout4[i] - rout4[i] / 30.;
+  }
+  TString pipevac4name     = "pipevac4";
+  const Int_t nSects04     = nSects4;
+  Double_t z04[nSects04]   = {1250., 1700.};  // mm
+  Double_t rin04[nSects04] = {0., 0.};
+  Double_t rout04[nSects04];
+  for (Int_t i = 0; i < nSects04; i++) {
+    rout04[i] = rin4[i];
+  }
+  //  Double_t rout04[nSects04]; for(Int_t i=0; i<nSects04; i++) { rout04[i]=rin4[i]-0.001; }
+
+  /*
+  TString pipe5name = "pipe5 - MUCH Al-section - inner part";
+  const Int_t nSects5 = 2;
+  Double_t z5[nSects5]      = { 1850.,  4000. }; // mm
+  Double_t rout5[nSects5]   = {  109.,   217. };
+  Double_t rin5[nSects5]    = {  104.,   212. };
+  TString pipevac5name = "pipevac5";
+  const Int_t nSects05 = 2;
+  Double_t z05[nSects05]    = { 1850.,  4000. }; // mm
+  Double_t rin05[nSects05]  = {    0.,     0. };
+  Double_t rout05[nSects05]; for(Int_t i=0; i<nSects05; i++) { rout05[i]=rin5[i]; }
+  //  Double_t rout05[nSects05]; for(Int_t i=0; i<nSects05; i++) { rout05[i]=rin5[i]-0.001; }
+  */
+
+  // --------------------------------------------------------------------------
+
+
+  // -------   Open info file   -----------------------------------------------
+  TString infoFileName = rootFileName;
+  infoFileName.ReplaceAll("root", "info");
+  fstream infoFile;
+  fstream infoFileEmpty;
+  infoFile.open(infoFileName.Data(), fstream::out);
+  infoFile << "SIS-100. Beam pipe geometry created with " + macrosname << endl << endl;
+
+  infoFile << "pipe_v16c_1e is the shifted by 40cm version of pipe_v16b_1e " << endl;
+  infoFile << "	  pipe_v16b_1e = pipe_v14f + fixed sizes of vacuum chamber for "
+              "mvd_v14a"
+           << endl
+           << endl;
+  infoFile << " The beam pipe is composed of aluminium with a thickness "
+              "proportional to the"
+           << endl;
+  infoFile << " diameter (D(z)mm/60). It is placed directly into the cave as "
+              "mother volume."
+           << endl;
+  infoFile << " The beam pipe consists of few sections excluding RICH "
+              "section(1700-3700mm) "
+           << endl;
+  infoFile << " because it is part of the RICH geometry. Each section has a "
+              "PCON shape "
+           << endl;
+  infoFile << " (including windows). There are two windows: first one @ 220mm "
+              "with R600mm "
+           << endl;
+  infoFile << " and 0.7mm thickness, second one of iron @ 6000mm with R600mm "
+              "and 0.2mm "
+           << endl;
+  infoFile << " thickness. The STS section is composed of cylinder "
+              "D(z=220-500mm)=36mm and "
+           << endl;
+  infoFile << " cone (z=500-1700mm). All sections of the beam pipe with "
+              "conical shape have "
+           << endl;
+  infoFile << " half opening angle 2.5deg. The PSD section of the beam pipe is "
+              "missing "
+           << endl;
+  infoFile << " because it is planned that it will be part of PSD geometry." << endl << endl;
+
+  infoFile << "Material:  " << pipeMediumName << endl;
+  infoFile << "Thickness: D(z)mm/60" << endl << 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();
+  TGeoManager* gGeoMan = gGeoManager;
+  // --------------------------------------------------------------------------
+
+
+  // -----------------   Get and create the required media    -----------------
+  FairGeoMedia* geoMedia   = geoFace->getMedia();
+  FairGeoBuilder* geoBuild = geoLoad->getGeoBuilder();
+
+  // ---> pipe medium
+  FairGeoMedium* fPipeMedium = geoMedia->getMedium(pipeMediumName.Data());
+  TString fairError          = "FairMedium " + pipeMediumName + " not found";
+  if (!fPipeMedium) Fatal("Main", fairError.Data());
+  geoBuild->createMedium(fPipeMedium);
+  TGeoMedium* pipeMedium = gGeoMan->GetMedium(pipeMediumName.Data());
+  TString geoError       = "Medium " + pipeMediumName + " not found";
+  if (!pipeMedium) Fatal("Main", geoError.Data());
+  //  // ---> iron
+  //  FairGeoMedium* mIron = geoMedia->getMedium("iron");
+  //  if ( ! mIron ) Fatal("Main", "FairMedium iron not found");
+  //  geoBuild->createMedium(mIron);
+  //  TGeoMedium* iron = gGeoMan->GetMedium("iron");
+  //  if ( ! iron ) Fatal("Main", "Medium iron not found");
+  //  // ---> lead
+  //  FairGeoMedium* mLead = geoMedia->getMedium("lead");
+  //  if ( ! mLead ) Fatal("Main", "FairMedium lead not found");
+  //  geoBuild->createMedium(mLead);
+  //  TGeoMedium* lead = gGeoMan->GetMedium("lead");
+  //  if ( ! lead ) Fatal("Main", "Medium lead not found");
+  // ---> vacuum
+  FairGeoMedium* mVacuum = geoMedia->getMedium("vacuum");
+  if (!mVacuum) Fatal("Main", "FairMedium vacuum not found");
+  geoBuild->createMedium(mVacuum);
+  TGeoMedium* vacuum = gGeoMan->GetMedium("vacuum");
+  if (!vacuum) Fatal("Main", "Medium vacuum not found");
+  // --------------------------------------------------------------------------
+
+
+  // --------------   Create geometry and top volume  -------------------------
+  gGeoMan = (TGeoManager*) gROOT->FindObject("FAIRGeom");
+  gGeoMan->SetName("PIPEgeom");
+  TGeoVolume* top = new TGeoVolumeAssembly("TOP");
+  gGeoMan->SetTopVolume(top);
+  TGeoVolume* pipe = new TGeoVolumeAssembly(pipeName.Data());
+  // --------------------------------------------------------------------------
+
+  // Shifting to center of magnetic coordinate system
+  TGeoMatrix* shift = new TGeoTranslation(0, 0, -40);
+  top->AddNode(pipe, 0, shift);
+
+
+  // -----   Create sections  -------------------------------------------------
+  infoFile << endl << "Beam pipe section: " << pipe1name << endl;
+  infoFile << setw(2) << "i" << setw(10) << "Z,mm" << setw(10) << "Rin,mm" << setw(10) << "Rout,mm" << setw(10)
+           << "h,mm" << endl;
+  TGeoVolume* pipe1 = MakePipe(1, nSects1, z1, rin1, rout1, pipeMedium, &infoFile);
+  pipe1->SetLineColor(kGray);
+  pipe->AddNode(pipe1, 0);
+
+  infoFile << endl << "Beam pipe section: " << pipe2name << endl;
+  infoFile << setw(2) << "i" << setw(10) << "Z,mm" << setw(10) << "Rin,mm" << setw(10) << "Rout,mm" << setw(10)
+           << "h,mm" << endl;
+  TGeoVolume* pipe2 = MakePipe(2, nSects2, z2, rin2, rout2, pipeMedium, &infoFile);
+  pipe2->SetLineColor(kBlue);
+  pipe->AddNode(pipe2, 0);
+  TGeoVolume* pipevac1 = MakeVacuum(1, nSects01, z01, rin01, rout01, vacuum, &infoFile);
+  pipevac1->SetLineColor(kCyan);
+  pipe->AddNode(pipevac1, 0);
+
+  infoFile << endl << "Beam pipe section: " << pipe3name << endl;
+  infoFile << setw(2) << "i" << setw(10) << "Z,mm" << setw(10) << "Rin,mm" << setw(10) << "Rout,mm" << setw(10)
+           << "h,mm" << endl;
+  TGeoVolume* pipe3 = MakePipe(3, nSects3, z3, rin3, rout3, pipeMedium, &infoFile);
+  pipe3->SetLineColor(kGreen);
+  pipe->AddNode(pipe3, 0);
+  TGeoVolume* pipevac3 = MakeVacuum(3, nSects03, z03, rin03, rout03, vacuum, &infoFile);
+  pipevac3->SetLineColor(kCyan);
+  pipe->AddNode(pipevac3, 0);
+
+  infoFile << endl << "Beam pipe section: " << pipe4name << endl;
+  infoFile << setw(2) << "i" << setw(10) << "Z,mm" << setw(10) << "Rin,mm" << setw(10) << "Rout,mm" << setw(10)
+           << "h,mm" << endl;
+  TGeoVolume* pipe4 = MakePipe(4, nSects4, z4, rin4, rout4, pipeMedium, &infoFile);
+  pipe4->SetLineColor(kGreen);
+  pipe->AddNode(pipe4, 0);
+  TGeoVolume* pipevac4 = MakeVacuum(4, nSects04, z04, rin04, rout04, vacuum, &infoFile);
+  pipevac4->SetLineColor(kCyan);
+  pipe->AddNode(pipevac4, 0);
+
+  /*
+  infoFile << endl << "Beam pipe section: " << pipe5name << endl;
+  infoFile << setw(2) << "i" << setw(10) << "Z,mm" << setw(10) << "Rin,mm" << setw(10) << "Rout,mm" << setw(10) << "h,mm" << endl;
+  TGeoVolume* pipe5    = MakePipe  (5, nSects5,  z5,  rin5,  rout5,  pipeMedium, &infoFile); 
+  pipe5->SetLineColor(kGreen);
+  pipe->AddNode(pipe5, 0);
+  TGeoVolume* pipevac5 = MakeVacuum(5, nSects05, z05, rin05, rout05, vacuum,     &infoFile); 
+  pipevac5->SetLineColor(kCyan);
+  pipe->AddNode(pipevac5, 0);
+  */
+  // -----   End   --------------------------------------------------
+
+  // ---------------   Finish   -----------------------------------------------
+  top->AddNode(pipe, 1);
+  cout << endl << endl;
+  gGeoMan->CloseGeometry();
+  gGeoMan->CheckOverlaps(0.0001);
+  gGeoMan->PrintOverlaps();
+  gGeoMan->Test();
+
+  // visualize it with ray tracing, OGL/X3D viewer
+  //top->Raytrace();
+  // top->Draw("ogl");
+  //top->Draw("x3d");
+
+
+  TFile* rootFile = new TFile(rootFileName, "RECREATE");
+  top->Write();
+  cout << endl;
+  cout << "Geometry " << top->GetName() << " written to " << rootFileName << endl;
+  rootFile->Close();
+  infoFile.close();
+}
+// ============================================================================
+// ======                   End of main function                          =====
+// ============================================================================
+
+
+// =====  Make the beam pipe volume   =========================================
+TGeoPcon* MakeShape(Int_t nSects, char* name, Double_t* z, Double_t* rin, Double_t* rout, fstream* infoFile)
+{
+
+  // ---> Shape
+  TGeoPcon* shape = new TGeoPcon(name, 0., 360., nSects);
+  for (Int_t iSect = 0; iSect < nSects; iSect++) {
+    shape->DefineSection(iSect, z[iSect] / 10., rin[iSect] / 10., rout[iSect] / 10.);  // mm->cm
+    *infoFile << setw(2) << iSect + 1 << setw(10) << fixed << setprecision(2) << z[iSect] << setw(10) << fixed
+              << setprecision(2) << rin[iSect] << setw(10) << fixed << setprecision(2) << rout[iSect] << setw(10)
+              << fixed << setprecision(2) << rout[iSect] - rin[iSect] << endl;
+  }
+
+  return shape;
+}
+// ============================================================================
+
+
+// =====  Make the beam pipe volume   =========================================
+TGeoVolume* MakePipe(Int_t iPart, Int_t nSects, Double_t* z, Double_t* rin, Double_t* rout, TGeoMedium* medium,
+                     fstream* infoFile)
+{
+
+  // ---> Shape
+  TString volName = Form("pipe%i", iPart);
+  TGeoPcon* shape = new TGeoPcon(volName.Data(), 0., 360., nSects);
+  for (Int_t iSect = 0; iSect < nSects; iSect++) {
+    shape->DefineSection(iSect, z[iSect] / 10., rin[iSect] / 10., rout[iSect] / 10.);  // mm->cm
+    *infoFile << setw(2) << iSect + 1 << setw(10) << fixed << setprecision(2) << z[iSect] << setw(10) << fixed
+              << setprecision(2) << rin[iSect] << setw(10) << fixed << setprecision(2) << rout[iSect] << setw(10)
+              << fixed << setprecision(2) << rout[iSect] - rin[iSect] << endl;
+  }
+
+  // ---> Volume
+  TGeoVolume* pipe = new TGeoVolume(volName.Data(), shape, medium);
+
+  return pipe;
+}
+// ============================================================================
+
+
+// =====   Make the volume for the vacuum inside the beam pipe   ==============
+TGeoVolume* MakeVacuum(Int_t iPart, Int_t nSects, Double_t* z, Double_t* rin, Double_t* rout, TGeoMedium* medium,
+                       fstream* infoFile)
+{
+
+  // ---> Shape
+  TString volName = Form("pipevac%i", iPart);
+  TGeoPcon* shape = new TGeoPcon(volName.Data(), 0., 360., nSects);
+  for (Int_t iSect = 0; iSect < nSects; iSect++) {
+    shape->DefineSection(iSect, z[iSect] / 10., rin[iSect] / 10., rout[iSect] / 10.);  // mm->cm
+  }
+
+  // ---> Volume
+  TGeoVolume* pipevac = new TGeoVolume(volName.Data(), shape, medium);
+
+  return pipevac;
+}
+// ============================================================================
diff --git a/macro/passive/create_bpipe_geometry_v20b_1m.C b/macro/passive/create_bpipe_geometry_v20b_1m.C
new file mode 100644
index 0000000000000000000000000000000000000000..33595b3be9f43a40a9f3c973afbe1485708580cf
--- /dev/null
+++ b/macro/passive/create_bpipe_geometry_v20b_1m.C
@@ -0,0 +1,479 @@
+/* Copyright (C) 2016-2020 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
+   SPDX-License-Identifier: GPL-3.0-only
+   Authors: Andrey Chernogorov, Florian Uhlig [committer] */
+
+/******************************************************************************
+ ** Creation of beam pipe geometry in ROOT format (TGeo).
+ **
+ ** @file create_bpipe_geometry_v16_1m.C
+ ** @author Andrey Chernogorov <a.chernogorov@gsi.de>
+ ** @author P.-A Loizeau <p.-a.loizeau@gsi.de>
+ ** @date 02.06.2016
+ ** @author Anna Senger <a.senger@gsi.de>
+ ** SIS-100
+ ** pipe_v18
+ **
+ ** The beam pipe is composed of carbon with a thickness of 0.5 mm 
+ ** It is placed directly into the cave as mother volume.
+ ** Each section has a PCON shape (including window).
+ ** There is one window of iron the end of the pipe with R95mm and 0.2mm thickness.
+ ** The STS section is composed of cylinder D(z=220-500mm)=36mm and cone
+ ** (z=500-1700mm).
+ ** All other sections of the beam pipe fit either the 2.5 degree standard
+ ** limit or their respective detectors opening if less than 2.5 degree is
+ ** available.
+ *****************************************************************************/
+
+
+#include "TGeoManager.h"
+
+#include <iomanip>
+#include <iostream>
+
+
+using namespace std;
+
+
+// -------------   Steering variables       -----------------------------------
+// ---> Beam pipe material name
+TString pipeMediumName  = "carbon";  // "aluminium" "beryllium" "carbon"
+Double_t dPipeThickness = 0.5;       // mm
+Int_t energy            = 8;
+TString Energy          = "8";
+// ----------------------------------------------------------------------------
+
+
+// -------------   Other global variables   -----------------------------------
+//TString Version = "v19_v2_1m";
+TString Version = "v20b_1m";
+//TString Variation = Version + ".AuAu" + Energy + "AGeV"; //sup
+TString Variation = Version;  //sup
+// ---> Macros name to info file
+TString macrosname = "create_bpipe_geometry_" + Variation + ".C";
+// ---> Geometry file name (output)
+TString rootFileName = "pipe_" + Variation + ".geo.root";
+// ---> Geometry name
+TString pipeName = "pipe_" + Variation;
+// ----------------------------------------------------------------------------
+// ----------------------------------------------------------------------------
+
+TGeoVolume* MakePipe(Int_t iPart, Int_t nSects, Double_t* z, Double_t* rin, Double_t* rout, TGeoMedium* medium,
+                     fstream* infoFile);
+
+TGeoVolume* MakeVacuum(Int_t iPart, Int_t nSects, Double_t* z, Double_t* rin, Double_t* rout, TGeoMedium* medium,
+                       fstream* infoFile);
+
+// ============================================================================
+// ======                         Main function                           =====
+// ============================================================================
+
+void create_bpipe_geometry_v20b_1m(Bool_t bMuch = kTRUE, Bool_t bTrd = kTRUE, Bool_t bTof = kTRUE, Bool_t bEnd = kTRUE,
+                                   Bool_t bWin = kTRUE)
+{
+  Double_t pipeRotationAngle[15];
+  pipeRotationAngle[2]  = 1.8;
+  pipeRotationAngle[4]  = 1.2;
+  pipeRotationAngle[6]  = 0.8;
+  pipeRotationAngle[8]  = 1.;
+  pipeRotationAngle[10] = 0.7;
+  pipeRotationAngle[12] = 0.6;
+
+  Double_t pipeXshift1 = -370. * TMath::Tan(pipeRotationAngle[energy] * TMath::DegToRad());
+  Double_t pipeXshift2 = pipeXshift1 + 5;
+  Double_t pipeXshift3 = 5;
+
+  // -----   Define beam pipe sections   --------------------------------------
+
+  TString pipe1name   = "pipe1 - vacuum chamber";
+  const Int_t nSects1 = 6;
+
+  Double_t z1[nSects1]    = {-50., -5., -5., 230.17, 230.17, 230.87};  // mm
+  Double_t rin1[nSects1]  = {25., 25., 400., 400., 110., 110.};
+  Double_t rout1[nSects1] = {25.7, 25.7, 400.7, 400.7, 400.7, 130.7};
+
+  /*
+  Double_t z1[nSects1]    = { -50.,  -5.,   -5.,  230.17, 230.17, 230.87 }; // mm
+  Double_t rin1[nSects1]  = {  25.,  25.,  400.,  400.,   110.,   110.   };
+  Double_t rout1[nSects1] = {  30, 30, 405, 405,  405,  135  };
+  */
+  TString pipe2name       = "pipe2 - first window @ 220mm, h=0.7mm, R=600mm";
+  const Int_t nSects2     = 7;
+  Double_t z2[nSects2]    = {220., 220.7, 221.45, 223.71, 227.49, 230.17, 230.87};  // mm
+  Double_t rin2[nSects2]  = {18., 18., 30., 60., 90., 105.86, 110.};
+  Double_t rout2[nSects2] = {18., 28.69, 39.3, 65.55, 94.14, 110., 110.};
+
+  TString pipevac1name      = "pipevac1";
+  const Int_t nSects01      = 10;
+  Double_t z01[nSects01]    = {-50., -5., -5., 220., 220., 220.7, 221.45, 223.71, 227.49, 230.17};  // mm
+  Double_t rin01[nSects01]  = {0., 0., 0., 0., 18., 28.69, 39.3, 65.55, 94.14, 110.};
+  Double_t rout01[nSects01] = {25., 25., 400., 400., 400., 400., 400., 400., 400., 400.};
+
+  TString pipe3name       = "pipe3 - STS section";
+  const Int_t nSects3     = 4;
+  Double_t z3[nSects3]    = {220., 500., 1250., 1700.};  // mm
+  Double_t rout3[nSects3] = {18., 18., 55., 74.2};
+  Double_t rin3[nSects3];
+  for (Int_t i = 0; i < nSects3; i++) {
+    rin3[i] = rout3[i] - dPipeThickness;
+  }
+  TString pipevac2name     = "pipevac3";
+  const Int_t nSects02     = nSects3;
+  Double_t z02[nSects02]   = {220., 500., 1250., 1700.};  // mm
+  Double_t rin02[nSects02] = {0., 0., 0., 0.};
+  Double_t rout02[nSects02];
+  for (Int_t i = 0; i < nSects02; i++) {
+    rout02[i] = rin3[i];
+  }
+
+  /*************************************************************/
+  TString pipeNameMuch           = "pipe4 - MUCH/RICH section";  // First 2.5 then 3.0 from 1850 mm up to TRD
+  const Int_t nSectsMuch         = 2;
+  Double_t dZposMuch[nSectsMuch] = {1700., 3700.};  // mm
+  Double_t dRoutMuch[nSectsMuch] = {74.2, 161.1};   // mm
+  Double_t dRinMuch[nSectsMuch];  //for(Int_t i=0; i<nSectsMuch; i++) { dRinMuch[i] = dRoutMuch[i] - dPipeThickness; }
+  dRinMuch[0] = dRoutMuch[0] - 1.48;
+  dRinMuch[1] = dRoutMuch[1] - 3.2;
+
+  TString pipeVacNameMuch   = "pipevac4";
+  const Int_t nSectsVacMuch = nSectsMuch;
+  Double_t dZposVacMuch[nSectsVacMuch];
+  for (Int_t i = 0; i < nSectsVacMuch; i++) {
+    dZposVacMuch[i] = dZposMuch[i];
+  }
+  Double_t dRinVacMuch[nSectsVacMuch];
+  for (Int_t i = 0; i < nSectsVacMuch; i++) {
+    dRinVacMuch[i] = 0.;
+  }
+  Double_t dRoutVacMuch[nSectsVacMuch];
+  for (Int_t i = 0; i < nSectsVacMuch; i++) {
+    dRoutVacMuch[i] = dRinMuch[i];
+  }
+  /*************************************************************/
+  /*************************************************************/
+  TString pipeNameTrd   = "pipe5 - TRD-ToF section";
+  const Int_t nSectsTrd = 2;
+  //  Double_t dZposTrd[nSectsTrd] = { 3700.,  9000. }; // mm
+  Double_t dZposTrd[nSectsTrd] = {3700. + 2, 9000.};  // mm
+  Double_t dRoutTrd[nSectsTrd] = {95., 95.};          // mm
+  Double_t dRinTrd[nSectsTrd];
+  for (Int_t i = 0; i < nSectsTrd; i++) {
+    dRinTrd[i] = dRoutTrd[i] - dPipeThickness;
+  }
+
+  TString pipeVacNameTrd   = "pipevac5";
+  const Int_t nSectsVacTrd = nSectsTrd;
+  Double_t dZposVacTrd[nSectsVacTrd];
+  for (Int_t i = 0; i < nSectsVacTrd; i++) {
+    dZposVacTrd[i] = dZposTrd[i];
+  }
+  Double_t dRinVacTrd[nSectsVacTrd];
+  for (Int_t i = 0; i < nSectsVacTrd; i++) {
+    dRinVacTrd[i] = 0.;
+  }
+  Double_t dRoutVacTrd[nSectsVacTrd];
+  for (Int_t i = 0; i < nSectsVacTrd; i++) {
+    dRoutVacTrd[i] = dRinTrd[i];
+  }
+  /*************************************************************/
+  // Straight window
+  TString pipeNameWin   = "pipe6 - second window @ the end, h=0.2mm, R=161.1mm";  // iron !!!
+  const Int_t nSectsWin = 2;
+  //  Double_t dZposWin[nSectsWin] = { 3700, 3700 + 0.2  }; // mm
+  Double_t dZposWin[nSectsWin] = {3700 + 2, 3700 + 2.2};  // mm
+  Double_t dRoutWin[nSectsWin] = {161.1, 161.1};          // mm
+  Double_t dRinWin[nSectsWin]  = {0., 0.};                // mm
+
+  TString pipeNameWinVac   = "pipevac6";  // iron !!!
+  const Int_t nSectsWinVac = nSectsWin;
+  //  Double_t dZposWinVac[nSectsWinVac] = { 3700, 3700 + 0.2  }; // mm
+  Double_t dZposWinVac[nSectsWinVac] = {3700 + 2, 3700 + 2.2};  // mm
+  Double_t dRoutWinVac[nSectsWinVac] = {95., 95.};              // mm
+  Double_t dRinWinVac[nSectsWinVac]  = {0., 0.};                // mm
+
+  /*************************************************************/
+  TString pipeNamePsd          = "pipe7 - PSD section";
+  const Int_t nSectsPsd        = 2;
+  Double_t dZposPsd[nSectsPsd] = {9000 + 0.2, 19000.};  // mm
+  Double_t dRoutPsd[nSectsPsd] = {95., 95.};            // mm
+  Double_t dRinPsd[nSectsPsd];
+  for (Int_t i = 0; i < nSectsPsd; i++) {
+    dRinPsd[i] = dRoutPsd[i] - dPipeThickness;
+  }
+
+  TString pipeVacNamePsd   = "pipevac7";
+  const Int_t nSectsVacPsd = nSectsPsd;
+  Double_t dZposVacPsd[nSectsVacPsd];
+  for (Int_t i = 0; i < nSectsVacPsd; i++) {
+    dZposVacPsd[i] = dZposPsd[i];
+  }
+  Double_t dRinVacPsd[nSectsVacPsd];
+  for (Int_t i = 0; i < nSectsVacPsd; i++) {
+    dRinVacPsd[i] = 0.;
+  }
+  Double_t dRoutVacPsd[nSectsVacPsd];
+  for (Int_t i = 0; i < nSectsVacPsd; i++) {
+    dRoutVacPsd[i] = dRinPsd[i];
+  }
+  /*************************************************************/
+
+  /*************************************************************/
+  // Straight window
+  TString pipeNameWinEnd             = "pipe8 - second window @ the end, h=0.2mm, R=95mm";  // iron !!!
+  const Int_t nSectsWinEnd           = 2;
+  Double_t dZposWinEnd[nSectsWinEnd] = {dZposPsd[nSectsPsd - 1], dZposPsd[nSectsPsd - 1] + 0.2};  // mm
+  Double_t dRoutWinEnd[nSectsWinEnd] = {dRoutPsd[nSectsPsd - 1], dRoutPsd[nSectsPsd - 1]};        // mm
+  Double_t dRinWinEnd[nSectsWinEnd]  = {0., 0.};                                                  // mm
+
+  TString pipeVacNameWinEnd   = "pipevac8";
+  const Int_t nSectsVacWinEnd = 0;
+
+  /*************************************************************/
+  // --------------------------------------------------------------------------
+
+
+  // -------   Open info file   -----------------------------------------------
+  TString infoFileName = rootFileName;
+  infoFileName.ReplaceAll("root", "info");
+  fstream infoFile;
+  fstream infoFileEmpty;
+  infoFile.open(infoFileName.Data(), fstream::out);
+  infoFile << "SIS-100. Beam pipe geometry created with " + macrosname << endl << endl;
+  infoFile << "pipe_" << Version << " = pipe for the SIS100" << endl << endl;
+  infoFile << "Sections: MVD + STS + MUCH + TRD + TOF + PSD" << endl;
+  infoFile << "Beam pipe behind MUCH with R=95mm" << endl;
+  infoFile << "Beam pipe stops @ 19 m from target with 0.2 mm Fe" << endl;
+  infoFile << "Material:  " << pipeMediumName << endl;
+  infoFile << "Thickness: " << dPipeThickness << " mm" << endl << 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();
+  TGeoManager* gGeoMan = gGeoManager;
+  // --------------------------------------------------------------------------
+
+
+  // -----------------   Get and create the required media    -----------------
+  FairGeoMedia* geoMedia   = geoFace->getMedia();
+  FairGeoBuilder* geoBuild = geoLoad->getGeoBuilder();
+
+  // ---> pipe medium
+  FairGeoMedium* fPipeMedium = geoMedia->getMedium(pipeMediumName.Data());
+  TString fairError          = "FairMedium " + pipeMediumName + " not found";
+  if (!fPipeMedium) Fatal("Main", "FairMedium for PipeMedium not found");
+  geoBuild->createMedium(fPipeMedium);
+  TGeoMedium* pipeMedium = gGeoMan->GetMedium(pipeMediumName.Data());
+  TString geoError       = "Medium " + pipeMediumName + " not found";
+  if (!pipeMedium) Fatal("Main", "Medium for PipeMedium not found");
+  // ---> iron
+  FairGeoMedium* mIron = geoMedia->getMedium("iron");
+  if (!mIron) Fatal("Main", "FairMedium iron not found");
+  geoBuild->createMedium(mIron);
+  TGeoMedium* iron = gGeoMan->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 = gGeoMan->GetMedium("vacuum");
+  if (!vacuum) Fatal("Main", "Medium vacuum not found");
+  // --------------------------------------------------------------------------
+
+
+  // --------------   Create geometry and top volume  -------------------------
+  gGeoMan = (TGeoManager*) gROOT->FindObject("FAIRGeom");
+  gGeoMan->SetName("PIPEgeom");
+  TGeoVolume* top = new TGeoVolumeAssembly("TOP");
+  gGeoMan->SetTopVolume(top);
+  TGeoVolume* pipe = new TGeoVolumeAssembly(pipeName.Data());
+  // --------------------------------------------------------------------------
+
+
+  // -----   Create sections  -------------------------------------------------
+  infoFile << endl << "Beam pipe section: " << pipe1name << endl;
+  infoFile << setw(2) << "i" << setw(10) << "Z,mm" << setw(10) << "Rin,mm" << setw(10) << "Rout,mm" << setw(10)
+           << "h,mm" << endl;
+
+  TGeoVolume* pipe1 = MakePipe(1, nSects1, z1, rin1, rout1, pipeMedium, &infoFile);
+  pipe1->SetLineColor(kGray);
+  pipe->AddNode(pipe1, 0);
+
+  infoFile << endl << "Beam pipe section: " << pipe2name << endl;
+  infoFile << setw(2) << "i" << setw(10) << "Z,mm" << setw(10) << "Rin,mm" << setw(10) << "Rout,mm" << setw(10)
+           << "h,mm" << endl;
+  TGeoVolume* pipe2 = MakePipe(2, nSects2, z2, rin2, rout2, pipeMedium, &infoFile);
+  pipe2->SetLineColor(kBlue);
+  pipe->AddNode(pipe2, 0);
+  TGeoVolume* pipevac1 = MakeVacuum(1, nSects01, z01, rin01, rout01, vacuum, &infoFile);
+  pipevac1->SetLineColor(kCyan);
+  pipe->AddNode(pipevac1, 0);
+
+  infoFile << endl << "Beam pipe section: " << pipe3name << endl;
+  infoFile << setw(2) << "i" << setw(10) << "Z,mm" << setw(10) << "Rin,mm" << setw(10) << "Rout,mm" << setw(10)
+           << "h,mm" << endl;
+  TGeoVolume* pipe3 = MakePipe(3, nSects3, z3, rin3, rout3, pipeMedium, &infoFile);
+  pipe3->SetLineColor(kGreen);
+  pipe->AddNode(pipe3, 0);
+  TGeoVolume* pipevac2 = MakeVacuum(3, nSects02, z02, rin02, rout02, vacuum, &infoFile);
+  pipevac2->SetLineColor(kCyan);
+  pipe->AddNode(pipevac2, 0);
+
+  infoFile << endl << "Beam pipe section: " << pipeNameMuch << endl;
+  infoFile << setw(2) << "i" << setw(10) << "Z,mm" << setw(10) << "Rin,mm" << setw(10) << "Rout,mm" << setw(10)
+           << "h,mm" << endl;
+  TGeoVolume* pipeMuch = MakePipe(4, nSectsMuch, dZposMuch, dRinMuch, dRoutMuch, pipeMedium, &infoFile);
+  pipeMuch->SetLineColor(kGreen);
+  pipe->AddNode(pipeMuch, 0);
+  TGeoVolume* pipeVacMuch = MakeVacuum(4, nSectsVacMuch, dZposVacMuch, dRinVacMuch, dRoutVacMuch, vacuum, &infoFile);
+  pipeVacMuch->SetLineColor(kCyan);
+
+  TGeoRotation* pipe_rot = new TGeoRotation();
+  pipe_rot->RotateY(pipeRotationAngle[energy]);
+
+  TGeoTranslation* pipe_trans1 = new TGeoTranslation("pipe_trans1", pipeXshift1, 0., 0);
+  TGeoCombiTrans* combi_trans1 = new TGeoCombiTrans(*pipe_trans1, *pipe_rot);
+
+  TGeoTranslation* pipe_trans2 = new TGeoTranslation("pipe_trans2", pipeXshift2, 0., 0.);
+  TGeoTranslation* pipe_trans3 = new TGeoTranslation("pipe_trans3", pipeXshift3, 0., 0.);
+  TGeoCombiTrans* combi_trans2 = new TGeoCombiTrans(*pipe_trans2, *pipe_rot);
+
+  infoFile << endl << "Beam pipe section: " << pipeNameTrd << endl;
+  infoFile << setw(2) << "i" << setw(10) << "Z,mm" << setw(10) << "Rin,mm" << setw(10) << "Rout,mm" << setw(10)
+           << "h,mm" << endl;
+  TGeoVolume* pipeTrd = MakePipe(5, nSectsTrd, dZposTrd, dRinTrd, dRoutTrd, pipeMedium, &infoFile);
+  pipeTrd->SetLineColor(kGreen);
+  //pipe->AddNode(pipeTrd, 0, combi_trans2);
+
+  TGeoVolume* pipeVacTrd = MakeVacuum(5, nSectsVacTrd, dZposVacTrd, dRinVacTrd, dRoutVacTrd, vacuum, &infoFile);
+  pipeVacTrd->SetLineColor(kCyan);
+  //pipe->AddNode(pipeVacTrd, 0, combi_trans2);
+
+  infoFile << endl << "Beam pipe section: " << pipeNameWin << ", material: iron" << endl;
+  infoFile << setw(2) << "i" << setw(10) << "Z,mm" << setw(10) << "Rin,mm" << setw(10) << "Rout,mm" << setw(10)
+           << "h,mm" << endl;
+  TGeoVolume* pipeWin = MakePipe(6, nSectsWin, dZposWin, dRinWin, dRoutWin, iron, &infoFile);
+  pipeWin->SetLineColor(kBlue);
+  //pipe->AddNode(pipeWin, 0, combi_trans1);
+
+  TGeoVolume* pipeWinVac = MakeVacuum(6, nSectsWinVac, dZposWinVac, dRinWinVac, dRoutWinVac, vacuum, &infoFile);
+  pipeWinVac->SetLineColor(kCyan);
+  pipeWin->AddNode(pipeWinVac, 0, pipe_trans3);
+  //pipe->AddNode(pipeWin, 0, combi_trans1);
+
+  pipeVacMuch->AddNodeOverlap(pipeTrd, 0, combi_trans2);
+  pipeVacMuch->AddNodeOverlap(pipeVacTrd, 0, combi_trans2);
+  pipeVacMuch->AddNodeOverlap(pipeWinVac, 0, pipe_trans3);
+  pipe->AddNode(pipeVacMuch, 0);
+
+  infoFile << endl << "Beam pipe section: " << pipeNamePsd << endl;
+  infoFile << setw(2) << "i" << setw(10) << "Z,mm" << setw(10) << "Rin,mm" << setw(10) << "Rout,mm" << setw(10)
+           << "h,mm" << endl;
+  TGeoVolume* pipePsd = MakePipe(7, nSectsPsd, dZposPsd, dRinPsd, dRoutPsd, pipeMedium, &infoFile);
+  pipePsd->SetLineColor(kCyan);
+  pipe->AddNode(pipePsd, 0, combi_trans2);
+
+  TGeoVolume* pipeVacPsd = MakeVacuum(7, nSectsVacPsd, dZposVacPsd, dRinVacPsd, dRoutVacPsd, vacuum, &infoFile);
+  pipeVacPsd->SetLineColor(kCyan);
+  pipe->AddNode(pipeVacPsd, 0, combi_trans2);
+
+  infoFile << endl << "Beam pipe section: " << pipeNameWinEnd << ", material: iron" << endl;
+  infoFile << setw(2) << "i" << setw(10) << "Z,mm" << setw(10) << "Rin,mm" << setw(10) << "Rout,mm" << setw(10)
+           << "h,mm" << endl;
+  TGeoVolume* pipeWinEnd = MakePipe(8, nSectsWinEnd, dZposWinEnd, dRinWinEnd, dRoutWinEnd, iron, &infoFile);
+  pipeWinEnd->SetLineColor(kBlue);
+  pipe->AddNode(pipeWinEnd, 0, combi_trans2);
+
+  // -----   End   --------------------------------------------------
+
+  // ---------------   Finish   -----------------------------------------------
+  top->AddNode(pipe, 1);
+  cout << endl << endl;
+  gGeoMan->CloseGeometry();
+  gGeoMan->CheckOverlaps(0.0001);
+  gGeoMan->PrintOverlaps();
+  gGeoMan->Test();
+
+  TFile* rootFile = new TFile(rootFileName, "RECREATE");
+  top->Write();
+  cout << endl;
+  cout << "Geometry " << top->GetName() << " written to " << rootFileName << endl;
+  TGeoTranslation* trans = new TGeoTranslation(0., 0., -40.0);
+  cout << "Geometry shifted by 40 cm upstream." << endl;
+  trans->Write("trans");
+  rootFile->Close();
+  infoFile.close();
+
+  // visualize it with ray tracing, OGL/X3D viewer
+  //top->Raytrace();
+  // top->Draw("ogl");
+  //top->Draw("x3d");
+}
+// ============================================================================
+// ======                   End of main function                          =====
+// ============================================================================
+
+
+// =====  Make the beam pipe volume   =========================================
+TGeoPcon* MakeShape(Int_t nSects, char* name, Double_t* z, Double_t* rin, Double_t* rout, fstream* infoFile)
+{
+
+  // ---> Shape
+  TGeoPcon* shape = new TGeoPcon(name, 0., 360., nSects);
+  for (Int_t iSect = 0; iSect < nSects; iSect++) {
+    shape->DefineSection(iSect, z[iSect] / 10., rin[iSect] / 10., rout[iSect] / 10.);  // mm->cm
+    *infoFile << setw(2) << iSect + 1 << setw(10) << fixed << setprecision(2) << z[iSect] << setw(10) << fixed
+              << setprecision(2) << rin[iSect] << setw(10) << fixed << setprecision(2) << rout[iSect] << setw(10)
+              << fixed << setprecision(2) << rout[iSect] - rin[iSect] << endl;
+  }
+
+  return shape;
+}
+// ============================================================================
+
+
+// =====  Make the beam pipe volume   =========================================
+TGeoVolume* MakePipe(Int_t iPart, Int_t nSects, Double_t* z, Double_t* rin, Double_t* rout, TGeoMedium* medium,
+                     fstream* infoFile)
+{
+
+  // ---> Shape
+  TGeoPcon* shape = new TGeoPcon(0., 360., nSects);
+  for (Int_t iSect = 0; iSect < nSects; iSect++) {
+    shape->DefineSection(iSect, z[iSect] / 10., rin[iSect] / 10., rout[iSect] / 10.);  // mm->cm
+    *infoFile << setw(2) << iSect + 1 << setw(10) << fixed << setprecision(2) << z[iSect] << setw(10) << fixed
+              << setprecision(2) << rin[iSect] << setw(10) << fixed << setprecision(2) << rout[iSect] << setw(10)
+              << fixed << setprecision(2) << rout[iSect] - rin[iSect] << endl;
+  }
+
+  // ---> Volume
+  TString volName  = Form("pipe%i", iPart);
+  TGeoVolume* pipe = new TGeoVolume(volName.Data(), shape, medium);
+
+  return pipe;
+}
+// ============================================================================
+
+
+// =====   Make the volume for the vacuum inside the beam pipe   ==============
+TGeoVolume* MakeVacuum(Int_t iPart, Int_t nSects, Double_t* z, Double_t* rin, Double_t* rout, TGeoMedium* medium,
+                       fstream* infoFile)
+{
+
+  // ---> Shape
+  TGeoPcon* shape = new TGeoPcon(0., 360., nSects);
+  for (Int_t iSect = 0; iSect < nSects; iSect++) {
+    shape->DefineSection(iSect, z[iSect] / 10., rin[iSect] / 10., rout[iSect] / 10.);  // mm->cm
+  }
+
+  // ---> Volume
+  TString volName     = Form("pipevac%i", iPart);
+  TGeoVolume* pipevac = new TGeoVolume(volName.Data(), shape, medium);
+
+  return pipevac;
+}
+// ============================================================================
diff --git a/macro/psd/create_psdgeo_with_hole.C b/macro/psd/create_psdgeo_with_hole.C
index a40bd13f639b6faa3aadfd90e05bd4f17246ac14..9750df9b0475b661dc999a2afe561482a1dfb592 100644
--- a/macro/psd/create_psdgeo_with_hole.C
+++ b/macro/psd/create_psdgeo_with_hole.C
@@ -39,7 +39,7 @@ TGeoVolume* ConstructShield(const char* name, Double_t sizeXY, Double_t holesize
 
 void create_psdgeo_with_hole()
 {
-  TString geoTag = "v20b";  // Geometry tag
+  TString geoTag = "v20c";  // Geometry tag
 
   // -----   Steering variables   ---------------------------------------------
   Double_t psdX;      // x position (cm) of PSD in cave (front plane center)
@@ -48,7 +48,14 @@ void create_psdgeo_with_hole()
   Double_t psdRotY;   // Rotation of PSD around y axis (rad)
   Double_t holeSize;  // side length of the square shaped hole (cm)
 
-  if (geoTag == "v20a") {
+  if (geoTag == "v20c") {
+    psdX     = 12.95;
+    psdY     = 0.;
+    psdZ     = 1010;
+    psdRotY  = 0.0132;
+    holeSize = 20.;
+  }
+  else if (geoTag == "v20a") {
     psdX     = 12.95;
     psdY     = 0.;
     psdZ     = 1050;
diff --git a/macro/run/CMakeLists.txt b/macro/run/CMakeLists.txt
index bfacfd6ff2de219112153d7e333c137777ea91a8..c5eaf7de3c89048c774beadd280517fb9d3019f9 100644
--- a/macro/run/CMakeLists.txt
+++ b/macro/run/CMakeLists.txt
@@ -36,10 +36,15 @@ math(EXPR nBeam "${nEvents} * 3")
 
 # =====   Define the different setups to be tested with   ====================
 if(NOT ${CBM_TEST_MODEL} MATCHES Experimental )
-  List(APPEND cbm_setup sis100_hadron sis100_electron sis100_muon_lmvm
-  	sis100_muon_jpsi sis300_electron)
+  List(APPEND cbm_setup 
+	sis100_hadron_APR21 sis100_electron_APR21 
+	sis100_muon_lmvm_APR21 sis100_muon_jpsi_APR21 
+	sis300_electron
+	sis100_hadron sis100_electron
+	sis100_hadron_DEC21 sis100_electron_DEC21  
+	)
 else()
-  List(APPEND cbm_setup sis100_electron sis100_muon_jpsi)
+  List(APPEND cbm_setup sis100_electron_APR21 sis100_muon_jpsi_APR21)
 endif()
 # ============================================================================
 
@@ -171,7 +176,7 @@ foreach(setup IN LISTS cbm_setup)
   # --- Event-by-event reconstruction from event-based simulation
   # --- Ideal raw event builder
   set(testname run_${sname}_reco_ev_ideal)
-  add_test(${testname} ${MACRODIR}/run_reco.sh
+  add_test(${testname}	 ${MACRODIR}/run_reco.sh
   	\"data/${sname}_ev\" -1 0 \"data/${sname}_eb_eb_ideal\" \"Ideal\" \"${setup}\" \"data/${sname}_coll\")
   set_tests_properties(${testname} PROPERTIES
   	TIMEOUT ${timeOutTime}
diff --git a/macro/run/run_tra_beam.C b/macro/run/run_tra_beam.C
index ff41a84ca9a5794f05554c65adfcc97109980b4c..8a474f35ea54db0ea62866cd188ef9bacf551d8e 100644
--- a/macro/run/run_tra_beam.C
+++ b/macro/run/run_tra_beam.C
@@ -137,13 +137,25 @@ void run_tra_beam(Int_t nEvents = 1, const char* species = "Au", Double_t beamP
   Double_t beamSigmaTy = 0.001;  // Gaussian sigma of beam x-y angle [rad]
   // ------------------------------------------------------------------------
 
+  // -----  Target properties -----------------------------------------------
+  Double_t targetZpos = -40.0;
+  // The target position is at z=0 for the old coordinate system but is intended
+  // to be moved to -4cm in the DEC21 release. The global coordinate system will
+  // also shift from the old target position to the center of the magnet which
+  // is a net displacement of -40 cm. In terms of the new coordainte system
+  // the target is therefore to be at -44 cm. In order not to cause forgetting
+  // we will automate the shifting process for a short time, until the full move
+  // has been completed.
+  if (strstr(setup, "_APR21")) targetZpos = 0.0;
+  if (strstr(setup, "_DEC21")) targetZpos = -44.0;
+  std::cout << "Target is at " << targetZpos << "cm from origin" << std::endl;
+  // ------------------------------------------------------------------------
 
   // -----   Timer   --------------------------------------------------------
   TStopwatch timer;
   timer.Start();
   // ------------------------------------------------------------------------
 
-
   // --- Transport run   ----------------------------------------------------
   CbmTransport run;
   run.SetEngine(engine);
@@ -151,7 +163,7 @@ void run_tra_beam(Int_t nEvents = 1, const char* species = "Au", Double_t beamP
   run.SetParFileName(parFile);
   run.SetGeoFileName(geoFile);
   run.LoadSetup(setup);
-  run.SetTarget("Gold", 0.025, 2.5);
+  run.SetTarget("Gold", 0.025, 2.5, 0, 0, targetZpos);
   run.SetBeamPosition(beamMeanX, beamMeanY, beamSigmaX, beamSigmaY, beamFocusZ);
   run.SetBeamAngle(beamMeanTx, beamMeanTy, beamSigmaTx, beamSigmaTy);
   run.AddInput(new CbmBeamGenerator(beamZ, beamA, beamQ, beamP, beamStartZ));
diff --git a/macro/run/run_tra_file.C b/macro/run/run_tra_file.C
index e188d9710c4658a5239eef8e352cedffbbef5a26..f2395aba50f6a45354ab157fac5dc0219abb4167 100644
--- a/macro/run/run_tra_file.C
+++ b/macro/run/run_tra_file.C
@@ -108,7 +108,18 @@ void run_tra_file(const char* input = "", Int_t nEvents = 1, const char* output
   const char* targetMedium = "Gold";
   Double_t targetThickness = 0.025;  // in cm
   Double_t targetDiameter  = 2.5;    // in cm
-  Double_t targetZpos = -40
+
+  Double_t targetZpos = -40.0;
+  // The target position is at z=0 for the old coordinate system but is intended
+  // to be moved to -4cm in the DEC21 release. The global coordinate system will
+  // also shift from the old target position to the center of the magnet which
+  // is a net displacement of -40 cm. In terms of the new coordainte system
+  // the target is therefore to be at -44 cm. In order not to cause forgetting
+  // we will automate the shifting process for a short time, until the full move
+  // has been completed.
+  if (strstr(setup, "_APR21")) targetZpos = 0.0;
+  if (strstr(setup, "_DEC21")) targetZpos = -44.0;
+  std::cout << "Target is at " << targetZpos << "cm from origin" << std::endl;
   // ------------------------------------------------------------------------
 
   // -----   Beam properties   ----------------------------------------------
@@ -151,7 +162,6 @@ void run_tra_file(const char* input = "", Int_t nEvents = 1, const char* output
   run.SetParFileName(parFile);
   run.SetGeoFileName(geoFile);
   run.LoadSetup(setup);
-//  run.SetTarget(targetMedium, targetThickness, targetDiameter);
   run.SetTarget(targetMedium, targetThickness, targetDiameter, 0, 0, targetZpos);
   run.SetBeamPosition(beamPosX, beamPosY, beamSigmaX, beamSigmaY);
   if (rotateEvents) run.SetRandomEventPlane();
diff --git a/macro/sts/geometry/create_stsgeo_v20a.C b/macro/sts/geometry/create_stsgeo_v20a.C
new file mode 100644
index 0000000000000000000000000000000000000000..6690a10704244a5e95267ee2b61bf11090bd2a7d
--- /dev/null
+++ b/macro/sts/geometry/create_stsgeo_v20a.C
@@ -0,0 +1,2139 @@
+/* Copyright (C) 2012-2021 Facility for Antiproton and Ion Research in Europe, Darmstadt
+   SPDX-License-Identifier: GPL-3.0-only
+   Authors: Volker Friese, Evgeny Lavrik [committer] */
+
+/******************************************************************************
+ ** Creation of STS geometry in ROOT format (TGeo).
+ **
+ ** @file create_stsgeo_v20a.C
+ ** @author Volker Friese <v.friese@gsi.de>
+ ** @since 15 June 2012
+ ** @date 09.05.2014
+ ** @author Tomas Balog <T.Balog@gsi.de>
+ **
+ ** v20a: shift to centre of magnet as origin
+ ** v19a: import passive materials from gdml file
+ **       extend CF ladder structures and cables towards FEE plane
+ **       change CF ladder frame shape
+ ** v18d: increases thickness of sensors within a 7.5 degree cone from 300 mu to 400 mu (based on v18b)
+ ** v18c: fixed cut-out windows in cooling plates, improve the box shape/materials
+ ** v18b: increases thickness of sensors within a 7.5 degree cone from 300 mu to 400 mu
+ ** v18a: adds 9 cooling/holding plates and a box around the setup
+ ** v16g: v16g is the new standard geometry from November 2017
+ ** v16g: switch from stations to units - left / right ("Unit01L", "Unit01R")
+ ** v16f: switch from stations to units
+ **     - split in upstream / downstream and left / right parts
+ **     - named Unit0xUR, Unit0xUL, Unit0xDR, Unit0xDL
+ ** v16e: switch from stations to units - upstream / downstream ("Unit01U", "Unit01D")
+ ** v16d: skip keeping volumes of sts and stations
+ ** v16c: like v16b, but senors of ladders beampipe next to beampipe
+ **       shifted closer to the pipe, like in the CAD model
+ ** v16b: like v16a, but yellow sensors removed
+ ** v16a: derived from v15c (no cones), but with sensor types renamed:
+ ** 2 -> 1, 3 -> 2, 4 -> 3, 5 -> 4, 1 -> 5
+ **
+ ** v15c: as v15b without cones
+ ** v15b: introduce modified carbon ladders from v13z
+ ** v15a: with flipped ladder orientation for stations 0,2,4,6 to match CAD design
+ **
+ ** TODO:
+ **
+ ** DONE:
+ ** v15b - use carbon macaroni as ladder support
+ ** v15b - introduce a small gap between lowest sensor and carbon ladder
+ ** v15b - build small cones for the first 2 stations
+ ** v15b - within a station the ladders of adjacent units should not touch eachother - set gkLadderGapZ to 10 mm
+ ** v15b - for all ladders set an even number of ladder elements 
+ ** v15b - z offset of cones to ladders should not be 0.3 by default, but 0.26
+ ** v15b - within a station the ladders should be aligned in z, defined either by the unit or the ladder with most sensors
+ ** v15b - get rid of cone overlap in stations 7 and 8 - done by adapting rHole size
+ **
+ ** The geometry hierarachy is:
+ **
+ ** 1. Sensors  (see function CreateSensors)
+ **    The sensors are the active volumes and the lowest geometry level.
+ **    They are built as TGeoVolumes, shape box, material silicon.
+ **    x size is determined by strip pitch 58 mu and 1024 strips 
+ **    plus guard ring of 1.3 mm at each border -> 6.1992 cm.
+ **    Sensor type 1 is half of that (3.0792 cm).
+ **    y size is determined by strip length (2.2 / 4.2 / 6.3 cm) plus
+ **    guard ring of 1.3 mm at top and bottom -> 2.46 / 4.46 / 6.46 cm.
+ **    z size is a parameter, to be set by gkSensorThickness.
+ **
+ ** 2. Sectors  (see function CreateSectors)
+ **    Sectors consist of several chained sensors. These are arranged
+ **    vertically on top of each other with a gap to be set by
+ **    gkChainGapY. Sectors are constructed as TGeoVolumeAssembly.
+ **    The sectors are auxiliary volumes used for proper placement
+ **    of the sensor(s) in the module. They do not show up in the
+ **    final geometry.
+ **
+ ** 3. Modules (see function ConstructModule)
+ **    A module is a readout unit, consisting of one sensor or
+ **    a chain of sensors (see sector) and a cable.
+ **    The cable extends from the top of the sector vertically to the
+ **    top of the halfladder the module is placed in. The cable and module
+ **    volume thus depend on the vertical position of the sector in 
+ **    the halfladder. The cables consist of silicon with a thickness to be
+ **    set by gkCableThickness.
+ **    Modules are constructed as TGeoVolume, shape box, medium gStsMedium.
+ **    The module construction can be switched off (gkConstructCables)
+ **    to reproduce older geometries.
+ **
+ ** 4. Halfladders (see function ConstructHalfLadder)
+ **    A halfladder is a vertical assembly of several modules. The modules
+ **    are placed vertically such that their sectors overlap by 
+ **    gkSectorOverlapY. They are displaced in z direction to allow for the 
+ **    overlap in y by gkSectorGapZ.
+ **    The horizontal placement of modules in the halfladder can be choosen
+ **    to left aligned or right aligned, which only matters if sensors of
+ **    different x size are involved.
+ **    Halfladders are constructed as TGeoVolumeAssembly.
+ **
+ ** 5. Ladders (see function CreateLadders and ConstructLadder)
+ **    A ladder is a vertical assembly of two halfladders, and is such the
+ **    vertical building block of a station. The second (bottom) half ladder
+ **    is rotated upside down. The vertical arrangement is such that the
+ **    inner sectors of the two halfladders have the overlap gkSectorOverlapY
+ **    (function CreateLadder) or that there is a vertical gap for the beam
+ **    hole (function CreateLadderWithGap).
+ **    Ladders are constructed as TGeoVolumeAssembly.
+ **   
+ ** 6. Stations (see function ConstructStation)
+ **    A station represents one layer of the STS geometry: one measurement
+ **    at (approximately) a given z position. It consist of several ladders
+ **    arranged horizontally to cover the acceptance.
+ **    The ladders are arranged such that there is a horizontal overlap
+ **    between neighbouring ladders (gkLadderOverLapX) and a vertical gap
+ **    to allow for this overlap (gkLadderGapZ). Each second ladder is
+ **    rotated around its y axis to face away from or into the beam.
+ **    Stations are constructed as TGeoVolumes, shape box minus tube (for
+ **    the beam hole), material gStsMedium.
+ **
+ ** 7. STS
+ **    The STS is a volume hosting the entire detectors system. It consists
+ **    of several stations located at different z positions.
+ **    The STS is constructed as TGeoVolume, shape box minus cone (for the
+ **    beam pipe), material gStsMedium. The size of the box is computed to
+ **    enclose all stations.
+ *****************************************************************************/
+
+
+// Remark: With the proper steering variables, this should exactly reproduce
+// the geometry version v11b of A. Kotynia's described in the ASCII format.
+// The only exception is a minimal difference in the z position of the
+// sectors/sensors. This is because of ladder types 2 and 4 containing the half
+// sensors around the beam hole (stations 1,2 and 3). In v11b, the two ladders
+// covering the beam hole cannot be transformed into each other by rotations,
+// but only by a reflection. This means they are constructionally different.
+// To avoid introducing another two ladder types, the difference in z position
+// was accepted.
+
+
+// Differences to v12:
+// gkChainGap reduced from 1 mm to 0
+// gkCableThickness increased from 100 mum to 200 mum (2 cables per module)
+// gkSectorOverlapY reduced from 3 mm to 2.4 mm
+// New sensor types 05 and 06
+// New sector types 07 and 08
+// Re-definiton of ladders (17 types instead of 8)
+// Re-definiton of station from new ladders
+
+
+#include "TGeoCompositeShape.h"
+#include "TGeoCone.h"
+#include "TGeoManager.h"
+#include "TGeoPara.h"
+#include "TGeoPhysicalNode.h"
+#include "TGeoTrd2.h"
+#include "TGeoTube.h"
+#include "TGeoXtru.h"
+
+#include <iomanip>
+#include <iostream>
+
+// forward declarations
+Int_t CreateSensors();
+Int_t CreateSectors();
+Int_t CreateLadders();
+TGeoVolume* ConstructModule(const char* name, TGeoVolume* sector, Double_t cableLength);
+TGeoVolume* ConstructHalfLadder(const TString& name, Int_t nSectors, Int_t* sectorTypes, char align,
+                                Double_t ladderLength, Double_t offsetY);
+TGeoVolume* ConstructLadder(Int_t LadderIndex, TGeoVolume* halfLadderU, TGeoVolume* halfLadderD, Double_t gapY,
+                            Double_t shiftZ);
+TGeoVolume* ConstructUnit(Int_t iSide, Int_t iUnit, Int_t nLadders, Int_t* ladderTypes, Int_t iStation);
+void ImportPassive(TGeoVolume* stsVolume, TString geoTag, fstream& infoFile);
+void PostProcessGdml(TGeoVolume* gdmlTop);
+void CheckVolume(TGeoVolume* volume);
+void CheckVolume(TGeoVolume* volume, fstream& file, Bool_t listChildren = kTRUE);
+Double_t BeamPipeRadius(Double_t z);
+TGeoVolume* ConstructFrameElement(const TString& name, TGeoVolume* frameBoxVol, Double_t x);
+TGeoVolume* ConstructSmallCone(Double_t coneDz);
+TGeoVolume* ConstructBigCone(Double_t coneDz);
+
+// -------------   Version highlight        -----------------------------------
+
+const std::string gVersionHighlight = R"(
+Summary:
+  This version adds passive materials imported from GDML model to the STS geometry:
+    * Taken from and largely correspond to mechanical CAD drawings of the detector
+    * Thermal insulation box:
+      - made out of carbon sandwitch panel (2mm carbon fiber sheet + layer of carbon foam + 2mm carbon fiber sheet)
+      - front window of complex shape with interface to MVD / target chamber
+      - back window with large aperture (2000 x 1200 mm) square cut into carbon foam
+    * Structural units:
+      - made of 2 complex shape aluminum C-Frames, 15mm thick
+      - placed at 25, 35, ... ,105 cm absolute Z
+      - contain front-end and power distribution boxes with equivalent X_0 values
+
+  Scripted geometry tweaks:
+    * Ladders and cables are extended towards the read-out planes having same lengths in respective rows
+    * Adjusted form and shape of carbon ladder structures from L-type to X-type
+    * Reduced verbosity of this file
+
+  Sensor arrangement is the same as in version v16g
+
+  !! Important for this version is the discrepancy from the mechanical CAD w.r.t. front wall.
+  The square window was replaced by a round one to avoid overlaps with present beam pipe designs, e.g. pipe_v16b_1e
+)";
+
+// -------------   Steering variables       -----------------------------------
+
+// ---> Horizontal width of sensors [cm]
+const Double_t gkSensorSizeX = 6.2092;
+
+// ---> Thickness of sensors [cm]
+const Double_t gkSensorThickness = 0.03;
+
+// ---> Vertical gap between chained sensors [cm]
+const Double_t gkChainGapY = 0.00;
+
+// ---> Thickness of cables [cm]
+const Double_t gkCableThickness = 0.02;
+
+// ---> Vertical overlap of neighbouring sectors in a ladder [cm]
+const Double_t gkSectorOverlapY = 0.27;  // DEJH -> 0.3345 / 0.4600
+
+// ---> Gap in z between neighbouring sectors in a ladder [cm]
+const Double_t gkSectorGapZ = 0.02;  // DEJH -> 0.07 / 0.07
+
+// ---> Horizontal overlap of neighbouring ladders [cm]
+const Double_t gkLadderOverlapX = 0.30;  // DEJH -> 0.25 / 0.25
+
+// ---> Gap in z between neighbouring ladders [cm]
+const Double_t gkLadderGapZ = 1.00;  // DEJH -> 0.90 / 0.50
+
+// ---> Gap in z between lowest sector to carbon support structure [cm]
+const Double_t gkSectorGapZFrame = 0.10;
+
+// ---> Switch to construct / not to construct readout cables
+const Bool_t gkConstructCables = kTRUE;
+
+// ---> Switch to construct / not to construct frames
+const Bool_t gkConstructCones       = kFALSE;  // kTRUE;   // switch this false by default for v15c and v16x
+const Bool_t gkConstructFrames      = kTRUE;   // kFALSE;  // switch this true  by default for v15c and v16x
+const Bool_t gkConstructSmallFrames = kTRUE;   // kFALSE;
+const Bool_t gkCylindricalFrames    = kTRUE;   // kFALSE;
+
+// ---> Size of the frame
+const Double_t gkFrameThickness     = 0.2;
+const Double_t gkThinFrameThickness = 0.05;
+const Double_t gkFrameStep          = 4.0;  // size of frame cell along y direction
+
+const Double_t gkCylinderDiaInner =
+  0.07;  // properties of cylindrical carbon supports, see CBM-STS Integration Meeting (10 Jul 2015)
+const Double_t gkCylinderDiaOuter =
+  0.15;  // properties of cylindrical carbon supports, see CBM-STS Integration Meeting (10 Jul 2015)
+
+// ---> Switch to import / not to import the Passive materials from GDML file
+const Bool_t gkImportPassive = kTRUE;
+
+// ----------------------------------------------------------------------------
+
+
+// --------------   Parameters of beam pipe in the STS region    --------------
+// ---> Needed to compute stations and STS such as to avoid overlaps
+const Double_t gkPipeZ1 = 22.0;
+const Double_t gkPipeR1 = 1.8;
+const Double_t gkPipeZ2 = 50.0;
+const Double_t gkPipeR2 = 1.8;
+const Double_t gkPipeZ3 = 125.0;
+const Double_t gkPipeR3 = 5.5;
+
+//DE const Double_t gkPipeZ1 =  27.0;
+//DE const Double_t gkPipeR1 =   1.05;
+//DE const Double_t gkPipeZ2 = 160.0;
+//DE const Double_t gkPipeR2 =   3.25;
+// ----------------------------------------------------------------------------
+
+//TString unitName[16] =    // names of units for v16e
+// {            "Unit00D",
+//   "Unit01U", "Unit01D",
+//   "Unit02U", "Unit02D",
+//   "Unit03U", "Unit03D",
+//   "Unit04U", "Unit04D",
+//   "Unit05U", "Unit05D",
+//   "Unit06U", "Unit06D",
+//   "Unit07U", "Unit07D",
+//   "Unit08U"            };
+
+//TString unitName[32] =    // names of units for v16f
+// {                         "Unit00DR", "Unit00DL",
+//   "Unit01UR", "Unit01UL", "Unit01DR", "Unit01DL",
+//   "Unit02UR", "Unit02UL", "Unit02DR", "Unit02DL",
+//   "Unit03UR", "Unit03UL", "Unit03DR", "Unit03DL",
+//   "Unit04UR", "Unit04UL", "Unit04DR", "Unit04DL",
+//   "Unit05UR", "Unit05UL", "Unit05DR", "Unit05DL",
+//   "Unit06UR", "Unit06UL", "Unit06DR", "Unit06DL",
+//   "Unit07UR", "Unit07UL", "Unit07DR", "Unit07DL",
+//   "Unit08UR", "Unit08UL" };
+
+TString unitName[32] =  // names of units for v16g - while merging D and U parts
+  {"Unit00R", "Unit00L", "Unit01R", "Unit01L", "Unit01R", "Unit01L", "Unit02R", "Unit02L",
+   "Unit02R", "Unit02L", "Unit03R", "Unit03L", "Unit03R", "Unit03L", "Unit04R", "Unit04L",
+   "Unit04R", "Unit04L", "Unit05R", "Unit05L", "Unit05R", "Unit05L", "Unit06R", "Unit06L",
+   "Unit06R", "Unit06L", "Unit07R", "Unit07L", "Unit07R", "Unit07L", "Unit08R", "Unit08L"};
+
+TString unitName18[18] =  // names of units for v16g
+  {"Unit00R", "Unit00L", "Unit01R", "Unit01L", "Unit02R", "Unit02L", "Unit03R", "Unit03L", "Unit04R",
+   "Unit04L", "Unit05R", "Unit05L", "Unit06R", "Unit06L", "Unit07R", "Unit07L", "Unit08R", "Unit08L"};
+
+// -------------   Other global variables   -----------------------------------
+// ---> STS medium (for every volume except silicon)
+TGeoMedium* gStsMedium = NULL;  // will be set later
+// ---> TGeoManager (too lazy to write out 'Manager' all the time
+TGeoManager* gGeoMan = NULL;  // will be set later
+// ----------------------------------------------------------------------------
+
+
+// ============================================================================
+// ======                         Main function                           =====
+// ============================================================================
+
+void create_stsgeo_v20a(const char* geoTag = "v20a")
+{
+
+  // -------   Geometry file name (output)   ----------------------------------
+  TString geoFileName = "sts_";
+  geoFileName         = geoFileName + geoTag + ".geo.root";
+  // --------------------------------------------------------------------------
+
+
+  // -------   Open info file   -----------------------------------------------
+  TString infoFileName = geoFileName;
+  infoFileName.ReplaceAll("root", "info");
+  fstream infoFile;
+  infoFile.open(infoFileName.Data(), fstream::out);
+  infoFile << "STS geometry created with create_stsgeo_v20a.C" << endl;
+  infoFile << gVersionHighlight << endl;
+  infoFile << "Global variables: " << endl;
+  infoFile << "Sensor thickness = " << gkSensorThickness << " cm" << endl;
+  infoFile << "Vertical gap in sensor chain = " << gkChainGapY << " cm" << endl;
+  infoFile << "Vertical overlap of sensors = " << gkSectorOverlapY << " cm" << endl;
+  infoFile << "Gap in z between neighbour sensors = " << gkSectorGapZ << " cm" << endl;
+  infoFile << "Horizontal overlap of sensors = " << gkLadderOverlapX << " cm" << endl;
+  infoFile << "Gap in z between neighbour ladders = " << gkLadderGapZ << " cm" << endl;
+  if (gkConstructCables) infoFile << "Cable thickness = " << gkCableThickness << " cm" << endl;
+  else
+    infoFile << "No cables" << endl;
+  infoFile << endl;
+  infoFile << "Beam pipe: R1 = " << gkPipeR1 << " cm at z = " << gkPipeZ1 << " cm" << endl;
+  infoFile << "Beam pipe: R2 = " << gkPipeR2 << " cm at z = " << gkPipeZ2 << " cm" << endl;
+  infoFile << "Beam pipe: R3 = " << gkPipeR3 << " cm at z = " << gkPipeZ3 << " cm" << 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();
+  gGeoMan = gGeoManager;
+  // --------------------------------------------------------------------------
+
+
+  // -----------------   Get and create the required media    -----------------
+  FairGeoMedia* geoMedia   = geoFace->getMedia();
+  FairGeoBuilder* geoBuild = geoLoad->getGeoBuilder();
+
+  // ---> air
+  FairGeoMedium* mAir = geoMedia->getMedium("air");
+  if (!mAir) Fatal("Main", "FairMedium air not found");
+  geoBuild->createMedium(mAir);
+  TGeoMedium* air = gGeoMan->GetMedium("air");
+  if (!air) Fatal("Main", "Medium air not found");
+
+  // ---> silicon
+  FairGeoMedium* mSilicon = geoMedia->getMedium("silicon");
+  if (!mSilicon) Fatal("Main", "FairMedium silicon not found");
+  geoBuild->createMedium(mSilicon);
+  TGeoMedium* silicon = gGeoMan->GetMedium("silicon");
+  if (!silicon) Fatal("Main", "Medium silicon not found");
+
+  // ---> carbon
+  FairGeoMedium* mCarbon = geoMedia->getMedium("carbon");
+  if (!mCarbon) Fatal("Main", "FairMedium carbon not found");
+  geoBuild->createMedium(mCarbon);
+  TGeoMedium* carbon = gGeoMan->GetMedium("carbon");
+  if (!carbon) Fatal("Main", "Medium carbon not found");
+
+  // ---> STSBoxCarbonFoam
+  FairGeoMedium* mSTSBoxCarbonFoam = geoMedia->getMedium("STSBoxCarbonFoam");
+  if (!mSTSBoxCarbonFoam) Fatal("Main", "FairMedium STSBoxCarbonFoam not found");
+  geoBuild->createMedium(mSTSBoxCarbonFoam);
+  TGeoMedium* STSBoxCarbonFoam = gGeoMan->GetMedium("STSBoxCarbonFoam");
+  if (!STSBoxCarbonFoam) Fatal("Main", "Medium STSBoxCarbonFoam not found");
+
+  // ---> STSBoxCarbonFibre
+  FairGeoMedium* mSTSBoxCarbonFibre = geoMedia->getMedium("STSBoxCarbonFibre");
+  if (!mSTSBoxCarbonFibre) Fatal("Main", "FairMedium STSBoxCarbonFibre not found");
+  geoBuild->createMedium(mSTSBoxCarbonFibre);
+  TGeoMedium* STSBoxCarbonFibre = gGeoMan->GetMedium("STSBoxCarbonFibre");
+  if (!STSBoxCarbonFibre) Fatal("Main", "Medium STSBoxCarbonFibre not found");
+
+  // ---> STScable
+  FairGeoMedium* mSTScable = geoMedia->getMedium("STScable");
+  if (!mSTScable) Fatal("Main", "FairMedium STScable not found");
+  geoBuild->createMedium(mSTScable);
+  TGeoMedium* STScable = gGeoMan->GetMedium("STScable");
+  if (!STScable) Fatal("Main", "Medium STScable not found");
+
+  // ---> Aluminium
+  FairGeoMedium* mAluminium = geoMedia->getMedium("aluminium");
+  if (!mAluminium) Fatal("Main", "FairMedium aluminium not found");
+  geoBuild->createMedium(mAluminium);
+  TGeoMedium* aluminium = gGeoMan->GetMedium("aluminium");
+  if (!aluminium) Fatal("Main", "Medium aluminium not found");
+
+  // ---
+  gStsMedium = air;
+  // --------------------------------------------------------------------------
+
+
+  // --------------   Create geometry and top volume  -------------------------
+  gGeoMan = (TGeoManager*) gROOT->FindObject("FAIRGeom");
+  //  gGeoMan->SetName("STSgeom");
+  TGeoVolume* top = new TGeoVolumeAssembly("top");
+  //  TGeoBBox* topbox= new TGeoBBox("", 120., 120., 120.);
+  //  TGeoVolume* top = new TGeoVolume("top", topbox, gGeoMan->GetMedium("air"));
+  gGeoMan->SetTopVolume(top);
+  // --------------------------------------------------------------------------
+
+
+  // --------------   Create media   ------------------------------------------
+  /*
+  cout << endl;
+  cout << "===> Creating media....";
+  cout << CreateMedia();
+  cout << " media created" << endl;
+  TList* media = gGeoMan->GetListOfMedia();
+  for (Int_t iMedium = 0; iMedium < media->GetSize(); iMedium++ ) {
+    cout << "Medium " << iMedium << ": " 
+   << ((TGeoMedium*) media->At(iMedium))->GetName() << endl;
+  }
+  gStsMedium = gGeoMan->GetMedium("air");
+  if ( ! gStsMedium ) Fatal("Main", "medium sts_air not found");
+  */
+  // --------------------------------------------------------------------------
+
+
+  // ---------------   Create sensors   ---------------------------------------
+  cout << endl << endl;
+  cout << "===> Creating sensors...." << endl << endl;
+  infoFile << endl << "Sensors: " << endl;
+  Int_t nSensors = CreateSensors();
+  for (Int_t iSensor = 1; iSensor <= nSensors; iSensor++) {
+    TString name       = Form("Sensor%02d", iSensor);
+    TGeoVolume* sensor = gGeoMan->GetVolume(name);
+
+    // add color to sensors
+    if (iSensor == 1) sensor->SetLineColor(kRed);
+    if (iSensor == 2) sensor->SetLineColor(kGreen);
+    if (iSensor == 3) sensor->SetLineColor(kBlue);
+    if (iSensor == 4) sensor->SetLineColor(kAzure);
+    if (iSensor == 5) sensor->SetLineColor(kYellow);
+    if (iSensor == 6) sensor->SetLineColor(kYellow);
+    if (iSensor == 7) sensor->SetLineColor(kYellow);
+
+    CheckVolume(sensor);
+    CheckVolume(sensor, infoFile);
+  }
+  // --------------------------------------------------------------------------
+
+
+  // ----------------   Create sectors   --------------------------------------
+  cout << endl << endl;
+  cout << "===> Creating sectors...." << endl;
+  // infoFile << endl << "Sectors: " << endl;
+  Int_t nSectors = CreateSectors();
+  for (Int_t iSector = 1; iSector <= nSectors; iSector++) {
+    // cout << endl;
+    TString name       = Form("Sector%02d", iSector);
+    TGeoVolume* sector = gGeoMan->GetVolume(name);
+    CheckVolume(sector);
+    // CheckVolume(sector, infoFile);
+  }
+  // --------------------------------------------------------------------------
+
+
+  // ----------------   Create ladders   --------------------------------------
+  cout << endl << endl;
+  cout << "===> Creating ladders...." << endl;
+  infoFile << endl << "Ladders:" << endl;
+  Int_t nLadders = CreateLadders();
+  for (Int_t iLadder = 1; iLadder <= nLadders; iLadder++) {
+    cout << endl;
+    TString name       = Form("LadderType%02d", iLadder);
+    TGeoVolume* ladder = gGeoMan->GetVolume(name);
+    CheckVolume(ladder);
+    CheckVolume(ladder, infoFile, kFALSE);
+    // CheckVolume(ladder->GetNode(0)->GetVolume(), infoFile, kFALSE);
+  }
+  // --------------------------------------------------------------------------
+
+
+  // ----------------   Create cones   ----------------------------------------
+  Double_t coneDz            = 1.64;
+  TGeoVolume* coneSmallVolum = ConstructSmallCone(coneDz);
+  if (!coneSmallVolum) Fatal("ConstructSmallCone", "Volume Cone not found");
+  TGeoVolume* coneBigVolum = ConstructBigCone(coneDz);
+  if (!coneBigVolum) Fatal("ConstructBigCone", "Volume Cone not found");
+  // --------------------------------------------------------------------------
+
+
+  // ----------------   Create stations   -------------------------------------
+  cout << endl << endl;
+  cout << "===> Creating stations...." << endl;
+  infoFile << endl << "Stations: " << endl;
+  Int_t angle = 0;
+  nLadders    = 0;
+  Int_t ladderTypes[16];
+  TGeoTranslation* statTrans = NULL;
+
+  //  TGeoVolume *mystation[8];  // stations
+  //  TGeoVolume *myunit[16];  // units
+  TGeoVolume* myunit[32];  // units
+
+  //  Int_t statPos[8]  = { 30, 40, 50, 60, 70, 80, 90, 100 };  // z positions of stations
+  //  Int_t statPos[16]  = { 28, 32, 38, 42, 48, 52, 58, 62,
+  //                         68, 72, 78, 82, 88, 92, 98,102 };  // z positions of units
+  Int_t statPos[16]   = {30, 30, 40, 40, 50, 50, 60, 60, 70, 70, 80, 80, 90, 90, 100, 100};  // z positions of units
+  Int_t statPos18[18] = {30,
+                         30,  // expanded for placement of Unit00
+                         30, 30, 40, 40, 50, 50, 60, 60, 70, 70, 80, 80, 90, 90, 100, 100};  // z positions of units
+
+  ////Double_t rHole[8] = { 2.0, 2.0, 2.0, 2.9 , 3.7 , 3.7 , 4.2 , 4.2 };  // size of cutouts in stations
+  //  Double_t rHole[8] = { 2.0, 2.0, 2.0, 2.43, 3.04, 3.35, 3.96, 4.2 };  // size of cutouts in stations, derived from gapXYZ[x][1]/2
+
+  Int_t cone_size[8] = {0, 0, 0, 1, 1, 1, 1, 1};  // size of cones: 0 = small, 1 = large
+
+  Double_t cone_offset[2] = {0.305, 0.285};
+
+  //  Int_t allLadderTypes[8][16]=
+  //  { {  -1,  -1,  -1,  -1,  10, 109,   9, 101,   1, 109,   9, 110,  -1,  -1,  -1,  -1 },    // station 1
+  //    {  -1,  -1, 111,  10, 110,   9, 109,   2, 102,   9, 109,  10, 110,  11,  -1,  -1 },    // station 2
+  //    {  -1,  -1,  14, 113,  12, 112,  12, 103,   3, 112,  12, 112,  13, 114,  -1,  -1 },    // station 3
+  //    {  -1,  15, 114,  13, 112,  12, 112,   4, 104,  12, 112,  12, 113,  14, 115,  -1 },    // station 4
+  //    {  -1, 119,  18, 117,  17, 116,  16, 105,   5, 116,  16, 117,  17, 118,  19,  -1 },    // station 5
+  //    {  -1,  19, 118,  17, 117,  16, 116,   6, 106,  16, 116,  17, 117,  18, 119,  -1 },    // station 6
+  //    {  21, 119,  18, 120,  20, 120,  20, 107,   7, 120,  20, 120,  20, 118,  19, 121 },    // station 7
+  //    { 119,  17, 123,  22, 122,  22, 122,   8, 108,  22, 122,  22, 122,  23, 117,  19 } };  // station 8
+
+
+  Int_t allUnitTypes[16][16] = {
+    {-1, -1, -1, -1, 10, 0, 9, 0, 1, 0, 9, 0, -1, -1, -1, -1},          // unit00D Station01 00
+    {-1, -1, -1, -1, 0, 109, 0, 101, 0, 109, 0, 110, -1, -1, -1, -1},   // unit01U Station01 01
+    {-1, -1, 0, 10, 0, 9, 0, 2, 0, 9, 0, 10, 0, 11, -1, -1},            // unit01D Station02 02
+    {-1, -1, 111, 0, 110, 0, 109, 0, 102, 0, 109, 0, 110, 0, -1, -1},   // unit02U Station02 03
+    {-1, -1, 14, 0, 12, 0, 12, 0, 3, 0, 12, 0, 13, 0, -1, -1},          // unit02D Station03 04
+    {-1, -1, 0, 113, 0, 112, 0, 103, 0, 112, 0, 112, 0, 114, -1, -1},   // unit03U Station03 05
+    {-1, 15, 0, 13, 0, 12, 0, 4, 0, 12, 0, 12, 0, 14, 0, -1},           // unit03D Station04 06
+    {-1, 0, 114, 0, 112, 0, 112, 0, 104, 0, 112, 0, 113, 0, 115, -1},   // unit04U Station04 07
+    {-1, 0, 18, 0, 17, 0, 16, 0, 5, 0, 16, 0, 17, 0, 19, -1},           // unit04D Station05 08
+    {-1, 119, 0, 117, 0, 116, 0, 105, 0, 116, 0, 117, 0, 118, 0, -1},   // unit05U Station05 09
+    {-1, 19, 0, 17, 0, 16, 0, 6, 0, 16, 0, 17, 0, 18, 0, -1},           // unit05D Station06 10
+    {-1, 0, 118, 0, 117, 0, 116, 0, 106, 0, 116, 0, 117, 0, 119, -1},   // unit06U Station06 11
+    {21, 0, 25, 0, 20, 0, 20, 0, 7, 0, 20, 0, 20, 0, 27, 0},            // unit06D Station07 12
+    {0, 127, 0, 120, 0, 120, 0, 107, 0, 120, 0, 120, 0, 125, 0, 121},   // unit07U Station07 13
+    {0, 24, 0, 22, 0, 22, 0, 8, 0, 22, 0, 22, 0, 23, 0, 26},            // unit07D Station08 14
+    {126, 0, 123, 0, 122, 0, 122, 0, 108, 0, 122, 0, 122, 0, 124, 0}};  // unit08U Station08 15
+
+
+  //  unitTypes[0]  = {   0,   0,   0,   0,  10,   0,   9,   0,   1,   0,   9,   0,   0,   0,   0,   0 };  // unit 0D
+  //  unitTypes[1]  = {   0,   0,   0,   0,   0, 109,   0, 101,   0, 109,   0, 110,   0,   0,   0,   0 };  // unit 1U
+  //  unitTypes[2]  = {   0,   0,   0,  10,   0,   9,   0,   2,   0,   9,   0,  10,   0,  11,   0,   0 };  // unit 1D
+  //  unitTypes[3]  = {   0,   0, 111,   0, 110,   0, 109,   0, 102,   0, 109,   0, 110,   0,   0,   0 };  // unit 2U
+  //  unitTypes[4]  = {   0,   0,  14,   0,  12,   0,  12,   0,   3,   0,  12,   0,  13,   0,   0,   0 };  // unit 2D
+  //  unitTypes[5]  = {   0,   0,   0, 113,   0, 112,   0, 103,   0, 112,   0, 112,   0, 114,   0,   0 };  // unit 3U
+  //  unitTypes[6]  = {   0,  15,   0,  13,   0,  12,   0,   4,   0,  12,   0,  12,   0,  14,   0,   0 };  // unit 3D
+  //  unitTypes[7]  = {   0,   0, 114,   0, 112,   0, 112,   0, 104,   0, 112,   0, 113,   0, 115,   0 };  // unit 4U
+  //  unitTypes[8]  = {   0,   0,  18,   0,  17,   0,  16,   0,   5,   0,  16,   0,  17,   0,  19,   0 };  // unit 4D
+  //  unitTypes[9]  = {   0, 119,   0, 117,   0, 116,   0, 105,   0, 116,   0, 117,   0, 118,   0,   0 };  // unit 5U
+  //  unitTypes[10] = {   0,  19,   0,  17,   0,  16,   0,   6,   0,  16,   0,  17,   0,  18,   0,   0 };  // unit 5D
+  //  unitTypes[11] = {   0,   0, 118,   0, 117,   0, 116,   0, 106,   0, 116,   0, 117,   0, 119,   0 };  // unit 6U
+  //  unitTypes[12] = {  21,   0,  18,   0,  20,   0,  20,   0,   7,   0,  20,   0,  20,   0,  19,   0 };  // unit 6D
+  //  unitTypes[13] = {   0, 119,   0, 120,   0, 120,   0, 107,   0, 120,   0, 120,   0, 118,   0, 121 };  // unit 7U
+  //  unitTypes[14] = {   0,  17,   0,  22,   0,  22,   0,   8,   0,  22,   0,  22,   0,  23,   0,  19 };  // unit 7D
+  //  unitTypes[15] = { 119,   0, 123,   0, 122,   0, 122,   0, 108,   0, 122,   0, 122,   0, 117,   0 };  // unit 8U
+
+
+  //  // generate unit
+  //  for (Int_t iUnit = 0; iUnit < 16; iUnit++)
+  //    for (Int_t iLadder = 0; iLadder < 16; iLadder++)
+  //    {
+  //      allUnitTypes[iUnit][iLadder] = 0;
+  //      if ((iUnit % 2 == 0) && (allLadderTypes[iUnit/2][iLadder] <  100))  // if carbon structure is oriented upstream
+  //        allUnitTypes[iUnit][iLadder] = allLadderTypes[iUnit/2][iLadder];
+  //      if ((iUnit % 2 == 1) && (allLadderTypes[iUnit/2][iLadder] >= 100))  // if carbon structure is oriented downstream
+  //        allUnitTypes[iUnit][iLadder] = allLadderTypes[iUnit/2][iLadder];
+  //    }
+
+
+  // dump unit
+  for (Int_t iUnit = 0; iUnit < 16; iUnit++) {
+    cout << "DE unitTypes[" << iUnit << "] = { ";
+    for (Int_t iLadder = 0; iLadder < 16; iLadder++) {
+      cout << allUnitTypes[iUnit][iLadder];
+      if (iLadder < 15) cout << ", ";
+      else
+        cout << " };";
+    }
+    cout << endl;
+  }
+
+
+  // --- Units 01 - 16
+  for (Int_t iUnit = 0; iUnit < 16; iUnit++) {
+    cout << endl;
+
+    nLadders = 0;
+    for (Int_t iLadder = 0; iLadder < 16; iLadder++)
+      if (allUnitTypes[iUnit][iLadder] >= 0) {
+        ladderTypes[nLadders] = allUnitTypes[iUnit][iLadder];
+        cout << "DE ladderTypes[" << nLadders << "] = " << allUnitTypes[iUnit][iLadder] << ";" << endl;
+        nLadders++;
+      }
+    //    myunit[iUnit] = ConstructUnit(iUnit, nLadders, ladderTypes);
+    //    myunit[iUnit] = ConstructUnit(iUnit*2+0, nLadders, ladderTypes);
+    //    myunit[iUnit*2+0] = ConstructUnit(0, iUnit*2+0, nLadders, ladderTypes);
+    //    myunit[iUnit*2+1] = ConstructUnit(1, iUnit*2+1, nLadders, ladderTypes);
+    myunit[iUnit * 2 + 0] = ConstructUnit(0, iUnit * 2 + 0, nLadders, ladderTypes, iUnit / 2 + 1);
+    myunit[iUnit * 2 + 1] = ConstructUnit(1, iUnit * 2 + 1, nLadders, ladderTypes, iUnit / 2 + 1);
+
+    //    if (gkConstructCones) {
+    //      if (iUnit%2 == 0)
+    //        angle =  90;
+    //      else
+    //        angle = -90;
+    //
+    //      // upstream
+    //      TGeoRotation* coneRot11 = new TGeoRotation;
+    //      coneRot11->RotateZ(angle);
+    //      coneRot11->RotateY(180);
+    //      TGeoCombiTrans* conePosRot11 = new TGeoCombiTrans(name+"conePosRot2", 0., 0., -coneDz-cone_offset[cone_size[iUnit]]-gkLadderGapZ/2., coneRot11);
+    //      if (cone_size[iUnit] == 0)
+    //        myunit[iUnit]->AddNode(coneSmallVolum, 1, conePosRot11);
+    //      else
+    //        myunit[iUnit]->AddNode(coneBigVolum, 1, conePosRot11);
+    //
+    //      // downstream
+    //      TGeoRotation* coneRot12 = new TGeoRotation;
+    //      coneRot12->RotateZ(angle);
+    //      TGeoCombiTrans* conePosRot12 = new TGeoCombiTrans(name+"conePosRot1", 0., 0.,  coneDz+cone_offset[cone_size[iUnit]]+gkLadderGapZ/2., coneRot12);
+    //      if (cone_size[iUnit] == 0)
+    //        myunit[iUnit]->AddNode(coneSmallVolum, 2, conePosRot12);
+    //      else
+    //        myunit[iUnit]->AddNode(coneBigVolum, 2, conePosRot12);
+    //
+    //      myunit[iUnit]->GetShape()->ComputeBBox();
+    //    }
+
+    //    CheckVolume(myunit[iUnit]);
+    //    CheckVolume(myunit[iUnit], infoFile);
+    if ((iUnit % 2 == 0) || (iUnit == 15)) {
+      CheckVolume(myunit[iUnit * 2 + 0]);
+      CheckVolume(myunit[iUnit * 2 + 0], infoFile);
+      CheckVolume(myunit[iUnit * 2 + 1]);
+      CheckVolume(myunit[iUnit * 2 + 1], infoFile);
+    }
+    infoFile << "Position z = " << statPos[iUnit] << endl;
+  }
+  // --------------------------------------------------------------------------
+
+
+  // ---------------   Create STS volume   ------------------------------------
+  cout << endl << endl;
+  cout << "===> Creating STS...." << endl;
+
+  //  // --- Determine size of STS box
+  //  Double_t stsX = 0.;
+  //  Double_t stsY = 0.;
+  //  Double_t stsZ = 0.;
+  //  Double_t stsBorder = 2*5.;  // 5 cm space for carbon ladders on each side
+  //  for (Int_t iStation = 1; iStation<=8; iStation++) {
+  //    TString statName = Form("Station%02d", iStation);
+  //    TGeoVolume* station = gGeoMan->GetVolume(statName);
+  //    TGeoBBox* shape = (TGeoBBox*) station->GetShape();
+  //    stsX = TMath::Max(stsX, 2.* shape->GetDX() );
+  //    stsY = TMath::Max(stsY, 2.* shape->GetDY() );
+  //    cout << "Station " << iStation << ":  Y " << stsY << endl;
+  //  }
+  //  // --- Some border around the stations
+  //  stsX += stsBorder;
+  //  stsY += stsBorder;
+  //  stsZ = ( statPos[7] - statPos[0] ) + stsBorder;
+  //
+  //  // --- Create box  around the stations
+  //  new TGeoBBox("stsBox", stsX/2., stsY/2., stsZ/2.);
+  //  cout << "size of STS box: x " <<  stsX << " - y " << stsY << " - z " << stsZ << endl;
+  //
+  //  // --- Create cone hosting the beam pipe
+  //  // --- One straight section with constant radius followed by a cone
+  //  Double_t z1 = statPos[0] - 0.5 * stsBorder;  // start of STS box
+  //  Double_t z2 = gkPipeZ2;
+  //  Double_t z3 = statPos[7] + 0.5 * stsBorder;  // end of STS box
+  //  Double_t r1 = BeamPipeRadius(z1);
+  //  Double_t r2 = BeamPipeRadius(z2);
+  //  Double_t r3 = BeamPipeRadius(z3);
+  //  r1 += 0.01;    // safety margin
+  //  r2 += 0.01;    // safety margin
+  //  r3 += 0.01;    // safety margin
+  //
+  //  cout << endl;
+  //  cout << z1 << "  " << r1 << endl;
+  //  cout << z2 << "  " << r2 << endl;
+  //  cout << z3 << "  " << r3 << endl;
+  //
+  //  cout << endl;
+  //  cout << "station1 :  " << BeamPipeRadius(statPos[0]) << endl;
+  //  cout << "station2 :  " << BeamPipeRadius(statPos[1]) << endl;
+  //  cout << "station3 :  " << BeamPipeRadius(statPos[2]) << endl;
+  //  cout << "station4 :  " << BeamPipeRadius(statPos[3]) << endl;
+  //  cout << "station5 :  " << BeamPipeRadius(statPos[4]) << endl;
+  //  cout << "station6 :  " << BeamPipeRadius(statPos[5]) << endl;
+  //  cout << "station7 :  " << BeamPipeRadius(statPos[6]) << endl;
+  //  cout << "station8 :  " << BeamPipeRadius(statPos[7]) << endl;
+  //
+  //  //  TGeoPcon* cutout = new TGeoPcon("stsCone", 0., 360., 3); // 2.*TMath::Pi(), 3);
+  //  //  cutout->DefineSection(0, z1, 0., r1);
+  //  //  cutout->DefineSection(1, z2, 0., r2);
+  //  //  cutout->DefineSection(2, z3, 0., r3);
+  //  new TGeoTrd2("stsCone1", r1, r2, r1, r2, (z2-z1)/2.+.1);  // add .1 in z length for a clean cutout
+  //  TGeoTranslation *trans1 = new TGeoTranslation("trans1", 0., 0., -(z3-z1)/2.+(z2-z1)/2.);
+  //  trans1->RegisterYourself();
+  //  new TGeoTrd2("stsCone2", r2, r3, r2, r3, (z3-z2)/2.+.1);  // add .1 in z length for a clean cutout
+  //  TGeoTranslation *trans2 = new TGeoTranslation("trans2", 0., 0., +(z3-z1)/2.-(z3-z2)/2.);
+  //  trans2->RegisterYourself();
+  //
+  ////DE   Double_t z1 = statPos[0] - 0.5 * stsBorder;  // start of STS box
+  ////DE   Double_t z2 = statPos[7] + 0.5 * stsBorder;  // end of STS box
+  ////DE   Double_t slope = (gkPipeR2 - gkPipeR1) / (gkPipeZ2 - gkPipeZ1);
+  ////DE   Double_t r1 = gkPipeR1 + slope * (z1 - gkPipeZ1); // at start of STS
+  ////DE   Double_t r2 = gkPipeR1 + slope * (z2 - gkPipeZ1); // at end of STS
+  ////DE   r1 += 0.1;    // safety margin
+  ////DE   r2 += 0.1;    // safety margin
+  ////DE   //  new TGeoCone("stsCone", stsZ/2., 0., r1, 0., r2);
+  ////DE   new TGeoTrd2("stsCone", r1, r2, r1, r2, stsZ/2.);
+
+
+  // // Create holding/cooling plates
+  // static std::vector< std::vector<Double_t> > plateSizes = {
+  //   { 177.5/2., 100.0/2., 1.5/2. },
+  //   { 177.5/2., 100.0/2., 1.5/2. },
+  //   { 177.5/2., 100.0/2., 1.5/2. },
+  //   { 177.5/2., 111.5/2., 1.5/2. },
+  //   { 177.5/2., 111.5/2., 1.5/2. },
+  //   { 177.5/2., 111.5/2., 1.5/2. },
+  //   { 177.5/2., 130.0/2., 1.5/2. },
+  //   { 177.5/2., 130.0/2., 1.5/2. },
+  //   { 177.5/2., 130.0/2., 1.5/2. },
+  // };
+
+  // // 8-vertex cut-outs { minWidth, maxWidth, minHeight, maxHeight }
+  // static std::vector< std::vector<Double_t> > plateCutOuts = {
+  //   { 78.3, 97.5, 20.0, 50.0 },
+  //   { 78.3, 97.5, 20.0, 50.0 },
+  //   { 78.3, 97.5, 17.6, 47.6 },
+  //   { 85.5,105.5, 37.0, 67.0 },
+  //   { 85.5,105.5, 37.0, 67.0 },
+  //   { 85.5,105.5, 49.0, 79.0 },
+  //   { 85.5,115.5, 51.5, 82.8 },
+  //   { 85.5,115.5, 59.0, 91.4 },
+  //   { 85.5,115.5, 68.0, 99.0 },
+  // };
+
+  // for (Int_t iPlate = 0; iPlate < 9; iPlate++) {
+  //   Int_t iUnit = iPlate * 2;
+  //   TGeoBBox* outerPlate = new TGeoBBox(Form("outerPlate%02d",iPlate),
+  //       plateSizes[iPlate][0], plateSizes[iPlate][1], plateSizes[iPlate][2]);
+
+  //   TGeoBBox* unitShapeR = (TGeoBBox*) gGeoManager->GetVolume(unitName18[iUnit+0])->GetShape();
+  //   TGeoBBox* unitShapeL = (TGeoBBox*) gGeoManager->GetVolume(unitName18[iUnit+1])->GetShape();
+
+  //   Double_t maxDx = (unitShapeR->GetDX() + unitShapeL->GetDX()) / 2.;
+  //   Double_t maxDy = TMath::Max(unitShapeR->GetDY(), unitShapeL->GetDY());
+  //   cout << maxDy << endl;
+
+  //   Double_t* cutOutX = new Double_t[8];
+  //   Double_t* cutOutY = new Double_t[8];
+
+  //   cutOutX[0] = -1/2. * plateCutOuts[iPlate][0];  cutOutY[0] =  1/2. * plateCutOuts[iPlate][3];
+  //   cutOutX[1] =  1/2. * plateCutOuts[iPlate][0];  cutOutY[1] =  1/2. * plateCutOuts[iPlate][3];
+  //   cutOutX[2] =  1/2. * plateCutOuts[iPlate][1];  cutOutY[2] =  1/2. * plateCutOuts[iPlate][2];
+  //   cutOutX[3] =  1/2. * plateCutOuts[iPlate][1];  cutOutY[3] = -1/2. * plateCutOuts[iPlate][2];
+  //   cutOutX[4] =  1/2. * plateCutOuts[iPlate][0];  cutOutY[4] = -1/2. * plateCutOuts[iPlate][3];
+  //   cutOutX[5] = -1/2. * plateCutOuts[iPlate][0];  cutOutY[5] = -1/2. * plateCutOuts[iPlate][3];
+  //   cutOutX[6] = -1/2. * plateCutOuts[iPlate][1];  cutOutY[6] = -1/2. * plateCutOuts[iPlate][2];
+  //   cutOutX[7] = -1/2. * plateCutOuts[iPlate][1];  cutOutY[7] =  1/2. * plateCutOuts[iPlate][2];
+
+  //   TGeoXtru* cutOutShape = new TGeoXtru(2);
+  //   cutOutShape->SetName(Form("innerPlate%02d", iPlate));
+  //   cutOutShape->DefinePolygon(8, cutOutX, cutOutY);
+  //   cutOutShape->DefineSection(0, -1*plateSizes[iPlate][2]-1e-7);
+  //   cutOutShape->DefineSection(1, +1*plateSizes[iPlate][2]+1e-7);
+
+  //   TGeoShape* plateShape = new TGeoCompositeShape(Form("PlateShape%02d",iPlate), Form("outerPlate%02d-innerPlate%02d",iPlate,iPlate));
+  //   TGeoVolume* plate = new TGeoVolume(Form("Plate%02d", iPlate), plateShape, gGeoManager->GetMedium("aluminium"));
+  //   plate->SetLineColor(kRed);
+  //   plate->SetTransparency(65);
+  //   plate->GetShape()->ComputeBBox();
+  // }
+
+  // --- Create STS volume
+  TString stsName = "sts_";
+  stsName += geoTag;
+
+  //  TGeoShape* stsShape = new TGeoCompositeShape("stsShape",
+  //                                               "stsBox-stsCone1:trans1-stsCone2:trans2");
+  //  TGeoVolume* sts = new TGeoVolume(stsName.Data(), stsShape, gStsMedium);
+
+  Double_t stsBorder = 2 * 5.;
+
+  TGeoVolume* sts = new TGeoVolumeAssembly(stsName.Data());
+
+  // --- Place stations in the STS
+  Double_t stsPosZ = 0.5 * (statPos[15] + statPos[0]);  // todo units: update statPos[7]
+  //  cout << "stsPosZ " << stsPosZ << " " << statPos[15] << " " << statPos[0] << "*****" << endl;
+
+  //  for (Int_t iUnit = 0; iUnit < 16; iUnit++) {
+  for (Int_t iUnit = 0; iUnit < 18; iUnit++) {
+    //  for (Int_t iUnit = 0; iUnit < 32; iUnit++) {
+    TGeoVolume* station = gGeoMan->GetVolume(unitName18[iUnit]);
+    //    Double_t posZ = statPos[iUnit] - stsPosZ;
+    Double_t posZ = statPos18[iUnit] - stsPosZ;
+    //    Double_t posZ = statPos[iUnit/2] - stsPosZ;
+    TGeoTranslation* trans = new TGeoTranslation(0., 0., posZ);
+    sts->AddNode(station, iUnit + 1, trans);
+    sts->GetShape()->ComputeBBox();
+  }
+
+  // --- Import passive elements from GDML file
+  if (gkImportPassive) { ImportPassive(sts, geoTag, infoFile); }
+
+  cout << endl;
+  CheckVolume(sts);
+  // --------------------------------------------------------------------------
+
+
+  // ---------------   Finish   -----------------------------------------------
+  TGeoTranslation* stsTrans = new TGeoTranslation(0., 0., stsPosZ - 40.0);
+  top->AddNode(sts, 1, stsTrans);
+  top->GetShape()->ComputeBBox();
+  cout << endl << endl;
+
+  CheckVolume(top);
+  cout << endl << endl;
+  gGeoMan->CloseGeometry();
+  gGeoMan->CheckOverlaps(0.0001);
+  gGeoMan->PrintOverlaps();
+  gGeoMan->CheckOverlaps(0.0001, "s");
+  gGeoMan->PrintOverlaps();
+  gGeoMan->Test();
+
+  TFile* geoFile = new TFile(geoFileName, "RECREATE");
+  top->Write();
+  //  TGeoTranslation* ststrans = new TGeoTranslation(0., 0., -40.0);
+  //  ststrans->Write("trans");
+  cout << endl;
+  cout << "Geometry " << top->GetName() << " written to " << geoFileName << endl;
+  geoFile->Close();
+
+  TString geoFileName_ = "sts_";
+  geoFileName_         = geoFileName_ + geoTag + "_geo.root";
+
+  geoFile = new TFile(geoFileName_, "RECREATE");
+  gGeoMan->Write();  // use this is you want GeoManager format in the output
+  geoFile->Close();
+
+  TString geoFileName__ = "sts_";
+  geoFileName_          = geoFileName__ + geoTag + "-geo.root";
+  sts->Export(geoFileName_);
+
+  geoFile = new TFile(geoFileName_, "UPDATE");
+  stsTrans->Write();
+  geoFile->Close();
+
+  // gGeoManager->FindVolumeFast("LadderType10_CarbonElement")->Draw("ogl");
+  // top->Draw("ogl");
+  gGeoManager->SetVisLevel(8);
+
+  infoFile.close();
+}
+// ============================================================================
+// ======                   End of main function                          =====
+// ============================================================================
+
+
+// ****************************************************************************
+// *****      Definition of media, sensors, sectors and ladders           *****
+// *****                                                                  *****
+// *****     Decoupled from main function for better readability          *****
+// ****************************************************************************
+
+
+/** ===========================================================================
+ ** Create media
+ **
+ ** Currently created: air, active silicon, passive silion
+ **
+ ** Not used for the time being
+ **/
+Int_t CreateMedia()
+{
+
+  Int_t nMedia     = 0;
+  Double_t density = 0.;
+
+  // --- Material air
+  density             = 1.205e-3;  // [g/cm^3]
+  TGeoMixture* matAir = new TGeoMixture("sts_air", 3, density);
+  matAir->AddElement(14.0067, 7, 0.755);  // Nitrogen
+  matAir->AddElement(15.999, 8, 0.231);   // Oxygen
+  matAir->AddElement(39.948, 18, 0.014);  // Argon
+
+  // --- Material silicon
+  density             = 2.33;  // [g/cm^3]
+  TGeoElement* elSi   = gGeoMan->GetElementTable()->GetElement(14);
+  TGeoMaterial* matSi = new TGeoMaterial("matSi", elSi, density);
+
+
+  // --- Air (passive)
+  TGeoMedium* medAir = new TGeoMedium("air", nMedia++, matAir);
+  medAir->SetParam(0, 0.);     // is passive
+  medAir->SetParam(1, 1.);     // is in magnetic field
+  medAir->SetParam(2, 20.);    // max. field [kG]
+  medAir->SetParam(6, 0.001);  // boundary crossing precision [cm]
+
+
+  // --- Active silicon for sensors
+  TGeoMedium* medSiAct = new TGeoMedium("silicon", nMedia++, matSi);
+  medSiAct->SetParam(0, 1.);     // is active
+  medSiAct->SetParam(1, 1.);     // is in magnetic field
+  medSiAct->SetParam(2, 20.);    // max. field [kG]
+  medSiAct->SetParam(6, 0.001);  // boundary crossing precisison [cm]
+
+  // --- Passive silicon for cables
+  TGeoMedium* medSiPas = new TGeoMedium("carbon", nMedia++, matSi);
+  medSiPas->SetParam(0, 0.);     // is passive
+  medSiPas->SetParam(1, 1.);     // is in magnetic field
+  medSiPas->SetParam(2, 20.);    // max. field [kG]
+  medSiPas->SetParam(6, 0.001);  // boundary crossing precisison [cm]
+
+  return nMedia;
+}
+/** ======================================================================= **/
+
+
+/** ===========================================================================
+ ** Create sensors
+ **
+ ** Sensors are created as volumes with box shape and active silicon as medium.
+ ** Four kinds of sensors: 3.2x2.2, 6.2x2.2, 6.2x4.2, 6.2x6.2
+ **/
+Int_t CreateSensors()
+{
+
+  Int_t nSensors = 0;
+
+  Double_t xSize      = 0.;
+  Double_t ySize      = 0.;
+  Double_t zSize      = gkSensorThickness;
+  TGeoMedium* silicon = gGeoMan->GetMedium("silicon");
+
+
+  // --- Sensor type 01: Small sensor (6.2 cm x 2.2 cm)
+  xSize                    = gkSensorSizeX;
+  ySize                    = 2.2;
+  TGeoBBox* shape_sensor01 = new TGeoBBox("sensor01", xSize / 2., ySize / 2., zSize / 2.);
+  new TGeoVolume("Sensor01", shape_sensor01, silicon);
+  nSensors++;
+
+
+  // --- Sensor type 02: Medium sensor (6.2 cm x 4.2 cm)
+  xSize                    = gkSensorSizeX;
+  ySize                    = 4.2;
+  TGeoBBox* shape_sensor02 = new TGeoBBox("sensor02", xSize / 2., ySize / 2., zSize / 2.);
+  new TGeoVolume("Sensor02", shape_sensor02, silicon);
+  nSensors++;
+
+
+  // ---  Sensor type 03: Big sensor (6.2 cm x 6.2 cm)
+  xSize                    = gkSensorSizeX;
+  ySize                    = 6.2;
+  TGeoBBox* shape_sensor03 = new TGeoBBox("sensor03", xSize / 2., ySize / 2., zSize / 2.);
+  new TGeoVolume("Sensor03", shape_sensor03, silicon);
+  nSensors++;
+
+
+  // ---  Sensor type 04: Big sensor (6.2 cm x 12.4 cm)
+  xSize                    = gkSensorSizeX;
+  ySize                    = 12.4;
+  TGeoBBox* shape_sensor04 = new TGeoBBox("sensor04", xSize / 2., ySize / 2., zSize / 2.);
+  new TGeoVolume("Sensor04", shape_sensor04, silicon);
+  nSensors++;
+
+
+  // below are extra small sensors, those are not available in the CAD model
+
+  // --- Sensor Type 05: Half small sensor (4 cm x 2.5 cm)
+  xSize                    = 4.0;
+  ySize                    = 2.5;
+  TGeoBBox* shape_sensor05 = new TGeoBBox("sensor05", xSize / 2., ySize / 2., zSize / 2.);
+  new TGeoVolume("Sensor05", shape_sensor05, silicon);
+  nSensors++;
+
+
+  // ---  Sensor type 06: Additional "in hole" sensor (3.1 cm x 4.2 cm)
+  xSize                    = 3.1;
+  ySize                    = 4.2;
+  TGeoBBox* shape_sensor06 = new TGeoBBox("sensor06", xSize / 2., ySize / 2., zSize / 2.);
+  new TGeoVolume("Sensor06", shape_sensor06, silicon);
+  nSensors++;
+
+
+  // ---  Sensor type 07: Mini Medium sensor (1.5 cm x 4.2 cm)
+  xSize                    = 1.5;
+  ySize                    = 4.2;
+  TGeoBBox* shape_sensor07 = new TGeoBBox("sensor07", xSize / 2., ySize / 2., zSize / 2.);
+  new TGeoVolume("Sensor07", shape_sensor07, silicon);
+  nSensors++;
+
+
+  return nSensors;
+}
+/** ======================================================================= **/
+
+
+/** ===========================================================================
+ ** Create sectors
+ **
+ ** A sector is either a single sensor or several chained sensors.
+ ** It is implemented as TGeoVolumeAssembly.
+ ** Currently available:
+ ** - single sensors of type 1 - 4
+ ** - two chained sensors of type 4
+ ** - three chained sensors of type 4
+ **/
+Int_t CreateSectors()
+{
+
+  Int_t nSectors = 0;
+
+  TGeoVolume* sensor01 = gGeoMan->GetVolume("Sensor01");
+  TGeoVolume* sensor02 = gGeoMan->GetVolume("Sensor02");
+  TGeoVolume* sensor03 = gGeoMan->GetVolume("Sensor03");
+  TGeoVolume* sensor04 = gGeoMan->GetVolume("Sensor04");
+  TGeoVolume* sensor05 = gGeoMan->GetVolume("Sensor05");
+  TGeoVolume* sensor06 = gGeoMan->GetVolume("Sensor06");
+  TGeoVolume* sensor07 = gGeoMan->GetVolume("Sensor07");
+  //  TGeoBBox*   box4     = (TGeoBBox*) sensor04->GetShape();
+
+  // --- Sector type 1: single sensor of type 1
+  TGeoVolumeAssembly* sector01 = new TGeoVolumeAssembly("Sector01");
+  sector01->AddNode(sensor01, 1);
+  sector01->GetShape()->ComputeBBox();
+  nSectors++;
+
+  // --- Sector type 2: single sensor of type 2
+  TGeoVolumeAssembly* sector02 = new TGeoVolumeAssembly("Sector02");
+  sector02->AddNode(sensor02, 1);
+  sector02->GetShape()->ComputeBBox();
+  nSectors++;
+
+  // --- Sector type 3: single sensor of type 3
+  TGeoVolumeAssembly* sector03 = new TGeoVolumeAssembly("Sector03");
+  sector03->AddNode(sensor03, 1);
+  sector03->GetShape()->ComputeBBox();
+  nSectors++;
+
+  // --- Sector type 4: single sensor of type 4
+  TGeoVolumeAssembly* sector04 = new TGeoVolumeAssembly("Sector04");
+  sector04->AddNode(sensor04, 1);
+  sector04->GetShape()->ComputeBBox();
+  nSectors++;
+
+  // --- Sector type 5: single sensor of type 5
+  TGeoVolumeAssembly* sector05 = new TGeoVolumeAssembly("Sector05");
+  sector05->AddNode(sensor05, 1);
+  sector05->GetShape()->ComputeBBox();
+  nSectors++;
+
+  // --- Sector type 6: single sensor of type 6
+  TGeoVolumeAssembly* sector06 = new TGeoVolumeAssembly("Sector06");
+  sector06->AddNode(sensor06, 1);
+  sector06->GetShape()->ComputeBBox();
+  nSectors++;
+
+  // --- Sector type 7: single sensor of type 7
+  TGeoVolumeAssembly* sector07 = new TGeoVolumeAssembly("Sector07");
+  sector07->AddNode(sensor07, 1);
+  sector07->GetShape()->ComputeBBox();
+  nSectors++;
+
+  //  // --- Sector type 5: two sensors of type 4
+  //  TGeoVolumeAssembly* sector05 = new TGeoVolumeAssembly("Sector05");
+  //  Double_t shift5 = 0.5 * gkChainGapY + box4->GetDY();
+  //  TGeoTranslation* transD5 =
+  //    new TGeoTranslation("td", 0., -1. * shift5, 0.);
+  //  TGeoTranslation* transU5 =
+  //    new TGeoTranslation("tu", 0., shift5, 0.);
+  //  sector05->AddNode(sensor04, 1, transD5);
+  //  sector05->AddNode(sensor04, 2, transU5);
+  //  sector05->GetShape()->ComputeBBox();
+  //  nSectors++;
+
+  return nSectors;
+}
+/** ======================================================================= **/
+
+
+/** ===========================================================================
+ ** Create ladders
+ **
+ ** Ladders are the building blocks of the stations. They contain 
+ ** several modules placed one after the other along the z axis
+ ** such that the sectors are arranged vertically (with overlap).
+ ** 
+ ** A ladder is constructed out of two half ladders, the second of which
+ ** is rotated in the x-y plane by 180 degrees and displaced
+ ** in z direction.
+ **/
+Int_t CreateLadders()
+{
+
+  Int_t nLadders = 0;
+
+  // --- Some variables
+  Int_t nSectors = 0;
+  Int_t sectorTypes[10];
+  TGeoBBox* shape = NULL;
+  TString s0name;
+  TString hlname;
+  char align;
+  TGeoVolume* s0vol       = NULL;
+  TGeoVolume* halfLadderU = NULL;
+  TGeoVolume* halfLadderD = NULL;
+
+  // --- Ladders 01-23
+  Int_t allSectorTypes[27][6] = {
+    {1, 2, 3, 3, 0, -1},  // ladder 01 - 5 - last column defines alignment of small sensors
+    {1, 2, 3, 3, 0, 0},   // ladder 02 - 5 - last column defines alignment of small sensors
+    {2, 2, 3, 4, 0, -1},  // ladder 03 - 6 - last column defines alignment of small sensors
+    {2, 2, 3, 4, 0, 0},   // ladder 04 - 6 - last column defines alignment of small sensors
+    {2, 3, 4, 4, 0, -1},  // ladder 05 - 7 - last column defines alignment of small sensors
+    {2, 3, 4, 4, 0, 0},   // ladder 06 - 7 - last column defines alignment of small sensors
+    {2, 2, 3, 4, 4, 0},   // ladder 07 - last column defines alignment of small sensors
+    {3, 4, 4, 4, 0, 0},   // ladder 08 - last column defines alignment of small sensors
+    {1, 1, 2, 3, 3, 0},   // ladder 09 - last column defines alignment of small sensors
+    {1, 1, 2, 2, 3, 0},   // ladder 10 - last column defines alignment of small sensors
+    {2, 2, 0, 0, 0, 0},   // ladder 11 - last column defines alignment of small sensors
+    {2, 2, 2, 3, 4, 0},   // ladder 12 - last column defines alignment of small sensors
+    {2, 2, 3, 4, 0, 0},   // ladder 13 - last column defines alignment of small sensors
+    {2, 3, 4, 0, 0, 0},   // ladder 14 - last column defines alignment of small sensors
+    {3, 3, 0, 0, 0, 0},   // ladder 15 - last column defines alignment of small sensors
+    {2, 2, 3, 4, 4, 0},   // ladder 16 - last column defines alignment of small sensors
+    {2, 3, 4, 4, 0, 0},   // ladder 17 - last column defines alignment of small sensors
+    {3, 4, 4, 0, 0, 0},   // ladder 18 - last column defines alignment of small sensors
+    {4, 4, 0, 0, 0, 0},   // ladder 19 - last column defines alignment of small sensors
+    {1, 2, 4, 4, 4, 0},   // ladder 20 - last column defines alignment of small sensors
+    {4, 0, 0, 0, 0, 0},   // ladder 21 - last column defines alignment of small sensors
+    {2, 3, 4, 4, 4, 0},   // ladder 22 - last column defines alignment of small sensors
+    {2, 3, 3, 4, 4, 0},   // ladder 23 - last column defines alignment of small sensors
+
+    {2, 3, 4, 4, 0, 0},  // ladder 24 - copy of 17 with different total length
+    {3, 4, 4, 0, 0, 0},  // ladder 25 - copy of 18 with different total length
+    {4, 4, 0, 0, 0, 0},  // ladder 26 - copy of 19 with different total length
+    {4, 4, 0, 0, 0, 0},  // ladder 27 - copy of 19 with different total length
+  };
+
+  //  Issue #405
+  //  Counting from the most upstream ladder, the gaps between sensors are as follows:
+  //    01 (most upstream): 41.3mm
+  //    02: 41.3mm
+  //    03: 42.0mm
+  //    04: 48.6mm
+  //    05: 60.8mm
+  //    06: 67.0mm
+  //    07: 79.2mm
+  //    08 (most downstream): 88.0mm
+
+  Double_t gapXYZ[27][3] = {
+    {0., 4.13, 0.},               // ladder 01
+    {0., 4.13, 0.},               // ladder 02
+    {0., 4.20, 0.},               // ladder 03
+    {0., 4.86, 0.},               // ladder 04
+    {0., 6.08, 0.},               // ladder 05
+    {0., 6.70, 0.},               // ladder 06
+    {0., 7.92, 0.},               // ladder 07
+    {0., 8.80, 0.},               // ladder 08
+    {0., -gkSectorOverlapY, 0.},  // ladder 09
+    {0., -gkSectorOverlapY, 0.},  // ladder 10
+    {0., -gkSectorOverlapY, 0.},  // ladder 11
+    {0., -gkSectorOverlapY, 0.},  // ladder 12
+    {0., -gkSectorOverlapY, 0.},  // ladder 13
+    {0., -gkSectorOverlapY, 0.},  // ladder 14
+    {0., -gkSectorOverlapY, 0.},  // ladder 15
+    {0., -gkSectorOverlapY, 0.},  // ladder 16
+    {0., -gkSectorOverlapY, 0.},  // ladder 17
+    {0., -gkSectorOverlapY, 0.},  // ladder 18
+    {0., -gkSectorOverlapY, 0.},  // ladder 19
+    {0., -gkSectorOverlapY, 0.},  // ladder 20
+    {0., -gkSectorOverlapY, 0.},  // ladder 21
+    {0., -gkSectorOverlapY, 0.},  // ladder 22
+    {0., -gkSectorOverlapY, 0.},  // ladder 23
+
+    {0., -gkSectorOverlapY, 0.},  // ladder 24 - copy of 17 with different total length
+    {0., -gkSectorOverlapY, 0.},  // ladder 25 - copy of 18 with different total length
+    {0., -gkSectorOverlapY, 0.},  // ladder 26 - copy of 19 with different total length
+    {0., -gkSectorOverlapY, 0.},  // ladder 27 - copy of 19 with different total length
+  };
+
+  Double_t ladderLength[27] = {
+    48.0,  // ladder 01
+    48.0,  // ladder 02
+    64.0,  // ladder 03
+    64.0,  // ladder 04
+    80.0,  // ladder 05
+    80.0,  // ladder 06
+    92.0,  // ladder 07
+    96.0,  // ladder 08
+    48.0,  // ladder 09
+    48.0,  // ladder 10
+    48.0,  // ladder 11
+    64.0,  // ladder 12
+    64.0,  // ladder 13
+    64.0,  // ladder 14
+    64.0,  // ladder 15
+    80.0,  // ladder 16
+    80.0,  // ladder 17
+    80.0,  // ladder 18
+    80.0,  // ladder 19
+    92.0,  // ladder 20
+    92.0,  // ladder 21
+    96.0,  // ladder 22
+    96.0,  // ladder 23
+
+    96.0,  // ladder 24 - copy of 17 with different total length
+    92.0,  // ladder 25 - copy of 18 with different total length
+    96.0,  // ladder 26 - copy of 19 with different total length
+    92.0,  // ladder 27 - copy of 19 with different total length
+  };
+  // ========================================================================
+
+  // calculate Z shift for ladders with and without gaps in the center
+  s0name = Form("Sector%02d", allSectorTypes[0][0]);
+  s0vol  = gGeoMan->GetVolume(s0name);
+  shape  = (TGeoBBox*) s0vol->GetShape();
+
+  for (Int_t iLadder = 0; iLadder < 27; iLadder++) {
+    if (iLadder + 1 <= 8)
+      //    if ((iLadder+1 == 7) || (iLadder+1 == 8))  // not for ladders with gap
+      gapXYZ[iLadder][2] = 0;
+    else
+      gapXYZ[iLadder][2] = 2. * shape->GetDZ() + gkSectorGapZ;  // set displacement in z for overlapping half ladders
+  }
+
+  // ========================================================================
+
+  for (Int_t iLadder = 0; iLadder < 27; iLadder++) {
+    cout << endl;
+    nSectors = 0;
+    for (Int_t i = 0; i < 5; i++)
+      if (allSectorTypes[iLadder][i] != 0) {
+        sectorTypes[nSectors] = allSectorTypes[iLadder][i];
+        cout << "DE sectorTypes[" << nSectors << "] = " << allSectorTypes[iLadder][i] << ";" << endl;
+        nSectors++;
+      }
+
+    if (allSectorTypes[iLadder][5] == 0) align = 'l';
+    else
+      align = 'r';
+    hlname      = Form("HalfLadder%02du", iLadder + 1);
+    halfLadderU = ConstructHalfLadder(hlname, nSectors, sectorTypes, align, ladderLength[iLadder] / 2.,
+                                      gapXYZ[iLadder][1] / 2.);  // mirrored
+
+    if (allSectorTypes[iLadder][5] == 0) align = 'r';
+    else
+      align = 'l';
+    hlname      = Form("HalfLadder%02dd", iLadder + 1);
+    halfLadderD = ConstructHalfLadder(hlname, nSectors, sectorTypes, align, ladderLength[iLadder] / 2.,
+                                      gapXYZ[iLadder][1] / 2.);  // mirrored
+
+    ConstructLadder(iLadder + 1, halfLadderU, halfLadderD, gapXYZ[iLadder][1], gapXYZ[iLadder][2]);
+    nLadders++;
+  }
+
+  return nLadders;
+}
+/** ======================================================================= **/
+
+
+// ****************************************************************************
+// *****                                                                  *****
+// *****    Generic functions  for the construction of STS elements       *****
+// *****                                                                  *****
+// *****  module:     volume (made of a sector and a cable)               *****
+// *****  haf ladder: assembly (made of modules)                          *****
+// *****  ladder:     assembly (made of two half ladders)                 *****
+// *****  station:    volume (made of ladders)                            *****
+// *****                                                                  *****
+// ****************************************************************************
+
+
+/** ===========================================================================
+ ** Construct a module
+ **
+ ** A module is a sector plus the readout cable extending from the
+ ** top of the sector. The cable is made from passive silicon.
+ ** The cable has the same x size as the sector.
+ ** Its thickness is given by the global variable gkCableThickness.
+ ** The cable length is a parameter.
+ ** The sensor(s) of the sector is/are placed directly in the module;
+ ** the sector is just auxiliary for the proper placement.
+ **
+ ** Arguments: 
+ **            name             volume name
+ **            sector           pointer to sector volume
+ **            cableLength      length of cable
+ **/
+TGeoVolume* ConstructModule(const char* name, TGeoVolume* sector, Double_t cableLength)
+{
+
+  // --- Check sector volume
+  if (!sector) Fatal("CreateModule", "Sector volume not found!");
+
+  // --- Get size of sector
+  TGeoBBox* box    = (TGeoBBox*) sector->GetShape();
+  Double_t sectorX = 2. * box->GetDX();
+  Double_t sectorY = 2. * box->GetDY();
+  Double_t sectorZ = 2. * box->GetDZ();
+
+  // --- Get size of cable
+  Double_t cableX = sectorX;
+  Double_t cableY = cableLength;
+  Double_t cableZ = gkCableThickness;
+
+  // --- Create module volume
+  Double_t moduleX = TMath::Max(sectorX, cableX);
+  Double_t moduleY = sectorY + cableLength;
+
+  Double_t moduleZ = TMath::Max(sectorZ, cableZ);
+
+  TGeoVolume* module = gGeoManager->MakeBox(name, gStsMedium, moduleX / 2., moduleY / 2., moduleZ / 2.);
+
+  // --- Position of sector in module
+  // --- Sector is centred in x and z and aligned to the bottom
+  Double_t sectorXpos = 0.;
+  Double_t sectorYpos = 0.5 * (sectorY - moduleY);
+  Double_t sectorZpos = 0.;
+
+
+  // --- Get sensor(s) from sector
+  Int_t nSensors = sector->GetNdaughters();
+  for (Int_t iSensor = 0; iSensor < nSensors; iSensor++) {
+    TGeoNode* sensor = sector->GetNode(iSensor);
+
+    // --- Calculate position of sensor in module
+    const Double_t* xSensTrans = sensor->GetMatrix()->GetTranslation();
+    Double_t sensorXpos        = 0.;
+    Double_t sensorYpos        = sectorYpos + xSensTrans[1];
+    Double_t sensorZpos        = 0.;
+    TGeoTranslation* sensTrans = new TGeoTranslation("sensTrans", sensorXpos, sensorYpos, sensorZpos);
+
+    // --- Add sensor volume to module
+    TGeoVolume* sensVol = sensor->GetVolume();
+    module->AddNode(sensor->GetVolume(), iSensor + 1, sensTrans);
+    module->GetShape()->ComputeBBox();
+  }
+
+
+  // --- Create cable volume, if necessary, and place it in module
+  // --- Cable is centred in x and z and aligned to the top
+  if (gkConstructCables && cableLength > 0.0001) {
+    TString cableName       = TString(name) + "_cable";
+    TGeoMedium* cableMedium = gGeoMan->GetMedium("STScable");
+    if (!cableMedium) Fatal("CreateModule", "Medium STScable not found!");
+    TGeoVolume* cable = gGeoManager->MakeBox(cableName.Data(), cableMedium, cableX / 2., cableY / 2., cableZ / 2.);
+    // add color to cables
+    cable->SetLineColor(kOrange);
+    cable->SetTransparency(60);
+    Double_t cableXpos          = 0.;
+    Double_t cableYpos          = sectorY + 0.5 * cableY - 0.5 * moduleY;
+    Double_t cableZpos          = 0.;
+    TGeoTranslation* cableTrans = new TGeoTranslation("cableTrans", cableXpos, cableYpos, cableZpos);
+    module->AddNode(cable, 1, cableTrans);
+    module->GetShape()->ComputeBBox();
+  }
+
+  return module;
+}
+/** ======================================================================= **/
+
+
+/** ===========================================================================
+ ** Construct a half ladder
+ **
+ ** A half ladder is a virtual volume (TGeoVolumeAssembly) consisting
+ ** of several modules arranged on top of each other. The modules
+ ** have a given overlap in y and a displacement in z to allow for the
+ ** overlap.
+ **
+ ** The typ of sectors / modules to be placed must be specified:
+ **    1 = sensor01
+ **    2 = sensor02
+ **    3 = sensor03
+ **    4 = sensor04
+ **    5 = 2 x sensor04 (chained)
+ **    6 = 3 x sensor04 (chained)
+ ** The cable is added automatically from the top of each sensor to
+ ** the top of the half ladder.
+ ** The alignment can be left (l) or right (r), which matters in the
+ ** case of different x sizes of sensors (e.g. SensorType01).
+ **
+ ** Arguments: 
+ **            name             volume name
+ **            nSectors         number of sectors
+ **            sectorTypes      array with sector types
+ **            align            horizontal alignment of sectors
+ *             ladderLength     full length of the ladder towards FEE
+ *             offsetY          gap in the beam-pipe region
+ **/
+TGeoVolume* ConstructHalfLadder(const TString& name, Int_t nSectors, Int_t* sectorTypes, char align,
+                                Double_t ladderLength, Double_t offsetY)
+{
+
+  // --- Create half ladder volume assembly
+  TGeoVolumeAssembly* halfLadder = new TGeoVolumeAssembly(name);
+
+  // --- Determine size of ladder
+  Double_t ladderX = 0.;
+  Double_t ladderY = 0.;
+  Double_t ladderZ = 0.;
+  for (Int_t iSector = 0; iSector < nSectors; iSector++) {
+    TString sectorName = Form("Sector%02d", sectorTypes[iSector]);
+    TGeoVolume* sector = gGeoMan->GetVolume(sectorName);
+    if (!sector) Fatal("ConstructHalfLadder", Form("Volume %s not found", sectorName.Data()));
+    TGeoBBox* box = (TGeoBBox*) sector->GetShape();
+    // --- Ladder x size equals largest sector x size
+    ladderX = TMath::Max(ladderX, 2. * box->GetDX());
+    // --- Ladder y size is sum of sector ysizes
+    ladderY += 2. * box->GetDY();
+    // --- Ladder z size is sum of sector z sizes
+    ladderZ += 2. * box->GetDZ();
+  }
+  // --- Subtract overlaps in y
+  ladderY -= Double_t(nSectors - 1) * gkSectorOverlapY;
+  // --- Add gaps in z direction
+  ladderZ += Double_t(nSectors - 1) * gkSectorGapZ;
+
+  ladderY = TMath::Max(ladderLength - offsetY, ladderY);
+
+  // --- Create and place modules
+  Double_t yPosSect = -0.5 * ladderY;
+  Double_t zPosMod  = -0.5 * ladderZ;
+  for (Int_t iSector = 0; iSector < nSectors; iSector++) {
+    TString sectorName = Form("Sector%02d", sectorTypes[iSector]);
+    TGeoVolume* sector = gGeoMan->GetVolume(sectorName);
+    TGeoBBox* box      = (TGeoBBox*) sector->GetShape();
+    Double_t sectorX   = 2. * box->GetDX();
+    Double_t sectorY   = 2. * box->GetDY();
+    Double_t sectorZ   = 2. * box->GetDZ();
+    yPosSect += 0.5 * sectorY;  // Position of sector in ladder
+    Double_t cableLength = 0.5 * ladderY - yPosSect - 0.5 * sectorY;
+    TString moduleName   = name + "_" + Form("Module%02d", sectorTypes[iSector]);
+    TGeoVolume* module   = ConstructModule(moduleName.Data(), sector, cableLength);
+
+    TGeoBBox* shapeMod = (TGeoBBox*) module->GetShape();
+    Double_t moduleX   = 2. * shapeMod->GetDX();
+    Double_t moduleY   = 2. * shapeMod->GetDY();
+    Double_t moduleZ   = 2. * shapeMod->GetDZ();
+    Double_t xPosMod   = 0.;
+    if (align == 'l') xPosMod = 0.5 * (moduleX - ladderX);  // left aligned
+    else if (align == 'r')
+      xPosMod = 0.5 * (ladderX - moduleX);  // right aligned
+    else
+      xPosMod = 0.;                                // centred in x
+    Double_t yPosMod = 0.5 * (ladderY - moduleY);  // top aligned
+    zPosMod += 0.5 * moduleZ;
+    TGeoTranslation* trans = new TGeoTranslation("t", xPosMod, yPosMod, zPosMod);
+    halfLadder->AddNode(module, iSector + 1, trans);
+    halfLadder->GetShape()->ComputeBBox();
+    yPosSect += 0.5 * sectorY - gkSectorOverlapY;
+    zPosMod += 0.5 * moduleZ + gkSectorGapZ;
+  }
+
+  CheckVolume(halfLadder);
+  cout << endl;
+
+  return halfLadder;
+}
+/** ======================================================================= **/
+
+
+/** ===========================================================================
+ ** Add a carbon support to a ladder
+ ** 
+ ** Arguments: 
+ **            LadderIndex      ladder number
+ **            ladder           pointer to ladder
+ **            xu               size of halfladder
+ **            ladderY          height of ladder along y
+ **            ladderZ          thickness of ladder along z
+ **/
+void AddCarbonLadder(Int_t LadderIndex, TGeoVolume* ladder, Double_t xu, Double_t ladderY, Double_t ladderZ)
+{
+
+  // Int_t carbon_elem[23]= { 11, 11, 16, 16, 20,
+  //                          20, 22, 24, 11, 11,
+  //                          11, 16, 16, 16, 16,
+  //                          20, 20, 20, 20, 22,
+  //                          22, 24, 24      };  // number of carbon elements in ladder types
+  Int_t carbon_elem[23] = {11, 11, 16, 16, 20, 20, 22, 24, 11, 10, 6, 16,
+                           14, 12, 7,  20, 18, 16, 13, 22, 7,  24, 21};  // number of carbon elements in ladder types
+
+  // --- Some variables
+  TString name = Form("LadderType%02d", LadderIndex);
+  Int_t i;
+  Double_t j;
+
+  // guess  Int_t YnumOfFrameBoxes = (Int_t)(ladderY / gkFrameStep)+1;    // calculate number of elements
+  // guess  if (LadderIndex == 1 || LadderIndex == 2)  // set even number of ladder elements for these ladders in station 1 and 2
+  // guess  YnumOfFrameBoxes--;
+  // guess//  if (LadderIndex == 3 || LadderIndex == 4)  // set even number of ladder elements for these ladders in station 3 and 4
+  // guess//  YnumOfFrameBoxes++;
+  // guess  YnumOfFrameBoxes += YnumOfFrameBoxes % 2;                     // use even number of frame elements for all ladders
+
+  Int_t YnumOfFrameBoxes = round(ladderY / gkFrameStep);  //carbon_elem[LadderIndex-1];
+
+  //      cout << "DE: lad " << LadderIndex << " inum " << YnumOfFrameBoxes << endl;
+
+  // DEDE
+  Double_t ladderDZ      = (xu / 2. + sqrt(2.) * gkFrameThickness / 2.) / 2.;
+  TGeoBBox* fullFrameShp = new TGeoBBox(name + "_CarbonElement_shp", xu / 2., gkFrameStep / 2., ladderDZ);
+  //  TGeoBBox* fullFrameShp = new TGeoBBox (name+"_CarbonElement_shp", xu/2., gkFrameStep/2., (gkSectorGapZFrame+xu/2.+sqrt(2.)*gkFrameThickness/2.)/2.);
+  TGeoVolume* fullFrameBoxVol = new TGeoVolume(name + "_CarbonElement", fullFrameShp, gStsMedium);
+
+  //  cout << "DE: frame Z size " << (xu/2.+sqrt(2.)*gkFrameThickness/2.) << " cm" << endl;
+
+  //  ConstructFrameElement("FrameBox", fullFrameBoxVol, xu/2.);
+  ConstructFrameElement("CarbonElement", fullFrameBoxVol, xu / 2.);
+  TGeoRotation* fullFrameRot = new TGeoRotation;
+  fullFrameRot->RotateY(180);
+
+  Int_t inum = YnumOfFrameBoxes;  // 6; // 9;
+  for (i = 1; i <= inum; i++) {
+    j = -(inum - 1) / 2. + (i - 1);
+    // -(10-1)/2. +0 +10-1 -> -4.5 .. +4.5 -> -0.5, +0.5 (= 2)
+    // -(11-1)/2. +0 +11-1 -> -5.0 .. +5.0 -> -1, 0, 1   (= 3)
+    //        cout << "DE: i " << i << " j " << j << endl;
+
+    if (LadderIndex <= 3)  // central ladders in stations 1 to 3
+    {
+      if ((j >= -1) && (j <= 1))  // keep the inner 2 (even) or 3 (odd) elements free for the cone
+        continue;
+    }
+    else if (LadderIndex <= 8)  // central ladders in stations 4 to 8
+    {
+      if ((j >= -2) && (j <= 2))  // keep the inner 4 elements free for the cone
+        continue;
+    }
+
+    // DEDE
+    ladder->AddNode(
+      fullFrameBoxVol, i,
+      new TGeoCombiTrans(name + "_CarbonElement_posrot", 0., j * gkFrameStep, -ladderZ / 2. - ladderDZ, fullFrameRot));
+    //    ladder->AddNode(fullFrameBoxVol, i, new TGeoCombiTrans(name+"_CarbonElement_posrot", 0., j*gkFrameStep, -ladderZ/2.-(gkSectorGapZFrame+xu/2.+sqrt(2.)*gkFrameThickness/2.)/2., fullFrameRot));
+  }
+  //      cout << endl;
+  ladder->GetShape()->ComputeBBox();
+}
+/** ======================================================================= **/
+
+
+/** ===========================================================================
+ ** Construct a ladder out of two half ladders with vertical gap
+ ** 
+ ** The second half ladder will be rotated by 180 degrees 
+ ** in the x-y plane. The two half ladders will be put on top of each
+ ** other with a vertical gap.
+ **
+ ** Arguments: 
+ **            name             volume name
+ **            halfLadderU      pointer to upper half ladder
+ **            halfLadderD      pointer to lower half ladder
+ **            gapY             vertical gap
+ **            shiftZ           relative displacement along the z axis
+ **/
+
+TGeoVolume* ConstructLadder(Int_t LadderIndex, TGeoVolume* halfLadderU, TGeoVolume* halfLadderD, Double_t gapY,
+                            Double_t shiftZ)
+{
+
+  // --- Some variables
+  TGeoBBox* shape = NULL;
+
+  // --- Dimensions of half ladders
+  shape       = (TGeoBBox*) halfLadderU->GetShape();
+  Double_t xu = 2. * shape->GetDX();
+  Double_t yu = 2. * shape->GetDY();
+  Double_t zu = 2. * shape->GetDZ();
+
+  shape       = (TGeoBBox*) halfLadderD->GetShape();
+  Double_t xd = 2. * shape->GetDX();
+  Double_t yd = 2. * shape->GetDY();
+  Double_t zd = 2. * shape->GetDZ();
+
+  // --- Create ladder volume assembly
+  TString name               = Form("LadderType%02d", LadderIndex);
+  TGeoVolumeAssembly* ladder = new TGeoVolumeAssembly(name);
+  Double_t ladderX           = TMath::Max(xu, xd);
+  Double_t ladderY           = yu + yd + gapY;
+  Double_t ladderZ           = TMath::Max(zu, zd + shiftZ);
+
+  // --- Place half ladders
+  Double_t xPosU      = 0.;                    // centred in x
+  Double_t yPosU      = 0.5 * (ladderY - yu);  // top aligned
+  Double_t zPosU      = 0.5 * (ladderZ - zu);  // front aligned
+  TGeoTranslation* tu = new TGeoTranslation("tu", xPosU, yPosU, zPosU);
+  ladder->AddNode(halfLadderU, 1, tu);
+
+  Double_t xPosD   = 0.;                    // centred in x
+  Double_t yPosD   = 0.5 * (yd - ladderY);  // bottom aligned
+  Double_t zPosD   = 0.5 * (zd - ladderZ);  // back aligned
+  TGeoRotation* rd = new TGeoRotation();
+  rd->RotateZ(180.);
+  TGeoCombiTrans* cd = new TGeoCombiTrans(xPosD, yPosD, zPosD, rd);
+  ladder->AddNode(halfLadderD, 2, cd);
+  ladder->GetShape()->ComputeBBox();
+
+  // ----------------   Create and place frame boxes   ------------------------
+
+  if (gkConstructFrames) AddCarbonLadder(LadderIndex, ladder, xu, ladderY, ladderZ);
+
+  // --------------------------------------------------------------------------
+
+  return ladder;
+}
+/** ======================================================================= **/
+
+
+/** ===========================================================================
+ ** Construct a unit
+ **
+ ** The unit volume is the minimal box comprising all ladders
+ ** minus a tube accomodating the beam pipe.
+ **
+ ** The ladders are arranged horizontally from left to right with
+ ** a given overlap in x.
+ ** Every second ladder is slightly displaced upstream from the centre
+ ** z plane and facing downstream, the others are slightly displaced
+ ** downstream and facing upstream (rotated around the y axis).
+ **
+ ** Arguments: 
+ **            name             volume name
+ **            nLadders         number of ladders
+ **            ladderTypes      array of ladder types
+ **/
+
+TGeoVolume* ConstructUnit(Int_t iSide, Int_t iUnit, Int_t nLadders, Int_t* ladderTypes, Int_t iStation)
+{
+
+  Bool_t isFirstPartOfHalfUnit = kFALSE;
+
+  //  TString name = Form("Unit%02d", iUnit);    // 0,1,2,3,4,5,6,7 - Unit00 missing in output
+  //  TString name = Form("Unit%02d", iUnit+1);  // 1,2,3,4,5,6,7,8
+
+  TGeoVolume* unit = gGeoMan->GetVolume(unitName[iUnit]);
+  if (!unit)  // if it does not yet exist, create a new one
+  {
+    unit                  = new TGeoVolumeAssembly(unitName[iUnit]);
+    isFirstPartOfHalfUnit = kTRUE;
+  }
+
+  // --- Some local variables
+  TGeoBBox* ladderShape = NULL;
+  TGeoVolume* ladder    = NULL;
+  TString ladderName;
+  Double_t subtractedVal;
+
+  // --- Determine size of unit from ladders
+  Double_t statX = 0.;
+  //  Double_t statY     = 0.;
+
+  for (Int_t iLadder = 0; iLadder < nLadders; iLadder++) {
+    Int_t ladderType = ladderTypes[iLadder] % 100;
+    if (ladderType > 0) {
+      ladderName = Form("LadderType%02d", ladderType);
+      ladder     = gGeoManager->GetVolume(ladderName);
+      if (!ladder) Fatal("ConstructUnit", Form("Volume %s not found", ladderName.Data()));
+      ladderShape = (TGeoBBox*) ladder->GetShape();
+      statX += 2. * ladderShape->GetDX();
+      //      statY = TMath::Max(statY, 2. * ladderShape->GetDY());
+    }
+    else
+      statX += gkSensorSizeX;  // empty ladder in unit
+  }
+  statX -= Double_t(nLadders - 1) * gkLadderOverlapX;
+
+  // --- Place ladders in unit
+  cout << "xPos0: " << statX << endl;
+  Double_t xPos = -0.5 * statX;
+  cout << "xPos1: " << xPos << endl;
+  Double_t yPos = 0.;
+  Double_t zPos = 0.;
+
+  Double_t maxdz = 0.;
+  for (Int_t iLadder = 0; iLadder < nLadders; iLadder++) {  // find maximum dz in this unit
+    Int_t ladderType = ladderTypes[iLadder] % 100;
+    if (ladderType > 0) {
+      ladderName  = Form("LadderType%02d", ladderType);
+      ladder      = gGeoManager->GetVolume(ladderName);
+      ladderShape = (TGeoBBox*) ladder->GetShape();
+      if (maxdz < ladderShape->GetDZ()) maxdz = ladderShape->GetDZ();
+    }
+  }
+
+  for (Int_t iLadder = 0; iLadder < nLadders; iLadder++) {
+    Int_t ladderType = ladderTypes[iLadder] % 100;
+    if (ladderType > 0) {
+      ladderName  = Form("LadderType%02d", ladderType);
+      ladder      = gGeoManager->GetVolume(ladderName);
+      ladderShape = (TGeoBBox*) ladder->GetShape();
+      xPos += ladderShape->GetDX();
+      cout << "xPos2: " << xPos << endl;
+      yPos              = 0.;  // vertically centred
+      TGeoRotation* rot = new TGeoRotation();
+
+      if (gkConstructFrames)
+        // DEDE
+        subtractedVal = sqrt(2.) * gkFrameThickness / 2. + ladderShape->GetDX();
+      //      subtractedVal = 2*gkSectorGapZFrame + sqrt(2.)*gkFrameThickness/2. + ladderShape->GetDX();
+      else
+        subtractedVal = 0.;
+
+      //    zPos = 0.5 * gkLadderGapZ + (ladderShape->GetDZ()-subtractedVal/2.);  // non z-aligned ladders
+      zPos = 0.5 * gkLadderGapZ + (2 * maxdz - ladderShape->GetDZ() - subtractedVal / 2.);  // z-aligned ladders
+
+      cout << "DE ladder" << ladderTypes[iLadder] % 100 << "  dx: " << ladderShape->GetDX()
+           << "  dy: " << ladderShape->GetDY() << "  dz: " << ladderShape->GetDZ() << "  max dz: " << maxdz << endl;
+
+      cout << "DE ladder" << ladderTypes[iLadder] % 100 << "  fra: " << gkFrameThickness / 2.
+           << "  sub: " << subtractedVal << "  zpo: " << zPos << endl
+           << endl;
+
+      if (ladderTypes[iLadder] / 100 == 1)  // flip some of the ladders to reproduce the CAD layout
+        rot->RotateY(180.);
+      else
+        zPos = -zPos;
+
+      if (!isFirstPartOfHalfUnit) zPos += 10;
+
+      TGeoCombiTrans* trans = new TGeoCombiTrans(xPos, yPos, zPos, rot);
+      // start
+      //      cout << "DEEE** iLadder " << iLadder << " " << nLadders/2 << " " << nLadders << endl;
+
+      if (iSide == 0) {
+        if (iLadder < nLadders / 2)  // right side - only half unit -x
+        {
+          unit->AddNode(ladder, iStation * 100 + iLadder + 1, trans);
+          // calculate Station number to encode the ladder copy number
+          cout << "DEFG** iLadder: " << iLadder << " iStation: " << iStation << endl;
+        }
+      }
+      else {
+        if (iLadder >= nLadders / 2)  // left  side - only half unit +x
+        {
+          unit->AddNode(ladder, iStation * 100 + iLadder + 1, trans);
+          // calculate Station number to encode the ladder copy number
+          cout << "DEFG** iLadder: " << iLadder << " iStation: " << iStation << endl;
+        }
+      }
+      unit->GetShape()->ComputeBBox();
+      // stop
+      xPos += ladderShape->GetDX() - gkLadderOverlapX;
+      cout << "xPos3: " << xPos << endl;
+    }
+    else
+      xPos += gkSensorSizeX - gkLadderOverlapX;
+  }
+
+  return unit;
+}
+/** ======================================================================= **/
+
+
+/** ===========================================================================
+ ** Import and add the passive materials to the STS volume
+ **/
+void ImportPassive(TGeoVolume* stsVolume, TString geoTag, fstream& infoFile)
+{
+  TString passiveName     = TString("sts_passive_v19a");
+  TString basePath        = gSystem->Getenv("VMCWORKDIR");
+  TString relPath         = "/geometry/sts/passive/" + passiveName + ".gdml";
+  TString passiveFileName = basePath + relPath;
+  infoFile << std::endl << std::endl;
+  infoFile << "Importing STS passive materials from GDML file '" << relPath << "'." << std::endl;
+
+  TGDMLParse parser;
+  TGeoVolume* gdmlVolume = parser.GDMLReadFile(passiveFileName);
+  PostProcessGdml(gdmlVolume);
+  gdmlVolume->SetName(passiveName);
+
+  TGeoTranslation* passiveTrans = new TGeoTranslation(0., 0., 4.68);
+  infoFile << "Passive assembly is translated for Z=4.68 cm downstream with "
+              "respect to parent volume"
+           << std::endl
+           << std::endl;
+
+  gdmlVolume->GetShape()->ComputeBBox();
+  CheckVolume(gdmlVolume, infoFile);
+
+  infoFile << std::endl;
+  for (Int_t iNode = 0; iNode < gdmlVolume->GetNdaughters(); iNode++) {
+    CheckVolume(gdmlVolume->GetNode(iNode)->GetVolume(), infoFile, kFALSE);
+  }
+
+  stsVolume->AddNode(gdmlVolume, stsVolume->GetNdaughters(), passiveTrans, "");
+}
+
+/** ===========================================================================
+ ** Assign visual properties to the imported gdml volumes
+ **/
+void PostProcessGdml(TGeoVolume* gdmlVolume)
+{
+  const UInt_t kPOBColor        = kRed - 6;
+  const UInt_t kPOBTransparency = 0;  // 5;
+
+  const UInt_t kFEBColor        = kOrange - 6;
+  const UInt_t kFEBTransparency = 0;  // 5;
+
+  const UInt_t kUnitColor        = kCyan - 10;
+  const UInt_t kUnitTransparency = 0;  // 5;
+
+  const UInt_t kCfColor        = kGray + 3;
+  const UInt_t kCfTransparency = 0;  // 10;
+
+  // name <Color, Transparency>
+  std::map<std::string, std::tuple<UInt_t, UInt_t>> props {
+    {"passive_POB", std::tuple<UInt_t, UInt_t> {kPOBColor, kPOBTransparency}},
+    {"passive_FEB", std::tuple<UInt_t, UInt_t> {kFEBColor, kFEBTransparency}},
+    {"passive_unit", std::tuple<UInt_t, UInt_t> {kUnitColor, kUnitTransparency}},
+    {"passive_Box_Wall", std::tuple<UInt_t, UInt_t> {kCfColor, kCfTransparency}},
+    {"passive_Box_Wall_Front_CF2", std::tuple<UInt_t, UInt_t> {kCfColor - 3, kCfTransparency}},
+  };
+
+  // Match volume name and apply visual properties
+  const TObjArray* volumes = gGeoManager->GetListOfVolumes();
+  for (auto& entry : props) {
+    TIter next(volumes);
+    TGeoVolume* vol = nullptr;
+    while ((vol = (TGeoVolume*) next())) {
+      if (TString(vol->GetName()).Contains(entry.first.c_str())) {
+        vol->SetLineColor(std::get<0>(entry.second));
+        vol->SetTransparency(std::get<1>(entry.second));
+      }
+    }
+  }
+}
+
+/** ===========================================================================
+ ** Volume information for debugging
+ **/
+void CheckVolume(TGeoVolume* volume)
+{
+
+  TGeoBBox* shape = (TGeoBBox*) volume->GetShape();
+  cout << volume->GetName() << ": size " << fixed << setprecision(4) << setw(7) << 2. * shape->GetDX() << " x "
+       << setw(7) << 2. * shape->GetDY() << " x " << setw(7) << 2. * shape->GetDZ();
+  if (volume->IsAssembly()) cout << ", assembly";
+  else {
+    if (volume->GetMedium()) cout << ", medium " << volume->GetMedium()->GetName();
+    else
+      cout << ", "
+           << "\033[31m"
+           << " no medium"
+           << "\033[0m";
+  }
+  cout << endl;
+  if (volume->GetNdaughters()) {
+    cout << "Daughters: " << endl;
+    for (Int_t iNode = 0; iNode < volume->GetNdaughters(); iNode++) {
+      TGeoNode* node  = volume->GetNode(iNode);
+      TGeoBBox* shape = (TGeoBBox*) node->GetVolume()->GetShape();
+      cout << setw(15) << node->GetName() << ", size " << fixed << setprecision(3) << setw(6) << 2. * shape->GetDX()
+           << " x " << setw(6) << 2. * shape->GetDY() << " x " << setw(6) << 2. * shape->GetDZ() << ", position ( ";
+      TGeoMatrix* matrix  = node->GetMatrix();
+      const Double_t* pos = matrix->GetTranslation();
+      cout << setfill(' ');
+      cout << fixed << setw(8) << pos[0] << ", " << setw(8) << pos[1] << ", " << setw(8) << pos[2] << " )" << endl;
+    }
+  }
+}
+/** ======================================================================= **/
+
+
+/** ===========================================================================
+ ** Volume information for output to file
+ **/
+void CheckVolume(TGeoVolume* volume, fstream& file, Bool_t listChildren)
+{
+  if (!file) return;
+
+  TGeoBBox* shape = (TGeoBBox*) volume->GetShape();
+  file << volume->GetName() << ": size " << fixed << setprecision(4) << setw(7) << 2. * shape->GetDX() << " x "
+       << setw(7) << 2. * shape->GetDY() << " x " << setw(7) << 2. * shape->GetDZ();
+  if (volume->IsAssembly()) file << ", assembly";
+  else {
+    if (volume->GetMedium()) file << ", medium " << volume->GetMedium()->GetName();
+    else
+      file << ", "
+           << "\033[31m"
+           << " no medium"
+           << "\033[0m";
+  }
+  file << endl;
+  if (volume->GetNdaughters() && listChildren) {
+    file << "Contains: ";
+    for (Int_t iNode = 0; iNode < volume->GetNdaughters(); iNode++)
+      file << volume->GetNode(iNode)->GetVolume()->GetName() << " ";
+    file << endl;
+  }
+}
+/** ======================================================================= **/
+
+
+/** ===========================================================================
+ ** Calculate beam pipe outer radius for a given z
+ **/
+Double_t BeamPipeRadius(Double_t z)
+{
+  if (z < gkPipeZ2) return gkPipeR1;
+  Double_t slope = (gkPipeR3 - gkPipeR2) / (gkPipeZ3 - gkPipeZ2);
+  return gkPipeR2 + slope * (z - gkPipeZ2);
+}
+/** ======================================================================= **/
+
+
+/** ======================================================================= **/
+TGeoVolume* ConstructFrameElement(const TString& name, TGeoVolume* frameBoxVol, Double_t x)
+{
+  // --- Material of the frames
+  TGeoMedium* framesMaterial = gGeoMan->GetMedium("carbon");
+
+  TGeoBBox* frameVertPillarShp;
+
+  Double_t t = gkFrameThickness / 2.;
+
+  // --- Main vertical pillars
+  //      TGeoBBox* frameVertPillarShp = new TGeoBBox(name + "_vertpillar_shape", t, gkFrameStep/2., t);  // square crossection, along y
+  //  TGeoVolume* frameVertPillarVol = new TGeoVolume(name + "_vertpillar", frameVertPillarShp, framesMaterial);
+  //  frameVertPillarVol->SetLineColor(kGreen);
+  //  frameBoxVol->AddNode(frameVertPillarVol, 1, new TGeoTranslation(name + "_vertpillar_pos_1", x-t, 0., -(x+sqrt(2.)*t-2.*t)/2.));
+  //  frameBoxVol->AddNode(frameVertPillarVol, 2, new TGeoTranslation(name + "_vertpillar_pos_2", -(x-t), 0., -(x+sqrt(2.)*t-2.*t)/2.));
+
+  if (gkCylindricalFrames)
+    //          TGeoBBox* frameVertPillarShp = new TGeoTube(name + "_vertpillar_shape", 0, t, gkFrameStep/2.);  // circle crossection, along z
+    frameVertPillarShp = new TGeoTube(name + "_vertpillar_shape", gkCylinderDiaInner / 2., gkCylinderDiaOuter / 2.,
+                                      gkFrameStep / 2.);  // circle crossection, along z
+  else
+    frameVertPillarShp = new TGeoBBox(name + "_vertpillar_shape", t, t,
+                                      gkFrameStep / 2.);  // square crossection, along z
+  TGeoVolume* frameVertPillarVol = new TGeoVolume(name + "_vertpillar", frameVertPillarShp, framesMaterial);
+  frameVertPillarVol->SetLineColor(kGreen);
+
+  TGeoRotation* xRot90 = new TGeoRotation;
+  xRot90->RotateX(90.);
+  frameBoxVol->AddNode(
+    frameVertPillarVol, 1,
+    new TGeoCombiTrans(name + "_vertpillar_pos_1", x - t, 0., -(x + sqrt(2.) * t - 2. * t) / 2., xRot90));
+  frameBoxVol->AddNode(
+    frameVertPillarVol, 2,
+    new TGeoCombiTrans(name + "_vertpillar_pos_2", -(x - t), 0., -(x + sqrt(2.) * t - 2. * t) / 2., xRot90));
+
+  //  TGeoRotation* vertRot = new TGeoRotation(name + "_vertpillar_rot_1", 90., 45., -90.);
+  TGeoRotation* vertRot = new TGeoRotation;
+  vertRot->RotateX(90.);
+  vertRot->RotateY(45.);
+  frameBoxVol->AddNode(frameVertPillarVol, 3,
+                       new TGeoCombiTrans(name + "_vertpillar_pos_3", 0., 0., (x - sqrt(2.) * t) / 2., vertRot));
+
+  // --- Small horizontal pillar
+  // TGeoBBox* frameHorPillarShp = new TGeoBBox(name + "_horpillar_shape", x-2.*t, gkThinFrameThickness/2., gkThinFrameThickness/2.);
+  // TGeoVolume* frameHorPillarVol = new TGeoVolume(name + "_horpillar", frameHorPillarShp, framesMaterial);
+  // frameHorPillarVol->SetLineColor(kCyan);
+  // frameBoxVol->AddNode(frameHorPillarVol, 1, new TGeoTranslation(name + "_horpillar_pos_1", 0., -gkFrameStep/2.+gkThinFrameThickness/2., -(x+sqrt(2.)*t-2.*t)/2.));
+
+  if (gkConstructSmallFrames) {
+
+    // --- Small sloping pillars
+    TGeoPara* frameSlopePillarShp =
+      new TGeoPara(name + "_slopepillar_shape", (x - 2. * t) / TMath::Cos(31.4 / 180. * TMath::Pi()),
+                   gkThinFrameThickness / 2., gkThinFrameThickness / 2., 31.4, 0., 90.);
+    TGeoVolume* frameSlopePillarVol = new TGeoVolume(name + "_slopepillar", frameSlopePillarShp, framesMaterial);
+    frameSlopePillarVol->SetLineColor(kCyan);
+    TGeoRotation* slopeRot  = new TGeoRotation(name + "_slopepillar_rot_1", 0., 0., 31.4);
+    TGeoRotation* slopeRot2 = new TGeoRotation(name + "_slopepillar_rot_2", 0., 0., -31.4);
+    TGeoCombiTrans* slopeTrRot =
+      new TGeoCombiTrans(name + "_slopepillar_posrot_1", 0., 0., -(x + sqrt(2.) * t - 2. * t) / 2., slopeRot);
+    TGeoCombiTrans* slopeTrRot2 =
+      new TGeoCombiTrans(name + "_slopepillar_posrot_2", 0., 0., -(x + sqrt(2.) * t - 2. * t) / 2., slopeRot2);
+
+    frameBoxVol->AddNode(frameSlopePillarVol, 1, slopeTrRot);
+    frameBoxVol->AddNodeOverlap(frameSlopePillarVol, 2, slopeTrRot2);
+
+
+    Double_t angl = 23.;
+    // --- Small sub pillar
+    TGeoPara* frameSubPillarShp =
+      new TGeoPara(name + "_subpillar_shape", (sqrt(2) * (x / 2. - t) - t / 2.) / TMath::Cos(angl / 180. * TMath::Pi()),
+                   gkThinFrameThickness / 2., gkThinFrameThickness / 2., angl, 0., 90.);
+    TGeoVolume* frameSubPillarVol = new TGeoVolume(name + "_subpillar", frameSubPillarShp, framesMaterial);
+    frameSubPillarVol->SetLineColor(kMagenta);
+
+    Double_t posZ = t * (1. - 3. / (2. * sqrt(2.)));
+
+    // one side of X direction
+    TGeoRotation* subRot1 = new TGeoRotation(name + "_subpillar_rot_1", 90., 45., -90. + angl);
+    TGeoCombiTrans* subTrRot1 =
+      new TGeoCombiTrans(name + "_subpillar_posrot_1", -(-x / 2. + t - t / (2. * sqrt(2.))), 1., posZ, subRot1);
+
+    TGeoRotation* subRot2 = new TGeoRotation(name + "_subpillar_rot_2", 90., -90. - 45., -90. + angl);
+    TGeoCombiTrans* subTrRot2 =
+      new TGeoCombiTrans(name + "_subpillar_posrot_2", -(-x / 2. + t - t / (2. * sqrt(2.))), -1., posZ, subRot2);
+
+    // other side of X direction
+    TGeoRotation* subRot3 = new TGeoRotation(name + "_subpillar_rot_3", 90., 90. + 45., -90. + angl);
+    TGeoCombiTrans* subTrRot3 =
+      new TGeoCombiTrans(name + "_subpillar_posrot_3", -x / 2. + t - t / (2. * sqrt(2.)), 1., posZ, subRot3);
+
+    TGeoRotation* subRot4 = new TGeoRotation(name + "_subpillar_rot_4", 90., -45., -90. + angl);
+    TGeoCombiTrans* subTrRot4 =
+      new TGeoCombiTrans(name + "_subpillar_posrot_4", -x / 2. + t - t / (2. * sqrt(2.)), -1., posZ, subRot4);
+
+    frameBoxVol->AddNode(frameSubPillarVol, 1, subTrRot1);
+    frameBoxVol->AddNode(frameSubPillarVol, 2, subTrRot2);
+    frameBoxVol->AddNode(frameSubPillarVol, 3, subTrRot3);
+    frameBoxVol->AddNode(frameSubPillarVol, 4, subTrRot4);
+    //                frameBoxVol->GetShape()->ComputeBBox();
+  }
+
+  return frameBoxVol;
+}
+/** ======================================================================= **/
+
+/** ======================================================================= **/
+TGeoVolume* ConstructSmallCone(Double_t coneDz)
+{
+  // --- Material of the frames
+  TGeoMedium* framesMaterial = gGeoMan->GetMedium("carbon");
+
+  // --- Outer cone
+  //  TGeoConeSeg* A = new TGeoConeSeg ("A", coneDz, 6., 7.6, 6., 6.04, 0., 180.);
+  //  TGeoBBox* B = new TGeoBBox ("B", 8., 6., 10.);
+
+  Double_t radius    = 3.0;
+  Double_t thickness = 0.04;  // 0.4 mm
+  //  TGeoConeSeg* A = new TGeoConeSeg ("A", coneDz, 3., 3.2, 3., 3.2, 0., 180.);
+  TGeoConeSeg* A = new TGeoConeSeg("A", coneDz, radius, radius + thickness, radius, radius + thickness, 0., 180.);
+  TGeoBBox* B    = new TGeoBBox("B", 8., 6., 10.);
+
+  TGeoCombiTrans* M = new TGeoCombiTrans("M");
+  M->RotateX(45.);
+  M->SetDy(-5.575);
+  M->SetDz(6.935);
+  M->RegisterYourself();
+
+  TGeoShape* coneShp  = new TGeoCompositeShape("Cone_shp", "A-B:M");
+  TGeoVolume* coneVol = new TGeoVolume("Cone", coneShp, framesMaterial);
+  coneVol->SetLineColor(kGreen);
+  //  coneVol->RegisterYourself();
+
+  //  // --- Inner cone
+  //  Double_t thickness = 0.02;
+  //  Double_t thickness2 = 0.022;
+  //  //  TGeoConeSeg* A2 = new TGeoConeSeg ("A2", coneDz-thickness, 6.+thickness, 7.6-thickness2, 5.99+thickness, 6.05-thickness2, 0., 180.);
+  //  TGeoConeSeg* A2 = new TGeoConeSeg ("A2", coneDz-thickness, 3.+thickness, 4.6-thickness2, 2.99+thickness, 3.05-thickness2, 0., 180.);
+  //
+  //  TGeoCombiTrans* M2 = new TGeoCombiTrans ("M2");
+  //  M2->RotateX (45.);
+  //  M2->SetDy (-5.575+thickness*sqrt(2.));
+  //  M2->SetDz (6.935);
+  //  M2->RegisterYourself();
+  //
+  //  TGeoShape* coneShp2 = new TGeoCompositeShape ("Cone2_shp", "A2-B:M2");
+  //  TGeoVolume* coneVol2 = new TGeoVolume ("Cone2", coneShp2, gStsMedium);
+  //  coneVol2->SetLineColor(kGreen);
+  ////  coneVol2->RegisterYourself();
+  //
+  //  coneVol->AddNode(coneVol2, 1);
+
+  return coneVol;
+}
+/** ======================================================================= **/
+
+/** ======================================================================= **/
+TGeoVolume* ConstructBigCone(Double_t coneDz)
+{
+  // --- Material of the frames
+  TGeoMedium* framesMaterial = gGeoMan->GetMedium("carbon");
+
+  // --- Outer cone
+  TGeoConeSeg* bA = new TGeoConeSeg("bA", coneDz, 6., 7.6, 6., 6.04, 0., 180.);
+  TGeoBBox* bB    = new TGeoBBox("bB", 8., 6., 10.);
+
+  TGeoCombiTrans* bM = new TGeoCombiTrans("bM");
+  bM->RotateX(45.);
+  bM->SetDy(-5.575);
+  bM->SetDz(6.935);
+  bM->RegisterYourself();
+
+  TGeoShape* coneBigShp  = new TGeoCompositeShape("ConeBig_shp", "bA-bB:bM");
+  TGeoVolume* coneBigVol = new TGeoVolume("ConeBig", coneBigShp, framesMaterial);
+  coneBigVol->SetLineColor(kGreen);
+  //  coneBigVol->RegisterYourself();
+
+  // --- Inner cone
+  Double_t thickness  = 0.02;
+  Double_t thickness2 = 0.022;
+  TGeoConeSeg* bA2    = new TGeoConeSeg("bA2", coneDz - thickness, 6. + thickness, 7.6 - thickness2, 5.99 + thickness,
+                                     6.05 - thickness2, 0., 180.);
+
+  TGeoCombiTrans* bM2 = new TGeoCombiTrans("bM2");
+  bM2->RotateX(45.);
+  bM2->SetDy(-5.575 + thickness * sqrt(2.));
+  bM2->SetDz(6.935);
+  bM2->RegisterYourself();
+
+  TGeoShape* coneBigShp2  = new TGeoCompositeShape("ConeBig2_shp", "bA2-bB:bM2");
+  TGeoVolume* coneBigVol2 = new TGeoVolume("ConeBig2", coneBigShp2, gStsMedium);
+  coneBigVol2->SetLineColor(kGreen);
+  //  coneBigVol2->RegisterYourself();
+
+  coneBigVol->AddNode(coneBigVol2, 1);
+
+  return coneBigVol;
+}
+
+/** ======================================================================= **/
diff --git a/macro/tof/geometry/Create_TOF_Geometry_v20c.C b/macro/tof/geometry/Create_TOF_Geometry_v20c.C
new file mode 100644
index 0000000000000000000000000000000000000000..bd5a0dc074f099140439e32988c2abd6f75c2f17
--- /dev/null
+++ b/macro/tof/geometry/Create_TOF_Geometry_v20c.C
@@ -0,0 +1,1813 @@
+/* Copyright (C) 2021 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
+   SPDX-License-Identifier: GPL-3.0-only
+   Authors: Florian Uhlig, Eoin Clerkin [committer] */
+
+///
+/// \file Create_TOF_Geometry_v20c.C
+/// \brief Generates TOF geometry in Root format.
+///
+
+// Changelog
+//
+// 2021-12-15 - EC - Placement for centre of the magnet as global coordinate system
+// 2020-04-19 - FU - The change are the same ones introduced with 723791eafb1810b6e1e067e067907420668056de
+//                   in the file Create_TOF_Geometry_v20a.C to fix a problem with the geometry.
+//                   Since it was decided not to change an existing geometry the macro Create_TOF_Geometry_v20a.C
+//                   was reverted back to the previous version and a new macro was created.
+// 2020-10-19 - EC - prepare tof_v20_1{e,h,m} geometry (Placement Corrected) SIS 100 electron: TOF_Z_Front =  703 cm
+// 2020-09-29 - FU - Change as per commit 4408f9a9d3d66809f48c9091cda52c0f9c542165
+// 2017-10-18 - PAL- Fix the overlaps in the support structure => v16c
+// 2016-07-18 - DE - patch double free or corruption with poleshort: same TGeoVolume name was used in pole
+// 2015-11-09 - PAL- Change naming convention to follow the more meaningfull one used in trd: YYv_ss
+//                   with YY = year, v = version (a, b, ...) and ss = setup (1h for SIS100 hadron, ...)
+//                   => Prepare tof_v16a_1h to tof_v16a_3m
+// 2015-11-09 - PAL- Modify to easily prepare tof_v14_0a to tof_v14_0e on model of 13_5a to 13_5e
+// 2014-06-30 - NH - prepare tof_v14_0  geometry - SIS 300 hadron  : TOF_Z_Front =  880 cm //Bucharest
+// 2014-06-27 - NH - prepare tof_v13_6b geometry - SIS 300 hadron  : TOF_Z_Front =  880 cm //external input
+// 2013-10-16 - DE - prepare tof_v13_5a geometry - SIS 100 hadron  : TOF_Z_Front =  450 cm
+// 2013-10-16 - DE - prepare tof_v13_5b geometry - SIS 100 electron: TOF_Z_Front =  600 cm
+// 2013-10-16 - DE - prepare tof_v13_5c geometry - SIS 100 muon    : TOF_Z_Front =  650 cm
+// 2013-10-16 - DE - prepare tof_v13_5d geometry - SIS 300 electron: TOF_Z_Front =  880 cm
+// 2013-10-16 - DE - prepare tof_v13_5e geometry - SIS 300 muon    : TOF_Z_Front = 1020 cm
+// 2013-10-16 - DE - patch pole_alu bug - skip 0 thickness air volume in pole
+// 2013-09-04 - DE - prepare tof_v13_4a geometry - SIS 100 hadron  : TOF_Z_Front =  450 cm
+// 2013-09-04 - DE - prepare tof_v13_4b geometry - SIS 100 electron: TOF_Z_Front =  600 cm
+// 2013-09-04 - DE - prepare tof_v13_4c geometry - SIS 100 muon    : TOF_Z_Front =  650 cm
+// 2013-09-04 - DE - prepare tof_v13_4d geometry - SIS 300 electron: TOF_Z_Front =  880 cm
+// 2013-09-04 - DE - prepare tof_v13_4e geometry - SIS 300 muon    : TOF_Z_Front = 1020 cm
+// 2013-09-04 - DE - dump z-positions to .geo.info file
+// 2013-09-04 - DE - define front z-position of TOF wall (TOF_Z_Front)
+// 2013-09-04 - DE - fix arrangement of glass plates in RPC cells
+
+// in root all sizes are given in cm
+// read positions of modules from dat - file
+
+#include "TFile.h"
+#include "TGeoCompositeShape.h"
+#include "TGeoManager.h"
+#include "TGeoMaterial.h"
+#include "TGeoMatrix.h"
+#include "TGeoMedium.h"
+#include "TGeoPgon.h"
+#include "TGeoVolume.h"
+#include "TList.h"
+#include "TROOT.h"
+#include "TString.h"
+#include "TSystem.h"
+
+#include <iostream>
+#include <sstream>
+
+// Name of geometry version and output file
+
+//const TString geoVersion = "tof_v20c_1m";  // SIS 100
+//const TString geoVersion = "tof_v20c_1h";  // SIS 100 hadron
+const TString geoVersion = "tof_v20c_1e";  // SIS 100 hadron
+
+//const TString geoVersion = "tof_v20b_1m";  // SIS 100, 7.62m
+//const TString geoVersion = "tof_v20b_1h";  // SIS 100 hadron, 4.5 m
+//const TString geoVersion = "tof_v20b_1e";  // SIS 100 hadron, 4.5 m
+//const TString geoVersion = "tof_v16e_1h";  // SIS 100 hadron, 4.5 m
+//const TString geoVersion = "tof_v16e_1e";     // SIS 100 electron, 6 m
+//const TString geoVersion = "tof_v16e_1m";     // SIS 100 muon, 6.8 m
+//const TString geoVersion = "tof_v16e_3e";  // SIS 300 electron, 8.8 m
+//const TString geoVersion = "tof_v16e_3m";     // SIS 300 muon, 10 m
+const TString FileNameSim  = geoVersion + ".geo.root";
+const TString FileNameGeo  = geoVersion + "_geo.root";
+const TString FileNameInfo = geoVersion + ".geo.info";
+
+const Double_t TOF_Z_Corr = ("tof_v20c_1e" == geoVersion ? 760 :                        // SIS 100 electron
+                               ("tof_v20c_1h" == geoVersion ? 760 :                     // SIS 100 hadron
+                                  ("tof_v20c_1m" == geoVersion ? 839 :                  // SIS 100 muon
+                                     ("tof_v16e_1h" == geoVersion ? 546.485 :           // SIS 100 hadron
+                                        ("tof_v16e_1e" == geoVersion ? 696.485 :        // SIS 100 electron
+                                           ("tof_v16e_1m" == geoVersion ? 776.485 :     // SIS 100 muon
+                                              ("tof_v16e_3e" == geoVersion ? 976.485 :  // SIS 300 electron
+                                                 ("tof_v16e_3m" == geoVersion ? 0 :     // SIS 300 muon
+                                                    600  // Set default to SIS 100 electron
+                                                  ))))))));
+
+
+// TOF_Z_Front corresponds to front cover of outer super module towers
+const Double_t TOF_Z_Front = ("tof_v20c_1m" == geoVersion ? (762 - TOF_Z_Corr) :                    // SIS 100 muon
+                                ("tof_v20c_1e" == geoVersion ? (703 - TOF_Z_Corr) :                 // SIS 100 electron
+                                   ("tof_v20c_1h" == geoVersion ? (703 - TOF_Z_Corr) :              // SIS 100 hadron
+                                      ("tof_v16e_1h" == geoVersion ? (450 - TOF_Z_Corr) :           // SIS 100 hadron
+                                         ("tof_v16e_1e" == geoVersion ? (600 - TOF_Z_Corr) :        // SIS 100 electron
+                                            ("tof_v16e_1m" == geoVersion ? (680 - TOF_Z_Corr) :     // SIS 100 muon
+                                               ("tof_v16e_3e" == geoVersion ? (880 - TOF_Z_Corr) :  // SIS 300 electron
+                                                  ("tof_v16e_3m" == geoVersion ? (1020 - TOF_Z_Corr) :  // SIS 300 muon
+                                                     600  // Set default to SIS 100 electron
+                                                   ))))))));
+
+// Shift of the TOF inner wall relative to default position [cm];
+const Double_t InnerWall_Z_PositionShift = TOF_Z_Front - 475;  // in cm, Inner wall Offset 0 for wall at 6m
+// Shift of the TOF outer wall relative to default position [cm];
+const Double_t Wall_Z_PositionShift = InnerWall_Z_PositionShift - 405;  // in cm, Outer wall Offset -5cm for wall at 10m
+// for 0 m
+/*
+const Double_t  = -600.;  // inner wall placed at 600
+const Double_t       = -998.;  // outer wall placed at 1000
+*/
+// for 6m
+/*
+const Double_t InnerWall_Z_PositionShift = 0.;    // -600.;  // inner wall placed at 600
+const Double_t Wall_Z_PositionShift      = -425.; // -998.;  // outer wall placed at 1000
+*/
+/*
+// for 10 m
+const Double_t InnerWall_Z_PositionShift = 400.;    // -600.;  // inner wall placed at 600
+const Double_t Wall_Z_PositionShift      = -25.; // -998.;  // outer wall placed at 1000
+*/
+
+// Names of the different used materials which are used to build the modules
+// The materials are defined in the global media.geo file
+const TString KeepingVolumeMedium = "air";
+const TString BoxVolumeMedium     = "aluminium";
+const TString PoleVolumeMedium    = "tof_pole_aluminium";
+const TString NoActivGasMedium    = "RPCgas_noact";
+const TString ActivGasMedium      = "RPCgas";
+const TString GlasMedium          = "RPCglass";
+const TString ElectronicsMedium   = "carbon";
+
+const Int_t NumberOfDifferentCounterTypes             = 4;
+const Double_t Glass_X[NumberOfDifferentCounterTypes] = {32., 32., 30.0, 30.0};
+const Double_t Glass_Y[NumberOfDifferentCounterTypes] = {26.9, 53., 20., 10.};
+const Double_t Glass_Z[NumberOfDifferentCounterTypes] = {0.1, 0.1, 0.1, 0.1};
+
+const Double_t GasGap_X[NumberOfDifferentCounterTypes] = {32., 32., 30.0, 30.0};
+const Double_t GasGap_Y[NumberOfDifferentCounterTypes] = {26.9, 53., 20., 10.};
+const Double_t GasGap_Z[NumberOfDifferentCounterTypes] = {0.025, 0.025, 0.025, 0.025};
+
+const Int_t NumberOfGaps[NumberOfDifferentCounterTypes] = {8, 8, 8, 8};
+//const Int_t NumberOfGaps[NumberOfDifferentCounterTypes] = {1,1,1,1}; //deb
+const Int_t NumberOfReadoutStrips[NumberOfDifferentCounterTypes] = {32, 32, 32, 32};
+//const Int_t NumberOfReadoutStrips[NumberOfDifferentCounterTypes] = {1,1,1,1}; //deb
+
+const Double_t SingleStackStartPosition_Z[NumberOfDifferentCounterTypes] = {-0.6, -0.6, -0.6, -0.6};
+
+const Double_t Electronics_X[NumberOfDifferentCounterTypes] = {34.0, 34.0, 32.0, 32.};
+const Double_t Electronics_Y[NumberOfDifferentCounterTypes] = {5.0, 5.0, 0.5, 0.5};
+const Double_t Electronics_Z[NumberOfDifferentCounterTypes] = {0.3, 0.3, 0.3, 0.3};
+
+const Int_t NofModuleTypes     = 7;
+const Int_t MaxNofModules      = 128;
+Int_t NModules[NofModuleTypes] = {0};
+Double_t xPosMod[NofModuleTypes][MaxNofModules];
+Double_t yPosMod[NofModuleTypes][MaxNofModules];
+Double_t zPosMod[NofModuleTypes][MaxNofModules];
+Double_t FlipMod[NofModuleTypes][MaxNofModules];
+
+const Int_t NMm  = 4;
+const Int_t NMTm = 3;
+// modules are placed in master reference frame (0,0,0) is the target position
+// x - horizontal, y vertical, z along beam
+// all number for the 6m position
+
+Double_t xPosModm[NMTm][NMm] = {{0., 0., 0., 0.},             //x - coordinates of center of M1 modules
+                                {129.5, -129.5, 0., 0.},      //x - coordinates of center of M2 modules
+                                {146., -146., 146., -146.}};  //x - coordinates of center of M3 modules
+Double_t yPosModm[NMTm][NMm] = {{-92.1, 92.1, 0., 0.},        //y - coordinates of center of M1 modules
+                                {0., 0., 0., 0.},             //y - coordinates of center of M2 modules
+                                {-92.1, -92.1, 92.1, 92.1}};  //y - coordinates of center of M3 modules
+
+// original z- positions
+/*
+Double_t zPosModm[NMTm][NMm] = {{608.32,608.32,0.,0.},       //z - coordinates of center of M1 modules
+			       {632.22,632.22,0.,0.},        //z - coordinates of center of M2 modules
+			       {656.12,656.12,656.12,656.12}};//z - coordinates of center of M3 modules
+*/
+// inverted M1/M2 positions
+
+Double_t zPosModm[NMTm][NMm] = {{632.22, 632.22, 0., 0.},           //z - coordinates of center of M1 modules
+                                {608.22, 608.22, 0., 0.},           //z - coordinates of center of M2 modules
+                                {656.12, 656.12, 656.12, 656.12}};  //z - coordinates of center of M3 modules
+
+Double_t FlipModm[NMTm][NMm] = {{0., 180., 0., 0.},  //M1 rotation angle with respect to normal of surface
+                                {0., 180., 0., 0.},  //M2 rotation angle
+                                {0., 0., 0., 0.}};   //M3 rotation angle
+
+/*
+Double_t xPosModm[NMTm][NMm] = {{0.,0.,0.,0.},            //M1 coordinates
+			       {132.8,-132.8,0.,0.},     //M2 coordinates
+			       {140.,140.,-140.,-140.}}; //M3 coordinates
+Double_t yPosModm[NMTm][NMm] = {{89.,-89.,0.,0.},         //M1 coordinates
+			       {0.,0.,0.,0.},            //M2 coordinates
+			       {89.,-89.,89.,-89.}};     //M3 coordinates
+Double_t zPosModm[NMTm][NMm] = {{1082.,1082.,0.,0.},      //M1 coordinates
+			       {1045.,1045,0.,0.},       //M2 coordinates
+			       {1015.,1015.,1015.,1015.}};//M3 coordinates
+Double_t FlipModm[NMTm][NMm] = {{0.,180.,0.,0.},           //M1 angle
+			       {0.,180.,0.,0.},           //M2 angle
+			       {0.,0.,180.,180.}};        //M3 angle
+
+const Double_t CounterXstart1[NMTm] = {-44.,-27.,-64.};
+const Double_t CounterYstart1[NMTm] = {-37.,-19.,-55.};
+const Double_t CounterDyoff1[NMTm][2] = {{3.,-3.},
+					{-3.,3.},
+					{3.,-3.}};
+const Double_t CounterDzoff1[NMTm][2] = {{5.,-5.},
+					{-5.,5.},
+					{5.,-5.}};
+const Double_t CounterDxpos1[NMTm] = {30.,32.,31.};
+const Double_t CounterDypos1[NMTm] = {18.,18.,18.};
+
+const Int_t NCounter2Y[NMTm]       = {2,6,0};
+const Double_t CounterXstart2[NMTm] = {-44.,-85.,-62.};
+const Double_t CounterYstart2[NMTm] = {-59.,-23.,-55.};
+const Double_t CounterDyoff2[NMTm][2] = {{ 3.,-3.},
+					{-3.,3.},
+					{3.,-3.}};
+const Double_t CounterDzoff2[NMTm][2] = {{-5.,5.},
+					{-5.,5.},
+					{5.,-5.}};
+const Double_t CounterDxpos2[NMTm] = {30.,30.,30.};
+const Double_t CounterDypos2[NMTm] = { 8.,9.,8.};
+*/
+
+//*************************************************************
+const Double_t xPosCounter1[32] = {43.5,  14.5,  -14.5, -43.5, 43.5,  14.5,  -14.5, -43.5, 43.5,  14.5, -14.5,
+                                   -43.5, 43.5,  14.5,  -14.5, -43.5, 43.5,  14.5,  -14.5, -43.5, 43.5, 14.5,
+                                   -14.5, -43.5, 43.5,  14.5,  -14.5, -43.5, 43.5,  14.5,  -14.5, -43.5};
+const Double_t yPosCounter1[32] = {-54.6, -54.6, -54.6, -54.6, -36.4, -36.4, -36.4, -36.4, -18.2, -18.2, -18.2,
+                                   -18.2, 0.,    0.,    0.,    0.,    18.2,  18.2,  18.2,  18.2,  36.4,  36.4,
+                                   36.4,  36.4,  50.5,  50.5,  50.5,  50.5,  59.6,  59.6,  59.6,  59.6};
+const Double_t zPosCounter1[32] = {-3.01, -7.55, -3.01, -7.55, 6.07,  1.53,  6.07,  1.53,  -3.01, -7.55, -3.01,
+                                   -7.55, 6.07,  1.53,  6.07,  1.53,  -3.01, -7.55, -3.01, -7.55, 6.07,  1.53,
+                                   6.07,  1.53,  -3.01, -7.55, -3.01, -7.55, 6.07,  1.53,  6.07,  1.53};
+/*
+const Double_t xPosCounter2[27] = {87.,58.,29.,0.,-29.,-58.,-87.,-58.,-87.,87.,58.,29.,0.,-29.,-58.,-87.,-58.,-87.,
+87.,58.,29.,0.,-29.,-58.,-87.,-58.,-87.};
+const Double_t yPosCounter2[27] = {-19.,-19.,-19.,-19.,-19.,-24.,-24.,-14.4,-14.4,0.,0.,0.,0.,0.,-4.8,-4.8,4.8,4.8,
+19.,19.,19.,19.,19.,14.4,14.4,24.,24.};
+const Double_t zPosCounter2[27] = {-7.55,-3.01,-7.55,-3.01,-7.55,-3.01,-7.55,6.07,1.53,1.53,6.07,1.53,6.07,1.53,
+-3.01,-7.55,6.07,1.53,-7.55,-3.01,-7.55,-3.01,-7.55,-3.01,-7.55,6.07,1.53};
+*/
+// rearranged: first all large, than the small counters
+const Double_t xPosCounter2[27] = {87.,  58.,  29.,  0.,   -29., 87.,  58.,  29.,  0.,   -29., 87.,  58.,  29., 0.,
+                                   -29., -58., -87., -58., -87., -58., -87., -58., -87., -58., -87., -58., -87.};
+const Double_t yPosCounter2[27] = {-19., -19., -19., -19.,  -19.,  0.,   0.,   0.,  0.,  0.,   19.,  19., 19., 19.,
+                                   19.,  -24., -24., -14.4, -14.4, -4.8, -4.8, 4.8, 4.8, 14.4, 14.4, 24., 24.};
+const Double_t zPosCounter2[27] = {-7.55, -3.01, -7.55, -3.01, -7.55, 1.53,  6.07,  1.53,  6.07,
+                                   1.53,  -7.55, -3.01, -7.55, -3.01, -7.55, -3.01, -7.55, 6.07,
+                                   1.53,  -3.01, -7.55, 6.07,  1.53,  -3.01, -7.55, 6.07,  1.53};
+
+const Double_t xPosCounter3[42] = {72.5,  43.5,  14.5,  -14.5, -43.5, -72.5, 72.5,  43.5,  14.5, -14.5, -43.5,
+                                   -72.5, 72.5,  43.5,  14.5,  -14.5, -43.5, -72.5, 72.5,  43.5, 14.5,  -14.5,
+                                   -43.5, -72.5, 72.5,  43.5,  14.5,  -14.5, -43.5, -72.5, 72.5, 43.5,  14.5,
+                                   -14.5, -43.5, -72.5, 72.5,  43.5,  14.5,  -14.5, -43.5, -72.5};
+const Double_t yPosCounter3[42] = {-54.6, -54.6, -54.6, -54.6, -54.6, -54.6, -34.6, -34.6, -34.6, -34.6, -34.6,
+                                   -34.6, -18.2, -18.2, -18.2, -18.2, -18.2, -18.2, 0.,    0.,    0.,    0.,
+                                   0.,    0.,    18.2,  18.2,  18.2,  18.2,  18.2,  18.2,  34.6,  34.6,  34.6,
+                                   34.6,  34.6,  34.6,  54.6,  54.6,  54.6,  54.6,  54.6,  54.6};
+const Double_t zPosCounter3[42] = {-7.55, -3.01, -7.55, -3.01, -7.55, -3.01, 1.53,  6.07,  1.53, 6.07, 1.53,
+                                   6.07,  -7.55, -3.01, -7.55, -3.01, -7.55, -3.01, 1.53,  6.07, 1.53, 6.07,
+                                   1.53,  6.07,  -7.55, -3.01, -7.55, -3.01, -7.55, -3.01, 1.53, 6.07, 1.53,
+                                   6.07,  1.53,  6.07,  -7.55, -3.01, -7.55, -3.01, -7.55, -3.01};
+
+//  trebuie recalculat pt a da centrul detectorului, nu coltul lui
+const Int_t NCounter1Y[NMTm]        = {6, 3, 7};
+const Double_t CounterXstart1[NMTm] = {
+  -43.5, 87., 72.5};  // position of left most counter in x - direction (for un-rotated modules)
+const Double_t CounterYstart1[NMTm]   = {-54.6, -19.,
+                                       -54.6};  // position of lowest counter in y direction (for un-rotated modules)
+const Double_t CounterDyoff1[NMTm][2] = {{-4.54, 4.54},  // staggering in z direction due to row number
+                                         {4.54, -4.54},
+                                         {4.54, -4.54}};
+const Double_t CounterDzoff1[NMTm][2] = {{4.54, -4.54},  // staggering in z direction due to column number
+                                         {4.54, -4.54},
+                                         {4.54, -4.54}};
+const Double_t CounterDxpos1[NMTm]    = {29., 29., 29.};    // distance of counters in x - direction
+const Double_t CounterDypos1[NMTm]    = {18.2, 19., 18.2};  // distance of counters in y - direction
+
+const Int_t NCounter2Y[NMTm] = {2, 6,
+                                0};  //number of counters of 100 mm strip length in a column within each module type
+
+const Double_t CounterXstart2[NMTm]   = {-43.5, -58., 0.};
+const Double_t CounterYstart2[NMTm]   = {50.5, -24., 0.};
+const Double_t CounterDyoff2[NMTm][2] = {{-4.54, 4.54}, {-4.54, 4.54}, {0., 0.}};
+const Double_t CounterDzoff2[NMTm][2] = {{4.54, -4.54}, {4.54, -4.54}, {0., 0.}};
+const Double_t CounterDxpos2[NMTm]    = {29., 29., 29.};
+const Double_t CounterDypos2[NMTm]    = {9.1, 9.6, 0.};
+
+// Aluminum box for all module types
+//m,s,b,m1,m2,m3
+const Double_t Module_Size_X[NofModuleTypes] = {180.2, 180.2, 180.2, 180.2, 127.0, 214.0, 185.0};
+const Double_t Module_Size_Y[NofModuleTypes] = {49., 49., 49., 74., 141.7, 70.5, 141.7};
+const Double_t Module_Over_Y[NofModuleTypes] = {11.5, 11.5, 11., 4.5, 4.5, 5.1};
+const Double_t Module_Size_Z[NofModuleTypes] = {10., 10., 10., 10., 23.9, 23.9, 23.9};
+const Double_t Module_Thick_Alu_X_left       = 1.;
+const Double_t Module_Thick_Alu_X_right      = 0.1;
+const Double_t Module_Thick_Alu_Y            = 0.1;
+const Double_t Module_Thick_Alu_Z            = 0.1;
+
+const Double_t shift_gas_box = (Module_Thick_Alu_X_right - Module_Thick_Alu_X_left) / 2;
+
+// Distance to the center of the TOF wall [cm];
+// for 0m
+/*
+const Double_t InnerWall_Z_PositionShift = -600.;  // inner wall placed at 600
+const Double_t Wall_Z_PositionShift      = -998.;  // outer wall placed at 1000
+*/
+
+// for 6m
+/*
+const Double_t InnerWall_Z_PositionShift = 0.;    // -600.;  // inner wall placed at 600
+const Double_t Wall_Z_PositionShift      = -425.; // -998.;  // outer wall placed at 1000
+*/
+/*
+// for 10 m
+const Double_t InnerWall_Z_PositionShift = 400.;    // -600.;  // inner wall placed at 600
+const Double_t Wall_Z_PositionShift      = -25.; // -998.;  // outer wall placed at 1000
+*/
+
+const Double_t Wall_Z_Position = TOF_Z_Front + 0.5 * Module_Size_Z[0] + 3.5 * Module_Size_Z[1] + 4.5 * Module_Size_Z[2];
+//const Double_t Wall_Z_Position = TOF_Z_Front + 98.5;  // corresponds to center of front module in the inner tower
+//const Double_t Wall_Z_Position = 1050;  // corresponds to center of front module in the inner tower
+//
+// TOF z front = Wall_Z_Position - 0.5 * Module_Size_Z[0]
+//                               - 3.5 * Module_Size_Z[1]
+//                               - 4.5 * Module_Size_Z[2]
+//             = 1050 - 4.0 * 10 - 4.5 * 13 = 951.5 cm
+//
+// TOF z back  = Wall_Z_Position + 1.5 * Module_Size_Z[0]
+//             = 1050 + 1.5 * 10 = 1065
+
+//Type of Counter for module
+const Int_t CounterTypeInModule[NofModuleTypes] = {0, 0, 0, 1, 23, 23, 23};
+const Int_t NCounterInModule[NofModuleTypes]    = {5, 5, 5, 5, 2408, 1512, 4200};
+
+// Placement of the counter inside the module
+const Double_t CounterXStartPosition[NofModuleTypes] = {-60.0, -67.02, -67.02, -67.02, -60.0, -60.0, -16.0};
+const Double_t CounterXDistance[NofModuleTypes]      = {30.0, 30.351, 30.351, 30.351, 30.0, 30.0, 30.0};
+const Double_t CounterZDistance[NofModuleTypes]      = {2.5, 0.0, 0.0, 0.0, 2.5, 2.5, 2.5};
+const Double_t CounterRotationAngle[NofModuleTypes]  = {0., 8.7, 8.7, 8.7, 0., 0., 0.};
+
+// Pole (support structure)
+const Int_t MaxNumberOfPoles = 200;
+Double_t Pole_ZPos[MaxNumberOfPoles];
+Double_t Pole_XPos[MaxNumberOfPoles];
+Double_t Pole_Col[MaxNumberOfPoles];
+Int_t NumberOfPoles = 0;
+
+const Double_t Pole_Size_X      = 8.;
+const Double_t Pole_Size_Y      = 1000.;
+const Double_t PoleShort_Size_Y = 370.;
+const Double_t Pole_Size_Z      = 2.;
+const Double_t Pole_Thick_X     = 0.4;
+const Double_t Pole_Thick_Y     = 0.4;
+const Double_t Pole_Thick_Z     = 0.4;
+const Double_t XLimInner        = 180.;
+
+
+// Bars & frame (support structure)
+const Double_t Frame_Size_X = 20.;
+const Double_t Frame_Size_Y = 20.;
+Double_t Bar_Size_Z         = 100.;
+const Double_t Frame_XLen   = 1400;
+const Double_t Frame_YLen   = Pole_Size_Y + 2. * Frame_Size_Y;
+Double_t Frame_Pos_Z;
+const Double_t Bar_Size_X = 30;
+const Double_t Bar_Size_Y = 20.;
+Double_t Bar_Pos_Z;
+
+const Int_t MaxNumberOfBars = 200;
+Double_t Bar_ZPos[MaxNumberOfBars];
+Double_t Bar_XPos[MaxNumberOfBars];
+Int_t NumberOfBars = 0;
+
+const Double_t ChamberOverlap = 40;
+const Double_t DxColl         = 158.0;  //Module_Size_X-ChamberOverlap;
+//const Double_t Pole_Offset=Module_Size_X/2.+Pole_Size_X/2.;
+const Double_t Pole_Offset = 90.0 + Pole_Size_X / 2.;
+
+// Position for module placement
+const Double_t Inner_Module_First_Y_Position            = 16.;
+const Double_t Inner_Module_Last_Y_Position             = 480.;
+const Double_t Inner_Module_X_Offset                    = 2.;
+const Int_t Inner_Module_NTypes                         = 3;
+const Double_t Inner_Module_Types[Inner_Module_NTypes]  = {4., 5., 6.};
+const Double_t Inner_Module_Number[Inner_Module_NTypes] = {2., 2., 4.};  //V13_3a
+//const Double_t Inner_Module_Number[Inner_Module_NTypes] = {0.,0.,0.}; //debugging
+
+const Double_t InnerSide_Module_X_Offset                    = 51.;
+const Double_t InnerSide_Module_NTypes                      = 1;
+const Double_t InnerSide_Module_Types[Inner_Module_NTypes]  = {5.};
+const Double_t InnerSide_Module_Number[Inner_Module_NTypes] = {2.};  //v13_3a
+//const Double_t InnerSide_Module_Number[Inner_Module_NTypes] = {0.};  //debug
+
+const Double_t Outer_Module_First_Y_Position                              = 0.;
+const Double_t Outer_Module_Last_Y_Position                               = 480.;
+const Double_t Outer_Module_X_Offset                                      = 3.;
+const Int_t Outer_Module_Col                                              = 4;
+const Int_t Outer_Module_NTypes                                           = 2;
+const Double_t Outer_Module_Types[Outer_Module_NTypes][Outer_Module_Col]  = {1., 1., 1., 1., 2., 2., 2., 2.};
+const Double_t Outer_Module_Number[Outer_Module_NTypes][Outer_Module_Col] = {9., 9., 2., 0., 0., 0., 3., 4.};  //V13_3a
+//const Double_t Outer_Module_Number[Outer_Module_NTypes][Outer_Module_Col] = {1.,1.,0.,0.,  0.,0.,0.,0.};//debug
+
+// some global variables
+TGeoManager* gGeoMan = NULL;           // Pointer to TGeoManager instance
+TGeoVolume* gModules[NofModuleTypes];  // Global storage for module types
+TGeoVolume* gCounter[NumberOfDifferentCounterTypes];
+TGeoVolume* gPole;
+TGeoVolume* gPoleShort;
+TGeoVolume* gBar[MaxNumberOfBars];
+
+Double_t Last_Size_Y = 0.;
+Double_t Last_Over_Y = 0.;
+
+// Forward declarations
+void create_materials_from_media_file();
+TGeoVolume* create_counter(Int_t);
+TGeoVolume* create_new_counter(Int_t);
+TGeoVolume* create_tof_module(Int_t);
+TGeoVolume* create_tof_module_m(Int_t);
+TGeoVolume* create_new_tof_module(Int_t);
+TGeoVolume* create_new_tof_module_m(Int_t);
+TGeoVolume* create_tof_pole();
+TGeoVolume* create_tof_poleshort();
+TGeoVolume* create_tof_bar();
+void position_tof_poles(Int_t);
+void position_tof_bars(Int_t);
+void position_inner_tof_modules(Int_t);
+void position_side_tof_modules(Int_t);
+void position_outer_tof_modules(Int_t);
+void position_tof_modules(Int_t);
+void position_tof_modules_m(Int_t, Int_t);
+void dump_info_file();
+void read_module_positions();
+
+void Create_TOF_Geometry_v20c()
+{
+  // Load the necessary FairRoot libraries
+  //  gROOT->LoadMacro("$VMCWORKDIR/gconfig/basiclibs.C");
+  //  basiclibs();
+  //  gSystem->Load("libGeoBase");
+  //  gSystem->Load("libParBase");
+  //  gSystem->Load("libBase");
+
+  // Printout what we are generating
+  std::cout << "Generating geometry " << geoVersion << " at " << TOF_Z_Front << " cm from target." << std::endl
+            << "Inner wall need to be shifted by " << InnerWall_Z_PositionShift << std::endl
+            << "Outer wall need to be shifted by " << Wall_Z_PositionShift << std::endl;
+
+  // read input Data
+  read_module_positions();
+  // Load needed material definition from media.geo file
+  create_materials_from_media_file();
+
+  // Get the GeoManager for later usage
+  gGeoMan = (TGeoManager*) gROOT->FindObject("FAIRGeom");
+  gGeoMan->SetVisLevel(7);  // 2 = super modules
+  gGeoMan->SetVisOption(1);
+
+  // Create the top volume
+  /*
+  TGeoBBox* topbox= new TGeoBBox("", 1000., 1000., 1000.);
+  TGeoVolume* top = new TGeoVolume("top", topbox, gGeoMan->GetMedium("air"));
+  gGeoMan->SetTopVolume(top);
+  */
+
+  TGeoVolume* top = new TGeoVolumeAssembly("TOP");
+  gGeoMan->SetTopVolume(top);
+
+  TGeoTranslation* toftrans = new TGeoTranslation(0., 0., TOF_Z_Corr);
+  TGeoVolume* tof           = new TGeoVolumeAssembly(geoVersion);
+  top->AddNode(tof, 1, toftrans);
+
+  for (Int_t counterType = 0; counterType < NumberOfDifferentCounterTypes; counterType++) {
+    gCounter[counterType] = create_new_counter(counterType);
+  }
+
+  for (Int_t moduleType = 0; moduleType < NofModuleTypes; moduleType++) {
+    gModules[moduleType] = create_new_tof_module(moduleType);
+    gModules[moduleType]->SetVisContainers(1);
+  }
+
+  gPole      = create_tof_pole();
+  gPoleShort = create_tof_poleshort();
+
+  position_tof_modules(3);
+  position_tof_modules_m(4, 6);  // Bucharest modules
+  //position_tof_modules_m(3,3); // Bucharest modules
+  /*
+  position_side_tof_modules(1);  // keep order !!
+  position_inner_tof_modules(3);
+  cout << "Outer Types "<<Outer_Module_Types[0][0]<<", "<<Outer_Module_Types[1][0]
+       <<", col=1:  "<<Outer_Module_Types[0][1]<<", "<<Outer_Module_Types[1][1]
+       <<endl;
+  cout << "Outer Number "<<Outer_Module_Number[0][0]<<", "<<Outer_Module_Number[1][0]
+       <<", col=1:  "<<Outer_Module_Number[0][1]<<", "<<Outer_Module_Number[1][1]
+       <<endl;
+  position_outer_tof_modules(4);
+  */
+  position_tof_poles(0);
+  position_tof_bars(0);
+
+  gGeoMan->CloseGeometry();
+  gGeoMan->CheckOverlaps(0.00001);
+  gGeoMan->PrintOverlaps();
+  gGeoMan->GetListOfOverlaps()->Print();
+
+  gGeoMan->CheckOverlaps(0.00001, "s");
+  gGeoMan->PrintOverlaps();
+  gGeoMan->GetListOfOverlaps()->Print();
+  gGeoMan->Test();
+
+
+  tof->Export(FileNameSim);
+  TFile* outfile = new TFile(FileNameSim, "UPDATE");
+  toftrans->Write();
+  outfile->Close();
+
+  dump_info_file();
+
+  top->SetVisContainers(1);
+  gGeoMan->SetVisLevel(5);
+  //top->Draw("ogl");
+  //top->Draw();
+  //gModules[0]->Draw("ogl");
+  //  gModules[0]->Draw("");
+  gModules[0]->SetVisContainers(1);
+  //  gModules[1]->Draw("");
+  gModules[1]->SetVisContainers(1);
+  //gModules[5]->Draw("");
+  //  top->Raytrace();
+
+  // Printout what we are generating
+  std::cout << "Done generating geometry " << geoVersion << " at " << TOF_Z_Front << " cm from target." << std::endl;
+}
+
+void read_module_positions()
+{
+  //TFile * fPosInput = new TFile( "TOF_10M.dat", "READ");
+  ifstream inFile;
+  inFile.open("TOF_10M.dat");
+  if (!inFile.is_open()) {
+    cout << "<E> cannot open input file " << endl;
+    exit(0);
+  }
+
+  cout << "------------------------------" << endl;
+  cout << "Reading content of TOF_10M.dat" << endl;
+  std::string strdummy;
+  std::getline(inFile, strdummy);
+  cout << strdummy << endl;
+  Int_t iNum;
+  Int_t iX;
+  Int_t iY;
+  Int_t iZ;
+  Char_t cMod;
+  Char_t cPos;
+  Int_t iModType = 0;
+  //while( !inFile.eof()  )
+  //for(Int_t iL=0; iL<2; iL++)
+  while (std::getline(inFile, strdummy)) {
+    //  std::getline(inFile,strdummy);
+    cout << strdummy << endl;
+    stringstream ss;
+    ss << strdummy;
+    ss >> iNum >> iX >> iY >> iZ >> cMod >> cPos;
+    ss << strdummy;
+    //  ss>>iNum>>iX>>iY>>iZ>>cType[0]>>cType[1];
+    Char_t cType[2];
+    cType[0] = cMod;
+    cType[1] = cPos;
+
+    //    cout<<iNum<<" "<<iX<<" "<<iY<<" "<<iZ<<" "<<cMod<<" "<<cPos<<" "<<cType<<endl;
+
+    switch (cMod) {
+      case 'b': iModType = 3; break;
+      case 's':
+        switch (cPos) {
+          case 'l': iModType = 1; break;
+          case 'r': iModType = 2; break;
+        }
+        break;
+      default: cout << " case " << cMod << " not implemented" << endl;
+    }
+    if (cPos == 'm') iModType = 0;
+
+    //cout<<" ModType "<<iModType<<endl;
+    Int_t iMod = NModules[iModType]++;
+    //cout<<" ModType "<<iModType<<", # "<<iMod<<endl;
+
+    xPosMod[iModType][iMod] = (Double_t) iX / 10.;
+    yPosMod[iModType][iMod] = (Double_t) iY / 10.;
+    zPosMod[iModType][iMod] = (Double_t) iZ / 10. + Wall_Z_PositionShift;
+    if (cPos == 'l') { FlipMod[iModType][iMod] = 1.; }
+    else {
+      FlipMod[iModType][iMod] = 0.;
+    }
+    //  if (iModType==1 && iMod==1) return;
+    /*
+  cout<<" ModType "<<iModType<<", Mod "<<iMod<<", x "<<xPosMod[iModType][iMod]<<", y "
+      <<yPosMod[iModType][iMod]<<", z "<<zPosMod[iModType][iMod]<<endl;
+  */
+  }
+  cout << "Data reading finished for " << NModules[0] << " modules of type 0, " << NModules[1] << " of type 1, "
+       << NModules[2] << " of type 2  " << endl;
+}
+void create_materials_from_media_file()
+{
+  // 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();
+
+  FairGeoMedium* air                = geoMedia->getMedium("air");
+  FairGeoMedium* aluminium          = geoMedia->getMedium("aluminium");
+  FairGeoMedium* tof_pole_aluminium = geoMedia->getMedium("tof_pole_aluminium");
+  FairGeoMedium* RPCgas             = geoMedia->getMedium("RPCgas");
+  FairGeoMedium* RPCgas_noact       = geoMedia->getMedium("RPCgas_noact");
+  FairGeoMedium* RPCglass           = geoMedia->getMedium("RPCglass");
+  FairGeoMedium* carbon             = geoMedia->getMedium("carbon");
+
+  // include check if all media are found
+
+  geoBuild->createMedium(air);
+  geoBuild->createMedium(aluminium);
+  geoBuild->createMedium(tof_pole_aluminium);
+  geoBuild->createMedium(RPCgas);
+  geoBuild->createMedium(RPCgas_noact);
+  geoBuild->createMedium(RPCglass);
+  geoBuild->createMedium(carbon);
+}
+
+TGeoVolume* create_counter(Int_t modType)
+{
+
+  //glass
+  Double_t gdx = Glass_X[modType];
+  Double_t gdy = Glass_Y[modType];
+  Double_t gdz = Glass_Z[modType];
+
+  //gas gap
+  Int_t nstrips = NumberOfReadoutStrips[modType];
+  Int_t ngaps   = NumberOfGaps[modType];
+
+
+  Double_t ggdx = GasGap_X[modType];
+  Double_t ggdy = GasGap_Y[modType];
+  Double_t ggdz = GasGap_Z[modType];
+  Double_t gsdx = ggdx / float(nstrips);
+
+  //single stack
+  Double_t dzpos     = gdz + ggdz;
+  Double_t startzpos = SingleStackStartPosition_Z[modType];
+
+  // electronics
+  //pcb dimensions
+  Double_t dxe  = Electronics_X[modType];
+  Double_t dye  = Electronics_Y[modType];
+  Double_t dze  = Electronics_Z[modType];
+  Double_t yele = (gdy + 0.1) / 2. + dye / 2.;
+
+  // needed materials
+  TGeoMedium* glassPlateVolMed  = gGeoMan->GetMedium(GlasMedium);
+  TGeoMedium* noActiveGasVolMed = gGeoMan->GetMedium(NoActivGasMedium);
+  TGeoMedium* activeGasVolMed   = gGeoMan->GetMedium(ActivGasMedium);
+  TGeoMedium* electronicsVolMed = gGeoMan->GetMedium(ElectronicsMedium);
+
+  // Single glass plate
+  TGeoBBox* glass_plate       = new TGeoBBox("", gdx / 2., gdy / 2., gdz / 2.);
+  TGeoVolume* glass_plate_vol = new TGeoVolume("tof_glass", glass_plate, glassPlateVolMed);
+  glass_plate_vol->SetLineColor(kMagenta);  // set line color for the glass plate
+  glass_plate_vol->SetTransparency(20);     // set transparency for the TOF
+  TGeoTranslation* glass_plate_trans = new TGeoTranslation("", 0., 0., 0.);
+
+  // Single gas gap
+  TGeoBBox* gas_gap = new TGeoBBox("", ggdx / 2., ggdy / 2., ggdz / 2.);
+  //TGeoVolume* gas_gap_vol =
+  //new TGeoVolume("tof_gas_gap", gas_gap, noActiveGasVolMed);
+  TGeoVolume* gas_gap_vol = new TGeoVolume("tof_gas_active", gas_gap, activeGasVolMed);
+  gas_gap_vol->Divide("Strip", 1, nstrips, -ggdx / 2., 0);
+
+  gas_gap_vol->SetLineColor(kRed);   // set line color for the gas gap
+  gas_gap_vol->SetTransparency(70);  // set transparency for the TOF
+  TGeoTranslation* gas_gap_trans = new TGeoTranslation("", 0., 0., (gdz + ggdz) / 2.);
+
+
+  // Single subdivided active gas gap
+  /*
+    TGeoBBox* gas_active = new TGeoBBox("", gsdx/2., ggdy/2., ggdz/2.);
+    TGeoVolume* gas_active_vol =
+    new TGeoVolume("tof_gas_active", gas_active, activeGasVolMed);
+  gas_active_vol->SetLineColor(kBlack); // set line color for the gas gap
+  gas_active_vol->SetTransparency(70); // set transparency for the TOF
+  */
+
+  // Add glass plate, inactive gas gap and active gas gaps to a single stack
+  TGeoVolume* single_stack = new TGeoVolumeAssembly("single_stack");
+  single_stack->AddNode(glass_plate_vol, 0, glass_plate_trans);
+  single_stack->AddNode(gas_gap_vol, 0, gas_gap_trans);
+
+  /*
+  for (Int_t l=0; l<nstrips; l++){
+    TGeoTranslation* gas_active_trans
+      = new TGeoTranslation("", -ggdx/2+(l+0.5)*gsdx, 0., 0.);
+    gas_gap_vol->AddNode(gas_active_vol, l, gas_active_trans);
+    //    single_stack->AddNode(gas_active_vol, l, gas_active_trans);
+  }
+  */
+
+  // Add 8 single stacks + one glass plate at the e09.750nd to a multi stack
+  TGeoVolume* multi_stack = new TGeoVolumeAssembly("multi_stack");
+  Int_t l                 = 0;
+  for (l = 0; l < ngaps; l++) {
+    TGeoTranslation* single_stack_trans = new TGeoTranslation("", 0., 0., startzpos + l * dzpos);
+    multi_stack->AddNode(single_stack, l, single_stack_trans);
+  }
+  TGeoTranslation* single_glass_back_trans = new TGeoTranslation("", 0., 0., startzpos + ngaps * dzpos);
+  multi_stack->AddNode(glass_plate_vol, l, single_glass_back_trans);
+
+  // Add electronics above and below the glass stack to build a complete counter
+  TGeoVolume* counter                = new TGeoVolumeAssembly("counter");
+  TGeoTranslation* multi_stack_trans = new TGeoTranslation("", 0., 0., 0.);
+  counter->AddNode(multi_stack, l, multi_stack_trans);
+
+  TGeoBBox* pcb       = new TGeoBBox("", dxe / 2., dye / 2., dze / 2.);
+  TGeoVolume* pcb_vol = new TGeoVolume("pcb", pcb, electronicsVolMed);
+  pcb_vol->SetLineColor(kCyan);  // set line color for the gas gap
+  pcb_vol->SetTransparency(10);  // set transparency for the TOF
+  for (Int_t l = 0; l < 2; l++) {
+    yele *= -1.;
+    TGeoTranslation* pcb_trans = new TGeoTranslation("", 0., yele, 0.);
+    counter->AddNode(pcb_vol, l, pcb_trans);
+  }
+
+  return counter;
+}
+
+TGeoVolume* create_new_counter(Int_t modType)
+{
+
+  //glass
+  Double_t gdx = Glass_X[modType];
+  Double_t gdy = Glass_Y[modType];
+  Double_t gdz = Glass_Z[modType];
+
+  //gas gap
+  Int_t nstrips = NumberOfReadoutStrips[modType];
+  Int_t ngaps   = NumberOfGaps[modType];
+
+
+  Double_t ggdx = GasGap_X[modType];
+  Double_t ggdy = GasGap_Y[modType];
+  Double_t ggdz = GasGap_Z[modType];
+  Double_t gsdx = ggdx / (Double_t)(nstrips);
+
+  // electronics
+  //pcb dimensions
+  Double_t dxe  = Electronics_X[modType];
+  Double_t dye  = Electronics_Y[modType];
+  Double_t dze  = Electronics_Z[modType];
+  Double_t yele = gdy / 2. + dye / 2.;
+
+  // counter size (calculate from glas, gap and electronics sizes)
+  Double_t cdx = TMath::Max(gdx, ggdx);
+  cdx          = TMath::Max(cdx, dxe) + 0.2;
+  Double_t cdy = TMath::Max(gdy, ggdy) + 2 * dye + 0.2;
+  Double_t cdz = ngaps * ggdz + (ngaps + 1) * gdz + 0.2;  // ngaps * (gdz+ggdz) + gdz + 0.2; // ok
+
+  //calculate thickness and first position in counter of single stack
+  Double_t dzpos         = gdz + ggdz;
+  Double_t startzposglas = -ngaps * (gdz + ggdz) / 2.;  // -cdz/2.+0.1+gdz/2.; // ok  // (-cdz+gdz)/2.; // not ok
+  Double_t startzposgas  = startzposglas + gdz / 2. + ggdz / 2.;  // -cdz/2.+0.1+gdz   +ggdz/2.;  // ok
+
+
+  // needed materials
+  TGeoMedium* glassPlateVolMed  = gGeoMan->GetMedium(GlasMedium);
+  TGeoMedium* noActiveGasVolMed = gGeoMan->GetMedium(NoActivGasMedium);
+  TGeoMedium* activeGasVolMed   = gGeoMan->GetMedium(ActivGasMedium);
+  TGeoMedium* electronicsVolMed = gGeoMan->GetMedium(ElectronicsMedium);
+
+
+  // define counter volume
+  TGeoBBox* counter_box = new TGeoBBox("", cdx / 2., cdy / 2., cdz / 2.);
+  TGeoVolume* counter   = new TGeoVolume("counter", counter_box, noActiveGasVolMed);
+  counter->SetLineColor(kCyan);  // set line color for the counter
+  counter->SetTransparency(70);  // set transparency for the TOF
+
+  // define single glass plate volume
+  TGeoBBox* glass_plate       = new TGeoBBox("", gdx / 2., gdy / 2., gdz / 2.);
+  TGeoVolume* glass_plate_vol = new TGeoVolume("tof_glass", glass_plate, glassPlateVolMed);
+  glass_plate_vol->SetLineColor(kMagenta);  // set line color for the glass plate
+  glass_plate_vol->SetTransparency(20);     // set transparency for the TOF
+  // define single gas gap volume
+  TGeoBBox* gas_gap       = new TGeoBBox("", ggdx / 2., ggdy / 2., ggdz / 2.);
+  TGeoVolume* gas_gap_vol = new TGeoVolume("Gap", gas_gap, activeGasVolMed);
+  gas_gap_vol->Divide("Cell", 1, nstrips, -ggdx / 2., 0);
+  gas_gap_vol->SetLineColor(kRed);   // set line color for the gas gap
+  gas_gap_vol->SetTransparency(99);  // set transparency for the TOF
+
+  // place 8 gas gaps and 9 glas plates in the counter
+  for (Int_t igap = 0; igap <= ngaps; igap++) {
+    // place (ngaps+1) glass plates
+    Double_t zpos_glas                 = startzposglas + igap * dzpos;
+    TGeoTranslation* glass_plate_trans = new TGeoTranslation("", 0., 0., zpos_glas);
+    counter->AddNode(glass_plate_vol, igap, glass_plate_trans);
+    // place ngaps gas gaps
+    if (igap < ngaps) {
+      Double_t zpos_gas              = startzposgas + igap * dzpos;
+      TGeoTranslation* gas_gap_trans = new TGeoTranslation("", 0., 0., zpos_gas);
+      counter->AddNode(gas_gap_vol, igap, gas_gap_trans);
+    }
+    //    cout <<"Zpos(Glas): "<< zpos_glas << endl;
+    //    cout <<"Zpos(Gas): "<< zpos_gas << endl;
+  }
+
+  // create and place the electronics above and below the glas stack
+  TGeoBBox* pcb       = new TGeoBBox("", dxe / 2., dye / 2., dze / 2.);
+  TGeoVolume* pcb_vol = new TGeoVolume("pcb", pcb, electronicsVolMed);
+  pcb_vol->SetLineColor(kYellow);  // kCyan); // set line color for electronics
+  pcb_vol->SetTransparency(10);    // set transparency for the TOF
+  for (Int_t l = 0; l < 2; l++) {
+    yele *= -1.;
+    TGeoTranslation* pcb_trans = new TGeoTranslation("", 0., yele, 0.);
+    counter->AddNode(pcb_vol, l, pcb_trans);
+  }
+
+
+  return counter;
+}
+
+TGeoVolume* create_tof_module(Int_t modType)
+{
+  Int_t cType          = CounterTypeInModule[modType];
+  Double_t dx          = Module_Size_X[modType];
+  Double_t dy          = Module_Size_Y[modType];
+  Double_t dz          = Module_Size_Z[modType];
+  Double_t width_aluxl = Module_Thick_Alu_X_left;
+  Double_t width_aluxr = Module_Thick_Alu_X_right;
+  Double_t width_aluy  = Module_Thick_Alu_Y;
+  Double_t width_aluz  = Module_Thick_Alu_Z;
+
+
+  Double_t dxpos     = CounterXDistance[modType];
+  Double_t startxpos = CounterXStartPosition[modType];
+  Double_t dzoff     = CounterZDistance[modType];
+  Double_t rotangle  = CounterRotationAngle[modType];
+
+  TGeoMedium* boxVolMed         = gGeoMan->GetMedium(BoxVolumeMedium);
+  TGeoMedium* noActiveGasVolMed = gGeoMan->GetMedium(NoActivGasMedium);
+
+  TString moduleName = Form("module_%d", modType);
+  TGeoVolume* module = new TGeoVolumeAssembly(moduleName);
+
+  TGeoBBox* alu_box       = new TGeoBBox("", dx / 2., dy / 2., dz / 2.);
+  TGeoVolume* alu_box_vol = new TGeoVolume("alu_box", alu_box, boxVolMed);
+  alu_box_vol->SetLineColor(kGreen);  // set line color for the alu box
+  alu_box_vol->SetTransparency(20);   // set transparency for the TOF
+  TGeoTranslation* alu_box_trans = new TGeoTranslation("", 0., 0., 0.);
+  module->AddNode(alu_box_vol, 0, alu_box_trans);
+
+  TGeoBBox* gas_box =
+    new TGeoBBox("", (dx - (width_aluxl + width_aluxr)) / 2., (dy - 2 * width_aluy) / 2., (dz - 2 * width_aluz) / 2.);
+  TGeoVolume* gas_box_vol = new TGeoVolume("gas_box", gas_box, noActiveGasVolMed);
+  gas_box_vol->SetLineColor(kYellow);  // set line color for the gas box
+  gas_box_vol->SetTransparency(70);    // set transparency for the TOF
+  TGeoTranslation* gas_box_trans = new TGeoTranslation("", shift_gas_box, 0., 0.);
+  alu_box_vol->AddNode(gas_box_vol, 0, gas_box_trans);
+
+  for (Int_t j = 0; j < 5; j++) {  //loop over counters (modules)
+    Double_t zpos;
+    if (0 == modType) { zpos = dzoff *= -1; }
+    else {
+      zpos = 0.;
+    }
+    TGeoTranslation* counter_trans = new TGeoTranslation("", startxpos + j * dxpos, 0.0, zpos);
+
+    TGeoRotation* counter_rot = new TGeoRotation();
+    counter_rot->RotateY(rotangle);
+    TGeoCombiTrans* counter_combi_trans = new TGeoCombiTrans(*counter_trans, *counter_rot);
+    gas_box_vol->AddNode(gCounter[cType], j, counter_combi_trans);
+  }
+
+  return module;
+}
+
+TGeoVolume* create_new_tof_module(Int_t modType)
+{
+  if (modType > 3) return create_new_tof_module_m(modType);  // Bucharest modules
+
+  Int_t cType          = CounterTypeInModule[modType];
+  Double_t dx          = Module_Size_X[modType];
+  Double_t dy          = Module_Size_Y[modType];
+  Double_t dz          = Module_Size_Z[modType];
+  Double_t width_aluxl = Module_Thick_Alu_X_left;
+  Double_t width_aluxr = Module_Thick_Alu_X_right;
+  Double_t width_aluy  = Module_Thick_Alu_Y;
+  Double_t width_aluz  = Module_Thick_Alu_Z;
+
+  Double_t dxpos     = CounterXDistance[modType];
+  Double_t startxpos = CounterXStartPosition[modType];
+  Double_t dzoff     = CounterZDistance[modType];
+  Double_t rotangle  = CounterRotationAngle[modType];
+
+  TGeoMedium* boxVolMed         = gGeoMan->GetMedium(BoxVolumeMedium);
+  TGeoMedium* noActiveGasVolMed = gGeoMan->GetMedium(NoActivGasMedium);
+
+  TString moduleName = Form("module_%d", modType);
+
+  TGeoBBox* module_box = new TGeoBBox("", dx / 2., dy / 2., dz / 2.);
+  TGeoVolume* module   = new TGeoVolume(moduleName, module_box, boxVolMed);
+  module->SetLineColor(kGreen);  // set line color for the alu box
+  module->SetTransparency(20);   // set transparency for the TOF
+
+  TGeoBBox* gas_box =
+    new TGeoBBox("", (dx - (width_aluxl + width_aluxr)) / 2., (dy - 2 * width_aluy) / 2., (dz - 2 * width_aluz) / 2.);
+  TGeoVolume* gas_box_vol = new TGeoVolume("gas_box", gas_box, noActiveGasVolMed);
+  gas_box_vol->SetLineColor(kBlue);  // set line color for the alu box
+  gas_box_vol->SetTransparency(50);  // set transparency for the TOF
+  TGeoTranslation* gas_box_trans = new TGeoTranslation("", shift_gas_box, 0., 0.);
+  module->AddNode(gas_box_vol, 0, gas_box_trans);
+
+  for (Int_t j = 0; j < NCounterInModule[modType]; j++) {  //loop over counters (modules)
+    Double_t zpos;
+    if (0 == modType || 3 == modType || 4 == modType || 5 == modType) { zpos = dzoff *= -1; }
+    else {
+      zpos = 0.;
+    }
+    TGeoTranslation* counter_trans = new TGeoTranslation("", startxpos + j * dxpos, 0.0, zpos);
+
+    TGeoRotation* counter_rot = new TGeoRotation();
+    counter_rot->RotateY(rotangle);
+    TGeoCombiTrans* counter_combi_trans = new TGeoCombiTrans(*counter_trans, *counter_rot);
+    gas_box_vol->AddNode(gCounter[cType], j, counter_combi_trans);
+  }
+
+  return module;
+}
+
+
+TGeoVolume* create_new_tof_module_m(Int_t modType)
+{
+  Int_t cType2 = CounterTypeInModule[modType] % 10;
+  Int_t cType1 = (CounterTypeInModule[modType] - cType2) / 10;
+
+  Int_t iNum2 = NCounterInModule[modType] % 100;
+  Int_t iNum1 = (NCounterInModule[modType] - iNum2) / 100;
+
+  Int_t jm         = modType - 4;
+  const Int_t iNum = iNum1 + iNum2;
+
+  cout << " module_m: " << modType << ", " << jm << ": " << iNum1 << " counters type " << cType1 << ", " << iNum2
+       << " type " << cType2 << endl;
+
+  Double_t dx          = Module_Size_X[modType];
+  Double_t dy          = Module_Size_Y[modType];
+  Double_t dz          = Module_Size_Z[modType];
+  Double_t width_aluxl = Module_Thick_Alu_X_left;
+  Double_t width_aluxr = Module_Thick_Alu_X_right;
+  Double_t width_aluy  = Module_Thick_Alu_Y;
+  Double_t width_aluz  = Module_Thick_Alu_Z;
+
+  Double_t dxpos     = CounterXDistance[modType];
+  Double_t startxpos = CounterXStartPosition[modType];
+  Double_t dzoff     = CounterZDistance[modType];
+  Double_t rotangle  = CounterRotationAngle[modType];
+
+  TGeoMedium* boxVolMed         = gGeoMan->GetMedium(BoxVolumeMedium);
+  TGeoMedium* noActiveGasVolMed = gGeoMan->GetMedium(NoActivGasMedium);
+
+  TString moduleName = Form("module_%d", modType);
+
+  TGeoBBox* module_box = new TGeoBBox("", dx / 2., dy / 2., dz / 2.);
+  TGeoVolume* module   = new TGeoVolume(moduleName, module_box, boxVolMed);
+  module->SetLineColor(kGreen);  // set line color for the alu box
+  module->SetTransparency(20);   // set transparency for the TOF
+
+  TGeoBBox* gas_box =
+    new TGeoBBox("", (dx - (width_aluxl + width_aluxr)) / 2., (dy - 2 * width_aluy) / 2., (dz - 2 * width_aluz) / 2.);
+  TGeoVolume* gas_box_vol = new TGeoVolume("gas_box", gas_box, noActiveGasVolMed);
+  gas_box_vol->SetLineColor(kBlue);  // set line color for the alu box
+  gas_box_vol->SetTransparency(50);  // set transparency for the TOF
+  TGeoTranslation* gas_box_trans = new TGeoTranslation("", shift_gas_box, 0., 0.);
+  module->AddNode(gas_box_vol, 0, gas_box_trans);
+  Double_t xpos;
+  Double_t ypos;
+  Double_t zpos;
+  Int_t ii = 0;
+  for (Int_t j = 0; j < iNum1; j++) {  //loop over counters (in modules)
+    Int_t iX  = (j - j % NCounter1Y[jm]) / NCounter1Y[jm];
+    Int_t iY  = j % NCounter1Y[jm];
+    Int_t iX2 = iX % 2;
+    Int_t iY2 = iY % 2;
+    //    cout << "Put counter "<<j<<", jm: "<<jm<<", iX "<<iX<<", iY "<<iY<<", iX2 "<<iX2<<endl;
+    /*
+    Double_t xpos = CounterXstart1[jm] + iX*CounterDxpos1[jm];
+    Double_t ypos = CounterYstart1[jm] + iY*CounterDypos1[jm];
+    Double_t zpos = CounterDyoff1[jm][iY2]+CounterDzoff1[jm][iX2];
+    */
+
+    switch (jm) {
+      case 0:
+        xpos = xPosCounter1[ii];
+        ypos = yPosCounter1[ii];
+        zpos = zPosCounter1[ii];
+        break;
+      case 1:
+        xpos = xPosCounter2[ii];
+        ypos = yPosCounter2[ii];
+        zpos = zPosCounter2[ii];
+        break;
+      case 2:
+        xpos = xPosCounter3[ii];
+        ypos = yPosCounter3[ii];
+        zpos = zPosCounter3[ii];
+        break;
+    }
+
+    cout << "Place counter " << j << " " << ii << ", iX " << iX << ", iY " << iY << " at " << xpos << ", " << ypos
+         << ", " << zpos << endl;
+
+    TGeoTranslation* counter_trans = new TGeoTranslation("", xpos, ypos, zpos);
+    TGeoRotation* counter_rot      = new TGeoRotation();
+    counter_rot->RotateY(rotangle);
+    TGeoCombiTrans* counter_combi_trans = new TGeoCombiTrans(*counter_trans, *counter_rot);
+    gas_box_vol->AddNode(gCounter[cType1], j, counter_combi_trans);
+    ii++;
+  }
+
+  for (Int_t j = 0; j < iNum2; j++) {  //loop over counters (in modules)
+    Int_t iX  = (j - j % NCounter2Y[jm]) / NCounter2Y[jm];
+    Int_t iY  = j % NCounter2Y[jm];
+    Int_t iX2 = iX % 2;
+    Int_t iY2 = iY % 2;
+    cout << "Put counter type 2 j=" << j << ", jm: " << jm << ", iX " << iX << ", iY " << iY << ", iX2 " << iX2 << endl;
+    /*
+    Double_t xpos = CounterXstart2[jm] + iX*CounterDxpos2[jm];
+    Double_t ypos = CounterYstart2[jm] + iY*CounterDypos2[jm];
+    Double_t zpos = CounterDyoff2[jm][iY2]+CounterDzoff2[jm][iX2];
+    */
+
+    switch (jm) {
+      case 0:
+        xpos = xPosCounter1[ii];
+        ypos = yPosCounter1[ii];
+        zpos = zPosCounter1[ii];
+        break;
+      case 1:
+        xpos = xPosCounter2[ii];
+        ypos = yPosCounter2[ii];
+        zpos = zPosCounter2[ii];
+        break;
+      case 2:
+        xpos = xPosCounter3[ii];
+        ypos = yPosCounter3[ii];
+        zpos = zPosCounter3[ii];
+        break;
+    }
+
+
+    cout << "Place counter " << j << ", iX " << iX << ", iY " << iY << " at " << xpos << ", " << ypos << ", " << zpos
+         << endl;
+    TGeoTranslation* counter_trans = new TGeoTranslation("", xpos, ypos, zpos);
+    TGeoRotation* counter_rot      = new TGeoRotation();
+    counter_rot->RotateY(rotangle);
+    TGeoCombiTrans* counter_combi_trans = new TGeoCombiTrans(*counter_trans, *counter_rot);
+    gas_box_vol->AddNode(gCounter[cType2], j + iNum1, counter_combi_trans);
+    ii++;
+  }
+
+  return module;
+}
+
+
+TGeoVolume* create_tof_pole()
+{
+  // needed materials
+  TGeoMedium* boxVolMed = gGeoMan->GetMedium(PoleVolumeMedium);
+  TGeoMedium* airVolMed = gGeoMan->GetMedium(KeepingVolumeMedium);
+
+  Double_t dx         = Pole_Size_X;
+  Double_t dy         = Pole_Size_Y;
+  Double_t dz         = Pole_Size_Z;
+  Double_t width_alux = Pole_Thick_X;
+  Double_t width_aluy = Pole_Thick_Y;
+  Double_t width_aluz = Pole_Thick_Z;
+
+  TGeoVolume* pole         = new TGeoVolumeAssembly("Pole");
+  TGeoBBox* pole_alu_box   = new TGeoBBox("", dx / 2., dy / 2., dz / 2.);
+  TGeoVolume* pole_alu_vol = new TGeoVolume("pole_alu", pole_alu_box, boxVolMed);
+  pole_alu_vol->SetLineColor(kGreen);  // set line color for the alu box
+  //  pole_alu_vol->SetTransparency(20); // set transparency for the TOF
+  TGeoTranslation* pole_alu_trans = new TGeoTranslation("", 0., 0., 0.);
+  pole->AddNode(pole_alu_vol, 0, pole_alu_trans);
+
+  Double_t air_dx = dx / 2. - width_alux;
+  Double_t air_dy = dy / 2. - width_aluy;
+  Double_t air_dz = dz / 2. - width_aluz;
+
+  //  cout << "My pole." << endl;
+  if (air_dx <= 0.) cout << "ERROR - No air volume in pole X, size: " << air_dx << endl;
+  if (air_dy <= 0.) cout << "ERROR - No air volume in pole Y, size: " << air_dy << endl;
+  if (air_dz <= 0.) cout << "ERROR - No air volume in pole Z, size: " << air_dz << endl;
+
+  if ((air_dx > 0.) && (air_dy > 0.) && (air_dz > 0.))  // crate air volume only, if larger than zero
+  {
+    TGeoBBox* pole_air_box = new TGeoBBox("", air_dx, air_dy, air_dz);
+    //  TGeoBBox* pole_air_box = new TGeoBBox("", dx/2.-width_alux, dy/2.-width_aluy, dz/2.-width_aluz);
+    TGeoVolume* pole_air_vol = new TGeoVolume("pole_air", pole_air_box, airVolMed);
+    pole_air_vol->SetLineColor(kYellow);  // set line color for the alu box
+    pole_air_vol->SetTransparency(70);    // set transparency for the TOF
+    TGeoTranslation* pole_air_trans = new TGeoTranslation("", 0., 0., 0.);
+    pole_alu_vol->AddNode(pole_air_vol, 0, pole_air_trans);
+  }
+  else
+    cout << "Skipping pole_air_vol, no thickness: " << air_dx << " " << air_dy << " " << air_dz << endl;
+
+  return pole;
+}
+
+TGeoVolume* create_tof_poleshort()
+{
+  // needed materials
+  TGeoMedium* boxVolMed = gGeoMan->GetMedium(PoleVolumeMedium);
+  TGeoMedium* airVolMed = gGeoMan->GetMedium(KeepingVolumeMedium);
+
+  Double_t dx         = Pole_Size_X;
+  Double_t dy         = PoleShort_Size_Y;
+  Double_t dz         = Pole_Size_Z;
+  Double_t width_alux = Pole_Thick_X;
+  Double_t width_aluy = Pole_Thick_Y;
+  Double_t width_aluz = Pole_Thick_Z;
+
+  TGeoVolume* pole         = new TGeoVolumeAssembly("PoleShort");
+  TGeoBBox* pole_alu_box   = new TGeoBBox("", dx / 2., dy / 2., dz / 2.);
+  TGeoVolume* pole_alu_vol = new TGeoVolume("poleshort_alu", pole_alu_box, boxVolMed);
+  pole_alu_vol->SetLineColor(kGreen);  // set line color for the alu box
+  //  pole_alu_vol->SetTransparency(20); // set transparency for the TOF
+  TGeoTranslation* pole_alu_trans = new TGeoTranslation("", 0., 0., 0.);
+  pole->AddNode(pole_alu_vol, 0, pole_alu_trans);
+
+  Double_t air_dx = dx / 2. - width_alux;
+  Double_t air_dy = dy / 2. - width_aluy;
+  Double_t air_dz = dz / 2. - width_aluz;
+  //  cout << "My pole." << endl;
+  if (air_dx <= 0.) cout << "ERROR - No air volume in pole X, size: " << air_dx << endl;
+  if (air_dy <= 0.) cout << "ERROR - No air volume in pole Y, size: " << air_dy << endl;
+  if (air_dz <= 0.) cout << "ERROR - No air volume in pole Z, size: " << air_dz << endl;
+
+  if ((air_dx > 0.) && (air_dy > 0.) && (air_dz > 0.))  // crate air volume only, if larger than zero
+  {
+    TGeoBBox* pole_air_box = new TGeoBBox("", air_dx, air_dy, air_dz);
+    //  TGeoBBox* pole_air_box = new TGeoBBox("", dx/2.-width_alux, dy/2.-width_aluy, dz/2.-width_aluz);
+    TGeoVolume* pole_air_vol = new TGeoVolume("poleshort_air", pole_air_box, airVolMed);
+    pole_air_vol->SetLineColor(kYellow);  // set line color for the alu box
+    pole_air_vol->SetTransparency(70);    // set transparency for the TOF
+    TGeoTranslation* pole_air_trans = new TGeoTranslation("", 0., 0., 0.);
+    pole_alu_vol->AddNode(pole_air_vol, 0, pole_air_trans);
+  }
+  else
+    cout << "Skipping pole_air_vol, no thickness: " << air_dx << " " << air_dy << " " << air_dz << endl;
+
+  return pole;
+}
+
+
+TGeoVolume* create_tof_bar(Double_t dx, Double_t dy, Double_t dz)
+{
+  // needed materials
+  TGeoMedium* boxVolMed = gGeoMan->GetMedium(PoleVolumeMedium);
+  TGeoMedium* airVolMed = gGeoMan->GetMedium(KeepingVolumeMedium);
+
+  Double_t width_alux = Pole_Thick_X;
+  Double_t width_aluy = Pole_Thick_Y;
+  Double_t width_aluz = Pole_Thick_Z;
+
+  TGeoVolume* bar         = new TGeoVolumeAssembly("Bar");
+  TGeoBBox* bar_alu_box   = new TGeoBBox("", dx / 2., dy / 2., dz / 2.);
+  TGeoVolume* bar_alu_vol = new TGeoVolume("bar_alu", bar_alu_box, boxVolMed);
+  bar_alu_vol->SetLineColor(kGreen);  // set line color for the alu box
+  //  bar_alu_vol->SetTransparency(20); // set transparency for the TOF
+  TGeoTranslation* bar_alu_trans = new TGeoTranslation("", 0., 0., 0.);
+  bar->AddNode(bar_alu_vol, 0, bar_alu_trans);
+
+  TGeoBBox* bar_air_box   = new TGeoBBox("", dx / 2. - width_alux, dy / 2. - width_aluy, dz / 2. - width_aluz);
+  TGeoVolume* bar_air_vol = new TGeoVolume("bar_air", bar_air_box, airVolMed);
+  bar_air_vol->SetLineColor(kYellow);  // set line color for the alu box
+  bar_air_vol->SetTransparency(70);    // set transparency for the TOF
+  TGeoTranslation* bar_air_trans = new TGeoTranslation("", 0., 0., 0.);
+  bar_alu_vol->AddNode(bar_air_vol, 0, bar_air_trans);
+
+  return bar;
+}
+
+void position_tof_poles(Int_t modType)
+{
+
+  TGeoTranslation* pole_trans = NULL;
+
+  Int_t numPoles      = 0;
+  Int_t numPolesShort = 0;
+  for (Int_t i = 0; i < NumberOfPoles; i++) {
+
+    Double_t xPos = Pole_XPos[i];
+    Double_t zPos = Pole_ZPos[i];
+    if (TMath::Abs(xPos) > XLimInner) {
+      pole_trans = new TGeoTranslation("", xPos, 0., zPos);
+      gGeoMan->GetVolume(geoVersion)->AddNode(gPole, numPoles, pole_trans);
+      numPoles++;
+    }
+    else {  // position 2 short poles
+
+      // upper short poles
+      pole_trans = new TGeoTranslation("", xPos, Pole_Size_Y / 2. - PoleShort_Size_Y / 2., zPos);
+      gGeoMan->GetVolume(geoVersion)->AddNode(gPoleShort, numPolesShort, pole_trans);
+      numPolesShort++;
+
+      // lower short poles
+      pole_trans = new TGeoTranslation("", xPos, PoleShort_Size_Y / 2. - Pole_Size_Y / 2., zPos);
+      gGeoMan->GetVolume(geoVersion)->AddNode(gPoleShort, numPolesShort, pole_trans);
+      numPolesShort++;
+    }
+    //     cout << " Position Pole "<< numPoles<<" at z="<< Pole_ZPos[i] <<", x "<<Pole_XPos[i]<< endl;
+  }
+}
+
+void position_tof_bars(Int_t modType)
+{
+
+  TGeoTranslation* bar_trans = NULL;
+
+  Int_t numBars = 0;
+  Int_t i       = 0;
+  for (i = 0; i < NumberOfBars; i++) {
+
+    Double_t xPos = Bar_XPos[i];
+    Double_t zPos = Bar_ZPos[i];
+    Double_t yPos = Pole_Size_Y / 2. + Bar_Size_Y / 2.;
+
+    bar_trans = new TGeoTranslation("", xPos, yPos, zPos);
+    gGeoMan->GetVolume(geoVersion)->AddNode(gBar[i], numBars, bar_trans);
+    numBars++;
+
+    bar_trans = new TGeoTranslation("", xPos, -yPos, zPos);
+    gGeoMan->GetVolume(geoVersion)->AddNode(gBar[i], numBars, bar_trans);
+    numBars++;
+
+    bar_trans = new TGeoTranslation("", -xPos, yPos, zPos);
+    gGeoMan->GetVolume(geoVersion)->AddNode(gBar[i], numBars, bar_trans);
+    numBars++;
+
+    bar_trans = new TGeoTranslation("", -xPos, -yPos, zPos);
+    gGeoMan->GetVolume(geoVersion)->AddNode(gBar[i], numBars, bar_trans);
+    numBars++;
+  }
+  cout << " Position Bar " << numBars << " at z=" << Bar_ZPos[i] << endl;
+
+  // outer horizontal and vertical frame bars
+
+  NumberOfBars++;
+  i                = NumberOfBars;
+  gBar[i]          = create_tof_bar(Frame_XLen, Frame_Size_Y, Frame_Size_Y);  // Outer frame big bar along X
+  int j            = i + 1;
+  gBar[j]          = create_tof_bar(Frame_Size_X, Frame_YLen, Frame_Size_Y);  // Outer frame big bar along Y
+  Double_t numBarY = 0;
+  numBars          = 0;
+
+  for (Double_t dZ = -1.; dZ < 2.; dZ += 2.) {
+    Double_t zPos = Frame_Pos_Z - dZ * Bar_Size_Z / 2.;
+    //    Double_t yPos = Pole_Size_Y/2.+1.5*Bar_Size_Y;
+    Double_t yPos = Frame_YLen / 2. + Frame_Size_Y / 2;  // Make outer frame independent of the inner poles!!!!
+
+    // Outer Frame Top bar
+    bar_trans = new TGeoTranslation("", 0., yPos, zPos);
+    gGeoMan->GetVolume(geoVersion)->AddNode(gBar[i], numBars, bar_trans);
+    numBars++;
+
+    // Outer Frame Bottom bar
+    bar_trans = new TGeoTranslation("", 0., -yPos, zPos);
+    gGeoMan->GetVolume(geoVersion)->AddNode(gBar[i], numBars, bar_trans);
+    numBars++;
+
+    // Outer Frame Right bar
+    Double_t xPos = Frame_XLen / 2 - Frame_Size_Y / 2.;
+    bar_trans     = new TGeoTranslation("", xPos, 0., zPos);
+    gGeoMan->GetVolume(geoVersion)->AddNode(gBar[j], numBarY, bar_trans);
+    numBarY++;
+
+    // Outer Frame Left bar
+    bar_trans = new TGeoTranslation("", -xPos, 0., zPos);
+    gGeoMan->GetVolume(geoVersion)->AddNode(gBar[j], numBarY, bar_trans);
+    numBarY++;
+  }
+}
+
+void position_inner_tof_modules(Int_t modNType)
+{
+  TGeoTranslation* module_trans = NULL;
+
+  //  Int_t numModules=(Int_t)( (Inner_Module_Last_Y_Position-Inner_Module_First_Y_Position)/Module_Size_Y[modType])+1;
+  Double_t yPos = Inner_Module_First_Y_Position;
+  Int_t ii      = 0;
+  Double_t xPos = Inner_Module_X_Offset;
+  Double_t zPos = Wall_Z_Position;
+
+  Pole_ZPos[NumberOfPoles] = zPos;
+  Pole_Col[NumberOfPoles]  = 0;
+  NumberOfPoles++;
+
+  Double_t DzPos = 0.;
+  for (Int_t j = 0; j < modNType; j++) {
+    if (Module_Size_Z[j] > DzPos) { DzPos = Module_Size_Z[j]; }
+  }
+  Pole_ZPos[NumberOfPoles] = zPos + DzPos;
+  Pole_Col[NumberOfPoles]  = 0;
+  NumberOfPoles++;
+
+  for (Int_t j = 0; j < modNType; j++) {
+    Int_t modType = Inner_Module_Types[j];
+    Int_t modNum  = 0;
+    for (Int_t i = 0; i < Inner_Module_Number[j]; i++) {
+      ii++;
+      cout << "Inner ii " << ii << " Last " << Last_Size_Y << "," << Last_Over_Y << endl;
+      Double_t DeltaY = Module_Size_Y[modType] + Last_Size_Y - 2. * (Module_Over_Y[modType] + Last_Over_Y);
+      yPos += DeltaY;
+      Last_Size_Y = Module_Size_Y[modType];
+      Last_Over_Y = Module_Over_Y[modType];
+      cout << "Position Inner Module " << i << " of " << Inner_Module_Number[j] << " Type " << modType
+           << " at Y = " << yPos << " Ysize = " << Module_Size_Y[modType] << " DeltaY = " << DeltaY << endl;
+
+      module_trans = new TGeoTranslation("", xPos, yPos, zPos);
+      gGeoMan->GetVolume(geoVersion)->AddNode(gModules[modType], modNum, module_trans);
+      modNum++;
+      module_trans = new TGeoTranslation("", xPos, -yPos, zPos);
+      gGeoMan->GetVolume(geoVersion)->AddNode(gModules[modType], modNum, module_trans);
+      modNum++;
+      if (ii > 0) {
+        module_trans = new TGeoTranslation("", xPos, yPos - DeltaY / 2, zPos + Module_Size_Z[modType]);
+        gGeoMan->GetVolume(geoVersion)->AddNode(gModules[modType], modNum, module_trans);
+        modNum++;
+        module_trans = new TGeoTranslation("", xPos, -(yPos - DeltaY / 2), zPos + Module_Size_Z[modType]);
+        gGeoMan->GetVolume(geoVersion)->AddNode(gModules[modType], modNum, module_trans);
+        modNum++;
+      }
+    }
+  }
+}
+
+void position_tof_modules_m(Int_t ModType1, Int_t ModType2)
+{
+
+  TGeoTranslation* module_trans = NULL;
+  TGeoRotation* module_rot0     = new TGeoRotation();
+  module_rot0->RotateZ(0.);
+  TGeoRotation* module_rot1 = new TGeoRotation();
+  module_rot1->RotateZ(180.);
+  TGeoCombiTrans* module_combi_trans = NULL;
+
+  NModules[4] = 2;  //M1
+  NModules[5] = 2;  //M2
+  NModules[6] = 4;  //M3
+
+  Int_t ii = 0;
+  for (Int_t j = ModType1; j < ModType2 + 1; j++) {
+    Int_t modType = j;
+    Int_t jm      = j - 4;
+    Int_t modNum  = 0;
+    Double_t SignZ;
+    //  if(modType != 0) continue; // debugging
+    for (Int_t i = 0; i < NModules[j]; i++) {
+      //if(i != 0) continue; // debugging
+      ii++;
+      Double_t xPos = xPosModm[jm][i];
+      Double_t yPos = yPosModm[jm][i];
+      Double_t zPos = zPosModm[jm][i] + InnerWall_Z_PositionShift;
+      cout << "Place Mod " << i << " of Type " << j << " at x " << xPos << ", y " << yPos << ", z " << zPos << ", Flip "
+           << FlipModm[jm][i] << endl;
+
+      module_trans = new TGeoTranslation("", xPos, yPos, zPos);
+      if (FlipModm[jm][i] == 180.) { module_combi_trans = new TGeoCombiTrans(*module_trans, *module_rot1); }
+      else {
+        module_combi_trans = new TGeoCombiTrans(*module_trans, *module_rot0);
+      }
+      gGeoMan->GetVolume(geoVersion)->AddNode(gModules[modType], modNum, module_combi_trans);
+      modNum++;
+    }
+  }
+}
+
+void position_tof_modules(Int_t NModTypes)
+{
+  TGeoTranslation* module_trans = NULL;
+  TGeoRotation* module_rot0     = new TGeoRotation();
+  module_rot0->RotateZ(0.);
+  TGeoRotation* module_rot1 = new TGeoRotation();
+  module_rot1->RotateZ(180.);
+  TGeoCombiTrans* module_combi_trans = NULL;
+  const Int_t MaxLayer               = 20;
+  Int_t NLayer                       = 0;
+  Double_t zPosLayer[MaxLayer]       = {0.};
+  const Int_t MaxCol                 = 100;
+  Int_t NCol                         = 0;
+  Double_t xPosCol[MaxCol]           = {0.};
+  const Double_t zAcc                = 0.1;
+  const Double_t xAcc                = 2.;
+
+  Int_t ii     = 0;
+  Int_t modNum = 0;
+  for (Int_t j = 0; j < NModTypes + 1; j++) {
+    Int_t modType = j;
+    modNum        = 0;
+    Double_t SignZ;
+    //  if(modType != 0) continue; // debugging
+    for (Int_t i = 0; i < NModules[j]; i++) {
+      //if(i != 0) continue; // debugging
+      ii++;
+      Double_t xPos = xPosMod[j][i] - shift_gas_box;
+      Double_t yPos = yPosMod[j][i];
+      Double_t zPos = zPosMod[j][i];
+      //cout<<"Place Mod Type "<<j<<" at x "<<xPos<<", y "<<yPos<<", z "<<zPos<<", Flip "<<FlipMod[j][i]<<endl;
+
+      module_trans = new TGeoTranslation("", xPos, yPos, zPos);
+      if (FlipMod[j][i] == 1) { module_combi_trans = new TGeoCombiTrans(*module_trans, *module_rot1); }
+      else {
+        module_combi_trans = new TGeoCombiTrans(*module_trans, *module_rot0);
+      }
+      gGeoMan->GetVolume(geoVersion)->AddNode(gModules[modType], modNum, module_combi_trans);
+      modNum++;
+
+      // add structural material
+
+      Bool_t BPexist = kFALSE;
+      Double_t SignX;
+      if (xPosMod[j][i] != 0.) { SignX = xPos / TMath::Abs(xPos); }
+      else {
+        SignX = 1.;
+      }
+
+      Int_t iLz = -1;
+      for (Int_t iL = 0; iL < NLayer; iL++) {
+        if (zPos == zPosLayer[iL]) {
+          iLz = iL;
+          break;
+        }
+      }
+      if (iLz == -1) {
+        zPosLayer[NLayer] = zPos;
+        iLz               = NLayer;
+        //	cout <<"Add zLayer "<<NLayer<<" at z="<<zPos<<" from ModType "<<j<<", Module "<<i<<endl;
+        NLayer++;
+      }
+      if (iLz % 2) { SignZ = 1; }
+      else {
+        SignZ = -1;
+      }
+      switch (iLz) {  // fix inconsistencies with above
+        case 6: SignZ = 1; break;
+        case 7: SignZ = -1; break;
+        default:
+          //      cout << " default SignZ as iLz is " << iLz << endl;
+          break;
+      }
+
+      Double_t zPosPole = zPos + (Module_Size_Z[j] / 2. + Pole_Size_Z / 2.) * SignZ;
+      Double_t xPosPole = xPos + (Module_Size_X[j] / 2.) * SignX;
+
+      Int_t iCx = -1;
+      for (Int_t iC = 0; iC < NCol; iC++) {
+        if (TMath::Abs(xPosPole - xPosCol[iC]) < xAcc) {
+          iCx = iC;
+          break;
+        }
+      }
+      if (iCx == -1) {
+        xPosCol[NCol] = xPosPole;
+        iCx           = NCol;
+        //	cout <<"Add xCol "<<NCol<<" at x="<<xPos<<" from ModType "<<j<<", Module "<<i<<endl;
+        NCol++;
+
+        xPosCol[NCol] = xPos - (Module_Size_X[j] / 2.) * SignX;
+        iCx           = NCol;
+        //	cout <<"Add xCol "<<NCol<<" at x="<<xPos<<" from ModType "<<j<<", Module "<<i<<endl;
+        NCol++;
+      }
+
+      for (Int_t iP = 0; iP < NumberOfPoles; iP++) {
+        if (TMath::Abs(zPosPole - Pole_ZPos[iP]) < Pole_Size_Z && TMath::Abs(xPosPole - Pole_XPos[iP]) < Pole_Size_X) {
+          BPexist = kTRUE;
+          break;
+        }
+      }
+
+      if (!BPexist) {
+        Pole_ZPos[NumberOfPoles] = zPosPole;
+        Pole_XPos[NumberOfPoles] = xPosPole;
+        Pole_Col[NumberOfPoles]  = 0;
+        NumberOfPoles++;
+
+        Pole_ZPos[NumberOfPoles] = zPosPole;
+        Pole_XPos[NumberOfPoles] = xPos - (Module_Size_X[j] / 2.) * SignX;
+        Pole_Col[NumberOfPoles]  = 0;
+        NumberOfPoles++;
+
+        if (xPosMod[j][i] != 0.) {
+          for (int iP = 0; iP < 2; iP++) {
+            Int_t iLast              = NumberOfPoles - 2;
+            Pole_ZPos[NumberOfPoles] = Pole_ZPos[iLast];
+            Pole_XPos[NumberOfPoles] = -Pole_XPos[iLast];
+            Pole_Col[NumberOfPoles]  = 0;
+            NumberOfPoles++;
+          }
+        }
+        /*
+      cout << " Add pole "<< NumberOfPoles <<" at z = "<<zPos<<", "<<zPos<<", x = "<< Pole_XPos[NumberOfPoles-1]
+	   <<", xsiz = "<<Module_Size_X[j]<<endl;
+      */
+      }
+    }  // for i
+  }    // for j
+  cout << " Total number of modules: " << modNum << ", poles: " << NumberOfPoles << endl;
+
+  //  Pole related bars
+  Double_t BZMin = 10000.;
+  Double_t BZMax = -10000.;
+  Int_t iL;
+  for (iL = 0; iL < NLayer; iL++) {
+    if (zPosLayer[iL] > BZMax) BZMax = zPosLayer[iL];
+    if (zPosLayer[iL] < BZMin) BZMin = zPosLayer[iL];
+  }
+
+  Bar_Size_Z  = BZMax - BZMin;
+  Frame_Pos_Z = (BZMax + BZMin) / 2.;
+  Bar_Pos_Z   = (BZMax + BZMin) / 2.;
+
+  cout << "Place " << NCol << " bars of z-length " << Bar_Size_Z << " at z = " << Bar_Pos_Z << endl;
+
+  Int_t iC;
+  Bool_t bBarExist = kFALSE;
+  for (iC = 0; iC < NCol; iC++) {
+    // Check if creating a bar for this pole would not collide with an existing bar
+    bBarExist = kFALSE;
+    for (Int_t iBar = 0; iBar < NumberOfBars; iBar++) {
+      if ((TMath::Abs(xPosCol[iC] - Bar_XPos[iBar]) < Bar_Size_X))  // Original bar
+      {
+        cout << Form("Rejected bar for col %03d at X= %7.2f due to bar %03d at X= %7.2f", iC, xPosCol[iC], iBar,
+                     Bar_XPos[iBar])
+             << endl;
+
+        cout << Form(" ==> Replaced bar %03d at X= %7.2f by a bar at ", iBar, Bar_XPos[iBar]);
+        Bar_XPos[iBar] = (xPosCol[iC] + Bar_XPos[iBar]) / 2.0;  // take mean of the 2 positions!!
+        cout << Form(" X= %7.2f (middle of colliding X positions)", Bar_XPos[iBar]) << endl;
+
+        bBarExist = kTRUE;
+        break;
+      }
+
+      if ((TMath::Abs(xPosCol[iC] + Bar_XPos[iBar]) < Bar_Size_X))  // Mirrored bar VS original
+      {
+        cout << Form("Rejected bar for col %03d at X= %7.2f due to bar %03d at X= %7.2f", iC, xPosCol[iC], iBar,
+                     Bar_XPos[iBar])
+             << endl;
+
+        cout << Form(" ==> Replaced bar %03d at X= %7.2f by a bar at ", iBar, Bar_XPos[iBar]);
+        Bar_XPos[iBar] = (Bar_XPos[iBar] - xPosCol[iC]) / 2.0;  // take mean of the 2 positions!!
+        cout << Form(" X= %7.2f (middle of colliding X positions)", Bar_XPos[iBar]) << endl;
+
+        bBarExist = kTRUE;
+        break;
+      }
+    }  //  for (Int_t iP=0; iP<NumberOfPoles; iP++)
+
+    if (!bBarExist) {
+      gBar[NumberOfBars]     = create_tof_bar(Bar_Size_X, Bar_Size_Y, Bar_Size_Z);
+      Bar_ZPos[NumberOfBars] = Bar_Pos_Z;  //PosPole+Bar_Size_Z/2.-Pole_Size_Z/2.;
+      Bar_XPos[NumberOfBars] = xPosCol[iC];
+      cout << Form("Placed bar %03d at X= %7.2f and Z = %7.2f ", NumberOfBars, Bar_XPos[NumberOfBars],
+                   Bar_ZPos[NumberOfBars])
+           << endl;
+      NumberOfBars++;
+    }  // if(!BPexist)
+  }
+}
+
+
+void position_side_tof_modules(Int_t modNType)
+{
+  TGeoTranslation* module_trans = NULL;
+  TGeoRotation* module_rot      = new TGeoRotation();
+  module_rot->RotateZ(180.);
+  TGeoCombiTrans* module_combi_trans = NULL;
+
+  //  Int_t numModules=(Int_t)( (Inner_Module_Last_Y_Position-Inner_Module_First_Y_Position)/Module_Size_Y[modType])+1;
+  Double_t yPos = 0.;  //Inner_Module_First_Y_Position;
+  Int_t ii      = 0;
+  for (Int_t j = 0; j < modNType; j++) {
+    Int_t modType = InnerSide_Module_Types[j];
+    Int_t modNum  = 0;
+    for (Int_t i = 0; i < InnerSide_Module_Number[j]; i++) {
+      ii++;
+      cout << "InnerSide ii " << ii << " Last " << Last_Size_Y << "," << Last_Over_Y << endl;
+      Double_t DeltaY = Module_Size_Y[modType] + Last_Size_Y - 2. * (Module_Over_Y[modType] + Last_Over_Y);
+      if (ii > 1) { yPos += DeltaY; }
+      Last_Size_Y   = Module_Size_Y[modType];
+      Last_Over_Y   = Module_Over_Y[modType];
+      Double_t xPos = InnerSide_Module_X_Offset;
+      Double_t zPos = Wall_Z_Position;
+      cout << "Position InnerSide Module " << i << " of " << InnerSide_Module_Number[j] << " Type " << modType
+           << " at Y = " << yPos << " Ysize = " << Module_Size_Y[modType] << " DeltaY = " << DeltaY << endl;
+
+      module_trans = new TGeoTranslation("", xPos, yPos, zPos);
+      gGeoMan->GetVolume(geoVersion)->AddNode(gModules[modType], modNum, module_trans);
+      modNum++;
+
+      module_trans       = new TGeoTranslation("", -xPos, yPos, zPos);
+      module_combi_trans = new TGeoCombiTrans(*module_trans, *module_rot);
+      gGeoMan->GetVolume(geoVersion)->AddNode(gModules[modType], modNum, module_combi_trans);
+      modNum++;
+
+      if (ii > 1) {
+        module_trans = new TGeoTranslation("", xPos, -yPos, zPos);
+        gGeoMan->GetVolume(geoVersion)->AddNode(gModules[modType], modNum, module_trans);
+        modNum++;
+
+        module_trans       = new TGeoTranslation("", -xPos, -yPos, zPos);
+        module_combi_trans = new TGeoCombiTrans(*module_trans, *module_rot);
+        gGeoMan->GetVolume(geoVersion)->AddNode(gModules[modType], modNum, module_combi_trans);
+        modNum++;
+
+        module_trans = new TGeoTranslation("", xPos, yPos - DeltaY / 2, zPos + Module_Size_Z[modType]);
+        gGeoMan->GetVolume(geoVersion)->AddNode(gModules[modType], modNum, module_trans);
+        modNum++;
+
+        module_trans       = new TGeoTranslation("", -xPos, yPos - DeltaY / 2, zPos + Module_Size_Z[modType]);
+        module_combi_trans = new TGeoCombiTrans(*module_trans, *module_rot);
+        gGeoMan->GetVolume(geoVersion)->AddNode(gModules[modType], modNum, module_combi_trans);
+        modNum++;
+
+        module_trans = new TGeoTranslation("", xPos, -(yPos - DeltaY / 2), zPos + Module_Size_Z[modType]);
+        gGeoMan->GetVolume(geoVersion)->AddNode(gModules[modType], modNum, module_trans);
+        modNum++;
+
+        module_trans       = new TGeoTranslation("", -xPos, -(yPos - DeltaY / 2), zPos + Module_Size_Z[modType]);
+        module_combi_trans = new TGeoCombiTrans(*module_trans, *module_rot);
+        gGeoMan->GetVolume(geoVersion)->AddNode(gModules[modType], modNum, module_combi_trans);
+        modNum++;
+      }
+    }
+  }
+}
+
+void position_outer_tof_modules(Int_t nCol)  //modType, Int_t col1, Int_t col2)
+{
+  TGeoTranslation* module_trans = NULL;
+  TGeoRotation* module_rot      = new TGeoRotation();
+  module_rot->RotateZ(180.);
+  TGeoCombiTrans* module_combi_trans = NULL;
+
+  //  Int_t numModules=(Int_t)( (Outer_Module_Last_Y_Position-Outer_Module_First_Y_Position)/Module_Size_Y[modType])+1;
+
+  Int_t modNum[NofModuleTypes];
+  for (Int_t k = 0; k < NofModuleTypes; k++) {
+    modNum[k] = 0;
+  }
+
+  Double_t zPos = Wall_Z_Position;
+  for (Int_t j = 0; j < nCol; j++) {
+    Double_t xPos  = Outer_Module_X_Offset + ((j + 1) * DxColl);
+    Last_Size_Y    = 0.;
+    Last_Over_Y    = 0.;
+    Double_t yPos  = 0.;
+    Int_t ii       = 0;
+    Double_t DzPos = 0.;
+    for (Int_t k = 0; k < Outer_Module_NTypes; k++) {
+      Int_t modType = Outer_Module_Types[k][j];
+      if (Module_Size_Z[modType] > DzPos) {
+        if (Outer_Module_Number[k][j] > 0) { DzPos = Module_Size_Z[modType]; }
+      }
+    }
+
+    zPos -= 2. * DzPos;  //((j+1)*2*Module_Size_Z[modType]);
+
+    Pole_ZPos[NumberOfPoles] = zPos;
+    Pole_Col[NumberOfPoles]  = j + 1;
+    NumberOfPoles++;
+    Pole_ZPos[NumberOfPoles] = zPos + DzPos;
+    Pole_Col[NumberOfPoles]  = j + 1;
+    NumberOfPoles++;
+    //if (j+1==nCol) {
+    if (1) {
+      Pole_ZPos[NumberOfPoles] = Pole_ZPos[0];
+      Pole_Col[NumberOfPoles]  = j + 1;
+      NumberOfPoles++;
+
+      Bar_Size_Z             = Pole_ZPos[0] - zPos;
+      gBar[NumberOfBars]     = create_tof_bar(Bar_Size_X, Bar_Size_Y, Bar_Size_Z);
+      Bar_ZPos[NumberOfBars] = zPos + Bar_Size_Z / 2. - Pole_Size_Z / 2.;
+      Bar_XPos[NumberOfBars] = xPos + Pole_Offset;
+      NumberOfBars++;
+
+      cout << Form("Placed Outer module bar %03d at X= %7.2f and Z = %7.2f ", NumberOfBars, Bar_XPos[NumberOfBars],
+                   Bar_ZPos[NumberOfBars])
+           << endl;
+    }
+
+    for (Int_t k = 0; k < Outer_Module_NTypes; k++) {
+      Int_t modType    = Outer_Module_Types[k][j];
+      Int_t numModules = Outer_Module_Number[k][j];
+
+      cout << " Outer: position " << numModules << " of type " << modType << " in col " << j << " at z = " << zPos
+           << ", DzPos = " << DzPos << endl;
+      for (Int_t i = 0; i < numModules; i++) {
+        ii++;
+        cout << "Outer ii " << ii << " Last " << Last_Size_Y << "," << Last_Over_Y << endl;
+        Double_t DeltaY = Module_Size_Y[modType] + Last_Size_Y - 2. * (Module_Over_Y[modType] + Last_Over_Y);
+        if (ii > 1) { yPos += DeltaY; }
+        Last_Size_Y = Module_Size_Y[modType];
+        Last_Over_Y = Module_Over_Y[modType];
+        cout << "Position Outer Module " << i << " of " << Outer_Module_Number[k][j] << " Type " << modType << "(#"
+             << modNum[modType] << ") "
+             << " at Y = " << yPos << " Ysize = " << Module_Size_Y[modType] << " DeltaY = " << DeltaY << endl;
+
+        module_trans = new TGeoTranslation("", xPos, yPos, zPos);
+        gGeoMan->GetVolume(geoVersion)->AddNode(gModules[modType], modNum[modType], module_trans);
+        modNum[modType]++;
+
+        module_trans       = new TGeoTranslation("", -xPos, yPos, zPos);
+        module_combi_trans = new TGeoCombiTrans(*module_trans, *module_rot);
+        gGeoMan->GetVolume(geoVersion)->AddNode(gModules[modType], modNum[modType], module_combi_trans);
+        modNum[modType]++;
+
+        if (ii > 1) {
+          module_trans = new TGeoTranslation("", xPos, -yPos, zPos);
+          gGeoMan->GetVolume(geoVersion)->AddNode(gModules[modType], modNum[modType], module_trans);
+          modNum[modType]++;
+          module_trans       = new TGeoTranslation("", -xPos, -yPos, zPos);
+          module_combi_trans = new TGeoCombiTrans(*module_trans, *module_rot);
+          gGeoMan->GetVolume(geoVersion)->AddNode(gModules[modType], modNum[modType], module_combi_trans);
+          modNum[modType]++;
+
+          // second layer
+          module_trans = new TGeoTranslation("", xPos, yPos - DeltaY / 2., zPos + DzPos);
+          gGeoMan->GetVolume(geoVersion)->AddNode(gModules[modType], modNum[modType], module_trans);
+          modNum[modType]++;
+          module_trans       = new TGeoTranslation("", -xPos, yPos - DeltaY / 2., zPos + DzPos);
+          module_combi_trans = new TGeoCombiTrans(*module_trans, *module_rot);
+          gGeoMan->GetVolume(geoVersion)->AddNode(gModules[modType], modNum[modType], module_combi_trans);
+          modNum[modType]++;
+
+          module_trans = new TGeoTranslation("", xPos, -(yPos - DeltaY / 2.), zPos + DzPos);
+          gGeoMan->GetVolume(geoVersion)->AddNode(gModules[modType], modNum[modType], module_trans);
+          modNum[modType]++;
+          module_trans       = new TGeoTranslation("", -xPos, -(yPos - DeltaY / 2.), zPos + DzPos);
+          module_combi_trans = new TGeoCombiTrans(*module_trans, *module_rot);
+          gGeoMan->GetVolume(geoVersion)->AddNode(gModules[modType], modNum[modType], module_combi_trans);
+          modNum[modType]++;
+        }
+      }
+    }
+  }
+}
+
+
+void dump_info_file()
+{
+  TDatime datetime;  // used to get timestamp
+
+  printf("writing info file: %s\n", FileNameInfo.Data());
+
+  FILE* ifile;
+  ifile = fopen(FileNameInfo.Data(), "w");
+
+  if (ifile == NULL) {
+    printf("error opening %s\n", FileNameInfo.Data());
+    exit(1);
+  }
+
+  fprintf(ifile, "#\n##   %s information file\n#\n\n", geoVersion.Data());
+
+  fprintf(ifile, "# created %d\n\n", datetime.GetDate());
+
+  fprintf(ifile, "# TOF setup\n");
+  if (TOF_Z_Front == 450) fprintf(ifile, "SIS 100 hadron setup\n");
+  if (TOF_Z_Front == 600) fprintf(ifile, "SIS 100 electron\n");
+  if (TOF_Z_Front == 650) fprintf(ifile, "SIS 100 muon\n");
+  if (TOF_Z_Front == 880) fprintf(ifile, "SIS 300 electron\n");
+  if (TOF_Z_Front == 1020) fprintf(ifile, "SIS 300 muon\n");
+  fprintf(ifile, "\n");
+
+  const Double_t TOF_Z_Back = Wall_Z_Position + 1.5 * Module_Size_Z[0];  // back of TOF wall
+
+  fprintf(ifile, "# envelope\n");
+  // Show extension of TRD
+  fprintf(ifile, "%7.2f cm   start of TOF (z)\n", TOF_Z_Front);
+  fprintf(ifile, "%7.2f cm   end   of TOF (z)\n", TOF_Z_Back);
+  fprintf(ifile, "\n");
+
+  // Layer thickness
+  fprintf(ifile, "# central tower position\n");
+  fprintf(ifile, "%7.2f cm   center of staggered, front RPC cell at x=0\n", Wall_Z_Position);
+  fprintf(ifile, "\n");
+
+  fclose(ifile);
+}
diff --git a/macro/trd/geometry/trd.v20/Create_TRD_Geometry_v20c.C b/macro/trd/geometry/trd.v20/Create_TRD_Geometry_v20c.C
new file mode 100644
index 0000000000000000000000000000000000000000..a8f64cdfb740cfdcfe68f144eb9397a9e8c8b03e
--- /dev/null
+++ b/macro/trd/geometry/trd.v20/Create_TRD_Geometry_v20c.C
@@ -0,0 +1,3834 @@
+/* Copyright (C) 2021 Facitity for antiproton and ion Research in Europe, Darmstadt
+   SPDX-License-Identifier: GPL-3.0-only:
+   Authors: Pascal Raisig, Eoin Clerkin [committer] */
+
+///
+/// \file Create_TRD_Geometry_v20c.C
+/// \brief Generates TRD geometry in Root format.
+///
+
+// 2021-12-15 - EC - v20c    - same as v20b but positioning relative to the center of the magnet
+// 2020-10-20 - PR - v20b    - put TRD layers at z-startposition according to 17n/18a, only sis100_hadron at 410 instead of 260 (260 should not be possible due to rail construction)
+// 2020-10-12 - DE - v20a    - put TRD layers at z-positions according to proposed CAD frame design
+// 2017-06-02 - DE - v17n    - increase pad granularity wrt v17l: type 6 = 24 rows, type 8 = 8 rows
+// 2017-05-31 - DE - v17l    - increase large module size to 96/99 cm
+// 2017-05-25 - DE - v17k    - use only 4 module types: 1, 3, 6, 8
+// 2017-05-25 - DE - v17j    - re-arrange inner zone to allow for a 2x1 hole
+// 2017-04-28 - DE - v17     - implement power bus bars as defined in the TDR
+// 2017-04-26 - DE - v17     - add aluminium ledge around backpanel
+// 2017-04-25 - DE - v17c_3e - reduce the number of FEBs on the small modules from 10, 6, 4 to 8, 4 and 2
+// 2017-02-14 - DE - v17b_3e - build TRD from ROB-3 only, optimise layout
+// 2017-01-10 - DE - v17a_3e - replace 6 ultimate density by 9 super density FEBs for TRD type 1 modules
+// 2016-07-05 - FU - v16a_3e - identical to v15a, change the way the trd volume is exported to resolve a bug with TGeoShape destructor
+// 2015-01-08 - DE - v15a_3e - reduce frame thickness in large modules to 15 mm instead of 20 mm
+// 2014-06-25 - DE - v14a_3e - consists of only 3 small and 3 large modules types (was 4+4 before)
+// 2014-06-25 - DE - v14a_3e - inner part of all 3 stations is now identical
+// 2014-05-02 - DE - v14a_3e - redesign inner part of station 3, now with 5x5-1 small modules, like in station 1 and station 2
+// 2014-05-02 - DE - v14a_3e - include optional GBTX readout boards on each module
+// 2014-05-02 - DE - v14a_3e - introduce 3x5=15 Spadic FEBs for ultimate density on module type 1
+//
+// 2013-11-14 - DE - v13q_3e - generate information about pad plane layout (CbmTrdPads_v14a.h) for all module types in this macro
+//
+// 2013-11-04 - DE - v13p4 - adapt the number of front-end boards to the pad layout of the 540 mm modules
+// 2013-11-04 - DE - v13p4 - use 8 module types (4x S + 4x L) to better match the occupancy
+// 2013-10-31 - DE - v13p4 - modify the support structure of station 1 to match with the MUCH/RICH platform
+// 2013-10-29 - DE - v13p4 - build lattice grid as TGeoBBox instead of VolumeAssembly - in run_sim.C save  9% of time compared to v13p7
+// 2013-10-29 - DE - v13p4 - build lattice grid as TGeoBBox instead of CompositeShape - in run_sim.C save 18% of time compared to v13p6
+//
+// 2013-10-28 - DE - introduce new geometry naming scheme: v13p1 - SIS 100 hadron
+// 2013-10-28 - DE - introduce new geometry naming scheme: v13p2 - SIS 100 electron
+// 2013-10-28 - DE - introduce new geometry naming scheme: v13p3 - SIS 100 muon
+// 2013-10-28 - DE - introduce new geometry naming scheme: v13p4 - SIS 300 electron
+// 2013-10-28 - DE - introduce new geometry naming scheme: v13p5 - SIS 300 muon
+// 2013-10-28 - DE - add option to draw the magnetic field vector in the magnet
+// 2013-09-27 - DE - do not use TGeoXtru to build the supports, use TGeoBBox instead
+//
+// 2013-06-25 - DE - v13g trd300_rich             (10 layers, z = 4100 ) - TRD right behind SIS300 RICH
+// 2013-06-25 - DE - v13h trd100_sts              ( 4 layers, z = 2600 ) - TRD completely on RICH/MUCH platform to allow TOF to move upstream
+// 2013-06-25 - DE - v13i trd100_rich             ( 2 layers, z = 4100 ) - TRD right behind RICH
+// 2013-06-25 - DE - v13j trd100_rich             ( 3 layers, z = 4100 ) - TRD right behind RICH
+// 2013-06-25 - DE - v13k trd100_rich             ( 4 layers, z = 4100 ) - TRD right behind RICH
+// 2013-06-25 - DE - ---  trd100_much_2_absorbers ( 4 layers, z = 4300 ) - same as version at z = 4600
+// 2013-06-25 - DE - v13l trd100_much_3_absorbers ( 4 layers, z = 4600 ) - TRD right behind SIS100 MUCH
+// 2013-06-25 - DE - v13m trd300_much_6_absorbers (10 layers, z = 5500 ) - TRD right behind SIS300 MUCH
+// 2013-06-25 - DE - v13n trd300_rich_stretched   (10 layers, z = 4600 ) - TRD stretched behind SIS300 RICH
+//
+// 2013-06-19 - DE - add TRD (I, II, III) labels on support structure
+// 2013-05-29 - DE - allow for flexible TRD z-positions defined by position of layer01
+// 2013-05-23 - DE - remove "trd_" prefix from node names (except top node)
+// 2013-05-22 - DE - radiators G30 (z=240 mm)
+// 2013-05-22 - DE - radiators H (z=275 mm - 125 * 2.2mm), (H++ z=335 mm)
+// 2013-05-22 - DE - radiators B++ (z=254 mm - 350 * 0.724 mm), K++ (z=254 mm - 350 * 0.724 mm)
+// 2013-04-17 - DE - introduce volume assembly for layers, e.g. trd_layer03
+// 2013-03-26 - DE - use Air as ASIC material
+// 2013-03-26 - DE - put support structure into its own assembly
+// 2013-03-26 - DE - move TRD upstream to z=400m
+// 2013-03-26 - DE - RICH will probably end at z=380 cm, TRD can move to 400 cm
+// 2013-03-25 - DE - shrink active area from 570 to 540 mm and 960 to 910 mm
+// 2013-03-06 - DE - add ASICs on FEBs
+// 2013-03-05 - DE - introduce supports for SIS100 and SIS300
+// 2013-03-05 - DE - replace all Float_t by Double_t
+// 2013-01-21 - DE - introduce TRD media, use TRDG10 as material for pad plane and FEBs
+// 2013-01-21 - DE - put backpanel into the geometry
+// 2013-01-11 - DE - allow for misalignment of TRD modules
+// 2012-11-04 - DE - add kapton foil, add FR4 padplane
+// 2012-11-03 - DE - add lattice grid on entrance window as CompositeShape
+
+// TODO:
+// - use Silicon as ASIC material
+
+// in root all sizes are given in cm
+
+#include "TDatime.h"
+#include "TFile.h"
+#include "TGeoArb8.h"
+#include "TGeoCompositeShape.h"
+#include "TGeoCone.h"
+#include "TGeoManager.h"
+#include "TGeoMaterial.h"
+#include "TGeoMatrix.h"
+#include "TGeoMedium.h"
+#include "TGeoPgon.h"
+#include "TGeoTube.h"
+#include "TGeoVolume.h"
+#include "TGeoXtru.h"
+#include "TList.h"
+#include "TRandom3.h"
+#include "TString.h"
+#include "TSystem.h"
+
+#include <iostream>
+
+// Name of output file with geometry
+const TString tagVersion = "v20c";
+//const TString subVersion   = "_1h";
+//const TString subVersion   = "_1e";
+//const TString subVersion   = "_1m";
+//const TString subVersion   = "_3e";
+//const TString subVersion   = "_3m";
+
+const Int_t setupid = 0;  // 1e is the default
+//const Double_t zfront[5]  = { 260., 410., 360., 410., 550. };  // original
+const Double_t zfront[5]  = {370.,         // SIS100 hadron
+                            370.,         // SIS100 electron
+                            450.,         // SIS100 muon
+                            370., 510.};  // muon_jpsi and muon_lmvm
+const TString setupVer[5] = {"_1h", "_1e", "_1m", "_3e", "_3m"};
+const TString subVersion  = setupVer[setupid];
+
+const TString geoVersion   = "trd_" + tagVersion + subVersion;
+const TString FileNameSim  = geoVersion + ".geo.root";
+const TString FileNameGeo  = geoVersion + "_geo.root";
+const TString FileNameInfo = geoVersion + ".geo.info";
+const TString FileNamePads = "CbmTrdPads_" + tagVersion + ".h";
+
+// display switches
+const Bool_t IncludeRadiator = true;  // false;  // true, if radiator is included in geometry
+const Bool_t IncludeLattice  = true;  // false;  // true, if lattice grid is included in geometry
+
+const Bool_t IncludeKaptonFoil = true;  // false;  // true, if entrance window is included in geometry
+const Bool_t IncludeGasFrame   = true;  // false;  // true, if frame around gas volume is included in geometry
+const Bool_t IncludePadplane   = true;  // false;  // true, if padplane is included in geometry
+const Bool_t IncludeBackpanel  = true;  // false;  // true, if backpanel is included in geometry
+const Bool_t IncludeAluLedge   = true;  // false;  // true, if Al-ledge around the backpanel is included in geometry
+const Bool_t IncludePowerbars  = true;  // false;  // true, if LV copper bus bars to be drawn
+
+const Bool_t IncludeFebs        = true;   // false;  // true, if FEBs are included in geometry
+const Bool_t IncludeRobs        = true;   // false;  // true, if ROBs are included in geometry
+const Bool_t IncludeAsics       = true;   // false;  // true, if ASICs are included in geometry
+const Bool_t IncludeSupports    = true;   // false;  // true, if support structure is included in geometry
+const Bool_t IncludeLabels      = true;   // false;  // true, if TRD (I, II, III) labels are plotted in (VisLevel 5)
+const Bool_t IncludeFieldVector = false;  // true, if magnetic field vector to be shown (in the magnet)
+
+// positioning switches
+const Bool_t DisplaceRandom = false;  // true; // false;  // add random displacement of modules for alignment study
+const Bool_t RotateRandom   = false;  // true; // false;  // add random rotation of modules for alignment study
+const Bool_t DoExplode      = false;  // true, // false;  // add random displacement of modules for alignment study
+
+// positioning parameters
+const Double_t maxdx = 0.2;  // max +- 0.1 cm shift in x
+const Double_t maxdy = 0.2;  // max +- 0.1 cm shift in y
+const Double_t maxdz = 1.0;  // max +- 1.0 cm shift in z
+
+const Double_t maxdrotx = 2.0;  // 20.0; // max rotation around x
+const Double_t maxdroty = 2.0;  // 20.0; // max rotation around y
+const Double_t maxdrotz = 2.0;  // 20.0; // max rotation around z
+
+const Double_t ExplodeFactor = 1.02;  // 1.02; // Factor by which modules are exploded in the x/y plane
+
+// initialise random numbers
+TRandom3 r3(0);
+
+// Parameters defining the layout of the complete detector build out of different detector layers.
+const Int_t MaxLayers = 10;  // max layers
+
+// select layers to display
+//
+//const Int_t    ShowLayer[MaxLayers] = { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 };  //  1st layer only
+//const Int_t    ShowLayer[MaxLayers] = { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 };  //  2nd layer only
+//const Int_t    ShowLayer[MaxLayers] = { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 };  //  5th layer only
+//const Int_t    ShowLayer[MaxLayers] = { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 };  //  6th layer only
+//const Int_t    ShowLayer[MaxLayers] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 };  //  9th layer only
+//const Int_t    ShowLayer[MaxLayers] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 };  // 10th layer only
+//
+//const Int_t    ShowLayer[MaxLayers] = { 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 };  // Station 1, layer 1, 2
+//const Int_t    ShowLayer[MaxLayers] = { 0, 0, 0, 0, 1, 1, 0, 0, 0, 0 };  // Station 2, layer 5, 6
+//const Int_t    ShowLayer[MaxLayers] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 };  // Station 3, layer 9,10
+//const Int_t    ShowLayer[MaxLayers] = { 1, 1, 0, 0, 1, 1, 0, 0, 0, 0 };  // Station 1 and 2
+//const Int_t    ShowLayer[MaxLayers] = { 1, 1, 0, 0, 1, 1, 1, 0, 1, 1 };  // Station 1, 2 and 3
+//
+//const Int_t    ShowLayer[MaxLayers] = { 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 };  // SIS100-2l  // 1: plot, 0: hide
+//const Int_t    ShowLayer[MaxLayers] = { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 };  // SIS100-3l  // 1: plot, 0: hide
+//
+//const Int_t    ShowLayer[MaxLayers] = { 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 };  // SIS100-4l  // 1: plot, 0: hide
+//const Int_t    ShowLayer[MaxLayers] = { 0, 0, 0, 0, 1, 1, 1, 1, 1, 1 };  // SIS300-mu  // 1: plot, 0: hide
+//const Int_t    ShowLayer[MaxLayers] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };  // SIS300-e   // 1: plot, 0: hide
+Int_t ShowLayer[MaxLayers] = {1, 1, 1, 1, 0, 0, 0, 0, 0, 0};  // SIS100-4l is default
+
+Int_t BusBarOrientation[MaxLayers] = {1, 1, 1, 1, 0, 0, 0, 0, 0, 0};  // 1 = vertical
+
+Int_t PlaneId[MaxLayers];  // automatically filled with layer ID
+
+const Int_t LayerType[MaxLayers] = {10, 11, 10, 11, 20, 21,
+                                    20, 21, 30, 31};  // ab: a [1-3] - layer type, b [0,1] - vertical/horizontal pads
+// ### Layer Type 11 is Layer Type 1 with detector modules rotated by 90°
+// ### Layer Type 21 is Layer Type 2 with detector modules rotated by 90°
+// ### Layer Type 31 is Layer Type 3 with detector modules rotated by 90°
+// In the subroutine creating the layers this is recognized automatically
+
+const Int_t LayerNrInStation[MaxLayers] = {1, 2, 3, 4, 1, 2, 3, 4, 1, 2};
+
+Double_t LayerPosition[MaxLayers] = {0.};  // start position = 0 - 2016-07-12 - DE
+
+// 5x z-positions from 260 till 550 cm
+//Double_t LayerPosition[MaxLayers] = { 260. }; // start position - 2013-10-28 - DE - v14_1h - SIS 100 hadron         ( 4 layers, z = 2600 )
+//Double_t LayerPosition[MaxLayers] = { 410. }; // start position - 2013-10-28 - DE - v14_1e - SIS 100 electron       ( 4 layers, z = 4100 )
+//Double_t LayerPosition[MaxLayers] = { 360. }; // start position - 2014-06-16 - DE - v14_1m - SIS 100 muon           ( 4 layers, z = 3600 ) was 460.
+//Double_t LayerPosition[MaxLayers] = { 410. }; // start position - 2013-10-28 - DE - v14_3e - SIS 300 electron       (10 layers, z = 4100 )
+//Double_t LayerPosition[MaxLayers] = { 550. }; // start position - 2013-10-28 - DE - v14_3m - SIS 300 muon     6_abs (10 layers, z = 5500 )
+//
+// obsolete variants
+//Double_t LayerPosition[MaxLayers] = { 460. }; // start position - 2013-10-28 - DE - v13x3 - SIS 100 muon         ( 4 layers, z = 4600 )
+//Double_t LayerPosition[MaxLayers] = { 410. }; // start position - 2013-06-25 - DE - v13i trd100_rich             ( 2 layers, z = 4100 )
+//Double_t LayerPosition[MaxLayers] = { 410. }; // start position - 2013-06-25 - DE - v13j trd100_rich             ( 3 layers, z = 4100 )
+//Double_t LayerPosition[MaxLayers] = { 430. }; // start position - 2013-06-25 - DE - ---  trd100_much_2_absorbers ( 4 layers, z = 4300 )
+//Double_t LayerPosition[MaxLayers] = { 460. }; // start position - 2013-06-25 - DE - v13n trd300_rich_stretched   (10 layers, z = 4600 )
+
+
+const Double_t LayerThickness = 71.0;  // 45.0;  // Thickness of one TRD layer in cm
+
+const Double_t LayerOffset[MaxLayers] = {0., 0., 0., 0., 5.,
+                                         0., 0., 0., 5., 0.};  // v13x[4,5] - z offset in addition to LayerThickness
+//const Double_t LayerOffset[MaxLayers] = {   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0. };  // SIS100 - z offset in addition to LayerThickness
+//const Double_t LayerOffset[MaxLayers] = {   0.,   0.,   0.,   0.,  95.,   0.,   0.,   0.,   5.,   0. };  // v13n       - z offset in addition to LayerThickness
+
+const Int_t LayerArraySize[3][4] = {{9, 4, 9, 11},  // for layer[1-3][i,o] below
+                                    {5, 5, 9, 11},
+                                    {5, 5, 9, 11}};
+
+
+// ### Layer Type 1
+// v14x - module types in the inner sector of layer type 1 - looking upstream
+const Int_t layer1i[9][4] = {
+  {323, 323, 321, 321},  // abc: a module type - b orientation (x90 deg) in odd - c even layers
+  {323, 323, 321, 321}, {323, 323, 321, 321}, {123, 123, 121, 121}, {103, 0, 0, 101},
+  {103, 103, 101, 101}, {303, 303, 301, 301}, {303, 303, 301, 301}, {303, 303, 301, 301}};
+// number of modules: 24
+
+// v14x - module types in the outer sector of layer type 1 - looking upstream
+const Int_t layer1o[9][11] = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},         {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+                              {0, 0, 723, 723, 0, 0, 0, 721, 721, 0, 0}, {0, 0, 723, 523, 0, 0, 0, 521, 721, 0, 0},
+                              {0, 0, 503, 503, 0, 0, 0, 501, 501, 0, 0}, {0, 0, 703, 503, 0, 0, 0, 501, 701, 0, 0},
+                              {0, 0, 703, 703, 0, 0, 0, 701, 701, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+                              {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
+// number of modules: 26
+// Layer1 =  24 + 26;   // v14a
+
+
+// ### Layer Type 2
+// v14x - module types in the inner sector of layer type 2 - looking upstream
+const Int_t layer2i[5][5] = {
+  {323, 323, 321, 321, 321},  // abc: a module type - b orientation (x90 deg) in odd - c even layers
+  {223, 123, 121, 121, 221},
+  {203, 103, 0, 101, 201},
+  {203, 103, 101, 101, 201},
+  {303, 303, 301, 301, 301}};
+// number of modules: 24
+
+// v14x - module types in the outer sector of layer type 2 - looking upstream
+const Int_t layer2o[9][11] = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+                              {0, 823, 823, 823, 823, 821, 821, 821, 821, 821, 0},
+                              {0, 823, 823, 823, 723, 721, 721, 821, 821, 821, 0},
+                              {0, 823, 723, 623, 0, 0, 0, 621, 721, 821, 0},
+                              {0, 803, 703, 603, 0, 0, 0, 601, 701, 801, 0},
+                              {0, 803, 703, 603, 0, 0, 0, 601, 701, 801, 0},
+                              {0, 803, 803, 803, 703, 701, 701, 801, 801, 801, 0},
+                              {0, 803, 803, 803, 803, 801, 801, 801, 801, 801, 0},
+                              {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
+// number of modules: 54
+// Layer2 =  24 + 54;   // v14a
+
+
+// ### Layer Type 3
+// v14x - module types in the inner sector of layer type 3 - looking upstream
+const Int_t layer3i[5][5] = {
+  {323, 323, 321, 321, 321},  // abc: a module type - b orientation (x90 deg) in odd - c even layers
+  {223, 123, 121, 121, 221},
+  {203, 103, 0, 101, 201},
+  {203, 103, 101, 101, 201},
+  {303, 303, 301, 301, 301}};
+// number of modules: 24
+
+// v14x - module types in the outer sector of layer type 3 - looking upstream
+const Int_t layer3o[9][11] = {
+  {823, 823, 823, 823, 823, 821, 821, 821, 821, 821, 821}, {823, 823, 823, 823, 823, 821, 821, 821, 821, 821, 821},
+  {823, 823, 823, 723, 623, 621, 621, 721, 821, 821, 821}, {823, 823, 723, 623, 0, 0, 0, 621, 721, 821, 821},
+  {803, 803, 703, 603, 0, 0, 0, 601, 701, 801, 801},       {803, 803, 703, 603, 0, 0, 0, 601, 701, 801, 801},
+  {803, 803, 803, 703, 603, 601, 601, 701, 801, 801, 801}, {803, 803, 803, 803, 803, 801, 801, 801, 801, 801, 801},
+  {803, 803, 803, 803, 803, 801, 801, 801, 801, 801, 801}};
+// number of modules: 90
+// Layer2 =  24 + 90;   // v14a
+
+
+// Parameters defining the layout of the different detector modules
+const Int_t NofModuleTypes             = 8;
+const Int_t ModuleType[NofModuleTypes] = {0, 0, 0, 0, 1, 1, 1, 1};  // 0 = small module, 1 = large module
+
+// FEB inclination angle
+const Double_t feb_rotation_angle[NofModuleTypes] = {
+  60, 90, 90, 80, 60, 60, 90, 90};  // rotation around x-axis, 0 = vertical, 90 = horizontal
+//const Double_t feb_rotation_angle[NofModuleTypes] = { 60,  90,  90,  80,  80,  90,  90,  90 }; // rotation around x-axis, 0 = vertical, 90 = horizontal
+//const Double_t feb_rotation_angle[NofModuleTypes] = { 45,  45,  45,  45,  45,  45,  45,  45 }; // rotation around x-axis, 0 = vertical, 90 = horizontal
+
+// GBTx ROB definitions
+//// v17d
+//const Int_t RobsPerModule[NofModuleTypes] = {  4,  2,  2,  1,  2,  3,  2,  1 }; // number of GBTx ROBs on module
+//const Int_t GbtxPerRob[NofModuleTypes]    = {103,103,103,103,107,103,103,103 }; // number of GBTx ASICs on ROB
+//
+//const Int_t GbtxPerModule[NofModuleTypes] = {   12,  6,  6,  0,  0,  9,  6,  3 }; // for .geo.info - TODO: merge with above GbtxPerRob
+//const Int_t RobTypeOnModule[NofModuleTypes]={ 3333, 33, 33,  0,  0,333, 33,  3 }; // for .geo.info - TODO: merge with above GbtxPerRob
+//
+// v17l - 96 cm
+const Int_t RobsPerModule[NofModuleTypes] = {4, 2, 1, 1, 6, 6, 2, 2};                  // number of GBTx ROBs on module
+const Int_t GbtxPerRob[NofModuleTypes]    = {103, 103, 103, 103, 103, 103, 103, 103};  // number of GBTx ASICs on ROB
+
+const Int_t GbtxPerModule[NofModuleTypes]   = {12, 6,  3, 0,
+                                             18, 18, 6, 6};  // for .geo.info - TODO: merge with above GbtxPerRob
+const Int_t RobTypeOnModule[NofModuleTypes] = {3333,   33, 3, 0, 333333,
+                                               333333, 33, 33};  // for .geo.info - TODO: merge with above GbtxPerRob
+
+//// v17c
+//const Int_t RobsPerModule[NofModuleTypes] = {  4,  2,  1,  1,  2,  3,  2,  1 }; // number of GBTx ROBs on module
+//const Int_t GbtxPerRob[NofModuleTypes]    = {103,103,103,103,107,103,103,103 }; // number of GBTx ASICs on ROB
+//
+//const Int_t GbtxPerModule[NofModuleTypes] = {   12,  6,  3,  0,  0,  9,  6,  3 }; // for .geo.info - TODO: merge with above GbtxPerRob
+//const Int_t RobTypeOnModule[NofModuleTypes]={ 3333, 33,  3,  0,  0,333, 33,  3 }; // for .geo.info - TODO: merge with above GbtxPerRob
+
+//// v17b
+//const Int_t RobsPerModule[NofModuleTypes] = {  5,  3,  2,  1,  2,  3,  2,  1 }; // number of GBTx ROBs on module
+//const Int_t GbtxPerRob[NofModuleTypes]    = {103,103,103,103,107,103,103,103 }; // number of GBTx ASICs on ROB
+//
+//const Int_t GbtxPerModule[NofModuleTypes] = {   15,  9,  6,  0,  0,  9,  6,  3 }; // for .geo.info - TODO: merge with above GbtxPerRob
+//const Int_t RobTypeOnModule[NofModuleTypes]={33333,333, 33,  0,  0,333, 33,  3 }; // for .geo.info - TODO: merge with above GbtxPerRob
+
+//v17a // GBTx ROB definitions
+//v17a const Int_t RobsPerModule[NofModuleTypes] = {  3,  2,  1,  1,  2,  2,  1,  1 }; // number of GBTx ROBs on module
+//v17a const Int_t GbtxPerRob[NofModuleTypes]    = {105,105,105,103,107,105,105,103 }; // number of GBTx ASICs on ROB
+//v17a
+//v17a const Int_t GbtxPerModule[NofModuleTypes] = { 15, 10,  5,  0,  0, 10,  5,  3 }; // for .geo.info - TODO: merge with above GbtxPerRob
+//v17a const Int_t RobTypeOnModule[NofModuleTypes]={555, 55,  5,  0,  0, 55,  5,  3 }; // for .geo.info - TODO: merge with above GbtxPerRob
+
+//const Int_t RobsPerModule[NofModuleTypes] = {  2,  2,  1,  1,  2,  2,  1,  1 }; // number of GBTx ROBs on module
+//const Int_t GbtxPerRob[NofModuleTypes]    = {107,105,105,103,107,105,105,103 }; // number of GBTx ASICs on ROB
+//const Int_t GbtxPerModule[NofModuleTypes] = { 14,  8,  5,  0,  0, 10,  5,  3 }; // for .geo.info - TODO: merge with above GbtxPerRob
+//const Int_t RobTypeOnModule[NofModuleTypes] = { 77, 53,  5,  0,  0, 55,  5,  3 }; // for .geo.info - TODO: merge with above GbtxPerRob
+
+// super density for type 1 modules - 2017 - 540 mm
+//// v17d
+//const Int_t FebsPerModule[NofModuleTypes] = {  8,  4,  4,  4, 12,  9,  6,  3 }; // number of FEBs on backside
+//const Int_t AsicsPerFeb[NofModuleTypes]   = {210,210,210,105,108,107,107,107 }; // %100 gives number of ASICs on FEB, /100 gives grouping
+
+// v17l - 96 cm
+//const Int_t FebsPerModule[NofModuleTypes] = {  8,  4,  2,  4, 12,  8,  6,  4 }; // number of FEBs on backside
+//const Int_t FebsPerModule[NofModuleTypes] = {  8,  4,  2,  4, 12,  8,  6,  2 }; // number of FEBs on backside
+const Int_t FebsPerModule[NofModuleTypes] = {8, 4, 2, 4, 12, 12, 4, 4};  // number of FEBs on backside
+const Int_t AsicsPerFeb[NofModuleTypes]   = {210, 210, 210, 105, 109,
+                                           109, 109, 109};  // %100 gives number of ASICs on FEB, /100 gives grouping
+
+//// v17c
+//const Int_t FebsPerModule[NofModuleTypes] = {  8,  4,  2,  4, 12,  9,  6,  3 }; // number of FEBs on backside
+//const Int_t AsicsPerFeb[NofModuleTypes]   = {210,210,210,105,108,107,107,107 }; // %100 gives number of ASICs on FEB, /100 gives grouping
+
+//// v17b
+//const Int_t FebsPerModule[NofModuleTypes] = {  10,  6,  4,  4, 12,  9,  6,  3 }; // number of FEBs on backside
+//const Int_t AsicsPerFeb[NofModuleTypes]   = {210,210,210,105,108,107,107,107 }; // %100 gives number of ASICs on FEB, /100 gives grouping
+// v17a // super density for type 1 modules - 2017 - 540 mm
+// v17a //const Int_t FebsPerModule[NofModuleTypes] = {  9,  5,  6,  4, 12,  8,  4,  3 }; // number of FEBs on backside
+// v17a const Int_t FebsPerModule[NofModuleTypes] = {  9,  6,  3,  4, 12,  8,  4,  3 }; // number of FEBs on backside
+// v17a const Int_t AsicsPerFeb[NofModuleTypes]   = {210,210,210,105,108,108,108,108 }; // %100 gives number of ASICs on FEB, /100 gives grouping
+//// ultimate density - 540 mm
+//const Int_t FebsPerModule[NofModuleTypes] = {  6,  5,  6,  4, 12,  8,  4,  3 }; // number of FEBs on backside - reduced FEBs (64 ch ASICs)
+//const Int_t AsicsPerFeb[NofModuleTypes]   = {315,210,105,105,108,108,108,108 }; //  %100 gives number of ASICs on FEB, /100 gives grouping
+////const Int_t FebsPerModule[NofModuleTypes] = {  6,  5,  3,  2,  6,  3,  4,  3 }; // min number of FEBs // number of FEBs on backside - reduced FEBs (64 ch ASICs)
+////const Int_t AsicsPerFeb[NofModuleTypes]   = {315,210,210,210,216,216,108,108 }; //  %100 gives number of ASICs on FEB, /100 gives grouping
+////const Int_t AsicsPerFeb[NofModuleTypes]   = {216,210,210,210,216,216,108,108 }; //  %100 gives number of ASICs on FEB, /100 gives grouping
+//
+////// super density - 540 mm
+//const Int_t FebsPerModule[NofModuleTypes] = {  9,  5,  6,  4, 12,  6,  4,  3 }; // light // number of FEBs on backside - reduced FEBs (64 ch ASICs)
+//const Int_t AsicsPerFeb[NofModuleTypes]   = {210,210,105,105,108,108,108,108 }; // %100 gives number of ASICs on FEB, /100 gives grouping
+//
+//// normal density - 540 mm
+//const Int_t FebsPerModule[NofModuleTypes] = { 18, 10,  6,  4, 12,  6,  4,  3 }; // number of FEBs on backside (linked to pad layout) - mod4 = mod3, therefore same
+//const Int_t AsicsPerFeb[NofModuleTypes]   = {105,105,105,105,108,108,108,108 }; // %100 gives number of ASICs on FEB, /100 gives grouping
+
+// ultimate density - 570 mm
+//const Int_t FebsPerModule[NofModuleTypes] = {  6,  5,  3,  2,  5,  3,  2,  1 }; // min number of FEBs // number of FEBs on backside - reduced FEBs (64 ch ASICs)
+//const Int_t AsicsPerFeb[NofModuleTypes]   = {216,210,210,210,216,216,216,216 }; //  %100 gives number of ASICs on FEB, /100 gives grouping
+//
+//const Int_t FebsPerModule[NofModuleTypes] = {  6,  5,  3,  3, 10,  5,  3,  3 }; // min (6) module types // number of FEBs on backside - reduced FEBs (64 ch ASICs)
+//const Int_t AsicsPerFeb[NofModuleTypes]   = {216,210,210,210,108,108,108,108 }; //  %100 gives number of ASICs on FEB, /100 gives grouping
+//// super density - 570 mm
+//const Int_t FebsPerModule[NofModuleTypes] = { 10,  5,  5,  5, 12,  6,  4,  3 }; // light // number of FEBs on backside - reduced FEBs (64 ch ASICs)
+//const Int_t AsicsPerFeb[NofModuleTypes]   = {210,210,105,105,108,108,108,108 }; // %100 gives number of ASICs on FEB, /100 gives grouping
+//
+//// normal density - 570 mm
+//const Int_t FebsPerModule[NofModuleTypes] = { 19, 10,  5,  5, 12,  6,  4,  3 }; // number of FEBs on backside (linked to pad layout) - mod4 = mod3, therefore same
+//const Int_t AsicsPerFeb[NofModuleTypes]   = {105,105,105,105,108,108,108,108 }; // %100 gives number of ASICs on FEB, /100 gives grouping
+
+
+/* TODO: activate connector grouping info below
+// ultimate - grouping of pads to connectors
+const Int_t RowsPerConnector[NofModuleTypes]  = {  6,  4,  2,  2,  2,  2,  2,  2 };
+const Int_t ColsPerConnector[NofModuleTypes]  = { 16, 16, 16, 16, 16, 16, 16, 16 };
+// super    - grouping of pads to connectors
+const Int_t RowsPerConnector[NofModuleTypes]  = {  4,  4,  2,  2,  2,  2,  2,  2 };
+const Int_t ColsPerConnector[NofModuleTypes]  = { 16, 16, 16, 16, 16, 16, 16, 16 };
+// normal   - grouping of pads to connectors
+const Int_t RowsPerConnector[NofModuleTypes]  = {  2,  2,  2,  2,  2,  2,  2,  2 };
+const Int_t ColsPerConnector[NofModuleTypes]  = { 16, 16, 16, 16, 16, 16, 16, 16 };
+*/
+
+
+const Double_t feb_z_offset = 0.1;  // 1 mm - offset in z of FEBs to backpanel
+const Double_t asic_offset  = 0.1;  // 1 mm - offset of ASICs to FEBs to avoid overlaps
+
+// ASIC parameters
+Double_t asic_distance;
+
+//const Double_t FrameWidth[2]    = { 1.5, 2.0 };   // Width of detector frames in cm
+const Double_t FrameWidth[2] = {1.5, 1.5};  // Width of detector frames in cm
+// mini - production
+const Double_t DetectorSizeX[2] = {57., 99.};  // => 54 x 54 cm2 & 96 x 96 cm2 active area
+const Double_t DetectorSizeY[2] = {57., 99.};  // quadratic modules
+// 108 cm const Double_t DetectorSizeX[2] = { 57., 111.};   // => 54 x 54 cm2 & 108 x 108 cm2 active area
+// 108 cm const Double_t DetectorSizeY[2] = { 57., 111.};   // quadratic modules
+//// default
+//const Double_t DetectorSizeX[2] = { 60., 100.};   // => 57 x 57 cm2 & 96 x 96 cm2 active area
+//const Double_t DetectorSizeY[2] = { 60., 100.};   // quadratic modules
+
+// Parameters tor the lattice grid reinforcing the entrance window
+//const Double_t lattice_o_width[2] = { 1.5, 2.0 };   // Width of outer lattice frame in cm
+const Double_t lattice_o_width[2] = {1.5, 1.5};  // Width of outer lattice frame in cm
+const Double_t lattice_i_width[2] = {0.2, 0.2};  // { 0.4, 0.4 };   // Width of inner lattice frame in cm
+// Thickness (in z) of lattice frames in cm - see below
+
+// statistics
+Int_t ModuleStats[MaxLayers][NofModuleTypes] = {0};
+
+// z - geometry of TRD modules
+//const Double_t radiator_thickness     =  35.0;    // 35 cm thickness of radiator
+const Double_t radiator_thickness = 30.0;  // 30 cm thickness of radiator + shift pad plane to integer multiple of 1 mm
+const Double_t radiator_position  = -LayerThickness / 2. + radiator_thickness / 2.;
+
+//const Double_t lattice_thickness      =   1.0;  // 1.0;  // 10 mm thick lattice frames
+const Double_t lattice_thickness = 1.0 - 0.0025;  // 0.9975;  // 1.0;  // 10 mm thick lattice frames
+const Double_t lattice_position  = radiator_position + radiator_thickness / 2. + lattice_thickness / 2.;
+
+const Double_t kapton_thickness = 0.0025;  //  25 micron thickness of kapton
+const Double_t kapton_position  = lattice_position + lattice_thickness / 2. + kapton_thickness / 2.;
+
+const Double_t gas_thickness = 1.2;  //  12 mm thickness of gas
+const Double_t gas_position  = kapton_position + kapton_thickness / 2. + gas_thickness / 2.;
+
+// frame thickness
+const Double_t frame_thickness = gas_thickness;  // frame covers gas volume: from kapton foil to pad plane
+const Double_t frame_position =
+  -LayerThickness / 2. + radiator_thickness + lattice_thickness + kapton_thickness + frame_thickness / 2.;
+
+// pad plane
+const Double_t padcopper_thickness = 0.0025;  //  25 micron thickness of copper pads
+const Double_t padcopper_position  = gas_position + gas_thickness / 2. + padcopper_thickness / 2.;
+
+const Double_t padplane_thickness = 0.0360;  // 360 micron thickness of padplane
+const Double_t padplane_position  = padcopper_position + padcopper_thickness / 2. + padplane_thickness / 2.;
+
+// backpanel components
+const Double_t carbon_thickness = 0.0190 * 2;  // use 2 layers!!   // 190 micron thickness for 1 layer of carbon fibers
+const Double_t honeycomb_thickness = 2.3 - kapton_thickness - padcopper_thickness - padplane_thickness
+                                     - carbon_thickness;  //  ~ 2.3 mm thickness of honeycomb
+const Double_t honeycomb_position = padplane_position + padplane_thickness / 2. + honeycomb_thickness / 2.;
+const Double_t carbon_position    = honeycomb_position + honeycomb_thickness / 2. + carbon_thickness / 2.;
+
+// aluminium thickness
+const Double_t aluminium_thickness = 0.4;  // crossbar of 1 x 1 cm at every module edge
+const Double_t aluminium_width     = 1.0;  // crossbar of 1 x 1 cm at every module edge
+const Double_t aluminium_position  = carbon_position + carbon_thickness / 2. + aluminium_thickness / 2.;
+
+// power bus bars
+const Double_t powerbar_thickness = 1.0;  // 1 cm in z direction
+const Double_t powerbar_width     = 2.0;  // 2 cm in x/y direction
+const Double_t powerbar_position  = aluminium_position + aluminium_thickness / 2. + powerbar_thickness / 2.;
+
+// readout boards
+//const  Double_t feb_width           =  10.0;    // width of FEBs in cm
+const Double_t feb_width          = 8.5;   // width of FEBs in cm
+const Double_t feb_thickness      = 0.25;  // light //  2.5 mm thickness of FEBs
+const Double_t febvolume_position = aluminium_position + aluminium_thickness / 2. + feb_width / 2.;
+
+// ASIC parameters
+const Double_t asic_thickness = 0.25;  // 2.5 mm asic_thickness
+const Double_t asic_width     = 3.0;   // 2.0;  1.0;   // 1 cm
+
+
+// Names of the different used materials which are used to build the modules
+// The materials are defined in the global media.geo file
+const TString KeepingVolumeMedium   = "air";
+const TString RadiatorVolumeMedium  = "TRDpefoam20";
+const TString LatticeVolumeMedium   = "TRDG10";
+const TString KaptonVolumeMedium    = "TRDkapton";
+const TString GasVolumeMedium       = "TRDgas";
+const TString PadCopperVolumeMedium = "TRDcopper";
+const TString PadPcbVolumeMedium    = "TRDG10";  // todo - put correct FEB material here
+const TString HoneycombVolumeMedium = "TRDaramide";
+const TString CarbonVolumeMedium    = "TRDcarbon";
+const TString FebVolumeMedium       = "TRDG10";  // todo - put correct FEB material here
+const TString AsicVolumeMedium      = "air";     // todo - put correct ASIC material here
+const TString TextVolumeMedium      = "air";     // leave as air
+const TString FrameVolumeMedium     = "TRDG10";
+const TString PowerBusVolumeMedium  = "TRDcopper";  // power bus bars
+const TString AluLegdeVolumeMedium  = "aluminium";  // aluminium frame around backpanel
+const TString AluminiumVolumeMedium = "aluminium";
+//const TString MylarVolumeMedium       = "mylar";
+//const TString RadiatorVolumeMedium    = "polypropylene";
+//const TString ElectronicsVolumeMedium = "goldcoatedcopper";
+
+
+// some global variables
+TGeoManager* gGeoMan = NULL;           // Pointer to TGeoManager instance
+TGeoVolume* gModules[NofModuleTypes];  // Global storage for module types
+
+// Forward declarations
+void create_materials_from_media_file();
+TGeoVolume* create_trd_module_type(Int_t moduleType);
+void create_detector_layers(Int_t layer);
+void create_power_bars_vertical();
+void create_power_bars_horizontal();
+void create_xtru_supports();
+void create_box_supports();
+void add_trd_labels(TGeoVolume*, TGeoVolume*, TGeoVolume*);
+void create_mag_field_vector();
+void dump_info_file();
+void dump_digi_file();
+
+
+//void Create_TRD_Geometry_v20b(const Int_t setupid = 1) {
+void Create_TRD_Geometry_v20c()
+{
+
+  // declare TRD layer layout
+  if (setupid > 2)
+    for (Int_t i = 0; i < MaxLayers; i++)
+      ShowLayer[i] = 1;  // show all layers
+
+  // Load needed material definition from media.geo file
+  create_materials_from_media_file();
+
+  // Position the layers in z
+  for (Int_t iLayer = 1; iLayer < MaxLayers; iLayer++)
+    LayerPosition[iLayer] =
+      LayerPosition[iLayer - 1] + LayerThickness + LayerOffset[iLayer];  // add offset for extra gaps
+
+  // Get the GeoManager for later usage
+  gGeoMan = (TGeoManager*) gROOT->FindObject("FAIRGeom");
+  gGeoMan->SetVisLevel(10);
+
+  // Create the top volume
+  TGeoBBox* topbox = new TGeoBBox("", 1000., 1000., 2000.);
+  TGeoVolume* top  = new TGeoVolume("top", topbox, gGeoMan->GetMedium("air"));
+  gGeoMan->SetTopVolume(top);
+
+  TGeoVolume* trd = new TGeoVolumeAssembly(geoVersion);
+  top->AddNode(trd, 1);
+
+  for (Int_t iModule = 0; iModule < NofModuleTypes; iModule++) {
+    Int_t moduleType  = iModule + 1;
+    gModules[iModule] = create_trd_module_type(moduleType);
+  }
+
+  Int_t nLayer = 0;  // active layer counter
+  for (Int_t iLayer = 0; iLayer < MaxLayers; iLayer++) {
+    //    if ((iLayer != 0) && (iLayer != 3))  continue;  // first layer only - comment later on
+    //    if (iLayer != 0) continue;  // first layer only - comment later on
+    if (ShowLayer[iLayer]) {
+      PlaneId[iLayer] = ++nLayer;
+      create_detector_layers(iLayer);
+      //      printf("calling layer %2d\n",iLayer);
+    }
+  }
+
+  // TODO: remove or comment out
+  // test PlaneId
+  printf("generated TRD layers: ");
+  for (Int_t iLayer = 0; iLayer < MaxLayers; iLayer++)
+    if (ShowLayer[iLayer]) printf(" %2d", PlaneId[iLayer]);
+  printf("\n");
+
+  if (IncludeSupports) { create_box_supports(); }
+
+  if (IncludePowerbars) {
+    create_power_bars_vertical();
+    create_power_bars_horizontal();
+  }
+
+  if (IncludeFieldVector) create_mag_field_vector();
+
+  gGeoMan->CloseGeometry();
+  //  gGeoMan->CheckOverlaps(0.001);
+  //  gGeoMan->PrintOverlaps();
+  gGeoMan->Test();
+
+  trd->Export(FileNameSim);  // an alternative way of writing the trd volume
+
+  TFile* outfile = new TFile(FileNameSim, "UPDATE");
+  //  TGeoTranslation* trd_placement = new TGeoTranslation("trd_trans", 0., 0., 0.);
+  TGeoTranslation* trd_placement = new TGeoTranslation("trd_trans", 0., 0., zfront[setupid]);
+  trd_placement->Write();
+  outfile->Close();
+
+  outfile = new TFile(FileNameGeo, "RECREATE");
+  gGeoMan->Write();  // use this is you want GeoManager format in the output
+  outfile->Close();
+
+  dump_info_file();
+  dump_digi_file();
+
+  //  top->Draw("ogl");
+
+  //top->Raytrace();
+
+  //  cout << "Press Return to exit" << endl;
+  //  cin.get();
+  //  exit();
+}
+
+
+//==============================================================
+void dump_digi_file()
+{
+  TDatime datetime;  // used to get timestamp
+
+  const Double_t ActiveAreaX[2] = {DetectorSizeX[0] - 2 * FrameWidth[0], DetectorSizeX[1] - 2 * FrameWidth[1]};
+  const Int_t NofSectors        = 3;
+  // v17b
+  //  const Int_t NofPadsInRow[2]  = { 80, 112 };  //  7 // number of pads in rows
+  //  const Int_t NofPadsInRow[2]  = { 80, 128 };  //  8 // number of pads in rows
+  const Int_t NofPadsInRow[2] = {80, 144};  //  9 // number of pads in rows
+  //  const Int_t NofPadsInRow[2]  = { 80, 160 };  // 10 // number of pads in rows
+  Int_t nrow = 0;  // number of rows in module
+
+  const Double_t PadHeightInSector[NofModuleTypes][NofSectors] =  // pad height
+    {//v17b {  1.25,  1.50,  1.25 },   // module type 1 -  1.01 cm2
+     //v17b {  2.25,  2.25,  2.25 },   // module type 2 -  1.52 cm2
+     //v17b {  3.25,  3.50,  3.25 },   // module type 3 -  2.36 cm2
+
+     {1.50, 1.75, 1.50},  // module type 1 -  1.18 cm2
+     {3.25, 3.50, 3.25},  // module type 2 -  2.36 cm2
+     {6.75, 6.75, 6.75},  // module type 3 -  4.56 cm2
+     {6.75, 6.75, 6.75},  // module type 4 -
+
+     // 108 cm          {  2.25,  2.25,  2.25 },   // module type 5 -
+     // 108 cm          {  4.50,  4.50,  4.50 },   // module type 6 -  4.52 cm2
+     // 108 cm          {  9.00,  9.00,  9.00 },   // module type 7 -  6.37 cm2
+     // 108 cm          { 18.00, 18.00, 18.00 } }; // module type 8 - 12.73 cm2
+
+     {4.00, 4.00, 4.00},      // module type 5 -  2.67 cm2
+     {6.00, 6.00, 6.00},      // module type 6 -  4.00 cm2
+     {12.00, 12.00, 12.00},   // module type 7 -  8.00 cm2
+     {24.00, 24.00, 24.00}};  // module type 8 - 16.00 cm2
+
+  //          {  3.75,  4.00,  3.75 },   // module type 5 -
+  //          {  5.00,  5.50,  5.00 },   // module type 6 -  4.52 cm2
+  //          {  7.50,  7.75,  7.50 },   // module type 7 -  6.37 cm2
+  //          { 15.25, 15.50, 15.25 } }; // module type 8 - 12.73 cm2
+
+  const Int_t NofRowsInSector[NofModuleTypes][NofSectors] =
+    // number of rows per sector
+    {//v17b {  12,  16,  12 },         // module type 1
+     //v17b {   8,   8,   8 },         // module type 2
+     //v17b {   4,   8,   4 },         // module type 3
+
+     {4, 24, 4},  // module type 1
+     {4, 8, 4},   // module type 2
+     {2, 4, 2},   // module type 3
+     {2, 4, 2},   // module type 4
+
+     {8, 8, 8},   // module type 5
+     {6, 4, 6},   // module type 6
+     {2, 4, 2},   // module type 7
+     {1, 2, 1}};  // module type 8
+
+  //          {   8,   8,   8 },         // module type 5
+  //          {   4,   8,   4 },         // module type 6
+  //          {   2,   8,   2 },         // module type 7
+  //          {   2,   2,   2 } };       // module type 8
+
+  // v17a   const Int_t NofPadsInRow[2]  = { 80, 128 };  // number of pads in rows
+  // v17a   Int_t nrow = 0;   // number of rows in module
+  // v17a
+  // v17a   const Double_t PadHeightInSector[NofModuleTypes][NofSectors] =  // pad height
+  // v17a         { {  1.50,  1.50,  1.50 },   // module type 1 -  1.01 cm2
+  // v17a           {  2.25,  2.25,  2.25 },   // module type 2 -  1.52 cm2
+  // v17a //          {  2.75,  2.50,  2.75 },   // module type 2 -  1.86 cm2
+  // v17a           {  4.50,  4.50,  4.50 },   // module type 3 -  3.04 cm2
+  // v17a           {  6.75,  6.75,  6.75 },   // module type 4 -  4.56 cm2
+  // v17a
+  // v17a           {  3.75,  4.00,  3.75 },   // module type 5 -  2.84 cm2
+  // v17a           {  5.75,  5.75,  5.75 },   // module type 6 -  4.13 cm2
+  // v17a           { 11.50, 11.50, 11.50 },   // module type 7 -  8.26 cm2
+  // v17a           { 15.25, 15.50, 15.25 } }; // module type 8 - 11.14 cm2
+  // v17a //          {  7.50,  7.75,  7.50 },   // module type 6 -  5.51 cm2
+  // v17a //          {  5.50,  5.75,  5.50 },   // module type 6 -  4.09 cm2
+  // v17a //          { 11.25, 11.50, 11.25 },   // module type 7 -  8.18 cm2
+  // v17a
+  // v17a   const Int_t NofRowsInSector[NofModuleTypes][NofSectors] =   // number of rows per sector
+  // v17a         { {  12,  12,  12 },         // module type 1
+  // v17a           {   8,   8,   8 },         // module type 2
+  // v17a //          {   8,   4,   8 },         // module type 2
+  // v17a           {   4,   4,   4 },         // module type 3
+  // v17a           {   2,   4,   2 },         // module type 4
+  // v17a
+  // v17a           {   8,   8,   8 },         // module type 5
+  // v17a           {   4,   8,   4 },         // module type 6
+  // v17a           {   2,   4,   2 },         // module type 7
+  // v17a           {   2,   2,   2 } };       // module type 8
+  // v17a //          {  10,   4,  10 },         // module type 5
+  // v17a //          {   4,   4,   4 },         // module type 6
+  // v17a //          {   2,  12,   2 },         // module type 6
+  // v17a //          {   2,   4,   2 },         // module type 7
+  // v17a //          {   2,   2,   2 } };       // module type 8
+  // v17a
+
+  Double_t HeightOfSector[NofModuleTypes][NofSectors];
+  Double_t PadWidth[NofModuleTypes];
+
+  // calculate pad width
+  for (Int_t im = 0; im < NofModuleTypes; im++)
+    PadWidth[im] = ActiveAreaX[ModuleType[im]] / NofPadsInRow[ModuleType[im]];
+
+  // calculate height of sectors
+  for (Int_t im = 0; im < NofModuleTypes; im++)
+    for (Int_t is = 0; is < NofSectors; is++)
+      HeightOfSector[im][is] = NofRowsInSector[im][is] * PadHeightInSector[im][is];
+
+  // check, if the entire module size is covered by pads
+  for (Int_t im = 0; im < NofModuleTypes; im++)
+    if (ActiveAreaX[ModuleType[im]] - (HeightOfSector[im][0] + HeightOfSector[im][1] + HeightOfSector[im][2]) != 0) {
+      printf("WARNING: sector size does not add up to module size for module "
+             "type %d\n",
+             im + 1);
+      printf("%.2f = %.2f + %.2f + %.2f\n", ActiveAreaX[ModuleType[im]], HeightOfSector[im][0], HeightOfSector[im][1],
+             HeightOfSector[im][2]);
+      exit(1);
+    }
+
+  //==============================================================
+
+  printf("writing trd pad information file: %s\n", FileNamePads.Data());
+
+  FILE* ifile;
+  ifile = fopen(FileNamePads.Data(), "w");
+
+  if (ifile == NULL) {
+    printf("error opening %s\n", FileNamePads.Data());
+    exit(1);
+  }
+
+  fprintf(ifile, "//\n");
+  fprintf(ifile, "//   TRD pad layout for geometry %s\n", tagVersion.Data());
+  fprintf(ifile, "//\n");
+  fprintf(ifile, "// automatically generated by Create_TRD_Geometry_%s%s.C\n", tagVersion.Data(), subVersion.Data());
+  fprintf(ifile, "// created %d\n", datetime.GetDate());
+  fprintf(ifile, "//\n");
+
+  fprintf(ifile, "\n");
+  fprintf(ifile, "#ifndef CBMTRDPADS_H\n");
+  fprintf(ifile, "#define CBMTRDPADS_H\n");
+  fprintf(ifile, "\n");
+  fprintf(ifile, "Int_t fst1_sect_count = 3;\n");
+  fprintf(ifile, "// array of pad geometries in the TRD (trd1mod[1-8])\n");
+  fprintf(ifile, "// 8 modules  // 3 sectors  // 4 values \n");
+  fprintf(ifile, "Float_t fst1_pad_type[8][3][4] =        \n");
+  //fprintf(ifile,"Double_t fst1_pad_type[8][3][4] =       \n");
+  fprintf(ifile, "			 		 \n");
+
+  for (Int_t im = 0; im < NofModuleTypes; im++) {
+    if (im + 1 == 5) fprintf(ifile, "//---\n\n");
+    fprintf(ifile, "// module type %d\n", im + 1);
+
+    // number of pads
+    nrow = 0;  // reset number of pad rows to 0
+    for (Int_t is = 0; is < NofSectors; is++)
+      nrow += HeightOfSector[im][is] / PadHeightInSector[im][is];  // add number of rows in this sector
+    fprintf(ifile, "// number of pads: %3d x %2d = %4d\n", NofPadsInRow[ModuleType[im]], nrow,
+            NofPadsInRow[ModuleType[im]] * nrow);
+
+    // pad size
+    fprintf(ifile, "// pad size sector 1: %5.2f cm x %5.2f cm = %5.2f cm2\n", PadWidth[im], PadHeightInSector[im][1],
+            PadWidth[im] * PadHeightInSector[im][1]);
+    fprintf(ifile, "// pad size sector 0: %5.2f cm x %5.2f cm = %5.2f cm2\n", PadWidth[im], PadHeightInSector[im][0],
+            PadWidth[im] * PadHeightInSector[im][0]);
+
+    for (Int_t is = 0; is < NofSectors; is++) {
+      if ((im == 0) && (is == 0)) fprintf(ifile, "  { { ");
+      else if (is == 0)
+        fprintf(ifile, "    { ");
+      else
+        fprintf(ifile, "      ");
+
+      fprintf(ifile, "{ %.1f, %5.2f, %.1f/%3d, %5.2f }", ActiveAreaX[ModuleType[im]], HeightOfSector[im][is],
+              ActiveAreaX[ModuleType[im]], NofPadsInRow[ModuleType[im]], PadHeightInSector[im][is]);
+
+      if ((im == NofModuleTypes - 1) && (is == 2)) fprintf(ifile, " } };");
+      else if (is == 2)
+        fprintf(ifile, " },");
+      else
+        fprintf(ifile, ",");
+
+      fprintf(ifile, "\n");
+    }
+
+    fprintf(ifile, "\n");
+  }
+
+  fprintf(ifile, "#endif\n");
+
+  //  Int_t im = 0;
+  //  fprintf(ifile,"// module type %d	 		   \n", im+1);
+  //  fprintf(ifile,"  { { { %.1f, %5.2f, %.1f/%3d, %5.2f },    \n", ActiveAreaX[ModuleType[im]], HeightOfSector[im][0], ActiveAreaX[ModuleType[im]], NofPadsInRow[ModuleType[im]], PadHeightInSector[im][0]);
+  //  fprintf(ifile,"      { %.1f, %5.2f, %.1f/%3d, %5.2f },    \n", ActiveAreaX[ModuleType[im]], HeightOfSector[im][1], ActiveAreaX[ModuleType[im]], NofPadsInRow[ModuleType[im]], PadHeightInSector[im][1]);
+  //  fprintf(ifile,"      { %.1f, %5.2f, %.1f/%3d, %5.2f } },  \n", ActiveAreaX[ModuleType[im]], HeightOfSector[im][2], ActiveAreaX[ModuleType[im]], NofPadsInRow[ModuleType[im]], PadHeightInSector[im][2]);
+  //  fprintf(ifile,"\n");
+  //
+  //  for (Int_t im = 1; im < NofModuleTypes-1; im++)
+  //  {
+  //    fprintf(ifile,"// module type %d	 		     \n", im+1);
+  //    fprintf(ifile,"    { { %.1f, %5.2f, %.1f/%3d, %5.2f },    \n", ActiveAreaX[ModuleType[im]], HeightOfSector[im][0], ActiveAreaX[ModuleType[im]], NofPadsInRow[ModuleType[im]], PadHeightInSector[im][0]);
+  //    fprintf(ifile,"      { %.1f, %5.2f, %.1f/%3d, %5.2f },    \n", ActiveAreaX[ModuleType[im]], HeightOfSector[im][1], ActiveAreaX[ModuleType[im]], NofPadsInRow[ModuleType[im]], PadHeightInSector[im][1]);
+  //    fprintf(ifile,"      { %.1f, %5.2f, %.1f/%3d, %5.2f } },  \n", ActiveAreaX[ModuleType[im]], HeightOfSector[im][2], ActiveAreaX[ModuleType[im]], NofPadsInRow[ModuleType[im]], PadHeightInSector[im][2]);
+  //    fprintf(ifile,"\n");
+  //  }
+  //
+  //  Int_t im = 7;
+  //  fprintf(ifile,"// module type %d	 		   \n", im+1);
+  //  fprintf(ifile,"    { { %.1f, %5.2f, %.1f/%3d, %5.2f },    \n", ActiveAreaX[ModuleType[im]], HeightOfSector[im][0], ActiveAreaX[ModuleType[im]], NofPadsInRow[ModuleType[im]], PadHeightInSector[im][0]);
+  //  fprintf(ifile,"      { %.1f, %5.2f, %.1f/%3d, %5.2f },    \n", ActiveAreaX[ModuleType[im]], HeightOfSector[im][1], ActiveAreaX[ModuleType[im]], NofPadsInRow[ModuleType[im]], PadHeightInSector[im][1]);
+  //  fprintf(ifile,"      { %.1f, %5.2f, %.1f/%3d, %5.2f } } };\n", ActiveAreaX[ModuleType[im]], HeightOfSector[im][2], ActiveAreaX[ModuleType[im]], NofPadsInRow[ModuleType[im]], PadHeightInSector[im][2]);
+  //  fprintf(ifile,"\n");
+
+  fclose(ifile);
+}
+
+
+void dump_info_file()
+{
+  TDatime datetime;  // used to get timestamp
+
+  Double_t z_first_layer = 2000;  // z position of first layer (front)
+  Double_t z_last_layer  = 0;     // z position of last  layer (front)
+
+  Double_t xangle;   // horizontal angle
+  Double_t yangle;   // vertical   angle for inner modules
+  Double_t yangleo;  // vertical   angle for outer modules
+
+  Double_t total_surface = 0;  // total surface
+  Double_t total_actarea = 0;  // total active area
+
+  Int_t channels_per_module[NofModuleTypes + 1] = {0};  // number of channels per module
+  Int_t channels_per_feb[NofModuleTypes + 1]    = {0};  // number of channels per feb
+  Int_t asics_per_module[NofModuleTypes + 1]    = {0};  // number of asics per module
+
+  Int_t total_modules[NofModuleTypes + 1]  = {0};  // total number of modules
+  Int_t total_febs[NofModuleTypes + 1]     = {0};  // total number of febs
+  Int_t total_asics[NofModuleTypes + 1]    = {0};  // total number of asics
+  Int_t total_gbtx[NofModuleTypes + 1]     = {0};  // total number of gbtx
+  Int_t total_rob3[NofModuleTypes + 1]     = {0};  // total number of gbtx rob3
+  Int_t total_rob5[NofModuleTypes + 1]     = {0};  // total number of gbtx rob5
+  Int_t total_rob7[NofModuleTypes + 1]     = {0};  // total number of gbtx rob7
+  Int_t total_channels[NofModuleTypes + 1] = {0};  // total number of channels
+
+  Int_t total_channels_u = 0;  // total number of ultimate channels
+  Int_t total_channels_s = 0;  // total number of super    channels
+  Int_t total_channels_r = 0;  // total number of regular  channels
+
+  printf("writing summary information file: %s\n", FileNameInfo.Data());
+
+  FILE* ifile;
+  ifile = fopen(FileNameInfo.Data(), "w");
+
+  if (ifile == NULL) {
+    printf("error opening %s\n", FileNameInfo.Data());
+    exit(1);
+  }
+
+  fprintf(ifile, "#\n##   %s information file\n#\n\n", geoVersion.Data());
+
+  fprintf(ifile, "# created %d\n\n", datetime.GetDate());
+
+  // determine first and last TRD layer
+  for (Int_t iLayer = 0; iLayer < MaxLayers; iLayer++) {
+    if (ShowLayer[iLayer]) {
+      if (z_first_layer > LayerPosition[iLayer]) z_first_layer = LayerPosition[iLayer];
+      if (z_last_layer < LayerPosition[iLayer]) z_last_layer = LayerPosition[iLayer];
+    }
+  }
+
+  fprintf(ifile, "# position\n");
+  // Show position of TRD
+  fprintf(ifile, "%4f cm z-front position of TRD in hadron   setup\n", zfront[0]);
+  fprintf(ifile, "%4f cm z-front position of TRD in electron setup\n", zfront[1]);
+  fprintf(ifile, "%4f cm z-front position of TRD in muon     setup\n", zfront[2]);
+  fprintf(ifile, "\n");
+
+  //  fprintf(ifile, "# envelope\n");
+  fprintf(ifile, "# detector thickness\n");
+  // Show extension of TRD
+  //  fprintf(ifile, "%4f cm   start of TRD (z)\n", z_first_layer);
+  fprintf(ifile, "%4f cm   end   of TRD (z)\n", z_last_layer + LayerThickness);
+  fprintf(ifile, "\n");
+
+  // Layer thickness
+  fprintf(ifile, "# layer thickness\n");
+  fprintf(ifile, "%4f cm   per single layer (z)\n", LayerThickness);
+  fprintf(ifile, "\n");
+
+  // Show extra gaps
+  fprintf(ifile, "# extra gaps\n ");
+  for (Int_t iLayer = 0; iLayer < MaxLayers; iLayer++)
+    if (ShowLayer[iLayer]) fprintf(ifile, "%3f ", LayerOffset[iLayer]);
+  fprintf(ifile, "   extra gaps in z (cm)\n");
+  fprintf(ifile, "\n");
+
+  // Show layer flags
+  fprintf(ifile, "# generated TRD layers\n ");
+  for (Int_t iLayer = 0; iLayer < MaxLayers; iLayer++)
+    if (ShowLayer[iLayer]) fprintf(ifile, "%2d ", PlaneId[iLayer]);
+  fprintf(ifile, "   planeID\n");
+  fprintf(ifile, "\n");
+
+  // Dimensions in x
+  fprintf(ifile, "# dimensions in x\n");
+  for (Int_t iLayer = 0; iLayer < MaxLayers; iLayer++)
+    if (ShowLayer[iLayer]) {
+      if (PlaneId[iLayer] < 5)
+        fprintf(ifile, "%5f cm to %5f cm x-dimension of layer %2d\n",
+                -(2.0 * DetectorSizeX[0] + 2.0 * DetectorSizeX[1]), 2.0 * DetectorSizeX[0] + 2.0 * DetectorSizeX[1],
+                PlaneId[iLayer]);
+      else {
+        if (PlaneId[iLayer] < 9)
+          fprintf(ifile, "%5f cm to %5f cm x-dimension of layer %2d\n", -4.5 * DetectorSizeX[1], 4.5 * DetectorSizeX[1],
+                  PlaneId[iLayer]);
+        else
+          fprintf(ifile, "%5f cm to %5f cm x-dimension of layer %2d\n", -5.5 * DetectorSizeX[1], 5.5 * DetectorSizeX[1],
+                  PlaneId[iLayer]);
+      }
+    }
+  fprintf(ifile, "\n");
+
+  // Dimensions in y
+  fprintf(ifile, "# dimensions in y inner modules\n");
+  for (Int_t iLayer = 0; iLayer < MaxLayers; iLayer++)
+    if (ShowLayer[iLayer]) {
+      if (PlaneId[iLayer] < 5)
+        fprintf(ifile, "%5f cm to %5f cm y-dimension of layer %2d\n", -4.5 * DetectorSizeY[0], 4.5 * DetectorSizeY[0],
+                PlaneId[iLayer]);
+      else {
+        if (PlaneId[iLayer] < 9)
+          fprintf(ifile, "%5f cm to %5f cm y-dimension of layer %2d\n", -3.5 * DetectorSizeY[1], 3.5 * DetectorSizeY[1],
+                  PlaneId[iLayer]);
+        else
+          fprintf(ifile, "%5f cm to %5f cm y-dimension of layer %2d\n", -4.5 * DetectorSizeY[1], 4.5 * DetectorSizeY[1],
+                  PlaneId[iLayer]);
+      }
+    }
+  fprintf(ifile, "\n");
+
+  // Dimensions in y
+  fprintf(ifile, "# dimensions in y outer modules\n");
+  for (Int_t iLayer = 0; iLayer < MaxLayers; iLayer++)
+    if (ShowLayer[iLayer]) {
+      if (PlaneId[iLayer] < 5)
+        fprintf(ifile, "%5f cm to %5f cm y-dimension of layer %2d\n", -2.5 * DetectorSizeY[1], 2.5 * DetectorSizeY[1],
+                PlaneId[iLayer]);
+    }
+  fprintf(ifile, "\n");
+
+  // angles
+  fprintf(ifile, "# angles of acceptance for inner + outer modules\n");
+
+  for (Int_t iLayer = 0; iLayer < MaxLayers; iLayer++)
+    if (ShowLayer[iLayer]) {
+      if (iLayer < 4) {
+        //        fprintf(ifile,"y %10.4f cm   x %10.4f cm\n", 2.5 * DetectorSizeY[1], 3.5 * DetectorSizeX[1]);
+        yangle = atan(4.5 * DetectorSizeY[0]
+                      / (zfront[setupid] + LayerPosition[iLayer] + LayerThickness / 2. + padplane_position))
+                 * 180. / acos(-1.);
+        yangleo = atan(2.5 * DetectorSizeY[1]
+                       / (zfront[setupid] + LayerPosition[iLayer] + LayerThickness / 2. + padplane_position))
+                  * 180. / acos(-1.);
+        xangle = atan((2.0 * DetectorSizeX[0] + 2.0 * DetectorSizeX[1])
+                      / (zfront[setupid] + LayerPosition[iLayer] + LayerThickness / 2. + padplane_position))
+                 * 180. / acos(-1.);
+      }
+      if ((iLayer >= 4) && (iLayer < 8)) {
+        //        fprintf(ifile,"y %10.4f cm   x %10.4f cm\n", 3.5 * DetectorSizeY[1], 4.5 * DetectorSizeX[1]);
+        yangle = atan(3.5 * DetectorSizeY[1] / (LayerPosition[iLayer] + LayerThickness / 2. + padplane_position)) * 180.
+                 / acos(-1.);
+        xangle = atan(4.5 * DetectorSizeX[1] / (LayerPosition[iLayer] + LayerThickness / 2. + padplane_position)) * 180.
+                 / acos(-1.);
+      }
+      if ((iLayer >= 8) && (iLayer < 10)) {
+        //        fprintf(ifile,"y %10.4f cm   x %10.4f cm\n", 4.5 * DetectorSizeY[1], 5.5 * DetectorSizeX[1]);
+        yangle = atan(4.5 * DetectorSizeY[1] / (LayerPosition[iLayer] + LayerThickness / 2. + padplane_position)) * 180.
+                 / acos(-1.);
+        xangle = atan(5.5 * DetectorSizeX[1] / (LayerPosition[iLayer] + LayerThickness / 2. + padplane_position)) * 180.
+                 / acos(-1.);
+      }
+      fprintf(ifile,
+              "vi: %5.2f deg, vo: %5.2f deg, h: %5.2f deg - "
+              "vertical/horizontal - layer %2d\n",
+              yangle, yangleo, xangle, PlaneId[iLayer]);
+    }
+  fprintf(ifile, "\n");
+
+  // aperture
+  fprintf(ifile, "# inner aperture\n");
+
+  for (Int_t iLayer = 0; iLayer < MaxLayers; iLayer++)
+    if (ShowLayer[iLayer]) {
+      if (iLayer < 4) {
+        //        fprintf(ifile,"y %10.4f cm   x %10.4f cm\n", 2.5 * DetectorSizeY[1], 3.5 * DetectorSizeX[1]);
+        yangle = atan(0.5 * DetectorSizeY[0]
+                      / (zfront[setupid] + LayerPosition[iLayer] + LayerThickness / 2. + padplane_position))
+                 * 180. / acos(-1.);
+        xangle = atan(1.0 * DetectorSizeX[0]
+                      / (zfront[setupid] + LayerPosition[iLayer] + LayerThickness / 2. + padplane_position))
+                 * 180. / acos(-1.);
+      }
+      if ((iLayer >= 4) && (iLayer < 8)) {
+        //        fprintf(ifile,"y %10.4f cm   x %10.4f cm\n", 3.5 * DetectorSizeY[1], 4.5 * DetectorSizeX[1]);
+        yangle = atan(0.5 * DetectorSizeY[0]
+                      / (zfront[setupid] + LayerPosition[iLayer] + LayerThickness / 2. + padplane_position))
+                 * 180. / acos(-1.);
+        xangle = atan(0.5 * DetectorSizeX[0]
+                      / (zfront[setupid] + LayerPosition[iLayer] + LayerThickness / 2. + padplane_position))
+                 * 180. / acos(-1.);
+      }
+      if ((iLayer >= 8) && (iLayer < 10)) {
+        //        fprintf(ifile,"y %10.4f cm   x %10.4f cm\n", 4.5 * DetectorSizeY[1], 5.5 * DetectorSizeX[1]);
+        yangle = atan(0.5 * DetectorSizeY[0]
+                      / (zfront[setupid] + LayerPosition[iLayer] + LayerThickness / 2. + padplane_position))
+                 * 180. / acos(-1.);
+        xangle = atan(0.5 * DetectorSizeX[0]
+                      / (zfront[setupid] + LayerPosition[iLayer] + LayerThickness / 2. + padplane_position))
+                 * 180. / acos(-1.);
+      }
+      fprintf(ifile, "v: %5.2f deg, h: %5.2f deg - vertical/horizontal - layer %2d\n", yangle, xangle, PlaneId[iLayer]);
+    }
+  fprintf(ifile, "\n");
+
+  // Show layer positions
+  fprintf(ifile, "# z-positions of layer front\n");
+  for (Int_t iLayer = 0; iLayer < MaxLayers; iLayer++) {
+    if (ShowLayer[iLayer])
+      fprintf(ifile, "%7.2f cm   z-position of layer %2d\n", LayerPosition[iLayer], PlaneId[iLayer]);
+  }
+  fprintf(ifile, "\n");
+
+  // flags
+  fprintf(ifile, "# flags\n");
+
+  fprintf(ifile, "support structure is    : ");
+  if (!IncludeSupports) fprintf(ifile, "NOT ");
+  fprintf(ifile, "included\n");
+
+  fprintf(ifile, "radiator is             : ");
+  if (!IncludeRadiator) fprintf(ifile, "NOT ");
+  fprintf(ifile, "included\n");
+
+  fprintf(ifile, "lattice grid is         : ");
+  if (!IncludeLattice) fprintf(ifile, "NOT ");
+  fprintf(ifile, "included\n");
+
+  fprintf(ifile, "kapton window is        : ");
+  if (!IncludeKaptonFoil) fprintf(ifile, "NOT ");
+  fprintf(ifile, "included\n");
+
+  fprintf(ifile, "gas frame is            : ");
+  if (!IncludeGasFrame) fprintf(ifile, "NOT ");
+  fprintf(ifile, "included\n");
+
+  fprintf(ifile, "padplane is             : ");
+  if (!IncludePadplane) fprintf(ifile, "NOT ");
+  fprintf(ifile, "included\n");
+
+  fprintf(ifile, "backpanel is            : ");
+  if (!IncludeBackpanel) fprintf(ifile, "NOT ");
+  fprintf(ifile, "included\n");
+
+  fprintf(ifile, "Aluminium ledge is      : ");
+  if (!IncludeAluLedge) fprintf(ifile, "NOT ");
+  fprintf(ifile, "included\n");
+
+  fprintf(ifile, "Power bus bars are      : ");
+  if (!IncludePowerbars) fprintf(ifile, "NOT ");
+  fprintf(ifile, "included\n");
+
+  fprintf(ifile, "asics are               : ");
+  if (!IncludeAsics) fprintf(ifile, "NOT ");
+  fprintf(ifile, "included\n");
+
+  fprintf(ifile, "front-end boards are    : ");
+  if (!IncludeFebs) fprintf(ifile, "NOT ");
+  fprintf(ifile, "included\n");
+
+  fprintf(ifile, "GBTX readout boards are : ");
+  if (!IncludeRobs) fprintf(ifile, "NOT ");
+  fprintf(ifile, "included\n");
+
+  fprintf(ifile, "\n");
+
+
+  // module statistics
+  //  fprintf(ifile,"#\n##   modules\n#\n\n");
+  //  fprintf(ifile,"number of modules per type and layer:\n");
+  fprintf(ifile, "# modules\n");
+
+  for (Int_t iModule = 1; iModule <= NofModuleTypes; iModule++)
+    fprintf(ifile, "     mod%1d", iModule);
+  fprintf(ifile, "    total");
+
+  fprintf(ifile, "\n------------------------------------------------------------------"
+                 "---------------\n");
+  for (Int_t iLayer = 0; iLayer < MaxLayers; iLayer++)
+    if (ShowLayer[iLayer]) {
+      for (Int_t iModule = 0; iModule < NofModuleTypes; iModule++) {
+        fprintf(ifile, " %8d", ModuleStats[iLayer][iModule]);
+        total_modules[iModule] += ModuleStats[iLayer][iModule];  // sum up modules across layers
+      }
+      fprintf(ifile, "            layer %2d\n", PlaneId[iLayer]);
+    }
+  fprintf(ifile, "\n------------------------------------------------------------------"
+                 "---------------\n");
+
+  // total statistics
+  for (Int_t iModule = 0; iModule < NofModuleTypes; iModule++) {
+    fprintf(ifile, " %8d", total_modules[iModule]);
+    total_modules[NofModuleTypes] += total_modules[iModule];
+  }
+  fprintf(ifile, " %8d", total_modules[NofModuleTypes]);
+  fprintf(ifile, "   number of modules\n");
+
+  //------------------------------------------------------------------------------
+
+  // number of FEBs
+  //  fprintf(ifile,"\n#\n##   febs\n#\n\n");
+  fprintf(ifile, "# febs\n");
+
+  fprintf(ifile, " ");
+  for (Int_t iModule = 0; iModule < NofModuleTypes; iModule++) {
+    if ((AsicsPerFeb[iModule] / 100) == 3) fprintf(ifile, "%8du", FebsPerModule[iModule]);
+    else if ((AsicsPerFeb[iModule] / 100) == 2)
+      fprintf(ifile, "%8ds", FebsPerModule[iModule]);
+    else
+      fprintf(ifile, "%8d ", FebsPerModule[iModule]);
+  }
+  fprintf(ifile, "           FEBs per module\n");
+
+  // FEB total per type
+  total_febs[NofModuleTypes] = 0;  // reset sum to 0
+  fprintf(ifile, " ");
+  for (Int_t iModule = 0; iModule < NofModuleTypes; iModule++) {
+    if ((AsicsPerFeb[iModule] / 100) == 3) {
+      total_febs[iModule] = total_modules[iModule] * FebsPerModule[iModule];
+      fprintf(ifile, "%8du", total_febs[iModule]);
+      total_febs[NofModuleTypes] += total_febs[iModule];
+    }
+    else
+      fprintf(ifile, "         ");
+  }
+  fprintf(ifile, "%8d", total_febs[NofModuleTypes]);
+  fprintf(ifile, "   ultimate  FEBs\n");
+
+  // FEB total per type
+  total_febs[NofModuleTypes] = 0;  // reset sum to 0
+  fprintf(ifile, " ");
+  for (Int_t iModule = 0; iModule < NofModuleTypes; iModule++) {
+    if ((AsicsPerFeb[iModule] / 100) == 2) {
+      total_febs[iModule] = total_modules[iModule] * FebsPerModule[iModule];
+      fprintf(ifile, "%8ds", total_febs[iModule]);
+      total_febs[NofModuleTypes] += total_febs[iModule];
+    }
+    else
+      fprintf(ifile, "         ");
+  }
+  fprintf(ifile, "%8d", total_febs[NofModuleTypes]);
+  fprintf(ifile, "   super     FEBs\n");
+
+  // FEB total per type
+  total_febs[NofModuleTypes] = 0;  // reset sum to 0
+  fprintf(ifile, " ");
+  for (Int_t iModule = 0; iModule < NofModuleTypes; iModule++) {
+    if ((AsicsPerFeb[iModule] / 100) == 1) {
+      total_febs[iModule] = total_modules[iModule] * FebsPerModule[iModule];
+      fprintf(ifile, "%8d ", total_febs[iModule]);
+      total_febs[NofModuleTypes] += total_febs[iModule];
+    }
+    else
+      fprintf(ifile, "         ");
+  }
+  fprintf(ifile, "%8d", total_febs[NofModuleTypes]);
+  fprintf(ifile, "   regular   FEBs\n");
+
+  // FEB total over all types
+  total_febs[NofModuleTypes] = 0;  // reset sum to 0
+  for (Int_t iModule = 0; iModule < NofModuleTypes; iModule++) {
+    total_febs[iModule] = total_modules[iModule] * FebsPerModule[iModule];
+    fprintf(ifile, " %8d", total_febs[iModule]);
+    total_febs[NofModuleTypes] += total_febs[iModule];
+  }
+  fprintf(ifile, " %8d", total_febs[NofModuleTypes]);
+  fprintf(ifile, "   number of FEBs\n");
+
+  //------------------------------------------------------------------------------
+
+  // number of ASICs
+  //  fprintf(ifile,"\n#\n##   asics\n#\n\n");
+  fprintf(ifile, "# asics\n");
+
+  for (Int_t iModule = 0; iModule < NofModuleTypes; iModule++) {
+    fprintf(ifile, " %8d", AsicsPerFeb[iModule] % 100);
+  }
+  fprintf(ifile, "            ASICs per FEB\n");
+
+  // ASICs per module
+  for (Int_t iModule = 0; iModule < NofModuleTypes; iModule++) {
+    asics_per_module[iModule] = FebsPerModule[iModule] * (AsicsPerFeb[iModule] % 100);
+    fprintf(ifile, " %8d", asics_per_module[iModule]);
+  }
+  fprintf(ifile, "            ASICs per module\n");
+
+  // ASICs per module type
+  for (Int_t iModule = 0; iModule < NofModuleTypes; iModule++) {
+    total_asics[iModule] = total_febs[iModule] * (AsicsPerFeb[iModule] % 100);
+    fprintf(ifile, " %8d", total_asics[iModule]);
+    total_asics[NofModuleTypes] += total_asics[iModule];
+  }
+  fprintf(ifile, " %8d", total_asics[NofModuleTypes]);
+  fprintf(ifile, "   number of ASICs\n");
+
+  //------------------------------------------------------------------------------
+
+  // number of GBTXs
+  //  fprintf(ifile,"\n#\n##   asics\n#\n\n");
+  fprintf(ifile, "# gbtx\n");
+
+  for (Int_t iModule = 0; iModule < NofModuleTypes; iModule++) {
+    fprintf(ifile, " %8d", GbtxPerModule[iModule]);
+  }
+  fprintf(ifile, "            GBTXs per module\n");
+
+  // GBTXs per module type
+  for (Int_t iModule = 0; iModule < NofModuleTypes; iModule++) {
+    total_gbtx[iModule] = total_modules[iModule] * GbtxPerModule[iModule];
+    fprintf(ifile, " %8d", total_gbtx[iModule]);
+    total_gbtx[NofModuleTypes] += total_gbtx[iModule];
+  }
+  fprintf(ifile, " %8d", total_gbtx[NofModuleTypes]);
+  fprintf(ifile, "   number of GBTXs\n");
+
+  // GBTX ROB types per module type
+  for (Int_t iModule = 0; iModule < NofModuleTypes; iModule++) {
+    fprintf(ifile, " %8d", RobTypeOnModule[iModule]);
+  }
+  fprintf(ifile, "            GBTX ROB types on module\n");
+
+  for (Int_t iModule = 0; iModule < NofModuleTypes; iModule++) {
+    if ((RobTypeOnModule[iModule] % 10) == 7) total_rob7[iModule]++;
+    if ((RobTypeOnModule[iModule] / 10 % 10) == 7) total_rob7[iModule]++;
+    if ((RobTypeOnModule[iModule] / 100) == 7) total_rob7[iModule]++;
+
+    if ((RobTypeOnModule[iModule] % 10) == 5) total_rob5[iModule]++;
+    if ((RobTypeOnModule[iModule] / 10 % 10) == 5) total_rob5[iModule]++;
+    if ((RobTypeOnModule[iModule] / 100) == 5) total_rob5[iModule]++;
+
+    if ((RobTypeOnModule[iModule] % 10) == 3) total_rob3[iModule]++;
+    if ((RobTypeOnModule[iModule] / 10 % 10) == 3) total_rob3[iModule]++;
+    if ((RobTypeOnModule[iModule] / 100 % 10) == 3) total_rob3[iModule]++;
+    if ((RobTypeOnModule[iModule] / 1000 % 10) == 3) total_rob3[iModule]++;
+    if ((RobTypeOnModule[iModule] / 10000 % 10) == 3) total_rob3[iModule]++;
+    if ((RobTypeOnModule[iModule] / 100000 % 10) == 3) total_rob3[iModule]++;
+  }
+
+  for (Int_t iModule = 0; iModule < NofModuleTypes; iModule++) {
+    total_rob7[iModule] *= total_modules[iModule];
+    fprintf(ifile, " %8d", total_rob7[iModule]);
+    total_rob7[NofModuleTypes] += total_rob7[iModule];
+  }
+  fprintf(ifile, " %8d", total_rob7[NofModuleTypes]);
+  fprintf(ifile, "   number of GBTX ROB7\n");
+
+  for (Int_t iModule = 0; iModule < NofModuleTypes; iModule++) {
+    total_rob5[iModule] *= total_modules[iModule];
+    fprintf(ifile, " %8d", total_rob5[iModule]);
+    total_rob5[NofModuleTypes] += total_rob5[iModule];
+  }
+  fprintf(ifile, " %8d", total_rob5[NofModuleTypes]);
+  fprintf(ifile, "   number of GBTX ROB5\n");
+
+  for (Int_t iModule = 0; iModule < NofModuleTypes; iModule++) {
+    total_rob3[iModule] *= total_modules[iModule];
+    fprintf(ifile, " %8d", total_rob3[iModule]);
+    total_rob3[NofModuleTypes] += total_rob3[iModule];
+  }
+  fprintf(ifile, " %8d", total_rob3[NofModuleTypes]);
+  fprintf(ifile, "   number of GBTX ROB3\n");
+
+  //------------------------------------------------------------------------------
+  fprintf(ifile, "# e-links\n");
+
+  // e-links used
+  for (Int_t iModule = 0; iModule < NofModuleTypes; iModule++)
+    fprintf(ifile, " %8d", asics_per_module[iModule] * 2);
+  fprintf(ifile, " %8d", total_asics[NofModuleTypes] * 2);
+  fprintf(ifile, "   e-links used\n");
+
+  // e-links available
+  for (Int_t iModule = 0; iModule < NofModuleTypes; iModule++)
+    fprintf(ifile, " %8d", GbtxPerModule[iModule] * 14);
+  fprintf(ifile, " %8d", total_gbtx[NofModuleTypes] * 14);
+  fprintf(ifile, "   e-links available\n");
+
+  // e-link efficiency
+  for (Int_t iModule = 0; iModule < NofModuleTypes; iModule++) {
+    if (total_gbtx[iModule] != 0)
+      fprintf(ifile, " %7.1f%%", (float) total_asics[iModule] * 2 / (total_gbtx[iModule] * 14) * 100);
+    else
+      fprintf(ifile, "        -");
+  }
+  if (total_gbtx[NofModuleTypes] != 0)
+    fprintf(ifile, " %7.1f%%", (float) total_asics[NofModuleTypes] * 2 / (total_gbtx[NofModuleTypes] * 14) * 100);
+  fprintf(ifile, "   e-link efficiency\n\n");
+
+  //------------------------------------------------------------------------------
+
+  // number of channels
+  fprintf(ifile, "# channels\n");
+
+  // channels per module
+  for (Int_t iModule = 0; iModule < NofModuleTypes; iModule++) {
+    if ((AsicsPerFeb[iModule] % 100) == 16) {
+      channels_per_feb[iModule]    = 80 * 6;  // rows  // 84, if 63 of 64 ch used
+      channels_per_module[iModule] = channels_per_feb[iModule] * FebsPerModule[iModule];
+    }
+    if ((AsicsPerFeb[iModule] % 100) == 15) {
+      channels_per_feb[iModule]    = 80 * 6;  // rows
+      channels_per_module[iModule] = channels_per_feb[iModule] * FebsPerModule[iModule];
+    }
+    if ((AsicsPerFeb[iModule] % 100) == 10) {
+      channels_per_feb[iModule]    = 80 * 4;  // rows
+      channels_per_module[iModule] = channels_per_feb[iModule] * FebsPerModule[iModule];
+    }
+    if ((AsicsPerFeb[iModule] % 100) == 5) {
+      channels_per_feb[iModule]    = 80 * 2;  // rows
+      channels_per_module[iModule] = channels_per_feb[iModule] * FebsPerModule[iModule];
+    }
+
+    if ((AsicsPerFeb[iModule] % 100) == 9) {
+      channels_per_feb[iModule]    = 144 * 2;  // rows
+      channels_per_module[iModule] = channels_per_feb[iModule] * FebsPerModule[iModule];
+    }
+    if ((AsicsPerFeb[iModule] % 100) == 8) {
+      channels_per_feb[iModule]    = 128 * 2;  // rows
+      channels_per_module[iModule] = channels_per_feb[iModule] * FebsPerModule[iModule];
+    }
+    if ((AsicsPerFeb[iModule] % 100) == 7) {
+      channels_per_feb[iModule]    = 112 * 2;  // rows
+      channels_per_module[iModule] = channels_per_feb[iModule] * FebsPerModule[iModule];
+    }
+  }
+
+  for (Int_t iModule = 0; iModule < NofModuleTypes; iModule++)
+    fprintf(ifile, " %8d", channels_per_module[iModule]);
+  fprintf(ifile, "            channels per module\n");
+
+  for (Int_t iModule = 0; iModule < NofModuleTypes; iModule++)
+    fprintf(ifile, " %8d", channels_per_feb[iModule]);
+  fprintf(ifile, "            channels per feb\n");
+
+  // channels used
+  for (Int_t iModule = 0; iModule < NofModuleTypes; iModule++) {
+    total_channels[iModule] = channels_per_module[iModule] * total_modules[iModule];
+    fprintf(ifile, " %8d", total_channels[iModule]);
+    total_channels[NofModuleTypes] += total_channels[iModule];
+  }
+  fprintf(ifile, " %8d", total_channels[NofModuleTypes]);
+  fprintf(ifile, "   channels used\n");
+
+  // channels available
+  fprintf(ifile, " ");
+  for (Int_t iModule = 0; iModule < NofModuleTypes; iModule++) {
+    if ((AsicsPerFeb[iModule] / 100) == 3) {
+      fprintf(ifile, "%8du", total_asics[iModule] * 32);
+      total_channels_u += total_asics[iModule] * 32;
+    }
+    else if ((AsicsPerFeb[iModule] / 100) == 2) {
+      fprintf(ifile, "%8ds", total_asics[iModule] * 32);
+      total_channels_s += total_asics[iModule] * 32;
+    }
+    else {
+      fprintf(ifile, "%8d ", total_asics[iModule] * 32);
+      total_channels_r += total_asics[iModule] * 32;
+    }
+  }
+  fprintf(ifile, "%8d", total_asics[NofModuleTypes] * 32);
+  fprintf(ifile, "   channels available\n");
+
+  // channel ratio for u,s,r density
+  fprintf(ifile, " ");
+  fprintf(ifile, "%7.1f%%u", (float) total_channels_u / (total_asics[NofModuleTypes] * 32) * 100);
+  fprintf(ifile, "%7.1f%%s", (float) total_channels_s / (total_asics[NofModuleTypes] * 32) * 100);
+  fprintf(ifile, "%7.1f%%r", (float) total_channels_r / (total_asics[NofModuleTypes] * 32) * 100);
+  fprintf(ifile, "                                                        channel ratio\n");
+
+  fprintf(ifile, "\n");
+  fprintf(ifile, "%8.1f%%   channel efficiency\n",
+          1. * total_channels[NofModuleTypes] / (total_asics[NofModuleTypes] * 32) * 100);
+
+  //------------------------------------------------------------------------------
+
+  // total surface of TRD
+  for (Int_t iModule = 0; iModule < NofModuleTypes; iModule++)
+    if (iModule <= 3) {
+      total_surface += total_modules[iModule] * DetectorSizeX[0] / 100 * DetectorSizeY[0] / 100;
+      total_actarea += total_modules[iModule] * (DetectorSizeX[0] - 2 * FrameWidth[0]) / 100
+                       * (DetectorSizeY[0] - 2 * FrameWidth[0]) / 100;
+    }
+    else {
+      total_surface += total_modules[iModule] * DetectorSizeX[1] / 100 * DetectorSizeY[1] / 100;
+      total_actarea += total_modules[iModule] * (DetectorSizeX[1] - 2 * FrameWidth[1]) / 100
+                       * (DetectorSizeY[1] - 2 * FrameWidth[1]) / 100;
+    }
+  fprintf(ifile, "\n");
+
+  // summary
+  fprintf(ifile, "%7.2f m2      total surface    \n", total_surface);
+  fprintf(ifile, "%7.2f m2      total active area\n", total_actarea);
+  fprintf(ifile, "%7.2f m3      total gas volume \n",
+          total_actarea * gas_thickness / 100);  // convert cm to m for thickness
+
+  fprintf(ifile, "%7.2f cm2/ch  average channel size\n", 100. * 100 * total_actarea / total_channels[NofModuleTypes]);
+  fprintf(ifile, "%7.2f ch/m2   channels per m2 active area\n", 1. * total_channels[NofModuleTypes] / total_actarea);
+  fprintf(ifile, "\n");
+
+  // gas volume position
+  fprintf(ifile, "# gas volume position\n");
+  for (Int_t iLayer = 0; iLayer < MaxLayers; iLayer++)
+    if (ShowLayer[iLayer])
+      fprintf(ifile, "%10.4f cm   position of gas volume - layer %2d\n",
+              LayerPosition[iLayer] + LayerThickness / 2. + gas_position, PlaneId[iLayer]);
+  fprintf(ifile, "\n");
+
+  fclose(ifile);
+}
+
+
+void create_materials_from_media_file()
+{
+  // 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 medFile           = geoPath + "/geometry/media.geo";
+  geoFace->setMediaFile(medFile);
+  geoFace->readMedia();
+
+  // Read the required media and create them in the GeoManager
+  FairGeoMedia* geoMedia   = geoFace->getMedia();
+  FairGeoBuilder* geoBuild = geoLoad->getGeoBuilder();
+
+  FairGeoMedium* air       = geoMedia->getMedium(KeepingVolumeMedium);
+  FairGeoMedium* pefoam20  = geoMedia->getMedium(RadiatorVolumeMedium);
+  FairGeoMedium* G10       = geoMedia->getMedium(LatticeVolumeMedium);
+  FairGeoMedium* kapton    = geoMedia->getMedium(KaptonVolumeMedium);
+  FairGeoMedium* trdGas    = geoMedia->getMedium(GasVolumeMedium);
+  FairGeoMedium* copper    = geoMedia->getMedium(PadCopperVolumeMedium);
+  FairGeoMedium* carbon    = geoMedia->getMedium(CarbonVolumeMedium);
+  FairGeoMedium* honeycomb = geoMedia->getMedium(HoneycombVolumeMedium);
+  FairGeoMedium* aluminium = geoMedia->getMedium(AluminiumVolumeMedium);
+
+  //  FairGeoMedium* goldCoatedCopper = geoMedia->getMedium("goldcoatedcopper");
+  //  FairGeoMedium* polypropylene    = geoMedia->getMedium("polypropylene");
+  //  FairGeoMedium* mylar            = geoMedia->getMedium("mylar");
+
+  geoBuild->createMedium(air);
+  geoBuild->createMedium(pefoam20);
+  geoBuild->createMedium(trdGas);
+  geoBuild->createMedium(honeycomb);
+  geoBuild->createMedium(carbon);
+  geoBuild->createMedium(G10);
+  geoBuild->createMedium(copper);
+  geoBuild->createMedium(kapton);
+  geoBuild->createMedium(aluminium);
+
+  //  geoBuild->createMedium(goldCoatedCopper);
+  //  geoBuild->createMedium(polypropylene);
+  //  geoBuild->createMedium(mylar);
+}
+
+TGeoVolume* create_trd_module_type(Int_t moduleType)
+{
+  Int_t type           = ModuleType[moduleType - 1];
+  Double_t sizeX       = DetectorSizeX[type];
+  Double_t sizeY       = DetectorSizeY[type];
+  Double_t frameWidth  = FrameWidth[type];
+  Double_t activeAreaX = sizeX - 2 * frameWidth;
+  Double_t activeAreaY = sizeY - 2 * frameWidth;
+
+  TGeoMedium* keepVolMed      = gGeoMan->GetMedium(KeepingVolumeMedium);
+  TGeoMedium* radVolMed       = gGeoMan->GetMedium(RadiatorVolumeMedium);
+  TGeoMedium* latticeVolMed   = gGeoMan->GetMedium(LatticeVolumeMedium);
+  TGeoMedium* kaptonVolMed    = gGeoMan->GetMedium(KaptonVolumeMedium);
+  TGeoMedium* gasVolMed       = gGeoMan->GetMedium(GasVolumeMedium);
+  TGeoMedium* padcopperVolMed = gGeoMan->GetMedium(PadCopperVolumeMedium);
+  TGeoMedium* padpcbVolMed    = gGeoMan->GetMedium(PadPcbVolumeMedium);
+  TGeoMedium* honeycombVolMed = gGeoMan->GetMedium(HoneycombVolumeMedium);
+  TGeoMedium* carbonVolMed    = gGeoMan->GetMedium(CarbonVolumeMedium);
+  //  TGeoMedium* mylarVolMed       = gGeoMan->GetMedium(MylarVolumeMedium);
+  //  TGeoMedium* electronicsVolMed = gGeoMan->GetMedium(ElectronicsVolumeMedium);
+  TGeoMedium* frameVolMed    = gGeoMan->GetMedium(FrameVolumeMedium);
+  TGeoMedium* aluledgeVolMed = gGeoMan->GetMedium(AluLegdeVolumeMedium);
+  TGeoMedium* febVolMed      = gGeoMan->GetMedium(FebVolumeMedium);
+  TGeoMedium* asicVolMed     = gGeoMan->GetMedium(AsicVolumeMedium);
+  //  TGeoMedium* aluminiumVolMed   = gGeoMan->GetMedium(AluminiumVolumeMedium);
+
+  TString name       = Form("module%d", moduleType);
+  TGeoVolume* module = new TGeoVolumeAssembly(name);
+
+
+  if (IncludeRadiator) {
+    // Radiator
+    //   TGeoBBox* trd_radiator = new TGeoBBox("", activeAreaX /2., activeAreaY /2., radiator_thickness /2.);
+    TGeoBBox* trd_radiator     = new TGeoBBox("trd_radiator", sizeX / 2., sizeY / 2., radiator_thickness / 2.);
+    TGeoVolume* trdmod1_radvol = new TGeoVolume("radiator", trd_radiator, radVolMed);
+    //     TGeoVolume* trdmod1_radvol = new TGeoVolume(Form("module%d_radiator", moduleType), trd_radiator, radVolMed);
+    //     TGeoVolume* trdmod1_radvol = new TGeoVolume(Form("trd1mod%dradiator", moduleType), trd_radiator, radVolMed);
+    trdmod1_radvol->SetLineColor(kBlue);
+    trdmod1_radvol->SetTransparency(70);  // (60);  // (70);  // set transparency for the TRD radiator
+    TGeoTranslation* trd_radiator_trans = new TGeoTranslation("", 0., 0., radiator_position);
+    module->AddNode(trdmod1_radvol, 1, trd_radiator_trans);
+  }
+
+  // Lattice grid
+  if (IncludeLattice) {
+
+    if (type == 0)  // inner modules
+    {
+      //     printf("lattice type %d\n", type);
+      // drift window - lattice grid - sprossenfenster
+      TGeoBBox* trd_lattice_mod0_ho = new TGeoBBox("trd_lattice_mod0_ho", sizeX / 2., lattice_o_width[type] / 2.,
+                                                   lattice_thickness / 2.);  // horizontal outer
+      TGeoBBox* trd_lattice_mod0_hi =
+        new TGeoBBox("trd_lattice_mod0_hi", sizeX / 2. - lattice_o_width[type], lattice_i_width[type] / 2.,
+                     lattice_thickness / 2.);  // horizontal inner
+      TGeoBBox* trd_lattice_mod0_vo =
+        new TGeoBBox("trd_lattice_mod0_vo", lattice_o_width[type] / 2., sizeX / 2. - lattice_o_width[type],
+                     lattice_thickness / 2.);  // vertical outer
+      TGeoBBox* trd_lattice_mod0_vi = new TGeoBBox("trd_lattice_mod0_vi", lattice_i_width[type] / 2.,
+                                                   0.20 * activeAreaY / 2. - lattice_i_width[type] / 2.,
+                                                   lattice_thickness / 2.);  // vertical inner
+      TGeoBBox* trd_lattice_mod0_vb = new TGeoBBox("trd_lattice_mod0_vb", lattice_i_width[type] / 2.,
+                                                   0.20 * activeAreaY / 2. - lattice_i_width[type] / 4.,
+                                                   lattice_thickness / 2.);  // vertical border
+
+      TGeoVolume* trd_lattice_mod0_vol_ho = new TGeoVolume("lattice0ho", trd_lattice_mod0_ho, latticeVolMed);
+      TGeoVolume* trd_lattice_mod0_vol_hi = new TGeoVolume("lattice0hi", trd_lattice_mod0_hi, latticeVolMed);
+      TGeoVolume* trd_lattice_mod0_vol_vo = new TGeoVolume("lattice0vo", trd_lattice_mod0_vo, latticeVolMed);
+      TGeoVolume* trd_lattice_mod0_vol_vi = new TGeoVolume("lattice0vi", trd_lattice_mod0_vi, latticeVolMed);
+      TGeoVolume* trd_lattice_mod0_vol_vb = new TGeoVolume("lattice0vb", trd_lattice_mod0_vb, latticeVolMed);
+
+      trd_lattice_mod0_vol_ho->SetLineColor(kYellow);  // kBlue);
+      trd_lattice_mod0_vol_vo->SetLineColor(kYellow);  // kOrange);
+      trd_lattice_mod0_vol_hi->SetLineColor(kYellow);  // kRed);
+      trd_lattice_mod0_vol_vi->SetLineColor(kYellow);  // kWhite);
+      trd_lattice_mod0_vol_vb->SetLineColor(kYellow);
+
+      TGeoTranslation* tv010 =
+        new TGeoTranslation("tv010", 0., (1.00 * activeAreaY / 2. + lattice_o_width[type] / 2.), 0);
+      TGeoTranslation* tv015 =
+        new TGeoTranslation("tv015", 0., -(1.00 * activeAreaY / 2. + lattice_o_width[type] / 2.), 0);
+
+      TGeoTranslation* th020 =
+        new TGeoTranslation("th020", (1.00 * activeAreaX / 2. + lattice_o_width[type] / 2.), 0., 0);
+      TGeoTranslation* th025 =
+        new TGeoTranslation("th025", -(1.00 * activeAreaX / 2. + lattice_o_width[type] / 2.), 0., 0);
+
+      Double_t hypos0[4] = {(0.60 * activeAreaY / 2.), (0.20 * activeAreaY / 2.), -(0.20 * activeAreaY / 2.),
+                            -(0.60 * activeAreaY / 2.)};
+
+      Double_t vxpos0[4] = {(0.60 * activeAreaX / 2.), (0.20 * activeAreaX / 2.), -(0.20 * activeAreaX / 2.),
+                            -(0.60 * activeAreaX / 2.)};
+
+      Double_t vypos0[5] = {(0.80 * activeAreaY / 2. + lattice_i_width[type] / 4.), (0.40 * activeAreaY / 2.),
+                            (0.00 * activeAreaY / 2.), -(0.40 * activeAreaY / 2.),
+                            -(0.80 * activeAreaY / 2. + lattice_i_width[type] / 4.)};
+
+      //       TGeoVolumeAssembly* trdmod0_lattice = new TGeoVolumeAssembly("mod0lattice"); // volume for lattice grid
+
+      TGeoBBox* trd_lattice_mod0  = new TGeoBBox("trd_lattice_mod0", sizeX / 2., sizeY / 2., lattice_thickness / 2.);
+      TGeoVolume* trdmod0_lattice = new TGeoVolume("lat_grid_mod0", trd_lattice_mod0, keepVolMed);
+
+      //       trdmod0_lattice->SetLineColor(kGreen);  // set color for keeping volume
+
+      // outer frame
+      trdmod0_lattice->AddNode(trd_lattice_mod0_vol_ho, 1, tv010);
+      trdmod0_lattice->AddNode(trd_lattice_mod0_vol_ho, 2, tv015);
+
+      trdmod0_lattice->AddNode(trd_lattice_mod0_vol_vo, 3, th020);
+      trdmod0_lattice->AddNode(trd_lattice_mod0_vol_vo, 4, th025);
+
+      // lattice piece number
+      Int_t lat0_no = 5;
+
+      // horizontal bars
+      for (Int_t y = 0; y < 4; y++) {
+        TGeoTranslation* t0xy = new TGeoTranslation("", 0, hypos0[y], 0);
+        trdmod0_lattice->AddNode(trd_lattice_mod0_vol_hi, lat0_no, t0xy);
+        lat0_no++;
+      }
+
+      // vertical bars
+      for (Int_t x = 0; x < 4; x++)
+        for (Int_t y = 0; y < 5; y++) {
+          TGeoTranslation* t0xy = new TGeoTranslation("", vxpos0[x], vypos0[y], 0);
+          if ((y == 0) || (y == 4)) trdmod0_lattice->AddNode(trd_lattice_mod0_vol_vb, lat0_no, t0xy);  // border piece
+          else
+            trdmod0_lattice->AddNode(trd_lattice_mod0_vol_vi, lat0_no, t0xy);  // middle piece
+          lat0_no++;
+        }
+
+      // add lattice to module
+      TGeoTranslation* trd_lattice_trans = new TGeoTranslation("", 0., 0., lattice_position);
+      module->AddNode(trdmod0_lattice, 1, trd_lattice_trans);
+    }
+
+    else if (type == 1)  // outer modules
+    {
+      //     printf("lattice type %d\n", type);
+      // drift window - lattice grid - sprossenfenster
+      TGeoBBox* trd_lattice_mod1_ho = new TGeoBBox("trd_lattice_mod1_ho", sizeX / 2., lattice_o_width[type] / 2.,
+                                                   lattice_thickness / 2.);  // horizontal outer
+      TGeoBBox* trd_lattice_mod1_hi =
+        new TGeoBBox("trd_lattice_mod1_hi", sizeX / 2. - lattice_o_width[type], lattice_i_width[type] / 2.,
+                     lattice_thickness / 2.);  // horizontal inner
+      TGeoBBox* trd_lattice_mod1_vo =
+        new TGeoBBox("trd_lattice_mod1_vo", lattice_o_width[type] / 2., sizeX / 2. - lattice_o_width[type],
+                     lattice_thickness / 2.);  // vertical outer
+      TGeoBBox* trd_lattice_mod1_vi = new TGeoBBox("trd_lattice_mod1_vi", lattice_i_width[type] / 2.,
+                                                   0.125 * activeAreaY / 2. - lattice_i_width[type] / 2.,
+                                                   lattice_thickness / 2.);  // vertical inner
+      TGeoBBox* trd_lattice_mod1_vb = new TGeoBBox("trd_lattice_mod1_vb", lattice_i_width[type] / 2.,
+                                                   0.125 * activeAreaY / 2. - lattice_i_width[type] / 4.,
+                                                   lattice_thickness / 2.);  // vertical border
+
+      TGeoVolume* trd_lattice_mod1_vol_ho = new TGeoVolume("lattice1ho", trd_lattice_mod1_ho, latticeVolMed);
+      TGeoVolume* trd_lattice_mod1_vol_hi = new TGeoVolume("lattice1hi", trd_lattice_mod1_hi, latticeVolMed);
+      TGeoVolume* trd_lattice_mod1_vol_vo = new TGeoVolume("lattice1vo", trd_lattice_mod1_vo, latticeVolMed);
+      TGeoVolume* trd_lattice_mod1_vol_vi = new TGeoVolume("lattice1vi", trd_lattice_mod1_vi, latticeVolMed);
+      TGeoVolume* trd_lattice_mod1_vol_vb = new TGeoVolume("lattice1vb", trd_lattice_mod1_vb, latticeVolMed);
+
+      trd_lattice_mod1_vol_ho->SetLineColor(kYellow);  // kBlue);
+      trd_lattice_mod1_vol_vo->SetLineColor(kYellow);  // kOrange);
+      trd_lattice_mod1_vol_hi->SetLineColor(kYellow);  // kRed);
+      trd_lattice_mod1_vol_vi->SetLineColor(kYellow);  // kWhite);
+      trd_lattice_mod1_vol_vb->SetLineColor(kYellow);
+
+      TGeoTranslation* tv110 =
+        new TGeoTranslation("tv110", 0., (1.00 * activeAreaY / 2. + lattice_o_width[type] / 2.), 0);
+      TGeoTranslation* tv118 =
+        new TGeoTranslation("tv118", 0., -(1.00 * activeAreaY / 2. + lattice_o_width[type] / 2.), 0);
+
+      TGeoTranslation* th120 =
+        new TGeoTranslation("th120", (1.00 * activeAreaX / 2. + lattice_o_width[type] / 2.), 0., 0);
+      TGeoTranslation* th128 =
+        new TGeoTranslation("th128", -(1.00 * activeAreaX / 2. + lattice_o_width[type] / 2.), 0., 0);
+
+      Double_t hypos1[7] = {(0.75 * activeAreaY / 2.), (0.50 * activeAreaY / 2.),  (0.25 * activeAreaY / 2.),
+                            (0.00 * activeAreaY / 2.), -(0.25 * activeAreaY / 2.), -(0.50 * activeAreaY / 2.),
+                            -(0.75 * activeAreaY / 2.)};
+
+      Double_t vxpos1[7] = {(0.75 * activeAreaX / 2.), (0.50 * activeAreaX / 2.),  (0.25 * activeAreaX / 2.),
+                            (0.00 * activeAreaX / 2.), -(0.25 * activeAreaX / 2.), -(0.50 * activeAreaX / 2.),
+                            -(0.75 * activeAreaX / 2.)};
+
+      Double_t vypos1[8] = {(0.875 * activeAreaY / 2. + lattice_i_width[type] / 4.),
+                            (0.625 * activeAreaY / 2.),
+                            (0.375 * activeAreaY / 2.),
+                            (0.125 * activeAreaY / 2.),
+                            -(0.125 * activeAreaY / 2.),
+                            -(0.375 * activeAreaY / 2.),
+                            -(0.625 * activeAreaY / 2.),
+                            -(0.875 * activeAreaY / 2. + lattice_i_width[type] / 4.)};
+
+      //       TGeoVolumeAssembly* trdmod1_lattice = new TGeoVolumeAssembly("mod1lattice"); // volume for lattice grid
+
+      TGeoBBox* trd_lattice_mod1  = new TGeoBBox("trd_lattice_mod1", sizeX / 2., sizeY / 2., lattice_thickness / 2.);
+      TGeoVolume* trdmod1_lattice = new TGeoVolume("lat_grid_mod1", trd_lattice_mod1, keepVolMed);
+
+      //       trdmod1_lattice->SetLineColor(kGreen);  // set color for keeping volume
+
+      // outer frame
+      trdmod1_lattice->AddNode(trd_lattice_mod1_vol_ho, 1, tv110);
+      trdmod1_lattice->AddNode(trd_lattice_mod1_vol_ho, 2, tv118);
+
+      trdmod1_lattice->AddNode(trd_lattice_mod1_vol_vo, 3, th120);
+      trdmod1_lattice->AddNode(trd_lattice_mod1_vol_vo, 4, th128);
+
+      // lattice piece number
+      Int_t lat1_no = 5;
+
+      // horizontal bars
+      for (Int_t y = 0; y < 7; y++) {
+        TGeoTranslation* t1xy = new TGeoTranslation("", 0, hypos1[y], 0);
+        trdmod1_lattice->AddNode(trd_lattice_mod1_vol_hi, lat1_no, t1xy);
+        lat1_no++;
+      }
+
+      // vertical bars
+      for (Int_t x = 0; x < 7; x++)
+        for (Int_t y = 0; y < 8; y++) {
+          TGeoTranslation* t1xy = new TGeoTranslation("", vxpos1[x], vypos1[y], 0);
+          if ((y == 0) || (y == 7)) trdmod1_lattice->AddNode(trd_lattice_mod1_vol_vb, lat1_no, t1xy);  // border piece
+          else
+            trdmod1_lattice->AddNode(trd_lattice_mod1_vol_vi, lat1_no, t1xy);  // middle piece
+          lat1_no++;
+        }
+
+      // add lattice to module
+      TGeoTranslation* trd_lattice_trans = new TGeoTranslation("", 0., 0., lattice_position);
+      module->AddNode(trdmod1_lattice, 1, trd_lattice_trans);
+    }
+
+  }  // with lattice grid
+
+  if (IncludeKaptonFoil) {
+    // Kapton Foil
+    TGeoBBox* trd_kapton          = new TGeoBBox("trd_kapton", sizeX / 2., sizeY / 2., kapton_thickness / 2.);
+    TGeoVolume* trdmod1_kaptonvol = new TGeoVolume("kaptonfoil", trd_kapton, kaptonVolMed);
+    //   TGeoVolume* trdmod1_kaptonvol = new TGeoVolume(Form("module%d_kaptonfoil", moduleType), trd_kapton, kaptonVolMed);
+    //   TGeoVolume* trdmod1_kaptonvol = new TGeoVolume(Form("trd1mod%dkapton", moduleType), trd_kapton, kaptonVolMed);
+    trdmod1_kaptonvol->SetLineColor(kGreen);
+    TGeoTranslation* trd_kapton_trans = new TGeoTranslation("", 0., 0., kapton_position);
+    module->AddNode(trdmod1_kaptonvol, 1, trd_kapton_trans);
+  }
+
+  // start of Frame in z
+  // Gas
+  TGeoBBox* trd_gas          = new TGeoBBox("trd_gas", activeAreaX / 2., activeAreaY / 2., gas_thickness / 2.);
+  TGeoVolume* trdmod1_gasvol = new TGeoVolume("gas", trd_gas, gasVolMed);
+  //   TGeoVolume* trdmod1_gasvol = new TGeoVolume(Form("module%d_gas", moduleType), trd_gas, gasVolMed);
+  //   TGeoVolume* trdmod1_gasvol = new TGeoVolume(Form("trd1mod%dgas", moduleType), trd_gas, gasVolMed);
+  //   trdmod1_gasvol->SetLineColor(kBlue);
+  trdmod1_gasvol->SetLineColor(kGreen);  // to avoid blue overlaps in the screenshots
+  trdmod1_gasvol->SetTransparency(40);   // set transparency for the TRD gas
+  TGeoTranslation* trd_gas_trans = new TGeoTranslation("", 0., 0., gas_position);
+  module->AddNode(trdmod1_gasvol, 1, trd_gas_trans);
+  // end of Frame in z
+
+  if (IncludeGasFrame) {
+    // frame1
+    TGeoBBox* trd_frame1          = new TGeoBBox("trd_frame1", sizeX / 2., frameWidth / 2., frame_thickness / 2.);
+    TGeoVolume* trdmod1_frame1vol = new TGeoVolume("frame1", trd_frame1, frameVolMed);
+    trdmod1_frame1vol->SetLineColor(kRed);
+
+    // translations
+    TGeoTranslation* trd_frame1_trans = new TGeoTranslation("", 0., activeAreaY / 2. + frameWidth / 2., frame_position);
+    module->AddNode(trdmod1_frame1vol, 1, trd_frame1_trans);
+    trd_frame1_trans = new TGeoTranslation("", 0., -(activeAreaY / 2. + frameWidth / 2.), frame_position);
+    module->AddNode(trdmod1_frame1vol, 2, trd_frame1_trans);
+
+
+    // frame2
+    TGeoBBox* trd_frame2          = new TGeoBBox("trd_frame2", frameWidth / 2., activeAreaY / 2., frame_thickness / 2.);
+    TGeoVolume* trdmod1_frame2vol = new TGeoVolume("frame2", trd_frame2, frameVolMed);
+    trdmod1_frame2vol->SetLineColor(kRed);
+
+    // translations
+    TGeoTranslation* trd_frame2_trans = new TGeoTranslation("", activeAreaX / 2. + frameWidth / 2., 0., frame_position);
+    module->AddNode(trdmod1_frame2vol, 1, trd_frame2_trans);
+    trd_frame2_trans = new TGeoTranslation("", -(activeAreaX / 2. + frameWidth / 2.), 0., frame_position);
+    module->AddNode(trdmod1_frame2vol, 2, trd_frame2_trans);
+  }
+
+  if (IncludePadplane) {
+    // Pad Copper
+    TGeoBBox* trd_padcopper          = new TGeoBBox("trd_padcopper", sizeX / 2., sizeY / 2., padcopper_thickness / 2.);
+    TGeoVolume* trdmod1_padcoppervol = new TGeoVolume("padcopper", trd_padcopper, padcopperVolMed);
+    //   TGeoVolume* trdmod1_padcoppervol = new TGeoVolume(Form("module%d_padcopper", moduleType), trd_padcopper, padcopperVolMed);
+    //   TGeoVolume* trdmod1_padcoppervol = new TGeoVolume(Form("trd1mod%dpadcopper", moduleType), trd_padcopper, padcopperVolMed);
+    trdmod1_padcoppervol->SetLineColor(kOrange);
+    TGeoTranslation* trd_padcopper_trans = new TGeoTranslation("", 0., 0., padcopper_position);
+    module->AddNode(trdmod1_padcoppervol, 1, trd_padcopper_trans);
+
+    // Pad Plane
+    TGeoBBox* trd_padpcb          = new TGeoBBox("trd_padpcb", sizeX / 2., sizeY / 2., padplane_thickness / 2.);
+    TGeoVolume* trdmod1_padpcbvol = new TGeoVolume("padplane", trd_padpcb, padpcbVolMed);
+    //   TGeoVolume* trdmod1_padpcbvol = new TGeoVolume(Form("module%d_padplane", moduleType), trd_padpcb, padpcbVolMed);
+    //   TGeoVolume* trdmod1_padpcbvol = new TGeoVolume(Form("trd1mod%dpadplane", moduleType), trd_padpcb, padpcbVolMed);
+    trdmod1_padpcbvol->SetLineColor(kBlue);
+    TGeoTranslation* trd_padpcb_trans = new TGeoTranslation("", 0., 0., padplane_position);
+    module->AddNode(trdmod1_padpcbvol, 1, trd_padpcb_trans);
+  }
+
+  if (IncludeBackpanel) {
+    // Honeycomb
+    TGeoBBox* trd_honeycomb          = new TGeoBBox("trd_honeycomb", sizeX / 2., sizeY / 2., honeycomb_thickness / 2.);
+    TGeoVolume* trdmod1_honeycombvol = new TGeoVolume("honeycomb", trd_honeycomb, honeycombVolMed);
+    //   TGeoVolume* trdmod1_honeycombvol = new TGeoVolume(Form("module%d_honeycomb", moduleType), trd_honeycomb, honeycombVolMed);
+    //   TGeoVolume* trdmod1_honeycombvol = new TGeoVolume(Form("trd1mod%dhoneycomb", moduleType), trd_honeycomb, honeycombVolMed);
+    trdmod1_honeycombvol->SetLineColor(kOrange);
+    TGeoTranslation* trd_honeycomb_trans = new TGeoTranslation("", 0., 0., honeycomb_position);
+    module->AddNode(trdmod1_honeycombvol, 1, trd_honeycomb_trans);
+
+    // Carbon fiber layers
+    TGeoBBox* trd_carbon          = new TGeoBBox("trd_carbon", sizeX / 2., sizeY / 2., carbon_thickness / 2.);
+    TGeoVolume* trdmod1_carbonvol = new TGeoVolume("carbonsheet", trd_carbon, carbonVolMed);
+    //   TGeoVolume* trdmod1_carbonvol = new TGeoVolume(Form("module%d_carbonsheet", moduleType), trd_carbon, carbonVolMed);
+    //   TGeoVolume* trdmod1_carbonvol = new TGeoVolume(Form("trd1mod%dcarbon", moduleType), trd_carbon, carbonVolMed);
+    trdmod1_carbonvol->SetLineColor(kGreen);
+    TGeoTranslation* trd_carbon_trans = new TGeoTranslation("", 0., 0., carbon_position);
+    module->AddNode(trdmod1_carbonvol, 1, trd_carbon_trans);
+  }
+
+  if (IncludeAluLedge) {
+    // Al-ledge
+    TGeoBBox* trd_aluledge1 = new TGeoBBox("trd_aluledge1", sizeY / 2., aluminium_width / 2., aluminium_thickness / 2.);
+    TGeoVolume* trdmod1_aluledge1vol = new TGeoVolume("aluledge1", trd_aluledge1, aluledgeVolMed);
+    trdmod1_aluledge1vol->SetLineColor(kRed);
+
+    // translations
+    TGeoTranslation* trd_aluledge1_trans =
+      new TGeoTranslation("", 0., sizeY / 2. - aluminium_width / 2., aluminium_position);
+    module->AddNode(trdmod1_aluledge1vol, 1, trd_aluledge1_trans);
+    trd_aluledge1_trans = new TGeoTranslation("", 0., -(sizeY / 2. - aluminium_width / 2.), aluminium_position);
+    module->AddNode(trdmod1_aluledge1vol, 2, trd_aluledge1_trans);
+
+
+    // Al-ledge
+    TGeoBBox* trd_aluledge2 =
+      new TGeoBBox("trd_aluledge2", aluminium_width / 2., sizeY / 2. - aluminium_width, aluminium_thickness / 2.);
+    TGeoVolume* trdmod1_aluledge2vol = new TGeoVolume("aluledge2", trd_aluledge2, aluledgeVolMed);
+    trdmod1_aluledge2vol->SetLineColor(kRed);
+
+    // translations
+    TGeoTranslation* trd_aluledge2_trans =
+      new TGeoTranslation("", sizeX / 2. - aluminium_width / 2., 0., aluminium_position);
+    module->AddNode(trdmod1_aluledge2vol, 1, trd_aluledge2_trans);
+    trd_aluledge2_trans = new TGeoTranslation("", -(sizeX / 2. - aluminium_width / 2.), 0., aluminium_position);
+    module->AddNode(trdmod1_aluledge2vol, 2, trd_aluledge2_trans);
+  }
+
+  // FEBs
+  if (IncludeFebs) {
+    // assemblies
+    TGeoVolumeAssembly* trd_feb_vol = new TGeoVolumeAssembly("febvol");  // the mother volume of all FEBs
+    TGeoVolumeAssembly* trd_feb_box =
+      new TGeoVolumeAssembly("febbox");  // volume for inclined FEBs, then shifted along y
+    //TGeoVolumeAssembly* trd_feb_vol = new TGeoVolumeAssembly(Form("module%d_febvol", moduleType));  // the mother volume of all FEBs
+    //TGeoVolumeAssembly* trd_feb_box = new TGeoVolumeAssembly(Form("module%d_febbox", moduleType));  // volume for inclined FEBs, then shifted along y
+    //TGeoVolumeAssembly* trd_feb_vol = new TGeoVolumeAssembly(Form("trd1mod%dfebvol", moduleType));  // the mother volume of all FEBs
+    //TGeoVolumeAssembly* trd_feb_box = new TGeoVolumeAssembly(Form("trd1mod%dfebbox", moduleType));  // volume for inclined FEBs, then shifted along y
+
+    // translations + rotations
+    TGeoTranslation* trd_feb_trans1;      // center to corner
+    TGeoTranslation* trd_feb_trans2;      // corner back
+    TGeoRotation* trd_feb_rotation;       // rotation around x axis
+    TGeoTranslation* trd_feb_y_position;  // shift to y position on TRD
+    //      TGeoTranslation *trd_feb_null;       // no displacement
+
+    // replaced by matrix operation (see below)
+    //  //      Double_t yback, zback;
+    //  //      TGeoCombiTrans  *trd_feb_placement;
+    //  //      // fix Z back offset 0.3 at some point
+    //  //      yback = -    sin(feb_rotation_angle/180*3.141)  * feb_width /2.;
+    //  //      zback = - (1-cos(feb_rotation_angle/180*3.141)) * feb_width /2. + 0.3;
+    //  //      trd_feb_placement = new TGeoCombiTrans(0, feb_pos_y + yback, zback, trd_feb_rotation);
+    //  //      trd_feb_box->AddNode(trdmod1_feb, iFeb+1, trd_feb_placement);
+
+    //      trd_feb_null       = new TGeoTranslation("", 0., 0., 0.);  // empty operation
+    trd_feb_trans1   = new TGeoTranslation("", 0., -feb_thickness / 2.,
+                                         -feb_width / 2.);  // move bottom right corner to center
+    trd_feb_trans2   = new TGeoTranslation("", 0., feb_thickness / 2.,
+                                         feb_width / 2.);  // move bottom right corner back
+    trd_feb_rotation = new TGeoRotation();
+    trd_feb_rotation->RotateX(feb_rotation_angle[moduleType - 1]);
+
+    TGeoHMatrix* incline_feb = new TGeoHMatrix("");
+
+    //        (*incline_feb) = (*trd_feb_null);        // OK
+    //        (*incline_feb) = (*trd_feb_y_position);  // OK
+    //        (*incline_feb) = (*trd_feb_trans1);      // OK
+    //        (*incline_feb) = (*trd_feb_trans1) * (*trd_feb_y_position);  // OK
+    //        (*incline_feb) = (*trd_feb_trans1) * (*trd_feb_trans2);      // OK
+    //        (*incline_feb) = (*trd_feb_trans1) * (*trd_feb_rotation);    // OK
+    //        (*incline_feb) =  (*trd_feb_trans1) * (*trd_feb_rotation) * (*trd_feb_trans2) * (*trd_feb_y_position);  // not OK
+    // trd_feb_y_position is displaced in rotated coordinate system
+
+    // matrix operation to rotate FEB PCB around its corner on the backanel
+    (*incline_feb) = (*trd_feb_trans1) * (*trd_feb_rotation) * (*trd_feb_trans2);  // OK
+
+    // Create all FEBs and place them in an assembly which will be added to the TRD module
+    TGeoBBox* trd_feb       = new TGeoBBox("trd_feb", activeAreaX / 2., feb_thickness / 2.,
+                                     feb_width / 2.);               // the FEB itself - as a cuboid
+    TGeoVolume* trdmod1_feb = new TGeoVolume("feb", trd_feb, febVolMed);  // the FEB made of a certain medium
+    //      TGeoVolume* trdmod1_feb = new TGeoVolume(Form("module%d_feb", moduleType), trd_feb, febVolMed);  // the FEB made of a certain medium
+    //      TGeoVolume* trdmod1_feb = new TGeoVolume(Form("trd1mod%dfeb", moduleType), trd_feb, febVolMed);  // the FEB made of a certain medium
+    trdmod1_feb->SetLineColor(kYellow);  // set yellow color
+    trd_feb_box->AddNode(trdmod1_feb, 1, incline_feb);
+    // now we have an inclined FEB
+
+    // ASICs
+    if (IncludeAsics) {
+      Double_t asic_pos;
+      Double_t asic_pos_x;
+      TGeoTranslation* trd_asic_trans0;  // ASIC on FEB x position
+      TGeoTranslation* trd_asic_trans1;  // center to corner
+      TGeoTranslation* trd_asic_trans2;  // corner back
+      TGeoRotation* trd_asic_rotation;   // rotation around x axis
+
+      trd_asic_trans1   = new TGeoTranslation("", 0., -(feb_thickness + asic_offset + asic_thickness / 2.),
+                                            -feb_width / 2.);  // move ASIC center to FEB corner
+      trd_asic_trans2   = new TGeoTranslation("", 0., feb_thickness + asic_offset + asic_thickness / 2.,
+                                            feb_width / 2.);  // move FEB corner back to asic center
+      trd_asic_rotation = new TGeoRotation();
+      trd_asic_rotation->RotateX(feb_rotation_angle[moduleType - 1]);
+
+      TGeoHMatrix* incline_asic;
+
+      // put many ASICs on each inclined FEB
+      TGeoBBox* trd_asic = new TGeoBBox("trd_asic", asic_width / 2., asic_thickness / 2.,
+                                        asic_width / 2.);  // ASIC dimensions
+      // TODO: use Silicon as ASICs material
+      TGeoVolume* trdmod1_asic = new TGeoVolume("asic", trd_asic, asicVolMed);  // the ASIC made of a certain medium
+      //        TGeoVolume* trdmod1_asic = new TGeoVolume(Form("module%d_asic", moduleType), trd_asic, asicVolMed);   // the ASIC made of a certain medium
+      //        TGeoVolume* trdmod1_asic = new TGeoVolume(Form("trd1mod%dasic", moduleType), trd_asic, asicVolMed);   // the ASIC made of a certain medium
+      trdmod1_asic->SetLineColor(kBlue);  // set blue color for ASICs
+
+      Int_t nofAsics   = AsicsPerFeb[moduleType - 1] % 100;
+      Int_t groupAsics = AsicsPerFeb[moduleType - 1] / 100;  // either 1 or 2 or 3 (new ultimate)
+
+      if ((nofAsics == 16) && (activeAreaX < 60)) asic_distance = 0.0;  // for 57 cm  // 0.1;  // for 60 cm
+      else
+        asic_distance = 0.4;
+
+      for (Int_t iAsic = 0; iAsic < (nofAsics / groupAsics); iAsic++) {
+        if (groupAsics == 1)  // single ASICs
+        {
+          asic_pos =
+            (iAsic + 0.5) / nofAsics - 0.5;  // equal spacing of ASICs on the FEB, e.g. for no=3 : -1/3, 0, +1/3
+
+          // ASIC 1
+          asic_pos_x      = asic_pos * activeAreaX;
+          trd_asic_trans0 = new TGeoTranslation("", asic_pos_x, feb_thickness / 2. + asic_thickness / 2. + asic_offset,
+                                                0.);  // move asic on top of FEB
+          incline_asic    = new TGeoHMatrix("");
+          (*incline_asic) = (*trd_asic_trans0) * (*trd_asic_trans1) * (*trd_asic_rotation) * (*trd_asic_trans2);  // OK
+          trd_feb_box->AddNode(trdmod1_asic, iAsic + 1,
+                               incline_asic);  // now we have ASICs on the inclined FEB
+        }
+
+        if (groupAsics == 2)  // pairs of ASICs
+        {
+          asic_pos = (iAsic + 0.5) / (nofAsics / groupAsics)
+                     - 0.5;  // equal spacing of ASICs on the FEB, e.g. for no=3 : -1/3, 0, +1/3
+
+          // ASIC 1
+          asic_pos_x      = asic_pos * activeAreaX + (0.5 + asic_distance / 2.) * asic_width;
+          trd_asic_trans0 = new TGeoTranslation("", asic_pos_x, feb_thickness / 2. + asic_thickness / 2. + asic_offset,
+                                                0.);  // move asic on top of FEB);
+          incline_asic    = new TGeoHMatrix("");
+          (*incline_asic) = (*trd_asic_trans0) * (*trd_asic_trans1) * (*trd_asic_rotation) * (*trd_asic_trans2);  // OK
+          trd_feb_box->AddNode(trdmod1_asic, 2 * iAsic + 1,
+                               incline_asic);  // now we have ASICs on the inclined FEB
+
+          // ASIC 2
+          asic_pos_x      = asic_pos * activeAreaX - (0.5 + asic_distance / 2.) * asic_width;
+          trd_asic_trans0 = new TGeoTranslation("", asic_pos_x, feb_thickness / 2. + asic_thickness / 2. + asic_offset,
+                                                0.);  // move asic on top of FEB
+          incline_asic    = new TGeoHMatrix("");
+          (*incline_asic) = (*trd_asic_trans0) * (*trd_asic_trans1) * (*trd_asic_rotation) * (*trd_asic_trans2);  // OK
+          trd_feb_box->AddNode(trdmod1_asic, 2 * iAsic + 2,
+                               incline_asic);  // now we have ASICs on the inclined FEB
+        }
+
+        if (groupAsics == 3)  // triplets of ASICs
+        {
+          asic_pos = (iAsic + 0.5) / (nofAsics / groupAsics)
+                     - 0.5;  // equal spacing of ASICs on the FEB, e.g. for no=3 : -1/3, 0, +1/3
+
+          // ASIC 1
+          asic_pos_x      = asic_pos * activeAreaX + 1.1 * asic_width;  // (0.5 + asic_distance/2.) * asic_width;
+          trd_asic_trans0 = new TGeoTranslation("", asic_pos_x, feb_thickness / 2. + asic_thickness / 2. + asic_offset,
+                                                0.);  // move asic on top of FEB);
+          incline_asic    = new TGeoHMatrix("");
+          (*incline_asic) = (*trd_asic_trans0) * (*trd_asic_trans1) * (*trd_asic_rotation) * (*trd_asic_trans2);  // OK
+          trd_feb_box->AddNode(trdmod1_asic, 3 * iAsic + 1,
+                               incline_asic);  // now we have ASICs on the inclined FEB
+
+          // ASIC 2
+          asic_pos_x      = asic_pos * activeAreaX;
+          trd_asic_trans0 = new TGeoTranslation("", asic_pos_x, feb_thickness / 2. + asic_thickness / 2. + asic_offset,
+                                                0.);  // move asic on top of FEB
+          incline_asic    = new TGeoHMatrix("");
+          (*incline_asic) = (*trd_asic_trans0) * (*trd_asic_trans1) * (*trd_asic_rotation) * (*trd_asic_trans2);  // OK
+          trd_feb_box->AddNode(trdmod1_asic, 3 * iAsic + 2,
+                               incline_asic);  // now we have ASICs on the inclined FEB
+
+          // ASIC 3
+          asic_pos_x      = asic_pos * activeAreaX - 1.1 * asic_width;  // (0.5 + asic_distance/2.) * asic_width;
+          trd_asic_trans0 = new TGeoTranslation("", asic_pos_x, feb_thickness / 2. + asic_thickness / 2. + asic_offset,
+                                                0.);  // move asic on top of FEB
+          incline_asic    = new TGeoHMatrix("");
+          (*incline_asic) = (*trd_asic_trans0) * (*trd_asic_trans1) * (*trd_asic_rotation) * (*trd_asic_trans2);  // OK
+          trd_feb_box->AddNode(trdmod1_asic, 3 * iAsic + 3,
+                               incline_asic);  // now we have ASICs on the inclined FEB
+        }
+      }
+      // now we have an inclined FEB with ASICs
+    }
+
+
+    // now go on with FEB placement
+    Double_t feb_pos;
+    Double_t feb_pos_y;
+
+    Int_t nofFebs = FebsPerModule[moduleType - 1];
+    for (Int_t iFeb = 0; iFeb < nofFebs; iFeb++) {
+      feb_pos = (iFeb + 0.5) / nofFebs - 0.5;  // equal spacing of FEBs on the backpanel
+      // cout << "feb_pos " << iFeb << ": " << feb_pos << endl;
+      feb_pos_y = feb_pos * activeAreaY;
+      feb_pos_y += feb_width / 2. * sin(feb_rotation_angle[moduleType - 1] * acos(-1.) / 180.);
+
+      // shift inclined FEB in y to its final position
+      trd_feb_y_position = new TGeoTranslation("", 0., feb_pos_y,
+                                               feb_z_offset);  // with additional fixed offset in z direction
+      //        trd_feb_y_position = new TGeoTranslation("", 0., feb_pos_y, 0.0);  // touching the backpanel with the corner
+      trd_feb_vol->AddNode(trd_feb_box, iFeb + 1, trd_feb_y_position);  // position FEB in y
+    }
+
+    if (IncludeRobs) {
+      // GBTx ROBs
+      Double_t rob_size_x    = 20.0;  // 13.0; // 130 mm
+      Double_t rob_size_y    = 9.0;   //  4.5; //  45 mm
+      Double_t rob_offset    = 1.2;
+      Double_t rob_thickness = feb_thickness;
+
+      TGeoVolumeAssembly* trd_rob_box =
+        new TGeoVolumeAssembly("robbox");  // volume for inclined FEBs, then shifted along y
+      TGeoBBox* trd_rob       = new TGeoBBox("trd_rob", rob_size_x / 2., rob_size_y / 2.,
+                                       rob_thickness / 2.);           // the ROB itself
+      TGeoVolume* trdmod1_rob = new TGeoVolume("rob", trd_rob, febVolMed);  // the ROB made of a certain medium
+      trdmod1_rob->SetLineColor(kRed);                                      // set color
+
+      //      TGeoHMatrix *incline_rob = new TGeoHMatrix("");
+      trd_rob_box->AddNode(trdmod1_rob, 1);
+
+      // GBTXs
+      Double_t gbtx_pos;
+      Double_t gbtx_pos_x;
+      Double_t gbtx_pos_y;
+      TGeoTranslation* trd_gbtx_trans1;  // center to corner
+
+      // GBTX parameters
+      const Double_t gbtx_thickness = 0.25;  // 2.5 mm
+      const Double_t gbtx_width     = 3.0;   // 2.0;  1.0;   // 1 cm
+
+      // put many GBTXs on each inclined FEB
+      TGeoBBox* trd_gbtx       = new TGeoBBox("trd_gbtx", gbtx_width / 2., gbtx_width / 2.,
+                                        gbtx_thickness / 2.);             // GBTX dimensions
+      TGeoVolume* trdmod1_gbtx = new TGeoVolume("gbtx", trd_gbtx, asicVolMed);  // the GBTX made of a certain medium
+      trdmod1_gbtx->SetLineColor(kGreen);                                       // set color for GBTXs
+
+      Int_t nofGbtxs   = GbtxPerRob[moduleType - 1] % 100;
+      Int_t groupGbtxs = GbtxPerRob[moduleType - 1] / 100;  // usually 1
+
+      //      nofGbtxs   = 7;
+      //      groupGbtxs = 1;
+
+      Int_t nofGbtxX = (nofGbtxs - 1) / 2. + 1;  // +1 is for GBTx master
+      Int_t nofGbtxY = 2;
+
+      Double_t gbtx_distance = 0.4;
+      Int_t iGbtx            = 1;
+
+      for (Int_t iGbtxX = 0; iGbtxX < nofGbtxX; iGbtxX++) {
+        gbtx_pos = (iGbtxX + 0.5) / nofGbtxX - 0.5;  // equal spacing of GBTXs on the FEB, e.g. for no=3 : -1/3, 0, +1/3
+        gbtx_pos_x = -gbtx_pos * rob_size_x;
+
+        if (iGbtxX > 0)
+          for (Int_t iGbtxY = 0; iGbtxY < nofGbtxY; iGbtxY++) {
+            gbtx_pos =
+              (iGbtxY + 0.5) / nofGbtxY - 0.5;  // equal spacing of GBTXs on the FEB, e.g. for no=3 : -1/3, 0, +1/3
+            gbtx_pos_y = gbtx_pos * rob_size_y;
+
+            trd_gbtx_trans1 = new TGeoTranslation("", gbtx_pos_x, gbtx_pos_y,
+                                                  rob_thickness / 2. + gbtx_thickness / 2.);  // move gbtx on top of ROB
+            trd_rob_box->AddNode(trdmod1_gbtx, iGbtx++,
+                                 trd_gbtx_trans1);  // now we have GBTXs on the ROB
+          }
+        else {
+          gbtx_pos_y = 0;
+
+          trd_gbtx_trans1 = new TGeoTranslation("", gbtx_pos_x, gbtx_pos_y,
+                                                rob_thickness / 2. + gbtx_thickness / 2.);  // move gbtx on top of ROB
+          trd_rob_box->AddNode(trdmod1_gbtx, iGbtx++,
+                               trd_gbtx_trans1);  // now we have GBTXs on the ROB
+        }
+      }
+
+      // now go on with ROB placement
+      Double_t rob_pos;
+      Double_t rob_pos_y;
+      TGeoTranslation* trd_rob_y_position;  // shift to y position on TRD
+
+      Int_t nofRobs = RobsPerModule[moduleType - 1];
+      for (Int_t iRob = 0; iRob < nofRobs; iRob++) {
+        rob_pos   = (iRob + 0.5) / nofRobs - 0.5;  // equal spacing of ROBs on the backpanel
+        rob_pos_y = rob_pos * activeAreaY;
+
+        // shift inclined ROB in y to its final position
+        if (feb_rotation_angle[moduleType - 1] == 90)  // if FEB parallel to backpanel
+          trd_rob_y_position = new TGeoTranslation("", 0., rob_pos_y,
+                                                   -feb_width / 2. + rob_offset);  // place ROBs close to FEBs
+        else {
+          //	    Int_t rob_z_pos = 0.;  // test where ROB is placed by default
+          Int_t rob_z_pos =
+            -feb_width / 2. + feb_width * cos(feb_rotation_angle[moduleType - 1] * acos(-1.) / 180.) + rob_offset;
+          if (rob_z_pos > feb_width / 2.)  // if the rob is too far out
+          {
+            rob_z_pos = feb_width / 2. - rob_thickness;  // place ROBs at end of feb volume
+            std::cout << "GBTx ROB was outside of the FEB volume, check "
+                         "overlap with FEB"
+                      << std::endl;
+          }
+          trd_rob_y_position = new TGeoTranslation("", 0., rob_pos_y, rob_z_pos);
+        }
+        trd_feb_vol->AddNode(trd_rob_box, iRob + 1, trd_rob_y_position);  // position FEB in y
+      }
+
+    }  // IncludeGbtx
+
+    // put FEB box on module
+    TGeoTranslation* trd_febvolume_trans = new TGeoTranslation("", 0., 0., febvolume_position);
+    gGeoMan->GetVolume(name)->AddNode(trd_feb_vol, 1,
+                                      trd_febvolume_trans);  // put febvolume at correct z position wrt to the module
+  }
+
+  return module;
+}
+
+Int_t copy_nr(Int_t stationNr, Int_t copyNr, Int_t isRotated, Int_t planeNr, Int_t modinplaneNr)
+{
+  if (modinplaneNr > 128)
+    printf("Warning: too many modules in this layer %02d (max 128 according to "
+           "CbmTrdAddress)\n",
+           planeNr);
+
+  return (stationNr * 100000000  // 1 digit
+          + copyNr * 1000000     // 2 digit
+          + isRotated * 100000   // 1 digit
+          + planeNr * 1000       // 2 digit
+          + modinplaneNr * 1);   // 3 digit
+}
+
+void create_detector_layers(Int_t layerId)
+{
+  Int_t module_id               = 0;
+  Int_t layerType               = LayerType[layerId] / 10;  // this is also a station number
+  Int_t isRotated               = LayerType[layerId] % 10;  // is 1 for layers 2,4, ...
+  TGeoRotation* module_rotation = new TGeoRotation();
+
+  Int_t stationNr = layerType;
+
+  // rotation is now done in the for loop for each module individually
+  //  if ( isRotated == 1 ) {
+  //    module_rotation = new TGeoRotation();
+  //    module_rotation->RotateZ(90.);
+  //  } else {
+  //    module_rotation = new TGeoRotation();
+  //    module_rotation->RotateZ( 0.);
+  //  }
+
+  Int_t innerarray_size1 = LayerArraySize[layerType - 1][0];
+  Int_t innerarray_size2 = LayerArraySize[layerType - 1][1];
+  const Int_t* innerLayer;
+
+  Int_t outerarray_size1 = LayerArraySize[layerType - 1][2];
+  Int_t outerarray_size2 = LayerArraySize[layerType - 1][3];
+  const Int_t* outerLayer;
+
+  if (1 == layerType) {
+    innerLayer = (Int_t*) layer1i;
+    outerLayer = (Int_t*) layer1o;
+  }
+  else if (2 == layerType) {
+    innerLayer = (Int_t*) layer2i;
+    outerLayer = (Int_t*) layer2o;
+  }
+  else if (3 == layerType) {
+    innerLayer = (Int_t*) layer3i;
+    outerLayer = (Int_t*) layer3o;
+  }
+  else {
+    std::cout << "Type of layer not known" << std::endl;
+  }
+
+  // add layer keeping volume
+  TString layername = Form("layer%02d", PlaneId[layerId]);
+  TGeoVolume* layer = new TGeoVolumeAssembly(layername);
+
+  // compute layer copy number
+  Int_t i = LayerType[layerId] / 10 * 10000    // 1 digit  // fStation
+            + LayerType[layerId] % 10 * 1000   // 1 digit  // isRotated
+            + LayerNrInStation[layerId] * 100  // 1 digit  // fLayer
+            + PlaneId[layerId];
+  // 2 digits // fPlane   // layer type as leading digit in copy number of layer
+  gGeoMan->GetVolume(geoVersion)->AddNode(layer, i);
+
+  //  Int_t i = 100 + PlaneId[layerId];
+  //  gGeoMan->GetVolume(geoVersion)->AddNode(layer, 1);
+  //  cout << layername << endl;
+
+  Double_t ExplodeScale = 1.00;
+  if (DoExplode)  // if explosion, set scale
+    ExplodeScale = ExplodeFactor;
+
+  Int_t modId = 0;  // module id, only within this layer
+
+  Int_t copyNrIn[4] = {0, 0, 0, 0};  // copy number for each module type
+  for (Int_t type = 1; type <= 4; type++) {
+    for (Int_t j = (innerarray_size1 - 1); j >= 0; j--) {  // start from the bottom
+      for (Int_t i = 0; i < innerarray_size2; i++) {
+        module_id = *(innerLayer + (j * innerarray_size2 + i));
+        if (module_id / 100 == type) {
+          Float_t y = -(j - 4);
+          Float_t x = i - 1.5;
+
+          // displacement
+          Double_t dx = 0;
+          Double_t dy = 0;
+          Double_t dz = 0;
+
+          if (DisplaceRandom) {
+            dx = (r3.Rndm() - .5) * 2 * maxdx;  // max +- 0.1 cm shift
+            dy = (r3.Rndm() - .5) * 2 * maxdy;  // max +- 0.1 cm shift
+            dz = (r3.Rndm() - .5) * 2 * maxdz;  // max +- 1.0 cm shift
+          }
+
+          Double_t xPos = DetectorSizeX[0] * x * ExplodeScale + dx;
+          Double_t yPos = DetectorSizeY[0] * y * ExplodeScale + dy;
+          copyNrIn[type - 1]++;
+          modId++;
+
+          // statistics per layer and module type
+          ModuleStats[layerId][type - 1]++;
+
+          //          Int_t copy = copy_nr_modid(stationNr, layerNrInStation, copyNrIn[type - 1], PlaneId[layerId], modId);  // with modID
+          //          Int_t copy = copy_nr(stationNr, copyNrIn[type - 1], isRotated, PlaneId[layerId], modId);
+
+          // take care of FEB orientation - away from beam
+          Int_t copy      = 0;
+          module_rotation = new TGeoRotation();  // need to renew rotation to start from 0 degree angle
+          if (isRotated == 0)                    // layer 1,3 ...
+          {
+            copy = copy_nr(stationNr, copyNrIn[type - 1], module_id / 10 % 10, PlaneId[layerId], modId);
+            module_rotation->RotateZ(
+              (module_id / 10 % 10) * 90.);  // rotate module by   0 or 180 degrees, see layer[1-3][i,o] - vertical pads
+          }
+          else  // layer 2,4 ...
+          {
+            copy = copy_nr(stationNr, copyNrIn[type - 1], module_id % 10, PlaneId[layerId], modId);
+            module_rotation->RotateZ(
+              (module_id % 10) * 90.);  // rotate module by  90 or 270 degrees, see layer[1-3][i,o] - horizontal pads
+          }
+
+          // rotation
+          Double_t drotx = 0;
+          Double_t droty = 0;
+          Double_t drotz = 0;
+
+          if (RotateRandom) {
+            drotx = (r3.Rndm() - .5) * 2 * maxdrotx;
+            droty = (r3.Rndm() - .5) * 2 * maxdroty;
+            drotz = (r3.Rndm() - .5) * 2 * maxdrotz;
+
+            module_rotation->RotateZ(drotz);
+            module_rotation->RotateY(droty);
+            module_rotation->RotateX(drotx);
+          }
+
+          TGeoCombiTrans* module_placement =
+            new TGeoCombiTrans(xPos, yPos, LayerPosition[layerId] + LayerThickness / 2 + dz,
+                               module_rotation);  // shift by half layer thickness
+          //          gGeoMan->GetVolume(geoVersion)->AddNode(gModules[type - 1], copy, module_placement);
+          // add module to layer
+          gGeoMan->GetVolume(layername)->AddNode(gModules[type - 1], copy, module_placement);
+          //
+        }
+      }
+    }
+  }
+
+  Int_t copyNrOut[4] = {0, 0, 0, 0};  // copy number for each module type
+  for (Int_t type = 5; type <= 8; type++) {
+    for (Int_t j = (outerarray_size1 - 1); j >= 0; j--) {  // start from the bottom
+      for (Int_t i = 0; i < outerarray_size2; i++) {
+        module_id = *(outerLayer + (j * outerarray_size2 + i));
+        if (module_id / 100 == type) {
+          Float_t y = -(j - 4);
+          Float_t x = i - 5;
+
+          // displacement
+          Double_t dx = 0;
+          Double_t dy = 0;
+          Double_t dz = 0;
+
+          if (DisplaceRandom) {
+            dx = (r3.Rndm() - .5) * 2 * maxdx;  // max +- 0.1 cm shift
+            dy = (r3.Rndm() - .5) * 2 * maxdy;  // max +- 0.1 cm shift
+            dz = (r3.Rndm() - .5) * 2 * maxdz;  // max +- 1.0 cm shift
+          }
+
+          //          Double_t xPos = DetectorSizeX[1] * x * ExplodeScale + dx;
+          Double_t xPos = 0;
+
+          cout << "x before: " << x;
+          if (x > 0) {
+            x += -2 + 0.5;
+            xPos = 2 * DetectorSizeX[0] + DetectorSizeX[1] * x * ExplodeScale + dx;
+          }
+          else {
+            x += +2 - 0.5;
+            xPos = -2 * DetectorSizeX[0] + DetectorSizeX[1] * x * ExplodeScale + dx;
+          }
+          cout << " x after: " << x << endl;
+          Double_t yPos = DetectorSizeY[1] * y * ExplodeScale + dy;
+          copyNrOut[type - 5]++;
+          modId++;
+
+          // statistics per layer and module type
+          ModuleStats[layerId][type - 1]++;
+
+          //          Int_t copy = copy_nr_modid(stationNr, layerNrInStation, copyNrOut[type - 5],  PlaneId[layerId], modId);  // with modID
+          //          Int_t copy = copy_nr(stationNr, copyNrOut[type - 5], isRotated, PlaneId[layerId], modId);
+
+          // take care of FEB orientation - away from beam
+          Int_t copy      = 0;
+          module_rotation = new TGeoRotation();  // need to renew rotation to start from 0 degree angle
+          if (isRotated == 0)                    // layer 1,3 ...
+          {
+            copy = copy_nr(stationNr, copyNrOut[type - 5], module_id / 10 % 10, PlaneId[layerId], modId);
+            module_rotation->RotateZ(
+              (module_id / 10 % 10) * 90.);  // rotate module by   0 or 180 degrees, see layer[1-3][i,o] - vertical pads
+          }
+          else  // layer 2,4 ...
+          {
+            copy = copy_nr(stationNr, copyNrOut[type - 5], module_id % 10, PlaneId[layerId], modId);
+            module_rotation->RotateZ(
+              (module_id % 10) * 90.);  // rotate module by  90 or 270 degrees, see layer[1-3][i,o] - horizontal pads
+          }
+
+          // rotation
+          Double_t drotx = 0;
+          Double_t droty = 0;
+          Double_t drotz = 0;
+
+          if (RotateRandom) {
+            drotx = (r3.Rndm() - .5) * 2 * maxdrotx;
+            droty = (r3.Rndm() - .5) * 2 * maxdroty;
+            drotz = (r3.Rndm() - .5) * 2 * maxdrotz;
+
+            module_rotation->RotateZ(drotz);
+            module_rotation->RotateY(droty);
+            module_rotation->RotateX(drotx);
+          }
+
+          TGeoCombiTrans* module_placement =
+            new TGeoCombiTrans(xPos, yPos, LayerPosition[layerId] + LayerThickness / 2 + dz,
+                               module_rotation);  // shift by half layer thickness
+          //          gGeoMan->GetVolume(geoVersion)->AddNode(gModules[type - 1], copy, module_placement);
+          // add module to layer
+          gGeoMan->GetVolume(layername)->AddNode(gModules[type - 1], copy, module_placement);
+          //
+        }
+      }
+    }
+  }
+}
+
+
+void create_mag_field_vector()
+{
+  const TString cbmfield_01 = "cbm_field";
+  TGeoVolume* cbmfield_1    = new TGeoVolumeAssembly(cbmfield_01);
+
+  TGeoMedium* copperVolMed = gGeoMan->GetMedium(PadCopperVolumeMedium);  // define Volume Medium
+
+  TGeoRotation* rotx090 = new TGeoRotation("rotx090");
+  rotx090->RotateX(90.);  // rotate  90 deg around x-axis
+  TGeoRotation* rotx270 = new TGeoRotation("rotx270");
+  rotx270->RotateX(270.);  // rotate 270 deg around x-axis
+
+  Int_t tube_length = 500;
+  Int_t cone_length = 120;
+  Int_t cone_width  = 280;
+
+  // field tube
+  TGeoTube* trd_field          = new TGeoTube("", 0., 100 / 2., tube_length / 2.);
+  TGeoVolume* trdmod1_fieldvol = new TGeoVolume("tube", trd_field, copperVolMed);
+  trdmod1_fieldvol->SetLineColor(kRed);
+  trdmod1_fieldvol->SetTransparency(30);                                   // transparency for the TRD
+  TGeoTranslation* trd_field_trans = new TGeoTranslation("", 0., 0., 0.);  // tube position
+  cbmfield_1->AddNode(trdmod1_fieldvol, 1, trd_field_trans);
+
+  // field cone
+  TGeoCone* trd_cone          = new TGeoCone("", cone_length / 2., 0., cone_width / 2., 0., 0.);
+  TGeoVolume* trdmod1_conevol = new TGeoVolume("cone", trd_cone, copperVolMed);
+  trdmod1_conevol->SetLineColor(kRed);
+  trdmod1_conevol->SetTransparency(30);  // transparency for the TRD
+  TGeoTranslation* trd_cone_trans = new TGeoTranslation("", 0., 0., (tube_length + cone_length) / 2.);  // cone position
+  cbmfield_1->AddNode(trdmod1_conevol, 1, trd_cone_trans);
+
+  TGeoCombiTrans* field_combi01 = new TGeoCombiTrans(0., 0., 40., rotx270);  // point in +y direction
+  gGeoMan->GetVolume(geoVersion)->AddNode(cbmfield_1, 1, field_combi01);
+
+  //   TGeoCombiTrans* field_combi02 = new TGeoCombiTrans( 200., 0., 0., rotx090);   // point in -y direction
+  //   gGeoMan->GetVolume(geoVersion)->AddNode(cbmfield_1, 2, field_combi02);
+}
+
+
+void create_power_bars_vertical()
+{
+  const TString power_01 = "power_bars_trd1";
+  TGeoVolume* power_1    = new TGeoVolumeAssembly(power_01);
+
+  TGeoBBox* power1;
+  TGeoBBox* power2;
+
+  TGeoVolume* power1_vol;
+  TGeoVolume* power2_vol;
+
+  TGeoTranslation* power1_trans;
+  TGeoTranslation* power2_trans;
+
+  const Int_t kColor = kBlue;  // bus bar color
+
+  TGeoMedium* powerBusVolMed = gGeoMan->GetMedium(PowerBusVolumeMedium);
+
+  //  // powerbus - horizontal short
+  //  power1     = new TGeoBBox("power1", (DetectorSizeX[1] - DetectorSizeX[0] - powerbar_width)/2., powerbar_width /2., powerbar_thickness /2.);
+  //  power1_vol = new TGeoVolume("powerbus1", power1, powerBusVolMed);
+  //  power1_vol->SetLineColor(kColor);
+  //
+  //  // translations
+  //  power1_trans = new TGeoTranslation("",  1 * (DetectorSizeX[1] - DetectorSizeY[0]/2.),  1.5 * DetectorSizeY[1], 0.);
+  //  power_1->AddNode(power1_vol, 1, power1_trans);
+  //
+  //  power1_trans = new TGeoTranslation("", -1 * (DetectorSizeX[1] - DetectorSizeY[0]/2.), -1.5 * DetectorSizeY[1], 0.);
+  //  power_1->AddNode(power1_vol, 2, power1_trans);
+  //
+  //  // powerbus - horizontal long
+  //  power1     = new TGeoBBox("power1", (DetectorSizeX[0] - powerbar_width)/2., powerbar_width /2., powerbar_thickness /2.);
+  //  power1_vol = new TGeoVolume("powerbus1", power1, powerBusVolMed);
+  //  power1_vol->SetLineColor(kColor);
+  //
+  //  // translations
+  //  power1_trans = new TGeoTranslation("", -1 * DetectorSizeX[0],  1.5 * DetectorSizeY[1], 0.);
+  //  power_1->AddNode(power1_vol, 3, power1_trans);
+  //
+  //  power1_trans = new TGeoTranslation("",  1 * DetectorSizeX[0], -1.5 * DetectorSizeY[1], 0.);
+  //  power_1->AddNode(power1_vol, 4, power1_trans);
+
+
+  // powerbus - vertical long
+  power2 =
+    new TGeoBBox("power2", powerbar_width / 2., (9 * DetectorSizeY[0] + powerbar_width) / 2., powerbar_thickness / 2.);
+  power2_vol = new TGeoVolume("powerbus2", power2, powerBusVolMed);
+  power2_vol->SetLineColor(kColor);
+
+  // translations
+  power2_trans = new TGeoTranslation("", -(2.0 * DetectorSizeX[0] + 1.0 * DetectorSizeX[1]), 0., 0.);
+  power_1->AddNode(power2_vol, 1, power2_trans);
+  power2_trans = new TGeoTranslation("", 2.0 * DetectorSizeX[0] + 1.0 * DetectorSizeX[1], 0., 0.);
+  power_1->AddNode(power2_vol, 2, power2_trans);
+
+  power2_trans = new TGeoTranslation("", -1.0 * DetectorSizeX[0], 0., 0.);
+  power_1->AddNode(power2_vol, 3, power2_trans);
+  power2_trans = new TGeoTranslation("", 1.0 * DetectorSizeX[0], 0., 0.);
+  power_1->AddNode(power2_vol, 4, power2_trans);
+
+  //  // powerbus - vertical middle
+  //  power2     = new TGeoBBox("power2", powerbar_width /2., (3 * DetectorSizeY[1] + powerbar_width) /2., powerbar_thickness /2.);
+  //  power2_vol = new TGeoVolume("powerbus2", power2, powerBusVolMed);
+  //  power2_vol->SetLineColor(kColor);
+  //
+  //  // translations
+  //  power2_trans = new TGeoTranslation("", -1.5 * DetectorSizeX[0],  0., 0.);
+  //  power_1->AddNode(power2_vol, 7, power2_trans);
+  //  power2_trans = new TGeoTranslation("",  1.5 * DetectorSizeX[0],  0., 0.);
+  //  power_1->AddNode(power2_vol, 8, power2_trans);
+  //
+  //  // powerbus - vertical short 1
+  //  power2     = new TGeoBBox("power2", powerbar_width /2., 1 * DetectorSizeY[1] /2., powerbar_thickness /2.);
+  //  power2_vol = new TGeoVolume("powerbus2", power2, powerBusVolMed);
+  //  power2_vol->SetLineColor(kColor);
+  //  //  power2_vol->SetLineColor(kRed);
+  //
+  //  // translations
+  //  power2_trans = new TGeoTranslation("", -0.5 * DetectorSizeX[1],  (2.0 * DetectorSizeY[1] + powerbar_width/2.), 0.);
+  //  power_1->AddNode(power2_vol, 9, power2_trans);
+  //  power2_trans = new TGeoTranslation("",  0.5 * DetectorSizeX[1], -(2.0 * DetectorSizeY[1] + powerbar_width/2.), 0.);
+  //  power_1->AddNode(power2_vol,10, power2_trans);
+  //
+  //  // powerbus - vertical short 2
+  //  power2     = new TGeoBBox("power2", powerbar_width /2., (1 * DetectorSizeY[1] + powerbar_width) /2., powerbar_thickness /2.);
+  //  power2_vol = new TGeoVolume("powerbus2", power2, powerBusVolMed);
+  //  power2_vol->SetLineColor(kColor);
+  //
+  //  // translations
+  //  power2_trans = new TGeoTranslation("", -0.5 * DetectorSizeX[1], -2.0 * DetectorSizeY[1], 0.);
+  //  power_1->AddNode(power2_vol,11, power2_trans);
+  //  power2_trans = new TGeoTranslation("",  0.5 * DetectorSizeX[1],  2.0 * DetectorSizeY[1], 0.);
+  //  power_1->AddNode(power2_vol,12, power2_trans);
+  //
+  //  // powerbus - vertical short 3
+  //  power2     = new TGeoBBox("power2", powerbar_width /2., (2 * DetectorSizeY[0] + powerbar_width/2.) /2., powerbar_thickness /2.);
+  //  power2_vol = new TGeoVolume("powerbus2", power2, powerBusVolMed);
+  //  power2_vol->SetLineColor(kColor);
+  //
+  //  // translations
+  //  power2_trans = new TGeoTranslation("", -0.5 * DetectorSizeX[0],  (1.5 * DetectorSizeY[0] + powerbar_width/4.), 0.);
+  //  power_1->AddNode(power2_vol,11, power2_trans);
+  //  power2_trans = new TGeoTranslation("",  0.5 * DetectorSizeX[0], -(1.5 * DetectorSizeY[0] + powerbar_width/4.), 0.);
+  //  power_1->AddNode(power2_vol,12, power2_trans);
+
+  Int_t l;
+  for (l = 0; l < 4; l++)
+    if ((ShowLayer[l]) && (BusBarOrientation[l] == 1))  // if geometry contains layer l
+    {
+      TString layername = Form("layer%02d", l + 1);
+      TGeoTranslation* power_placement =
+        new TGeoTranslation(0, 0, LayerPosition[l] + LayerThickness / 2. + powerbar_position);
+      gGeoMan->GetVolume(layername)->AddNode(power_1, l, power_placement);
+    }
+}
+
+
+void create_power_bars_horizontal()
+{
+  const TString power_01 = "power_bars_trd1";
+  TGeoVolume* power_1    = new TGeoVolumeAssembly(power_01);
+
+  TGeoBBox* power1;
+  TGeoBBox* power2;
+
+  TGeoVolume* power1_vol;
+  TGeoVolume* power2_vol;
+
+  TGeoTranslation* power1_trans;
+  TGeoTranslation* power2_trans;
+
+  const Int_t kColor = kBlue;  // bus bar color
+
+  TGeoMedium* powerBusVolMed = gGeoMan->GetMedium(PowerBusVolumeMedium);
+
+  // powerbus - vertical short
+  power1     = new TGeoBBox("power1", powerbar_width / 2., (DetectorSizeY[1] - DetectorSizeY[0] - powerbar_width) / 2.,
+                        powerbar_thickness / 2.);
+  power1_vol = new TGeoVolume("powerbus1", power1, powerBusVolMed);
+  power1_vol->SetLineColor(kColor);
+
+  // translations
+  power1_trans = new TGeoTranslation("", 1.5 * DetectorSizeX[1], -1 * (DetectorSizeY[1] - DetectorSizeY[0] / 2.), 0.);
+  power_1->AddNode(power1_vol, 1, power1_trans);
+
+  power1_trans = new TGeoTranslation("", -1.5 * DetectorSizeX[1], 1 * (DetectorSizeY[1] - DetectorSizeY[0] / 2.), 0.);
+  power_1->AddNode(power1_vol, 2, power1_trans);
+
+  // powerbus - vertical long
+  power1 =
+    new TGeoBBox("power1", powerbar_width / 2., (DetectorSizeY[0] - powerbar_width) / 2., powerbar_thickness / 2.);
+  power1_vol = new TGeoVolume("powerbus1", power1, powerBusVolMed);
+  power1_vol->SetLineColor(kColor);
+
+  // translations
+  power1_trans = new TGeoTranslation("", 1.5 * DetectorSizeX[1], 1 * DetectorSizeY[0], 0.);
+  power_1->AddNode(power1_vol, 3, power1_trans);
+
+  power1_trans = new TGeoTranslation("", -1.5 * DetectorSizeX[1], -1 * DetectorSizeY[0], 0.);
+  power_1->AddNode(power1_vol, 4, power1_trans);
+
+
+  // powerbus - horizontal long
+  power2 =
+    new TGeoBBox("power2", (7 * DetectorSizeX[1] + powerbar_width) / 2., powerbar_width / 2., powerbar_thickness / 2.);
+  power2_vol = new TGeoVolume("powerbus2", power2, powerBusVolMed);
+  power2_vol->SetLineColor(kColor);
+
+  // translations
+  power2_trans = new TGeoTranslation("", 0., -2.5 * DetectorSizeY[1], 0.);
+  power_1->AddNode(power2_vol, 1, power2_trans);
+  power2_trans = new TGeoTranslation("", 0., 2.5 * DetectorSizeY[1], 0.);
+  power_1->AddNode(power2_vol, 2, power2_trans);
+
+  power2_trans = new TGeoTranslation("", 0., -1.5 * DetectorSizeY[1], 0.);
+  power_1->AddNode(power2_vol, 3, power2_trans);
+  power2_trans = new TGeoTranslation("", 0., 1.5 * DetectorSizeY[1], 0.);
+  power_1->AddNode(power2_vol, 4, power2_trans);
+
+  // powerbus - horizontal middle
+  power2 =
+    new TGeoBBox("power2", (3 * DetectorSizeX[1] + powerbar_width) / 2., powerbar_width / 2., powerbar_thickness / 2.);
+  power2_vol = new TGeoVolume("powerbus2", power2, powerBusVolMed);
+  power2_vol->SetLineColor(kColor);
+
+  // translations
+  power2_trans = new TGeoTranslation("", 0., -1.5 * DetectorSizeY[0], 0.);
+  power_1->AddNode(power2_vol, 7, power2_trans);
+  power2_trans = new TGeoTranslation("", 0., 1.5 * DetectorSizeY[0], 0.);
+  power_1->AddNode(power2_vol, 8, power2_trans);
+
+  // powerbus - horizontal short 1
+  power2     = new TGeoBBox("power2", 2 * DetectorSizeX[1] / 2., powerbar_width / 2., powerbar_thickness / 2.);
+  power2_vol = new TGeoVolume("powerbus2", power2, powerBusVolMed);
+  power2_vol->SetLineColor(kColor);
+  //  power2_vol->SetLineColor(kRed);
+
+  // translations
+  power2_trans = new TGeoTranslation("", (2.5 * DetectorSizeX[1] + powerbar_width / 2.), 0.5 * DetectorSizeY[1], 0.);
+  power_1->AddNode(power2_vol, 9, power2_trans);
+  power2_trans = new TGeoTranslation("", -(2.5 * DetectorSizeX[1] + powerbar_width / 2.), -0.5 * DetectorSizeY[1], 0.);
+  power_1->AddNode(power2_vol, 10, power2_trans);
+
+  // powerbus - horizontal short 2
+  power2 =
+    new TGeoBBox("power2", (2 * DetectorSizeX[1] + powerbar_width) / 2., powerbar_width / 2., powerbar_thickness / 2.);
+  power2_vol = new TGeoVolume("powerbus2", power2, powerBusVolMed);
+  power2_vol->SetLineColor(kColor);
+
+  // translations
+  power2_trans = new TGeoTranslation("", -2.5 * DetectorSizeX[1], 0.5 * DetectorSizeY[1], 0.);
+  power_1->AddNode(power2_vol, 11, power2_trans);
+  power2_trans = new TGeoTranslation("", 2.5 * DetectorSizeX[1], -0.5 * DetectorSizeY[1], 0.);
+  power_1->AddNode(power2_vol, 12, power2_trans);
+
+  // powerbus - horizontal short 3
+  power2     = new TGeoBBox("power2", (2 * DetectorSizeX[0] + powerbar_width / 2.) / 2., powerbar_width / 2.,
+                        powerbar_thickness / 2.);
+  power2_vol = new TGeoVolume("powerbus2", power2, powerBusVolMed);
+  power2_vol->SetLineColor(kColor);
+
+  // translations
+  power2_trans = new TGeoTranslation("", (1.5 * DetectorSizeX[0] + powerbar_width / 4.), 0.5 * DetectorSizeY[0], 0.);
+  power_1->AddNode(power2_vol, 11, power2_trans);
+  power2_trans = new TGeoTranslation("", -(1.5 * DetectorSizeX[0] + powerbar_width / 4.), -0.5 * DetectorSizeY[0], 0.);
+  power_1->AddNode(power2_vol, 12, power2_trans);
+
+  Int_t l;
+  for (l = 0; l < 4; l++)
+    if ((ShowLayer[l]) && (BusBarOrientation[l] == 0))  // if geometry contains layer l
+    {
+      TString layername = Form("layer%02d", l + 1);
+      TGeoTranslation* power_placement =
+        new TGeoTranslation(0, 0, LayerPosition[l] + LayerThickness / 2. + powerbar_position);
+      gGeoMan->GetVolume(layername)->AddNode(power_1, l, power_placement);
+    }
+}
+
+
+void create_xtru_supports()
+{
+  const TString trd_01 = "support_trd1";
+  TGeoVolume* trd_1    = new TGeoVolumeAssembly(trd_01);
+
+  const TString trd_02 = "support_trd2";
+  TGeoVolume* trd_2    = new TGeoVolumeAssembly(trd_02);
+
+  const TString trd_03 = "support_trd3";
+  TGeoVolume* trd_3    = new TGeoVolumeAssembly(trd_03);
+
+  //  const TString trdSupport = "supportframe";
+  //  TGeoVolume* trdsupport = new TGeoVolumeAssembly(trdSupport);
+  //
+  //  trdsupport->AddNode(trd_1, 1);
+  //  trdsupport->AddNode(trd_2, 2);
+  //  trdsupport->AddNode(trd_3, 3);
+
+  TGeoMedium* aluminiumVolMed = gGeoMan->GetMedium(AluminiumVolumeMedium);  // define Volume Medium
+
+  const Double_t x[12] = {-15, -15, -1, -1, -15, -15, 15, 15, 1, 1, 15, 15};  // IPB 400
+  const Double_t y[12] = {-20, -18, -18, 18,  18,  20,
+                          20,  18,  18,  -18, -18, -20};  // 30 x 40 cm in size, 2 cm wall thickness
+  const Double_t Hwid  = -2 * x[0];                       // 30
+  const Double_t Hhei  = -2 * y[0];                       // 40
+
+  Double_t AperX[3] = {450., 550., 600.};  // inner aperture in X of support structure for stations 1,2,3
+  Double_t AperY[3] = {350., 450., 500.};  // inner aperture in Y of support structure for stations 1,2,3
+  Double_t PilPosX;
+  Double_t BarPosY;
+
+  const Double_t BeamHeight = 570;  // beamline is at 5.7m above floor
+
+  Double_t PilPosZ[6];  // PilPosZ
+                        //  PilPosZ[0] = LayerPosition[0] + LayerThickness/2.;
+                        //  PilPosZ[1] = LayerPosition[3] + LayerThickness/2.;
+                        //  PilPosZ[2] = LayerPosition[4] + LayerThickness/2.;
+                        //  PilPosZ[3] = LayerPosition[7] + LayerThickness/2.;
+                        //  PilPosZ[4] = LayerPosition[8] + LayerThickness/2.;
+                        //  PilPosZ[5] = LayerPosition[9] + LayerThickness/2.;
+
+  PilPosZ[0] = LayerPosition[0] + 15;
+  PilPosZ[1] = LayerPosition[3] - 15 + LayerThickness;
+  PilPosZ[2] = LayerPosition[4] + 15;
+  PilPosZ[3] = LayerPosition[7] - 15 + LayerThickness;
+  PilPosZ[4] = LayerPosition[8] + 15;
+  PilPosZ[5] = LayerPosition[9] - 15 + LayerThickness;
+
+  //  cout << "PilPosZ[0]: " << PilPosZ[0] << endl;
+  //  cout << "PilPosZ[1]: " << PilPosZ[1] << endl;
+
+  TGeoRotation* rotx090 = new TGeoRotation("rotx090");
+  rotx090->RotateX(90.);  // rotate  90 deg around x-axis
+  TGeoRotation* roty090 = new TGeoRotation("roty090");
+  roty090->RotateY(90.);  // rotate  90 deg around y-axis
+  TGeoRotation* rotz090 = new TGeoRotation("rotz090");
+  rotz090->RotateZ(90.);  // rotate  90 deg around y-axis
+  TGeoRotation* roty270 = new TGeoRotation("roty270");
+  roty270->RotateY(270.);  // rotate 270 deg around y-axis
+
+  TGeoRotation* rotzx01 = new TGeoRotation("rotzx01");
+  rotzx01->RotateZ(90.);  // rotate  90 deg around z-axis
+  rotzx01->RotateX(90.);  // rotate  90 deg around x-axis
+
+  //  TGeoRotation  *rotxz01 = new TGeoRotation("rotxz01");
+  //  rotxz01->RotateX(  90.); // rotate  90 deg around x-axis
+  //  rotxz01->RotateZ(  90.); // rotate  90 deg around z-axis
+
+  Double_t ang1 = atan(3. / 4.) * 180. / acos(-1.);
+  //  cout << "DEDE " << ang1 << endl;
+  //  Double_t sin1 = acos(-1.);
+  //  cout << "DEDE " << sin1 << endl;
+  TGeoRotation* rotx080 = new TGeoRotation("rotx080");
+  rotx080->RotateX(90. - ang1);  // rotate  80 deg around x-axis
+  TGeoRotation* rotx100 = new TGeoRotation("rotx100");
+  rotx100->RotateX(90. + ang1);  // rotate 100 deg around x-axis
+
+  TGeoRotation* rotxy01 = new TGeoRotation("rotxy01");
+  rotxy01->RotateX(90.);    // rotate  90 deg around x-axis
+  rotxy01->RotateZ(-ang1);  // rotate  ang1   around rotated y-axis
+
+  TGeoRotation* rotxy02 = new TGeoRotation("rotxy02");
+  rotxy02->RotateX(90.);   // rotate  90 deg around x-axis
+  rotxy02->RotateZ(ang1);  // rotate  ang1   around rotated y-axis
+
+
+  //-------------------
+  // vertical pillars (Y)
+  //-------------------
+
+  // station 1
+  if (ShowLayer[0])  // if geometry contains layer 1 (1st layer of station 1)
+  {
+    TGeoXtru* trd_H_vert1 = new TGeoXtru(2);  // define Xtrusion of 2 planes
+    trd_H_vert1->DefinePolygon(12, x, y);
+    trd_H_vert1->DefineSection(0, -(AperY[0] + Hhei), 0, 0, 1.0);
+    trd_H_vert1->DefineSection(1, BeamHeight, 0, 0, 1.0);
+    TGeoVolume* trd_H_vert_vol1 = new TGeoVolume("trd_H_y_01", trd_H_vert1, aluminiumVolMed);
+    trd_H_vert_vol1->SetLineColor(kYellow);
+    PilPosX = AperX[0];
+
+    TGeoCombiTrans* trd_H_vert_combi01 = new TGeoCombiTrans((PilPosX + Hhei / 2.), 0., PilPosZ[0], rotzx01);
+    trd_1->AddNode(trd_H_vert_vol1, 11, trd_H_vert_combi01);
+    TGeoCombiTrans* trd_H_vert_combi02 = new TGeoCombiTrans(-(PilPosX + Hhei / 2.), 0., PilPosZ[0], rotzx01);
+    trd_1->AddNode(trd_H_vert_vol1, 12, trd_H_vert_combi02);
+    TGeoCombiTrans* trd_H_vert_combi03 = new TGeoCombiTrans((PilPosX + Hhei / 2.), 0., PilPosZ[1], rotzx01);
+    trd_1->AddNode(trd_H_vert_vol1, 13, trd_H_vert_combi03);
+    TGeoCombiTrans* trd_H_vert_combi04 = new TGeoCombiTrans(-(PilPosX + Hhei / 2.), 0., PilPosZ[1], rotzx01);
+    trd_1->AddNode(trd_H_vert_vol1, 14, trd_H_vert_combi04);
+  }
+
+  // station 2
+  if (ShowLayer[4])  // if geometry contains layer 5 (1st layer of station 2)
+  {
+    TGeoXtru* trd_H_vert1 = new TGeoXtru(2);  // define Xtrusion of 2 planes
+    trd_H_vert1->DefinePolygon(12, x, y);
+    trd_H_vert1->DefineSection(0, -(AperY[1] + Hhei), 0, 0, 1.0);
+    trd_H_vert1->DefineSection(1, BeamHeight, 0, 0, 1.0);
+    TGeoVolume* trd_H_vert_vol1 = new TGeoVolume("trd_H_y_02", trd_H_vert1, aluminiumVolMed);
+    trd_H_vert_vol1->SetLineColor(kYellow);
+    PilPosX = AperX[1];
+
+    TGeoCombiTrans* trd_H_vert_combi01 = new TGeoCombiTrans((PilPosX + Hhei / 2.), 0., PilPosZ[2], rotzx01);
+    trd_2->AddNode(trd_H_vert_vol1, 21, trd_H_vert_combi01);
+    TGeoCombiTrans* trd_H_vert_combi02 = new TGeoCombiTrans(-(PilPosX + Hhei / 2.), 0., PilPosZ[2], rotzx01);
+    trd_2->AddNode(trd_H_vert_vol1, 22, trd_H_vert_combi02);
+    TGeoCombiTrans* trd_H_vert_combi03 = new TGeoCombiTrans((PilPosX + Hhei / 2.), 0., PilPosZ[3], rotzx01);
+    trd_2->AddNode(trd_H_vert_vol1, 23, trd_H_vert_combi03);
+    TGeoCombiTrans* trd_H_vert_combi04 = new TGeoCombiTrans(-(PilPosX + Hhei / 2.), 0., PilPosZ[3], rotzx01);
+    trd_2->AddNode(trd_H_vert_vol1, 24, trd_H_vert_combi04);
+  }
+
+  // station 3
+  if (ShowLayer[8])  // if geometry contains layer 9 (1st layer of station 3)
+  {
+    TGeoXtru* trd_H_vert1 = new TGeoXtru(2);  // define Xtrusion of 2 planes
+    trd_H_vert1->DefinePolygon(12, x, y);
+    trd_H_vert1->DefineSection(0, -(AperY[2] + Hhei), 0, 0, 1.0);
+    trd_H_vert1->DefineSection(1, BeamHeight, 0, 0, 1.0);
+    TGeoVolume* trd_H_vert_vol1 = new TGeoVolume("trd_H_y_03", trd_H_vert1, aluminiumVolMed);
+    trd_H_vert_vol1->SetLineColor(kYellow);
+    PilPosX = AperX[2];
+
+    TGeoCombiTrans* trd_H_vert_combi01 = new TGeoCombiTrans((PilPosX + Hhei / 2.), 0., PilPosZ[4], rotzx01);
+    trd_3->AddNode(trd_H_vert_vol1, 31, trd_H_vert_combi01);
+    TGeoCombiTrans* trd_H_vert_combi02 = new TGeoCombiTrans(-(PilPosX + Hhei / 2.), 0., PilPosZ[4], rotzx01);
+    trd_3->AddNode(trd_H_vert_vol1, 32, trd_H_vert_combi02);
+    TGeoCombiTrans* trd_H_vert_combi03 = new TGeoCombiTrans((PilPosX + Hhei / 2.), 0., PilPosZ[5], rotzx01);
+    trd_3->AddNode(trd_H_vert_vol1, 33, trd_H_vert_combi03);
+    TGeoCombiTrans* trd_H_vert_combi04 = new TGeoCombiTrans(-(PilPosX + Hhei / 2.), 0., PilPosZ[5], rotzx01);
+    trd_3->AddNode(trd_H_vert_vol1, 34, trd_H_vert_combi04);
+  }
+
+
+  //-------------------
+  // horizontal supports (X)
+  //-------------------
+
+  // station 1
+  if (ShowLayer[0])  // if geometry contains layer 1 (1st layer of station 1)
+  {
+    TGeoXtru* trd_H_hori1 = new TGeoXtru(2);  // define Xtrusion of 2 planes
+    trd_H_hori1->DefinePolygon(12, x, y);
+    trd_H_hori1->DefineSection(0, -AperX[0], 0, 0, 1.0);
+    trd_H_hori1->DefineSection(1, AperX[0], 0, 0, 1.0);
+    TGeoVolume* trd_H_hori_vol1 = new TGeoVolume("trd_H_x_01", trd_H_hori1, aluminiumVolMed);
+    trd_H_hori_vol1->SetLineColor(kRed);
+    BarPosY = AperY[0];
+
+    TGeoCombiTrans* trd_H_hori_combi01 = new TGeoCombiTrans(0., (BarPosY + Hhei / 2.), PilPosZ[0], roty090);
+    trd_1->AddNode(trd_H_hori_vol1, 11, trd_H_hori_combi01);
+    TGeoCombiTrans* trd_H_hori_combi02 = new TGeoCombiTrans(0., -(BarPosY + Hhei / 2.), PilPosZ[0], roty090);
+    trd_1->AddNode(trd_H_hori_vol1, 12, trd_H_hori_combi02);
+    TGeoCombiTrans* trd_H_hori_combi03 = new TGeoCombiTrans(0., (BarPosY + Hhei / 2.), PilPosZ[1], roty090);
+    trd_1->AddNode(trd_H_hori_vol1, 13, trd_H_hori_combi03);
+    TGeoCombiTrans* trd_H_hori_combi04 = new TGeoCombiTrans(0., -(BarPosY + Hhei / 2.), PilPosZ[1], roty090);
+    trd_1->AddNode(trd_H_hori_vol1, 14, trd_H_hori_combi04);
+  }
+
+  // station 2
+  if (ShowLayer[4])  // if geometry contains layer 5 (1st layer of station 2)
+  {
+    TGeoXtru* trd_H_hori1 = new TGeoXtru(2);  // define Xtrusion of 2 planes
+    trd_H_hori1->DefinePolygon(12, x, y);
+    trd_H_hori1->DefineSection(0, -AperX[1], 0, 0, 1.0);
+    trd_H_hori1->DefineSection(1, AperX[1], 0, 0, 1.0);
+    TGeoVolume* trd_H_hori_vol1 = new TGeoVolume("trd_H_x_02", trd_H_hori1, aluminiumVolMed);
+    trd_H_hori_vol1->SetLineColor(kRed);
+    BarPosY = AperY[1];
+
+    TGeoCombiTrans* trd_H_hori_combi01 = new TGeoCombiTrans(0., (BarPosY + Hhei / 2.), PilPosZ[2], roty090);
+    trd_2->AddNode(trd_H_hori_vol1, 21, trd_H_hori_combi01);
+    TGeoCombiTrans* trd_H_hori_combi02 = new TGeoCombiTrans(0., -(BarPosY + Hhei / 2.), PilPosZ[2], roty090);
+    trd_2->AddNode(trd_H_hori_vol1, 22, trd_H_hori_combi02);
+    TGeoCombiTrans* trd_H_hori_combi03 = new TGeoCombiTrans(0., (BarPosY + Hhei / 2.), PilPosZ[3], roty090);
+    trd_2->AddNode(trd_H_hori_vol1, 23, trd_H_hori_combi03);
+    TGeoCombiTrans* trd_H_hori_combi04 = new TGeoCombiTrans(0., -(BarPosY + Hhei / 2.), PilPosZ[3], roty090);
+    trd_2->AddNode(trd_H_hori_vol1, 24, trd_H_hori_combi04);
+  }
+
+  // station 3
+  if (ShowLayer[8])  // if geometry contains layer 9 (1st layer of station 3)
+  {
+    TGeoXtru* trd_H_hori1 = new TGeoXtru(2);  // define Xtrusion of 2 planes
+    trd_H_hori1->DefinePolygon(12, x, y);
+    trd_H_hori1->DefineSection(0, -AperX[2], 0, 0, 1.0);
+    trd_H_hori1->DefineSection(1, AperX[2], 0, 0, 1.0);
+    TGeoVolume* trd_H_hori_vol1 = new TGeoVolume("trd_H_x_03", trd_H_hori1, aluminiumVolMed);
+    trd_H_hori_vol1->SetLineColor(kRed);
+    BarPosY = AperY[2];
+
+    TGeoCombiTrans* trd_H_hori_combi01 = new TGeoCombiTrans(0., (BarPosY + Hhei / 2.), PilPosZ[4], roty090);
+    trd_3->AddNode(trd_H_hori_vol1, 31, trd_H_hori_combi01);
+    TGeoCombiTrans* trd_H_hori_combi02 = new TGeoCombiTrans(0., -(BarPosY + Hhei / 2.), PilPosZ[4], roty090);
+    trd_3->AddNode(trd_H_hori_vol1, 32, trd_H_hori_combi02);
+    TGeoCombiTrans* trd_H_hori_combi03 = new TGeoCombiTrans(0., (BarPosY + Hhei / 2.), PilPosZ[5], roty090);
+    trd_3->AddNode(trd_H_hori_vol1, 33, trd_H_hori_combi03);
+    TGeoCombiTrans* trd_H_hori_combi04 = new TGeoCombiTrans(0., -(BarPosY + Hhei / 2.), PilPosZ[5], roty090);
+    trd_3->AddNode(trd_H_hori_vol1, 34, trd_H_hori_combi04);
+  }
+
+
+  //-------------------
+  // horizontal supports (Z)
+  //-------------------
+
+  // station 1
+  if (ShowLayer[0])  // if geometry contains layer 1 (1st layer of station 1)
+  {
+    TGeoXtru* trd_H_slope1 = new TGeoXtru(2);  // define Xtrusion of 2 planes
+    trd_H_slope1->DefinePolygon(12, x, y);
+    trd_H_slope1->DefineSection(0, -(PilPosZ[1] - PilPosZ[0] - Hwid) / 2., 0, 0, 1.0);
+    trd_H_slope1->DefineSection(1, +(PilPosZ[1] - PilPosZ[0] - Hwid) / 2., 0, 0, 1.0);
+    TGeoVolume* trd_H_slope_vol1 = new TGeoVolume("trd_H_z_01", trd_H_slope1, aluminiumVolMed);
+    trd_H_slope_vol1->SetLineColor(kGreen);
+    PilPosX = AperX[0];
+    BarPosY = AperY[0];
+
+    TGeoCombiTrans* trd_H_slope_combi01 =
+      new TGeoCombiTrans((PilPosX + Hhei / 2.), (BarPosY + Hhei - Hwid / 2.), (PilPosZ[0] + PilPosZ[1]) / 2., rotz090);
+    trd_1->AddNode(trd_H_slope_vol1, 11, trd_H_slope_combi01);
+    TGeoCombiTrans* trd_H_slope_combi02 =
+      new TGeoCombiTrans(-(PilPosX + Hhei / 2.), (BarPosY + Hhei - Hwid / 2.), (PilPosZ[0] + PilPosZ[1]) / 2., rotz090);
+    trd_1->AddNode(trd_H_slope_vol1, 12, trd_H_slope_combi02);
+    TGeoCombiTrans* trd_H_slope_combi03 =
+      new TGeoCombiTrans((PilPosX + Hhei / 2.), -(BarPosY + Hhei - Hwid / 2.), (PilPosZ[0] + PilPosZ[1]) / 2., rotz090);
+    trd_1->AddNode(trd_H_slope_vol1, 13, trd_H_slope_combi03);
+    TGeoCombiTrans* trd_H_slope_combi04 = new TGeoCombiTrans(-(PilPosX + Hhei / 2.), -(BarPosY + Hhei - Hwid / 2.),
+                                                             (PilPosZ[0] + PilPosZ[1]) / 2., rotz090);
+    trd_1->AddNode(trd_H_slope_vol1, 14, trd_H_slope_combi04);
+  }
+
+  // station 2
+  if (ShowLayer[4])  // if geometry contains layer 5 (1st layer of station 2)
+  {
+    TGeoXtru* trd_H_slope1 = new TGeoXtru(2);  // define Xtrusion of 2 planes
+    trd_H_slope1->DefinePolygon(12, x, y);
+    trd_H_slope1->DefineSection(0, -(PilPosZ[3] - PilPosZ[2] - Hwid) / 2., 0, 0, 1.0);
+    trd_H_slope1->DefineSection(1, +(PilPosZ[3] - PilPosZ[2] - Hwid) / 2., 0, 0, 1.0);
+    TGeoVolume* trd_H_slope_vol1 = new TGeoVolume("trd_H_z_02", trd_H_slope1, aluminiumVolMed);
+    trd_H_slope_vol1->SetLineColor(kGreen);
+    PilPosX = AperX[1];
+    BarPosY = AperY[1];
+
+    TGeoCombiTrans* trd_H_slope_combi01 =
+      new TGeoCombiTrans((PilPosX + Hhei / 2.), (BarPosY + Hhei - Hwid / 2.), (PilPosZ[2] + PilPosZ[3]) / 2., rotz090);
+    trd_2->AddNode(trd_H_slope_vol1, 21, trd_H_slope_combi01);
+    TGeoCombiTrans* trd_H_slope_combi02 =
+      new TGeoCombiTrans(-(PilPosX + Hhei / 2.), (BarPosY + Hhei - Hwid / 2.), (PilPosZ[2] + PilPosZ[3]) / 2., rotz090);
+    trd_2->AddNode(trd_H_slope_vol1, 22, trd_H_slope_combi02);
+    TGeoCombiTrans* trd_H_slope_combi03 =
+      new TGeoCombiTrans((PilPosX + Hhei / 2.), -(BarPosY + Hhei - Hwid / 2.), (PilPosZ[2] + PilPosZ[3]) / 2., rotz090);
+    trd_2->AddNode(trd_H_slope_vol1, 23, trd_H_slope_combi03);
+    TGeoCombiTrans* trd_H_slope_combi04 = new TGeoCombiTrans(-(PilPosX + Hhei / 2.), -(BarPosY + Hhei - Hwid / 2.),
+                                                             (PilPosZ[2] + PilPosZ[3]) / 2., rotz090);
+    trd_2->AddNode(trd_H_slope_vol1, 24, trd_H_slope_combi04);
+  }
+
+  // station 3
+  if (ShowLayer[8])  // if geometry contains layer 9 (1st layer of station 3)
+  {
+    TGeoXtru* trd_H_slope1 = new TGeoXtru(2);  // define Xtrusion of 2 planes
+    trd_H_slope1->DefinePolygon(12, x, y);
+    trd_H_slope1->DefineSection(0, -(PilPosZ[5] - PilPosZ[4] - Hwid) / 2., 0, 0, 1.0);
+    trd_H_slope1->DefineSection(1, +(PilPosZ[5] - PilPosZ[4] - Hwid) / 2., 0, 0, 1.0);
+    TGeoVolume* trd_H_slope_vol1 = new TGeoVolume("trd_H_z_03", trd_H_slope1, aluminiumVolMed);
+    trd_H_slope_vol1->SetLineColor(kGreen);
+    PilPosX = AperX[2];
+    BarPosY = AperY[2];
+
+    TGeoCombiTrans* trd_H_slope_combi01 =
+      new TGeoCombiTrans((PilPosX + Hhei / 2.), (BarPosY + Hhei - Hwid / 2.), (PilPosZ[4] + PilPosZ[5]) / 2., rotz090);
+    trd_3->AddNode(trd_H_slope_vol1, 31, trd_H_slope_combi01);
+    TGeoCombiTrans* trd_H_slope_combi02 =
+      new TGeoCombiTrans(-(PilPosX + Hhei / 2.), (BarPosY + Hhei - Hwid / 2.), (PilPosZ[4] + PilPosZ[5]) / 2., rotz090);
+    trd_3->AddNode(trd_H_slope_vol1, 32, trd_H_slope_combi02);
+    TGeoCombiTrans* trd_H_slope_combi03 =
+      new TGeoCombiTrans((PilPosX + Hhei / 2.), -(BarPosY + Hhei - Hwid / 2.), (PilPosZ[4] + PilPosZ[5]) / 2., rotz090);
+    trd_3->AddNode(trd_H_slope_vol1, 33, trd_H_slope_combi03);
+    TGeoCombiTrans* trd_H_slope_combi04 = new TGeoCombiTrans(-(PilPosX + Hhei / 2.), -(BarPosY + Hhei - Hwid / 2.),
+                                                             (PilPosZ[4] + PilPosZ[5]) / 2., rotz090);
+    trd_3->AddNode(trd_H_slope_vol1, 34, trd_H_slope_combi04);
+  }
+
+  if (IncludeLabels) {
+
+    Int_t text_height    = 40;
+    Int_t text_thickness = 8;
+
+    TGeoTranslation* tr200 =
+      new TGeoTranslation(0., (AperY[0] + Hhei + text_height / 2.), PilPosZ[0] - 15 + text_thickness / 2.);
+    TGeoTranslation* tr201 =
+      new TGeoTranslation(0., (AperY[1] + Hhei + text_height / 2.), PilPosZ[2] - 15 + text_thickness / 2.);
+    TGeoTranslation* tr202 =
+      new TGeoTranslation(0., (AperY[2] + Hhei + text_height / 2.), PilPosZ[4] - 15 + text_thickness / 2.);
+
+    TGeoCombiTrans* tr203 =
+      new TGeoCombiTrans(-(AperX[0] + Hhei + text_thickness / 2.), (AperY[0] + Hhei - Hwid - text_height / 2.),
+                         (PilPosZ[0] + PilPosZ[1]) / 2., roty090);
+    TGeoCombiTrans* tr204 =
+      new TGeoCombiTrans(-(AperX[1] + Hhei + text_thickness / 2.), (AperY[1] + Hhei - Hwid - text_height / 2.),
+                         (PilPosZ[2] + PilPosZ[3]) / 2., roty090);
+    TGeoCombiTrans* tr205 =
+      new TGeoCombiTrans(-(AperX[2] + Hhei + text_thickness / 2.), (AperY[2] + Hhei - Hwid - text_height / 2.),
+                         (PilPosZ[4] + PilPosZ[5]) / 2., roty090);
+
+    TGeoCombiTrans* tr206 =
+      new TGeoCombiTrans((AperX[0] + Hhei + text_thickness / 2.), (AperY[0] + Hhei - Hwid - text_height / 2.),
+                         (PilPosZ[0] + PilPosZ[1]) / 2., roty270);
+    TGeoCombiTrans* tr207 =
+      new TGeoCombiTrans((AperX[1] + Hhei + text_thickness / 2.), (AperY[1] + Hhei - Hwid - text_height / 2.),
+                         (PilPosZ[2] + PilPosZ[3]) / 2., roty270);
+    TGeoCombiTrans* tr208 =
+      new TGeoCombiTrans((AperX[2] + Hhei + text_thickness / 2.), (AperY[2] + Hhei - Hwid - text_height / 2.),
+                         (PilPosZ[4] + PilPosZ[5]) / 2., roty270);
+
+    TGeoVolume* trdbox1 = new TGeoVolumeAssembly("trdbox1");  // volume for TRD text (108, 40, 8)
+    TGeoVolume* trdbox2 = new TGeoVolumeAssembly("trdbox2");  // volume for TRD text (108, 40, 8)
+    TGeoVolume* trdbox3 = new TGeoVolumeAssembly("trdbox3");  // volume for TRD text (108, 40, 8)
+    add_trd_labels(trdbox1, trdbox2, trdbox3);
+
+    // final placement
+    if (ShowLayer[0])  // if geometry contains layer 1 (1st layer of station 1)
+    {
+      //    trd_1->AddNode(trdbox1, 1, tr200);
+      trd_1->AddNode(trdbox1, 4, tr203);
+      trd_1->AddNode(trdbox1, 7, tr206);
+    }
+    if (ShowLayer[4])  // if geometry contains layer 5 (1st layer of station 2)
+    {
+      //    trd_2->AddNode(trdbox2, 2, tr201);
+      trd_2->AddNode(trdbox2, 5, tr204);
+      trd_2->AddNode(trdbox2, 8, tr207);
+    }
+    if (ShowLayer[8])  // if geometry contains layer 9 (1st layer of station 3)
+    {
+      //    trd_3->AddNode(trdbox3, 3, tr202);
+      trd_3->AddNode(trdbox3, 6, tr205);
+      trd_3->AddNode(trdbox3, 9, tr208);
+    }
+  }
+
+  //  gGeoMan->GetVolume(geoVersion)->AddNode(trdsupport,1);
+
+  if (ShowLayer[0])  // if geometry contains layer 1 (1st layer of station 1)
+    gGeoMan->GetVolume(geoVersion)->AddNode(trd_1, 1);
+  if (ShowLayer[4])  // if geometry contains layer 5 (1st layer of station 2)
+    gGeoMan->GetVolume(geoVersion)->AddNode(trd_2, 2);
+  if (ShowLayer[8])  // if geometry contains layer 9 (1st layer of station 3)
+    gGeoMan->GetVolume(geoVersion)->AddNode(trd_3, 3);
+}
+
+
+void add_trd_labels(TGeoVolume* trdbox1, TGeoVolume* trdbox2, TGeoVolume* trdbox3)
+{
+  // write TRD (the 3 characters) in a simple geometry
+  TGeoMedium* textVolMed = gGeoMan->GetMedium(TextVolumeMedium);
+
+  Int_t Tcolor = kBlue;  // kRed;
+  Int_t Rcolor = kBlue;  // kRed;  // kRed;
+  Int_t Dcolor = kBlue;  // kRed;  // kYellow;
+  Int_t Icolor = kBlue;  // kRed;
+
+  // define transformations for letter pieces
+  // T
+  TGeoTranslation* tr01 = new TGeoTranslation(0., -4., 0.);
+  TGeoTranslation* tr02 = new TGeoTranslation(0., 16., 0.);
+
+  // R
+  TGeoTranslation* tr11 = new TGeoTranslation(10, 0., 0.);
+  TGeoTranslation* tr12 = new TGeoTranslation(2, 0., 0.);
+  TGeoTranslation* tr13 = new TGeoTranslation(2, 16., 0.);
+  TGeoTranslation* tr14 = new TGeoTranslation(-2, 8., 0.);
+  TGeoTranslation* tr15 = new TGeoTranslation(-6, 0., 0.);
+
+  // D
+  TGeoTranslation* tr21 = new TGeoTranslation(12., 0., 0.);
+  TGeoTranslation* tr22 = new TGeoTranslation(6., 16., 0.);
+  TGeoTranslation* tr23 = new TGeoTranslation(6., -16., 0.);
+  TGeoTranslation* tr24 = new TGeoTranslation(4., 0., 0.);
+
+  // I
+  TGeoTranslation* tr31 = new TGeoTranslation(0., 0., 0.);
+  TGeoTranslation* tr32 = new TGeoTranslation(0., 16., 0.);
+  TGeoTranslation* tr33 = new TGeoTranslation(0., -16., 0.);
+
+  // make letter T
+  //   TGeoVolume *T = geom->MakeBox("T", Vacuum, 25., 25., 5.);
+  //   T->SetVisibility(kFALSE);
+  TGeoVolume* T = new TGeoVolumeAssembly("Tbox");  // volume for T
+
+  TGeoBBox* Tbar1b  = new TGeoBBox("trd_Tbar1b", 4., 16., 4.);  // | vertical
+  TGeoVolume* Tbar1 = new TGeoVolume("Tbar1", Tbar1b, textVolMed);
+  Tbar1->SetLineColor(Tcolor);
+  T->AddNode(Tbar1, 1, tr01);
+  TGeoBBox* Tbar2b  = new TGeoBBox("trd_Tbar2b", 16, 4., 4.);  // - top
+  TGeoVolume* Tbar2 = new TGeoVolume("Tbar2", Tbar2b, textVolMed);
+  Tbar2->SetLineColor(Tcolor);
+  T->AddNode(Tbar2, 1, tr02);
+
+  // make letter R
+  //   TGeoVolume *R = geom->MakeBox("R", Vacuum, 25., 25., 5.);
+  //   R->SetVisibility(kFALSE);
+  TGeoVolume* R = new TGeoVolumeAssembly("Rbox");  // volume for R
+
+  TGeoBBox* Rbar1b  = new TGeoBBox("trd_Rbar1b", 4., 20, 4.);
+  TGeoVolume* Rbar1 = new TGeoVolume("Rbar1", Rbar1b, textVolMed);
+  Rbar1->SetLineColor(Rcolor);
+  R->AddNode(Rbar1, 1, tr11);
+  TGeoBBox* Rbar2b  = new TGeoBBox("trd_Rbar2b", 4., 4., 4.);
+  TGeoVolume* Rbar2 = new TGeoVolume("Rbar2", Rbar2b, textVolMed);
+  Rbar2->SetLineColor(Rcolor);
+  R->AddNode(Rbar2, 1, tr12);
+  R->AddNode(Rbar2, 2, tr13);
+  TGeoTubeSeg* Rtub1b = new TGeoTubeSeg("trd_Rtub1b", 4., 12, 4., 90., 270.);
+  TGeoVolume* Rtub1   = new TGeoVolume("Rtub1", (TGeoShape*) Rtub1b, textVolMed);
+  Rtub1->SetLineColor(Rcolor);
+  R->AddNode(Rtub1, 1, tr14);
+  TGeoArb8* Rbar3b  = new TGeoArb8("trd_Rbar3b", 4.);
+  TGeoVolume* Rbar3 = new TGeoVolume("Rbar3", Rbar3b, textVolMed);
+  Rbar3->SetLineColor(Rcolor);
+  TGeoArb8* arb = (TGeoArb8*) Rbar3->GetShape();
+  arb->SetVertex(0, 12., -4.);
+  arb->SetVertex(1, 0., -20.);
+  arb->SetVertex(2, -8., -20.);
+  arb->SetVertex(3, 4., -4.);
+  arb->SetVertex(4, 12., -4.);
+  arb->SetVertex(5, 0., -20.);
+  arb->SetVertex(6, -8., -20.);
+  arb->SetVertex(7, 4., -4.);
+  R->AddNode(Rbar3, 1, tr15);
+
+  // make letter D
+  //   TGeoVolume *D = geom->MakeBox("D", Vacuum, 25., 25., 5.);
+  //   D->SetVisibility(kFALSE);
+  TGeoVolume* D = new TGeoVolumeAssembly("Dbox");  // volume for D
+
+  TGeoBBox* Dbar1b  = new TGeoBBox("trd_Dbar1b", 4., 20, 4.);
+  TGeoVolume* Dbar1 = new TGeoVolume("Dbar1", Dbar1b, textVolMed);
+  Dbar1->SetLineColor(Dcolor);
+  D->AddNode(Dbar1, 1, tr21);
+  TGeoBBox* Dbar2b  = new TGeoBBox("trd_Dbar2b", 2., 4., 4.);
+  TGeoVolume* Dbar2 = new TGeoVolume("Dbar2", Dbar2b, textVolMed);
+  Dbar2->SetLineColor(Dcolor);
+  D->AddNode(Dbar2, 1, tr22);
+  D->AddNode(Dbar2, 2, tr23);
+  TGeoTubeSeg* Dtub1b = new TGeoTubeSeg("trd_Dtub1b", 12, 20, 4., 90., 270.);
+  TGeoVolume* Dtub1   = new TGeoVolume("Dtub1", (TGeoShape*) Dtub1b, textVolMed);
+  Dtub1->SetLineColor(Dcolor);
+  D->AddNode(Dtub1, 1, tr24);
+
+  // make letter I
+  TGeoVolume* I = new TGeoVolumeAssembly("Ibox");  // volume for I
+
+  TGeoBBox* Ibar1b  = new TGeoBBox("trd_Ibar1b", 4., 12., 4.);  // | vertical
+  TGeoVolume* Ibar1 = new TGeoVolume("Ibar1", Ibar1b, textVolMed);
+  Ibar1->SetLineColor(Icolor);
+  I->AddNode(Ibar1, 1, tr31);
+  TGeoBBox* Ibar2b  = new TGeoBBox("trd_Ibar2b", 10., 4., 4.);  // - top
+  TGeoVolume* Ibar2 = new TGeoVolume("Ibar2", Ibar2b, textVolMed);
+  Ibar2->SetLineColor(Icolor);
+  I->AddNode(Ibar2, 1, tr32);
+  I->AddNode(Ibar2, 2, tr33);
+
+
+  // build text block "TRD"  <32> + 8 + <28> + 8 + <32> = 108
+
+  //  TGeoBBox *trdboxb = new TGeoBBox("", 108./2, 40./2, 8./2);
+  //  TGeoVolume *trdbox = new TGeoVolume("trdboxb", trdboxb, textVolMed);
+  //  trdbox->SetVisibility(kFALSE);
+
+  //  TGeoVolume* trdbox[0] = new TGeoVolumeAssembly("trdbox1"); // volume for TRD text (108, 40, 8)
+  //  TGeoVolume* trdbox[1] = new TGeoVolumeAssembly("trdbox2"); // volume for TRD text (108, 40, 8)
+  //  TGeoVolume* trdbox[2] = new TGeoVolumeAssembly("trdbox3"); // volume for TRD text (108, 40, 8)
+
+  TGeoTranslation* tr100 = new TGeoTranslation(38., 0., 0.);
+  TGeoTranslation* tr101 = new TGeoTranslation(0., 0., 0.);
+  TGeoTranslation* tr102 = new TGeoTranslation(-38., 0., 0.);
+
+  //  TGeoTranslation *tr103 = new TGeoTranslation( -70., 0., 0.);  // on the same line
+  //  TGeoTranslation *tr104 = new TGeoTranslation( -86., 0., 0.);  // on the same line
+  //  TGeoTranslation *tr105 = new TGeoTranslation(-102., 0., 0.);  // on the same line
+
+  TGeoTranslation* tr110 = new TGeoTranslation(0., -50., 0.);
+  TGeoTranslation* tr111 = new TGeoTranslation(8., -50., 0.);
+  TGeoTranslation* tr112 = new TGeoTranslation(-8., -50., 0.);
+  TGeoTranslation* tr113 = new TGeoTranslation(16., -50., 0.);
+  TGeoTranslation* tr114 = new TGeoTranslation(-16., -50., 0.);
+
+  TGeoTranslation* tr200 = new TGeoTranslation(0., 0., 0.);
+  TGeoTranslation* tr201 = new TGeoTranslation(0., -50., 0.);
+  TGeoTranslation* tr202 = new TGeoTranslation(0., -100., 0.);
+
+  TGeoTranslation* tr210 = new TGeoTranslation(0., -150., 0.);
+  TGeoTranslation* tr213 = new TGeoTranslation(16., -150., 0.);
+  TGeoTranslation* tr214 = new TGeoTranslation(-16., -150., 0.);
+
+  // station 1
+  trdbox1->AddNode(T, 1, tr100);
+  trdbox1->AddNode(R, 1, tr101);
+  trdbox1->AddNode(D, 1, tr102);
+
+  trdbox1->AddNode(I, 1, tr110);
+
+  // station 2
+  trdbox2->AddNode(T, 1, tr100);
+  trdbox2->AddNode(R, 1, tr101);
+  trdbox2->AddNode(D, 1, tr102);
+
+  trdbox2->AddNode(I, 1, tr111);
+  trdbox2->AddNode(I, 2, tr112);
+
+  //// station 3
+  //  trdbox3->AddNode(T, 1, tr100);
+  //  trdbox3->AddNode(R, 1, tr101);
+  //  trdbox3->AddNode(D, 1, tr102);
+  //
+  //  trdbox3->AddNode(I, 1, tr110);
+  //  trdbox3->AddNode(I, 2, tr113);
+  //  trdbox3->AddNode(I, 3, tr114);
+
+  // station 3
+  trdbox3->AddNode(T, 1, tr200);
+  trdbox3->AddNode(R, 1, tr201);
+  trdbox3->AddNode(D, 1, tr202);
+
+  trdbox3->AddNode(I, 1, tr210);
+  trdbox3->AddNode(I, 2, tr213);
+  trdbox3->AddNode(I, 3, tr214);
+
+  //  TGeoScale *sc100 = new TGeoScale( 36./50., 36./50., 1.);  // text is vertical 50 cm, H-bar opening is 36 cm
+  //
+  //  // scale text
+  //  TGeoHMatrix *mat100 = new TGeoHMatrix("");
+  //  TGeoHMatrix *mat101 = new TGeoHMatrix("");
+  //  TGeoHMatrix *mat102 = new TGeoHMatrix("");
+  //  (*mat100) = (*tr100) * (*sc100);
+  //  (*mat101) = (*tr101) * (*sc100);
+  //  (*mat102) = (*tr102) * (*sc100);
+  //
+  //  trdbox->AddNode(T, 1, mat100);
+  //  trdbox->AddNode(R, 1, mat101);
+  //  trdbox->AddNode(D, 1, mat102);
+
+  //   // final placement
+  //   //   TGeoTranslation *tr103 = new TGeoTranslation(0., 400., 500.);
+  //   gGeoMan->GetVolume(geoVersion)->AddNode(trdbox, 1, new TGeoTranslation(0., 400., 500.));
+  //   gGeoMan->GetVolume(geoVersion)->AddNode(trdbox, 2, new TGeoTranslation(0., 500., 600.));
+  //   gGeoMan->GetVolume(geoVersion)->AddNode(trdbox, 3, new TGeoTranslation(0., 600., 700.));
+
+  //  return trdbox;
+}
+
+
+void create_box_supports()
+{
+  const TString trd_01 = "support_trd1";
+  TGeoVolume* trd_1    = new TGeoVolumeAssembly(trd_01);
+
+  const TString trd_02 = "support_trd2";
+  TGeoVolume* trd_2    = new TGeoVolumeAssembly(trd_02);
+
+  const TString trd_03 = "support_trd3";
+  TGeoVolume* trd_3    = new TGeoVolumeAssembly(trd_03);
+
+  //  const TString trdSupport = "supportframe";
+  //  TGeoVolume* trdsupport = new TGeoVolumeAssembly(trdSupport);
+  //
+  //  trdsupport->AddNode(trd_1, 1);
+  //  trdsupport->AddNode(trd_2, 2);
+  //  trdsupport->AddNode(trd_3, 3);
+
+  TGeoMedium* keepVolMed      = gGeoMan->GetMedium(KeepingVolumeMedium);
+  TGeoMedium* aluminiumVolMed = gGeoMan->GetMedium(AluminiumVolumeMedium);  // define Volume Medium
+
+  const Int_t I_height = 40;  // cm // I profile properties
+  const Int_t I_width  = 30;  // cm // I profile properties
+  const Int_t I_thick  = 2;   // cm // I profile properties
+
+  const Double_t BeamHeight     = 570;  // beamline is at 5.7m above the floor
+  const Double_t PlatformHeight = 234;  // platform is   2.34m above the floor
+  const Double_t PlatformOffset = 1;    // distance to platform
+
+  //  Double_t AperX[3] = { 450., 550., 600.};  // 100 cm modules  // inner aperture in X of support structure for stations 1,2,3
+  //  Double_t AperY[3] = { 350., 450., 500.};  // 100 cm modules  // inner aperture in Y of support structure for stations 1,2,3
+
+  const Double_t AperX[3] = {4.5 * DetectorSizeX[1], 5.5 * DetectorSizeX[1], 6 * DetectorSizeX[1]};
+  // inner aperture in X of support structure for stations 1,2,3
+  const Double_t AperY[3] = {3.5 * DetectorSizeY[1], 4.5 * DetectorSizeY[1], 5 * DetectorSizeY[1]};
+  // inner aperture in Y of support structure for stations 1,2,3
+  // platform
+  const Double_t AperYbot[3] = {BeamHeight - (PlatformHeight + PlatformOffset + I_height), 4.5 * DetectorSizeY[1],
+                                5 * DetectorSizeY[1]};  // inner aperture for station1
+
+  const Double_t xBarPosYtop[3] = {AperY[0] + I_height / 2., AperY[1] + I_height / 2., AperY[2] + I_height / 2.};
+  const Double_t xBarPosYbot[3] = {AperYbot[0] + I_height / 2., xBarPosYtop[1], xBarPosYtop[2]};
+
+  const Double_t zBarPosYtop[3] = {AperY[0] + I_height - I_width / 2., AperY[1] + I_height - I_width / 2.,
+                                   AperY[2] + I_height - I_width / 2.};
+  const Double_t zBarPosYbot[3] = {AperYbot[0] + I_height - I_width / 2., zBarPosYtop[1], zBarPosYtop[2]};
+
+  Double_t PilPosX;
+  Double_t PilPosZ[6];  // PilPosZ
+
+  PilPosZ[0] = LayerPosition[0] + I_width / 2.;
+  PilPosZ[1] = LayerPosition[3] - I_width / 2. + LayerThickness;
+  PilPosZ[2] = LayerPosition[4] + I_width / 2.;
+  PilPosZ[3] = LayerPosition[7] - I_width / 2. + LayerThickness;
+  PilPosZ[4] = LayerPosition[8] + I_width / 2.;
+  PilPosZ[5] = LayerPosition[9] - I_width / 2. + LayerThickness;
+
+  //  cout << "PilPosZ[0]: " << PilPosZ[0] << endl;
+  //  cout << "PilPosZ[1]: " << PilPosZ[1] << endl;
+
+  TGeoRotation* rotx090 = new TGeoRotation("rotx090");
+  rotx090->RotateX(90.);  // rotate  90 deg around x-axis
+  TGeoRotation* roty090 = new TGeoRotation("roty090");
+  roty090->RotateY(90.);  // rotate  90 deg around y-axis
+  TGeoRotation* rotz090 = new TGeoRotation("rotz090");
+  rotz090->RotateZ(90.);  // rotate  90 deg around y-axis
+  TGeoRotation* roty270 = new TGeoRotation("roty270");
+  roty270->RotateY(270.);  // rotate 270 deg around y-axis
+
+  TGeoRotation* rotzx01 = new TGeoRotation("rotzx01");
+  rotzx01->RotateZ(90.);  // rotate  90 deg around z-axis
+  rotzx01->RotateX(90.);  // rotate  90 deg around x-axis
+
+  TGeoRotation* rotzx02 = new TGeoRotation("rotzx02");
+  rotzx02->RotateZ(270.);  // rotate 270 deg around z-axis
+  rotzx02->RotateX(90.);   // rotate  90 deg around x-axis
+
+  Double_t ang1 = atan(3. / 4.) * 180. / acos(-1.);
+  //  cout << "DEDE " << ang1 << endl;
+  //  Double_t sin1 = acos(-1.);
+  //  cout << "DEDE " << sin1 << endl;
+  TGeoRotation* rotx080 = new TGeoRotation("rotx080");
+  rotx080->RotateX(90. - ang1);  // rotate  80 deg around x-axis
+  TGeoRotation* rotx100 = new TGeoRotation("rotx100");
+  rotx100->RotateX(90. + ang1);  // rotate 100 deg around x-axis
+
+  TGeoRotation* rotxy01 = new TGeoRotation("rotxy01");
+  rotxy01->RotateX(90.);    // rotate  90 deg around x-axis
+  rotxy01->RotateZ(-ang1);  // rotate  ang1   around rotated y-axis
+
+  TGeoRotation* rotxy02 = new TGeoRotation("rotxy02");
+  rotxy02->RotateX(90.);   // rotate  90 deg around x-axis
+  rotxy02->RotateZ(ang1);  // rotate  ang1   around rotated y-axis
+
+
+  //-------------------
+  // vertical pillars (Y)
+  //-------------------
+
+  // station 1
+  if (ShowLayer[0])  // if geometry contains layer 1 (1st layer of station 1)
+  {
+    //      TGeoBBox* trd_I_vert1_keep  = new TGeoBBox("", I_thick /2., I_height /2. - I_thick, (BeamHeight + (AperY[0]+I_height) ) /2.);
+    TGeoBBox* trd_I_vert1_keep = new TGeoBBox("trd_I_vert1_keep", I_thick / 2., I_height / 2. - I_thick,
+                                              ((AperYbot[0] + I_height) + (AperY[0] + I_height)) / 2.);
+    TGeoVolume* trd_I_vert1    = new TGeoVolume("trd_I_y11", trd_I_vert1_keep, aluminiumVolMed);
+    //      TGeoBBox* trd_I_vert2_keep  = new TGeoBBox("", I_width /2.,            I_thick /2., (BeamHeight + (AperY[0]+I_height) ) /2.);
+    TGeoBBox* trd_I_vert2_keep = new TGeoBBox("trd_I_vert2_keep", I_width / 2., I_thick / 2.,
+                                              ((AperYbot[0] + I_height) + (AperY[0] + I_height)) / 2.);
+    TGeoVolume* trd_I_vert2    = new TGeoVolume("trd_I_y12", trd_I_vert2_keep, aluminiumVolMed);
+
+    trd_I_vert1->SetLineColor(kGreen);  // kBlue);  // Yellow);  // kOrange);
+    trd_I_vert2->SetLineColor(kGreen);  // kBlue);  // Yellow);  // kOrange);
+
+    TGeoTranslation* ty01 = new TGeoTranslation("ty01", 0., 0., 0.);
+    TGeoTranslation* ty02 = new TGeoTranslation("ty02", 0., (I_height - I_thick) / 2., 0.);
+    TGeoTranslation* ty03 = new TGeoTranslation("ty03", 0., -(I_height - I_thick) / 2., 0.);
+
+    //      TGeoBBox* trd_I_vert_vol1_keep = new TGeoBBox("", I_width /2., I_height /2., (BeamHeight + (AperY[0]+I_height) ) /2.);
+    TGeoBBox* trd_I_vert_vol1_keep = new TGeoBBox("trd_I_vert_vol1_keep", I_width / 2., I_height / 2.,
+                                                  ((AperYbot[0] + I_height) + (AperY[0] + I_height)) / 2.);
+    TGeoVolume* trd_I_vert_vol1    = new TGeoVolume("trd_I_y10", trd_I_vert_vol1_keep, keepVolMed);
+
+    // set green color for keeping volume of I profile, seen with gGeoManager->SetVisLevel(2)
+    trd_I_vert_vol1->SetLineColor(kGreen);
+
+    // build I-bar trd_I_vert_vol1
+    trd_I_vert_vol1->AddNode(trd_I_vert1, 1, ty01);
+    trd_I_vert_vol1->AddNode(trd_I_vert2, 2, ty02);
+    trd_I_vert_vol1->AddNode(trd_I_vert2, 3, ty03);
+
+    // close gap to horizontal z-bars
+    TGeoBBox* trd_I_vert3_keep =
+      new TGeoBBox("trd_I_vert3_keep", (I_width - I_thick) / 2. / 2., I_height / 2. - I_thick, I_thick / 2.);
+    TGeoVolume* trd_I_vert3 = new TGeoVolume("trd_I_y13", trd_I_vert3_keep, aluminiumVolMed);
+    trd_I_vert3->SetLineColor(kGreen);
+    //      TGeoTranslation *ty04 = new TGeoTranslation("ty04",  (I_thick/2. + (I_width-I_thick)/2./2.), 0., -( (AperYbot[0]+I_height) + (AperY[0]+I_height) - I_width) /2.);  // top
+    //      TGeoTranslation *ty05 = new TGeoTranslation("ty05",  (I_thick/2. + (I_width-I_thick)/2./2.), 0.,  ( (AperYbot[0]+I_height) + (AperY[0]+I_height) - I_width) /2.);  // bottom
+    TGeoTranslation* ty04 = new TGeoTranslation("ty04", (I_thick / 2. + (I_width - I_thick) / 2. / 2.), 0.,
+                                                -(zBarPosYbot[0] + zBarPosYtop[0]) / 2.);  // top
+    TGeoTranslation* ty05 = new TGeoTranslation("ty05", (I_thick / 2. + (I_width - I_thick) / 2. / 2.), 0.,
+                                                (zBarPosYbot[0] + zBarPosYtop[0]) / 2.);  // bottom
+    trd_I_vert_vol1->AddNode(trd_I_vert3, 4, ty04);
+    trd_I_vert_vol1->AddNode(trd_I_vert3, 5, ty05);
+
+    PilPosX = AperX[0];
+
+    TGeoCombiTrans* trd_I_vert_combi01 = new TGeoCombiTrans(
+      (PilPosX + I_height / 2.), -((AperYbot[0] + I_height) - (AperY[0] + I_height)) / 2., PilPosZ[0], rotzx01);
+    trd_1->AddNode(trd_I_vert_vol1, 11, trd_I_vert_combi01);
+    TGeoCombiTrans* trd_I_vert_combi02 = new TGeoCombiTrans(
+      -(PilPosX + I_height / 2.), -((AperYbot[0] + I_height) - (AperY[0] + I_height)) / 2., PilPosZ[0], rotzx01);
+    trd_1->AddNode(trd_I_vert_vol1, 12, trd_I_vert_combi02);
+    TGeoCombiTrans* trd_I_vert_combi03 = new TGeoCombiTrans(
+      (PilPosX + I_height / 2.), -((AperYbot[0] + I_height) - (AperY[0] + I_height)) / 2., PilPosZ[1], rotzx02);
+    trd_1->AddNode(trd_I_vert_vol1, 13, trd_I_vert_combi03);
+    TGeoCombiTrans* trd_I_vert_combi04 = new TGeoCombiTrans(
+      -(PilPosX + I_height / 2.), -((AperYbot[0] + I_height) - (AperY[0] + I_height)) / 2., PilPosZ[1], rotzx02);
+    trd_1->AddNode(trd_I_vert_vol1, 14, trd_I_vert_combi04);
+  }
+
+  // station 2
+  if (ShowLayer[4])  // if geometry contains layer 5 (1st layer of station 2)
+  {
+    TGeoBBox* trd_I_vert1_keep = new TGeoBBox("trd_I_vert1_keep", I_thick / 2., I_height / 2. - I_thick,
+                                              (BeamHeight + (AperY[1] + I_height)) / 2.);
+    TGeoVolume* trd_I_vert1    = new TGeoVolume("trd_I_y21", trd_I_vert1_keep, aluminiumVolMed);
+    TGeoBBox* trd_I_vert2_keep =
+      new TGeoBBox("trd_I_vert2_keep", I_width / 2., I_thick / 2., (BeamHeight + (AperY[1] + I_height)) / 2.);
+    TGeoVolume* trd_I_vert2 = new TGeoVolume("trd_I_y22", trd_I_vert2_keep, aluminiumVolMed);
+
+    trd_I_vert1->SetLineColor(kGreen);
+    trd_I_vert2->SetLineColor(kGreen);
+
+    TGeoTranslation* ty01 = new TGeoTranslation("ty01", 0., 0., 0.);
+    TGeoTranslation* ty02 = new TGeoTranslation("ty02", 0., (I_height - I_thick) / 2., 0.);
+    TGeoTranslation* ty03 = new TGeoTranslation("ty03", 0., -(I_height - I_thick) / 2., 0.);
+
+    TGeoBBox* trd_I_vert_vol1_keep =
+      new TGeoBBox("trd_I_vert_vol1_keep", I_width / 2., I_height / 2., (BeamHeight + (AperY[1] + I_height)) / 2.);
+    TGeoVolume* trd_I_vert_vol1 = new TGeoVolume("trd_I_y20", trd_I_vert_vol1_keep, keepVolMed);
+
+    // set green color for keeping volume of I profile, seen with gGeoManager->SetVisLevel(2)
+    trd_I_vert_vol1->SetLineColor(kGreen);
+
+    // build I-bar trd_I_vert_vol1
+    trd_I_vert_vol1->AddNode(trd_I_vert1, 1, ty01);
+    trd_I_vert_vol1->AddNode(trd_I_vert2, 2, ty02);
+    trd_I_vert_vol1->AddNode(trd_I_vert2, 3, ty03);
+
+    // close gap to horizontal z-bars
+    TGeoBBox* trd_I_vert3_keep =
+      new TGeoBBox("trd_I_vert3_keep", (I_width - I_thick) / 2. / 2., I_height / 2. - I_thick, I_thick / 2.);
+    TGeoVolume* trd_I_vert3 = new TGeoVolume("trd_I_y23", trd_I_vert3_keep, aluminiumVolMed);
+    trd_I_vert3->SetLineColor(kGreen);
+    TGeoTranslation* ty04 = new TGeoTranslation("ty04", (I_thick / 2. + (I_width - I_thick) / 2. / 2.), 0.,
+                                                -(BeamHeight + (AperY[1] + I_height) - I_width) / 2.);  // top
+    TGeoTranslation* ty05 = new TGeoTranslation("ty05", (I_thick / 2. + (I_width - I_thick) / 2. / 2.), 0.,
+                                                -(BeamHeight - (AperY[1] + I_height)) / 2. + zBarPosYbot[1]);  // bottom
+    trd_I_vert_vol1->AddNode(trd_I_vert3, 4, ty04);
+    trd_I_vert_vol1->AddNode(trd_I_vert3, 5, ty05);
+
+    PilPosX = AperX[1];
+
+    TGeoCombiTrans* trd_I_vert_combi01 =
+      new TGeoCombiTrans((PilPosX + I_height / 2.), -(BeamHeight - (AperY[1] + I_height)) / 2., PilPosZ[2], rotzx01);
+    trd_2->AddNode(trd_I_vert_vol1, 21, trd_I_vert_combi01);
+    TGeoCombiTrans* trd_I_vert_combi02 =
+      new TGeoCombiTrans(-(PilPosX + I_height / 2.), -(BeamHeight - (AperY[1] + I_height)) / 2., PilPosZ[2], rotzx01);
+    trd_2->AddNode(trd_I_vert_vol1, 22, trd_I_vert_combi02);
+    TGeoCombiTrans* trd_I_vert_combi03 =
+      new TGeoCombiTrans((PilPosX + I_height / 2.), -(BeamHeight - (AperY[1] + I_height)) / 2., PilPosZ[3], rotzx02);
+    trd_2->AddNode(trd_I_vert_vol1, 23, trd_I_vert_combi03);
+    TGeoCombiTrans* trd_I_vert_combi04 =
+      new TGeoCombiTrans(-(PilPosX + I_height / 2.), -(BeamHeight - (AperY[1] + I_height)) / 2., PilPosZ[3], rotzx02);
+    trd_2->AddNode(trd_I_vert_vol1, 24, trd_I_vert_combi04);
+  }
+
+  // station 3
+  if (ShowLayer[8])  // if geometry contains layer 9 (1st layer of station 3)
+  {
+    TGeoBBox* trd_I_vert1_keep = new TGeoBBox("trd_I_vert1_keep", I_thick / 2., I_height / 2. - I_thick,
+                                              (BeamHeight + (AperY[2] + I_height)) / 2.);
+    TGeoVolume* trd_I_vert1    = new TGeoVolume("trd_I_y31", trd_I_vert1_keep, aluminiumVolMed);
+    TGeoBBox* trd_I_vert2_keep =
+      new TGeoBBox("trd_I_vert2_keep", I_width / 2., I_thick / 2., (BeamHeight + (AperY[2] + I_height)) / 2.);
+    TGeoVolume* trd_I_vert2 = new TGeoVolume("trd_I_y32", trd_I_vert2_keep, aluminiumVolMed);
+
+    trd_I_vert1->SetLineColor(kGreen);
+    trd_I_vert2->SetLineColor(kGreen);
+
+    TGeoTranslation* ty01 = new TGeoTranslation("ty01", 0., 0., 0.);
+    TGeoTranslation* ty02 = new TGeoTranslation("ty02", 0., (I_height - I_thick) / 2., 0.);
+    TGeoTranslation* ty03 = new TGeoTranslation("ty03", 0., -(I_height - I_thick) / 2., 0.);
+
+    TGeoBBox* trd_I_vert_vol1_keep =
+      new TGeoBBox("trd_I_vert_vol1_keep", I_width / 2., I_height / 2., (BeamHeight + (AperY[2] + I_height)) / 2.);
+    TGeoVolume* trd_I_vert_vol1 = new TGeoVolume("trd_I_y30", trd_I_vert_vol1_keep, keepVolMed);
+
+    // set green color for keeping volume of I profile, seen with gGeoManager->SetVisLevel(2)
+    trd_I_vert_vol1->SetLineColor(kGreen);
+
+    // build I-bar trd_I_vert_vol1
+    trd_I_vert_vol1->AddNode(trd_I_vert1, 1, ty01);
+    trd_I_vert_vol1->AddNode(trd_I_vert2, 2, ty02);
+    trd_I_vert_vol1->AddNode(trd_I_vert2, 3, ty03);
+
+    // close gap to horizontal z-bars
+    TGeoBBox* trd_I_vert3_keep =
+      new TGeoBBox("trd_I_vert3_keep", (I_width - I_thick) / 2. / 2., I_height / 2. - I_thick, I_thick / 2.);
+    TGeoVolume* trd_I_vert3 = new TGeoVolume("trd_I_y33", trd_I_vert3_keep, aluminiumVolMed);
+    trd_I_vert3->SetLineColor(kGreen);
+    TGeoTranslation* ty04 = new TGeoTranslation("ty04", (I_thick / 2. + (I_width - I_thick) / 2. / 2.), 0.,
+                                                -(BeamHeight + (AperY[2] + I_height) - I_width) / 2.);  // top
+    TGeoTranslation* ty05 = new TGeoTranslation("ty05", (I_thick / 2. + (I_width - I_thick) / 2. / 2.), 0.,
+                                                -(BeamHeight - (AperY[2] + I_height)) / 2. + zBarPosYbot[2]);  // bottom
+    trd_I_vert_vol1->AddNode(trd_I_vert3, 4, ty04);
+    trd_I_vert_vol1->AddNode(trd_I_vert3, 5, ty05);
+
+    PilPosX = AperX[2];
+
+    TGeoCombiTrans* trd_I_vert_combi01 =
+      new TGeoCombiTrans((PilPosX + I_height / 2.), -(BeamHeight - (AperY[2] + I_height)) / 2., PilPosZ[4], rotzx01);
+    trd_3->AddNode(trd_I_vert_vol1, 31, trd_I_vert_combi01);
+    TGeoCombiTrans* trd_I_vert_combi02 =
+      new TGeoCombiTrans(-(PilPosX + I_height / 2.), -(BeamHeight - (AperY[2] + I_height)) / 2., PilPosZ[4], rotzx01);
+    trd_3->AddNode(trd_I_vert_vol1, 32, trd_I_vert_combi02);
+    TGeoCombiTrans* trd_I_vert_combi03 =
+      new TGeoCombiTrans((PilPosX + I_height / 2.), -(BeamHeight - (AperY[2] + I_height)) / 2., PilPosZ[5], rotzx02);
+    trd_3->AddNode(trd_I_vert_vol1, 33, trd_I_vert_combi03);
+    TGeoCombiTrans* trd_I_vert_combi04 =
+      new TGeoCombiTrans(-(PilPosX + I_height / 2.), -(BeamHeight - (AperY[2] + I_height)) / 2., PilPosZ[5], rotzx02);
+    trd_3->AddNode(trd_I_vert_vol1, 34, trd_I_vert_combi04);
+  }
+
+
+  //-------------------
+  // horizontal supports (X)
+  //-------------------
+
+  // station 1
+  if (ShowLayer[0])  // if geometry contains layer 1 (1st layer of station 1)
+  {
+    TGeoBBox* trd_I_hori1_keep = new TGeoBBox("trd_I_hori1_keep", I_thick / 2., I_height / 2. - I_thick, AperX[0]);
+    TGeoVolume* trd_I_hori1    = new TGeoVolume("trd_I_x11", trd_I_hori1_keep, aluminiumVolMed);
+    TGeoBBox* trd_I_hori2_keep = new TGeoBBox("trd_I_hori2_keep", I_width / 2., I_thick / 2., AperX[0]);
+    TGeoVolume* trd_I_hori2    = new TGeoVolume("trd_I_x12", trd_I_hori2_keep, aluminiumVolMed);
+
+    trd_I_hori1->SetLineColor(kRed);  // Yellow);
+    trd_I_hori2->SetLineColor(kRed);  // Yellow);
+
+    TGeoTranslation* tx01 = new TGeoTranslation("tx01", 0., 0., 0.);
+    TGeoTranslation* tx02 = new TGeoTranslation("tx02", 0., (I_height - I_thick) / 2., 0.);
+    TGeoTranslation* tx03 = new TGeoTranslation("tx03", 0., -(I_height - I_thick) / 2., 0.);
+
+    TGeoBBox* trd_I_hori_vol1_keep = new TGeoBBox("trd_I_hori_vol1_keep", I_width / 2., I_height / 2., AperX[0]);
+    TGeoVolume* trd_I_hori_vol1    = new TGeoVolume("trd_I_x10", trd_I_hori_vol1_keep, keepVolMed);
+
+    // set red color for keeping volume of I profile, seen with gGeoManager->SetVisLevel(2)
+    trd_I_hori_vol1->SetLineColor(kRed);
+
+    // build I-bar trd_I_hori_vol1
+    trd_I_hori_vol1->AddNode(trd_I_hori1, 1, tx01);
+    trd_I_hori_vol1->AddNode(trd_I_hori2, 2, tx02);
+    trd_I_hori_vol1->AddNode(trd_I_hori2, 3, tx03);
+
+    TGeoCombiTrans* trd_I_hori_combi01 = new TGeoCombiTrans(0., xBarPosYtop[0], PilPosZ[0], roty090);
+    trd_1->AddNode(trd_I_hori_vol1, 11, trd_I_hori_combi01);
+    TGeoCombiTrans* trd_I_hori_combi02 = new TGeoCombiTrans(0., -xBarPosYbot[0], PilPosZ[0], roty090);
+    trd_1->AddNode(trd_I_hori_vol1, 12, trd_I_hori_combi02);
+    TGeoCombiTrans* trd_I_hori_combi03 = new TGeoCombiTrans(0., xBarPosYtop[0], PilPosZ[1], roty090);
+    trd_1->AddNode(trd_I_hori_vol1, 13, trd_I_hori_combi03);
+    TGeoCombiTrans* trd_I_hori_combi04 = new TGeoCombiTrans(0., -xBarPosYbot[0], PilPosZ[1], roty090);
+    trd_1->AddNode(trd_I_hori_vol1, 14, trd_I_hori_combi04);
+  }
+
+  // station 2
+  if (ShowLayer[4])  // if geometry contains layer 5 (1st layer of station 2)
+  {
+    TGeoBBox* trd_I_hori1_keep = new TGeoBBox("trd_I_hori1_keep", I_thick / 2., I_height / 2. - I_thick, AperX[1]);
+    TGeoVolume* trd_I_hori1    = new TGeoVolume("trd_I_x21", trd_I_hori1_keep, aluminiumVolMed);
+    TGeoBBox* trd_I_hori2_keep = new TGeoBBox("trd_I_hori2_keep", I_width / 2., I_thick / 2., AperX[1]);
+    TGeoVolume* trd_I_hori2    = new TGeoVolume("trd_I_x22", trd_I_hori2_keep, aluminiumVolMed);
+
+    trd_I_hori1->SetLineColor(kRed);
+    trd_I_hori2->SetLineColor(kRed);
+
+    TGeoTranslation* tx01 = new TGeoTranslation("tx01", 0., 0., 0.);
+    TGeoTranslation* tx02 = new TGeoTranslation("tx02", 0., (I_height - I_thick) / 2., 0.);
+    TGeoTranslation* tx03 = new TGeoTranslation("tx03", 0., -(I_height - I_thick) / 2., 0.);
+
+    TGeoBBox* trd_I_hori_vol1_keep = new TGeoBBox("trd_I_hori_vol1_keep", I_width / 2., I_height / 2., AperX[1]);
+    TGeoVolume* trd_I_hori_vol1    = new TGeoVolume("trd_I_x20", trd_I_hori_vol1_keep, keepVolMed);
+
+    // set red color for keeping volume of I profile, seen with gGeoManager->SetVisLevel(2)
+    trd_I_hori_vol1->SetLineColor(kRed);
+
+    // build I-bar trd_I_hori_vol1
+    trd_I_hori_vol1->AddNode(trd_I_hori1, 1, tx01);
+    trd_I_hori_vol1->AddNode(trd_I_hori2, 2, tx02);
+    trd_I_hori_vol1->AddNode(trd_I_hori2, 3, tx03);
+
+    TGeoCombiTrans* trd_I_hori_combi01 = new TGeoCombiTrans(0., xBarPosYtop[1], PilPosZ[2], roty090);
+    trd_2->AddNode(trd_I_hori_vol1, 21, trd_I_hori_combi01);
+    TGeoCombiTrans* trd_I_hori_combi02 = new TGeoCombiTrans(0., -xBarPosYbot[1], PilPosZ[2], roty090);
+    trd_2->AddNode(trd_I_hori_vol1, 22, trd_I_hori_combi02);
+    TGeoCombiTrans* trd_I_hori_combi03 = new TGeoCombiTrans(0., xBarPosYtop[1], PilPosZ[3], roty090);
+    trd_2->AddNode(trd_I_hori_vol1, 23, trd_I_hori_combi03);
+    TGeoCombiTrans* trd_I_hori_combi04 = new TGeoCombiTrans(0., -xBarPosYbot[1], PilPosZ[3], roty090);
+    trd_2->AddNode(trd_I_hori_vol1, 24, trd_I_hori_combi04);
+  }
+
+  // station 3
+  if (ShowLayer[8])  // if geometry contains layer 9 (1st layer of station 3)
+  {
+    TGeoBBox* trd_I_hori1_keep = new TGeoBBox("trd_I_hori1_keep", I_thick / 2., I_height / 2. - I_thick, AperX[2]);
+    TGeoVolume* trd_I_hori1    = new TGeoVolume("trd_I_x31", trd_I_hori1_keep, aluminiumVolMed);
+    TGeoBBox* trd_I_hori2_keep = new TGeoBBox("trd_I_hori2_keep", I_width / 2., I_thick / 2., AperX[2]);
+    TGeoVolume* trd_I_hori2    = new TGeoVolume("trd_I_x32", trd_I_hori2_keep, aluminiumVolMed);
+
+    trd_I_hori1->SetLineColor(kRed);
+    trd_I_hori2->SetLineColor(kRed);
+
+    TGeoTranslation* tx01 = new TGeoTranslation("tx01", 0., 0., 0.);
+    TGeoTranslation* tx02 = new TGeoTranslation("tx02", 0., (I_height - I_thick) / 2., 0.);
+    TGeoTranslation* tx03 = new TGeoTranslation("tx03", 0., -(I_height - I_thick) / 2., 0.);
+
+    TGeoBBox* trd_I_hori_vol1_keep = new TGeoBBox("trd_I_hori_vol1_keep", I_width / 2., I_height / 2., AperX[2]);
+    TGeoVolume* trd_I_hori_vol1    = new TGeoVolume("trd_I_x30", trd_I_hori_vol1_keep, keepVolMed);
+
+    // set red color for keeping volume of I profile, seen with gGeoManager->SetVisLevel(2)
+    trd_I_hori_vol1->SetLineColor(kRed);
+
+    // build I-bar trd_I_hori_vol1
+    trd_I_hori_vol1->AddNode(trd_I_hori1, 1, tx01);
+    trd_I_hori_vol1->AddNode(trd_I_hori2, 2, tx02);
+    trd_I_hori_vol1->AddNode(trd_I_hori2, 3, tx03);
+
+    TGeoCombiTrans* trd_I_hori_combi01 = new TGeoCombiTrans(0., xBarPosYtop[2], PilPosZ[4], roty090);
+    trd_3->AddNode(trd_I_hori_vol1, 31, trd_I_hori_combi01);
+    TGeoCombiTrans* trd_I_hori_combi02 = new TGeoCombiTrans(0., -xBarPosYbot[2], PilPosZ[4], roty090);
+    trd_3->AddNode(trd_I_hori_vol1, 32, trd_I_hori_combi02);
+    TGeoCombiTrans* trd_I_hori_combi03 = new TGeoCombiTrans(0., xBarPosYtop[2], PilPosZ[5], roty090);
+    trd_3->AddNode(trd_I_hori_vol1, 33, trd_I_hori_combi03);
+    TGeoCombiTrans* trd_I_hori_combi04 = new TGeoCombiTrans(0., -xBarPosYbot[2], PilPosZ[5], roty090);
+    trd_3->AddNode(trd_I_hori_vol1, 34, trd_I_hori_combi04);
+  }
+
+
+  //-------------------
+  // horizontal supports (Z)
+  //-------------------
+
+  // station 1
+  if (ShowLayer[0])  // if geometry contains layer 1 (1st layer of station 1)
+  {
+    TGeoBBox* trd_I_slope1_keep = new TGeoBBox("trd_I_slope1_keep", I_thick / 2., I_height / 2. - I_thick,
+                                               (PilPosZ[1] - PilPosZ[0] - I_width) / 2.);
+    TGeoVolume* trd_I_slope1    = new TGeoVolume("trd_I_z11", trd_I_slope1_keep, aluminiumVolMed);
+    TGeoBBox* trd_I_slope2_keep =
+      new TGeoBBox("trd_I_slope2_keep", I_width / 2., I_thick / 2., (PilPosZ[1] - PilPosZ[0] - I_width) / 2.);
+    TGeoVolume* trd_I_slope2 = new TGeoVolume("trd_I_z12", trd_I_slope2_keep, aluminiumVolMed);
+
+    trd_I_slope1->SetLineColor(kYellow);
+    trd_I_slope2->SetLineColor(kYellow);
+
+    TGeoTranslation* tz01 = new TGeoTranslation("tz01", 0., 0., 0.);
+    TGeoTranslation* tz02 = new TGeoTranslation("tz02", 0., (I_height - I_thick) / 2., 0.);
+    TGeoTranslation* tz03 = new TGeoTranslation("tz03", 0., -(I_height - I_thick) / 2., 0.);
+
+    TGeoBBox* trd_I_slope_vol1_keep =
+      new TGeoBBox("trd_I_slope_vol1_keep", I_width / 2., I_height / 2., (PilPosZ[1] - PilPosZ[0] - I_width) / 2.);
+    TGeoVolume* trd_I_slope_vol1 = new TGeoVolume("trd_I_z10", trd_I_slope_vol1_keep, keepVolMed);
+
+    // set yellow color for keeping volume of I profile, seen with gGeoManager->SetVisLevel(2)
+    trd_I_slope_vol1->SetLineColor(kYellow);
+
+    // build I-bar trd_I_slope_vol1
+    trd_I_slope_vol1->AddNode(trd_I_slope1, 1, tz01);
+    trd_I_slope_vol1->AddNode(trd_I_slope2, 2, tz02);
+    trd_I_slope_vol1->AddNode(trd_I_slope2, 3, tz03);
+
+    PilPosX = AperX[0];
+
+    TGeoCombiTrans* trd_I_slope_combi01 =
+      new TGeoCombiTrans((PilPosX + I_height / 2.), zBarPosYtop[0], (PilPosZ[0] + PilPosZ[1]) / 2., rotz090);
+    trd_1->AddNode(trd_I_slope_vol1, 11, trd_I_slope_combi01);
+    TGeoCombiTrans* trd_I_slope_combi02 =
+      new TGeoCombiTrans(-(PilPosX + I_height / 2.), zBarPosYtop[0], (PilPosZ[0] + PilPosZ[1]) / 2., rotz090);
+    trd_1->AddNode(trd_I_slope_vol1, 12, trd_I_slope_combi02);
+    TGeoCombiTrans* trd_I_slope_combi03 =
+      new TGeoCombiTrans((PilPosX + I_height / 2.), -zBarPosYbot[0], (PilPosZ[0] + PilPosZ[1]) / 2., rotz090);
+    trd_1->AddNode(trd_I_slope_vol1, 13, trd_I_slope_combi03);
+    TGeoCombiTrans* trd_I_slope_combi04 =
+      new TGeoCombiTrans(-(PilPosX + I_height / 2.), -zBarPosYbot[0], (PilPosZ[0] + PilPosZ[1]) / 2., rotz090);
+    trd_1->AddNode(trd_I_slope_vol1, 14, trd_I_slope_combi04);
+  }
+
+  // station 2
+  if (ShowLayer[4])  // if geometry contains layer 5 (1st layer of station 2)
+  {
+    TGeoBBox* trd_I_slope1_keep = new TGeoBBox("trd_I_slope1_keep", I_thick / 2., I_height / 2. - I_thick,
+                                               (PilPosZ[3] - PilPosZ[2] - I_width) / 2.);
+    TGeoVolume* trd_I_slope1    = new TGeoVolume("trd_I_z21", trd_I_slope1_keep, aluminiumVolMed);
+    TGeoBBox* trd_I_slope2_keep =
+      new TGeoBBox("trd_I_slope2_keep", I_width / 2., I_thick / 2., (PilPosZ[3] - PilPosZ[2] - I_width) / 2.);
+    TGeoVolume* trd_I_slope2 = new TGeoVolume("trd_I_z22", trd_I_slope2_keep, aluminiumVolMed);
+
+    trd_I_slope1->SetLineColor(kYellow);
+    trd_I_slope2->SetLineColor(kYellow);
+
+    TGeoTranslation* tz01 = new TGeoTranslation("tz01", 0., 0., 0.);
+    TGeoTranslation* tz02 = new TGeoTranslation("tz02", 0., (I_height - I_thick) / 2., 0.);
+    TGeoTranslation* tz03 = new TGeoTranslation("tz03", 0., -(I_height - I_thick) / 2., 0.);
+
+    TGeoBBox* trd_I_slope_vol1_keep =
+      new TGeoBBox("trd_I_slope_vol1_keep", I_width / 2., I_height / 2., (PilPosZ[3] - PilPosZ[2] - I_width) / 2.);
+    TGeoVolume* trd_I_slope_vol1 = new TGeoVolume("trd_I_z20", trd_I_slope_vol1_keep, keepVolMed);
+
+    // set yellow color for keeping volume of I profile, seen with gGeoManager->SetVisLevel(2)
+    trd_I_slope_vol1->SetLineColor(kYellow);
+
+    // build I-bar trd_I_slope_vol1
+    trd_I_slope_vol1->AddNode(trd_I_slope1, 1, tz01);
+    trd_I_slope_vol1->AddNode(trd_I_slope2, 2, tz02);
+    trd_I_slope_vol1->AddNode(trd_I_slope2, 3, tz03);
+
+    PilPosX = AperX[1];
+
+    TGeoCombiTrans* trd_I_slope_combi01 =
+      new TGeoCombiTrans((PilPosX + I_height / 2.), zBarPosYtop[1], (PilPosZ[2] + PilPosZ[3]) / 2., rotz090);
+    trd_2->AddNode(trd_I_slope_vol1, 21, trd_I_slope_combi01);
+    TGeoCombiTrans* trd_I_slope_combi02 =
+      new TGeoCombiTrans(-(PilPosX + I_height / 2.), zBarPosYtop[1], (PilPosZ[2] + PilPosZ[3]) / 2., rotz090);
+    trd_2->AddNode(trd_I_slope_vol1, 22, trd_I_slope_combi02);
+    TGeoCombiTrans* trd_I_slope_combi03 =
+      new TGeoCombiTrans((PilPosX + I_height / 2.), -zBarPosYbot[1], (PilPosZ[2] + PilPosZ[3]) / 2., rotz090);
+    trd_2->AddNode(trd_I_slope_vol1, 23, trd_I_slope_combi03);
+    TGeoCombiTrans* trd_I_slope_combi04 =
+      new TGeoCombiTrans(-(PilPosX + I_height / 2.), -zBarPosYbot[1], (PilPosZ[2] + PilPosZ[3]) / 2., rotz090);
+    trd_2->AddNode(trd_I_slope_vol1, 24, trd_I_slope_combi04);
+  }
+
+  // station 3
+  if (ShowLayer[8])  // if geometry contains layer 9 (1st layer of station 3)
+  {
+    TGeoBBox* trd_I_slope1_keep = new TGeoBBox("trd_I_slope1_keep", I_thick / 2., I_height / 2. - I_thick,
+                                               (PilPosZ[5] - PilPosZ[4] - I_width) / 2.);
+    TGeoVolume* trd_I_slope1    = new TGeoVolume("trd_I_z31", trd_I_slope1_keep, aluminiumVolMed);
+    TGeoBBox* trd_I_slope2_keep =
+      new TGeoBBox("trd_I_slope2_keep", I_width / 2., I_thick / 2., (PilPosZ[5] - PilPosZ[4] - I_width) / 2.);
+    TGeoVolume* trd_I_slope2 = new TGeoVolume("trd_I_z32", trd_I_slope2_keep, aluminiumVolMed);
+
+    trd_I_slope1->SetLineColor(kYellow);
+    trd_I_slope2->SetLineColor(kYellow);
+
+    TGeoTranslation* tz01 = new TGeoTranslation("tz01", 0., 0., 0.);
+    TGeoTranslation* tz02 = new TGeoTranslation("tz02", 0., (I_height - I_thick) / 2., 0.);
+    TGeoTranslation* tz03 = new TGeoTranslation("tz03", 0., -(I_height - I_thick) / 2., 0.);
+
+    TGeoBBox* trd_I_slope_vol1_keep =
+      new TGeoBBox("trd_I_slope_vol1_keep", I_width / 2., I_height / 2., (PilPosZ[5] - PilPosZ[4] - I_width) / 2.);
+    TGeoVolume* trd_I_slope_vol1 = new TGeoVolume("trd_I_z30", trd_I_slope_vol1_keep, keepVolMed);
+
+    // set yellow color for keeping volume of I profile, seen with gGeoManager->SetVisLevel(2)
+    trd_I_slope_vol1->SetLineColor(kYellow);
+
+    // build I-bar trd_I_slope_vol1
+    trd_I_slope_vol1->AddNode(trd_I_slope1, 1, tz01);
+    trd_I_slope_vol1->AddNode(trd_I_slope2, 2, tz02);
+    trd_I_slope_vol1->AddNode(trd_I_slope2, 3, tz03);
+
+    PilPosX = AperX[2];
+
+    TGeoCombiTrans* trd_I_slope_combi01 =
+      new TGeoCombiTrans((PilPosX + I_height / 2.), zBarPosYtop[2], (PilPosZ[4] + PilPosZ[5]) / 2., rotz090);
+    trd_3->AddNode(trd_I_slope_vol1, 31, trd_I_slope_combi01);
+    TGeoCombiTrans* trd_I_slope_combi02 =
+      new TGeoCombiTrans(-(PilPosX + I_height / 2.), zBarPosYtop[2], (PilPosZ[4] + PilPosZ[5]) / 2., rotz090);
+    trd_3->AddNode(trd_I_slope_vol1, 32, trd_I_slope_combi02);
+    TGeoCombiTrans* trd_I_slope_combi03 =
+      new TGeoCombiTrans((PilPosX + I_height / 2.), -zBarPosYbot[2], (PilPosZ[4] + PilPosZ[5]) / 2., rotz090);
+    trd_3->AddNode(trd_I_slope_vol1, 33, trd_I_slope_combi03);
+    TGeoCombiTrans* trd_I_slope_combi04 =
+      new TGeoCombiTrans(-(PilPosX + I_height / 2.), -zBarPosYbot[2], (PilPosZ[4] + PilPosZ[5]) / 2., rotz090);
+    trd_3->AddNode(trd_I_slope_vol1, 34, trd_I_slope_combi04);
+  }
+
+  if (IncludeLabels) {
+
+    Int_t text_height    = 40;
+    Int_t text_thickness = 8;
+
+    TGeoTranslation* tr200 = new TGeoTranslation(0., (AperY[0] + I_height + text_height / 2.),
+                                                 PilPosZ[0] - I_width / 2. + text_thickness / 2.);
+    TGeoTranslation* tr201 = new TGeoTranslation(0., (AperY[1] + I_height + text_height / 2.),
+                                                 PilPosZ[2] - I_width / 2. + text_thickness / 2.);
+    TGeoTranslation* tr202 = new TGeoTranslation(0., (AperY[2] + I_height + text_height / 2.),
+                                                 PilPosZ[4] - I_width / 2. + text_thickness / 2.);
+
+    TGeoCombiTrans* tr203 =
+      new TGeoCombiTrans(-(AperX[0] + I_height + text_thickness / 2.),
+                         (AperY[0] + I_height - I_width - text_height / 2.), (PilPosZ[0] + PilPosZ[1]) / 2., roty090);
+    TGeoCombiTrans* tr204 =
+      new TGeoCombiTrans(-(AperX[1] + I_height + text_thickness / 2.),
+                         (AperY[1] + I_height - I_width - text_height / 2.), (PilPosZ[2] + PilPosZ[3]) / 2., roty090);
+    TGeoCombiTrans* tr205 =
+      new TGeoCombiTrans(-(AperX[2] + I_height + text_thickness / 2.),
+                         (AperY[2] + I_height - I_width - text_height / 2.), (PilPosZ[4] + PilPosZ[5]) / 2., roty090);
+
+    TGeoCombiTrans* tr206 =
+      new TGeoCombiTrans((AperX[0] + I_height + text_thickness / 2.),
+                         (AperY[0] + I_height - I_width - text_height / 2.), (PilPosZ[0] + PilPosZ[1]) / 2., roty270);
+    TGeoCombiTrans* tr207 =
+      new TGeoCombiTrans((AperX[1] + I_height + text_thickness / 2.),
+                         (AperY[1] + I_height - I_width - text_height / 2.), (PilPosZ[2] + PilPosZ[3]) / 2., roty270);
+    TGeoCombiTrans* tr208 =
+      new TGeoCombiTrans((AperX[2] + I_height + text_thickness / 2.),
+                         (AperY[2] + I_height - I_width - text_height / 2.), (PilPosZ[4] + PilPosZ[5]) / 2., roty270);
+
+    TGeoVolume* trdbox1 = new TGeoVolumeAssembly("trdbox1");  // volume for TRD text (108, 40, 8)
+    TGeoVolume* trdbox2 = new TGeoVolumeAssembly("trdbox2");  // volume for TRD text (108, 40, 8)
+    TGeoVolume* trdbox3 = new TGeoVolumeAssembly("trdbox3");  // volume for TRD text (108, 40, 8)
+    add_trd_labels(trdbox1, trdbox2, trdbox3);
+
+    // final placement
+    if (ShowLayer[0])  // if geometry contains layer 1 (1st layer of station 1)
+    {
+      //    trd_1->AddNode(trdbox1, 1, tr200);
+      trd_1->AddNode(trdbox1, 4, tr203);
+      trd_1->AddNode(trdbox1, 7, tr206);
+    }
+    if (ShowLayer[4])  // if geometry contains layer 5 (1st layer of station 2)
+    {
+      //    trd_2->AddNode(trdbox2, 2, tr201);
+      trd_2->AddNode(trdbox2, 5, tr204);
+      trd_2->AddNode(trdbox2, 8, tr207);
+    }
+    if (ShowLayer[8])  // if geometry contains layer 9 (1st layer of station 3)
+    {
+      //    trd_3->AddNode(trdbox3, 3, tr202);
+      trd_3->AddNode(trdbox3, 6, tr205);
+      trd_3->AddNode(trdbox3, 9, tr208);
+    }
+  }
+
+  if (ShowLayer[0])  // if geometry contains layer 1 (1st layer of station 1)
+    gGeoMan->GetVolume(geoVersion)->AddNode(trd_1, 1);
+  if (ShowLayer[4])  // if geometry contains layer 5 (1st layer of station 2)
+    gGeoMan->GetVolume(geoVersion)->AddNode(trd_2, 2);
+  if (ShowLayer[8])  // if geometry contains layer 9 (1st layer of station 3)
+    gGeoMan->GetVolume(geoVersion)->AddNode(trd_3, 3);
+}