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:

  1. Create two random variables \theta and b, 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*}
  2. Compute the slope of the line from \theta and dertermine the equation of the line:

    y = a x + b
  3. Create x values from -10 to 10 with a division of 1, i.e. {-10, -8, -7, ... 9, 10}

  4. Calculate the mean value of y:

    \bar{y} = a x + b
  5. Calculate the value of y of each point from its mean value from gaussian distribution:

    y \sim \mathcal{N}(\bar{y}, 1)
  6. After generating 21 points, save the data to a root file.

  7. 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