LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
spectrum.C
Go to the documentation of this file.
1 // *********************************************************************
2 // To execute this macro under ROOT after your simulation ended,
3 // 1 - launch ROOT (usually type 'root' at your machine's prompt)
4 // 2 - type '.X spectrum.C' at the ROOT session prompt
5 // 3 - OR type directly 'root spectrum.C'
6 // this will generate an output energy spectrum spectrum.txt,
7 // according to selected statistics and distribution
8 // (energy unit assumed by svalue example: eV)
9 // *********************************************************************
10 
11 {
12 gROOT->Reset();
13 
14 // 1) SELECT number of values to shoot
15 int nbValues = 100;
16 //
17 
18 double value;
19 TNtuple * ntuple = new TNtuple ("","","value");
20 
21 FILE * fp = fopen("spectrum.txt","w");
22 
23 TRandom r;
24 
25 for (int i=0;i<nbValues;i++)
26 {
27 // 2) SELECT distribution
28 // here Gaussian with mean, sigma
29 // see https://root.cern.ch/doc/master/classTRandom.html
30  value = r.Gaus(1.,0.1);
31 //
32  ntuple->Fill(value);
33  fprintf(fp,"%f \n",value);
34 }
35 fclose(fp);
36 
37 ntuple->Draw("value");
38 }
TRandom r
Definition: spectrum.C:23
TNtuple * ntuple
Definition: spectrum.C:19
int nbValues
Definition: spectrum.C:15
fclose(fp)
FILE * fp
Definition: spectrum.C:21
double value
Definition: spectrum.C:18