HOWTO Access Calibration Constants from JANA/DANA

From GlueXWiki
Revision as of 23:26, 7 July 2007 by Davidl (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Introduction

Here I am starting a page that will hopefully get updated as the calibration system is developed. Right now, the intention is to document the new features in JANA that provide a standard API for accessing calibration constants. Note that the API should support full database access across a network or even through web objects. Right now though, only a local file system mechanism is provided. Factory writers won't have to change any code when these other methods are finally implemented.

Accessing calibration constants from within a factory

Calibration constants can be obtained using one of two methods in JEventLoop. Both are named GetCalib and are distinguished only by the data type of their second argument. The formats of the methods are:

bool GetCalib(string namepath, map<string, T> &vals)
bool GetCalib(string namepath, vector<T> &vals)

Both methods are templated. The "T" represents the data type you wish to have the values converted to when they are copied into your container. This should be one of int, float, double, or string. The "namepath" string specifies which constants you want. This should be a heirarchical, forward-slash separated list starting with the detector system name and ending with the name of the constants themselves.

The first method returns values in an STL map container. This is appropriate for values best indexed by name. For example, if the constants were the result of a Gaussian fit, you might name them "mean" and "sigma". These names(keys) would be stored with the constants in the database. One could also use detector id values for the keys.

The second method copies the values into an STL vector container. This is appropriate for values that are best indexed by position in the array. For example, pedestal values for all of the channels of a calorimeter.

Example 1

In this example a set of 3 values representing a timewalk correction function for the FDC are retrieved. They are copied into data members of the class for use later in the evnt(...) method.


... in factory class definition ...

double slope, offset, exponent; 


... in brun() method ...

map<string, double> twpars;
loop->GetCalib("FDC/driftvelocity/timewalk_parameters", twpars);

slope    = twpars["slope"];
offset   = twpars["offset"];
exponent = twpars["exponent"];

Example 2

In this example a set of pedestal values are read in and stored in the vector peds.


... in factory class definition ...

vector<int> peds;


... in brun() method ...

loop->GetCalib("FCAL/pedestals", peds);


... in evnt() method ...

hit->ADC -= peds[hit->id];


Specifying the location and set of calibration constants

The location of the constants is specified using the JANA_CALIB_URL environment variable. Since the only mechanism currently implemented for storing the constants is through ascii files, this should start with "file://". For example, if I have my constants stored in the directory /home/davidl/HallD/calib, then I would set my JANA_CALIB_URL to:

file:///home/davidl/HallD/calib

Note that since this is a full path, it starts with a "/" thus, the 3 slashes before "home".

Calibration sets can also be identified by a context. The idea is that one can have multiple calibration sets which can, in part, be based on one another. The context will eventually be used to specify this relationship. The default context is just default. So, for the above example, all of the calibration constants will be stored in a directory named default in the root calibration directory above. For example 1 above, the constants should be stored in the file /home/davidl/HallD/calib/default/FDC/driftvelocity/timewalk_parameters.