Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Functions | Variables
JGIZMO Namespace Reference

Auxiliary applications for use of ROOT and more. More...

Classes

class  JCanvas
 Data structure for size of TCanvas. More...
 
struct  JOpera
 Auxiliary data structure for JOpera1D.cc and JOpera2D.cc applications. More...
 
class  JLegend
 Wrapper class for ROOT TLegend. More...
 
class  JLineAttributes
 Auxiliary class to set line attributes. More...
 
class  JManager
 Auxiliary class to manage set of compatible ROOT objects (e.g. More...
 
class  JMarkerAttributes
 Auxiliary class to set marker attributes. More...
 
class  JRootObject
 Auxiliary data structure for TObject with a user defined label. More...
 
class  JRootObjectID
 Auxiliary class to handle file name, ROOT directory and object name. More...
 
class  JStyle
 Wrapper class around ROOT TStyle. More...
 
struct  JVolume
 Auxiliary class for histogramming of effective volume. More...
 

Functions

TFile * getFile (const std::string &file_name, const std::string &option="exist")
 Get TFile pointer. More...
 
TDirectory * getDirectory (const JRootObjectID &id)
 Get TDirectory pointer. More...
 
TObjectgetObject (const JRootObjectID &id)
 Get TObject. More...
 
bool isTAttLine (const TObject *object)
 Get drawing option of TH1. More...
 
Double_t getResult (const TString &text, TObject *object=NULL)
 Get result of given textual formula. More...
 
Double_t getResult (const std::string &text, TObject *object=NULL)
 Get result of given textual formula. More...
 
int getParameter (const std::string &text)
 Get parameter number from text string. More...
 
Double_t getValue (const std::string &text, TObject *object=NULL)
 Get parameter value from text string. More...
 
void setLogarithm (TAxis *axis)
 Make axis logarithmic (e.g. More...
 
void convertToPDF (TH1 &h1, const std::string &option="NW", const double factor=1.0)
 Convert 1D histogram to PDF. More...
 
void convertToPDF (TH2 &h2, const std::string &option="NXYW", const double factor=1.0)
 Convert 2D histogram to PDF. More...
 
void setLimits (TGraph &g1)
 Set limits of TGraph. More...
 
void setLimits (TGraph2D &g2)
 Set limits of TGraph2D. More...
 
void setRange (double &xmin, double &xmax, const bool logx)
 Set axis range. More...
 
void setAxisLabels (TAxis *axis, const JModuleAddressMap &memo)
 initialize axis with PMT address labels More...
 

Variables

static const char LABEL_TERMINATOR = '&'
 label terminator More...
 

Detailed Description

Auxiliary applications for use of ROOT and more.

Author
mdejong

Function Documentation

TFile* JGIZMO::getFile ( const std::string &  file_name,
const std::string &  option = "exist" 
)
inline

Get TFile pointer.


The TFile pointer of an already opened file is recovered, else a new file is opened.

Parameters
file_namefile name
optionTFile::Open option
Returns
pointer to TFile

Definition at line 84 of file JGizmoToolkit.hh.

85  {
86  using namespace std;
87 
88  gErrorIgnoreLevel = kError;
89 
90  static map<string, TFile*> zmap;
91 
92  map<string, TFile*>::iterator i = zmap.find(file_name);
93 
94  if (i == zmap.end() || i->second == NULL || !i->second->IsOpen()) {
95 
96  TFile* file = TFile::Open(file_name.c_str(), option.c_str());
97 
98  zmap[file_name] = file;
99 
100  return file;
101 
102  } else {
103 
104  return i->second;
105  }
106  }
TDirectory* JGIZMO::getDirectory ( const JRootObjectID id)
inline

Get TDirectory pointer.


The TFile pointer of an already opened file is recovered, else a new file is opened.

Parameters
ididentifier
Returns
pointer to TDirectory

Definition at line 116 of file JGizmoToolkit.hh.

117  {
118  TFile* in = getFile(id.getFilename().c_str(), "exist");
119 
120  if (in == NULL || !in->IsOpen()) {
121  return NULL;
122  }
123 
124  if (id.getDirectory() != "")
125  return in->GetDirectory(id.getDirectory());
126  else
127  return in;
128  }
TFile * getFile(const std::string &file_name, const std::string &option="exist")
Get TFile pointer.
TDirectory * getDirectory(const JRootObjectID &id)
Get TDirectory pointer.
std::string getFilename(const std::string &file_name)
Get file name part, i.e.
Definition: JeepToolkit.hh:85
TObject* JGIZMO::getObject ( const JRootObjectID id)
inline

Get TObject.

Parameters
ididentifier
Returns
pointer to TObject (or NULL)

Definition at line 137 of file JGizmoToolkit.hh.

138  {
139  TDirectory* dir = getDirectory(id);
140 
141  if (dir != NULL) {
142 
143  const TRegexp regexp(id.getObjectName());
144 
145  TIter iter(dir->GetListOfKeys());
146 
147  for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
148 
149  const TString tag(key->GetName());
150 
151  // option match
152 
153  if (tag.Index(regexp) != -1) {
154  return key->ReadObj();
155  }
156  }
157  }
158 
159  return NULL;
160  }
TDirectory * getDirectory(const JRootObjectID &id)
Get TDirectory pointer.
bool JGIZMO::isTAttLine ( const TObject object)
inline

Get drawing option of TH1.

Parameters
objectpointer to TObject
Returns
true if TH1 looks a line; else false

Definition at line 169 of file JGizmoToolkit.hh.

170  {
171  const TH1* h1 = dynamic_cast<const TH1*>(object);
172 
173  if (h1 != NULL) {
174 
175  if (h1->GetSumw2N()) {
176 
177  for (Int_t i = 1; i <= h1->GetNbinsX(); ++i) {
178 
179  if (h1->GetBinError(i) != 0.0) {
180  return false;
181  }
182  }
183  }
184 
185  return true;
186 
187  } else {
188 
189  return false;
190  }
191  }
Double_t JGIZMO::getResult ( const TString &  text,
TObject object = NULL 
)
inline

Get result of given textual formula.


The formula may contain names of member methods of the object pointed to. These methods should have no arguments and the return type Double_t. Example:

        getResult("1.0/GetEntries", TH1*);
Parameters
texttext
objectpointer to object
Returns
value

Definition at line 207 of file JGizmoToolkit.hh.

208  {
209  TString buffer(text);
210 
211  if (object != NULL) {
212 
213  TClass* p = TClass::GetClass(object->ClassName());
214 
215  if (p != NULL) {
216 
217  TIterator* iter = p->GetListOfAllPublicMethods()->MakeIterator();
218 
219  for (TMethod* method; (method = (TMethod*) iter->Next()) != NULL; ) {
220 
221  if (buffer.Contains(method->GetName())) {
222 
223  Double_t value;
224 
225  TMethodCall(p, method->GetName(), NULL).Execute(object, value);
226 
227  buffer.ReplaceAll(method->GetName(), TString::Format("%f", value));
228  }
229  }
230  }
231  }
232 
233  return TFormula("/tmp", buffer.Data()).Eval(0.0);
234  }
Double_t JGIZMO::getResult ( const std::string &  text,
TObject object = NULL 
)
inline

Get result of given textual formula.


The formula may contain names of member methods of the object pointed to. These methods should have no arguments and the return type Double_t. Example:

        getResult("1.0/GetEntries", TH1*);
Parameters
texttext
objectpointer to object
Returns
value

Definition at line 250 of file JGizmoToolkit.hh.

251  {
252  return getResult(TString(text.c_str()), object);
253  }
Double_t getResult(const TString &text, TObject *object=NULL)
Get result of given textual formula.
int JGIZMO::getParameter ( const std::string &  text)
inline

Get parameter number from text string.


The number corresponds to the value [0-9]* in the expression "p[0-9]* = ..".

Parameters
texttext
Returns
parameter number

Definition at line 263 of file JGizmoToolkit.hh.

264  {
265  const char* regexp("p[0-9]* *=");
266 
267  TString buffer(text.c_str());
268 
269  buffer = buffer(TRegexp(regexp));
270  buffer = buffer(1, buffer.Length() - 2);
271 
272  if (!buffer.IsDigit()) {
273  THROW(JParseError, "Text is not a number " << text << ' ' << regexp);
274  }
275 
276  return buffer.Atoi();
277  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:633
Double_t JGIZMO::getValue ( const std::string &  text,
TObject object = NULL 
)
inline

Get parameter value from text string.


The formula may contain names of member methods of the object pointed to. These methods should have no arguments and the return type Double_t. Example:

        getValue("p[..] = 2*GetMaximum", TH1*);
Parameters
texttext
objectpointer to object
Returns
value

Definition at line 293 of file JGizmoToolkit.hh.

294  {
295  const char* regexp("=.*");
296 
297  TString buffer(text.c_str());
298 
299  buffer = buffer(TRegexp(regexp));
300  buffer = buffer(1, buffer.Length() - 1);
301 
302  return getResult(std::string(buffer), object);
303  }
Double_t getResult(const TString &text, TObject *object=NULL)
Get result of given textual formula.
void JGIZMO::setLogarithm ( TAxis *  axis)
inline

Make axis logarithmic (e.g.

after filling with log10()).

Parameters
axisaxis

Definition at line 311 of file JGizmoToolkit.hh.

312  {
313  if (axis != NULL) {
314 
315  const int N = axis->GetNbins();
316  Double_t buffer[N+1];
317 
318  buffer[0] = TMath::Power(10.0, axis->GetBinLowEdge(1));
319 
320  for (int i = 1; i <= N; ++i) {
321  buffer[i] = TMath::Power(10.0, axis->GetBinLowEdge(i) + axis->GetBinWidth(i));
322  }
323 
324  axis->Set(N, buffer);
325  }
326  }
void JGIZMO::convertToPDF ( TH1 &  h1,
const std::string &  option = "NW",
const double  factor = 1.0 
)
inline

Convert 1D histogram to PDF.

Possible options are:

  • N normalise to histogram contents;
  • W divide by bin width;
  • E convert also bin errors.
Parameters
h1histogram
optionoption
factorscaling factor

Definition at line 341 of file JGizmoToolkit.hh.

342  {
343  using namespace std;
344 
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);
348 
349  Double_t W = 1.0;
350 
351  if (normalise) {
352 
353  W = 0.0;
354 
355  for (Int_t i = 1; i <= h1.GetXaxis()->GetNbins(); ++i) {
356  W += h1.GetBinContent(i);
357  }
358  }
359 
360  if (W != 0.0) {
361 
362  for (Int_t i = 1; i <= h1.GetXaxis()->GetNbins(); ++i) {
363 
364  const Double_t w = W * (bin_width ? h1.GetXaxis()->GetBinWidth(i) : 1.0);
365 
366  h1.SetBinContent(i, h1.GetBinContent(i) * factor / w);
367 
368  if (use_error) {
369  h1.SetBinError(i, h1.GetBinError(i) * factor / w);
370  }
371  }
372  }
373  }
void JGIZMO::convertToPDF ( TH2 &  h2,
const std::string &  option = "NXYW",
const double  factor = 1.0 
)
inline

Convert 2D histogram to PDF.

Possible options are:

  • N normalise to histogram contents;
  • X convert x-axis to PDF;
  • Y convert y-axis to PDF;
  • W divide by bin width;
  • E convert also bin errors.
Parameters
h2histogram
optionoption
factorscaling factor

Definition at line 390 of file JGizmoToolkit.hh.

391  {
392  using namespace std;
393 
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);
399 
400  Double_t W = 1.0;
401 
402  if (X && Y) {
403 
404  if (normalise) {
405 
406  W = 0.0;
407 
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);
411  }
412  }
413  }
414 
415  if (W != 0.0) {
416 
417  for (Int_t i = 1; i <= h2.GetXaxis()->GetNbins(); ++i) {
418  for (Int_t j = 1; j <= h2.GetYaxis()->GetNbins(); ++j) {
419 
420  const Double_t w = W * (bin_width ? h2.GetXaxis()->GetBinWidth(i) * h2.GetYaxis()->GetBinWidth(j) : 1.0);
421 
422  h2.SetBinContent(i, j, h2.GetBinContent(i,j) * factor / w);
423 
424  if (use_error) {
425  h2.SetBinError(i, j, h2.GetBinError(i,j) * factor / w);
426  }
427  }
428  }
429  }
430 
431  } else if (X) {
432 
433  for (Int_t j = 1; j <= h2.GetYaxis()->GetNbins(); ++j) {
434 
435  if (normalise) {
436 
437  W = 0.0;
438 
439  for (Int_t i = 1; i <= h2.GetXaxis()->GetNbins(); ++i) {
440  W += h2.GetBinContent(i,j);
441  }
442  }
443 
444  if (W != 0.0) {
445 
446  for (Int_t i = 1; i <= h2.GetXaxis()->GetNbins(); ++i) {
447 
448  const Double_t w = W * (bin_width ? h2.GetXaxis()->GetBinWidth(i) : 1.0);
449 
450  h2.SetBinContent(i, j, h2.GetBinContent(i,j) * factor / w);
451 
452  if (use_error) {
453  h2.SetBinError(i, j, h2.GetBinError(i,j) * factor / w);
454  }
455  }
456  }
457  }
458 
459  } else if (Y) {
460 
461  for (Int_t i = 1; i <= h2.GetXaxis()->GetNbins(); ++i) {
462 
463  if (normalise) {
464 
465  W = 0.0;
466 
467  for (Int_t j = 1; j <= h2.GetYaxis()->GetNbins(); ++j) {
468  W += h2.GetBinContent(i,j);
469  }
470  }
471 
472  if (W != 0.0) {
473 
474  for (Int_t j = 1; j <= h2.GetYaxis()->GetNbins(); ++j) {
475 
476  const Double_t w = W * (bin_width ? h2.GetYaxis()->GetBinWidth(j) : 1.0);
477 
478  h2.SetBinContent(i, j, h2.GetBinContent(i,j) / w);
479 
480  if (use_error) {
481  h2.SetBinError(i, j, h2.GetBinError(i,j) / w);
482  }
483  }
484  }
485  }
486  }
487  }
void JGIZMO::setLimits ( TGraph &  g1)
inline

