Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
write_ntuple_to_file.C
Go to the documentation of this file.
1// Fill an n-tuple and write it to a file simulating measurement of
2// conductivity of a material in different conditions of pressure
3// and temperature.
4
6
7 TFile ofile("conductivity_experiment.root","RECREATE");
8
9 // Initialise the TNtuple
10 TNtuple cond_data("cond_data",
11 "Example N-Tuple",
12 "Potential:Current:Temperature:Pressure");
13
14 // Fill it randomly to fake the acquired data
16 float pot,cur,temp,pres;
17 for (int i=0;i<10000;++i){
18 pot=rndm.Uniform(0.,10.); // get voltage
19 temp=rndm.Uniform(250.,350.); // get temperature
20 pres=rndm.Uniform(0.5,1.5); // get pressure
21 cur=pot/(10.+0.05*(temp-300.)-0.2*(pres-1.)); // current
22 // add some random smearing (measurement errors)
23 pot*=rndm.Gaus(1.,0.01); // 1% error on voltage
24 temp+=rndm.Gaus(0.,0.3); // 0.3 abs. error on temp.
25 pres*=rndm.Gaus(1.,0.02);// 1% error on pressure
26 cur*=rndm.Gaus(1.,0.01); // 1% error on current
27 // write to ntuple
28 cond_data.Fill(pot,cur,temp,pres);
29 }
30
31 // Save the ntuple and close the file
32 cond_data.Write();
33 ofile.Close();
34}
TRandom3 rndm
A file, usually with extension .root, that stores data and code in the form of serialized objects in ...
Definition TFile.h:130
void Close(Option_t *option="") override
Close a file.
Definition TFile.cxx:982
A simple TTree restricted to a list of float variables only.
Definition TNtuple.h:28
Int_t Fill() override
Fill a Ntuple with current values in fArgs.
Definition TNtuple.cxx:168
Random number generator class based on M.
Definition TRandom3.h:27
Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0) override
Write this object to the current directory.
Definition TTree.cxx:10022
void write_ntuple_to_file()