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