G4MolecularConfiguration.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 // $Id: G4MolecularConfiguration.cc 65022 2012-11-12 16:43:12Z gcosmo $
00027 //
00028 // Author: Mathieu Karamitros (kara (AT) cenbg . in2p3 . fr) 
00029 //
00030 // History:
00031 // -----------
00032 // 10 Oct 2011 M.Karamitros created
00033 //
00034 // -------------------------------------------------------------------
00035 
00036 #include "G4MolecularConfiguration.hh"
00037 #include "G4UIcommand.hh"
00038 
00039 using namespace std;
00040 
00041 //°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
00042 // G4MolecularConfigurationManager
00043 G4MolecularConfiguration::G4MolecularConfigurationManager* G4MolecularConfiguration::fgManager = 0 ;
00044 
00045 G4MolecularConfiguration::G4MolecularConfigurationManager*
00046         G4MolecularConfiguration::GetManager()
00047 {
00048     if(!fgManager)
00049     {
00050         fgManager = new G4MolecularConfiguration::G4MolecularConfigurationManager;
00051     }
00052 
00053     return fgManager;
00054 }
00055 
00056 G4MolecularConfiguration::G4MolecularConfigurationManager::~G4MolecularConfigurationManager()
00057 {
00058     G4MolecularConfigurationManager::MolecularConfigurationTable::iterator it1;
00059     std::map<G4ElectronOccupancy, G4MolecularConfiguration*, comparator>::iterator it2;
00060 
00061     for(it1 = fTable.begin() ; it1 != fTable.end() ; it1++)
00062     {
00063         for(it2=it1->second.begin(); it2!=it1->second.end(); it2++)
00064         {
00065             if(it2->second)
00066             {
00067                 delete it2->second;
00068             }
00069         }
00070     }
00071 }
00072 
00073 //°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
00074 // Static method in G4MolecularConfiguration
00075 G4MolecularConfiguration* G4MolecularConfiguration::GetMolecularConfiguration(const G4MoleculeDefinition* molDef)
00076 {
00077     const G4ElectronOccupancy& elecOcc = *molDef->GetGroundStateElectronOccupancy();
00078     if(GetManager()->fTable[molDef][elecOcc])
00079     {
00080         return GetManager()->fTable[molDef][elecOcc];
00081     }
00082     else
00083     {
00084         G4MolecularConfiguration* newConf = new G4MolecularConfiguration(molDef, elecOcc);
00085         return newConf ;
00086     }
00087 }
00088 
00089 G4MolecularConfiguration* G4MolecularConfiguration::GetMolecularConfiguration(const G4MoleculeDefinition* molDef,
00090         const G4ElectronOccupancy& elecOcc )
00091 {
00092     if(GetManager()->fTable[molDef][elecOcc])
00093     {
00094         return GetManager()->fTable[molDef][elecOcc];
00095     }
00096     else
00097     {
00098         G4MolecularConfiguration* newConf = new G4MolecularConfiguration(molDef, elecOcc);
00099         return newConf ;
00100     }
00101 }
00102 
00103 void G4MolecularConfiguration::DeleteManager()
00104 {
00105     if(fgManager) delete fgManager;
00106     fgManager = 0;
00107 }
00108 
00109 //°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
00110 // G4MolecularConfiguration
00111 G4MolecularConfiguration::G4MolecularConfiguration(const G4MoleculeDefinition* moleculeDef,
00112         const G4ElectronOccupancy& elecOcc)
00113 {
00114     fMoleculeDefinition = moleculeDef ;
00115     fgManager->fTable[fMoleculeDefinition][elecOcc] = this;
00116     std::map<G4ElectronOccupancy, G4MolecularConfiguration*, comparator>::iterator it ;
00117     it = fgManager->fTable[moleculeDef].find(elecOcc);
00118     fElectronOccupancy = &(it->first);
00119 
00120     fDynCharge = fMoleculeDefinition->GetNbElectrons()-fElectronOccupancy->GetTotalOccupancy();
00121     fDynMass = fMoleculeDefinition->GetMass() ;
00122 
00123     fDynDiffusionCoefficient = fMoleculeDefinition->GetDiffusionCoefficient() ;
00124     fDynVanDerVaalsRadius = fMoleculeDefinition->GetVanDerVaalsRadius() ;
00125     fDynDecayTime = fMoleculeDefinition->GetDecayTime() ;
00126 }
00127 
00128 G4MolecularConfiguration::~G4MolecularConfiguration()
00129 {
00130     if(fElectronOccupancy)
00131     {
00132         delete fElectronOccupancy;
00133         fElectronOccupancy = 0;
00134     }
00135 }
00136 
00137 G4MolecularConfiguration* G4MolecularConfiguration::ChangeConfiguration(const G4ElectronOccupancy& newElectronOccupancy)
00138 {
00139     G4MolecularConfiguration* output = fgManager->fTable[fMoleculeDefinition][newElectronOccupancy] ;
00140     if(! output)
00141     {
00142         output = new G4MolecularConfiguration(fMoleculeDefinition, newElectronOccupancy);
00143     }
00144     return output ;
00145 }
00146 
00147 G4MolecularConfiguration& G4MolecularConfiguration::operator=(G4MolecularConfiguration& right)
00148 {
00149     if (&right==this) return *this;
00150     return *this;
00151 }
00152 
00153 
00156 G4MolecularConfiguration* G4MolecularConfiguration::ExciteMolecule(G4int ExcitedLevel)
00157 {
00158     G4ElectronOccupancy newElectronOccupancy (*fElectronOccupancy);
00159 
00160     newElectronOccupancy.RemoveElectron(ExcitedLevel,1);
00161     newElectronOccupancy.AddElectron(5,1);
00162 
00163     return ChangeConfiguration(newElectronOccupancy);
00164 }
00165 
00168 G4MolecularConfiguration* G4MolecularConfiguration::IonizeMolecule(G4int IonizedLevel)
00169 {
00170     G4ElectronOccupancy newElectronOccupancy(*fElectronOccupancy);
00171 
00172     if(newElectronOccupancy.GetOccupancy(IonizedLevel) != 0)
00173     {
00174         newElectronOccupancy.RemoveElectron(IonizedLevel,1);
00175     }
00176     else
00177     {
00178         G4String errMsg = "There is no electron on the orbit " + G4UIcommand::ConvertToString(IonizedLevel) +
00179                           " you want to free. The molecule's name you want to ionized is "+ GetName();
00180         G4Exception("G4Molecule::IonizeMolecule","",FatalErrorInArgument, errMsg);
00181         PrintState();
00182     }
00183 
00184     // PrintState();
00185 
00186     return ChangeConfiguration(newElectronOccupancy);
00187 }
00188 
00189 G4MolecularConfiguration* G4MolecularConfiguration::AddElectron(G4int orbit, G4int number)
00190 {
00191     G4ElectronOccupancy newElectronOccupancy(*fElectronOccupancy);
00192     newElectronOccupancy.AddElectron(orbit, number);
00193     return ChangeConfiguration(newElectronOccupancy);
00194 }
00195 
00196 G4MolecularConfiguration* G4MolecularConfiguration::RemoveElectron(G4int orbit,G4int number)
00197 {
00198     G4ElectronOccupancy newElectronOccupancy (*fElectronOccupancy);
00199 
00200     if(newElectronOccupancy.GetOccupancy(orbit) != 0)
00201     {
00202         newElectronOccupancy.RemoveElectron(orbit, number );
00203     }
00204     else
00205     {
00206         G4String errMsg = "There is already no electron into the orbit " + G4UIcommand::ConvertToString(orbit) +
00207                           " you want to free. The molecule's name is "+ GetName();
00208         G4Exception("G4Molecule::RemoveElectron","",JustWarning, errMsg);
00209         PrintState();
00210     }
00211 
00212     return ChangeConfiguration(newElectronOccupancy);
00213 }
00214 
00215 G4MolecularConfiguration* G4MolecularConfiguration::MoveOneElectron(G4int orbitToFree,G4int orbitToFill)
00216 {
00217     G4ElectronOccupancy newElectronOccupancy (*fElectronOccupancy);
00218 
00219     if(newElectronOccupancy . GetOccupancy(orbitToFree)>=1)
00220     {
00221         newElectronOccupancy . RemoveElectron(orbitToFree,1);
00222         newElectronOccupancy . AddElectron(orbitToFill,1);
00223     }
00224     else
00225     {
00226         G4String errMsg = "There is no electron on the orbit " + G4UIcommand::ConvertToString(orbitToFree) +
00227                           " you want to free. The molecule's name is "+ GetName();
00228         G4Exception("G4Molecule::MoveOneElectron","",FatalErrorInArgument, errMsg);
00229         PrintState();
00230     }
00231 
00232     return ChangeConfiguration(newElectronOccupancy);
00233 }
00234 
00235 const G4String& G4MolecularConfiguration::GetName() const
00236 {
00237     if(fName.isNull())
00238     {
00239         fName = fMoleculeDefinition->GetName();
00240         fName+= "^";
00241         fName+= "{";
00242         fName+= G4UIcommand::ConvertToString(fDynCharge);
00243         fName+= "}";
00244     }
00245     return fName;
00246 }
00247 
00248 G4int G4MolecularConfiguration::GetAtomsNumber() const
00249 {
00250     return fMoleculeDefinition->GetAtomsNumber();
00251 }
00252 
00253 G4double G4MolecularConfiguration::GetNbElectrons() const
00254 {
00255     return fElectronOccupancy->GetTotalOccupancy();
00256 }
00257 
00258 void G4MolecularConfiguration::PrintState() const
00259 {
00260     G4cout<<"--------------Print electronic state of "<<GetName()<<"---------------"<<G4endl;
00261     fElectronOccupancy->DumpInfo();
00262     if(fElectronOccupancy==fMoleculeDefinition->GetGroundStateElectronOccupancy())
00263     {
00264         G4cout<<"At ground state"<<G4endl;
00265     }
00266     else
00267     {
00268         if(fMoleculeDefinition->GetDecayTable())
00269             G4cout<<"Transition :"<<(fMoleculeDefinition->GetDecayTable())->GetExcitedState(fElectronOccupancy)<<G4endl;
00270     }
00271 }
00272 
00273 // added - to be transformed in a "Decay method"
00274 const vector <const G4MolecularDecayChannel*>* G4MolecularConfiguration::GetDecayChannel() const
00275 {
00276     return fMoleculeDefinition-> GetDecayChannels(fElectronOccupancy);
00277 }
00278 
00279 G4int G4MolecularConfiguration::GetMoleculeID() const
00280 {
00281     if(fMoleculeDefinition)
00282         return fMoleculeDefinition->GetPDGEncoding();
00283     else
00284         G4Exception("G4Molecule::GetMoleculeID","",FatalErrorInArgument, "You should first enter a molecule defintion");
00285 
00286     return INT_MAX;
00287 }

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