The histogram data store is one of the data stores discussed in chapter 2. Its purpose is to store statistics based data and user created objects that have a lifetime of more than a single event (e.g. histograms).
As with the other data stores, all access to data is via a service interface. In this case it is via the IHistogramSvc interface, which is derived from the IDataProviderSvc interface discussed in chapter 6. The user asks the Histogram Service to book a histogram and register it in the histogram data store. The service returns a pointer to the histogram, which can then be used to fill and manipulate the histogram
The histograms themselves are booked and manipulated using four interfaces as defined by the AIDA (Abstract Interfaces for Data Analysis) project. These interfaces are documented on the AIDA web pages: http://wwwinfo.cern.ch/asd/lhc++/AIDA/index.html. The Gaudi implementation uses the transient part of HTL (Histogram Template Library), provided by LHC++.
The histogram data model is shown in Figure 21. The interface IHistogram is a base class, which is used for management purposes. It is not a complete histogram interface, it should not be used by the users. Both interfaces IHistogram1D and IHistogram2D are derived from IHistogram, and use by reference the IAxis interface. Users can book their 1D or 2D histograms in the histogram data store in the same type of tree structure as the event data. Concrete 1D and 2D histograms derive from the DataObject in order to be storable.
|
An instance of the histogram data service is created by the application manager. After the service has been initialised, the histogram data store will contain a root directory "/stat" in which users may book histograms and/or create sub-directories (for example, in the code fragment below, the histogram is stored in the subdirectory "/stat/simple"). A suggested naming convention for the sub-directories is given in Section 1.2.3 .
As discussed in section 5.2, the Algorithm base class defines a member function
IHistogramSvc* histoSvc() |
which returns a pointer to the IHistogramSvc interface of the standard histogram data service. Access to any other non-standard histogram data service (if one exists) must be sought via the ISvcLocator interface of the application manager as discussed in section 11.2.
An example code fragment illustrating how to book a 1D histogram and place it in a directory within the histogram data store, and a simple statement which fills that histogram is shown here:
The parameters of the book function are the directory in which to store the histogram in the data store, the histogram identifier, the histogram title, the number of bins and the lower and upper limits of the X axis. 1D histograms with fixed and variable binning are available. In the case of 2D histograms, the book method requires in addition the number of bins and lower and upper limits of the Y axis.
If using HBOOK for persistency, the histogram identifier should be a valid HBOOK histogram identifier (number), must be unique and, in particular, must be different from any n-tuple number. Even if using another persistency solution (e.g. ROOT) it is recommended to comply with the HBOOK constraints in order to make the code independent of the persistency choice.
The call to histoSvc()->book(...) returns a pointer to an object of type IHistogram1D (or IHistogram2D in the case of a 2D histogram). All the methods of this interface can be used to further manipulate the histogram, and in particular to fill it, as shown in the example. Note that this pointer is guaranteed to be non-null, the algorithm would have failed the initialisation step if the histogram data service could not be found. On the contrary the user variable particles may be null (in case of absence of Monte Carlo particles in the transient data store and in the persistent storage), and the fill statement would fail - so the value of particles must be checked before using it.
Algorithms that create histograms will in general keep pointers to those histograms, which they may use for filling operations. However it may be that you wish to share histograms between different algorithms. Maybe one algorithm is responsible for filling the histogram and another algorithm is responsible for fitting it at the end of the job. In this case it may be necessary to look for histograms within the store. The mechanism for doing this is identical to the method for locating event data objects within the event data store, namely via the IDataProviderSvc interface, as discussed in section 6.2.
SmartDataPtr<IHistogram1D> hist1D( histoSvc(), "/stat/simple/1" );if( 0 != hist1D ) { // Print the found histogram histoSvc()->print( hist1D );} |
An HBOOK conversion service exists which can convert objects of types IHistogram1D and IHistogram2D into a form suitable for storage in a standard HBOOK file. In order to use it you need to
in the CMT
requirements
file of your application, and specify the following the job options
|
The default implementation of the histogram persistency service uses HBOOK. An alternate implementation using ROOT files is now available. To use this alternative you need to
in the CMT
requirements
file of your application, and specify the following job options:
|