FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
run_rutherford.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_rutherford(Int_t nEvents = 10, TString mcEngine = "TGeant4", Bool_t isMT = true)
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 + "/test_";
22  outFile = outFile + mcEngine + ".mc.root";
23 
24  TString geoFile = outDir + "/geofile_rutherford_";
25  geoFile = geoFile + mcEngine + "_full.root";
26 
27  TString parFile = outDir + "/params_";
28  parFile = parFile + mcEngine + ".root";
29 
30  // Set the random seed
31  gRandom->SetSeed(98989);
32 
33  // In general, the following parts need not be touched
34  // ========================================================================
35 
36  // ---- Debug option -------------------------------------------------
37  gDebug = 0;
38  // ------------------------------------------------------------------------
39  // ----- Timer --------------------------------------------------------
40  TStopwatch timer;
41  timer.Start();
42  // ------------------------------------------------------------------------
43 
45  // define log file name
46  logger->SetLogFileName("MyLog.log");
47  // log to screen and to file
48  logger->SetLogToScreen(kTRUE);
49  logger->SetLogToFile(kTRUE);
50  // Print very accurate output. Levels are LOW, MEDIUM and HIGH
51  logger->SetLogVerbosityLevel("HIGH");
52 
53  // ----- Create simulation run ----------------------------------------
54  FairRunSim* run = new FairRunSim();
55  run->SetName(mcEngine); // Transport engine
56  run->SetIsMT(isMT); // Multi-threading mode (Geant4 only)
57  run->SetSink(new FairRootFileSink(outFile)); // Output file
58  FairRuntimeDb* rtdb = run->GetRuntimeDb();
59  // ------------------------------------------------------------------------
60 
61  run->SetWriteRunInfoFile(kFALSE);
62  // ----- Create media -------------------------------------------------
63  run->SetMaterials("media.geo"); // Materials
64  // ------------------------------------------------------------------------
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", kTRUE);
77  rutherford->SetGeometryFileName("rutherford.geo");
78  run->AddModule(rutherford);
79  // ------------------------------------------------------------------------
80 
81  // ----- Create PrimaryGenerator --------------------------------------
83  run->SetGenerator(primGen);
84 
85  // Ion Generator
86 
87  FairIonGenerator* fIongen = new FairIonGenerator(2, 4, 2, 1, 0., 0., 1. / 20., 0., 0., -1.);
88  primGen->AddGenerator(fIongen);
89 
90  FairBoxGenerator* boxGen1 = new FairBoxGenerator(2212, 1);
91  boxGen1->SetPRange(.005, .005);
92  boxGen1->SetPhiRange(0., 0.);
93  boxGen1->SetThetaRange(0., 0.);
94  boxGen1->SetXYZ(0., 0., -3.);
95  primGen->AddGenerator(boxGen1);
96 
98  // create and fill histogram with y-pT distribution
99  TH2D ypt_hist("ypt", "ypt;y;p_{T}", 100, -2, 2, 100, 0, 2);
100  ypt_hist.Fill(0.2, 0.2);
101  ypt_hist.Fill(0.2, 0.4);
102  ypt->SetYPt(ypt_hist);
103  ypt->SetMultiplicity(10);
104  ypt->SetPDGType(211);
105  // set vertex with gaussian distribution
106  ypt->SetVertex(0, 0, -2.5, 0.1, 0.1, 0.1, FairBaseMCGenerator::kGauss);
107  primGen->AddGenerator(ypt);
108  // ------------------------------------------------------------------------
109 
110  run->SetStoreTraj(kTRUE);
111 
112  // ----- Run initialisation -------------------------------------------
113  run->Init();
114  // ------------------------------------------------------------------------
115 
116  // Set cuts for storing the trajectories.
117  // Switch this on only if trajectories are stored.
118  // Choose this cuts according to your needs, but be aware
119  // that the file size of the output file depends on these cuts
120 
122  // trajFilter->SetStepSizeCut(0.01); // 1 cm
123  // trajFilter->SetVertexCut(-2000., -2000., 4., 2000., 2000., 100.);
124  // trajFilter->SetMomentumCutP(10e-3); // p_lab > 10 MeV
125  // trajFilter->SetEnergyCut(0., 1.02); // 0 < Etot < 1.04 GeV
126  trajFilter->SetStorePrimaries(kTRUE);
127  trajFilter->SetStoreSecondaries(kTRUE);
128  // ------------------------------------------------------------------------
129 
130  // ----- Runtime database ---------------------------------------------
131 
132  Bool_t kParameterMerged = kTRUE;
133  FairParRootFileIo* parOut = new FairParRootFileIo(kParameterMerged);
134  parOut->open(parFile.Data());
135  rtdb->setOutput(parOut);
136  rtdb->saveOutput();
137  rtdb->print();
138  // ------------------------------------------------------------------------
139 
140  // ----- Start run ----------------------------------------------------
141  run->Run(nEvents);
142  // ------------------------------------------------------------------------
143  run->CreateGeometryFile(geoFile);
144 
145  // ----- Finish -------------------------------------------------------
146 
147  cout << endl << endl;
148 
149  // Extract the maximal used memory an add is as Dart measurement
150  // This line is filtered by CTest and the value send to CDash
151  FairSystemInfo sysInfo;
152  Float_t maxMemory = sysInfo.GetMaxMemory();
153  cout << "<DartMeasurement name=\"MaxMemory\" type=\"numeric/double\">";
154  cout << maxMemory;
155  cout << "</DartMeasurement>" << endl;
156 
157  timer.Stop();
158  Double_t rtime = timer.RealTime();
159  Double_t ctime = timer.CpuTime();
160 
161  Float_t cpuUsage = ctime / rtime;
162  cout << "<DartMeasurement name=\"CpuLoad\" type=\"numeric/double\">";
163  cout << cpuUsage;
164  cout << "</DartMeasurement>" << endl;
165 
166  cout << endl << endl;
167  cout << "Output file is " << outFile << endl;
168  cout << "Parameter file is " << parFile << endl;
169  cout << "Real time " << rtime << " s, CPU time " << ctime << "s" << endl << endl;
170  cout << "Macro finished successfully." << endl;
171 
172  // ------------------------------------------------------------------------
173 }
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 SetYPt(const TH2D &yPt)
void SetMultiplicity(Int_t mult)
void SetPRange(Double32_t pmin=0, Double32_t pmax=10)
void AddGenerator(FairGenerator *generator)
void SetWriteRunInfoFile(Bool_t write)
Definition: FairRun.cxx:122
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 SetIsMT(Bool_t isMT)
Definition: FairRunSim.h:184
void SetXYZ(Double32_t x=0, Double32_t y=0, Double32_t z=0)
FairParRootFileIo * parOut
void SetPDGType(Int_t pdg)
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 SetVertex(Double_t vx, Double_t vy, Double_t vz, Double_t evx=0, Double_t evy=0, Double_t evz=0, eVertexSmear sm=kBox)
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 run_rutherford(Int_t nEvents=10, TString mcEngine="TGeant4", Bool_t isMT=true)
Definition: run_rutherford.C:8
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