Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EvtGenExtDecayerPhysics.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EvtGenExtDecayerPhysics.cc
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 // $Id: EvtGenExtDecayerPhysics.cc, 2022/08/09 23:49:39 mccumber Exp $
27 //
32 
34 
35 #include <Geant4/G4Decay.hh>
36 #include <Geant4/G4ParticleDefinition.hh>
37 #include <Geant4/G4ParticleTable.hh> // for G4ParticleTable::G4PTblDi...
38 #include <Geant4/G4ProcessManager.hh>
39 #include <Geant4/G4ProcessVector.hh> // for G4ProcessVector
40 #include <Geant4/G4String.hh> // for G4String
41 #include <Geant4/G4VPhysicsConstructor.hh>
42 #include <Geant4/G4VProcess.hh> // for G4VProcess
43 #include <Geant4/G4Version.hh>
44 
45 #include <boost/io/ios_state.hpp>
46 
47 #include <cstddef> // for size_t
48 #include <fstream>
49 #include <iostream> // for operator<<, endl, basic_o...
50 #include <string> // for operator<<
51 
52 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
53 // hack for Geant 10.03.p03
54 // Geant 10.02.p02 has this defined
55 #ifndef aParticleIterator
56 #define aParticleIterator ((subInstanceManager.offset[g4vpcInstanceID])._aParticleIterator)
57 #endif
58 
60  : G4VPhysicsConstructor(name)
61 {
63 }
64 
65 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
66 
68 {
70 }
71 
72 //
73 // protected methods
74 //
75 
76 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
77 
79 {
81 }
82 
83 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
84 
86 {
87  // EvtGen model initialization changed the behavior of std::cout float print. Recover the default float print format
88  boost::io::ios_all_saver ias_cout(std::cout);
89  boost::io::ios_all_saver ias_cerr(std::cerr);
90 
93 
94  // Create Geant4 external decayer
97 
98  if (!DecayFile.empty())
99  {
100  std::ifstream f_local(DecayFile);
101 
102  if (f_local.good())
103  {
105  }
106  else
107  {
108  const char* CALIBRATIONROOT = getenv("CALIBRATIONROOT");
109  if (!CALIBRATIONROOT)
110  {
111  exit(1);
112  }
113  std::string DecayFileCalibrationRepo = std::string(CALIBRATIONROOT) + "/EvtGen/" + DecayFile;
114 
115  std::ifstream f_calib(DecayFileCalibrationRepo);
116 
117  if (f_calib.good())
118  {
119  extDecayer->SetDecayTable(DecayFileCalibrationRepo, false);
120  }
121  else
122  {
123  std::cout << __PRETTY_FUNCTION__ << " : Fatal error. Decay file can not be found at "
124  << DecayFile << " nor at " << DecayFileCalibrationRepo << std::endl;
125 
126  exit(1);
127  }
128  }
129  }
130 
131  aParticleIterator->reset();
132  int decayer_used = 0;
133  while ((*aParticleIterator)())
134  {
135  G4ParticleDefinition* particle = aParticleIterator->value();
136  G4ProcessManager* pmanager = particle->GetProcessManager();
137 
138  if (verboseLevel > 1)
139  {
140  std::cout << "Setting ext decayer for: "
141  << aParticleIterator->value()->GetParticleName()
142  << std::endl;
143  }
144 
145  G4ProcessVector* processVector = pmanager->GetProcessList();
146 #if G4VERSION_NUMBER >= 1060
147  for (size_t i = 0; i < processVector->length(); i++)
148 #else
149  for (G4int i = 0; i < processVector->length(); i++)
150 #endif
151  {
152  G4Decay* decay = dynamic_cast<G4Decay*>((*processVector)[i]);
153  if (decay)
154  {
155  // The extDecayer will be deleted in G4Decay destructor
156  // increment counter in case we want to print out stats
157  // for whatever reason (non null means it is used and
158  // must not be deleted)
159  // particle->SetDecayTable(NULL);
160  decay->SetExtDecayer(extDecayer);
161  decayer_used++;
162  }
163  }
164  }
165 
166  // If the extDecayer isn't used for this particle we need to delete it here
167  // as far as I see this never happens but this makes coverity happy
168  if (!decayer_used)
169  {
170  delete extDecayer;
171  }
172 
173  if (verboseLevel > 0)
174  {
175  std::cout << "External decayer physics constructed." << std::endl;
176  }
177 }
178 
179 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......