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