-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy pathrun_tutorial1_binary.C
168 lines (129 loc) · 5.94 KB
/
run_tutorial1_binary.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/********************************************************************************
* Copyright (C) 2014-2022 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
#include "FairBoxGenerator.h"
#include "FairCave.h"
#include "FairParRootFileIo.h"
#include "FairPrimaryGenerator.h"
#include "FairRootFileSink.h"
#include "FairRunSim.h"
#include "FairSimConfig.h"
#include "FairSystemInfo.h"
#include "FairTutorialDet1.h"
#include "FairVMCConfig.h"
#include <TRandom3.h>
#include <TStopwatch.h>
#if !defined(__CLING__) || defined(__ROOTCLING__)
#include <iostream>
using std::cout;
using std::endl;
#endif
void run_tutorial1_main(const FairSimConfig& config);
// Default function, to be executed from cling
void run_tutorial1_binary()
{
FairSimConfig config;
run_tutorial1_main(config);
}
// This function should be called from main of the executable
void run_tutorial1_main(const FairSimConfig& config)
{
TString dir = getenv("VMCWORKDIR");
TString tutdir = dir + "/simulation/Tutorial1";
TString tut_geomdir = dir + "/common/geometry";
gSystem->Setenv("GEOMPATH", tut_geomdir.Data());
TString tut_configdir = dir + "/common/gconfig";
gSystem->Setenv("CONFIG_DIR", tut_configdir.Data());
TString partName[] = {"pions", "eplus", "proton"};
Int_t partPdgC[] = {211, 11, 2212};
Int_t chosenPart = 0;
Double_t momentum = 2.;
Double_t theta = 0.;
// Output file name
TString outFile = config.GetOutputFile();
// Parameter file name
TString parFile = config.GetParameterFile();
TString geoFile = "geofile_" + config.GetEngine() + "_full.root";
// In general, the following parts need not be touched
// ========================================================================
// ---- Debug option -------------------------------------------------
gDebug = 0;
// ------------------------------------------------------------------------
// ----- Timer --------------------------------------------------------
TStopwatch timer;
timer.Start();
// ------------------------------------------------------------------------
// ----- Create simulation run ----------------------------------------
FairRunSim run;
run.SetName(config.GetEngine()); // Transport engine
run.SetSimulationConfig(std::make_unique<FairVMCConfig>());
run.SetIsMT(config.IsMultiThreaded()); // Multi-threading mode (Geant4 only)
run.SetSink(std::make_unique<FairRootFileSink>(outFile));
FairRuntimeDb* rtdb = run.GetRuntimeDb();
// ------------------------------------------------------------------------
// ----- Create media -------------------------------------------------
run.SetMaterials("media.geo"); // Materials
// ------------------------------------------------------------------------
// ----- Create geometry ----------------------------------------------
FairCave cave("CAVE");
cave.SetGeometryFileName("cave_vacuum.geo");
run.AddModule(&cave);
FairTutorialDet1 tutdet("TUTDET", kTRUE);
tutdet.SetGeometryFileName("double_sector.geo");
run.AddModule(&tutdet);
// ------------------------------------------------------------------------
// ----- Create PrimaryGenerator --------------------------------------
FairPrimaryGenerator primGen;
FairBoxGenerator boxGen(partPdgC[chosenPart], 1);
boxGen.SetThetaRange(theta, theta + 0.01);
boxGen.SetPRange(momentum, momentum + 0.01);
boxGen.SetPhiRange(0., 360.);
boxGen.SetDebug(kTRUE);
primGen.AddGenerator(&boxGen);
run.SetGenerator(&primGen);
// ------------------------------------------------------------------------
// ----- Initialize simulation run ------------------------------------
UInt_t randomSeed = config.GetRandomSeed();
TRandom3 random(randomSeed);
gRandom = &random;
run.Init();
// ------------------------------------------------------------------------
// ----- Runtime database ---------------------------------------------
Bool_t kParameterMerged = kTRUE;
FairParRootFileIo parOut(kParameterMerged);
parOut.open(parFile.Data());
rtdb->setOutput(&parOut);
rtdb->saveOutput();
rtdb->print();
// ------------------------------------------------------------------------
// ----- Start run ----------------------------------------------------
run.Run(config.GetNEvents());
run.CreateGeometryFile(geoFile);
// ------------------------------------------------------------------------
// ----- Finish -------------------------------------------------------
cout << endl << endl;
// Extract the maximal used memory an add is as Dart measurement
// This line is filtered by CTest and the value send to CDash
FairSystemInfo sysInfo;
Float_t maxMemory = sysInfo.GetMaxMemory();
cout << "<DartMeasurement name=\"MaxMemory\" type=\"numeric/double\">";
cout << maxMemory;
cout << "</DartMeasurement>" << endl;
timer.Stop();
Double_t rtime = timer.RealTime();
Double_t ctime = timer.CpuTime();
Float_t cpuUsage = ctime / rtime;
cout << "<DartMeasurement name=\"CpuLoad\" type=\"numeric/double\">";
cout << cpuUsage;
cout << "</DartMeasurement>" << endl;
cout << endl << endl;
cout << "Output file is " << outFile << endl;
cout << "Parameter file is " << parFile << endl;
cout << "Real time " << rtime << " s, CPU time " << ctime << "s" << endl << endl;
cout << "Macro finished successfully." << endl;
// ------------------------------------------------------------------------
}