run.C

Elvira Gazeeva, 12/20/2017 12:09 PM

Download (4.43 KB)

 
1

    
2
void run(Int_t nEvents = 100, Float_t ekin = 0.01){
3
  //---------------------Files-----------------------------------------------
4
  TString outFile;
5
  outFile.Form("run%.4f.root", ekin);
6
  TString parFile;
7
  parFile.Form("par%.4f.root", ekin);
8
  // ------------------------------------------------------------------------
9

    
10
  // -----   Timer   --------------------------------------------------------
11
  TStopwatch timer;
12
  timer.Start();
13
  // ------------------------------------------------------------------------
14
 
15
  // -----   Create simulation run   ----------------------------------------
16
  FairRunSim* run = new FairRunSim();
17
  /** Select transport engine
18
  * TGeant3
19
  * TGeant4
20
  **/
21
  run->SetName("TGeant4");              // Transport engine
22
  run->SetOutputFile(outFile.Data());          // Output file
23
  // ------------------------------------------------------------------------
24
  
25
  // -----   Runtime database   ---------------------------------------------
26
  FairRuntimeDb* rtdb = run->GetRuntimeDb();
27
  // ------------------------------------------------------------------------
28
  
29
  // -----   Create media   -------------------------------------------------
30
  run->SetMaterials("media.geo");       // Materials
31
  // ------------------------------------------------------------------------
32

    
33
  // -----   Create detectors  ----------------------------------------------        
34
  FairModule* cave= new ERCave("CAVE");
35
  cave->SetGeometryFileName("cave.geo");
36
  run->AddModule(cave);
37
        
38
  // ER NeuRad definition
39
  /* Select verbosity level
40
   * 1 - only standard logs
41
   * 2 - Print points after each event
42
   * 3 - - GEANT Step information
43
  */
44
  Int_t verbose = 1;
45
  ERND* nd= new ERND("ERND", kTRUE,verbose);
46
  nd->SetGeometryFileName("ND1ch.geo.root");
47
  run->AddModule(nd);
48
  // ------------------------------------------------------------------------
49
        
50
  // -----   Create PrimaryGenerator   --------------------------------------
51
  FairPrimaryGenerator* primGen = new FairPrimaryGenerator();
52
//  Int_t pdgId = 2112; // neutron  beam
53
  Int_t pdgId = 11; // proton  beam
54
  Double32_t theta1 = 0.;  // polar angle distribution
55
  Double32_t theta2 = 0.;
56
  Double32_t kin_energy = ekin; //GeV
57
  Double_t mass = TDatabasePDG::Instance()->GetParticle(pdgId)->Mass();
58
  Double32_t momentum = TMath::Sqrt(kin_energy*kin_energy + 2.*kin_energy*mass); //GeV
59
  FairBoxGenerator* boxGen = new FairBoxGenerator(pdgId, 1);
60
  boxGen->SetThetaRange(theta1, theta2);
61
  boxGen->SetPRange(momentum, momentum);
62
  boxGen->SetPhiRange(0., 180.);
63
  boxGen->SetBoxXYZ(0.,0,0.0,0.0,-10.);
64
  boxGen->SetCosTheta();
65

    
66
  primGen->AddGenerator(boxGen);
67
  run->SetGenerator(primGen);
68
  // ------------------------------------------------------------------------
69

    
70
  // ------------------------ND digitizer -----------------------------------
71
  ERNDDigitizer* digitizer = new ERNDDigitizer(1);
72
  digitizer->SetEdepError(0.0,0.0,0.0);
73
  digitizer->SetLYError(0.0,0.0,0.0);
74
  digitizer->SetTimeError(0.0);
75
  digitizer->SetQuenchThreshold(0.005);
76
  digitizer->SetLYThreshold(0.004);
77
  digitizer->SetProbabilityB(0.1);
78
  digitizer->SetProbabilityC(0.3);
79
  run->AddTask(digitizer);
80
  // ------------------------------------------------------------------------
81
        
82
  //-------Set visualisation flag to true------------------------------------
83
  run->SetStoreTraj(kTRUE);
84
        
85
  //-------Set LOG verbosity  ----------------------------------------------- 
86
  FairLogger::GetLogger()->SetLogScreenLevel("DEBUG");
87
  
88
  // -----   Initialize simulation run   ------------------------------------
89
  run->Init();
90
  Int_t nSteps = -15000;
91
  //gMC->SetMaxNStep(nSteps);
92
        
93
  // -----   Runtime database   ---------------------------------------------
94
  Bool_t kParameterMerged = kTRUE;
95
  FairParRootFileIo* parOut = new FairParRootFileIo(kParameterMerged);
96
  parOut->open(parFile.Data());
97
  rtdb->setOutput(parOut);
98
  rtdb->saveOutput();
99
  rtdb->print();
100
  // ---------------------------------------------------------
101
  
102
  // -----   Run simulation  ------------------------------------------------
103
  run->Run(nEvents);
104
  
105
  // -----   Finish   -------------------------------------------------------
106
  //neuRad->WriteHistos();
107
  timer.Stop();
108
  Double_t rtime = timer.RealTime();
109
  Double_t ctime = timer.CpuTime();
110
  cout << endl << endl;
111
  cout << "Macro finished succesfully." << endl;
112
  cout << "Output file is sim.root" << endl;
113
  cout << "Parameter file is par.root" << endl;
114
  cout << "Real time " << rtime << " s, CPU time " << ctime
115
                  << "s" << endl << endl;
116
}