G4DecayTable.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 // 
00030 // ------------------------------------------------------------
00031 //      GEANT 4 class implementation file
00032 //
00033 //      History: first implementation, based on object model of
00034 //      27 July 1996 H.Kurashige
00035 // ----------------------------------------
00036 //      implementation for STL          14 Feb. 2000 H.Kurashige
00037 // ------------------------------------------------------------
00038 
00039 #include "globals.hh"
00040 #include "G4DecayTable.hh"
00041 #include "Randomize.hh"
00042 
00043 G4DecayTable::G4DecayTable():parent(0)
00044 {
00045   channels =  new G4VDecayChannelVector;
00046 }
00047 
00048 G4DecayTable::~G4DecayTable()
00049 {
00050   // remove and delete all contents  
00051   G4VDecayChannelVector::iterator i;
00052   for (i = channels->begin(); i!= channels->end(); ++i) {
00053     delete (*i);
00054   }
00055   channels->clear();
00056   delete  channels;
00057   channels = 0;
00058 }    
00059 
00060 void G4DecayTable::Insert( G4VDecayChannel * aChannel){
00061   if (parent == 0) { parent = (G4ParticleDefinition*)(aChannel->GetParent()); }
00062   if (parent != aChannel->GetParent()) {
00063 #ifdef G4VERBOSE
00064     G4cerr << " G4DecayTable::Insert :: bad   G4VDecayChannel (mismatch parent) "
00065            << "       " << parent->GetParticleName()
00066            << " input:" << aChannel->GetParent()->GetParticleName() << G4endl;
00067 #endif
00068   } else {
00069     G4double r = aChannel->GetBR();
00070     G4VDecayChannelVector::iterator i;
00071     for (i = channels->begin(); i!= channels->end(); ++i) {
00072       if (r > (*i)->GetBR()) {
00073         channels->insert(i,aChannel);
00074         return;
00075       }
00076     }
00077     channels->push_back(aChannel);
00078   }
00079 }
00080 
00081 G4VDecayChannel *G4DecayTable::SelectADecayChannel()
00082 {
00083   // check if contents exist
00084   if (channels->size()<1) return 0;
00085 
00086   while (1) {
00087     G4double sumBR = 0.0;
00088     G4double r= G4UniformRand();
00089     // select decay channel
00090     G4VDecayChannelVector::iterator i;
00091     for (i = channels->begin(); i!= channels->end(); ++i) {
00092       sumBR += (*i)->GetBR();
00093       if (r < sumBR) {
00094         return (*i);
00095       }
00096     }
00097   }
00098   return 0;
00099 }
00100 
00101 void G4DecayTable::DumpInfo() const
00102 {
00103   G4cout << "G4DecayTable:  " << parent->GetParticleName() << G4endl;
00104   G4int index =0;
00105   G4VDecayChannelVector::iterator i;
00106   for (i = channels->begin(); i!= channels->end(); ++i) {
00107     G4cout << index << ": ";
00108     (*i)->DumpInfo();
00109     index +=1;
00110   }
00111   G4cout << G4endl;
00112 }
00113 
00114 
00115 
00116 
00117 
00118 
00119 
00120 
00121 
00122 
00123 

Generated on Mon May 27 17:48:00 2013 for Geant4 by  doxygen 1.4.7