HGCal Test Beam  03a93d6239a951948e06fb3ef8dae4cbdebfad30
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 // ====================================================================
30 //
31 // HepMCG4PythiaMessenger.cc
32 // $Id$
33 //
34 // ====================================================================
35 
36 #ifdef G4LIB_USE_PYTHIA
37 
38 #include "HepMCG4PythiaMessenger.hh"
39 #include "HepMCG4PythiaInterface.hh"
40 
41 #include <sstream>
42 #include <fstream>
43 
44 #include "G4UIdirectory.hh"
45 #include "G4UIcmdWithoutParameter.hh"
46 #include "G4UIcmdWithAString.hh"
47 #include "G4UIcmdWithAnInteger.hh"
48 
49 ////////////////////////////////////////////////////////////////////////////
50 HepMCG4PythiaMessenger::HepMCG4PythiaMessenger(HepMCG4PythiaInterface* agen)
51  : gen(agen)
52 ////////////////////////////////////////////////////////////////////////////
53 {
54  dir = new G4UIdirectory("/generator/pythia/");
55  dir-> SetGuidance("Commands for Pythia event generation");
56 
57  verbose = new G4UIcmdWithAnInteger("/generator/pythia/verbose", this);
58  verbose-> SetGuidance("set verbose level");
59  verbose-> SetParameterName("verboseLevel", false, false);
60  verbose-> SetRange("verboseLevel>=0 && verboseLevel<=2");
61 
62  mpylist = new G4UIcmdWithAnInteger("/generator/pythia/pylist", this);
63  mpylist-> SetGuidance("set argument of pylist (not called if mlist=0)");
64  mpylist-> SetParameterName("mlist", false, false);
65  mpylist-> SetRange("mlist>=0 && mlist<=3");
66 
67  print = new G4UIcmdWithoutParameter("/generator/pythia/print", this);
68  print-> SetGuidance("print user information.");
69 
70  cpyinit = new G4UIcommand("/generator/pythia/pyinit", this);
71  cpyinit-> SetGuidance("call PYINIT");
72  G4UIparameter* frame =
73  new G4UIparameter("frame of the experiment", 's', false);
74  cpyinit-> SetParameter(frame);
75  G4UIparameter* beam = new G4UIparameter("beam particle", 's', false);
76  cpyinit-> SetParameter(beam);
77  G4UIparameter* target = new G4UIparameter("target particle", 's', false);
78  cpyinit-> SetParameter(target);
79  G4UIparameter* win = new G4UIparameter("energy of system (GeV)", 'd', false);
80  cpyinit-> SetParameter(win);
81 
82  cpystat = new G4UIcmdWithAnInteger("/generator/pythia/pystat", this);
83  cpystat-> SetGuidance("call PYSTAT");
84  cpystat-> SetParameterName("mstat", false, false);
85  cpystat-> SetRange("mstat>=1 && mstat<=5");
86 
87  cpygive = new G4UIcommand("/generator/pythia/pygive", this);
88  cpygive-> SetGuidance("call PYGIVE");
89  G4UIparameter* parameter = new G4UIparameter ("Parameter", 's', false);
90  cpygive-> SetParameter(parameter);
91 
92  setUserParameters =
93  new G4UIcmdWithoutParameter("/generator/pythia/setUserParameters", this);
94  setUserParameters->
95  SetGuidance("Set user parameters in the Pythia common blocks");
96 
97  setSeed = new G4UIcmdWithAnInteger("/generator/pythia/setSeed", this);
98  setSeed-> SetGuidance("set initial seed.");
99 
100  cpyrget = new G4UIcommand("/generator/pythia/pyrget", this);
101  cpyrget-> SetGuidance("call PYRGET");
102  G4UIparameter* lun, *move;
103  lun = new G4UIparameter("logical file number", 'i', false);
104  cpyrget-> SetParameter(lun);
105  move = new G4UIparameter("choice of adding a new record", 'i', true);
106  move-> SetDefaultValue(-1);
107  cpyrget-> SetParameter(move);
108 
109  cpyrset = new G4UIcommand("/generator/pythia/pyrset", this);
110  cpyrset-> SetGuidance("call PYRSET");
111  lun = new G4UIparameter("logical file number", 'i', false);
112  cpyrset-> SetParameter(lun);
113  move = new G4UIparameter("choice of adding a new record", 'i', true);
114  move-> SetDefaultValue(0);
115  cpyrset-> SetParameter(move);
116 
117  printRandomStatus =
118  new G4UIcmdWithAString("/generator/pythia/printRandomStatus", this);
119  printRandomStatus-> SetGuidance("print random number status.");
120  printRandomStatus-> SetParameterName("filename", true, false);
121  printRandomStatus-> SetDefaultValue("std::cout");
122 }
123 
124 /////////////////////////////////////////////////
125 HepMCG4PythiaMessenger::~HepMCG4PythiaMessenger()
126 /////////////////////////////////////////////////
127 {
128  delete verbose;
129  delete mpylist;
130  delete print;
131  delete cpyinit;
132  delete cpystat;
133  delete cpygive;
134  delete setUserParameters;
135  delete setSeed;
136  delete cpyrget;
137  delete cpyrset;
138  delete printRandomStatus;
139 
140  delete dir;
141 }
142 
143 //////////////////////////////////////////////////////////////
144 void HepMCG4PythiaMessenger::SetNewValue(G4UIcommand* command,
145  G4String newValues)
146 //////////////////////////////////////////////////////////////
147 {
148  if(command == verbose) { // /verbose ...
149  G4int level = verbose-> GetNewIntValue(newValues);
150  gen-> SetVerboseLevel(level);
151 
152  } else if (command == mpylist) { // /mpylist ...
153  G4int mlist = mpylist-> GetNewIntValue(newValues);
154  gen-> SetPylist(mlist);
155 
156  } else if (command == print) { // /print ...
157  gen-> Print();
158 
159  } else if (command == cpyinit) { // /pyinit ...
160  const char* strvaluelist = newValues.c_str();
161  std::istringstream is(strvaluelist);
162  G4String sframe, sbeam, starget;
163  G4double dwin;
164  is >> sframe >> sbeam >> starget >> dwin;
165  gen-> CallPyinit(sframe, sbeam, starget, dwin);
166 
167  } else if (command == cpystat) { // /pystat ...
168  G4int imod = cpystat-> GetNewIntValue(newValues);
169  gen-> CallPystat(imod);
170 
171  } else if (command == cpygive) { // /pygive ...
172  G4String s = newValues;
173  gen-> CallPygive(s);
174 
175  } else if (command == setUserParameters) { // /setUserParameters ...
176  gen-> SetUserParameters();
177 
178  } else if (command == setSeed) { // /setSeed ...
179  G4int iseed = setSeed-> GetNewIntValue(newValues);
180  gen-> SetRandomSeed(iseed);
181 
182  } else if (command == cpyrget) { // /pyrget ...
183  const char* strvaluelist = newValues.c_str();
184  std::istringstream is(strvaluelist);
185  G4int lun, move;
186  is >> lun >> move;
187  gen-> CallPyrget(lun, move);
188 
189  } else if (command == cpyrset) { // /pyrset ...
190  const char* strvaluelist = newValues.c_str();
191  std::istringstream is(strvaluelist);
192  G4int lun, move;
193  is >> lun >> move;
194  gen-> CallPyrset(lun, move);
195 
196  } else if (command == printRandomStatus) { // /printRandomStatus ...
197  G4String s = newValues;
198  if (newValues == "std::cout") {
199  gen-> PrintRandomStatus();
200  } else {
201  // to a file (overwrite mode)
202  std::ofstream ofs;
203  ofs.open(s.c_str(), std::ios::out);
204  //ofs.open(randomStatusFileName.c_str(), std::ios::out|std::ios::app);
205  ofs.setf(std::ios::fixed | std::ios::showpoint);
206  gen-> PrintRandomStatus(ofs);
207  ofs.close();
208  }
209  }
210 }
211 
212 //////////////////////////////////////////////////////////////////////
213 G4String HepMCG4PythiaMessenger::GetCurrentValue(G4UIcommand* command)
214 //////////////////////////////////////////////////////////////////////
215 {
216  G4String cv;
217  if (command == verbose) {
218  cv = verbose-> ConvertToString(gen->GetVerboseLevel());
219  } else if (command == mpylist) {
220  cv = verbose-> ConvertToString(gen->GetPylist());
221  }
222  return cv;
223 }
224 
225 #endif