1#ifndef __JROOT__JROOTTOOLKIT__
2#define __JROOT__JROOTTOOLKIT__
11#pragma GCC diagnostic push
12#pragma GCC diagnostic ignored "-Wall"
14#include "TObjString.h"
19#include "TStreamerInfo.h"
26#include "TGraphErrors.h"
27#include "TGraphAsymmErrors.h"
29#include "TGraph2DErrors.h"
30#include "TMultiGraph.h"
32#pragma GCC diagnostic pop
44namespace JPP {
using namespace JROOT; }
72 return T::Class_Name();
86 for (
int ix = 1; ix <= h3->GetXaxis()->GetNbins(); ++ix) {
87 for (
int iy = 1; iy <= h3->GetYaxis()->GetNbins(); ++iy) {
88 for (
int iz = 1; iz <= h3->GetZaxis()->GetNbins(); ++iz) {
90 h3->SetBinError(ix, iy, iz, 0.0);
93 h3->SetBinContent(ix, iy, iz, 0.0);
112 for (
int ix = 1; ix <= h2->GetXaxis()->GetNbins(); ++ix) {
113 for (
int iy = 1; iy <= h2->GetYaxis()->GetNbins(); ++iy) {
115 h2->SetBinError(ix, iy, 0.0);
118 h2->SetBinContent(ix, iy, 0.0);
134#define RESET_OBJECT(T, P, O) if (dynamic_cast<T*>(P) != NULL) { resetObject(dynamic_cast<T*>(P), O); return; }
147 for (
int ix = 1; ix <= h1->GetXaxis()->GetNbins(); ++ix) {
149 h1->SetBinError(ix, 0.0);
152 h1->SetBinContent(ix, 0.0);
172 for (
int i = 0; i !=
g1->GetN(); ++i) {
175 g1->SetPoint(i,
g1->GetX()[i], 0.0);
192 for (
int i = 0; i !=
g1->GetN(); ++i) {
194 g1->SetPointError(i, 0.0, 0.0);
197 g1->SetPoint(i,
g1->GetX()[i], 0.0);
214 for (
int i = 0; i !=
g1->GetN(); ++i) {
216 g1->SetPointError(i, 0.0, 0.0, 0.0, 0.0);
219 g1->SetPoint(i,
g1->GetX()[i], 0.0);
236 for (
int i = 0; i != g2->GetN(); ++i) {
239 g2->SetPoint(i, g2->GetX()[i], g2->GetY()[i], 0.0);
252 inline void resetObject(TGraph2DErrors* g2,
const bool reset =
false)
256 for (
int i = 0; i != g2->GetN(); ++i) {
258 g2->SetPointError(i, 0.0, 0.0, 0.0);
261 g2->SetPoint(i, g2->GetX()[i], g2->GetY()[i], 0.0);
274 inline void resetObject(TMultiGraph* gs,
const bool reset =
false)
276#define RESET_OBJECT(T, P, O) if (dynamic_cast<T*>(P) != NULL) { resetObject(dynamic_cast<T*>(P), O); continue; }
280 for (TIter next(gs->GetListOfGraphs()); TGraph* graph = (TGraph*) next(); ) {
302 const Int_t n =
g1->GetN();
305 g1->SetPoint(n, x, y);
324 const Int_t n =
g1->GetN();
327 g1->SetPoint(n, x, y);
328 g1->SetPointError(n, ex, ey);
351 const Int_t n =
g1->GetN();
354 g1->SetPoint(n, x, y);
355 g1->SetPointError(n, exl, exh, eyl, eyh);
372 const Int_t n =
g1->GetN();
375 g1->SetPoint(n, x, y, z);
398 const Int_t n =
g1->GetN();
401 g1->SetPoint(n, x, y, z);
402 g1->SetPointError(n, ex, ey, ez);
415 file.WriteTObject(&
object);
431 if (file != NULL && file->IsOpen()) {
432 return dynamic_cast<const TStreamerInfo*
>(file->GetStreamerInfoList()->FindObject(name));
447 inline const TStreamerInfo*
getStreamerInfo(
const char*
const file_name,
const char*
const name)
467 if (pStreamerInfo != NULL)
468 return pStreamerInfo->GetClassVersion();
500 inline TString
parse(
const TPRegexp& regexp,
const TString&
string,
const int index = 1)
502 TPRegexp buffer = regexp;
503 TObjArray* array = buffer.MatchS(
string);
504 TString result = string;
506 if (index - 1 < array->GetLast()) {
507 result = ((TObjString*) array->At(index))->GetName();
536 const Double_t
value) :
548 inline operator Int_t()
const
567 if (parameter.
index >= 0 && parameter.
index < f1.GetNpar()) {
569 f1.SetParameter(parameter.
index, parameter.
value);
588 if (parameter.
index >= 0 && parameter.
index < f1.GetNpar()) {
590 f1.FixParameter(parameter.
index, parameter.
value);
609 if (index >= 0 && index < f1.GetNpar()) {
611 f1.ReleaseParameter(index);
630 inline bool setParLimits(TF1& f1,
const Int_t index, Double_t xmin, Double_t xmax)
634 if (index >= 0 && index < f1.GetNpar()) {
636 if (xmin == 0.0) { xmin = -numeric_limits<Double_t>::min(); }
637 if (xmax == 0.0) { xmax = +numeric_limits<Double_t>::min(); }
639 f1.SetParLimits(index, xmin, xmax);
658 if (index >= 0 && index < f1.GetNpar()) {
663 f1.GetParLimits(index, xmin, xmax);
665 return (xmin != 0.0 && xmax != 0.0 && xmin >= xmax);
686 const int N = h1.GetNbinsX();
690 for (
int i = 0; i < N; i++) {
691 x[i] = h1.GetBinCenter (i + 1);
692 y[i] = h1.GetBinContent(i + 1);
695 return new TGraph(N, &x[0], &y[0]);
708 inline TH1*
projectHistogram(
const TH2& h2,
const Double_t xmin,
const Double_t xmax,
const char projection)
710 switch (projection) {
714 return h2.ProjectionX(
"_px", h2.GetYaxis()->FindBin(xmin), h2.GetYaxis()->FindBin(xmax));
718 return h2.ProjectionY(
"_py", h2.GetXaxis()->FindBin(xmin), h2.GetXaxis()->FindBin(xmax));
734inline std::istream&
operator>>(std::istream& in, TRegexp&
object)
739 object = TRegexp(buffer.c_str());
753inline std::ostream&
operator<<(std::ostream& out,
const TRegexp&
object)
766inline std::istream&
operator>>(std::istream& in, TFormula&
object)
770 if (getline(in,buffer)) {
771 object = TFormula(
"", buffer.c_str());
785inline std::ostream&
operator<<(std::ostream& out,
const TFormula&
object)
787 return out <<
object.GetExpFormula();
Double_t g1(const Double_t x)
Function.
TFile * getFile() const
Get file.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary classes and methods for ROOT I/O.
const TStreamerInfo * getStreamerInfo(TFile *file, const char *const name)
Get ROOT streamer information of class with given name.
bool fixParameter(TF1 &f1, const JFitParameter_t ¶meter)
Fix fit parameter.
TGraph * histogramToGraph(const TH1 &h1)
Helper method to convert a 1D histogram to a graph.
TFile & operator<<(TFile &file, const TObject &object)
Write object to ROOT file.
void AddPoint(TGraph *g1, const Double_t x, const Double_t y)
Add point to TGraph.
int getStreamerVersion(TFile *file, const char *const name)
Get ROOT streamer version of class with given name.
void resetObject(JManager< JKey_t, JValue_t > *object, const bool reset=false)
Reset JManager object.
TH1 * projectHistogram(const TH2 &h2, const Double_t xmin, const Double_t xmax, const char projection)
Helper method for ROOT histogram projections.
bool setParameter(TF1 &f1, const JFitParameter_t ¶meter)
Set fit parameter.
bool isParameterFixed(const TF1 &f1, const Int_t index)
Check if fit parameter is fixed.
bool releaseParameter(TF1 &f1, const Int_t index)
Release fit parameter.
TString parse(const TPRegexp ®exp, const TString &string, const int index=1)
Match a regular expression with given string and return the specified matched parts.
bool setParLimits(TF1 &f1, const Int_t index, Double_t xmin, Double_t xmax)
Set fit parameter limits.
const char * getName()
Get ROOT name of given data type.
Auxiliary class for a type holder.
Auxiliary data structure for a parameter index and its value.
JFitParameter_t(const Int_t index, const Double_t value)
Constructor.
JFitParameter_t()
Default constructor.