sim.C

Vitaliy Schetinin, 07/05/2017 08:08 AM

Download (4.78 KB)

 
1
void sim(Int_t seed = 9999, Int_t nEvents = 1000000){
2
  //---------------------Files-----------------------------------------------
3
  TString outFile;
4
  outFile.Form("sim%d.root",seed);
5
  TString parFile;
6
  parFile.Form("par%d.root",seed);
7
  // ------------------------------------------------------------------------
8
  gRandom->SetSeed(seed);
9
  // -----   Timer   --------------------------------------------------------
10
  TStopwatch timer;
11
  timer.Start();
12
  // ------------------------------------------------------------------------
13
 
14
  // -----   Create simulation run   ----------------------------------------
15
  FairRunSim* run = new FairRunSim();
16
  /** Select transport engine
17
  * TGeant3
18
  * TGeant4
19
  **/
20
  run->SetName("TGeant4");              // Transport engine
21
  run->SetOutputFile(outFile.Data());          // Output file
22
  // ------------------------------------------------------------------------
23
  
24
  // -----   Runtime database   ---------------------------------------------
25
  FairRuntimeDb* rtdb = run->GetRuntimeDb();
26
  // ------------------------------------------------------------------------
27
  
28
  // -----   Create media   -------------------------------------------------
29
  run->SetMaterials("media.geo");       // Materials
30
  // ------------------------------------------------------------------------
31

    
32
  //-------- Set MC event header --------------------------------------------
33
  ERMCEventHeader* header = new ERMCEventHeader();
34
  run->SetMCEventHeader(header);
35
  //-------------------------------------------------------------------------
36

    
37
  // -----   Create detectors  ---------------------------------------------- 
38
  FairModule* cave= new ERCave("CAVE");
39
  cave->SetGeometryFileName("cave.geo");
40
  run->AddModule(cave);
41
  
42
  ERCollimator* collimator = new ERCollimator();
43
  collimator->SetGeometryFileName("collimator.geo.root");
44
  run->AddModule(collimator);
45

    
46
  // ER NeuRad definition
47
  /* Select verbosity level
48
   * 1 - only standard logs
49
   * 2 - Print points after each event
50
   * 3 - - GEANT Step information
51
  */
52
  Int_t verbose = 1;
53
  ERNeuRad* neuRad= new ERNeuRad("ERNeuRad", kTRUE,verbose);
54
  neuRad->SetGeometryFileName("NeuRad.v4.geo.root");
55
  /* Select storing stepss
56
   * not store steps
57
   * SetStorePrimarySteps() - store only primary particle step
58
   * SetStoreAllSteps() - store all steps. WARNING - very slow
59
  */
60
  //neuRad->SetStorePrimarySteps();
61
  run->AddModule(neuRad);
62
  // ------------------------------------------------------------------------
63
  
64
  // -----   Create PrimaryGenerator   --------------------------------------
65
  FairPrimaryGenerator* primGen = new FairPrimaryGenerator();
66
  // Int_t pdgId = 2112; // neutron  beam
67
  // Double32_t theta1 = 0.;  // polar angle distribution
68
  // Double32_t theta2 = 7.;
69
  // Double32_t kin_energy = .500; //GeV
70
  Int_t pdgId = 22; // neutron  beam
71
  Double32_t theta1 = 0.;  // polar angle distribution
72
  Double32_t theta2 = 180.;
73
  Double32_t kin_energy = 0.001333; //GeV
74

    
75
  Double_t mass = TDatabasePDG::Instance()->GetParticle(pdgId)->Mass();
76
  Double32_t momentum = TMath::Sqrt(kin_energy*kin_energy + 2.*kin_energy*mass); //GeV
77
  FairBoxGenerator* boxGen = new FairBoxGenerator(pdgId, 1);
78
  boxGen->SetThetaRange(theta1, theta1);
79
  boxGen->SetPRange(momentum, momentum);
80
  // boxGen->SetPhiRange(90, 90);
81
  boxGen->SetPhiRange(0, 0);
82
  // boxGen->SetBoxXYZ(0.,0,0.3,0.3,0.);
83
  boxGen->SetBoxXYZ(-0.149,-0.149,0.149,0.149,19.4);
84
  primGen->AddGenerator(boxGen);
85
  run->SetGenerator(primGen);
86
  // ------------------------------------------------------------------------
87
  
88
  //-------Set visualisation flag to true------------------------------------
89
  //run->SetStoreTraj(kTRUE);
90
  
91
  //-------Set LOG verbosity  ----------------------------------------------- 
92
  FairLogger::GetLogger()->SetLogVerbosityLevel("LOW");
93
  
94
  // -----   Initialize simulation run   ------------------------------------
95
  run->Init();
96
  Int_t nSteps = -15000;
97
  //gMC->SetMaxNStep(nSteps);
98
  
99
  // -----   Runtime database   ---------------------------------------------
100
  Bool_t kParameterMerged = kTRUE;
101
  FairParRootFileIo* parOut = new FairParRootFileIo(kParameterMerged);
102
  parOut->open(parFile.Data());
103
  rtdb->setOutput(parOut);
104
  rtdb->saveOutput();
105
  rtdb->print();
106
  // ---------------------------------------------------------
107
  
108
  // -----   Run simulation  ------------------------------------------------
109
  run->Run(nEvents);
110
  
111
  // -----   Finish   -------------------------------------------------------
112
  neuRad->WriteHistos();
113
  timer.Stop();
114
  Double_t rtime = timer.RealTime();
115
  Double_t ctime = timer.CpuTime();
116
  cout << endl << endl;
117
  cout << "Macro finished succesfully." << endl;
118
  cout << "Output file is sim.root" << endl;
119
  cout << "Parameter file is par.root" << endl;
120
  cout << "Real time " << rtime << " s, CPU time " << ctime
121
      << "s" << endl << endl;
122
}