Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-04-10 08:05:41

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 /// \file eventgenerator/HepMC/HepMCEx01/src/HepMCG4PythiaMessenger.cc
0027 /// \brief Implementation of the HepMCG4PythiaMessenger class
0028 //
0029 //
0030 
0031 #ifdef G4LIB_USE_PYTHIA
0032 
0033 #  include "HepMCG4PythiaMessenger.hh"
0034 
0035 #  include "HepMCG4PythiaInterface.hh"
0036 
0037 #  include "G4UIcmdWithAString.hh"
0038 #  include "G4UIcmdWithAnInteger.hh"
0039 #  include "G4UIcmdWithoutParameter.hh"
0040 #  include "G4UIdirectory.hh"
0041 
0042 #  include <fstream>
0043 #  include <sstream>
0044 
0045 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0046 HepMCG4PythiaMessenger::HepMCG4PythiaMessenger(HepMCG4PythiaInterface* agen) : gen(agen)
0047 {
0048   dir = new G4UIdirectory("/generator/pythia/");
0049   dir->SetGuidance("Commands for Pythia event generation");
0050 
0051   verbose = new G4UIcmdWithAnInteger("/generator/pythia/verbose", this);
0052   verbose->SetGuidance("set verbose level");
0053   verbose->SetParameterName("verboseLevel", false, false);
0054   verbose->SetRange("verboseLevel>=0 && verboseLevel<=2");
0055 
0056   mpylist = new G4UIcmdWithAnInteger("/generator/pythia/pylist", this);
0057   mpylist->SetGuidance("set argument of pylist (not called if mlist=0)");
0058   mpylist->SetParameterName("mlist", false, false);
0059   mpylist->SetRange("mlist>=0 && mlist<=3");
0060 
0061   print = new G4UIcmdWithoutParameter("/generator/pythia/print", this);
0062   print->SetGuidance("print user information.");
0063 
0064   cpyinit = new G4UIcommand("/generator/pythia/pyinit", this);
0065   cpyinit->SetGuidance("call PYINIT");
0066   G4UIparameter* frame = new G4UIparameter("frame of the experiment", 's', false);
0067   cpyinit->SetParameter(frame);
0068   G4UIparameter* beam = new G4UIparameter("beam particle", 's', false);
0069   cpyinit->SetParameter(beam);
0070   G4UIparameter* target = new G4UIparameter("target particle", 's', false);
0071   cpyinit->SetParameter(target);
0072   G4UIparameter* win = new G4UIparameter("energy of system (GeV)", 'd', false);
0073   cpyinit->SetParameter(win);
0074 
0075   cpystat = new G4UIcmdWithAnInteger("/generator/pythia/pystat", this);
0076   cpystat->SetGuidance("call PYSTAT");
0077   cpystat->SetParameterName("mstat", false, false);
0078   cpystat->SetRange("mstat>=1 && mstat<=5");
0079 
0080   cpygive = new G4UIcommand("/generator/pythia/pygive", this);
0081   cpygive->SetGuidance("call PYGIVE");
0082   G4UIparameter* parameter = new G4UIparameter("Parameter", 's', false);
0083   cpygive->SetParameter(parameter);
0084 
0085   setUserParameters = new G4UIcmdWithoutParameter("/generator/pythia/setUserParameters", this);
0086   setUserParameters->SetGuidance("Set user parameters in the Pythia common blocks");
0087 
0088   setSeed = new G4UIcmdWithAnInteger("/generator/pythia/setSeed", this);
0089   setSeed->SetGuidance("set initial seed.");
0090 
0091   cpyrget = new G4UIcommand("/generator/pythia/pyrget", this);
0092   cpyrget->SetGuidance("call PYRGET");
0093   G4UIparameter *lun, *move;
0094   lun = new G4UIparameter("logical file number", 'i', false);
0095   cpyrget->SetParameter(lun);
0096   move = new G4UIparameter("choice of adding a new record", 'i', true);
0097   move->SetDefaultValue(-1);
0098   cpyrget->SetParameter(move);
0099 
0100   cpyrset = new G4UIcommand("/generator/pythia/pyrset", this);
0101   cpyrset->SetGuidance("call PYRSET");
0102   lun = new G4UIparameter("logical file number", 'i', false);
0103   cpyrset->SetParameter(lun);
0104   move = new G4UIparameter("choice of adding a new record", 'i', true);
0105   move->SetDefaultValue(0);
0106   cpyrset->SetParameter(move);
0107 
0108   printRandomStatus = new G4UIcmdWithAString("/generator/pythia/printRandomStatus", this);
0109   printRandomStatus->SetGuidance("print random number status.");
0110   printRandomStatus->SetParameterName("filename", true, false);
0111   printRandomStatus->SetDefaultValue("std::cout");
0112 }
0113 
0114 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0115 HepMCG4PythiaMessenger::~HepMCG4PythiaMessenger()
0116 {
0117   delete verbose;
0118   delete mpylist;
0119   delete print;
0120   delete cpyinit;
0121   delete cpystat;
0122   delete cpygive;
0123   delete setUserParameters;
0124   delete setSeed;
0125   delete cpyrget;
0126   delete cpyrset;
0127   delete printRandomStatus;
0128 
0129   delete dir;
0130 }
0131 
0132 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0133 void HepMCG4PythiaMessenger::SetNewValue(G4UIcommand* command, G4String newValues)
0134 {
0135   if (command == verbose) {  // /verbose ...
0136     G4int level = verbose->GetNewIntValue(newValues);
0137     gen->SetVerboseLevel(level);
0138   }
0139   else if (command == mpylist) {  // /mpylist ...
0140     G4int mlist = mpylist->GetNewIntValue(newValues);
0141     gen->SetPylist(mlist);
0142   }
0143   else if (command == print) {  // /print ...
0144     gen->Print();
0145   }
0146   else if (command == cpyinit) {  // /pyinit ...
0147     const char* strvaluelist = newValues.c_str();
0148     std::istringstream is(strvaluelist);
0149     G4String sframe, sbeam, starget;
0150     G4double dwin;
0151     is >> sframe >> sbeam >> starget >> dwin;
0152     gen->CallPyinit(sframe, sbeam, starget, dwin);
0153   }
0154   else if (command == cpystat) {  // /pystat ...
0155     G4int imod = cpystat->GetNewIntValue(newValues);
0156     gen->CallPystat(imod);
0157   }
0158   else if (command == cpygive) {  // /pygive ...
0159     G4String s = newValues;
0160     gen->CallPygive(s);
0161   }
0162   else if (command == setUserParameters) {  // /setUserParameters ...
0163     gen->SetUserParameters();
0164   }
0165   else if (command == setSeed) {  // /setSeed ...
0166     G4int iseed = setSeed->GetNewIntValue(newValues);
0167     gen->SetRandomSeed(iseed);
0168   }
0169   else if (command == cpyrget) {  // /pyrget ...
0170     const char* strvaluelist = newValues.c_str();
0171     std::istringstream is(strvaluelist);
0172     G4int lun, move;
0173     is >> lun >> move;
0174     gen->CallPyrget(lun, move);
0175   }
0176   else if (command == cpyrset) {  // /pyrset ...
0177     const char* strvaluelist = newValues.c_str();
0178     std::istringstream is(strvaluelist);
0179     G4int lun, move;
0180     is >> lun >> move;
0181     gen->CallPyrset(lun, move);
0182   }
0183   else if (command == printRandomStatus) {  // /printRandomStatus ...
0184     G4String s = newValues;
0185     if (newValues == "std::cout") {
0186       gen->PrintRandomStatus();
0187     }
0188     else {
0189       // to a file (overwrite mode)
0190       std::ofstream ofs;
0191       ofs.open(s.c_str(), std::ios::out);
0192       // ofs.open(randomStatusFileName.c_str(), std::ios::out|std::ios::app);
0193       ofs.setf(std::ios::fixed | std::ios::showpoint);
0194       gen->PrintRandomStatus(ofs);
0195       ofs.close();
0196     }
0197   }
0198 }
0199 
0200 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0201 G4String HepMCG4PythiaMessenger::GetCurrentValue(G4UIcommand* command)
0202 {
0203   G4String cv;
0204   if (command == verbose) {
0205     cv = verbose->ConvertToString(gen->GetVerboseLevel());
0206   }
0207   else if (command == mpylist) {
0208     cv = verbose->ConvertToString(gen->GetPylist());
0209   }
0210   return cv;
0211 }
0212 
0213 #endif