|
| 1 | +/****************************************************************************** |
| 2 | + * Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH * |
| 3 | + * Copyright (C) 2019-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 | +#include <TStopwatch.h> |
| 15 | +#include <TString.h> |
| 16 | +#include <TSystem.h> |
| 17 | +#include <memory> |
| 18 | + |
| 19 | +void testSimulation(const int nbevents = 10) |
| 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 = "test.simu.root"; |
| 38 | + const TString parafile = "test.para.root"; |
| 39 | + |
| 40 | + // Basic simulation setup |
| 41 | + auto run = new FairRunSim(); |
| 42 | + run->SetName("TGeant4"); |
| 43 | + run->SetStoreTraj(false); |
| 44 | + run->SetMaterials("media_r3b.geo"); |
| 45 | + run->SetSink(new FairRootFileSink(simufile)); |
| 46 | + |
| 47 | + auto rtdb = run->GetRuntimeDb(); |
| 48 | + rtdb->initContainers(1); |
| 49 | + |
| 50 | + // Primary particle generator |
| 51 | + auto boxGen = new FairBoxGenerator(2212, 3); |
| 52 | + boxGen->SetXYZ(0, 0, 0.); |
| 53 | + boxGen->SetThetaRange(0., 145.); |
| 54 | + boxGen->SetPhiRange(0., 360.); |
| 55 | + boxGen->SetEkinRange(0.4, 0.8); |
| 56 | + auto primGen = new FairPrimaryGenerator(); |
| 57 | + primGen->AddGenerator(boxGen); |
| 58 | + run->SetGenerator(primGen); |
| 59 | + |
| 60 | + // Geometry: Cave |
| 61 | + auto cave = new R3BCave("CAVE"); |
| 62 | + cave->SetGeometryFileName("r3b_cave.geo"); |
| 63 | + run->AddModule(cave); |
| 64 | + |
| 65 | + // Geometry: Califa |
| 66 | + auto calsim = new R3BCalifa("califa_full.geo.root", { 0., 0., 0. }); |
| 67 | + calsim->SelectGeometryVersion(0); |
| 68 | + run->AddModule(calsim); |
| 69 | + |
| 70 | + // Digitizer: Califa |
| 71 | + auto califaDig = new R3BCalifaDigitizer(); |
| 72 | + run->AddTask(califaDig); |
| 73 | + |
| 74 | + auto califaCal2Cluster = new R3BCalifaCrystalCal2Cluster(); |
| 75 | + califaCal2Cluster->SetCrystalThreshold(0.1); // 100 keV |
| 76 | + run->AddTask(califaCal2Cluster); |
| 77 | + |
| 78 | + // Init |
| 79 | + run->Init(); |
| 80 | + |
| 81 | + // ----- Runtime database --------------------------------------------- |
| 82 | + auto parOut = new FairParRootFileIo(true); |
| 83 | + parOut->open(parafile.Data()); |
| 84 | + rtdb->setOutput(parOut); |
| 85 | + rtdb->saveOutput(); |
| 86 | + rtdb->print(); |
| 87 | + |
| 88 | + // Simulate |
| 89 | + run->Run(nbevents); |
| 90 | + |
| 91 | + // Report |
| 92 | + timer.Stop(); |
| 93 | + std::cout << "Real time: " << timer.RealTime() << "s, CPU time: " << timer.CpuTime() << "s" << std::endl; |
| 94 | + std::cout << "Macro finished successfully." << std::endl; |
| 95 | +} |
0 commit comments