31 #include "G4ParticleGun.hh"
32 #include "G4ParticleTable.hh"
33 #include "G4ParticleDefinition.hh"
34 #include "Randomize.hh"
44 #include "G4Threading.hh"
46 #ifdef G4MULTITHREADED
47 #include "G4AutoLock.hh"
48 namespace { G4Mutex buildMutex = G4MUTEX_INITIALIZER; G4Mutex runMutex = G4MUTEX_INITIALIZER; }
58 G4VUserPrimaryGeneratorAction(),
59 theChainOfPrimaryEvents(0x0),
64 fPr =
new SBRPEvent(); fEntries = fCurrentEntry = 0L;
93 G4VUserPrimaryGeneratorAction(),
94 theChainOfPrimaryEvents(0x0),
99 fPr =
new SBRPEvent(); fEntries = fCurrentEntry = 0L;
112 G4ThreeVector particle_position(0,0,0), particle_momentum_direction;
114 G4PrimaryParticle* particle = 0x0; G4PrimaryVertex* vertex =
new G4PrimaryVertex(particle_position, 0);
118 G4AutoLock lock(&runMutex);
120 if ( !(fCurrentEntry < fEntries) )
122 theChainOfPrimaryEvents->GetEntry(fCurrentEntry++);
127 for (G4int i = 0; i < fPr->
GetNbHits(); i++) {
132 new G4PrimaryParticle(aprimary->
fPDG);
138 particle->Set4Momentum(aprimary->
fPX*aprimary->
fE*CLHEP::MeV,
139 aprimary->
fPY*aprimary->
fE*CLHEP::MeV,
140 aprimary->
fPZ*aprimary->
fE*CLHEP::MeV,
141 aprimary->
fE*CLHEP::MeV);
155 particle->SetWeight(1);
157 vertex->SetPrimary(particle);
159 anEvent->AddPrimaryVertex(vertex);
224 G4cout << G4endl <<
" ------ INFO ------ from toROOTGPSPrimaryGeneratorAction::GetInputFiles " << (
void*)(
this) << G4endl;
227 std::ostringstream fullfilename;
228 fullfilename.clear();
231 G4AutoLock lock(&buildMutex);
233 thread_id = G4Threading::G4GetThreadId();
234 fullfilename << filename <<
"_Thread" << std::setfill(
'0') << std::setw(2) << thread_id <<
".gene";
236 fullfilename << filename <<
".gene";
240 ifstream file; file.open(fullfilename.str().data());
241 if ( file.is_open() == false ) {
242 G4cout <<
" ** WARNING ** cannot open file " << fullfilename <<
" (Default parameters are used) "<< G4endl;
247 std::string aline, key, rfile; std::getline (file,aline);
248 while ( file.good() ) {
250 if ( aline[0] ==
'#' ) {
251 std::getline (file,aline);
256 std::istringstream decode(aline);
257 decode >> key >> rfile;
259 if ( key ==
"tree_name" ) {
260 theChainOfPrimaryEvents =
new TChain(rfile.data());
261 std::getline (file,aline);
263 G4cout <<
" ==> TTree expected name is " << rfile.data() << G4endl;
267 if ( theChainOfPrimaryEvents == 0x0 ) {
268 theChainOfPrimaryEvents =
new TChain(
"ROOTGPS");
269 G4cout <<
" ==> TTree expected name is ROOTGPS " << G4endl;
271 Int_t added = theChainOfPrimaryEvents->AddFile(rfile.data());
273 G4cout <<
" ==> add the file to TChain " << rfile.data() << G4endl;
276 G4cout <<
" !!! Cannot add the file to TChain " << rfile.data() << G4endl;
278 std::getline (file,aline);
282 theChainOfPrimaryEvents->SetBranchAddress(
"Pr.",&fPr);
283 fEntries = theChainOfPrimaryEvents->GetEntries();
285 G4cout <<
" ------ END ------ from toROOTGPSPrimaryGeneratorAction::GetInputFiles " << G4endl << G4endl;
288 #include "G4UIdirectory.hh"
289 #include "G4UIcmdWithAString.hh"
293 theDirectory =
new G4UIdirectory(
"/toROOTGPS/generator/");
294 theDirectory->SetGuidance(
"To modify generator's parameters");
296 resetParametersCmd =
new G4UIcmdWithAString(
"/toROOTGPS/generator/file",
this);
297 resetParametersCmd->SetGuidance(
"To load new parameters of toROOTGPSPrimaryGeneratorAction from a file");
298 resetParametersCmd->SetGuidance(
"Required parameters: one valid filename (string)");
299 resetParametersCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
305 delete resetParametersCmd;
310 if( command == resetParametersCmd )
virtual ~toROOTGPSPrimaryGeneratorAction()
virtual void GeneratePrimaries(G4Event *anEvent)
toROOTGPSPrimaryGeneratorActionMessanger(toROOTGPSPrimaryGeneratorAction *)
SToGS Base Root Polarized Hit.
toROOTGPSPrimaryGeneratorActionMessanger * theMessanger
void GetInputFiles(G4String filename="setup/toROOTGPS")
from a given file, it reads the characteristics of the gamma cascade
~toROOTGPSPrimaryGeneratorActionMessanger()
first step to a general file (ROOT) GPS generator in which events are read from files and/or generata...
void SetNewValue(G4UIcommand *, G4String)
Int_t GetNbHits() const
helper function
Messanger class for ParisBasicPrimaryGenerator.
SBRPHit * GetHit(Int_t)
to get a Hit
toROOTGPSPrimaryGeneratorAction()