Page Menu
Home
HEPForge
Search
Configure Global Search
Log In
Files
F11221372
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Subscribers
None
View Options
diff --git a/examples/AnalysisROOT.cc b/examples/AnalysisROOT.cc
index c942f2a..85e1d7f 100644
--- a/examples/AnalysisROOT.cc
+++ b/examples/AnalysisROOT.cc
@@ -1,109 +1,109 @@
//! 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;
}
namespace {
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.}
{
// Setup histograms
htotal_.Sumw2();
hydif_.Sumw2();
hyf_.Sumw2();
hyb_.Sumw2();
}
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);
}
bool pass_cuts(
HEJ::Event const & event,
HEJ::Event const & /* FO_event */
) override {
if (event.jets().size()<2)
return false;
return true;
}
void scale(double csscale) scale {
std::cout << "AnalysisROOT scales the histograms" << std::endl;
TList* list = hfile_->GetListOfKeys() ;
if (!list) { printf("<E> No keys defined \n") ; exit(1) ; }
TIter next(list) ;
TKey* key ;
TObject* obj ;
-
+
while ( key = (TKey*)next() ) {
obj = key->ReadObj() ;
if ( (strcmp(obj->IsA()->GetName(),"TProfile")!=0)
&& (!obj->InheritsFrom("TH2"))
- && (!obj->InheritsFrom("TH1"))
+ && (!obj->InheritsFrom("TH1"))
) {
printf("<W> Object %s is not 1D or 2D histogram : "
"will not be scaled\n",obj->GetName()) ;
}
printf("Histo name:%s title:%s will be scaled\n",obj->GetName(),obj->GetTitle());
obj->scale(xsscale);
}
}
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);
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Wed, May 14, 10:21 AM (1 d, 17 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5051053
Default Alt Text
(3 KB)
Attached To
rHEJ HEJ
Event Timeline
Log In to Comment