Set limits of TGraph.

Parameters
g1graph

Definition at line 495 of file JGizmoToolkit.hh.

496  {
497  using namespace std;
498 
499  Double_t ymin = +numeric_limits<Double_t>::max();
500  Double_t ymax = -numeric_limits<Double_t>::max();
501 
502  for (Int_t i = 0; i != g1.GetN(); ++i) {
503 
504  const Double_t y = g1.GetY()[i];
505 
506  if (y > ymax) { ymax = y; }
507  if (y < ymin) { ymin = y; }
508  }
509 
510  g1.SetMinimum(ymin);
511  g1.SetMaximum(ymax);
512  }
Double_t g1(const Double_t x)
Function.
Definition: JQuantiles.cc:25
void JGIZMO::setLimits ( TGraph2D &  g2)
inline

Set limits of TGraph2D.

Parameters
g2graph

Definition at line 520 of file JGizmoToolkit.hh.

521  {
522  using namespace std;
523 
524  Double_t zmin = +numeric_limits<Double_t>::max();
525  Double_t zmax = -numeric_limits<Double_t>::max();
526 
527  for (Int_t i = 0; i != g2.GetN(); ++i) {
528 
529  const Double_t z = g2.GetZ()[i];
530 
531  if (z > zmax) { zmax = z; }
532  if (z < zmin) { zmin = z; }
533  }
534 
535  g2.SetMinimum(zmin);
536  g2.SetMaximum(zmax);
537  }
void JGIZMO::setRange ( double &  xmin,
double &  xmax,
const bool  logx 
)
inline

