1 #ifndef __JGIZMOTOOLKIT__
2 #define __JGIZMOTOOLKIT__
20 #include "TIterator.h"
22 #include "TMethodCall.h"
37 namespace JPP {
using namespace JGIZMO; }
62 static const char*
const Add() {
return "Add"; }
63 static const char*
const add() {
return "add"; }
64 static const char*
const Subtract() {
return "Subtract"; }
65 static const char*
const subtract() {
return "subtract"; }
66 static const char*
const Multiply() {
return "Multiply"; }
67 static const char*
const multiply() {
return "multiply"; }
68 static const char*
const Divide() {
return "Divide"; }
69 static const char*
const divide() {
return "divide"; }
70 static const char*
const efficiency() {
return "efficiency"; }
71 static const char*
const stdev() {
return "stdev"; }
72 static const char*
const sqrt() {
return "sqrt"; }
84 inline TFile*
getFile(
const std::string& file_name,
const std::string& option =
"exist")
88 gErrorIgnoreLevel = kError;
94 if (i == zmap.end() || i->second == NULL || !i->second->IsOpen()) {
96 TFile* file = TFile::Open(file_name.c_str(), option.c_str());
98 zmap[file_name] = file;
120 if (in == NULL || !in->IsOpen()) {
125 return in->GetDirectory(
id.getDirectory());
143 const TRegexp regexp(
id.getObjectName());
145 TIter iter(dir->GetListOfKeys());
147 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
149 const TString tag(key->GetName());
153 if (tag.Index(regexp) != -1) {
154 return key->ReadObj();
171 const TH1* h1 =
dynamic_cast<const TH1*
>(object);
175 if (h1->GetSumw2N()) {
177 for (Int_t i = 1; i <= h1->GetNbinsX(); ++i) {
179 if (h1->GetBinError(i) != 0.0) {
209 TString buffer(text);
211 if (
object != NULL) {
213 TClass* p = TClass::GetClass(object->ClassName());
217 TIterator* iter = p->GetListOfAllPublicMethods()->MakeIterator();
219 for (TMethod* method; (method = (TMethod*) iter->Next()) != NULL; ) {
221 if (buffer.Contains(method->GetName())) {
225 TMethodCall(p, method->GetName(), NULL).Execute(
object, value);
227 buffer.ReplaceAll(method->GetName(), TString::Format(
"%f", value));
233 return TFormula(
"/tmp", buffer.Data()).Eval(0.0);
252 return getResult(TString(text.c_str()),
object);
265 const char* regexp(
"p[0-9]* *=");
267 TString buffer(text.c_str());
269 buffer = buffer(TRegexp(regexp));
270 buffer = buffer(1, buffer.Length() - 2);
272 if (!buffer.IsDigit()) {
276 return buffer.Atoi();
295 const char* regexp(
"=.*");
297 TString buffer(text.c_str());
299 buffer = buffer(TRegexp(regexp));
300 buffer = buffer(1, buffer.Length() - 1);
302 return getResult(std::string(buffer),
object);
315 const int N = axis->GetNbins();
316 Double_t buffer[N+1];
318 buffer[0] = TMath::Power(10.0, axis->GetBinLowEdge(1));
320 for (
int i = 1; i <= N; ++i) {
321 buffer[i] = TMath::Power(10.0, axis->GetBinLowEdge(i) + axis->GetBinWidth(i));
324 axis->Set(N, buffer);
341 inline void convertToPDF(TH1& h1,
const std::string& option =
"NW",
const double factor = 1.0)
345 const bool normalise = (option.find(
'N') != string::npos || option.find(
'n') != string::npos);
346 const bool bin_width = (option.find(
'W') != string::npos || option.find(
'w') != string::npos);
347 const bool use_error = (option.find(
'E') != string::npos || option.find(
'e') != string::npos);
355 for (Int_t i = 1; i <= h1.GetXaxis()->GetNbins(); ++i) {
356 W += h1.GetBinContent(i);
362 for (Int_t i = 1; i <= h1.GetXaxis()->GetNbins(); ++i) {
364 const Double_t w = W * (bin_width ? h1.GetXaxis()->GetBinWidth(i) : 1.0);
366 h1.SetBinContent(i, h1.GetBinContent(i) * factor / w);
369 h1.SetBinError(i, h1.GetBinError(i) * factor / w);
390 inline void convertToPDF(TH2& h2,
const std::string& option =
"NXYW",
const double factor = 1.0)
394 const bool normalise = (option.find(
'N') != string::npos || option.find(
'n') != string::npos);
395 const bool X = (option.find(
'X') != string::npos || option.find(
'x') != string::npos);
396 const bool Y = (option.find(
'Y') != string::npos || option.find(
'y') != string::npos);
397 const bool bin_width = (option.find(
'W') != string::npos || option.find(
'w') != string::npos);
398 const bool use_error = (option.find(
'E') != string::npos || option.find(
'e') != string::npos);
408 for (Int_t i = 1; i <= h2.GetXaxis()->GetNbins(); ++i) {
409 for (Int_t j = 1; j <= h2.GetYaxis()->GetNbins(); ++j) {
410 W += h2.GetBinContent(i,j);
417 for (Int_t i = 1; i <= h2.GetXaxis()->GetNbins(); ++i) {
418 for (Int_t j = 1; j <= h2.GetYaxis()->GetNbins(); ++j) {
420 const Double_t w = W * (bin_width ? h2.GetXaxis()->GetBinWidth(i) * h2.GetYaxis()->GetBinWidth(j) : 1.0);
422 h2.SetBinContent(i, j, h2.GetBinContent(i,j) * factor / w);
425 h2.SetBinError(i, j, h2.GetBinError(i,j) * factor / w);
433 for (Int_t j = 1; j <= h2.GetYaxis()->GetNbins(); ++j) {
439 for (Int_t i = 1; i <= h2.GetXaxis()->GetNbins(); ++i) {
440 W += h2.GetBinContent(i,j);
446 for (Int_t i = 1; i <= h2.GetXaxis()->GetNbins(); ++i) {
448 const Double_t w = W * (bin_width ? h2.GetXaxis()->GetBinWidth(i) : 1.0);
450 h2.SetBinContent(i, j, h2.GetBinContent(i,j) * factor / w);
453 h2.SetBinError(i, j, h2.GetBinError(i,j) * factor / w);
461 for (Int_t i = 1; i <= h2.GetXaxis()->GetNbins(); ++i) {
467 for (Int_t j = 1; j <= h2.GetYaxis()->GetNbins(); ++j) {
468 W += h2.GetBinContent(i,j);
474 for (Int_t j = 1; j <= h2.GetYaxis()->GetNbins(); ++j) {
476 const Double_t w = W * (bin_width ? h2.GetYaxis()->GetBinWidth(j) : 1.0);
478 h2.SetBinContent(i, j, h2.GetBinContent(i,j) / w);
481 h2.SetBinError(i, j, h2.GetBinError(i,j) / w);
499 Double_t ymin = +numeric_limits<Double_t>::max();
500 Double_t ymax = -numeric_limits<Double_t>::max();
502 for (Int_t i = 0; i != g1.GetN(); ++i) {
504 const Double_t y = g1.GetY()[i];
506 if (y > ymax) { ymax = y; }
507 if (y < ymin) { ymin = y; }
524 Double_t zmin = +numeric_limits<Double_t>::max();
525 Double_t zmax = -numeric_limits<Double_t>::max();
527 for (Int_t i = 0; i != g2.GetN(); ++i) {
529 const Double_t z = g2.GetZ()[i];
531 if (z > zmax) { zmax = z; }
532 if (z < zmin) { zmin = z; }
556 double dx = (xmax - xmin) * 0.1;
558 if (xmin > dx || xmin < 0.0)
582 if (axis->GetNbins() == (int) memo.size()) {
584 for (
int i = 0; i < axis->GetNbins(); i++) {
586 const JPMTPhysicalAddress& pmtAddress = memo[i];
588 axis->SetBinLabel(i + 1, TString(pmtAddress.toString()));
static const char *const sqrt()
Set contents to signed difference between squares.
TObject * getObject(const JRootObjectID &id)
Get TObject.
double getValue(const JScale_t scale)
Get numerical value corresponding to scale.
int getParameter(const std::string &text)
Get parameter number from text string.
static const char *const Divide()
ROOT TH1::Divide.
static const char *const Subtract()
ROOT TH1::Subtract.
static const char *const SAME_AS_INPUT()
Set name of output histogram to name of input histogram.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
void setLimits(TGraph &g1)
Set limits of TGraph.
static const char *const subtract()
Subtract contents with lookup bin in second histogram.
Auxiliary class to handle file name, ROOT directory and object name.
static const char *const stdev()
Set contents to standard deviation.
void setLogarithm(TAxis *axis)
Make axis logarithmic (e.g.
bool isTAttLine(const TObject *object)
Get drawing option of TH1.
static const char *const efficiency()
Divide contents and multiply errors with inefficiency.
static const char *const Add()
ROOT TH1::Add.
Lookup table for PMT addresses in optical module.
static const char *const multiply()
Multiply contents with lookup bin in second histogram.
TFile * getFile(const std::string &file_name, const std::string &option="exist")
Get TFile pointer.
static const char *const add()
Add contents with lookup bin in second histogram.
Auxiliary data structure for JOpera1D.cc and JOpera2D.cc applications.
Double_t getResult(const TString &text, TObject *object=NULL)
Get result of given textual formula.
void convertToPDF(TH1 &h1, const std::string &option="NW", const double factor=1.0)
Convert 1D histogram to PDF.
void setAxisLabels(TAxis *axis, const JModuleAddressMap &memo)
initialize axis with PMT address labels
static const char *const Multiply()
ROOT TH1::Multiply.
static const char *const SAME_AS_OPERATION()
Set name of output histogram to name of operation.
void setRange(double &xmin, double &xmax, const bool logx)
Set axis range.
static const char *const divide()
Divide contents with lookup bin in second histogram.
Exception for parsing value.
TDirectory * getDirectory(const JRootObjectID &id)
Get TDirectory pointer.
std::string getFilename(const std::string &file_name)
Get file name part, i.e.
Exception for accessing a value in a collection that is outside of its range.
Double_t g1(const Double_t x)
Function.