Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HepMCEx01/src/HepMCG4PythiaMessenger.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 /// \file eventgenerator/HepMC/HepMCEx01/src/HepMCG4PythiaMessenger.cc
27 /// \brief Implementation of the HepMCG4PythiaMessenger class
28 //
29 // $Id: HepMCG4PythiaMessenger.cc 77801 2013-11-28 13:33:20Z gcosmo $
30 //
31 
32 #ifdef G4LIB_USE_PYTHIA
33 
34 #include <sstream>
35 #include <fstream>
36 #include "G4UIdirectory.hh"
38 #include "G4UIcmdWithAString.hh"
39 #include "G4UIcmdWithAnInteger.hh"
40 #include "HepMCG4PythiaMessenger.hh"
41 #include "HepMCG4PythiaInterface.hh"
42 
43 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
45  : gen(agen)
46 {
47  dir= new G4UIdirectory("/generator/pythia/");
48  dir-> SetGuidance("Commands for Pythia event generation");
49 
50  verbose= new G4UIcmdWithAnInteger("/generator/pythia/verbose",this);
51  verbose-> SetGuidance("set verbose level");
52  verbose-> SetParameterName("verboseLevel", false, false);
53  verbose-> SetRange("verboseLevel>=0 && verboseLevel<=2");
54 
55  mpylist= new G4UIcmdWithAnInteger("/generator/pythia/pylist",this);
56  mpylist-> SetGuidance("set argument of pylist (not called if mlist=0)");
57  mpylist-> SetParameterName("mlist", false, false);
58  mpylist-> SetRange("mlist>=0 && mlist<=3");
59 
60  print= new G4UIcmdWithoutParameter("/generator/pythia/print", this);
61  print-> SetGuidance("print user information.");
62 
63  cpyinit= new G4UIcommand("/generator/pythia/pyinit", this);
64  cpyinit-> SetGuidance("call PYINIT");
65  G4UIparameter* frame=
66  new G4UIparameter("frame of the experiment", 's', false);
67  cpyinit-> SetParameter(frame);
68  G4UIparameter* beam= new G4UIparameter("beam particle", 's', false);
69  cpyinit-> SetParameter(beam);
70  G4UIparameter* target= new G4UIparameter("target particle", 's', false);
71  cpyinit-> SetParameter(target);
72  G4UIparameter* win= new G4UIparameter("energy of system (GeV)", 'd', false);
73  cpyinit-> SetParameter(win);
74 
75  cpystat= new G4UIcmdWithAnInteger("/generator/pythia/pystat", this);
76  cpystat-> SetGuidance("call PYSTAT");
77  cpystat-> SetParameterName("mstat", false, false);
78  cpystat-> SetRange("mstat>=1 && mstat<=5");
79 
80  cpygive= new G4UIcommand("/generator/pythia/pygive",this);
81  cpygive-> SetGuidance("call PYGIVE");
82  G4UIparameter* parameter= new G4UIparameter ("Parameter", 's', false);
83  cpygive-> SetParameter(parameter);
84 
85  setUserParameters=
86  new G4UIcmdWithoutParameter("/generator/pythia/setUserParameters",this);
87  setUserParameters->
88  SetGuidance("Set user parameters in the Pythia common blocks");
89 
90  setSeed= new G4UIcmdWithAnInteger("/generator/pythia/setSeed", this);
91  setSeed-> SetGuidance("set initial seed.");
92 
93  cpyrget= new G4UIcommand("/generator/pythia/pyrget", this);
94  cpyrget-> SetGuidance("call PYRGET");
95  G4UIparameter* lun, *move;
96  lun= new G4UIparameter("logical file number", 'i', false);
97  cpyrget-> SetParameter(lun);
98  move= new G4UIparameter("choice of adding a new record", 'i', true);
99  move-> SetDefaultValue(-1);
100  cpyrget-> SetParameter(move);
101 
102  cpyrset= new G4UIcommand("/generator/pythia/pyrset", this);
103  cpyrset-> SetGuidance("call PYRSET");
104  lun= new G4UIparameter("logical file number", 'i', false);
105  cpyrset-> SetParameter(lun);
106  move= new G4UIparameter("choice of adding a new record", 'i', true);
107  move-> SetDefaultValue(0);
108  cpyrset-> SetParameter(move);
109 
110  printRandomStatus=
111  new G4UIcmdWithAString("/generator/pythia/printRandomStatus", this);
112  printRandomStatus-> SetGuidance("print random number status.");
113  printRandomStatus-> SetParameterName("filename", true, false);
114  printRandomStatus-> SetDefaultValue("std::cout");
115 }
116 
117 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
119 {
120  delete verbose;
121  delete mpylist;
122  delete print;
123  delete cpyinit;
124  delete cpystat;
125  delete cpygive;
126  delete setUserParameters;
127  delete setSeed;
128  delete cpyrget;
129  delete cpyrset;
130  delete printRandomStatus;
131 
132  delete dir;
133 }
134 
135 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
137  G4String newValues)
138 {
139  if(command == verbose) { // /verbose ...
140  G4int level= verbose-> GetNewIntValue(newValues);
141  gen-> SetVerboseLevel(level);
142 
143  } else if (command == mpylist) { // /mpylist ...
144  G4int mlist= mpylist-> GetNewIntValue(newValues);
145  gen-> SetPylist(mlist);
146 
147  } else if (command == print) { // /print ...
148  gen-> Print();
149 
150  } else if (command == cpyinit) { // /pyinit ...
151  const char* strvaluelist= newValues.c_str();
152  std::istringstream is(strvaluelist);
153  G4String sframe, sbeam, starget; G4double dwin;
154  is >> sframe >> sbeam >> starget >> dwin;
155  gen-> CallPyinit(sframe, sbeam, starget, dwin);
156 
157  } else if (command == cpystat) { // /pystat ...
158  G4int imod= cpystat-> GetNewIntValue(newValues);
159  gen-> CallPystat(imod);
160 
161  } else if (command == cpygive) { // /pygive ...
162  G4String s= newValues;
163  gen-> CallPygive(s);
164 
165  } else if (command == setUserParameters) { // /setUserParameters ...
166  gen-> SetUserParameters();
167 
168  } else if (command == setSeed) { // /setSeed ...
169  G4int iseed= setSeed-> GetNewIntValue(newValues);
170  gen-> SetRandomSeed(iseed);
171 
172  } else if (command == cpyrget) { // /pyrget ...
173  const char* strvaluelist= newValues.c_str();
174  std::istringstream is(strvaluelist);
175  G4int lun, move;
176  is >> lun >> move;
177  gen-> CallPyrget(lun, move);
178 
179  } else if (command == cpyrset) { // /pyrset ...
180  const char* strvaluelist= newValues.c_str();
181  std::istringstream is(strvaluelist);
182  G4int lun, move;
183  is >> lun >> move;
184  gen-> CallPyrset(lun, move);
185 
186  } else if (command == printRandomStatus) { // /printRandomStatus ...
187  G4String s= newValues;
188  if (newValues == "std::cout") {
189  gen-> PrintRandomStatus();
190  } else {
191  // to a file (overwrite mode)
192  std::ofstream ofs;
193  ofs.open(s.c_str(), std::ios::out);
194  //ofs.open(randomStatusFileName.c_str(), std::ios::out|std::ios::app);
195  ofs.setf(std::ios::fixed | std::ios::showpoint);
196  gen-> PrintRandomStatus(ofs);
197  ofs.close();
198  }
199  }
200 }
201 
202 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
204 {
205  G4String cv;
206  if (command == verbose) {
207  cv= verbose-> ConvertToString(gen->GetVerboseLevel());
208  } else if (command == mpylist) {
209  cv= verbose-> ConvertToString(gen->GetPylist());
210  }
211  return cv;
212 }
213 
214 #endif
void SetNewValue(G4UIcommand *command, G4String newValues)
const XML_Char * s
G4String GetCurrentValue(G4UIcommand *command)
A generic interface class with Pythia event generator via HepMC.
const XML_Char * target
int G4int
Definition: G4Types.hh:78
HepMCG4PythiaMessenger(HepMCG4PythiaInterface *agen)
double G4double
Definition: G4Types.hh:76
void print(const std::vector< T > &data)
Definition: DicomRun.hh:111
void Print(G4Element &ele)
Definition: pyG4Element.cc:56