|
| 1 | +/****************************************************************************** |
| 2 | + * Copyright (C) 2025 GSI Helmholtzzentrum für Schwerionenforschung GmbH * |
| 3 | + * Copyright (C) 2025-2026 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 | +#include <TStopwatch.h> |
| 15 | +#include <TString.h> |
| 16 | +#include <TSystem.h> |
| 17 | +#include <memory> |
| 18 | + |
| 19 | +void testGladHecSimulation(const int nbevents = 100) |
| 20 | +{ |
| 21 | + // Timer |
| 22 | + TStopwatch timer; |
| 23 | + timer.Start(); |
| 24 | + |
| 25 | + // Logging |
| 26 | + auto logger = FairLogger::GetLogger(); |
| 27 | + logger->SetLogVerbosityLevel("low"); |
| 28 | + logger->SetLogScreenLevel("warn"); |
| 29 | + logger->SetColoredLog(true); |
| 30 | + |
| 31 | + // System paths |
| 32 | + const TString workDirectory = getenv("VMCWORKDIR"); |
| 33 | + gSystem->Setenv("GEOMPATH", workDirectory + "/geometry"); |
| 34 | + gSystem->Setenv("CONFIG_DIR", workDirectory + "/gconfig"); |
| 35 | + |
| 36 | + // Output files |
| 37 | + const TString simufile = "gladhec.simu.root"; |
| 38 | + const TString parafile = "gladhec.para.root"; |
| 39 | + |
| 40 | + // Input GLAD geometry |
| 41 | + const TString fGladGeo = "glad_hec14_v2025.1.geo.root"; |
| 42 | + |
| 43 | + // Basic simulation setup |
| 44 | + auto run = std::make_unique<FairRunSim>(); |
| 45 | + run->SetName("TGeant4"); |
| 46 | + run->SetStoreTraj(false); |
| 47 | + run->SetMaterials("media_r3b.geo"); |
| 48 | + |
| 49 | + auto config = std::make_unique<FairGenericVMCConfig>(); |
| 50 | + run->SetSimulationConfig(std::move(config)); |
| 51 | + run->SetSink(std::make_unique<FairRootFileSink>(simufile.Data())); |
| 52 | + |
| 53 | + // ----- Runtime data base -------------------------------------------- |
| 54 | + auto* rtdb = run->GetRuntimeDb(); |
| 55 | + UInt_t runId = 1; |
| 56 | + rtdb->initContainers(runId); |
| 57 | + |
| 58 | + // Primary particle generator |
| 59 | + auto ionGen = std::make_unique<FairIonGenerator>(92, 238, 92, 1, 0., 0., 1.09, 0., 0., 0.); |
| 60 | + auto primGen = std::make_unique<FairPrimaryGenerator>(); |
| 61 | + primGen->AddGenerator(ionGen.release()); |
| 62 | + run->SetGenerator(primGen.release()); |
| 63 | + |
| 64 | + // Geometry: Cave |
| 65 | + auto cave = std::make_unique<R3BCave>("CAVE"); |
| 66 | + cave->SetGeometryFileName("r3b_cave_vacuum.geo"); |
| 67 | + run->AddModule(cave.release()); |
| 68 | + |
| 69 | + // Geometry: GLAD |
| 70 | + run->AddModule(new R3BGladMagnet(fGladGeo.Data(), R3BGladMagnet::HEC14)); |
| 71 | + |
| 72 | + // GLAD Filed |
| 73 | + auto* GladField = new R3BGladFieldMap("R3BGladMap", "A", R3BGladFieldMap::HEC14); |
| 74 | + GladField->SetFieldfromCurrent(2600.); // Current in Amperes |
| 75 | + run->SetField(GladField); |
| 76 | + |
| 77 | + // Init |
| 78 | + run->Init(); |
| 79 | + |
| 80 | + // Save field parameters |
| 81 | + auto* fieldPar = dynamic_cast<R3BFieldPar*>(rtdb->getContainer("R3BFieldPar")); |
| 82 | + fieldPar->SetParameters(GladField); |
| 83 | + fieldPar->setChanged(); |
| 84 | + |
| 85 | + // Output file with parameters |
| 86 | + auto parOut = std::make_unique<FairParRootFileIo>(true); |
| 87 | + parOut->open(parafile.Data()); |
| 88 | + rtdb->setOutput(parOut.release()); |
| 89 | + rtdb->saveOutput(); |
| 90 | + rtdb->print(); |
| 91 | + |
| 92 | + // Simulate |
| 93 | + run->Run(nbevents); |
| 94 | + |
| 95 | + // Report |
| 96 | + timer.Stop(); |
| 97 | + std::cout << "Real time: " << timer.RealTime() << "s, CPU time: " << timer.CpuTime() << "s" << std::endl; |
| 98 | + std::cout << "Macro finished successfully." << std::endl; |
| 99 | +} |
0 commit comments