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