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);
241 Error(
"TGraphErrors",
"Cannot open file: %s, TGraphErrors is Zombie", filename);
248 if (strcmp(option,
"") == 0) {
252 while (std::getline(
infile, line,
'\n')) {
255 res = sscanf(line.c_str(),
format, &
x, &
y);
256 }
else if (ncol < 4) {
257 res = sscanf(line.c_str(),
format, &
x, &
y, &
ey);
281 Error(
"TGraphErrors",
"Incorrect input format! Allowed format tags are {\"%%lg\",\"%%*lg\" or \"%%*s\"}");
286 Error(
"TGraphErrors",
"Incorrect input format! Only %d tag(s) in format whereas at least 2 \"%%lg\" tags are expected!", ntokens);
289 Int_t ntokensToBeSaved = 0 ;
291 for (
Int_t idx = 0; idx < ntokens; idx++) {
293 if (isTokenToBeSaved[idx] == 1) {
297 if (ntokens >= 2 && (ntokensToBeSaved < 2 || ntokensToBeSaved > 4)) {
298 Error(
"TGraphErrors",
"Incorrect input format! There are %d \"%%lg\" tag(s) in format whereas 2,3 or 4 are expected!", ntokensToBeSaved);
299 delete [] isTokenToBeSaved ;
305 char * token =
NULL ;
307 Int_t token_idx = 0 ;
309 for (
Int_t k = 0; k < 4; k++) {
312 Int_t value_idx = 0 ;
315 while (std::getline(
infile, line,
'\n')) {
317 if (line[line.size() - 1] == char(13)) {
318 line.erase(line.end() - 1, line.end()) ;
320 token = strtok(const_cast<char*>(line.c_str()), option) ;
321 while (token !=
NULL && value_idx < ntokensToBeSaved) {
322 if (isTokenToBeSaved[token_idx]) {
326 isLineToBeSkipped =
kTRUE ;
329 value[value_idx] = token_str.
Atof() ;
333 token = strtok(
NULL, option) ;
336 if (!isLineToBeSkipped && value_idx > 1) {
346 isLineToBeSkipped =
kFALSE ;
354 delete [] isTokenToBeSaved ;
411 while ((fmt = strchr(fmt,
'%'))) {
415 if (*++fmt &&
'^' == *fmt) ++fmt;
416 if (*++fmt &&
']' == *fmt) ++fmt;
417 while (*fmt && *fmt !=
']')
422 if (
'%' == *fmt)
break;
425 }
else if (strchr(
"dDiouxXxfegEscpn", *fmt)) {
444 if (
fX[i] -
fEX[i] < xmin) {
449 xmin =
fX[i] -
fEX[i];
452 if (
fX[i] +
fEX[i] > xmax) xmax =
fX[i] +
fEX[i];
453 if (
fY[i] -
fEY[i] < ymin) {
458 ymin =
fY[i] -
fEY[i];
461 if (
fY[i] +
fEY[i] > ymax) ymax =
fY[i] +
fEY[i];
497 memmove(&arrays[0][obegin], &
fEX[ibegin], n);
498 memmove(&arrays[1][obegin], &
fEY[ibegin], n);
500 memmove(&
fEX[obegin], &
fEX[ibegin], n);
501 memmove(&
fEY[obegin], &
fEY[ibegin], n);
537 if (ex == 0 || ey == 0 ) {
539 Warning(
"DoMerge",
"Merging a %s is not compatible with a TGraphErrors - errors will be ignored",g->IsA()->
GetName());
562 memset(
fEX + begin, 0, n);
563 memset(
fEY + begin, 0, n);
573 if (i < 0 || i >=
fNpoints)
return -1;
585 if (i < 0 || i >=
fNpoints)
return -1;
597 if (i < 0 || i >=
fNpoints)
return -1;
609 if (i < 0 || i >=
fNpoints)
return -1;
621 if (i < 0 || i >=
fNpoints)
return -1;
633 if (i < 0 || i >=
fNpoints)
return -1;
646 TGraph *
g =
dynamic_cast<TGraph*
>(o);
649 "Cannot merge - an object which doesn't inherit from TGraph found in the list");
653 int n1 = n0+g->
GetN();
661 if (ex)
fEX[n0+i] = ex[i];
662 if (ey)
fEY[n0+i] = ey[i];
674 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]);
685 out <<
" " << std::endl;
686 static Int_t frameNumber = 1000;
694 out <<
" Double_t " << fXName <<
"[" <<
fNpoints <<
"] = {" << std::endl;
695 for (i = 0; i <
fNpoints-1; i++) out <<
" " <<
fX[i] <<
"," << std::endl;
696 out <<
" " <<
fX[fNpoints-1] <<
"};" << std::endl;
697 out <<
" Double_t " << fYName <<
"[" << fNpoints <<
"] = {" << std::endl;
698 for (i = 0; i < fNpoints-1; i++) out <<
" " <<
fY[i] <<
"," << std::endl;
699 out <<
" " <<
fY[fNpoints-1] <<
"};" << std::endl;
700 out <<
" Double_t " << fEXName <<
"[" << fNpoints <<
"] = {" << std::endl;
701 for (i = 0; i < fNpoints-1; i++) out <<
" " <<
fEX[i] <<
"," << std::endl;
702 out <<
" " <<
fEX[fNpoints-1] <<
"};" << std::endl;
703 out <<
" Double_t " << fEYName <<
"[" << fNpoints <<
"] = {" << std::endl;
704 for (i = 0; i < fNpoints-1; i++) out <<
" " <<
fEY[i] <<
"," << std::endl;
705 out <<
" " <<
fEY[fNpoints-1] <<
"};" << std::endl;
708 else out <<
" TGraphErrors *";
709 out <<
"gre = new TGraphErrors(" << fNpoints <<
","
710 << fXName <<
"," << fYName <<
","
711 << fEXName <<
"," << fEYName <<
");"
714 out <<
" gre->SetName(" << quote <<
GetName() << quote <<
");" << std::endl;
715 out <<
" gre->SetTitle(" << quote <<
GetTitle() << quote <<
");" << std::endl;
723 hname += frameNumber;
727 out <<
" " << std::endl;
733 while ((obj =
next())) {
736 out <<
" gre->GetListOfFunctions()->Add(ptstats);" << std::endl;
737 out <<
" ptstats->SetParent(gre->GetListOfFunctions());" << std::endl;
739 out <<
" gre->GetListOfFunctions()->Add("
740 <<
Form(
"%s%d",obj->
GetName(),frameNumber) <<
");" << std::endl;
744 const char *
l = strstr(option,
"multigraph");
746 out <<
" multigraph->Add(gre," << quote << l + 10 << quote <<
");" << std::endl;
748 out <<
" gre->Draw(" << quote << option << quote <<
");" << std::endl;
768 if (dpx * dpx + dpy * dpy < 25) {
773 if (ipoint == -2)
return;
799 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
Current dimension of arrays fX and fY.
virtual const char * GetTitle() const
Returns title of object.
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
virtual void Print(Option_t *chopt="") const
Print graph and errors values.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
Double_t GetErrorX(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
Double_t GetErrorXlow(Int_t bin) const
This function is called by GraphFitChisquare.
virtual ~TGraphErrors()
TGraphErrors default destructor.
TString & ReplaceAll(const TString &s1, const TString &s2)
R__EXTERN TStyle * gStyle
Double_t Atof() const
Return floating-point value contained in string.
Buffer base class used for serializing objects.
Double_t GetErrorYhigh(Int_t bin) const
This function is called by GraphFitChisquare.
static const char * filename()
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=0
Short_t Min(Short_t a, Short_t b)
static std::string format(double x, double y, int digits, int width)
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 Double_t * GetEY() const
virtual Double_t GetBinWidth(Int_t bin) const
return bin width for 1D historam Better to use h1.GetXaxis().GetBinWidth(bin)
const char * Data() const
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...
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 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.
Int_t Atoi() const
Return integer value of string.
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 void Error(const char *method, const char *msgfmt,...) const
Issue error message.
virtual void SwapPoints(Int_t pos1, Int_t pos2)
Swap points.
R__EXTERN TSystem * gSystem
TGraphErrors & operator=(const TGraphErrors &gr)
TGraphErrors assignment operator.
static void SwapValues(Double_t *arr, Int_t pos1, Int_t pos2)
Swap values.
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.
char * Form(const char *fmt,...)
virtual const char * GetName() const
Returns name of object.
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
Float_t GetErrorX() const
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
virtual const char * GetName() const
Returns name of object.
Double_t GetErrorY(Int_t bin) const
This function is called by GraphFitChisquare.
ClassImp(TMCParticle) void TMCParticle printf(": p=(%7.3f,%7.3f,%9.3f) ;", fPx, fPy, fPz)
Bool_t IsFloat() const
Returns kTRUE if string contains a floating point or integer number.
virtual Int_t GetPoint(Int_t i, Double_t &x, Double_t &y) const
Get x and y values for point number i.
Double_t GetErrorYlow(Int_t bin) const
This function is called by GraphFitChisquare.
Mother of all ROOT objects.
Bool_t IsDigit() const
Returns true if all characters in string are digits (0-9) or white spaces, i.e.
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.
Bool_t CtorAllocate()
Constructor allocate.
virtual Double_t Eval(Double_t x, Double_t y=0, Double_t z=0, Double_t t=0) const
Evaluate this function.
A TGraphErrors is a TGraph with error bars.
static Int_t CalculateScanfFields(const char *fmt)
Calculate scan fields.
virtual Double_t * GetEX() const
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
virtual void SetPointError(Double_t ex, Double_t ey)
Set ex and ey values for point pointed by the mouse.
virtual void Set(Int_t n)
Set number of points in the graph Existing coordinates are preserved New coordinates above fNpoints a...
virtual Double_t GetBinError(Int_t bin) const
Return value of error associated to bin number bin.
Double_t GetErrorXhigh(Int_t bin) const
This function is called by GraphFitChisquare.
static char * skip(char **buf, const char *delimiters)
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)=0
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream "out".
virtual void ComputeRange(Double_t &xmin, Double_t &ymin, Double_t &xmax, Double_t &ymax) const
Compute range.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.