Skip to content

Commit

Permalink
Included the text output module into the Lpair-like steering cards pa…
Browse files Browse the repository at this point in the history
…rser, switch to include the cepgen banner and/or variables list into the output
  • Loading branch information
forthommel committed Jul 14, 2019
1 parent ddf03da commit 507f8cc
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 27 deletions.
2 changes: 2 additions & 0 deletions Cards/legacy/lpair.card
Expand Up @@ -19,4 +19,6 @@ MXMX 1000.0
#THMX 180.
XIMN 0.02
XIMX 0.15
#OUTP lhef
OUTP text

4 changes: 3 additions & 1 deletion Cards/lpair_cfg.py
Expand Up @@ -27,7 +27,9 @@
#),
)

output = cepgen.Module('text', variables = ['m(4)', 'pt(4)', 'xi(ob1)'])
#--- example of an output module parameterisation
#output = cepgen.Module('text', variables = ['m(4)'])
#output = cepgen.Module('lhef', output = 'test.lhe')

#--- let the user specify the run conditions
from Config.generator_cff import generator
Expand Down
11 changes: 11 additions & 0 deletions CepGen/Cards/LpairHandler.cpp
Expand Up @@ -6,6 +6,7 @@

#include "CepGen/Processes/ProcessesHandler.h"
#include "CepGen/Hadronisers/HadronisersHandler.h"
#include "CepGen/IO/ExportHandler.h"
#include "CepGen/StructureFunctions/StructureFunctions.h"

#include "CepGen/Physics/GluonGrid.h"
Expand Down Expand Up @@ -89,6 +90,14 @@ namespace cepgen
params_.hadroniser()->setParameters( params_ );
}

//--- parse the output module name
if ( !out_mod_name_.empty() ) {
ParametersList outm;
if ( !out_file_name_.empty() )
outm.set<std::string>( "filename", out_file_name_ );
params_.setOutputModule( cepgen::io::ExportHandler::get().build( out_mod_name_, outm ) );
}

if ( m_params.count( "IEND" ) )
setValue<bool>( "IEND", ( std::stoi( m_params["IEND"] ) > 1 ) );

Expand Down Expand Up @@ -116,6 +125,8 @@ namespace cepgen
registerParameter<std::string>( "PROC", "Process name to simulate", &proc_name_ );
registerParameter<std::string>( "ITYP", "Integration algorithm", &integr_type_ );
registerParameter<std::string>( "HADR", "Hadronisation algorithm", &hadr_name_ );
registerParameter<std::string>( "OUTP", "Output module", &out_mod_name_ );
registerParameter<std::string>( "OUTF", "Output file name", &out_file_name_ );
registerParameter<std::string>( "KMRG", "KMR grid interpolation path", &kmr_grid_path_ );

//-------------------------------------------------------------------------------------------
Expand Down
5 changes: 4 additions & 1 deletion CepGen/Cards/LpairHandler.h
Expand Up @@ -52,7 +52,10 @@ namespace cepgen
std::shared_ptr<ParametersList> proc_params_;
int str_fun_, sr_type_;
double xi_min_, xi_max_;
std::string proc_name_, hadr_name_, integr_type_, kmr_grid_path_, mstw_grid_path_;
std::string proc_name_, hadr_name_, out_mod_name_;
std::string out_file_name_;
std::string integr_type_;
std::string kmr_grid_path_, mstw_grid_path_;
std::pair<unsigned short,unsigned short> hi_1_, hi_2_;
};

Expand Down
6 changes: 3 additions & 3 deletions CepGen/Core/Version.cpp
Expand Up @@ -5,8 +5,8 @@ namespace cepgen
{
const std::string version()
{
return Form( "%02u.%02u.%02u", ( cepgen_version >> 16 ) & 0xff,
( cepgen_version >> 8 ) & 0xff,
cepgen_version & 0xff );
return Form( "%u.%u.%u", ( cepgen_version >> 16 ) & 0xff,
( cepgen_version >> 8 ) & 0xff,
cepgen_version & 0xff );
}
}
30 changes: 15 additions & 15 deletions CepGen/IO/GenericExportHandler.cpp
Expand Up @@ -20,51 +20,51 @@ namespace cepgen
{}

