EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GeantinoRecording.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file GeantinoRecording.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017-2020 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
10 
12 
13 #include <iostream>
14 #include <stdexcept>
15 
16 #include <FTFP_BERT.hh>
17 #include <G4RunManager.hh>
18 #include <G4VUserDetectorConstruction.hh>
19 
20 #include "EventAction.hpp"
21 #include "RunAction.hpp"
22 #include "SteppingAction.hpp"
23 
24 using namespace ActsExamples;
25 
28  : BareAlgorithm("GeantinoRecording", lvl),
29  m_cfg(std::move(cfg)),
30  m_runManager(std::make_unique<G4RunManager>()) {
31  if (m_cfg.outputMaterialTracks.empty()) {
32  throw std::invalid_argument("Missing output material tracks collection");
33  }
34  if (not m_cfg.detectorConstruction) {
35  throw std::invalid_argument("Missing detector construction object");
36  }
37 
38  m_cfg.generationConfig.particleName = "geantino";
40 
41  m_runManager->SetUserInitialization(m_cfg.detectorConstruction.release());
42  m_runManager->SetUserInitialization(new FTFP_BERT);
43  m_runManager->SetUserAction(new RunAction());
44  m_runManager->SetUserAction(new EventAction());
45  m_runManager->SetUserAction(
47  m_runManager->SetUserAction(new SteppingAction());
48  m_runManager->Initialize();
49 }
50 
51 // needed to allow std::unique_ptr<G4RunManager> with forward-declared class.
53 
55  const ActsExamples::AlgorithmContext& ctx) const {
56  // ensure exclusive access to the geant run manager
57  std::lock_guard<std::mutex> guard(m_runManagerLock);
58 
59  // TODO use framework random numbers directly or at least context seed
60  // TODO take particles collection as input instead of generating them
61 
62  // start simulation. each track is simulated as a separate Geant4 event.
64 
65  auto materialTracks = EventAction::instance()->materialTracks();
66  // Write the recorded material to the event store
67  ctx.eventStore.add(m_cfg.outputMaterialTracks, move(materialTracks));
68 
70 }