MuNuclearSplittingProcess.cxx
Go to the documentation of this file.
1 //
2 // Code adapted from EventBiasing from Jane Tinslay, SLAC. 2008. Now at Cisco,
3 // I think.
4 //
5 // This is a variance reduction technique.
6 //
7 // The point is to create Nsplit secondaries with each muNucl process, so
8 // that we may, e.g., create many, otherwise-rare, K0s which
9 // may charge exchange into pernicious K+s which then mimic proton dk.
10 //
11 // echurch@fnal.gov, May, 2011.
12 //
13 
14 
16 
17 #include <stdexcept> // std::runtime_error
18 
19 #include "Geant4/G4WrapperProcess.hh"
20 #include "Geant4/G4VParticleChange.hh"
21 
22 #include "Geant4/G4SDManager.hh"
23 #include "Geant4/G4RunManager.hh"
24 #include "Geant4/G4Event.hh"
25 #include "Geant4/G4HCofThisEvent.hh"
26 #include "Geant4/G4Track.hh"
27 #include "Geant4/G4Step.hh"
28 #include "Geant4/G4TrackStatus.hh"
29 #include "Geant4/G4ParticleDefinition.hh"
30 #include "Geant4/G4ParticleTypes.hh"
31 #include "Geant4/Randomize.hh"
32 #include "Geant4/G4KaonZeroLong.hh"
33 #include "Geant4/G4ios.hh"
34 
35 #include <TMath.h>
36 
37 namespace gar {
38  namespace garg4 {
39 
40  G4VParticleChange* MuNuclearSplittingProcess::PostStepDoIt(const G4Track& track, const G4Step& step)
41  {
42 
43  G4VParticleChange* particleChange = new G4VParticleChange();
44  G4double weight = track.GetWeight()/fNSplit;
45  std::vector<G4Track*> secondaries; // Secondary store
46 
47  // Loop over PostStepDoIt method to generate multiple secondaries.
48  // The point is for each value of ii up to Nsplit we want to re-toss
49  // all secondaries for the muNucl process. Each toss gives back numSec
50  // secondaries, which will be a different sample of species/momenta each time.
51  for (unsigned int ii=0; ii<(unsigned int)fNSplit; ii++) {
52  particleChange = pRegProcess->PostStepDoIt(track, step);
53  if (!particleChange)
54  throw std::runtime_error("MuNuclearSplittingProcess::PostStepDoIt(): no particle change");
55  G4int j(0);
56  G4int numSec(particleChange->GetNumberOfSecondaries());
57  for (j=0; j<numSec; j++)
58  {
59  G4Track* newSec = new G4Track(*(particleChange->GetSecondary(j)));
60  G4String pdgstr = newSec->GetParticleDefinition()->GetParticleName();
61  G4double ke = newSec->GetKineticEnergy()/CLHEP::GeV;
62  G4int pdg = newSec->GetParticleDefinition()->GetPDGEncoding();
63  if (abs(pdg)==310 ||abs(pdg)==311 || abs(pdg)==3122 || abs(pdg)==2112)
64  {
65  // std::cout << "MuNuclSplProc: Creating " << pdgstr << " of Kinetic Energy " << ke << " GeV. numSec is " << j << std::endl;
66 
67  if (pdg==G4KaonZeroShort::KaonZeroShort()->GetPDGEncoding()&&G4UniformRand()<0.50)
68  {
69  pdg = G4KaonZeroLong::KaonZeroLong()->GetPDGEncoding();
70  pdgstr = G4KaonZeroLong::KaonZeroLong()->GetParticleName();
71  G4LorentzVector pK0L(newSec->GetMomentum(),TMath::Sqrt(TMath::Power(G4KaonZeroLong::KaonZeroLong()->GetPDGMass(),2)+TMath::Power(newSec->GetMomentum().mag(),2)));
72  G4DynamicParticle *newK0L = new G4DynamicParticle(G4KaonZeroLong::KaonZeroLong(),pK0L);
73 
74  G4Track* newSecK0L = new G4Track(newK0L,track.GetGlobalTime(),track.GetPosition());
75  secondaries.push_back(newSecK0L);
76  }
77  else
78  {
79  secondaries.push_back(newSec);
80  }
81 
82  if (abs(pdg)==130 ||abs(pdg)==310 ||abs(pdg)==311 || abs(pdg)==3122)
83  {
84  // WrappedmuNuclear always produces K0s if it produces a K0 at all.
85  // Let's make half of these K0Ls.
86  std::cout << "MuNuclSplProc: Creating " << pdgstr << " of Kinetic Energy " << ke << " GeV. numSec is " << j << std::endl;
87  }
88 
89  }
90  }
91  }
92 
93  particleChange->SetNumberOfSecondaries(secondaries.size());
94  particleChange->SetSecondaryWeightByProcess(true);
95  //int numSecAdd = secondaries.size();
96  std::vector<G4Track*>::iterator iter = secondaries.begin(); // Add all secondaries
97  while (iter != secondaries.end()) {
98  G4Track* myTrack = *iter;
99  G4String pdgstr = myTrack->GetParticleDefinition()->GetParticleName();
100  //G4double ke = myTrack->GetKineticEnergy()/GeV;
101  G4int pdg = myTrack->GetParticleDefinition()->GetPDGEncoding();
102  if (abs(pdg)==130 ||abs(pdg)==310 ||abs(pdg)==311 || abs(pdg)==3122 || abs(pdg)==2112)
103  // std::cout << "MuNuclSplProc: Adding " << pdgstr << " of Kinetic Energy " << ke << " GeV." << std::endl;
104  // Will ask for PdgCode and only Add K0s.
105  myTrack->SetWeight(weight);
106  particleChange->AddSecondary(myTrack);
107  iter++;
108  }
109  return particleChange;
110  }
111 
112  } // end namespace
113 } // gar
intermediate_table::iterator iterator
weight
Definition: test.py:257
T abs(T value)
static constexpr double GeV
Definition: Units.h:28
G4VParticleChange * PostStepDoIt(const G4Track &track, const G4Step &step)
General GArSoft Utilities.
QTextStream & endl(QTextStream &s)