Jpp  19.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JGizmoToolkit.hh
Go to the documentation of this file.
1 #ifndef __JGIZMOTOOLKIT__
2 #define __JGIZMOTOOLKIT__
3 
4 #include <string>
5 #include <sstream>
6 #include <map>
7 #include <cmath>
8 #include <memory>
9 
10 #pragma GCC diagnostic push
11 #pragma GCC diagnostic ignored "-Wall"
12 #include "TError.h"
13 #include "TFile.h"
14 #include "TClass.h"
15 #include "TObject.h"
16 #include "TKey.h"
17 #include "TH1.h"
18 #include "TH2.h"
19 #include "TH3.h"
20 #include "TGraph.h"
21 #include "TGraphErrors.h"
22 #include "TGraph2D.h"
23 #include "TGraph2DErrors.h"
24 #include "TMultiGraph.h"
25 #include "TLine.h"
26 #include "TEllipse.h"
27 #include "TString.h"
28 #include "TRegexp.h"
29 #include "TFormula.h"
30 #include "TF1.h"
31 #include "TF2.h"
32 #include "TList.h"
33 #include "TIterator.h"
34 #include "TMethod.h"
35 #include "TMethodCall.h"
36 #include "TAxis.h"
37 #include "TMath.h"
38 #pragma GCC diagnostic pop
39 
40 #include "JLang/JException.hh"
41 #include "JGizmo/JRootObjectID.hh"
42 
44 
45 
46 /**
47  * \author mdejong
48  */
49 
50 namespace JGIZMO {}
51 namespace JPP { using namespace JGIZMO; }
52 
53 /**
54  * Auxiliary applications for use of ROOT and more.
55  */
56 namespace JGIZMO {
57 
58  using JLANG::JParseError;
62 
63 
64  /**
65  * Auxiliary data structure for JOpera1D.cc and JOpera2D.cc applications.
66  */
67  struct JOpera {
68  //
69  // Histogram name.
70  //
71  static const char* const SAME_AS_OPERATION() { return "%"; } //!< Set name of output histogram to name of operation
72  static const char* const SAME_AS_INPUT() { return "="; } //!< Set name of output histogram to name of input histogram
73 
74  //
75  // Histogram operations.
76  //
77  static const char* const Add() { return "Add"; } //!< ROOT TH1::Add
78  static const char* const add() { return "add"; } //!< Add contents with lookup bin in second histogram
79  static const char* const Subtract() { return "Subtract"; } //!< ROOT TH1::Subtract
80  static const char* const subtract() { return "subtract"; } //!< Subtract contents with lookup bin in second histogram
81  static const char* const Multiply() { return "Multiply"; } //!< ROOT TH1::Multiply
82  static const char* const multiply() { return "multiply"; } //!< Multiply contents with lookup bin in second histogram
83  static const char* const Divide() { return "Divide"; } //!< ROOT TH1::Divide
84  static const char* const divide() { return "divide"; } //!< Divide contents with lookup bin in second histogram
85  static const char* const efficiency() { return "efficiency"; } //!< Divide contents and multiply errors with inefficiency
86  static const char* const stdev() { return "stdev"; } //!< Set contents to standard deviation
87  static const char* const sqrt() { return "sqrt"; } //!< Set contents to signed difference between squares
88  static const char* const Replace() { return "Replace"; } //!< Set contents to associated function
89  };
90 
91 
92  /**
93  * Time stamp of earliest UTC time.
94  */
95  static const char* const TIMESTAMP = "#splitline{}{#splitline{%d:%m:%y}{ %H:%M}}%F1970-01-01 00:00:00";
96 
97 
98  /**
99  * Get TFile pointer corresponding to give file name.
100  *
101  * The TFile pointer of an already opened file is recovered, else a new file is opened.\n
102  * Note that the closure of the opened files should be done by the caller of this method.
103  *
104  * \param file_name file name
105  * \param option TFile::Open option
106  * \return pointer to TFile
107  */
108  inline TFile* getFile(const std::string& file_name, const std::string& option = "exist")
109  {
110  using namespace std;
111 
112  gErrorIgnoreLevel = kError;
113 
114  static map<string, TFile*> zmap;
115 
116  map<string, TFile*>::iterator i = zmap.find(file_name);
117 
118  if (i == zmap.end() || i->second == NULL || !i->second->IsOpen()) {
119 
120  TFile* file = TFile::Open(file_name.c_str(), option.c_str());
121 
122  zmap[file_name] = file;
123 
124  return file;
125 
126  } else {
127 
128  return i->second;
129  }
130  }
131 
132 
133  /**
134  * Get TDirectory pointer.
135  *
136  * The TFile pointer of an already opened file is recovered, else a new file is opened.
137  *
138  * \param id identifier
139  * \return pointer to TDirectory
140  */
141  inline TDirectory* getDirectory(const JRootObjectID& id)
142  {
143  TFile* in = getFile(id.getFilename().c_str(), "exist");
144 
145  if (in == NULL || !in->IsOpen()) {
146  return NULL;
147  }
148 
149  if (id.getDirectory() != "")
150  return in->GetDirectory(id.getDirectory());
151  else
152  return in;
153  }
154 
155 
156  /**
157  * Get first TObject with given identifier.
158  *
159  * \param id identifier
160  * \return pointer to TObject (or NULL)
161  */
162  inline TObject* getObject(const JRootObjectID& id)
163  {
164  TDirectory* dir = getDirectory(id);
165 
166  if (dir != NULL) {
167 
168  const TRegexp regexp(id.getObjectName());
169 
170  TIter iter(dir->GetListOfKeys());
171 
172  for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
173 
174  const TString tag(key->GetName());
175 
176  // option match
177 
178  if (tag.Index(regexp) != -1) {
179  return key->ReadObj();
180  }
181  }
182  }
183 
184  return NULL;
185  }
186 
187 
188  /**
189  * Get drawing option of TH1.
190  *
191  * \param object pointer to TObject
192  * \return true if TH1 looks like a line; else false
193  */
194  inline bool isTAttLine(const TObject* object)
195  {
196  {
197  const TH1* h1 = dynamic_cast<const TH1*>(object);
198 
199  if (h1 != NULL) {
200 
201  if (h1->GetSumw2N()) {
202  for (Int_t i = 1; i <= h1->GetNbinsX(); ++i) {
203  if (h1->GetBinError(i) != 0.0) {
204  return false;
205  }
206  }
207  }
208  }
209  }
210  {
211  const TGraphErrors* g1 = dynamic_cast<const TGraphErrors*>(object);
212 
213  if (g1 != NULL) {
214 
215  for (Int_t i = 0; i != g1->GetN(); ++i) {
216  if (g1->GetEY()[i] != 0.0) {
217  return false;
218  }
219  }
220 
221  return g1->GetN() > 1;
222  }
223  }
224  {
225  const TGraph* g1 = dynamic_cast<const TGraph*>(object);
226 
227  if (g1 != NULL) {
228  return g1->GetN() > 1;
229  }
230  }
231 
232  return true;
233  }
234 
235 
236  /**
237  * Get result of given textual formula.
238  *
239  * The formula may contain names of member methods of the object pointed to.\n
240  * These methods should return a value that is compatible with <tt>Double_t</tt> and could have arguments.\n
241  * For example:
242  * <pre>
243  * getResult("1.0 / GetEntries", TH1*);
244  * </pre>
245  *
246  * \param text text
247  * \param object pointer to object
248  * \return value
249  */
250  inline Double_t getResult(const TString& text, TObject* object = NULL)
251  {
252  TString buffer(text);
253 
254  if (object != NULL) {
255 
256  TClass* p = TClass::GetClass(object->ClassName());
257 
258  if (p != NULL) {
259 
260  for ( ; ; ) {
261 
262  TMethod* method = NULL;
263 
264  for (std::unique_ptr<TIterator> iter(p->GetListOfAllPublicMethods()->MakeIterator()); TMethod* p = (TMethod*) iter->Next(); ) {
265  if (buffer.Index(p->GetName()) != -1) {
266  if (method == NULL || strlen(p->GetName()) > strlen(method->GetName())) {
267  method = p;
268  }
269  }
270  }
271 
272  if (method == NULL) {
273  break;
274  }
275 
276  for (Ssiz_t index; (index = buffer.Index(method->GetName())) != -1; ) {
277 
278  const TRegexp fp(" *([^)]*)"); // function call
279 
280  Ssiz_t len;
281  Ssiz_t pos = buffer.Index(fp, &len, index);
282 
283  Double_t value;
284 
285  if (pos == -1 || pos != index + (Ssiz_t) strlen(method->GetName())) {
286 
287  TMethodCall(p, method->GetName(), NULL).Execute(object, value);
288 
289  len = strlen(method->GetName());
290 
291  } else {
292 
293  TMethodCall(p, method->GetName(), NULL).Execute(object, TString(buffer(pos + 1, len - 2)), value);
294 
295  len += strlen(method->GetName());
296  }
297 
298  buffer.Replace(index, len, TString::Format("%20.10e", value));
299  }
300  }
301  }
302  }
303 
304  return TFormula("/tmp", buffer.Data()).Eval(0.0);
305  }
306 
307 
308  /**
309  * Get result of given textual formula.
310  *
311  * The formula may contain names of member methods of the object pointed to.\n
312  * These methods should return a value that is compatible with <tt>Double_t</tt> and could have arguments.\n
313  * For example:
314  * <pre>
315  * getResult("1.0 / GetEntries", TH1*);
316  * </pre>
317  *
318  * \param text text
319  * \param object pointer to object
320  * \return value
321  */
322  inline Double_t getResult(const std::string& text, TObject* object = NULL)
323  {
324  return getResult(TString(text.c_str()), object);
325  }
326 
327 
328  /**
329  * Get parameter number from text string.
330  *
331  * The number corresponds to the value <tt>[0-9]*</tt> in the expression <tt>"p[0-9]* = .."</tt>.
332  *
333  * \param text text
334  * \return parameter number
335  */
336  inline int getParameter(const std::string& text)
337  {
338  const char* regexp("p[0-9]* *=");
339 
340  TString buffer(text.c_str());
341 
342  buffer = buffer(TRegexp(regexp));
343  buffer = buffer(1, buffer.Length() - 2);
344 
345  if (!buffer.IsDigit()) {
346  THROW(JParseError, "Text is not a number " << text << ' ' << regexp);
347  }
348 
349  return buffer.Atoi();
350  }
351 
352 
353  /**
354  * Get parameter value from text string.
355  *
356  * The formula may contain names of member methods of the object pointed to.\n
357  * These methods should return a value that is compatible with <tt>Double_t</tt> and could have arguments.\n
358  * For example:
359  * <pre>
360  * getValue("p[..] = 2 * GetMaximum", TH1*);
361  * </pre>
362  *
363  * \param text text
364  * \param object pointer to object
365  * \return value
366  */
367  inline Double_t getValue(const std::string& text, TObject* object = NULL)
368  {
369  const char* regexp("=.*");
370 
371  TString buffer(text.c_str());
372 
373  buffer = buffer(TRegexp(regexp));
374  buffer = buffer(1, buffer.Length() - 1);
375 
376  return getResult(std::string(buffer), object);
377  }
378 
379 
380  /**
381  * Get parameter value from text string.
382  *
383  * The formula may contain names of member methods of the object pointed to.\n
384  * These methods should return a value that is compatible with <tt>Double_t</tt> and could have arguments.\n
385  * For example:
386  * <pre>
387  * getValue("p[..] = 1.0 2.0 3.0", 1);
388  * </pre>
389  * will return <tt>2.0</tt>.
390  *
391  * \param text text
392  * \param index index
393  * \return value
394  */
395  inline Double_t getValue(const std::string& text, const int index)
396  {
397  using namespace std;
398 
399  const char* regexp("=.*");
400 
401  TString buffer(text.c_str());
402 
403  buffer = buffer(TRegexp(regexp));
404  buffer = buffer(1, buffer.Length() - 1);
405 
406 
407  istringstream is((std::string(buffer)));
408 
409  Double_t value;
410 
411  for (int i = index; is >> value && i > 0; --i) {}
412 
413  if (is)
414  return value;
415  else
416  THROW(JParseError, "Text does not contain a number at given position " << buffer << ' ' << index);
417  }
418 
419 
420  /**
421  * Make histogram axis logarithmic (e.g.\ after using <tt>log10()</tt>).
422  *
423  * \param axis axis
424  */
425  inline void setLogarithmic(TAxis* axis)
426  {
427  if (axis != NULL) {
428 
429  const Int_t N = axis->GetNbins();
430  Double_t buffer[N+1];
431 
432  buffer[0] = TMath::Power(10.0, axis->GetBinLowEdge(1));
433 
434  for (Int_t i = 1; i <= N; ++i) {
435  buffer[i] = TMath::Power(10.0, axis->GetBinLowEdge(i) + axis->GetBinWidth(i));
436  }
437 
438  axis->Set(N, buffer);
439  /*
440  if (axis->TestBit(TAxis::kAxisRange)) {
441 
442  const Int_t first = axis->GetFirst();
443  const Int_t last = axis->GetLast();
444 
445  if (first != last) {
446 
447  const Double_t xmin = axis->GetBinLowEdge(first);
448  const Double_t xmax = axis->GetBinLowEdge(last) + axis->GetBinWidth(last);
449 
450  axis->SetRangeUser(TMath::Power(10.0, xmin), TMath::Power(10.0, xmax));
451  }
452  }
453  */
454  }
455  }
456 
457 
458  /**
459  * Make given parameter in formula logarithmic (e.g.\ after using <tt>log10()</tt>).
460  *
461  * \param formula formula
462  * \param parameter parameter
463  * \return formula
464  */
465  inline TString getLogarithmic(const TString& formula, const char parameter)
466  {
467  const TRegexp regexp[] = {
468  TString("^") + TString(parameter) + TString("[^a-zA-Z_]"), // parameter at start of line
469  TString("[^a-zA-Z_]") + TString(parameter) + TString("[^a-zA-Z_]"), // parameter in middle of line
470  TString("[^a-zA-Z_]") + TString(parameter) + TString("$") // parameter at end of line
471  };
472 
473  const TString replacement = TString("log10(") + TString(parameter) + TString(")");
474 
475  TString buffer(formula);
476 
477  if (buffer.Length() == 1 && buffer[0] == parameter) {
478 
479  buffer = replacement;
480 
481  } else {
482 
483  for (Ssiz_t pos = 0, i; pos < buffer.Length(); pos += replacement.Length()) {
484  if ((i = buffer.Index(regexp[0], pos)) != -1) { buffer.Replace((pos = i + 0), 1, replacement); }
485  else if ((i = buffer.Index(regexp[1], pos)) != -1) { buffer.Replace((pos = i + 1), 1, replacement); }
486  else if ((i = buffer.Index(regexp[2], pos)) != -1) { buffer.Replace((pos = i + 1), 1, replacement); }
487  else { break; }
488  }
489  }
490 
491  return buffer;
492  }
493 
494 
495  /**
496  * Copy function parameters.
497  *
498  * \param from function
499  * \param to function
500  */
501  inline void copy(const TF1& from, TF1& to)
502  {
503  static_cast<TAttLine&> (to) = static_cast<const TAttLine&> (from);
504  static_cast<TAttFill&> (to) = static_cast<const TAttFill&> (from);
505  static_cast<TAttMarker&>(to) = static_cast<const TAttMarker&>(from);
506 
507  to.SetParameters(from.GetParameters());
508 
509  to.SetNpx(from.GetNpx());
510  }
511 
512 
513  /**
514  * Copy function parameters.
515  *
516  * \param from function
517  * \param to function
518  */
519  inline void copy(const TF2& from, TF2& to)
520  {
521  copy(static_cast<const TF1&>(from), static_cast<TF1&>(to));
522 
523  to.SetNpy(from.GetNpy());
524  }
525 
526 
527  /**
528  * Make x-axis of objects in list logarithmic (e.g.\ after using <tt>log10()</tt>).
529  *
530  * \param list list
531  */
532  template<class T>
533  inline void setLogarithmicX(TList* list);
534 
535 
536  /**
537  * Make y-axis of objects in list logarithmic (e.g.\ after using <tt>log10()</tt>).
538  *
539  * \param list list
540  */
541  template<class T>
542  inline void setLogarithmicY(TList* list);
543 
544 
545  /**
546  * Make x-axis of given function logarithmic (e.g.\ after using <tt>log10()</tt>).
547  *
548  * \param f1 function
549  */
550  inline void setLogarithmicX(TF1* f1)
551  {
552  if (f1 != NULL) {
553 
554  TF1 fn(f1->GetName(), getLogarithmic(f1->GetExpFormula(), 'x'));
555 
556  copy(*f1, fn);
557 
558  fn.SetRange(f1->GetXmin(),
559  f1->GetXmax());
560 
561  *f1 = fn;
562 
563  f1->SetRange(TMath::Power(10.0,f1->GetXmin()),
564  TMath::Power(10.0,f1->GetXmax()));
565  }
566  }
567 
568 
569  /**
570  * Make y-axis of given function logarithmic (e.g.\ after using <tt>log10()</tt>).
571  *
572  * \param f1 function
573  */
574  inline void setLogarithmicY(TF1* f1)
575  {
576  if (f1 != NULL) {
577 
578  TString buffer = f1->GetExpFormula();
579 
580  buffer = "pow(10.0, " + buffer + ")";
581 
582  TF1 fn(f1->GetName(), buffer);
583 
584  copy(*f1, fn);
585 
586  *f1 = fn;
587  }
588  }
589 
590 
591  /**
592  * Make x-axis of given function logarithmic (e.g.\ after using <tt>log10()</tt>).
593  *
594  * \param f2 function
595  */
596  inline void setLogarithmicX(TF2* f2)
597  {
598  if (f2 != NULL) {
599 
600  TF2 fn(f2->GetName(), getLogarithmic(f2->GetExpFormula(), 'x'));
601 
602  copy(*f2, fn);
603 
604  fn.SetRange(f2->GetXmin(),
605  f2->GetYmin(),
606  f2->GetXmax(),
607  f2->GetYmax());
608 
609  *f2 = fn;
610 
611  f2->SetRange(TMath::Power(10.0,f2->GetXmin()),
612  f2->GetYmin(),
613  TMath::Power(10.0,f2->GetXmax()),
614  f2->GetYmax());
615  }
616  }
617 
618 
619  /**
620  * Make y-axis of given function logarithmic (e.g.\ after using <tt>log10()</tt>).
621  *
622  * \param f2 function
623  */
624  inline void setLogarithmicY(TF2* f2)
625  {
626  if (f2 != NULL) {
627 
628  TF2 fn(f2->GetName(), getLogarithmic(f2->GetExpFormula(), 'y'));
629 
630  copy(*f2, fn);
631 
632  fn.SetRange(f2->GetXmin(),
633  f2->GetYmin(),
634  f2->GetXmax(),
635  f2->GetYmax());
636 
637  *f2 = fn;
638 
639  f2->SetRange(f2->GetXmin(),
640  TMath::Power(10.0,f2->GetYmin()),
641  f2->GetXmax(),
642  TMath::Power(10.0,f2->GetYmax()));
643  }
644  }
645 
646 
647  /**
648  * Make x-axis and associated functions of given histogram logarithmic (e.g.\ after using <tt>log10()</tt>).
649  *
650  * \param h1 histogram
651  */
652  inline void setLogarithmicX(TH1* h1)
653  {
654  if (h1 != NULL) {
655 
656  setLogarithmicX<TF1>(h1->GetListOfFunctions());
657 
658  setLogarithmic(h1->GetXaxis());
659  }
660  }
661 
662 
663  /**
664  * Make x-axis and associated functions of given histogram logarithmic (e.g.\ after using <tt>log10()</tt>).
665  *
666  * \param h2 histogram
667  */
668  inline void setLogarithmicX(TH2* h2)
669  {
670  using namespace std;
671 
672  if (h2 != NULL) {
673 
674  setLogarithmicX<TF2>(h2->GetListOfFunctions());
675 
676  setLogarithmic(h2->GetXaxis());
677  }
678  }
679 
680 
681  /**
682  * Make y-axis and associated functions of given histogram logarithmic (e.g.\ after using <tt>log10()</tt>).
683  *
684  * \param h2 histogram
685  */
686  inline void setLogarithmicY(TH2* h2)
687  {
688  if (h2 != NULL) {
689 
690  setLogarithmicY<TF2>(h2->GetListOfFunctions());
691 
692  setLogarithmic(h2->GetYaxis());
693  }
694  }
695 
696 
697  /**
698  * Make x-axis and associated functions of given graph logarithmic (e.g.\ after using <tt>log10()</tt>).
699  *
700  * \param g1 graph
701  */
702  inline void setLogarithmicX(TGraph* g1)
703  {
704  if (g1 != NULL) {
705 
706  setLogarithmicX<TF1>(g1->GetListOfFunctions());
707 
708  for (Int_t i = 0; i != g1->GetN(); ++i) {
709  g1->GetX()[i] = pow(10.0, g1->GetX()[i]);
710  }
711  }
712  }
713 
714 
715  /**
716  * Make y-axis and associated functions of given graph logarithmic (e.g.\ after using <tt>log10()</tt>).
717  *
718  * \param g1 graph
719  */
720  inline void setLogarithmicY(TGraph* g1)
721  {
722  if (g1 != NULL) {
723 
724  setLogarithmicY<TF1>(g1->GetListOfFunctions());
725 
726  for (Int_t i = 0; i != g1->GetN(); ++i) {
727  g1->GetY()[i] = pow(10.0, g1->GetY()[i]);
728  }
729  }
730  }
731 
732 
733  /**
734  * Make x-axis and associated functions of given graph logarithmic (e.g.\ after using <tt>log10()</tt>).
735  *
736  * \param g1 graph
737  */
738  inline void setLogarithmicX(TGraphErrors* g1)
739  {
740  if (g1 != NULL) {
741 
742  setLogarithmicX<TF1>(g1->GetListOfFunctions());
743 
744  for (Int_t i = 0; i != g1->GetN(); ++i) {
745  g1->GetEX()[i] = pow(10.0, g1->GetX()[i] + g1->GetEX()[i]) - pow(10.0, g1->GetX()[i]);
746  g1->GetX() [i] = pow(10.0, g1->GetX()[i]);
747  }
748  }
749  }
750 
751 
752  /**
753  * Make y-axis and associated functions of given graph logarithmic (e.g.\ after using <tt>log10()</tt>).
754  *
755  * \param g1 graph
756  */
757  inline void setLogarithmicY(TGraphErrors* g1)
758  {
759  if (g1 != NULL) {
760 
761  setLogarithmicY<TF1>(g1->GetListOfFunctions());
762 
763  for (Int_t i = 0; i != g1->GetN(); ++i) {
764  g1->GetEY()[i] = pow(10.0, g1->GetY()[i] + g1->GetEY()[i]) - pow(10.0, g1->GetY()[i]);
765  g1->GetY() [i] = pow(10.0, g1->GetY()[i]);
766  }
767  }
768  }
769 
770 
771  /**
772  * Make x-axis and associated functions of given graph logarithmic (e.g.\ after using <tt>log10()</tt>).
773  *
774  * \param g2 graph
775  */
776  inline void setLogarithmicX(TGraph2D* g2)
777  {
778  if (g2 != NULL) {
779 
780  setLogarithmicX<TF2>(g2->GetListOfFunctions());
781 
782  for (Int_t i = 0; i != g2->GetN(); ++i) {
783  g2->GetX()[i] = pow(10.0, g2->GetX()[i]);
784  }
785  }
786  }
787 
788 
789  /**
790  * Make y-axis and associated functions of given graph logarithmic (e.g.\ after using <tt>log10()</tt>).
791  *
792  * \param g2 graph
793  */
794  inline void setLogarithmicY(TGraph2D* g2)
795  {
796  if (g2 != NULL) {
797 
798  setLogarithmicY<TF2>(g2->GetListOfFunctions());
799 
800  for (Int_t i = 0; i != g2->GetN(); ++i) {
801  g2->GetY()[i] = pow(10.0, g2->GetY()[i]);
802  }
803  }
804  }
805 
806 
807  /**
808  * Make x-axis and associated functions of given graph logarithmic (e.g.\ after using <tt>log10()</tt>).
809  *
810  * \param g2 graph
811  */
812  inline void setLogarithmicX(TGraph2DErrors* g2)
813  {
814  if (g2 != NULL) {
815 
816  setLogarithmicX<TF2>(g2->GetListOfFunctions());
817 
818  for (Int_t i = 0; i != g2->GetN(); ++i) {
819  g2->GetEX()[i] = pow(10.0, g2->GetX()[i] + g2->GetEX()[i]) - pow(10.0, g2->GetX()[i]);
820  g2->GetX() [i] = pow(10.0, g2->GetX()[i]);
821  }
822  }
823  }
824 
825 
826  /**
827  * Make y-axis and associated functions of given graph logarithmic (e.g.\ after using <tt>log10()</tt>).
828  *
829  * \param g2 graph
830  */
831  inline void setLogarithmicY(TGraph2DErrors* g2)
832  {
833  if (g2 != NULL) {
834 
835  setLogarithmicY<TF2>(g2->GetListOfFunctions());
836 
837  for (Int_t i = 0; i != g2->GetN(); ++i) {
838  g2->GetEY()[i] = pow(10.0, g2->GetY()[i] + g2->GetEY()[i]) - pow(10.0, g2->GetY()[i]);
839  g2->GetY() [i] = pow(10.0, g2->GetY()[i]);
840  }
841  }
842  }
843 
844 
845  /**
846  * Make x-axis of given multi-graph logarithmic (e.g.\ after using <tt>log10()</tt>).
847  *
848  * \param gn multi graph
849  */
850  inline void setLogarithmicX(TMultiGraph* gn)
851  {
852  if (gn != NULL) {
853  setLogarithmicX<TGraph>(gn->GetListOfGraphs());
854  }
855  }
856 
857 
858  /**
859  * Make y-axis of given multi-graph logarithmic (e.g.\ after using <tt>log10()</tt>).
860  *
861  * \param gn multi graph
862  */
863  inline void setLogarithmicY(TMultiGraph* gn)
864  {
865  if (gn != NULL) {
866  setLogarithmicY<TGraph>(gn->GetListOfGraphs());
867  }
868  }
869 
870 
871  /**
872  * Make x-axis of given line logarithmic (e.g.\ after using <tt>log10()</tt>).
873  *
874  * \param line line
875  */
876  inline void setLogarithmicX(TLine* line)
877  {
878  if (line != NULL) {
879  line->SetX1(pow(10.0, line->GetX1()));
880  line->SetX2(pow(10.0, line->GetX2()));
881  }
882  }
883 
884 
885  /**
886  * Make y-axis of given line logarithmic (e.g.\ after using <tt>log10()</tt>).
887  *
888  * \param line line
889  */
890  inline void setLogarithmicY(TLine* line)
891  {
892  if (line != NULL) {
893  line->SetY1(pow(10.0, line->GetY1()));
894  line->SetY2(pow(10.0, line->GetY2()));
895  }
896  }
897 
898 
899  /**
900  * Make x-axis of given ellipse logarithmic (e.g.\ after using <tt>log10()</tt>).
901  *
902  * \param ellipse ellipse
903  */
904  inline void setLogarithmicX(TEllipse* ellipse)
905  {
906  THROW(JFunctionalException, "Operation setLogarithmicX on TEllipse not allowed.");
907  }
908 
909 
910  /**
911  * Make y-axis of given ellipse logarithmic (e.g.\ after using <tt>log10()</tt>).
912  *
913  * \param ellipse ellipse
914  */
915  inline void setLogarithmicY(TEllipse* ellipse)
916  {
917  THROW(JFunctionalException, "Operation setLogarithmicY on TEllipse not allowed.");
918  }
919 
920 
921  /**
922  * Make x-axis of objects in list logarithmic (e.g.\ after using <tt>log10()</tt>).
923  *
924  * \param list list
925  */
926  template<class T>
927  inline void setLogarithmicX(TList* list)
928  {
929  for (TIter i(list); T* p = dynamic_cast<T*>(i.Next()); ) {
930  setLogarithmicX(p);
931  }
932  }
933 
934 
935  /**
936  * Make y-axis of objects in list logarithmic (e.g.\ after using <tt>log10()</tt>).
937  *
938  * \param list list
939  */
940  template<class T>
941  inline void setLogarithmicY(TList* list)
942  {
943  for (TIter i(list); T* p = dynamic_cast<T*>(i.Next()); ) {
944  setLogarithmicY(p);
945  }
946  }
947 
948 
949  /**
950  * Convert 1D histogram to PDF.
951  *
952  * Possible options are:
953  * - N normalise to histogram contents;
954  * - W divide by bin width;
955  * - E convert also bin errors.
956  *
957  * \param h1 histogram
958  * \param option option
959  * \param factor scaling factor
960  */
961  inline void convertToPDF(TH1& h1, const std::string& option = "NW", const double factor = 1.0)
962  {
963  using namespace std;
964 
965  const bool normalise = (option.find('N') != string::npos || option.find('n') != string::npos);
966  const bool bin_width = (option.find('W') != string::npos || option.find('w') != string::npos);
967  const bool use_error = (option.find('E') != string::npos || option.find('e') != string::npos);
968 
969  Double_t W = 1.0;
970 
971  if (normalise) {
972 
973  W = 0.0;
974 
975  for (Int_t i = 1; i <= h1.GetXaxis()->GetNbins(); ++i) {
976  W += h1.GetBinContent(i);
977  }
978  }
979 
980  if (W != 0.0) {
981 
982  for (Int_t i = 1; i <= h1.GetXaxis()->GetNbins(); ++i) {
983 
984  const Double_t w = W * (bin_width ? h1.GetXaxis()->GetBinWidth(i) : 1.0);
985 
986  h1.SetBinContent(i, h1.GetBinContent(i) * factor / w);
987 
988  if (use_error) {
989  h1.SetBinError(i, h1.GetBinError(i) * factor / w);
990  }
991  }
992  }
993  }
994 
995 
996  /**
997  * Convert 2D histogram to PDF.
998  *
999  * Possible options are:
1000  * - N normalise to histogram contents;
1001  * - X convert x-axis to PDF;
1002  * - Y convert y-axis to PDF;
1003  * - W divide by bin width;
1004  * - E convert also bin errors.
1005  *
1006  * \param h2 histogram
1007  * \param option option
1008  * \param factor scaling factor
1009  */
1010  inline void convertToPDF(TH2& h2, const std::string& option = "NXYW", const double factor = 1.0)
1011  {
1012  using namespace std;
1013 
1014  const bool normalise = (option.find('N') != string::npos || option.find('n') != string::npos);
1015  const bool X = (option.find('X') != string::npos || option.find('x') != string::npos);
1016  const bool Y = (option.find('Y') != string::npos || option.find('y') != string::npos);
1017  const bool bin_width = (option.find('W') != string::npos || option.find('w') != string::npos);
1018  const bool use_error = (option.find('E') != string::npos || option.find('e') != string::npos);
1019 
1020  Double_t W = 1.0;
1021 
1022  if (X && Y) {
1023 
1024  if (normalise) {
1025 
1026  W = 0.0;
1027 
1028  for (Int_t ix = 1; ix <= h2.GetXaxis()->GetNbins(); ++ix) {
1029  for (Int_t iy = 1; iy <= h2.GetYaxis()->GetNbins(); ++iy) {
1030  W += h2.GetBinContent(ix,iy);
1031  }
1032  }
1033  }
1034 
1035  if (W != 0.0) {
1036 
1037  for (Int_t ix = 1; ix <= h2.GetXaxis()->GetNbins(); ++ix) {
1038  for (Int_t iy = 1; iy <= h2.GetYaxis()->GetNbins(); ++iy) {
1039 
1040  const Double_t w = W * (bin_width ? h2.GetXaxis()->GetBinWidth(ix) * h2.GetYaxis()->GetBinWidth(iy) : 1.0);
1041 
1042  h2.SetBinContent(ix, iy, h2.GetBinContent(ix,iy) * factor / w);
1043 
1044  if (use_error) {
1045  h2.SetBinError(ix, iy, h2.GetBinError(ix,iy) * factor / w);
1046  }
1047  }
1048  }
1049  }
1050 
1051  } else if (X) {
1052 
1053  for (Int_t iy = 1; iy <= h2.GetYaxis()->GetNbins(); ++iy) {
1054 
1055  if (normalise) {
1056 
1057  W = 0.0;
1058 
1059  for (Int_t ix = 1; ix <= h2.GetXaxis()->GetNbins(); ++ix) {
1060  W += h2.GetBinContent(ix,iy);
1061  }
1062  }
1063 
1064  if (W != 0.0) {
1065 
1066  for (Int_t ix = 1; ix <= h2.GetXaxis()->GetNbins(); ++ix) {
1067 
1068  const Double_t w = W * (bin_width ? h2.GetXaxis()->GetBinWidth(ix) : 1.0);
1069 
1070  h2.SetBinContent(ix, iy, h2.GetBinContent(ix,iy) * factor / w);
1071 
1072  if (use_error) {
1073  h2.SetBinError(ix, iy, h2.GetBinError(ix,iy) * factor / w);
1074  }
1075  }
1076  }
1077  }
1078 
1079  } else if (Y) {
1080 
1081  for (Int_t ix = 1; ix <= h2.GetXaxis()->GetNbins(); ++ix) {
1082 
1083  if (normalise) {
1084 
1085  W = 0.0;
1086 
1087  for (Int_t iy = 1; iy <= h2.GetYaxis()->GetNbins(); ++iy) {
1088  W += h2.GetBinContent(ix,iy);
1089  }
1090  }
1091 
1092  if (W != 0.0) {
1093 
1094  for (Int_t iy = 1; iy <= h2.GetYaxis()->GetNbins(); ++iy) {
1095 
1096  const Double_t w = W * (bin_width ? h2.GetYaxis()->GetBinWidth(iy) : 1.0);
1097 
1098  h2.SetBinContent(ix, iy, h2.GetBinContent(ix,iy) / w);
1099 
1100  if (use_error) {
1101  h2.SetBinError(ix, iy, h2.GetBinError(ix,iy) / w);
1102  }
1103  }
1104  }
1105  }
1106  }
1107  }
1108 
1109 
1110  /**
1111  * Convert 3D histogram to PDF.
1112  *
1113  * Possible options are:
1114  * - N normalise to histogram contents;
1115  * - X convert x-axis to PDF;
1116  * - Y convert y-axis to PDF;
1117  * - Z convert z-axis to PDF;
1118  * - W divide by bin width;
1119  * - E convert also bin errors.
1120  *
1121  * \param h3 histogram
1122  * \param option option
1123  * \param factor scaling factor
1124  */
1125  inline void convertToPDF(TH3& h3, const std::string& option = "NXYW", const double factor = 1.0)
1126  {
1127  using namespace std;
1128 
1129  const bool normalise = (option.find('N') != string::npos || option.find('n') != string::npos);
1130  const bool X = (option.find('X') != string::npos || option.find('x') != string::npos);
1131  const bool Y = (option.find('Y') != string::npos || option.find('y') != string::npos);
1132  const bool Z = (option.find('Z') != string::npos || option.find('z') != string::npos);
1133  const bool bin_width = (option.find('W') != string::npos || option.find('w') != string::npos);
1134  const bool use_error = (option.find('E') != string::npos || option.find('e') != string::npos);
1135 
1136  Double_t W = 1.0;
1137 
1138  if (X && Y && Z) {
1139 
1140  if (normalise) {
1141 
1142  W = 0.0;
1143 
1144  for (Int_t ix = 1; ix <= h3.GetXaxis()->GetNbins(); ++ix) {
1145  for (Int_t iy = 1; iy <= h3.GetYaxis()->GetNbins(); ++iy) {
1146  for (Int_t iz = 1; iz <= h3.GetZaxis()->GetNbins(); ++iz) {
1147  W += h3.GetBinContent(ix,iy,iz);
1148  }
1149  }
1150  }
1151  }
1152 
1153  if (W != 0.0) {
1154 
1155  for (Int_t ix = 1; ix <= h3.GetXaxis()->GetNbins(); ++ix) {
1156  for (Int_t iy = 1; iy <= h3.GetYaxis()->GetNbins(); ++iy) {
1157  for (Int_t iz = 1; iz <= h3.GetZaxis()->GetNbins(); ++iz) {
1158 
1159  const Double_t w = W * (bin_width ? h3.GetXaxis()->GetBinWidth(ix) * h3.GetYaxis()->GetBinWidth(iy) * h3.GetZaxis()->GetBinWidth(iz) : 1.0);
1160 
1161  h3.SetBinContent(ix, iy, iz, h3.GetBinContent(ix,iy,iz) * factor / w);
1162 
1163  if (use_error) {
1164  h3.SetBinError(ix, iy, iz, h3.GetBinError(ix,iy,iz) * factor / w);
1165  }
1166  }
1167  }
1168  }
1169  }
1170 
1171  } else if (X && Z) {
1172 
1173  for (Int_t iy = 1; iy <= h3.GetYaxis()->GetNbins(); ++iy) {
1174 
1175  if (normalise) {
1176 
1177  W = 0.0;
1178 
1179  for (Int_t ix = 1; ix <= h3.GetXaxis()->GetNbins(); ++ix) {
1180  for (Int_t iz = 1; iz <= h3.GetZaxis()->GetNbins(); ++iz) {
1181  W += h3.GetBinContent(ix,iy,iz);
1182  }
1183  }
1184  }
1185 
1186  if (W != 0.0) {
1187 
1188  for (Int_t ix = 1; ix <= h3.GetXaxis()->GetNbins(); ++ix) {
1189  for (Int_t iz = 1; iz <= h3.GetZaxis()->GetNbins(); ++iz) {
1190 
1191  const Double_t w = W * (bin_width ? h3.GetXaxis()->GetBinWidth(ix) * h3.GetZaxis()->GetBinWidth(iz) : 1.0);
1192 
1193  h3.SetBinContent(ix, iy, iz, h3.GetBinContent(ix,iy,iz) * factor / w);
1194 
1195  if (use_error) {
1196  h3.SetBinError(ix, iy, iz, h3.GetBinError(ix,iy,iz) * factor / w);
1197  }
1198  }
1199  }
1200  }
1201  }
1202 
1203  } else if (Y && Z) {
1204 
1205  for (Int_t ix = 1; ix <= h3.GetXaxis()->GetNbins(); ++ix) {
1206 
1207  if (normalise) {
1208 
1209  W = 0.0;
1210 
1211  for (Int_t iy = 1; iy <= h3.GetYaxis()->GetNbins(); ++iy) {
1212  for (Int_t iz = 1; iz <= h3.GetZaxis()->GetNbins(); ++iz) {
1213  W += h3.GetBinContent(ix,iy,iz);
1214  }
1215  }
1216  }
1217 
1218  if (W != 0.0) {
1219 
1220  for (Int_t iy = 1; iy <= h3.GetYaxis()->GetNbins(); ++iy) {
1221  for (Int_t iz = 1; iz <= h3.GetZaxis()->GetNbins(); ++iz) {
1222 
1223  const Double_t w = W * (bin_width ? h3.GetYaxis()->GetBinWidth(iy) * h3.GetZaxis()->GetBinWidth(iz) : 1.0);
1224 
1225  h3.SetBinContent(ix, iy, iz, h3.GetBinContent(ix,iy,iz) * factor / w);
1226 
1227  if (use_error) {
1228  h3.SetBinError(ix, iy, iz, h3.GetBinError(ix,iy,iz) * factor / w);
1229  }
1230  }
1231  }
1232  }
1233  }
1234 
1235  } else if (X && Y) {
1236 
1237  for (Int_t iz = 1; iz <= h3.GetZaxis()->GetNbins(); ++iz) {
1238 
1239  if (normalise) {
1240 
1241  W = 0.0;
1242 
1243  for (Int_t ix = 1; ix <= h3.GetXaxis()->GetNbins(); ++ix) {
1244  for (Int_t iy = 1; iy <= h3.GetYaxis()->GetNbins(); ++iy) {
1245  W += h3.GetBinContent(ix,iy,iz);
1246  }
1247  }
1248  }
1249 
1250  if (W != 0.0) {
1251 
1252  for (Int_t ix = 1; ix <= h3.GetXaxis()->GetNbins(); ++ix) {
1253  for (Int_t iy = 1; iy <= h3.GetYaxis()->GetNbins(); ++iy) {
1254 
1255  const Double_t w = W * (bin_width ? h3.GetXaxis()->GetBinWidth(ix) * h3.GetYaxis()->GetBinWidth(iy) : 1.0);
1256 
1257  h3.SetBinContent(ix, iy, iz, h3.GetBinContent(ix,iy,iz) * factor / w);
1258 
1259  if (use_error) {
1260  h3.SetBinError(ix, iy, iz, h3.GetBinError(ix,iy,iz) * factor / w);
1261  }
1262  }
1263  }
1264  }
1265  }
1266 
1267  } else if (X) {
1268 
1269  for (Int_t iy = 1; iy <= h3.GetYaxis()->GetNbins(); ++iy) {
1270  for (Int_t iz = 1; iz <= h3.GetZaxis()->GetNbins(); ++iz) {
1271 
1272  if (normalise) {
1273 
1274  W = 0.0;
1275 
1276  for (Int_t ix = 1; ix <= h3.GetXaxis()->GetNbins(); ++ix) {
1277  W += h3.GetBinContent(ix,iy,iz);
1278  }
1279  }
1280 
1281  if (W != 0.0) {
1282 
1283  for (Int_t ix = 1; ix <= h3.GetXaxis()->GetNbins(); ++ix) {
1284 
1285  const Double_t w = W * (bin_width ? h3.GetXaxis()->GetBinWidth(ix) : 1.0);
1286 
1287  h3.SetBinContent(ix, iy, iz, h3.GetBinContent(ix,iy,iz) * factor / w);
1288 
1289  if (use_error) {
1290  h3.SetBinError(ix, iy, iz, h3.GetBinError(ix,iy,iz) * factor / w);
1291  }
1292  }
1293  }
1294  }
1295  }
1296 
1297  } else if (Y) {
1298 
1299  for (Int_t ix = 1; ix <= h3.GetXaxis()->GetNbins(); ++ix) {
1300  for (Int_t iz = 1; iz <= h3.GetZaxis()->GetNbins(); ++iz) {
1301 
1302  if (normalise) {
1303 
1304  W = 0.0;
1305 
1306  for (Int_t iy = 1; iy <= h3.GetYaxis()->GetNbins(); ++iy) {
1307  W += h3.GetBinContent(ix,iy,iz);
1308  }
1309  }
1310 
1311  if (W != 0.0) {
1312 
1313  for (Int_t iy = 1; iy <= h3.GetYaxis()->GetNbins(); ++iy) {
1314 
1315  const Double_t w = W * (bin_width ? h3.GetYaxis()->GetBinWidth(iy) : 1.0);
1316 
1317  h3.SetBinContent(ix, iy, iz, h3.GetBinContent(ix,iy,iz) / w);
1318 
1319  if (use_error) {
1320  h3.SetBinError(ix, iy, iz, h3.GetBinError(ix,iy,iz) / w);
1321  }
1322  }
1323  }
1324  }
1325  }
1326 
1327  } else if (Z) {
1328 
1329  for (Int_t ix = 1; ix <= h3.GetXaxis()->GetNbins(); ++ix) {
1330  for (Int_t iy = 1; iy <= h3.GetYaxis()->GetNbins(); ++iy) {
1331 
1332  if (normalise) {
1333 
1334  W = 0.0;
1335 
1336  for (Int_t iz = 1; iz <= h3.GetZaxis()->GetNbins(); ++iz) {
1337  W += h3.GetBinContent(ix,iy,iz);
1338  }
1339  }
1340 
1341  if (W != 0.0) {
1342 
1343  for (Int_t iz = 1; iz <= h3.GetZaxis()->GetNbins(); ++iz) {
1344 
1345  const Double_t w = W * (bin_width ? h3.GetZaxis()->GetBinWidth(iz) : 1.0);
1346 
1347  h3.SetBinContent(ix, iy, iz, h3.GetBinContent(ix,iy,iz) / w);
1348 
1349  if (use_error) {
1350  h3.SetBinError(ix, iy, iz, h3.GetBinError(ix,iy,iz) / w);
1351  }
1352  }
1353  }
1354  }
1355  }
1356  }
1357  }
1358 
1359 
1360  /**
1361  * Set limits of TGraph.
1362  *
1363  * \param g1 graph
1364  */
1365  inline void setLimits(TGraph& g1)
1366  {
1367  using namespace std;
1368 
1369  Double_t ymin = numeric_limits<Double_t>::max();
1370  Double_t ymax = numeric_limits<Double_t>::lowest();
1371 
1372  for (Int_t i = 0; i != g1.GetN(); ++i) {
1373 
1374  const Double_t y = g1.GetY()[i];
1375 
1376  if (y > ymax) { ymax = y; }
1377  if (y < ymin) { ymin = y; }
1378  }
1379 
1380  g1.SetMinimum(ymin);
1381  g1.SetMaximum(ymax);
1382  }
1383 
1384 
1385  /**
1386  * Set limits of TGraph2D.
1387  *
1388  * \param g2 graph
1389  */
1390  inline void setLimits(TGraph2D& g2)
1391  {
1392  using namespace std;
1393 
1394  Double_t zmin = numeric_limits<Double_t>::max();
1395  Double_t zmax = numeric_limits<Double_t>::lowest();
1396 
1397  for (Int_t i = 0; i != g2.GetN(); ++i) {
1398 
1399  const Double_t z = g2.GetZ()[i];
1400 
1401  if (z > zmax) { zmax = z; }
1402  if (z < zmin) { zmin = z; }
1403  }
1404 
1405  g2.SetMinimum(zmin);
1406  g2.SetMaximum(zmax);
1407  }
1408 
1409 
1410  /**
1411  * Set axis range.
1412  *
1413  * \param xmin lower limit (I/O)
1414  * \param xmax upper limit (I/O)
1415  * \param logx logarithmic
1416  */
1417  inline void setRange(double& xmin,
1418  double& xmax,
1419  const bool logx)
1420  {
1421  if (logx) {
1422  xmin = log(xmin);
1423  xmax = log(xmax);
1424  }
1425 
1426  double dx = (xmax - xmin) * 0.1;
1427 
1428  if (logx || xmin >= dx || xmin < 0.0)
1429  xmin -= dx;
1430  else
1431  xmin = 0.0;
1432 
1433  xmax += dx;
1434 
1435  if (logx) {
1436  xmin = exp(xmin);
1437  xmax = exp(xmax);
1438  }
1439  }
1440 
1441 
1442  /**
1443  * Set axis with PMT address labels.
1444  *
1445  * This methods sets the labels of the given axis to the sorted values of the PMT ring and position.\n
1446  * It should normally be called before filling of the corresponding histogram.\n
1447  * The filling should then be made with the textual representation of the PMT ring and position (i.e.\ JDETECTOR::JPMTPhysicalAddress::toString).
1448  *
1449  * Alternatively, the filling can be made with the index of the PMT in the address map of the corresponding module
1450  * (i.e.\ JDETECTOR::JModuleAddressMap::getIndex).\n
1451  * In that case, the method can be called before or after filling of the histogram.
1452  *
1453  * \param axis axis
1454  * \param memo module address map
1455  */
1456  inline void setAxisLabels(TAxis *axis, const JModuleAddressMap& memo)
1457  {
1458  using namespace JPP;
1459 
1460  if (axis->GetNbins() == (int) memo.size()) {
1461 
1462  for (int i = 0; i != axis->GetNbins(); ++i) {
1463 
1464  const JPMTPhysicalAddress& address = memo[i];
1465 
1466  axis->SetBinLabel(i + 1, address.toString().c_str());
1467  }
1468 
1469  } else {
1470 
1471  THROW(JValueOutOfRange, "Number of bins " << axis->GetNbins() << " != " << memo.size());
1472  }
1473  }
1474 
1475 
1476  /**
1477  * Set axis labels with PMT addresses.
1478  *
1479  * This methods sets the labels of the given axis to the sorted values of the PMT ring and position.\n
1480  * It should be called after filling of the corresponding histogram.\n
1481  * The filling should have been made with the PMT number (e.g.\ KM3NETDAQ::JDAQHit::getPMT).
1482  *
1483  * \param h1 histogram
1484  * \param axis axis <tt>(x, X, y, Y, z, Z)</tt>
1485  * \param memo module address map
1486  */
1487  inline void setAxisLabels(TH1& h1, const std::string axis, const JModuleAddressMap& memo)
1488  {
1489  using namespace JPP;
1490 
1491  TAxis* pax = NULL;
1492 
1493  if (axis == "x" || axis == "X")
1494  pax = h1.GetXaxis();
1495  else if (axis == "y" || axis == "Y")
1496  pax = h1.GetYaxis();
1497  else if (axis == "z" || axis == "Z")
1498  pax = h1.GetZaxis();
1499  else
1500  THROW(JValueOutOfRange, "Invalid axis " << axis);
1501 
1502  if (pax->GetNbins() == (int) memo.size()) {
1503 
1504  for (int i = 0; i != pax->GetNbins(); ++i) {
1505 
1506  const JPMTPhysicalAddress& address = memo.getAddressTranslator(i);
1507 
1508  pax->SetBinLabel(i + 1, address.toString().c_str());
1509  }
1510 
1511  h1.LabelsOption("a", axis.c_str()); // sort labels
1512 
1513  } else {
1514 
1515  THROW(JValueOutOfRange, "Number of bins " << pax->GetNbins() << " != " << memo.size());
1516  }
1517  }
1518 
1519 
1520  /**
1521  * Check if given key corresponds to a TObject.
1522  *
1523  * \param key ROOT key
1524  * \return true if given key corresponds to a TObject; else false
1525  */
1526  inline bool isTObject(const TKey* key)
1527  {
1528  return (key != NULL && TClass::GetClass(key->GetClassName())->IsTObject());
1529  }
1530 
1531 
1532  /**
1533  * Get first object of which name matches given reguar expression.
1534  *
1535  * \param ls pointer to list of objects
1536  * \param name regular expression
1537  * \return pointer to object (maybe NULL)
1538  */
1539  inline TObject* getObject(TList* ls, const char* const name)
1540  {
1541  const TRegexp regexp(name);
1542 
1543  TIter iter(ls);
1544 
1545  for (TObject* p1; (p1 = (TObject*) iter.Next()) != NULL; ) {
1546 
1547  const TString tag(p1->GetName());
1548 
1549  if (tag.Contains(regexp)) {
1550  return p1;
1551  }
1552  }
1553 
1554  return NULL;
1555  }
1556 
1557 
1558  /**
1559  * Get function.
1560  *
1561  * \param h1 histogram
1562  * \param fcn function name
1563  * \return pointer to function (maybe NULL)
1564  */
1565  inline TF1* getFunction(TH1* h1, const char* const fcn)
1566  {
1567  return (TF1*) getObject(h1->GetListOfFunctions(), fcn);
1568  }
1569 
1570 
1571  /**
1572  * Get function.
1573  *
1574  * \param g1 graph
1575  * \param fcn function name
1576  * \return pointer to function (maybe NULL)
1577  */
1578  inline TF1* getFunction(TGraph* g1, const char* const fcn)
1579  {
1580  return (TF1*) getObject(g1->GetListOfFunctions(), fcn);
1581  }
1582 
1583 
1584  /**
1585  * Get function.
1586  *
1587  * \param g2 graph
1588  * \param fcn function name
1589  * \return pointer to function (maybe NULL)
1590  */
1591  inline TF1* getFunction(TGraph2D* g2, const char* const fcn)
1592  {
1593  return (TF1*) getObject(g2->GetListOfFunctions(), fcn);
1594  }
1595 }
1596 
1597 #endif
static const char *const sqrt()
Set contents to signed difference between squares.
const double xmax
Definition: JQuadrature.cc:24
data_type w[N+1][M+1]
Definition: JPolint.hh:867
Exceptions.
TObject * getObject(const JRootObjectID &id)
Get first TObject with given identifier.
double getValue(const JScale_t scale)
Get numerical value corresponding to scale.
Definition: JScale.hh:47
TF1 * getFunction(TH1 *h1, const char *const fcn)
Get function.
int getParameter(const std::string &text)
Get parameter number from text string.
static const char *const Divide()
ROOT TH1::Divide.
TPaveText * p1
static const char *const Subtract()
ROOT TH1::Subtract.
Exception for a functional operation.
Definition: JException.hh:142
static const char *const SAME_AS_INPUT()
Set name of output histogram to name of input histogram.
then usage $script[< detector identifier >< run range >]< QA/QCfile > nExample script to produce data quality plots nWhen a detector identifier and run range are data are downloaded from the database nand subsequently stored in the given QA QC file
Definition: JDataQuality.sh:19
char text[TEXT_SIZE]
Definition: elog.cc:72
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
Definition: JRoot.hh:19
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.
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.
is
Definition: JDAQCHSM.chsm:167
void setLogarithmic(TAxis *axis)
Make histogram axis logarithmic (e.g. after using log10()).
const JPolynome f1(1.0, 2.0, 3.0)
Function.
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 .
Definition: JMath.hh:97
static const char *const Multiply()
ROOT TH1::Multiply.
static const char *const SAME_AS_OPERATION()
Set name of output histogram to name of operation.
then fatal The output file must have the wildcard in the name
Definition: JCanberra.sh:31
void setLogarithmicY(TList *list)
Make y-axis of objects in list logarithmic (e.g. after using log10()).
const double xmin
Definition: JQuadrature.cc:23
void setRange(double &xmin, double &xmax, const bool logx)
Set axis range.
const JPMTAddressTranslator & getAddressTranslator(const int tdc) const
Get PMT address translator.
then usage $script[energy[distance[z of PMT]]] fi case set_variable z
Definition: JDrawPDF.sh:45
then usage $script< input file >[option[primary[working directory]]] nWhere option can be N
Definition: JMuonPostfit.sh:40
then fatal The output file must have the wildcard in the e g root fi eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:48
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.
Definition: JHead.cc:162
Exception for parsing value.
Definition: JException.hh:196
bool isTObject(const TKey *key)
Check if given key corresponds to a TObject.
no fit printf nominal n $STRING awk v X
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.
Definition: JeepToolkit.hh:128
do set_variable MODULE getModule a $WORKDIR detector_a datx L $STRING JEditDetector a $WORKDIR detector_a datx M $MODULE setz o $WORKDIR detector_a datx JEditDetector a $WORKDIR detector_b datx M $MODULE setz o $WORKDIR detector_b datx done echo Output stored at $WORKDIR detector_a datx and $WORKDIR tripod_a txt JDrawDetector2D a $WORKDIR detector_a datx a $WORKDIR detector_b datx L BL o detector $FORMAT $BATCH JDrawDetector2D T $WORKDIR tripod_a txt T $WORKDIR tripod_b txt L BL o tripod $FORMAT $BATCH JCompareDetector a $WORKDIR detector_a datx b $WORKDIR detector_b datx o $WORKDIR abc root &dev null for KEY in X Y Z
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:178
TString getLogarithmic(const TString &formula, const char parameter)
Make given parameter in formula logarithmic (e.g. after using log10()).
static const char *const TIMESTAMP
Time stamp of earliest UTC time.
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 JAcousticsToolkit.sh typeset -A TRIPODS get_tripods $WORKDIR/tripod.txt TRIPODS XMEAN
Double_t g1(const Double_t x)
Function.
Definition: JQuantiles.cc:25