Project
Loading...
Searching...
No Matches
o2_sim_tpc.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
13#include <Monitoring/Monitoring.h>
17
18#include "Framework/Logger.h"
19
20#include "FairRunSim.h"
21#include <FairRootFileSink.h>
22#include "FairRuntimeDb.h"
23#include "FairPrimaryGenerator.h"
24#include "FairBoxGenerator.h"
25#include "FairParRootFileIo.h"
26
28#include "Field/MagneticField.h"
29
34#include <vector>
35
36using namespace o2::framework;
37
38#define BOX_GENERATOR 1
39
40namespace o2
41{
42namespace workflows
43{
44
46{
47 return {
48 "sim_tpc",
49 Inputs{},
50 Outputs{OutputSpec{"TPC", "GEN"}},
52 [](InitContext& setup) {
53 int nEvents = setup.options().get<int>("nEvents");
54 auto mcEngine = setup.options().get<std::string>("mcEngine");
55
56 // FIXME: this should probably be part of some generic
57 // FairRunInitSpec
58 TString dir = getenv("VMCWORKDIR");
59 TString geom_dir = dir + "/Detectors/Geometry/";
60 gSystem->Setenv("GEOMPATH", geom_dir.Data());
61
62 TString tut_configdir = dir + "/Detectors/gconfig";
63 gSystem->Setenv("CONFIG_DIR", tut_configdir.Data());
64
65 // Requiring a file is something which requires IO, and it's therefore
66 // delegated to the framework
67 auto& rfm = setup.services().get<RootFileService>();
68 // FIXME: We should propably have a service for FairRunSim, rather than
69 // for the root files themselves...
70 // Output file name
71 auto outFile = rfm.format("AliceO2_%s.tpc.mc_%i_event.root", mcEngine.c_str(), nEvents);
72
73 // Parameter file name
74 auto parFile = rfm.format("AliceO2_%s.tpc.mc_%i_event.root", mcEngine.c_str(), nEvents);
75
76 // Create simulation run
77 FairRunSim* run = new FairRunSim();
78
79 run->SetName(mcEngine.c_str());
80 run->SetSink(new FairRootFileSink(outFile.c_str())); // Output file
81 FairRuntimeDb* rtdb = run->GetRuntimeDb();
82
83 // Create media
84 run->SetMaterials("media.geo"); // Materials
85
86 // Create geometry
87 o2::passive::Cave* cave = new o2::passive::Cave("CAVE");
88 cave->SetGeometryFileName("cave.geo");
89 run->AddModule(cave);
90
92 run->SetField(magField);
93
94 // ===| Add TPC |============================================================
95 o2::tpc::Detector* tpc = new o2::tpc::Detector(kTRUE);
96 tpc->SetGeoFileName("TPCGeometry.root");
97 run->AddModule(tpc);
98
99 // Create PrimaryGenerator
101#ifdef BOX_GENERATOR
102 FairBoxGenerator* boxGen = new FairBoxGenerator(211, 10); /*protons*/
103
104 //boxGen->SetThetaRange(0.0, 90.0);
105 boxGen->SetEtaRange(-0.9, 0.9);
106 boxGen->SetPRange(0.1, 5);
107 boxGen->SetPhiRange(0., 360.);
108 boxGen->SetDebug(kTRUE);
109
110 primGen->AddGenerator(boxGen);
111#else
112 // reading the events from a kinematics file (produced by AliRoot)
113 auto extGen = new o2::eventgen::GeneratorFromFile(params.get<std::string>("extKinFile"));
114 extGen->SetStartEvent(params.get<int>("startEvent"));
115 primGen->AddGenerator(extGen);
116#endif
117
118 run->SetGenerator(primGen);
119
120 // store track trajectories
121 // run->SetStoreTraj(kTRUE);
122
123 // Initialize simulation run
124 run->Init();
125
126 // Runtime database
127 Bool_t kParameterMerged = kTRUE;
128 FairParRootFileIo* parOut = new FairParRootFileIo(kParameterMerged);
129 parOut->open(parFile.c_str());
130 rtdb->setOutput(parOut);
131 rtdb->saveOutput();
132 rtdb->print();
133 run->Run(nEvents);
134
135 static bool once = true;
136
137 // This is the actual inner loop for the device
138 return [run, nEvents](ProcessingContext& ctx) {
139 if (!once) {
140 run->Run(nEvents);
141 once = true;
142 } else {
143 std::this_thread::sleep_for(std::chrono::seconds(1));
144 }
145 // FIXME: After we run we should readback events
146 // and push them as messages, for the next stage of
147 // processing.
148 };
149 }},
150 Options{
151 {"mcEngine", VariantType::String, "TGeant3", {"Engine to use"}},
152 {"nEvents", VariantType::Int, 10, {"Events to process"}},
153 {"extKinFile", VariantType::String, "Kinematics.root", {"name of kinematics file for event generator from file (when applicable)"}},
154 {"startEvent", VariantType::Int, 2, {"Events to skip"}}}};
155};
156} // namespace workflows
157} // namespace o2
Definition of the MagF class.
virtual std::string format(const char *fmt,...)=0
GLenum const GLfloat * params
Definition glcorearb.h:272
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > Inputs
std::vector< OutputSpec > Outputs
DataProcessorSpec sim_tpc()
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
const int nEvents
Definition test_Fifo.cxx:27