3 #include <gsl/gsl_randist.h>
4 #include <gsl/gsl_rng.h>
10 R__LOAD_LIBRARY(libgslcblas.so)
11 R__LOAD_LIBRARY(libgsl.so)
18 auto rng = gsl_rng_alloc(gsl_rng_mt19937);
24 static constexpr
double deltat_crossing = 106
e-9;
28 static constexpr
double trigger_rate = 5e4;
32 static constexpr
double mu = trigger_rate*deltat_crossing;
35 printf(
"SimulateCollisions - deltat_crossing: %f \n", deltat_crossing );
36 printf(
"SimulateCollisions - trigger_rate: %f \n" , trigger_rate);
37 printf(
"SimulateCollisions - mu: %f \n" , mu);
42 static constexpr uint ntrigtot = 1e6;
45 fptr = fopen(
"./data/timestamps_50kHz_1M.txt",
"w");
46 fprintf(fptr,
"// bunchcrossin id; time (ns)\n");
47 fprintf(fptr,
"// assuming 106ns between bunches\n" );
51 int64_t bunchcrossing = 0;
54 TTree *timestamps =
new TTree(
"timestamps",
"beamcrossings timestamps");
55 timestamps ->
Branch(
"bc", &bunchcrossing,
"bc/I");
56 timestamps ->
Branch(
"t", &time,
"t/F");
57 timestamps ->
Branch(
"dt", &timeD,
"dt/F");
60 double previous_trigger_time = 0;
63 for(
int itrig = 0; itrig < ntrigtot; )
66 time += deltat_crossing;
68 auto ntrig = gsl_ran_poisson(
rng, mu );
69 for( uint
i = 0;
i < ntrig; ++
i )
71 fprintf(fptr,
"%d %d\n",
int(bunchcrossing),
int(time*1e9) );
72 timeD = (time-previous_trigger_time)*1e9;
74 previous_trigger_time =
time;
76 if( itrig%100000==0 )
printf(
"SimulateCollisions - itrig: %d \n", itrig );
81 printf(
"SimulateCollisions - last trigger time: %f \n", time );
87 TFile *outf =
new TFile(
"./data/timestamps_50kHz_1M_t.root",
"recreate");
88 timestamps ->
Write();