73 if (!CtorAllocate())
return;
100 for (
Int_t i = 0; i <
n; i++) {
101 if (ex)
fEX[i] = ex[i];
103 if (ey)
fEY[i] = ey[i];
120 if (ex) memcpy(
fEX, ex, n);
121 else memset(
fEX, 0, n);
122 if (ey) memcpy(
fEY, ey, n);
123 else memset(
fEY, 0, n);
135 :
TGraph(
TMath::
Min(vx.GetNrows(), vy.GetNrows()), vx.GetMatrixArray(), vy.GetMatrixArray() )
141 fEX[i] = vex(i + ivexlow);
142 fEY[i] = vey(i + iveylow);
155 :
TGraph(
TMath::
Min(vx.GetNrows(), vy.GetNrows()), vx.GetMatrixArray(), vy.GetMatrixArray() )
161 fEX[i] = vex(i + ivexlow);
162 fEY[i] = vey(i + iveylow);
239 std::ifstream infile(fname.
Data());
240 if (!infile.good()) {
242 Error(
"TGraphErrors",
"Cannot open file: %s, TGraphErrors is Zombie", filename);
249 if (strcmp(option,
"") == 0) {
253 while (std::getline(infile, line,
'\n')) {
256 res = sscanf(line.c_str(),
format, &
x, &
y);
257 }
else if (ncol < 4) {
258 res = sscanf(line.c_str(),
format, &
x, &
y, &
ey);
282 Error(
"TGraphErrors",
"Incorrect input format! Allowed format tags are {\"%%lg\",\"%%*lg\" or \"%%*s\"}");
287 Error(
"TGraphErrors",
"Incorrect input format! Only %d tag(s) in format whereas at least 2 \"%%lg\" tags are expected!", ntokens);
290 Int_t ntokensToBeSaved = 0 ;
292 for (
Int_t idx = 0; idx < ntokens; idx++) {
294 if (isTokenToBeSaved[idx] == 1) {
298 if (ntokens >= 2 && (ntokensToBeSaved < 2 || ntokensToBeSaved > 4)) {
299 Error(
"TGraphErrors",
"Incorrect input format! There are %d \"%%lg\" tag(s) in format whereas 2,3 or 4 are expected!", ntokensToBeSaved);
300 delete [] isTokenToBeSaved ;
306 char * token =
NULL ;
308 Int_t token_idx = 0 ;
310 for (
Int_t k = 0; k < 4; k++) {
313 Int_t value_idx = 0 ;
316 while (std::getline(infile, line,
'\n')) {
318 if (line[line.size() - 1] == char(13)) {
319 line.erase(line.end() - 1, line.end()) ;
321 token = strtok(const_cast<char*>(line.c_str()), option) ;
322 while (token !=
NULL && value_idx < ntokensToBeSaved) {
323 if (isTokenToBeSaved[token_idx]) {
327 isLineToBeSkipped =
kTRUE ;
330 value[value_idx] = token_str.
Atof() ;
334 token = strtok(
NULL, option) ;
337 if (!isLineToBeSkipped && value_idx > 1) {
347 isLineToBeSkipped =
kFALSE ;
355 delete [] isTokenToBeSaved ;
412 while ((fmt = strchr(fmt,
'%'))) {
416 if (*++fmt &&
'^' == *fmt) ++fmt;
417 if (*++fmt &&
']' == *fmt) ++fmt;
418 while (*fmt && *fmt !=
']')
423 if (
'%' == *fmt)
break;
426 }
else if (strchr(
"dDiouxXxfegEscpn", *fmt)) {
445 if (
fX[i] -
fEX[i] < xmin) {
450 xmin =
fX[i] -
fEX[i];
453 if (
fX[i] +
fEX[i] > xmax) xmax =
fX[i] +
fEX[i];
454 if (
fY[i] -
fEY[i] < ymin) {
459 ymin =
fY[i] -
fEY[i];
462 if (
fY[i] +
fEY[i] > ymax) ymax =
fY[i] +
fEY[i];
498 memmove(&arrays[0][obegin], &
fEX[ibegin], n);
499 memmove(&arrays[1][obegin], &
fEY[ibegin], n);
501 memmove(&
fEX[obegin], &
fEX[ibegin], n);
502 memmove(&
fEY[obegin], &
fEY[ibegin], n);
538 if (ex == 0 || ey == 0 ) {
540 Warning(
"DoMerge",
"Merging a %s is not compatible with a TGraphErrors - errors will be ignored",g->IsA()->
GetName());
563 memset(
fEX + begin, 0, n);
564 memset(
fEY + begin, 0, n);
574 if (i < 0 || i >=
fNpoints)
return -1;
586 if (i < 0 || i >=
fNpoints)
return -1;
598 if (i < 0 || i >=
fNpoints)
return -1;
610 if (i < 0 || i >=
fNpoints)
return -1;
622 if (i < 0 || i >=
fNpoints)
return -1;
634 if (i < 0 || i >=
fNpoints)
return -1;
650 "Cannot merge - an object which doesn't inherit from TGraph found in the list");
654 int n1 = n0+g->
GetN();
662 if (ex)
fEX[n0+i] = ex[i];
663 if (ey)
fEY[n0+i] = ey[i];
675 printf(
"x[%d]=%g, y[%d]=%g, ex[%d]=%g, ey[%d]=%g\n", i,
fX[i], i,
fY[i], i,
fEX[i], i,
fEY[i]);
686 out <<
" " << std::endl;
687 static Int_t frameNumber = 1000;
695 out <<
" Double_t " << fXName <<
"[" <<
fNpoints <<
"] = {" << std::endl;
696 for (i = 0; i <
fNpoints-1; i++) out <<
" " <<
fX[i] <<
"," << std::endl;
697 out <<
" " <<
fX[fNpoints-1] <<
"};" << std::endl;
698 out <<
" Double_t " << fYName <<
"[" << fNpoints <<
"] = {" << std::endl;
699 for (i = 0; i < fNpoints-1; i++) out <<
" " <<
fY[i] <<
"," << std::endl;
700 out <<
" " <<
fY[fNpoints-1] <<
"};" << std::endl;
701 out <<
" Double_t " << fEXName <<
"[" << fNpoints <<
"] = {" << std::endl;
702 for (i = 0; i < fNpoints-1; i++) out <<
" " <<
fEX[i] <<
"," << std::endl;
703 out <<
" " <<
fEX[fNpoints-1] <<
"};" << std::endl;
704 out <<
" Double_t " << fEYName <<
"[" << fNpoints <<
"] = {" << std::endl;
705 for (i = 0; i < fNpoints-1; i++) out <<
" " <<
fEY[i] <<
"," << std::endl;
706 out <<
" " <<
fEY[fNpoints-1] <<
"};" << std::endl;
709 else out <<
" TGraphErrors *";
710 out <<
"gre = new TGraphErrors(" << fNpoints <<
"," 711 << fXName <<
"," << fYName <<
"," 712 << fEXName <<
"," << fEYName <<
");" 715 out <<
" gre->SetName(" << quote <<
GetName() << quote <<
");" << std::endl;
716 out <<
" gre->SetTitle(" << quote <<
GetTitle() << quote <<
");" << std::endl;
724 hname += frameNumber;
728 out <<
" " << std::endl;
734 while ((obj = next())) {
737 out <<
" gre->GetListOfFunctions()->Add(ptstats);" << std::endl;
738 out <<
" ptstats->SetParent(gre->GetListOfFunctions());" << std::endl;
740 out <<
" gre->GetListOfFunctions()->Add(" 741 <<
Form(
"%s%d",obj->
GetName(),frameNumber) <<
");" << std::endl;
745 const char *
l = strstr(option,
"multigraph");
747 out <<
" multigraph->Add(gre," << quote << l + 10 << quote <<
");" << std::endl;
749 out <<
" gre->Draw(" << quote << option << quote <<
");" << std::endl;
769 if (dpx * dpx + dpy * dpy < 25) {
774 if (ipoint == -2)
return;
800 void TGraphErrors::Streamer(
TBuffer &
b)
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save primitive as a C++ statement(s) on output stream out.
Int_t fNpoints
Number of points <= fMaxSize.
virtual const char * GetName() const
Returns name of object.
Double_t * fX
[fNpoints] array of X points
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
virtual Double_t * GetEX() const
Double_t GetErrorYlow(Int_t bin) const
This function is called by GraphFitChisquare.
virtual Bool_t DoMerge(const TGraph *g)
protected function to perform the merge operation of a graph with errors
virtual ~TGraphErrors()
TGraphErrors default destructor.
TString & ReplaceAll(const TString &s1, const TString &s2)
R__EXTERN TStyle * gStyle
Double_t GetErrorYhigh(Int_t bin) const
This function is called by GraphFitChisquare.
Bool_t IsFloat() const
Returns kTRUE if string contains a floating point or integer number.
Buffer base class used for serializing objects.
virtual Double_t * GetEY() const
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=0
Short_t Min(Short_t a, Short_t b)
TList * fFunctions
Pointer to list of functions (fits and user)
TH1F * fHistogram
Pointer to histogram used for drawing axis.
static std::string format(double x, double y, int digits, int width)
TGraphErrors()
TGraphErrors default constructor.
virtual Bool_t CopyPoints(Double_t **arrays, Int_t ibegin, Int_t iend, Int_t obegin)
Copy errors from fEX and fEY to arrays[0] and arrays[1] or to fX and fY.
virtual Int_t Merge(TCollection *list)
Adds all graphs with errors from the collection to this graph.
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 != ie...
Double_t GetErrorXlow(Int_t bin) const
This function is called by GraphFitChisquare.
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
TGraph & operator=(const TGraph &)
Equal operator for this graph.
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.
virtual void SwapPoints(Int_t pos1, Int_t pos2)
Swap points.
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save primitive as a C++ statement(s) on output stream out.
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.
Double_t GetErrorX(Int_t bin) const
This function is called by GraphFitChisquare.
Float_t GetErrorX() const
virtual Int_t GetPoint(Int_t i, Double_t &x, Double_t &y) const
Get x and y values for point number i.
virtual void SwapPoints(Int_t pos1, Int_t pos2)
Swap points.
R__EXTERN TSystem * gSystem
TGraphErrors & operator=(const TGraphErrors &gr)
TGraphErrors assignment operator.
virtual void ComputeRange(Double_t &xmin, Double_t &ymin, Double_t &xmax, Double_t &ymax) const
Compute range.
static void SwapValues(Double_t *arr, Int_t pos1, Int_t pos2)
Swap values.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Collection abstract base class.
virtual Bool_t DoMerge(const TGraph *g)
protected function to perform the merge operation of a graph
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.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
char * Form(const char *fmt,...)
virtual void Apply(TF1 *f)
apply function to all the data points y = f(x,y)
virtual void CopyAndRelease(Double_t **newarrays, Int_t ibegin, Int_t iend, Int_t obegin)
Copy and release.
virtual void ReadFastArray(Bool_t *b, Int_t n)=0
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].
virtual void SetName(const char *name)
Change the name of this histogram.
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=0)=0
Double_t * fEX
[fNpoints] array of X errors
virtual Double_t Eval(Double_t x, Double_t y=0, Double_t z=0, Double_t t=0) const
Evaluate this function.
Double_t GetErrorY(Int_t bin) const
This function is called by GraphFitChisquare.
virtual Double_t GetBinWidth(Int_t bin) const
Return bin width for 1D histogram.
Mother of all ROOT objects.
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...
virtual void SetPoint(Int_t i, Double_t x, Double_t y)
Set x and y values for point number i.
Double_t * fY
[fNpoints] array of Y points
Bool_t CtorAllocate()
Constructor allocate.
A Graph is a graphics object made of two arrays X and Y with npoints each.
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
A TGraphErrors is a TGraph with error bars.
Int_t Atoi() const
Return integer value of string.
static Int_t CalculateScanfFields(const char *fmt)
Calculate scan fields.
Double_t Atof() const
Return floating-point value contained in string.
Bool_t IsDigit() const
Returns true if all characters in string are digits (0-9) or white spaces, i.e.
Double_t * fEY
[fNpoints] array of Y errors
virtual void Print(Option_t *chopt="") const
Print graph and errors values.
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Int_t fMaxSize
!Current dimension of arrays fX and fY
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.
virtual void SetPointError(Double_t ex, Double_t ey)
Set ex and ey values for point pointed by the mouse.
Double_t GetErrorXhigh(Int_t bin) const
This function is called by GraphFitChisquare.
virtual const char * GetName() const
Returns name of object.
virtual void Set(Int_t n)
Set number of points in the graph Existing coordinates are preserved New coordinates above fNpoints a...
static char * skip(char **buf, const char *delimiters)
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)=0
virtual const char * GetTitle() const
Returns title of object.
virtual Double_t GetBinError(Int_t bin) const
Return value of error associated to bin number bin.
const char * Data() const
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream "out".