1 #ifndef __JGIZMOTOOLKIT__
2 #define __JGIZMOTOOLKIT__
18 #include "TMultiGraph.h"
24 #include "TIterator.h"
26 #include "TMethodCall.h"
41 namespace JPP {
using namespace JGIZMO; }
66 static const char*
const Add() {
return "Add"; }
67 static const char*
const add() {
return "add"; }
68 static const char*
const Subtract() {
return "Subtract"; }
69 static const char*
const subtract() {
return "subtract"; }
70 static const char*
const Multiply() {
return "Multiply"; }
71 static const char*
const multiply() {
return "multiply"; }
72 static const char*
const Divide() {
return "Divide"; }
73 static const char*
const divide() {
return "divide"; }
74 static const char*
const efficiency() {
return "efficiency"; }
75 static const char*
const stdev() {
return "stdev"; }
76 static const char*
const sqrt() {
return "sqrt"; }
77 static const char*
const Replace() {
return "Replace"; }
84 static const char*
const TIMESTAMP =
"#splitline{}{#splitline{%d:%m:%y}{ %H:%M}}%F1970-01-01 00:00:00";
97 inline TFile*
getFile(
const std::string& file_name,
const std::string& option =
"exist")
101 gErrorIgnoreLevel = kError;
107 if (i == zmap.end() || i->second == NULL || !i->second->IsOpen()) {
109 TFile*
file = TFile::Open(file_name.c_str(), option.c_str());
111 zmap[file_name] =
file;
134 if (in == NULL || !in->IsOpen()) {
139 return in->GetDirectory(
id.getDirectory());
157 const TRegexp regexp(
id.getObjectName());
159 TIter iter(dir->GetListOfKeys());
161 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
163 const TString tag(key->GetName());
167 if (tag.Index(regexp) != -1) {
168 return key->ReadObj();
185 const TH1*
h1 =
dynamic_cast<const TH1*
>(object);
189 if (h1->GetSumw2N()) {
191 for (Int_t i = 1; i <= h1->GetNbinsX(); ++i) {
193 if (h1->GetBinError(i) != 0.0) {
224 TString buffer(text);
226 if (
object != NULL) {
228 TClass* p = TClass::GetClass(object->ClassName());
234 TIterator* iter = p->GetListOfAllPublicMethods()->MakeIterator();
235 TMethod* method = NULL;
237 for (TMethod* p; (p = (TMethod*) iter->Next()) != NULL; ) {
238 if (buffer.Index(p->GetName()) != -1) {
239 if (method == NULL || strlen(p->GetName()) > strlen(method->GetName())) {
245 if (method == NULL) {
249 for (Ssiz_t index; (index = buffer.Index(method->GetName())) != -1; ) {
251 const TRegexp fp(
" *([^)]*)");
254 Ssiz_t pos = buffer.Index(fp, &len, index);
258 if (pos == -1 || pos != index + (Ssiz_t) strlen(method->GetName())) {
260 TMethodCall(p, method->GetName(), NULL).Execute(
object, value);
262 len = strlen(method->GetName());
266 TMethodCall(p, method->GetName(), NULL).Execute(
object, TString(buffer(pos + 1, len - 2)), value);
268 len += strlen(method->GetName());
271 buffer.Replace(index, len, TString::Format(
"%15.5e", value));
277 return TFormula(
"/tmp", buffer.Data()).Eval(0.0);
297 return getResult(TString(text.c_str()),
object);
311 const char* regexp(
"p[0-9]* *=");
313 TString buffer(text.c_str());
315 buffer = buffer(TRegexp(regexp));
316 buffer = buffer(1, buffer.Length() - 2);
318 if (!buffer.IsDigit()) {
322 return buffer.Atoi();
342 const char* regexp(
"=.*");
344 TString buffer(text.c_str());
346 buffer = buffer(TRegexp(regexp));
347 buffer = buffer(1, buffer.Length() - 1);
349 return getResult(std::string(buffer),
object);
372 const char* regexp(
"=.*");
374 TString buffer(text.c_str());
376 buffer = buffer(TRegexp(regexp));
377 buffer = buffer(1, buffer.Length() - 1);
380 istringstream
is((std::string(buffer)));
384 for (
int i = index; is >> value && i > 0; --i) {}
389 THROW(
JParseError,
"Text des not contain a number at given position " << buffer <<
' ' << index);
402 const Int_t
first = axis->GetFirst();
403 const Int_t last = axis->GetLast();
405 const Double_t xmin = axis->GetBinLowEdge(first);
406 const Double_t xmax = axis->GetBinLowEdge(last) + axis->GetBinWidth(last);
408 const Int_t
N = axis->GetNbins();
409 Double_t buffer[N+1];
411 buffer[0] = TMath::Power(10.0, axis->GetBinLowEdge(1));
413 for (Int_t i = 1; i <=
N; ++i) {
414 buffer[i] = TMath::Power(10.0, axis->GetBinLowEdge(i) + axis->GetBinWidth(i));
417 axis->Set(N, buffer);
419 if (axis->TestBit(TAxis::kAxisRange)) {
420 axis->SetRangeUser(TMath::Power(10.0, xmin), TMath::Power(10.0, xmax));
435 const TRegexp regexp[] = {
436 TString(
"^") + TString(parameter) + TString(
"[^a-zA-Z_]"),
437 TString(
"[^a-zA-Z_]") + TString(parameter) + TString(
"[^a-zA-Z_]"),
438 TString(
"[^a-zA-Z_]") + TString(parameter) + TString(
"$")
441 const TString replacement = TString(
"log10(") + TString(parameter) + TString(
")");
443 TString buffer(formula);
445 if (buffer.Length() == 1 && buffer[0] == parameter) {
447 buffer = replacement;
451 for (Ssiz_t pos = 0, i; pos < buffer.Length(); pos += replacement.Length()) {
452 if ((i = buffer.Index(regexp[0], pos)) != -1) { buffer.Replace((pos = i + 0), 1, replacement); }
453 else if ((i = buffer.Index(regexp[1], pos)) != -1) { buffer.Replace((pos = i + 1), 1, replacement); }
454 else if ((i = buffer.Index(regexp[2], pos)) != -1) { buffer.Replace((pos = i + 1), 1, replacement); }
468 inline void copy(
const TF1& from, TF1& to)
470 static_cast<TAttLine&
> (to) = static_cast<const TAttLine&> (from);
471 static_cast<TAttFill&
> (to) = static_cast<const TAttFill&> (from);
472 static_cast<TAttMarker&
>(to) = static_cast<const TAttMarker&>(from);
474 to.SetParameters(from.GetParameters());
476 to.SetNpx(from.GetNpx());
486 inline void copy(
const TF2& from, TF2& to)
488 copy(static_cast<const TF1&>(from), static_cast<TF1&>(to));
490 to.SetNpy(from.GetNpy());
507 fn.SetRange(f1->GetXmin(),
512 f1->SetRange(TMath::Power(10.0,f1->GetXmin()),
513 TMath::Power(10.0,f1->GetXmax()));
531 fn.SetRange(f2->GetXmin(),
538 f2->SetRange(TMath::Power(10.0,f2->GetXmin()),
540 TMath::Power(10.0,f2->GetXmax()),
559 fn.SetRange(f2->GetXmin(),
566 f2->SetRange(f2->GetXmin(),
567 TMath::Power(10.0,f2->GetYmin()),
569 TMath::Power(10.0,f2->GetYmax()));
583 for (TIter iter(h1->GetListOfFunctions()); TF1* f1 =
dynamic_cast<TF1*
>(iter.Next()); ) {
603 for (TIter iter(h2->GetListOfFunctions()); TF2* f2 =
dynamic_cast<TF2*
>(iter.Next()); ) {
621 for (TIter iter(h2->GetListOfFunctions()); TF2* f2 =
dynamic_cast<TF2*
>(iter.Next()); ) {
639 for (TIter iter(g1->GetListOfFunctions()); TF1* f1 =
dynamic_cast<TF1*
>(iter.Next()); ) {
643 for (Int_t i = 0; i != g1->GetN(); ++i) {
644 g1->GetX()[i] =
pow(10.0, g1->GetX()[i]);
659 for (TIter iter(g2->GetListOfFunctions()); TF2* f2 =
dynamic_cast<TF2*
>(iter.Next()); ) {
663 for (Int_t i = 0; i != g2->GetN(); ++i) {
664 g2->GetX()[i] =
pow(10.0, g2->GetX()[i]);
679 for (TIter iter(g2->GetListOfFunctions()); TF2* f2 =
dynamic_cast<TF2*
>(iter.Next()); ) {
683 for (Int_t i = 0; i != g2->GetN(); ++i) {
684 g2->GetY()[i] =
pow(10.0, g2->GetY()[i]);
699 for (TIter i1(m1->GetListOfGraphs()); TGraph*
g1 =
dynamic_cast<TGraph*
>(i1()); ) {
718 inline void convertToPDF(TH1&
h1,
const std::string& option =
"NW",
const double factor = 1.0)
722 const bool normalise = (option.find(
'N') != string::npos || option.find(
'n') != string::npos);
723 const bool bin_width = (option.find(
'W') != string::npos || option.find(
'w') != string::npos);
724 const bool use_error = (option.find(
'E') != string::npos || option.find(
'e') != string::npos);
732 for (Int_t i = 1; i <= h1.GetXaxis()->GetNbins(); ++i) {
733 W += h1.GetBinContent(i);
739 for (Int_t i = 1; i <= h1.GetXaxis()->GetNbins(); ++i) {
741 const Double_t
w = W * (bin_width ? h1.GetXaxis()->GetBinWidth(i) : 1.0);
743 h1.SetBinContent(i, h1.GetBinContent(i) * factor /
w);
746 h1.SetBinError(i, h1.GetBinError(i) * factor /
w);
767 inline void convertToPDF(TH2& h2,
const std::string& option =
"NXYW",
const double factor = 1.0)
771 const bool normalise = (option.find(
'N') != string::npos || option.find(
'n') != string::npos);
772 const bool X = (option.find(
'X') != string::npos || option.find(
'x') != string::npos);
773 const bool Y = (option.find(
'Y') != string::npos || option.find(
'y') != string::npos);
774 const bool bin_width = (option.find(
'W') != string::npos || option.find(
'w') != string::npos);
775 const bool use_error = (option.find(
'E') != string::npos || option.find(
'e') != string::npos);
785 for (Int_t ix = 1; ix <= h2.GetXaxis()->GetNbins(); ++ix) {
786 for (Int_t iy = 1; iy <= h2.GetYaxis()->GetNbins(); ++iy) {
787 W += h2.GetBinContent(ix,iy);
794 for (Int_t ix = 1; ix <= h2.GetXaxis()->GetNbins(); ++ix) {
795 for (Int_t iy = 1; iy <= h2.GetYaxis()->GetNbins(); ++iy) {
797 const Double_t
w = W * (bin_width ? h2.GetXaxis()->GetBinWidth(ix) * h2.GetYaxis()->GetBinWidth(iy) : 1.0);
799 h2.SetBinContent(ix, iy, h2.GetBinContent(ix,iy) * factor /
w);
802 h2.SetBinError(ix, iy, h2.GetBinError(ix,iy) * factor /
w);
810 for (Int_t iy = 1; iy <= h2.GetYaxis()->GetNbins(); ++iy) {
816 for (Int_t ix = 1; ix <= h2.GetXaxis()->GetNbins(); ++ix) {
817 W += h2.GetBinContent(ix,iy);
823 for (Int_t ix = 1; ix <= h2.GetXaxis()->GetNbins(); ++ix) {
825 const Double_t
w = W * (bin_width ? h2.GetXaxis()->GetBinWidth(ix) : 1.0);
827 h2.SetBinContent(ix, iy, h2.GetBinContent(ix,iy) * factor /
w);
830 h2.SetBinError(ix, iy, h2.GetBinError(ix,iy) * factor /
w);
838 for (Int_t ix = 1; ix <= h2.GetXaxis()->GetNbins(); ++ix) {
844 for (Int_t iy = 1; iy <= h2.GetYaxis()->GetNbins(); ++iy) {
845 W += h2.GetBinContent(ix,iy);
851 for (Int_t iy = 1; iy <= h2.GetYaxis()->GetNbins(); ++iy) {
853 const Double_t
w = W * (bin_width ? h2.GetYaxis()->GetBinWidth(iy) : 1.0);
855 h2.SetBinContent(ix, iy, h2.GetBinContent(ix,iy) /
w);
858 h2.SetBinError(ix, iy, h2.GetBinError(ix,iy) /
w);
876 Double_t ymin = numeric_limits<Double_t>::max();
877 Double_t ymax = numeric_limits<Double_t>::lowest();
879 for (Int_t i = 0; i != g1.GetN(); ++i) {
881 const Double_t y = g1.GetY()[i];
883 if (y > ymax) { ymax = y; }
884 if (y < ymin) { ymin = y; }
901 Double_t zmin = numeric_limits<Double_t>::max();
902 Double_t zmax = numeric_limits<Double_t>::lowest();
904 for (Int_t i = 0; i != g2.GetN(); ++i) {
906 const Double_t z = g2.GetZ()[i];
908 if (z > zmax) { zmax = z; }
909 if (z < zmin) { zmin = z; }
933 double dx = (xmax - xmin) * 0.1;
935 if (xmin > dx || xmin < 0.0)
967 if (axis->GetNbins() == (int) memo.size()) {
969 for (
int i = 0; i != axis->GetNbins(); ++i) {
971 const JPMTPhysicalAddress& address = memo[i];
973 axis->SetBinLabel(i + 1, address.toString().c_str());
1000 if (axis ==
"x" || axis ==
"X")
1001 pax = h1.GetXaxis();
1002 else if (axis ==
"y" || axis ==
"Y")
1003 pax = h1.GetYaxis();
1004 else if (axis ==
"z" || axis ==
"Z")
1005 pax = h1.GetZaxis();
1009 if (pax->GetNbins() == (int) memo.size()) {
1011 for (
int i = 0; i != pax->GetNbins(); ++i) {
1015 pax->SetBinLabel(i + 1, address.toString().c_str());
1018 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 .
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 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.