File indexing completed on 2025-08-06 08:16:41
0001 #include <TTree.h>
0002 #include <TFile.h>
0003 #include <gsl/gsl_randist.h>
0004 #include <gsl/gsl_rng.h>
0005
0006 #include <stdio.h>
0007 #include <stdlib.h>
0008
0009
0010 R__LOAD_LIBRARY(libgslcblas.so)
0011 R__LOAD_LIBRARY(libgsl.so)
0012
0013
0014 void simulateTimestamps()
0015 {
0016
0017
0018 auto rng = gsl_rng_alloc(gsl_rng_mt19937);
0019
0020 gsl_rng_set( rng, 1 );
0021
0022
0023
0024 static constexpr double deltat_crossing = 106e-9;
0025
0026
0027
0028 static constexpr double trigger_rate = 5e4;
0029
0030
0031
0032 static constexpr double mu = trigger_rate*deltat_crossing;
0033
0034
0035 printf("SimulateCollisions - deltat_crossing: %f \n", deltat_crossing );
0036 printf("SimulateCollisions - trigger_rate: %f \n" , trigger_rate);
0037 printf("SimulateCollisions - mu: %f \n" , mu);
0038
0039
0040
0041
0042 static constexpr uint ntrigtot = 1e6;
0043
0044 FILE *fptr;
0045 fptr = fopen("./data/timestamps_50kHz_1M.txt","w");
0046 fprintf(fptr,"// bunchcrossin id; time (ns)\n");
0047 fprintf(fptr,"// assuming 106ns between bunches\n" );
0048
0049
0050
0051 int64_t bunchcrossing = 0;
0052 float time = 0;
0053 float timeD = 0;
0054 TTree *timestamps = new TTree("timestamps","beamcrossings timestamps");
0055 timestamps -> Branch("bc", &bunchcrossing, "bc/I");
0056 timestamps -> Branch("t", &time, "t/F");
0057 timestamps -> Branch("dt", &timeD, "dt/F");
0058
0059
0060 double previous_trigger_time = 0;
0061
0062
0063 for( int itrig = 0; itrig < ntrigtot; )
0064 {
0065 ++ bunchcrossing;
0066 time += deltat_crossing;
0067
0068 auto ntrig = gsl_ran_poisson( rng, mu );
0069 for( uint i = 0; i < ntrig; ++i )
0070 {
0071 fprintf(fptr,"%d %d\n",int(bunchcrossing), int(time*1e9) );
0072 timeD = (time-previous_trigger_time)*1e9;
0073 timestamps ->Fill();
0074 previous_trigger_time = time;
0075 ++itrig;
0076 if( itrig%100000==0 ) printf("SimulateCollisions - itrig: %d \n", itrig );
0077 }
0078 }
0079
0080
0081 printf("SimulateCollisions - last trigger time: %f \n", time );
0082
0083 fclose(fptr);
0084
0085 gsl_rng_free(rng);
0086
0087 TFile *outf = new TFile("./data/timestamps_50kHz_1M_t.root","recreate");
0088 timestamps -> Write();
0089
0090 outf -> Write();
0091 outf -> Close();
0092
0093 }