//////////////////////////////////////////////////////////////////////////// //// VDyPlot //// //// class describing a plot (representation) of a series //// Used to adapt the behaviour of TH1F to datadisplay needs //// ////////////////////////////////////////////////////////////////////////////
#include <fstream.h>
#include <iostream.h>
#include "VDyPlot.h"
#include "TString.h"
#include "TCanvas.h"
#include "TStyle.h"
#include <sys/time.h>
VDyPlot* gLastModifiedPlot=0;
ClassImp(VDyPlot)
//______________________________________________________________________________VDyPlot::VDyPlot() : TH1F()
{
mTimeFlag = 0;
mTimeString = "";
mTimePave = 0;
mTimeX1 = 0.02;
mTimeY1 = 0.02;
mTimeX2 = 0.98;
mTimeY2 = 0.08;
mOldFirstXbin = GetXaxis()->GetFirst();
mOldLastXbin = GetXaxis()->GetLast();
mIndicator.Set(0);
}
//______________________________________________________________________________VDyPlot::VDyPlot(Text_t* name, Text_t* title, Int_t nbinsx, Axis_t xlow, Axis_t xup)
:TH1F(name,title,nbinsx,xlow,xup)
{
mTimeFlag = 0;
mTimeString = "";
mTimePave = 0;
mTimeX1 = 0.02;
mTimeY1 = 0.02;
mTimeX2 = 0.98;
mTimeY2 = 0.08;
mOldFirstXbin = GetXaxis()->GetFirst();
mOldLastXbin = GetXaxis()->GetLast();
mIndicator.Set(fNcells);
}
//______________________________________________________________________________VDyPlot::VDyPlot(VDyPlot &plot)
{
((VDyPlot&)plot).Copy(*this);
}
//______________________________________________________________________________voidVDyPlot::Copy(TObject& newvsp)
{
TH1F::Copy((VDyPlot&)newvsp);
}
//______________________________________________________________________________voidVDyPlot::Draw(Option_t* option)
{
// Draw the plot. Added the drawing of the time string, with respect to// the TH1F base class
if (gPad && mTimeFlag) {
if (gPad->GetBottomMargin() < mTimeY2+0.10) gPad->SetBottomMargin(mTimeY2+0.10);
}
TH1F::Draw(option);
if (gPad && mTimeFlag) {
if (!mTimePave) {
mTimePave = new TPaveText(mTimeX1, mTimeY1, mTimeX2, mTimeY2,"bNDC");
mTimePave->ResetBit(kCanDelete);
mTimePave->SetName("DyTimeString");
mTimePave->AddText(mTimeString.Data());
mTimePave->SetTextFont(20);
// mTimePave->SetTextFont(23);// mTimePave->SetTextSize(12);// mTimePave->SetFillStyle(0);mTimePave->Draw("NDC");
}
else {
mTimePave->Clear();
mTimePave->AddText(mTimeString.Data());
mTimePave->Draw("NDC");
}
}
}
//______________________________________________________________________________char *VDyPlot::GetObjectInfo(Int_t px, Int_t py) const
{
// Redefines TH1::GetObjectInfo.// Displays the histogram info (bin number, contents, integral up to bin// corresponding to cursor position px,py// Switches to the right pad before doing so.// Correction of a ROOT bug (feature ?).//
static char info[128];
TVirtualPad* savepad;
savepad = gPad;
gPad = (gPad->GetCanvas())->GetSelectedPad();
if (!gPad) return (char*)"";
Double_t x = gPad->PadtoX(gPad->AbsPixeltoX(px));
Double_t y = gPad->PadtoY(gPad->AbsPixeltoY(py));
Double_t x1 = gPad->PadtoX(gPad->AbsPixeltoX(px+1));
const char *drawOption = GetDrawOption();
Double_t xmin, xmax, uxmin,uxmax;
Double_t ymin, ymax, uymin,uymax;
Int_t binx,biny,binmin,binx1;
binx = fXaxis.FindFixBin(x);
binmin = fXaxis.GetFirst();
binx1 = fXaxis.FindFixBin(x1);
// special case if more than 1 bin in x per pixel
if (binx1-binx>1 && GetDimension() == 1) {
Double_t binval=GetBinContent(binx);
Int_t binnear=binx;
for (Int_t ibin=binx+1; ibin<binx1; ibin++) {
Double_t binvaltmp = GetBinContent(ibin);
if (TMath::Abs(y-binvaltmp) < TMath::Abs(y-binval)) {
binval=binvaltmp;
binnear=ibin;
}
}
binx = binnear;
}
Double_t integ = 0;
for (Int_t bin=binmin;bin<=binx;bin++) {integ += GetBinContent(bin);}
sprintf(info,"(x=%g, y=%g, bin=%d, value=%g, Sum=%g)",x,y,binx,GetBinContent(binx),integ);
gPad = savepad;
return info;
}
//______________________________________________________________________________voidVDyPlot::SavePrimitive(ofstream &out, Option_t *option)
{
// Save primitive as a C++ statement(s) on output stream out //Note the following restrictions in the code generated: // - variable bin size not implemented // - Objects in list of functions not saved (fits) // Adapted for Data Display: DO NOT save the bin contents, unnecessarychar quote = '"';
out<<" "<<endl;
out<<" "<<"TH1"<<" *";
out<<GetName()<<" = new "<<ClassName()<<"("<<quote<<GetName()<<quote<<","<<quote<<GetTitle()<<quote
<<","<<GetXaxis()->GetNbins()
<<","<<GetXaxis()->GetXmin()
<<","<<GetXaxis()->GetXmax();
if (fDimension > 1) {
out<<","<<GetYaxis()->GetNbins()
<<","<<GetYaxis()->GetXmin()
<<","<<GetYaxis()->GetXmax();
}
if (fDimension > 2) {
out<<","<<GetZaxis()->GetNbins()
<<","<<GetZaxis()->GetXmin()
<<","<<GetZaxis()->GetXmax();
}
out<<");"<<endl;
if (TMath::Abs(GetBarOffset()) > 1e-5) {
out<<" "<<GetName()<<"->SetBarOffset("<<GetBarOffset()<<");"<<endl;
}
if (TMath::Abs(GetBarWidth()-1) > 1e-5) {
out<<" "<<GetName()<<"->SetBarWidth("<<GetBarWidth()<<");"<<endl;
}
if (fMinimum != -1111) {
out<<" "<<GetName()<<"->SetMinimum("<<fMinimum<<");"<<endl;
}
if (fMaximum != -1111) {
out<<" "<<GetName()<<"->SetMaximum("<<fMaximum<<");"<<endl;
}
if (fNormFactor != 0) {
out<<" "<<GetName()<<"->SetNormFactor("<<fNormFactor<<");"<<endl;
}
if (fEntries != 0) {
out<<" "<<GetName()<<"->SetEntries("<<fEntries<<");"<<endl;
}
if (fDirectory == 0) {
out<<" "<<GetName()<<"->SetDirectory(0);"<<endl;
}
if (TestBit(kNoStats)) {
out<<" "<<GetName()<<"->SetStats(0);"<<endl;
}
if (fOption.Length() != 0) {
out<<" "<<GetName()<<"->SetOption("<<quote<<fOption.Data()<<quote<<");"<<endl;
}
Int_t bin;
// for (bin=0;bin<fNcells;bin++) {// Double_t bc = GetBinContent(bin);// if (bc) {// out<<" "<<GetName()<<"->SetBinContent("<<bin<<","<<bc<<");"<<endl;// }// }// if (fSumw2.fN) {// for (bin=0;bin<fNcells;bin++) {// Double_t be = GetBinError(bin);// if (be) {// out<<" "<<GetName()<<"->SetBinError("<<bin<<","<<be<<");"<<endl;// }// }// }Int_t ncontours = GetContour();
if (ncontours > 0) {
out<<" "<<GetName()<<"->SetContour("<<ncontours<<");"<<endl;
for (bin=0;bin<ncontours;bin++) {
out<<" "<<GetName()<<"->SetContourLevel("<<bin<<","<<GetContourLevel(bin)<<");"<<endl;
}
}
SaveFillAttributes(out,GetName(),0,1001);
SaveLineAttributes(out,GetName(),1,1,1);
SaveMarkerAttributes(out,GetName(),1,1,1);
fXaxis.SaveAttributes(out,GetName(),"->GetXaxis()");
fYaxis.SaveAttributes(out,GetName(),"->GetYaxis()");
fZaxis.SaveAttributes(out,GetName(),"->GetZaxis()");
TString opt = option;
opt.ToLower();
if (!opt.Contains("nodraw")) {
out<<" "<<GetName()<<"->Draw("
<<quote<<option<<quote<<");"<<endl;
}
}
//______________________________________________________________________________voidVDyPlot::SetIndicator(int bin, short colorValue)
{
// Sets the value for indicator on bin. This will be used to draw a colored vertical// line indicating something went wrong.
if (bin < 0) return;
mIndicator.AddAt((short)colorValue,bin);
}
//______________________________________________________________________________voidVDyPlot::Paint(Option_t* option)
{
// Paint the plot and add indicator linesdouble indicymin, indicymax, indicxmin,indicxmax;
Float_t savexloffset;
double oldTime, currentTime, dtime;
struct timeval *tv;
/***
if (Dy->debug>3)
{tv = new timeval;
gettimeofday(tv, NULL);
oldTime = tv->tv_sec + ( tv->tv_usec * 1.0e-6 );
}
***/
savexloffset = GetXaxis()->GetLabelOffset();
if (gPad->GetLogx()==1) {
GetXaxis()->SetLabelOffset(savexloffset-0.025);
}
TH1F::Paint(option);
// Add colored indicator lines
for (int i=1;i<fNcells;i++) {
if (mIndicator[i] > 0) {
indicymin = gPad->GetUymin();
indicymax = gPad->GetUymax();
indicxmin = GetXaxis()->GetBinLowEdge(i);
indicxmax = GetXaxis()->GetBinUpEdge(i);
gVirtualX->SetFillStyle(1001);
gVirtualX->SetFillColor(mIndicator[i]); //is redefined in TPad::PaintBox
gPad->PaintBox(indicxmin, indicymin, indicxmax, indicymax);
}
}
GetXaxis()->SetLabelOffset(savexloffset);
// If a zoom was made, set this plot as last modified plot
if (mOldFirstXbin != GetXaxis()->GetFirst()
|| mOldLastXbin != GetXaxis()->GetLast()) {
mOldFirstXbin = GetXaxis()->GetFirst();
mOldLastXbin = GetXaxis()->GetLast();
gLastModifiedPlot = this;
}
/***
if (Dy->debug>3)
{gettimeofday(tv, NULL);
currentTime = tv->tv_sec + ( tv->tv_usec * 1.0e-6 );
dtime = 1000. * (currentTime - oldTime);
if (oldTime > 0.) printf("VDyPlot::Paint: time passed =%.2f msn",dtime);
delete(tv);
}
***/
}
//______________________________________________________________________________voidVDyPlot::ZoomAsLast()
{
// Zoom with the same range as the last plot as the last plot
GetXaxis()->SetRange(gLastModifiedPlot->GetXaxis()->GetFirst(),
gLastModifiedPlot->GetXaxis()->GetLast());
}
//______________________________________________________________________________voidVDyPlot::ExportAscii(const char* fileName)
{
// Create a file containing plot data in ASCII format: col1=x col2=yint i, nBin;
double x,y;
char realName[256];
FILE *fp_ascii;
if (strcmp(fileName,"Default_file_name_=_Plot_name") == 0)
{sprintf(realName,"%s.txt",GetTitle());
fp_ascii = fopen(realName,"w");
}
else
{fp_ascii = fopen(fileName,"w");}
if (fp_ascii == NULL) return;
nBin = GetNbinsX();
for (i=1; i<nBin+1; i++)
{
x = GetBinCenter(i);
y = GetBinContent(i);
fprintf(fp_ascii,"%e %e n",x, y);
}
fclose(fp_ascii);
}
- ROOT page - VEGA page - Class index - Top of the page This page has been automatically generated. If you have any comments or suggestions
about the page layout send a mail to
, or
contact
with any questions or problems regarding ROOT or VEGA.