NeuRad_sim.C

Ivan Muzalevsky, 10/13/2017 12:03 PM

Download (4.46 KB)

 
1
void NeuRad_sim(Int_t nEvents = 100){
2
  //---------------------Files-----------------------------------------------
3
  TString outFile= "sim.root";
4
  TString parFile= "par.root";
5
  // ------------------------------------------------------------------------
6

    
7
  // -----   Timer   --------------------------------------------------------
8
  TStopwatch timer;
9
  timer.Start();
10
  // ------------------------------------------------------------------------
11
 
12
  // -----   Create simulation run   ----------------------------------------
13
  FairRunSim* run = new FairRunSim();
14
  /** Select transport engine
15
  * TGeant3
16
  * TGeant4
17
  **/
18
  run->SetName("TGeant4");              // Transport engine
19
  run->SetOutputFile(outFile.Data());          // Output file
20
  // ------------------------------------------------------------------------
21
  
22
  // -----   Runtime database   ---------------------------------------------
23
  FairRuntimeDb* rtdb = run->GetRuntimeDb();
24
  // ------------------------------------------------------------------------
25
  
26
  // -----   Create media   -------------------------------------------------
27
  run->SetMaterials("media.geo");       // Materials
28
  // ------------------------------------------------------------------------
29
  //-------- Set MC event header --------------------------------------------
30
  ERMCEventHeader* header = new ERMCEventHeader();
31
  run->SetMCEventHeader(header);
32
  //-------------------------------------------------------------------------
33
  // -----   Create detectors  ----------------------------------------------        
34
  FairModule* cave= new ERCave("CAVE");
35
  cave->SetGeometryFileName("cave.geo");
36
  run->AddModule(cave);
37

    
38
  ERCollimator* collimator = new ERCollimator();
39
  collimator->SetGeometryFileName("collimator.geo.root");
40
  run->AddModule(collimator);
41
  // ER NeuRad definition
42
  /* Select verbosity level
43
   * 1 - only standard logs
44
   * 2 - Print points after each event
45
   * 3 - - GEANT Step information
46
  */
47
  Int_t verbose = 1;
48
  ERNeuRad* neuRad= new ERNeuRad("ERNeuRad", kTRUE,verbose);
49
  neuRad->SetGeometryFileName("NeuRad.v4.geo.root");
50
  /* Select storing stepss
51
   * not store steps
52
   * SetStorePrimarySteps() - store only primary particle step
53
   * SetStoreAllSteps() - store all steps. WARNING - very slow
54
  */
55
  neuRad->SetStorePrimarySteps();
56
  run->AddModule(neuRad);
57
  // ------------------------------------------------------------------------
58
        
59
  // -----   Create PrimaryGenerator   --------------------------------------
60
  FairPrimaryGenerator* primGen = new FairPrimaryGenerator();
61
  Int_t pdgId = 22; // gamma  beam
62
  Double32_t theta1 = 0.;  // polar angle distribution
63
  Double32_t theta2 = 0.001*TMath::RadToDeg();  // degree
64
  Double32_t kin_energy = .000660; //GeV
65
  Double_t mass = TDatabasePDG::Instance()->GetParticle(pdgId)->Mass();
66
  Double32_t momentum = TMath::Sqrt(kin_energy*kin_energy + 2.*kin_energy*mass); //GeV
67
  FairBoxGenerator* boxGen = new FairBoxGenerator(pdgId, 1);
68
  boxGen->SetThetaRange(theta1, theta2);
69
  boxGen->SetPRange(momentum, momentum);
70
  boxGen->SetPhiRange(0, 360);
71
  //boxGen->SetXYZ(0.3,0.3,55.);
72
  boxGen->SetBoxXYZ(0., 0.6,0., 0.6,0.);
73

    
74
  primGen->AddGenerator(boxGen);
75
  run->SetGenerator(primGen);
76
  // ------------------------------------------------------------------------
77
        
78
  //-------Set visualisation flag to true------------------------------------
79
  run->SetStoreTraj(kTRUE);
80
        
81
  //-------Set LOG verbosity  ----------------------------------------------- 
82
  FairLogger::GetLogger()->SetLogVerbosityLevel("LOW");
83
  
84
  // -----   Initialize simulation run   ------------------------------------
85
  run->Init();
86
  Int_t nSteps = -15000;
87
  //gMC->SetMaxNStep(nSteps);
88
        
89
  // -----   Runtime database   ---------------------------------------------
90
  Bool_t kParameterMerged = kTRUE;
91
  FairParRootFileIo* parOut = new FairParRootFileIo(kParameterMerged);
92
  parOut->open(parFile.Data());
93
  rtdb->setOutput(parOut);
94
  rtdb->saveOutput();
95
  rtdb->print();
96
  // ---------------------------------------------------------
97
  
98
  // -----   Run simulation  ------------------------------------------------
99
  run->Run(nEvents);
100
  
101
  // -----   Finish   -------------------------------------------------------
102
  timer.Stop();
103
  Double_t rtime = timer.RealTime();
104
  Double_t ctime = timer.CpuTime();
105
  cout << endl << endl;
106
  cout << "Macro finished succesfully." << endl;
107
  cout << "Output file is sim.root" << endl;
108
  cout << "Parameter file is par.root" << endl;
109
  cout << "Real time " << rtime << " s, CPU time " << ctime
110
                  << "s" << endl << endl;
111
}