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