1 #ifndef __JGIZMOTOOLKIT__
2 #define __JGIZMOTOOLKIT__
17 #include "TGraphErrors.h"
19 #include "TGraph2DErrors.h"
20 #include "TMultiGraph.h"
28 #include "TIterator.h"
30 #include "TMethodCall.h"
45 namespace JPP {
using namespace JGIZMO; }
71 static const char*
const Add() {
return "Add"; }
72 static const char*
const add() {
return "add"; }
73 static const char*
const Subtract() {
return "Subtract"; }
74 static const char*
const subtract() {
return "subtract"; }
75 static const char*
const Multiply() {
return "Multiply"; }
76 static const char*
const multiply() {
return "multiply"; }
77 static const char*
const Divide() {
return "Divide"; }
78 static const char*
const divide() {
return "divide"; }
79 static const char*
const efficiency() {
return "efficiency"; }
80 static const char*
const stdev() {
return "stdev"; }
81 static const char*
const sqrt() {
return "sqrt"; }
82 static const char*
const Replace() {
return "Replace"; }
89 static const char*
const TIMESTAMP =
"#splitline{}{#splitline{%d:%m:%y}{ %H:%M}}%F1970-01-01 00:00:00";
102 inline TFile*
getFile(
const std::string& file_name,
const std::string& option =
"exist")
106 gErrorIgnoreLevel = kError;
112 if (i == zmap.end() || i->second == NULL || !i->second->IsOpen()) {
114 TFile*
file = TFile::Open(file_name.c_str(), option.c_str());
116 zmap[file_name] =
file;
139 if (in == NULL || !in->IsOpen()) {
144 return in->GetDirectory(
id.getDirectory());
162 const TRegexp regexp(
id.getObjectName());
164 TIter iter(dir->GetListOfKeys());
166 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
168 const TString tag(key->GetName());
172 if (tag.Index(regexp) != -1) {
173 return key->ReadObj();
191 const TH1*
h1 =
dynamic_cast<const TH1*
>(object);
195 if (h1->GetSumw2N()) {
196 for (Int_t i = 1; i <= h1->GetNbinsX(); ++i) {
197 if (h1->GetBinError(i) != 0.0) {
205 const TGraphErrors*
g1 =
dynamic_cast<const TGraphErrors*
>(object);
209 for (Int_t i = 0; i != g1->GetN(); ++i) {
210 if (g1->GetEY()[i] != 0.0) {
215 return g1->GetN() > 1;
219 const TGraph*
g1 =
dynamic_cast<const TGraph*
>(object);
222 return g1->GetN() > 1;
246 TString buffer(text);
248 if (
object != NULL) {
250 TClass* p = TClass::GetClass(object->ClassName());
256 TIterator* iter = p->GetListOfAllPublicMethods()->MakeIterator();
257 TMethod* method = NULL;
259 for (TMethod* p; (p = (TMethod*) iter->Next()) != NULL; ) {
260 if (buffer.Index(p->GetName()) != -1) {
261 if (method == NULL || strlen(p->GetName()) > strlen(method->GetName())) {
267 if (method == NULL) {
271 for (Ssiz_t index; (index = buffer.Index(method->GetName())) != -1; ) {
273 const TRegexp fp(
" *([^)]*)");
276 Ssiz_t pos = buffer.Index(fp, &len, index);
280 if (pos == -1 || pos != index + (Ssiz_t) strlen(method->GetName())) {
282 TMethodCall(p, method->GetName(), NULL).Execute(
object, value);
284 len = strlen(method->GetName());
288 TMethodCall(p, method->GetName(), NULL).Execute(
object, TString(buffer(pos + 1, len - 2)), value);
290 len += strlen(method->GetName());
293 buffer.Replace(index, len, TString::Format(
"%15.5e", value));
299 return TFormula(
"/tmp", buffer.Data()).Eval(0.0);
319 return getResult(TString(text.c_str()),
object);
333 const char* regexp(
"p[0-9]* *=");
335 TString buffer(text.c_str());
337 buffer = buffer(TRegexp(regexp));
338 buffer = buffer(1, buffer.Length() - 2);
340 if (!buffer.IsDigit()) {
344 return buffer.Atoi();
364 const char* regexp(
"=.*");
366 TString buffer(text.c_str());
368 buffer = buffer(TRegexp(regexp));
369 buffer = buffer(1, buffer.Length() - 1);
371 return getResult(std::string(buffer),
object);
394 const char* regexp(
"=.*");
396 TString buffer(text.c_str());
398 buffer = buffer(TRegexp(regexp));
399 buffer = buffer(1, buffer.Length() - 1);
402 istringstream
is((std::string(buffer)));
406 for (
int i = index; is >> value && i > 0; --i) {}
411 THROW(
JParseError,
"Text des not contain a number at given position " << buffer <<
' ' << index);
424 const Int_t
first = axis->GetFirst();
425 const Int_t last = axis->GetLast();
427 const Double_t xmin = axis->GetBinLowEdge(first);
428 const Double_t xmax = axis->GetBinLowEdge(last) + axis->GetBinWidth(last);
430 const Int_t
N = axis->GetNbins();
431 Double_t buffer[N+1];
433 buffer[0] = TMath::Power(10.0, axis->GetBinLowEdge(1));
435 for (Int_t i = 1; i <=
N; ++i) {
436 buffer[i] = TMath::Power(10.0, axis->GetBinLowEdge(i) + axis->GetBinWidth(i));
439 axis->Set(N, buffer);
441 if (axis->TestBit(TAxis::kAxisRange)) {
442 axis->SetRangeUser(TMath::Power(10.0, xmin), TMath::Power(10.0, xmax));
457 const TRegexp regexp[] = {
458 TString(
"^") + TString(parameter) + TString(
"[^a-zA-Z_]"),
459 TString(
"[^a-zA-Z_]") + TString(parameter) + TString(
"[^a-zA-Z_]"),
460 TString(
"[^a-zA-Z_]") + TString(parameter) + TString(
"$")
463 const TString replacement = TString(
"log10(") + TString(parameter) + TString(
")");
465 TString buffer(formula);
467 if (buffer.Length() == 1 && buffer[0] == parameter) {
469 buffer = replacement;
473 for (Ssiz_t pos = 0, i; pos < buffer.Length(); pos += replacement.Length()) {
474 if ((i = buffer.Index(regexp[0], pos)) != -1) { buffer.Replace((pos = i + 0), 1, replacement); }
475 else if ((i = buffer.Index(regexp[1], pos)) != -1) { buffer.Replace((pos = i + 1), 1, replacement); }
476 else if ((i = buffer.Index(regexp[2], pos)) != -1) { buffer.Replace((pos = i + 1), 1, replacement); }
491 inline void copy(
const TF1& from, TF1& to)
493 static_cast<TAttLine&
> (to) = static_cast<const TAttLine&> (from);
494 static_cast<TAttFill&
> (to) = static_cast<const TAttFill&> (from);
495 static_cast<TAttMarker&
>(to) = static_cast<const TAttMarker&>(from);
497 to.SetParameters(from.GetParameters());
499 to.SetNpx(from.GetNpx());
509 inline void copy(
const TF2& from, TF2& to)
511 copy(static_cast<const TF1&>(from), static_cast<TF1&>(to));
513 to.SetNpy(from.GetNpy());
548 fn.SetRange(f1->GetXmin(),
553 f1->SetRange(TMath::Power(10.0,f1->GetXmin()),
554 TMath::Power(10.0,f1->GetXmax()));
568 TString buffer = f1->GetExpFormula();
570 buffer =
"pow(10.0, " + buffer +
")";
572 TF1 fn(f1->GetName(), buffer);
594 fn.SetRange(f2->GetXmin(),
601 f2->SetRange(TMath::Power(10.0,f2->GetXmin()),
603 TMath::Power(10.0,f2->GetXmax()),
622 fn.SetRange(f2->GetXmin(),
629 f2->SetRange(f2->GetXmin(),
630 TMath::Power(10.0,f2->GetYmin()),
632 TMath::Power(10.0,f2->GetYmax()));
646 setLogarithmicX<TF1>(h1->GetListOfFunctions());
664 setLogarithmicX<TF2>(h2->GetListOfFunctions());
680 setLogarithmicY<TF2>(h2->GetListOfFunctions());
696 setLogarithmicX<TF1>(g1->GetListOfFunctions());
698 for (Int_t i = 0; i != g1->GetN(); ++i) {
699 g1->GetX()[i] =
pow(10.0, g1->GetX()[i]);
714 setLogarithmicY<TF1>(g1->GetListOfFunctions());
716 for (Int_t i = 0; i != g1->GetN(); ++i) {
717 g1->GetY()[i] =
pow(10.0, g1->GetY()[i]);
732 setLogarithmicX<TF1>(g1->GetListOfFunctions());
734 for (Int_t i = 0; i != g1->GetN(); ++i) {
735 g1->GetEX()[i] =
pow(10.0, g1->GetX()[i] + g1->GetEX()[i]) -
pow(10.0, g1->GetX()[i]);
736 g1->GetX() [i] =
pow(10.0, g1->GetX()[i]);
751 setLogarithmicY<TF1>(g1->GetListOfFunctions());
753 for (Int_t i = 0; i != g1->GetN(); ++i) {
754 g1->GetEY()[i] =
pow(10.0, g1->GetY()[i] + g1->GetEY()[i]) -
pow(10.0, g1->GetY()[i]);
755 g1->GetY() [i] =
pow(10.0, g1->GetY()[i]);
770 setLogarithmicX<TF2>(g2->GetListOfFunctions());
772 for (Int_t i = 0; i != g2->GetN(); ++i) {
773 g2->GetX()[i] =
pow(10.0, g2->GetX()[i]);
788 setLogarithmicY<TF2>(g2->GetListOfFunctions());
790 for (Int_t i = 0; i != g2->GetN(); ++i) {
791 g2->GetY()[i] =
pow(10.0, g2->GetY()[i]);
806 setLogarithmicX<TF2>(g2->GetListOfFunctions());
808 for (Int_t i = 0; i != g2->GetN(); ++i) {
809 g2->GetEX()[i] =
pow(10.0, g2->GetX()[i] + g2->GetEX()[i]) -
pow(10.0, g2->GetX()[i]);
810 g2->GetX() [i] =
pow(10.0, g2->GetX()[i]);
825 setLogarithmicY<TF2>(g2->GetListOfFunctions());
827 for (Int_t i = 0; i != g2->GetN(); ++i) {
828 g2->GetEY()[i] =
pow(10.0, g2->GetY()[i] + g2->GetEY()[i]) -
pow(10.0, g2->GetY()[i]);
829 g2->GetY() [i] =
pow(10.0, g2->GetY()[i]);
843 setLogarithmicX<TGraph>(gn->GetListOfGraphs());
856 setLogarithmicY<TGraph>(gn->GetListOfGraphs());
869 line->SetX1(
pow(10.0, line->GetX1()));
870 line->SetX2(
pow(10.0, line->GetX2()));
883 line->SetY1(
pow(10.0, line->GetY1()));
884 line->SetY2(
pow(10.0, line->GetY2()));
919 for (TIter i(list);
T* p =
dynamic_cast<T*
>(i.Next()); ) {
933 for (TIter i(list);
T* p =
dynamic_cast<T*
>(i.Next()); ) {
951 inline void convertToPDF(TH1&
h1,
const std::string& option =
"NW",
const double factor = 1.0)
955 const bool normalise = (option.find(
'N') != string::npos || option.find(
'n') != string::npos);
956 const bool bin_width = (option.find(
'W') != string::npos || option.find(
'w') != string::npos);
957 const bool use_error = (option.find(
'E') != string::npos || option.find(
'e') != string::npos);
965 for (Int_t i = 1; i <= h1.GetXaxis()->GetNbins(); ++i) {
966 W += h1.GetBinContent(i);
972 for (Int_t i = 1; i <= h1.GetXaxis()->GetNbins(); ++i) {
974 const Double_t
w = W * (bin_width ? h1.GetXaxis()->GetBinWidth(i) : 1.0);
976 h1.SetBinContent(i, h1.GetBinContent(i) * factor /
w);
979 h1.SetBinError(i, h1.GetBinError(i) * factor /
w);
1000 inline void convertToPDF(TH2& h2,
const std::string& option =
"NXYW",
const double factor = 1.0)
1002 using namespace std;
1004 const bool normalise = (option.find(
'N') != string::npos || option.find(
'n') != string::npos);
1005 const bool X = (option.find(
'X') != string::npos || option.find(
'x') != string::npos);
1006 const bool Y = (option.find(
'Y') != string::npos || option.find(
'y') != string::npos);
1007 const bool bin_width = (option.find(
'W') != string::npos || option.find(
'w') != string::npos);
1008 const bool use_error = (option.find(
'E') != string::npos || option.find(
'e') != string::npos);
1018 for (Int_t ix = 1; ix <= h2.GetXaxis()->GetNbins(); ++ix) {
1019 for (Int_t iy = 1; iy <= h2.GetYaxis()->GetNbins(); ++iy) {
1020 W += h2.GetBinContent(ix,iy);
1027 for (Int_t ix = 1; ix <= h2.GetXaxis()->GetNbins(); ++ix) {
1028 for (Int_t iy = 1; iy <= h2.GetYaxis()->GetNbins(); ++iy) {
1030 const Double_t
w = W * (bin_width ? h2.GetXaxis()->GetBinWidth(ix) * h2.GetYaxis()->GetBinWidth(iy) : 1.0);
1032 h2.SetBinContent(ix, iy, h2.GetBinContent(ix,iy) * factor /
w);
1035 h2.SetBinError(ix, iy, h2.GetBinError(ix,iy) * factor /
w);
1043 for (Int_t iy = 1; iy <= h2.GetYaxis()->GetNbins(); ++iy) {
1049 for (Int_t ix = 1; ix <= h2.GetXaxis()->GetNbins(); ++ix) {
1050 W += h2.GetBinContent(ix,iy);
1056 for (Int_t ix = 1; ix <= h2.GetXaxis()->GetNbins(); ++ix) {
1058 const Double_t
w = W * (bin_width ? h2.GetXaxis()->GetBinWidth(ix) : 1.0);
1060 h2.SetBinContent(ix, iy, h2.GetBinContent(ix,iy) * factor /
w);
1063 h2.SetBinError(ix, iy, h2.GetBinError(ix,iy) * factor /
w);
1071 for (Int_t ix = 1; ix <= h2.GetXaxis()->GetNbins(); ++ix) {
1077 for (Int_t iy = 1; iy <= h2.GetYaxis()->GetNbins(); ++iy) {
1078 W += h2.GetBinContent(ix,iy);
1084 for (Int_t iy = 1; iy <= h2.GetYaxis()->GetNbins(); ++iy) {
1086 const Double_t
w = W * (bin_width ? h2.GetYaxis()->GetBinWidth(iy) : 1.0);
1088 h2.SetBinContent(ix, iy, h2.GetBinContent(ix,iy) /
w);
1091 h2.SetBinError(ix, iy, h2.GetBinError(ix,iy) /
w);
1107 using namespace std;
1109 Double_t ymin = numeric_limits<Double_t>::max();
1110 Double_t ymax = numeric_limits<Double_t>::lowest();
1112 for (Int_t i = 0; i != g1.GetN(); ++i) {
1114 const Double_t y = g1.GetY()[i];
1116 if (y > ymax) { ymax = y; }
1117 if (y < ymin) { ymin = y; }
1120 g1.SetMinimum(ymin);
1121 g1.SetMaximum(ymax);
1132 using namespace std;
1134 Double_t zmin = numeric_limits<Double_t>::max();
1135 Double_t zmax = numeric_limits<Double_t>::lowest();
1137 for (Int_t i = 0; i != g2.GetN(); ++i) {
1139 const Double_t z = g2.GetZ()[i];
1141 if (z > zmax) { zmax = z; }
1142 if (z < zmin) { zmin = z; }
1145 g2.SetMinimum(zmin);
1146 g2.SetMaximum(zmax);
1166 double dx = (xmax - xmin) * 0.1;
1168 if (xmin > dx || xmin < 0.0)
1198 using namespace JPP;
1200 if (axis->GetNbins() == (int) memo.size()) {
1202 for (
int i = 0; i != axis->GetNbins(); ++i) {
1204 const JPMTPhysicalAddress& address = memo[i];
1206 axis->SetBinLabel(i + 1, address.toString().c_str());
1229 using namespace JPP;
1233 if (axis ==
"x" || axis ==
"X")
1234 pax = h1.GetXaxis();
1235 else if (axis ==
"y" || axis ==
"Y")
1236 pax = h1.GetYaxis();
1237 else if (axis ==
"z" || axis ==
"Z")
1238 pax = h1.GetZaxis();
1242 if (pax->GetNbins() == (int) memo.size()) {
1244 for (
int i = 0; i != pax->GetNbins(); ++i) {
1248 pax->SetBinLabel(i + 1, address.toString().c_str());
1251 h1.LabelsOption(
"a", axis.c_str());
1268 return (key != NULL && TClass::GetClass(key->GetClassName())->IsTObject());
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.
Exception for a functional operation.
static const char *const SAME_AS_INPUT()
Set name of output histogram to name of input histogram.
then set_variable PMT_FILE set_variable DAQ_FILE set_variable OUTPUT_FILE set_variable DETECTOR else fatal Wrong number of arguments fi set_variable RUNBYRUN file
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
static const char *const Replace()
Set contents to associated function.
then JShowerPostfit f $INPUT_FILE o $OUTPUT_FILE N
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 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 fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable STRING $argv[2] set_array QUANTILES set_variable FORMULA *[0] exp(-0.5 *(x-[1])*(x-[1])/([2]*[2]))" set_variable MODULE `getModule -a $DETECTOR -L "$STRING 0"` source JAcoustics.sh -- typeset -A TRIPODS get_tripods $WORKDIR/tripod.txt TRIPODS XMEAN
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 using 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.
void setLogarithmicX(TList *list)
Make x-axis of objects in list logarithmic (e.g. after using log10()).
Double_t getResult(const TString &text, TObject *object=NULL)
Get result of given textual formula.
do set_variable OUTPUT_DIRECTORY $WORKDIR T
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 .
then break fi done getCenter read X Y Z let X
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 setLogarithmicY(TList *list)
Make y-axis of objects in list logarithmic (e.g. after using log10()).
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.
bool isTObject(const TKey *key)
Check if given key corresponds to a TObject.
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.
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 using 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.
Double_t g1(const Double_t x)
Function.