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