DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4Output2ROOT.h
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 #ifndef DDG4_GEANT4OUTPUT2ROOT_H
14 #define DDG4_GEANT4OUTPUT2ROOT_H
15 
16 // Framework include files
18 
19 class TFile;
20 class TTree;
21 class TBranch;
22 
24 namespace dd4hep {
25 
26  class ComponentCast;
27 
29  namespace sim {
30 
32 
38  protected:
39  typedef std::map<std::string, TBranch*> Branches;
40  typedef std::map<std::string, TTree*> Sections;
46  TFile* m_file;
48  TTree* m_tree;
50  int m_fseqNunmber { 0 };
52  std::string m_section;
54  std::vector<std::string> m_disabledCollections;
56  bool m_disableParticles = false;
61 
62  public:
64  Geant4Output2ROOT(Geant4Context* context, const std::string& nam);
66  virtual ~Geant4Output2ROOT();
68  TTree* section(const std::string& nam);
70  int fill(const std::string& nam, const ComponentCast& type, void* ptr);
71 
73  virtual void closeOutput();
75  virtual void beginRun(const G4Run* run) override;
77  virtual void saveCollection(OutputContext<G4Event>& ctxt, G4VHitsCollection* collection) override;
79  virtual void saveEvent(OutputContext<G4Event>& ctxt) override;
80 
82  virtual void commit(OutputContext<G4Event>& ctxt) override;
83  };
84 
85  } // End namespace sim
86 } // End namespace dd4hep
87 #endif // DDG4_GEANT4OUTPUT2ROOT_H
dd4hep::sim::Geant4Output2ROOT::saveEvent
virtual void saveEvent(OutputContext< G4Event > &ctxt) override
Callback to store the Geant4 event.
Definition: Geant4Output2ROOT.cpp:180
G4VHitsCollection
Class of the Geant4 toolkit. See http://www-geant4.kek.jp/Reference.
Definition: Geant4Classes.h:47
dd4hep::sim::Geant4OutputAction
Base class to output Geant4 event data to persistent media.
Definition: Geant4OutputAction.h:40
dd4hep::sim::Geant4Output2ROOT::m_handleMCTruth
bool m_handleMCTruth
Property: Flag if Monte-Carlo truth should be followed and checked.
Definition: Geant4Output2ROOT.h:58
dd4hep::sim::Geant4Output2ROOT::~Geant4Output2ROOT
virtual ~Geant4Output2ROOT()
Default destructor.
Definition: Geant4Output2ROOT.cpp:49
dd4hep::sim::Geant4Output2ROOT::commit
virtual void commit(OutputContext< G4Event > &ctxt) override
Commit data at end of filling procedure.
Definition: Geant4Output2ROOT.cpp:156
dd4hep::sim::Geant4OutputAction::OutputContext
Helper class for thread savety.
Definition: Geant4OutputAction.h:43
dd4hep::sim::Geant4Output2ROOT::Geant4Output2ROOT
Geant4Output2ROOT(Geant4Context *context, const std::string &nam)
Standard constructor.
Definition: Geant4Output2ROOT.cpp:38
Geant4OutputAction.h
dd4hep::sim::Geant4Output2ROOT::m_tree
TTree * m_tree
Reference to the event data tree.
Definition: Geant4Output2ROOT.h:48
dd4hep::sim::Geant4Output2ROOT::fill
int fill(const std::string &nam, const ComponentCast &type, void *ptr)
Fill single EVENT branch entry (Geant4 collection data)
Definition: Geant4Output2ROOT.cpp:118
dd4hep::sim::Geant4Output2ROOT::m_branches
Branches m_branches
Branches in the event tree.
Definition: Geant4Output2ROOT.h:44
dd4hep::sim::Geant4Output2ROOT::section
TTree * section(const std::string &nam)
Create/access tree by name for non collection user data.
Definition: Geant4Output2ROOT.cpp:71
dd4hep::sim::Geant4Output2ROOT::Sections
std::map< std::string, TTree * > Sections
Definition: Geant4Output2ROOT.h:40
dd4hep::sim::Geant4Output2ROOT
Class to output Geant4 event data to ROOT files.
Definition: Geant4Output2ROOT.h:37
dd4hep::sim::Geant4Output2ROOT::saveCollection
virtual void saveCollection(OutputContext< G4Event > &ctxt, G4VHitsCollection *collection) override
Callback to store each Geant4 hit collection.
Definition: Geant4Output2ROOT.cpp:203
dd4hep::sim::Geant4Output2ROOT::m_sections
Sections m_sections
Known file sections.
Definition: Geant4Output2ROOT.h:42
dd4hep::sim::Geant4Output2ROOT::m_disabledCollections
std::vector< std::string > m_disabledCollections
Property: vector with disabled collections.
Definition: Geant4Output2ROOT.h:54
dd4hep::sim::Geant4Output2ROOT::beginRun
virtual void beginRun(const G4Run *run) override
Callback to store the Geant4 run information.
Definition: Geant4Output2ROOT.cpp:83
dd4hep::sim::Geant4Output2ROOT::m_section
std::string m_section
Property: name of the event tree.
Definition: Geant4Output2ROOT.h:52
dd4hep::sim::Geant4Output2ROOT::m_disableParticles
bool m_disableParticles
Property: vector with disabled collections.
Definition: Geant4Output2ROOT.h:56
dd4hep::sim::Geant4Output2ROOT::m_filesByRun
bool m_filesByRun
Property: Flag if Monte-Carlo truth should be followed and checked.
Definition: Geant4Output2ROOT.h:60
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::sim::Geant4Output2ROOT::m_fseqNunmber
int m_fseqNunmber
File sequence number.
Definition: Geant4Output2ROOT.h:50
dd4hep::sim::Geant4Output2ROOT::closeOutput
virtual void closeOutput()
Close current output file.
Definition: Geant4Output2ROOT.cpp:55
dd4hep::sim::Geant4Output2ROOT::Branches
std::map< std::string, TBranch * > Branches
Definition: Geant4Output2ROOT.h:39
dd4hep::sim::Geant4Output2ROOT::m_file
TFile * m_file
Reference to the ROOT file to open.
Definition: Geant4Output2ROOT.h:46
dd4hep::sim::Geant4Context
Generic context to extend user, run and event information.
Definition: Geant4Context.h:201
dd4hep::sim::Geant4Action::context
Geant4Context * context() const
Access the context.
Definition: Geant4Action.h:270