Create points along a random linear line
Task 1
In each event, create 21 two dimensional points (x, y) with x ranging from -10 to 10 and y ranging from -10 to 10.
The x and y values of each point is determined in the following way:
-
Create two random variables
\thetaandb, which have the following distribution:\begin{align*} \theta &\sim \cos(\theta),\enskip \theta \in [-\frac{\pi}{2}, \frac{\pi}{2}] \\ b &\sim \mathcal{U}(-10, 10) \end{align*} -
Compute the slope of the line from
\thetaand dertermine the equation of the line:y = a x + b -
Create x values from -10 to 10 with a division of 1, i.e.
{-10, -8, -7, ... 9, 10} -
Calculate the mean value of y:
\bar{y} = a x + b -
Calculate the value of y of each point from its mean value from gaussian distribution:
y \sim \mathcal{N}(\bar{y}, 1) -
After generating 21 points, save the data to a root file.
-
Reiterate such process for 10'000 events.
Data structure stored in ROOT file:
struct {
double theta;
double offset;
std::vector<double> x;
std::vector<double> y;
};
Example to write data to root file:
check this: https://gitlab.ikp.uni-koeln.de/ywang/examplerntuple.git
Edited by Yanzhao Wang