Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-07 10:20:32

0001 //------------------------------- -*- C++ -*- -------------------------------//
0002 // Copyright Celeritas contributors: see top-level COPYRIGHT file for details
0003 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0004 //---------------------------------------------------------------------------//
0005 //! \file larceler/GeoSimExporter.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <TTree.h>
0010 #include <art/Framework/Core/EDAnalyzer.h>
0011 #include <canvas/Utilities/InputTag.h>
0012 #include <fhiclcpp/types/Atom.h>
0013 #include <fhiclcpp/types/Sequence.h>
0014 
0015 #include "SimEnergyDepositData.hh"
0016 
0017 namespace celeritas
0018 {
0019 //---------------------------------------------------------------------------//
0020 /*!
0021  * Analyzer module that exports detector geometry information and, \em
0022  * optionally , \c sim::SimEnergyDeposit data to basic ROOT types for use in
0023  * - Celeritas unit tests (e.g. LarStandaloneRunner); or
0024  * - Non-LarSoft applications (e.g. a Geant4 offloading app).
0025  *
0026  * The simplified TTree does not require dictionaries. Each TTree entry is one
0027  * event. Each TBranch is a vector of \c sim::SimEnergyDeposit data, and thus
0028  * each TBranch entry is associated to a \c sim::SimEnergyDeposit object.
0029  *
0030  * Usage:
0031  * Export detector geometry data only:
0032  * $ lar -c job.fcl
0033  * Export detector geometry \em and simulation data:
0034  * $ lar -c job.fcl -s [geant4-output.root]
0035  *
0036  * To store only a subset of events, use the optional `-n [num_events]` flag.
0037  */
0038 class GeoSimExporter : public art::EDAnalyzer
0039 {
0040   public:
0041     struct Config
0042     {
0043         fhicl::Atom<art::InputTag> SimulationLabel{
0044             fhicl::Name("SimulationLabel"),
0045             fhicl::Comment(R"(SimEnergyDeposit event tag)")};
0046 
0047         fhicl::Atom<int> MaxEdepsPerEvent{
0048             fhicl::Name{"MaxEdepsPerEvent"},
0049             fhicl::Comment{R"(Maximum to write per event)"},
0050             0};
0051     };
0052     using Parameters = art::EDAnalyzer::Table<Config>;
0053 
0054   public:
0055     // Construct with input parameters and export geometry data
0056     explicit GeoSimExporter(Parameters const& p);
0057 
0058     //!@{
0059     // Prevent copy and assignment operations
0060     GeoSimExporter(GeoSimExporter const&) = delete;
0061     GeoSimExporter(GeoSimExporter&&) = delete;
0062     GeoSimExporter& operator=(GeoSimExporter const&) = delete;
0063     GeoSimExporter& operator=(GeoSimExporter&&) = delete;
0064     //!@}
0065 
0066     // Create tree with sim energy deposit data
0067     void beginJob() override;
0068 
0069     // Export simulation data from input file
0070     void analyze(art::Event const& event) override;
0071 
0072   private:
0073     // Fcl input data
0074     art::InputTag sim_tag_;
0075     int max_edeps_{};
0076 
0077     TTree* sim_tree_;  // TTree with sim::SimEnergyDeposit data
0078     SimEnergyDepositData sim_edep_data_;  // TBranch reference data
0079 
0080     // Clear SimEnergyDepositData vectors
0081     void clear();
0082 };
0083 
0084 //---------------------------------------------------------------------------//
0085 }  // namespace celeritas