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