#!/usr/bin/env python # coding: utf-8 # # Filling a n-tuple (simulating the conductivity of a material in different conditions of pressure and temperature) and writing it to a file # Ported to Notebook by: Theis Hansen # # To use the ROOT toolkit, we need to import ROOT onto our Notebook, which we also set to C++ # In[1]: from ROOTaaS.iPyROOT import ROOT ROOT.toCpp() # ### The Tuple # We create a file which will contain our ntuple and the tuple itself. # In[2]: TFile ofile("conductivity_experiment.root","RECREATE"); TNtuple cond_data("cond_data","Example N-Tuple","Potential:Current:Temperature:Pressure"); # Then we fill it randomly (to simulate acquired data) using the TRandom3 random generator. # We are also applying some "smearing" (measurement errors): 1% error on voltage (pot), pressure and current and 1.3 absolute error on temperature. # At the end of the loop body we fill the ntuple. # In[3]: TRandom3 rndm; float pot,cur,temp,pres; for (int i=0;i<10000;++i){ pot=rndm.Uniform(0.,10.); temp=rndm.Uniform(250.,350.); pres=rndm.Uniform(0.5,1.5); cur=pot/(10.+0.05*(temp-300.)-0.2*(pres-1)); pot*=rndm.Gaus(1.,0.01); temp+=rndm.Gaus(0.,0.3); pres*=rndm.Gaus(1.,0.02); cur*=rndm.Gaus(1.,0.01); cond_data.Fill(pot,cur,temp,pres); } # Save the TNtuple and close the file. # In[4]: cond_data.Write(); ofile.Close(); # In[ ]: