| 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 | #include "G4HadLeadBias.hh"
|
|---|
| 27 | #include "G4Gamma.hh"
|
|---|
| 28 | #include "G4PionZero.hh"
|
|---|
| 29 | #include "Randomize.hh"
|
|---|
| 30 | #include "G4HadFinalState.hh"
|
|---|
| 31 |
|
|---|
| 32 | G4HadFinalState * G4HadLeadBias::Bias(G4HadFinalState * result)
|
|---|
| 33 | {
|
|---|
| 34 | // G4cerr << "bias enter"<<G4endl;
|
|---|
| 35 | G4int nMeson(0), nBaryon(0), npi0(0), ngamma(0), nLepton(0);
|
|---|
| 36 | G4int i(0);
|
|---|
| 37 | G4int maxE = -1;
|
|---|
| 38 | G4double emax = 0;
|
|---|
| 39 | if(result->GetStatusChange()==isAlive)
|
|---|
| 40 | {
|
|---|
| 41 | emax = result->GetEnergyChange();
|
|---|
| 42 | }
|
|---|
| 43 | //G4cout << "max energy "<<G4endl;
|
|---|
| 44 | for(i=0;i<result->GetNumberOfSecondaries();i++)
|
|---|
| 45 | {
|
|---|
| 46 | if(result->GetSecondary(i)->GetParticle()->GetKineticEnergy()>emax)
|
|---|
| 47 | {
|
|---|
| 48 | maxE = i;
|
|---|
| 49 | emax = result->GetSecondary(i)->GetParticle()->GetKineticEnergy();
|
|---|
| 50 | }
|
|---|
| 51 | }
|
|---|
| 52 | //G4cout <<"loop1"<<G4endl;
|
|---|
| 53 | for(i=0; i<result->GetNumberOfSecondaries(); i++)
|
|---|
| 54 | {
|
|---|
| 55 | const G4DynamicParticle* aSecTrack = result->GetSecondary(i)->GetParticle();
|
|---|
| 56 | if(i==maxE)
|
|---|
| 57 | {
|
|---|
| 58 | }
|
|---|
| 59 | else if(aSecTrack->GetDefinition()->GetBaryonNumber()!=0)
|
|---|
| 60 | {
|
|---|
| 61 | nBaryon++;
|
|---|
| 62 | }
|
|---|
| 63 | else if(aSecTrack->GetDefinition()->GetLeptonNumber()!=0)
|
|---|
| 64 | {
|
|---|
| 65 | nLepton++;
|
|---|
| 66 | }
|
|---|
| 67 | else if(aSecTrack->GetDefinition()==G4Gamma::Gamma())
|
|---|
| 68 | {
|
|---|
| 69 | ngamma++;
|
|---|
| 70 | }
|
|---|
| 71 | else if(aSecTrack->GetDefinition()==G4PionZero::PionZero())
|
|---|
| 72 | {
|
|---|
| 73 | npi0++;
|
|---|
| 74 | }
|
|---|
| 75 | else
|
|---|
| 76 | {
|
|---|
| 77 | nMeson++;
|
|---|
| 78 | }
|
|---|
| 79 | }
|
|---|
| 80 | //G4cout << "BiasDebug 1 = "<<result->GetNumberOfSecondaries()<<" "
|
|---|
| 81 | // <<nMeson<<" "<< nBaryon<<" "<< npi0<<" "<< ngamma<<" "<< nLepton<<G4endl;
|
|---|
| 82 | G4double mesonWeight = nMeson;
|
|---|
| 83 | G4double baryonWeight = nBaryon;
|
|---|
| 84 | G4double gammaWeight = ngamma;
|
|---|
| 85 | G4double npi0Weight = npi0;
|
|---|
| 86 | G4double leptonWeight = nLepton;
|
|---|
| 87 | G4int randomMeson = static_cast<G4int>((nMeson+1)*G4UniformRand());
|
|---|
| 88 | G4int randomBaryon = static_cast<G4int>((nBaryon+1)*G4UniformRand());
|
|---|
| 89 | G4int randomGamma = static_cast<G4int>((ngamma+1)*G4UniformRand());
|
|---|
| 90 | G4int randomPi0 = static_cast<G4int>((npi0+1)*G4UniformRand());
|
|---|
| 91 | G4int randomLepton = static_cast<G4int>((nLepton+1)*G4UniformRand());
|
|---|
| 92 |
|
|---|
| 93 | std::vector<G4HadSecondary *> buffer;
|
|---|
| 94 | G4int cMeson(0), cBaryon(0), cpi0(0), cgamma(0), cLepton(0);
|
|---|
| 95 | for(i=0; i<result->GetNumberOfSecondaries(); i++)
|
|---|
| 96 | {
|
|---|
| 97 | G4bool aCatch = false;
|
|---|
| 98 | G4double weight = 1;
|
|---|
| 99 | G4HadSecondary * aSecTrack = result->GetSecondary(i);
|
|---|
| 100 | if(i==maxE)
|
|---|
| 101 | {
|
|---|
| 102 | aCatch = true;
|
|---|
| 103 | weight = 1;
|
|---|
| 104 | }
|
|---|
| 105 | else if(aSecTrack->GetParticle()->GetDefinition()->GetBaryonNumber()!=0)
|
|---|
| 106 | {
|
|---|
| 107 | if(++cBaryon==randomBaryon)
|
|---|
| 108 | {
|
|---|
| 109 | aCatch = true;
|
|---|
| 110 | weight = baryonWeight;
|
|---|
| 111 | }
|
|---|
| 112 | }
|
|---|
| 113 | else if(aSecTrack->GetParticle()->GetDefinition()->GetLeptonNumber()!=0)
|
|---|
| 114 | {
|
|---|
| 115 | if(++cLepton==randomLepton)
|
|---|
| 116 | {
|
|---|
| 117 | aCatch = true;
|
|---|
| 118 | weight = leptonWeight;
|
|---|
| 119 | }
|
|---|
| 120 | }
|
|---|
| 121 | else if(aSecTrack->GetParticle()->GetDefinition()==G4Gamma::Gamma())
|
|---|
| 122 | {
|
|---|
| 123 | if(++cgamma==randomGamma)
|
|---|
| 124 | {
|
|---|
| 125 | aCatch = true;
|
|---|
| 126 | weight = gammaWeight;
|
|---|
| 127 | }
|
|---|
| 128 | }
|
|---|
| 129 | else if(aSecTrack->GetParticle()->GetDefinition()==G4PionZero::PionZero())
|
|---|
| 130 | {
|
|---|
| 131 | if(++cpi0==randomPi0)
|
|---|
| 132 | {
|
|---|
| 133 | aCatch = true;
|
|---|
| 134 | weight = npi0Weight;
|
|---|
| 135 | }
|
|---|
| 136 | }
|
|---|
| 137 | else
|
|---|
| 138 | {
|
|---|
| 139 | if(++cMeson==randomMeson)
|
|---|
| 140 | {
|
|---|
| 141 | aCatch = true;
|
|---|
| 142 | weight = mesonWeight;
|
|---|
| 143 | }
|
|---|
| 144 | }
|
|---|
| 145 | if(aCatch)
|
|---|
| 146 | {
|
|---|
| 147 | buffer.push_back(aSecTrack);
|
|---|
| 148 | aSecTrack->SetWeight(aSecTrack->GetWeight()*weight);
|
|---|
| 149 | }
|
|---|
| 150 | else
|
|---|
| 151 | {
|
|---|
| 152 | delete aSecTrack;
|
|---|
| 153 | }
|
|---|
| 154 | }
|
|---|
| 155 | result->ClearSecondaries();
|
|---|
| 156 | // G4cerr << "pre"<<G4endl;
|
|---|
| 157 | for(i=0;i<static_cast<G4int>(buffer.size());i++)
|
|---|
| 158 | {
|
|---|
| 159 | result->AddSecondary(buffer[i]);
|
|---|
| 160 | }
|
|---|
| 161 | // G4cerr << "bias exit"<<G4endl;
|
|---|
| 162 |
|
|---|
| 163 | return result;
|
|---|
| 164 | }
|
|---|