1 #ifndef __JGIZMOTOOLKIT__
2 #define __JGIZMOTOOLKIT__
17 #include "TMultiGraph.h"
23 #include "TIterator.h"
25 #include "TMethodCall.h"
40 namespace JPP {
using namespace JGIZMO; }
65 static const char*
const Add() {
return "Add"; }
66 static const char*
const add() {
return "add"; }
67 static const char*
const Subtract() {
return "Subtract"; }
68 static const char*
const subtract() {
return "subtract"; }
69 static const char*
const Multiply() {
return "Multiply"; }
70 static const char*
const multiply() {
return "multiply"; }
71 static const char*
const Divide() {
return "Divide"; }
72 static const char*
const divide() {
return "divide"; }
73 static const char*
const efficiency() {
return "efficiency"; }
74 static const char*
const stdev() {
return "stdev"; }
75 static const char*
const sqrt() {
return "sqrt"; }
76 static const char*
const Replace() {
return "Replace"; }
83 static const char*
const TIMESTAMP =
"#splitline{}{#splitline{%d:%m:%y}{ %H:%M}}%F1970-01-01 00:00:00";
96 inline TFile*
getFile(
const std::string& file_name,
const std::string& option =
"exist")
100 gErrorIgnoreLevel = kError;
106 if (i == zmap.end() || i->second == NULL || !i->second->IsOpen()) {
108 TFile*
file = TFile::Open(file_name.c_str(), option.c_str());
110 zmap[file_name] =
file;
133 if (in == NULL || !in->IsOpen()) {
138 return in->GetDirectory(
id.getDirectory());
156 const TRegexp regexp(
id.getObjectName());
158 TIter iter(dir->GetListOfKeys());
160 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
162 const TString tag(key->GetName());
166 if (tag.Index(regexp) != -1) {
167 return key->ReadObj();
184 const TH1*
h1 =
dynamic_cast<const TH1*
>(object);
188 if (h1->GetSumw2N()) {
190 for (Int_t i = 1; i <= h1->GetNbinsX(); ++i) {
192 if (h1->GetBinError(i) != 0.0) {
223 TString buffer(text);
225 if (
object != NULL) {
227 TClass* p = TClass::GetClass(object->ClassName());
233 TIterator* iter = p->GetListOfAllPublicMethods()->MakeIterator();
234 TMethod* method = NULL;
236 for (TMethod* p; (p = (TMethod*) iter->Next()) != NULL; ) {
237 if (buffer.Index(p->GetName()) != -1) {
238 if (method == NULL || strlen(p->GetName()) > strlen(method->GetName())) {
244 if (method == NULL) {
248 for (Ssiz_t index; (index = buffer.Index(method->GetName())) != -1; ) {
250 const TRegexp fp(
" *([^)]*)");
253 Ssiz_t pos = buffer.Index(fp, &len, index);
257 if (pos == -1 || pos != index + (Ssiz_t) strlen(method->GetName())) {
259 TMethodCall(p, method->GetName(), NULL).Execute(
object, value);
261 len = strlen(method->GetName());
265 TMethodCall(p, method->GetName(), NULL).Execute(
object, TString(buffer(pos + 1, len - 2)), value);
267 len += strlen(method->GetName());
270 buffer.Replace(index, len, TString::Format(
"%15.5e", value));
276 return TFormula(
"/tmp", buffer.Data()).Eval(0.0);
296 return getResult(TString(text.c_str()),
object);
310 const char* regexp(
"p[0-9]* *=");
312 TString buffer(text.c_str());
314 buffer = buffer(TRegexp(regexp));
315 buffer = buffer(1, buffer.Length() - 2);
317 if (!buffer.IsDigit()) {
321 return buffer.Atoi();
341 const char* regexp(
"=.*");
343 TString buffer(text.c_str());
345 buffer = buffer(TRegexp(regexp));
346 buffer = buffer(1, buffer.Length() - 1);
348 return getResult(std::string(buffer),
object);
361 const Int_t
first = axis->GetFirst();
362 const Int_t last = axis->GetLast();
364 const Double_t xmin = axis->GetBinLowEdge(first);
365 const Double_t xmax = axis->GetBinLowEdge(last) + axis->GetBinWidth(last);
367 const Int_t
N = axis->GetNbins();
368 Double_t buffer[N+1];
370 buffer[0] = TMath::Power(10.0, axis->GetBinLowEdge(1));
372 for (Int_t i = 1; i <=
N; ++i) {
373 buffer[i] = TMath::Power(10.0, axis->GetBinLowEdge(i) + axis->GetBinWidth(i));
376 axis->Set(N, buffer);
378 if (axis->TestBit(TAxis::kAxisRange)) {
379 axis->SetRangeUser(TMath::Power(10.0, xmin), TMath::Power(10.0, xmax));
394 const TRegexp regexp[] = {
395 TString(
"^") + TString(parameter) + TString(
"[^a-zA-Z_]"),
396 TString(
"[^a-zA-Z_]") + TString(parameter) + TString(
"[^a-zA-Z_]"),
397 TString(
"[^a-zA-Z_]") + TString(parameter) + TString(
"$")
400 const TString replacement = TString(
"log10(") + TString(parameter) + TString(
")");
402 TString buffer(formula);
404 if (buffer.Length() == 1 && buffer[0] == parameter) {
406 buffer = replacement;
410 for (Ssiz_t pos = 0, i; pos < buffer.Length(); pos += replacement.Length()) {
411 if ((i = buffer.Index(regexp[0], pos)) != -1) { buffer.Replace((pos = i + 0), 1, replacement); }
412 else if ((i = buffer.Index(regexp[1], pos)) != -1) { buffer.Replace((pos = i + 1), 1, replacement); }
413 else if ((i = buffer.Index(regexp[2], pos)) != -1) { buffer.Replace((pos = i + 1), 1, replacement); }
427 inline void copy(
const TF1& from, TF1& to)
429 static_cast<TAttLine&
> (to) = static_cast<const TAttLine&> (from);
430 static_cast<TAttFill&
> (to) = static_cast<const TAttFill&> (from);
431 static_cast<TAttMarker&
>(to) = static_cast<const TAttMarker&>(from);
433 to.SetParameters(from.GetParameters());
435 to.SetNpx(from.GetNpx());
445 inline void copy(
const TF2& from, TF2& to)
447 copy(static_cast<const TF1&>(from), static_cast<TF1&>(to));
449 to.SetNpy(from.GetNpy());
466 fn.SetRange(f1->GetXmin(),
471 f1->SetRange(TMath::Power(10.0,f1->GetXmin()),
472 TMath::Power(10.0,f1->GetXmax()));
490 fn.SetRange(f2->GetXmin(),
497 f2->SetRange(TMath::Power(10.0,f2->GetXmin()),
499 TMath::Power(10.0,f2->GetXmax()),
518 fn.SetRange(f2->GetXmin(),
525 f2->SetRange(f2->GetXmin(),
526 TMath::Power(10.0,f2->GetYmin()),
528 TMath::Power(10.0,f2->GetYmax()));
542 for (TIter iter(h1->GetListOfFunctions()); TF1* f1 =
dynamic_cast<TF1*
>(iter.Next()); ) {
562 for (TIter iter(h2->GetListOfFunctions()); TF2* f2 =
dynamic_cast<TF2*
>(iter.Next()); ) {
580 for (TIter iter(h2->GetListOfFunctions()); TF2* f2 =
dynamic_cast<TF2*
>(iter.Next()); ) {
598 for (TIter iter(g1->GetListOfFunctions()); TF1* f1 =
dynamic_cast<TF1*
>(iter.Next()); ) {
602 for (Int_t i = 0; i != g1->GetN(); ++i) {
603 g1->GetX()[i] =
pow(10.0, g1->GetX()[i]);
618 for (TIter iter(g2->GetListOfFunctions()); TF2* f2 =
dynamic_cast<TF2*
>(iter.Next()); ) {
622 for (Int_t i = 0; i != g2->GetN(); ++i) {
623 g2->GetX()[i] =
pow(10.0, g2->GetX()[i]);
638 for (TIter iter(g2->GetListOfFunctions()); TF2* f2 =
dynamic_cast<TF2*
>(iter.Next()); ) {
642 for (Int_t i = 0; i != g2->GetN(); ++i) {
643 g2->GetY()[i] =
pow(10.0, g2->GetY()[i]);
658 for (TIter i1(m1->GetListOfGraphs()); TGraph*
g1 =
dynamic_cast<TGraph*
>(i1()); ) {
677 inline void convertToPDF(TH1&
h1,
const std::string& option =
"NW",
const double factor = 1.0)
681 const bool normalise = (option.find(
'N') != string::npos || option.find(
'n') != string::npos);
682 const bool bin_width = (option.find(
'W') != string::npos || option.find(
'w') != string::npos);
683 const bool use_error = (option.find(
'E') != string::npos || option.find(
'e') != string::npos);
691 for (Int_t i = 1; i <= h1.GetXaxis()->GetNbins(); ++i) {
692 W += h1.GetBinContent(i);
698 for (Int_t i = 1; i <= h1.GetXaxis()->GetNbins(); ++i) {
700 const Double_t
w = W * (bin_width ? h1.GetXaxis()->GetBinWidth(i) : 1.0);
702 h1.SetBinContent(i, h1.GetBinContent(i) * factor /
w);
705 h1.SetBinError(i, h1.GetBinError(i) * factor /
w);
726 inline void convertToPDF(TH2& h2,
const std::string& option =
"NXYW",
const double factor = 1.0)
730 const bool normalise = (option.find(
'N') != string::npos || option.find(
'n') != string::npos);
731 const bool X = (option.find(
'X') != string::npos || option.find(
'x') != string::npos);
732 const bool Y = (option.find(
'Y') != string::npos || option.find(
'y') != string::npos);
733 const bool bin_width = (option.find(
'W') != string::npos || option.find(
'w') != string::npos);
734 const bool use_error = (option.find(
'E') != string::npos || option.find(
'e') != string::npos);
744 for (Int_t ix = 1; ix <= h2.GetXaxis()->GetNbins(); ++ix) {
745 for (Int_t iy = 1; iy <= h2.GetYaxis()->GetNbins(); ++iy) {
746 W += h2.GetBinContent(ix,iy);
753 for (Int_t ix = 1; ix <= h2.GetXaxis()->GetNbins(); ++ix) {
754 for (Int_t iy = 1; iy <= h2.GetYaxis()->GetNbins(); ++iy) {
756 const Double_t
w = W * (bin_width ? h2.GetXaxis()->GetBinWidth(ix) * h2.GetYaxis()->GetBinWidth(iy) : 1.0);
758 h2.SetBinContent(ix, iy, h2.GetBinContent(ix,iy) * factor /
w);
761 h2.SetBinError(ix, iy, h2.GetBinError(ix,iy) * factor /
w);
769 for (Int_t iy = 1; iy <= h2.GetYaxis()->GetNbins(); ++iy) {
775 for (Int_t ix = 1; ix <= h2.GetXaxis()->GetNbins(); ++ix) {
776 W += h2.GetBinContent(ix,iy);
782 for (Int_t ix = 1; ix <= h2.GetXaxis()->GetNbins(); ++ix) {
784 const Double_t
w = W * (bin_width ? h2.GetXaxis()->GetBinWidth(ix) : 1.0);
786 h2.SetBinContent(ix, iy, h2.GetBinContent(ix,iy) * factor /
w);
789 h2.SetBinError(ix, iy, h2.GetBinError(ix,iy) * factor /
w);
797 for (Int_t ix = 1; ix <= h2.GetXaxis()->GetNbins(); ++ix) {
803 for (Int_t iy = 1; iy <= h2.GetYaxis()->GetNbins(); ++iy) {
804 W += h2.GetBinContent(ix,iy);
810 for (Int_t iy = 1; iy <= h2.GetYaxis()->GetNbins(); ++iy) {
812 const Double_t
w = W * (bin_width ? h2.GetYaxis()->GetBinWidth(iy) : 1.0);
814 h2.SetBinContent(ix, iy, h2.GetBinContent(ix,iy) /
w);
817 h2.SetBinError(ix, iy, h2.GetBinError(ix,iy) /
w);
835 Double_t ymin = numeric_limits<Double_t>::max();
836 Double_t ymax = numeric_limits<Double_t>::lowest();
838 for (Int_t i = 0; i != g1.GetN(); ++i) {
840 const Double_t y = g1.GetY()[i];
842 if (y > ymax) { ymax = y; }
843 if (y < ymin) { ymin = y; }
860 Double_t zmin = numeric_limits<Double_t>::max();
861 Double_t zmax = numeric_limits<Double_t>::lowest();
863 for (Int_t i = 0; i != g2.GetN(); ++i) {
865 const Double_t z = g2.GetZ()[i];
867 if (z > zmax) { zmax = z; }
868 if (z < zmin) { zmin = z; }
892 double dx = (xmax - xmin) * 0.1;
894 if (xmin > dx || xmin < 0.0)
926 if (axis->GetNbins() == (int) memo.size()) {
928 for (
int i = 0; i != axis->GetNbins(); ++i) {
930 const JPMTPhysicalAddress& address = memo[i];
932 axis->SetBinLabel(i + 1, address.toString().c_str());
959 if (axis ==
"x" || axis ==
"X")
961 else if (axis ==
"y" || axis ==
"Y")
963 else if (axis ==
"z" || axis ==
"Z")
968 if (pax->GetNbins() == (int) memo.size()) {
970 for (
int i = 0; i != pax->GetNbins(); ++i) {
974 pax->SetBinLabel(i + 1, address.toString().c_str());
977 h1.LabelsOption(
"a", axis.c_str());
static const char *const sqrt()
Set contents to signed difference between squares.
TObject * getObject(const JRootObjectID &id)
Get first TObject with given identifier.
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.
void setLogarithmicX(TF1 *f1)
Make parameter x of function logarithmic (e.g. after filling with log10()).
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
static const char *const Replace()
Set contents to associated function.
void setLimits(TGraph &g1)
Set limits of TGraph.
static const char *const subtract()
Subtract contents with lookup bin in second histogram.
then for HISTOGRAM in h0 h1
Auxiliary class to handle file name, ROOT directory and object name.
then usage $script< string identifier >< detectorfile > input file(toashort file)+" "\nNote that the input files and toashort files should be one-to-one related." fi if (( $
then fatal Wrong number of arguments fi set_variable STRING $argv[1] set_variable DETECTORXY_TXT $WORKDIR $DETECTORXY_TXT tail read X Y CHI2 RMS printf optimum n $X $Y $CHI2 $RMS awk v Y
static const char *const stdev()
Set contents to standard deviation.
then set_variable FORMULA *[0] exp(-0.5 *(x-[1])*(x-[1])/([2]*[2]))*exp(-0.5 *(y-[1])*(y-[1])/([2]*[2]))" JF2 -o $WORKDIR/f2.root -F "$FORMULA" -@ "p0
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
void setLogarithmic(TAxis *axis)
Make histogram axis logarithmic (e.g. after filling with log10()).
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 corresponding to give file name.
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)
Set axis with PMT address labels.
T pow(const T &x, const double y)
Power .
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.
const JPMTAddressTranslator & getAddressTranslator(const int tdc) const
Get PMT address translator.
static const char *const divide()
Divide contents with lookup bin in second histogram.
void copy(const Head &from, JHead &to)
Copy header from from to to.
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. part after last JEEP::PATHNAME_SEPARATOR if any.
void setLogarithmicY(TF2 *f2)
Make parameter y of function logarithmic (e.g. after filling with log10()).
Exception for accessing a value in a collection that is outside of its range.
TString getLogarithmic(const TString &formula, const char parameter)
Make given parameter in formula logarithmic (e.g. after filling with log10()).
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
static const char *const TIMESTAMP
Time stamp of earliest UTC time.
then usage $script[input file[working directory[option]]] nWhere option can be N
Double_t g1(const Double_t x)
Function.