FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
run_sim.C
Go to the documentation of this file.
1 void run_sim(Int_t nEvents = 100, TString mcEngine = "TGeant4", Bool_t isMT = false)
2 {
3 
4  // Output file name
5  TString outFile = "test.root";
6 
7  // Parameter file name
8  TString parFile = "params.root";
9 
10  // ----- Timer --------------------------------------------------------
11  TStopwatch timer;
12  timer.Start();
13  // ------------------------------------------------------------------------
14 
15  // ----- Create simulation run ----------------------------------------
16  FairRunSim* run = new FairRunSim();
17  run->SetName(mcEngine); // Transport engine
18  run->SetSink(new FairRootFileSink(outFile)); // Output file
19  run->SetIsMT(isMT);
20  FairRuntimeDb* rtdb = run->GetRuntimeDb();
21  // ------------------------------------------------------------------------
22 
23  // ----- Create media -------------------------------------------------
24  run->SetMaterials("media.geo"); // Materials
25  // ------------------------------------------------------------------------
26 
27  // ----- Create geometry ----------------------------------------------
28 
29  FairModule* cave = new MyCave("CAVE");
30  cave->SetGeometryFileName("cave.geo");
31  run->AddModule(cave);
32 
33  FairModule* magnet = new MyMagnet("Magnet");
34  run->AddModule(magnet);
35 
36  FairModule* pipe = new MyPipe("Pipe");
37  run->AddModule(pipe);
38 
39  FairDetector* NewDet = new NewDetector("TestDetector", kTRUE);
40  run->AddModule(NewDet);
41 
42  // ------------------------------------------------------------------------
43 
44  // ----- Magnetic field -------------------------------------------
45  // Constant Field
46  MyConstField* fMagField = new MyConstField();
47  fMagField->SetField(0., 20., 0.); // values are in kG
48  fMagField->SetFieldRegion(-200, 200, -200, 200, -200, 200); // values are in cm
49  // (xmin,xmax,ymin,ymax,zmin,zmax)
50  run->SetField(fMagField);
51  // --------------------------------------------------------------------
52 
53  // ----- Create PrimaryGenerator --------------------------------------
55 
56  // Add a box generator also to the run
57  FairBoxGenerator* boxGen = new FairBoxGenerator(13, 5); // 13 = muon; 1 = multipl.
58  boxGen->SetPRange(20, 25); // GeV/c
59  boxGen->SetPhiRange(0., 360.); // Azimuth angle range [degree]
60  boxGen->SetThetaRange(0., 90.); // Polar angle in lab system range [degree]
61  boxGen->SetXYZ(0., 0., 0.); // cm
62  primGen->AddGenerator(boxGen);
63 
64  run->SetGenerator(primGen);
65  // ------------------------------------------------------------------------
66 
67  //---Store the visualiztion info of the tracks, this make the output file very large!!
68  //--- Use it only to display but not for production!
69  run->SetStoreTraj(kTRUE);
70 
71  // ----- Initialize simulation run ------------------------------------
72  run->Init();
73  // ------------------------------------------------------------------------
74 
75  // ----- Runtime database ---------------------------------------------
76 
77  Bool_t kParameterMerged = kTRUE;
78  FairParRootFileIo* parOut = new FairParRootFileIo(kParameterMerged);
79  parOut->open(parFile.Data());
80  rtdb->setOutput(parOut);
81  rtdb->saveOutput();
82  rtdb->print();
83  // ------------------------------------------------------------------------
84 
85  // ----- Start run ----------------------------------------------------
86  run->Run(nEvents);
87 
88  // You can export your ROOT geometry ot a separate file
89  run->CreateGeometryFile("geofile_full.root");
90  // ------------------------------------------------------------------------
91 
92  // ----- Finish -------------------------------------------------------
93  timer.Stop();
94  Double_t rtime = timer.RealTime();
95  Double_t ctime = timer.CpuTime();
96  cout << endl << endl;
97  cout << "Macro finished succesfully." << endl;
98  cout << "Output file is " << outFile << endl;
99  cout << "Parameter file is " << parFile << endl;
100  cout << "Real time " << rtime << " s, CPU time " << ctime << "s" << endl << endl;
101  // ------------------------------------------------------------------------
102 }
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 SetField(FairField *field)
Definition: FairRunSim.cxx:308
void SetPRange(Double32_t pmin=0, Double32_t pmax=10)
void AddGenerator(FairGenerator *generator)
void SetGenerator(FairPrimaryGenerator *Gen)
Definition: FairRunSim.cxx:310
void print(void)
void SetSink(FairSink *tempSink)
Definition: FairRun.h:84
void SetField(Double_t bX, Double_t bY, Double_t bZ)
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
virtual void Init()
Definition: FairRunSim.cxx:143
void run_sim(Int_t nEvents=100, TString mcEngine="TGeant3")
Definition: run_sim.C:8
Definition: MyPipe.h:19
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 SetFieldRegion(Double_t xMin, Double_t xMax, Double_t yMin, Double_t yMax, Double_t zMin, Double_t zMax)
Definition: MyCave.h:21
virtual void Run(Int_t NEvents=0, Int_t NotUsed=0)
Definition: FairRunSim.cxx:306
void AddModule(FairModule *Mod)
Definition: FairRunSim.cxx:118
void SetPhiRange(Double32_t phimin=0, Double32_t phimax=360)
void saveOutput(void)
void SetStoreTraj(Bool_t storeTraj=kTRUE)
Definition: FairRunSim.h:92