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 // G4DecayTable class implementation << 27 // 26 // 28 // Author: H.Kurashige, 7 July 1996 << 27 // $Id: G4DecayTable.cc,v 1.8 2006/06/29 19:25:02 gunter Exp $ 29 // ------------------------------------------- << 28 // GEANT4 tag $Name: geant4-08-03-patch-01 $ >> 29 // >> 30 // >> 31 // ------------------------------------------------------------ >> 32 // GEANT 4 class implementation file >> 33 // >> 34 // History: first implementation, based on object model of >> 35 // 27 July 1996 H.Kurashige >> 36 // ---------------------------------------- >> 37 // implementation for STL 14 Feb. 2000 H.Kurashige >> 38 // ------------------------------------------------------------ 30 39 >> 40 #include "globals.hh" 31 #include "G4DecayTable.hh" 41 #include "G4DecayTable.hh" 32 << 33 #include "Randomize.hh" 42 #include "Randomize.hh" 34 #include "globals.hh" << 35 43 36 G4DecayTable::G4DecayTable() << 44 G4DecayTable::G4DecayTable():parent(0) 37 { 45 { 38 channels = new G4VDecayChannelVector; << 46 channels = new G4VDecayChannelVector; 39 } 47 } 40 48 41 G4DecayTable::~G4DecayTable() 49 G4DecayTable::~G4DecayTable() 42 { 50 { 43 // remove and delete all contents << 51 // remove and delete all contents 44 for (const auto channel : *channels) { << 52 G4VDecayChannelVector::iterator i; 45 delete channel; << 53 for (i = channels->begin(); i!= channels->end(); ++i) { >> 54 delete (*i); 46 } 55 } 47 channels->clear(); 56 channels->clear(); 48 delete channels; << 57 delete channels; 49 channels = nullptr; << 58 channels = 0; 50 parent = nullptr; << 59 } 51 } << 52 60 53 void G4DecayTable::Insert(G4VDecayChannel* aCh << 61 void G4DecayTable::Insert( G4VDecayChannel * aChannel){ 54 { << 62 if (parent == 0) { parent = (G4ParticleDefinition*)(aChannel->GetParent()); } 55 if (parent == nullptr) { << 56 parent = (G4ParticleDefinition*)(aChannel- << 57 } << 58 if (parent != aChannel->GetParent()) { 63 if (parent != aChannel->GetParent()) { 59 #ifdef G4VERBOSE 64 #ifdef G4VERBOSE 60 G4cout << " G4DecayTable::Insert :: bad G4 << 65 G4cout << " G4DecayTable::Insert :: bad G4VDecayChannel (mismatch parent) "; 61 << " " << parent->GetParticle << 66 G4cout << " " << parent->GetParticleName(); 62 << " input:" << aChannel->GetParent << 67 G4cout << " input:" << aChannel->GetParent()->GetParticleName() << G4endl; 63 #endif 68 #endif 64 } << 69 } else { 65 else { << 70 G4double r = aChannel->GetBR(); 66 G4double br = aChannel->GetBR(); << 71 G4VDecayChannelVector::iterator i; 67 for (auto iCh = channels->cbegin(); iCh != << 72 for (i = channels->begin(); i!= channels->end(); ++i) { 68 if (br > (*iCh)->GetBR()) { << 73 if (r > (*i)->GetBR()) { 69 channels->insert(iCh, aChannel); << 74 channels->insert(i,aChannel); 70 return; << 75 return; 71 } 76 } 72 } 77 } 73 channels->push_back(aChannel); 78 channels->push_back(aChannel); 74 } 79 } 75 } 80 } 76 81 77 G4VDecayChannel* G4DecayTable::SelectADecayCha << 82 G4VDecayChannel *G4DecayTable::SelectADecayChannel() 78 { 83 { 79 // check if contents exist 84 // check if contents exist 80 if (channels->empty()) return nullptr; << 85 if (channels->size()<1) return 0; 81 86 82 if (parentMass < 0.) parentMass = parent->Ge << 87 while (1) { 83 << 88 G4double sumBR = 0.0; 84 G4double sumBR = 0.; << 89 G4double r= G4UniformRand(); 85 for (const auto channel : *channels) { << 86 if (!(channel->IsOKWithParentMass(parentMa << 87 sumBR += channel->GetBR(); << 88 } << 89 if (sumBR <= 0.0) { << 90 #ifdef G4VERBOSE << 91 G4cout << " G4DecayTable::SelectADecayChan << 92 << " " << parent->GetParticle << 93 #endif << 94 return nullptr; << 95 } << 96 << 97 const std::size_t MAX_LOOP = 10000; << 98 for (std::size_t loop_counter = 0; loop_coun << 99 G4double sum = 0.0; << 100 G4double br = sumBR * G4UniformRand(); << 101 // select decay channel 90 // select decay channel 102 for (const auto channel : *channels) { << 91 G4VDecayChannelVector::iterator i; 103 sum += channel->GetBR(); << 92 for (i = channels->begin(); i!= channels->end(); ++i) { 104 if (!(channel->IsOKWithParentMass(parent << 93 sumBR += (*i)->GetBR(); 105 if (br < sum) return channel; << 94 if (r < sumBR) { >> 95 return (*i); >> 96 } 106 } 97 } 107 } 98 } 108 return nullptr; << 99 return 0; 109 } 100 } 110 101 111 void G4DecayTable::DumpInfo() const 102 void G4DecayTable::DumpInfo() const 112 { 103 { 113 G4cout << "G4DecayTable: " << parent->GetPa 104 G4cout << "G4DecayTable: " << parent->GetParticleName() << G4endl; 114 G4int index = 0; << 105 G4int index =0; 115 for (const auto channel : *channels) { << 106 G4VDecayChannelVector::iterator i; >> 107 for (i = channels->begin(); i!= channels->end(); ++i) { 116 G4cout << index << ": "; 108 G4cout << index << ": "; 117 channel->DumpInfo(); << 109 (*i)->DumpInfo(); 118 index += 1; << 110 index +=1; 119 } 111 } 120 G4cout << G4endl; 112 G4cout << G4endl; 121 } 113 } >> 114 >> 115 >> 116 >> 117 >> 118 >> 119 >> 120 >> 121 >> 122 >> 123 >> 124 122 125