Skip to main content

Posts

How to Install CERN ROOT on Ubuntu: A Step-by-Step Guide

If you're involved in scientific research or data analysis, you've likely heard of CERN ROOT. Developed by CERN (the European Organization for Nuclear Research), ROOT is an essential toolkit for high-energy physics data analysis. In this guide, we'll walk you through the process of installing CERN ROOT on your Ubuntu machine.  Prerequisites Before we dive into the installation process, make sure you have the following prerequisites in place: A working Ubuntu machine (this guide is tested on Ubuntu 23.04, but it should work on other versions as well). Sudo privileges to install packages. Downloading CERN ROOT Start by downloading the latest version of CERN ROOT from the official website  or open your terminal and use the following command to download the source code: wget https://root.cern/download/root_vX.YY.Z.source.tar.gz Replace X.YY.Z with the version number you want to install (e.g., 6.22.08). Installing Dependencies CERN ROOT relies on several libraries and tools. To
Recent posts

Use of TClonesArray Class

void write { TClonesArray * arr = new TClonesArray ( " TVector3 " ); TClonesArray & ar = * arr ; TFile * file = new TFile ( " file.root " , " recreate " ); TTree * tree = new TTree ( " tcl " , " tcl " ); tree -> Branch ( " array " , & arr ); TRandom2 * rand = new TRandom2 ( 1 ); for ( int i = 0 ; i < 100 ; i ++) { arr -> Clear (); for ( int j = 0 ; j < 1000 ; j ++) { double x = rand -> Rndm (); double y = rand -> Rndm (); double z = rand -> Rndm (); new ( ar [ j ]) TVector3 ( x , y , z ); } tree -> Fill (); } file -> Write (); file -> Close (); } void read () { TFile * file = new TFile ( " file.root " ); TTree * tree = ( TTree *) file -> Get ( " tcl " ); TClonesArray * arr = new

7a

 # Q 7A import numpy as np from scipy.special import legendre as P theta = np.pi n= 2 lhs = np.sin((n+1)*theta)/np.sin(theta) rhs = sum([np.poly1d(P(l))(np.cos(theta)) * np.poly1d(P(n-l))(np.cos(theta)) for l in range(0, n+1)]) print("LHS = ",lhs) print("RHS = ",rhs) print("Difference = ", abs(lhs-rhs))

6a

 # Q 6A # Integral e^-x2 from 0 --> infinity import numpy as np from scipy.integrate import quad, simps import matplotlib.pyplot as plt f = lambda x: np.exp(-x**2) res = quad(f, 0, np.inf) print("Value of integral is = ", round(res[0], 4))

5b

 # Q 5B import numpy as np from scipy.integrate import quad, simps from scipy.signal import square, sawtooth import matplotlib.pyplot as plt x = np.linspace(-np.pi, np.pi, 1001) f1 = abs(np.sin(x)) L = 2*np.pi # Evaluation of Fourier coefficients a0 = (2.0/L)*simps(f1, x) an = lambda n: (2.0/L) * simps(f1*np.cos(n*x), x) bn = lambda n: (2.0/L) * simps(f1*np.sin(n*x), x) # Summing the serier R = 10 xn = np.linspace(-R, R, 1001) s = 0.5*a0 +  sum([an(n)*np.cos(n*xn) + bn(n)*np.sin(n*xn) for n in range(1, 50)]) signal = abs(np.sin(xn)) #Plotting the Functions plt.plot(xn, signal,'r-' ,label="Original Signal") plt.plot(xn, s,'ko',ms=2, label = "Fourier Approximation") plt.legend() plt.show()

5a

 import numpy as np from scipy.integrate import quad import matplotlib.pyplot as plt f = lambda x: np.sin(x**2) A = [] x = np.arange(0.01, 10, 0.01) for i in x:          res = quad(f, 0, i)     A.append(res[0]) print(sum(A)) plt.plot(x[:600], A[:600],label="Fresnel Integral Si(x)") plt.grid() plt.legend() plt.show() print("From the plot, we find that the solution slowly converges to 0.5")

4b

 # Q 4B # Question is nothing but 1-D Heat Equation with heating at middle # Solve by using finite difference method import numpy as np import matplotlib.pyplot as plt from scipy.integrate import quad x = np.linspace(0, 1, 101) u = np.zeros(101) u[0] = u[100] = 0       # Boundary Conditions u[50] = 1               # Initial Condition for t in range(100):     for i in range(1,100):         u[i] += (u[i+1] + u[i-1] -2*u[i])/4 plt.plot(x, u, 'r-', lw=3) plt.xlabel("Length of rod") plt.ylabel("Temperature (in reduced units)") plt.title("Temperature Profile of Rod") plt.show()