1 #ifndef __JGIZMOTOOLKIT__
2 #define __JGIZMOTOOLKIT__
20 #include "TIterator.h"
22 #include "TMethodCall.h"
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"; }
79 static const char*
const TIMESTAMP =
"#splitline{}{#splitline{%d:%m:%y}{ %H:%M}}%F1970-01-01 00:00:00";
89 inline TFile*
getFile(
const std::string& file_name,
const std::string& option =
"exist")
93 gErrorIgnoreLevel = kError;
99 if (i == zmap.end() || i->second == NULL || !i->second->IsOpen()) {
101 TFile* file = TFile::Open(file_name.c_str(), option.c_str());
103 zmap[file_name] = file;
125 if (in == NULL || !in->IsOpen()) {
130 return in->GetDirectory(
id.getDirectory());
148 const TRegexp regexp(
id.getObjectName());
150 TIter iter(dir->GetListOfKeys());
152 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
154 const TString tag(key->GetName());
158 if (tag.Index(regexp) != -1) {
159 return key->ReadObj();
176 const TH1* h1 = dynamic_cast<const TH1*>(
object);
180 if (h1->GetSumw2N()) {
182 for (Int_t i = 1; i <= h1->GetNbinsX(); ++i) {
184 if (h1->GetBinError(i) != 0.0) {
214 TString buffer(
text);
216 if (
object != NULL) {
218 TClass* p = TClass::GetClass(object->ClassName());
222 TIterator* iter = p->GetListOfAllPublicMethods()->MakeIterator();
224 for (TMethod* method; (method = (TMethod*) iter->Next()) != NULL; ) {
226 for (Ssiz_t index; (index = buffer.Index(method->GetName())) != -1; ) {
228 const TRegexp fp(
"([^)]*)");
231 Ssiz_t pos = buffer.Index(fp, &len, index);
237 TMethodCall(p, method->GetName(), NULL).Execute(
object, value);
239 len = strlen(method->GetName());
241 }
else if (pos == index + (Ssiz_t) strlen(method->GetName())) {
243 TMethodCall(p, method->GetName(), NULL).Execute(
object, TString(buffer(pos + 1, len - 2)), value);
245 len += strlen(method->GetName());
252 buffer.Replace(index, len, TString::Format(
"%f", value));
258 return TFormula(
"/tmp", buffer.Data()).Eval(0.0);
290 const char* regexp(
"p[0-9]* *=");
292 TString buffer(
text.c_str());
294 buffer = buffer(TRegexp(regexp));
295 buffer = buffer(1, buffer.Length() - 2);
297 if (!buffer.IsDigit()) {
301 return buffer.Atoi();
320 const char* regexp(
"=.*");
322 TString buffer(
text.c_str());
324 buffer = buffer(TRegexp(regexp));
325 buffer = buffer(1, buffer.Length() - 1);
327 return getResult(std::string(buffer),
object);
340 const int N = axis->GetNbins();
341 Double_t buffer[N+1];
343 buffer[0] = TMath::Power(10.0, axis->GetBinLowEdge(1));
345 for (
int i = 1; i <= N; ++i) {
346 buffer[i] = TMath::Power(10.0, axis->GetBinLowEdge(i) + axis->GetBinWidth(i));
349 axis->Set(N, buffer);
366 inline void convertToPDF(TH1& h1,
const std::string& option =
"NW",
const double factor = 1.0)
370 const bool normalise = (option.find(
'N') != string::npos || option.find(
'n') != string::npos);
371 const bool bin_width = (option.find(
'W') != string::npos || option.find(
'w') != string::npos);
372 const bool use_error = (option.find(
'E') != string::npos || option.find(
'e') != string::npos);
380 for (Int_t i = 1; i <= h1.GetXaxis()->GetNbins(); ++i) {
381 W += h1.GetBinContent(i);
387 for (Int_t i = 1; i <= h1.GetXaxis()->GetNbins(); ++i) {
389 const Double_t
w = W * (bin_width ? h1.GetXaxis()->GetBinWidth(i) : 1.0);
391 h1.SetBinContent(i, h1.GetBinContent(i) * factor /
w);
394 h1.SetBinError(i, h1.GetBinError(i) * factor /
w);
415 inline void convertToPDF(TH2& h2,
const std::string& option =
"NXYW",
const double factor = 1.0)
419 const bool normalise = (option.find(
'N') != string::npos || option.find(
'n') != string::npos);
420 const bool X = (option.find(
'X') != string::npos || option.find(
'x') != string::npos);
421 const bool Y = (option.find(
'Y') != string::npos || option.find(
'y') != string::npos);
422 const bool bin_width = (option.find(
'W') != string::npos || option.find(
'w') != string::npos);
423 const bool use_error = (option.find(
'E') != string::npos || option.find(
'e') != string::npos);
433 for (Int_t i = 1; i <= h2.GetXaxis()->GetNbins(); ++i) {
434 for (Int_t
j = 1;
j <= h2.GetYaxis()->GetNbins(); ++
j) {
435 W += h2.GetBinContent(i,
j);
442 for (Int_t i = 1; i <= h2.GetXaxis()->GetNbins(); ++i) {
443 for (Int_t
j = 1;
j <= h2.GetYaxis()->GetNbins(); ++
j) {
445 const Double_t
w = W * (bin_width ? h2.GetXaxis()->GetBinWidth(i) * h2.GetYaxis()->GetBinWidth(
j) : 1.0);
447 h2.SetBinContent(i,
j, h2.GetBinContent(i,
j) * factor /
w);
450 h2.SetBinError(i,
j, h2.GetBinError(i,
j) * factor /
w);
458 for (Int_t
j = 1;
j <= h2.GetYaxis()->GetNbins(); ++
j) {
464 for (Int_t i = 1; i <= h2.GetXaxis()->GetNbins(); ++i) {
465 W += h2.GetBinContent(i,
j);
471 for (Int_t i = 1; i <= h2.GetXaxis()->GetNbins(); ++i) {
473 const Double_t
w = W * (bin_width ? h2.GetXaxis()->GetBinWidth(i) : 1.0);
475 h2.SetBinContent(i,
j, h2.GetBinContent(i,
j) * factor /
w);
478 h2.SetBinError(i,
j, h2.GetBinError(i,
j) * factor /
w);
486 for (Int_t i = 1; i <= h2.GetXaxis()->GetNbins(); ++i) {
492 for (Int_t
j = 1;
j <= h2.GetYaxis()->GetNbins(); ++
j) {
493 W += h2.GetBinContent(i,
j);
499 for (Int_t
j = 1;
j <= h2.GetYaxis()->GetNbins(); ++
j) {
501 const Double_t
w = W * (bin_width ? h2.GetYaxis()->GetBinWidth(
j) : 1.0);
503 h2.SetBinContent(i,
j, h2.GetBinContent(i,
j) /
w);
506 h2.SetBinError(i,
j, h2.GetBinError(i,
j) /
w);
524 Double_t ymin = +numeric_limits<Double_t>::max();
525 Double_t ymax = -numeric_limits<Double_t>::max();
527 for (Int_t i = 0; i !=
g1.GetN(); ++i) {
529 const Double_t y =
g1.GetY()[i];
531 if (y > ymax) { ymax = y; }
532 if (y < ymin) { ymin = y; }
549 Double_t zmin = +numeric_limits<Double_t>::max();
550 Double_t zmax = -numeric_limits<Double_t>::max();
552 for (Int_t i = 0; i != g2.GetN(); ++i) {
554 const Double_t z = g2.GetZ()[i];
556 if (z > zmax) { zmax = z; }
557 if (z < zmin) { zmin = z; }
581 double dx = (xmax - xmin) * 0.1;
583 if (xmin > dx || xmin < 0.0)
607 if (axis->GetNbins() == (int) memo.size()) {
609 for (
int i = 0; i < axis->GetNbins(); i++) {
611 const JPMTPhysicalAddress& pmtAddress = memo[i];
613 axis->SetBinLabel(i + 1, TString(pmtAddress.toString()));