FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
runMQSim.cxx
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014-2019 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 
9 #include "FairBoxGenerator.h"
10 #include "FairCave.h"
11 #include "FairMQSimDevice.h"
12 #include "FairModule.h"
13 #include "FairOnlineSink.h"
14 #include "FairParAsciiFileIo.h"
15 #include "FairPrimaryGenerator.h"
16 #include "Pixel.h"
17 #include "PixelDigitize.h"
18 #include "runFairMQDevice.h"
19 
20 #include <Rtypes.h>
21 #include <TObjArray.h>
22 #include <TRandom.h>
23 #include <TString.h>
24 #include <TSystem.h>
25 #include <cstdint>
26 #include <cstdlib>
27 #include <stdexcept>
28 #include <string>
29 
30 namespace bpo = boost::program_options;
31 
32 void addCustomOptions(bpo::options_description& options)
33 {
34  // clang-format off
35  options.add_options()
36  ("random-seed", bpo::value<int64_t> ()->default_value(0), "Random seed number")
37  ("transport-name", bpo::value<std::string>()->default_value("TGeant3"), "Transport name")
38  ("nof-events", bpo::value<int64_t> ()->required(), "Number of events to simulate")
39  ("fairroot-config-dir", bpo::value<std::string>()->default_value(""), "FairRoot config dir")
40  ("param-channel-name", bpo::value<std::string>()->default_value("updateChannel"), "Parameter update channel name")
41  ("run-digi-tasks", bpo::value<bool> ()->default_value(false), "Run digi tasks")
42  // clang-format on
43  ;
44 }
45 
46 FairMQDevicePtr getDevice(const FairMQProgOptions& config)
47 {
48  gRandom->SetSeed(config.GetValue<int64_t>("random-seed"));
49 
50  char* cdir = getenv("VMCWORKDIR");
51 
52  if (cdir == nullptr) {
53  throw std::runtime_error("VMCWORKDIR not initialized");
54  }
55 
56  std::string dir = cdir;
57  std::string tutdir = dir + "/MQ/pixelDetector";
58 
59  std::string tutGeomDir = dir + "/common/geometry";
60  gSystem->Setenv("GEOMPATH", tutGeomDir.c_str());
61 
62  std::string tutConfigDir = config.GetValue<std::string>("fairroot-config-dir");
63  if (tutConfigDir.empty()) {
64  tutConfigDir = dir + "/common/gconfig";
65  }
66  gSystem->Setenv("CONFIG_DIR", tutConfigDir.c_str());
67 
68  FairMQSimDevice* run = new FairMQSimDevice();
69 
70  FairOnlineSink* sink = new FairOnlineSink();
71  sink->SetMQRunDevice(run);
72  run->SetSink(sink);
73 
74  run->SetParamUpdateChannelName(config.GetValue<std::string>("param-channel-name"));
75 
76  run->SetNofEvents(config.GetValue<int64_t>("nof-events"));
77  run->SetTransportName(config.GetValue<std::string>("transport-name"));
78  run->SetMaterials("media.geo");
79 
80  TObjArray* detArray = new TObjArray();
81  FairModule* cave = new FairCave("CAVE");
82  cave->SetGeometryFileName("cave_vacuum.geo");
83  detArray->Add(cave);
84  Pixel* det = new Pixel("PixelDetector", kTRUE);
85  det->SetGeometryFileName("pixel.geo");
86  detArray->Add(det);
87  run->SetDetectorArray(detArray);
88 
89  TString partName[] = {"pions", "eplus", "proton"};
90  Int_t partPdgC[] = {211, 11, 2212};
91  Int_t chosenPart = 0;
92 
94  FairBoxGenerator* boxGen = new FairBoxGenerator(partPdgC[chosenPart], 100);
95  boxGen->SetPRange(1, 2);
96  boxGen->SetThetaRange(0, 180);
97  boxGen->SetPhiRange(0, 360);
98  primGen->AddGenerator(boxGen);
99  run->SetGenerator(primGen);
100 
101  run->SetStoreTraj(false);
102 
103  if (config.GetValue<bool>("run-digi-tasks")) {
104  // Attach tasks if needed
105  TString digParFile = tutdir + "/param/pixel_digi.par";
106  FairParAsciiFileIo* parIo1 = new FairParAsciiFileIo();
107  parIo1->open(digParFile.Data(), "in");
108  run->SetFirstParameter(parIo1);
109 
110  TObjArray* taskArray = new TObjArray();
111  PixelDigitize* digiTask = new PixelDigitize();
112  taskArray->Add(digiTask);
113  run->SetTaskArray(taskArray);
114  }
115 
116  return run;
117 }
virtual void SetGeometryFileName(TString fname, TString geoVer="0")
Definition: FairModule.cxx:199
void SetFirstParameter(FairParIo *par)
Bool_t open(const Text_t *fname, const Text_t *status="in")
void addCustomOptions(bpo::options_description &options)
void SetNofEvents(int64_t nofev)
void SetPRange(Double32_t pmin=0, Double32_t pmax=10)
void AddGenerator(FairGenerator *generator)
void SetTransportName(const std::string &str)
void SetMaterials(const std::string &str)
virtual void SetParamUpdateChannelName(const TString &tString)
void SetSink(FairSink *sink)
Definition: Pixel.h:21
void SetTaskArray(TObjArray *array)
virtual void SetMQRunDevice(FairMQRunDevice *mrs)
void SetDetectorArray(TObjArray *array)
void SetGenerator(FairPrimaryGenerator *primGen)
void SetThetaRange(Double32_t thetamin=0, Double32_t thetamax=90)
FairMQDevicePtr getDevice(const FairMQProgOptions &config)
void SetStoreTraj(bool flag=true)
void SetPhiRange(Double32_t phimin=0, Double32_t phimax=360)