|
| 1 | +/****************************************************************************** |
| 2 | + * Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH * |
| 3 | + * Copyright (C) 2022-2025 Members of R3B Collaboration * |
| 4 | + * * |
| 5 | + * This software is distributed under the terms of the * |
| 6 | + * GNU General Public Licence (GPL) version 3, * |
| 7 | + * copied verbatim in the file "LICENSE". * |
| 8 | + * * |
| 9 | + * In applying this license GSI does not waive the privileges and immunities * |
| 10 | + * granted to it by virtue of its status as an Intergovernmental Organization * |
| 11 | + * or submit itself to any jurisdiction. * |
| 12 | + ******************************************************************************/ |
| 13 | + |
| 14 | +// ---------------------------------------------------------------------------- |
| 15 | +// Author: M. Feijoo |
| 16 | +// |
| 17 | +// Last Update: 06/05/2022 |
| 18 | +// |
| 19 | +// Comments: |
| 20 | +// ---------------------------------------------------------------------------- |
| 21 | + |
| 22 | +#include "TROOT.h" |
| 23 | +#include <TGeoManager.h> |
| 24 | +#include <TGeoMatrix.h> |
| 25 | +#include <TGeoVolume.h> |
| 26 | +#include <TMath.h> |
| 27 | +#include <fstream> |
| 28 | +#include <iomanip> |
| 29 | +#include <iostream> |
| 30 | + |
| 31 | +// -------------------------------------------------------------------------- |
| 32 | +// Configurable geometry for the Tof. |
| 33 | +// Use this macro to create root files with the different configurations |
| 34 | +// and positions/angles of the detector. |
| 35 | +// |
| 36 | +// Execute macro: root -l |
| 37 | +// .L create_tofd_geo.C |
| 38 | +// create_tofd_geo() |
| 39 | +// -------------------------------------------------------------------------- |
| 40 | + |
| 41 | +void create_tofd_geo(const char* geoTag = "v2025.6") |
| 42 | +{ |
| 43 | + |
| 44 | + TString geoPath = gSystem->Getenv("VMCWORKDIR"); |
| 45 | + if (geoPath.IsNull()) |
| 46 | + { |
| 47 | + std::cerr << "\033[35mERROR: VMCWORKDIR is not defined\033[0m" << std::endl; |
| 48 | + gApplication->Terminate(); |
| 49 | + } |
| 50 | + |
| 51 | + auto fRefRot = new TGeoRotation(); |
| 52 | + TGeoManager* gGeoMan = nullptr; |
| 53 | + |
| 54 | + // ------- Load media from media file ----------------------------------- |
| 55 | + FairGeoLoader* geoLoad = new FairGeoLoader("TGeo", "FairGeoLoader"); |
| 56 | + FairGeoInterface* geoFace = geoLoad->getGeoInterface(); |
| 57 | + TString medFile = geoPath + "/geometry/media_r3b.geo"; |
| 58 | + geoFace->setMediaFile(medFile); |
| 59 | + geoFace->readMedia(); |
| 60 | + gGeoMan = gGeoManager; |
| 61 | + // -------------------------------------------------------------------------- |
| 62 | + |
| 63 | + // ------- Geometry file name (output) ---------------------------------- |
| 64 | + TString geoFileName = geoPath + "/geometry/tofd_"; |
| 65 | + geoFileName = geoFileName + geoTag + ".geo.root"; |
| 66 | + // -------------------------------------------------------------------------- |
| 67 | + |
| 68 | + // ----------------- Get and create the required media ----------------- |
| 69 | + FairGeoMedia* geoMedia = geoFace->getMedia(); |
| 70 | + FairGeoBuilder* geoBuild = geoLoad->getGeoBuilder(); |
| 71 | + |
| 72 | + auto mAir = geoMedia->getMedium("Air"); |
| 73 | + if (!mAir) |
| 74 | + Fatal("Main", "FairMedium Air not found"); |
| 75 | + geoBuild->createMedium(mAir); |
| 76 | + auto pAirMedium = gGeoMan->GetMedium("Air"); |
| 77 | + if (!pAirMedium) |
| 78 | + Fatal("Main", "Medium Air not found"); |
| 79 | + |
| 80 | + auto mTof = geoMedia->getMedium("plasticForTOF"); |
| 81 | + if (!mTof) |
| 82 | + Fatal("Main", "FairMedium plasticForTOF not found"); |
| 83 | + geoBuild->createMedium(mTof); |
| 84 | + auto pMedTof = gGeoMan->GetMedium("plasticForTOF"); |
| 85 | + if (!pMedTof) |
| 86 | + Fatal("Main", "Medium plasticForTOF not found"); |
| 87 | + |
| 88 | + // -------------- Create geometry and top volume ------------------------- |
| 89 | + gGeoMan = static_cast<TGeoManager*>(gROOT->FindObject("FAIRGeom")); |
| 90 | + gGeoMan->SetName("TOFDgeom"); |
| 91 | + auto top = new TGeoVolumeAssembly("TOP"); |
| 92 | + gGeoMan->SetTopVolume(top); |
| 93 | + |
| 94 | + // Top Volume |
| 95 | + auto pWorld = gGeoMan->GetTopVolume(); |
| 96 | + pWorld->SetVisLeaves(kTRUE); |
| 97 | + |
| 98 | + // Detector specifications |
| 99 | + const size_t n_planes = 4; |
| 100 | + const size_t n_paddles = 44; |
| 101 | + |
| 102 | + // Paddle dimensions in cm |
| 103 | + const float dx = 2.7; |
| 104 | + const float dy = 100.0; |
| 105 | + const float dz = 0.5; |
| 106 | + |
| 107 | + // Positions (for each paddle) |
| 108 | + float x = 0.0, y = 0.0, z = 0.0; |
| 109 | + float shift = 0.0; |
| 110 | + const float air_gap_paddles = 0.04; |
| 111 | + const float air_gap_planes = 3.0; |
| 112 | + |
| 113 | + // Plane definition |
| 114 | + auto Plane = gGeoMan->MakeBox( |
| 115 | + "Plane", pAirMedium, dx / 2. * n_paddles + dx / 4. + (n_paddles - 1) * air_gap_paddles / 2., dy / 2., dz / 2.); |
| 116 | + Plane->SetLineColor(1); |
| 117 | + |
| 118 | + auto detector_width = n_paddles * dx + (n_paddles - 1) * air_gap_paddles; |
| 119 | + auto tofd = new TGeoVolumeAssembly("TOFD"); |
| 120 | + |
| 121 | + auto Paddle = gGeoMan->MakeBox("Paddle", pMedTof, dx / 2., dy / 2., dz / 2.); |
| 122 | + Paddle->SetVisLeaves(kTRUE); |
| 123 | + Paddle->SetLineColor(kBlue); |
| 124 | + |
| 125 | + for (size_t n = 0; n < n_paddles; n++) |
| 126 | + { |
| 127 | + x = -detector_width / 2 + dx / 2 + n * (dx + air_gap_paddles); |
| 128 | + |
| 129 | + auto pMatrix = new TGeoCombiTrans("", x, y, z, fRefRot); |
| 130 | + pMatrix->RegisterYourself(); |
| 131 | + Plane->AddNode(Paddle, n + 1, pMatrix); |
| 132 | + } |
| 133 | + |
| 134 | + for (size_t m = 0; m < n_planes; m++) |
| 135 | + { |
| 136 | + shift = (m % 2 == 0) ? -dx / 4. : dx / 4.; |
| 137 | + |
| 138 | + auto z_plane = -dz * n_planes / 2 - (n_planes - 1) * air_gap_planes / 2 + dz / 2 + m * (dz + air_gap_planes) + |
| 139 | + (m > 1 ? 1.5 : -1.5); |
| 140 | + auto pMatrix_planes = new TGeoCombiTrans("", shift, y, z_plane, fRefRot); |
| 141 | + pMatrix_planes->RegisterYourself(); |
| 142 | + tofd->AddNode(Plane, m + 1, pMatrix_planes); |
| 143 | + } |
| 144 | + |
| 145 | + auto t0 = new TGeoCombiTrans(); |
| 146 | + t0->RegisterYourself(); |
| 147 | + pWorld->AddNode(tofd, 1, t0); |
| 148 | + |
| 149 | + // --------------- Finish ----------------------------------------------- |
| 150 | + gGeoMan->CloseGeometry(); |
| 151 | + gGeoMan->CheckOverlaps(0.001); |
| 152 | + gGeoMan->PrintOverlaps(); |
| 153 | + gGeoMan->Test(); |
| 154 | + |
| 155 | + TFile geoFile(geoFileName, "RECREATE"); |
| 156 | + top->Write(); |
| 157 | + // top->Draw("ogl"); |
| 158 | + geoFile.Close(); |
| 159 | + std::cout << "\033[34m Creating geometry:\033[0m " |
| 160 | + << "\033[33m" << geoFileName << " \033[0m" << std::endl; |
| 161 | + std::cout << "Macro finished successfully." << std::endl; |
| 162 | + gApplication->Terminate(); |
| 163 | +} |
0 commit comments