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"
21 #include "TIterator.h"
27 #include "TGraphErrors.h"
28 #include "TGraphAsymmErrors.h"
30 #include "TGraph2DErrors.h"
31 #include "TMultiGraph.h"
33 #pragma GCC diagnostic pop
49 namespace JPP {
using namespace JROOT; }
77 return T::Class_Name();
91 for (
int ix = 1; ix <= h3->GetXaxis()->GetNbins(); ++ix) {
92 for (
int iy = 1; iy <= h3->GetYaxis()->GetNbins(); ++iy) {
93 for (
int iz = 1; iz <= h3->GetZaxis()->GetNbins(); ++iz) {
95 h3->SetBinError(ix, iy, iz, 0.0);
98 h3->SetBinContent(ix, iy, iz, 0.0);
117 for (
int ix = 1; ix <= h2->GetXaxis()->GetNbins(); ++ix) {
118 for (
int iy = 1; iy <= h2->GetYaxis()->GetNbins(); ++iy) {
120 h2->SetBinError(ix, iy, 0.0);
123 h2->SetBinContent(ix, iy, 0.0);
139 #define RESET_OBJECT(T, P, O) if (dynamic_cast<T*>(P) != NULL) { resetObject(dynamic_cast<T*>(P), O); return; }
152 for (
int ix = 1; ix <= h1->GetXaxis()->GetNbins(); ++ix) {
154 h1->SetBinError(ix, 0.0);
157 h1->SetBinContent(ix, 0.0);
177 for (
int i = 0; i !=
g1->GetN(); ++i) {
180 g1->SetPoint(i,
g1->GetX()[i], 0.0);
197 for (
int i = 0; i !=
g1->GetN(); ++i) {
199 g1->SetPointError(i, 0.0, 0.0);
202 g1->SetPoint(i,
g1->GetX()[i], 0.0);
219 for (
int i = 0; i !=
g1->GetN(); ++i) {
221 g1->SetPointError(i, 0.0, 0.0, 0.0, 0.0);
224 g1->SetPoint(i,
g1->GetX()[i], 0.0);
241 for (
int i = 0; i != g2->GetN(); ++i) {
244 g2->SetPoint(i, g2->GetX()[i], g2->GetY()[i], 0.0);
261 for (
int i = 0; i != g2->GetN(); ++i) {
263 g2->SetPointError(i, 0.0, 0.0, 0.0);
266 g2->SetPoint(i, g2->GetX()[i], g2->GetY()[i], 0.0);
281 #define RESET_OBJECT(T, P, O) if (dynamic_cast<T*>(P) != NULL) { resetObject(dynamic_cast<T*>(P), O); continue; }
285 for (TIter next(gs->GetListOfGraphs()); TGraph* graph = (TGraph*) next(); ) {
307 const Int_t
n =
g1->GetN();
310 g1->SetPoint(
n,
x,
y);
329 const Int_t
n =
g1->GetN();
332 g1->SetPoint(
n,
x,
y);
333 g1->SetPointError(
n, ex, ey);
356 const Int_t
n =
g1->GetN();
359 g1->SetPoint(
n,
x,
y);
360 g1->SetPointError(
n, exl, exh, eyl, eyh);
377 const Int_t
n =
g1->GetN();
380 g1->SetPoint(
n,
x,
y, z);
403 const Int_t
n =
g1->GetN();
406 g1->SetPoint(
n,
x,
y, z);
407 g1->SetPointError(
n, ex, ey, ez);
420 file.WriteTObject(&
object);
436 if (file != NULL && file->IsOpen()) {
438 const TString buffer(name);
440 TIter iter(file->GetStreamerInfoList());
442 for (
const TStreamerInfo* pStreamerInfo; (pStreamerInfo = (TStreamerInfo*) iter.Next()) != NULL; ) {
443 if (buffer == TString(pStreamerInfo->GetName())) {
444 return pStreamerInfo;
461 inline const TStreamerInfo*
getStreamerInfo(
const char*
const file_name,
const char*
const name)
481 if (pStreamerInfo != NULL)
482 return pStreamerInfo->GetClassVersion();
514 inline TString
parse(
const TPRegexp& regexp,
const TString&
string,
const int index = 1)
516 TPRegexp buffer = regexp;
517 TObjArray* array = buffer.MatchS(
string);
520 if (index - 1 < array->GetLast()) {
521 result = ((TObjString*) array->At(index))->GetName();
550 const Double_t
value) :
562 inline operator Int_t()
const
581 if (parameter.
index >= 0 && parameter.
index <
f1.GetNpar()) {
602 if (parameter.
index >= 0 && parameter.
index <
f1.GetNpar()) {
623 if (index >= 0 && index <
f1.GetNpar()) {
625 f1.ReleaseParameter(index);
648 if (index >= 0 && index <
f1.GetNpar()) {
650 if (
xmin == 0.0) {
xmin = -numeric_limits<Double_t>::min(); }
651 if (
xmax == 0.0) {
xmax = +numeric_limits<Double_t>::min(); }
672 if (index >= 0 && index <
f1.GetNpar()) {
712 const TRegexp DOUBLE(
"[0-9.][eE][+-0-9]");
714 string buffer = (
const char*)
text;
716 for (string::size_type pos = 0; pos != buffer.size(); ) {
718 if (isalpha(buffer[pos]) || buffer[pos] ==
'_') {
720 string::size_type len = 1;
722 while (pos + len != buffer.size() && (isalnum(buffer[pos+len]) || buffer[pos+len] ==
'_' || buffer[pos+len] ==
'.')) {
726 if (len != 1 || pos == 0 || TString(buffer.substr(pos-1).c_str()).Index(DOUBLE) != 0) {
735 buffer.replace(pos, len, os.str());
737 pos += os.str().size();
746 return TFormula(
"/tmp", buffer.c_str()).Eval(0.0);
764 const int N = h1.GetNbinsX();
768 for (
int i = 0; i < N; i++) {
769 x[i] = h1.GetBinCenter (i + 1);
770 y[i] = h1.GetBinContent(i + 1);
773 return new TGraph(N, &
x[0], &
y[0]);
788 switch (projection) {
792 return h2.ProjectionX(
"_px", h2.GetYaxis()->FindBin(
xmin), h2.GetYaxis()->FindBin(
xmax));
796 return h2.ProjectionY(
"_py", h2.GetXaxis()->FindBin(
xmin), h2.GetXaxis()->FindBin(
xmax));
812 inline std::istream&
operator>>(std::istream& in, TRegexp&
object)
817 object = TRegexp(buffer.c_str());
831 inline std::ostream&
operator<<(std::ostream& out,
const TRegexp&
object)
I/O formatting auxiliaries.
Double_t g1(const Double_t x)
Function.
Print objects in ASCII format using ROOT dictionary.
TFile * getFile() const
Get file.
const JPolynome f1(1.0, 2.0, 3.0)
Function.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary classes and methods for ROOT I/O.
int getStreamerVersion(const char *const file_name, const char *const name)
Get ROOT streamer version of class with given name.
Double_t getResult(const TString &text, const T &object, const JRootDictionary_t &dictionary=JRootDictionary::getInstance())
Get result of given textual formula.
TH1 * projectHistogram(const TH2 &h2, const Double_t xmin, const Double_t xmax, const char projection)
Helper method for ROOT histogram projections.
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.
void resetObject(TMultiGraph *gs, const bool reset=false)
Reset TMultiGraph object.
const char * getName(const JType< T > &type)
Get ROOT name of given data type.
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.
void AddPoint(TGraph2DErrors *g1, const Double_t x, const Double_t y, const Double_t z, const Double_t ex, const Double_t ey, const Double_t ez)
Add point to TGraph2DErrors.
const TStreamerInfo * getStreamerInfo(const char *const file_name, const char *const name)
Get ROOT streamer information of class with given name.
static data_type & getInstance()
Get unique instance of template class.
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.
Type definition of ROOT based dictionary for ASCII I/O.
static void print(JRootWriter &writer, const JRootWritableClass &cls)
Write class contents to output.