source: trunk/examples/extended/eventgenerator/HepMC/HepMCEx02/src/HepMCG4PythiaMessenger.cc

Last change on this file was 807, checked in by garnier, 16 years ago

update

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