[Prev][Next][Index][Thread]
opacs/histos/plots
Hello
I will answer your questions
by piece.
First, I shall explain how to do histograms
and plot them with the XoPlot widget.
HISTOGRAMS:
----------
Histograms are handled by the Ho package.
There is a running exemple in the HoT.exe
program. If not done, reconstruct it with:
UNIX> cd .../Ho/v1/mgr
UNIX> source setup.csh
UNIX> make
UNIX> $HOBIN/HoT.exe
Source is in HoT.c.
The first way to create an Histogram object
(OHist class) is by C programming.
OHist hist1,hist2;
...
/*one dimensionnal histogram.*/
hist1 = OHistCreate ("my_histo",1,"x",10,0.,10.);
/*two dimensionnal histogram.*/
hist2 = OHistCreate ("my_histo_2",2,"x",10,0.,10.,
"y",50,0.,20.);
You fill an histo with OHistFill routine.
for(count=0;count<1000;count++)
{
double x,y;
x = (double)rand();
x /= ((double)RAND_MAX);
x *= 10.;
y = (double)rand();
y /= ((double)RAND_MAX);
y *= 20.;
OHistFill (hist1,x,1.);
OHistFill (hist2,x,y,1.);
}
Last argument is the weight of the entry.
There are optimized routines to improve the filling.
For 1D:
OHistFillFastOne (hist,x,1.);
For 2D:
OHistFillFastTwo (hist,x,y,1.);
Deletion of an histogram is done with
the OHistDelete routine:
OHistDelete (hist1);
Look the OHist.h, and OHist.c for other
convenient routines that work on an OHist object.
PLOTTING:
---------
Plotting is done with the XoPlot widget.
You have to create one in you interface. The
best is to create one in the odb file.
The "user.odb" template contains the "user_plot"
XoPlot widget.
Mainly the link between the XoPlot widget and
an OHist object is done through the setting of the
resource "toPlot".
The setting of the resource produces a "representation"
of the histogram by the plot widget. This involves that the
histogram must be created and filled when you set
the resource.
NOTE that the XoPlot widget DO NOT SURVEY
the state of the histogram.
Then if you fill again, or change booking parameters
of the the histo, you have to trigger a new
representation of it in the plot
with a new setting of the "toPlot" resource.
Maily what you should do in your display:
- create some histo at startup.
- clear, fill, plot them at each event
You can create an osh command "histo" that
look like this:
...
OShAddCmd ((OSh)a_osh,OCmdCreate("KLOE/histos",(VoidProc)histos));
....
/*create histos*/
OHistCreate("KLOE_ecal_energy",....)
....
WoStartup ();
.....
/***************************************************************************/
static int histos (
int a_argn
,char** a_args
,OExec a_exec
)
/***************************************************************************/
/*
*/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
OHist hist_ecal_energy;
Widget plot;
/*.........................................................................*/
if( (a_argn!=1) && (a_argn!=2) ){CWarnF ("%s: bad arg number.\n",a_args[0]);return EXIT_FAILURE;}
hist_ecal_energy = OHistFrName ("KLOE_ecal_energy");
OHistRaz (hist_ecal_energy);
for(...)
{
double energy;
/*Get ecal data.*/
energy = ....
OHistFill (hist_ecal_energy,energy,1.);
}
/*We trigger a representation of the histo
in the user_plot widget.*/
plot = OWidgetFrName ("user_plot");
/*Reset objects to plot.*/
OWidgetSetResource (plot,"toPlot","",False);
/*Plot the KLOE_ecal_energy histogram*/
OWidgetSetResource (plot,"toPlot","KLOE_ecal_energy",False);
OExecPutPipe (a_exec,0);
return EXIT_SUCCESS;
}
When this is done, you execute the "histos"
command in any buildSceneCallback. For exemple
on the user_plot widget:
user_plot.buildSceneCallback = osh> histos
This is the basic mechanism.
The OHist class is declared to the type
manager. Then you could see histos with:
osh> collect OHist | dump
or
osh> collect OHist where name eq KLOE_ecal* | dump
In principle you can declare histo in an odb
file (today only 1D !!!):
hist.odb
begin OHist
name = KLOE_ecal_energy
dimension = 1
title = hello
xn = 100
xmin = 0.
xmax = 10.
end
you load the file with the command:
osh> load hist.odb
The load command will do the OHistCreate.
Look HoT.c for a running example.
Next version will have the "create" and
"fill" command that will permits to
create histo and fill them with
object properties declared to the "type manager".
Them mainly all histos manipulation
wil be done without user C programming.
I shall put in the GEANT template
that come with "Wo" full exemples of all these.
G.Barrand