Jpp  17.2.1-pre0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JPlot1D.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 #include <vector>
5 #include <set>
6 #include <cmath>
7 
8 #include "TROOT.h"
9 #include "TFile.h"
10 #include "TClass.h"
11 #include "TApplication.h"
12 #include "TCanvas.h"
13 #include "TKey.h"
14 #include "TStyle.h"
15 #include "TAttMarker.h"
16 #include "TAttLine.h"
17 #include "TH1.h"
18 #include "TH2.h"
19 #include "TH3.h"
20 #include "TF1.h"
21 #include "TF2.h"
22 #include "THStack.h"
23 #include "TGraph.h"
24 #include "TGraphErrors.h"
25 #include "TMultiGraph.h"
26 #include "TProfile.h"
27 #include "TEllipse.h"
28 #include "TMarker.h"
29 #include "TLine.h"
30 #include "TLegend.h"
31 #include "TString.h"
32 #include "TRegexp.h"
33 #include "TText.h"
34 
35 #include "JTools/JRange.hh"
36 #include "JLang/JSinglePointer.hh"
37 #include "JROOT/JStyle.hh"
38 #include "JROOT/JCanvas.hh"
40 #include "JROOT/JLineAttributes.hh"
41 #include "JROOT/JLegend.hh"
42 #include "JGizmo/JRootObjectID.hh"
43 #include "JGizmo/JRootObject.hh"
44 #include "JGizmo/JGizmoToolkit.hh"
45 
46 #include "Jeep/JPrint.hh"
47 #include "Jeep/JParser.hh"
48 #include "Jeep/JMessage.hh"
49 
50 namespace {
51 
52  using JLANG::JEquals;
53 
54  /**
55  * Set x of object to logarithmic.
56  *
57  * \param object pointer to object
58  * \return true if set; else false
59  */
60  template<class T>
61  inline bool setLogX(TObject* object)
62  {
63  using namespace JPP;
64 
65  T* p = dynamic_cast<T*>(object);
66 
67  if (p != NULL) {
68 
69  setLogarithmicX(p);
70 
71  return true;
72  }
73 
74  return false;
75  }
76 
77  /**
78  * Auxiliary data structure for legend options.
79  */
80  struct JLegend :
81  public JEquals<JLegend>
82  {
83  /**
84  * Default constructor.
85  */
86  JLegend() :
87  location(),
88  factor (0.0)
89  {}
90 
91  /**
92  * Constructor.
93  *
94  * \param location location
95  * \param factor factor
96  */
97  JLegend(const std::string& location,
98  const Double_t factor = 1.0) :
99  location(location),
100  factor (factor)
101  {}
102 
103  /**
104  * Check validity.
105  *
106  * \return true if valid; else false
107  */
108  bool is_valid() const
109  {
110  return (location != "" && factor != 0.0);
111  }
112 
113  /**
114  * Chek equality.
115  *
116  * \param legend legend
117  * \return input stream
118  */
119  bool equals(const JLegend& legend) const
120  {
121  return (this->location == legend.location);
122  }
123 
124  /**
125  * Read legend from input stream.
126  *
127  * \param in input stream
128  * \param legend legend
129  * \return input stream
130  */
131  friend inline std::istream& operator>>(std::istream& in, JLegend& legend)
132  {
133  in >> legend.location;
134 
135  if (!(in >> legend.factor)) {
136 
137  legend.factor = 1.0;
138 
139  in.clear();
140  }
141 
142  return in;
143  }
144 
145  /**
146  * Write legend to output stream.
147  *
148  * \param out output stream
149  * \param legend legend
150  * \return output stream
151  */
152  friend inline std::ostream& operator<<(std::ostream& out, const JLegend& legend)
153  {
154  return out << legend.location << ' ' << legend.factor;
155  }
156 
157  std::string location;
158  Double_t factor;
159  };
160 
161 
162  /**
163  * Get width of string.
164  *
165  * \param buffer string
166  * \return width
167  */
168  inline Ssiz_t getWidth(const TString& buffer)
169  {
170  double w = 0.0;
171 
172  for (Ssiz_t i = 0; i != buffer.Length(); ++i) {
173 
174  if (buffer(i) == ' ')
175  w += 0.5;
176  else if (buffer(i) >= 'A' && buffer(i) <= 'Z')
177  w += 1.0;
178  else if (buffer(i) >= 'a' && buffer(i) <= 'z')
179  w += 0.7;
180  else if (buffer(i) == '.' || buffer(i) == ':' || buffer(i) == ';' || buffer(i) == ',' || buffer(i) == '\'')
181  w += 0.5;
182  else
183  w += 1.0;
184  }
185 
186  return (Ssiz_t) w;
187  }
188 
189 
190  const std::string MASTER = "__H__"; //!< Name of prototype
191 
192  const char* const JName_t = "?"; //!< Draw histogram name as title of plot
193  const char* const JTitle_t = "%"; //!< Draw histogram title as title of plot
194 }
195 
196 
197 /**
198  * \file
199  * General purpose plot program for 1D ROOT objects.
200  * The option <tt>-f</tt> corresponds to <tt><file name>:<object name></tt>.
201  * \author mdejong
202  */
203 int main(int argc, char **argv)
204 {
205  using namespace std;
206  using namespace JPP;
207 
208  typedef JRange<double> JRange_t;
209 
210  vector<JRootObjectID> inputFile;
211  string outputFile;
212  JCanvas canvas;
213  int stats;
214  JLegend legend;
215  JRange_t X;
216  JRange_t Y;
217  JRange_t Z;
218  JCounter logx;
219  bool logy;
220  bool logz;
221  char project;
222  string xLabel;
223  string yLabel;
224  JCounter drawLine;
225  bool fillArea;
226  int lineWidth;
227  double markerSize;
228  string option;
229  set<char> grid;
230  bool batch;
231  string title;
232  map<string, int> Ndivisions;
233  int group;
234  int debug;
235  string xTimeFormat;
236 
237  try {
238 
239  JParser<> zap("General purpose plot program for 1D ROOT objects.");
240 
241  zap['f'] = make_field(inputFile, "<input file>:<object name>");
242  zap['o'] = make_field(outputFile, "graphics output") = "";
243  zap['w'] = make_field(canvas, "size of canvas <nx>x<ny> [pixels]") = JCanvas(500, 500);
244  zap['s'] = make_field(stats) = -1;
245  zap['L'] = make_field(legend, "position legend e.g. TR [factor]") = JLegend(), JLegend("TL"), JLegend("TR"), JLegend("BR"), JLegend("BL");
246  zap['x'] = make_field(X, "abscissa range") = JRange_t();
247  zap['y'] = make_field(Y, "ordinate range") = JRange_t();
248  zap['z'] = make_field(Z, "ordinate range of projection)") = JRange_t();
249  zap['X'] = make_field(logx, "logarithmic x-axis (-XX log10 axis)");
250  zap['Y'] = make_field(logy, "logarithmic y-axis");
251  zap['Z'] = make_field(logz, "logarithmic y-axis; after projection");
252  zap['P'] = make_field(project, "projection") = '\0', 'x', 'X', 'y', 'Y';
253  zap['>'] = make_field(xLabel, "x-axis label") = "";
254  zap['^'] = make_field(yLabel, "y-axis label") = "";
255  zap['C'] = make_field(drawLine, "draw line (-C black-and-white -CC colour)");
256  zap['F'] = make_field(fillArea, "fill area");
257  zap['l'] = make_field(lineWidth, "line width") = 2;
258  zap['S'] = make_field(markerSize, "marker size") = 1.0;
259  zap['O'] = make_field(option, "plotting option") = "";
260  zap['G'] = make_field(grid, "grid lines [X][Y]") = JPARSER::initialised();
261  zap['B'] = make_field(batch, "batch processing");
262  zap['T'] = make_field(title, "graphics title ("
263  << "\"" << JName_t << "\" -> ROOT name; "
264  << "\"" << JTitle_t << "\" -> ROOT title)") = "KM3NeT preliminary";
265  zap['N'] = make_field(Ndivisions, "axis divisioning (e.g. \"X 505\")") = JPARSER::initialised();
266  zap['g'] = make_field(group, "group colour codes of objects") = 1;
267  zap['t'] = make_field(xTimeFormat, "set time format for x-axis, e.g. \%d\\/\%m\\/\\%y%F1970-01-01 00:00:00") = "";
268  zap['d'] = make_field(debug) = 0;
269 
270  zap(argc, argv);
271  }
272  catch(const exception &error) {
273  FATAL(error.what() << endl);
274  }
275 
276 
277  gROOT->SetBatch(batch);
278 
279  TApplication* tp = new TApplication("user", NULL, NULL);
280  TCanvas* cv = new TCanvas("c1", "c1", canvas.x, canvas.y);
281 
282  JSinglePointer<TStyle> gStyle(new JStyle("gplot", cv->GetWw(), cv->GetWh()));
283 
284  gROOT->SetStyle("gplot");
285  gROOT->ForceStyle();
286 
287 
288  cv->SetFillStyle(4000);
289  cv->SetFillColor(kWhite);
290  cv->Divide(1,1);
291  cv->cd(1);
292 
293 
294  JMarkerAttributes::getInstance().setMarkerSize(markerSize);
295  JLineAttributes ::getInstance().setLineWidth (lineWidth);
296 
297 
298  Double_t xmin = numeric_limits<double>::max();
299  Double_t xmax = numeric_limits<double>::lowest();
300 
301  Double_t ymin = numeric_limits<double>::max();
302  Double_t ymax = numeric_limits<double>::lowest();
303 
304 
305  vector<JRootObject> listOfObjects;
306 
307  const bool px = (project == 'x' || project == 'X'); // projection on x-axis of (2|3)D histogram
308  const bool py = (project == 'y' || project == 'Y'); // projection on y-axis of (2|3)D histogram
309  const bool pz = (project == 'z' || project == 'Z'); // projection on z-axis of 3D histogram
310 
311  logy = (logy || logz);
312 
313  if (px) {
314  swap(Y, Z); // Y becomes range in TH2::ProjectionX() and Z becomes y-axis range
315  }
316 
317  if (py) {
318  swap(X, Z); // X becomes range in TH2::ProjectionY()
319  swap(Y, X); // Y becomes x-axis range and Z becomes y-axis range
320  }
321 
322  TH1* master = NULL;
323 
324  for (vector<JRootObjectID>::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) {
325 
326  DEBUG("Input: " << *input << endl);
327 
328  TDirectory* dir = getDirectory(*input);
329 
330  if (dir == NULL) {
331  ERROR("File: " << input->getFullFilename() << " not opened." << endl);
332  continue;
333  }
334 
335  const TRegexp regexp(input->getObjectName());
336 
337  TIter iter(dir->GetListOfKeys());
338 
339  for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
340 
341  const TString tag(key->GetName());
342 
343  DEBUG("Key: " << tag << " match = " << tag.Contains(regexp) << endl);
344 
345  // option match
346 
347  if (tag.Contains(regexp) && isTObject(key)) {
348 
349  if (title == JName_t) {
350  title = key->GetName();
351  } else if (title == JTitle_t) {
352  title = key->GetTitle();
353  }
354 
355  JRootObject object(key->ReadObj());
356 
357  TAttMarker marker = JMarkerAttributes::getInstance().get(0);
358  TAttLine line = JLineAttributes ::getInstance().get(0);
359 
360  if (group > 1)
361  marker.SetMarkerColor(JMarkerAttributes::getInstance().get(listOfObjects.size()/group).GetMarkerColor());
362  else
363  marker = JMarkerAttributes::getInstance().get(listOfObjects.size());
364 
365  if (drawLine == 1)
366  line = JLineAttributes::getInstance().get(listOfObjects.size());
367  else
368  line.SetLineColor(marker.GetMarkerColor());
369 
370  // projections
371 
372  try {
373 
374  TProfile& h1 = dynamic_cast<TProfile&>(*object);
375 
376  object = h1.ProjectionX();
377  }
378  catch(exception&) {}
379 
380  try {
381 
382  TH2& h2 = dynamic_cast<TH2&>(*object);
383 
384  if (px) {
385 
386  if (Z != JRange_t())
387  object = h2.ProjectionX(MAKE_CSTRING(h2.GetName() << "_px" << LABEL_TERMINATOR << listOfObjects.size()),
388  h2.GetYaxis()->FindBin(Z.getLowerLimit()),
389  h2.GetYaxis()->FindBin(Z.getUpperLimit()) - 1);
390  else
391  object = h2.ProjectionX(MAKE_CSTRING(h2.GetName() << "_px" << LABEL_TERMINATOR << listOfObjects.size()),
392  1,
393  h2.GetYaxis()->GetNbins());
394 
395  } else if (py) {
396 
397  if (Z != JRange_t())
398  object = h2.ProjectionY(MAKE_CSTRING(h2.GetName() << "_py" << LABEL_TERMINATOR << listOfObjects.size()),
399  h2.GetXaxis()->FindBin(Z.getLowerLimit()),
400  h2.GetXaxis()->FindBin(Z.getUpperLimit()) - 1);
401  else
402  object = h2.ProjectionY(MAKE_CSTRING(h2.GetName() << "_py" << LABEL_TERMINATOR << listOfObjects.size()),
403  1,
404  h2.GetXaxis()->GetNbins());
405 
406  } else {
407 
408  ERROR("For 2D histograms, use option option -P for projections or use JPlot2D" << endl);
409 
410  continue;
411  }
412  }
413  catch(exception&) {}
414 
415  try {
416 
417  TH3& h3 = dynamic_cast<TH3&>(*object);
418 
419  if (px) {
420 
421  object = h3.ProjectionX(MAKE_CSTRING(h3.GetName() << "_px" << LABEL_TERMINATOR << listOfObjects.size()));
422 
423  } else if (py) {
424 
425  object = h3.ProjectionY(MAKE_CSTRING(h3.GetName() << "_py" << LABEL_TERMINATOR << listOfObjects.size()));
426 
427  } else if (pz) {
428 
429  object = h3.ProjectionZ(MAKE_CSTRING(h3.GetName() << "_pz" << LABEL_TERMINATOR << listOfObjects.size()));
430 
431  } else {
432 
433  ERROR("For 3D histograms, use option option -P for projections or use JPlot2D -P <projection>" << endl);
434 
435  continue;
436  }
437  }
438  catch(exception&) {}
439 
440  // colouring
441 
442  try {
443  if (dynamic_cast<TMarker*>(object.get()) == NULL) {
444  dynamic_cast<TAttMarker&>(*object) = marker;
445  }
446  }
447  catch(exception&) {}
448 
449  try {
450  if (dynamic_cast<TLine*>(object.get()) == NULL) {
451  dynamic_cast<TAttLine&> (*object) = line;
452  }
453  }
454  catch(exception&) {}
455 
456  if (fillArea) {
457 
458  try {
459 
460  TAttFill& fill = dynamic_cast<TAttFill&>(*object);
461 
462  fill.SetFillColor(marker.GetMarkerColor());
463  }
464  catch(exception&) {}
465  }
466 
467  // set errors
468 
469  if (drawLine) {
470 
471  try {
472 
473  TH1& h1 = dynamic_cast<TH1&>(*object);
474 
475  for (int i = 1; i <= h1.GetNbinsX(); ++i) {
476  h1.SetBinError(i, 0.0);
477  }
478  }
479  catch(exception&) {}
480 
481  try {
482 
483  TGraphErrors& g1 = dynamic_cast<TGraphErrors&>(*object);
484 
485  for (Int_t i = 0; i != g1.GetN(); ++i) {
486  g1.GetEX()[i] = 0.0;
487  g1.GetEY()[i] = 0.0;
488  }
489  }
490  catch(exception&) {}
491  }
492 
493  // min-max
494 
495  try {
496 
497  TH1& h1 = dynamic_cast<TH1&>(*object);
498 
499  h1.SetStats(stats != -1);
500 
501  xmin = min(xmin, h1.GetXaxis()->GetXmin());
502  xmax = max(xmax, h1.GetXaxis()->GetXmax());
503  ymin = min(ymin, logy ? h1.GetMinimum(0.0) : h1.GetMinimum());
504  ymax = max(ymax, h1.GetMaximum());
505  }
506  catch(exception&) {}
507 
508  try {
509 
510  TGraph& g1 = dynamic_cast<TGraph&>(*object);
511 
512  for (Int_t i = 0; i != g1.GetN(); ++i) {
513 
514  xmin = min(xmin, g1.GetX()[i]);
515  xmax = max(xmax, g1.GetX()[i]);
516 
517  if (!logy || g1.GetY()[i] > 0.0) {
518  ymin = min(ymin, g1.GetY()[i]);
519  ymax = max(ymax, g1.GetY()[i]);
520  }
521  }
522  }
523  catch(exception&) {}
524 
525  try {
526 
527  TGraphErrors& g1 = dynamic_cast<TGraphErrors&>(*object);
528 
529  for (Int_t i = 0; i != g1.GetN(); ++i) {
530  if (!logy || g1.GetY()[i] - g1.GetEY()[i] > 0.0) { ymin = min(ymin, g1.GetY()[i] - g1.GetEY()[i]); }
531  if (!logy || g1.GetY()[i] + g1.GetEY()[i] > 0.0) { ymax = max(ymax, g1.GetY()[i] + g1.GetEY()[i]); }
532  }
533  }
534  catch(exception&) {}
535 
536  try {
537 
538  TMultiGraph& m1 = dynamic_cast<TMultiGraph&>(*object);
539 
540  for (TIter i1(m1.GetListOfGraphs()); TGraph* g1 = dynamic_cast<TGraph*>(i1()); ) {
541 
542  for (Int_t i = 0; i != g1->GetN(); ++i) {
543 
544  xmin = min(xmin, g1->GetX()[i]);
545  xmax = max(xmax, g1->GetX()[i]);
546 
547  if (!logy || g1->GetY()[i] > 0.0) {
548  ymin = min(ymin, g1->GetY()[i]);
549  ymax = max(ymax, g1->GetY()[i]);
550  }
551  }
552  }
553  }
554  catch(exception&) {}
555 
556  try {
557 
558  TF2& f2 = dynamic_cast<TF2&>(*object);
559  TF1* f1 = NULL;
560 
561  TString formula = f2.GetExpFormula();
562  TString _z_ = TString::Format("%f", 0.5 * (Z.getLowerLimit() + Z.getUpperLimit()));
563 
564  double __xmin;
565  double __xmax;
566  double __ymin;
567  double __ymax;
568 
569  f2.GetRange(__xmin, __ymin, __xmax, __ymax);
570 
571  if (px) {
572 
573  formula.ReplaceAll("y", _z_);
574 
575  f1 = new TF1(MAKE_CSTRING(f2.GetName() << "_px" << LABEL_TERMINATOR << listOfObjects.size()), formula);
576 
577  f1->SetRange(__xmin, __xmax);
578 
579  } else if (py) {
580 
581  formula.ReplaceAll("x", _z_);
582  formula.ReplaceAll("y", "x");
583 
584  f1 = new TF1(MAKE_CSTRING(f2.GetName() << "_py" << LABEL_TERMINATOR << listOfObjects.size()), formula);
585 
586  f1->SetRange(__ymin, __ymax);
587 
588  } else {
589 
590  ERROR("For 2D functions, use option option -P for projections or use JPlot2D" << endl);
591 
592  continue;
593  }
594 
595  DEBUG("TF1: " << f1->GetExpFormula() << endl);
596 
597  f1->SetParameters(f2.GetParameters());
598 
599  object = f1;
600  }
601  catch(exception&) {}
602 
603  try {
604 
605  TF1& f1 = dynamic_cast<TF1&>(*object);
606 
607  double __xmin;
608  double __xmax;
609 
610  f1.GetRange(__xmin, __xmax);
611 
612  xmin = min(xmin, __xmin);
613  xmax = max(xmax, __xmax);
614  ymin = min(ymin, f1.GetMinimum());
615  ymax = max(ymax, f1.GetMaximum());
616  }
617  catch(exception&) {}
618 
619  try {
620 
621  THStack& hs = dynamic_cast<THStack&>(*object);
622 
623  NOTICE("THStack" << endl);
624 
625  TIterator* iterator = hs.GetHists()->MakeIterator();
626 
627  for (size_t index = 1; TObject* i = iterator->Next(); ++index) {
628 
629  TH1& h1 = dynamic_cast<TH1&>(*i);
630 
631  NOTICE("TH1[" << index << "] " << h1.GetName() << endl);
632 
633  xmin = min(xmin, h1.GetXaxis()->GetXmin());
634  xmax = max(xmax, h1.GetXaxis()->GetXmax());
635 
636  ymin = min(ymin, logy ? h1.GetMinimum(0.0) : h1.GetMinimum());
637  ymax = max(ymax, h1.GetMaximum());
638 
639  h1.SetLineWidth(1);
640  h1.SetLineColor(kBlack);
641 
642  h1.SetFillColor(JMarkerAttributes::getInstance().get(index).GetMarkerColor());
643  }
644  }
645  catch(exception&) {}
646 
647  try {
648 
649  TLine& h1 = dynamic_cast<TLine&>(*object);
650 
651  xmin = min(xmin, h1.GetX1());
652  xmax = max(xmax, h1.GetX2());
653  ymin = min(ymin, h1.GetY1());
654  ymax = max(ymax, h1.GetY2());
655  }
656  catch(exception&) {}
657 
658  // label
659 
660  for (TString buffer[] = { object.getLabel(), input->getFilename().c_str(), "" }, *i = buffer; *i != ""; ++i) {
661 
662  *i = (*i)(TRegexp("\\[.*\\]"));
663 
664  if (i->Length() > 2) {
665  object.setLabel((*i)(1, i->Length() - 2));
666  }
667  }
668 
669  DEBUG("Add object: " << tag << " with label <" << object.getLabel() << ">" << endl);
670 
671  if (master == NULL) {
672  master = dynamic_cast<TH1*>(object.get());
673  }
674 
675  listOfObjects.push_back(object);
676  }
677  }
678  }
679 
680  if (listOfObjects.empty()) {
681  ERROR("Nothing to draw." << endl);
682  }
683 
684  for (vector<JRootObject>::iterator i = listOfObjects.begin(); i != listOfObjects.end(); ++i) {
685 
686  // set line attributes of associated functions
687  // for single objects, change colour if same range else change style
688  // for multiple objecs, keep colour and change style
689 
690  TH1* h1 = dynamic_cast<TH1*> (i->get());
691  TGraph* g1 = dynamic_cast<TGraph*> (i->get());
692  TMultiGraph* m1 = dynamic_cast<TMultiGraph*>(i->get());
693  TAttLine* ls = dynamic_cast<TAttLine*> (i->get());
694 
695  TList list;
696  TIterator* iterator = NULL;
697 
698  if (h1 != NULL) {
699 
700  iterator = h1->GetListOfFunctions()->MakeIterator();
701 
702  } else if (g1 != NULL) {
703 
704  iterator = g1->GetListOfFunctions()->MakeIterator();
705 
706  } else if (m1 != NULL) {
707 
708  for (TIter i1(m1->GetListOfGraphs()); TGraph* gi = dynamic_cast<TGraph*>(i1()); ) {
709  for (TIter i2(gi->GetListOfFunctions()); TF1* fi = dynamic_cast<TF1*>(i2()); ) {
710  list.Add(fi);
711  }
712  }
713 
714  iterator = list.MakeIterator();
715  }
716 
717  if (iterator != NULL) {
718 
719  Double_t x1[] = { numeric_limits<Double_t>::max(), numeric_limits<Double_t>::max() };
720  Double_t x2[] = { numeric_limits<Double_t>::lowest(), numeric_limits<Double_t>::lowest() };
721 
722  for (int nf = 0, ns = 0, nc = 1; TF1* f1 = (TF1*) iterator->Next(); ++nf) {
723 
724  f1->GetRange(x1[1], x2[1]);
725  f1->SetNpx(5000);
726 
727  dynamic_cast<TAttLine&>(*f1) = JLineAttributes::getInstance().get(0);
728 
729  if (listOfObjects.size() == 1) {
730 
731  if (x1[0] == x1[1] &&
732  x2[0] == x2[1])
733  ++nc; // change colour
734  else if (nf != 0)
735  ++ns; // change style
736 
737  f1->SetLineStyle(JLineAttributes ::getInstance().get(ns).GetLineStyle());
738  f1->SetLineColor(JMarkerAttributes::getInstance().get(nc).GetMarkerColor());
739 
740  } else {
741 
742  // keep colour of base object and accordingly modify line style.
743 
744  f1->SetLineColor(ls->GetLineColor());
745  f1->SetLineStyle(JLineAttributes::getInstance().get(ns++).GetLineStyle());
746  }
747 
748  x1[0] = x1[1];
749  x2[0] = x2[1];
750 
751  // set limits
752  /*
753  double __xmin;
754  double __xmax;
755 
756  f1->GetRange(__xmin, __xmax);
757 
758  ymin = min(ymin, f1->GetMinimum(__xmin, __xmax));
759  ymax = max(ymax, f1->GetMaximum(__xmin, __xmax));
760  */
761  }
762  }
763  }
764 
765  // plot frame
766 
767  if (X != JRange_t()) {
768  xmin = X.getLowerLimit();
769  xmax = X.getUpperLimit();
770  }
771 
772  if (Y != JRange_t()) {
773  ymin = Y.getLowerLimit();
774  ymax = Y.getUpperLimit();
775  } else if (ymax > ymin) {
776  setRange(ymin, ymax, logy);
777  }
778 
779  cv->cd(1);
780 
781  if (!listOfObjects.empty()) {
782 
783  if (master == NULL || listOfObjects.size() >= 2u) {
784 
785  master = new TH1D(MASTER.c_str(), NULL, 100, xmin, xmax);
786 
787  master->SetStats(kFALSE);
788 
789  for (Int_t i = 1; i <= master->GetXaxis()->GetNbins(); ++i) {
790  master->SetBinContent(i, ymin);
791  }
792  }
793  }
794 
795  if (master == NULL) {
796 
797  TText* p = new TText(0.5, 0.5, MAKE_CSTRING("No data"));
798 
799  p->SetTextAlign(21);
800  p->SetTextAngle(45);
801  p->Draw();
802 
803  } else {
804 
805  if (logx) { gPad->SetLogx(); }
806  if (logy) { gPad->SetLogy(); }
807 
808  master->GetXaxis()->SetRangeUser(xmin, xmax);
809  master->SetTitle(title.c_str());
810 
811  if (logx > 1) {
813  }
814 
815  master->SetMinimum(ymin);
816  master->SetMaximum(ymax);
817 
818  if (xLabel != "") { master->GetXaxis()->SetTitle(xLabel.c_str()); master->GetXaxis()->CenterTitle(true); }
819  if (yLabel != "") { master->GetYaxis()->SetTitle(yLabel.c_str()); master->GetYaxis()->CenterTitle(true); }
820 
821  master->GetXaxis()->SetMoreLogLabels((logx == 1 && log10(xmax/xmin) < 2) ||
822  (logx > 1 && (xmax-xmin) < 2));
823 
824  master->GetYaxis()->SetMoreLogLabels( logy && log10(ymax/ymin) < 2);
825  master->GetYaxis()->SetNoExponent ( logy && log10(ymax/ymin) < 2);
826 
827  for (map<string, int>::const_iterator i = Ndivisions.begin(); i != Ndivisions.end(); ++i) {
828  master->SetNdivisions(i->second, i->first.c_str());
829  }
830 
831  if (xTimeFormat != "") {
832 
833  master->GetXaxis()->SetTimeDisplay(1);
834 
835  if (xTimeFormat == "utc") {
836  master->GetXaxis()->SetTimeFormat("#splitline{}{#splitline{%d-%m-%y}{ %H:%M}}");
837  master->GetXaxis()->SetTimeOffset(0.0, "gmt");
838  } else if (xTimeFormat == "UTC") {
839  master->GetXaxis()->SetTimeFormat("%d-%m-%y");
840  master->GetXaxis()->SetTimeOffset(0.0, "gmt");
841  } else {
842  master->GetXaxis()->SetTimeFormat(xTimeFormat.c_str());
843  }
844  }
845 
846  master->Draw(option.c_str());
847  }
848 
849  if (logx > 1) {
850  for (vector<JRootObject>::iterator i = listOfObjects.begin(); i != listOfObjects.end(); ++i) {
851  if (dynamic_cast<TH1*>(i->get()) != master) {
852  if (setLogX<TH1> (i->get())) {}
853  else if (setLogX<TF1> (i->get())) {}
854  else if (setLogX<TGraphErrors>(i->get())) {}
855  else if (setLogX<TGraph> (i->get())) {}
856  else if (setLogX<TMultiGraph> (i->get())) {}
857  else if (setLogX<TLine> (i->get())) {}
858  else if (setLogX<TEllipse> (i->get())) {}
859  }
860  }
861  }
862 
863  if (grid.count('x') || grid.count('X')) { gPad->SetGridx(); }
864  if (grid.count('y') || grid.count('Y')) { gPad->SetGridy(); }
865 
866  if (stats != -1)
867  gStyle->SetOptStat(stats);
868  else
869  gStyle->SetOptFit(kFALSE);
870 
871 
872  for (vector<JRootObject>::const_iterator i = listOfObjects.begin(); i != listOfObjects.end(); ++i) {
873 
874  DEBUG("Draw " << (*i)->GetName() << ' ' << (*i)->GetTitle() << endl);
875 
876  string buffer(option);
877 
878  //if (!dynamic_cast<THStack*>(i->get())) {
879  // buffer += "SAMES";
880  //}
881 
882  buffer += "SAME";
883 
884  TF1* f1 = dynamic_cast<TF1*> (i->get());
885  TGraph* g1 = dynamic_cast<TGraph*> (i->get());
886  TMultiGraph* q1 = dynamic_cast<TMultiGraph*>(i->get());
887 
888  if (f1 != NULL) {
889  f1->SetNpx(5000);
890  }
891 
892  if (g1 != NULL) {
893  if (g1->GetN() > 1 && drawLine)
894  buffer += "L"; // drawing cut line
895  else
896  buffer += "P"; // drawing point(s)
897  }
898 
899  if (q1 != NULL) {
900 
901  for (TIter i1(q1->GetListOfGraphs()); TGraph* gi = dynamic_cast<TGraph*>(i1()); ) {
902 
903  string zbuf = buffer;
904 
905  if (gi->GetN() > 1 && drawLine)
906  zbuf += "L"; // drawing cut line
907  else
908  zbuf += "P"; // drawing point(s)
909 
910  gi->Draw(zbuf.c_str());
911  }
912 
913  } else {
914 
915  (*i).Draw(buffer.c_str());
916  }
917  }
918 
919  //gPad->RedrawAxis();
920 
921  if (legend.is_valid()) {
922 
923  Ssiz_t height = listOfObjects.size();
924  Ssiz_t width = 1;
925 
926  for (vector<JRootObject>::const_iterator i = listOfObjects.begin(); i != listOfObjects.end(); ++i) {
927  width = max(width, getWidth(i->getLabel()));
928  }
929 
930  TLegend* lg = getLegend(width, height, legend.location, legend.factor);
931 
932  for (vector<JRootObject>::const_iterator i = listOfObjects.begin(); i != listOfObjects.end(); ++i) {
933  if (dynamic_cast<TMarker*>(i->get()) == NULL &&
934  dynamic_cast<TLine*> (i->get()) == NULL &&
935  dynamic_cast<TText*> (i->get()) == NULL) {
936  lg->AddEntry(*i, " " + i->getLabel(), isTAttLine(*i) ? "L" : "LPF");
937  }
938  }
939 
940  lg->Draw();
941  }
942 
943  cv->Update();
944 
945  if (outputFile != "") {
946  cv->SaveAs(outputFile.c_str());
947  }
948 
949  if (!batch) {
950  tp->Run();
951  }
952 
953  return (master != NULL ? 0 : 1);
954 }
const double xmax
Definition: JQuadrature.cc:24
Utility class to parse command line options.
Definition: JParser.hh:1517
then echo Test string reversed by master(hit< return > to continue)." $DIR/JProcess -c "$DIR/JEcho" -rC fi if (( 1 ))
data_type w[N+1][M+1]
Definition: JPolint.hh:778
int main(int argc, char *argv[])
Definition: Main.cc:15
std::string getLabel(const JLocation &location)
Get module label for monitoring and other applications.
Definition: JLocation.hh:246
Definition: JRoot.hh:19
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:136
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:83
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
string outputFile
const JPolynome f1(1.0, 2.0, 3.0)
Function.
bool isTAttLine(const TObject *object)
Get drawing option of TH1.
I/O formatting auxiliaries.
void setLogarithmicX(TList *list)
Make x-axis of objects in list logarithmic (e.g. after using log10()).
T & getInstance(const T &object)
Get static instance from temporary object.
Definition: JObject.hh:75
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1993
set_variable E_E log10(E_{fit}/E_{#mu})"
do set_variable OUTPUT_DIRECTORY $WORKDIR T
Template definition of auxiliary base class for comparison of data structures.
Definition: JEquals.hh:24
bool is_valid(const json &js)
Check validity of JSon data.
TLegend * getLegend(const Int_t width, const Int_t height, const std::string option, const Double_t factor=1.0)
Get legend.
Definition: JLegend.hh:29
#define NOTICE(A)
Definition: JMessage.hh:64
#define ERROR(A)
Definition: JMessage.hh:66
then awk string
General purpose messaging.
static const char LABEL_TERMINATOR
label terminator
Definition: JRootObject.hh:23
#define FATAL(A)
Definition: JMessage.hh:67
const double xmin
Definition: JQuadrature.cc:23
void setRange(double &xmin, double &xmax, const bool logx)
Set axis range.
std::istream & operator>>(std::istream &in, JAANET::JHead &header)
Read header from input.
Definition: JHead.hh:1756
Auxiliary class to define a range between two values.
Utility class to parse command line options.
Auxiliary class to handle multiple boolean-like I/O.
Definition: JParser.hh:238
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::ostream & operator<<(std::ostream &stream, const CLBCommonHeader &header)
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
bool equals(const JFirst_t &first, const JSecond_t &second, const double precision=std::numeric_limits< double >::min())
Check equality.
Definition: JMathToolkit.hh:86
double u[N+1]
Definition: JPolint.hh:776
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 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:46
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
Double_t g1(const Double_t x)
Function.
Definition: JQuantiles.cc:25