G4ITModelProcessor.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: G4ITModelProcessor.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 "G4ITModelProcessor.hh"
00037 #include "G4VITTimeStepper.hh"
00038 #include "G4VITReactionProcess.hh"
00039 
00040 std::map<const G4Track*, G4bool> G4ITModelProcessor::fHasReacted ;
00041 
00042 G4ITModelProcessor::G4ITModelProcessor()
00043 {
00044     //ctor
00045     fpTrack = 0;
00046     fpModelHandler = 0;
00047     fpModel = 0;
00048     fInitialized = false;
00049     fpModelManager = 0;
00050     fCurrentModel.assign(G4ITType::size(), std::vector<G4VITModel*>());
00051 
00052     for(int i = 0 ; i < (int) G4ITType::size() ; i++)
00053     {
00054         fCurrentModel[i].assign(G4ITType::size(),0);
00055     }
00056     fUserMinTimeStep = -1.;
00057 }
00058 
00059 G4ITModelProcessor::~G4ITModelProcessor()
00060 {
00061     //dtor
00062 //    if(fpModelHandler) delete fpModelHandler; deleted by G4ITStepManager
00063     fCurrentModel.clear();
00064     fReactionInfo.clear();
00065 }
00066 
00067 // Should not be used
00068 G4ITModelProcessor::G4ITModelProcessor(const G4ITModelProcessor& /*other*/)
00069 {
00070     //copy ctorr
00071     fpTrack = 0;
00072     fpModelHandler = 0;
00073     fpModel = 0;
00074     fInitialized = false;
00075     fpModelManager = 0;
00076     fUserMinTimeStep = -1.;
00077 }
00078 
00079 // Should not be used
00080 G4ITModelProcessor& G4ITModelProcessor::operator=(const G4ITModelProcessor& rhs)
00081 {
00082     if (this == &rhs) return *this; // handle self assignment
00083     //assignment operator
00084     return *this;
00085 }
00086 //______________________________________________________________________________
00087 void G4ITModelProcessor::Initialize()
00088 {
00089     fpModelHandler->Initialize();
00090     fInitialized = true;
00091 }
00092 
00093 //______________________________________________________________________________
00094 void G4ITModelProcessor::InitializeStepper(const G4double& currentGlobalTime,
00095                                            const G4double& userMinTime)
00096 {
00097     // G4cout << "G4ITModelProcessor::InitializeStepper" << G4endl;
00098     if(fpModelHandler==0)
00099     {
00100         G4ExceptionDescription exceptionDescription ;
00101         exceptionDescription << "No G4ITModelHandler was passed to the modelProcessor.";
00102         G4Exception("G4ITModelProcessor::InitializeStepper","ITModelProcessor002",
00103                     FatalErrorInArgument,exceptionDescription);
00104     }
00105     const std::vector<std::vector<G4ITModelManager*> >* modelManager = fpModelHandler
00106             ->GetAllModelManager();
00107 
00108     if(modelManager==0)
00109     {
00110         G4ExceptionDescription exceptionDescription ;
00111         exceptionDescription << "No G4ITModelManager was register to G4ITModelHandler.";
00112         G4Exception("G4ITModelProcessor::InitializeStepper","ITModelProcessor003",
00113                     FatalErrorInArgument,exceptionDescription);
00114     }
00115 
00116     int nbModels1 = modelManager->size() ;
00117 
00118     G4VITTimeStepper::SetTimes(currentGlobalTime, userMinTime) ;
00119 
00120     // TODO !!!
00121     //    if( nbModels1 != 1 || (nbModels1 == 1 && !fpModelManager) )
00122     {
00123         int nbModels2 = -1;
00124         G4VITModel* model = 0;
00125         G4ITModelManager* modman = 0;
00126 
00127         for(int i = 0 ; i < nbModels1 ; i++)
00128         {
00129             nbModels2 = (*modelManager)[i].size();
00130 
00131             for(int j = 0 ; j <= i ; j++)
00132             {
00133                 modman = (*modelManager)[i][j];
00134 
00135                 if(modman == 0) continue ;
00136 
00137                 model       =  modman -> GetModel(currentGlobalTime);
00138                 G4VITTimeStepper* stepper   = model->GetTimeStepper() ;
00139 
00140 //                stepper -> PrepareForAllProcessors() ;
00141                 stepper -> Prepare() ;
00142                 fCurrentModel[i][j] = model;
00143             }
00144         }
00145 
00146         if(nbModels1 == 1 && nbModels2 ==1)
00147         {
00148             fpModelManager = modman;
00149             fpModel = model;
00150         }
00151         else fpModel = 0;
00152     }
00153 }
00154 
00155 //______________________________________________________________________________
00156 void G4ITModelProcessor::CalculateTimeStep(const G4Track* track, const G4double userMinTimeStep)
00157 {
00158     // G4cout  << "G4ITModelProcessor::CalculateStep" << G4endl;
00159     CleanProcessor();
00160     if(track == 0)
00161     {
00162         G4ExceptionDescription exceptionDescription ;
00163         exceptionDescription << "No track was passed to the method (track == 0).";
00164         G4Exception("G4ITModelProcessor::CalculateStep","ITModelProcessor004",
00165                     FatalErrorInArgument,exceptionDescription);
00166     }
00167     SetTrack(track);
00168     fUserMinTimeStep = userMinTimeStep ;
00169 
00170     DoCalculateStep();
00171 }
00172 
00173 //______________________________________________________________________________
00174 void G4ITModelProcessor::DoCalculateStep()
00175 {
00176     if(fpModel) // ie only one model has been declared and will be used
00177     {
00178         fpModel -> GetTimeStepper()->CalculateStep(*fpTrack, fUserMinTimeStep);
00179     }
00180     else // ie many models have been declared and will be used
00181     {
00182         std::vector<G4VITModel*>& model = fCurrentModel[GetIT(fpTrack)->GetITType()];
00183 
00184         for(int i =0 ; i < (int) model.size() ; i++)
00185         {
00186             if(model[i] == 0) continue;
00187             model[i]->GetTimeStepper()->CalculateStep(*fpTrack, fUserMinTimeStep);
00188         }
00189     }
00190 }
00191 
00192 //______________________________________________________________________________
00193 void G4ITModelProcessor::FindReaction(std::map<G4Track*, G4TrackVectorHandle>* tracks,
00194                                       const double currentStepTime,
00195                                       const double previousStepTime,
00196                                       const bool reachedUserStepTimeLimit)
00197 {
00198     // DEBUG
00199     //    G4cout << "G4ITReactionManager::FindReaction" << G4endl;
00200     if(tracks == 0)       return ;
00201 
00202     if(fpModelHandler->GetAllModelManager()->empty()) return ;
00203 
00204     std::map<G4Track*, G4TrackVectorHandle>::iterator tracks_i = tracks->begin();;
00205 
00206     for(tracks_i = tracks->begin() ; tracks_i != tracks-> end() ; tracks_i ++)
00207     {
00209         G4Track* trackA = tracks_i->first;
00210 
00211         if(trackA == 0)         continue;
00212 
00213         std::map<const G4Track*, G4bool>::iterator it_hasReacted = fHasReacted.find(trackA);
00214         if(it_hasReacted != fHasReacted.end()) continue;
00215         if(trackA->GetTrackStatus() == fStopAndKill) continue;
00216 
00217         G4IT* ITA = GetIT(trackA);
00218         G4ITType ITypeA = ITA -> GetITType();
00219 
00220         const std::vector<G4VITModel*> model = fCurrentModel[ITypeA];
00221 
00222         G4TrackVectorHandle& trackB_vector = tracks_i->second ;
00223         std::vector<G4Track*>::iterator trackB_i = trackB_vector->begin();
00224 
00225         G4Track* trackB = 0 ;
00226         G4ITType ITypeB(-1);
00227         G4VITReactionProcess* process = 0;
00228         G4ITReactionChange* changes = 0;
00229 
00230         for(; trackB_i != trackB_vector->end() ; trackB_i++)
00231         {
00232             trackB = *trackB_i;
00233 
00234             if(trackB == 0)         continue;
00235             it_hasReacted = fHasReacted.find(trackB);
00236             if(it_hasReacted != fHasReacted.end()) continue;
00237             if(trackB->GetTrackStatus() == fStopAndKill) continue;
00238 
00239             // DEBUG
00240             //             G4cout << "Couple : " << trackA->GetParticleDefinition->GetParticleName() << " ("
00241             //                        << trackA->GetTrackID() << ")   "
00242             //                        << trackB->GetParticleDefinition->GetParticleName() << " ("
00243             //                        << trackB->GetTrackID() << ")"
00244             //                        << G4endl;
00245 
00246             if(trackB == trackA)
00247             {
00248                 G4ExceptionDescription exceptionDescription ;
00249                 exceptionDescription << "The IT reaction process sent back a reaction between trackA and trackB. ";
00250                 exceptionDescription << "The problem is trackA == trackB";
00251                 G4Exception("G4ITModelProcessor::FindReaction","ITModelProcessor005",
00252                             FatalErrorInArgument,exceptionDescription);
00253             }
00254 
00255             G4IT* ITB = GetIT(trackB);
00256             G4ITType ITypeBtmp = ITB -> GetITType();
00257 
00258             if(ITypeB != ITypeBtmp)
00259             {
00260                 ITypeB = ITypeBtmp ;
00261 
00262                 if(model[ITypeB])
00263                     process = model[ITypeB]->GetReactionProcess();
00264             }
00265 
00266             if(process && process -> TestReactibility(*trackA, *trackB,
00267                                                       currentStepTime, previousStepTime,
00268                                                       reachedUserStepTimeLimit))
00269             {
00270                 changes = process->MakeReaction(*trackA, *trackB);
00271             }
00272 
00273             if(changes)
00274             {
00275                 fHasReacted[trackA] = true;
00276                 fHasReacted[trackB] = true;
00277                 changes -> GetTrackA();
00278                 changes -> GetTrackB();
00279 
00280                 fReactionInfo.push_back(changes);
00281 
00282                 process->ResetChanges();
00283                 changes = 0;
00284 
00285                 break;
00286             }
00287         }
00288     }
00289 
00290     fHasReacted.clear();
00291 }

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