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()) {
433 TList* ps = file->GetStreamerInfoList();
436 return dynamic_cast<const TStreamerInfo*
>(ps->FindObject(name));
452 inline const TStreamerInfo*
getStreamerInfo(
const char*
const file_name,
const char*
const name)
472 if (pStreamerInfo != NULL)
473 return pStreamerInfo->GetClassVersion();
505 inline TString
parse(
const TPRegexp& regexp,
const TString&
string,
const int index = 1)
507 TPRegexp buffer = regexp;
508 TObjArray* array = buffer.MatchS(
string);
509 TString result = string;
511 if (index - 1 < array->GetLast()) {
512 result = ((TObjString*) array->At(index))->GetName();
541 const Double_t
value) :
553 inline operator Int_t()
const
572 if (parameter.
index >= 0 && parameter.
index < f1.GetNpar()) {
574 f1.SetParameter(parameter.
index, parameter.
value);
593 if (parameter.
index >= 0 && parameter.
index < f1.GetNpar()) {
595 f1.FixParameter(parameter.
index, parameter.
value);
614 if (index >= 0 && index < f1.GetNpar()) {
616 f1.ReleaseParameter(index);
635 inline bool setParLimits(TF1& f1,
const Int_t index, Double_t xmin, Double_t xmax)
639 if (index >= 0 && index < f1.GetNpar()) {
641 if (xmin == 0.0) { xmin = -numeric_limits<Double_t>::min(); }
642 if (xmax == 0.0) { xmax = +numeric_limits<Double_t>::min(); }
644 f1.SetParLimits(index, xmin, xmax);
663 if (index >= 0 && index < f1.GetNpar()) {
668 f1.GetParLimits(index, xmin, xmax);
670 return (xmin != 0.0 && xmax != 0.0 && xmin >= xmax);
691 const int N = h1.GetNbinsX();
695 for (
int i = 0; i < N; i++) {
696 x[i] = h1.GetBinCenter (i + 1);
697 y[i] = h1.GetBinContent(i + 1);
700 return new TGraph(N, &x[0], &y[0]);
713 inline TH1*
projectHistogram(
const TH2& h2,
const Double_t xmin,
const Double_t xmax,
const char projection)
715 switch (projection) {
719 return h2.ProjectionX(
"_px", h2.GetYaxis()->FindBin(xmin), h2.GetYaxis()->FindBin(xmax));
723 return h2.ProjectionY(
"_py", h2.GetXaxis()->FindBin(xmin), h2.GetXaxis()->FindBin(xmax));
739inline std::istream&
operator>>(std::istream& in, TRegexp&
object)
744 object = TRegexp(buffer.c_str());
758inline std::ostream&
operator<<(std::ostream& out,
const TRegexp&
object)
771inline std::istream&
operator>>(std::istream& in, TFormula&
object)
775 if (getline(in,buffer)) {
776 object = TFormula(
"", buffer.c_str());
790inline std::ostream&
operator<<(std::ostream& out,
const TFormula&
object)
792 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.