Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 09:21:47

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 //
0027 
0028 // ********************************************************************
0029 //
0030 //  CaTS (Calorimetry and Tracking Simulation)
0031 //
0032 //  Authors : Hans Wenzel
0033 //            Soon Yung Jun
0034 //            (Fermi National Accelerator Laboratory)
0035 //
0036 // History
0037 //   October 18th, 2021 : first implementation
0038 //
0039 // ********************************************************************
0040 //
0041 /// \file PrimaryGeneratorAction.hh
0042 /// \brief Definition of the CaTS::PrimaryGeneratorAction class
0043 
0044 #pragma once
0045 
0046 #include "G4VUserPrimaryGeneratorAction.hh"
0047 #include <G4String.hh>
0048 #include <G4ios.hh>
0049 #include <map>
0050 #include <utility>
0051 class G4GenericMessenger;
0052 class G4VPrimaryGenerator;
0053 class G4Event;
0054 
0055 class PrimaryGeneratorAction : public G4VUserPrimaryGeneratorAction
0056 {
0057  public:
0058   PrimaryGeneratorAction();
0059   virtual ~PrimaryGeneratorAction();
0060   void GeneratePrimaries(G4Event*) final;
0061   inline void SetGenerator(G4String genname)
0062   {
0063     std::map<G4String, G4VPrimaryGenerator*>::iterator pos =
0064       gentypeMap.find(genname);
0065     if(pos != gentypeMap.end())
0066     {
0067       fcurrentGenerator     = pos->second;
0068       fcurrentGeneratorName = genname;
0069     }
0070     else
0071     {
0072       G4cout << "Primary  Generator: " << genname << " is not a valid Option"
0073              << G4endl;
0074       G4cout << "Valid Options are: ";
0075 #if(G4VERSION_NUMBER > 1072)
0076       for(auto [genType, generator] : gentypeMap)
0077       {
0078         G4cout << genType << " ";
0079       }
0080       G4cout << G4endl;
0081 #else
0082       for(std::map<G4String, G4VPrimaryGenerator*>::iterator ii =
0083             gentypeMap.begin();
0084           ii != gentypeMap.end(); ++ii)
0085       {
0086         G4cout << (*ii).first << " ";
0087       }
0088       G4cout << G4endl;
0089 #endif
0090     }
0091   }
0092   inline G4VPrimaryGenerator* GetGenerator() const { return fcurrentGenerator; }
0093   inline G4String GetGeneratorName() const { return fcurrentGeneratorName; }
0094   inline void Print()
0095   {
0096     G4cout << "===================================================" << G4endl;
0097     G4cout << " Primary  Generator: " << fcurrentGeneratorName << G4endl;
0098     G4cout << "===================================================" << G4endl;
0099   }
0100 
0101  private:
0102   /// Define UI commands: choice of primary generators
0103   void DefineCommands();
0104   G4VPrimaryGenerator* fcurrentGenerator = nullptr;
0105   G4String fcurrentGeneratorName{ "particleGun" };
0106   PrimaryGeneratorAction& operator=(const PrimaryGeneratorAction& right);
0107   PrimaryGeneratorAction(const PrimaryGeneratorAction&);
0108   std::map<G4String, G4VPrimaryGenerator*> gentypeMap;
0109   /// Pointer to the messenger for UI commands
0110   G4GenericMessenger* fMessenger = nullptr;
0111 };