FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
run_rad.C
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 void run_rad(Int_t nEvents = 100, TString mcEngine = "TGeant3")
9 {
10 
11  TString dir = gSystem->Getenv("VMCWORKDIR");
12  TString tutdir = dir + "/simulation/rutherford/macros";
13 
14  TString tut_geomdir = dir + "/common/geometry";
15  gSystem->Setenv("GEOMPATH", tut_geomdir.Data());
16 
17  TString tut_configdir = dir + "/common/gconfig";
18  gSystem->Setenv("CONFIG_DIR", tut_configdir.Data());
19 
20  TString outDir = "data";
21  TString outFile = outDir + "/test1_";
22  outFile = outFile + mcEngine + ".mc.root";
23 
24  TString geoFile = outDir + "/geofile_rad_";
25  geoFile = geoFile + mcEngine + "_full.root";
26 
27  TString parFile = outDir + "/params1_";
28  parFile = parFile + mcEngine + ".root";
29 
30  // In general, the following parts need not be touched
31  // ========================================================================
32 
33  // ---- Debug option -------------------------------------------------
34  gDebug = 0;
35  // ------------------------------------------------------------------------
36 
37  // ----- Timer --------------------------------------------------------
38  TStopwatch timer;
39  timer.Start();
40  // ------------------------------------------------------------------------
41 
43  // define log file name
44  logger->SetLogFileName("MyLog.log");
45  // log to screen and to file
46  logger->SetLogToScreen(kTRUE);
47  logger->SetLogToFile(kTRUE);
48  // Print very accurate output. Levels are LOW, MEDIUM and HIGH
49  logger->SetLogVerbosityLevel("HIGH");
50 
51  // ----- Create simulation run ----------------------------------------
52  FairRunSim* run = new FairRunSim();
53  run->SetName(mcEngine); // Transport engine
54  run->SetSink(new FairRootFileSink(outFile)); // Output file
55  FairRuntimeDb* rtdb = run->GetRuntimeDb();
56  // ------------------------------------------------------------------------
57 
58  // ----- Create media -------------------------------------------------
59  run->SetMaterials("media.geo"); // Materials
60  // ------------------------------------------------------------------------
61 
62  //----Start the radiation length manager ----------------------------------
63 
64  run->SetRadLenRegister(kTRUE);
65 
66  // ----- Create geometry ----------------------------------------------
67 
68  FairModule* cave = new FairCave("CAVE");
69  cave->SetGeometryFileName("cave_vacuum.geo");
70  run->AddModule(cave);
71 
72  FairModule* target = new FairTarget("Target");
73  target->SetGeometryFileName("target_rutherford.geo");
74  run->AddModule(target);
75 
76  FairDetector* rutherford = new FairRutherford("RutherfordDetector", kFALSE);
77  rutherford->SetGeometryFileName("rutherford.geo");
78  run->AddModule(rutherford);
79  // ------------------------------------------------------------------------
80 
81  // ----- Create PrimaryGenerator --------------------------------------
83  run->SetGenerator(primGen);
84 
85  FairBoxGenerator* boxGen1 = new FairBoxGenerator(0, 1);
86  boxGen1->SetPRange(.005, .005);
87  boxGen1->SetPhiRange(0., 0.);
88  boxGen1->SetThetaRange(-90., 90.);
89  boxGen1->SetXYZ(0., 0., -3.);
90  primGen->AddGenerator(boxGen1);
91 
92  // ------------------------------------------------------------------------
93 
94  run->SetStoreTraj(kTRUE);
95 
96  // ----- Run initialisation -------------------------------------------
97  run->Init();
98  // ------------------------------------------------------------------------
99 
100  // Set cuts for storing the trajectories.
101  // Switch this on only if trajectories are stored.
102  // Choose this cuts according to your needs, but be aware
103  // that the file size of the output file depends on these cuts
104 
106  // trajFilter->SetStepSizeCut(0.01); // 1 cm
107  // trajFilter->SetVertexCut(-2000., -2000., 4., 2000., 2000., 100.);
108  // trajFilter->SetMomentumCutP(10e-3); // p_lab > 10 MeV
109  // trajFilter->SetEnergyCut(0., 1.02); // 0 < Etot < 1.04 GeV
110  trajFilter->SetStorePrimaries(kTRUE);
111  trajFilter->SetStoreSecondaries(kTRUE);
112  // ------------------------------------------------------------------------
113 
114  // ----- Runtime database ---------------------------------------------
115 
116  Bool_t kParameterMerged = kTRUE;
117  FairParRootFileIo* parOut = new FairParRootFileIo(kParameterMerged);
118  parOut->open(parFile.Data());
119  rtdb->setOutput(parOut);
120  rtdb->saveOutput();
121  rtdb->print();
122  // ------------------------------------------------------------------------
123 
124  // ----- Start run ----------------------------------------------------
125  run->Run(nEvents);
126  // ------------------------------------------------------------------------
127  run->CreateGeometryFile(geoFile);
128 
129  // ----- Finish -------------------------------------------------------
130 
131  cout << endl << endl;
132 
133  // Extract the maximal used memory an add is as Dart measurement
134  // This line is filtered by CTest and the value send to CDash
135  FairSystemInfo sysInfo;
136  Float_t maxMemory = sysInfo.GetMaxMemory();
137  cout << "<DartMeasurement name=\"MaxMemory\" type=\"numeric/double\">";
138  cout << maxMemory;
139  cout << "</DartMeasurement>" << endl;
140 
141  timer.Stop();
142  Double_t rtime = timer.RealTime();
143  Double_t ctime = timer.CpuTime();
144 
145  Float_t cpuUsage = ctime / rtime;
146  cout << "<DartMeasurement name=\"CpuLoad\" type=\"numeric/double\">";
147  cout << cpuUsage;
148  cout << "</DartMeasurement>" << endl;
149 
150  cout << endl << endl;
151  cout << "Output file is " << outFile << endl;
152  cout << "Parameter file is " << parFile << endl;
153  cout << "Real time " << rtime << " s, CPU time " << ctime << "s" << endl << endl;
154  cout << "Macro finished successfully." << endl;
155 
156  // ------------------------------------------------------------------------
157 }
Bool_t kParameterMerged
virtual void SetGeometryFileName(TString fname, TString geoVer="0")
Definition: FairModule.cxx:199
void CreateGeometryFile(const char *geofile)
Definition: FairRun.cxx:103
list of container factories
Definition: FairRuntimeDb.h:24
void SetPRange(Double32_t pmin=0, Double32_t pmax=10)
void AddGenerator(FairGenerator *generator)
void run_rad(Int_t nEvents=100, TString mcEngine="TGeant3")
Definition: run_rad.C:8
void SetGenerator(FairPrimaryGenerator *Gen)
Definition: FairRunSim.cxx:310
void print(void)
void SetSink(FairSink *tempSink)
Definition: FairRun.h:84
Float_t GetMaxMemory()
void SetLogFileName(const std::string &name)
Definition: FairLogger.h:79
void SetXYZ(Double32_t x=0, Double32_t y=0, Double32_t z=0)
FairParRootFileIo * parOut
void SetLogToScreen(bool enabled)
Definition: FairLogger.h:49
void SetLogToFile(bool enabled)
Definition: FairLogger.h:64
void SetStoreSecondaries(Bool_t storeSec=kTRUE)
static FairTrajFilter * Instance()
static FairLogger * GetLogger()
Definition: FairLogger.cxx:39
void SetStorePrimaries(Bool_t storePrim=kTRUE)
virtual void Init()
Definition: FairRunSim.cxx:143
FairRuntimeDb * GetRuntimeDb(void)
Definition: FairRun.h:80
void SetThetaRange(Double32_t thetamin=0, Double32_t thetamax=90)
void SetMaterials(const char *MatFileName)
Definition: FairRunSim.cxx:312
Bool_t setOutput(FairParIo *)
Bool_t open(const Text_t *fname, Option_t *option="READ", const Text_t *ftitle="", Int_t compress=1)
void SetRadLenRegister(Bool_t value)
Definition: FairRunSim.h:142
virtual void Run(Int_t NEvents=0, Int_t NotUsed=0)
Definition: FairRunSim.cxx:306
StepLogger logger
void AddModule(FairModule *Mod)
Definition: FairRunSim.cxx:118
void SetLogVerbosityLevel(const char *verbosity)
Definition: FairLogger.h:87
void SetPhiRange(Double32_t phimin=0, Double32_t phimax=360)
void saveOutput(void)
void SetStoreTraj(Bool_t storeTraj=kTRUE)
Definition: FairRunSim.h:92