Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:55:23

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : M.Frank
0011 //
0012 //==========================================================================
0013 #ifndef DDG4_GEANT4OUTPUT2ROOT_H
0014 #define DDG4_GEANT4OUTPUT2ROOT_H
0015 
0016 // Framework include files
0017 #include <DDG4/Geant4OutputAction.h>
0018 
0019 class TFile;
0020 class TTree;
0021 class TBranch;
0022 
0023 /// Namespace for the AIDA detector description toolkit
0024 namespace dd4hep {
0025 
0026   class ComponentCast;
0027 
0028   /// Namespace for the Geant4 based simulation part of the AIDA detector description toolkit
0029   namespace sim {
0030 
0031     /// Class to output Geant4 event data to ROOT files
0032     /**
0033      *  \author  M.Frank
0034      *  \version 1.0
0035      *  \ingroup DD4HEP_SIMULATION
0036      */
0037     class Geant4Output2ROOT: public Geant4OutputAction {
0038     protected:
0039       typedef std::map<std::string, TBranch*> Branches;
0040       typedef std::map<std::string, TTree*> Sections;
0041       /// Known file sections
0042       Sections m_sections;
0043       /// Branches in the event tree
0044       Branches m_branches;
0045       /// Reference to the ROOT file to open
0046       TFile* m_file;
0047       /// Reference to the event data tree
0048       TTree* m_tree;
0049       /// File sequence number
0050       int    m_fseqNunmber  { 0 };
0051       /// Property: name of the event tree
0052       std::string m_section;
0053       /// Property: vector with disabled collections
0054       std::vector<std::string> m_disabledCollections;
0055       /// Property: vector with disabled collections
0056       bool  m_disableParticles = false;
0057       /// Property: Flag if Monte-Carlo truth should be followed and checked
0058       bool m_handleMCTruth;
0059       /// Property: Flag if Monte-Carlo truth should be followed and checked
0060       bool m_filesByRun;
0061       
0062     public:
0063       /// Standard constructor
0064       Geant4Output2ROOT(Geant4Context* context, const std::string& nam);
0065       /// Default destructor
0066       virtual ~Geant4Output2ROOT();
0067       /// Create/access tree by name for non collection user data
0068       TTree* section(const std::string& nam);
0069       /// Fill single EVENT branch entry (Geant4 collection data)
0070       int fill(const std::string& nam, const ComponentCast& type, void* ptr);
0071 
0072       /// Close current output file
0073       virtual void closeOutput();
0074       /// Callback to store the Geant4 run information
0075       virtual void beginRun(const G4Run* run);
0076       /// Callback to store each Geant4 hit collection
0077       virtual void saveCollection(OutputContext<G4Event>& ctxt, G4VHitsCollection* collection);
0078       /// Callback to store the Geant4 event
0079       virtual void saveEvent(OutputContext<G4Event>& ctxt);
0080 
0081       /// Commit data at end of filling procedure
0082       virtual void commit(OutputContext<G4Event>& ctxt);
0083     };
0084 
0085   }    // End namespace sim
0086 }      // End namespace dd4hep
0087 #endif // DDG4_GEANT4OUTPUT2ROOT_H