2.4.3.1. Specific case of vectors

As stated in List of variable information, these information are now stored in vectors because of the new possible attribute nature. In the case of constant-size vectors whose dimension is \(N\), the attribute-statistical vectors are filled with the statistical information considering every elements of the input vector independent from the others. This results in attribute-statistical vectors of size \(N+1\), the extra element being the statistical information computed over the complete vector. Here is an example of computeStatistic use with the tdstest.dat file already shown in Adding attributes to a TDataServer:

    TDataServer *tdsop =new TDataServer("foo","poet");
    tdsop->fileDataRead("tdstest.dat");

    //Considering every element of a vector independent from the others
    tdsop->computeStatistic("x");
    TAttribute *px = tdsop->getAttribute("x");

    cout<<"min(x[0])= "<<px->getMinimum(0)<<";  max(x[0])= "<<px->getMaximum(0)
        <<";  mean(x[0])= "<<px->getMean(0)<<";  std(x[0])= "<<px->getStd(0)<<endl;
    cout<<"min(x[1])= "<<px->getMinimum(1)<<";  max(x[1])= "<<px->getMaximum(1)
        <<";  mean(x[1])= "<<px->getMean(1)<<";  std(x[1])= "<<px->getStd(1)<<endl;
    cout<<"min(x[2])= "<<px->getMinimum(2)<<";  max(x[2])= "<<px->getMaximum(2)
        <<";  mean(x[2])= "<<px->getMean(2)<<";  std(x[2])= "<<px->getStd(2)<<endl;
    cout<<"min(xtot)= "<<px->getMinimum(3)<<";  max(xtot)= "<<px->getMaximum(3)
        <<";  mean(xtot)= "<<px->getMean(3)<<";  std(xtot)= "<<px->getStd(3)<<endl;

    //Statistic for a single realisation of a vector, not considering other events
    tdsop->addAttribute("Min_x","Min$(x)");
    tdsop->addAttribute("Max_x","Max$(x)");
    tdsop->addAttribute("Mean_x","Sum$(x)/Length$(x)");

    tdsop->scan("x:Min_x:Max_x:Mean_x","","colsize=5 col=2:::6");

The first computation is filling the vector of statistical elementary in the concerned attribute \(x\). The first, second and third cout line in the previous piece of code are dumping the statistical characteristics respectively for the first, second and third element of the vector. The fourth one is giving the main characteristics considering the complete vector and all the entries. The results of this example are shown below:

min(x[0])= 1;  max(x[0])= 7;  mean(x[0])= 3;  std(x[0])= 3.4641
min(x[1])= 2;  max(x[1])= 8;  mean(x[1])= 4.66667;  std(x[1])= 3.05505
min(x[2])= 3;  max(x[2])= 9;  mean(x[2])= 6.66667;  std(x[2])= 3.21455
min(xtot)= 1;  max(xtot)= 9;  mean(xtot)= 4.77778;  std(xtot)= 3.23179

This implementation has been chosen as ROOT offers access to another way of computing these notions if one wants to consider every element of a vector, assuming that every event is now independent from the others. Indeed it is possible to get the minimum, maximum and mean of a vector on an event-by-event basis by introducing a new attribute with a formula, as done in Adding attributes to a TDataServer. This is the second part of the code shown in the box above (using specific function from ROOT, that needs the sign “$” to be recognised). The results are shown below:

*****************************************************
*    Row   * Instance *  x * Min_x * Max_x * Mean_x *
*****************************************************
*        0 *        0 *  1 *     1 *     3 *      2 *
*        0 *        1 *  2 *     1 *     3 *      2 *
*        0 *        2 *  3 *     1 *     3 *      2 *
*        1 *        0 *  7 *     7 *     9 *      8 *
*        1 *        1 *  8 *     7 *     9 *      8 *
*        1 *        2 *  9 *     7 *     9 *      8 *
*        2 *        0 *  1 *     1 *     8 * 4.3333 *
*        2 *        1 *  4 *     1 *     8 * 4.3333 *
*        2 *        2 *  8 *     1 *     8 * 4.3333 *
*****************************************************