Set axis range.

Parameters
xminlower limit (I/O)
xmaxupper limit (I/O)
logxlogarithmic

Definition at line 547 of file JGizmoToolkit.hh.

550  {
551  if (logx) {
552  xmin = log(xmin);
553  xmax = log(xmax);
554  }
555 
556  double dx = (xmax - xmin) * 0.1;
557 
558  if (xmin > dx || xmin < 0.0)
559  xmin -= dx;
560  else
561  xmin = 0.0;
562 
563  xmax += dx;
564 
565  if (logx) {
566  xmin = exp(xmin);
567  xmax = exp(xmax);
568  }
569  }
void JGIZMO::setAxisLabels ( TAxis *  axis,
const JModuleAddressMap &  memo 
)
inline

initialize axis with PMT address labels

Parameters
axisaxis
memodefault module address map

Definition at line 578 of file JGizmoToolkit.hh.

579  {
580  using namespace JPP;
581 
582  if (axis->GetNbins() == (int) memo.size()) {
583 
584  for (int i = 0; i < axis->GetNbins(); i++) {
585 
586  const JPMTPhysicalAddress& pmtAddress = memo[i];
587 
588  axis->SetBinLabel(i + 1, TString(pmtAddress.toString()));
589  }
590 
591  } else {
592 
593  THROW(JValueOutOfRange, "Number of bins " << axis->GetNbins() << " != " << memo.size());
594  }
595  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:633

Variable Documentation

const char JGIZMO::LABEL_TERMINATOR = '&'
static

label terminator

Definition at line 21 of file JRootObject.hh.