00001 // BLBeam.hh 00002 /* 00003 This source file is part of G4beamline, http://g4beamline.muonsinc.com 00004 Copyright (C) 2003,2004,2005,2006 by Tom Roberts, all rights reserved. 00005 00006 This program is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU General Public License 00008 as published by the Free Software Foundation; either version 2 00009 of the License, or (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 http://www.gnu.org/copyleft/gpl.html 00017 */ 00018 00019 #ifndef BLBEAM_HH 00020 #define BLBEAM_HH 00021 00022 #include "globals.hh" 00023 #include "G4Event.hh" 00024 #include "G4ParticleGun.hh" 00025 #include "G4ParticleDefinition.hh" 00026 #include "Randomize.hh" 00027 00028 #include "BLManager.hh" 00029 #include "BLCommand.hh" 00030 #include "BLTime.hh" 00031 00032 /** class BLBeam is an interface class for a beam. 00033 * 00034 * NOTE: all functions are either inline or abstract, so no .cc file is 00035 * needed. 00036 **/ 00037 class BLBeam { 00038 protected: 00039 G4int nEvents; 00040 public: 00041 /// Constructor. 00042 BLBeam() { nEvents = 0; } 00043 00044 /// Utility: setRandomSeedToGenerate() sets the random seed for 00045 /// the generation of an event. 00046 static void setRandomSeedToGenerate(int evid) // reference has evid<0 00047 { switch(BLManager::getObject()->getPRNGSeedMethod()) { 00048 case EVENT_NUMBER: 00049 CLHEP::HepRandom::setTheSeed(evid>=0? evid : 0); 00050 break; 00051 case TIME_US: 00052 CLHEP::HepRandom::setTheSeed(BLTime::timems() & 00053 0x7FFFFFFFL); 00054 // do it only once, to avoid duplication 00055 BLManager::getObject()->setPRNGSeedMethod(NO_SEED); 00056 break; 00057 case NO_SEED: 00058 return; 00059 } 00060 CLHEP::RandGauss::setFlag(false); 00061 G4UniformRand(); // eat one for luck (don't get seed back) 00062 } 00063 00064 /// Utility: setRandomSeedToTrack() sets the random seed for 00065 /// the tracking of an event. 00066 static void setRandomSeedToTrack(int evid) // reference has evid<0 00067 { setRandomSeedToGenerate(evid); 00068 // allow 16 random numbers for generation 00069 for(int i=0; i<16; ++i) 00070 G4UniformRand(); 00071 } 00072 00073 /// getNEvents() returns the # events to process. 00074 virtual int getNEvents() const { return nEvents; } 00075 00076 /// init() will initialize internal variables. 00077 virtual void init() = 0; 00078 00079 /// generateReferenceParticle() generates the reference particle. 00080 /// BLManager calls this once for the TuneParticle during event -2, 00081 /// and once for the ReferenceParticle during event -1. 00082 /// Should always call setRandomSeedToTrack() before returning. 00083 /// Returns true if event generated; false if not. 00084 virtual bool generateReferenceParticle(G4Event *event) = 0; 00085 00086 /// nextBeamEvent() generates the next beam event. 00087 /// If generating randomly, should call setRandomSeedToGenerate() 00088 /// and use no more than 16 random numbers. 00089 /// If read from a file, it should call event->SetEventID(). 00090 /// Should always call setRandomSeedToTrack() before returning. 00091 /// Returns true if event generated; false if no more events. 00092 virtual bool nextBeamEvent(G4Event *event) = 0; 00093 00094 /// summary() will print a summary, if necessary. 00095 virtual void summary() { } 00096 }; 00097 00098 #endif// BLBEAM_HH