FairRoot/PandaRoot
sim_hypGe_COSY2014.C
Go to the documentation of this file.
1 // Macro created 5/04/2007 by A.Sanchez
2 // It creates a geant simulation file for hypGe
3 int sim_hypGe_COSY2014(Double_t ProtonMomentum = 2.78,Int_t nEvents = 100, Int_t PDG_ext = 2212, Bool_t GausSmearedBeam = 0, Bool_t BremsStahlungActivated = 0, Double_t RunNo = 0)
4 //void sim_hypGe_COSY(Int_t nEvents, Int_t PDG_ext ,Double_t TargetThickness , Double_t TargetAngle , Bool_t GausSmearedBeam , Bool_t BremsStahlungActivated , Bool_t WithBeamDump , Double_t ClusterRadius , Double_t BeamDumpDist )
5 //sim_hypGe_COSY.C(10 ,2212 ,5 ,0 ,0 ,1 ,1 ,30 ,200)
6 {
7  Bool_t FirstBeamTime = false; // set this true to activate in beam stuff and beam dump of 2013 beam time at TOF area
8  Int_t ParticlePDG = PDG_ext; //(-)2212 = (Anti)Proton
9 
10  // Load basic libraries
11  // If it does not work, please check the path of the libs and put it by hands
12  gROOT->Macro("$VMCWORKDIR/gconfig/rootlogon.C");
13  gSystem->Load("libHypGe");
14  gSystem->Load("libHyp");
15 
16  //create Target geometry
17  //gROOT->ProcessLine(".L ../Geometry/hypGeTargetAbsorptionTest.C");
18  //TString TargetFilename = hypGeTargetAbsorptionTest(TargetThickness);
19 
20  FairRunSim *fRun = new FairRunSim();
21 
22  TStopwatch timer;
23  timer.Start();
24  gDebug=0;
25 
26  //Choose geometry
27  TString outFile="$SIMDATADIR/COSY/"; // If no SIMDATADIR, data in subdir COSY
28  TString GeoFile;
29 
30  //GeoFile = "hypGeGeoSingle.root";
31  outFile += "hypGeCOSYBeamTime2014_";
32  if (ParticlePDG < 0)
33  outFile += "ANTI";
34  outFile += "protons_mom";
35  outFile += ProtonMomentum;
36  outFile += "GeV_";
37 
38 
39  // Set the number of events
40 
41  outFile += nEvents;
42  outFile += "Evts";
43 
44  if (GausSmearedBeam)
45  outFile += "_GausianSmearedBeam";
46  if (!BremsStahlungActivated)
47  outFile += "_withoutBremsStahlung";
48 
49 
50  outFile +="_";
51  outFile += RunNo;
52  TString SimparamsFile;
53  SimparamsFile=outFile;
54  outFile +=".root";
55  SimparamsFile += "__Simparams.root";
56 
57  // set the MC version used
58  // ------------------------
59 
60  fRun->SetName("TGeant4");
61 
62  fRun->SetOutputFile(outFile);
63  // Set Material file Name
64  //-----------------------
65  cout << outFile << endl;
66  fRun->SetMaterials("media_pnd_hypGe.geo");//("moded_media_pnd_hypGe.geo");//("../macro/hypGe/Marcell/MiscFiles/moded_media_pnd_hypGe.geo");
67 
68  // Create and add detectors
69  //-------------------------
70 
71  FairModule *Cave= new PndCave("CAVE");
72  Cave->SetGeometryFileName("pndcave.geo");
73  fRun->AddModule(Cave);
74 
75 
76 
77  PndHypGe *HypGe= new PndHypGe("HYPGE",kTRUE); // Germaniums + SiPm + Piezo + everything else "active"
78  TString nam = gSystem->Getenv("VMCWORKDIR");
79  HypGe->SetPathGeo(nam.Data());
80  HypGe->SetGeometryFileName("hypGeGeoCOSY2014setupActives.root");
81  fRun->AddModule(HypGe);
82  cout << "active parts loaded" << endl;
83  // add passive parts
84  FairModule *Target = new PndHyp("Target",kFALSE);
85  //Target->SetPathGeo(nam.Data());
86 
87  Target->SetGeometryFileName("hypGeGeoCOSY2014setupPassives.root");
88  fRun->AddModule(Target);
89 
90 
91 
92  FairPrimaryGenerator* primGen = new FairPrimaryGenerator();
93  fRun->SetGenerator(primGen);
94 
95 
96  PndBoxGenerator* boxGen = new PndBoxGenerator(ParticlePDG, 1);
97  boxGen->SetPRange(ProtonMomentum,ProtonMomentum); // GeV/c
98 
99  boxGen->SetPhiRange(0., 360.); // Azimuth angle range [degree]
100  boxGen->SetThetaRange(0, 0.2); // Polar angle in lab system range [degree]
101  //boxGen->SetCosTheta(); // Set uniform ditribution in cos(theta)
102  boxGen->SetXYZ(0., 0., -50); // vertex coordinates [cm]
103 
104  if (GausSmearedBeam)
105  {
106  primGen->SetBeam(0, 0, 1, 1);
107  primGen->SmearVertexXY(1);
108  }
109  primGen->AddGenerator(boxGen);
110 
111 
112 
113 
114  fRun->SetStoreTraj(kTRUE); // to store particle trajectories
115 
116 
117 
118 
119  // seg error somewhere!!!!
120 
121  cout << "init now" << endl;
122  fRun->Init();
123 
124  // Fill the Parameter containers for this run
125  //-------------------------------------------
126 
127  FairRuntimeDb *rtdb=fRun->GetRuntimeDb();
128  Bool_t kParameterMerged=kTRUE;
129 
130 
131  FairParRootFileIo* output=new FairParRootFileIo(kParameterMerged);
132  output->open(SimparamsFile);
133  rtdb->setOutput(output);
134  rtdb->saveOutput();
135  rtdb->print();
136 
137 
138  // Transport nEvents
139  // -----------------
140  gRandom->SetSeed(); // sets a random seed, added 08.06.14
141  fRun->Run(nEvents);
142 
143  timer.Stop();
144 
145  Double_t rtime = timer.RealTime();
146  Double_t ctime = timer.CpuTime();
147  printf("RealTime=%f seconds, CpuTime=%f seconds\n",rtime,ctime);
148  cout << "Data written to file:\t" << outFile.Data() << endl;
149 
150  return 0;
151 }
152 
153 
printf("RealTime=%f seconds, CpuTime=%f seconds\n", rtime, ctime)
PndHypGe * HypGe
Definition: sim_hypGe.C:47
void SetThetaRange(Double32_t thetamin=0, Double32_t thetamax=90)
Definition: PndHyp.h:30
Bool_t kParameterMerged
Definition: sim_emc_apd.C:113
TString outFile
Definition: hit_dirc.C:17
void SetXYZ(Double32_t x=0, Double32_t y=0, Double32_t z=0)
TFile * Target
Definition: hadd.C:35
FairParRootFileIo * output
Definition: sim_emc_apd.C:120
FairPrimaryGenerator * primGen
Definition: sim_emc_apd.C:81
FairRunAna * fRun
Definition: hit_dirc.C:58
int sim_hypGe_COSY2014(Double_t ProtonMomentum=2.78, Int_t nEvents=100, Int_t PDG_ext=2212, Bool_t GausSmearedBeam=0, Bool_t BremsStahlungActivated=0, Double_t RunNo=0)
Double_t
FairModule * Cave
Definition: sim_emc_apd.C:32
Int_t nEvents
Definition: hit_dirc.C:11
TStopwatch timer
Definition: hit_dirc.C:51
FairRuntimeDb * rtdb
Definition: hit_dirc.C:66
gDebug
Definition: sim_emc_apd.C:6
Double_t ctime
Definition: hit_dirc.C:114
FairBoxGenerator * boxGen
Definition: sim_emc_apd.C:85
void SetPRange(Double32_t pmin=0, Double32_t pmax=10)
Double_t rtime
Definition: hit_dirc.C:113
TString nam
Definition: sim_hypGe.C:48
void SetPhiRange(Double32_t phimin=0, Double32_t phimax=360)
void SetPathGeo(TString pgeo)
Definition: PndHypGe.h:136
Definition: PndCave.h:8