std::string
GenericExportHandler::banner( const Parameters& params )
GenericExportHandler::banner( const Parameters& params, const std::string& prep )
{
std::ostringstream os;
os
<< " ***** Sample generated with CepGen v" << version() << " *****\n"
<< " * process: " << params.processName() << " (" << params.kinematics.mode << ")\n";
<< prep << " ***** Sample generated with CepGen v" << version() << " *****\n"
<< prep << " * process: " << params.processName() << " (" << params.kinematics.mode << ")\n";
if ( params.kinematics.mode != KinematicsMode::ElasticElastic ) {
os << " * structure functions: " << params.kinematics.structure_functions->description() << "\n";
os << prep << " * structure functions: " << params.kinematics.structure_functions->description() << "\n";
if ( !params.hadroniserName().empty() )
os << " * hadroniser: " << params.hadroniserName() << "\n";
os << prep << " * hadroniser: " << params.hadroniserName() << "\n";
}
os
<< " *--- incoming state\n";
<< prep << " *--- incoming state\n";
if ( params.kinematics.cuts.initial.q2.valid() )
os
<< " * Q2 range (GeV2): "
<< prep << " * Q2 range (GeV2): "
<< params.kinematics.cuts.initial.q2 << "\n";
if ( params.kinematics.mode != KinematicsMode::ElasticElastic
&& params.kinematics.cuts.remnants.mass_single.valid() )
os
<< " * remnants mass range (GeV/c2): "
<< prep << " * remnants mass range (GeV/c2): "
<< params.kinematics.cuts.remnants.mass_single << "\n";
os << " *--- central system\n";
os << prep << " *--- central system\n";
if ( params.kinematics.cuts.central.pt_single.valid() )
os
<< " * single particle pt (GeV/c): "
<< prep << " * single particle pt (GeV/c): "
<< params.kinematics.cuts.central.pt_single << "\n";
if ( params.kinematics.cuts.central.energy_single.valid() )
os
<< " * single particle energy (GeV): "
<< prep << " * single particle energy (GeV): "
<< params.kinematics.cuts.central.energy_single << "\n";
if ( params.kinematics.cuts.central.eta_single.valid() )
os
<< " * single particle eta: "
<< prep << " * single particle eta: "
<< params.kinematics.cuts.central.eta_single << "\n";
if ( params.kinematics.cuts.central.pt_sum.valid() )
os
<< " * total pt (GeV/c): "
<< prep << " * total pt (GeV/c): "
<< params.kinematics.cuts.central.mass_sum << "\n";
if ( params.kinematics.cuts.central.mass_sum.valid() )
os
<< " * total invariant mass (GeV/c2): "
<< prep << " * total invariant mass (GeV/c2): "
<< params.kinematics.cuts.central.mass_sum << "\n";
os
<< " **************************************************";
<< prep << " **************************************************";
return os.str();
}
}
Expand Down
2 changes: 1 addition & 1 deletion CepGen/IO/GenericExportHandler.h
Expand Up @@ -33,7 +33,7 @@ namespace cepgen
virtual void operator<<( const Event& ) = 0;

protected:
static std::string banner( const Parameters& );
static std::string banner( const Parameters&, const std::string& prep = "" );
/// Module unique name
const std::string name_;
/// Event index
Expand Down
20 changes: 14 additions & 6 deletions CepGen/IO/TextHandler.cpp
Expand Up @@ -4,6 +4,7 @@
#include "CepGen/Core/ParametersList.h"
#include "CepGen/Event/Event.h"
#include "CepGen/Parameters.h"
#include "CepGen/Version.h"

#include <fstream>
#include <regex>
Expand Down Expand Up @@ -36,14 +37,16 @@ namespace cepgen
static constexpr double INVALID_OUTPUT = -999.;

std::ofstream file_;
std::vector<std::string> variables_;
const std::vector<std::string> variables_;
const bool print_banner_;

//--- variables definition
typedef std::pair<unsigned short,std::string> IndexedVariable;
std::unordered_map<short,std::vector<IndexedVariable> > variables_per_id_;
std::unordered_map<Particle::Role,std::vector<IndexedVariable> > variables_per_role_;
std::vector<IndexedVariable> variables_for_event_;
unsigned short num_vars_;
std::ostringstream oss_vars_;

//--- auxiliary helper maps
const std::unordered_map<std::string,Particle::Role> role_str_ = {
Expand Down Expand Up @@ -79,13 +82,15 @@ namespace cepgen

TextHandler::TextHandler( const ParametersList& params ) :
GenericExportHandler( "text" ),
file_( params.get<std::string>( "filename", "output.txt" ) ),
variables_( params.get<std::vector<std::string> >( "variables" ) ),
file_ ( params.get<std::string>( "filename", "output.txt" ) ),
variables_ ( params.get<std::vector<std::string> >( "variables" ) ),
print_banner_( params.get<bool>( "saveBanner", true ) ),
num_vars_( 0 )
{
std::smatch sm;
oss_vars_.clear();
std::string sep;
file_ << "# ";
oss_vars_ << "# ";
for ( const auto& var : variables_ ) {
if ( std::regex_match( var, sm, rgx_select_id_ ) )
variables_per_id_[stod( sm[2].str() )].emplace_back( std::make_pair( num_vars_, sm[1].str() ) );
Expand All @@ -101,10 +106,10 @@ namespace cepgen
}
else // event-level variables
variables_for_event_.emplace_back( std::make_pair( num_vars_, var ) );
file_ << sep << var, sep = "\t";
oss_vars_ << sep << var, sep = "\t";
++num_vars_;
}
file_ << "\n";
oss_vars_ << "\n";
}

TextHandler::~TextHandler()
Expand All @@ -116,6 +121,9 @@ namespace cepgen
TextHandler::initialise( const Parameters& params )
{
sqrts_ = params.kinematics.sqrtS();
if ( print_banner_ )
file_ << banner( params, "#" ) << "\n";
file_ << oss_vars_.str();
}

void
Expand Down

0 comments on commit 507f8cc

Please sign in to comment.