TGraph Drawn like TVectorD

Hi, I had a script where I made plots by directly using the .Draw() method on a TVectorD, where the content of the vector was drawn on the Y axis, and the X axis was just the index. I need to rescale the index to make it have real units, so I tried making a TGraph with the original TVector as the Y values, and another TVector of the appropriate values.

My problem is that the appearance is changed from one case to the other. TVectorD::Draw() makes a histogram-like thing, where each data point is a horizontal bar extending from the index i to the index i+1. The TGraph has many draw options (AL, AP, AC, etc), but none of the draw options make it look like the original TVectorD::Draw().

Can anyone suggest a good way to make the TGraph look like the original drawn TVector? Or another way to rescale the X-axis on a directly drawn TVector?

Note that this is related to my post two years ago: Suggestion for new TGraph Constructor , but I didn’t want to resurrect it.


[code]#include “TVectorD.h”
#include “TGraph.h”

TGraph *TVectorD2TGraph(TVectorD *v)
if (!v) return ((TGraph *)0); // just a precaution
TGraph *g = new TGraph( (2 * v->GetNoElements()) );
for (Int_t i = 0; i < v->GetNoElements(); i++) {
(g->GetX())[(2 * i)] = ((Double_t)i);
(g->GetX())[(2 * i + 1)] = ((Double_t)(i + 1));
(g->GetY())[(2 * i + 1)] = (g->GetY())[(2 * i)] = (*v)[i];
// g->Draw(“AL”);
return g;
}[/code] You can then “scale” the “X” coordinates of the points of the returned TGraph as you wish. See, for example, [url]Shifting TMultigraph on x-axis to the same starting point (and don’t forget [url]Shifting TMultigraph on x-axis to the same starting point

BTW. If you want to “scale” the “X” axis of the drawn histogram:
TH1D h = static_cast<TH1D>(gPad->FindObject(“TVectorD”));
you need to remember that it has “fix bin sizes” along “X”, so you can only modify “xmin” and “xmax” of its “X” axis (hence the “scaling function” must be linear and “xmax” must remain greater than “xmin”). See: [url]Can we shift histogram for several channels?