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