Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:17:40

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 // $Id: EvtGenExtDecayerPhysics.cc, 2022/08/09 23:49:39 mccumber Exp $
0027 //
0028 /// \file derived from eventgenerator/pythia/decayer6/src/P6DExtDecayerPhysics.cc
0029 /// \brief Implementation of the EvtGenExtDecayerPhysics class
0030 ///
0031 /// \author Zhaozhong Shi; LANL, Los Alamos
0032 
0033 #include "EvtGenExtDecayerPhysics.hh"
0034 
0035 #include <Geant4/G4Decay.hh>
0036 #include <Geant4/G4ParticleDefinition.hh>
0037 #include <Geant4/G4ParticleTable.hh>  // for G4ParticleTable::G4PTblDi...
0038 #include <Geant4/G4ProcessManager.hh>
0039 #include <Geant4/G4ProcessVector.hh>  // for G4ProcessVector
0040 #include <Geant4/G4String.hh>         // for G4String
0041 #include <Geant4/G4VPhysicsConstructor.hh>
0042 #include <Geant4/G4VProcess.hh>  // for G4VProcess
0043 #include <Geant4/G4Version.hh>
0044 
0045 #include <boost/io/ios_state.hpp>
0046 
0047 #include <cstddef>  // for size_t
0048 #include <fstream>
0049 #include <iostream>  // for operator<<, endl, basic_o...
0050 #include <string>    // for operator<<
0051 
0052 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0053 // hack for Geant 10.03.p03
0054 // Geant 10.02.p02 has this defined
0055 #ifndef aParticleIterator
0056 #define aParticleIterator ((subInstanceManager.offset[g4vpcInstanceID])._aParticleIterator)
0057 #endif
0058 
0059 EvtGenExtDecayerPhysics::EvtGenExtDecayerPhysics(const G4String& name)
0060   : G4VPhysicsConstructor(name)
0061 {
0062   /// Standard constructor
0063 }
0064 
0065 //
0066 // protected methods
0067 //
0068 
0069 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0070 
0071 void EvtGenExtDecayerPhysics::ConstructProcess()
0072 {
0073   // EvtGen model initialization changed the behavior of std::cout float print. Recover the default float print format
0074   boost::io::ios_all_saver ias_cout(std::cout);
0075   boost::io::ios_all_saver ias_cerr(std::cerr);
0076 
0077   /// Loop over all particles instantiated and add external decayer
0078   /// to all decay processes if External decayer is set
0079 
0080   // Create Geant4 external decayer
0081   extDecayer = new G4EvtGenDecayer();
0082   extDecayer->SetVerboseLevel(0);
0083 
0084   if (!DecayFile.empty())
0085   {
0086     std::ifstream f_local(DecayFile);
0087 
0088     if (f_local.good())
0089     {
0090       extDecayer->SetDecayTable(DecayFile, false);
0091     }
0092     else
0093     {
0094       const char* CALIBRATIONROOT = getenv("CALIBRATIONROOT");
0095       if (!CALIBRATIONROOT)
0096       {
0097         exit(1);
0098       }
0099       std::string DecayFileCalibrationRepo = std::string(CALIBRATIONROOT) + "/EvtGen/" + DecayFile;
0100 
0101       std::ifstream f_calib(DecayFileCalibrationRepo);
0102 
0103       if (f_calib.good())
0104       {
0105         extDecayer->SetDecayTable(DecayFileCalibrationRepo, false);
0106       }
0107       else
0108       {
0109         std::cout << __PRETTY_FUNCTION__ << " : Fatal error. Decay file can not be found at "
0110                   << DecayFile << " nor at " << DecayFileCalibrationRepo << std::endl;
0111 
0112         exit(1);
0113       }
0114     }
0115   }
0116 
0117   aParticleIterator->reset();
0118   int decayer_used = 0;
0119   while ((*aParticleIterator)())
0120   {
0121     G4ParticleDefinition* particle = aParticleIterator->value();
0122     G4ProcessManager* pmanager = particle->GetProcessManager();
0123 
0124     if (verboseLevel > 1)
0125     {
0126       std::cout << "Setting ext decayer for: "
0127                 << aParticleIterator->value()->GetParticleName()
0128                 << std::endl;
0129     }
0130 
0131     G4ProcessVector* processVector = pmanager->GetProcessList();
0132 #if G4VERSION_NUMBER >= 1060
0133     for (size_t i = 0; i < processVector->length(); i++)
0134 #else
0135     for (G4int i = 0; i < processVector->length(); i++)
0136 #endif
0137     {
0138       G4Decay* decay = dynamic_cast<G4Decay*>((*processVector)[i]);
0139       if (decay)
0140       {
0141         // The extDecayer will be deleted in G4Decay destructor
0142         // increment counter in case we want to print out stats
0143         // for whatever reason (non null means it is used and
0144         // must not be deleted)
0145         //       particle->SetDecayTable(NULL);
0146         decay->SetExtDecayer(extDecayer);
0147         decayer_used++;
0148       }
0149     }
0150   }
0151 
0152   // If the extDecayer isn't used for this particle we need to delete it here
0153   // as far as I see this never happens but this makes coverity happy
0154   if (!decayer_used)
0155   {
0156     delete extDecayer;
0157   }
0158 
0159   if (verboseLevel > 0)
0160   {
0161     std::cout << "External decayer physics constructed." << std::endl;
0162   }
0163 }
0164 
0165 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......