G4ITReactionChange.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: G4ITReactionChange.cc 64057 2012-10-30 15:04:49Z 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 "G4ITReactionChange.hh"
00037 
00038 G4ITReactionChange::G4ITReactionChange():
00039     fSecondaries(0),
00040     fNumberOfSecondaries(0),
00041     fKillParents(false),
00042     fParticleChangeIsSet(false)
00043 {
00044     //ctor
00045 }
00046 
00047 G4ITReactionChange::~G4ITReactionChange()
00048 {
00049     //dtor
00050     delete fSecondaries;
00051     fSecondaries = 0 ;
00052 }
00053 
00054 // Should not be used
00055 G4ITReactionChange::G4ITReactionChange(const G4ITReactionChange& /*other*/) :
00056     fSecondaries(0),
00057     fNumberOfSecondaries(0),
00058     fKillParents(false),
00059     fParticleChangeIsSet(false)
00060 {
00061     //copy ctor
00062 }
00063 
00064 // should not be used
00065 G4ITReactionChange& G4ITReactionChange::operator=(const G4ITReactionChange& rhs)
00066 {
00067     if (this == &rhs) return *this; // handle self assignment
00068     //assignment operator
00069     return *this;
00070 }
00071 
00072 void G4ITReactionChange::Initialize(const G4Track& trackA,
00073                             const G4Track& trackB,
00074                             G4VParticleChange* particleChangeA,
00075                             G4VParticleChange* particleChangeB
00076                             )
00077 {
00078     fParticleChange.clear();
00079     fParticleChange[&trackA] = particleChangeA;
00080     fParticleChange[&trackB] = particleChangeB;
00081 
00082     if(particleChangeA || particleChangeB)
00083     {
00084         G4bool test = particleChangeA && particleChangeB ;
00085 
00086         if(test == false)
00087         {
00088             G4ExceptionDescription exceptionDescription ;
00089             exceptionDescription << "If you give for one track a particleChange, ";
00090             exceptionDescription << "G4ITReactionChange is expecting that you give for both ";
00091             exceptionDescription << "reacting tracks a particleChange.";
00092             G4Exception("G4ITReactionChange::Initialize","ITReactionChange001",
00093                         FatalErrorInArgument,exceptionDescription);
00094         }
00095 
00096         fParticleChangeIsSet = true;
00097 
00098         fParticleChange[&trackA]->Initialize(trackA);
00099         fParticleChange[&trackB]->Initialize(trackB);;
00100 
00101     }
00102 
00103     fSecondaries = 0;
00104     fNumberOfSecondaries = 0;
00105     fKillParents = false;
00106 }
00107 
00108 void G4ITReactionChange::AddSecondary(G4Track* aTrack)
00109 {
00110     if(fSecondaries==0) fSecondaries = new G4TrackFastVector();
00111 
00112     // add a secondary after size check
00113     if (G4TrackFastVectorSize > fNumberOfSecondaries)
00114     {
00115         fSecondaries->SetElement(fNumberOfSecondaries, aTrack);
00116         fNumberOfSecondaries++;
00117     }
00118     else
00119     {
00120         G4cerr << "G4ITReactionChange::AddSecondary() Warning  ";
00121         G4cerr << "fSecondaries is full !! " << G4endl;
00122         G4cerr << " The object will not be added in fSecondaries" << G4endl;
00123     }
00124 }
00125 
00126 void G4ITReactionChange::UpdateStepInfo(G4Step* stepA, G4Step* stepB)
00127 {
00128     fParticleChange[stepA->GetTrack()]->UpdateStepForPostStep(stepA);
00129     fParticleChange[stepB->GetTrack()]->UpdateStepForPostStep(stepB);
00130 }
00131 
00132 G4VParticleChange* G4ITReactionChange::GetParticleChange(const G4Track* track)
00133 {
00134     std::map<const G4Track*, G4VParticleChange*>::iterator it = fParticleChange.find(track);
00135 
00136     if(it == fParticleChange.end()) return 0;
00137     else return it ->second;
00138 }
00139 
00140 const G4Track* G4ITReactionChange::GetTrackA()
00141 {
00142     std::map<const G4Track*, G4VParticleChange*>::iterator it = fParticleChange.begin();
00143     if(it != fParticleChange.end())
00144     {
00145         return it->first;
00146     }
00147 
00148     G4ExceptionDescription exceptionDescription ;
00149     exceptionDescription << "No track A found ! Have you initialized the ReactionChange ?";
00150     G4Exception("G4ITReactionChange::GetTrackA","ITReactionChange001",
00151                 FatalErrorInArgument,exceptionDescription);
00152     return 0;
00153 }
00154 
00155 const G4Track* G4ITReactionChange::GetTrackB()
00156 {
00157     std::map<const G4Track*, G4VParticleChange*>::iterator it = fParticleChange.begin();
00158     std::map<const G4Track*, G4VParticleChange*>::iterator next = it++;
00159     if(next == fParticleChange.end())
00160     {
00161         G4ExceptionDescription exceptionDescription ;
00162         exceptionDescription << "No track B found ! Have you initialized the ReactionChange ?";
00163         G4Exception("G4ITReactionChange::GetTrackB","ITReactionChange002",
00164                     FatalErrorInArgument,exceptionDescription);
00165     }
00166 
00167     return it->first;
00168 }

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