Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-08 07:53:58

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 /// \file Par02Output.hh
0027 /// \brief Definition of the Par02Output class
0028 
0029 #ifndef PAR02_OUTPUT_H
0030 #define PAR02_OUTPUT_H
0031 
0032 #include "G4ThreeVector.hh"
0033 #include "globals.hh"
0034 
0035 /// Handling the saving to the file.
0036 ///
0037 /// A singleton class that manages creation, writing to and closing of the
0038 /// Root output file.
0039 /// @author Anna Zaborowska
0040 
0041 class Par02Output
0042 {
0043   public:
0044     /// Indicates to which ntuple to save the information.
0045     enum SaveType
0046     {
0047       eNoSave,
0048       eSaveMC,
0049       eSaveTracker,
0050       eSaveEMCal,
0051       eSaveHCal
0052     };
0053 
0054     /// Allows the access to the unique Par02Output object.
0055     /// @return A pointer to the Par02Output class.
0056     static Par02Output* Instance();
0057 
0058     /// Sets the file name of the output root file.
0059     /// @param name The name of the file.
0060     void SetFileName(G4String name);
0061 
0062     /// Gets the file name of the output root file.
0063     /// @return The name of the file.
0064     G4String GetFileName();
0065 
0066     /// Sets fFileNameWithRunNo that indicates whether to add the run number
0067     /// to the file name.
0068     /// @param app If add the run number.
0069     void AppendName(G4bool app);
0070 
0071     /// Calls the G4AnalysisManager::Instance(). It sets the file name of the
0072     /// output file based on fFileName and fFileNameWithRunNo and opens the file.
0073     /// @param runID A run number (to be added to file name if fFileNameWithRunNo
0074     ///              is true).
0075     void StartAnalysis(G4int runID);
0076 
0077     /// Calls the G4AnalysisManager::Instance().
0078     /// It writes to the output file and close it.
0079     void EndAnalysis();
0080 
0081     /// Creates Ntuples used to store information about particle (its ID, PDG code,
0082     /// energy deposits, etc.). To be called for each event in Par02EventAction.
0083     void CreateNtuples();
0084 
0085     /// Creates histograms to combine information from all the events in the run.
0086     /// To be called for each run in Par02RunAction.
0087     void CreateHistograms();
0088 
0089     /// Saves the information about the particle (track).
0090     /// @param aWhatToSave enum indicating what kind of information to store
0091     ///                    (in which ntuple).
0092     /// @param aPartID A unique ID within event (taken Geant TrackID).
0093     /// @param aPDG A PDG code of a particle.
0094     /// @param aVector A vector to be stored (particle momentum in tracker or
0095     ///                position of energy deposit in calorimeter).
0096     /// @param aResolution A resolution of the detector that was used.
0097     /// @param aEfficiency An efficiency of the detector that was used.
0098     /// @param aEnergy An energy deposit (for calorimeters only:
0099     ///                Par02Output::SaveType::eEMCal or Par02Output::SaveType::eHCal).
0100     void SaveTrack(SaveType aWhatToSave, G4int aPartID, G4int aPDG, G4ThreeVector aVector,
0101                    G4double aResolution = 0, G4double aEfficiency = 1, G4double aEnergy = 0);
0102 
0103     /// Fills the histogram.
0104     /// @param HNo Number of a histogram (decided by the order of creation
0105     ///            in CreateHistograms(), the first one is 0).
0106     /// @param value A value to be filled into the histogram.
0107     void FillHistogram(G4int HNo, G4double value) const;
0108 
0109     ~Par02Output();
0110 
0111   protected:
0112     /// A default, protected constructor (due to singleton pattern).
0113     Par02Output();
0114 
0115   private:
0116     /// The pointer to the only Par02Output class object.
0117     static Par02Output* fPar02Output;
0118 
0119     /// Current ntuple Id
0120     static G4ThreadLocal G4int fCurrentNtupleId;
0121 
0122     /// A name of the output root file.
0123     G4String fFileName;
0124 
0125     /// If true, a run number should be added to the file. Default: false.
0126     G4bool fFileNameWithRunNo;
0127 
0128     /// A control value of particle ID to ensure that data saved to various ntuples
0129     /// match the same particle. It is set when Monte Carlo information is saved
0130     /// and checked for all the detectors.
0131     static G4ThreadLocal G4int fCurrentID;
0132 };
0133 
0134 #endif