er  dev
ERRunSim.cxx
1 #include "ERRunSim.h"
2 
3 #include "FairBaseParSet.h" // for FairBaseParSet
4 #include "FairGeoParSet.h" // for FairGeoParSet
5 #include "FairField.h" // for FairField
6 #include "FairFileHeader.h" // for FairFileHeader
7 #include "FairGeoInterface.h" // for FairGeoInterface
8 #include "FairGeoLoader.h" // for FairGeoLoader
9 #include <iostream> // for FairLogger, MESSAGE_ORIGIN
10 #include "FairMCEventHeader.h" // for FairMCEventHeader
11 #include "FairMesh.h" // for FairMesh
12 #include "FairModule.h" // for FairModule
13 #include "FairParSet.h" // for FairParSet
14 #include "FairPrimaryGenerator.h" // for FairPrimaryGenerator
15 #include "FairRootManager.h" // for FairRootManager
16 #include "FairRunIdGenerator.h" // for FairRunIdGenerator
17 #include "FairRuntimeDb.h" // for FairRuntimeDb
18 #include "FairTask.h" // for FairTask
19 #include "FairTrajFilter.h" // for FairTrajFilter
20 
21 #include <iosfwd> // for ostream
22 #include "TCollection.h" // for TIter
23 #include "TGeoManager.h" // for gGeoManager
24 #include "TList.h" // for TList
25 #include "TObjString.h" // for TObjString
26 #include "TObject.h" // for TObject
27 #include "TROOT.h" // for TROOT, gROOT
28 #include "TSystem.h" // for TSystem, gSystem
29 
30 #include <stdlib.h> // for getenv, NULL
31 #include <string.h> // for strcmp, strncmp
32 #include <iostream> // for cout, endl, ostream
33 
34 using std::cout;
35 using std::endl;
36 
38 ERRunSim::ERRunSim(Bool_t isMaster):
39 fDecayer(NULL)
40 {
41 
42 }
45 
46 }
53  //CheckFlukaExec();
54 
55 // fOutFile=fRootManager->OpenOutFile(fOutname);
56  std::cout << "============== FairRunSim: Initialising simulation run ==============" << std::endl;
57 
58  FairGeoLoader* loader=new FairGeoLoader(fLoaderName->Data(), "Geo Loader");
59  FairGeoInterface* GeoInterFace=loader->getGeoInterface();
60  GeoInterFace->SetNoOfSets(ListOfModules->GetEntries());
61  GeoInterFace->setMediaFile(MatFname.Data());
62  GeoInterFace->readMedia();
63 
64  // gSystem->cd(flout.Data());
65 
66  fApp= new ERMCApplication("Fair","The Fair VMC App",ListOfModules, MatFname);
67  fApp->SetGenerator(fGen);
68 
69  // Add a Generated run ID to the FairRunTimeDb
70  FairRunIdGenerator genid;
71  // FairRuntimeDb *rtdb= GetRuntimeDb();
72  fRunId = genid.generateId();
73  fRtdb->addRun(fRunId);
74 
75  fFileHeader->SetRunId(fRunId);
77  fApp->AddTask(fTask);
78 
79  FairBaseParSet* par=dynamic_cast<FairBaseParSet*>(fRtdb->getContainer("FairBaseParSet"));
80  if (par) {
81  par->SetDetList(GetListOfModules());
82  par->SetGen(GetPrimaryGenerator());
83  par->SetBeamMom(fBeamMom);
84  }
85 
86  FairGeoParSet* geopar=dynamic_cast<FairGeoParSet*>(fRtdb->getContainer("FairGeoParSet"));
87  if (geopar) {
88  geopar->SetGeometry(gGeoManager);
89  }
90 
91  // Set global Parameter Info
92 
93  if(fPythiaDecayer) {
94  fApp->SetPythiaDecayer(fPythiaDecayer);
95  if (fPythiaDecayerConfig) {
96  fApp->SetPythiaDecayerConfig(fPythiaDecayerConfig);
97  }
98  }
99  if(fUserDecay) {
100  fApp->SetUserDecay(fUserDecay);
101  if (fUserDecayConfig) {
102  fApp->SetUserDecayConfig(fUserDecayConfig);
103  }
104  }
105  // on/off visualisation
106  if( fStoreTraj ) {
107  std::cout << "Create visualisation manager " << std::endl;
108  new FairTrajFilter();
109  }
110  if(fRadLength) {
111  fApp->SetRadiationLengthReg(fRadLength);
112  }
113  if(fRadMap) {
114  fApp->SetRadiationMapReg(fRadMap);
115  }
116  if(fRadGrid) {
117  fApp->AddMeshList(fMeshList);
118  }
119 
120  fApp->SetField(fField);
121  SetFieldContainer();
122 
123  TList* containerList=fRtdb->getListOfContainers();
124  TIter next(containerList);
125  FairParSet* cont;
126  TObjArray* ContList= new TObjArray();
127  while ((cont=dynamic_cast<FairParSet*>(next()))) {
128  ContList->Add(new TObjString(cont->GetName()));
129  }
130 
131  par->SetContListStr(ContList);
132  par->setChanged();
133  par->setInputVersion(fRunId,1);
134 
135  geopar->setChanged();
136  geopar->setInputVersion(fRunId,1);
137 
139  SetMCConfig();
140  fRootManager->WriteFileHeader(fFileHeader);
141 
142  if (fDecayer){
143  ((ERMCApplication*)fApp)->SetDecayer(fDecayer);
144  if (!fDecayer->Init())
145  Fatal("ERRunSim::Init", "Decayer init problem");
146  }
147  if(fField) {
148  fField->Init();
149  }
150 }
151 
153 {
156  TString work = getenv("VMCWORKDIR");
157  TString work_config=work+"/gconfig/";
158  work_config.ReplaceAll("//","/");
159 
160  TString Lib_config= getenv("GEANT4VMC_MACRO_DIR");
161  Lib_config.ReplaceAll("//","/");
162  if (!Lib_config.EndsWith("/")) { Lib_config+="/"; }
163 
164  TString config_dir= getenv("CONFIG_DIR");
165  config_dir.ReplaceAll("//","/");
166 
167  Bool_t AbsPath=kFALSE;
168 
169  TString LibMacro;
170  TString LibFunction;
171  TString ConfigMacro;
172  TString cuts=fUserCuts;
173  //----------------------------------------------Geant4 Config-----------------------------------------
174  if(strcmp(GetName(),"TGeant4") == 0 ) {
175  TString g4LibMacro="g4libs.C";
176  TString g4Macro;
177  if(fUserConfig.IsNull()) {
178  g4Macro="g4Config.C";
179  fUserConfig = g4Macro;
180  } else {
181  if (fUserConfig.Contains("/")) { AbsPath=kTRUE; }
182  g4Macro = fUserConfig;
183  std::cout << "---------------User config is used: "
184  << g4Macro.Data() << std::endl;
185  }
186  if (TString(gSystem->FindFile(config_dir.Data(),g4LibMacro)) != TString("")) { //be carfull after this call the string g4LibMacro is empty if not found!!!!
187  std::cout << "---User path for Configuration (g4libs.C) is used: "
188  << config_dir.Data() << std::endl;
189  } else {
190  g4LibMacro=Lib_config+"g4libs.C";
191  }
192  LibMacro=g4LibMacro;
193  LibFunction="g4libs()";
194  if (!AbsPath && TString(gSystem->FindFile(config_dir.Data(),g4Macro)) != TString("")) {
195  std::cout << "---User path for Configuration (g4Config.C) is used: "
196  << config_dir.Data() << std::endl;
197  ConfigMacro=g4Macro;
198  } else {
199  if(AbsPath) { ConfigMacro = fUserConfig; }
200  else { ConfigMacro =work_config+fUserConfig; }
201  }
202  //----------------------------------------------Geant3 Config-----------------------------------------
203  } else if(strcmp(GetName(),"TGeant3") == 0 ) {
204  TString g3LibMacro="g3libs.C";
205  TString g3Macro="g3Config.C";
206  if(fUserConfig.IsNull()) {
207  g3Macro="g3Config.C";
208  fUserConfig = g3Macro;
209  std::cout << "-------------- Standard Config is called ------------------------------------" << std::endl;
210  } else {
211  if (fUserConfig.Contains("/")) { AbsPath=kTRUE; }
212  g3Macro = fUserConfig;
213  std::cout << "---------------User config is used: "
214  << g3Macro.Data() << std::endl;
215  }
216  if (TString(gSystem->FindFile(config_dir.Data(),g3LibMacro)) != TString("")) {
217  std::cout << "---User path for Configuration (g3libs.C) is used: "
218  << config_dir.Data() << std::endl;
219  } else {
220  g3LibMacro=work_config+"g3libs.C";
221  }
222  LibMacro=g3LibMacro;
223  LibFunction="g3libs()";
224  if (!AbsPath && TString(gSystem->FindFile(config_dir.Data(),g3Macro)) != TString("")) {
225  std::cout << "---User path for Configuration (g3Config.C) is used: "
226  << config_dir.Data() << std::endl;
227  ConfigMacro=g3Macro;
228  } else {
229  if(AbsPath) { ConfigMacro = fUserConfig; }
230  else { ConfigMacro =work_config+fUserConfig; }
231  }
232  //----------------------------------------------Fluka Config-----------------------------------------
233  } else if(strcmp(GetName(),"TFluka") == 0 ) {
234  TString flLibMacro="fllibs.C";
235  TString flMacro="flConfig.C";
236  if(fUserConfig.IsNull()) {
237  flMacro="flConfig.C";
238  fUserConfig=flMacro;
239  } else {
240  if (fUserConfig.Contains("/")) { AbsPath=kTRUE; }
241  flMacro = fUserConfig;
242  std::cout << "---------------User config is used: "
243  << flMacro.Data() << std::endl;
244  }
245  if (TString(gSystem->FindFile(config_dir.Data(), flLibMacro)) != TString("")) {
246  std::cout << "---User path for Configuration (fllibs.C) is used: "
247  << config_dir.Data() << std::endl;
248  } else {
249  flLibMacro=work_config+"fllibs.C";
250  }
251  LibMacro=flLibMacro;
252  LibFunction="fllibs()";
253  if (!AbsPath && TString(gSystem->FindFile(config_dir.Data(),flMacro)) != TString("")) {
254  std::cout << "---User path for Configuration (flConfig.C) is used: "
255  << config_dir.Data() << std::endl;
256  ConfigMacro=flMacro;
257  } else {
258  if(AbsPath) { ConfigMacro = fUserConfig; }
259  else { ConfigMacro =work_config+fUserConfig; }
260  }
261  }
262  //----------------------------------------------SetCuts------------------------------------------------
263  if (TString(gSystem->FindFile(config_dir.Data(),cuts)) != TString("")) {
264  std::cout << "---User path for Cuts and Processes (SetCuts.C) is used: "
265  << config_dir.Data() << std::endl;
266  } else {
267  cuts =work_config+ fUserCuts;
268  }
269  //--------------------------------------Now load the Config and Cuts------------------------------------
270  gROOT->LoadMacro(LibMacro.Data());
271  gROOT->ProcessLine(LibFunction.Data());
272 
273  gROOT->LoadMacro(ConfigMacro.Data());
274  gROOT->ProcessLine("Config()");
275 
276  gROOT->LoadMacro(cuts);
277  gROOT->ProcessLine("SetCuts()");
278 
279  ((ERMCApplication*)fApp)->InitMC(ConfigMacro.Data(), cuts.Data());
280 }
virtual void Init()
Definition: ERRunSim.cxx:50
ERRunSim(Bool_t isMaster=kTRUE)
Definition: ERRunSim.cxx:38
void SetMCConfig()
Definition: ERRunSim.cxx:152
virtual ~ERRunSim()
Definition: ERRunSim.cxx:44