NCFS-Pack
A generic (astro)particle physics analysis framework
 
Loading...
Searching...
No Matches
NcSample.h
Go to the documentation of this file.
1#ifndef NcSample_h
2#define NcSample_h
3// Copyright(c) 1996 NCFS/IIHE, All Rights Reserved.
4// See cxx source for full Copyright notice.
5
6#include <math.h>
7
8#include "TNamed.h"
9#include "TArrayD.h"
10#include "TArrayL64.h"
11#include "TH1.h"
12#include "TH2.h"
13#include "TH3.h"
14#include "TGraphErrors.h"
15#include "TGraph2DErrors.h"
16#include "TGraphTime.h"
17#include "TF1.h"
18#include "TGraphQQ.h"
19#include "TMarker.h"
20#include "TCanvas.h"
21#include "TSystem.h"
22
23#include "NcMath.h"
24
26
27class NcSample : public TNamed
28{
29 public:
30 NcSample(const char* name="",const char* title=""); // Default constructor
31 virtual ~NcSample(); // Default destructor
32 NcSample(const NcSample& s); // Copy constructor
33 virtual TObject* Clone(const char* name="") const; // Make a deep copy and provide its pointer
34 void Reset(); // Reset complete statistics
35 void SetNames(TString name1="X",TString name2="Y",TString name3="Z",TString name4="T"); // Set the variable names
36 void Enter(Double_t x); // Enter value for 1-dim. sample
37 void Remove(Double_t x); // Remove value from 1-dim. sample
38 void Enter(Double_t x,Double_t y); // Enter values for 2-dim. sample
39 void Remove(Double_t x,Double_t y); // Remove values from 2-dim. sample
40 void Enter(Double_t x,Double_t y,Double_t z); // Enter values for 3-dim. sample
41 void Remove(Double_t x,Double_t y,Double_t z); // Remove values from 3-dim. sample
42 void Enter(Double_t x,Double_t y,Double_t z,Double_t t); // Enter values for 4-dim. sample
43 void Remove(Double_t x,Double_t y,Double_t z,Double_t t); // Remove values from 4-dim. sample
44 void RemoveEntry(Int_t i,Int_t mode,Int_t j); // Remove the i-th entry after ordering according to the j-th variable
45 void RemoveEntry(Int_t i,Int_t mode,TString name); // Remove the i-th entry after ordering according to the variable with the specified name
46 void RemoveEntry(Int_t i,Int_t j,Int_t mode,Int_t k); // Remove the entries in the interval [i,j] after ordering according to the k-th variable
47 void RemoveEntry(Int_t i,Int_t j,Int_t mode,TString name); // Remove the entries in the interval [i,j] after ordering according to the variable with the specified name
48 Int_t GetDimension() const; // Provide dimension of the sample
49 Int_t GetN() const; // Provide the number of entries
50 TString GetVariableName(Int_t i) const; // Provide the name of the i-th variable
51 Int_t GetIndex(TString name) const; // Provide the index of the specified variable name
52 Double_t GetSum(Int_t i) const; // Provide sum for i-th variable
53 Double_t GetSum(TString name) const; // Provide sum for the variable with the specified name
54 Double_t GetMean(Int_t i) const; // Provide mean for i-th variable
55 Double_t GetMean(TString name) const; // Provide mean for the variable with the specified name
56 Double_t GetRMS(Int_t i) const; // Provide Root Mean Square for i-th variable
57 Double_t GetRMS(TString name) const; // Provide Root Mean Square for the variable with the specified name
58 Double_t GetVar(Int_t i,Int_t model=0) const; // Provide variance for i-th variable
59 Double_t GetVar(TString name,Int_t model=0) const; // Provide variance for the variable with the specified name
60 Double_t GetSigma(Int_t i,Int_t model=0) const; // RMS or standard deviation for i-th variable
61 Double_t GetSigma(TString name,Int_t model=0) const; // RMS or standard deviation for variable with the specified name
62 Double_t GetCov(Int_t i,Int_t j) const; // Covariance for i-th and j-th variable
63 Double_t GetCov(TString nameA,TString nameB) const; // Covariance for variables with the specified names
64 Double_t GetCor(Int_t i,Int_t j) const; // Correlation for i-th and j-th variable
65 Double_t GetCor(TString nameA,TString nameB) const; // Correlation for variables with the specified names
66 Double_t GetQuantile(Double_t f,Int_t i); // Quantile value of the i-th variable for the fraction f
67 Double_t GetQuantile(Double_t f,TString name); // Quantile value of variable with the specified name for the fraction f
68 Double_t GetMedian(Int_t i); // Provide median for the i-th variable
69 Double_t GetMedian(TString name); // Provide median for the variable with the specified name
70 Double_t GetSpread(Int_t i,Int_t model=0,Double_t vref=0); // Provide spread w.r.t. some reference value for the i-th variable
71 Double_t GetSpread(TString name,Int_t model=0,Double_t vref=0); // Provide spread w.r.t. some reference value for the variable with the specified name
72 Double_t GetMinimum(Int_t i) const; // Provide the minimum value for the i-th variable
73 Double_t GetMinimum(TString name) const; // Provide the minimum value for the variable with the specified name
74 Double_t GetMaximum(Int_t i) const; // Provide the maximum value for the i-th variable
75 Double_t GetMaximum(TString name) const; // Provide the maximum value for the variable with the specified name
76 void Data(Int_t i=0,Int_t j=0); // Statistics info for the sample
77 void Data(TString nameA,TString nameB="-"); // Statistics info for the sample
78 void ListOrdered(Int_t mode,Int_t i); // Provide a listing of the stored entries ordered w.r.t. the i-th variable
79 void ListOrdered(Int_t mode,TString name); // Provide a listing of the stored entries ordered w.r.t. the variable with the specified name
80 void SetStoreMode(Int_t mode=1,Int_t nmax=0,Int_t i=0); // Set mode for storage of entered data
81 Int_t GetStoreMode() const; // Provide storage mode of entered data
82 Int_t GetStoreNmax() const; // Provide the maximum number of entries for storage
83 Double_t GetQuantile(Double_t f,TH1* histo,Int_t mode=0) const; // Quantile value for fraction f from the specified 1D histogram
84 Double_t GetMedian(TH1* histo,Int_t mode=0) const; // Provide median from the specified 1D histogram
85 Double_t GetSpread(TH1* histo,Int_t mode=0,Int_t model=0,Double_t vref=0) const; // Provide spread w.r.t. some reference value from the 1D histo
86 Double_t GetEntry(Int_t i,Int_t j,Int_t mode=0,Int_t k=0); // Access the i-th (ordered) entry and provide the value of the j-th variable
87 Double_t GetEntry(Int_t i,TString nameA,Int_t mode=0,TString nameB="-"); // Access the i-th (ordered) entry and provide the value of the variable with nameA
88 void GetSubset(NcSample* s,Int_t ifirst,Int_t ilast,Int_t mode=0,Int_t k=0); // Provide the [ifirst,ilast] (ordered) entries via NcSample "s"
89 NcSample GetDtSample(Int_t i,Int_t nc,Int_t store=1,Int_t nmax=0,Int_t order=0); // Provide the dt interval values for the i-th variable of input sample s
90 NcSample GetDtSample(TString name,Int_t nc,Int_t store=1,Int_t nmax=0,Int_t order=0); // Provide the dt interval values for the requested named variable of input sample s
91 TH1D GetSamplingHistogram(Int_t i,TF1* f=0); // Provide a TH1D with values of (a function of) variable i vs. the sampling entry number
92 TH1D GetSamplingHistogram(Int_t i,TString f); // Provide a TH1D with values of (a function of) variable i vs. the sampling entry number
93 TH1D GetSamplingHistogram(TString nameA,TF1* f=0); // Provide a TH1D for (a function of) variable nameA vs. the sampling entry number
94 TH1D GetSamplingHistogram(TString nameA,TString f); // Provide a TH1D for (a function of) variable nameA vs. the sampling entry number
95 TH1D Get1DHistogram(Int_t i,Int_t j=0,Bool_t sumw2=kFALSE,Int_t nbx=100,TF1* f=0); // Provide a TH1D for variable i (weighted with (a function of) variable j)
96 TH1D Get1DHistogram(TString nameA,TString nameB="-",Bool_t sumw2=kFALSE,Int_t nbx=100,TF1* f=0); // Provide a TH1D for variable nameA (weighted with (a function of) variable nameB)
97 TH2D Get2DHistogram(Int_t i,Int_t j,Int_t k=0,Bool_t sumw2=kFALSE,Int_t nbx=100,Int_t nby=100,TF1* f=0); // Provide a TH2D for variables i and j (weighted with (a function of) variable k)
98 TH2D Get2DHistogram(TString nameA,TString nameB,TString nameC="-",Bool_t sumw2=kFALSE,Int_t nbx=100,Int_t nby=100,TF1* f=0); // Provide a TH2D for variables nameA and nameB (weighted with (a function of) variable nameC)
99 TH3D Get3DHistogram(Int_t i,Int_t j,Int_t k,Int_t m=0,Bool_t sumw2=kFALSE,Int_t nbx=100,Int_t nby=100,Int_t nbz=100,TF1* f=0); // Provide a TH3D with values of variables i, j and k (weighted with (a function of) variable m)
100 TH3D Get3DHistogram(TString nameA,TString nameB,TString nameC,TString nameD="-",Bool_t sumw2=kFALSE,Int_t nbx=100,Int_t nby=100,Int_t nbz=100,TF1* f=0); // Provide a TH3D for variables nameA, nameB and nameC (weighted with (a function of) variable nameD)
101 TGraph GetGraph(Int_t i,TF1* f=0); // Provide a TGraph with values of (a function of) variable i vs. the sampling entry number
102 TGraph GetGraph(Int_t i,TString f); // Provide a TGraph with values of (a function of) variable i vs. the sampling entry number
103 TGraph GetGraph(TString nameA,TF1* f=0); // Provide a TGraph for (a function of) variable nameA vs. the sampling entry number
104 TGraph GetGraph(Int_t i,Int_t j,TF1* f=0); // Provide a TGraph with values of (a function of) variable j vs. variable i
105 TGraph GetGraph(Int_t i,Int_t j,TString f); // Provide a TGraph with values of (a function of) variable j vs. variable i
106 TGraph GetGraph(TString nameA,TString nameB,TF1* f=0); // Provide a TGraph for (a function of) variable nameB vs. variable nameA
107 TGraphErrors GetGraphErrors(TGraph* g,Int_t ix=0,Int_t iy=0,TF1* fx=0,TF1* fy=0); // Provide a Graph with new c.q. modified errors
108 TGraphErrors GetGraphErrors(TGraph* g,TString nameA,TString nameB,TF1* fx=0,TF1* fy=0); // Provide a Graph with new c.q. modified errors
109 TGraphTime* GetGraph(Int_t i,Int_t j,Int_t mode,Int_t k,Bool_t smp=kTRUE); // Provide a TGraphTime with (ordered) values of variables i and j
110 TGraphTime* GetGraph(TString nameA,TString nameB,Int_t mode,TString nameC,Bool_t smp=kTRUE); // Provide a TGraphTime with (ordered) values of variables nameA and nameB
111 TGraph2D GetGraph(Int_t i,Int_t j,Int_t k,TF1* f=0); // Provide a TGraph2D with values of (a function of) variable k vs. i and j
112 TGraph2D GetGraph(Int_t i,Int_t j,Int_t k,TString f); // Provide a TGraph2D with values of (a function of) variable k vs. i and j
113 TGraph2D GetGraph(TString nameA,TString nameB,TString nameC,TF1* f=0); // Provide a TGraph2D for (a function of) variable nameC vs. nameA and nameB
114 TGraph2D GetGraph(TString nameA,TString nameB,TString nameC,TString f); // Provide a TGraph2D for (a function of) variable nameC vs. nameA and nameB
115 TGraph2DErrors GetGraph2DErrors(TGraph2D* g,Int_t ix=0,Int_t iy=0,Int_t iz=0,TF1* fx=0,TF1* fy=0,TF1* fz=0); // Provide a Graph2D with new c.q. modified errors
116 TGraph2DErrors GetGraph2DErrors(TGraph2D* g,TString nameA,TString nameB,TString nameC,TF1* fx=0,TF1* fy=0,TF1* fz=0); // Provide a Graph2D with new c.q. modified errors
117 TGraphQQ GetQQplot(Int_t i,Int_t j,TF1* f=0); // Provide a TGraphQQ for the values of variables i and j or the function f replacing j
118 TGraphQQ GetQQplot(TString nameA,TString nameB,TF1* f=0); // Provide a TGraphQQ for variables nameA and nameB or the function f replacing nameB
119 void Load(TGraph* g,Int_t clr=1); // Load the data points of a TGraph object as 2-dimensional (x,y) data.
120 void Load(TGraph2D* g,Int_t clr=1); // Load the data points of a TGraph2D object as 3-dimensional (x,y,z) data.
121 void Load(TH1* h,Int_t clr=1); // Load the data of a 1-dimensional histogram.
122 void Load(TArray* h,Int_t clr=1); // Load the data of a 1-dimensional data array.
123 Double_t GetSNR(Int_t i,Int_t mode=2,Bool_t db=kTRUE) const; // Provide the Signal to Noise ratio for the i-th variable
124 Double_t GetSNR(TString name,Int_t mode=2,Bool_t db=kTRUE) const; // Provide the Signal to Noise ratio for the variable with the specified name
125 Double_t GetCV(Int_t i,Int_t mode=1) const; // Provide the Coefficient of Variation for the i-th variable
126 Double_t GetCV(TString name,Int_t mode=1) const; // Provide the Coefficient of Variation for the variable with the specified name
127 void Animation(Int_t i,Int_t j,Int_t mode,Int_t k,Int_t delay,TString opt="AP"); // Animation of an (ordered) sampling of the values of variables i and j
128 void Animation(TString nameA,TString nameB,Int_t mode,TString nameC,Int_t delay,TString opt="AP"); // Animation of an (ordered) sampling of the values of variables nameA and nameB
129 void Animation(Int_t i,Int_t j,Int_t k,Int_t mode,Int_t m,Int_t delay,TString opt="PFB"); // Animation of an (ordered) sampling of the values of variables i, j and k
130 void Animation(TString nameA,TString nameB,TString nameC,Int_t mode,TString nameD,Int_t delay,TString opt="PFB"); // Animation of an (ordered) sampling of the values of variables nameA, nameB and nameC
131 Double_t Digitize(Int_t i,Int_t nbits,Double_t vcal,Int_t mode); // Digitize the values of the i-th variable with an "nbits" ADC
132 Double_t Digitize(TString name,Int_t nbits,Double_t vcal,Int_t mode); // Digitize the values of the specified variable with an "nbits" ADC
133 Long64_t Transmit(Int_t i,Int_t nbits,Double_t range,Double_t Vbias=0,TArray* peds=0,TH1* hist=0,Int_t B=0,Int_t C=3); // Transmit the values of the i-th variable via an "nbits" ADC-DAC chain
134 Long64_t Transmit(TString name,Int_t nbits,Double_t range,Double_t Vbias=0,TArray* peds=0,TH1* hist=0,Int_t B=0,Int_t C=3); // Transmit the values of the specified variable via an "nbits" ADC-DAC chain
135 NcSample SampleAndHold(TF1 f,Double_t step,Double_t vmin,Double_t vmax,Int_t loc=-1) const; // Perform a Sample-And-Hold operation on the specified function
136 NcSample SampleAndSum(Int_t i,Double_t step,Int_t loc=0,Int_t j=0,Double_t vmin=0,Double_t vmax=-1); // Perform a Sample-And-Hold operation on the values of the i-th variable
137 NcSample SampleAndSum(TString nameA,Double_t step,Int_t loc=0,TString nameB="-",Double_t vmin=0,Double_t vmax=-1); // Perform a Sample-And-Hold operation on the values of the variable nameA
138
139 protected:
140 Int_t fDim; // Dimension of the sample
141 Int_t fN; // Number of entries of the sample
142 enum {fMaxdim=4}; // Maximum supported dimension
143 TString fNames[fMaxdim]; // Variable names e.g. X,Y,Z,T
144 Double_t fSum[fMaxdim]; // Total sum for each variable
145 Double_t fSum2[fMaxdim][fMaxdim]; // Total sum**2 for each variable
146 Double_t fMean[fMaxdim]; // Mean for each variable
147 Double_t fRMSdev[fMaxdim]; // Root Mean Square deviation for each variable
148 Double_t fSigma[fMaxdim]; // Standard deviation for each variable
149 Double_t fCov[fMaxdim][fMaxdim]; // Covariances of pairs of variables
150 Double_t fCor[fMaxdim][fMaxdim]; // Correlations of pairs of variables
151 Double_t fMin[fMaxdim]; // Minimum value for each variable
152 Double_t fMax[fMaxdim]; // Maximum value for each variable
153 Int_t fRemove; // Flag to indicate that some entry has been removed
154 Int_t fStore; // Flag to denote storage of entered data
155 Int_t fNmax; // Maximum number of entries to be stored before moving some out
156 Int_t fMoveVariable; // Variable to order before moving out entries
157 TArrayD* fX; // Storage array for the 1st variable (e.g. X)
158 TArrayD* fY; // Storage array for the 2nd variable (e.g. Y)
159 TArrayD* fZ; // Storage array for the 3rd variable (e.g. Z)
160 TArrayD* fT; // Storage array for the 4th variable (e.g. T)
161 TArrayD* fArr;
162 TArrayI* fIndices;
163 Int_t fOrdered;
164 TGraphTime* fGraphT;
165 TCanvas* fCanvas;
166 TObject* fAnimObject;
167
168 void Compute(); // Compute the various quantities
169 void Order(Int_t mode,Int_t i); // Order the entries according to the i-th variable
170 void List(Int_t i); // Statistics info for the i-th variable
171 void List(Int_t i,Int_t j) const; // Correlation statistics info for i-th and j-th variable
172 TArrayL64 ADC(Int_t nbits,Double_t range,Double_t Vbias=0,TArray* Vsig=0,TH1* hist=0,Int_t B=0,Int_t C=3) const; // Provide the quantized data of an "nbits" ADC.
173 TArrayD DAC(Int_t nbits,Double_t range,Double_t Vbias=0,TArray* adcs=0,TArray* peds=0,TH1* hist=0,Int_t B=0,Int_t C=3) const; // Reconstruct the analog signals from an "nbits" ADC.
174
175 ClassDef(NcSample,17) // Sampling and statistics tools for various multi-dimensional data samples.
176};
177#endif
Long64_t Transmit(Int_t i, Int_t nbits, Double_t range, Double_t Vbias=0, TArray *peds=0, TH1 *hist=0, Int_t B=0, Int_t C=3)
TGraphQQ GetQQplot(Int_t i, Int_t j, TF1 *f=0)
void Order(Int_t mode, Int_t i)
Definition NcSample.cxx:991
Double_t GetSNR(Int_t i, Int_t mode=2, Bool_t db=kTRUE) const
TCanvas * fCanvas
! Multi-purpose canvas for e.g. animation displays
Definition NcSample.h:165
Int_t fRemove
Definition NcSample.h:153
Int_t GetStoreMode() const
Double_t fRMSdev[fMaxdim]
Definition NcSample.h:147
TH3D Get3DHistogram(Int_t i, Int_t j, Int_t k, Int_t m=0, Bool_t sumw2=kFALSE, Int_t nbx=100, Int_t nby=100, Int_t nbz=100, TF1 *f=0)
void Data(Int_t i=0, Int_t j=0)
Double_t GetCov(Int_t i, Int_t j) const
virtual TObject * Clone(const char *name="") const
TObject * fAnimObject
! Multi-purpose pointer for animation objects
Definition NcSample.h:166
void GetSubset(NcSample *s, Int_t ifirst, Int_t ilast, Int_t mode=0, Int_t k=0)
Int_t GetN() const
TArrayD * fX
Definition NcSample.h:157
Double_t GetMinimum(Int_t i) const
TArrayL64 ADC(Int_t nbits, Double_t range, Double_t Vbias=0, TArray *Vsig=0, TH1 *hist=0, Int_t B=0, Int_t C=3) const
Double_t fMin[fMaxdim]
Definition NcSample.h:151
virtual ~NcSample()
Definition NcSample.cxx:120
Int_t GetIndex(TString name) const
Double_t fSum[fMaxdim]
Definition NcSample.h:144
TH1D Get1DHistogram(Int_t i, Int_t j=0, Bool_t sumw2=kFALSE, Int_t nbx=100, TF1 *f=0)
Double_t GetCor(Int_t i, Int_t j) const
TArrayD * fArr
! Temp. storage array for ordered values
Definition NcSample.h:161
Double_t fCor[fMaxdim][fMaxdim]
Definition NcSample.h:150
TString fNames[fMaxdim]
Definition NcSample.h:143
Double_t fSum2[fMaxdim][fMaxdim]
Definition NcSample.h:145
Int_t fN
Definition NcSample.h:141
void List(Int_t i)
Double_t GetSigma(Int_t i, Int_t model=0) const
void Compute()
TGraphTime * fGraphT
! Temp. pointer to return a TGraphTime object
Definition NcSample.h:164
Double_t GetMedian(Int_t i)
void Animation(Int_t i, Int_t j, Int_t mode, Int_t k, Int_t delay, TString opt="AP")
TGraphErrors GetGraphErrors(TGraph *g, Int_t ix=0, Int_t iy=0, TF1 *fx=0, TF1 *fy=0)
TArrayD * fT
Definition NcSample.h:160
TH1D GetSamplingHistogram(Int_t i, TF1 *f=0)
Int_t fNmax
Definition NcSample.h:155
Int_t fDim
Definition NcSample.h:140
Int_t GetStoreNmax() const
void Reset()
Definition NcSample.cxx:255
NcSample SampleAndHold(TF1 f, Double_t step, Double_t vmin, Double_t vmax, Int_t loc=-1) const
Int_t fOrdered
! Indicator of the status of the current ordering
Definition NcSample.h:163
Double_t GetRMS(Int_t i) const
void Enter(Double_t x)
Definition NcSample.cxx:357
void SetNames(TString name1="X", TString name2="Y", TString name3="Z", TString name4="T")
Definition NcSample.cxx:327
Int_t fStore
Definition NcSample.h:154
Double_t Digitize(Int_t i, Int_t nbits, Double_t vcal, Int_t mode)
NcSample GetDtSample(Int_t i, Int_t nc, Int_t store=1, Int_t nmax=0, Int_t order=0)
TArrayD * fY
Definition NcSample.h:158
Double_t fCov[fMaxdim][fMaxdim]
Definition NcSample.h:149
TArrayD * fZ
Definition NcSample.h:159
Double_t fMax[fMaxdim]
Definition NcSample.h:152
Double_t GetMean(Int_t i) const
TArrayD DAC(Int_t nbits, Double_t range, Double_t Vbias=0, TArray *adcs=0, TArray *peds=0, TH1 *hist=0, Int_t B=0, Int_t C=3) const
void RemoveEntry(Int_t i, Int_t mode, Int_t j)
Definition NcSample.cxx:858
void ListOrdered(Int_t mode, Int_t i)
Double_t fMean[fMaxdim]
Definition NcSample.h:146
Double_t fSigma[fMaxdim]
Definition NcSample.h:148
TString GetVariableName(Int_t i) const
TArrayI * fIndices
! Temp. storage array for the indices of the ordered entries
Definition NcSample.h:162
Int_t GetDimension() const
TGraph GetGraph(Int_t i, TF1 *f=0)
Double_t GetVar(Int_t i, Int_t model=0) const
void SetStoreMode(Int_t mode=1, Int_t nmax=0, Int_t i=0)
Double_t GetMaximum(Int_t i) const
void Load(TGraph *g, Int_t clr=1)
Double_t GetCV(Int_t i, Int_t mode=1) const
Double_t GetSpread(Int_t i, Int_t model=0, Double_t vref=0)
Double_t GetQuantile(Double_t f, Int_t i)
Double_t GetEntry(Int_t i, Int_t j, Int_t mode=0, Int_t k=0)
TGraph2DErrors GetGraph2DErrors(TGraph2D *g, Int_t ix=0, Int_t iy=0, Int_t iz=0, TF1 *fx=0, TF1 *fy=0, TF1 *fz=0)
void Remove(Double_t x)
Definition NcSample.cxx:410
NcSample(const char *name="", const char *title="")
Definition NcSample.cxx:91
TH2D Get2DHistogram(Int_t i, Int_t j, Int_t k=0, Bool_t sumw2=kFALSE, Int_t nbx=100, Int_t nby=100, TF1 *f=0)
Double_t GetSum(Int_t i) const
NcSample SampleAndSum(Int_t i, Double_t step, Int_t loc=0, Int_t j=0, Double_t vmin=0, Double_t vmax=-1)
Int_t fMoveVariable
Definition NcSample.h:156