diff --git a/examples/AnalysisPrint.cc b/examples/AnalysisPrint.cc index 4c0d801..522fe2b 100644 --- a/examples/AnalysisPrint.cc +++ b/examples/AnalysisPrint.cc @@ -1,78 +1,78 @@ //! HEJ analysis to output the cross section to a file #include #include #include #include #include #include "HEJ/Analysis.hh" #include "HEJ/Event.hh" #include "yaml-cpp/yaml.h" #include "LHEF/LHEF.h" namespace { class AnalysisPrint: public HEJ::Analysis { public: AnalysisPrint(YAML::Node const & config, LHEF::HEPRUP const & heprup): xsection_{0.}, xsection_error_{0.}, outfile_{config["output"].as()}, generators_{heprup.generators} {} void fill( HEJ::Event const & event, HEJ::Event const & /* FO_event */ ) override { const double wt = event.central().weight; xsection_ += wt; xsection_error_ += wt*wt; // this error estimate is too small } bool pass_cuts( HEJ::Event const & /* event */, HEJ::Event const & /* FO_event */ ) override { return true; } void scale(double xsscale) override { - // used to scale the cross sections and histograms before .finalise in case the - // normalisation is unknown until the end of the run + // used to scale the cross sections and histograms before .finalise in case the + // normalisation is unknown until the end of the run xsection_*=xsscale; xsection_error_*=xsscale*xsscale; - } + } void finalise() override { // print to screen std::cout << "Generated with:\n"; for(auto const & generator: generators_) std::cout << generator.name << " " << generator.version << "\n"; std::cout << "cross section: " << xsection_ << " +- " << std::sqrt(xsection_error_) << std::endl; // print to file std::ofstream fout{outfile_}; fout << "Generated with\n"; for(auto const & generator: generators_) fout << generator.name << " " << generator.version << "\n"; fout << "cross section: " << xsection_ << " +- " << std::sqrt(xsection_error_) << std::endl; } private: double xsection_, xsection_error_; std::string outfile_; std::vector generators_; }; } extern "C" __attribute__((visibility("default"))) std::unique_ptr make_analysis( YAML::Node const & config, LHEF::HEPRUP const & heprup ){ return std::make_unique(config, heprup); }