Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGraph.cxx
Go to the documentation of this file.
1// @(#)root/hist:$Id$
2// Author: Rene Brun, Olivier Couet 12/12/94
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12
13#include "TROOT.h"
14#include "TBuffer.h"
15#include "TEnv.h"
16#include "TGraph.h"
17#include "TH1.h"
18#include "TF1.h"
19#include "TStyle.h"
20#include "TMath.h"
21#include "TVectorD.h"
22#include "Foption.h"
23#include "TRandom.h"
24#include "TSpline.h"
25#include "TVirtualFitter.h"
26#include "TVirtualPad.h"
28#include "TBrowser.h"
29#include "TSystem.h"
30#include "TPluginManager.h"
31#include "strtok.h"
32
33#include <cstdlib>
34#include <string>
35#include <cassert>
36#include <iostream>
37#include <fstream>
38#include <cstring>
39#include <numeric>
40#include <limits>
41#include <iomanip>
42
43#include "HFitInterface.h"
44#include "Fit/DataRange.h"
46
48
49
50////////////////////////////////////////////////////////////////////////////////
51
52/** \class TGraph
53 \ingroup Graphs
54A TGraph is an object made of two arrays X and Y with npoints each.
55The TGraph painting is performed thanks to the TGraphPainter
56class. All details about the various painting options are given in this class.
57
58#### Notes
59
60 - Unlike histogram or tree (or even TGraph2D), TGraph objects
61 are not automatically attached to the current TFile, in order to keep the
62 management and size of the TGraph as small as possible.
63 - The TGraph constructors do not have the TGraph title and name as parameters.
64 A TGraph has the default title and name "Graph". To change the default title
65 and name `SetTitle` and `SetName` should be called on the TGraph after its creation.
66 TGraph was a light weight object to start with, like TPolyline or TPolyMarker.
67 That’s why it did not have any title and name parameters in the constructors.
68
69#### Example
70
71The picture below gives an example:
72
73Begin_Macro(source)
74{
75 double x[100], y[100];
76 int n = 20;
77 for (int i=0;i<n;i++) {
78 x[i] = i*0.1;
79 y[i] = 10*sin(x[i]+0.2);
80 }
81 auto g = new TGraph(n,x,y);
82 g->SetTitle("Graph title;X title;Y title");
83 g->Draw("AC*");
84}
85End_Macro
86
87#### Default X-Points
88
89If one doesn't specify the points in the x-axis, they will get the default values 0, 1, 2, 3, (etc. depending
90on the length of the y-points):
91
92Begin_Macro(source)
93{
94 double y[6] = {3, 8, 1, 10, 5, 7};
95 auto g = new TGraph(6,y);
96 g->SetTitle("A Graph with default X points");
97 g->Draw();
98}
99End_Macro
100
101#### X-axis zooming
102
103The underlying x axis of a TGraph is based on a virtual fixed binwidth histogram, which means that one can not infinitely zoom on it, just down to one bin.
104The number of virtual bins is the maximum between 100 and the number of points in the TGraph. If you find a case where you would like to zoom deeper than allowed,
105you can either start canvas in web mode, or keep in classic mode but predefine the histogram before the first drawing of the graph:
106
107\code{.cpp}
108TGraph gr;
109for(auto i = 0; i < 100; ++i) gr.AddPoint(i,i);
110gr.AddPoint(10000, 0);
111// If one draws here, one can not zoom between x = 0 and x = 50, since first bin goes from x = 0 to 100.
112auto h1 = new TH1F("hist", "hist", 10000, -10., 11000.); // Define underlying hist with 10000 instead of 101 bins
113h1->SetMaximum(120);
114h1->SetStats(0);
115h1->SetDirectory(nullptr);
116gr.SetHistogram(h1);
117gr.Draw("A*")
118\endcode
119
120*/
121
122////////////////////////////////////////////////////////////////////////////////
123/// Graph default constructor.
124
126{
127 fNpoints = -1; //will be reset to 0 in CtorAllocate
128 if (!CtorAllocate()) return;
129}
130
131////////////////////////////////////////////////////////////////////////////////
132/// Constructor with only the number of points set
133/// the arrays x and y will be set later
134
136 : TNamed("Graph", "Graph"), TAttFill(0, 1000)
137{
138 fNpoints = n;
139 if (!CtorAllocate()) return;
140 FillZero(0, fNpoints);
141}
142
143////////////////////////////////////////////////////////////////////////////////
144/// Graph normal constructor with ints.
145
147 : TNamed("Graph", "Graph"), TAttFill(0, 1000)
148{
149 if (!x || !y) {
150 fNpoints = 0;
151 } else {
152 fNpoints = n;
153 }
154 if (!CtorAllocate()) return;
155 for (Int_t i = 0; i < n; i++) {
156 fX[i] = (Double_t)x[i];
157 fY[i] = (Double_t)y[i];
158 }
159}
160
161////////////////////////////////////////////////////////////////////////////////
162/// Graph normal constructor with floats.
163
165 : TNamed("Graph", "Graph"), TAttFill(0, 1000)
166{
167 if (!x || !y) {
168 fNpoints = 0;
169 } else {
170 fNpoints = n;
171 }
172 if (!CtorAllocate()) return;
173 for (Int_t i = 0; i < n; i++) {
174 fX[i] = x[i];
175 fY[i] = y[i];
176 }
177}
178
179////////////////////////////////////////////////////////////////////////////////
180/// Default X-Points constructor. The points along the x-axis get the default
181/// values `start`, `start+step`, `start+2*step`, `start+3*step`, etc ...
182
184 : TNamed("Graph", "Graph"), TAttFill(0, 1000)
185{
186 if (!y) {
187 fNpoints = 0;
188 } else {
189 fNpoints = n;
190 }
191 if (!CtorAllocate()) return;
192 for (Int_t i = 0; i < n; i++) {
193 fX[i] = start+i*step;
194 fY[i] = y[i];
195 }
196}
197
198////////////////////////////////////////////////////////////////////////////////
199/// Graph normal constructor with doubles.
200
202 : TNamed("Graph", "Graph"), TAttFill(0, 1000)
203{
204 if (!x || !y) {
205 fNpoints = 0;
206 } else {
207 fNpoints = n;
208 }
209 if (!CtorAllocate()) return;
210 n = fNpoints * sizeof(Double_t);
211 memcpy(fX, x, n);
212 memcpy(fY, y, n);
213}
214
215////////////////////////////////////////////////////////////////////////////////
216/// Copy constructor for this graph
217
220{
224 else fFunctions = new TList;
225 if (gr.fHistogram) {
227 fHistogram->SetDirectory(nullptr);
228 } else {
229 fHistogram = nullptr;
230 }
233 if (!fMaxSize) {
234 fX = fY = nullptr;
235 return;
236 } else {
237 fX = new Double_t[fMaxSize];
238 fY = new Double_t[fMaxSize];
239 }
240
241 Int_t n = gr.GetN() * sizeof(Double_t);
242 memcpy(fX, gr.fX, n);
243 memcpy(fY, gr.fY, n);
244}
245
246////////////////////////////////////////////////////////////////////////////////
247/// Equal operator for this graph
248
250{
251 if (this != &gr) {
253 TAttLine::operator=(gr);
254 TAttFill::operator=(gr);
255 TAttMarker::operator=(gr);
256
259
260 // delete list of functions and their contents before copying it
261 if (fFunctions) {
262 // delete previous lists of functions
263 if (!fFunctions->IsEmpty()) {
265 // use TList::Remove to take into account the case the same object is
266 // added multiple times in the list
267 TObject *obj;
268 while ((obj = fFunctions->First())) {
269 while (fFunctions->Remove(obj)) { }
270 delete obj;
271 }
272 }
273 delete fFunctions;
274 }
275
277 else fFunctions = new TList;
278
279 if (fHistogram) delete fHistogram;
280 if (gr.fHistogram) {
281 fHistogram = new TH1F(*(gr.fHistogram));
282 fHistogram->SetDirectory(nullptr);
283 } else {
284 fHistogram = nullptr;
285 }
286
289 if (fX) delete [] fX;
290 if (fY) delete [] fY;
291 if (!fMaxSize) {
292 fX = fY = nullptr;
293 return *this;
294 } else {
295 fX = new Double_t[fMaxSize];
296 fY = new Double_t[fMaxSize];
297 }
298
299 Int_t n = gr.GetN() * sizeof(Double_t);
300 if (n > 0) {
301 memcpy(fX, gr.fX, n);
302 memcpy(fY, gr.fY, n);
303 }
304 }
305 return *this;
306}
307
308////////////////////////////////////////////////////////////////////////////////
309/// Graph constructor with two vectors of floats in input
310/// A graph is build with the X coordinates taken from vx and Y coord from vy
311/// The number of points in the graph is the minimum of number of points
312/// in vx and vy.
313
315 : TNamed("Graph", "Graph"), TAttFill(0, 1000)
316{
317 fNpoints = TMath::Min(vx.GetNrows(), vy.GetNrows());
318 if (!CtorAllocate()) return;
319 Int_t ivxlow = vx.GetLwb();
320 Int_t ivylow = vy.GetLwb();
321 for (Int_t i = 0; i < fNpoints; i++) {
322 fX[i] = vx(i + ivxlow);
323 fY[i] = vy(i + ivylow);
324 }
325}
326
327////////////////////////////////////////////////////////////////////////////////
328/// Graph constructor with two vectors of doubles in input
329/// A graph is build with the X coordinates taken from vx and Y coord from vy
330/// The number of points in the graph is the minimum of number of points
331/// in vx and vy.
332
334 : TNamed("Graph", "Graph"), TAttFill(0, 1000)
335{
336 fNpoints = TMath::Min(vx.GetNrows(), vy.GetNrows());
337 if (!CtorAllocate()) return;
338 Int_t ivxlow = vx.GetLwb();
339 Int_t ivylow = vy.GetLwb();
340 for (Int_t i = 0; i < fNpoints; i++) {
341 fX[i] = vx(i + ivxlow);
342 fY[i] = vy(i + ivylow);
343 }
344}
345
346////////////////////////////////////////////////////////////////////////////////
347/// Graph constructor importing its parameters from the TH1 object passed as argument
348
350 : TNamed("Graph", "Graph"), TAttFill(0, 1000)
351{
352 if (!h) {
353 Error("TGraph", "Pointer to histogram is null");
354 fNpoints = 0;
355 return;
356 }
357 if (h->GetDimension() != 1) {
358 Error("TGraph", "Histogram must be 1-D; h %s is %d-D", h->GetName(), h->GetDimension());
359 fNpoints = 0;
360 } else {
361 fNpoints = h->GetXaxis()->GetNbins();
362 }
363
364 if (!CtorAllocate())
365 return;
366
367 auto xaxis = h->GetXaxis();
368 for (Int_t i = 0; i < fNpoints; i++) {
369 fX[i] = xaxis->GetBinCenter(i + 1);
370 fY[i] = h->GetBinContent(i + 1);
371 }
372 h->TAttLine::Copy(*this);
373 h->TAttFill::Copy(*this);
374 h->TAttMarker::Copy(*this);
375
376 std::string gname = "Graph_from_" + std::string(h->GetName());
377 SetName(gname.c_str());
378 SetTitle(h->GetTitle());
379}
380
381////////////////////////////////////////////////////////////////////////////////
382/// Graph constructor importing its parameters from the TF1 object passed as argument
383/// - if option =="" (default), a TGraph is created with points computed
384/// at the fNpx points of f.
385/// - if option =="d", a TGraph is created with points computed with the derivatives
386/// at the fNpx points of f.
387/// - if option =="i", a TGraph is created with points computed with the integral
388/// at the fNpx points of f.
389/// - if option =="I", a TGraph is created with points computed with the integral
390/// at the fNpx+1 points of f and the integral is normalized to 1.
391
393 : TNamed("Graph", "Graph"), TAttFill(0, 1000)
394{
395 char coption = ' ';
396 if (!f) {
397 Error("TGraph", "Pointer to function is null");
398 fNpoints = 0;
399 } else {
400 fNpoints = f->GetNpx();
401 if (option) coption = *option;
402 if (coption == 'i' || coption == 'I') fNpoints++;
403 }
404 if (!CtorAllocate()) return;
405
406 Double_t xmin = f->GetXmin();
407 Double_t xmax = f->GetXmax();
408 Double_t dx = (xmax - xmin) / fNpoints;
409 Double_t integ = 0;
410 Int_t i;
411 for (i = 0; i < fNpoints; i++) {
412 if (coption == 'i' || coption == 'I') {
413 fX[i] = xmin + i * dx;
414 if (i == 0) fY[i] = 0;
415 else fY[i] = integ + ((TF1*)f)->Integral(fX[i] - dx, fX[i]);
416 integ = fY[i];
417 } else if (coption == 'd' || coption == 'D') {
418 fX[i] = xmin + (i + 0.5) * dx;
419 fY[i] = ((TF1*)f)->Derivative(fX[i]);
420 } else {
421 fX[i] = xmin + (i + 0.5) * dx;
422 fY[i] = ((TF1*)f)->Eval(fX[i]);
423 }
424 }
425 if (integ != 0 && coption == 'I') {
426 for (i = 1; i < fNpoints; i++) fY[i] /= integ;
427 }
428
429 f->TAttLine::Copy(*this);
430 f->TAttFill::Copy(*this);
431 f->TAttMarker::Copy(*this);
432
433 SetName(f->GetName());
434 SetTitle(f->GetTitle());
435}
436
437////////////////////////////////////////////////////////////////////////////////
438/// Graph constructor reading input from filename.
439///
440/// `filename` is assumed to contain at least two columns of numbers.
441/// The string format is by default `"%lg %lg"`.
442/// This is a standard c formatting for `scanf()`.
443/// For example, set format to `"%lg,%lg"` for a comma-separated file.
444/// If format string is empty, suitable value will be provided based on file extension
445///
446/// If columns of numbers should be skipped, a `"%*lg"` or `"%*s"` for each column
447/// can be added, e.g. `"%lg %*lg %lg"` would read x-values from the first and
448/// y-values from the third column.
449///
450/// For files separated by a specific delimiter different from ' ' and '\\t' (e.g.
451/// ';' in csv files) you can avoid using `%*s` to bypass this delimiter by explicitly
452/// specify the `option` argument,
453/// e.g. option=`" \\t,;"` for columns of figures separated by any of these characters
454/// (' ', '\\t', ',', ';')
455/// used once (e.g. `"1;1"`) or in a combined way (`" 1;,;; 1"`).
456/// Note in that case, the instantiation is about two times slower.
457
458TGraph::TGraph(const char *filename, const char *format, Option_t *option)
459 : TNamed("Graph", filename), TAttFill(0, 1000)
460{
461 Double_t x, y;
464
465 std::ifstream infile(fname.Data());
466 if (!infile.good()) {
467 MakeZombie();
468 Error("TGraph", "Cannot open file: %s, TGraph is Zombie", filename);
469 fNpoints = 0;
470 return;
471 } else {
472 fNpoints = 100; //initial number of points
473 }
474 if (!CtorAllocate()) return;
475 std::string line;
476 Int_t np = 0;
477
479
480 if (!option || !*option) { // No delimiters specified (standard constructor).
481 // is empty format string specified - try to guess format from the file extension
482 if (format_.IsNull()) {
483 if (fname.EndsWith(".txt", TString::kIgnoreCase))
484 format_ = "%lg %lg";
485 else if (fname.EndsWith(".tsv", TString::kIgnoreCase))
486 format_ = "%lg\t%lg";
487 else
488 format_ = "%lg,%lg";
489 }
490
491 while (std::getline(infile, line, '\n')) {
492 if (2 != sscanf(line.c_str(), format_.Data(), &x, &y)) {
493 continue; //skip empty and ill-formed lines
494 }
495 SetPoint(np, x, y);
496 np++;
497 }
498 Set(np);
499
500 // A delimiter has been specified in "option"
501 } else {
502
503 // Checking format and creating its boolean counterpart
504 format_.ReplaceAll(" ", "") ;
505 format_.ReplaceAll("\t", "") ;
506 format_.ReplaceAll("lg", "") ;
507 format_.ReplaceAll("s", "") ;
508 format_.ReplaceAll("%*", "0") ;
509 format_.ReplaceAll("%", "1") ;
510 if (!format_.IsDigit()) {
511 Error("TGraph", "Incorrect input format! Allowed formats are {\"%%lg\",\"%%*lg\" or \"%%*s\"}");
512 return;
513 }
514 Int_t ntokens = format_.Length() ;
515 if (ntokens < 2) {
516 Error("TGraph", "Incorrect input format! Only %d tag(s) in format whereas 2 \"%%lg\" tags are expected!", ntokens);
517 return;
518 }
521 for (Int_t idx = 0; idx < ntokens; idx++) {
522 isTokenToBeSaved[idx] = TString::Format("%c", format_[idx]).Atoi() ; //atoi(&format_[idx]) does not work for some reason...
523 if (isTokenToBeSaved[idx] == 1) {
525 }
526 }
527 if (ntokens >= 2 && ntokensToBeSaved != 2) { //first condition not to repeat the previous error message
528 Error("TGraph", "Incorrect input format! There are %d \"%%lg\" tag(s) in format whereas 2 and only 2 are expected!", ntokensToBeSaved);
529 delete [] isTokenToBeSaved ;
530 return;
531 }
532
533 // Initializing loop variables
534 Bool_t isLineToBeSkipped = kFALSE ; //empty and ill-formed lines
535 char * token = nullptr ;
536 TString token_str = "" ;
537 Int_t token_idx = 0 ;
538 Double_t * value = new Double_t [2] ; //x,y buffers
539 Int_t value_idx = 0 ;
540
541 // Looping
542 char *rest;
543 while (std::getline(infile, line, '\n')) {
544 if (!line.empty()) {
545 if (line[line.size() - 1] == char(13)) { // removing DOS CR character
546 line.erase(line.end() - 1, line.end()) ;
547 }
548 //token = R__STRTOK_R(const_cast<char *>(line.c_str()), option, rest);
549 token = R__STRTOK_R(const_cast<char *>(line.c_str()), option, &rest);
550 while (token != nullptr && value_idx < 2) {
552 token_str = TString(token) ;
553 token_str.ReplaceAll("\t", "") ;
554 if (!token_str.IsFloat()) {
556 break ;
557 } else {
558 value[value_idx] = token_str.Atof() ;
559 value_idx++ ;
560 }
561 }
562 token = R__STRTOK_R(nullptr, option, &rest); // next token
563 token_idx++ ;
564 }
565 if (!isLineToBeSkipped && value_idx == 2) {
566 x = value[0] ;
567 y = value[1] ;
568 SetPoint(np, x, y) ;
569 np++ ;
570 }
571 }
573 token = nullptr ;
574 token_idx = 0 ;
575 value_idx = 0 ;
576 }
577 Set(np) ;
578
579 // Cleaning
580 delete [] isTokenToBeSaved ;
581 delete [] value ;
582 delete token ;
583 }
584 infile.close();
585 if (fNpoints == 0) {
586 Warning("TGraph", "No points were found in file %s with the specified input format %s", filename, format);
587 return;
588 }
589}
590
591////////////////////////////////////////////////////////////////////////////////
592/// Graph default destructor.
593
595{
596 delete [] fX;
597 delete [] fY;
598 if (fFunctions) {
600 //special logic to support the case where the same object is
601 //added multiple times in fFunctions.
602 //This case happens when the same object is added with different
603 //drawing modes
604 TObject *obj;
605 while ((obj = fFunctions->First())) {
606 while (fFunctions->Remove(obj)) { }
607 delete obj;
608 }
609 delete fFunctions;
610 fFunctions = nullptr; //to avoid accessing a deleted object in RecursiveRemove
611 }
612 delete fHistogram;
613}
614
615////////////////////////////////////////////////////////////////////////////////
616/// Allocate internal data structures for `newsize` points.
617
622
623////////////////////////////////////////////////////////////////////////////////
624/// Allocate arrays.
625
627{
628 if (arraySize < 0) {
629 arraySize = 0;
630 }
632 if (!arraySize) {
633 for (Int_t i = 0; i < Narrays; ++i)
634 newarrays[i] = nullptr;
635 } else {
636 for (Int_t i = 0; i < Narrays; ++i)
637 newarrays[i] = new Double_t[arraySize];
638 }
639 fMaxSize = arraySize;
640 return newarrays;
641}
642
643////////////////////////////////////////////////////////////////////////////////
644/// Performs the operation: `y = y + c1*f(x,y)`
645/// Errors are not recalculated.
646///
647/// \param f may be a 1-D function TF1 or 2-d function TF2
648/// \param c1 a scaling factor, 1 by default
649
651{
653
654 for (Int_t i = 0; i < fNpoints; i++) {
655 fY[i] += c1*f->Eval(fX[i], fY[i]);
656 }
657 if (gPad) gPad->Modified();
658}
659
660////////////////////////////////////////////////////////////////////////////////
661/// Apply function f to all the data points
662/// f may be a 1-D function TF1 or 2-d function TF2
663/// The Y values of the graph are replaced by the new values computed
664/// using the function
665
667{
669
670 for (Int_t i = 0; i < fNpoints; i++) {
671 fY[i] = f->Eval(fX[i], fY[i]);
672 }
673 if (gPad) gPad->Modified();
674}
675
676////////////////////////////////////////////////////////////////////////////////
677/// Browse
678
680{
681 TString opt = gEnv->GetValue("TGraph.BrowseOption", "");
682 if (opt.IsNull()) {
683 opt = b ? b->GetDrawOption() : "alp";
684 opt = (opt == "") ? "alp" : opt.Data();
685 }
686 Draw(opt.Data());
687 gPad->Update();
688}
689
690////////////////////////////////////////////////////////////////////////////////
691/// Return the chisquare of this graph with respect to f1.
692/// The chisquare is computed as the sum of the quantity below at each point:
693/// \f[
694/// \frac{(y-f1(x))^{2}}{ey^{2}+(\frac{1}{2}(exl+exh)f1'(x))^{2}}
695/// \f]
696/// where x and y are the graph point coordinates and f1'(x) is the derivative of function f1(x).
697/// This method to approximate the uncertainty in y because of the errors in x, is called
698/// "effective variance" method.
699/// In case of a pure TGraph, the denominator is 1.
700/// In case of a TGraphErrors or TGraphAsymmErrors the errors are taken
701/// into account.
702/// By default the range of the graph is used whatever function range.
703/// Use option "R" to use the function range
704
706{
707 if (!func) {
708 Error("Chisquare","Function pointer is Null - return -1");
709 return -1;
710 }
711
712 TString opt(option); opt.ToUpper();
713 bool useRange = opt.Contains("R");
714
715 return ROOT::Fit::Chisquare(*this, *func,useRange);
716}
717
718////////////////////////////////////////////////////////////////////////////////
719/// Return kTRUE if point number "left"'s argument (angle with respect to positive
720/// x-axis) is bigger than that of point number "right". Can be used by Sort.
721
723{
724 Double_t xl = 0, yl = 0, xr = 0, yr = 0;
725 gr->GetPoint(left, xl, yl);
726 gr->GetPoint(right, xr, yr);
727 return (TMath::ATan2(yl, xl) > TMath::ATan2(yr, xr));
728}
729
730////////////////////////////////////////////////////////////////////////////////
731/// Return kTRUE if fX[left] > fX[right]. Can be used by Sort.
732
734{
735 return gr->fX[left] > gr->fX[right];
736}
737
738////////////////////////////////////////////////////////////////////////////////
739/// Return kTRUE if fY[left] > fY[right]. Can be used by Sort.
740
742{
743 return gr->fY[left] > gr->fY[right];
744}
745
746////////////////////////////////////////////////////////////////////////////////
747/// Return kTRUE if point number "left"'s distance to origin is bigger than
748/// that of point number "right". Can be used by Sort.
749
751{
752 return gr->fX[left] * gr->fX[left] + gr->fY[left] * gr->fY[left]
753 > gr->fX[right] * gr->fX[right] + gr->fY[right] * gr->fY[right];
754}
755
756////////////////////////////////////////////////////////////////////////////////
757/// Compute the x/y range of the points in this graph
758
760{
761 if (fNpoints <= 0) {
762 xmin = xmax = ymin = ymax = 0;
763 return;
764 }
765 xmin = xmax = fX[0];
766 ymin = ymax = fY[0];
767
768 Double_t xminl = 0; // Positive minimum. Used in case of log scale along X axis.
769 Double_t yminl = 0; // Positive minimum. Used in case of log scale along Y axis.
770
771 for (Int_t i = 1; i < fNpoints; i++) {
772 if (fX[i] < xmin) xmin = fX[i];
773 if (fX[i] > xmax) xmax = fX[i];
774 if (fY[i] < ymin) ymin = fY[i];
775 if (fY[i] > ymax) ymax = fY[i];
776 if (ymin>0 && (yminl==0 || ymin<yminl)) yminl = ymin;
777 if (xmin>0 && (xminl==0 || xmin<xminl)) xminl = xmin;
778 }
779
780 if (gPad && gPad->GetLogy() && yminl>0) ymin = yminl;
781 if (gPad && gPad->GetLogx() && xminl>0) xmin = xminl;
782}
783
784////////////////////////////////////////////////////////////////////////////////
785/// Copy points from fX and fY to arrays[0] and arrays[1]
786/// or to fX and fY if arrays == 0 and ibegin != iend.
787/// If newarrays is non null, replace fX, fY with pointers from newarrays[0,1].
788/// Delete newarrays, old fX and fY
789
792{
794 if (newarrays) {
795 delete[] fX;
796 fX = newarrays[0];
797 delete[] fY;
798 fY = newarrays[1];
799 delete[] newarrays;
800 }
801}
802
803////////////////////////////////////////////////////////////////////////////////
804/// Copy points from fX and fY to arrays[0] and arrays[1]
805/// or to fX and fY if arrays == 0 and ibegin != iend.
806
809{
810 if (ibegin < 0 || iend <= ibegin || obegin < 0) { // Error;
811 return kFALSE;
812 }
813 if (!arrays && ibegin == obegin) { // No copying is needed
814 return kFALSE;
815 }
816 Int_t n = (iend - ibegin) * sizeof(Double_t);
817 if (arrays) {
818 memmove(&arrays[0][obegin], &fX[ibegin], n);
819 memmove(&arrays[1][obegin], &fY[ibegin], n);
820 } else {
821 memmove(&fX[obegin], &fX[ibegin], n);
822 memmove(&fY[obegin], &fY[ibegin], n);
823 }
824 return kTRUE;
825}
826
827////////////////////////////////////////////////////////////////////////////////
828/// In constructors set fNpoints than call this method.
829/// Return kFALSE if the graph will contain no points.
830///Note: This function should be called only from the constructor
831/// since it does not delete previously existing arrays
832
834{
835 fHistogram = nullptr;
836 fMaximum = -1111;
837 fMinimum = -1111;
839 fFunctions = new TList;
840 if (fNpoints <= 0) {
841 fNpoints = 0;
842 fMaxSize = 0;
843 fX = nullptr;
844 fY = nullptr;
845 return kFALSE;
846 } else {
848 fX = new Double_t[fMaxSize];
849 fY = new Double_t[fMaxSize];
850 }
851 return kTRUE;
852}
853
854////////////////////////////////////////////////////////////////////////////////
855/// Draw this graph with its current attributes.
856///
857/// The options to draw a graph are described in TGraphPainter class.
858
860{
861 TString opt = option;
862 opt.ToLower();
863
864 if (opt.Contains("same")) {
865 opt.ReplaceAll("same", "");
866 }
867
868 // in case of option *, set marker style to 3 (star) and replace
869 // * option by option P.
870 Ssiz_t pos;
871 if ((pos = opt.Index("*")) != kNPOS) {
873 opt.Replace(pos, 1, "p");
874 }
875
876 // If no option is specified, it is defined as "alp" in case there is
877 // no current pad or if the current pad has no axis defined and if there is
878 // no default option set using TGraph::SetOption. If fOption is set using
879 // TGraph::SetOption, it is used as default option.
880 if ((!option || !strlen(option))) {
881 Option_t *topt = (!fOption.IsNull()) ? fOption.Data() : "alp";
882 if (gPad) {
883 if (!gPad->GetListOfPrimitives()->FindObject("TFrame"))
884 opt = topt;
885 } else {
886 opt = topt;
887 }
888 }
889
890 if (gPad) {
891 if (!gPad->IsEditable()) gROOT->MakeDefCanvas();
892 if (opt.Contains("a")) gPad->Clear();
893 }
894
895 AppendPad(opt);
896
897 gPad->IncrementPaletteColor(1, opt);
898
899}
900
901////////////////////////////////////////////////////////////////////////////////
902/// Compute distance from point px,py to a graph.
903///
904/// Compute the closest distance of approach from point px,py to this line.
905/// The distance is computed in pixels units.
906
908{
910 if (painter) return painter->DistancetoPrimitiveHelper(this, px, py);
911 else return 0;
912}
913
914////////////////////////////////////////////////////////////////////////////////
915/// Draw this graph with new attributes.
916
918{
919 TGraph *newgraph = new TGraph(n, x, y);
923 newgraph->SetBit(kCanDelete);
924 newgraph->AppendPad(option);
925}
926
927////////////////////////////////////////////////////////////////////////////////
928/// Draw this graph with new attributes.
929
931{
932 TGraph *newgraph = new TGraph(n, x, y);
936 newgraph->SetBit(kCanDelete);
937 newgraph->AppendPad(option);
938}
939
940////////////////////////////////////////////////////////////////////////////////
941/// Draw this graph with new attributes.
942
944{
945 const Double_t *xx = x;
946 const Double_t *yy = y;
947 if (!xx) xx = fX;
948 if (!yy) yy = fY;
949 TGraph *newgraph = new TGraph(n, xx, yy);
953 newgraph->SetBit(kCanDelete);
954 newgraph->AppendPad(option);
955}
956
957////////////////////////////////////////////////////////////////////////////////
958/// Display a panel with all graph drawing options.
959
961{
963 if (painter) painter->DrawPanelHelper(this);
964}
965
966////////////////////////////////////////////////////////////////////////////////
967/// Interpolate points in this graph at x using a TSpline.
968///
969/// - if spline==0 and option="" a linear interpolation between the two points
970/// close to x is computed. If x is outside the graph range, a linear
971/// extrapolation is computed.
972/// - if spline==0 and option="S" a TSpline3 object is created using this graph
973/// and the interpolated value from the spline is returned.
974/// the internally created spline is deleted on return.
975/// - if spline is specified, it is used to return the interpolated value.
976///
977/// If the points are sorted in X a binary search is used (significantly faster)
978/// One needs to set the bit TGraph::SetBit(TGraph::kIsSortedX) before calling
979/// TGraph::Eval to indicate that the graph is sorted in X.
980
982{
983
984 if (spline) {
985 //spline interpolation using the input spline
986 return spline->Eval(x);
987 }
988
989 if (fNpoints == 0) return 0;
990 if (fNpoints == 1) return fY[0];
991
992 if (option && *option) {
993 TString opt = option;
994 opt.ToLower();
995 // create a TSpline every time when using option "s" and no spline pointer is given
996 if (opt.Contains("s")) {
997
998 // points must be sorted before using a TSpline
999 std::vector<Double_t> xsort(fNpoints);
1000 std::vector<Double_t> ysort(fNpoints);
1001 std::vector<Int_t> indxsort(fNpoints);
1002 TMath::Sort(fNpoints, fX, &indxsort[0], false);
1003 for (Int_t i = 0; i < fNpoints; ++i) {
1004 xsort[i] = fX[ indxsort[i] ];
1005 ysort[i] = fY[ indxsort[i] ];
1006 }
1007
1008 // spline interpolation creating a new spline
1009 TSpline3 s("", &xsort[0], &ysort[0], fNpoints);
1010 Double_t result = s.Eval(x);
1011 return result;
1012 }
1013 }
1014 //linear interpolation
1015 //In case x is < fX[0] or > fX[fNpoints-1] return the extrapolated point
1016
1017 //find points in graph around x assuming points are not sorted
1018 // (if point are sorted use a binary search)
1019 Int_t low = -1;
1020 Int_t up = -1;
1023 if (low == -1) {
1024 // use first two points for doing an extrapolation
1025 low = 0;
1026 }
1027 if (fX[low] == x) return fY[low];
1028 if (low == fNpoints-1) low--; // for extrapolating
1029 up = low+1;
1030 }
1031 else {
1032 // case TGraph is not sorted
1033
1034 // find neighbours simply looping all points
1035 // and find also the 2 adjacent points: (low2 < low < x < up < up2 )
1036 // needed in case x is outside the graph ascissa interval
1037 Int_t low2 = -1;
1038 Int_t up2 = -1;
1039
1040 for (Int_t i = 0; i < fNpoints; ++i) {
1041 if (fX[i] < x) {
1042 if (low == -1 || fX[i] > fX[low]) {
1043 low2 = low;
1044 low = i;
1045 } else if (low2 == -1) low2 = i;
1046 } else if (fX[i] > x) {
1047 if (up == -1 || fX[i] < fX[up]) {
1048 up2 = up;
1049 up = i;
1050 } else if (up2 == -1) up2 = i;
1051 } else // case x == fX[i]
1052 return fY[i]; // no interpolation needed
1053 }
1054
1055 // treat cases when x is outside graph min max abscissa
1056 if (up == -1) {
1057 up = low;
1058 low = low2;
1059 }
1060 if (low == -1) {
1061 low = up;
1062 up = up2;
1063 }
1064 }
1065 // do now the linear interpolation
1066 assert(low != -1 && up != -1);
1067
1068 if (fX[low] == fX[up]) return fY[low];
1069 Double_t yn = fY[up] + (x - fX[up]) * (fY[low] - fY[up]) / (fX[low] - fX[up]);
1070 return yn;
1071}
1072
1073////////////////////////////////////////////////////////////////////////////////
1074/// Execute action corresponding to one event.
1075///
1076/// This member function is called when a graph is clicked with the locator
1077///
1078/// If Left button clicked on one of the line end points, this point
1079/// follows the cursor until button is released.
1080///
1081/// if Middle button clicked, the line is moved parallel to itself
1082/// until the button is released.
1083
1085{
1087 if (painter) painter->ExecuteEventHelper(this, event, px, py);
1088}
1089
1090////////////////////////////////////////////////////////////////////////////////
1091/// If array sizes <= newsize, expand storage to 2*newsize.
1092
1094{
1096 CopyAndRelease(ps, 0, 0, 0);
1097}
1098
1099////////////////////////////////////////////////////////////////////////////////
1100/// If graph capacity is less than newsize points then make array sizes
1101/// equal to least multiple of step to contain newsize points.
1102
1104{
1105 if (newsize <= fMaxSize) {
1106 return;
1107 }
1108 Double_t **ps = Allocate(step * (newsize / step + (newsize % step ? 1 : 0)));
1109 CopyAndRelease(ps, 0, fNpoints, 0);
1110}
1111
1112////////////////////////////////////////////////////////////////////////////////
1113/// if size > fMaxSize allocate new arrays of 2*size points and copy iend first
1114/// points.
1115/// Return pointer to new arrays.
1116
1118{
1119 if (size <= fMaxSize)
1120 return nullptr;
1122 CopyPoints(newarrays, 0, iend, 0);
1123 return newarrays;
1124}
1125
1126////////////////////////////////////////////////////////////////////////////////
1127/// Set zero values for point arrays in the range [begin, end)
1128/// Should be redefined in descendant classes
1129
1131{
1132 memset(fX + begin, 0, (end - begin)*sizeof(Double_t));
1133 memset(fY + begin, 0, (end - begin)*sizeof(Double_t));
1134}
1135
1136////////////////////////////////////////////////////////////////////////////////
1137/// Search object named name in the list of functions
1138
1140{
1141 return fFunctions ? fFunctions->FindObject(name) : nullptr;
1142}
1143
1144////////////////////////////////////////////////////////////////////////////////
1145/// Search object obj in the list of functions
1146
1148{
1149 return fFunctions ? fFunctions->FindObject(obj) : nullptr;
1150}
1151
1152////////////////////////////////////////////////////////////////////////////////
1153/// Fit this graph with function f1.
1154///
1155/// \param[in] f1 pointer to the function object
1156/// \param[in] option string defining the fit options (see table below).
1157/// \param[in] goption specify a list of graphics options. See TGraph::Draw and TGraphPainter for a complete list of these possible options.
1158/// \param[in] rxmin lower fitting range
1159/// \param[in] rxmax upper fitting range
1160///
1161/// \anchor GFitOpt
1162/// ### Graph Fitting Options
1163/// The list of fit options is given in parameter option.
1164///
1165/// option | description
1166/// -------|------------
1167/// "S" | The full result of the fit is returned in the `TFitResultPtr`. This is needed to get the covariance matrix of the fit. See `TFitResult` and the base class `ROOT::Math::FitResult`.
1168/// "W" | Ignore all point errors when fitting a TGraphErrors or TGraphAsymmErrors
1169/// "F" | Uses the default minimizer (e.g. Minuit) when fitting a linear function (e.g. polN) instead of the linear fitter.
1170/// "U" | Uses a user specified objective function (e.g. user providedlikelihood function) defined using `TVirtualFitter::SetFCN`
1171/// "E" | Performs a better parameter errors estimation using the Minos technique for all fit parameters.
1172/// "M" | Uses the IMPROVE algorithm (available only in TMinuit). This algorithm attempts improve the found local minimum by searching for a better one.
1173/// "Q" | Quiet mode (minimum printing)
1174/// "V" | Verbose mode (default is between Q and V)
1175/// "+" | Adds this new fitted function to the list of fitted functions. By default, the previous function is deleted and only the last one is kept.
1176/// "N" | Does not store the graphics function, does not draw the histogram with the function after fitting.
1177/// "0" | Does not draw the histogram and the fitted function after fitting, but in contrast to option "N", it stores the fitted function in the histogram list of functions.
1178/// "R" | Fit using a fitting range specified in the function range with `TF1::SetRange`.
1179/// "B" | Use this option when you want to fix one or more parameters and the fitting function is a predefined one (e.g gaus, expo,..), otherwise in case of pre-defined functions, some default initial values and limits are set.
1180/// "C" | In case of linear fitting, do no calculate the chisquare (saves CPU time).
1181/// "G" | Uses the gradient implemented in `TF1::GradientPar` for the minimization. This allows to use Automatic Differentiation when it is supported by the provided TF1 function.
1182/// "EX0" | When fitting a TGraphErrors or TGraphAsymErrors do not consider errors in the X coordinates
1183/// "ROB" | In case of linear fitting, compute the LTS regression coefficients (robust (resistant) regression), using the default fraction of good points "ROB=0.x" - compute the LTS regression coefficients, using 0.x as a fraction of good points
1184/// "SERIAL" | Runs in serial mode. By default, if ROOT is built with MT support and MT is enabled, the fit is performed in multi-thread.
1185/// "MULTITHREAD" | Forces usage of multi-thread execution whenever possible.
1186///
1187///
1188/// This function is used for fitting also the derived TGraph classes such as TGraphErrors or TGraphAsymmErrors.
1189/// See the note below on how the errors are used when fitting a TGraphErrors or TGraphAsymmErrors.
1190///
1191/// The fitting of the TGraph, i.e simple data points without any error associated, is performed using the
1192/// un-weighted least-square (chi-square) method.
1193///
1194///
1195///\anchor GFitErrors
1196/// ### TGraphErrors fit:
1197///
1198/// In case of a TGraphErrors or TGraphAsymmErrors object, when `x` errors are present, the error along x,
1199/// is projected along the y-direction by calculating the function at the points `x-ex_low` and
1200/// `x+ex_high`, where `ex_low` and `ex_high` are the corresponding lower and upper error in x.
1201/// The chi-square is then computed as the sum of the quantity below at each data point:
1202///
1203/// \f[
1204/// \frac{(y-f(x))^{2}}{ey^{2}+(\frac{1}{2}(exl+exh)f'(x))^{2}}
1205/// \f]
1206///
1207/// where `x` and `y` are the point coordinates, and `f'(x)` is the derivative of the
1208/// function `f(x)`.
1209///
1210/// In case of asymmetric errors, if the function lies below (above) the data point, `ey` is `ey_low` (`ey_high`).
1211///
1212/// The approach used to approximate the uncertainty in y because of the
1213/// errors in x is to make it equal the error in x times the slope of the line.
1214/// This approach is called "effective variance method" and
1215/// the implementation is provided in the function FitUtil::EvaluateChi2Effective
1216///
1217/// \anchor GFitLinear
1218/// ### Linear fitting:
1219/// When the fitting function is linear (contains the `++` sign) or the fitting
1220/// function is a polynomial, a linear fitter is initialised.
1221/// To create a linear function, use the following syntax: linear parts
1222/// separated by `++` sign.
1223/// Example: to fit the parameters of the function `p0*x + p1*sin(x)`, you can create a
1224/// TF1 object as
1225///
1226/// TF1 *f1 = new TF1("f1", "x++sin(x)", xmin, xmax);
1227///
1228/// For such a TF1 you don't have to set the initial conditions and the linear fitter is used.
1229/// Going via the linear fitter for functions, linear in parameters, gives a
1230/// considerable advantage in speed.
1231/// When using the linear fitting it is also possible to perform a robust fitting with the
1232/// Least Trimmed Square (LTS) regression algorithm, by using the fit option `ROB`.
1233/// See the tutorial `fitLinearRobust.C`.
1234///
1235/// ### Notes on TGraph/TGraphErrors Fitting:
1236///
1237/// 1. By using the "effective variance" method a simple linear regression
1238/// becomes a non-linear case, which takes several iterations
1239/// instead of 0 as in the linear case.
1240/// 2. The effective variance technique assumes that there is no correlation
1241/// between the x and y coordinate.
1242/// 3. The standard chi2 (least square) method without error in the coordinates (x) can
1243/// be forced by using option "EX0"
1244/// 4. The linear fitter doesn't take into account the errors in x. When fitting a
1245/// TGraphErrors with a linear functions the errors in x will not be considered.
1246/// If errors in x are important, use option "F" for linear function fitting.
1247/// 5. When fitting a TGraph (i.e. no errors associated with each point),
1248/// a correction is applied to the errors on the parameters with the following
1249/// formula:
1250/// `parameter_error *= sqrt(chisquare/(ndf-1))`
1251///
1252/// ### General Fitting documentation
1253///
1254/// See in TH1::Fit for the documentation of
1255/// - [Fit Result](\ref HFitRes)
1256/// - [Fit Status](\ref HFitStatus)
1257/// - [Fit Statistics Box](\ref HFitStatBox)
1258/// - [Fitting in a Range](\ref HFitRange)
1259/// - [Setting Initial Conditions](\ref HFitInitial)
1260
1270
1271////////////////////////////////////////////////////////////////////////////////
1272/// Fit this graph with the global function named `fname`.
1273///
1274/// This will retrieve the function with name `fname` from ROOT's global list of functions, and use it to
1275/// fit the data in the TGraph.
1276/// TF1 or TF2 functions that have been created in the same ROOT session can be accessed using `fname`.
1277/// Predefined functions such as gaus, expo, poln, etc. are automatically created by ROOT.
1278/// @see TF1::InitStandardFunctions, TF2::InitStandardFunctions, TF3::InitStandardFunctions
1279///
1280/// Note that using a global function is not thread safe. In this case, use the overload
1281/// TGraph::Fit(TF1 *f1,Option_t *, Option_t *, Axis_t, Axis_t) with a locally created function.
1282/// For more details about fitting a TGraph, see the same overload.
1283///
1284/// The parameter `fname` can also be a formula, accepted by the linear fitter (linear parts divided
1285/// by "++" sign), for example "x++sin(x)" for fitting "[0]*x+[1]*sin(x)"
1286
1288{
1289 const char *linear = fname ? strstr(fname, "++") : nullptr;
1290 if (linear) {
1291 TF1 f1(fname, fname, xmin, xmax);
1292 return Fit(&f1, option, "", xmin, xmax);
1293 }
1294 TF1 * f1 = (TF1*)gROOT->GetFunction(fname);
1295 if (!f1) {
1296 Printf("Unknown function: %s", fname);
1297 return -1;
1298 }
1299 return Fit(f1, option, "", xmin, xmax);
1300}
1301
1302////////////////////////////////////////////////////////////////////////////////
1303/// Display a GUI panel with all graph fit options.
1304///
1305/// See class TFitEditor for example
1306
1308{
1309 if (!gPad)
1310 gROOT->MakeDefCanvas();
1311
1312 if (!gPad) {
1313 Error("FitPanel", "Unable to create a default canvas");
1314 return;
1315 }
1316
1317 // use plugin manager to create instance of TFitEditor
1318 TPluginHandler *handler = gROOT->GetPluginManager()->FindHandler("TFitEditor");
1319 if (handler && handler->LoadPlugin() != -1) {
1320 if (handler->ExecPlugin(2, gPad, this) == 0)
1321 Error("FitPanel", "Unable to crate the FitPanel");
1322 } else
1323 Error("FitPanel", "Unable to find the FitPanel plug-in");
1324}
1325
1326////////////////////////////////////////////////////////////////////////////////
1327/// Return graph correlation factor
1328
1330{
1331 Double_t rms1 = GetRMS(1);
1332 if (rms1 == 0) return 0;
1333 Double_t rms2 = GetRMS(2);
1334 if (rms2 == 0) return 0;
1335 return GetCovariance() / rms1 / rms2;
1336}
1337
1338////////////////////////////////////////////////////////////////////////////////
1339/// Return covariance of vectors x,y
1340
1342{
1343 if (fNpoints <= 0) return 0;
1344 Double_t sum = fNpoints, sumx = 0, sumy = 0, sumxy = 0;
1345
1346 for (Int_t i = 0; i < fNpoints; i++) {
1347 sumx += fX[i];
1348 sumy += fY[i];
1349 sumxy += fX[i] * fY[i];
1350 }
1351 return sumxy / sum - sumx / sum * sumy / sum;
1352}
1353
1354////////////////////////////////////////////////////////////////////////////////
1355/// Return mean value of X (axis=1) or Y (axis=2)
1356
1358{
1359 if (axis < 1 || axis > 2) return 0;
1360 if (fNpoints <= 0) return 0;
1361 Double_t sumx = 0;
1362 for (Int_t i = 0; i < fNpoints; i++) {
1363 if (axis == 1) sumx += fX[i];
1364 else sumx += fY[i];
1365 }
1366 return sumx / fNpoints;
1367}
1368
1369////////////////////////////////////////////////////////////////////////////////
1370/// Return RMS of X (axis=1) or Y (axis=2)
1371
1373{
1374 if (axis < 1 || axis > 2) return 0;
1375 if (fNpoints <= 0) return 0;
1376 Double_t sumx = 0, sumx2 = 0;
1377 for (Int_t i = 0; i < fNpoints; i++) {
1378 if (axis == 1) {
1379 sumx += fX[i];
1380 sumx2 += fX[i] * fX[i];
1381 } else {
1382 sumx += fY[i];
1383 sumx2 += fY[i] * fY[i];
1384 }
1385 }
1386 Double_t x = sumx / fNpoints;
1388 return TMath::Sqrt(rms2);
1389}
1390
1391////////////////////////////////////////////////////////////////////////////////
1392/// It always returns a negative value. Real implementation in TGraphErrors
1393
1395{
1396 return -1;
1397}
1398
1399////////////////////////////////////////////////////////////////////////////////
1400/// It always returns a negative value. Real implementation in TGraphErrors
1401
1403{
1404 return -1;
1405}
1406
1407////////////////////////////////////////////////////////////////////////////////
1408/// It always returns a negative value. Real implementation in TGraphErrors
1409/// and TGraphAsymmErrors
1410
1412{
1413 return -1;
1414}
1415
1416////////////////////////////////////////////////////////////////////////////////
1417/// It always returns a negative value. Real implementation in TGraphErrors
1418/// and TGraphAsymmErrors
1419
1421{
1422 return -1;
1423}
1424
1425////////////////////////////////////////////////////////////////////////////////
1426/// It always returns a negative value. Real implementation in TGraphErrors
1427/// and TGraphAsymmErrors
1428
1430{
1431 return -1;
1432}
1433
1434////////////////////////////////////////////////////////////////////////////////
1435/// It always returns a negative value. Real implementation in TGraphErrors
1436/// and TGraphAsymmErrors
1437
1439{
1440 return -1;
1441}
1442
1443////////////////////////////////////////////////////////////////////////////////
1444/// Return pointer to function with name.
1445///
1446/// Functions such as TGraph::Fit store the fitted function in the list of
1447/// functions of this graph.
1448
1449TF1 *TGraph::GetFunction(const char *name) const
1450{
1451 return dynamic_cast<TF1*>(FindObject(name));
1452}
1453
1454////////////////////////////////////////////////////////////////////////////////
1455/// Returns a pointer to the histogram used to draw the axis
1456/// Takes into account the two following cases.
1457/// 1. option 'A' was specified in TGraph::Draw. Return fHistogram
1458/// 2. user had called TPad::DrawFrame. return pointer to hframe histogram
1459
1461{
1464
1465 ComputeRange(rwxmin, rwymin, rwxmax, rwymax); //this is redefined in TGraphErrors
1466
1467 // (if fHistogram exist) && (if the log scale is on) &&
1468 // (if the computed range minimum is > 0) && (if the fHistogram minimum is zero)
1469 // then it means fHistogram limits have been computed in linear scale
1470 // therefore they might be too strict and cut some points. In that case the
1471 // fHistogram limits should be recomputed ie: the existing fHistogram
1472 // should not be returned.
1473 TH1F *histogr = nullptr;
1474 if (fHistogram) {
1475 if (!TestBit(kResetHisto)) {
1476 if (gPad && gPad->GetLogx()) {
1477 if (rwxmin <= 0 || fHistogram->GetXaxis()->GetXmin() != 0) return fHistogram;
1478 } else if (gPad && gPad->GetLogy()) {
1480 } else {
1481 return fHistogram;
1482 }
1483 } else {
1484 const_cast <TGraph*>(this)->ResetBit(kResetHisto);
1485 }
1487 }
1488
1489 if (rwxmin == rwxmax) rwxmax += 1.;
1490 if (rwymin == rwymax) rwymax += 1.;
1491 dx = 0.1 * (rwxmax - rwxmin);
1492 dy = 0.1 * (rwymax - rwymin);
1493 uxmin = rwxmin - dx;
1494 uxmax = rwxmax + dx;
1495 minimum = rwymin - dy;
1496 maximum = rwymax + dy;
1497
1498 if (fMinimum != -1111) minimum = fMinimum;
1499 if (fMaximum != -1111) maximum = fMaximum;
1500
1501 // the graph is created with at least as many channels as there are points
1502 // to permit zooming on the full range
1503 if (uxmin < 0 && rwxmin >= 0) {
1504 if (gPad && gPad->GetLogx()) uxmin = 0.9 * rwxmin;
1505 else uxmin = 0;
1506 }
1507 if (uxmax > 0 && rwxmax <= 0) {
1508 if (gPad && gPad->GetLogx()) uxmax = 1.1 * rwxmax;
1509 else uxmax = 0;
1510 }
1511
1512 if (minimum < 0 && rwymin >= 0) minimum = 0.9 * rwymin;
1513
1514 if (minimum <= 0 && gPad && gPad->GetLogy()) minimum = 0.001 * maximum;
1515 if (uxmin <= 0 && gPad && gPad->GetLogx()) {
1516 if (uxmax > 1000) uxmin = 1;
1517 else uxmin = 0.001 * uxmax;
1518 }
1519
1520 rwxmin = uxmin;
1521 rwxmax = uxmax;
1522 Int_t npt = 100;
1523 if (fNpoints > npt) npt = fNpoints;
1524 const char *gname = GetName();
1525 if (!gname[0]) gname = "Graph";
1526 // do not add the histogram to gDirectory
1527 // use local TDirectory::TContext that will set temporarly gDirectory to a nullptr and
1528 // will avoid that histogram is added in the global directory
1529 {
1530 TDirectory::TContext ctx(nullptr);
1531 ((TGraph*)this)->fHistogram = new TH1F(gname, GetTitle(), npt, rwxmin, rwxmax);
1532 }
1533 if (!fHistogram) return nullptr;
1538 // Restore the axis attributes if needed
1539 if (histogr) {
1540 fHistogram->GetXaxis()->SetTitle(histogr->GetXaxis()->GetTitle());
1541 fHistogram->GetXaxis()->CenterTitle(histogr->GetXaxis()->GetCenterTitle());
1542 fHistogram->GetXaxis()->RotateTitle(histogr->GetXaxis()->GetRotateTitle());
1543 fHistogram->GetXaxis()->SetNoExponent(histogr->GetXaxis()->GetNoExponent());
1544 fHistogram->GetXaxis()->SetTimeDisplay(histogr->GetXaxis()->GetTimeDisplay());
1545 fHistogram->GetXaxis()->SetTimeFormat(histogr->GetXaxis()->GetTimeFormat());
1546 histogr->GetXaxis()->TAttAxis::Copy(*(fHistogram->GetXaxis()));
1547
1548 fHistogram->GetYaxis()->SetTitle(histogr->GetYaxis()->GetTitle());
1549 fHistogram->GetYaxis()->CenterTitle(histogr->GetYaxis()->GetCenterTitle());
1550 fHistogram->GetYaxis()->RotateTitle(histogr->GetYaxis()->GetRotateTitle());
1551 fHistogram->GetYaxis()->SetNoExponent(histogr->GetYaxis()->GetNoExponent());
1552 fHistogram->GetYaxis()->SetTimeDisplay(histogr->GetYaxis()->GetTimeDisplay());
1553 fHistogram->GetYaxis()->SetTimeFormat(histogr->GetYaxis()->GetTimeFormat());
1554 histogr->GetYaxis()->TAttAxis::Copy(*(fHistogram->GetYaxis()));
1555
1556 delete histogr;
1557 }
1558 return fHistogram;
1559}
1560
1561////////////////////////////////////////////////////////////////////////////////
1562/// Get x and y values for point number i.
1563/// The function returns -1 in case of an invalid request or the point number otherwise
1564
1566{
1567 if (i < 0 || i >= fNpoints || !fX || !fY) return -1;
1568 x = fX[i];
1569 y = fY[i];
1570 return i;
1571}
1572
1573////////////////////////////////////////////////////////////////////////////////
1574/// Get x value for point i.
1575
1577{
1578 if (i < 0 || i >= fNpoints || !fX)
1579 return -1.;
1580
1581 return fX[i];
1582}
1583
1584////////////////////////////////////////////////////////////////////////////////
1585/// Get y value for point i.
1586
1588{
1589 if (i < 0 || i >= fNpoints || !fY)
1590 return -1.;
1591
1592 return fY[i];
1593}
1594
1595////////////////////////////////////////////////////////////////////////////////
1596/// Get x axis of the graph.
1597
1599{
1600 auto h = GetHistogram();
1601 return h ? h->GetXaxis() : nullptr;
1602}
1603
1604////////////////////////////////////////////////////////////////////////////////
1605/// Get y axis of the graph.
1606
1608{
1609 auto h = GetHistogram();
1610 return h ? h->GetYaxis() : nullptr;
1611}
1612
1613////////////////////////////////////////////////////////////////////////////////
1614/// Implementation to get information on point of graph at cursor position
1615/// Adapted from class TH1
1616
1618{
1619 if (!gPad) {
1620 Error("GetObjectInfo", "Cannot be used without gPad");
1621 return nullptr;
1622 }
1623
1624 // localize point
1625 Int_t ipoint = -2;
1626 // start with a small window (in case the mouse is very close to one point)
1627 for (Int_t i = 0; i < fNpoints; i++) {
1628 Int_t dpx = px - gPad->XtoAbsPixel(gPad->XtoPad(fX[i]));
1629 Int_t dpy = py - gPad->YtoAbsPixel(gPad->YtoPad(fY[i]));
1630
1631 if (dpx * dpx + dpy * dpy < 25) {
1632 ipoint = i;
1633 break;
1634 }
1635 }
1636
1637 Double_t x = gPad->PadtoX(gPad->AbsPixeltoX(px));
1638 Double_t y = gPad->PadtoY(gPad->AbsPixeltoY(py));
1639
1640 if (ipoint == -2)
1641 return Form("x=%g, y=%g", x, y);
1642
1645
1646 return Form("x=%g, y=%g, point=%d, xval=%g, yval=%g", x, y, ipoint, xval, yval);
1647}
1648
1649////////////////////////////////////////////////////////////////////////////////
1650/// Compute Initial values of parameters for a gaussian.
1651
1653{
1654 Double_t allcha, sumx, sumx2, x, val, rms, mean;
1655 Int_t bin;
1656 const Double_t sqrtpi = 2.506628;
1657
1658 // Compute mean value and RMS of the graph in the given range
1659 if (xmax <= xmin) {
1660 xmin = fX[0];
1661 xmax = fX[fNpoints-1];
1662 }
1663 Int_t np = 0;
1664 allcha = sumx = sumx2 = 0;
1665 for (bin = 0; bin < fNpoints; bin++) {
1666 x = fX[bin];
1667 if (x < xmin || x > xmax) continue;
1668 np++;
1669 val = fY[bin];
1670 sumx += val * x;
1671 sumx2 += val * x * x;
1672 allcha += val;
1673 }
1674 if (np == 0 || allcha == 0) return;
1675 mean = sumx / allcha;
1676 rms = TMath::Sqrt(sumx2 / allcha - mean * mean);
1678 if (rms == 0) rms = 1;
1680 TF1 *f1 = (TF1*)grFitter->GetUserFunc();
1681 f1->SetParameter(0, binwidx * allcha / (sqrtpi * rms));
1682 f1->SetParameter(1, mean);
1683 f1->SetParameter(2, rms);
1684 f1->SetParLimits(2, 0, 10 * rms);
1685}
1686
1687////////////////////////////////////////////////////////////////////////////////
1688/// Compute Initial values of parameters for an exponential.
1689
1691{
1693 Int_t ifail;
1694 if (xmax <= xmin) {
1695 xmin = fX[0];
1696 xmax = fX[fNpoints-1];
1697 }
1699
1701
1703 TF1 *f1 = (TF1*)grFitter->GetUserFunc();
1705 f1->SetParameter(1, slope);
1706}
1707
1708////////////////////////////////////////////////////////////////////////////////
1709/// Compute Initial values of parameters for a polynom.
1710
1712{
1713 Double_t fitpar[25];
1714
1716 TF1 *f1 = (TF1*)grFitter->GetUserFunc();
1717 Int_t npar = f1->GetNpar();
1718 if (xmax <= xmin) {
1719 xmin = fX[0];
1720 xmax = fX[fNpoints-1];
1721 }
1722
1724
1725 for (Int_t i = 0; i < npar; i++) f1->SetParameter(i, fitpar[i]);
1726}
1727
1728////////////////////////////////////////////////////////////////////////////////
1729/// Insert a new point at the mouse position
1730
1732{
1733 if (!gPad) {
1734 Error("InsertPoint", "Cannot be used without gPad, requires last mouse position");
1735 return -1;
1736 }
1737
1738 Int_t px = gPad->GetEventX();
1739 Int_t py = gPad->GetEventY();
1740
1741 //localize point where to insert
1742 Int_t ipoint = -2;
1743 Int_t i, d = 0;
1744 // start with a small window (in case the mouse is very close to one point)
1745 for (i = 0; i < fNpoints - 1; i++) {
1746 d = DistancetoLine(px, py, gPad->XtoPad(fX[i]), gPad->YtoPad(fY[i]), gPad->XtoPad(fX[i+1]), gPad->YtoPad(fY[i+1]));
1747 if (d < 5) {
1748 ipoint = i + 1;
1749 break;
1750 }
1751 }
1752 if (ipoint == -2) {
1753 //may be we are far from one point, try again with a larger window
1754 for (i = 0; i < fNpoints - 1; i++) {
1755 d = DistancetoLine(px, py, gPad->XtoPad(fX[i]), gPad->YtoPad(fY[i]), gPad->XtoPad(fX[i+1]), gPad->YtoPad(fY[i+1]));
1756 if (d < 10) {
1757 ipoint = i + 1;
1758 break;
1759 }
1760 }
1761 }
1762 if (ipoint == -2) {
1763 //distinguish between first and last point
1764 Int_t dpx = px - gPad->XtoAbsPixel(gPad->XtoPad(fX[0]));
1765 Int_t dpy = py - gPad->YtoAbsPixel(gPad->XtoPad(fY[0]));
1766 if (dpx * dpx + dpy * dpy < 25) ipoint = 0;
1767 else ipoint = fNpoints;
1768 }
1769
1770
1771 InsertPointBefore(ipoint, gPad->AbsPixeltoX(px), gPad->AbsPixeltoY(py));
1772
1773 gPad->Modified();
1774 return ipoint;
1775}
1776
1777
1778////////////////////////////////////////////////////////////////////////////////
1779/// Insert a new point with coordinates (x,y) before the point number `ipoint`.
1780
1782{
1783 if (ipoint < 0) {
1784 Error("TGraph", "Inserted point index should be >= 0");
1785 return;
1786 }
1787
1788 if (ipoint > fNpoints) {
1789 Error("TGraph", "Inserted point index should be <= %d", fNpoints);
1790 return;
1791 }
1792
1793 if (ipoint == fNpoints) {
1794 SetPoint(ipoint, x, y);
1795 return;
1796 }
1797
1799 CopyAndRelease(ps, ipoint, fNpoints++, ipoint + 1);
1800
1801 // To avoid redefinitions in descendant classes
1802 FillZero(ipoint, ipoint + 1);
1803
1804 fX[ipoint] = x;
1805 fY[ipoint] = y;
1806}
1807
1808
1809////////////////////////////////////////////////////////////////////////////////
1810/// Integrate the TGraph data within a given (index) range.
1811/// Note that this function computes the area of the polygon enclosed by the points of the TGraph.
1812/// The polygon segments, which are defined by the points of the TGraph, do not need to form a closed polygon,
1813/// since the last polygon segment, which closes the polygon, is taken as the line connecting the last TGraph point
1814/// with the first one. It is clear that the order of the point is essential in defining the polygon.
1815/// Also note that the segments should not intersect.
1816///
1817/// NB:
1818/// - if last=-1 (default) last is set to the last point.
1819/// - if (first <0) the first point (0) is taken.
1820///
1821/// ### Method:
1822///
1823/// There are many ways to calculate the surface of a polygon. It all depends on what kind of data
1824/// you have to deal with. The most evident solution would be to divide the polygon in triangles and
1825/// calculate the surface of them. But this can quickly become complicated as you will have to test
1826/// every segments of every triangles and check if they are intersecting with a current polygon's
1827/// segment or if it goes outside the polygon. Many calculations that would lead to many problems...
1828///
1829/// ### The solution (implemented by R.Brun)
1830/// Fortunately for us, there is a simple way to solve this problem, as long as the polygon's
1831/// segments don't intersect.
1832/// It takes the x coordinate of the current vertex and multiply it by the y coordinate of the next
1833/// vertex. Then it subtracts from it the result of the y coordinate of the current vertex multiplied
1834/// by the x coordinate of the next vertex. Then divide the result by 2 to get the surface/area.
1835///
1836/// ### Sources
1837/// - http://forums.wolfram.com/mathgroup/archive/1998/Mar/msg00462.html
1838/// - http://stackoverflow.com/questions/451426/how-do-i-calculate-the-surface-area-of-a-2d-polygon
1839
1841{
1842 if (first < 0) first = 0;
1843 if (last < 0) last = fNpoints - 1;
1844 if (last >= fNpoints) last = fNpoints - 1;
1845 if (first >= last) return 0;
1846 Int_t np = last - first + 1;
1847 Double_t sum = 0.0;
1848 //for(Int_t i=first;i<=last;i++) {
1849 // Int_t j = first + (i-first+1)%np;
1850 // sum += TMath::Abs(fX[i]*fY[j]);
1851 // sum -= TMath::Abs(fY[i]*fX[j]);
1852 //}
1853 for (Int_t i = first; i <= last; i++) {
1854 Int_t j = first + (i - first + 1) % np;
1855 sum += (fY[i] + fY[j]) * (fX[j] - fX[i]);
1856 }
1857 return 0.5 * TMath::Abs(sum);
1858}
1859
1860////////////////////////////////////////////////////////////////////////////////
1861/// Return 1 if the point (x,y) is inside the polygon defined by
1862/// the graph vertices 0 otherwise.
1863///
1864/// Algorithm:
1865///
1866/// The loop is executed with the end-point coordinates of a line segment
1867/// (X1,Y1)-(X2,Y2) and the Y-coordinate of a horizontal line.
1868/// The counter inter is incremented if the line (X1,Y1)-(X2,Y2) intersects
1869/// the horizontal line. In this case XINT is set to the X-coordinate of the
1870/// intersection point. If inter is an odd number, then the point x,y is within
1871/// the polygon.
1872
1874{
1875 return (Int_t)TMath::IsInside(x, y, fNpoints, fX, fY);
1876}
1877
1878////////////////////////////////////////////////////////////////////////////////
1879/// Least squares polynomial fitting without weights.
1880///
1881/// \param [in] m number of parameters
1882/// \param [in] a array of parameters
1883/// \param [in] xmin 1st point number to fit (default =0)
1884/// \param [in] xmax last point number to fit (default=fNpoints-1)
1885///
1886/// based on CERNLIB routine LSQ: Translated to C++ by Rene Brun
1887
1889{
1890 const Double_t zero = 0.;
1891 const Double_t one = 1.;
1892 const Int_t idim = 20;
1893
1894 Double_t b[400] /* was [20][20] */;
1895 Int_t i, k, l, ifail;
1897 Double_t da[20], xk, yk;
1898 Int_t n = fNpoints;
1899 if (xmax <= xmin) {
1900 xmin = fX[0];
1901 xmax = fX[fNpoints-1];
1902 }
1903
1904 if (m <= 2) {
1905 LeastSquareLinearFit(n, a[0], a[1], ifail, xmin, xmax);
1906 return;
1907 }
1908 if (m > idim || m > n) return;
1909 da[0] = zero;
1910 for (l = 2; l <= m; ++l) {
1911 b[l-1] = zero;
1912 b[m + l*20 - 21] = zero;
1913 da[l-1] = zero;
1914 }
1915 Int_t np = 0;
1916 for (k = 0; k < fNpoints; ++k) {
1917 xk = fX[k];
1918 if (xk < xmin || xk > xmax) continue;
1919 np++;
1920 yk = fY[k];
1921 power = one;
1922 da[0] += yk;
1923 for (l = 2; l <= m; ++l) {
1924 power *= xk;
1925 b[l-1] += power;
1926 da[l-1] += power * yk;
1927 }
1928 for (l = 2; l <= m; ++l) {
1929 power *= xk;
1930 b[m + l*20 - 21] += power;
1931 }
1932 }
1933 b[0] = Double_t(np);
1934 for (i = 3; i <= m; ++i) {
1935 for (k = i; k <= m; ++k) {
1936 b[k - 1 + (i-1)*20 - 21] = b[k + (i-2)*20 - 21];
1937 }
1938 }
1940
1941 if (ifail < 0) {
1942 a[0] = fY[0];
1943 for (i = 1; i < m; ++i) a[i] = 0;
1944 return;
1945 }
1946 for (i = 0; i < m; ++i) a[i] = da[i];
1947}
1948
1949////////////////////////////////////////////////////////////////////////////////
1950/// Least square linear fit without weights.
1951///
1952/// Fit a straight line (a0 + a1*x) to the data in this graph.
1953///
1954/// \param [in] ndata if ndata<0, fits the logarithm of the graph (used in InitExpo() to set
1955/// the initial parameter values for a fit with exponential function.
1956/// \param [in] a0 constant
1957/// \param [in] a1 slope
1958/// \param [in] ifail return parameter indicating the status of the fit (ifail=0, fit is OK)
1959/// \param [in] xmin, xmax fitting range
1960///
1961/// extracted from CERNLIB LLSQ: Translated to C++ by Rene Brun
1962
1964{
1966 Int_t i;
1968 Double_t fn, xk, yk;
1969 Double_t det;
1970 if (xmax <= xmin) {
1971 xmin = fX[0];
1972 xmax = fX[fNpoints-1];
1973 }
1974
1975 ifail = -2;
1976 xbar = ybar = x2bar = xybar = 0;
1977 Int_t np = 0;
1978 for (i = 0; i < fNpoints; ++i) {
1979 xk = fX[i];
1980 if (xk < xmin || xk > xmax) continue;
1981 np++;
1982 yk = fY[i];
1983 if (ndata < 0) {
1984 if (yk <= 0) yk = 1e-9;
1985 yk = TMath::Log(yk);
1986 }
1987 xbar += xk;
1988 ybar += yk;
1989 x2bar += xk * xk;
1990 xybar += xk * yk;
1991 }
1992 fn = Double_t(np);
1993 det = fn * x2bar - xbar * xbar;
1994 ifail = -1;
1995 if (det <= 0) {
1996 if (fn > 0) a0 = ybar / fn;
1997 else a0 = 0;
1998 a1 = 0;
1999 return;
2000 }
2001 ifail = 0;
2002 a0 = (x2bar * ybar - xbar * xybar) / det;
2003 a1 = (fn * xybar - xbar * ybar) / det;
2004}
2005
2006////////////////////////////////////////////////////////////////////////////////
2007/// Draw this graph with its current attributes.
2008
2014
2015////////////////////////////////////////////////////////////////////////////////
2016/// Draw the (x,y) as a graph.
2017
2023
2024////////////////////////////////////////////////////////////////////////////////
2025/// Draw the (x,y) as a histogram.
2026
2032
2033////////////////////////////////////////////////////////////////////////////////
2034/// Draw the stats
2035
2037{
2039 if (painter) painter->PaintStats(this, fit);
2040}
2041
2042////////////////////////////////////////////////////////////////////////////////
2043/// Print graph values.
2044
2046{
2047 for (Int_t i = 0; i < fNpoints; i++) {
2048 printf("x[%d]=%g, y[%d]=%g\n", i, fX[i], i, fY[i]);
2049 }
2050}
2051
2052////////////////////////////////////////////////////////////////////////////////
2053/// Recursively remove object from the list of functions
2054
2056{
2057 if (fFunctions) {
2060 }
2061 if (fHistogram == obj)
2062 fHistogram = nullptr;
2063}
2064
2065////////////////////////////////////////////////////////////////////////////////
2066/// Delete point close to the mouse position
2067/// Returns index of removed point (or -1 if nothing was changed)
2068
2070{
2071 if (!gPad) {
2072 Error("RemovePoint", "Cannot be used without gPad, requires last mouse position");
2073 return -1;
2074 }
2075
2076 Int_t px = gPad->GetEventX();
2077 Int_t py = gPad->GetEventY();
2078
2079 //localize point to be deleted
2080 Int_t ipoint = -2;
2081 // start with a small window (in case the mouse is very close to one point)
2082 for (Int_t i = 0; i < fNpoints; i++) {
2083 Int_t dpx = px - gPad->XtoAbsPixel(gPad->XtoPad(fX[i]));
2084 Int_t dpy = py - gPad->YtoAbsPixel(gPad->YtoPad(fY[i]));
2085 if (dpx * dpx + dpy * dpy < 100) {
2086 ipoint = i;
2087 break;
2088 }
2089 }
2090 return RemovePoint(ipoint);
2091}
2092
2093////////////////////////////////////////////////////////////////////////////////
2094/// Delete point number ipoint
2095/// Returns index of removed point (or -1 if nothing was changed)
2096
2098{
2099 if ((ipoint < 0) || (ipoint >= fNpoints))
2100 return -1;
2101
2103 CopyAndRelease(ps, ipoint + 1, fNpoints--, ipoint);
2104 if (gPad) gPad->Modified();
2105 return ipoint;
2106}
2107
2108////////////////////////////////////////////////////////////////////////////////
2109/// Save the graph as .csv, .tsv or .txt. In case of any other extension, fall
2110/// back to TObject::SaveAs
2111///
2112/// The result can be immediately imported into Excel, gnuplot, Python or whatever,
2113/// without the needing to install pyroot, etc.
2114///
2115/// \param filename the name of the file where to store the graph
2116/// \param option some tuning options
2117///
2118/// The file extension defines the delimiter used:
2119/// - `.csv` : comma
2120/// - `.tsv` : tab
2121/// - `.txt` : space
2122///
2123/// By default file contains lines with (X, Y) coordinates. If errors are present,
2124/// (X, EX, Y, EY) are written. With asymmetric errors (X, EXL, EXH, Y, EYL, EYH) are stored.
2125/// If option contains "asroot" string, order of values will match such order in TGraph constructors.
2126/// So one will get (X, Y, EX, EY) or (X, Y, EXL, EXH, EYL, EYH).
2127///
2128/// Also one can directly select that kind of errors are stored:
2129/// - "errors" - (X, Y, EX, EY) will be stored
2130/// - "asymmerrors" - (X, Y, EXL, EXH, EYL, EYH) will be stored
2131/// - "noerrors" - just (X, Y) will be stored disregard of graph kind
2132///
2133/// If option contains "title" a title line is generated with the axis titles.
2134
2135
2136void TGraph::SaveAs(const char *filename, Option_t *option) const
2137{
2138 char del = '\0';
2139 TString ext = "";
2141 TString opt = option;
2142 opt.ToLower();
2143
2144 if (filename) {
2145 if (fname.EndsWith(".csv")) {del = ','; ext = "csv";}
2146 else if (fname.EndsWith(".tsv")) {del = '\t'; ext = "tsv";}
2147 else if (fname.EndsWith(".txt")) {del = ' '; ext = "txt";}
2148 }
2149 if (del) {
2150 std::ofstream out;
2151 out.open(filename, std::ios::out);
2152 if (!out.good ()) {
2153 Error("SaveAs", "cannot open file: %s", filename);
2154 return;
2155 }
2156 Bool_t store_title = opt.Contains("title");
2158 Bool_t as_root = opt.Contains("asroot") || opt.Contains("native");
2159 if (opt.Contains("noerrors"))
2160 no_errors = kTRUE;
2161 else if (opt.Contains("asymmerrors"))
2163 else if (opt.Contains("errors"))
2165 else if (InheritsFrom("TGraphErrors"))
2167 else if (InheritsFrom("TGraphAsymmErrors") || InheritsFrom("TGraphBentErrors"))
2169 else
2170 no_errors = kTRUE;
2171
2173 if (fHistogram) {
2176 }
2177 if (xtitle.IsNull())
2178 xtitle = "x";
2179 if (ytitle.IsNull())
2180 ytitle = "y";
2181
2182 if (plain_errors) {
2183 if(store_title) {
2184 if (as_root)
2185 out << "# " << xtitle << "\t" << ytitle << "\tex\tey\n";
2186 else
2187 out << "# " << xtitle << "\tex\t" << ytitle << "\tey\n";
2188 }
2189 for(int i = 0; i < fNpoints ; i++) {
2190 Double_t x = GetPointX(i);
2191 Double_t y = GetPointY(i);
2192 Double_t ex = GetErrorX(i);
2193 Double_t ey = GetErrorY(i);
2194 if (as_root)
2195 out << x << del << y << del << ex << del << ey << "\n";
2196 else
2197 out << x << del << ex << del << y << del << ey << "\n";
2198 }
2199 } else if (asymm_erros) {
2200 if(store_title) {
2201 if (as_root)
2202 out << "# " << xtitle << "\t" << ytitle << "\texl\texh\teyl\teyh\n";
2203 else
2204 out << "# " << xtitle << "\texl\texh\t" << ytitle << "\teyl\teyh\n";
2205 }
2206 for(int i = 0; i < GetN(); i++) {
2207 Double_t x = GetPointX(i);
2208 Double_t y = GetPointY(i);
2213 if (as_root)
2214 out << x << del << y << del << exl << del << exh << del << eyl << del << eyh << "\n";
2215 else
2216 out << x << del << exl << del << exh << del << y << del << eyl << del << eyh << "\n";
2217 }
2218 } else if (no_errors) {
2219 if(store_title)
2220 out << "# " << xtitle << "\t" << ytitle << "\n";
2221 for (Int_t i = 0 ; i < GetN(); i++)
2222 out << GetPointX(i) << del << GetPointY(i) << "\n";
2223 }
2224 out.close();
2225 Info("SaveAs", "%s file: %s has been generated", ext.Data(), filename);
2226 } else {
2228 }
2229}
2230
2231
2232////////////////////////////////////////////////////////////////////////////////
2233/// Save primitive as a C++ statement(s) on output stream out
2234
2235void TGraph::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
2236{
2237 TString args;
2238 if (fNpoints >= 1) {
2239 TString xname = SavePrimitiveVector(out, "graph_x", fNpoints, fX, kTRUE);
2240 TString yname = SavePrimitiveVector(out, "graph_y", fNpoints, fY);
2241 args.Form("%d, %s.data(), %s.data()", fNpoints, xname.Data(), yname.Data());
2242 }
2243
2244 SavePrimitiveConstructor(out, Class(), "graph", args, fNpoints < 1);
2245
2246 SaveHistogramAndFunctions(out, "graph", option);
2247}
2248
2249////////////////////////////////////////////////////////////////////////////////
2250/// Save histogram and list of functions of TGraph as C++ statement
2251/// Used in all TGraph-derived classes
2252
2253void TGraph::SaveHistogramAndFunctions(std::ostream &out, const char *varname, Option_t *option)
2254{
2255 thread_local Int_t frameNumber = 0;
2256
2257 TString ref = "Graph";
2258 if ((ref != GetName()) || (ref != GetTitle()))
2260
2261 SaveFillAttributes(out, varname, 0, 1000);
2262 SaveLineAttributes(out, varname, 1, 1, 1);
2263 SaveMarkerAttributes(out, varname, 1, 1, 1);
2264
2265 if (fHistogram) {
2267 fHistogram->SetName(TString::Format("Graph_histogram%d", ++frameNumber).Data());
2268 fHistogram->SavePrimitive(out, "nodraw");
2269 out << " " <<varname << "->SetHistogram(" << fHistogram->GetName() << ");\n";
2270 out << " \n";
2271 fHistogram->SetName(hname.Data());
2272 }
2273
2275
2276 if (!option)
2277 option = "";
2278 const char *l = strstr(option, "multigraph");
2279 if (l) {
2280 out << " multigraph->Add(" << varname << ",\"" << l + 10 << "\");\n";
2281 return;
2282 }
2283 l = strstr(option, "th2poly");
2284 if (l) {
2285 out << " " << l + 7 << "->AddBin(" << varname << ");\n";
2286 return;
2287 }
2288
2290}
2291
2292////////////////////////////////////////////////////////////////////////////////
2293/// Multiply the values of a TGraph by a constant c1.
2294///
2295/// If option contains "x" the x values are scaled
2296/// If option contains "y" the y values are scaled
2297/// If option contains "xy" both x and y values are scaled
2298
2300{
2301 TString opt = option; opt.ToLower();
2302 if (opt.Contains("x")) {
2303 for (Int_t i=0; i<GetN(); i++)
2304 GetX()[i] *= c1;
2305 }
2306 if (opt.Contains("y")) {
2307 for (Int_t i=0; i<GetN(); i++)
2308 GetY()[i] *= c1;
2309 }
2310}
2311
2312////////////////////////////////////////////////////////////////////////////////
2313/// Set number of points in the graph
2314/// Existing coordinates are preserved
2315/// New coordinates above fNpoints are preset to 0.
2316
2318{
2319 if (n < 0) n = 0;
2320 if (n == fNpoints) return;
2321 Double_t **ps = Allocate(n);
2322 CopyAndRelease(ps, 0, TMath::Min(fNpoints, n), 0);
2323 if (n > fNpoints) {
2325 }
2326 fNpoints = n;
2327}
2328
2329////////////////////////////////////////////////////////////////////////////////
2330/// Return kTRUE if kNotEditable bit is not set, kFALSE otherwise.
2331
2333{
2334 return TestBit(kNotEditable) ? kFALSE : kTRUE;
2335}
2336
2337////////////////////////////////////////////////////////////////////////////////
2338/// if editable=kFALSE, the graph cannot be modified with the mouse
2339/// by default a TGraph is editable
2340
2346
2347////////////////////////////////////////////////////////////////////////////////
2348/// Set highlight (enable/disable) mode for the graph
2349/// by default highlight mode is disable
2350
2352{
2353 if (IsHighlight() == set) return;
2354
2356 if (!painter) return;
2357 SetBit(kIsHighlight, set);
2358 painter->SetHighlight(this);
2359}
2360
2361/// Set the histogram underlying the TGraph. This transfers the ownership of h to the TGraph. The preexisting fHistogram will be deleted.
2363{
2364 delete fHistogram;
2365 fHistogram = h;
2366}
2367
2368////////////////////////////////////////////////////////////////////////////////
2369/// Set the maximum of the graph.
2370
2372{
2373 fMaximum = maximum;
2374 GetHistogram()->SetMaximum(maximum);
2375}
2376
2377////////////////////////////////////////////////////////////////////////////////
2378/// Set the minimum of the graph.
2379
2381{
2382 fMinimum = minimum;
2383 GetHistogram()->SetMinimum(minimum);
2384}
2385
2386////////////////////////////////////////////////////////////////////////////////
2387/// Set x and y values for point number i.
2388
2390{
2391 if (i < 0) return;
2393
2394 if (i >= fMaxSize) {
2395 Double_t **ps = ExpandAndCopy(i + 1, fNpoints);
2396 CopyAndRelease(ps, 0, 0, 0);
2397 }
2398 if (i >= fNpoints) {
2399 // points above i can be not initialized
2400 // set zero up to i-th point to avoid redefinition
2401 // of this method in descendant classes
2402 FillZero(fNpoints, i + 1);
2403 fNpoints = i + 1;
2404 }
2405 fX[i] = x;
2406 fY[i] = y;
2407 if (gPad) gPad->Modified();
2408}
2409
2410////////////////////////////////////////////////////////////////////////////////
2411/// Set x value for point i.
2412
2414{
2415 SetPoint(i, x, GetPointY(i));
2416}
2417
2418////////////////////////////////////////////////////////////////////////////////
2419/// Set y value for point i.
2420
2422{
2423 SetPoint(i, GetPointX(i), y);
2424}
2425
2426////////////////////////////////////////////////////////////////////////////////
2427/// Set graph name.
2428void TGraph::SetName(const char *name)
2429{
2430 fName = name;
2432}
2433
2434////////////////////////////////////////////////////////////////////////////////
2435/// Change (i.e. set) the title
2436///
2437/// if title is in the form `stringt;stringx;stringy;stringz`
2438/// the graph title is set to `stringt`, the x axis title to `stringx`,
2439/// the y axis title to `stringy`, and the z axis title to `stringz`.
2440///
2441/// To insert the character `;` in one of the titles, one should use `#;`
2442/// or `#semicolon`.
2443
2444void TGraph::SetTitle(const char* title)
2445{
2446 fTitle = title;
2447 fTitle.ReplaceAll("#;",2,"#semicolon",10);
2448 Int_t p = fTitle.Index(";");
2449
2450 if (p>0) {
2451 if (!fHistogram) GetHistogram();
2452 fHistogram->SetTitle(title);
2453 Int_t n = fTitle.Length()-p;
2454 if (p>0) fTitle.Remove(p,n);
2455 fTitle.ReplaceAll("#semicolon",10,"#;",2);
2456 } else {
2457 if (fHistogram) fHistogram->SetTitle(title);
2458 }
2459}
2460
2461////////////////////////////////////////////////////////////////////////////////
2462/// Set graph name and title
2463
2464void TGraph::SetNameTitle(const char *name, const char *title)
2465{
2466 SetName(name);
2467 SetTitle(title);
2468}
2469
2470////////////////////////////////////////////////////////////////////////////////
2471/// Set statistics option on/off.
2472///
2473/// By default, the statistics box is drawn.
2474/// The paint options can be selected via gStyle->SetOptStat.
2475/// This function sets/resets the kNoStats bit in the graph object.
2476/// It has priority over the Style option.
2477
2479{
2481 if (!stats) {
2483 //remove the "stats" object from the list of functions
2484 if (fFunctions) {
2485 TObject *obj = fFunctions->FindObject("stats");
2486 if (obj) {
2487 fFunctions->Remove(obj);
2488 delete obj;
2489 }
2490 }
2491 }
2492}
2493
2494////////////////////////////////////////////////////////////////////////////////
2495/// if size*2 <= fMaxSize allocate new arrays of size points,
2496/// copy points [0,oend).
2497/// Return newarray (passed or new instance if it was zero
2498/// and allocations are needed)
2499
2501{
2502 if (size * 2 > fMaxSize || !fMaxSize)
2503 return nullptr;
2504
2506 CopyPoints(newarrays, 0, oend, 0);
2507 return newarrays;
2508}
2509
2510////////////////////////////////////////////////////////////////////////////////
2511/// Sorts the points of this TGraph using in-place quicksort (see e.g. older glibc).
2512/// To compare two points the function parameter greaterfunc is used (see TGraph::CompareX for an
2513/// example of such a method, which is also the default comparison function for Sort). After
2514/// the sort, greaterfunc(this, i, j) will return kTRUE for all i>j if ascending == kTRUE, and
2515/// kFALSE otherwise.
2516///
2517/// The last two parameters are used for the recursive quick sort, stating the range to be sorted
2518///
2519/// Examples:
2520/// ~~~ {.cpp}
2521/// // sort points along x axis
2522/// graph->Sort();
2523/// // sort points along their distance to origin
2524/// graph->Sort(&TGraph::CompareRadius);
2525///
2526/// Bool_t CompareErrors(const TGraph* gr, Int_t i, Int_t j) {
2527/// const TGraphErrors* ge=(const TGraphErrors*)gr;
2528/// return (ge->GetEY()[i]>ge->GetEY()[j]); }
2529/// // sort using the above comparison function, largest errors first
2530/// graph->Sort(&CompareErrors, kFALSE);
2531/// ~~~
2532
2533void TGraph::Sort(Bool_t (*greaterfunc)(const TGraph *, Int_t, Int_t) /*=TGraph::CompareX()*/,
2534 Bool_t ascending /*=kTRUE*/, Int_t low /*=0*/, Int_t high /*=-1111*/)
2535{
2536 // set the bit in case of an ascending =sort in X
2537 if (greaterfunc == TGraph::CompareX && ascending && low == 0 && high == -1111)
2539
2540 if (high == -1111)
2541 high = fNpoints - 1;
2542
2543 // Create a vector to store the indices of the graph data points.
2544 // We use std::vector<Int_t> instead of std::vector<ULong64_t> to match the input type
2545 // required by the comparison operator's signature provided as `greaterfunc`
2546 std::vector<int> sorting_indices(fNpoints);
2547 std::iota(sorting_indices.begin(), sorting_indices.end(), 0);
2548
2549 // Sort the indices using the provided comparison function
2550 // We use std::stable_sort here because the libc++ implementation of std::sort
2551 // is not standard-compliant until LLVM 14 which caused errors on the mac nodes
2552 // of our CI, related issue: https://github.com/llvm/llvm-project/issues/21211
2553 std::stable_sort(sorting_indices.begin() + low, sorting_indices.begin() + high + 1,
2554 [&](int left, int right) { return left != right && greaterfunc(this, left, right) != ascending; });
2555
2556 Int_t numSortedPoints = high - low + 1;
2558}
2559
2560////////////////////////////////////////////////////////////////////////////////
2561/// Stream an object of class TGraph.
2562
2564{
2565 if (b.IsReading()) {
2566 UInt_t R__s, R__c;
2567 Version_t R__v = b.ReadVersion(&R__s, &R__c);
2568 if (R__v > 2) {
2569 b.ReadClassBuffer(TGraph::Class(), this, R__v, R__s, R__c);
2570 if (fHistogram) fHistogram->SetDirectory(nullptr);
2571 TIter next(fFunctions);
2572 TObject *obj;
2573 while ((obj = next())) {
2574 if (obj->InheritsFrom(TF1::Class())) {
2575 TF1 *f1 = (TF1*)obj;
2576 f1->SetParent(this);
2577 }
2578 }
2580 return;
2581 }
2582 //====process old versions before automatic schema evolution
2587 b >> fNpoints;
2589 fX = new Double_t[fNpoints];
2590 fY = new Double_t[fNpoints];
2591 if (R__v < 2) {
2592 Float_t *x = new Float_t[fNpoints];
2593 Float_t *y = new Float_t[fNpoints];
2594 b.ReadFastArray(x, fNpoints);
2595 b.ReadFastArray(y, fNpoints);
2596 for (Int_t i = 0; i < fNpoints; i++) {
2597 fX[i] = x[i];
2598 fY[i] = y[i];
2599 }
2600 delete [] y;
2601 delete [] x;
2602 } else {
2603 b.ReadFastArray(fX, fNpoints);
2604 b.ReadFastArray(fY, fNpoints);
2605 }
2606 b >> fFunctions;
2607 b >> fHistogram;
2608 if (fHistogram) fHistogram->SetDirectory(nullptr);
2609 if (R__v < 2) {
2610 Float_t mi, ma;
2611 b >> mi;
2612 b >> ma;
2613 fMinimum = mi;
2614 fMaximum = ma;
2615 } else {
2616 b >> fMinimum;
2617 b >> fMaximum;
2618 }
2619 b.CheckByteCount(R__s, R__c, TGraph::IsA());
2620 //====end of old versions
2621
2622 } else {
2623 b.WriteClassBuffer(TGraph::Class(), this);
2624 }
2625}
2626
2627////////////////////////////////////////////////////////////////////////////////
2628/// Swap points.
2629
2635
2636////////////////////////////////////////////////////////////////////////////////
2637/// Update the fX and fY arrays with the sorted values.
2638
2640{
2641 std::vector<Double_t> fXSorted(numSortedPoints);
2642 std::vector<Double_t> fYSorted(numSortedPoints);
2643
2644 // Fill the sorted X and Y values based on the sorted indices
2645 std::generate(fXSorted.begin(), fXSorted.end(),
2646 [begin = low, &sorting_indices, this]() mutable { return fX[sorting_indices[begin++]]; });
2647 std::generate(fYSorted.begin(), fYSorted.end(),
2648 [begin = low, &sorting_indices, this]() mutable { return fY[sorting_indices[begin++]]; });
2649
2650 // Copy the sorted X and Y values back to the original arrays
2651 std::copy(fXSorted.begin(), fXSorted.end(), fX + low);
2652 std::copy(fYSorted.begin(), fYSorted.end(), fY + low);
2653}
2654
2655////////////////////////////////////////////////////////////////////////////////
2656/// Swap values.
2657
2659{
2660 Double_t tmp = arr[pos1];
2661 arr[pos1] = arr[pos2];
2662 arr[pos2] = tmp;
2663}
2664
2665////////////////////////////////////////////////////////////////////////////////
2666/// Set current style settings in this graph
2667/// This function is called when either TCanvas::UseCurrentStyle
2668/// or TROOT::ForceStyle have been invoked.
2669
2700
2701////////////////////////////////////////////////////////////////////////////////
2702/// Adds all graphs from the collection to this graph.
2703/// Returns the total number of points in the result or -1 in case of an error.
2704
2706{
2707 TIter next(li);
2708 while (TObject* o = next()) {
2709 TGraph *g = dynamic_cast<TGraph*>(o);
2710 if (!g) {
2711 Error("Merge",
2712 "Cannot merge - an object which doesn't inherit from TGraph found in the list");
2713 return -1;
2714 }
2715 DoMerge(g);
2716 }
2717 return GetN();
2718}
2719
2720////////////////////////////////////////////////////////////////////////////////
2721/// protected function to perform the merge operation of a graph
2722
2724{
2725 Double_t x = 0, y = 0;
2726 for (Int_t i = 0 ; i < g->GetN(); i++) {
2727 g->GetPoint(i, x, y);
2728 SetPoint(GetN(), x, y);
2729 }
2730 return kTRUE;
2731}
2732
2733////////////////////////////////////////////////////////////////////////////////
2734/// Move all graph points on specified values dx,dy
2735/// If log argument specified, calculation done in logarithmic scale like:
2736/// new_value = exp( log(old_value) + delta );
2737
2739{
2740 Double_t x = 0, y = 0;
2741 for (Int_t i = 0 ; i < GetN(); i++) {
2742 GetPoint(i, x, y);
2743 if (!logx) {
2744 x += dx;
2745 } else if (x > 0) {
2746 x = TMath::Exp(TMath::Log(x) + dx);
2747 }
2748 if (!logy) {
2749 y += dy;
2750 } else if (y > 0) {
2751 y = TMath::Exp(TMath::Log(y) + dy);
2752 }
2753 SetPoint(i, x, y);
2754 }
2755}
2756
2757
2758////////////////////////////////////////////////////////////////////////////////
2759/// Find zero of a continuous function.
2760/// This function finds a real zero of the continuous real
2761/// function Y(X) in a given interval (A,B). See accompanying
2762/// notes for details of the argument list and calling sequence
2763
2766{
2767 static Double_t a, b, ya, ytest, y1, x1, h;
2768 static Int_t j1, it, j3, j2;
2769 Double_t yb, x2;
2770 yb = 0;
2771
2772 // Calculate Y(X) at X=AZ.
2773 if (k <= 0) {
2774 a = AZ;
2775 b = BZ;
2776 X = a;
2777 j1 = 1;
2778 it = 1;
2779 k = j1;
2780 return;
2781 }
2782
2783 // Test whether Y(X) is sufficiently small.
2784
2785 if (TMath::Abs(Y) <= E2) {
2786 k = 2;
2787 return;
2788 }
2789
2790 // Calculate Y(X) at X=BZ.
2791
2792 if (j1 == 1) {
2793 ya = Y;
2794 X = b;
2795 j1 = 2;
2796 return;
2797 }
2798 // Test whether the signs of Y(AZ) and Y(BZ) are different.
2799 // if not, begin the binary subdivision.
2800
2801 if (j1 != 2) goto L100;
2802 if (ya * Y < 0) goto L120;
2803 x1 = a;
2804 y1 = ya;
2805 j1 = 3;
2806 h = b - a;
2807 j2 = 1;
2808 x2 = a + 0.5 * h;
2809 j3 = 1;
2810 it++; //*-*- Check whether (maxiterations) function values have been calculated.
2811 if (it >= maxiterations) k = j1;
2812 else X = x2;
2813 return;
2814
2815 // Test whether a bracket has been found .
2816 // If not,continue the search
2817
2818L100:
2819 if (j1 > 3) goto L170;
2820 if (ya*Y >= 0) {
2821 if (j3 >= j2) {
2822 h = 0.5 * h;
2823 j2 = 2 * j2;
2824 a = x1;
2825 ya = y1;
2826 x2 = a + 0.5 * h;
2827 j3 = 1;
2828 } else {
2829 a = X;
2830 ya = Y;
2831 x2 = X + h;
2832 j3++;
2833 }
2834 it++;
2835 if (it >= maxiterations) k = j1;
2836 else X = x2;
2837 return;
2838 }
2839
2840 // The first bracket has been found.calculate the next X by the
2841 // secant method based on the bracket.
2842
2843L120:
2844 b = X;
2845 yb = Y;
2846 j1 = 4;
2847L130:
2848 if (TMath::Abs(ya) > TMath::Abs(yb)) {
2849 x1 = a;
2850 y1 = ya;
2851 X = b;
2852 Y = yb;
2853 } else {
2854 x1 = b;
2855 y1 = yb;
2856 X = a;
2857 Y = ya;
2858 }
2859
2860 // Use the secant method based on the function values y1 and Y.
2861 // check that x2 is inside the interval (a,b).
2862
2863L150:
2864 x2 = X - Y * (X - x1) / (Y - y1);
2865 x1 = X;
2866 y1 = Y;
2868 if ((x2 - a)*(x2 - b) < 0) {
2869 it++;
2870 if (it >= maxiterations) k = j1;
2871 else X = x2;
2872 return;
2873 }
2874
2875 // Calculate the next value of X by bisection . Check whether
2876 // the maximum accuracy has been achieved.
2877
2878L160:
2879 x2 = 0.5 * (a + b);
2880 ytest = 0;
2881 if ((x2 - a)*(x2 - b) >= 0) {
2882 k = 2;
2883 return;
2884 }
2885 it++;
2886 if (it >= maxiterations) k = j1;
2887 else X = x2;
2888 return;
2889
2890
2891 // Revise the bracket (a,b).
2892
2893L170:
2894 if (j1 != 4) return;
2895 if (ya * Y < 0) {
2896 b = X;
2897 yb = Y;
2898 } else {
2899 a = X;
2900 ya = Y;
2901 }
2902
2903 // Use ytest to decide the method for the next value of X.
2904
2905 if (ytest <= 0) goto L130;
2906 if (TMath::Abs(Y) - ytest <= 0) goto L150;
2907 goto L160;
2908}
#define d(i)
Definition RSha256.hxx:102
#define b(i)
Definition RSha256.hxx:100
#define f(i)
Definition RSha256.hxx:104
#define g(i)
Definition RSha256.hxx:105
#define a(i)
Definition RSha256.hxx:99
#define h(i)
Definition RSha256.hxx:106
#define e(i)
Definition RSha256.hxx:103
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
short Version_t
Class version identifier (short)
Definition RtypesCore.h:79
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
constexpr Ssiz_t kNPOS
The equivalent of std::string::npos for the ROOT class TString.
Definition RtypesCore.h:131
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
#define X(type, name)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
R__EXTERN TEnv * gEnv
Definition TEnv.h:126
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t option
Option_t Option_t SetLineWidth
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t SetFillStyle
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t del
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t np
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t SetLineColor
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t format
Option_t Option_t SetFillColor
Option_t Option_t SetMarkerStyle
Option_t Option_t TPoint TPoint const char y1
char name[80]
Definition TGX11.cxx:148
void H1LeastSquareSeqnd(Int_t n, Double_t *a, Int_t idim, Int_t &ifail, Int_t k, Double_t *b)
Extracted from CERN Program library routine DSEQN.
Definition TH1.cxx:5048
float xmin
float ymin
float xmax
float ymax
#define gROOT
Definition TROOT.h:417
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2496
void Printf(const char *fmt,...)
Formats a string in a circular formatting buffer and prints the string.
Definition TString.cxx:2510
R__EXTERN TStyle * gStyle
Definition TStyle.h:442
R__EXTERN TSystem * gSystem
Definition TSystem.h:582
#define gPad
class describing the range in the coordinates it supports multiple range in a coordinate.
Definition DataRange.h:35
const_iterator begin() const
const_iterator end() const
Fill Area Attributes class.
Definition TAttFill.h:21
virtual void Streamer(TBuffer &)
virtual Color_t GetFillColor() const
Return the fill area color.
Definition TAttFill.h:32
void Copy(TAttFill &attfill) const
Copy this fill attributes to a new TAttFill.
Definition TAttFill.cxx:203
virtual Style_t GetFillStyle() const
Return the fill area style.
Definition TAttFill.h:33
virtual void SaveFillAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1001)
Save fill attributes as C++ statement(s) on output stream out.
Definition TAttFill.cxx:240
Line Attributes class.
Definition TAttLine.h:21
virtual void Streamer(TBuffer &)
virtual Color_t GetLineColor() const
Return the line color.
Definition TAttLine.h:36
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
Definition TAttLine.h:46
virtual Width_t GetLineWidth() const
Return the line width.
Definition TAttLine.h:38
virtual Style_t GetLineStyle() const
Return the line style.
Definition TAttLine.h:37
void Copy(TAttLine &attline) const
Copy this line attributes to a new TAttLine.
Definition TAttLine.cxx:176
Int_t DistancetoLine(Int_t px, Int_t py, Double_t xp1, Double_t yp1, Double_t xp2, Double_t yp2)
Compute distance from point px,py to a line.
Definition TAttLine.cxx:210
virtual void SaveLineAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1, Int_t widdef=1)
Save line attributes as C++ statement(s) on output stream out.
Definition TAttLine.cxx:289
Marker Attributes class.
Definition TAttMarker.h:21
virtual void SaveMarkerAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1, Int_t sizdef=1)
Save line attributes as C++ statement(s) on output stream out.
virtual Style_t GetMarkerStyle() const
Return the marker style.
Definition TAttMarker.h:34
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition TAttMarker.h:41
virtual Color_t GetMarkerColor() const
Return the marker color.
Definition TAttMarker.h:33
virtual Size_t GetMarkerSize() const
Return the marker size.
Definition TAttMarker.h:35
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition TAttMarker.h:43
void Copy(TAttMarker &attmarker) const
Copy this marker attributes to a new TAttMarker.
virtual void Streamer(TBuffer &)
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
Definition TAttMarker.h:48
Class to manage histogram axis.
Definition TAxis.h:32
const char * GetTitle() const override
Returns title of object.
Definition TAxis.h:137
virtual void SetTimeDisplay(Int_t value)
Definition TAxis.h:173
void RotateTitle(Bool_t rotate=kTRUE)
Rotate title by 180 degrees.
Definition TAxis.h:205
void CenterTitle(Bool_t center=kTRUE)
Center axis title.
Definition TAxis.h:196
void SetNoExponent(Bool_t noExponent=kTRUE)
Set the NoExponent flag By default, an exponent of the form 10^N is used when the label value are eit...
Definition TAxis.h:235
virtual void SetLimits(Double_t xmin, Double_t xmax)
Definition TAxis.h:166
virtual void SetTimeFormat(const char *format="")
Change the format used for time plotting.
Definition TAxis.cxx:1165
Using a TBrowser one can browse all ROOT objects.
Definition TBrowser.h:37
Buffer base class used for serializing objects.
Definition TBuffer.h:43
Collection abstract base class.
Definition TCollection.h:65
virtual Bool_t IsEmpty() const
TObject * Clone(const char *newname="") const override
Make a clone of an collection using the Streamer facility.
TDirectory::TContext keeps track and restore the current directory.
Definition TDirectory.h:89
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition TEnv.cxx:511
1-Dim function class
Definition TF1.h:182
static TClass * Class()
virtual Int_t GetNpar() const
Definition TF1.h:446
virtual void SetParent(TObject *p=nullptr)
Definition TF1.h:647
virtual void SetParLimits(Int_t ipar, Double_t parmin, Double_t parmax)
Set lower and upper limits for parameter ipar.
Definition TF1.cxx:3562
virtual void SetParameter(Int_t param, Double_t value)
Definition TF1.h:608
Provides an indirection to the TFitResult class and with a semantics identical to a TFitResult pointe...
A TGraph is an object made of two arrays X and Y with npoints each.
Definition TGraph.h:41
virtual Double_t GetPointX(Int_t i) const
Get x value for point i.
Definition TGraph.cxx:1576
static TClass * Class()
virtual Double_t Integral(Int_t first=0, Int_t last=-1) const
Integrate the TGraph data within a given (index) range.
Definition TGraph.cxx:1840
Int_t fNpoints
Number of points <= fMaxSize.
Definition TGraph.h:46
virtual Int_t IsInside(Double_t x, Double_t y) const
Return 1 if the point (x,y) is inside the polygon defined by the graph vertices 0 otherwise.
Definition TGraph.cxx:1873
virtual void LeastSquareFit(Int_t m, Double_t *a, Double_t xmin=0, Double_t xmax=0)
Least squares polynomial fitting without weights.
Definition TGraph.cxx:1888
virtual Double_t Chisquare(TF1 *f1, Option_t *option="") const
Return the chisquare of this graph with respect to f1.
Definition TGraph.cxx:705
void UseCurrentStyle() override
Set current style settings in this graph This function is called when either TCanvas::UseCurrentStyle...
Definition TGraph.cxx:2670
virtual void SetPoint(Int_t i, Double_t x, Double_t y)
Set x and y values for point number i.
Definition TGraph.cxx:2389
Double_t * GetY() const
Definition TGraph.h:139
virtual Int_t Merge(TCollection *list)
Adds all graphs from the collection to this graph.
Definition TGraph.cxx:2705
Int_t fMaxSize
!Current dimension of arrays fX and fY
Definition TGraph.h:45
TString fOption
Options used for drawing the graph.
Definition TGraph.h:53
~TGraph() override
Graph default destructor.
Definition TGraph.cxx:594
Double_t ** ShrinkAndCopy(Int_t size, Int_t iend)
if size*2 <= fMaxSize allocate new arrays of size points, copy points [0,oend).
Definition TGraph.cxx:2500
virtual Double_t GetRMS(Int_t axis=1) const
Return RMS of X (axis=1) or Y (axis=2)
Definition TGraph.cxx:1372
TH1F * fHistogram
Pointer to histogram used for drawing axis.
Definition TGraph.h:50
void Paint(Option_t *chopt="") override
Draw this graph with its current attributes.
Definition TGraph.cxx:2009
@ kNotEditable
Bit set if graph is non editable.
Definition TGraph.h:77
@ kIsHighlight
Bit set if graph is highlight.
Definition TGraph.h:79
@ kIsSortedX
Graph is sorted in X points.
Definition TGraph.h:78
@ kClipFrame
Clip to the frame boundary.
Definition TGraph.h:75
@ kResetHisto
fHistogram must be reset in GetHistogram
Definition TGraph.h:76
@ kNoStats
Don't draw stats box.
Definition TGraph.h:74
virtual Double_t GetErrorXlow(Int_t bin) const
It always returns a negative value.
Definition TGraph.cxx:1420
virtual void MovePoints(Double_t dx, Double_t dy, Bool_t logx=kFALSE, Bool_t logy=kFALSE)
Move all graph points on specified values dx,dy If log argument specified, calculation done in logari...
Definition TGraph.cxx:2738
virtual Double_t GetErrorYlow(Int_t bin) const
It always returns a negative value.
Definition TGraph.cxx:1438
virtual void UpdateArrays(const std::vector< Int_t > &sorting_indices, Int_t numSortedPoints, Int_t low)
Update the fX and fY arrays with the sorted values.
Definition TGraph.cxx:2639
virtual void CopyAndRelease(Double_t **newarrays, Int_t ibegin, Int_t iend, Int_t obegin)
Copy points from fX and fY to arrays[0] and arrays[1] or to fX and fY if arrays == 0 and ibegin !...
Definition TGraph.cxx:790
Double_t GetMinimum() const
Definition TGraph.h:151
void Print(Option_t *chopt="") const override
Print graph values.
Definition TGraph.cxx:2045
virtual void SetMaximum(Double_t maximum=-1111)
Set the maximum of the graph.
Definition TGraph.cxx:2371
static Bool_t CompareY(const TGraph *gr, Int_t left, Int_t right)
Return kTRUE if fY[left] > fY[right]. Can be used by Sort.
Definition TGraph.cxx:741
static Bool_t CompareRadius(const TGraph *gr, Int_t left, Int_t right)
Return kTRUE if point number "left"'s distance to origin is bigger than that of point number "right".
Definition TGraph.cxx:750
virtual Double_t GetErrorYhigh(Int_t bin) const
It always returns a negative value.
Definition TGraph.cxx:1429
TClass * IsA() const override
Definition TGraph.h:202
static Bool_t CompareX(const TGraph *gr, Int_t left, Int_t right)
Return kTRUE if fX[left] > fX[right]. Can be used by Sort.
Definition TGraph.cxx:733
Int_t GetN() const
Definition TGraph.h:131
TF1 * GetFunction(const char *name) const
Return pointer to function with name.
Definition TGraph.cxx:1449
virtual void LeastSquareLinearFit(Int_t n, Double_t &a0, Double_t &a1, Int_t &ifail, Double_t xmin=0, Double_t xmax=0)
Least square linear fit without weights.
Definition TGraph.cxx:1963
Double_t * fY
[fNpoints] array of Y points
Definition TGraph.h:48
Bool_t CtorAllocate()
In constructors set fNpoints than call this method.
Definition TGraph.cxx:833
virtual void DrawGraph(Int_t n, const Int_t *x, const Int_t *y, Option_t *option="")
Draw this graph with new attributes.
Definition TGraph.cxx:917
virtual TFitResultPtr Fit(const char *formula, Option_t *option="", Option_t *goption="", Axis_t xmin=0, Axis_t xmax=0)
Fit this graph with the global function named fname.
Definition TGraph.cxx:1287
virtual void Sort(Bool_t(*greater)(const TGraph *, Int_t, Int_t)=&TGraph::CompareX, Bool_t ascending=kTRUE, Int_t low=0, Int_t high=-1111)
Sorts the points of this TGraph using in-place quicksort (see e.g.
Definition TGraph.cxx:2533
static Bool_t CompareArg(const TGraph *gr, Int_t left, Int_t right)
Return kTRUE if point number "left"'s argument (angle with respect to positive x-axis) is bigger than...
Definition TGraph.cxx:722
virtual void ComputeRange(Double_t &xmin, Double_t &ymin, Double_t &xmax, Double_t &ymax) const
Compute the x/y range of the points in this graph.
Definition TGraph.cxx:759
char * GetObjectInfo(Int_t px, Int_t py) const override
Implementation to get information on point of graph at cursor position Adapted from class TH1.
Definition TGraph.cxx:1617
Double_t ** AllocateArrays(Int_t Narrays, Int_t arraySize)
Allocate arrays.
Definition TGraph.cxx:626
virtual void Scale(Double_t c1=1., Option_t *option="y")
Multiply the values of a TGraph by a constant c1.
Definition TGraph.cxx:2299
TList * fFunctions
Pointer to list of functions (fits and user)
Definition TGraph.h:49
virtual Double_t GetCovariance() const
Return covariance of vectors x,y.
Definition TGraph.cxx:1341
static void SwapValues(Double_t *arr, Int_t pos1, Int_t pos2)
Swap values.
Definition TGraph.cxx:2658
void Streamer(TBuffer &) override
Stream an object of class TGraph.
Definition TGraph.cxx:2563
void Zero(Int_t &k, Double_t AZ, Double_t BZ, Double_t E2, Double_t &X, Double_t &Y, Int_t maxiterations)
Find zero of a continuous function.
Definition TGraph.cxx:2764
virtual Double_t ** Allocate(Int_t newsize)
Allocate internal data structures for newsize points.
Definition TGraph.cxx:618
virtual void FitPanel()
Display a GUI panel with all graph fit options.
Definition TGraph.cxx:1307
void Browse(TBrowser *b) override
Browse.
Definition TGraph.cxx:679
virtual Bool_t DoMerge(const TGraph *g)
protected function to perform the merge operation of a graph
Definition TGraph.cxx:2723
virtual void InsertPointBefore(Int_t ipoint, Double_t x, Double_t y)
Insert a new point with coordinates (x,y) before the point number ipoint.
Definition TGraph.cxx:1781
TList * GetListOfFunctions() const
Definition TGraph.h:125
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Execute action corresponding to one event.
Definition TGraph.cxx:1084
Double_t * GetX() const
Definition TGraph.h:138
void SaveAs(const char *filename="graph", Option_t *option="") const override
Save the graph as .csv, .tsv or .txt.
Definition TGraph.cxx:2136
virtual Double_t Eval(Double_t x, TSpline *spline=nullptr, Option_t *option="") const
Interpolate points in this graph at x using a TSpline.
Definition TGraph.cxx:981
virtual void InitExpo(Double_t xmin=0, Double_t xmax=0)
Compute Initial values of parameters for an exponential.
Definition TGraph.cxx:1690
virtual Int_t RemovePoint()
Delete point close to the mouse position Returns index of removed point (or -1 if nothing was changed...
Definition TGraph.cxx:2069
virtual void InitGaus(Double_t xmin=0, Double_t xmax=0)
Compute Initial values of parameters for a gaussian.
Definition TGraph.cxx:1652
virtual Bool_t IsHighlight() const
Definition TGraph.h:166
virtual void Add(TF1 *f, Double_t c1=1)
Performs the operation: y = y + c1*f(x,y) Errors are not recalculated.
Definition TGraph.cxx:650
virtual void Apply(TF1 *f)
Apply function f to all the data points f may be a 1-D function TF1 or 2-d function TF2 The Y values ...
Definition TGraph.cxx:666
void SetName(const char *name="") override
Set graph name.
Definition TGraph.cxx:2428
virtual void SetHighlight(Bool_t set=kTRUE)
Set highlight (enable/disable) mode for the graph by default highlight mode is disable.
Definition TGraph.cxx:2351
virtual void SwapPoints(Int_t pos1, Int_t pos2)
Swap points.
Definition TGraph.cxx:2630
void Draw(Option_t *chopt="") override
Draw this graph with its current attributes.
Definition TGraph.cxx:859
TAxis * GetXaxis() const
Get x axis of the graph.
Definition TGraph.cxx:1598
Bool_t GetEditable() const
Return kTRUE if kNotEditable bit is not set, kFALSE otherwise.
Definition TGraph.cxx:2332
virtual Double_t GetCorrelationFactor() const
Return graph correlation factor.
Definition TGraph.cxx:1329
virtual void FillZero(Int_t begin, Int_t end, Bool_t from_ctor=kTRUE)
Set zero values for point arrays in the range [begin, end) Should be redefined in descendant classes.
Definition TGraph.cxx:1130
Double_t ** ExpandAndCopy(Int_t size, Int_t iend)
if size > fMaxSize allocate new arrays of 2*size points and copy iend first points.
Definition TGraph.cxx:1117
virtual void Expand(Int_t newsize)
If array sizes <= newsize, expand storage to 2*newsize.
Definition TGraph.cxx:1093
void SaveHistogramAndFunctions(std::ostream &out, const char *varname, Option_t *option)
Save histogram and list of functions of TGraph as C++ statement Used in all TGraph-derived classes.
Definition TGraph.cxx:2253
virtual Double_t GetMean(Int_t axis=1) const
Return mean value of X (axis=1) or Y (axis=2)
Definition TGraph.cxx:1357
Double_t * fX
[fNpoints] array of X points
Definition TGraph.h:47
virtual void PaintStats(TF1 *fit)
Draw the stats.
Definition TGraph.cxx:2036
TAxis * GetYaxis() const
Get y axis of the graph.
Definition TGraph.cxx:1607
TObject * FindObject(const char *name) const override
Search object named name in the list of functions.
Definition TGraph.cxx:1139
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
Definition TGraph.cxx:2478
virtual TH1F * GetHistogram() const
Returns a pointer to the histogram used to draw the axis Takes into account the two following cases.
Definition TGraph.cxx:1460
virtual Double_t GetErrorY(Int_t bin) const
It always returns a negative value. Real implementation in TGraphErrors.
Definition TGraph.cxx:1402
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save primitive as a C++ statement(s) on output stream out.
Definition TGraph.cxx:2235
virtual Double_t GetPointY(Int_t i) const
Get y value for point i.
Definition TGraph.cxx:1587
Double_t fMinimum
Minimum value for plotting along y.
Definition TGraph.h:51
void PaintGraph(Int_t npoints, const Double_t *x, const Double_t *y, Option_t *chopt)
Draw the (x,y) as a graph.
Definition TGraph.cxx:2018
void SetTitle(const char *title="") override
Change (i.e.
Definition TGraph.cxx:2444
virtual Int_t InsertPoint()
Insert a new point at the mouse position.
Definition TGraph.cxx:1731
void RecursiveRemove(TObject *obj) override
Recursively remove object from the list of functions.
Definition TGraph.cxx:2055
virtual void SetPointY(Int_t i, Double_t y)
Set y value for point i.
Definition TGraph.cxx:2421
Int_t DistancetoPrimitive(Int_t px, Int_t py) override
Compute distance from point px,py to a graph.
Definition TGraph.cxx:907
virtual void SetHistogram(TH1F *h)
Set the histogram underlying the TGraph. This transfers the ownership of h to the TGraph....
Definition TGraph.cxx:2362
virtual void DrawPanel()
Display a panel with all graph drawing options.
Definition TGraph.cxx:960
void PaintGrapHist(Int_t npoints, const Double_t *x, const Double_t *y, Option_t *chopt)
Draw the (x,y) as a histogram.
Definition TGraph.cxx:2027
void SetNameTitle(const char *name="", const char *title="") override
Set graph name and title.
Definition TGraph.cxx:2464
virtual void SetPointX(Int_t i, Double_t x)
Set x value for point i.
Definition TGraph.cxx:2413
virtual void Set(Int_t n)
Set number of points in the graph Existing coordinates are preserved New coordinates above fNpoints a...
Definition TGraph.cxx:2317
virtual Int_t GetPoint(Int_t i, Double_t &x, Double_t &y) const
Get x and y values for point number i.
Definition TGraph.cxx:1565
virtual void SetEditable(Bool_t editable=kTRUE)
if editable=kFALSE, the graph cannot be modified with the mouse by default a TGraph is editable
Definition TGraph.cxx:2341
virtual void SetMinimum(Double_t minimum=-1111)
Set the minimum of the graph.
Definition TGraph.cxx:2380
TGraph()
Graph default constructor.
Definition TGraph.cxx:125
virtual Bool_t CopyPoints(Double_t **newarrays, Int_t ibegin, Int_t iend, Int_t obegin)
Copy points from fX and fY to arrays[0] and arrays[1] or to fX and fY if arrays == 0 and ibegin !...
Definition TGraph.cxx:807
Double_t fMaximum
Maximum value for plotting along y.
Definition TGraph.h:52
virtual Double_t GetErrorXhigh(Int_t bin) const
It always returns a negative value.
Definition TGraph.cxx:1411
TGraph & operator=(const TGraph &)
Equal operator for this graph.
Definition TGraph.cxx:249
virtual void InitPolynom(Double_t xmin=0, Double_t xmax=0)
Compute Initial values of parameters for a polynom.
Definition TGraph.cxx:1711
virtual Double_t GetErrorX(Int_t bin) const
It always returns a negative value. Real implementation in TGraphErrors.
Definition TGraph.cxx:1394
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:878
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:109
virtual void SetDirectory(TDirectory *dir)
By default, when a histogram is created, it is added to the list of histogram objects in the current ...
Definition TH1.cxx:9170
void SetTitle(const char *title) override
Change/set the title.
Definition TH1.cxx:6932
void UseCurrentStyle() override
Copy current attributes from/to current style.
Definition TH1.cxx:7678
@ kNoStats
Don't draw stats box.
Definition TH1.h:403
TAxis * GetXaxis()
Definition TH1.h:571
virtual void SetMaximum(Double_t maximum=-1111)
Definition TH1.h:652
TAxis * GetYaxis()
Definition TH1.h:572
virtual void SetMinimum(Double_t minimum=-1111)
Definition TH1.h:653
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save primitive as a C++ statement(s) on output stream out.
Definition TH1.cxx:7485
void SetName(const char *name) override
Change the name of this histogram.
Definition TH1.cxx:9193
TObject * Clone(const char *newname="") const override
Make a complete copy of the underlying object.
Definition TH1.cxx:2882
static void SavePrimitiveFunctions(std::ostream &out, const char *varname, TList *lst)
Save list of functions Also can be used by TGraph classes.
Definition TH1.cxx:7644
A doubly linked list.
Definition TList.h:38
TObject * FindObject(const char *name) const override
Find an object in this list using its name.
Definition TList.cxx:708
void RecursiveRemove(TObject *obj) override
Remove object from this collection and recursively remove the object from all other objects (and coll...
Definition TList.cxx:894
TObject * Remove(TObject *obj) override
Remove object from the list.
Definition TList.cxx:952
TObject * First() const override
Return the first object in the list. Returns 0 when list is empty.
Definition TList.cxx:789
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
void SavePrimitiveNameTitle(std::ostream &out, const char *variable_name)
Save object name and title into the output stream "out".
Definition TNamed.cxx:135
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition TNamed.cxx:173
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
void Streamer(TBuffer &) override
Stream an object of class TObject.
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:50
TString fTitle
Definition TNamed.h:33
TString fName
Definition TNamed.h:32
TNamed & operator=(const TNamed &rhs)
TNamed assignment operator.
Definition TNamed.cxx:50
Mother of all ROOT objects.
Definition TObject.h:42
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:204
virtual void UseCurrentStyle()
Set current style settings in this object This function is called when either TCanvas::UseCurrentStyl...
Definition TObject.cxx:909
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:1084
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition TObject.cxx:204
virtual void SaveAs(const char *filename="", Option_t *option="") const
Save this object in the file specified by filename.
Definition TObject.cxx:708
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:888
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:549
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1098
void MakeZombie()
Definition TObject.h:55
static void SavePrimitiveDraw(std::ostream &out, const char *variable_name, Option_t *option=nullptr)
Save invocation of primitive Draw() method Skipped if option contains "nodraw" string.
Definition TObject.cxx:845
static void SavePrimitiveConstructor(std::ostream &out, TClass *cl, const char *variable_name, const char *constructor_agrs="", Bool_t empty_line=kTRUE)
Save object constructor in the output stream "out".
Definition TObject.cxx:777
static TString SavePrimitiveVector(std::ostream &out, const char *prefix, Int_t len, Double_t *arr, Int_t flag=0)
Save array in the output stream "out" as vector.
Definition TObject.cxx:796
void ResetBit(UInt_t f)
Definition TObject.h:203
@ kCanDelete
if object in a list can be deleted
Definition TObject.h:71
@ kInvalidObject
if object ctor succeeded but object should not be used
Definition TObject.h:81
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:1072
Longptr_t ExecPlugin(int nargs)
Int_t LoadPlugin()
Load the plugin library for this handler.
Class to create third splines to interpolate knots Arbitrary conditions can be introduced for first a...
Definition TSpline.h:182
Double_t Eval(Double_t x) const override
Eval this spline at x.
Definition TSpline.cxx:780
Base class for spline implementation containing the Draw/Paint methods.
Definition TSpline.h:31
virtual Double_t Eval(Double_t x) const =0
Basic string class.
Definition TString.h:138
Ssiz_t Length() const
Definition TString.h:425
void ToLower()
Change string to lower-case.
Definition TString.cxx:1189
void Clear()
Clear string without changing its capacity.
Definition TString.cxx:1241
TString & Replace(Ssiz_t pos, Ssiz_t n, const char *s)
Definition TString.h:703
const char * Data() const
Definition TString.h:384
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition TString.h:713
@ kIgnoreCase
Definition TString.h:285
void ToUpper()
Change string to upper case.
Definition TString.cxx:1202
Bool_t IsNull() const
Definition TString.h:422
TString & Remove(Ssiz_t pos)
Definition TString.h:694
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2385
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition TString.cxx:2363
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:641
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition TString.h:660
void SetHistFillColor(Color_t color=1)
Definition TStyle.h:383
Color_t GetHistLineColor() const
Definition TStyle.h:235
Bool_t IsReading() const
Definition TStyle.h:300
void SetHistLineStyle(Style_t styl=0)
Definition TStyle.h:386
Style_t GetHistFillStyle() const
Definition TStyle.h:236
Color_t GetHistFillColor() const
Definition TStyle.h:234
void SetHistLineColor(Color_t color=1)
Definition TStyle.h:384
Style_t GetHistLineStyle() const
Definition TStyle.h:237
void SetHistFillStyle(Style_t styl=0)
Definition TStyle.h:385
Width_t GetHistLineWidth() const
Definition TStyle.h:238
void SetHistLineWidth(Width_t width=1)
Definition TStyle.h:387
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition TSystem.cxx:1289
TVectorT.
Definition TVectorT.h:29
Abstract Base Class for Fitting.
static TVirtualFitter * GetFitter()
static: return the current Fitter
Abstract interface to a histogram painter.
static TVirtualGraphPainter * GetPainter()
Static function returning a pointer to the current graph painter.
TLine * line
Double_t y[n]
Definition legend1.C:17
return c1
Definition legend1.C:41
Double_t x[n]
Definition legend1.C:17
Double_t ey[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
TGraphErrors * gr
Definition legend1.C:25
Double_t ex[n]
Definition legend1.C:17
TF1 * f1
Definition legend1.C:11
TFitResultPtr FitObject(TH1 *h1, TF1 *f1, Foption_t &option, const ROOT::Math::MinimizerOptions &moption, const char *goption, ROOT::Fit::DataRange &range)
fitting function for a TH1 (called from TH1::Fit)
Definition HFitImpl.cxx:979
double Chisquare(const TH1 &h1, TF1 &f1, bool useRange, EChisquareType type, bool useIntegral=false)
compute the chi2 value for an histogram given a function (see TH1::Chisquare for the documentation)
void FitOptionsMake(EFitObjectType type, const char *option, Foption_t &fitOption)
Decode list of options into fitOption.
Definition HFitImpl.cxx:685
Bool_t IsInside(T xp, T yp, Int_t np, T *x, T *y)
Function which returns kTRUE if point xp,yp lies inside the polygon defined by the np points in array...
Definition TMath.h:1320
Double_t Exp(Double_t x)
Returns the base-e exponential function of x, which is e raised to the power x.
Definition TMath.h:720
Double_t ATan2(Double_t y, Double_t x)
Returns the principal value of the arc tangent of y/x, expressed in radians.
Definition TMath.h:657
Double_t Log(Double_t x)
Returns the natural logarithm of x.
Definition TMath.h:767
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:673
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Definition TMathBase.h:197
void Sort(Index n, const Element *a, Index *index, Bool_t down=kTRUE)
Sort the n elements of the array a of generic templated type Element.
Definition TMathBase.h:413
Long64_t BinarySearch(Long64_t n, const T *array, T value)
Binary search in an array of n values to locate value.
Definition TMathBase.h:329
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:122
th1 Draw()
TMarker m
Definition textangle.C:8
TLine l
Definition textangle.C:4
static uint64_t sum(uint64_t i)
Definition Factory.cxx:2338