Page MenuHomeHEPForge

No OneTemporary

diff --git a/examples/AnalysisPrint.cc b/examples/AnalysisPrint.cc
index 82ea137..59cf3e7 100644
--- a/examples/AnalysisPrint.cc
+++ b/examples/AnalysisPrint.cc
@@ -1,69 +1,71 @@
//! HEJ analysis to output the cross section to a file
#include <cmath>
#include <fstream>
#include <iostream>
#include <memory>
#include <string>
#include "HEJ/Analysis.hh"
#include "HEJ/Event.hh"
#include "yaml-cpp/yaml.h"
#include "LHEF/LHEF.h"
-class AnalysisPrint: public HEJ::Analysis {
-public:
- AnalysisPrint(YAML::Node const & config, LHEF::HEPRUP const & heprup):
- xsection_{0.}, xsection_error_{0.},
- outfile_{config["output"].as<std::string>()},
- generators_{heprup.generators}
- {}
+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<std::string>()},
+ 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
- }
+ 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;
- }
+ bool pass_cuts(
+ HEJ::Event const & /* event */,
+ HEJ::Event const & /* FO_event */
+ ) override {
+ return true;
+ }
- 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;
+ 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;
- }
+ // 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<LHEF::Generator> generators_;
-
-};
+ private:
+ double xsection_, xsection_error_;
+ std::string outfile_;
+ std::vector<LHEF::Generator> generators_;
+ };
+}
extern "C"
+__attribute__((visibility("default")))
std::unique_ptr<HEJ::Analysis> make_analysis(
YAML::Node const & config, LHEF::HEPRUP const & heprup
){
return std::make_unique<AnalysisPrint>(config, heprup);
}
diff --git a/examples/AnalysisROOT.cc b/examples/AnalysisROOT.cc
index b5c97a4..7419c9f 100644
--- a/examples/AnalysisROOT.cc
+++ b/examples/AnalysisROOT.cc
@@ -1,84 +1,86 @@
//! Simple HEJ analysis to plot Delta y_{fb} with ROOT
#include <memory> // for std::unique_ptr
#include <iostream> // for std::cout
#include "TFile.h"
#include "TH1.h"
#include "HEJ/Analysis.hh"
#include "HEJ/Event.hh"
#include "HEJ/Version.hh"
namespace YAML {
class Node;
}
namespace LHEF {
class HEPRUP;
}
-
-void Fill2DHistogram(TH1D & h,double x,double wt)
-{
- const int binnumber=h.GetXaxis()->FindBin(x);
- const double binwidth=h.GetXaxis()->GetBinWidth(binnumber);
- h.Fill(x,wt/binwidth);
-}
-
-class AnalysisROOT: public HEJ::Analysis {
-private:
- TFile hfile_;
- TH1D htotal_,hydif_,hyf_,hyb_;
-public:
- AnalysisROOT(
- YAML::Node const & /* config */, LHEF::HEPRUP const & /* heprup */
- ):hfile_{"HEJ.root","RECREATE",
- ("Output from "+HEJ::Version::package_name_full()).c_str()},
- htotal_{"total","total",1,-0.5,.5},
- hydif_{"ydif","ydif",40,0.,10.},
- hyf_{"yf","yf",40,-5.,5.},
- hyb_{"yb","yb",40,-5.,5.}
+namespace {
+ void Fill2DHistogram(TH1D & h,double x,double wt)
{
- // Setup histograms
- htotal_.Sumw2();
- hydif_.Sumw2();
- hyf_.Sumw2();
- hyb_.Sumw2();
+ const int binnumber=h.GetXaxis()->FindBin(x);
+ const double binwidth=h.GetXaxis()->GetBinWidth(binnumber);
+ h.Fill(x,wt/binwidth);
}
- void fill(
- HEJ::Event const & event,
- HEJ::Event const & /* FO_event */
- ) override {
- const double weight=event.central().weight;
- htotal_.Fill(0.0,weight);
- auto const & jets=event.jets(); // jets are sorted in rapidity
- Fill2DHistogram(hydif_,
- fabs(jets.back().rapidity()-jets.front().rapidity()), weight);
- Fill2DHistogram(hyf_, jets.front().rapidity(), weight);
- Fill2DHistogram(hyb_, jets.back().rapidity(), weight);
- }
+ class AnalysisROOT: public HEJ::Analysis {
+ private:
+ TFile hfile_;
+ TH1D htotal_,hydif_,hyf_,hyb_;
+ public:
+ AnalysisROOT(
+ YAML::Node const & /* config */, LHEF::HEPRUP const & /* heprup */
+ ):hfile_{"HEJ.root","RECREATE",
+ ("Output from "+HEJ::Version::package_name_full()).c_str()},
+ htotal_{"total","total",1,-0.5,.5},
+ hydif_{"ydif","ydif",40,0.,10.},
+ hyf_{"yf","yf",40,-5.,5.},
+ hyb_{"yb","yb",40,-5.,5.}
+ {
+ // Setup histograms
+ htotal_.Sumw2();
+ hydif_.Sumw2();
+ hyf_.Sumw2();
+ hyb_.Sumw2();
+ }
- bool pass_cuts(
- HEJ::Event const & event,
- HEJ::Event const & /* FO_event */
- ) override {
- if (event.jets().size()<2)
- return false;
- return true;
- }
+ void fill(
+ HEJ::Event const & event,
+ HEJ::Event const & /* FO_event */
+ ) override {
+ const double weight=event.central().weight;
+ htotal_.Fill(0.0,weight);
+ auto const & jets=event.jets(); // jets are sorted in rapidity
+ Fill2DHistogram(hydif_,
+ fabs(jets.back().rapidity()-jets.front().rapidity()), weight);
+ Fill2DHistogram(hyf_, jets.front().rapidity(), weight);
+ Fill2DHistogram(hyb_, jets.back().rapidity(), weight);
+ }
- void finalise() override {
- hfile_.Write();
- hfile_.Close();
- std::cout << "AnalysisROOT bids you farewell " << std::endl; // be polite
- }
+ bool pass_cuts(
+ HEJ::Event const & event,
+ HEJ::Event const & /* FO_event */
+ ) override {
+ if (event.jets().size()<2)
+ return false;
+ return true;
+ }
-};
+ void finalise() override {
+ hfile_.Write();
+ hfile_.Close();
+ std::cout << "AnalysisROOT bids you farewell " << std::endl; // be polite
+ }
+
+ };
+}
extern "C"
+__attribute__((visibility("default")))
std::unique_ptr<HEJ::Analysis> make_analysis(
YAML::Node const & config, LHEF::HEPRUP const & heprup
){
return std::make_unique<AnalysisROOT>(config, heprup);
}
diff --git a/examples/AnalysisTemplate.cc b/examples/AnalysisTemplate.cc
index 98bb556..c8ac66e 100644
--- a/examples/AnalysisTemplate.cc
+++ b/examples/AnalysisTemplate.cc
@@ -1,46 +1,48 @@
//! simple HEJ analysis that doesn't do anything
#include <memory> // for std::unique_ptr
#include <iostream>
#include "HEJ/Analysis.hh"
namespace YAML {
class Node;
}
namespace LHEF {
class HEPRUP;
}
-class AnalysisTemplate: public HEJ::Analysis {
-public:
- AnalysisTemplate(
- YAML::Node const & /* config */, LHEF::HEPRUP const & /* heprup */
- ) {}
-
- void fill(
- HEJ::Event const & /* event */,
- HEJ::Event const & /* FO_event */
- ) override {
- }
-
- bool pass_cuts(
- HEJ::Event const & /* event */,
- HEJ::Event const & /* FO_event */
- ) override {
- return true;
- }
-
- void finalise() override {
- std::cout << "bye" << std::endl; // be polite
- }
-
-};
+namespace {
+ class AnalysisTemplate: public HEJ::Analysis {
+ public:
+ AnalysisTemplate(
+ YAML::Node const & /* config */, LHEF::HEPRUP const & /* heprup */
+ ) {}
+
+ void fill(
+ HEJ::Event const & /* event */,
+ HEJ::Event const & /* FO_event */
+ ) override {
+ }
+
+ bool pass_cuts(
+ HEJ::Event const & /* event */,
+ HEJ::Event const & /* FO_event */
+ ) override {
+ return true;
+ }
+
+ void finalise() override {
+ std::cout << "bye" << std::endl; // be polite
+ }
+ };
+}
extern "C"
+__attribute__((visibility("default")))
std::unique_ptr<HEJ::Analysis> make_analysis(
YAML::Node const & config, LHEF::HEPRUP const & heprup
){
return std::make_unique<AnalysisTemplate>(config, heprup);
}
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index f64e195..5d05249 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -1,25 +1,26 @@
set(example_dir "${CMAKE_CURRENT_SOURCE_DIR}")
file(GLOB source_files ${example_dir}/*.cc)
if(NOT ROOT_FOUND)
list(REMOVE_ITEM source_files "${example_dir}/AnalysisROOT.cc")
endif()
foreach(source ${source_files})
get_filename_component(name ${source} NAME_WE)
add_library(${name}_lib SHARED ${source})
set_target_properties(${name}_lib PROPERTIES OUTPUT_NAME "${name}")
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# Clang warns about `std::unique_ptr` in C linked (`extern "C"`) function
# `make_analysis`. However this call is save from C++, and we don't care
# about pure C. We can ignore the warning.
target_compile_options(${name}_lib PRIVATE "-Wno-return-type-c-linkage")
endif()
+ target_compile_options(${name}_lib PRIVATE "-fvisibility=hidden")
## link library
target_link_libraries(${name}_lib HEJ)
endforeach(source)
if(ROOT_FOUND)
target_link_libraries(AnalysisROOT_lib ROOT::Core ROOT::Hist ROOT::RIO)
endif()

File Metadata

Mime Type
text/x-diff
Expires
Sun, Feb 23, 3:00 PM (5 h, 7 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4484198
Default Alt Text
(10 KB)

Event Timeline