Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // 26 // >> 27 // $Id: G4CollisionComposite.cc,v 1.9 2010-03-12 15:45:18 gunter Exp $ // 27 28 28 #include "globals.hh" 29 #include "globals.hh" 29 #include "G4SystemOfUnits.hh" 30 #include "G4SystemOfUnits.hh" 30 #include "G4CollisionComposite.hh" 31 #include "G4CollisionComposite.hh" 31 #include "G4VCollision.hh" 32 #include "G4VCollision.hh" 32 #include "G4CollisionVector.hh" 33 #include "G4CollisionVector.hh" 33 #include "G4KineticTrack.hh" 34 #include "G4KineticTrack.hh" 34 #include "G4KineticTrackVector.hh" 35 #include "G4KineticTrackVector.hh" 35 #include "G4VCrossSectionSource.hh" 36 #include "G4VCrossSectionSource.hh" 36 #include "G4HadTmpUtil.hh" 37 #include "G4HadTmpUtil.hh" 37 #include "G4AutoLock.hh" << 38 38 39 const G4int G4CollisionComposite::nPoints = 32 39 const G4int G4CollisionComposite::nPoints = 32; 40 40 41 const G4double G4CollisionComposite::theT[nPoi << 41 G4double G4CollisionComposite::theT[nPoints] = 42 {.01, .03, .05, .1, .15, .2, .3, .4, .5, .6, . 42 {.01, .03, .05, .1, .15, .2, .3, .4, .5, .6, .7, .8, .9, 1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 2.2, 2.5, 3.0, 3.5, 4.0, 5.0, 6.0, 8.0, 10., 15, 20, 50, 100}; 43 43 44 G4CollisionComposite::G4CollisionComposite() 44 G4CollisionComposite::G4CollisionComposite() 45 { 45 { 46 G4MUTEXINIT( bufferMutex ); << 47 } 46 } 48 47 49 48 50 G4CollisionComposite::~G4CollisionComposite() 49 G4CollisionComposite::~G4CollisionComposite() 51 { << 50 { 52 G4MUTEXDESTROY(bufferMutex); << 53 std::for_each(components.begin(), components 51 std::for_each(components.begin(), components.end(), G4Delete()); 54 } 52 } 55 53 56 54 57 G4double G4CollisionComposite::CrossSection(co 55 G4double G4CollisionComposite::CrossSection(const G4KineticTrack& trk1, 58 const G4KineticTrack& trk2) cons 56 const G4KineticTrack& trk2) const 59 { 57 { 60 G4double crossSect = 0.; 58 G4double crossSect = 0.; 61 const G4VCrossSectionSource* xSource = GetCr 59 const G4VCrossSectionSource* xSource = GetCrossSectionSource(); 62 if (xSource != 0) 60 if (xSource != 0) 63 // There is a total cross section for this C 61 // There is a total cross section for this Collision 64 { 62 { 65 crossSect = xSource->CrossSection(trk1,trk 63 crossSect = xSource->CrossSection(trk1,trk2); 66 } 64 } 67 else 65 else 68 { 66 { 69 G4AutoLock l(&bufferMutex); << 70 // waiting for mutable to enable buffering 67 // waiting for mutable to enable buffering. 71 const_cast<G4CollisionComposite *>(this)-> 68 const_cast<G4CollisionComposite *>(this)->BufferCrossSection(trk1.GetDefinition(), trk2.GetDefinition()); 72 // G4cerr << "Buffer filled, reying with sq 69 // G4cerr << "Buffer filled, reying with sqrts = "<< (trk1.Get4Momentum()+trk2.Get4Momentum()).mag() <<G4endl; 73 crossSect = BufferedCrossSection(trk1,trk2 70 crossSect = BufferedCrossSection(trk1,trk2); 74 } 71 } 75 return crossSect; 72 return crossSect; 76 } 73 } 77 74 78 75 79 G4KineticTrackVector* G4CollisionComposite::Fi 76 G4KineticTrackVector* G4CollisionComposite::FinalState(const G4KineticTrack& trk1, 80 const G4KineticTrack& trk2) co 77 const G4KineticTrack& trk2) const 81 { 78 { 82 std::vector<G4double> cxCache; 79 std::vector<G4double> cxCache; 83 G4double partialCxSum = 0.0; 80 G4double partialCxSum = 0.0; 84 81 85 size_t i; 82 size_t i; 86 for (i=0; i<components.size(); i++) 83 for (i=0; i<components.size(); i++) 87 { 84 { 88 G4double partialCx; 85 G4double partialCx; 89 // cout << "comp" << i << " " << components 86 // cout << "comp" << i << " " << components[i]()->GetName(); 90 if (components[i]->IsInCharge(trk1,trk2)) 87 if (components[i]->IsInCharge(trk1,trk2)) 91 { 88 { 92 partialCx = components[i]->CrossSection( 89 partialCx = components[i]->CrossSection(trk1,trk2); 93 } 90 } 94 else 91 else 95 { 92 { 96 partialCx = 0.0; 93 partialCx = 0.0; 97 } 94 } 98 // cout << " cx=" << partialCx << endl; 95 // cout << " cx=" << partialCx << endl; 99 partialCxSum += partialCx; 96 partialCxSum += partialCx; 100 cxCache.push_back(partialCx); 97 cxCache.push_back(partialCx); 101 } 98 } 102 99 103 G4double random = G4UniformRand()*partialCxS 100 G4double random = G4UniformRand()*partialCxSum; 104 G4double running = 0; 101 G4double running = 0; 105 for (i=0; i<cxCache.size(); i++) 102 for (i=0; i<cxCache.size(); i++) 106 { 103 { 107 running += cxCache[i]; 104 running += cxCache[i]; 108 if (running > random) 105 if (running > random) 109 { 106 { 110 return components[i]->FinalState(trk1, t 107 return components[i]->FinalState(trk1, trk2); 111 } 108 } 112 } 109 } 113 // G4cerr <<"in charge = "<<IsInCharge(trk1, 110 // G4cerr <<"in charge = "<<IsInCharge(trk1, trk2)<<G4endl; 114 // G4cerr <<"Cross-section = "<<CrossSection( 111 // G4cerr <<"Cross-section = "<<CrossSection(trk1, trk2)/millibarn<<" "<<running<<" "<<cxCache.size()<<G4endl; 115 // G4cerr <<"Names = "<<trk1.GetDefinition()- 112 // G4cerr <<"Names = "<<trk1.GetDefinition()->GetParticleName()<<", "<<trk2.GetDefinition()->GetParticleName()<<G4endl; 116 // throw G4HadronicException(__FILE__, __LINE 113 // throw G4HadronicException(__FILE__, __LINE__, "G4CollisionComposite: no final state found!"); 117 return NULL; 114 return NULL; 118 } 115 } 119 116 120 117 121 G4bool G4CollisionComposite::IsInCharge(const 118 G4bool G4CollisionComposite::IsInCharge(const G4KineticTrack& trk1, 122 const G4KineticTrack& trk2) const 119 const G4KineticTrack& trk2) const 123 { 120 { 124 G4bool isInCharge = false; 121 G4bool isInCharge = false; 125 122 126 // The composite is in charge if any of its 123 // The composite is in charge if any of its components is in charge 127 124 128 const G4CollisionVector* comps = GetComponen 125 const G4CollisionVector* comps = GetComponents(); 129 if (comps) 126 if (comps) 130 { 127 { 131 G4CollisionVector::const_iterator iter; 128 G4CollisionVector::const_iterator iter; 132 for (iter = comps->begin(); iter != comp 129 for (iter = comps->begin(); iter != comps->end(); ++iter) 133 { 130 { 134 if ( ((*iter))->IsInCharge(trk1,trk2) ) isI 131 if ( ((*iter))->IsInCharge(trk1,trk2) ) isInCharge = true; 135 } 132 } 136 } 133 } 137 134 138 return isInCharge; 135 return isInCharge; 139 } 136 } 140 137 141 void G4CollisionComposite:: 138 void G4CollisionComposite:: 142 BufferCrossSection(const G4ParticleDefinition 139 BufferCrossSection(const G4ParticleDefinition * aP, const G4ParticleDefinition * bP) 143 { 140 { 144 // check if already buffered 141 // check if already buffered 145 size_t i; 142 size_t i; 146 for(i=0; i<theBuffer.size(); i++) 143 for(i=0; i<theBuffer.size(); i++) 147 { 144 { 148 if(theBuffer[i].InCharge(aP, bP)) return; 145 if(theBuffer[i].InCharge(aP, bP)) return; 149 } 146 } 150 // G4cerr << "Buffering for "<<aP->GetPartic 147 // G4cerr << "Buffering for "<<aP->GetParticleName()<<" "<<bP->GetParticleName()<<G4endl; 151 148 152 // buffer the new one. 149 // buffer the new one. 153 G4CrossSectionBuffer aNewBuff(aP, bP); 150 G4CrossSectionBuffer aNewBuff(aP, bP); 154 size_t maxE=nPoints; 151 size_t maxE=nPoints; 155 for(size_t tt=0; tt<maxE; tt++) 152 for(size_t tt=0; tt<maxE; tt++) 156 { 153 { 157 G4double aT = theT[tt]*GeV; 154 G4double aT = theT[tt]*GeV; 158 G4double crossSect = 0; 155 G4double crossSect = 0; 159 // The total cross-section is summed over 156 // The total cross-section is summed over all the component channels 160 157 161 //A.R. 28-Sep-2012 Fix reproducibility pr 158 //A.R. 28-Sep-2012 Fix reproducibility problem 162 // Assign the kinetic ene 159 // Assign the kinetic energy to the lightest of the 163 // two particles, instead 160 // two particles, instead to the first one always. 164 G4double atime = 0; 161 G4double atime = 0; 165 G4double btime = 0; 162 G4double btime = 0; 166 G4ThreeVector aPosition(0,0,0); 163 G4ThreeVector aPosition(0,0,0); 167 G4ThreeVector bPosition(0,0,0); 164 G4ThreeVector bPosition(0,0,0); 168 G4double aM = aP->GetPDGMass(); 165 G4double aM = aP->GetPDGMass(); 169 G4double bM = bP->GetPDGMass(); 166 G4double bM = bP->GetPDGMass(); 170 G4double aE = aM; 167 G4double aE = aM; 171 G4double bE = bM; 168 G4double bE = bM; 172 G4ThreeVector aMom(0,0,0); 169 G4ThreeVector aMom(0,0,0); 173 G4ThreeVector bMom(0,0,0); 170 G4ThreeVector bMom(0,0,0); 174 if ( aM <= bM ) { 171 if ( aM <= bM ) { 175 aE += aT; 172 aE += aT; 176 aMom = G4ThreeVector(0,0,std::sqrt(aE*aE 173 aMom = G4ThreeVector(0,0,std::sqrt(aE*aE-aM*aM)); 177 } else { 174 } else { 178 bE += aT; 175 bE += aT; 179 bMom = G4ThreeVector(0,0,std::sqrt(bE*bE 176 bMom = G4ThreeVector(0,0,std::sqrt(bE*bE-bM*bM)); 180 } 177 } 181 G4LorentzVector a4Momentum(aE, aMom); 178 G4LorentzVector a4Momentum(aE, aMom); 182 G4LorentzVector b4Momentum(bE, bMom); 179 G4LorentzVector b4Momentum(bE, bMom); 183 G4KineticTrack a(aP, atime, aPosition, a4 << 180 G4KineticTrack a(const_cast<G4ParticleDefinition *>(aP), atime, aPosition, a4Momentum); 184 G4KineticTrack b(bP, btime, bPosition, b4 << 181 G4KineticTrack b(const_cast<G4ParticleDefinition *>(bP), btime, bPosition, b4Momentum); 185 182 186 for (i=0; i<components.size(); i++) 183 for (i=0; i<components.size(); i++) 187 { 184 { 188 if(components[i]->IsInCharge(a,b)) 185 if(components[i]->IsInCharge(a,b)) 189 { 186 { 190 crossSect += components[i]->CrossSection(a, 187 crossSect += components[i]->CrossSection(a,b); 191 } 188 } 192 } 189 } 193 G4double sqrts = (a4Momentum+b4Momentum). 190 G4double sqrts = (a4Momentum+b4Momentum).mag(); 194 aNewBuff.push_back(sqrts, crossSect); 191 aNewBuff.push_back(sqrts, crossSect); 195 } 192 } 196 theBuffer.push_back(std::move(aNewBuff)); << 193 theBuffer.push_back(aNewBuff); 197 // theBuffer.back().Print(); 194 // theBuffer.back().Print(); 198 } 195 } 199 196 200 197 201 G4double G4CollisionComposite:: 198 G4double G4CollisionComposite:: 202 BufferedCrossSection(const G4KineticTrack& trk 199 BufferedCrossSection(const G4KineticTrack& trk1, const G4KineticTrack& trk2) const 203 { 200 { 204 for(size_t i=0; i<theBuffer.size(); i++) 201 for(size_t i=0; i<theBuffer.size(); i++) 205 { 202 { 206 if(theBuffer[i].InCharge(trk1.GetDefiniti 203 if(theBuffer[i].InCharge(trk1.GetDefinition(), trk2.GetDefinition())) 207 { 204 { 208 return theBuffer[i].CrossSection(trk1, 205 return theBuffer[i].CrossSection(trk1, trk2); 209 } 206 } 210 } 207 } 211 throw G4HadronicException(__FILE__, __LINE_ 208 throw G4HadronicException(__FILE__, __LINE__, "G4CollisionComposite::BufferedCrossSection - Blitz !!"); 212 return 0; 209 return 0; 213 } 210 } 214 211 215 212