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:
"""
Example of statistical estimation on vector attributes
"""
from URANIE import DataServer
tdsop = DataServer.TDataServer("foo", "poet")
tdsop.fileDataRead("tdstest.dat")
# Considering every element of a vector independent from the others
tdsop.computeStatistic("x")
px = tdsop.getAttribute("x")
print("min(x[0])= "+str(px.getMinimum(0))+"; max(x[0])= "+str(px.getMaximum(0))
+ "; mean(x[0])= "+str(px.getMean(0))+"; std(x[0])= "+str(px.getStd(0)))
print("min(x[1])= "+str(px.getMinimum(1))+"; max(x[1])= "+str(px.getMaximum(1))
+ "; mean(x[1])= "+str(px.getMean(1))+"; std(x[1])= "+str(px.getStd(1)))
print("min(x[2])= "+str(px.getMinimum(2))+"; max(x[2])= "+str(px.getMaximum(2))
+ "; mean(x[2])= "+str(px.getMean(2))+"; std(x[2])= "+str(px.getStd(2)))
print("min(xtot)= "+str(px.getMinimum(3))+"; max(xtot)= "+str(px.getMaximum(3))
+ "; mean(xtot)= "+str(px.getMean(3))+"; std(xtot)= "+str(px.getStd(3)))
# 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.0; max(x[0])= 7.0; mean(x[0])= 3.0; std(x[0])= 3.4641016151377544
min(x[1])= 2.0; max(x[1])= 8.0; mean(x[1])= 4.666666666666666; std(x[1])= 3.055050463303893
min(x[2])= 3.0; max(x[2])= 9.0; mean(x[2])= 6.666666666666666; std(x[2])= 3.2145502536643185
min(xtot)= 1.0; max(xtot)= 9.0; mean(xtot)= 4.777777777777778; std(xtot)= 3.2317865716108862
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 *
*****************************************************