diff --git a/comp_hist_fit_rms_graph_errors.c b/comp_hist_fit_rms_graph_errors.c new file mode 100644 index 0000000..50a6bc6 --- /dev/null +++ b/comp_hist_fit_rms_graph_errors.c @@ -0,0 +1,852 @@ +void comp_hist_fit_rms_graph_errors() { + TCanvas *c1 = new TCanvas("graph1","graph1",200,10,700,500); + TCanvas *c2 = new TCanvas("graph2","graph2",200,10,700,500); + TCanvas *c3 = new TCanvas("graph3","graph3",200,10,700,500); + TCanvas *c4 = new TCanvas("graph4","graph4",200,10,700,500); + + c1->SetGrid(); + c2->SetGrid(); + c3->SetGrid(); + c4->SetGrid(); + + const Int_t n = 9; // 16 + + Float_t energy[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t energyerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t mean[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t meanerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rmserror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t mean60[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms60[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean65[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms65[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean70[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms70[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean75[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms75[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean80[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms80[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean85[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms85[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean100[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms100[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t mean_mean[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_mean[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_meanerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_meanerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_sigma[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_sigma[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_sigmaerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_sigmaerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_chi[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_chi[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t ratio_hist[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_stat_hist[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_sys_hist[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_hist[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_hist[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat_hist[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys_hist[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_hist[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t ratio60[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_stat60[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_sys60[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error60[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution60[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat60[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys60[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error60[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t ratio65[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_stat65[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_sys65[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error65[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution65[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat65[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys65[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error65[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t ratio70[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_stat70[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_sys70[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error70[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution70[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat70[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys70[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error70[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t ratio75[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_stat75[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_sys75[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error75[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution75[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat75[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys75[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error75[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t ratio80[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_stat80[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_sys80[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error80[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution80[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat80[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys80[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error80[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t ratio85[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_stat85[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_sys85[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error85[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution85[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat85[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys85[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error85[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t ratio90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_stat90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_sys90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t ratio95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_stat95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_sys95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t ratio100[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_stat100[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_sys100[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error100[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution100[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat100[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys100[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error100[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t linearity_error[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t absolute_error[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_stat[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_sys[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t mean_mean2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_mean2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_meanerror2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_meanerror2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_sigma2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_sigma2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_sigmaerror2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_sigmaerror2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_chi2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_chi2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t linearity_error2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t absolute_error2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_stat2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_sys2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + FILE *file1 = fopen("new_1out_data.txt", "r"); + if ( !(long)file1 ) return; + + FILE *file2 = fopen("new_2out_data.txt", "r"); + if ( !(long)file2 ) return; + + for ( int i = 0; i < n; i++ ) { + fscanf( file1, "%f %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E\n", &energy[i], &mean60[i], &rms60[i], &mean65[i], &rms65[i], &mean70[i], &rms70[i], &mean75[i], &rms75[i], &mean80[i], &rms80[i], &mean85[i], &rms85[i], &mean90[i], &rms90[i], &mean95[i], &rms95[i], &mean100[i], &rms100[i], &mean[i], &meanerror[i], &rms[i], &rmserror[i], &mean_mean[i], &rms_mean[i], &mean_meanerror[i], &rms_meanerror[i], &mean_sigma[i], &rms_sigma[i], &mean_sigmaerror[i], &rms_sigmaerror[i], &mean_chi[i], &rms_chi[i] ); + if ( feof( file1 ) ) break; + } + + for ( int i = 0; i < n; i++ ) { + fscanf( file2, "%f %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E\n", &energy[i], &mean60[i], &rms60[i], &mean65[i], &rms65[i], &mean70[i], &rms70[i], &mean75[i], &rms75[i], &mean80[i], &rms80[i], &mean85[i], &rms85[i], &mean90[i], &rms90[i], &mean95[i], &rms95[i], &mean100[i], &rms100[i], &mean[i], &meanerror[i], &rms[i], &rmserror[i], &mean_mean2[i], &mean_meanerror2[i], &mean_sigma2[i], &mean_sigmaerror2[i], &mean_chi2[i] ); + if ( feof( file2 ) ) break; + } + + for ( int i = 0; i < n; i++ ) { + + //linearity_error[ i ] = sqrt( ( pow( mean_meanerror[ i ], 2 ) ) + ( pow( rms_mean[ i ], 2 ) ) ); + //absolute_error[ i ] = sqrt( ( pow( mean_sigmaerror[ i ], 2 ) ) + ( pow( rms_sigma[ i ], 2 ) ) ); + //linearity_error2[ i ] = sqrt( ( pow( mean_meanerror2[ i ], 2 ) ) + ( pow( rms_mean2[ i ], 2 ) ) ); + //absolute_error2[ i ] = sqrt( ( pow( mean_sigmaerror2[ i ], 2 ) ) + ( pow( rms_sigma2[ i ], 2 ) ) ); + + ratio_hist[ i ] = ( mean[i] - energy[i] ) / energy[i]; + ratio_error_stat_hist[ i ] = sqrt( pow( (meanerror[i]) / (energy[i]), 2 ) + pow( (mean[i] * energyerror[i]) / (energy[i] * energy[i]), 2 ) ); + ratio_error_sys_hist[ i ] = 0.0; + ratio_error_hist[ i ] = sqrt( ( pow( ratio_error_stat_hist[ i ], 2 ) ) + ( pow( ratio_error_sys_hist[ i ], 2 ) ) ); + + ratio60[ i ] = ( mean60[i] - energy[i] ) / energy[i]; + ratio_error_stat60[ i ] = 0.0; + ratio_error_sys60[ i ] = 0.0; + ratio_error60[ i ] = sqrt( ( pow( ratio_error_stat60[ i ], 2 ) ) + ( pow( ratio_error_sys60[ i ], 2 ) ) ); + ratio65[ i ] = ( mean65[i] - energy[i] ) / energy[i]; + ratio_error_stat65[ i ] = 0.0; + ratio_error_sys65[ i ] = 0.0; + ratio_error65[ i ] = sqrt( ( pow( ratio_error_stat65[ i ], 2 ) ) + ( pow( ratio_error_sys65[ i ], 2 ) ) ); + ratio70[ i ] = ( mean70[i] - energy[i] ) / energy[i]; + ratio_error_stat70[ i ] = 0.0; + ratio_error_sys70[ i ] = 0.0; + ratio_error70[ i ] = sqrt( ( pow( ratio_error_stat70[ i ], 2 ) ) + ( pow( ratio_error_sys70[ i ], 2 ) ) ); + ratio75[ i ] = ( mean75[i] - energy[i] ) / energy[i]; + ratio_error_stat75[ i ] = 0.0; + ratio_error_sys75[ i ] = 0.0; + ratio_error75[ i ] = sqrt( ( pow( ratio_error_stat75[ i ], 2 ) ) + ( pow( ratio_error_sys75[ i ], 2 ) ) ); + ratio80[ i ] = ( mean80[i] - energy[i] ) / energy[i]; + ratio_error_stat80[ i ] = 0.0; + ratio_error_sys80[ i ] = 0.0; + ratio_error80[ i ] = sqrt( ( pow( ratio_error_stat80[ i ], 2 ) ) + ( pow( ratio_error_sys80[ i ], 2 ) ) ); + ratio85[ i ] = ( mean85[i] - energy[i] ) / energy[i]; + ratio_error_stat85[ i ] = 0.0; + ratio_error_sys85[ i ] = 0.0; + ratio_error85[ i ] = sqrt( ( pow( ratio_error_stat85[ i ], 2 ) ) + ( pow( ratio_error_sys85[ i ], 2 ) ) ); + ratio90[ i ] = ( mean90[i] - energy[i] ) / energy[i]; + ratio_error_stat90[ i ] = 0.0; + ratio_error_sys90[ i ] = 0.0; + ratio_error90[ i ] = sqrt( ( pow( ratio_error_stat90[ i ], 2 ) ) + ( pow( ratio_error_sys90[ i ], 2 ) ) ); + ratio95[ i ] = ( mean95[i] - energy[i] ) / energy[i]; + ratio_error_stat95[ i ] = 0.0; + ratio_error_sys95[ i ] = 0.0; + ratio_error95[ i ] = sqrt( ( pow( ratio_error_stat95[ i ], 2 ) ) + ( pow( ratio_error_sys95[ i ], 2 ) ) ); + ratio100[ i ] = ( mean100[i] - energy[i] ) / energy[i]; + ratio_error_stat100[ i ] = 0.0; + ratio_error_sys100[ i ] = 0.0; + ratio_error100[ i ] = sqrt( ( pow( ratio_error_stat100[ i ], 2 ) ) + ( pow( ratio_error_sys100[ i ], 2 ) ) ); + + ratio[ i ] = ( mean_mean[i] - energy[i] ) / energy[i]; + ratio_error_stat[ i ] = sqrt( pow( (mean_meanerror[i]) / (energy[i]), 2 ) + pow( (mean_mean[i] * energyerror[i]) / (energy[i] * energy[i]), 2 ) ); + ratio_error_sys[ i ] = sqrt( pow( (rms_mean[i]) / (energy[i]), 2 ) + pow( (mean_mean[i] * energyerror[i]) / (energy[i] * energy[i]), 2 ) ); + ratio_error[ i ] = sqrt( ( pow( ratio_error_stat[ i ], 2 ) ) + ( pow( ratio_error_sys[ i ], 2 ) ) ); + + ratio2[ i ] = ( mean_mean2[i] - energy[i] ) / energy[i]; + ratio_error_stat2[ i ] = sqrt( pow( (mean_meanerror2[i]) / (energy[i]), 2 ) + pow( (mean_mean2[i] * energyerror[i]) / (energy[i] * energy[i]), 2 ) ); + ratio_error_sys2[ i ] = 0.0; + ratio_error2[ i ] = sqrt( ( pow( ratio_error_stat2[ i ], 2 ) ) + ( pow( ratio_error_sys2[ i ], 2 ) ) ); + + resolution_hist[ i ] = rms[i] / mean[i]; + resolution_error_stat_hist[ i ] = sqrt( pow( (rmserror[i]) / (mean[i]), 2 ) + pow( (rms[i] * meanerror[i]) / (mean[i] * mean[i]), 2 ) ); + resolution_error_sys_hist[ i ] = 0.0; + resolution_error_hist[ i ] = sqrt( ( pow( resolution_error_stat_hist[ i ], 2 ) ) + ( pow( resolution_error_sys_hist[ i ], 2 ) ) ); + + resolution60[ i ] = rms60[i] / mean60[i]; + resolution_error_stat60[ i ] = 0.0; + resolution_error_sys60[ i ] = 0.0; + resolution_error60[ i ] = sqrt( ( pow( resolution_error_stat60[ i ], 2 ) ) + ( pow( resolution_error_sys60[ i ], 2 ) ) ); + + resolution65[ i ] = rms65[i] / mean65[i]; + resolution_error_stat65[ i ] = 0.0; + resolution_error_sys65[ i ] = 0.0; + resolution_error65[ i ] = sqrt( ( pow( resolution_error_stat65[ i ], 2 ) ) + ( pow( resolution_error_sys65[ i ], 2 ) ) ); + + resolution70[ i ] = rms70[i] / mean70[i]; + resolution_error_stat70[ i ] = 0.0; + resolution_error_sys70[ i ] = 0.0; + resolution_error70[ i ] = sqrt( ( pow( resolution_error_stat70[ i ], 2 ) ) + ( pow( resolution_error_sys70[ i ], 2 ) ) ); + + resolution75[ i ] = rms75[i] / mean75[i]; + resolution_error_stat75[ i ] = 0.0; + resolution_error_sys75[ i ] = 0.0; + resolution_error75[ i ] = sqrt( ( pow( resolution_error_stat75[ i ], 2 ) ) + ( pow( resolution_error_sys75[ i ], 2 ) ) ); + + resolution80[ i ] = rms80[i] / mean80[i]; + resolution_error_stat80[ i ] = 0.0; + resolution_error_sys80[ i ] = 0.0; + resolution_error80[ i ] = sqrt( ( pow( resolution_error_stat80[ i ], 2 ) ) + ( pow( resolution_error_sys80[ i ], 2 ) ) ); + + resolution85[ i ] = rms85[i] / mean85[i]; + resolution_error_stat85[ i ] = 0.0; + resolution_error_sys85[ i ] = 0.0; + resolution_error85[ i ] = sqrt( ( pow( resolution_error_stat85[ i ], 2 ) ) + ( pow( resolution_error_sys85[ i ], 2 ) ) ); + + resolution90[ i ] = rms90[i] / mean90[i]; + resolution_error_stat90[ i ] = 0.0; + resolution_error_sys90[ i ] = 0.0; + resolution_error90[ i ] = sqrt( ( pow( resolution_error_stat90[ i ], 2 ) ) + ( pow( resolution_error_sys90[ i ], 2 ) ) ); + + resolution95[ i ] = rms95[i] / mean95[i]; + resolution_error_stat95[ i ] = 0.0; + resolution_error_sys95[ i ] = 0.0; + resolution_error95[ i ] = sqrt( ( pow( resolution_error_stat95[ i ], 2 ) ) + ( pow( resolution_error_sys95[ i ], 2 ) ) ); + + resolution100[ i ] = rms100[i] / mean100[i]; + resolution_error_stat100[ i ] = 0.0; + resolution_error_sys100[ i ] = 0.0; + resolution_error100[ i ] = sqrt( ( pow( resolution_error_stat100[ i ], 2 ) ) + ( pow( resolution_error_sys100[ i ], 2 ) ) ); + + resolution[ i ] = mean_sigma[i] / mean_mean[i]; + resolution_error_stat[ i ] = sqrt( pow( (mean_sigmaerror[i]) / (mean_mean[i]), 2 ) + pow( (mean_sigma[i] * mean_meanerror[i]) / (mean_mean[i] * mean_mean[i]), 2 ) ); + resolution_error_sys[ i ] = sqrt( pow( (rms_sigma[i]) / (mean_mean[i]), 2 ) + pow( (mean_sigma[i] * rms_mean[i]) / (mean_mean[i] * mean_mean[i]), 2 ) ); + resolution_error[ i ] = sqrt( ( pow( resolution_error_stat[ i ], 2 ) ) + ( pow( resolution_error_sys[ i ], 2 ) ) ); + + resolution2[ i ] = mean_sigma2[i] / mean_mean2[i]; + resolution_error_stat2[ i ] = sqrt( pow( (mean_sigmaerror2[i]) / (mean_mean2[i]), 2 ) + pow( (mean_sigma2[i] * mean_meanerror2[i]) / (mean_mean2[i] * mean_mean2[i]), 2 ) ); + resolution_error_sys2[ i ] = 0.0; + resolution_error2[ i ] = sqrt( ( pow( resolution_error_stat2[ i ], 2 ) ) + ( pow( resolution_error_sys2[ i ], 2 ) ) ); + + } + + printf( "\n" ); + for (int i = 0; i < n; i++) { + printf( " %f ", energy[i] ); + printf( " %f ", energyerror[i] ); + + printf( " %f ", mean[i] ); + printf( " %f ", meanerror[i] ); + printf( " %f ", rms[i] ); + printf( " %f ", rmserror[i] ); + + printf( " %f ", mean60[i] ); + printf( " %f ", rms60[i] ); + printf( " %f ", mean65[i] ); + printf( " %f ", rms65[i] ); + printf( " %f ", mean70[i] ); + printf( " %f ", rms70[i] ); + printf( " %f ", mean75[i] ); + printf( " %f ", rms75[i] ); + printf( " %f ", mean80[i] ); + printf( " %f ", rms80[i] ); + printf( " %f ", mean85[i] ); + printf( " %f ", rms85[i] ); + printf( " %f ", mean90[i] ); + printf( " %f ", rms90[i] ); + printf( " %f ", mean95[i] ); + printf( " %f ", rms95[i] ); + printf( " %f ", mean100[i] ); + printf( " %f ", rms100[i] ); + + printf( " %f ", ratio_hist[i] ); + printf( " %f ", ratio_error_hist[i] ); + printf( " %f ", resolution_hist[i] ); + printf( " %f ", resolution_error_hist[i] ); + + printf( " %f ", ratio60[i] ); + printf( " %f ", ratio_error60[i] ); + printf( " %f ", resolution60[i] ); + printf( " %f ", resolution_error60[i] ); + printf( " %f ", ratio65[i] ); + printf( " %f ", ratio_error65[i] ); + printf( " %f ", resolution65[i] ); + printf( " %f ", resolution_error65[i] ); + printf( " %f ", ratio70[i] ); + printf( " %f ", ratio_error70[i] ); + printf( " %f ", resolution70[i] ); + printf( " %f ", resolution_error70[i] ); + printf( " %f ", ratio75[i] ); + printf( " %f ", ratio_error75[i] ); + printf( " %f ", resolution75[i] ); + printf( " %f ", resolution_error75[i] ); + printf( " %f ", ratio80[i] ); + printf( " %f ", ratio_error80[i] ); + printf( " %f ", resolution80[i] ); + printf( " %f ", resolution_error80[i] ); + printf( " %f ", ratio85[i] ); + printf( " %f ", ratio_error85[i] ); + printf( " %f ", resolution85[i] ); + printf( " %f ", resolution_error85[i] ); + printf( " %f ", ratio90[i] ); + printf( " %f ", ratio_error90[i] ); + printf( " %f ", resolution90[i] ); + printf( " %f ", resolution_error90[i] ); + printf( " %f ", ratio95[i] ); + printf( " %f ", ratio_error95[i] ); + printf( " %f ", resolution95[i] ); + printf( " %f ", resolution_error95[i] ); + printf( " %f ", ratio100[i] ); + printf( " %f ", ratio_error100 [i] ); + printf( " %f ", resolution100[i] ); + printf( " %f ", resolution_error100[i] ); + + printf( " %f ", mean_mean[i] ); + printf( " %f ", rms_mean[i] ); + printf( " %f ", mean_meanerror[i] ); + printf( " %f ", rms_meanerror[i] ); + printf( " %f ", mean_sigma[i] ); + printf( " %f ", rms_sigma[i] ); + printf( " %f ", mean_sigmaerror[i] ); + printf( " %f ", rms_sigmaerror[i] ); + printf( " %f ", linearity_error[i] ); + printf( " %f ", absolute_error[i] ); + printf( " %f ", ratio[i] ); + printf( " %f ", ratio_error[i] ); + printf( " %f ", resolution[i] ); + printf( " %f ", resolution_error[i] ); + + printf( " %f ", mean_mean2[i] ); + printf( " %f ", rms_mean2[i] ); + printf( " %f ", mean_meanerror2[i] ); + printf( " %f ", rms_meanerror2[i] ); + printf( " %f ", mean_sigma2[i] ); + printf( " %f ", rms_sigma2[i] ); + printf( " %f ", mean_sigmaerror2[i] ); + printf( " %f ", rms_sigmaerror2[i] ); + printf( " %f ", linearity_error2[i] ); + printf( " %f ", absolute_error2[i] ); + printf( " %f ", ratio2[i] ); + printf( " %f ", ratio_error2[i] ); + printf( " %f ", resolution2[i] ); + printf( " %f ", resolution_error2[i] ); + + printf( "\n" ); + printf( "\n" ); + printf( "\n" ); + + } + + TGraphErrors *agr; + TGraphErrors *bgr; + + TGraphErrors *cgr; + TGraphErrors *dgr; + + TGraphErrors *egr; + TGraphErrors *fgr; + + char fname[ 100 ]; + for ( int i = 0; i < 100; i++ ) fname[ i ] = 0; + + c1->cd(); + agr = new TGraphErrors( n, energy, ratio80, energyerror, ratio_error_sys80 ); + //agr = new TGraphErrors( n, energy, ratio90, energyerror, ratio_error_sys90 ); + //agr = new TGraphErrors( n, energy, ratio, energyerror, ratio_error_sys ); + //agr = new TGraphErrors( n, energy, ratio90, energyerror, ratio_error_sys90 ); + //agr = new TGraphErrors( n, energy, ratio2, energyerror, ratio_error_sys2 ); + //agr = new TGraphErrors( n, energy, ratio, energyerror, ratio_error_sys ); + agr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy, ratio80, energyerror, ratio_error_stat80 ); + //bgr = new TGraphErrors( n, energy, ratio90, energyerror, ratio_error_stat90 ); + //bgr = new TGraphErrors( n, energy, ratio, energyerror, ratio_error_stat ); + //bgr = new TGraphErrors( n, energy, ratio90, energyerror, ratio_error_stat90 ); + //bgr = new TGraphErrors( n, energy, ratio2, energyerror, ratio_error_stat2 ); + //bgr = new TGraphErrors( n, energy, ratio, energyerror, ratio_error_stat ); + bgr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + cgr = new TGraphErrors( n, energy, ratio85, energyerror, ratio_error_sys85 ); + //cgr = new TGraphErrors( n, energy, ratio95, energyerror, ratio_error_sys95 ); + //cgr = new TGraphErrors( n, energy, ratio2, energyerror, ratio_error_sys2 ); + //cgr = new TGraphErrors( n, energy, ratio100, energyerror, ratio_error_sys100 ); + //cgr = new TGraphErrors( n, energy, ratio_hist, energyerror, ratio_error_sys_hist ); + //cgr = new TGraphErrors( n, energy, ratio2, energyerror, ratio_error_sys2 ); + cgr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + cgr->GetXaxis()->SetTitle("E_{true}, GeV"); + dgr = new TGraphErrors( n, energy, ratio85, energyerror, ratio_error_stat85 ); + //dgr = new TGraphErrors( n, energy, ratio95, energyerror, ratio_error_stat95 ); + //dgr = new TGraphErrors( n, energy, ratio2, energyerror, ratio_error_stat2 ); + //dgr = new TGraphErrors( n, energy, ratio100, energyerror, ratio_error_stat100 ); + //dgr = new TGraphErrors( n, energy, ratio_hist, energyerror, ratio_error_stat_hist ); + //dgr = new TGraphErrors( n, energy, ratio2, energyerror, ratio_error_stat2 ); + dgr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + dgr->GetXaxis()->SetTitle("E_{true}, GeV"); + egr = new TGraphErrors( n, energy, ratio90, energyerror, ratio_error_sys90 ); + //egr = new TGraphErrors( n, energy, ratio100, energyerror, ratio_error_sys100 ); + //egr = new TGraphErrors( n, energy, ratio90, energyerror, ratio_error_sys90 ); + //egr = new TGraphErrors( n, energy, ratio_hist, energyerror, ratio_error_sys_hist ); + //egr = new TGraphErrors( n, energy, ratio90, energyerror, ratio_error_sys90 ); + //egr = new TGraphErrors( n, energy, ratio_hist, energyerror, ratio_error_sys_hist ); + egr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + egr->GetXaxis()->SetTitle("E_{true}, GeV"); + fgr = new TGraphErrors( n, energy, ratio90, energyerror, ratio_error_stat90 ); + //fgr = new TGraphErrors( n, energy, ratio100, energyerror, ratio_error_stat100 ); + //fgr = new TGraphErrors( n, energy, ratio90, energyerror, ratio_error_stat90 ); + //fgr = new TGraphErrors( n, energy, ratio_hist, energyerror, ratio_error_stat_hist ); + //fgr = new TGraphErrors( n, energy, ratio90, energyerror, ratio_error_stat90 ); + //fgr = new TGraphErrors( n, energy, ratio_hist, energyerror, ratio_error_stat_hist ); + fgr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + fgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Linearity" ); + agr->GetYaxis()->SetRangeUser(-0.2, 0.2); + agr->SetTitle(fname); + + agr->SetFillColor(kCyan); + agr->SetFillStyle(3001); + agr->SetMarkerColor(kCyan); + agr->SetLineColor(kCyan); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); + agr->Draw("A 3"); + bgr->SetMarkerColor(kBlue); + bgr->SetLineColor(kBlue); + bgr->SetLineWidth(3); + bgr->SetFillColor(kCyan); + bgr->SetMarkerStyle(20); + bgr->Draw("P SAME"); + cgr->SetMarkerColor(kYellow-6); + cgr->SetFillStyle(3001); + cgr->SetLineColor(kYellow-6); + cgr->SetLineWidth(3); + cgr->SetFillColor(kYellow-6); + cgr->SetMarkerStyle(20); + cgr->Draw("3 SAME"); + dgr->SetMarkerColor(kRed); + dgr->SetLineColor(kRed); + dgr->SetLineWidth(3); + dgr->SetFillColor(kYellow-6); + dgr->SetMarkerStyle(20); + dgr->Draw("P SAME"); + egr->SetMarkerColor(kViolet-6); + egr->SetFillStyle(3001); + egr->SetLineColor(kViolet-6); + egr->SetLineWidth(3); + egr->SetFillColor(kViolet-6); + egr->SetMarkerStyle(20); + egr->Draw("3 SAME"); + fgr->SetMarkerColor(kGreen+1); + fgr->SetLineColor(kGreen+1); + fgr->SetLineWidth(3); + fgr->SetFillColor(kViolet-6); + fgr->SetMarkerStyle(20); + fgr->Draw("P SAME"); + + c1->Update(); + + c2->cd(); + agr = new TGraphErrors( n, energy, rms80, energyerror, energyerror ); + //agr = new TGraphErrors( n, energy, rms90, energyerror, energyerror ); + //agr = new TGraphErrors( n, energy, mean_sigma, energyerror, rms_sigma ); + //agr = new TGraphErrors( n, energy, rms90, energyerror, energyerror ); + //agr = new TGraphErrors( n, energy, mean_sigma2, energyerror, rms_sigma2 ); + //agr = new TGraphErrors( n, energy, mean_sigma, energyerror, rms_sigma ); + agr->GetYaxis()->SetTitle("#sigma_{reco}, GeV"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy, rms80, energyerror, energyerror ); + //bgr = new TGraphErrors( n, energy, rms90, energyerror, energyerror ); + //bgr = new TGraphErrors( n, energy, mean_sigma, energyerror, mean_sigmaerror ); + //bgr = new TGraphErrors( n, energy, rms90, energyerror, energyerror ); + //bgr = new TGraphErrors( n, energy, mean_sigma2, energyerror, mean_sigmaerror2 ); + //bgr = new TGraphErrors( n, energy, mean_sigma, energyerror, mean_sigmaerror ); + bgr->GetYaxis()->SetTitle("#sigma_{reco}, GeV"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + cgr = new TGraphErrors( n, energy, rms85, energyerror, energyerror ); + //cgr = new TGraphErrors( n, energy, rms95, energyerror, energyerror ); + //cgr = new TGraphErrors( n, energy, mean_sigma2, energyerror, rms_sigma2 ); + //cgr = new TGraphErrors( n, energy, rms100, energyerror, energyerror ); + //cgr = new TGraphErrors( n, energy, rms, energyerror, energyerror );// energyerror == 0 + //cgr = new TGraphErrors( n, energy, mean_sigma2, energyerror, rms_sigma2 ); + cgr->GetYaxis()->SetTitle("#sigma_{reco}, GeV"); + cgr->GetXaxis()->SetTitle("E_{true}, GeV"); + dgr = new TGraphErrors( n, energy, rms85, energyerror, energyerror ); + //dgr = new TGraphErrors( n, energy, rms95, energyerror, energyerror ); + //dgr = new TGraphErrors( n, energy, mean_sigma2, energyerror, mean_sigmaerror2 ); + //dgr = new TGraphErrors( n, energy, rms100, energyerror, energyerror ); + //dgr = new TGraphErrors( n, energy, rms, energyerror, rmserror ); + //dgr = new TGraphErrors( n, energy, mean_sigma2, energyerror, mean_sigmaerror2 ); + dgr->GetYaxis()->SetTitle("#sigma_{reco}, GeV"); + dgr->GetXaxis()->SetTitle("E_{true}, GeV"); + egr = new TGraphErrors( n, energy, rms90, energyerror, energyerror ); + //egr = new TGraphErrors( n, energy, rms100, energyerror, energyerror ); + //egr = new TGraphErrors( n, energy, rms90, energyerror, energyerror ); + //egr = new TGraphErrors( n, energy, rms, energyerror, energyerror ); + //egr = new TGraphErrors( n, energy, rms90, energyerror, energyerror ); + //egr = new TGraphErrors( n, energy, rms, energyerror, energyerror ); + egr->GetYaxis()->SetTitle("#sigma_{reco}, GeV"); + egr->GetXaxis()->SetTitle("E_{true}, GeV"); + fgr = new TGraphErrors( n, energy, rms90, energyerror, energyerror ); + //fgr = new TGraphErrors( n, energy, rms100, energyerror, energyerror ); + //fgr = new TGraphErrors( n, energy, rms90, energyerror, energyerror ); + //fgr = new TGraphErrors( n, energy, rms, energyerror, rmserror ); + //fgr = new TGraphErrors( n, energy, rms90, energyerror, energyerror ); + //fgr = new TGraphErrors( n, energy, rms, energyerror, rmserror ); + fgr->GetYaxis()->SetTitle("#sigma_{reco}, GeV"); + fgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Absolute energy resolution" ); + agr->GetYaxis()->SetRangeUser(0.0, 9.0); + agr->SetTitle(fname); + + agr->SetFillColor(kCyan); + agr->SetFillStyle(3001); + agr->SetMarkerColor(kCyan); + agr->SetLineColor(kCyan); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); + agr->Draw("A 3"); + bgr->SetMarkerColor(kBlue); + bgr->SetLineColor(kBlue); + bgr->SetLineWidth(3); + bgr->SetFillColor(kCyan); + bgr->SetMarkerStyle(20); + bgr->Draw("P SAME"); + cgr->SetMarkerColor(kYellow-6); + cgr->SetFillStyle(3001); + cgr->SetLineColor(kYellow-6); + cgr->SetLineWidth(3); + cgr->SetFillColor(kYellow-6); + cgr->SetMarkerStyle(20); + cgr->Draw("3 SAME"); + dgr->SetMarkerColor(kRed); + dgr->SetLineColor(kRed); + dgr->SetLineWidth(3); + dgr->SetFillColor(kYellow-6); + dgr->SetMarkerStyle(20); + dgr->Draw("P SAME"); + egr->SetMarkerColor(kViolet-6); + egr->SetFillStyle(3001); + egr->SetLineColor(kViolet-6); + egr->SetLineWidth(3); + egr->SetFillColor(kViolet-6); + egr->SetMarkerStyle(20); + egr->Draw("3 SAME"); + fgr->SetMarkerColor(kGreen+1); + fgr->SetLineColor(kGreen+1); + fgr->SetLineWidth(3); + fgr->SetFillColor(kViolet-6); + fgr->SetMarkerStyle(20); + fgr->Draw("P SAME"); + c2->Update(); + + c3->cd(); + agr = new TGraphErrors( n, energy, mean80, energyerror, energyerror ); + //agr = new TGraphErrors( n, energy, mean90, energyerror, energyerror ); + //agr = new TGraphErrors( n, energy, mean_mean, energyerror, rms_mean ); + //agr = new TGraphErrors( n, energy, mean90, energyerror, energyerror ); + //agr = new TGraphErrors( n, energy, mean_mean2, energyerror, rms_mean2 ); + //agr = new TGraphErrors( n, energy, mean_mean, energyerror, rms_mean ); + agr->GetYaxis()->SetTitle("E_{reco}, GeV"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy, mean80, energyerror, energyerror ); + //bgr = new TGraphErrors( n, energy, mean90, energyerror, energyerror ); + //bgr = new TGraphErrors( n, energy, mean_mean, energyerror, mean_meanerror ); + //bgr = new TGraphErrors( n, energy, mean90, energyerror, energyerror ); + //bgr = new TGraphErrors( n, energy, mean_mean2, energyerror, mean_meanerror2 ); + //bgr = new TGraphErrors( n, energy, mean_mean, energyerror, mean_meanerror ); + bgr->GetYaxis()->SetTitle("E_{reco}, GeV"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + cgr = new TGraphErrors( n, energy, mean85, energyerror, energyerror ); + //cgr = new TGraphErrors( n, energy, mean95, energyerror, energyerror ); + //cgr = new TGraphErrors( n, energy, mean_mean2, energyerror, rms_mean2 ); + //cgr = new TGraphErrors( n, energy, mean100, energyerror, energyerror ); + //cgr = new TGraphErrors( n, energy, mean, energyerror, energyerror ); + //cgr = new TGraphErrors( n, energy, mean_mean2, energyerror, rms_mean2 ); + cgr->GetYaxis()->SetTitle("E_{reco}, GeV"); + cgr->GetXaxis()->SetTitle("E_{true}, GeV"); + dgr = new TGraphErrors( n, energy, mean85, energyerror, energyerror ); + //dgr = new TGraphErrors( n, energy, mean95, energyerror, energyerror ); + //dgr = new TGraphErrors( n, energy, mean_mean2, energyerror, mean_meanerror2 ); + //dgr = new TGraphErrors( n, energy, mean100, energyerror, energyerror ); + //dgr = new TGraphErrors( n, energy, mean, energyerror, meanerror ); + //dgr = new TGraphErrors( n, energy, mean_mean2, energyerror, mean_meanerror2 ); + dgr->GetYaxis()->SetTitle("E_{reco}, GeV"); + dgr->GetXaxis()->SetTitle("E_{true}, GeV"); + egr = new TGraphErrors( n, energy, mean90, energyerror, energyerror ); + //egr = new TGraphErrors( n, energy, mean100, energyerror, energyerror ); + //egr = new TGraphErrors( n, energy, mean90, energyerror, energyerror ); + //egr = new TGraphErrors( n, energy, mean, energyerror, energyerror ); + //egr = new TGraphErrors( n, energy, mean90, energyerror, energyerror ); + //egr = new TGraphErrors( n, energy, mean, energyerror, energyerror ); + egr->GetYaxis()->SetTitle("E_{reco}, GeV"); + egr->GetXaxis()->SetTitle("E_{true}, GeV"); + fgr = new TGraphErrors( n, energy, mean90, energyerror, energyerror ); + //fgr = new TGraphErrors( n, energy, mean100, energyerror, energyerror ); + //fgr = new TGraphErrors( n, energy, mean90, energyerror, energyerror ); + //fgr = new TGraphErrors( n, energy, mean, energyerror, meanerror ); + //fgr = new TGraphErrors( n, energy, mean90, energyerror, energyerror ); + //fgr = new TGraphErrors( n, energy, mean, energyerror, meanerror ); + fgr->GetYaxis()->SetTitle("E_{reco}, GeV"); + fgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Linearity 2" ); + agr->GetYaxis()->SetRangeUser(0.0, 70.0); + agr->SetTitle(fname); + + agr->SetFillColor(kCyan); + agr->SetFillStyle(3001); + agr->SetMarkerColor(kCyan); + agr->SetLineColor(kCyan); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); + agr->Draw("A 3"); + bgr->SetMarkerColor(kBlue); + bgr->SetLineColor(kBlue); + bgr->SetLineWidth(3); + bgr->SetFillColor(kCyan); + bgr->SetMarkerStyle(20); + bgr->Draw("P SAME"); + cgr->SetMarkerColor(kYellow-6); + cgr->SetFillStyle(3001); + cgr->SetLineColor(kYellow-6); + cgr->SetLineWidth(3); + cgr->SetFillColor(kYellow-6); + cgr->SetMarkerStyle(20); + cgr->Draw("3 SAME"); + dgr->SetMarkerColor(kRed); + dgr->SetLineColor(kRed); + dgr->SetLineWidth(3); + dgr->SetFillColor(kYellow-6); + dgr->SetMarkerStyle(20); + dgr->Draw("P SAME"); + egr->SetMarkerColor(kViolet-6); + egr->SetFillStyle(3001); + egr->SetLineColor(kViolet-6); + egr->SetLineWidth(3); + egr->SetFillColor(kViolet-6); + egr->SetMarkerStyle(20); + egr->Draw("3 SAME"); + fgr->SetMarkerColor(kGreen+1); + fgr->SetLineColor(kGreen+1); + fgr->SetLineWidth(3); + fgr->SetFillColor(kViolet-6); + fgr->SetMarkerStyle(20); + fgr->Draw("P SAME"); + c3->Update(); + + c4->cd(); + agr = new TGraphErrors( n, energy, resolution80, energyerror, resolution_error_sys80 ); + //agr = new TGraphErrors( n, energy, resolution90, energyerror, resolution_error_sys90 ); + //agr = new TGraphErrors( n, energy, resolution, energyerror, resolution_error_sys ); + //agr = new TGraphErrors( n, energy, resolution90, energyerror, resolution_error_sys90 ); + //agr = new TGraphErrors( n, energy, resolution2, energyerror, resolution_error_sys2 ); + //agr = new TGraphErrors( n, energy, resolution, energyerror, resolution_error_sys ); + agr->GetYaxis()->SetTitle("#sigma_{reco} / E_{reco}"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy, resolution80, energyerror, resolution_error_stat80 ); + //bgr = new TGraphErrors( n, energy, resolution90, energyerror, resolution_error_stat90 ); + //bgr = new TGraphErrors( n, energy, resolution, energyerror, resolution_error_stat ); + //bgr = new TGraphErrors( n, energy, resolution90, energyerror, resolution_error_stat90 ); + //bgr = new TGraphErrors( n, energy, resolution2, energyerror, resolution_error_stat2 ); + //bgr = new TGraphErrors( n, energy, resolution, energyerror, resolution_error_stat ); + bgr->GetYaxis()->SetTitle("#sigma_{reco} / E_{reco}"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + cgr = new TGraphErrors( n, energy, resolution85, energyerror, resolution_error_sys85 ); + //cgr = new TGraphErrors( n, energy, resolution95, energyerror, resolution_error_sys95 ); + //cgr = new TGraphErrors( n, energy, resolution2, energyerror, resolution_error_sys2 ); + //cgr = new TGraphErrors( n, energy, resolution100, energyerror, resolution_error_sys100 ); + //cgr = new TGraphErrors( n, energy, resolution_hist, energyerror, resolution_error_sys_hist ); + //cgr = new TGraphErrors( n, energy, resolution2, energyerror, resolution_error_sys2 ); + cgr->GetYaxis()->SetTitle("#sigma_{reco} / E_{reco}"); + cgr->GetXaxis()->SetTitle("E_{true}, GeV"); + dgr = new TGraphErrors( n, energy, resolution85, energyerror, resolution_error_stat85 ); + //dgr = new TGraphErrors( n, energy, resolution95, energyerror, resolution_error_stat95 ); + //dgr = new TGraphErrors( n, energy, resolution2, energyerror, resolution_error_stat2 ); + //dgr = new TGraphErrors( n, energy, resolution100, energyerror, resolution_error_stat100 ); + //dgr = new TGraphErrors( n, energy, resolution_hist, energyerror, resolution_error_stat_hist ); + //dgr = new TGraphErrors( n, energy, resolution2, energyerror, resolution_error_stat2 ); + dgr->GetYaxis()->SetTitle("#sigma_{reco} / E_{reco}"); + dgr->GetXaxis()->SetTitle("E_{true}, GeV"); + egr = new TGraphErrors( n, energy, resolution90, energyerror, resolution_error_sys90 ); + //egr = new TGraphErrors( n, energy, resolution100, energyerror, resolution_error_sys100 ); + //egr = new TGraphErrors( n, energy, resolution90, energyerror, resolution_error_sys90 ); + //egr = new TGraphErrors( n, energy, resolution_hist, energyerror, resolution_error_sys_hist ); + //egr = new TGraphErrors( n, energy, resolution90, energyerror, resolution_error_sys90 ); + //egr = new TGraphErrors( n, energy, resolution_hist, energyerror, resolution_error_sys_hist ); + egr->GetYaxis()->SetTitle("#sigma_{reco} / E_{reco}"); + egr->GetXaxis()->SetTitle("E_{true}, GeV"); + fgr = new TGraphErrors( n, energy, resolution90, energyerror, resolution_error_stat90 ); + //fgr = new TGraphErrors( n, energy, resolution100, energyerror, resolution_error_stat100 ); + //fgr = new TGraphErrors( n, energy, resolution90, energyerror, resolution_error_stat90 ); + //fgr = new TGraphErrors( n, energy, resolution_hist, energyerror, resolution_error_stat_hist ); + //fgr = new TGraphErrors( n, energy, resolution90, energyerror, resolution_error_stat90 ); + //fgr = new TGraphErrors( n, energy, resolution_hist, energyerror, resolution_error_stat_hist ); + fgr->GetYaxis()->SetTitle("#sigma_{reco} / E_{reco}"); + fgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Relative energy resolution" ); + agr->GetYaxis()->SetRangeUser(0.0, 0.30); + agr->SetTitle(fname); + + agr->SetFillColor(kCyan); + agr->SetFillStyle(3001); + agr->SetMarkerColor(kCyan); + agr->SetLineColor(kCyan); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); + agr->Draw("A 3"); + bgr->SetMarkerColor(kBlue); + bgr->SetLineColor(kBlue); + bgr->SetLineWidth(3); + bgr->SetFillColor(kCyan); + bgr->SetMarkerStyle(20); + bgr->Draw("P SAME"); + cgr->SetMarkerColor(kYellow-6); + cgr->SetFillStyle(3001); + cgr->SetLineColor(kYellow-6); + cgr->SetLineWidth(3); + cgr->SetFillColor(kYellow-6); + cgr->SetMarkerStyle(20); + cgr->Draw("3 SAME"); + dgr->SetMarkerColor(kRed); + dgr->SetLineColor(kRed); + dgr->SetLineWidth(3); + dgr->SetFillColor(kYellow-6); + dgr->SetMarkerStyle(20); + dgr->Draw("P SAME"); + egr->SetMarkerColor(kViolet-6); + egr->SetFillStyle(3001); + egr->SetLineColor(kViolet-6); + egr->SetLineWidth(3); + egr->SetFillColor(kViolet-6); + egr->SetMarkerStyle(20); + egr->Draw("3 SAME"); + fgr->SetMarkerColor(kGreen+1); + fgr->SetLineColor(kGreen+1); + fgr->SetLineWidth(3); + fgr->SetFillColor(kViolet-6); + fgr->SetMarkerStyle(20); + fgr->Draw("P SAME"); + c4->Update(); + + TLegend *lsc1 = new TLegend(0.55,0.62,0.90,0.92); + lsc1->AddEntry(bgr,"data, rms80 w/o errors","plf"); + lsc1->AddEntry(dgr,"data, rms85 w/o errors","plf"); + lsc1->AddEntry(fgr,"data, rms90 w/o errors","plf"); + //lsc1->AddEntry(bgr,"data, rms90 w/o errors","plf"); + //lsc1->AddEntry(dgr,"data, rms95 w/o errors","plf"); + //lsc1->AddEntry(fgr,"data, rms100 w/o errors","plf"); + //lsc1->AddEntry(bgr,"data, fit 1","plf"); + //lsc1->AddEntry(dgr,"data, fit 2 (stat)","plf"); + //lsc1->AddEntry(fgr,"data, rms90 w/o errors","plf"); + //lsc1->AddEntry(bgr,"data, rms90 w/o errors","plf"); + //lsc1->AddEntry(dgr,"data, rms100 w/o errors","plf"); + //lsc1->AddEntry(fgr,"data, rms_hist (stat)","plf"); + //lsc1->AddEntry(bgr,"data, fit 2 (stat)","plf"); + //lsc1->AddEntry(dgr,"data, rms_hist (stat)","plf"); + //lsc1->AddEntry(fgr,"data, rms90 w/o errors","plf"); + //lsc1->AddEntry(bgr,"data, fit 1","plf"); + //lsc1->AddEntry(dgr,"data, fit 2 (stat)","plf"); + //lsc1->AddEntry(fgr,"data, rms_hist (stat)","plf"); + + TLegend *lsc2 = new TLegend(0.55,0.62,0.90,0.92); + lsc2->AddEntry(bgr,"data, rms80 w/o errors","plf"); + lsc2->AddEntry(dgr,"data, rms85 w/o errors","plf"); + lsc2->AddEntry(fgr,"data, rms90 w/o errors","plf"); + + TLegend *lsc3 = new TLegend(0.55,0.62,0.90,0.92); + lsc3->AddEntry(bgr,"data, rms80 w/o errors","plf"); + lsc3->AddEntry(dgr,"data, rms85 w/o errors","plf"); + lsc3->AddEntry(fgr,"data, rms90 w/o errors","plf"); + + TLegend *lsc4 = new TLegend(0.55,0.62,0.90,0.92); + lsc4->AddEntry(bgr,"data, rms80 w/o errors","plf"); + lsc4->AddEntry(dgr,"data, rms85 w/o errors","plf"); + lsc4->AddEntry(fgr,"data, rms90 w/o errors","plf"); + + c1->cd(); + lsc1->Draw(); + c2->cd(); + lsc2->Draw(); + c3->cd(); + lsc3->Draw(); + c4->cd(); + lsc4->Draw(); + +} diff --git a/comp_hist_or_fit_graph_errors.c b/comp_hist_or_fit_graph_errors.c new file mode 100644 index 0000000..84847bb --- /dev/null +++ b/comp_hist_or_fit_graph_errors.c @@ -0,0 +1,436 @@ +void comp_hist_or_fit_graph_errors() { + TCanvas *c1 = new TCanvas("graph1","graph1",200,10,700,500); + TCanvas *c2 = new TCanvas("graph2","graph2",200,10,700,500); + TCanvas *c3 = new TCanvas("graph3","graph3",200,10,700,500); + TCanvas *c4 = new TCanvas("graph4","graph4",200,10,700,500); + + //c1->SetFillColor(42); + //gStyle->SetPalette(52); + c1->SetGrid(); + c2->SetGrid(); + c3->SetGrid(); + c4->SetGrid(); + //c1->GetFrame()->SetFillColor(21); + //c1->GetFrame()->SetBorderSize(12); + + const Int_t n = 9; // 16 + + Float_t energy[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t energyerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t meanerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rmserror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t mean_mean[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_mean[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_meanerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_meanerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_sigma[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_sigma[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_sigmaerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_sigmaerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_chi[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_chi[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t linearity_error[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t absolute_error[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_stat[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_sys[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t energy2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t energyerror2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t meanerror2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rmserror2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t mean_mean2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_mean2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_meanerror2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_meanerror2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_sigma2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_sigma2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_sigmaerror2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_sigmaerror2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_chi2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_chi2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t linearity_error2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t absolute_error2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_stat2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_sys2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + +/* + for (int i = 0; i < n; i++) { + printf( " %f ", energy[i] ); + printf( " %f ", energyerror[i] ); + printf( " %f ", mean[i] ); + printf( " %f ", meanerror[i] ); + printf( " %f ", sigma[i] ); + printf( " %f ", sigmaerror[i] ); + printf( " %f ", value[i] ); + printf( " %f ", error[i] ); + printf( "\n" ); + } +*/ + FILE *file1 = fopen("new_1out_data.txt", "r"); + if ( !(long)file1 ) return; + + FILE *file2 = fopen("new_2out_data.txt", "r"); + if ( !(long)file2 ) return; + + for ( int i = 0; i < n; i++ ) { + fscanf( file1, "%f %E %E %E %E %E %E %E %E %E %E %E %E %E %E\n", &energy[i], &mean[i], &meanerror[i], &rms[i], &rmserror[i], &mean_mean[i], &rms_mean[i], &mean_meanerror[i], &rms_meanerror[i], &mean_sigma[i], &rms_sigma[i], &mean_sigmaerror[i], &rms_sigmaerror[i], &mean_chi[i], &rms_chi[i] ); + if ( feof( file1 ) ) break; + } + + for ( int i = 0; i < n; i++ ) { + fscanf( file2, "%f %E %E %E %E %E %E %E %E %E\n", &energy2[i], &mean2[i], &meanerror2[i], &rms2[i], &rmserror2[i], &mean_mean2[i], &mean_meanerror2[i], &mean_sigma2[i], &mean_sigmaerror2[i], &mean_chi2[i] ); + if ( feof( file2 ) ) break; + } + + for ( int i = 0; i < n; i++ ) { + + linearity_error[ i ] = sqrt( ( pow( mean_meanerror[ i ], 2 ) ) + ( pow( rms_mean[ i ], 2 ) ) ); + absolute_error[ i ] = sqrt( ( pow( mean_sigmaerror[ i ], 2 ) ) + ( pow( rms_sigma[ i ], 2 ) ) ); + + ratio[ i ] = ( mean_mean[i] - energy[i] ) / energy[i]; + ratio_error_stat[ i ] = sqrt( pow( (mean_meanerror[i])/(energy[i]), 2 ) + pow( (mean_mean[i] * energyerror[i])/(energy[i] * energy[i]), 2 ) ); + ratio_error_sys[ i ] = sqrt( pow( (rms_mean[i])/(energy[i]), 2 ) + pow( (mean_mean[i] * energyerror[i])/(energy[i] * energy[i]), 2 ) ); + ratio_error[ i ] = sqrt( ( pow( ratio_error_stat[ i ], 2 ) ) + ( pow( ratio_error_sys[ i ], 2 ) ) ); + + resolution[ i ] = mean_sigma[i] / mean_mean[i]; + resolution_error_stat[ i ] = sqrt( pow( (mean_sigmaerror[i])/(mean_mean[i]), 2 ) + pow( (mean_sigma[i] * mean_meanerror[i])/(mean_mean[i] * mean_mean[i]), 2 ) ); + resolution_error_sys[ i ] = sqrt( pow( (rms_sigma[i])/(mean_mean[i]), 2 ) + pow( (mean_sigma[i] * rms_mean[i])/(mean_mean[i] * mean_mean[i]), 2 ) ); + resolution_error[ i ] = sqrt( ( pow( resolution_error_stat[ i ], 2 ) ) + ( pow( resolution_error_sys[ i ], 2 ) ) ); + + } + + for ( int i = 0; i < n; i++ ) { + + linearity_error2[ i ] = sqrt( ( pow( mean_meanerror2[ i ], 2 ) ) + ( pow( rms_mean2[ i ], 2 ) ) ); + absolute_error2[ i ] = sqrt( ( pow( mean_sigmaerror2[ i ], 2 ) ) + ( pow( rms_sigma2[ i ], 2 ) ) ); + + ratio2[ i ] = ( mean_mean2[i] - energy2[i] ) / energy2[i]; + ratio_error_stat2[ i ] = sqrt( pow( (mean_meanerror2[i])/(energy2[i]), 2 ) + pow( (mean_mean2[i] * energyerror2[i])/(energy2[i] * energy2[i]), 2 ) ); + ratio_error_sys2[ i ] = 0.0;//sqrt( pow( (rms_mean2[i])/(energy2[i]), 2 ) + pow( (mean_mean2[i] * energyerror2[i])/(energy2[i] * energy2[i]), 2 ) ); + ratio_error2[ i ] = sqrt( ( pow( ratio_error_stat2[ i ], 2 ) ) + ( pow( ratio_error_sys2[ i ], 2 ) ) ); + + resolution2[ i ] = mean_sigma2[i] / mean_mean2[i]; + resolution_error_stat2[ i ] = sqrt( pow( (mean_sigmaerror2[i])/(mean_mean2[i]), 2 ) + pow( (mean_sigma2[i] * mean_meanerror2[i])/(mean_mean2[i] * mean_mean2[i]), 2 ) ); + resolution_error_sys2[ i ] = 0.0;//sqrt( pow( (rms_sigma2[i])/(mean_mean2[i]), 2 ) + pow( (mean_sigma2[i] * rms_mean2[i])/(mean_mean2[i] * mean_mean2[i]), 2 ) ); + resolution_error2[ i ] = sqrt( ( pow( resolution_error_stat2[ i ], 2 ) ) + ( pow( resolution_error_sys2[ i ], 2 ) ) ); + + } + + printf( "\n" ); + for (int i = 0; i < n; i++) { + printf( " %f ", energy[i] ); + printf( " %f ", energyerror[i] ); + printf( " %f ", mean[i] ); + printf( " %f ", meanerror[i] ); + printf( " %f ", rms[i] ); + printf( " %f ", rmserror[i] ); + printf( " %f ", mean_mean[i] ); + printf( " %f ", rms_mean[i] ); + printf( " %f ", mean_meanerror[i] ); + printf( " %f ", rms_meanerror[i] ); + printf( " %f ", mean_sigma[i] ); + printf( " %f ", rms_sigma[i] ); + printf( " %f ", mean_sigmaerror[i] ); + printf( " %f ", rms_sigmaerror[i] ); + printf( " %f ", linearity_error[i] ); + printf( " %f ", absolute_error[i] ); + printf( " %f ", ratio[i] ); + printf( " %f ", ratio_error[i] ); + printf( " %f ", resolution[i] ); + printf( " %f ", resolution_error[i] ); + printf( "\n" ); + } + + + printf( "\n" ); + for (int i = 0; i < n; i++) { + printf( " %f ", energy2[i] ); + printf( " %f ", energyerror2[i] ); + printf( " %f ", mean2[i] ); + printf( " %f ", meanerror2[i] ); + printf( " %f ", rms2[i] ); + printf( " %f ", rmserror2[i] ); + printf( " %f ", mean_mean2[i] ); + printf( " %f ", rms_mean2[i] ); + printf( " %f ", mean_meanerror2[i] ); + printf( " %f ", rms_meanerror2[i] ); + printf( " %f ", mean_sigma2[i] ); + printf( " %f ", rms_sigma2[i] ); + printf( " %f ", mean_sigmaerror2[i] ); + printf( " %f ", rms_sigmaerror2[i] ); + printf( " %f ", linearity_error2[i] ); + printf( " %f ", absolute_error2[i] ); + printf( " %f ", ratio2[i] ); + printf( " %f ", ratio_error2[i] ); + printf( " %f ", resolution2[i] ); + printf( " %f ", resolution_error2[i] ); + printf( "\n" ); + } + + TGraphErrors *agr; + TGraphErrors *bgr; + + TGraphErrors *cgr; + TGraphErrors *dgr; + + char fname[ 100 ]; + for ( int i = 0; i < 100; i++ ) fname[ i ] = 0; + + c1->cd(); + agr = new TGraphErrors( n, energy, ratio, energyerror, ratio_error_sys ); + agr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy, ratio, energyerror, ratio_error_stat ); + bgr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + cgr = new TGraphErrors( n, energy2, ratio2, energyerror2, ratio_error_sys2 ); // stat2 ??? + cgr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + cgr->GetXaxis()->SetTitle("E_{true}, GeV"); + dgr = new TGraphErrors( n, energy2, ratio2, energyerror2, ratio_error_stat2 ); + dgr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + dgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Linearity" ); // Linearity energy resolution // Absolute energy resolution // Relative energy resolution + agr->GetYaxis()->SetRangeUser(-0.2, 0.2); // -0.25, 0.8 + agr->SetTitle(fname); + + agr->SetFillColor(kCyan); + agr->SetFillStyle(3001); + agr->SetMarkerColor(kCyan); // kBlue // 12 + agr->SetLineColor(kCyan); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); // 21 +// agr->SetMarkerSize(2); + agr->Draw("A 3"); // ALP + bgr->SetMarkerColor(kBlue); // kRed // 15 + bgr->SetLineColor(kBlue); + bgr->SetLineWidth(3); + bgr->SetFillColor(kCyan); + bgr->SetMarkerStyle(20); // 21 +// bgr->SetMarkerSize(2); + bgr->Draw("P SAME"); // LPSAME + cgr->SetMarkerColor(kYellow-6); // kRed // 15 // kBlack + cgr->SetFillStyle(3001); + cgr->SetLineColor(kYellow-6); + cgr->SetLineWidth(3); + cgr->SetFillColor(kYellow-6); + cgr->SetMarkerStyle(20); // 21 +// bgr->SetMarkerSize(2); + cgr->Draw("3 SAME"); // LPSAME + dgr->SetMarkerColor(kRed); // kRed // 15 + dgr->SetLineColor(kRed); + dgr->SetLineWidth(3); + dgr->SetFillColor(kYellow-6); + dgr->SetMarkerStyle(20); // 21 +// bgr->SetMarkerSize(2); + dgr->Draw("P SAME"); // LPSAME + c1->Update(); + + c2->cd(); + agr = new TGraphErrors( n, energy, mean_sigma, energyerror, rms_sigma ); + agr->GetYaxis()->SetTitle("#sigma_{reco}, GeV"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy, mean_sigma, energyerror, mean_sigmaerror ); + bgr->GetYaxis()->SetTitle("#sigma_{reco}, GeV"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + cgr = new TGraphErrors( n, energy2, mean_sigma2, energyerror2, rms_sigma2 );//ratio_error_sys2!!!!!!!!!!! + cgr->GetYaxis()->SetTitle("#sigma_{reco}, GeV"); + cgr->GetXaxis()->SetTitle("E_{true}, GeV"); + dgr = new TGraphErrors( n, energy2, mean_sigma2, energyerror2, mean_sigmaerror2 ); + dgr->GetYaxis()->SetTitle("#sigma_{reco}, GeV"); + dgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Absolute energy resolution" ); // Linearity energy resolution // Absolute energy resolution // Relative energy resolution + agr->GetYaxis()->SetRangeUser(0.0, 9.0); // -0.25, 1.0 + agr->SetTitle(fname); + + agr->SetFillColor(kCyan); + agr->SetFillStyle(3001); + agr->SetMarkerColor(kCyan); // kBlue // 12 + agr->SetLineColor(kCyan); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); // 21 +// agr->SetMarkerSize(2); + agr->Draw("A 3"); // ALP + bgr->SetMarkerColor(kBlue); // kRed // 15 + bgr->SetLineColor(kBlue); + bgr->SetLineWidth(3); + bgr->SetFillColor(kCyan); + bgr->SetMarkerStyle(20); // 21 +// bgr->SetMarkerSize(2); + bgr->Draw("P SAME"); // LPSAME + cgr->SetMarkerColor(kYellow-6); // kRed // 15 // kBlack + cgr->SetFillStyle(3001); + cgr->SetLineColor(kYellow-6); + cgr->SetLineWidth(3); + cgr->SetFillColor(kYellow-6); + cgr->SetMarkerStyle(20); // 21 +// bgr->SetMarkerSize(2); + cgr->Draw("3 SAME"); // LPSAME + dgr->SetMarkerColor(kRed); // kRed // 15 + dgr->SetLineColor(kRed); + dgr->SetLineWidth(3); + dgr->SetFillColor(kYellow-6); + dgr->SetMarkerStyle(20); // 21 +// bgr->SetMarkerSize(2); + dgr->Draw("P SAME"); // LPSAME + c2->Update(); + + c3->cd(); + agr = new TGraphErrors( n, energy, mean_mean, energyerror, rms_mean ); + agr->GetYaxis()->SetTitle("E_{reco}, GeV"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy, mean_mean, energyerror, mean_meanerror ); + bgr->GetYaxis()->SetTitle("E_{reco}, GeV"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + cgr = new TGraphErrors( n, energy2, mean_mean2, energyerror2, rms_mean2 );//ratio_error_sys2!!!!!!!!!!! + cgr->GetYaxis()->SetTitle("E_{reco}, GeV"); + cgr->GetXaxis()->SetTitle("E_{true}, GeV"); + dgr = new TGraphErrors( n, energy2, mean_mean2, energyerror2, mean_meanerror2 ); + dgr->GetYaxis()->SetTitle("E_{reco}, GeV"); + dgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Linearity 2" ); // Linearity energy resolution // Absolute energy resolution // Relative energy resolution + agr->GetYaxis()->SetRangeUser(0.0, 70.0); + agr->SetTitle(fname); + + agr->SetFillColor(kCyan); + agr->SetFillStyle(3001); + agr->SetMarkerColor(kCyan); // kBlue // 12 + agr->SetLineColor(kCyan); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); // 21 +// agr->SetMarkerSize(2); + agr->Draw("A 3"); // ALP + bgr->SetMarkerColor(kBlue); // kRed // 15 + bgr->SetLineColor(kBlue); + bgr->SetLineWidth(3); + bgr->SetFillColor(kCyan); + bgr->SetMarkerStyle(20); // 21 +// bgr->SetMarkerSize(2); + bgr->Draw("P SAME"); // LPSAME + cgr->SetMarkerColor(kYellow-6); // kRed // 15 // kBlack + cgr->SetFillStyle(3001); + cgr->SetLineColor(kYellow-6); + cgr->SetLineWidth(3); + cgr->SetFillColor(kYellow-6); + cgr->SetMarkerStyle(20); // 21 +// bgr->SetMarkerSize(2); + cgr->Draw("3 SAME"); // LPSAME + dgr->SetMarkerColor(kRed); // kRed // 15 + dgr->SetLineColor(kRed); + dgr->SetLineWidth(3); + dgr->SetFillColor(kYellow-6); + dgr->SetMarkerStyle(20); // 21 +// bgr->SetMarkerSize(2); + dgr->Draw("P SAME"); // LPSAME + c3->Update(); + + c4->cd(); + agr = new TGraphErrors( n, energy, resolution, energyerror, resolution_error_sys ); + agr->GetYaxis()->SetTitle("#sigma_{reco} / E_{reco}"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy, resolution, energyerror, resolution_error_stat ); + bgr->GetYaxis()->SetTitle("#sigma_{reco} / E_{reco}"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + cgr = new TGraphErrors( n, energy2, resolution2, energyerror2, resolution_error_sys2 ); + cgr->GetYaxis()->SetTitle("#sigma_{reco} / E_{reco}"); + cgr->GetXaxis()->SetTitle("E_{true}, GeV"); + dgr = new TGraphErrors( n, energy2, resolution2, energyerror2, resolution_error_stat2 ); + dgr->GetYaxis()->SetTitle("#sigma_{reco} / E_{reco}"); + dgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Relative energy resolution" ); // Linearity energy resolution // Absolute energy resolution // Relative energy resolution + agr->GetYaxis()->SetRangeUser(0.0, 0.30); // -0.25, 1.0 + agr->SetTitle(fname); + + agr->SetFillColor(kCyan); + agr->SetFillStyle(3001); + agr->SetMarkerColor(kCyan); // kBlue // 12 + agr->SetLineColor(kCyan); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); // 21 +// agr->SetMarkerSize(2); + agr->Draw("A 3"); // ALP + bgr->SetMarkerColor(kBlue); // kRed // 15 + bgr->SetLineColor(kBlue); + bgr->SetLineWidth(3); + bgr->SetFillColor(kCyan); + bgr->SetMarkerStyle(20); // 21 +// bgr->SetMarkerSize(2); + bgr->Draw("P SAME"); // LPSAME + cgr->SetMarkerColor(kYellow-6); // kRed // 15 // kBlack + cgr->SetFillStyle(3001); + cgr->SetLineColor(kYellow-6); + cgr->SetLineWidth(3); + cgr->SetFillColor(kYellow-6); + cgr->SetMarkerStyle(20); // 21 +// bgr->SetMarkerSize(2); + cgr->Draw("3 SAME"); // LPSAME + dgr->SetMarkerColor(kRed); // kRed // 15 + dgr->SetLineColor(kRed); + dgr->SetLineWidth(3); + dgr->SetFillColor(kYellow-6); + dgr->SetMarkerStyle(20); // 21 +// bgr->SetMarkerSize(2); + dgr->Draw("P SAME"); // LPSAME + c4->Update(); + + TLegend *lsc1 = new TLegend(0.55,0.62,0.90,0.92); +// lsc1->AddEntry(agr,"without ANN","pl"); + lsc1->AddEntry(bgr,"data, fit 1","plf"); +// lsc1->AddEntry(cgr,"without ANN","plf"); + lsc1->AddEntry(dgr,"data, fit 2 (stat)","plf"); + + TLegend *lsc2 = new TLegend(0.55,0.62,0.90,0.92); +// lsc2->AddEntry(agr,"without ANN","pl"); + lsc2->AddEntry(bgr,"data, fit 1","plf"); +// lsc2->AddEntry(cgr,"without ANN","plf"); + lsc2->AddEntry(dgr,"data, fit 2 (stat)","plf"); + + TLegend *lsc3 = new TLegend(0.55,0.62,0.90,0.92); +// lsc2->AddEntry(agr,"without ANN","pl"); + lsc3->AddEntry(bgr,"data, fit 1","plf"); +// lsc2->AddEntry(cgr,"without ANN","plf"); + lsc3->AddEntry(dgr,"data, fit 2 (stat)","plf"); + + TLegend *lsc4 = new TLegend(0.55,0.62,0.90,0.92); +// lsc2->AddEntry(agr,"without ANN","pl"); + lsc4->AddEntry(bgr,"data, fit 1","plf"); +// lsc2->AddEntry(cgr,"without ANN","plf"); + lsc4->AddEntry(dgr,"data, fit 2 (stat)","plf"); + +// TLegend *lsc3 = new TLegend(0.55,0.62,0.90,0.92); +// lsc3->AddEntry(agr,"without ANN","pl"); +// lsc3->AddEntry(bgr,"with ANN","pl"); + +// TLegend *lsc4 = new TLegend(0.55,0.62,0.90,0.92); +// lsc4->AddEntry(agr,"without ANN","pl"); +// lsc4->AddEntry(bgr,"with ANN","pl"); + + c1->cd(); + lsc1->Draw(); + c2->cd(); + lsc2->Draw(); + c3->cd(); + lsc3->Draw(); + c4->cd(); + lsc4->Draw(); + +} diff --git a/comp_hist_or_fit_graph_errors_old.c b/comp_hist_or_fit_graph_errors_old.c new file mode 100644 index 0000000..328e061 --- /dev/null +++ b/comp_hist_or_fit_graph_errors_old.c @@ -0,0 +1,502 @@ +void comp_hist_or_fit_graph_errors() { + TCanvas *c1 = new TCanvas("graph1","graph1",200,10,700,500); + TCanvas *c2 = new TCanvas("graph2","graph2",200,10,700,500); + TCanvas *c3 = new TCanvas("graph3","graph3",200,10,700,500); + TCanvas *c4 = new TCanvas("graph4","graph4",200,10,700,500); + + //c1->SetFillColor(42); + //gStyle->SetPalette(52); + c1->SetGrid(); + c2->SetGrid(); + c3->SetGrid(); + c4->SetGrid(); + //c1->GetFrame()->SetFillColor(21); + //c1->GetFrame()->SetBorderSize(12); + + const Int_t n = 9; // 16 + + Float_t energy[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t energyerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t meanerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rmserror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t mean_mean[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_mean[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_meanerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_meanerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_sigma[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_sigma[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_sigmaerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_sigmaerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_chi[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_chi[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t linearity_error[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t absolute_error[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_stat[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_sys[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t linearity_error2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t absolute_error2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_stat2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_sys2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + +/* + for (int i = 0; i < n; i++) { + printf( " %f ", energy[i] ); + printf( " %f ", energyerror[i] ); + printf( " %f ", mean[i] ); + printf( " %f ", meanerror[i] ); + printf( " %f ", sigma[i] ); + printf( " %f ", sigmaerror[i] ); + printf( " %f ", value[i] ); + printf( " %f ", error[i] ); + printf( "\n" ); + } +*/ + FILE *file1 = fopen("1out_data.txt", "r"); // 1out_data.txt // // 1out_ann.txt + if ( !(long)file1 ) return; + + for ( int i = 0; i < n; i++ ) { + fscanf( file1, "%f %E %E %E %E %E %E %E %E %E %E %E %E %E %E\n", &energy[i], &mean[i], &meanerror[i], &rms[i], &rmserror[i], &mean_mean[i], &rms_mean[i], &mean_meanerror[i], &rms_meanerror[i], &mean_sigma[i], &rms_sigma[i], &mean_sigmaerror[i], &rms_sigmaerror[i], &mean_chi[i], &rms_chi[i] ); + if ( feof( file1 ) ) break; + } + + for ( int i = 0; i < n; i++ ) { + + linearity_error[ i ] = sqrt( ( pow( mean_meanerror[ i ], 2 ) ) + ( pow( rms_mean[ i ], 2 ) ) ); + absolute_error[ i ] = sqrt( ( pow( mean_sigmaerror[ i ], 2 ) ) + ( pow( rms_sigma[ i ], 2 ) ) ); + + ratio[ i ] = ( mean_mean[i] - energy[i] ) / energy[i]; + ratio_error_stat[ i ] = sqrt( pow( (mean_meanerror[i])/(energy[i]), 2 ) + pow( (mean_mean[i] * energyerror[i])/(energy[i] * energy[i]), 2 ) ); + ratio_error_sys[ i ] = sqrt( pow( (rms_mean[i])/(energy[i]), 2 ) + pow( (mean_mean[i] * energyerror[i])/(energy[i] * energy[i]), 2 ) ); + ratio_error[ i ] = sqrt( ( pow( ratio_error_stat[ i ], 2 ) ) + ( pow( ratio_error_sys[ i ], 2 ) ) ); + + resolution[ i ] = mean_sigma[i] / mean_mean[i]; + resolution_error_stat[ i ] = sqrt( pow( (mean_sigmaerror[i])/(mean_mean[i]), 2 ) + pow( (mean_sigma[i] * mean_meanerror[i])/(mean_mean[i] * mean_mean[i]), 2 ) ); + resolution_error_sys[ i ] = sqrt( pow( (rms_sigma[i])/(mean_mean[i]), 2 ) + pow( (mean_sigma[i] * rms_mean[i])/(mean_mean[i] * mean_mean[i]), 2 ) ); + resolution_error[ i ] = sqrt( ( pow( resolution_error_stat[ i ], 2 ) ) + ( pow( resolution_error_sys[ i ], 2 ) ) ); + + + linearity_error2[ i ] = sqrt( pow( meanerror[ i ], 2 ) ); + absolute_error2[ i ] = sqrt( pow( rmserror[ i ], 2 ) ); + + ratio2[ i ] = ( mean[i] - energy[i] ) / energy[i]; + ratio_error_stat2[ i ] = sqrt( pow( (meanerror[i])/(energy[i]), 2 ) + pow( (mean[i] * energyerror[i])/(energy[i] * energy[i]), 2 ) ); + ratio_error_sys2[ i ] = 0.0;//sqrt( pow( (rms_mean[i])/(energy[i]), 2 ) + pow( (mean_mean[i] * energyerror[i])/(energy[i] * energy[i]), 2 ) ); + ratio_error2[ i ] = sqrt( ( pow( ratio_error_stat[ i ], 2 ) ) + ( pow( ratio_error_sys[ i ], 2 ) ) ); + + resolution2[ i ] = rms[i] / mean[i]; + resolution_error_stat2[ i ] = sqrt( pow( (rmserror[i])/(mean[i]), 2 ) + pow( (rms[i] * meanerror[i])/(mean[i] * mean[i]), 2 ) ); + resolution_error_sys2[ i ] = 0.0;//sqrt( pow( (rms_sigma[i])/(mean_mean[i]), 2 ) + pow( (mean_sigma[i] * rms_mean[i])/(mean_mean[i] * mean_mean[i]), 2 ) ); + resolution_error2[ i ] = sqrt( ( pow( resolution_error_stat[ i ], 2 ) ) + ( pow( resolution_error_sys[ i ], 2 ) ) ); + + } + + printf( "\n" ); + for (int i = 0; i < n; i++) { + printf( " %f ", energy[i] ); + printf( " %f ", energyerror[i] ); + printf( " %f ", mean[i] ); + printf( " %f ", meanerror[i] ); + printf( " %f ", rms[i] ); + printf( " %f ", rmserror[i] ); + printf( " %f ", mean_mean[i] ); + printf( " %f ", rms_mean[i] ); + printf( " %f ", mean_meanerror[i] ); + printf( " %f ", rms_meanerror[i] ); + printf( " %f ", mean_sigma[i] ); + printf( " %f ", rms_sigma[i] ); + printf( " %f ", mean_sigmaerror[i] ); + printf( " %f ", rms_sigmaerror[i] ); + printf( " %f ", linearity_error[i] ); + printf( " %f ", absolute_error[i] ); + printf( " %f ", ratio[i] ); + printf( " %f ", ratio_error[i] ); + printf( " %f ", resolution[i] ); + printf( " %f ", resolution_error[i] ); + printf( "\n" ); + } + +/* printf( "Here is difference:\n" ); + + Float_t v1 = 0; + Float_t v2 = 0; + Float_t v3 = 0; + + for ( int i = 0; i < n; i++ ) { + printf( " %f, %f, %f, %f \n", energy[i], value[i], value2[i], value3[i] ); + printf( " Difference between nodigi and digi20: %f \n", value2[i] - value[i] ); + v1 = v1 + ( value2[i] - value[i] ); + printf( " Difference between digi20 and digi60: %f \n", value3[i] - value2[i] ); + v2 = v2 + ( value3[i] - value2[i] ); + printf( " Difference between nodigi and digi60: %f \n", value3[i] - value[i] ); + v3 = v3 + ( value3[i] - value[i] ); + } + + printf( "Average values: %f, %f, %f \n", v1/n, v2/n, v3/n ); +*/ + TGraphErrors *agr; + TGraphErrors *bgr; + + TGraphErrors *cgr; + TGraphErrors *dgr; + + char fname[ 100 ]; + for ( int i = 0; i < 100; i++ ) fname[ i ] = 0; +/* + c1->cd(); + agr = new TGraphErrors( n, energy, mean_mean, energyerror, linearity_error ); + agr->GetYaxis()->SetTitle("E_{reco}, GeV"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy2, mean_mean2, energyerror2, linearity_error2 ); + bgr->GetYaxis()->SetTitle("E_{reco}, GeV"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Linearity" ); // Linearity energy resolution // Absolute energy resolution // Relative energy resolution + agr->SetTitle(fname); + + agr->SetMarkerColor(kBlue); // kBlue // 12 + agr->SetLineColor(kBlue); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); // 21 +// agr->SetMarkerSize(2); + agr->Draw("ALP"); + bgr->SetMarkerColor(kRed); // kRed // 15 + bgr->SetLineColor(kRed); + bgr->SetLineWidth(3); + bgr->SetMarkerStyle(29); // 21 +// bgr->SetMarkerSize(2); + bgr->Draw("LPSAME"); // LPSAME + c1->Update(); +*/ + +// ------------------------------------------------------------------------------------------------------------------------------------------------------------------ + + c1->cd(); + agr = new TGraphErrors( n, energy, ratio, energyerror, ratio_error_sys ); + agr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy, ratio, energyerror, ratio_error_stat ); + bgr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + cgr = new TGraphErrors( n, energy, ratio2, energyerror, ratio_error_sys2 ); // stat2 ??? + cgr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + cgr->GetXaxis()->SetTitle("E_{true}, GeV"); + dgr = new TGraphErrors( n, energy, ratio2, energyerror, ratio_error_stat2 ); + dgr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + dgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Linearity" ); // Linearity energy resolution // Absolute energy resolution // Relative energy resolution + agr->GetYaxis()->SetRangeUser(-0.2, 0.2); // -0.25, 0.8 + agr->SetTitle(fname); + + agr->SetFillColor(kCyan); + agr->SetFillStyle(3001); + agr->SetMarkerColor(kCyan); // kBlue // 12 + agr->SetLineColor(kCyan); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); // 21 +// agr->SetMarkerSize(2); + agr->Draw("A 3"); // ALP + bgr->SetMarkerColor(kBlue); // kRed // 15 + bgr->SetLineColor(kBlue); + bgr->SetLineWidth(3); + bgr->SetFillColor(kCyan); + bgr->SetMarkerStyle(20); // 21 +// bgr->SetMarkerSize(2); + bgr->Draw("P SAME"); // LPSAME + cgr->SetMarkerColor(kYellow-6); // kRed // 15 // kBlack + cgr->SetFillStyle(3001); + cgr->SetLineColor(kYellow-6); + cgr->SetLineWidth(3); + cgr->SetFillColor(kYellow-6); + cgr->SetMarkerStyle(20); // 21 +// bgr->SetMarkerSize(2); + cgr->Draw("3 SAME"); // LPSAME + dgr->SetMarkerColor(kRed); // kRed // 15 + dgr->SetLineColor(kRed); + dgr->SetLineWidth(3); + dgr->SetFillColor(kYellow-6); + dgr->SetMarkerStyle(20); // 21 +// bgr->SetMarkerSize(2); + dgr->Draw("P SAME"); // LPSAME + c1->Update(); + + c2->cd(); + agr = new TGraphErrors( n, energy, mean_sigma, energyerror, rms_sigma ); + agr->GetYaxis()->SetTitle("#sigma_{reco}, GeV"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy, mean_sigma, energyerror, mean_sigmaerror ); + bgr->GetYaxis()->SetTitle("#sigma_{reco}, GeV"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + cgr = new TGraphErrors( n, energy, rms, energyerror, ratio_error_sys2 );//ratio_error_sys2!!!!!!!!!!! + cgr->GetYaxis()->SetTitle("#sigma_{reco}, GeV"); + cgr->GetXaxis()->SetTitle("E_{true}, GeV"); + dgr = new TGraphErrors( n, energy, rms, energyerror, rmserror ); + dgr->GetYaxis()->SetTitle("#sigma_{reco}, GeV"); + dgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Absolute energy resolution" ); // Linearity energy resolution // Absolute energy resolution // Relative energy resolution + agr->GetYaxis()->SetRangeUser(0.0, 9.0); // -0.25, 1.0 + agr->SetTitle(fname); + + agr->SetFillColor(kCyan); + agr->SetFillStyle(3001); + agr->SetMarkerColor(kCyan); // kBlue // 12 + agr->SetLineColor(kCyan); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); // 21 +// agr->SetMarkerSize(2); + agr->Draw("A 3"); // ALP + bgr->SetMarkerColor(kBlue); // kRed // 15 + bgr->SetLineColor(kBlue); + bgr->SetLineWidth(3); + bgr->SetFillColor(kCyan); + bgr->SetMarkerStyle(20); // 21 +// bgr->SetMarkerSize(2); + bgr->Draw("P SAME"); // LPSAME + cgr->SetMarkerColor(kYellow-6); // kRed // 15 // kBlack + cgr->SetFillStyle(3001); + cgr->SetLineColor(kYellow-6); + cgr->SetLineWidth(3); + cgr->SetFillColor(kYellow-6); + cgr->SetMarkerStyle(20); // 21 +// bgr->SetMarkerSize(2); + cgr->Draw("3 SAME"); // LPSAME + dgr->SetMarkerColor(kRed); // kRed // 15 + dgr->SetLineColor(kRed); + dgr->SetLineWidth(3); + dgr->SetFillColor(kYellow-6); + dgr->SetMarkerStyle(20); // 21 +// bgr->SetMarkerSize(2); + dgr->Draw("P SAME"); // LPSAME + c2->Update(); + + c3->cd(); + agr = new TGraphErrors( n, energy, mean_mean, energyerror, rms_mean ); + agr->GetYaxis()->SetTitle("E_{reco}, GeV"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy, mean_mean, energyerror, mean_meanerror ); + bgr->GetYaxis()->SetTitle("E_{reco}, GeV"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + cgr = new TGraphErrors( n, energy, mean, energyerror, ratio_error_sys2 );//ratio_error_sys2!!!!!!!!!!! + cgr->GetYaxis()->SetTitle("E_{reco}, GeV"); + cgr->GetXaxis()->SetTitle("E_{true}, GeV"); + dgr = new TGraphErrors( n, energy, mean, energyerror, meanerror ); + dgr->GetYaxis()->SetTitle("E_{reco}, GeV"); + dgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Linearity 2" ); // Linearity energy resolution // Absolute energy resolution // Relative energy resolution + agr->GetYaxis()->SetRangeUser(0.0, 70.0); + agr->SetTitle(fname); + + agr->SetFillColor(kCyan); + agr->SetFillStyle(3001); + agr->SetMarkerColor(kCyan); // kBlue // 12 + agr->SetLineColor(kCyan); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); // 21 +// agr->SetMarkerSize(2); + agr->Draw("A 3"); // ALP + bgr->SetMarkerColor(kBlue); // kRed // 15 + bgr->SetLineColor(kBlue); + bgr->SetLineWidth(3); + bgr->SetFillColor(kCyan); + bgr->SetMarkerStyle(20); // 21 +// bgr->SetMarkerSize(2); + bgr->Draw("P SAME"); // LPSAME + cgr->SetMarkerColor(kYellow-6); // kRed // 15 // kBlack + cgr->SetFillStyle(3001); + cgr->SetLineColor(kYellow-6); + cgr->SetLineWidth(3); + cgr->SetFillColor(kYellow-6); + cgr->SetMarkerStyle(20); // 21 +// bgr->SetMarkerSize(2); + cgr->Draw("3 SAME"); // LPSAME + dgr->SetMarkerColor(kRed); // kRed // 15 + dgr->SetLineColor(kRed); + dgr->SetLineWidth(3); + dgr->SetFillColor(kYellow-6); + dgr->SetMarkerStyle(20); // 21 +// bgr->SetMarkerSize(2); + dgr->Draw("P SAME"); // LPSAME + c3->Update(); + + c4->cd(); + agr = new TGraphErrors( n, energy, resolution, energyerror, resolution_error_sys ); + agr->GetYaxis()->SetTitle("#sigma_{reco} / E_{reco}"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy, resolution, energyerror, resolution_error_stat ); + bgr->GetYaxis()->SetTitle("#sigma_{reco} / E_{reco}"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + cgr = new TGraphErrors( n, energy, resolution2, energyerror, resolution_error_sys2 ); + cgr->GetYaxis()->SetTitle("#sigma_{reco} / E_{reco}"); + cgr->GetXaxis()->SetTitle("E_{true}, GeV"); + dgr = new TGraphErrors( n, energy, resolution2, energyerror, resolution_error_stat2 ); + dgr->GetYaxis()->SetTitle("#sigma_{reco} / E_{reco}"); + dgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Relative energy resolution" ); // Linearity energy resolution // Absolute energy resolution // Relative energy resolution + agr->GetYaxis()->SetRangeUser(0.0, 0.30); // -0.25, 1.0 + agr->SetTitle(fname); + + agr->SetFillColor(kCyan); + agr->SetFillStyle(3001); + agr->SetMarkerColor(kCyan); // kBlue // 12 + agr->SetLineColor(kCyan); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); // 21 +// agr->SetMarkerSize(2); + agr->Draw("A 3"); // ALP + bgr->SetMarkerColor(kBlue); // kRed // 15 + bgr->SetLineColor(kBlue); + bgr->SetLineWidth(3); + bgr->SetFillColor(kCyan); + bgr->SetMarkerStyle(20); // 21 +// bgr->SetMarkerSize(2); + bgr->Draw("P SAME"); // LPSAME + cgr->SetMarkerColor(kYellow-6); // kRed // 15 // kBlack + cgr->SetFillStyle(3001); + cgr->SetLineColor(kYellow-6); + cgr->SetLineWidth(3); + cgr->SetFillColor(kYellow-6); + cgr->SetMarkerStyle(20); // 21 +// bgr->SetMarkerSize(2); + cgr->Draw("3 SAME"); // LPSAME + dgr->SetMarkerColor(kRed); // kRed // 15 + dgr->SetLineColor(kRed); + dgr->SetLineWidth(3); + dgr->SetFillColor(kYellow-6); + dgr->SetMarkerStyle(20); // 21 +// bgr->SetMarkerSize(2); + dgr->Draw("P SAME"); // LPSAME + c4->Update(); + +// ------------------------------------------------------------------------------------------------------------------------------------------------------------------ + +/* c2->cd(); + agr = new TGraphErrors( n, energy, ratio, energyerror, ratio_error ); + agr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy2, ratio2, energyerror2, ratio_error2 ); + bgr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Linearity" ); // Linearity energy resolution // Absolute energy resolution // Relative energy resolution + agr->GetYaxis()->SetRangeUser(-0.3,0.8); + agr->SetTitle(fname); + + agr->SetMarkerColor(kBlue); // kBlue // 12 + agr->SetLineColor(kBlue); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); // 21 +// agr->SetMarkerSize(2); + agr->Draw("ALP"); + bgr->SetMarkerColor(kRed); // kRed // 15 + bgr->SetLineColor(kRed); + bgr->SetLineWidth(3); + bgr->SetMarkerStyle(29); // 21 +// bgr->SetMarkerSize(2); + bgr->Draw("LPSAME"); // LPSAME + c2->Update(); + + c3->cd(); + agr = new TGraphErrors( n, energy, mean_sigma, energyerror, absolute_error ); + agr->GetYaxis()->SetTitle("#sigma_{reco}, GeV"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy2, mean_sigma2, energyerror2, absolute_error2 ); + bgr->GetYaxis()->SetTitle("#sigma_{reco}, GeV"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Absolute energy resolution" ); // Linearity energy resolution // Absolute energy resolution // Relative energy resolution + agr->SetTitle(fname); + + agr->SetMarkerColor(kBlue); // kBlue // 12 + agr->SetLineColor(kBlue); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); // 21 +// agr->SetMarkerSize(2); + agr->Draw("ALP"); + bgr->SetMarkerColor(kRed); // kRed // 15 + bgr->SetLineColor(kRed); + bgr->SetLineWidth(3); + bgr->SetMarkerStyle(29); // 21 +// bgr->SetMarkerSize(2); + bgr->Draw("LPSAME"); // LPSAME + c3->Update(); + + c4->cd(); + agr = new TGraphErrors( n, energy, resolution, energyerror, resolution_error ); + agr->GetYaxis()->SetTitle("#sigma_{reco} / E_{reco}"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy2, resolution2, energyerror2, resolution_error2 ); + bgr->GetYaxis()->SetTitle("#sigma_{reco} / E_{reco}"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Relative energy resolution" ); // Linearity energy resolution // Absolute energy resolution // Relative energy resolution +// agr->GetYaxis()->SetRangeUser(0.03,0.45); + agr->SetTitle(fname); + + agr->SetMarkerColor(kBlue); // kBlue // 12 + agr->SetLineColor(kBlue); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); // 21 +// agr->SetMarkerSize(2); + agr->Draw("ALP"); + bgr->SetMarkerColor(kRed); // kRed // 15 + bgr->SetLineColor(kRed); + bgr->SetLineWidth(3); + bgr->SetMarkerStyle(29); // 21 +// bgr->SetMarkerSize(2); + bgr->Draw("LPSAME"); // LPSAME + c4->Update(); +*/ + TLegend *lsc1 = new TLegend(0.55,0.62,0.90,0.92); +// lsc1->AddEntry(agr,"without ANN","pl"); + lsc1->AddEntry(bgr,"data, fit","plf"); +// lsc1->AddEntry(cgr,"without ANN","plf"); + lsc1->AddEntry(dgr,"data, nofit (stat)","plf"); + + TLegend *lsc2 = new TLegend(0.55,0.62,0.90,0.92); +// lsc2->AddEntry(agr,"without ANN","pl"); + lsc2->AddEntry(bgr,"data, fit","plf"); +// lsc2->AddEntry(cgr,"without ANN","plf"); + lsc2->AddEntry(dgr,"data, nofit (stat)","plf"); + + TLegend *lsc3 = new TLegend(0.55,0.62,0.90,0.92); +// lsc2->AddEntry(agr,"without ANN","pl"); + lsc3->AddEntry(bgr,"data, fit","plf"); +// lsc2->AddEntry(cgr,"without ANN","plf"); + lsc3->AddEntry(dgr,"data, nofit (stat)","plf"); + + TLegend *lsc4 = new TLegend(0.55,0.62,0.90,0.92); +// lsc2->AddEntry(agr,"without ANN","pl"); + lsc4->AddEntry(bgr,"data, fit","plf"); +// lsc2->AddEntry(cgr,"without ANN","plf"); + lsc4->AddEntry(dgr,"data, nofit (stat)","plf"); + +// TLegend *lsc3 = new TLegend(0.55,0.62,0.90,0.92); +// lsc3->AddEntry(agr,"without ANN","pl"); +// lsc3->AddEntry(bgr,"with ANN","pl"); + +// TLegend *lsc4 = new TLegend(0.55,0.62,0.90,0.92); +// lsc4->AddEntry(agr,"without ANN","pl"); +// lsc4->AddEntry(bgr,"with ANN","pl"); + + c1->cd(); + lsc1->Draw(); + c2->cd(); + lsc2->Draw(); + c3->cd(); + lsc3->Draw(); + c4->cd(); + lsc4->Draw(); + +} diff --git a/diff_rms.c b/diff_rms.c new file mode 100644 index 0000000..0af4f6b --- /dev/null +++ b/diff_rms.c @@ -0,0 +1,743 @@ +/* +void f4(const TH1F *const pTH1F, float &resolution, float &resolutionError, bool fixDistributionCentre, bool print) +{ + static const float FLOAT_MAX(std::numeric_limits::max()); + + if (NULL == pTH1F) + return; + + if (5 > pTH1F->GetEntries()) + { + std::cout << pTH1F->GetName() << " (" << pTH1F->GetEntries() << " entries) - skipped" << std::endl; + return; + } + + // Calculate raw properties of distribution + float sum = 0., total = 0.; + double sx = 0., sxx = 0.; + const unsigned int nbins(pTH1F->GetNbinsX()); + + for (unsigned int i = 0; i <= nbins; ++i) + { + const float binx(pTH1F->GetBinLowEdge(i) + (0.5 * pTH1F->GetBinWidth(i))); + const float yi(pTH1F->GetBinContent(i)); + sx += yi * binx; + sxx += yi * binx * binx; + total += yi; + } + + const float rawMean(sx / total); + const float rawMeanSquared(sxx / total); + const float rawRms(std::sqrt(rawMeanSquared - rawMean * rawMean)); + + sum = 0.; + unsigned int is0 = 0; + + for (unsigned int i = 0; (i <= nbins) && (sum < total / 10.); ++i) + { + sum += pTH1F->GetBinContent(i); + is0 = i; + } + + // Calculate truncated properties + float rmsmin(FLOAT_MAX), sigma(FLOAT_MAX), sigmasigma(FLOAT_MAX), frac(FLOAT_MAX), efrac(FLOAT_MAX), mean(FLOAT_MAX), low(FLOAT_MAX), rms(FLOAT_MAX); + float high(0.f); + + for (unsigned int istart = 0; istart <= is0; ++istart) + { + double sumn = 0.; + double csum = 0.; + double sumx = 0.; + double sumxx = 0.; + unsigned int iend = 0; + + for (unsigned int i = istart; (i <= nbins) && (csum < 0.9 * total); ++i) + { + const float binx(pTH1F->GetBinLowEdge(i) + (0.5 * pTH1F->GetBinWidth(i))); + const float yi(pTH1F->GetBinContent(i)); + csum += yi; + + if (sumn < 0.9 * total) + { + sumn += yi; + sumx += yi * binx; + sumxx+= yi * binx * binx; + iend = i; + } + } + + const float localMean(sumx / sumn); + const float localMeanSquared(sumxx / sumn); + const float localRms(std::sqrt(localMeanSquared - localMean * localMean)); + + if (localRms < rmsmin) + { + mean = localMean; + rms = localRms; + low = pTH1F->GetBinLowEdge(istart); + high = pTH1F->GetBinLowEdge(iend); + rmsmin = localRms; + + if (fixDistributionCentre) + { + float centre = 91.2; + + if (mean > 3500.) + { + //throw InvalidEnergyException(); + cout << "QWQWQWQWQWQWQWQWQWQWQWQWQWQWQWQWQWQWQWQWQWQWQWQW" << endl; + } + + if ((mean > 2500.) && (mean < 3500.)) + centre = 3000.; + + if ((mean > 1500.) && (mean < 2500.)) + centre = 2000.; + + if ((mean > 700.) && (mean < 1500.)) + centre = 1000.; + + if ((mean > 400.) && (mean < 700.)) + centre = 500.; + + if ((mean > 250.) && (mean < 400.)) + centre = 360.; + + if ((mean > 150.) && (mean < 250.)) + centre = 200.; + + sigma = rms / mean * sqrt(centre); + sigmasigma = sigma / std::sqrt(total); + + frac = rms / mean * std::sqrt(2) * 100.; + efrac = frac / std::sqrt(total); + } + else + { + sigma = rms; + sigmasigma = sigma / std::sqrt(total); + } + } + } + + if (print) + { + std::cout << pTH1F->GetName() << " (" << pTH1F->GetEntries() << " entries), rawrms: " << rawRms << ", rms90: " << rmsmin + << " (" << low << "-" << high << "), mean: " << mean << ", sigma: " << sigma << "+-" << sigmasigma; + (fixDistributionCentre) ? (std::cout << ", sE/E: " << frac << "+-" << efrac << std::endl) : (std::cout << std::endl); + } + + resolution = frac; + resolutionError = efrac; +} + +void f3(const TH1F *const m_histogram) +{ + static const float FLOAT_MAX(std::numeric_limits::max()); + + float m_fitRangeLow(std::numeric_limits::max()); + float m_fitRangeHigh(std::numeric_limits::max()); + float m_rMSFitRange(std::numeric_limits::max()); + + float m_fitPercentage = 90.0; + + if (NULL == m_histogram) + return; + + if (5 > m_histogram->GetEntries()) + { + std::cout << m_histogram->GetName() << " (" << m_histogram->GetEntries() << " entries) - skipped" << std::endl; + return; + } + + // Calculate raw properties of distribution (ie rms100) + float sum = 0., total = 0.; + double sx = 0., sxx = 0.; + const unsigned int nbins(m_histogram->GetNbinsX()); + + for (unsigned int i = 0; i <= nbins; ++i) + { + const float binx(m_histogram->GetBinLowEdge(i) + (0.5 * m_histogram->GetBinWidth(i))); + const float yi(m_histogram->GetBinContent(i)); + sx += yi * binx; + sxx += yi * binx * binx; + total += yi; + } + + const float rawMean(sx / total); + const float rawMeanSquared(sxx / total); + const float rawRms(std::sqrt(rawMeanSquared - rawMean * rawMean)); + + sum = 0.; + unsigned int is0 = 0; + + // The /10 comes from the fact that for rms 90 the start point for the fit must occur in the first 10% of the data. + float frac = (1 - (m_fitPercentage/100.0)); + for (unsigned int i = 0; (i <= nbins) && (sum < total * frac); ++i) + { + sum += m_histogram->GetBinContent(i); + is0 = i; + } + + // Calculate truncated properties + float rmsmin(FLOAT_MAX), mean(FLOAT_MAX), low(FLOAT_MAX); + float high(0.f); + + for (unsigned int istart = 0; istart <= is0; ++istart) + { + double sumn = 0.; + double csum = 0.; + double sumx = 0.; + double sumxx = 0.; + unsigned int iend = 0; + + for (unsigned int i = istart; (i <= nbins) && (csum < (m_fitPercentage/100) * total); ++i) + { + const float binx(m_histogram->GetBinLowEdge(i) + (0.5 * m_histogram->GetBinWidth(i))); + const float yi(m_histogram->GetBinContent(i)); + //csum is the sum of yi from istart and is used to stop the sum when this exceeds X% of data. + csum += yi; + + if (sumn < (m_fitPercentage/100) * total) + { + // These variables define the final sums required once we have considered X% of data, anything else is + // continuously overwritten. + sumn += yi; + sumx += yi * binx; + sumxx+= yi * binx * binx; + iend = i; + } + } + + const float localMean(sumx / sumn); + const float localMeanSquared(sumxx / sumn); + // Standard deviation formula + const float localRms(std::sqrt(localMeanSquared - localMean * localMean)); + + if (localRms < rmsmin) + { + mean = localMean; + if (istart==0) + { + low = 0; + m_fitRangeLow = 0; + } + else + { + low = m_histogram->GetBinLowEdge(istart); + m_fitRangeLow=m_histogram->GetBinLowEdge(istart) + (0.5 * m_histogram->GetBinWidth(istart)); + } + + high = m_histogram->GetBinLowEdge(iend); + rmsmin = localRms; + m_fitRangeHigh=m_histogram->GetBinLowEdge(iend) + (0.5 * m_histogram->GetBinWidth(iend)); + } + } + + m_rMSFitRange = rmsmin; + + std::cout << m_histogram->GetName() << " (" << m_histogram->GetEntries() << " entries), rawrms: " << rawRms << ", rmsx: " << rmsmin + << " (" << low << "-" << high << "), low_fit and high_fit " << " (" << m_fitRangeLow << "-" << m_fitRangeHigh + << "), << mean: " << mean << std::endl; +} + +void f2(const TH1F *const pTH1F, float &resolution, float &resolutionError, float &scale, float &scaleError, bool print) +{ + static const float FLOAT_MAX(std::numeric_limits::max()); + + if (NULL == pTH1F) + return; + + if (5 > pTH1F->GetEntries()) + { + std::cout << pTH1F->GetName() << " (" << pTH1F->GetEntries() << " entries) - skipped" << std::endl; + return; + } + + // Calculate raw properties of distribution + float sum = 0., total = 0.; + double sx = 0., sxx = 0.; + const unsigned int nbins(pTH1F->GetNbinsX()); + + for (unsigned int i = 0; i <= nbins; ++i) + { + const float binx(pTH1F->GetBinLowEdge(i) + (0.5 * pTH1F->GetBinWidth(i))); + const float yi(pTH1F->GetBinContent(i)); + sx += yi * binx; + sxx += yi * binx * binx; + total += yi; + } + + const float rawMean(sx / total); + const float rawMeanSquared(sxx / total); + const float rawRms(std::sqrt(rawMeanSquared - rawMean * rawMean)); + + sum = 0.; + unsigned int is0 = 0; + + for (unsigned int i = 0; (i <= nbins) && (sum < total / 10.); ++i) + { + sum += pTH1F->GetBinContent(i); + is0 = i; + } + + // Calculate truncated properties + float rmsmin(FLOAT_MAX), sigma(FLOAT_MAX), sigmasigma(FLOAT_MAX), frac(FLOAT_MAX), efrac(FLOAT_MAX), mean(FLOAT_MAX), low(FLOAT_MAX), rms(FLOAT_MAX); + float high(0.f); + + for (unsigned int istart = 0; istart <= is0; ++istart) + { + double sumn = 0.; + double csum = 0.; + double sumx = 0.; + double sumxx = 0.; + unsigned int iend = 0; + + for (unsigned int i = istart; (i <= nbins) && (csum < 0.9 * total); ++i) + { + const float binx(pTH1F->GetBinLowEdge(i) + (0.5 * pTH1F->GetBinWidth(i))); + const float yi(pTH1F->GetBinContent(i)); + csum += yi; + + if (sumn < 0.9 * total) + { + sumn += yi; + sumx += yi * binx; + sumxx+= yi * binx * binx; + iend = i; + } + } + + const float localMean(sumx / sumn); + const float localMeanSquared(sumxx / sumn); + const float localRms(std::sqrt(localMeanSquared - localMean * localMean)); + + if (localRms < rmsmin) + { + mean = localMean; + rms = localRms; + low = pTH1F->GetBinLowEdge(istart); + high = pTH1F->GetBinLowEdge(iend); + rmsmin = localRms; + + sigma = rms; + sigmasigma = sigma / std::sqrt(total); + + frac = rms / mean * std::sqrt(2) * 100.; + efrac = frac / std::sqrt(total); + } + } + + if (print) + { + std::cout << pTH1F->GetName() << " (" << pTH1F->GetEntries() << " entries), rawrms: " << rawRms << ", rms90: " << rmsmin + << " (" << low << "-" << high << "), mean: " << mean << ", sigma: " << sigma << "+-" << sigmasigma; + std::cout << ", sE/E: " << frac << "+-" << efrac << std::endl; + } + + resolution = frac; + resolutionError = efrac; + scale = mean; + scaleError = sigma; +} +*/ + +void f2( TH1F* h, float &value, float &a, float &b, int &l, int &r ) +{ + static const float FLOAT_MAX(std::numeric_limits::max()); + + cout << "Value2 === " << value << endl; + cout << "Value2 / 100.0 === " << value / 100.0 << endl; + + if (NULL == h) + return; + + if (5 > h->GetEntries()) + { + std::cout << h->GetName() << " (" << h->GetEntries() << " entries) - skipped" << std::endl; + return; + } + + // Calculate raw properties of distribution + float sum = 0., total = 0.; + double sx = 0., sxx = 0.; + const unsigned int nbins(h->GetNbinsX()); + + for (unsigned int i = 0; i <= nbins; ++i) + { + const float binx(h->GetBinLowEdge(i) + (0.5 * h->GetBinWidth(i))); + const float yi(h->GetBinContent(i)); + sx += yi * binx; + sxx += yi * binx * binx; + total += yi; + } + + const float rawMean(sx / total); + const float rawMeanSquared(sxx / total); + const float rawRms(std::sqrt(rawMeanSquared - rawMean * rawMean)); + + sum = 0.; + unsigned int is0 = 0; + + for (unsigned int i = 0; (i <= nbins) && (sum < total * ( 1.0 - (value)/(100.0) ) ); ++i) + { + sum += h->GetBinContent(i); + is0 = i; + } + + // Calculate truncated properties + float rmsmin(FLOAT_MAX), sigma(FLOAT_MAX), sigmasigma(FLOAT_MAX), frac(FLOAT_MAX), efrac(FLOAT_MAX), mean(FLOAT_MAX), low(FLOAT_MAX), rms(FLOAT_MAX); + float high(0.f); + + for (unsigned int istart = 0; istart <= is0; ++istart) + { + double sumn = 0.; + double csum = 0.; + double sumx = 0.; + double sumxx = 0.; + unsigned int iend = 0; + + for (unsigned int i = istart; (i <= nbins) && (csum < ( value / 100.0 ) * total); ++i) + { + const float binx(h->GetBinLowEdge(i) + (0.5 * h->GetBinWidth(i))); + const float yi(h->GetBinContent(i)); + csum += yi; + + if (sumn < ( value / 100.0 ) * total) + { + sumn += yi; + sumx += yi * binx; + sumxx+= yi * binx * binx; + iend = i; + } + } + + const float localMean(sumx / sumn); + const float localMeanSquared(sumxx / sumn); + const float localRms(std::sqrt(localMeanSquared - localMean * localMean)); + + if (localRms < rmsmin) + { + mean = localMean; + rms = localRms; + low = h->GetBinLowEdge(istart); + l = istart; + high = h->GetBinLowEdge(iend); + r = iend; + rmsmin = localRms; + + sigma = rms; + sigmasigma = sigma / std::sqrt(total); + + frac = rms / mean * std::sqrt(2) * 100.; + efrac = frac / std::sqrt(total); + } + } + +/* if (1) + { + std::cout << h->GetName() << " (" << h->GetEntries() << " entries), rawrms: " << rawRms << ", rms90: " << rmsmin + << " (" << low << "-" << high << "), mean: " << mean << ", sigma: " << sigma << "+-" << sigmasigma; + std::cout << ", sE/E: " << frac << "+-" << efrac << std::endl; + } + + resolution = frac; + resolutionError = efrac; + scale = mean; + scaleError = sigma; */ + + printf( "RMS of central %0.f%% = %f, RMS total = %f, Mean of central %.f%% = %f, Mean total = %f\n", value, rmsmin, h -> GetRMS(), value, mean, h -> GetMean() ); + a = mean; + b = rmsmin; +} + +void f( TH1F* h, float &value, float &a, float &b, int &l, int &r ) { + cout << "Value === " << value << endl; + cout << "Value / 100.0 === " << value / 100.0 << endl; + TAxis* axis = h -> GetXaxis(); + Int_t nbins = axis -> GetNbins(); + Int_t imean = axis -> FindBin( h -> GetMean() ); + Double_t entries = ( value / 100.0 ) * ( h -> GetEntries() ); + Double_t w = h -> GetBinContent( imean ); + Double_t x = h -> GetBinCenter( imean ); + Double_t sumw = w; + Double_t sumwx = w*x; + Double_t sumwx2 = w*x*x; + for ( Int_t i = 1; i < nbins; i++ ) { + if ( i > 0 ) { + w = h -> GetBinContent( imean - i ); + x = h -> GetBinCenter( imean - i ); + l = imean - i; + sumw += w; + sumwx += w*x; + sumwx2 += w*x*x; + } + if ( i <= nbins ) { + w = h -> GetBinContent( imean + i ); + x = h -> GetBinCenter( imean + i ); + r = imean + i; + sumw += w; + sumwx += w*x; + sumwx2 += w*x*x; + } + if ( sumw > entries ) break; + } + x = sumwx / sumw; + Double_t rms2 = TMath::Abs( ( sumwx2 / sumw ) - ( x * x ) ); + Double_t result = TMath::Sqrt( rms2 ); + printf( "RMS of central %0.f%% = %f, RMS total = %f, Mean of central %.f%% = %f, Mean total = %f\n", value, result, h -> GetRMS(), value, x, h -> GetMean() ); + a = x; + b = result; +} + +void fit_data( const int fenergy = 5, const int nBins = 1000 ) { + + float FFF = 90.0; + + char fname_out[ 200 ]; + for ( int i = 0; i < 200; i++ ) fname_out[ i ] = 0; + + char fname[ 200 ]; + char ftempname[ 200 ]; + char fname2[ 200 ]; + + for ( int i = 0; i < 200; i++ ) fname[ i ] = 0; + for ( int i = 0; i < 200; i++ ) ftempname[ i ] = 0; + for ( int i = 0; i < 200; i++ ) fname2[ i ] = 0; + + sprintf( ftempname, "gun_k0L_%dgev_FTFP_BERT_5000evt_ILD_l5_v02steel", fenergy ); + sprintf( fname, "%s.root", ftempname ); + + TH1F *hist; + + TH1F *hist2; + TH1F *hist3; + + TCanvas *c1 = new TCanvas("c1", "c1", 1); +/* TCanvas *c2 = new TCanvas("c2", "c2", 1); + TCanvas *c3 = new TCanvas("c3", "c3", 1); + TCanvas *c4 = new TCanvas("c4", "c4", 1); + + TCanvas *c5 = new TCanvas("c5", "c5", 1); + TCanvas *c6 = new TCanvas("c6", "c6", 1); + TCanvas *c7 = new TCanvas("c7", "c7", 1); + TCanvas *c8 = new TCanvas("c8", "c8", 1); + */ + gStyle->SetOptStat(0); + + const char *treeName = "tree"; + const float binLo = 0.0; + const float binHi = fenergy + 30.0; + + // + // Open data file + // + std::cout << "Trying to open data file... "; + TFile *file = new TFile(fname, "READ"); + if (!file) { // if error occure then exit + std::cout << "[FAIL]" << std::endl; + return; + } + std::cout << "[OK]" << std::endl; + + // + // Open file for output + // + + sprintf( fname_out, "out_diff_rms_%0.f.txt", FFF ); + + FILE *out = fopen(fname_out, "a+"); + printf("File open... "); + if (!out) { + printf("[FAIL]\n"); + return; + } else printf("[OK]\n"); + + // + // Setup a TTree + // + std::cout << "Setup a tree... "; + TTree *tree = (TTree *)file->Get(treeName); + if (!tree) { + std::cout << "[FAIL]" << std::endl; + file->Close(); + return; + } + std::cout << "[OK]" << std::endl; + + unsigned int nEvents = tree->GetEntries(); + + // + // Setup a branch + // + Float_t energy = 0; + tree->SetBranchAddress("energy", &energy); + + // + // Create a histogram and random generator + // + hist = new TH1F("hist", "hist", nBins, binLo, binHi); + + for ( int i = 0; i GetEntry(i); + if ( energy > 0 ) hist -> Fill( energy ); + } + +// cout << "Underflow hist === " << hist->GetBinContent( 0 ) << endl; +// cout << "Overflow hist === " << hist->GetBinContent( nBins + 1 ) << endl; + + float mean = hist -> GetMean(); + float meanerror = hist -> GetMeanError(); + float rms = hist -> GetRMS(); + float rmserror = hist -> GetRMSError(); + cout << " 0:" + << " Mean: " << mean + << " Mean error: " << meanerror + << " RMS: " << rms + << " RMS error: " << rmserror + << endl; + + cout << "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" << endl; + cout << "f2:" << endl; + float f2value = FFF; + float f2mean = 0; + float f2rms = 0; + int f2left = 0; + int f2right = 0; + f2( hist, f2value, f2mean, f2rms, f2left, f2right ); + cout << "f2mean = " << f2mean << " and f2rms = " << f2rms << endl; + cout << "f2left = " << f2left << " and f2right = " << f2right << endl; + cout << "Left value f2 = " << hist->GetBinCenter( f2left ) << " and right value f2 = " << hist->GetBinCenter( f2right ) << endl; + cout << "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" << endl; + + cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl; + cout << "f:" << endl; + float fvalue = FFF; + float fmean = 0; + float frms = 0; + int fleft = 0; + int fright = 0; + f( hist, fvalue, fmean, frms, fleft, fright ); + cout << "fmean = " << fmean << " and frms = " << frms << endl; + cout << "fleft = " << fleft << " and fright = " << fright << endl; + cout << "Left value f = " << hist->GetBinCenter( fleft ) << " and right value f = " << hist->GetBinCenter( fright ) << endl; + cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl; + + hist2 = (TH1F*)hist->Clone(); + hist3 = (TH1F*)hist->Clone(); + + hist2->GetXaxis()->SetRange(fleft, fright); + hist3->GetXaxis()->SetRange(f2left, f2right); + + cout << "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ" << endl; + + cout << "Underflow hist2 === " << hist2->GetBinContent( 0 ) << endl; + cout << "Overflow hist2 === " << hist2->GetBinContent( nBins + 1 ) << endl; + float mean_hist2 = hist2 -> GetMean(); + float meanerror_hist2 = hist2 -> GetMeanError(); + float rms_hist2 = hist2 -> GetRMS(); + float rmserror_hist2 = hist2 -> GetRMSError(); + cout << " 0:" + << " Mean2: " << mean_hist2 + << " Mean2 error: " << meanerror_hist2 + << " RMS2: " << rms_hist2 + << " RMS2 error: " << rmserror_hist2 + << endl; + + cout << "Underflow hist3 === " << hist3->GetBinContent( 0 ) << endl; + cout << "Overflow hist3 === " << hist3->GetBinContent( nBins + 1 ) << endl; + float mean_hist3 = hist3 -> GetMean(); + float meanerror_hist3 = hist3 -> GetMeanError(); + float rms_hist3 = hist3 -> GetRMS(); + float rmserror_hist3 = hist3 -> GetRMSError(); + cout << " 0:" + << " Mean3: " << mean_hist3 + << " Mean3 error: " << meanerror_hist3 + << " RMS3: " << rms_hist3 + << " RMS3 error: " << rmserror_hist3 + << endl; + + cout << "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ" << endl; + +/* + c2 -> cd(); + hist -> SetMarkerStyle(20); + hist -> SetMarkerColor(kBlue); + hist -> SetLineColor(kBlue); + hist -> Draw("p e"); + c3 -> cd(); + hist90 -> SetMarkerStyle(20); + hist90 -> SetMarkerColor(kRed); + hist90 -> SetLineColor(kRed); + hist90 -> Draw("p e"); + c4 -> cd(); + hist95 -> SetMarkerStyle(20); + hist95 -> SetMarkerColor(kGreen); + hist95 -> SetLineColor(kGreen); + hist95 -> Draw("p e"); + + c5 -> cd(); + hist2 -> SetMarkerStyle(20); + hist2 -> SetMarkerColor(kRed); + hist2 -> SetLineColor(kRed); + hist2 -> Draw("p e"); + c6 -> cd(); + hist3 -> SetMarkerStyle(20); + hist3 -> SetMarkerColor(kGreen); + hist3 -> SetLineColor(kGreen); + hist3 -> Draw("p e"); + + c7 -> cd(); + hist->SetTitle("1"); + hist->GetYaxis()->SetTitle("Number of events"); + hist->GetXaxis()->SetTitle("Energy, GeV"); + hist -> SetMarkerStyle(20); + hist -> SetMarkerColor(kBlue); + hist -> SetLineColor(kBlue); + hist -> Draw("p e"); + hist2 -> SetMarkerStyle(20); + hist2 -> SetMarkerColor(kRed); + hist2 -> SetLineColor(kRed); + hist2 -> Draw("p e SAME"); +// hist3 -> SetMarkerStyle(20); +// hist3 -> SetMarkerColor(kGreen); +// hist3 -> SetLineColor(kGreen); +// hist3 -> Draw("p e SAME"); + + c8 -> cd(); + c8->Update(); + hist->SetTitle("Full distribution and 95% of the distribution"); + hist->GetYaxis()->SetTitle("Number of events"); + hist->GetXaxis()->SetTitle("Energy, GeV"); + hist -> SetMarkerStyle(20); + hist -> SetMarkerColor(kBlue); + hist -> SetLineColor(kBlue); + hist -> Draw("p e"); +// hist2 -> SetMarkerStyle(20); +// hist2 -> SetMarkerColor(kRed); +// hist2 -> SetLineColor(kRed); +// hist2 -> Draw("p e SAME"); + hist3 -> SetMarkerStyle(20); + hist3 -> SetMarkerColor(kGreen); + hist3 -> SetLineColor(kGreen); + hist3 -> Draw("p e SAME"); +*/ + + fprintf( out, "%d %E %E %E %E %E %E %E %E\n", fenergy, mean_hist2, meanerror_hist2, rms_hist2, rmserror_hist2, mean_hist3, meanerror_hist3, rms_hist3, rmserror_hist3 ); + delete hist; + fclose( out ); + file -> Close(); + +} + +void diff_rms( const int bins = 1000 ) { + +// int mass[] = { 1, 2, 3, 4, 5, 10, 15, 20, 25, 30, 40, 50, 60, 70, 80, 90 }; + int mass[] = { 5, 10, 15, 20, 25, 30, 40, 50, 60 }; + int dim = 9; // 16 + + for (int i = 0; i < dim; i++ ) { + fit_data( mass[ i ], bins ); + } + +} diff --git a/diff_rms_graph.c b/diff_rms_graph.c new file mode 100644 index 0000000..e5c72a8 --- /dev/null +++ b/diff_rms_graph.c @@ -0,0 +1,346 @@ +void diff_rms_graph() { + + float FFF = 90.0; + + char fname_out[ 200 ]; + for ( int i = 0; i < 200; i++ ) fname_out[ i ] = 0; + + char fname_legend[ 200 ]; + for ( int i = 0; i < 200; i++ ) fname_legend[ i ] = 0; + + char fname_legend2[ 200 ]; + for ( int i = 0; i < 200; i++ ) fname_legend2[ i ] = 0; + + TCanvas *c1 = new TCanvas("graph1","graph1",200,10,700,500); + TCanvas *c2 = new TCanvas("graph2","graph2",200,10,700,500); + TCanvas *c3 = new TCanvas("graph3","graph3",200,10,700,500); + TCanvas *c4 = new TCanvas("graph4","graph4",200,10,700,500); + + c1->SetGrid(); + c2->SetGrid(); + c3->SetGrid(); + c4->SetGrid(); + + const Int_t n = 9; // 16 + + Float_t energy[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t energyerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t mean[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t meanerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rmserror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t mean2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t meanerror2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rmserror2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t ratio[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_stat[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_sys[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t ratio2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_stat2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_sys2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + sprintf( fname_out, "out_diff_rms_%0.f.txt", FFF ); + + FILE *file1 = fopen(fname_out, "r"); + if ( !(long)file1 ) return; + + for ( int i = 0; i < n; i++ ) { + fscanf( file1, "%f %E %E %E %E %E %E %E %E\n", &energy[i], &mean[i], &meanerror[i], &rms[i], &rmserror[i], &mean2[i], &meanerror2[i], &rms2[i], &rmserror2[i] ); + if ( feof( file1 ) ) break; + } + + for ( int i = 0; i < n; i++ ) { + + ratio[ i ] = ( mean[i] - energy[i] ) / energy[i]; + ratio_error_stat[ i ] = sqrt( pow( (meanerror[i]) / (energy[i]), 2 ) + pow( (mean[i] * energyerror[i]) / (energy[i] * energy[i]), 2 ) ); + ratio_error_sys[ i ] = 0.0; + ratio_error[ i ] = sqrt( ( pow( ratio_error_stat[ i ], 2 ) ) + ( pow( ratio_error_sys[ i ], 2 ) ) ); + + ratio2[ i ] = ( mean2[i] - energy[i] ) / energy[i]; + ratio_error_stat2[ i ] = sqrt( pow( (meanerror2[i]) / (energy[i]), 2 ) + pow( (mean2[i] * energyerror[i]) / (energy[i] * energy[i]), 2 ) ); + ratio_error_sys2[ i ] = 0.0; + ratio_error2[ i ] = sqrt( ( pow( ratio_error_stat2[ i ], 2 ) ) + ( pow( ratio_error_sys2[ i ], 2 ) ) ); + + resolution[ i ] = rms[i] / mean[i]; + resolution_error_stat[ i ] = sqrt( pow( (rmserror[i]) / (mean[i]), 2 ) + pow( (rms[i] * meanerror[i]) / (mean[i] * mean[i]), 2 ) ); + resolution_error_sys[ i ] = 0.0; + resolution_error[ i ] = sqrt( ( pow( resolution_error_stat[ i ], 2 ) ) + ( pow( resolution_error_sys[ i ], 2 ) ) ); + + resolution2[ i ] = rms2[i] / mean2[i]; + resolution_error_stat2[ i ] = sqrt( pow( (rmserror2[i]) / (mean2[i]), 2 ) + pow( (rms2[i] * meanerror2[i]) / (mean2[i] * mean2[i]), 2 ) ); + resolution_error_sys2[ i ] = 0.0; + resolution_error2[ i ] = sqrt( ( pow( resolution_error_stat2[ i ], 2 ) ) + ( pow( resolution_error_sys2[ i ], 2 ) ) ); + + } + + printf( "\n" ); + for (int i = 0; i < n; i++) { + + printf( " mean === %f \n", mean[i] ); + printf( " rms === %f \n", rms[i] ); + printf( " mean === %f \n", mean[i] ); + printf( " rms === %f \n", rms[i] ); + + printf( " mean2 === %f \n", mean2[i] ); + printf( " rms2 === %f \n", rms2[i] ); + printf( " mean2 === %f \n", mean2[i] ); + printf( " rms2 === %f \n", rms2[i] ); + + printf( "\n" ); + + printf( " ratio === %f \n", ratio[i] ); + printf( " ratio_error === %f \n", ratio_error[i] ); + printf( " resolution === %f \n", resolution[i] ); + printf( " resolution_error === %f \n", resolution_error[i] ); + printf( " ratio2 === %f \n", ratio2[i] ); + printf( " ratio_error2 === %f \n", ratio_error2[i] ); + printf( " resolution2 === %f \n", resolution2[i] ); + printf( " resolution_error2 === %f \n", resolution_error2[i] ); + + printf( " ratio === %f \n", ratio[i] ); + printf( " ratio_error === %f \n", ratio_error[i] ); + printf( " resolution === %f \n", resolution[i] ); + printf( " resolution_error === %f \n", resolution_error[i] ); + printf( " ratio2 === %f \n", ratio2[i] ); + printf( " ratio_error2 === %f \n", ratio_error2[i] ); + printf( " resolution2 === %f \n", resolution2[i] ); + printf( " resolution_error2 === %f \n", resolution_error2[i] ); + + printf( "\n" ); + printf( "\n" ); + printf( "\n" ); + } + + TGraphErrors *agr; + TGraphErrors *bgr; + + TGraphErrors *cgr; + TGraphErrors *dgr; + + char fname[ 100 ]; + for ( int i = 0; i < 100; i++ ) fname[ i ] = 0; + + c1->cd(); + agr = new TGraphErrors( n, energy, ratio, energyerror, ratio_error_sys ); + agr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy, ratio, energyerror, ratio_error_stat ); + bgr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + cgr = new TGraphErrors( n, energy, ratio2, energyerror, ratio_error_sys2 ); + cgr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + cgr->GetXaxis()->SetTitle("E_{true}, GeV"); + dgr = new TGraphErrors( n, energy, ratio2, energyerror, ratio_error_stat2 ); + dgr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + dgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Linearity" ); + agr->GetYaxis()->SetRangeUser(-0.2, 0.2); + agr->SetTitle(fname); + + agr->SetFillColor(kCyan); + agr->SetFillStyle(3001); + agr->SetMarkerColor(kCyan); + agr->SetLineColor(kCyan); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); + agr->Draw("A 3"); + bgr->SetMarkerColor(kBlue); + bgr->SetLineColor(kBlue); + bgr->SetLineWidth(3); + bgr->SetFillColor(kCyan); + bgr->SetMarkerStyle(20); + bgr->Draw("P SAME"); + cgr->SetMarkerColor(kYellow-6); + cgr->SetFillStyle(3001); + cgr->SetLineColor(kYellow-6); + cgr->SetLineWidth(3); + cgr->SetFillColor(kYellow-6); + cgr->SetMarkerStyle(20); + cgr->Draw("3 SAME"); + dgr->SetMarkerColor(kRed); + dgr->SetLineColor(kRed); + dgr->SetLineWidth(3); + dgr->SetFillColor(kYellow-6); + dgr->SetMarkerStyle(20); + dgr->Draw("P SAME"); + c1->Update(); + + c2->cd(); + agr = new TGraphErrors( n, energy, rms, energyerror, energyerror ); + agr->GetYaxis()->SetTitle("#DeltaE_{reco}, GeV"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy, rms, energyerror, rmserror ); + bgr->GetYaxis()->SetTitle("#DeltaE_{reco}, GeV"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + cgr = new TGraphErrors( n, energy, rms2, energyerror, energyerror ); + cgr->GetYaxis()->SetTitle("#DeltaE_{reco}, GeV"); + cgr->GetXaxis()->SetTitle("E_{true}, GeV"); + dgr = new TGraphErrors( n, energy, rms2, energyerror, rmserror2 ); + dgr->GetYaxis()->SetTitle("#DeltaE_{reco}, GeV"); + dgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Absolute energy resolution" ); + agr->GetYaxis()->SetRangeUser(0.0, 9.0); + agr->SetTitle(fname); + + agr->SetFillColor(kCyan); + agr->SetFillStyle(3001); + agr->SetMarkerColor(kCyan); + agr->SetLineColor(kCyan); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); + agr->Draw("A 3"); + bgr->SetMarkerColor(kBlue); + bgr->SetLineColor(kBlue); + bgr->SetLineWidth(3); + bgr->SetFillColor(kCyan); + bgr->SetMarkerStyle(20); + bgr->Draw("P SAME"); + cgr->SetMarkerColor(kYellow-6); + cgr->SetFillStyle(3001); + cgr->SetLineColor(kYellow-6); + cgr->SetLineWidth(3); + cgr->SetFillColor(kYellow-6); + cgr->SetMarkerStyle(20); + cgr->Draw("3 SAME"); + dgr->SetMarkerColor(kRed); + dgr->SetLineColor(kRed); + dgr->SetLineWidth(3); + dgr->SetFillColor(kYellow-6); + dgr->SetMarkerStyle(20); + dgr->Draw("P SAME"); + c2->Update(); + + c3->cd(); + agr = new TGraphErrors( n, energy, mean, energyerror, energyerror ); + agr->GetYaxis()->SetTitle("E_{reco}, GeV"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy, mean, energyerror, meanerror ); + bgr->GetYaxis()->SetTitle("E_{reco}, GeV"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + cgr = new TGraphErrors( n, energy, mean2, energyerror, energyerror ); + cgr->GetYaxis()->SetTitle("E_{reco}, GeV"); + cgr->GetXaxis()->SetTitle("E_{true}, GeV"); + dgr = new TGraphErrors( n, energy, mean2, energyerror, meanerror2 ); + dgr->GetYaxis()->SetTitle("E_{reco}, GeV"); + dgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Linearity 2" ); + agr->GetYaxis()->SetRangeUser(0.0, 70.0); + agr->SetTitle(fname); + + agr->SetFillColor(kCyan); + agr->SetFillStyle(3001); + agr->SetMarkerColor(kCyan); + agr->SetLineColor(kCyan); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); + agr->Draw("A 3"); + bgr->SetMarkerColor(kBlue); + bgr->SetLineColor(kBlue); + bgr->SetLineWidth(3); + bgr->SetFillColor(kCyan); + bgr->SetMarkerStyle(20); + bgr->Draw("P SAME"); + cgr->SetMarkerColor(kYellow-6); + cgr->SetFillStyle(3001); + cgr->SetLineColor(kYellow-6); + cgr->SetLineWidth(3); + cgr->SetFillColor(kYellow-6); + cgr->SetMarkerStyle(20); + cgr->Draw("3 SAME"); + dgr->SetMarkerColor(kRed); + dgr->SetLineColor(kRed); + dgr->SetLineWidth(3); + dgr->SetFillColor(kYellow-6); + dgr->SetMarkerStyle(20); + dgr->Draw("P SAME"); + c3->Update(); + + c4->cd(); + agr = new TGraphErrors( n, energy, resolution, energyerror, resolution_error_sys ); + agr->GetYaxis()->SetTitle("#DeltaE_{reco} / E_{reco}"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy, resolution, energyerror, resolution_error_stat ); + bgr->GetYaxis()->SetTitle("#DeltaE_{reco} / E_{reco}"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + cgr = new TGraphErrors( n, energy, resolution2, energyerror, resolution_error_sys2 ); + cgr->GetYaxis()->SetTitle("#DeltaE_{reco} / E_{reco}"); + cgr->GetXaxis()->SetTitle("E_{true}, GeV"); + dgr = new TGraphErrors( n, energy, resolution2, energyerror, resolution_error_stat2 ); + dgr->GetYaxis()->SetTitle("#DeltaE_{reco} / E_{reco}"); + dgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Relative energy resolution" ); + agr->GetYaxis()->SetRangeUser(0.0, 0.30); + agr->SetTitle(fname); + + agr->SetFillColor(kCyan); + agr->SetFillStyle(3001); + agr->SetMarkerColor(kCyan); + agr->SetLineColor(kCyan); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); + agr->Draw("A 3"); + bgr->SetMarkerColor(kBlue); + bgr->SetLineColor(kBlue); + bgr->SetLineWidth(3); + bgr->SetFillColor(kCyan); + bgr->SetMarkerStyle(20); + bgr->Draw("P SAME"); + cgr->SetMarkerColor(kYellow-6); + cgr->SetFillStyle(3001); + cgr->SetLineColor(kYellow-6); + cgr->SetLineWidth(3); + cgr->SetFillColor(kYellow-6); + cgr->SetMarkerStyle(20); + cgr->Draw("3 SAME"); + dgr->SetMarkerColor(kRed); + dgr->SetLineColor(kRed); + dgr->SetLineWidth(3); + dgr->SetFillColor(kYellow-6); + dgr->SetMarkerStyle(20); + dgr->Draw("P SAME"); + c4->Update(); + + sprintf( fname_legend, "hist%0.f_old (stat)", FFF ); + sprintf( fname_legend2, "hist%0.f_new (stat)", FFF ); + + TLegend *lsc1 = new TLegend(0.55,0.62,0.90,0.92); + lsc1->AddEntry( bgr, fname_legend, "pl" ); + lsc1->AddEntry( dgr, fname_legend2, "pl" ); + + TLegend *lsc2 = new TLegend(0.55,0.62,0.90,0.92); + lsc2->AddEntry( bgr, fname_legend, "pl" ); + lsc2->AddEntry( dgr, fname_legend2, "pl" ); + + TLegend *lsc3 = new TLegend(0.55,0.62,0.90,0.92); + lsc3->AddEntry( bgr, fname_legend, "pl" ); + lsc3->AddEntry( dgr, fname_legend2, "pl" ); + + TLegend *lsc4 = new TLegend(0.55,0.62,0.90,0.92); + lsc4->AddEntry( bgr, fname_legend, "pl" ); + lsc4->AddEntry( dgr, fname_legend2, "pl" ); + + c1->cd(); + lsc1->Draw(); + c2->cd(); + lsc2->Draw(); + c3->cd(); + lsc3->Draw(); + c4->cd(); + lsc4->Draw(); + +} diff --git a/fit_rel.c b/fit_rel.c new file mode 100644 index 0000000..c2dc7bf --- /dev/null +++ b/fit_rel.c @@ -0,0 +1,168 @@ +void fit_rel() { + TCanvas *c1 = new TCanvas("graph1","graph1",200,10,700,500); + + c1->SetGrid(); + + const Int_t n = 9; // 16 + + Float_t energy[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t energyerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t mean[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t mean90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t mean_mean[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_sigma[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t resolution_hist[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t temp = 0; + + FILE *file1 = fopen("new_2out_data.txt", "r"); + if ( !(long)file1 ) return; + + for ( int i = 0; i < n; i++ ) { + fscanf( file1, "%f %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E\n", &energy[i], &temp, &temp, &temp, &temp, &temp, &temp, &temp, &temp, &temp, &temp, &temp, &temp, &mean90[i], &rms90[i], &mean95[i], &rms95[i], &temp, &temp, &mean[i], &temp, &rms[i], &temp, &mean_mean[i], &temp, &mean_sigma[i], &temp, &temp ); + if ( feof( file1 ) ) break; + } + + for ( int i = 0; i < n; i++ ) { + + resolution_hist[ i ] = rms[i] / mean[i]; + + resolution90[ i ] = rms90[i] / mean90[i]; + + resolution95[ i ] = rms95[i] / mean95[i]; + + resolution[ i ] = mean_sigma[i] / mean_mean[i]; + + } + + printf( "\n" ); + for (int i = 0; i < n; i++) { + printf( " %f ", energy[i] ); + printf( " %f ", energyerror[i] ); + + printf( " %f ", mean[i] ); + printf( " %f ", rms[i] ); + + printf( " %f ", mean90[i] ); + printf( " %f ", rms90[i] ); + printf( " %f ", mean95[i] ); + printf( " %f ", rms95[i] ); + + printf( " %f ", resolution_hist[i] ); + + printf( " %f ", resolution90[i] ); + printf( " %f ", resolution95[i] ); + + printf( " %f ", mean_mean[i] ); + printf( " %f ", mean_sigma[i] ); + printf( " %f ", resolution[i] ); + + printf( "\n" ); + printf( "\n" ); + printf( "\n" ); + + } + + TGraph *agr; + TGraph *bgr; + TGraph *cgr; + TGraph *dgr; + + char fname[ 100 ]; + for ( int i = 0; i < 100; i++ ) fname[ i ] = 0; + + c1->cd(); + agr = new TGraph( n, energy, resolution ); + agr->GetYaxis()->SetTitle("#DeltaE_{reco} / E_{reco}"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraph( n, energy, resolution90 ); + bgr->GetYaxis()->SetTitle("#DeltaE_{reco} / E_{reco}"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + cgr = new TGraph( n, energy, resolution95 ); + cgr->GetYaxis()->SetTitle("#DeltaE_{reco} / E_{reco}"); + cgr->GetXaxis()->SetTitle("E_{true}, GeV"); + dgr = new TGraph( n, energy, resolution_hist ); + dgr->GetYaxis()->SetTitle("#DeltaE_{reco} / E_{reco}"); + dgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Relative energy resolution" ); + agr->GetYaxis()->SetRangeUser(0.0, 0.30); + agr->SetTitle(fname); + + //TF1 *f1 = new TF1("f1", "sqrt([0]*[0]/x + [1]*[1])" ); + //TF1 *f2 = new TF1("f2", "sqrt([0]*[0]/x + [1]*[1])" ); + //TF1 *f3 = new TF1("f3", "sqrt([0]*[0]/x + [1]*[1])" ); + //TF1 *f4 = new TF1("f4", "sqrt([0]*[0]/x + [1]*[1])" ); + + TF1 *f1 = new TF1("f1", "sqrt([0]*[0]/x + [1]*[1] + ([2]*[2])/(x*x))" ); + TF1 *f2 = new TF1("f2", "sqrt([0]*[0]/x + [1]*[1] + ([2]*[2])/(x*x))" ); + TF1 *f3 = new TF1("f3", "sqrt([0]*[0]/x + [1]*[1] + ([2]*[2])/(x*x))" ); + TF1 *f4 = new TF1("f4", "sqrt([0]*[0]/x + [1]*[1] + ([2]*[2])/(x*x))" ); + + cout << "Fit:" << endl; + agr -> Fit( f1 ); + cout << "Hist90:" << endl; + bgr -> Fit( f2 ); + cout << "Hist95:" << endl; + cgr -> Fit( f3 ); + cout << "Hist:" << endl; + dgr -> Fit( f4 ); + f1->SetLineColor(kBlue); + f2->SetLineColor(kRed); + f3->SetLineColor(kGreen); + f4->SetLineColor(kMagenta); + + c1 -> cd(); + agr->SetFillColor(kBlue); + //agr->SetFillStyle(3001); + agr->SetMarkerColor(kBlue); + agr->SetLineColor(kBlue); + agr->SetLineWidth(3); + agr->SetMarkerStyle(20); + agr->Draw("A P"); +// f1 -> Draw(); + bgr->SetMarkerColor(kRed); + bgr->SetLineColor(kRed); + bgr->SetLineWidth(3); + bgr->SetFillColor(kRed); + bgr->SetMarkerStyle(20); + bgr->Draw("P SAME"); +// f2 -> Draw("SAME"); + cgr->SetMarkerColor(kGreen); + //cgr->SetFillStyle(3001); + cgr->SetLineColor(kGreen); + cgr->SetLineWidth(3); + cgr->SetFillColor(kGreen); + cgr->SetMarkerStyle(20); + cgr->Draw("P SAME"); +// f3 -> Draw("SAME"); + dgr->SetMarkerColor(kMagenta); + dgr->SetLineColor(kMagenta); + dgr->SetLineWidth(3); + dgr->SetFillColor(kMagenta); + dgr->SetMarkerStyle(20); + dgr->Draw("P SAME"); +// f4 -> Draw("SAME"); + c1->Update(); + + TLegend *lsc1 = new TLegend(0.55,0.62,0.90,0.92); + lsc1->AddEntry(agr,"fit (w/o errors)","pl"); + lsc1->AddEntry(bgr,"hist90 (w/o errors)","pl"); + lsc1->AddEntry(cgr,"hist95 (w/o errors)","pl"); + lsc1->AddEntry(dgr,"hist (w/o errors)","pl"); + + c1->cd(); + lsc1->Draw(); + +} + diff --git a/fit_rel2.c b/fit_rel2.c new file mode 100644 index 0000000..9262b55 --- /dev/null +++ b/fit_rel2.c @@ -0,0 +1,293 @@ +/*Double_t func(Double_t *x, Double_t *par) { + + Double_t a = sqrt((par[0]*par[0])/(*x) + par[1]*par[1] + (par[2]*par[2])/((*x)*(*x))); + + return a; + +} +*/ +void fit_rel2() { + TCanvas *c1 = new TCanvas("graph1","graph1",200,10,700,500); + + c1->SetGrid(); + + const Int_t n = 9; // 16 + + Float_t energy[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t energyerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t mean[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t meanerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rmserror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t mean_hist90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t meanerror_hist90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_hist90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rmserror_hist90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t mean_hist95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t meanerror_hist95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_hist95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rmserror_hist95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t mean90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t mean_mean[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_mean[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_meanerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_meanerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_sigma[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_sigma[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_sigmaerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_sigmaerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_chi[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_chi[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t resolution_hist[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat_hist[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys_hist[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_hist[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t resolution_hist90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat_hist90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys_hist90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_hist90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t resolution_hist95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat_hist95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys_hist95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_hist95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t resolution90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t resolution95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t resolution[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + FILE *file1 = fopen("new_2out_data.txt", "r"); + if ( !(long)file1 ) return; + + for ( int i = 0; i < n; i++ ) { + fscanf( file1, "%f %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E\n", &energy[i], &mean_hist90[i], &meanerror_hist90[i], &rms_hist90[i], &rmserror_hist90[i], &mean_hist95[i], &meanerror_hist95[i], &rms_hist95[i], &rmserror_hist95[i], &mean90[i], &rms90[i], &mean95[i], &rms95[i], &mean[i], &meanerror[i], &rms[i], &rmserror[i], &mean_mean[i], &mean_meanerror[i], &mean_sigma[i], &mean_sigmaerror[i], &mean_chi[i] ); + if ( feof( file1 ) ) break; + } + + for ( int i = 0; i < n; i++ ) { + + resolution_hist[ i ] = rms[i] / mean[i]; + resolution_error_stat_hist[ i ] = sqrt( pow( (rmserror[i]) / (mean[i]), 2 ) + pow( (rms[i] * meanerror[i]) / (mean[i] * mean[i]), 2 ) ); + resolution_error_sys_hist[ i ] = 0.0; + resolution_error_hist[ i ] = sqrt( ( pow( resolution_error_stat_hist[ i ], 2 ) ) + ( pow( resolution_error_sys_hist[ i ], 2 ) ) ); + + resolution_hist90[ i ] = rms_hist90[i] / mean_hist90[i]; + resolution_error_stat_hist90[ i ] = sqrt( pow( (rmserror_hist90[i]) / (mean_hist90[i]), 2 ) + pow( (rms_hist90[i] * meanerror_hist90[i]) / (mean_hist90[i] * mean_hist90[i]), 2 ) ); + resolution_error_sys_hist90[ i ] = 0.0; + resolution_error_hist90[ i ] = sqrt( ( pow( resolution_error_stat_hist90[ i ], 2 ) ) + ( pow( resolution_error_sys_hist90[ i ], 2 ) ) ); + + resolution_hist95[ i ] = rms_hist95[i] / mean_hist95[i]; + resolution_error_stat_hist95[ i ] = sqrt( pow( (rmserror_hist95[i]) / (mean_hist95[i]), 2 ) + pow( (rms_hist95[i] * meanerror_hist95[i]) / (mean_hist95[i] * mean_hist95[i]), 2 ) ); + resolution_error_sys_hist95[ i ] = 0.0; + resolution_error_hist95[ i ] = sqrt( ( pow( resolution_error_stat_hist95[ i ], 2 ) ) + ( pow( resolution_error_sys_hist95[ i ], 2 ) ) ); + + resolution90[ i ] = rms90[i] / mean90[i]; + resolution_error_stat90[ i ] = 0.0; + resolution_error_sys90[ i ] = 0.0; + resolution_error90[ i ] = sqrt( ( pow( resolution_error_stat90[ i ], 2 ) ) + ( pow( resolution_error_sys90[ i ], 2 ) ) ); + + resolution95[ i ] = rms95[i] / mean95[i]; + resolution_error_stat95[ i ] = 0.0; + resolution_error_sys95[ i ] = 0.0; + resolution_error95[ i ] = sqrt( ( pow( resolution_error_stat95[ i ], 2 ) ) + ( pow( resolution_error_sys95[ i ], 2 ) ) ); + + resolution[ i ] = mean_sigma[i] / mean_mean[i]; + resolution_error_stat[ i ] = sqrt( pow( (mean_sigmaerror[i]) / (mean_mean[i]), 2 ) + pow( (mean_sigma[i] * mean_meanerror[i]) / (mean_mean[i] * mean_mean[i]), 2 ) ); + resolution_error_sys[ i ] = 0.0; + resolution_error[ i ] = sqrt( ( pow( resolution_error_stat[ i ], 2 ) ) + ( pow( resolution_error_sys[ i ], 2 ) ) ); + + } + printf( "\n" ); + for (int i = 0; i < n; i++) { + printf( " %f ", energy[i] ); + printf( " %f ", energyerror[i] ); + + printf( " %f ", mean[i] ); + printf( " %f ", meanerror[i] ); + printf( " %f ", rms[i] ); + printf( " %f ", rmserror[i] ); + + printf( " %f ", mean_hist90[i] ); + printf( " %f ", meanerror_hist90[i] ); + printf( " %f ", rms_hist90[i] ); + printf( " %f ", rmserror_hist90[i] ); + + printf( " %f ", mean_hist95[i] ); + printf( " %f ", meanerror_hist95[i] ); + printf( " %f ", rms_hist95[i] ); + printf( " %f ", rmserror_hist95[i] ); + + printf( " %f ", mean90[i] ); + printf( " %f ", rms90[i] ); + printf( " %f ", mean95[i] ); + printf( " %f ", rms95[i] ); + + printf( " %f ", resolution_hist[i] ); + printf( " %f ", resolution_error_hist[i] ); + + printf( " %f ", resolution_hist90[i] ); + printf( " %f ", resolution_error_hist90[i] ); + + printf( " %f ", resolution_hist95[i] ); + printf( " %f ", resolution_error_hist95[i] ); + + printf( " %f ", resolution90[i] ); + printf( " %f ", resolution_error90[i] ); + printf( " %f ", resolution95[i] ); + printf( " %f ", resolution_error95[i] ); + + printf( " %f ", mean_mean[i] ); + printf( " %f ", rms_mean[i] ); + printf( " %f ", mean_meanerror[i] ); + printf( " %f ", rms_meanerror[i] ); + printf( " %f ", mean_sigma[i] ); + printf( " %f ", rms_sigma[i] ); + printf( " %f ", mean_sigmaerror[i] ); + printf( " %f ", rms_sigmaerror[i] ); + printf( " %f ", resolution[i] ); + printf( " %f ", resolution_error[i] ); + + printf( "\n" ); + printf( "\n" ); + printf( "\n" ); + + } + + TGraphErrors *xgr; + TGraphErrors *ygr; + TGraphErrors *agr; + TGraphErrors *bgr; + TGraphErrors *cgr; + TGraphErrors *dgr; + + char fname[ 100 ]; + for ( int i = 0; i < 100; i++ ) fname[ i ] = 0; + + //c1->cd(); + xgr = new TGraphErrors( n, energy, resolution, energyerror, resolution_error ); + xgr->GetYaxis()->SetTitle("#DeltaE_{reco} / E_{reco}"); + xgr->GetXaxis()->SetTitle("E_{true}, GeV"); + ygr = new TGraphErrors( n, energy, resolution_hist90, energyerror, resolution_error_hist90 ); + ygr->GetYaxis()->SetTitle("#DeltaE_{reco} / E_{reco}"); + ygr->GetXaxis()->SetTitle("E_{true}, GeV"); + agr = new TGraphErrors( n, energy, resolution, energyerror, resolution_error ); + agr->GetYaxis()->SetTitle("#DeltaE_{reco} / E_{reco}"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy, resolution_hist90, energyerror, resolution_error_hist90 ); + bgr->GetYaxis()->SetTitle("#DeltaE_{reco} / E_{reco}"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + cgr = new TGraphErrors( n, energy, resolution_hist95, energyerror, resolution_error_hist95 ); + cgr->GetYaxis()->SetTitle("#DeltaE_{reco} / E_{reco}"); + cgr->GetXaxis()->SetTitle("E_{true}, GeV"); + dgr = new TGraphErrors( n, energy, resolution_hist, energyerror, resolution_error_hist ); + dgr->GetYaxis()->SetTitle("#DeltaE_{reco} / E_{reco}"); + dgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Relative energy resolution" ); + agr->GetYaxis()->SetRangeUser(0.0, 0.30); + agr->SetTitle(fname); + + //TFormula *my_formula2 = new TFormula("my_formula2","[0]*[0]/x + [1]*[1] + ([2]*[2])/(x*x)"); + //TFormula *my_formula = new TFormula("my_formula","TMath::Power([0], 2)/x + TMath::Power([1], 2) + TMath::Power([2], 2)/(TMath::Power(x, 2))"); + + //TF1 *f0 = new TF1("f0", "sqrt([0]*[0]/x + [1]*[1])" ); + //TF1 *f1 = new TF1("f1", "sqrt([0]*[0]/x + [1]*[1])" ); + //TF1 *f2 = new TF1("f2", "sqrt([0]*[0]/x + [1]*[1])" ); + //TF1 *f3 = new TF1("f3", "sqrt([0]*[0]/x + [1]*[1])" ); + //TF1 *f4 = new TF1("f4", "sqrt([0]*[0]/x + [1]*[1])" ); + + //TF1 *f0 = new TF1("f0", "sqrt([0]*[0]/x + [1]*[1] + ([2]*[2])/(x*x))" ); + TF1 *f1 = new TF1("f1", "sqrt([0]*[0]/x + [1]*[1] + ([2]*[2])/(x*x))" ); + //TF1 *f2 = new TF1("f2", "sqrt([0]*[0]/x + [1]*[1] + ([2]*[2])/(x*x))" ); + //TF1 *f3 = new TF1("f3", "sqrt([0]*[0]/x + [1]*[1] + ([2]*[2])/(x*x))" ); + //TF1 *f4 = new TF1("f4", "sqrt([0]*[0]/x + [1]*[1] + ([2]*[2])/(x*x))" ); + + //TF1 *f1 = new TF1("f1", "my_formula" ); + + cout << "Fit_test:" << endl; + //f1 -> SetParameter(2, 0.0); + //f1 -> SetParameter(1, 0.0); + //f1 -> SetParameter(2, 0.0); + xgr -> Fit( f1 ); + cout << "Hist90_2_test:" << endl; + //f2 -> SetParameter(2, 0.3); + ygr -> Fit( f1 ); + + cout << "Fit:" << endl; + //f1 -> SetParameter(0, 0.0); + //f1 -> SetParameter(1, 0.0); + //f1 -> SetParameter(2, 0.0); + agr -> Fit( f1 ); + cout << "Hist90_2:" << endl; + //f2 -> SetParameter(2, 0.3); + bgr -> Fit( f1 ); + cout << "Hist95_2:" << endl; + //f3 -> SetParameter(2, 0.3); + cgr -> Fit( f1 ); + cout << "Hist:" << endl; + //f4 -> SetParameter(2, 0.3); + dgr -> Fit( f1 ); + //f1->SetLineColor(kBlue); + //f1->SetLineColor(kRed); + //f1->SetLineColor(kGreen); + //f1->SetLineColor(kMagenta); + + //c1 -> cd(); + agr->SetFillColor(kBlue); + //agr->SetFillStyle(3001); + agr->SetMarkerColor(kBlue); + agr->SetLineColor(kBlue); + agr->SetLineWidth(3); + agr->SetMarkerStyle(20); + agr->Draw("A P"); + bgr->SetMarkerColor(kRed); + bgr->SetLineColor(kRed); + bgr->SetLineWidth(3); + bgr->SetFillColor(kRed); + bgr->SetMarkerStyle(20); + bgr->Draw("P SAME"); + cgr->SetMarkerColor(kGreen); + //cgr->SetFillStyle(3001); + cgr->SetLineColor(kGreen); + cgr->SetLineWidth(3); + cgr->SetFillColor(kGreen); + cgr->SetMarkerStyle(20); + cgr->Draw("P SAME"); + dgr->SetMarkerColor(kMagenta); + dgr->SetLineColor(kMagenta); + dgr->SetLineWidth(3); + dgr->SetFillColor(kMagenta); + dgr->SetMarkerStyle(20); + dgr->Draw("P SAME"); + c1->Update(); + + TLegend *lsc1 = new TLegend(0.55,0.62,0.90,0.92); + lsc1->AddEntry(agr,"fit (stat)","pl"); + lsc1->AddEntry(bgr,"hist90_2 (stat)","pl"); + lsc1->AddEntry(cgr,"hist95_2 (stat)","pl"); + lsc1->AddEntry(dgr,"hist (stat)","pl"); + + //c1->cd(); + lsc1->Draw(); + +} diff --git a/graph.c b/graph.c index 7b83665..204b63b 100644 --- a/graph.c +++ b/graph.c @@ -1,231 +1,1252 @@ -void graph(int count = 1) { - TCanvas *c1 = new TCanvas("graph","graph",200,10,700,500); +void graph() { + TCanvas *c1 = new TCanvas("graph1","graph1",200,10,700,500); + TCanvas *c2 = new TCanvas("graph2","graph2",200,10,700,500); + TCanvas *c3 = new TCanvas("graph3","graph3",200,10,700,500); + TCanvas *c4 = new TCanvas("graph4","graph4",200,10,700,500); - //c1->SetFillColor(42); - //gStyle->SetPalette(52); c1->SetGrid(); - //c1->GetFrame()->SetFillColor(21); - //c1->GetFrame()->SetBorderSize(12); + c2->SetGrid(); + c3->SetGrid(); + c4->SetGrid(); - const Int_t n = 9; + const Int_t n = 9; // 16 Float_t energy[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; Float_t energyerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; Float_t meanerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - Float_t sigma[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - Float_t sigmaerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - Float_t value[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - Float_t error[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - - Float_t energy2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - Float_t energyerror2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - Float_t mean2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - Float_t meanerror2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - Float_t sigma2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - Float_t sigmaerror2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - Float_t value2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - Float_t error2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - - Float_t energy3[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - Float_t energyerror3[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - Float_t mean3[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - Float_t meanerror3[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - Float_t sigma3[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - Float_t sigmaerror3[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - Float_t value3[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - Float_t error3[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - - float temp11 = 0; - float temp12 = 0; - float temp21 = 0; - float temp22 = 0; - float temp31 = 0; - float temp32 = 0; -/* - for (int i = 0; i < n; i++) { - printf( " %f ", energy[i] ); - printf( " %f ", energyerror[i] ); - printf( " %f ", mean[i] ); - printf( " %f ", meanerror[i] ); - printf( " %f ", sigma[i] ); - printf( " %f ", sigmaerror[i] ); - printf( " %f ", value[i] ); - printf( " %f ", error[i] ); - printf( "\n" ); - printf( " %f ", energy2[i] ); - printf( " %f ", energyerror2[i] ); - printf( " %f ", mean2[i] ); - printf( " %f ", meanerror2[i] ); - printf( " %f ", sigma2[i] ); - printf( " %f ", sigmaerror2[i] ); - printf( " %f ", value2[i] ); - printf( " %f ", error2[i] ); - printf( "\n" ); - } -*/ - FILE *file = fopen("out_nodigi.txt", "r"); - if ( !(long)file ) return; + Float_t rms[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rmserror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t mean_hist90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t meanerror_hist90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_hist90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rmserror_hist90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t mean_hist95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t meanerror_hist95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_hist95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rmserror_hist95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t mean_hist96[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t meanerror_hist96[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_hist96[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rmserror_hist96[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t mean_hist97[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t meanerror_hist97[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_hist97[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rmserror_hist97[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t mean_hist98[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t meanerror_hist98[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_hist98[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rmserror_hist98[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t mean_hist99[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t meanerror_hist99[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_hist99[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rmserror_hist99[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t mean_mean[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_mean[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_meanerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_meanerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_sigma[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_sigma[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_sigmaerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_sigmaerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_chi[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_chi[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t ratio_hist[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_stat_hist[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_sys_hist[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_hist[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_hist[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat_hist[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys_hist[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_hist[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t ratio_hist90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_stat_hist90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_sys_hist90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_hist90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_hist90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat_hist90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys_hist90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_hist90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t ratio_hist95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_stat_hist95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_sys_hist95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_hist95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_hist95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat_hist95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys_hist95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_hist95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t ratio_hist96[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_stat_hist96[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_sys_hist96[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_hist96[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_hist96[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat_hist96[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys_hist96[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_hist96[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t ratio_hist97[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_stat_hist97[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_sys_hist97[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_hist97[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_hist97[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat_hist97[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys_hist97[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_hist97[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t ratio_hist98[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_stat_hist98[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_sys_hist98[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_hist98[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_hist98[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat_hist98[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys_hist98[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_hist98[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t ratio_hist99[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_stat_hist99[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_sys_hist99[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_hist99[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_hist99[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat_hist99[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys_hist99[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_hist99[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t linearity_error[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t absolute_error[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_stat[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_sys[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - FILE *file2 = fopen("out_digi.txt", "r"); - if ( !(long)file2 ) return; - - FILE *file3 = fopen("out_60digi.txt", "r"); - if ( !(long)file3 ) return; + FILE *file1 = fopen("new_2out_data.txt", "r"); + if ( !(long)file1 ) return; for ( int i = 0; i < n; i++ ) { - fscanf( file, "%f %E %E %E %E %E %E\n", &energy[i], &mean[i], &meanerror[i], &sigma[i], &sigmaerror[i], &temp11, &temp12 ); - if ( feof( file ) ) break; + fscanf( file1, "%f %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E\n", &energy[i], &mean_hist90[i], &meanerror_hist90[i], &rms_hist90[i], &rmserror_hist90[i], &mean_hist95[i], &meanerror_hist95[i], &rms_hist95[i], &rmserror_hist95[i], &mean_hist96[i], &meanerror_hist96[i], &rms_hist96[i], &rmserror_hist96[i], &mean_hist97[i], &meanerror_hist97[i], &rms_hist97[i], &rmserror_hist97[i], &mean_hist98[i], &meanerror_hist98[i], &rms_hist98[i], &rmserror_hist98[i], &mean_hist99[i], &meanerror_hist99[i], &rms_hist99[i], &rmserror_hist99[i], &mean[i], &meanerror[i], &rms[i], &rmserror[i], &mean_mean[i], &mean_meanerror[i], &mean_sigma[i], &mean_sigmaerror[i], &mean_chi[i] ); + if ( feof( file1 ) ) break; } - + for ( int i = 0; i < n; i++ ) { - fscanf( file2, "%f %E %E %E %E %E %E\n", &energy2[i], &mean2[i], &meanerror2[i], &sigma2[i], &sigmaerror2[i], &temp21, &temp22 ); - if ( feof( file2 ) ) break; - } - for ( int i = 0; i < n; i++ ) { - fscanf( file3, "%f %E %E %E %E %E %E\n", &energy3[i], &mean3[i], &meanerror3[i], &sigma3[i], &sigmaerror3[i], &temp31, &temp32 ); - if ( feof( file3 ) ) break; - } - - for ( int i = 0; i < n; i++ ) { - value[ i ] = sigma[i] / mean[i]; - error[ i ] = sqrt( pow( (sigmaerror[i])/(mean[i]) ,2 ) + pow( (sigma[i] * meanerror[i])/(mean[i] * mean[i]) ,2 ) ); - - value2[ i ] = sigma2[i] / mean2[i]; - error2[ i ] = sqrt( pow( (sigmaerror2[i])/(mean2[i]) ,2 ) + pow( (sigma2[i] * meanerror2[i])/(mean2[i] * mean2[i]) ,2 ) ); + ratio_hist[ i ] = ( mean[i] - energy[i] ) / energy[i]; + ratio_error_stat_hist[ i ] = sqrt( pow( (meanerror[i]) / (energy[i]), 2 ) + pow( (mean[i] * energyerror[i]) / (energy[i] * energy[i]), 2 ) ); + ratio_error_sys_hist[ i ] = 0.0; + ratio_error_hist[ i ] = sqrt( ( pow( ratio_error_stat_hist[ i ], 2 ) ) + ( pow( ratio_error_sys_hist[ i ], 2 ) ) ); + + ratio_hist90[ i ] = ( mean_hist90[i] - energy[i] ) / energy[i]; + ratio_error_stat_hist90[ i ] = sqrt( pow( (meanerror_hist90[i]) / (energy[i]), 2 ) + pow( (mean_hist90[i] * energyerror[i]) / (energy[i] * energy[i]), 2 ) ); + ratio_error_sys_hist90[ i ] = 0.0; + ratio_error_hist90[ i ] = sqrt( ( pow( ratio_error_stat_hist90[ i ], 2 ) ) + ( pow( ratio_error_sys_hist90[ i ], 2 ) ) ); + + ratio_hist95[ i ] = ( mean_hist95[i] - energy[i] ) / energy[i]; + ratio_error_stat_hist95[ i ] = sqrt( pow( (meanerror_hist95[i]) / (energy[i]), 2 ) + pow( (mean_hist95[i] * energyerror[i]) / (energy[i] * energy[i]), 2 ) ); + ratio_error_sys_hist95[ i ] = 0.0; + ratio_error_hist95[ i ] = sqrt( ( pow( ratio_error_stat_hist95[ i ], 2 ) ) + ( pow( ratio_error_sys_hist95[ i ], 2 ) ) ); + + ratio_hist96[ i ] = ( mean_hist96[i] - energy[i] ) / energy[i]; + ratio_error_stat_hist96[ i ] = sqrt( pow( (meanerror_hist96[i]) / (energy[i]), 2 ) + pow( (mean_hist96[i] * energyerror[i]) / (energy[i] * energy[i]), 2 ) ); + ratio_error_sys_hist96[ i ] = 0.0; + ratio_error_hist96[ i ] = sqrt( ( pow( ratio_error_stat_hist96[ i ], 2 ) ) + ( pow( ratio_error_sys_hist96[ i ], 2 ) ) ); + + ratio_hist97[ i ] = ( mean_hist97[i] - energy[i] ) / energy[i]; + ratio_error_stat_hist97[ i ] = sqrt( pow( (meanerror_hist97[i]) / (energy[i]), 2 ) + pow( (mean_hist97[i] * energyerror[i]) / (energy[i] * energy[i]), 2 ) ); + ratio_error_sys_hist97[ i ] = 0.0; + ratio_error_hist97[ i ] = sqrt( ( pow( ratio_error_stat_hist97[ i ], 2 ) ) + ( pow( ratio_error_sys_hist97[ i ], 2 ) ) ); + + ratio_hist98[ i ] = ( mean_hist98[i] - energy[i] ) / energy[i]; + ratio_error_stat_hist98[ i ] = sqrt( pow( (meanerror_hist98[i]) / (energy[i]), 2 ) + pow( (mean_hist98[i] * energyerror[i]) / (energy[i] * energy[i]), 2 ) ); + ratio_error_sys_hist98[ i ] = 0.0; + ratio_error_hist98[ i ] = sqrt( ( pow( ratio_error_stat_hist98[ i ], 2 ) ) + ( pow( ratio_error_sys_hist98[ i ], 2 ) ) ); + + ratio_hist99[ i ] = ( mean_hist99[i] - energy[i] ) / energy[i]; + ratio_error_stat_hist99[ i ] = sqrt( pow( (meanerror_hist99[i]) / (energy[i]), 2 ) + pow( (mean_hist99[i] * energyerror[i]) / (energy[i] * energy[i]), 2 ) ); + ratio_error_sys_hist99[ i ] = 0.0; + ratio_error_hist99[ i ] = sqrt( ( pow( ratio_error_stat_hist99[ i ], 2 ) ) + ( pow( ratio_error_sys_hist99[ i ], 2 ) ) ); + + ratio[ i ] = ( mean_mean[i] - energy[i] ) / energy[i]; + ratio_error_stat[ i ] = sqrt( pow( (mean_meanerror[i]) / (energy[i]), 2 ) + pow( (mean_mean[i] * energyerror[i]) / (energy[i] * energy[i]), 2 ) ); + ratio_error_sys[ i ] = 0.0; + ratio_error[ i ] = sqrt( ( pow( ratio_error_stat[ i ], 2 ) ) + ( pow( ratio_error_sys[ i ], 2 ) ) ); + + resolution_hist[ i ] = rms[i] / mean[i]; + resolution_error_stat_hist[ i ] = sqrt( pow( (rmserror[i]) / (mean[i]), 2 ) + pow( (rms[i] * meanerror[i]) / (mean[i] * mean[i]), 2 ) ); + resolution_error_sys_hist[ i ] = 0.0; + resolution_error_hist[ i ] = sqrt( ( pow( resolution_error_stat_hist[ i ], 2 ) ) + ( pow( resolution_error_sys_hist[ i ], 2 ) ) ); + + resolution_hist90[ i ] = rms_hist90[i] / mean_hist90[i]; + resolution_error_stat_hist90[ i ] = sqrt( pow( (rmserror_hist90[i]) / (mean_hist90[i]), 2 ) + pow( (rms_hist90[i] * meanerror_hist90[i]) / (mean_hist90[i] * mean_hist90[i]), 2 ) ); + resolution_error_sys_hist90[ i ] = 0.0; + resolution_error_hist90[ i ] = sqrt( ( pow( resolution_error_stat_hist90[ i ], 2 ) ) + ( pow( resolution_error_sys_hist90[ i ], 2 ) ) ); + + resolution_hist95[ i ] = rms_hist95[i] / mean_hist95[i]; + resolution_error_stat_hist95[ i ] = sqrt( pow( (rmserror_hist95[i]) / (mean_hist95[i]), 2 ) + pow( (rms_hist95[i] * meanerror_hist95[i]) / (mean_hist95[i] * mean_hist95[i]), 2 ) ); + resolution_error_sys_hist95[ i ] = 0.0; + resolution_error_hist95[ i ] = sqrt( ( pow( resolution_error_stat_hist95[ i ], 2 ) ) + ( pow( resolution_error_sys_hist95[ i ], 2 ) ) ); + + resolution_hist96[ i ] = rms_hist96[i] / mean_hist96[i]; + resolution_error_stat_hist96[ i ] = sqrt( pow( (rmserror_hist96[i]) / (mean_hist96[i]), 2 ) + pow( (rms_hist96[i] * meanerror_hist96[i]) / (mean_hist96[i] * mean_hist96[i]), 2 ) ); + resolution_error_sys_hist96[ i ] = 0.0; + resolution_error_hist96[ i ] = sqrt( ( pow( resolution_error_stat_hist96[ i ], 2 ) ) + ( pow( resolution_error_sys_hist96[ i ], 2 ) ) ); + + resolution_hist97[ i ] = rms_hist97[i] / mean_hist97[i]; + resolution_error_stat_hist97[ i ] = sqrt( pow( (rmserror_hist97[i]) / (mean_hist97[i]), 2 ) + pow( (rms_hist97[i] * meanerror_hist97[i]) / (mean_hist97[i] * mean_hist97[i]), 2 ) ); + resolution_error_sys_hist97[ i ] = 0.0; + resolution_error_hist97[ i ] = sqrt( ( pow( resolution_error_stat_hist97[ i ], 2 ) ) + ( pow( resolution_error_sys_hist97[ i ], 2 ) ) ); + + resolution_hist98[ i ] = rms_hist98[i] / mean_hist98[i]; + resolution_error_stat_hist98[ i ] = sqrt( pow( (rmserror_hist98[i]) / (mean_hist98[i]), 2 ) + pow( (rms_hist98[i] * meanerror_hist98[i]) / (mean_hist98[i] * mean_hist98[i]), 2 ) ); + resolution_error_sys_hist98[ i ] = 0.0; + resolution_error_hist98[ i ] = sqrt( ( pow( resolution_error_stat_hist98[ i ], 2 ) ) + ( pow( resolution_error_sys_hist98[ i ], 2 ) ) ); + + resolution_hist99[ i ] = rms_hist99[i] / mean_hist99[i]; + resolution_error_stat_hist99[ i ] = sqrt( pow( (rmserror_hist99[i]) / (mean_hist99[i]), 2 ) + pow( (rms_hist99[i] * meanerror_hist99[i]) / (mean_hist99[i] * mean_hist99[i]), 2 ) ); + resolution_error_sys_hist99[ i ] = 0.0; + resolution_error_hist99[ i ] = sqrt( ( pow( resolution_error_stat_hist99[ i ], 2 ) ) + ( pow( resolution_error_sys_hist99[ i ], 2 ) ) ); - value3[ i ] = sigma3[i] / mean3[i]; - error3[ i ] = sqrt( pow( (sigmaerror3[i])/(mean3[i]) ,2 ) + pow( (sigma3[i] * meanerror3[i])/(mean3[i] * mean3[i]) ,2 ) ); + resolution[ i ] = mean_sigma[i] / mean_mean[i]; + resolution_error_stat[ i ] = sqrt( pow( (mean_sigmaerror[i]) / (mean_mean[i]), 2 ) + pow( (mean_sigma[i] * mean_meanerror[i]) / (mean_mean[i] * mean_mean[i]), 2 ) ); + resolution_error_sys[ i ] = 0.0; + resolution_error[ i ] = sqrt( ( pow( resolution_error_stat[ i ], 2 ) ) + ( pow( resolution_error_sys[ i ], 2 ) ) ); + } + +/* printf( "\n" ); + for (int i = 0; i < n; i++) { + + printf( " mean_hist90 === %f \n", mean_hist90[i] ); + printf( " rms_hist90 === %f \n", rms_hist90[i] ); + printf( " mean_hist95 === %f \n", mean_hist95[i] ); + printf( " rms_hist95 === %f \n", rms_hist95[i] ); + + printf( " mean90 === %f \n", mean90[i] ); + printf( " rms90 === %f \n", rms90[i] ); + printf( " mean95 === %f \n", mean95[i] ); + printf( " rms95 === %f \n", rms95[i] ); + + printf( "\n" ); + + printf( " ratio_hist90 === %f \n", ratio_hist90[i] ); + printf( " ratio_error_hist90 === %f \n", ratio_error_hist90[i] ); + printf( " resolution_hist90 === %f \n", resolution_hist90[i] ); + printf( " resolution_error_hist90 === %f \n", resolution_error_hist90[i] ); + printf( " ratio_hist95 === %f \n", ratio_hist95[i] ); + printf( " ratio_error_hist95 === %f \n", ratio_error_hist95[i] ); + printf( " resolution_hist95 === %f \n", resolution_hist95[i] ); + printf( " resolution_error_hist95 === %f \n", resolution_error_hist95[i] ); + + printf( " ratio90 === %f \n", ratio90[i] ); + printf( " ratio_error90 === %f \n", ratio_error90[i] ); + printf( " resolution90 === %f \n", resolution90[i] ); + printf( " resolution_error90 === %f \n", resolution_error90[i] ); + printf( " ratio95 === %f \n", ratio95[i] ); + printf( " ratio_error95 === %f \n", ratio_error95[i] ); + printf( " resolution95 === %f \n", resolution95[i] ); + printf( " resolution_error95 === %f \n", resolution_error95[i] ); + printf( "\n" ); + printf( "\n" ); + printf( "\n" ); + } +*/ printf( "\n" ); for (int i = 0; i < n; i++) { printf( " %f ", energy[i] ); printf( " %f ", energyerror[i] ); + printf( " %f ", mean[i] ); printf( " %f ", meanerror[i] ); - printf( " %f ", sigma[i] ); - printf( " %f ", sigmaerror[i] ); - printf( " %f ", value[i] ); - printf( " %f ", error[i] ); + printf( " %f ", rms[i] ); + printf( " %f ", rmserror[i] ); + + printf( " %f ", mean_hist90[i] ); + printf( " %f ", meanerror_hist90[i] ); + printf( " %f ", rms_hist90[i] ); + printf( " %f ", rmserror_hist90[i] ); + + printf( " %f ", mean_hist95[i] ); + printf( " %f ", meanerror_hist95[i] ); + printf( " %f ", rms_hist95[i] ); + printf( " %f ", rmserror_hist95[i] ); + + printf( " %f ", mean_hist96[i] ); + printf( " %f ", meanerror_hist96[i] ); + printf( " %f ", rms_hist96[i] ); + printf( " %f ", rmserror_hist96[i] ); + + printf( " %f ", mean_hist97[i] ); + printf( " %f ", meanerror_hist97[i] ); + printf( " %f ", rms_hist97[i] ); + printf( " %f ", rmserror_hist97[i] ); + + printf( " %f ", mean_hist98[i] ); + printf( " %f ", meanerror_hist98[i] ); + printf( " %f ", rms_hist98[i] ); + printf( " %f ", rmserror_hist98[i] ); + + printf( " %f ", mean_hist99[i] ); + printf( " %f ", meanerror_hist99[i] ); + printf( " %f ", rms_hist99[i] ); + printf( " %f ", rmserror_hist99[i] ); + + printf( " %f ", ratio_hist[i] ); + printf( " %f ", ratio_error_hist[i] ); + printf( " %f ", resolution_hist[i] ); + printf( " %f ", resolution_error_hist[i] ); + + printf( " %f ", ratio_hist90[i] ); + printf( " %f ", ratio_error_hist90[i] ); + printf( " %f ", resolution_hist90[i] ); + printf( " %f ", resolution_error_hist90[i] ); + + printf( " %f ", ratio_hist95[i] ); + printf( " %f ", ratio_error_hist95[i] ); + printf( " %f ", resolution_hist95[i] ); + printf( " %f ", resolution_error_hist95[i] ); + + printf( " %f ", ratio_hist96[i] ); + printf( " %f ", ratio_error_hist96[i] ); + printf( " %f ", resolution_hist96[i] ); + printf( " %f ", resolution_error_hist96[i] ); + + printf( " %f ", ratio_hist97[i] ); + printf( " %f ", ratio_error_hist97[i] ); + printf( " %f ", resolution_hist97[i] ); + printf( " %f ", resolution_error_hist97[i] ); + + printf( " %f ", ratio_hist98[i] ); + printf( " %f ", ratio_error_hist98[i] ); + printf( " %f ", resolution_hist98[i] ); + printf( " %f ", resolution_error_hist98[i] ); + + printf( " %f ", ratio_hist99[i] ); + printf( " %f ", ratio_error_hist99[i] ); + printf( " %f ", resolution_hist99[i] ); + printf( " %f ", resolution_error_hist99[i] ); + + printf( " %f ", mean_mean[i] ); + printf( " %f ", rms_mean[i] ); + printf( " %f ", mean_meanerror[i] ); + printf( " %f ", rms_meanerror[i] ); + printf( " %f ", mean_sigma[i] ); + printf( " %f ", rms_sigma[i] ); + printf( " %f ", mean_sigmaerror[i] ); + printf( " %f ", rms_sigmaerror[i] ); + printf( " %f ", linearity_error[i] ); + printf( " %f ", absolute_error[i] ); + printf( " %f ", ratio[i] ); + printf( " %f ", ratio_error[i] ); + printf( " %f ", resolution[i] ); + printf( " %f ", resolution_error[i] ); + printf( "\n" ); - } - - printf( "\n" ); - for (int i = 0; i < n; i++) { - printf( " %f ", energy2[i] ); - printf( " %f ", energyerror2[i] ); - printf( " %f ", mean2[i] ); - printf( " %f ", meanerror2[i] ); - printf( " %f ", sigma2[i] ); - printf( " %f ", sigmaerror2[i] ); - printf( " %f ", value2[i] ); - printf( " %f ", error2[i] ); printf( "\n" ); - } - - printf( "\n" ); - for (int i = 0; i < n; i++) { - printf( " %f ", energy3[i] ); - printf( " %f ", energyerror3[i] ); - printf( " %f ", mean3[i] ); - printf( " %f ", meanerror3[i] ); - printf( " %f ", sigma3[i] ); - printf( " %f ", sigmaerror3[i] ); - printf( " %f ", value3[i] ); - printf( " %f ", error3[i] ); printf( "\n" ); } - printf( "Here is difference:\n" ); - - Float_t v1 = 0; - Float_t v2 = 0; - Float_t v3 = 0; - - for ( int i = 0; i < n; i++ ) { - printf( " %f, %f, %f, %f \n", energy[i], value[i], value2[i], value3[i] ); - printf( " Difference between nodigi and digi20: %f \n", value2[i] - value[i] ); - v1 = v1 + ( value2[i] - value[i] ); - printf( " Difference between digi20 and digi60: %f \n", value3[i] - value2[i] ); - v2 = v2 + ( value3[i] - value2[i] ); - printf( " Difference between nodigi and digi60: %f \n", value3[i] - value[i] ); - v3 = v3 + ( value3[i] - value[i] ); - } - - printf( "Average values: %f, %f, %f \n", v1/n, v2/n, v3/n ); - TGraphErrors *agr; TGraphErrors *bgr; + TGraphErrors *cgr; + TGraphErrors *dgr; + + TGraphErrors *egr; + TGraphErrors *fgr; + + TGraphErrors *ggr; + TGraphErrors *hgr; + + TGraphErrors *igr; + TGraphErrors *jgr; + + TGraphErrors *kgr; + TGraphErrors *lgr; + + TGraphErrors *mgr; + TGraphErrors *ngr; + + TGraphErrors *ogr; + TGraphErrors *pgr; char fname[ 100 ]; for ( int i = 0; i < 100; i++ ) fname[ i ] = 0; - if ( count == 1 ) { - //agr = new TGraphErrors( n, energy, sigma, energyerror, sigmaerror ); - agr = new TGraphErrors( n, energy, value, energyerror, error ); - - //bgr = new TGraphErrors( n, energy2, sigma2, energyerror2, sigmaerror2 ); - bgr = new TGraphErrors( n, energy2, value2, energyerror2, error2 ); - - //cgr = new TGraphErrors( n, energy3, sigma3, energyerror3, sigmaerror3 ); - cgr = new TGraphErrors( n, energy3, value3, energyerror3, error3 ); - - sprintf( fname, "" ); // Relative energy resolution - agr->GetYaxis()->SetTitle("Sigma / Mean"); - agr->GetXaxis()->SetTitle("Energy, GeV"); - bgr->GetYaxis()->SetTitle("Sigma / Mean"); - bgr->GetXaxis()->SetTitle("Energy, GeV"); - cgr->GetYaxis()->SetTitle("Sigma / Mean"); - cgr->GetXaxis()->SetTitle("Energy, GeV"); - - agr->GetYaxis()->SetRangeUser(0.0,0.25); - - } - else { - agr = new TGraphErrors( n, energy, sigma, energyerror, sigmaerror ); - //agr = new TGraphErrors( n, energy, value, energyerror, error ); - - bgr = new TGraphErrors( n, energy2, sigma2, energyerror2, sigmaerror2 ); - //bgr = new TGraphErrors( n, energy2, value2, energyerror2, error2 ); + c1->cd(); + agr = new TGraphErrors( n, energy, ratio, energyerror, ratio_error_sys ); + //agr = new TGraphErrors( n, energy, ratio80, energyerror, ratio_error_sys80 ); + //agr = new TGraphErrors( n, energy, ratio90, energyerror, ratio_error_sys90 ); + //agr = new TGraphErrors( n, energy, ratio, energyerror, ratio_error_sys ); + //agr = new TGraphErrors( n, energy, ratio90, energyerror, ratio_error_sys90 ); + //agr = new TGraphErrors( n, energy, ratio2, energyerror, ratio_error_sys2 ); + //agr = new TGraphErrors( n, energy, ratio, energyerror, ratio_error_sys ); + agr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy, ratio, energyerror, ratio_error_stat ); + //bgr = new TGraphErrors( n, energy, ratio80, energyerror, ratio_error_stat80 ); + //bgr = new TGraphErrors( n, energy, ratio90, energyerror, ratio_error_stat90 ); + //bgr = new TGraphErrors( n, energy, ratio, energyerror, ratio_error_stat ); + //bgr = new TGraphErrors( n, energy, ratio90, energyerror, ratio_error_stat90 ); + //bgr = new TGraphErrors( n, energy, ratio2, energyerror, ratio_error_stat2 ); + //bgr = new TGraphErrors( n, energy, ratio, energyerror, ratio_error_stat ); + bgr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + cgr = new TGraphErrors( n, energy, ratio_hist90, energyerror, ratio_error_sys_hist90 ); + //cgr = new TGraphErrors( n, energy, ratio85, energyerror, ratio_error_sys85 ); + //cgr = new TGraphErrors( n, energy, ratio95, energyerror, ratio_error_sys95 ); + //cgr = new TGraphErrors( n, energy, ratio2, energyerror, ratio_error_sys2 ); + //cgr = new TGraphErrors( n, energy, ratio100, energyerror, ratio_error_sys100 ); + //cgr = new TGraphErrors( n, energy, ratio_hist, energyerror, ratio_error_sys_hist ); + //cgr = new TGraphErrors( n, energy, ratio2, energyerror, ratio_error_sys2 ); + cgr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + cgr->GetXaxis()->SetTitle("E_{true}, GeV"); + dgr = new TGraphErrors( n, energy, ratio_hist90, energyerror, ratio_error_stat_hist90 ); + //dgr = new TGraphErrors( n, energy, ratio85, energyerror, ratio_error_stat85 ); + //dgr = new TGraphErrors( n, energy, ratio95, energyerror, ratio_error_stat95 ); + //dgr = new TGraphErrors( n, energy, ratio2, energyerror, ratio_error_stat2 ); + //dgr = new TGraphErrors( n, energy, ratio100, energyerror, ratio_error_stat100 ); + //dgr = new TGraphErrors( n, energy, ratio_hist, energyerror, ratio_error_stat_hist ); + //dgr = new TGraphErrors( n, energy, ratio2, energyerror, ratio_error_stat2 ); + dgr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + dgr->GetXaxis()->SetTitle("E_{true}, GeV"); + egr = new TGraphErrors( n, energy, ratio_hist95, energyerror, ratio_error_sys_hist95 ); + //egr = new TGraphErrors( n, energy, ratio90, energyerror, ratio_error_sys90 ); + //egr = new TGraphErrors( n, energy, ratio100, energyerror, ratio_error_sys100 ); + //egr = new TGraphErrors( n, energy, ratio90, energyerror, ratio_error_sys90 ); + //egr = new TGraphErrors( n, energy, ratio_hist, energyerror, ratio_error_sys_hist ); + //egr = new TGraphErrors( n, energy, ratio90, energyerror, ratio_error_sys90 ); + //egr = new TGraphErrors( n, energy, ratio_hist, energyerror, ratio_error_sys_hist ); + egr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + egr->GetXaxis()->SetTitle("E_{true}, GeV"); + fgr = new TGraphErrors( n, energy, ratio_hist95, energyerror, ratio_error_stat_hist95 ); + //fgr = new TGraphErrors( n, energy, ratio90, energyerror, ratio_error_stat90 ); + //fgr = new TGraphErrors( n, energy, ratio100, energyerror, ratio_error_stat100 ); + //fgr = new TGraphErrors( n, energy, ratio90, energyerror, ratio_error_stat90 ); + //fgr = new TGraphErrors( n, energy, ratio_hist, energyerror, ratio_error_stat_hist ); + //fgr = new TGraphErrors( n, energy, ratio90, energyerror, ratio_error_stat90 ); + //fgr = new TGraphErrors( n, energy, ratio_hist, energyerror, ratio_error_stat_hist ); + fgr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + fgr->GetXaxis()->SetTitle("E_{true}, GeV"); + ggr = new TGraphErrors( n, energy, ratio_hist, energyerror, ratio_error_sys_hist ); + ggr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + ggr->GetXaxis()->SetTitle("E_{true}, GeV"); + hgr = new TGraphErrors( n, energy, ratio_hist, energyerror, ratio_error_stat_hist ); + hgr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + hgr->GetXaxis()->SetTitle("E_{true}, GeV"); + igr = new TGraphErrors( n, energy, ratio_hist96, energyerror, ratio_error_sys_hist96 ); + igr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + igr->GetXaxis()->SetTitle("E_{true}, GeV"); + jgr = new TGraphErrors( n, energy, ratio_hist96, energyerror, ratio_error_stat_hist96 ); + jgr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + jgr->GetXaxis()->SetTitle("E_{true}, GeV"); + kgr = new TGraphErrors( n, energy, ratio_hist97, energyerror, ratio_error_sys_hist97 ); + kgr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + kgr->GetXaxis()->SetTitle("E_{true}, GeV"); + lgr = new TGraphErrors( n, energy, ratio_hist97, energyerror, ratio_error_stat_hist97 ); + lgr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + lgr->GetXaxis()->SetTitle("E_{true}, GeV"); + mgr = new TGraphErrors( n, energy, ratio_hist98, energyerror, ratio_error_sys_hist98 ); + mgr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + mgr->GetXaxis()->SetTitle("E_{true}, GeV"); + ngr = new TGraphErrors( n, energy, ratio_hist98, energyerror, ratio_error_stat_hist98 ); + ngr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + ngr->GetXaxis()->SetTitle("E_{true}, GeV"); + ogr = new TGraphErrors( n, energy, ratio_hist99, energyerror, ratio_error_sys_hist99 ); + ogr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + ogr->GetXaxis()->SetTitle("E_{true}, GeV"); + pgr = new TGraphErrors( n, energy, ratio_hist99, energyerror, ratio_error_stat_hist99 ); + pgr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + pgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Linearity" ); + agr->GetYaxis()->SetRangeUser(-0.2, 0.2); + agr->SetTitle(fname); - cgr = new TGraphErrors( n, energy3, sigma3, energyerror3, sigmaerror3 ); - //cgr = new TGraphErrors( n, energy3, value3, energyerror3, error3 ); + agr->SetFillColor(kCyan); + agr->SetFillStyle(3001); + agr->SetMarkerColor(kCyan); + agr->SetLineColor(kCyan); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); + agr->Draw("A 3"); + bgr->SetMarkerColor(kBlue); + bgr->SetLineColor(kBlue); + bgr->SetLineWidth(3); + bgr->SetFillColor(kCyan); + bgr->SetMarkerStyle(20); + bgr->Draw("P SAME"); + cgr->SetMarkerColor(kYellow-6); + cgr->SetFillStyle(3001); + cgr->SetLineColor(kYellow-6); + cgr->SetLineWidth(3); + cgr->SetFillColor(kYellow-6); + cgr->SetMarkerStyle(20); + cgr->Draw("3 SAME"); + dgr->SetMarkerColor(kRed); + dgr->SetLineColor(kRed); + dgr->SetLineWidth(3); + dgr->SetFillColor(kYellow-6); + dgr->SetMarkerStyle(20); + dgr->Draw("P SAME"); + egr->SetMarkerColor(kViolet-6); + egr->SetFillStyle(3001); + egr->SetLineColor(kViolet-6); + egr->SetLineWidth(3); + egr->SetFillColor(kViolet-6); + egr->SetMarkerStyle(20); + egr->Draw("3 SAME"); + fgr->SetMarkerColor(kGreen+1); + fgr->SetLineColor(kGreen+1); + fgr->SetLineWidth(3); + fgr->SetFillColor(kViolet-6); + fgr->SetMarkerStyle(20); + fgr->Draw("P SAME"); + ggr->SetMarkerColor(kMagenta-10); + ggr->SetFillStyle(3001); + ggr->SetLineColor(kMagenta-10); + ggr->SetLineWidth(3); + ggr->SetFillColor(kMagenta-10); + ggr->SetMarkerStyle(20); + ggr->Draw("3 SAME"); + hgr->SetMarkerColor(kMagenta+1); + hgr->SetLineColor(kMagenta+1); + hgr->SetLineWidth(3); + hgr->SetFillColor(kMagenta-10); + hgr->SetMarkerStyle(20); + hgr->Draw("P SAME"); + igr->SetMarkerColor(kMagenta-10); + igr->SetFillStyle(3001); + igr->SetLineColor(kMagenta-10); + igr->SetLineWidth(3); + igr->SetFillColor(kMagenta-10); + igr->SetMarkerStyle(20); + igr->Draw("3 SAME"); + jgr->SetMarkerColor(kCyan+1); + jgr->SetLineColor(kCyan+1); + jgr->SetLineWidth(3); + jgr->SetFillColor(kMagenta-10); + jgr->SetMarkerStyle(20); + jgr->Draw("P SAME"); + kgr->SetMarkerColor(kMagenta-10); + kgr->SetFillStyle(3001); + kgr->SetLineColor(kMagenta-10); + kgr->SetLineWidth(3); + kgr->SetFillColor(kMagenta-10); + kgr->SetMarkerStyle(20); + kgr->Draw("3 SAME"); + lgr->SetMarkerColor(kCyan+2); + lgr->SetLineColor(kCyan+2); + lgr->SetLineWidth(3); + lgr->SetFillColor(kMagenta-10); + lgr->SetMarkerStyle(20); + lgr->Draw("P SAME"); + mgr->SetMarkerColor(kMagenta-10); + mgr->SetFillStyle(3001); + mgr->SetLineColor(kMagenta-10); + mgr->SetLineWidth(3); + mgr->SetFillColor(kMagenta-10); + mgr->SetMarkerStyle(20); + mgr->Draw("3 SAME"); + ngr->SetMarkerColor(kCyan+3); + ngr->SetLineColor(kCyan+3); + ngr->SetLineWidth(3); + ngr->SetFillColor(kMagenta-10); + ngr->SetMarkerStyle(20); + ngr->Draw("P SAME"); + ogr->SetMarkerColor(kMagenta-10); + ogr->SetFillStyle(3001); + ogr->SetLineColor(kMagenta-10); + ogr->SetLineWidth(3); + ogr->SetFillColor(kMagenta-10); + ogr->SetMarkerStyle(20); + ogr->Draw("3 SAME"); + pgr->SetMarkerColor(kCyan-8); + pgr->SetLineColor(kCyan-8); + pgr->SetLineWidth(3); + pgr->SetFillColor(kMagenta-10); + pgr->SetMarkerStyle(20); + pgr->Draw("P SAME"); + c1->Update(); - sprintf( fname, "" ); // Absolute energy resolution - agr->GetYaxis()->SetTitle("Sigma, GeV"); - agr->GetXaxis()->SetTitle("Energy, GeV"); - bgr->GetYaxis()->SetTitle("Sigma, GeV"); - bgr->GetXaxis()->SetTitle("Energy, GeV"); - cgr->GetYaxis()->SetTitle("Sigma, GeV"); - cgr->GetXaxis()->SetTitle("Energy, GeV"); + c2->cd(); + agr = new TGraphErrors( n, energy, mean_sigma, energyerror, energyerror ); + //agr = new TGraphErrors( n, energy, rms80, energyerror, energyerror ); + //agr = new TGraphErrors( n, energy, rms90, energyerror, energyerror ); + //agr = new TGraphErrors( n, energy, mean_sigma, energyerror, rms_sigma ); + //agr = new TGraphErrors( n, energy, rms90, energyerror, energyerror ); + //agr = new TGraphErrors( n, energy, mean_sigma2, energyerror, rms_sigma2 ); + //agr = new TGraphErrors( n, energy, mean_sigma, energyerror, rms_sigma ); + //agr->GetYaxis()->SetTitle("#sigma_{reco}, GeV"); + //agr->GetXaxis()->SetTitle("E_{true}, GeV"); + agr->GetYaxis()->SetTitle("#DeltaE_{reco}, GeV"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy, mean_sigma, energyerror, mean_sigmaerror ); + //bgr = new TGraphErrors( n, energy, rms80, energyerror, energyerror ); + //bgr = new TGraphErrors( n, energy, rms90, energyerror, energyerror ); + //bgr = new TGraphErrors( n, energy, mean_sigma, energyerror, mean_sigmaerror ); + //bgr = new TGraphErrors( n, energy, rms90, energyerror, energyerror ); + //bgr = new TGraphErrors( n, energy, mean_sigma2, energyerror, mean_sigmaerror2 ); + //bgr = new TGraphErrors( n, energy, mean_sigma, energyerror, mean_sigmaerror ); + bgr->GetYaxis()->SetTitle("#DeltaE_{reco}, GeV"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + cgr = new TGraphErrors( n, energy, rms_hist90, energyerror, energyerror ); + //cgr = new TGraphErrors( n, energy, rms85, energyerror, energyerror ); + //cgr = new TGraphErrors( n, energy, rms95, energyerror, energyerror ); + //cgr = new TGraphErrors( n, energy, mean_sigma2, energyerror, rms_sigma2 ); + //cgr = new TGraphErrors( n, energy, rms100, energyerror, energyerror ); + //cgr = new TGraphErrors( n, energy, rms, energyerror, energyerror );// energyerror == 0 + //cgr = new TGraphErrors( n, energy, mean_sigma2, energyerror, rms_sigma2 ); + cgr->GetYaxis()->SetTitle("#DeltaE_{reco}, GeV"); + cgr->GetXaxis()->SetTitle("E_{true}, GeV"); + dgr = new TGraphErrors( n, energy, rms_hist90, energyerror, rmserror_hist90 ); + //dgr = new TGraphErrors( n, energy, rms85, energyerror, energyerror ); + //dgr = new TGraphErrors( n, energy, rms95, energyerror, energyerror ); + //dgr = new TGraphErrors( n, energy, mean_sigma2, energyerror, mean_sigmaerror2 ); + //dgr = new TGraphErrors( n, energy, rms100, energyerror, energyerror ); + //dgr = new TGraphErrors( n, energy, rms, energyerror, rmserror ); + //dgr = new TGraphErrors( n, energy, mean_sigma2, energyerror, mean_sigmaerror2 ); + dgr->GetYaxis()->SetTitle("#DeltaE_{reco}, GeV"); + dgr->GetXaxis()->SetTitle("E_{true}, GeV"); + egr = new TGraphErrors( n, energy, rms_hist95, energyerror, energyerror ); + //egr = new TGraphErrors( n, energy, rms90, energyerror, energyerror ); + //egr = new TGraphErrors( n, energy, rms100, energyerror, energyerror ); + //egr = new TGraphErrors( n, energy, rms90, energyerror, energyerror ); + //egr = new TGraphErrors( n, energy, rms, energyerror, energyerror ); + //egr = new TGraphErrors( n, energy, rms90, energyerror, energyerror ); + //egr = new TGraphErrors( n, energy, rms, energyerror, energyerror ); + egr->GetYaxis()->SetTitle("#DeltaE_{reco}, GeV"); + egr->GetXaxis()->SetTitle("E_{true}, GeV"); + fgr = new TGraphErrors( n, energy, rms_hist95, energyerror, rmserror_hist95 ); + //fgr = new TGraphErrors( n, energy, rms90, energyerror, energyerror ); + //fgr = new TGraphErrors( n, energy, rms100, energyerror, energyerror ); + //fgr = new TGraphErrors( n, energy, rms90, energyerror, energyerror ); + //fgr = new TGraphErrors( n, energy, rms, energyerror, rmserror ); + //fgr = new TGraphErrors( n, energy, rms90, energyerror, energyerror ); + //fgr = new TGraphErrors( n, energy, rms, energyerror, rmserror ); + fgr->GetYaxis()->SetTitle("#DeltaE_{reco}, GeV"); + fgr->GetXaxis()->SetTitle("E_{true}, GeV"); + ggr = new TGraphErrors( n, energy, rms, energyerror, energyerror ); + ggr->GetYaxis()->SetTitle("#DeltaE_{reco}, GeV"); + ggr->GetXaxis()->SetTitle("E_{true}, GeV"); + hgr = new TGraphErrors( n, energy, rms, energyerror, rmserror ); + hgr->GetYaxis()->SetTitle("#DeltaE_{reco}, GeV"); + hgr->GetXaxis()->SetTitle("E_{true}, GeV"); + igr = new TGraphErrors( n, energy, rms_hist96, energyerror, energyerror ); + igr->GetYaxis()->SetTitle("#DeltaE_{reco}, GeV"); + igr->GetXaxis()->SetTitle("E_{true}, GeV"); + jgr = new TGraphErrors( n, energy, rms_hist96, energyerror, rmserror_hist96 ); + jgr->GetYaxis()->SetTitle("#DeltaE_{reco}, GeV"); + jgr->GetXaxis()->SetTitle("E_{true}, GeV"); + kgr = new TGraphErrors( n, energy, rms_hist97, energyerror, energyerror ); + kgr->GetYaxis()->SetTitle("#DeltaE_{reco}, GeV"); + kgr->GetXaxis()->SetTitle("E_{true}, GeV"); + lgr = new TGraphErrors( n, energy, rms_hist97, energyerror, rmserror_hist97 ); + lgr->GetYaxis()->SetTitle("#DeltaE_{reco}, GeV"); + lgr->GetXaxis()->SetTitle("E_{true}, GeV"); + mgr = new TGraphErrors( n, energy, rms_hist98, energyerror, energyerror ); + mgr->GetYaxis()->SetTitle("#DeltaE_{reco}, GeV"); + mgr->GetXaxis()->SetTitle("E_{true}, GeV"); + ngr = new TGraphErrors( n, energy, rms_hist98, energyerror, rmserror_hist98 ); + ngr->GetYaxis()->SetTitle("#DeltaE_{reco}, GeV"); + ngr->GetXaxis()->SetTitle("E_{true}, GeV"); + ogr = new TGraphErrors( n, energy, rms_hist99, energyerror, energyerror ); + ogr->GetYaxis()->SetTitle("#DeltaE_{reco}, GeV"); + ogr->GetXaxis()->SetTitle("E_{true}, GeV"); + pgr = new TGraphErrors( n, energy, rms_hist99, energyerror, rmserror_hist99 ); + pgr->GetYaxis()->SetTitle("#DeltaE_{reco}, GeV"); + pgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Absolute energy resolution" ); + agr->GetYaxis()->SetRangeUser(0.0, 9.0); + agr->SetTitle(fname); - agr->GetYaxis()->SetRangeUser(0.0,8.0); - - } + agr->SetFillColor(kCyan); + agr->SetFillStyle(3001); + agr->SetMarkerColor(kCyan); + agr->SetLineColor(kCyan); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); + agr->Draw("A 3"); + bgr->SetMarkerColor(kBlue); + bgr->SetLineColor(kBlue); + bgr->SetLineWidth(3); + bgr->SetFillColor(kCyan); + bgr->SetMarkerStyle(20); + bgr->Draw("P SAME"); + cgr->SetMarkerColor(kYellow-6); + cgr->SetFillStyle(3001); + cgr->SetLineColor(kYellow-6); + cgr->SetLineWidth(3); + cgr->SetFillColor(kYellow-6); + cgr->SetMarkerStyle(20); + cgr->Draw("3 SAME"); + dgr->SetMarkerColor(kRed); + dgr->SetLineColor(kRed); + dgr->SetLineWidth(3); + dgr->SetFillColor(kYellow-6); + dgr->SetMarkerStyle(20); + dgr->Draw("P SAME"); + egr->SetMarkerColor(kViolet-6); + egr->SetFillStyle(3001); + egr->SetLineColor(kViolet-6); + egr->SetLineWidth(3); + egr->SetFillColor(kViolet-6); + egr->SetMarkerStyle(20); + egr->Draw("3 SAME"); + fgr->SetMarkerColor(kGreen+1); + fgr->SetLineColor(kGreen+1); + fgr->SetLineWidth(3); + fgr->SetFillColor(kViolet-6); + fgr->SetMarkerStyle(20); + fgr->Draw("P SAME"); + ggr->SetMarkerColor(kMagenta-10); + ggr->SetFillStyle(3001); + ggr->SetLineColor(kMagenta-10); + ggr->SetLineWidth(3); + ggr->SetFillColor(kMagenta-10); + ggr->SetMarkerStyle(20); + ggr->Draw("3 SAME"); + hgr->SetMarkerColor(kMagenta+1); + hgr->SetLineColor(kMagenta+1); + hgr->SetLineWidth(3); + hgr->SetFillColor(kMagenta-10); + hgr->SetMarkerStyle(20); + hgr->Draw("P SAME"); + igr->SetMarkerColor(kMagenta-10); + igr->SetFillStyle(3001); + igr->SetLineColor(kMagenta-10); + igr->SetLineWidth(3); + igr->SetFillColor(kMagenta-10); + igr->SetMarkerStyle(20); + igr->Draw("3 SAME"); + jgr->SetMarkerColor(kCyan+1); + jgr->SetLineColor(kCyan+1); + jgr->SetLineWidth(3); + jgr->SetFillColor(kMagenta-10); + jgr->SetMarkerStyle(20); + jgr->Draw("P SAME"); + kgr->SetMarkerColor(kMagenta-10); + kgr->SetFillStyle(3001); + kgr->SetLineColor(kMagenta-10); + kgr->SetLineWidth(3); + kgr->SetFillColor(kMagenta-10); + kgr->SetMarkerStyle(20); + kgr->Draw("3 SAME"); + lgr->SetMarkerColor(kCyan+2); + lgr->SetLineColor(kCyan+2); + lgr->SetLineWidth(3); + lgr->SetFillColor(kMagenta-10); + lgr->SetMarkerStyle(20); + lgr->Draw("P SAME"); + mgr->SetMarkerColor(kMagenta-10); + mgr->SetFillStyle(3001); + mgr->SetLineColor(kMagenta-10); + mgr->SetLineWidth(3); + mgr->SetFillColor(kMagenta-10); + mgr->SetMarkerStyle(20); + mgr->Draw("3 SAME"); + ngr->SetMarkerColor(kCyan+3); + ngr->SetLineColor(kCyan+3); + ngr->SetLineWidth(3); + ngr->SetFillColor(kMagenta-10); + ngr->SetMarkerStyle(20); + ngr->Draw("P SAME"); + ogr->SetMarkerColor(kMagenta-10); + ogr->SetFillStyle(3001); + ogr->SetLineColor(kMagenta-10); + ogr->SetLineWidth(3); + ogr->SetFillColor(kMagenta-10); + ogr->SetMarkerStyle(20); + ogr->Draw("3 SAME"); + pgr->SetMarkerColor(kCyan-8); + pgr->SetLineColor(kCyan-8); + pgr->SetLineWidth(3); + pgr->SetFillColor(kMagenta-10); + pgr->SetMarkerStyle(20); + pgr->Draw("P SAME"); + c2->Update(); + c3->cd(); + agr = new TGraphErrors( n, energy, mean_mean, energyerror, energyerror ); + //agr = new TGraphErrors( n, energy, mean80, energyerror, energyerror ); + //agr = new TGraphErrors( n, energy, mean90, energyerror, energyerror ); + //agr = new TGraphErrors( n, energy, mean_mean, energyerror, rms_mean ); + //agr = new TGraphErrors( n, energy, mean90, energyerror, energyerror ); + //agr = new TGraphErrors( n, energy, mean_mean2, energyerror, rms_mean2 ); + //agr = new TGraphErrors( n, energy, mean_mean, energyerror, rms_mean ); + agr->GetYaxis()->SetTitle("E_{reco}, GeV"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy, mean_mean, energyerror, mean_meanerror ); + //bgr = new TGraphErrors( n, energy, mean80, energyerror, energyerror ); + //bgr = new TGraphErrors( n, energy, mean90, energyerror, energyerror ); + //bgr = new TGraphErrors( n, energy, mean_mean, energyerror, mean_meanerror ); + //bgr = new TGraphErrors( n, energy, mean90, energyerror, energyerror ); + //bgr = new TGraphErrors( n, energy, mean_mean2, energyerror, mean_meanerror2 ); + //bgr = new TGraphErrors( n, energy, mean_mean, energyerror, mean_meanerror ); + bgr->GetYaxis()->SetTitle("E_{reco}, GeV"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + cgr = new TGraphErrors( n, energy, mean_hist90, energyerror, energyerror ); + //cgr = new TGraphErrors( n, energy, mean85, energyerror, energyerror ); + //cgr = new TGraphErrors( n, energy, mean95, energyerror, energyerror ); + //cgr = new TGraphErrors( n, energy, mean_mean2, energyerror, rms_mean2 ); + //cgr = new TGraphErrors( n, energy, mean100, energyerror, energyerror ); + //cgr = new TGraphErrors( n, energy, mean, energyerror, energyerror ); + //cgr = new TGraphErrors( n, energy, mean_mean2, energyerror, rms_mean2 ); + cgr->GetYaxis()->SetTitle("E_{reco}, GeV"); + cgr->GetXaxis()->SetTitle("E_{true}, GeV"); + dgr = new TGraphErrors( n, energy, mean_hist90, energyerror, meanerror_hist90 ); + //dgr = new TGraphErrors( n, energy, mean85, energyerror, energyerror ); + //dgr = new TGraphErrors( n, energy, mean95, energyerror, energyerror ); + //dgr = new TGraphErrors( n, energy, mean_mean2, energyerror, mean_meanerror2 ); + //dgr = new TGraphErrors( n, energy, mean100, energyerror, energyerror ); + //dgr = new TGraphErrors( n, energy, mean, energyerror, meanerror ); + //dgr = new TGraphErrors( n, energy, mean_mean2, energyerror, mean_meanerror2 ); + dgr->GetYaxis()->SetTitle("E_{reco}, GeV"); + dgr->GetXaxis()->SetTitle("E_{true}, GeV"); + egr = new TGraphErrors( n, energy, mean_hist95, energyerror, energyerror ); + //egr = new TGraphErrors( n, energy, mean90, energyerror, energyerror ); + //egr = new TGraphErrors( n, energy, mean100, energyerror, energyerror ); + //egr = new TGraphErrors( n, energy, mean90, energyerror, energyerror ); + //egr = new TGraphErrors( n, energy, mean, energyerror, energyerror ); + //egr = new TGraphErrors( n, energy, mean90, energyerror, energyerror ); + //egr = new TGraphErrors( n, energy, mean, energyerror, energyerror ); + egr->GetYaxis()->SetTitle("E_{reco}, GeV"); + egr->GetXaxis()->SetTitle("E_{true}, GeV"); + fgr = new TGraphErrors( n, energy, mean_hist95, energyerror, meanerror_hist95 ); + //fgr = new TGraphErrors( n, energy, mean90, energyerror, energyerror ); + //fgr = new TGraphErrors( n, energy, mean100, energyerror, energyerror ); + //fgr = new TGraphErrors( n, energy, mean90, energyerror, energyerror ); + //fgr = new TGraphErrors( n, energy, mean, energyerror, meanerror ); + //fgr = new TGraphErrors( n, energy, mean90, energyerror, energyerror ); + //fgr = new TGraphErrors( n, energy, mean, energyerror, meanerror ); + fgr->GetYaxis()->SetTitle("E_{reco}, GeV"); + fgr->GetXaxis()->SetTitle("E_{true}, GeV"); + ggr = new TGraphErrors( n, energy, mean, energyerror, energyerror ); + ggr->GetYaxis()->SetTitle("E_{reco}, GeV"); + ggr->GetXaxis()->SetTitle("E_{true}, GeV"); + hgr = new TGraphErrors( n, energy, mean, energyerror, meanerror ); + hgr->GetYaxis()->SetTitle("E_{reco}, GeV"); + hgr->GetXaxis()->SetTitle("E_{true}, GeV"); + igr = new TGraphErrors( n, energy, mean_hist96, energyerror, energyerror ); + igr->GetYaxis()->SetTitle("E_{reco}, GeV"); + igr->GetXaxis()->SetTitle("E_{true}, GeV"); + jgr = new TGraphErrors( n, energy, mean_hist96, energyerror, meanerror_hist96 ); + jgr->GetYaxis()->SetTitle("E_{reco}, GeV"); + jgr->GetXaxis()->SetTitle("E_{true}, GeV"); + kgr = new TGraphErrors( n, energy, mean_hist97, energyerror, energyerror ); + kgr->GetYaxis()->SetTitle("E_{reco}, GeV"); + kgr->GetXaxis()->SetTitle("E_{true}, GeV"); + lgr = new TGraphErrors( n, energy, mean_hist97, energyerror, meanerror_hist97 ); + lgr->GetYaxis()->SetTitle("E_{reco}, GeV"); + lgr->GetXaxis()->SetTitle("E_{true}, GeV"); + mgr = new TGraphErrors( n, energy, mean_hist98, energyerror, energyerror ); + mgr->GetYaxis()->SetTitle("E_{reco}, GeV"); + mgr->GetXaxis()->SetTitle("E_{true}, GeV"); + ngr = new TGraphErrors( n, energy, mean_hist98, energyerror, meanerror_hist98 ); + ngr->GetYaxis()->SetTitle("E_{reco}, GeV"); + ngr->GetXaxis()->SetTitle("E_{true}, GeV"); + ogr = new TGraphErrors( n, energy, mean_hist99, energyerror, energyerror ); + ogr->GetYaxis()->SetTitle("E_{reco}, GeV"); + ogr->GetXaxis()->SetTitle("E_{true}, GeV"); + pgr = new TGraphErrors( n, energy, mean_hist99, energyerror, meanerror_hist99 ); + pgr->GetYaxis()->SetTitle("E_{reco}, GeV"); + pgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Linearity 2" ); + agr->GetYaxis()->SetRangeUser(0.0, 70.0); agr->SetTitle(fname); - agr->SetMarkerColor(12); // kBlue - agr->SetMarkerStyle(34); // 21 - agr->Draw("ALP"); - bgr->SetMarkerColor(15); // kRed - bgr->SetMarkerStyle(22); // 21 - bgr->Draw("LPSAME"); - cgr->SetMarkerColor(17); // kGreen - cgr->SetMarkerStyle(20); // 21 - cgr->Draw("LPSAME"); - - TLegend *lsc = new TLegend(0.55,0.62,0.90,0.92); - lsc->AddEntry(agr,"nodigi","pl"); - lsc->AddEntry(bgr,"digi(20%)","pl"); - lsc->AddEntry(cgr,"digi(60%)","pl"); - lsc->Draw(); - c1->Update(); + agr->SetFillColor(kCyan); + agr->SetFillStyle(3001); + agr->SetMarkerColor(kCyan); + agr->SetLineColor(kCyan); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); + agr->Draw("A 3"); + bgr->SetMarkerColor(kBlue); + bgr->SetLineColor(kBlue); + bgr->SetLineWidth(3); + bgr->SetFillColor(kCyan); + bgr->SetMarkerStyle(20); + bgr->Draw("P SAME"); + cgr->SetMarkerColor(kYellow-6); + cgr->SetFillStyle(3001); + cgr->SetLineColor(kYellow-6); + cgr->SetLineWidth(3); + cgr->SetFillColor(kYellow-6); + cgr->SetMarkerStyle(20); + cgr->Draw("3 SAME"); + dgr->SetMarkerColor(kRed); + dgr->SetLineColor(kRed); + dgr->SetLineWidth(3); + dgr->SetFillColor(kYellow-6); + dgr->SetMarkerStyle(20); + dgr->Draw("P SAME"); + egr->SetMarkerColor(kViolet-6); + egr->SetFillStyle(3001); + egr->SetLineColor(kViolet-6); + egr->SetLineWidth(3); + egr->SetFillColor(kViolet-6); + egr->SetMarkerStyle(20); + egr->Draw("3 SAME"); + fgr->SetMarkerColor(kGreen+1); + fgr->SetLineColor(kGreen+1); + fgr->SetLineWidth(3); + fgr->SetFillColor(kViolet-6); + fgr->SetMarkerStyle(20); + fgr->Draw("P SAME"); + ggr->SetMarkerColor(kMagenta-10); + ggr->SetFillStyle(3001); + ggr->SetLineColor(kMagenta-10); + ggr->SetLineWidth(3); + ggr->SetFillColor(kMagenta-10); + ggr->SetMarkerStyle(20); + ggr->Draw("3 SAME"); + hgr->SetMarkerColor(kMagenta+1); + hgr->SetLineColor(kMagenta+1); + hgr->SetLineWidth(3); + hgr->SetFillColor(kMagenta-10); + hgr->SetMarkerStyle(20); + hgr->Draw("P SAME"); + igr->SetMarkerColor(kMagenta-10); + igr->SetFillStyle(3001); + igr->SetLineColor(kMagenta-10); + igr->SetLineWidth(3); + igr->SetFillColor(kMagenta-10); + igr->SetMarkerStyle(20); + igr->Draw("3 SAME"); + jgr->SetMarkerColor(kCyan+1); + jgr->SetLineColor(kCyan+1); + jgr->SetLineWidth(3); + jgr->SetFillColor(kMagenta-10); + jgr->SetMarkerStyle(20); + jgr->Draw("P SAME"); + kgr->SetMarkerColor(kMagenta-10); + kgr->SetFillStyle(3001); + kgr->SetLineColor(kMagenta-10); + kgr->SetLineWidth(3); + kgr->SetFillColor(kMagenta-10); + kgr->SetMarkerStyle(20); + kgr->Draw("3 SAME"); + lgr->SetMarkerColor(kCyan+2); + lgr->SetLineColor(kCyan+2); + lgr->SetLineWidth(3); + lgr->SetFillColor(kMagenta-10); + lgr->SetMarkerStyle(20); + lgr->Draw("P SAME"); + mgr->SetMarkerColor(kMagenta-10); + mgr->SetFillStyle(3001); + mgr->SetLineColor(kMagenta-10); + mgr->SetLineWidth(3); + mgr->SetFillColor(kMagenta-10); + mgr->SetMarkerStyle(20); + mgr->Draw("3 SAME"); + ngr->SetMarkerColor(kCyan+3); + ngr->SetLineColor(kCyan+3); + ngr->SetLineWidth(3); + ngr->SetFillColor(kMagenta-10); + ngr->SetMarkerStyle(20); + ngr->Draw("P SAME"); + ogr->SetMarkerColor(kMagenta-10); + ogr->SetFillStyle(3001); + ogr->SetLineColor(kMagenta-10); + ogr->SetLineWidth(3); + ogr->SetFillColor(kMagenta-10); + ogr->SetMarkerStyle(20); + ogr->Draw("3 SAME"); + pgr->SetMarkerColor(kCyan-8); + pgr->SetLineColor(kCyan-8); + pgr->SetLineWidth(3); + pgr->SetFillColor(kMagenta-10); + pgr->SetMarkerStyle(20); + pgr->Draw("P SAME"); + c3->Update(); -} + c4->cd(); + agr = new TGraphErrors( n, energy, resolution, energyerror, resolution_error_sys ); + //agr = new TGraphErrors( n, energy, resolution80, energyerror, resolution_error_sys80 ); + //agr = new TGraphErrors( n, energy, resolution90, energyerror, resolution_error_sys90 ); + //agr = new TGraphErrors( n, energy, resolution, energyerror, resolution_error_sys ); + //agr = new TGraphErrors( n, energy, resolution90, energyerror, resolution_error_sys90 ); + //agr = new TGraphErrors( n, energy, resolution2, energyerror, resolution_error_sys2 ); + //agr = new TGraphErrors( n, energy, resolution, energyerror, resolution_error_sys ); + //agr->GetYaxis()->SetTitle("#sigma_{reco} / E_{reco}"); + //agr->GetXaxis()->SetTitle("E_{true}, GeV"); + agr->GetYaxis()->SetTitle("#DeltaE_{reco} / E_{reco}"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy, resolution, energyerror, resolution_error_stat ); + //bgr = new TGraphErrors( n, energy, resolution80, energyerror, resolution_error_stat80 ); + //bgr = new TGraphErrors( n, energy, resolution90, energyerror, resolution_error_stat90 ); + //bgr = new TGraphErrors( n, energy, resolution, energyerror, resolution_error_stat ); + //bgr = new TGraphErrors( n, energy, resolution90, energyerror, resolution_error_stat90 ); + //bgr = new TGraphErrors( n, energy, resolution2, energyerror, resolution_error_stat2 ); + //bgr = new TGraphErrors( n, energy, resolution, energyerror, resolution_error_stat ); + bgr->GetYaxis()->SetTitle("#DeltaE_{reco} / E_{reco}"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + cgr = new TGraphErrors( n, energy, resolution_hist90, energyerror, resolution_error_sys_hist90 ); + //cgr = new TGraphErrors( n, energy, resolution85, energyerror, resolution_error_sys85 ); + //cgr = new TGraphErrors( n, energy, resolution95, energyerror, resolution_error_sys95 ); + //cgr = new TGraphErrors( n, energy, resolution2, energyerror, resolution_error_sys2 ); + //cgr = new TGraphErrors( n, energy, resolution100, energyerror, resolution_error_sys100 ); + //cgr = new TGraphErrors( n, energy, resolution_hist, energyerror, resolution_error_sys_hist ); + //cgr = new TGraphErrors( n, energy, resolution2, energyerror, resolution_error_sys2 ); + cgr->GetYaxis()->SetTitle("#DeltaE_{reco} / E_{reco}"); + cgr->GetXaxis()->SetTitle("E_{true}, GeV"); + dgr = new TGraphErrors( n, energy, resolution_hist90, energyerror, resolution_error_stat_hist90 ); + //dgr = new TGraphErrors( n, energy, resolution85, energyerror, resolution_error_stat85 ); + //dgr = new TGraphErrors( n, energy, resolution95, energyerror, resolution_error_stat95 ); + //dgr = new TGraphErrors( n, energy, resolution2, energyerror, resolution_error_stat2 ); + //dgr = new TGraphErrors( n, energy, resolution100, energyerror, resolution_error_stat100 ); + //dgr = new TGraphErrors( n, energy, resolution_hist, energyerror, resolution_error_stat_hist ); + //dgr = new TGraphErrors( n, energy, resolution2, energyerror, resolution_error_stat2 ); + dgr->GetYaxis()->SetTitle("#DeltaE_{reco} / E_{reco}"); + dgr->GetXaxis()->SetTitle("E_{true}, GeV"); + egr = new TGraphErrors( n, energy, resolution_hist95, energyerror, resolution_error_sys_hist95 ); + //egr = new TGraphErrors( n, energy, resolution90, energyerror, resolution_error_sys90 ); + //egr = new TGraphErrors( n, energy, resolution100, energyerror, resolution_error_sys100 ); + //egr = new TGraphErrors( n, energy, resolution90, energyerror, resolution_error_sys90 ); + //egr = new TGraphErrors( n, energy, resolution_hist, energyerror, resolution_error_sys_hist ); + //egr = new TGraphErrors( n, energy, resolution90, energyerror, resolution_error_sys90 ); + //egr = new TGraphErrors( n, energy, resolution_hist, energyerror, resolution_error_sys_hist ); + egr->GetYaxis()->SetTitle("#DeltaE_{reco} / E_{reco}"); + egr->GetXaxis()->SetTitle("E_{true}, GeV"); + fgr = new TGraphErrors( n, energy, resolution_hist95, energyerror, resolution_error_stat_hist95 ); + //fgr = new TGraphErrors( n, energy, resolution90, energyerror, resolution_error_stat90 ); + //fgr = new TGraphErrors( n, energy, resolution100, energyerror, resolution_error_stat100 ); + //fgr = new TGraphErrors( n, energy, resolution90, energyerror, resolution_error_stat90 ); + //fgr = new TGraphErrors( n, energy, resolution_hist, energyerror, resolution_error_stat_hist ); + //fgr = new TGraphErrors( n, energy, resolution90, energyerror, resolution_error_stat90 ); + //fgr = new TGraphErrors( n, energy, resolution_hist, energyerror, resolution_error_stat_hist ); + fgr->GetYaxis()->SetTitle("#DeltaE_{reco} / E_{reco}"); + fgr->GetXaxis()->SetTitle("E_{true}, GeV"); + ggr = new TGraphErrors( n, energy, resolution_hist, energyerror, resolution_error_sys_hist ); + ggr->GetYaxis()->SetTitle("#DeltaE_{reco} / E_{reco}"); + ggr->GetXaxis()->SetTitle("E_{true}, GeV"); + hgr = new TGraphErrors( n, energy, resolution_hist, energyerror, resolution_error_stat_hist ); + hgr->GetYaxis()->SetTitle("#DeltaE_{reco} / E_{reco}"); + hgr->GetXaxis()->SetTitle("E_{true}, GeV"); + igr = new TGraphErrors( n, energy, resolution_hist96, energyerror, resolution_error_sys_hist96 ); + igr->GetYaxis()->SetTitle("#DeltaE_{reco} / E_{reco}"); + igr->GetXaxis()->SetTitle("E_{true}, GeV"); + jgr = new TGraphErrors( n, energy, resolution_hist96, energyerror, resolution_error_stat_hist96 ); + jgr->GetYaxis()->SetTitle("#DeltaE_{reco} / E_{reco}"); + jgr->GetXaxis()->SetTitle("E_{true}, GeV"); + kgr = new TGraphErrors( n, energy, resolution_hist97, energyerror, resolution_error_sys_hist97 ); + kgr->GetYaxis()->SetTitle("#DeltaE_{reco} / E_{reco}"); + kgr->GetXaxis()->SetTitle("E_{true}, GeV"); + lgr = new TGraphErrors( n, energy, resolution_hist97, energyerror, resolution_error_stat_hist97 ); + lgr->GetYaxis()->SetTitle("#DeltaE_{reco} / E_{reco}"); + lgr->GetXaxis()->SetTitle("E_{true}, GeV"); + mgr = new TGraphErrors( n, energy, resolution_hist98, energyerror, resolution_error_sys_hist98 ); + mgr->GetYaxis()->SetTitle("#DeltaE_{reco} / E_{reco}"); + mgr->GetXaxis()->SetTitle("E_{true}, GeV"); + ngr = new TGraphErrors( n, energy, resolution_hist98, energyerror, resolution_error_stat_hist98 ); + ngr->GetYaxis()->SetTitle("#DeltaE_{reco} / E_{reco}"); + ngr->GetXaxis()->SetTitle("E_{true}, GeV"); + ogr = new TGraphErrors( n, energy, resolution_hist99, energyerror, resolution_error_sys_hist99 ); + ogr->GetYaxis()->SetTitle("#DeltaE_{reco} / E_{reco}"); + ogr->GetXaxis()->SetTitle("E_{true}, GeV"); + pgr = new TGraphErrors( n, energy, resolution_hist99, energyerror, resolution_error_stat_hist99 ); + pgr->GetYaxis()->SetTitle("#DeltaE_{reco} / E_{reco}"); + pgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Relative energy resolution" ); + agr->GetYaxis()->SetRangeUser(0.0, 0.30); + agr->SetTitle(fname); + agr->SetFillColor(kCyan); + agr->SetFillStyle(3001); + agr->SetMarkerColor(kCyan); + agr->SetLineColor(kCyan); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); + agr->Draw("A 3"); + bgr->SetMarkerColor(kBlue); + bgr->SetLineColor(kBlue); + bgr->SetLineWidth(3); + bgr->SetFillColor(kCyan); + bgr->SetMarkerStyle(20); + bgr->Draw("P SAME"); + cgr->SetMarkerColor(kYellow-6); + cgr->SetFillStyle(3001); + cgr->SetLineColor(kYellow-6); + cgr->SetLineWidth(3); + cgr->SetFillColor(kYellow-6); + cgr->SetMarkerStyle(20); + cgr->Draw("3 SAME"); + dgr->SetMarkerColor(kRed); + dgr->SetLineColor(kRed); + dgr->SetLineWidth(3); + dgr->SetFillColor(kYellow-6); + dgr->SetMarkerStyle(20); + dgr->Draw("P SAME"); + egr->SetMarkerColor(kViolet-6); + egr->SetFillStyle(3001); + egr->SetLineColor(kViolet-6); + egr->SetLineWidth(3); + egr->SetFillColor(kViolet-6); + egr->SetMarkerStyle(20); + egr->Draw("3 SAME"); + fgr->SetMarkerColor(kGreen+1); + fgr->SetLineColor(kGreen+1); + fgr->SetLineWidth(3); + fgr->SetFillColor(kViolet-6); + fgr->SetMarkerStyle(20); + fgr->Draw("P SAME"); + ggr->SetMarkerColor(kMagenta-10); + ggr->SetFillStyle(3001); + ggr->SetLineColor(kMagenta-10); + ggr->SetLineWidth(3); + ggr->SetFillColor(kMagenta-10); + ggr->SetMarkerStyle(20); + ggr->Draw("3 SAME"); + hgr->SetMarkerColor(kMagenta+1); + hgr->SetLineColor(kMagenta+1); + hgr->SetLineWidth(3); + hgr->SetFillColor(kMagenta-10); + hgr->SetMarkerStyle(20); + hgr->Draw("P SAME"); + igr->SetMarkerColor(kMagenta-10); + igr->SetFillStyle(3001); + igr->SetLineColor(kMagenta-10); + igr->SetLineWidth(3); + igr->SetFillColor(kMagenta-10); + igr->SetMarkerStyle(20); + igr->Draw("3 SAME"); + jgr->SetMarkerColor(kCyan+1); + jgr->SetLineColor(kCyan+1); + jgr->SetLineWidth(3); + jgr->SetFillColor(kMagenta-10); + jgr->SetMarkerStyle(20); + jgr->Draw("P SAME"); + kgr->SetMarkerColor(kMagenta-10); + kgr->SetFillStyle(3001); + kgr->SetLineColor(kMagenta-10); + kgr->SetLineWidth(3); + kgr->SetFillColor(kMagenta-10); + kgr->SetMarkerStyle(20); + kgr->Draw("3 SAME"); + lgr->SetMarkerColor(kCyan+2); + lgr->SetLineColor(kCyan+2); + lgr->SetLineWidth(3); + lgr->SetFillColor(kMagenta-10); + lgr->SetMarkerStyle(20); + lgr->Draw("P SAME"); + mgr->SetMarkerColor(kMagenta-10); + mgr->SetFillStyle(3001); + mgr->SetLineColor(kMagenta-10); + mgr->SetLineWidth(3); + mgr->SetFillColor(kMagenta-10); + mgr->SetMarkerStyle(20); + mgr->Draw("3 SAME"); + ngr->SetMarkerColor(kCyan+3); + ngr->SetLineColor(kCyan+3); + ngr->SetLineWidth(3); + ngr->SetFillColor(kMagenta-10); + ngr->SetMarkerStyle(20); + ngr->Draw("P SAME"); + ogr->SetMarkerColor(kMagenta-10); + ogr->SetFillStyle(3001); + ogr->SetLineColor(kMagenta-10); + ogr->SetLineWidth(3); + ogr->SetFillColor(kMagenta-10); + ogr->SetMarkerStyle(20); + ogr->Draw("3 SAME"); + pgr->SetMarkerColor(kCyan-8); + pgr->SetLineColor(kCyan-8); + pgr->SetLineWidth(3); + pgr->SetFillColor(kMagenta-10); + pgr->SetMarkerStyle(20); + pgr->Draw("P SAME"); + c4->Update(); + + TLegend *lsc1 = new TLegend(0.55,0.62,0.90,0.92); + lsc1->AddEntry(bgr,"fit (stat)","pl"); + lsc1->AddEntry(dgr,"hist90 (stat)","pl"); + lsc1->AddEntry(fgr,"hist95 (stat)","pl"); + lsc1->AddEntry(jgr,"hist96 (stat)","pl"); + lsc1->AddEntry(lgr,"hist97 (stat)","pl"); + lsc1->AddEntry(ngr,"hist98 (stat)","pl"); + lsc1->AddEntry(pgr,"hist99 (stat)","pl"); + lsc1->AddEntry(hgr,"hist (stat)","pl"); + //lsc1->AddEntry(bgr,"fit (stat)","pl"); + //lsc1->AddEntry(dgr,"hist90 (stat)","pl"); + //lsc1->AddEntry(fgr,"hist95 (stat)","pl"); + //lsc1->AddEntry(hgr,"hist (stat)","pl"); + //lsc1->AddEntry(bgr,"hist90 (w/o errors)","pl"); + //lsc1->AddEntry(dgr,"hist95 (w/o errors)","pl"); + //lsc1->AddEntry(fgr,"hist90_2 (stat)","pl"); + //lsc1->AddEntry(hgr,"hist95_2 (stat)","pl"); + //lsc1->AddEntry(bgr,"fit (stat)","pl"); + //lsc1->AddEntry(dgr,"hist90 (w/o errors)","pl"); + //lsc1->AddEntry(fgr,"hist95 (w/o errors)","pl"); + //lsc1->AddEntry(hgr,"hist (stat)","pl"); + //lsc1->AddEntry(bgr,"data, rms80 w/o errors","plf"); + //lsc1->AddEntry(dgr,"data, rms85 w/o errors","plf"); + //lsc1->AddEntry(fgr,"data, rms90 w/o errors","plf"); + //lsc1->AddEntry(bgr,"data, rms90 w/o errors","plf"); + //lsc1->AddEntry(dgr,"data, rms95 w/o errors","plf"); + //lsc1->AddEntry(fgr,"data, rms100 w/o errors","plf"); + //lsc1->AddEntry(bgr,"data, fit 1","plf"); + //lsc1->AddEntry(dgr,"data, fit 2 (stat)","plf"); + //lsc1->AddEntry(fgr,"data, rms90 w/o errors","plf"); + //lsc1->AddEntry(bgr,"data, rms90 w/o errors","plf"); + //lsc1->AddEntry(dgr,"data, rms100 w/o errors","plf"); + //lsc1->AddEntry(fgr,"data, rms_hist (stat)","plf"); + //lsc1->AddEntry(bgr,"data, fit 2 (stat)","plf"); + //lsc1->AddEntry(dgr,"data, rms_hist (stat)","plf"); + //lsc1->AddEntry(fgr,"data, rms90 w/o errors","plf"); + //lsc1->AddEntry(bgr,"data, fit 1","plf"); + //lsc1->AddEntry(dgr,"data, fit 2 (stat)","plf"); + //lsc1->AddEntry(fgr,"data, rms_hist (stat)","plf"); + + TLegend *lsc2 = new TLegend(0.55,0.62,0.90,0.92); + lsc2->AddEntry(bgr,"fit (stat)","pl"); + lsc2->AddEntry(dgr,"hist90 (stat)","pl"); + lsc2->AddEntry(fgr,"hist95 (stat)","pl"); + lsc2->AddEntry(jgr,"hist96 (stat)","pl"); + lsc2->AddEntry(lgr,"hist97 (stat)","pl"); + lsc2->AddEntry(ngr,"hist98 (stat)","pl"); + lsc2->AddEntry(pgr,"hist99 (stat)","pl"); + lsc2->AddEntry(hgr,"hist (stat)","pl"); + + TLegend *lsc3 = new TLegend(0.55,0.62,0.90,0.92); + lsc3->AddEntry(bgr,"fit (stat)","pl"); + lsc3->AddEntry(dgr,"hist90 (stat)","pl"); + lsc3->AddEntry(fgr,"hist95 (stat)","pl"); + lsc3->AddEntry(jgr,"hist96 (stat)","pl"); + lsc3->AddEntry(lgr,"hist97 (stat)","pl"); + lsc3->AddEntry(ngr,"hist98 (stat)","pl"); + lsc3->AddEntry(pgr,"hist99 (stat)","pl"); + lsc3->AddEntry(hgr,"hist (stat)","pl"); + + TLegend *lsc4 = new TLegend(0.55,0.62,0.90,0.92); + lsc4->AddEntry(bgr,"fit (stat)","pl"); + lsc4->AddEntry(dgr,"hist90 (stat)","pl"); + lsc4->AddEntry(fgr,"hist95 (stat)","pl"); + lsc4->AddEntry(jgr,"hist96 (stat)","pl"); + lsc4->AddEntry(lgr,"hist97 (stat)","pl"); + lsc4->AddEntry(ngr,"hist98 (stat)","pl"); + lsc4->AddEntry(pgr,"hist99 (stat)","pl"); + lsc4->AddEntry(hgr,"hist (stat)","pl"); + c1->cd(); + lsc1->Draw(); + c2->cd(); + lsc2->Draw(); + c3->cd(); + lsc3->Draw(); + c4->cd(); + lsc4->Draw(); +} diff --git a/graph_errors.c b/graph_errors.c new file mode 100644 index 0000000..79e2f65 --- /dev/null +++ b/graph_errors.c @@ -0,0 +1,570 @@ +void graph_errors() { + TCanvas *c1 = new TCanvas("graph1","graph1",200,10,700,500); + TCanvas *c2 = new TCanvas("graph2","graph2",200,10,700,500); + TCanvas *c3 = new TCanvas("graph3","graph3",200,10,700,500); + TCanvas *c4 = new TCanvas("graph4","graph4",200,10,700,500); + + //c1->SetFillColor(42); + //gStyle->SetPalette(52); + c1->SetGrid(); + c2->SetGrid(); + c3->SetGrid(); + c4->SetGrid(); + //c1->GetFrame()->SetFillColor(21); + //c1->GetFrame()->SetBorderSize(12); + + const Int_t n = 9; // 16 + + Float_t energy[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t energyerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t meanerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rmserror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t mean_mean[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_mean[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_meanerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_meanerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_sigma[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_sigma[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_sigmaerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_sigmaerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_chi[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_chi[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t linearity_error[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t absolute_error[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_stat[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_sys[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + + Float_t energy2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t energyerror2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t meanerror2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rmserror2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t mean_mean2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_mean2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_meanerror2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_meanerror2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_sigma2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_sigma2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_sigmaerror2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_sigmaerror2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_chi2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_chi2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t linearity_error2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t absolute_error2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_stat2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_sys2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + +/* + for (int i = 0; i < n; i++) { + printf( " %f ", energy[i] ); + printf( " %f ", energyerror[i] ); + printf( " %f ", mean[i] ); + printf( " %f ", meanerror[i] ); + printf( " %f ", sigma[i] ); + printf( " %f ", sigmaerror[i] ); + printf( " %f ", value[i] ); + printf( " %f ", error[i] ); + printf( "\n" ); + } +*/ + FILE *file1 = fopen("1out_data.txt", "r"); // 1out_data.txt // // 2out_data.txt + if ( !(long)file1 ) return; + + FILE *file2 = fopen("1out_ann.txt", "r"); // 1out_ann.txt // // 2out_ann.txt + if ( !(long)file2 ) return; + + for ( int i = 0; i < n; i++ ) { + fscanf( file1, "%f %E %E %E %E %E %E %E %E %E %E %E %E %E %E\n", &energy[i], &mean[i], &meanerror[i], &rms[i], &rmserror[i], &mean_mean[i], &rms_mean[i], &mean_meanerror[i], &rms_meanerror[i], &mean_sigma[i], &rms_sigma[i], &mean_sigmaerror[i], &rms_sigmaerror[i], &mean_chi[i], &rms_chi[i] ); + if ( feof( file1 ) ) break; + } + + for ( int i = 0; i < n; i++ ) { + fscanf( file2, "%f %E %E %E %E %E %E %E %E %E %E %E %E %E %E\n", &energy2[i], &mean2[i], &meanerror2[i], &rms2[i], &rmserror2[i], &mean_mean2[i], &rms_mean2[i], &mean_meanerror2[i], &rms_meanerror2[i], &mean_sigma2[i], &rms_sigma2[i], &mean_sigmaerror2[i], &rms_sigmaerror2[i], &mean_chi2[i], &rms_chi2[i] ); + if ( feof( file2 ) ) break; + } + + + /* + for ( int i = 0; i < n; i++ ) { + fscanf( file1, "%f %E %E %E %E %E %E %E %E %E %E %E\n", &energy[i], &mean[i], &meanerror[i], &rms[i], &rmserror[i], &mean_mean[i], &rms_mean[i], &mean_meanerror[i], &mean_sigma[i], &rms_sigma[i], &mean_sigmaerror[i], &mean_chi[i] ); + if ( feof( file1 ) ) break; + } + + for ( int i = 0; i < n; i++ ) { + fscanf( file2, "%f %E %E %E %E %E %E %E %E %E %E %E\n", &energy2[i], &mean2[i], &meanerror2[i], &rms2[i], &rmserror2[i], &mean_mean2[i], &rms_mean2[i], &mean_meanerror2[i], &mean_sigma2[i], &rms_sigma2[i], &mean_sigmaerror2[i], &mean_chi2[i] ); + if ( feof( file2 ) ) break; + } + */ + + for ( int i = 0; i < n; i++ ) { + + linearity_error[ i ] = sqrt( ( pow( mean_meanerror[ i ], 2 ) ) + ( pow( rms_mean[ i ], 2 ) ) ); + absolute_error[ i ] = sqrt( ( pow( mean_sigmaerror[ i ], 2 ) ) + ( pow( rms_sigma[ i ], 2 ) ) ); + + ratio[ i ] = ( mean_mean[i] - energy[i] ) / energy[i]; + ratio_error_stat[ i ] = sqrt( pow( (mean_meanerror[i])/(energy[i]), 2 ) + pow( (mean_mean[i] * energyerror[i])/(energy[i] * energy[i]), 2 ) ); + ratio_error_sys[ i ] = sqrt( pow( (rms_mean[i])/(energy[i]), 2 ) + pow( (mean_mean[i] * energyerror[i])/(energy[i] * energy[i]), 2 ) ); + ratio_error[ i ] = sqrt( ( pow( ratio_error_stat[ i ], 2 ) ) + ( pow( ratio_error_sys[ i ], 2 ) ) ); + + resolution[ i ] = mean_sigma[i] / mean_mean[i]; + resolution_error_stat[ i ] = sqrt( pow( (mean_sigmaerror[i])/(mean_mean[i]), 2 ) + pow( (mean_sigma[i] * mean_meanerror[i])/(mean_mean[i] * mean_mean[i]), 2 ) ); + resolution_error_sys[ i ] = sqrt( pow( (rms_sigma[i])/(mean_mean[i]), 2 ) + pow( (mean_sigma[i] * rms_mean[i])/(mean_mean[i] * mean_mean[i]), 2 ) ); + resolution_error[ i ] = sqrt( ( pow( resolution_error_stat[ i ], 2 ) ) + ( pow( resolution_error_sys[ i ], 2 ) ) ); + + } + + for ( int i = 0; i < n; i++ ) { + + linearity_error2[ i ] = sqrt( ( pow( mean_meanerror2[ i ], 2 ) ) + ( pow( rms_mean2[ i ], 2 ) ) ); + absolute_error2[ i ] = sqrt( ( pow( mean_sigmaerror2[ i ], 2 ) ) + ( pow( rms_sigma2[ i ], 2 ) ) ); + + ratio2[ i ] = ( mean_mean2[i] - energy2[i] ) / energy2[i]; + ratio_error_stat2[ i ] = sqrt( pow( (mean_meanerror2[i])/(energy2[i]), 2 ) + pow( (mean_mean2[i] * energyerror2[i])/(energy2[i] * energy2[i]), 2 ) ); + ratio_error_sys2[ i ] = sqrt( pow( (rms_mean2[i])/(energy2[i]), 2 ) + pow( (mean_mean2[i] * energyerror2[i])/(energy2[i] * energy2[i]), 2 ) ); + ratio_error2[ i ] = sqrt( ( pow( ratio_error_stat2[ i ], 2 ) ) + ( pow( ratio_error_sys2[ i ], 2 ) ) ); + + resolution2[ i ] = mean_sigma2[i] / mean_mean2[i]; + resolution_error_stat2[ i ] = sqrt( pow( (mean_sigmaerror2[i])/(mean_mean2[i]), 2 ) + pow( (mean_sigma2[i] * mean_meanerror2[i])/(mean_mean2[i] * mean_mean2[i]), 2 ) ); + resolution_error_sys2[ i ] = sqrt( pow( (rms_sigma2[i])/(mean_mean2[i]), 2 ) + pow( (mean_sigma2[i] * rms_mean2[i])/(mean_mean2[i] * mean_mean2[i]), 2 ) ); + resolution_error2[ i ] = sqrt( ( pow( resolution_error_stat2[ i ], 2 ) ) + ( pow( resolution_error_sys2[ i ], 2 ) ) ); + + } + + printf( "\n" ); + for (int i = 0; i < n; i++) { + printf( " %f ", energy[i] ); + printf( " %f ", energyerror[i] ); + printf( " %f ", mean[i] ); + printf( " %f ", meanerror[i] ); + printf( " %f ", rms[i] ); + printf( " %f ", rmserror[i] ); + printf( " %f ", mean_mean[i] ); + printf( " %f ", rms_mean[i] ); + printf( " %f ", mean_meanerror[i] ); + printf( " %f ", rms_meanerror[i] ); + printf( " %f ", mean_sigma[i] ); + printf( " %f ", rms_sigma[i] ); + printf( " %f ", mean_sigmaerror[i] ); + printf( " %f ", rms_sigmaerror[i] ); + printf( " %f ", linearity_error[i] ); + printf( " %f ", absolute_error[i] ); + printf( " %f ", ratio[i] ); + printf( " %f ", ratio_error[i] ); + printf( " %f ", resolution[i] ); + printf( " %f ", resolution_error[i] ); + printf( "\n" ); + } + + printf( "\n" ); + for (int i = 0; i < n; i++) { + printf( " %f ", energy2[i] ); + printf( " %f ", energyerror2[i] ); + printf( " %f ", mean2[i] ); + printf( " %f ", meanerror2[i] ); + printf( " %f ", rms2[i] ); + printf( " %f ", rmserror2[i] ); + printf( " %f ", mean_mean2[i] ); + printf( " %f ", rms_mean2[i] ); + printf( " %f ", mean_meanerror2[i] ); + printf( " %f ", rms_meanerror2[i] ); + printf( " %f ", mean_sigma2[i] ); + printf( " %f ", rms_sigma2[i] ); + printf( " %f ", mean_sigmaerror2[i] ); + printf( " %f ", rms_sigmaerror2[i] ); + printf( " %f ", linearity_error2[i] ); + printf( " %f ", absolute_error2[i] ); + printf( " %f ", ratio2[i] ); + printf( " %f ", ratio_error2[i] ); + printf( " %f ", resolution2[i] ); + printf( " %f ", resolution_error2[i] ); + printf( "\n" ); + } + +/* printf( "Here is difference:\n" ); + + Float_t v1 = 0; + Float_t v2 = 0; + Float_t v3 = 0; + + for ( int i = 0; i < n; i++ ) { + printf( " %f, %f, %f, %f \n", energy[i], value[i], value2[i], value3[i] ); + printf( " Difference between nodigi and digi20: %f \n", value2[i] - value[i] ); + v1 = v1 + ( value2[i] - value[i] ); + printf( " Difference between digi20 and digi60: %f \n", value3[i] - value2[i] ); + v2 = v2 + ( value3[i] - value2[i] ); + printf( " Difference between nodigi and digi60: %f \n", value3[i] - value[i] ); + v3 = v3 + ( value3[i] - value[i] ); + } + + printf( "Average values: %f, %f, %f \n", v1/n, v2/n, v3/n ); +*/ + TGraphErrors *agr; + TGraphErrors *bgr; + + TGraphErrors *cgr; + TGraphErrors *dgr; + + char fname[ 100 ]; + for ( int i = 0; i < 100; i++ ) fname[ i ] = 0; +/* + c1->cd(); + agr = new TGraphErrors( n, energy, mean_mean, energyerror, linearity_error ); + agr->GetYaxis()->SetTitle("E_{reco}, GeV"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy2, mean_mean2, energyerror2, linearity_error2 ); + bgr->GetYaxis()->SetTitle("E_{reco}, GeV"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Linearity" ); // Linearity energy resolution // Absolute energy resolution // Relative energy resolution + agr->SetTitle(fname); + + agr->SetMarkerColor(kBlue); // kBlue // 12 + agr->SetLineColor(kBlue); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); // 21 +// agr->SetMarkerSize(2); + agr->Draw("ALP"); + bgr->SetMarkerColor(kRed); // kRed // 15 + bgr->SetLineColor(kRed); + bgr->SetLineWidth(3); + bgr->SetMarkerStyle(29); // 21 +// bgr->SetMarkerSize(2); + bgr->Draw("LPSAME"); // LPSAME + c1->Update(); +*/ + +// ------------------------------------------------------------------------------------------------------------------------------------------------------------------ + + c1->cd(); + agr = new TGraphErrors( n, energy, ratio, energyerror, ratio_error_sys ); + agr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy, ratio, energyerror, ratio_error_stat ); + bgr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + cgr = new TGraphErrors( n, energy2, ratio2, energyerror2, ratio_error_sys2 ); // stat2 ??? + cgr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + cgr->GetXaxis()->SetTitle("E_{true}, GeV"); + dgr = new TGraphErrors( n, energy2, ratio2, energyerror2, ratio_error_stat2 ); + dgr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + dgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Linearity" ); // Linearity energy resolution // Absolute energy resolution // Relative energy resolution + agr->GetYaxis()->SetRangeUser(-0.2, 0.2); // -0.25, 0.8 + agr->SetTitle(fname); + + agr->SetFillColor(kCyan); + agr->SetFillStyle(3001); + agr->SetMarkerColor(kCyan); // kBlue // 12 + agr->SetLineColor(kCyan); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); // 21 +// agr->SetMarkerSize(2); + agr->Draw("A 3"); // ALP + bgr->SetMarkerColor(kBlue); // kRed // 15 + bgr->SetLineColor(kBlue); + bgr->SetLineWidth(3); + bgr->SetFillColor(kCyan); + bgr->SetMarkerStyle(20); // 21 +// bgr->SetMarkerSize(2); + bgr->Draw("P SAME"); // LPSAME + cgr->SetMarkerColor(kYellow-6); // kRed // 15 // kBlack + cgr->SetFillStyle(3001); + cgr->SetLineColor(kYellow-6); + cgr->SetLineWidth(3); + cgr->SetFillColor(kYellow-6); + cgr->SetMarkerStyle(20); // 21 +// bgr->SetMarkerSize(2); + cgr->Draw("3 SAME"); // LPSAME + dgr->SetMarkerColor(kRed); // kRed // 15 + dgr->SetLineColor(kRed); + dgr->SetLineWidth(3); + dgr->SetFillColor(kYellow-6); + dgr->SetMarkerStyle(20); // 21 +// bgr->SetMarkerSize(2); + dgr->Draw("P SAME"); // LPSAME + c1->Update(); + + c2->cd(); + agr = new TGraphErrors( n, energy, mean_sigma, energyerror, rms_sigma ); + agr->GetYaxis()->SetTitle("#sigma_{reco}, GeV"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy, mean_sigma, energyerror, mean_sigmaerror ); + bgr->GetYaxis()->SetTitle("#sigma_{reco}, GeV"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + cgr = new TGraphErrors( n, energy2, mean_sigma2, energyerror2, rms_sigma2 ); + cgr->GetYaxis()->SetTitle("#sigma_{reco}, GeV"); + cgr->GetXaxis()->SetTitle("E_{true}, GeV"); + dgr = new TGraphErrors( n, energy2, mean_sigma2, energyerror2, mean_sigmaerror2 ); + dgr->GetYaxis()->SetTitle("#sigma_{reco}, GeV"); + dgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Absolute energy resolution" ); // Linearity energy resolution // Absolute energy resolution // Relative energy resolution + agr->GetYaxis()->SetRangeUser(0.0, 5.0); // -0.25, 1.0 + agr->SetTitle(fname); + + agr->SetFillColor(kCyan); + agr->SetFillStyle(3001); + agr->SetMarkerColor(kCyan); // kBlue // 12 + agr->SetLineColor(kCyan); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); // 21 +// agr->SetMarkerSize(2); + agr->Draw("A 3"); // ALP + bgr->SetMarkerColor(kBlue); // kRed // 15 + bgr->SetLineColor(kBlue); + bgr->SetLineWidth(3); + bgr->SetFillColor(kCyan); + bgr->SetMarkerStyle(20); // 21 +// bgr->SetMarkerSize(2); + bgr->Draw("P SAME"); // LPSAME + cgr->SetMarkerColor(kYellow-6); // kRed // 15 // kBlack + cgr->SetFillStyle(3001); + cgr->SetLineColor(kYellow-6); + cgr->SetLineWidth(3); + cgr->SetFillColor(kYellow-6); + cgr->SetMarkerStyle(20); // 21 +// bgr->SetMarkerSize(2); + cgr->Draw("3 SAME"); // LPSAME + dgr->SetMarkerColor(kRed); // kRed // 15 + dgr->SetLineColor(kRed); + dgr->SetLineWidth(3); + dgr->SetFillColor(kYellow-6); + dgr->SetMarkerStyle(20); // 21 +// bgr->SetMarkerSize(2); + dgr->Draw("P SAME"); // LPSAME + c2->Update(); + + c3->cd(); + agr = new TGraphErrors( n, energy, mean_mean, energyerror, rms_mean ); + agr->GetYaxis()->SetTitle("E_{reco}, GeV"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy, mean_mean, energyerror, mean_meanerror ); + bgr->GetYaxis()->SetTitle("E_{reco}, GeV"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + cgr = new TGraphErrors( n, energy2, mean_mean2, energyerror2, rms_mean2 ); + cgr->GetYaxis()->SetTitle("E_{reco}, GeV"); + cgr->GetXaxis()->SetTitle("E_{true}, GeV"); + dgr = new TGraphErrors( n, energy2, mean_mean2, energyerror2, mean_meanerror2 ); + dgr->GetYaxis()->SetTitle("E_{reco}, GeV"); + dgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Linearity 2" ); // Linearity energy resolution // Absolute energy resolution // Relative energy resolution + agr->GetYaxis()->SetRangeUser(0.0, 70.0); + agr->SetTitle(fname); + + agr->SetFillColor(kCyan); + agr->SetFillStyle(3001); + agr->SetMarkerColor(kCyan); // kBlue // 12 + agr->SetLineColor(kCyan); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); // 21 +// agr->SetMarkerSize(2); + agr->Draw("A 3"); // ALP + bgr->SetMarkerColor(kBlue); // kRed // 15 + bgr->SetLineColor(kBlue); + bgr->SetLineWidth(3); + bgr->SetFillColor(kCyan); + bgr->SetMarkerStyle(20); // 21 +// bgr->SetMarkerSize(2); + bgr->Draw("P SAME"); // LPSAME + cgr->SetMarkerColor(kYellow-6); // kRed // 15 // kBlack + cgr->SetFillStyle(3001); + cgr->SetLineColor(kYellow-6); + cgr->SetLineWidth(3); + cgr->SetFillColor(kYellow-6); + cgr->SetMarkerStyle(20); // 21 +// bgr->SetMarkerSize(2); + cgr->Draw("3 SAME"); // LPSAME + dgr->SetMarkerColor(kRed); // kRed // 15 + dgr->SetLineColor(kRed); + dgr->SetLineWidth(3); + dgr->SetFillColor(kYellow-6); + dgr->SetMarkerStyle(20); // 21 +// bgr->SetMarkerSize(2); + dgr->Draw("P SAME"); // LPSAME + c3->Update(); + + c4->cd(); + agr = new TGraphErrors( n, energy, resolution, energyerror, resolution_error_sys ); + agr->GetYaxis()->SetTitle("#sigma_{reco} / E_{reco}"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy, resolution, energyerror, resolution_error_stat ); + bgr->GetYaxis()->SetTitle("#sigma_{reco} / E_{reco}"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + cgr = new TGraphErrors( n, energy2, resolution2, energyerror2, resolution_error_sys2 ); + cgr->GetYaxis()->SetTitle("#sigma_{reco} / E_{reco}"); + cgr->GetXaxis()->SetTitle("E_{true}, GeV"); + dgr = new TGraphErrors( n, energy2, resolution2, energyerror2, resolution_error_stat2 ); + dgr->GetYaxis()->SetTitle("#sigma_{reco} / E_{reco}"); + dgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Relative energy resolution" ); // Linearity energy resolution // Absolute energy resolution // Relative energy resolution + agr->GetYaxis()->SetRangeUser(0.0, 0.25); // -0.25, 1.0 + agr->SetTitle(fname); + + agr->SetFillColor(kCyan); + agr->SetFillStyle(3001); + agr->SetMarkerColor(kCyan); // kBlue // 12 + agr->SetLineColor(kCyan); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); // 21 +// agr->SetMarkerSize(2); + agr->Draw("A 3"); // ALP + bgr->SetMarkerColor(kBlue); // kRed // 15 + bgr->SetLineColor(kBlue); + bgr->SetLineWidth(3); + bgr->SetFillColor(kCyan); + bgr->SetMarkerStyle(20); // 21 +// bgr->SetMarkerSize(2); + bgr->Draw("P SAME"); // LPSAME + cgr->SetMarkerColor(kYellow-6); // kRed // 15 // kBlack + cgr->SetFillStyle(3001); + cgr->SetLineColor(kYellow-6); + cgr->SetLineWidth(3); + cgr->SetFillColor(kYellow-6); + cgr->SetMarkerStyle(20); // 21 +// bgr->SetMarkerSize(2); + cgr->Draw("3 SAME"); // LPSAME + dgr->SetMarkerColor(kRed); // kRed // 15 + dgr->SetLineColor(kRed); + dgr->SetLineWidth(3); + dgr->SetFillColor(kYellow-6); + dgr->SetMarkerStyle(20); // 21 +// bgr->SetMarkerSize(2); + dgr->Draw("P SAME"); // LPSAME + c4->Update(); + +// ------------------------------------------------------------------------------------------------------------------------------------------------------------------ + +/* c2->cd(); + agr = new TGraphErrors( n, energy, ratio, energyerror, ratio_error ); + agr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy2, ratio2, energyerror2, ratio_error2 ); + bgr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Linearity" ); // Linearity energy resolution // Absolute energy resolution // Relative energy resolution + agr->GetYaxis()->SetRangeUser(-0.3,0.8); + agr->SetTitle(fname); + + agr->SetMarkerColor(kBlue); // kBlue // 12 + agr->SetLineColor(kBlue); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); // 21 +// agr->SetMarkerSize(2); + agr->Draw("ALP"); + bgr->SetMarkerColor(kRed); // kRed // 15 + bgr->SetLineColor(kRed); + bgr->SetLineWidth(3); + bgr->SetMarkerStyle(29); // 21 +// bgr->SetMarkerSize(2); + bgr->Draw("LPSAME"); // LPSAME + c2->Update(); + + c3->cd(); + agr = new TGraphErrors( n, energy, mean_sigma, energyerror, absolute_error ); + agr->GetYaxis()->SetTitle("#sigma_{reco}, GeV"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy2, mean_sigma2, energyerror2, absolute_error2 ); + bgr->GetYaxis()->SetTitle("#sigma_{reco}, GeV"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Absolute energy resolution" ); // Linearity energy resolution // Absolute energy resolution // Relative energy resolution + agr->SetTitle(fname); + + agr->SetMarkerColor(kBlue); // kBlue // 12 + agr->SetLineColor(kBlue); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); // 21 +// agr->SetMarkerSize(2); + agr->Draw("ALP"); + bgr->SetMarkerColor(kRed); // kRed // 15 + bgr->SetLineColor(kRed); + bgr->SetLineWidth(3); + bgr->SetMarkerStyle(29); // 21 +// bgr->SetMarkerSize(2); + bgr->Draw("LPSAME"); // LPSAME + c3->Update(); + + c4->cd(); + agr = new TGraphErrors( n, energy, resolution, energyerror, resolution_error ); + agr->GetYaxis()->SetTitle("#sigma_{reco} / E_{reco}"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy2, resolution2, energyerror2, resolution_error2 ); + bgr->GetYaxis()->SetTitle("#sigma_{reco} / E_{reco}"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Relative energy resolution" ); // Linearity energy resolution // Absolute energy resolution // Relative energy resolution +// agr->GetYaxis()->SetRangeUser(0.03,0.45); + agr->SetTitle(fname); + + agr->SetMarkerColor(kBlue); // kBlue // 12 + agr->SetLineColor(kBlue); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); // 21 +// agr->SetMarkerSize(2); + agr->Draw("ALP"); + bgr->SetMarkerColor(kRed); // kRed // 15 + bgr->SetLineColor(kRed); + bgr->SetLineWidth(3); + bgr->SetMarkerStyle(29); // 21 +// bgr->SetMarkerSize(2); + bgr->Draw("LPSAME"); // LPSAME + c4->Update(); +*/ + TLegend *lsc1 = new TLegend(0.55,0.62,0.90,0.92); +// lsc1->AddEntry(agr,"without ANN","pl"); + lsc1->AddEntry(bgr,"without ANN","plf"); +// lsc1->AddEntry(cgr,"without ANN","plf"); + lsc1->AddEntry(dgr,"with ANN","plf"); + + TLegend *lsc2 = new TLegend(0.55,0.62,0.90,0.92); +// lsc2->AddEntry(agr,"without ANN","pl"); + lsc2->AddEntry(bgr,"without ANN","plf"); +// lsc2->AddEntry(cgr,"without ANN","plf"); + lsc2->AddEntry(dgr,"with ANN","plf"); + + TLegend *lsc3 = new TLegend(0.55,0.62,0.90,0.92); +// lsc2->AddEntry(agr,"without ANN","pl"); + lsc3->AddEntry(bgr,"without ANN","plf"); +// lsc2->AddEntry(cgr,"without ANN","plf"); + lsc3->AddEntry(dgr,"with ANN","plf"); + + TLegend *lsc4 = new TLegend(0.55,0.62,0.90,0.92); +// lsc2->AddEntry(agr,"without ANN","pl"); + lsc4->AddEntry(bgr,"without ANN","plf"); +// lsc2->AddEntry(cgr,"without ANN","plf"); + lsc4->AddEntry(dgr,"with ANN","plf"); + +// TLegend *lsc3 = new TLegend(0.55,0.62,0.90,0.92); +// lsc3->AddEntry(agr,"without ANN","pl"); +// lsc3->AddEntry(bgr,"with ANN","pl"); + +// TLegend *lsc4 = new TLegend(0.55,0.62,0.90,0.92); +// lsc4->AddEntry(agr,"without ANN","pl"); +// lsc4->AddEntry(bgr,"with ANN","pl"); + + c1->cd(); + lsc1->Draw(); + c2->cd(); + lsc2->Draw(); + c3->cd(); + lsc3->Draw(); + c4->cd(); + lsc4->Draw(); + +} diff --git a/graph_for3.c b/graph_for3.c new file mode 100644 index 0000000..12e3436 --- /dev/null +++ b/graph_for3.c @@ -0,0 +1,414 @@ +void graph() { + TCanvas *c1 = new TCanvas("graph1","graph1",200,10,700,500); + TCanvas *c2 = new TCanvas("graph2","graph2",200,10,700,500); + TCanvas *c3 = new TCanvas("graph3","graph3",200,10,700,500); + TCanvas *c4 = new TCanvas("graph4","graph4",200,10,700,500); + + //c1->SetFillColor(42); + //gStyle->SetPalette(52); + c1->SetGrid(); + c2->SetGrid(); + c3->SetGrid(); + c4->SetGrid(); + //c1->GetFrame()->SetFillColor(21); + //c1->GetFrame()->SetBorderSize(12); + + const Int_t n = 16; + + Float_t energy[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t energyerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_mean[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_mean[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_meanerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_meanerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_sigma[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_sigma[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_sigmaerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_sigmaerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_chi[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_chi[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t linearity_error[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t absolute_error[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_stat[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_sys[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t energy2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t energyerror2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_mean2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_mean2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_meanerror2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_meanerror2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_sigma2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_sigma2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_sigmaerror2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_sigmaerror2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_chi2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_chi2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t linearity_error2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t absolute_error2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_stat2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_sys2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t energy3[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t energyerror3[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_mean3[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_mean3[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_meanerror3[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_meanerror3[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_sigma3[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_sigma3[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_sigmaerror3[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_sigmaerror3[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_chi3[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_chi3[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t linearity_error3[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t absolute_error3[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio3[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_stat3[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_sys3[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error3[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution3[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat3[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys3[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error3[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + +/* + for (int i = 0; i < n; i++) { + printf( " %f ", energy[i] ); + printf( " %f ", energyerror[i] ); + printf( " %f ", mean[i] ); + printf( " %f ", meanerror[i] ); + printf( " %f ", sigma[i] ); + printf( " %f ", sigmaerror[i] ); + printf( " %f ", value[i] ); + printf( " %f ", error[i] ); + printf( "\n" ); + } +*/ + FILE *file1 = fopen("out0_5000.txt", "r"); + if ( !(long)file1 ) return; + + FILE *file2 = fopen("out0_10000.txt", "r"); + if ( !(long)file2 ) return; + + FILE *file3 = fopen("out1.txt", "r"); + if ( !(long)file3 ) return; + + for ( int i = 0; i < n; i++ ) { + fscanf( file1, "%f %E %E %E %E %E %E %E\n", &energy[i], &mean_mean[i], &rms_mean[i], &mean_meanerror[i], &mean_sigma[i], &rms_sigma[i], &mean_sigmaerror[i], &mean_chi[i] ); + if ( feof( file1 ) ) break; + } + + for ( int i = 0; i < n; i++ ) { + fscanf( file2, "%f %E %E %E %E %E %E %E\n", &energy2[i], &mean_mean2[i], &rms_mean2[i], &mean_meanerror2[i], &mean_sigma2[i], &rms_sigma2[i], &mean_sigmaerror2[i], &mean_chi2[i] ); + if ( feof( file2 ) ) break; + } + + for ( int i = 0; i < n; i++ ) { + fscanf( file3, "%f %E %E %E %E %E %E %E\n", &energy3[i], &mean_mean3[i], &rms_mean3[i], &mean_meanerror3[i], &mean_sigma3[i], &rms_sigma3[i], &mean_sigmaerror3[i], &mean_chi3[i] ); + if ( feof( file3 ) ) break; + } + + for ( int i = 0; i < n; i++ ) { + + linearity_error[ i ] = sqrt( ( pow( mean_meanerror[ i ], 2 ) ) + ( pow( rms_mean[ i ], 2 ) ) ); + absolute_error[ i ] = sqrt( ( pow( mean_sigmaerror[ i ], 2 ) ) + ( pow( rms_sigma[ i ], 2 ) ) ); + + ratio[ i ] = ( mean_mean[i] - energy[i] ) / energy[i]; + ratio_error_stat[ i ] = sqrt( pow( (mean_meanerror[i])/(energy[i]), 2 ) + pow( (mean_mean[i] * energyerror[i])/(energy[i] * energy[i]), 2 ) ); + ratio_error_sys[ i ] = sqrt( pow( (rms_mean[i])/(energy[i]), 2 ) + pow( (mean_mean[i] * energyerror[i])/(energy[i] * energy[i]), 2 ) ); + ratio_error[ i ] = sqrt( ( pow( ratio_error_stat[ i ], 2 ) ) + ( pow( ratio_error_sys[ i ], 2 ) ) ); + + resolution[ i ] = mean_sigma[i] / mean_mean[i]; + resolution_error_stat[ i ] = sqrt( pow( (mean_sigmaerror[i])/(mean_mean[i]), 2 ) + pow( (mean_sigma[i] * mean_meanerror[i])/(mean_mean[i] * mean_mean[i]), 2 ) ); + resolution_error_sys[ i ] = sqrt( pow( (rms_sigma[i])/(mean_mean[i]), 2 ) + pow( (mean_sigma[i] * rms_mean[i])/(mean_mean[i] * mean_mean[i]), 2 ) ); + resolution_error[ i ] = sqrt( ( pow( resolution_error_stat[ i ], 2 ) ) + ( pow( resolution_error_sys[ i ], 2 ) ) ); + + } + + for ( int i = 0; i < n; i++ ) { + + linearity_error2[ i ] = sqrt( ( pow( mean_meanerror2[ i ], 2 ) ) + ( pow( rms_mean2[ i ], 2 ) ) ); + absolute_error2[ i ] = sqrt( ( pow( mean_sigmaerror2[ i ], 2 ) ) + ( pow( rms_sigma2[ i ], 2 ) ) ); + + ratio2[ i ] = ( mean_mean2[i] - energy2[i] ) / energy2[i]; + ratio_error_stat2[ i ] = sqrt( pow( (mean_meanerror2[i])/(energy2[i]), 2 ) + pow( (mean_mean2[i] * energyerror2[i])/(energy2[i] * energy2[i]), 2 ) ); + ratio_error_sys2[ i ] = sqrt( pow( (rms_mean2[i])/(energy2[i]), 2 ) + pow( (mean_mean2[i] * energyerror2[i])/(energy2[i] * energy2[i]), 2 ) ); + ratio_error2[ i ] = sqrt( ( pow( ratio_error_stat2[ i ], 2 ) ) + ( pow( ratio_error_sys2[ i ], 2 ) ) ); + + resolution2[ i ] = mean_sigma2[i] / mean_mean2[i]; + resolution_error_stat2[ i ] = sqrt( pow( (mean_sigmaerror2[i])/(mean_mean2[i]), 2 ) + pow( (mean_sigma2[i] * mean_meanerror2[i])/(mean_mean2[i] * mean_mean2[i]), 2 ) ); + resolution_error_sys2[ i ] = sqrt( pow( (rms_sigma2[i])/(mean_mean2[i]), 2 ) + pow( (mean_sigma2[i] * rms_mean2[i])/(mean_mean2[i] * mean_mean2[i]), 2 ) ); + resolution_error2[ i ] = sqrt( ( pow( resolution_error_stat2[ i ], 2 ) ) + ( pow( resolution_error_sys2[ i ], 2 ) ) ); + + } + + for ( int i = 0; i < n; i++ ) { + + linearity_error3[ i ] = sqrt( ( pow( mean_meanerror3[ i ], 2 ) ) + ( pow( rms_mean3[ i ], 2 ) ) ); + absolute_error3[ i ] = sqrt( ( pow( mean_sigmaerror3[ i ], 2 ) ) + ( pow( rms_sigma3[ i ], 2 ) ) ); + + ratio3[ i ] = ( mean_mean3[i] - energy3[i] ) / energy3[i]; + ratio_error_stat3[ i ] = sqrt( pow( (mean_meanerror3[i])/(energy3[i]), 2 ) + pow( (mean_mean3[i] * energyerror3[i])/(energy3[i] * energy3[i]), 2 ) ); + ratio_error_sys3[ i ] = sqrt( pow( (rms_mean3[i])/(energy3[i]), 2 ) + pow( (mean_mean3[i] * energyerror3[i])/(energy3[i] * energy3[i]), 2 ) ); + ratio_error3[ i ] = sqrt( ( pow( ratio_error_stat3[ i ], 2 ) ) + ( pow( ratio_error_sys3[ i ], 2 ) ) ); + + resolution3[ i ] = mean_sigma3[i] / mean_mean3[i]; + resolution_error_stat3[ i ] = sqrt( pow( (mean_sigmaerror3[i])/(mean_mean3[i]), 2 ) + pow( (mean_sigma3[i] * mean_meanerror3[i])/(mean_mean3[i] * mean_mean3[i]), 2 ) ); + resolution_error_sys3[ i ] = sqrt( pow( (rms_sigma3[i])/(mean_mean3[i]), 2 ) + pow( (mean_sigma3[i] * rms_mean3[i])/(mean_mean3[i] * mean_mean3[i]), 2 ) ); + resolution_error3[ i ] = sqrt( ( pow( resolution_error_stat3[ i ], 2 ) ) + ( pow( resolution_error_sys3[ i ], 2 ) ) ); + + } + + printf( "\n" ); + for (int i = 0; i < n; i++) { + printf( " %f ", energy[i] ); + printf( " %f ", energyerror[i] ); + printf( " %f ", mean_mean[i] ); + printf( " %f ", rms_mean[i] ); + printf( " %f ", mean_meanerror[i] ); + printf( " %f ", rms_meanerror[i] ); + printf( " %f ", mean_sigma[i] ); + printf( " %f ", rms_sigma[i] ); + printf( " %f ", mean_sigmaerror[i] ); + printf( " %f ", rms_sigmaerror[i] ); + printf( " %f ", linearity_error[i] ); + printf( " %f ", absolute_error[i] ); + printf( " %f ", ratio[i] ); + printf( " %f ", ratio_error[i] ); + printf( " %f ", resolution[i] ); + printf( " %f ", resolution_error[i] ); + printf( "\n" ); + } + + printf( "\n" ); + for (int i = 0; i < n; i++) { + printf( " %f ", energy2[i] ); + printf( " %f ", energyerror2[i] ); + printf( " %f ", mean_mean2[i] ); + printf( " %f ", rms_mean2[i] ); + printf( " %f ", mean_meanerror2[i] ); + printf( " %f ", rms_meanerror2[i] ); + printf( " %f ", mean_sigma2[i] ); + printf( " %f ", rms_sigma2[i] ); + printf( " %f ", mean_sigmaerror2[i] ); + printf( " %f ", rms_sigmaerror2[i] ); + printf( " %f ", linearity_error2[i] ); + printf( " %f ", absolute_error2[i] ); + printf( " %f ", ratio2[i] ); + printf( " %f ", ratio_error2[i] ); + printf( " %f ", resolution2[i] ); + printf( " %f ", resolution_error2[i] ); + printf( "\n" ); + } + + printf( "\n" ); + for (int i = 0; i < n; i++) { + printf( " %f ", energy3[i] ); + printf( " %f ", energyerror3[i] ); + printf( " %f ", mean_mean3[i] ); + printf( " %f ", rms_mean3[i] ); + printf( " %f ", mean_meanerror3[i] ); + printf( " %f ", rms_meanerror3[i] ); + printf( " %f ", mean_sigma3[i] ); + printf( " %f ", rms_sigma3[i] ); + printf( " %f ", mean_sigmaerror3[i] ); + printf( " %f ", rms_sigmaerror3[i] ); + printf( " %f ", linearity_error3[i] ); + printf( " %f ", absolute_error3[i] ); + printf( " %f ", ratio3[i] ); + printf( " %f ", ratio_error3[i] ); + printf( " %f ", resolution3[i] ); + printf( " %f ", resolution_error3[i] ); + printf( "\n" ); + } + +/* printf( "Here is difference:\n" ); + + Float_t v1 = 0; + Float_t v2 = 0; + Float_t v3 = 0; + + for ( int i = 0; i < n; i++ ) { + printf( " %f, %f, %f, %f \n", energy[i], value[i], value2[i], value3[i] ); + printf( " Difference between nodigi and digi20: %f \n", value2[i] - value[i] ); + v1 = v1 + ( value2[i] - value[i] ); + printf( " Difference between digi20 and digi60: %f \n", value3[i] - value2[i] ); + v2 = v2 + ( value3[i] - value2[i] ); + printf( " Difference between nodigi and digi60: %f \n", value3[i] - value[i] ); + v3 = v3 + ( value3[i] - value[i] ); + } + + printf( "Average values: %f, %f, %f \n", v1/n, v2/n, v3/n ); +*/ + TGraphErrors *agr; + TGraphErrors *bgr; + TGraphErrors *cgr; + + char fname[ 100 ]; + for ( int i = 0; i < 100; i++ ) fname[ i ] = 0; + + c1->cd(); + agr = new TGraphErrors( n, energy, mean_mean, energyerror, linearity_error ); + agr->GetYaxis()->SetTitle("E_{reco}, GeV"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy2, mean_mean2, energyerror2, linearity_error2 ); + bgr->GetYaxis()->SetTitle("E_{reco}, GeV"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + cgr = new TGraphErrors( n, energy3, mean_mean3, energyerror3, linearity_error3 ); + cgr->GetYaxis()->SetTitle("E_{reco}, GeV"); + cgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Linearity" ); // Linearity energy resolution // Absolute energy resolution // Relative energy resolution + agr->SetTitle(fname); + + agr->SetMarkerColor(kBlue); // kBlue // 12 + agr->SetLineColor(kBlue); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); // 21 +// agr->SetMarkerSize(2); + agr->Draw("ALP"); + bgr->SetMarkerColor(kRed); // kRed // 15 + bgr->SetLineColor(kRed); + bgr->SetLineWidth(3); + bgr->SetMarkerStyle(29); // 21 +// bgr->SetMarkerSize(2); + bgr->Draw("LPSAME"); // LPSAME + cgr->SetMarkerColor(kGreen); // kGreen // 17 + cgr->SetLineColor(kGreen); + cgr->SetLineWidth(3); + cgr->SetMarkerStyle(20); // 21 +// cgr->SetMarkerSize(2); + cgr->Draw("LPSAME"); // LPSAME // ALP + c1->Update(); + + c2->cd(); + agr = new TGraphErrors( n, energy, ratio, energyerror, ratio_error ); + agr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy2, ratio2, energyerror2, ratio_error2 ); + bgr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + cgr = new TGraphErrors( n, energy3, ratio3, energyerror3, ratio_error3 ); + cgr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + cgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Linearity" ); // Linearity energy resolution // Absolute energy resolution // Relative energy resolution + agr->GetYaxis()->SetRangeUser(-0.3,0.8); + agr->SetTitle(fname); + + agr->SetMarkerColor(kBlue); // kBlue // 12 + agr->SetLineColor(kBlue); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); // 21 +// agr->SetMarkerSize(2); + agr->Draw("ALP"); + bgr->SetMarkerColor(kRed); // kRed // 15 + bgr->SetLineColor(kRed); + bgr->SetLineWidth(3); + bgr->SetMarkerStyle(29); // 21 +// bgr->SetMarkerSize(2); + bgr->Draw("LPSAME"); // LPSAME + cgr->SetMarkerColor(kGreen); // kGreen // 17 + cgr->SetLineColor(kGreen); + cgr->SetLineWidth(3); + cgr->SetMarkerStyle(20); // 21 +// cgr->SetMarkerSize(2); + cgr->Draw("LPSAME"); // LPSAME // ALP + c2->Update(); + + c3->cd(); + agr = new TGraphErrors( n, energy, mean_sigma, energyerror, absolute_error ); + agr->GetYaxis()->SetTitle("#sigma_{reco}, GeV"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy2, mean_sigma2, energyerror2, absolute_error2 ); + bgr->GetYaxis()->SetTitle("#sigma_{reco}, GeV"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + cgr = new TGraphErrors( n, energy3, mean_sigma3, energyerror3, absolute_error3 ); + cgr->GetYaxis()->SetTitle("#sigma_{reco}, GeV"); + cgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Absolute energy resolution" ); // Linearity energy resolution // Absolute energy resolution // Relative energy resolution + agr->SetTitle(fname); + + agr->SetMarkerColor(kBlue); // kBlue // 12 + agr->SetLineColor(kBlue); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); // 21 +// agr->SetMarkerSize(2); + agr->Draw("ALP"); + bgr->SetMarkerColor(kRed); // kRed // 15 + bgr->SetLineColor(kRed); + bgr->SetLineWidth(3); + bgr->SetMarkerStyle(29); // 21 +// bgr->SetMarkerSize(2); + bgr->Draw("LPSAME"); // LPSAME + cgr->SetMarkerColor(kGreen); // kGreen // 17 + cgr->SetLineColor(kGreen); + cgr->SetLineWidth(3); + cgr->SetMarkerStyle(20); // 21 +// cgr->SetMarkerSize(2); + cgr->Draw("LPSAME"); // LPSAME // ALP + c3->Update(); + + c4->cd(); + agr = new TGraphErrors( n, energy, resolution, energyerror, resolution_error ); + agr->GetYaxis()->SetTitle("#sigma_{reco} / E_{reco}"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy2, resolution2, energyerror2, resolution_error2 ); + bgr->GetYaxis()->SetTitle("#sigma_{reco} / E_{reco}"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + cgr = new TGraphErrors( n, energy3, resolution3, energyerror3, resolution_error3 ); + cgr->GetYaxis()->SetTitle("#sigma_{reco} / E_{reco}"); + cgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Relative energy resolution" ); // Linearity energy resolution // Absolute energy resolution // Relative energy resolution +// agr->GetYaxis()->SetRangeUser(0.03,0.45); + agr->SetTitle(fname); + + agr->SetMarkerColor(kBlue); // kBlue // 12 + agr->SetLineColor(kBlue); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); // 21 +// agr->SetMarkerSize(2); + agr->Draw("ALP"); + bgr->SetMarkerColor(kRed); // kRed // 15 + bgr->SetLineColor(kRed); + bgr->SetLineWidth(3); + bgr->SetMarkerStyle(29); // 21 +// bgr->SetMarkerSize(2); + bgr->Draw("LPSAME"); // LPSAME + cgr->SetMarkerColor(kGreen); // kGreen // 17 + cgr->SetLineColor(kGreen); + cgr->SetLineWidth(3); + cgr->SetMarkerStyle(20); // 21 +// cgr->SetMarkerSize(2); + cgr->Draw("LPSAME"); // LPSAME // ALP + c4->Update(); + + TLegend *lsc = new TLegend(0.55,0.62,0.90,0.92); + lsc->AddEntry(agr,"without ANN, 5000 events","pl"); + lsc->AddEntry(bgr,"without ANN, 10000 events","pl"); + lsc->AddEntry(cgr,"with ANN","pl"); + + c1->cd(); + lsc->Draw(); + c2->cd(); + lsc->Draw(); + c3->cd(); + lsc->Draw(); + c4->cd(); + lsc->Draw(); + +} + + + diff --git a/graph_fraction.c b/graph_fraction.c new file mode 100644 index 0000000..824b0d9 --- /dev/null +++ b/graph_fraction.c @@ -0,0 +1,103 @@ +void graph_fraction1( const int fenergy = 5 ) { + TCanvas *c1 = new TCanvas("graph1","graph1",200,10,700,500); + + //c1->SetFillColor(42); + //gStyle->SetPalette(52); + c1->SetGrid(); + //c1->GetFrame()->SetFillColor(21); + //c1->GetFrame()->SetBorderSize(12); + + char fname[ 100 ]; + for ( int i = 0; i < 100; i++ ) fname[ i ] = 0; + + const Int_t n = 16; + + Float_t energy[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t step[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t range[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t chi[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t integral[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t fraction[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + +/* + for (int i = 0; i < n; i++) { + printf( " %f ", energy[i] ); + printf( " %f ", step[i] ); + printf( " %f ", range[i] ); + printf( " %f ", chi[i] ); + printf( " %f ", integral[i] ); + printf( " %f ", fraction[i] ); + printf( "\n" ); + } +*/ + sprintf( fname, "%d_out_data.txt", fenergy ); + + FILE *file1 = fopen(fname, "r"); + if ( !(long)file1 ) return; + + cout << "FILE: " << fname << endl; + + for ( int i = 0; i < n; i++ ) { + fscanf( file1, "%f %f %f %E %f %f\n", &energy[i], &step[i], &range[i], &chi[i], &integral[i], &fraction[i] ); + if ( feof( file1 ) ) break; + } + + printf( "\n" ); + for (int i = 0; i < n; i++) { + printf( " %f ", energy[i] ); + printf( " %f ", step[i] ); + printf( " %f ", range[i] ); + printf( " %f ", chi[i] ); + printf( " %f ", integral[i] ); + printf( " %f ", fraction[i] ); + printf( "\n" ); + } + + TGraphErrors *agr; + + char fname2[ 100 ]; + for ( int i = 0; i < 100; i++ ) fname2[ i ] = 0; + + c1->cd(); + agr = new TGraphErrors( n, fraction, chi, 0, 0 ); + agr->GetYaxis()->SetTitle("Chi^{2} / NDF"); + agr->GetXaxis()->SetTitle("Fraction"); + sprintf( fname2, "%d GeV", fenergy ); // Linearity energy resolution // Absolute energy resolution // Relative energy resolution + agr->SetTitle(fname2); + + agr->SetMarkerColor(kBlue); // kBlue // 12 + agr->SetLineColor(kBlue); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); // 21 +// agr->SetMarkerSize(2); + agr->Draw("ALP"); + c1->Update(); + + char fname3[ 100 ]; + for ( int i = 0; i < 100; i++ ) fname3[ i ] = 0; + + sprintf( fname3, "fraction%d.jpg", fenergy ); + c1->SaveAs( fname3 ); + +// TLegend *lsc = new TLegend(0.55,0.62,0.90,0.92); +// lsc->AddEntry(agr,"without ANN","pl"); + +// c1->cd(); +// lsc->Draw(); + + fclose( file1 ); + delete c1; + +} + +void graph_fraction( ) { + +// int mass[] = { 1, 2, 3, 4, 5, 10, 15, 20, 25, 30, 40, 50, 60, 70, 80, 90 }; + int mass[] = { 5, 10, 15, 20, 25, 30, 40, 50, 60 }; + int dim = 9; // 16 + + for ( int i = 0; i < dim; i++ ) { + graph_fraction1( mass[ i ] ); + } + +} diff --git a/graph_old.c b/graph_old.c new file mode 100644 index 0000000..83ba5e4 --- /dev/null +++ b/graph_old.c @@ -0,0 +1,846 @@ +void graph() { + TCanvas *c1 = new TCanvas("graph1","graph1",200,10,700,500); + TCanvas *c2 = new TCanvas("graph2","graph2",200,10,700,500); + TCanvas *c3 = new TCanvas("graph3","graph3",200,10,700,500); + TCanvas *c4 = new TCanvas("graph4","graph4",200,10,700,500); + + c1->SetGrid(); + c2->SetGrid(); + c3->SetGrid(); + c4->SetGrid(); + + const Int_t n = 9; // 16 + + Float_t energy[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t energyerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t mean[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t meanerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rmserror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t mean_hist90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t meanerror_hist90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_hist90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rmserror_hist90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t mean_hist95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t meanerror_hist95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_hist95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rmserror_hist95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t mean90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t mean_mean[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_mean[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_meanerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_meanerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_sigma[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_sigma[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_sigmaerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_sigmaerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_chi[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_chi[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t ratio_hist[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_stat_hist[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_sys_hist[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_hist[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_hist[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat_hist[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys_hist[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_hist[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t ratio_hist90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_stat_hist90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_sys_hist90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_hist90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_hist90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat_hist90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys_hist90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_hist90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t ratio_hist95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_stat_hist95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_sys_hist95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_hist95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_hist95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat_hist95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys_hist95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_hist95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t ratio90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_stat90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_sys90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error90[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t ratio95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_stat95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_sys95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error95[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t linearity_error[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t absolute_error[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_stat[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_sys[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + FILE *file1 = fopen("new_2out_data.txt", "r"); + if ( !(long)file1 ) return; + + for ( int i = 0; i < n; i++ ) { + fscanf( file1, "%f %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E\n", &energy[i], &mean_hist90[i], &meanerror_hist90[i], &rms_hist90[i], &rmserror_hist90[i], &mean_hist95[i], &meanerror_hist95[i], &rms_hist95[i], &rmserror_hist95[i], &mean90[i], &rms90[i], &mean95[i], &rms95[i], &mean[i], &meanerror[i], &rms[i], &rmserror[i], &mean_mean[i], &mean_meanerror[i], &mean_sigma[i], &mean_sigmaerror[i], &mean_chi[i] ); + if ( feof( file1 ) ) break; + } + + for ( int i = 0; i < n; i++ ) { + + //linearity_error[ i ] = sqrt( ( pow( mean_meanerror[ i ], 2 ) ) + ( pow( rms_mean[ i ], 2 ) ) ); + //absolute_error[ i ] = sqrt( ( pow( mean_sigmaerror[ i ], 2 ) ) + ( pow( rms_sigma[ i ], 2 ) ) ); + //linearity_error2[ i ] = sqrt( ( pow( mean_meanerror2[ i ], 2 ) ) + ( pow( rms_mean2[ i ], 2 ) ) ); + //absolute_error2[ i ] = sqrt( ( pow( mean_sigmaerror2[ i ], 2 ) ) + ( pow( rms_sigma2[ i ], 2 ) ) ); + + ratio_hist[ i ] = ( mean[i] - energy[i] ) / energy[i]; + ratio_error_stat_hist[ i ] = sqrt( pow( (meanerror[i]) / (energy[i]), 2 ) + pow( (mean[i] * energyerror[i]) / (energy[i] * energy[i]), 2 ) ); + ratio_error_sys_hist[ i ] = 0.0; + ratio_error_hist[ i ] = sqrt( ( pow( ratio_error_stat_hist[ i ], 2 ) ) + ( pow( ratio_error_sys_hist[ i ], 2 ) ) ); + + ratio_hist90[ i ] = ( mean_hist90[i] - energy[i] ) / energy[i]; + ratio_error_stat_hist90[ i ] = sqrt( pow( (meanerror_hist90[i]) / (energy[i]), 2 ) + pow( (mean_hist90[i] * energyerror[i]) / (energy[i] * energy[i]), 2 ) ); + ratio_error_sys_hist90[ i ] = 0.0; + ratio_error_hist90[ i ] = sqrt( ( pow( ratio_error_stat_hist90[ i ], 2 ) ) + ( pow( ratio_error_sys_hist90[ i ], 2 ) ) ); + + ratio_hist95[ i ] = ( mean_hist95[i] - energy[i] ) / energy[i]; + ratio_error_stat_hist95[ i ] = sqrt( pow( (meanerror_hist95[i]) / (energy[i]), 2 ) + pow( (mean_hist95[i] * energyerror[i]) / (energy[i] * energy[i]), 2 ) ); + ratio_error_sys_hist95[ i ] = 0.0; + ratio_error_hist95[ i ] = sqrt( ( pow( ratio_error_stat_hist95[ i ], 2 ) ) + ( pow( ratio_error_sys_hist95[ i ], 2 ) ) ); + + ratio90[ i ] = ( mean90[i] - energy[i] ) / energy[i]; + ratio_error_stat90[ i ] = 0.0; + ratio_error_sys90[ i ] = 0.0; + ratio_error90[ i ] = sqrt( ( pow( ratio_error_stat90[ i ], 2 ) ) + ( pow( ratio_error_sys90[ i ], 2 ) ) ); + ratio95[ i ] = ( mean95[i] - energy[i] ) / energy[i]; + ratio_error_stat95[ i ] = 0.0; + ratio_error_sys95[ i ] = 0.0; + ratio_error95[ i ] = sqrt( ( pow( ratio_error_stat95[ i ], 2 ) ) + ( pow( ratio_error_sys95[ i ], 2 ) ) ); + + ratio[ i ] = ( mean_mean[i] - energy[i] ) / energy[i]; + ratio_error_stat[ i ] = sqrt( pow( (mean_meanerror[i]) / (energy[i]), 2 ) + pow( (mean_mean[i] * energyerror[i]) / (energy[i] * energy[i]), 2 ) ); + ratio_error_sys[ i ] = 0.0; + ratio_error[ i ] = sqrt( ( pow( ratio_error_stat[ i ], 2 ) ) + ( pow( ratio_error_sys[ i ], 2 ) ) ); + + resolution_hist[ i ] = rms[i] / mean[i]; + resolution_error_stat_hist[ i ] = sqrt( pow( (rmserror[i]) / (mean[i]), 2 ) + pow( (rms[i] * meanerror[i]) / (mean[i] * mean[i]), 2 ) ); + resolution_error_sys_hist[ i ] = 0.0; + resolution_error_hist[ i ] = sqrt( ( pow( resolution_error_stat_hist[ i ], 2 ) ) + ( pow( resolution_error_sys_hist[ i ], 2 ) ) ); + + resolution_hist90[ i ] = rms_hist90[i] / mean_hist90[i]; + resolution_error_stat_hist90[ i ] = sqrt( pow( (rmserror_hist90[i]) / (mean_hist90[i]), 2 ) + pow( (rms_hist90[i] * meanerror_hist90[i]) / (mean_hist90[i] * mean_hist90[i]), 2 ) ); + resolution_error_sys_hist90[ i ] = 0.0; + resolution_error_hist90[ i ] = sqrt( ( pow( resolution_error_stat_hist90[ i ], 2 ) ) + ( pow( resolution_error_sys_hist90[ i ], 2 ) ) ); + + resolution_hist95[ i ] = rms_hist95[i] / mean_hist95[i]; + resolution_error_stat_hist95[ i ] = sqrt( pow( (rmserror_hist95[i]) / (mean_hist95[i]), 2 ) + pow( (rms_hist95[i] * meanerror_hist95[i]) / (mean_hist95[i] * mean_hist95[i]), 2 ) ); + resolution_error_sys_hist95[ i ] = 0.0; + resolution_error_hist95[ i ] = sqrt( ( pow( resolution_error_stat_hist95[ i ], 2 ) ) + ( pow( resolution_error_sys_hist95[ i ], 2 ) ) ); + + resolution90[ i ] = rms90[i] / mean90[i]; + resolution_error_stat90[ i ] = 0.0; + resolution_error_sys90[ i ] = 0.0; + resolution_error90[ i ] = sqrt( ( pow( resolution_error_stat90[ i ], 2 ) ) + ( pow( resolution_error_sys90[ i ], 2 ) ) ); + + resolution95[ i ] = rms95[i] / mean95[i]; + resolution_error_stat95[ i ] = 0.0; + resolution_error_sys95[ i ] = 0.0; + resolution_error95[ i ] = sqrt( ( pow( resolution_error_stat95[ i ], 2 ) ) + ( pow( resolution_error_sys95[ i ], 2 ) ) ); + + resolution[ i ] = mean_sigma[i] / mean_mean[i]; + resolution_error_stat[ i ] = sqrt( pow( (mean_sigmaerror[i]) / (mean_mean[i]), 2 ) + pow( (mean_sigma[i] * mean_meanerror[i]) / (mean_mean[i] * mean_mean[i]), 2 ) ); + resolution_error_sys[ i ] = 0.0; + resolution_error[ i ] = sqrt( ( pow( resolution_error_stat[ i ], 2 ) ) + ( pow( resolution_error_sys[ i ], 2 ) ) ); + + } + + +/* printf( "\n" ); + for (int i = 0; i < n; i++) { + + printf( " mean_hist90 === %f \n", mean_hist90[i] ); + printf( " rms_hist90 === %f \n", rms_hist90[i] ); + printf( " mean_hist95 === %f \n", mean_hist95[i] ); + printf( " rms_hist95 === %f \n", rms_hist95[i] ); + + printf( " mean90 === %f \n", mean90[i] ); + printf( " rms90 === %f \n", rms90[i] ); + printf( " mean95 === %f \n", mean95[i] ); + printf( " rms95 === %f \n", rms95[i] ); + + printf( "\n" ); + + printf( " ratio_hist90 === %f \n", ratio_hist90[i] ); + printf( " ratio_error_hist90 === %f \n", ratio_error_hist90[i] ); + printf( " resolution_hist90 === %f \n", resolution_hist90[i] ); + printf( " resolution_error_hist90 === %f \n", resolution_error_hist90[i] ); + printf( " ratio_hist95 === %f \n", ratio_hist95[i] ); + printf( " ratio_error_hist95 === %f \n", ratio_error_hist95[i] ); + printf( " resolution_hist95 === %f \n", resolution_hist95[i] ); + printf( " resolution_error_hist95 === %f \n", resolution_error_hist95[i] ); + + printf( " ratio90 === %f \n", ratio90[i] ); + printf( " ratio_error90 === %f \n", ratio_error90[i] ); + printf( " resolution90 === %f \n", resolution90[i] ); + printf( " resolution_error90 === %f \n", resolution_error90[i] ); + printf( " ratio95 === %f \n", ratio95[i] ); + printf( " ratio_error95 === %f \n", ratio_error95[i] ); + printf( " resolution95 === %f \n", resolution95[i] ); + printf( " resolution_error95 === %f \n", resolution_error95[i] ); + + printf( "\n" ); + printf( "\n" ); + printf( "\n" ); + + } +*/ + + + printf( "\n" ); + for (int i = 0; i < n; i++) { + printf( " %f ", energy[i] ); + printf( " %f ", energyerror[i] ); + + printf( " %f ", mean[i] ); + printf( " %f ", meanerror[i] ); + printf( " %f ", rms[i] ); + printf( " %f ", rmserror[i] ); + + printf( " %f ", mean_hist90[i] ); + printf( " %f ", meanerror_hist90[i] ); + printf( " %f ", rms_hist90[i] ); + printf( " %f ", rmserror_hist90[i] ); + + printf( " %f ", mean_hist95[i] ); + printf( " %f ", meanerror_hist95[i] ); + printf( " %f ", rms_hist95[i] ); + printf( " %f ", rmserror_hist95[i] ); + + printf( " %f ", mean90[i] ); + printf( " %f ", rms90[i] ); + printf( " %f ", mean95[i] ); + printf( " %f ", rms95[i] ); + + printf( " %f ", ratio_hist[i] ); + printf( " %f ", ratio_error_hist[i] ); + printf( " %f ", resolution_hist[i] ); + printf( " %f ", resolution_error_hist[i] ); + + printf( " %f ", ratio_hist90[i] ); + printf( " %f ", ratio_error_hist90[i] ); + printf( " %f ", resolution_hist90[i] ); + printf( " %f ", resolution_error_hist90[i] ); + + printf( " %f ", ratio_hist95[i] ); + printf( " %f ", ratio_error_hist95[i] ); + printf( " %f ", resolution_hist95[i] ); + printf( " %f ", resolution_error_hist95[i] ); + + printf( " %f ", ratio90[i] ); + printf( " %f ", ratio_error90[i] ); + printf( " %f ", resolution90[i] ); + printf( " %f ", resolution_error90[i] ); + printf( " %f ", ratio95[i] ); + printf( " %f ", ratio_error95[i] ); + printf( " %f ", resolution95[i] ); + printf( " %f ", resolution_error95[i] ); + + printf( " %f ", mean_mean[i] ); + printf( " %f ", rms_mean[i] ); + printf( " %f ", mean_meanerror[i] ); + printf( " %f ", rms_meanerror[i] ); + printf( " %f ", mean_sigma[i] ); + printf( " %f ", rms_sigma[i] ); + printf( " %f ", mean_sigmaerror[i] ); + printf( " %f ", rms_sigmaerror[i] ); + printf( " %f ", linearity_error[i] ); + printf( " %f ", absolute_error[i] ); + printf( " %f ", ratio[i] ); + printf( " %f ", ratio_error[i] ); + printf( " %f ", resolution[i] ); + printf( " %f ", resolution_error[i] ); + + printf( "\n" ); + printf( "\n" ); + printf( "\n" ); + + } + + TGraphErrors *agr; + TGraphErrors *bgr; + + TGraphErrors *cgr; + TGraphErrors *dgr; + + TGraphErrors *egr; + TGraphErrors *fgr; + + TGraphErrors *ggr; + TGraphErrors *hgr; + + char fname[ 100 ]; + for ( int i = 0; i < 100; i++ ) fname[ i ] = 0; + + c1->cd(); + agr = new TGraphErrors( n, energy, ratio, energyerror, ratio_error_sys ); + //agr = new TGraphErrors( n, energy, ratio80, energyerror, ratio_error_sys80 ); + //agr = new TGraphErrors( n, energy, ratio90, energyerror, ratio_error_sys90 ); + //agr = new TGraphErrors( n, energy, ratio, energyerror, ratio_error_sys ); + //agr = new TGraphErrors( n, energy, ratio90, energyerror, ratio_error_sys90 ); + //agr = new TGraphErrors( n, energy, ratio2, energyerror, ratio_error_sys2 ); + //agr = new TGraphErrors( n, energy, ratio, energyerror, ratio_error_sys ); + agr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy, ratio, energyerror, ratio_error_stat ); + //bgr = new TGraphErrors( n, energy, ratio80, energyerror, ratio_error_stat80 ); + //bgr = new TGraphErrors( n, energy, ratio90, energyerror, ratio_error_stat90 ); + //bgr = new TGraphErrors( n, energy, ratio, energyerror, ratio_error_stat ); + //bgr = new TGraphErrors( n, energy, ratio90, energyerror, ratio_error_stat90 ); + //bgr = new TGraphErrors( n, energy, ratio2, energyerror, ratio_error_stat2 ); + //bgr = new TGraphErrors( n, energy, ratio, energyerror, ratio_error_stat ); + bgr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + cgr = new TGraphErrors( n, energy, ratio_hist90, energyerror, ratio_error_sys_hist90 ); + //cgr = new TGraphErrors( n, energy, ratio85, energyerror, ratio_error_sys85 ); + //cgr = new TGraphErrors( n, energy, ratio95, energyerror, ratio_error_sys95 ); + //cgr = new TGraphErrors( n, energy, ratio2, energyerror, ratio_error_sys2 ); + //cgr = new TGraphErrors( n, energy, ratio100, energyerror, ratio_error_sys100 ); + //cgr = new TGraphErrors( n, energy, ratio_hist, energyerror, ratio_error_sys_hist ); + //cgr = new TGraphErrors( n, energy, ratio2, energyerror, ratio_error_sys2 ); + cgr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + cgr->GetXaxis()->SetTitle("E_{true}, GeV"); + dgr = new TGraphErrors( n, energy, ratio_hist90, energyerror, ratio_error_stat_hist90 ); + //dgr = new TGraphErrors( n, energy, ratio85, energyerror, ratio_error_stat85 ); + //dgr = new TGraphErrors( n, energy, ratio95, energyerror, ratio_error_stat95 ); + //dgr = new TGraphErrors( n, energy, ratio2, energyerror, ratio_error_stat2 ); + //dgr = new TGraphErrors( n, energy, ratio100, energyerror, ratio_error_stat100 ); + //dgr = new TGraphErrors( n, energy, ratio_hist, energyerror, ratio_error_stat_hist ); + //dgr = new TGraphErrors( n, energy, ratio2, energyerror, ratio_error_stat2 ); + dgr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + dgr->GetXaxis()->SetTitle("E_{true}, GeV"); + egr = new TGraphErrors( n, energy, ratio_hist95, energyerror, ratio_error_sys_hist95 ); + //egr = new TGraphErrors( n, energy, ratio90, energyerror, ratio_error_sys90 ); + //egr = new TGraphErrors( n, energy, ratio100, energyerror, ratio_error_sys100 ); + //egr = new TGraphErrors( n, energy, ratio90, energyerror, ratio_error_sys90 ); + //egr = new TGraphErrors( n, energy, ratio_hist, energyerror, ratio_error_sys_hist ); + //egr = new TGraphErrors( n, energy, ratio90, energyerror, ratio_error_sys90 ); + //egr = new TGraphErrors( n, energy, ratio_hist, energyerror, ratio_error_sys_hist ); + egr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + egr->GetXaxis()->SetTitle("E_{true}, GeV"); + fgr = new TGraphErrors( n, energy, ratio_hist95, energyerror, ratio_error_stat_hist95 ); + //fgr = new TGraphErrors( n, energy, ratio90, energyerror, ratio_error_stat90 ); + //fgr = new TGraphErrors( n, energy, ratio100, energyerror, ratio_error_stat100 ); + //fgr = new TGraphErrors( n, energy, ratio90, energyerror, ratio_error_stat90 ); + //fgr = new TGraphErrors( n, energy, ratio_hist, energyerror, ratio_error_stat_hist ); + //fgr = new TGraphErrors( n, energy, ratio90, energyerror, ratio_error_stat90 ); + //fgr = new TGraphErrors( n, energy, ratio_hist, energyerror, ratio_error_stat_hist ); + fgr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + fgr->GetXaxis()->SetTitle("E_{true}, GeV"); + ggr = new TGraphErrors( n, energy, ratio_hist, energyerror, ratio_error_sys_hist ); + ggr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + ggr->GetXaxis()->SetTitle("E_{true}, GeV"); + hgr = new TGraphErrors( n, energy, ratio_hist, energyerror, ratio_error_stat_hist ); + hgr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + hgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Linearity" ); + agr->GetYaxis()->SetRangeUser(-0.2, 0.2); + agr->SetTitle(fname); + + agr->SetFillColor(kCyan); + agr->SetFillStyle(3001); + agr->SetMarkerColor(kCyan); + agr->SetLineColor(kCyan); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); + agr->Draw("A 3"); + bgr->SetMarkerColor(kBlue); + bgr->SetLineColor(kBlue); + bgr->SetLineWidth(3); + bgr->SetFillColor(kCyan); + bgr->SetMarkerStyle(20); + bgr->Draw("P SAME"); + cgr->SetMarkerColor(kYellow-6); + cgr->SetFillStyle(3001); + cgr->SetLineColor(kYellow-6); + cgr->SetLineWidth(3); + cgr->SetFillColor(kYellow-6); + cgr->SetMarkerStyle(20); + cgr->Draw("3 SAME"); + dgr->SetMarkerColor(kRed); + dgr->SetLineColor(kRed); + dgr->SetLineWidth(3); + dgr->SetFillColor(kYellow-6); + dgr->SetMarkerStyle(20); + dgr->Draw("P SAME"); + egr->SetMarkerColor(kViolet-6); + egr->SetFillStyle(3001); + egr->SetLineColor(kViolet-6); + egr->SetLineWidth(3); + egr->SetFillColor(kViolet-6); + egr->SetMarkerStyle(20); + egr->Draw("3 SAME"); + fgr->SetMarkerColor(kGreen+1); + fgr->SetLineColor(kGreen+1); + fgr->SetLineWidth(3); + fgr->SetFillColor(kViolet-6); + fgr->SetMarkerStyle(20); + fgr->Draw("P SAME"); + ggr->SetMarkerColor(kMagenta-10); + ggr->SetFillStyle(3001); + ggr->SetLineColor(kMagenta-10); + ggr->SetLineWidth(3); + ggr->SetFillColor(kMagenta-10); + ggr->SetMarkerStyle(20); + ggr->Draw("3 SAME"); + hgr->SetMarkerColor(kMagenta+1); + hgr->SetLineColor(kMagenta+1); + hgr->SetLineWidth(3); + hgr->SetFillColor(kMagenta-10); + hgr->SetMarkerStyle(20); + hgr->Draw("P SAME"); + c1->Update(); + + c2->cd(); + agr = new TGraphErrors( n, energy, mean_sigma, energyerror, energyerror ); + //agr = new TGraphErrors( n, energy, rms80, energyerror, energyerror ); + //agr = new TGraphErrors( n, energy, rms90, energyerror, energyerror ); + //agr = new TGraphErrors( n, energy, mean_sigma, energyerror, rms_sigma ); + //agr = new TGraphErrors( n, energy, rms90, energyerror, energyerror ); + //agr = new TGraphErrors( n, energy, mean_sigma2, energyerror, rms_sigma2 ); + //agr = new TGraphErrors( n, energy, mean_sigma, energyerror, rms_sigma ); + //agr->GetYaxis()->SetTitle("#sigma_{reco}, GeV"); + //agr->GetXaxis()->SetTitle("E_{true}, GeV"); + agr->GetYaxis()->SetTitle("#DeltaE_{reco}, GeV"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy, mean_sigma, energyerror, mean_sigmaerror ); + //bgr = new TGraphErrors( n, energy, rms80, energyerror, energyerror ); + //bgr = new TGraphErrors( n, energy, rms90, energyerror, energyerror ); + //bgr = new TGraphErrors( n, energy, mean_sigma, energyerror, mean_sigmaerror ); + //bgr = new TGraphErrors( n, energy, rms90, energyerror, energyerror ); + //bgr = new TGraphErrors( n, energy, mean_sigma2, energyerror, mean_sigmaerror2 ); + //bgr = new TGraphErrors( n, energy, mean_sigma, energyerror, mean_sigmaerror ); + bgr->GetYaxis()->SetTitle("#DeltaE_{reco}, GeV"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + cgr = new TGraphErrors( n, energy, rms_hist90, energyerror, energyerror ); + //cgr = new TGraphErrors( n, energy, rms85, energyerror, energyerror ); + //cgr = new TGraphErrors( n, energy, rms95, energyerror, energyerror ); + //cgr = new TGraphErrors( n, energy, mean_sigma2, energyerror, rms_sigma2 ); + //cgr = new TGraphErrors( n, energy, rms100, energyerror, energyerror ); + //cgr = new TGraphErrors( n, energy, rms, energyerror, energyerror );// energyerror == 0 + //cgr = new TGraphErrors( n, energy, mean_sigma2, energyerror, rms_sigma2 ); + cgr->GetYaxis()->SetTitle("#DeltaE_{reco}, GeV"); + cgr->GetXaxis()->SetTitle("E_{true}, GeV"); + dgr = new TGraphErrors( n, energy, rms_hist90, energyerror, rmserror_hist90 ); + //dgr = new TGraphErrors( n, energy, rms85, energyerror, energyerror ); + //dgr = new TGraphErrors( n, energy, rms95, energyerror, energyerror ); + //dgr = new TGraphErrors( n, energy, mean_sigma2, energyerror, mean_sigmaerror2 ); + //dgr = new TGraphErrors( n, energy, rms100, energyerror, energyerror ); + //dgr = new TGraphErrors( n, energy, rms, energyerror, rmserror ); + //dgr = new TGraphErrors( n, energy, mean_sigma2, energyerror, mean_sigmaerror2 ); + dgr->GetYaxis()->SetTitle("#DeltaE_{reco}, GeV"); + dgr->GetXaxis()->SetTitle("E_{true}, GeV"); + egr = new TGraphErrors( n, energy, rms_hist95, energyerror, energyerror ); + //egr = new TGraphErrors( n, energy, rms90, energyerror, energyerror ); + //egr = new TGraphErrors( n, energy, rms100, energyerror, energyerror ); + //egr = new TGraphErrors( n, energy, rms90, energyerror, energyerror ); + //egr = new TGraphErrors( n, energy, rms, energyerror, energyerror ); + //egr = new TGraphErrors( n, energy, rms90, energyerror, energyerror ); + //egr = new TGraphErrors( n, energy, rms, energyerror, energyerror ); + egr->GetYaxis()->SetTitle("#DeltaE_{reco}, GeV"); + egr->GetXaxis()->SetTitle("E_{true}, GeV"); + fgr = new TGraphErrors( n, energy, rms_hist95, energyerror, rmserror_hist95 ); + //fgr = new TGraphErrors( n, energy, rms90, energyerror, energyerror ); + //fgr = new TGraphErrors( n, energy, rms100, energyerror, energyerror ); + //fgr = new TGraphErrors( n, energy, rms90, energyerror, energyerror ); + //fgr = new TGraphErrors( n, energy, rms, energyerror, rmserror ); + //fgr = new TGraphErrors( n, energy, rms90, energyerror, energyerror ); + //fgr = new TGraphErrors( n, energy, rms, energyerror, rmserror ); + fgr->GetYaxis()->SetTitle("#DeltaE_{reco}, GeV"); + fgr->GetXaxis()->SetTitle("E_{true}, GeV"); + ggr = new TGraphErrors( n, energy, rms, energyerror, energyerror ); + ggr->GetYaxis()->SetTitle("#DeltaE_{reco}, GeV"); + ggr->GetXaxis()->SetTitle("E_{true}, GeV"); + hgr = new TGraphErrors( n, energy, rms, energyerror, rmserror ); + hgr->GetYaxis()->SetTitle("#DeltaE_{reco}, GeV"); + hgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Absolute energy resolution" ); + agr->GetYaxis()->SetRangeUser(0.0, 9.0); + agr->SetTitle(fname); + + agr->SetFillColor(kCyan); + agr->SetFillStyle(3001); + agr->SetMarkerColor(kCyan); + agr->SetLineColor(kCyan); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); + agr->Draw("A 3"); + bgr->SetMarkerColor(kBlue); + bgr->SetLineColor(kBlue); + bgr->SetLineWidth(3); + bgr->SetFillColor(kCyan); + bgr->SetMarkerStyle(20); + bgr->Draw("P SAME"); + cgr->SetMarkerColor(kYellow-6); + cgr->SetFillStyle(3001); + cgr->SetLineColor(kYellow-6); + cgr->SetLineWidth(3); + cgr->SetFillColor(kYellow-6); + cgr->SetMarkerStyle(20); + cgr->Draw("3 SAME"); + dgr->SetMarkerColor(kRed); + dgr->SetLineColor(kRed); + dgr->SetLineWidth(3); + dgr->SetFillColor(kYellow-6); + dgr->SetMarkerStyle(20); + dgr->Draw("P SAME"); + egr->SetMarkerColor(kViolet-6); + egr->SetFillStyle(3001); + egr->SetLineColor(kViolet-6); + egr->SetLineWidth(3); + egr->SetFillColor(kViolet-6); + egr->SetMarkerStyle(20); + egr->Draw("3 SAME"); + fgr->SetMarkerColor(kGreen+1); + fgr->SetLineColor(kGreen+1); + fgr->SetLineWidth(3); + fgr->SetFillColor(kViolet-6); + fgr->SetMarkerStyle(20); + fgr->Draw("P SAME"); + ggr->SetMarkerColor(kMagenta-10); + ggr->SetFillStyle(3001); + ggr->SetLineColor(kMagenta-10); + ggr->SetLineWidth(3); + ggr->SetFillColor(kMagenta-10); + ggr->SetMarkerStyle(20); + ggr->Draw("3 SAME"); + hgr->SetMarkerColor(kMagenta+1); + hgr->SetLineColor(kMagenta+1); + hgr->SetLineWidth(3); + hgr->SetFillColor(kMagenta-10); + hgr->SetMarkerStyle(20); + hgr->Draw("P SAME"); + c2->Update(); + + c3->cd(); + agr = new TGraphErrors( n, energy, mean_mean, energyerror, energyerror ); + //agr = new TGraphErrors( n, energy, mean80, energyerror, energyerror ); + //agr = new TGraphErrors( n, energy, mean90, energyerror, energyerror ); + //agr = new TGraphErrors( n, energy, mean_mean, energyerror, rms_mean ); + //agr = new TGraphErrors( n, energy, mean90, energyerror, energyerror ); + //agr = new TGraphErrors( n, energy, mean_mean2, energyerror, rms_mean2 ); + //agr = new TGraphErrors( n, energy, mean_mean, energyerror, rms_mean ); + agr->GetYaxis()->SetTitle("E_{reco}, GeV"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy, mean_mean, energyerror, mean_meanerror ); + //bgr = new TGraphErrors( n, energy, mean80, energyerror, energyerror ); + //bgr = new TGraphErrors( n, energy, mean90, energyerror, energyerror ); + //bgr = new TGraphErrors( n, energy, mean_mean, energyerror, mean_meanerror ); + //bgr = new TGraphErrors( n, energy, mean90, energyerror, energyerror ); + //bgr = new TGraphErrors( n, energy, mean_mean2, energyerror, mean_meanerror2 ); + //bgr = new TGraphErrors( n, energy, mean_mean, energyerror, mean_meanerror ); + bgr->GetYaxis()->SetTitle("E_{reco}, GeV"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + cgr = new TGraphErrors( n, energy, mean_hist90, energyerror, energyerror ); + //cgr = new TGraphErrors( n, energy, mean85, energyerror, energyerror ); + //cgr = new TGraphErrors( n, energy, mean95, energyerror, energyerror ); + //cgr = new TGraphErrors( n, energy, mean_mean2, energyerror, rms_mean2 ); + //cgr = new TGraphErrors( n, energy, mean100, energyerror, energyerror ); + //cgr = new TGraphErrors( n, energy, mean, energyerror, energyerror ); + //cgr = new TGraphErrors( n, energy, mean_mean2, energyerror, rms_mean2 ); + cgr->GetYaxis()->SetTitle("E_{reco}, GeV"); + cgr->GetXaxis()->SetTitle("E_{true}, GeV"); + dgr = new TGraphErrors( n, energy, mean_hist90, energyerror, meanerror_hist90 ); + //dgr = new TGraphErrors( n, energy, mean85, energyerror, energyerror ); + //dgr = new TGraphErrors( n, energy, mean95, energyerror, energyerror ); + //dgr = new TGraphErrors( n, energy, mean_mean2, energyerror, mean_meanerror2 ); + //dgr = new TGraphErrors( n, energy, mean100, energyerror, energyerror ); + //dgr = new TGraphErrors( n, energy, mean, energyerror, meanerror ); + //dgr = new TGraphErrors( n, energy, mean_mean2, energyerror, mean_meanerror2 ); + dgr->GetYaxis()->SetTitle("E_{reco}, GeV"); + dgr->GetXaxis()->SetTitle("E_{true}, GeV"); + egr = new TGraphErrors( n, energy, mean_hist95, energyerror, energyerror ); + //egr = new TGraphErrors( n, energy, mean90, energyerror, energyerror ); + //egr = new TGraphErrors( n, energy, mean100, energyerror, energyerror ); + //egr = new TGraphErrors( n, energy, mean90, energyerror, energyerror ); + //egr = new TGraphErrors( n, energy, mean, energyerror, energyerror ); + //egr = new TGraphErrors( n, energy, mean90, energyerror, energyerror ); + //egr = new TGraphErrors( n, energy, mean, energyerror, energyerror ); + egr->GetYaxis()->SetTitle("E_{reco}, GeV"); + egr->GetXaxis()->SetTitle("E_{true}, GeV"); + fgr = new TGraphErrors( n, energy, mean_hist95, energyerror, meanerror_hist95 ); + //fgr = new TGraphErrors( n, energy, mean90, energyerror, energyerror ); + //fgr = new TGraphErrors( n, energy, mean100, energyerror, energyerror ); + //fgr = new TGraphErrors( n, energy, mean90, energyerror, energyerror ); + //fgr = new TGraphErrors( n, energy, mean, energyerror, meanerror ); + //fgr = new TGraphErrors( n, energy, mean90, energyerror, energyerror ); + //fgr = new TGraphErrors( n, energy, mean, energyerror, meanerror ); + fgr->GetYaxis()->SetTitle("E_{reco}, GeV"); + fgr->GetXaxis()->SetTitle("E_{true}, GeV"); + ggr = new TGraphErrors( n, energy, mean, energyerror, energyerror ); + ggr->GetYaxis()->SetTitle("E_{reco}, GeV"); + ggr->GetXaxis()->SetTitle("E_{true}, GeV"); + hgr = new TGraphErrors( n, energy, mean, energyerror, meanerror ); + hgr->GetYaxis()->SetTitle("E_{reco}, GeV"); + hgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Linearity 2" ); + agr->GetYaxis()->SetRangeUser(0.0, 70.0); + agr->SetTitle(fname); + + agr->SetFillColor(kCyan); + agr->SetFillStyle(3001); + agr->SetMarkerColor(kCyan); + agr->SetLineColor(kCyan); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); + agr->Draw("A 3"); + bgr->SetMarkerColor(kBlue); + bgr->SetLineColor(kBlue); + bgr->SetLineWidth(3); + bgr->SetFillColor(kCyan); + bgr->SetMarkerStyle(20); + bgr->Draw("P SAME"); + cgr->SetMarkerColor(kYellow-6); + cgr->SetFillStyle(3001); + cgr->SetLineColor(kYellow-6); + cgr->SetLineWidth(3); + cgr->SetFillColor(kYellow-6); + cgr->SetMarkerStyle(20); + cgr->Draw("3 SAME"); + dgr->SetMarkerColor(kRed); + dgr->SetLineColor(kRed); + dgr->SetLineWidth(3); + dgr->SetFillColor(kYellow-6); + dgr->SetMarkerStyle(20); + dgr->Draw("P SAME"); + egr->SetMarkerColor(kViolet-6); + egr->SetFillStyle(3001); + egr->SetLineColor(kViolet-6); + egr->SetLineWidth(3); + egr->SetFillColor(kViolet-6); + egr->SetMarkerStyle(20); + egr->Draw("3 SAME"); + fgr->SetMarkerColor(kGreen+1); + fgr->SetLineColor(kGreen+1); + fgr->SetLineWidth(3); + fgr->SetFillColor(kViolet-6); + fgr->SetMarkerStyle(20); + fgr->Draw("P SAME"); + ggr->SetMarkerColor(kMagenta-10); + ggr->SetFillStyle(3001); + ggr->SetLineColor(kMagenta-10); + ggr->SetLineWidth(3); + ggr->SetFillColor(kMagenta-10); + ggr->SetMarkerStyle(20); + ggr->Draw("3 SAME"); + hgr->SetMarkerColor(kMagenta+1); + hgr->SetLineColor(kMagenta+1); + hgr->SetLineWidth(3); + hgr->SetFillColor(kMagenta-10); + hgr->SetMarkerStyle(20); + hgr->Draw("P SAME"); + c3->Update(); + + c4->cd(); + agr = new TGraphErrors( n, energy, resolution, energyerror, resolution_error_sys ); + //agr = new TGraphErrors( n, energy, resolution80, energyerror, resolution_error_sys80 ); + //agr = new TGraphErrors( n, energy, resolution90, energyerror, resolution_error_sys90 ); + //agr = new TGraphErrors( n, energy, resolution, energyerror, resolution_error_sys ); + //agr = new TGraphErrors( n, energy, resolution90, energyerror, resolution_error_sys90 ); + //agr = new TGraphErrors( n, energy, resolution2, energyerror, resolution_error_sys2 ); + //agr = new TGraphErrors( n, energy, resolution, energyerror, resolution_error_sys ); + //agr->GetYaxis()->SetTitle("#sigma_{reco} / E_{reco}"); + //agr->GetXaxis()->SetTitle("E_{true}, GeV"); + agr->GetYaxis()->SetTitle("#DeltaE_{reco} / E_{reco}"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy, resolution, energyerror, resolution_error_stat ); + //bgr = new TGraphErrors( n, energy, resolution80, energyerror, resolution_error_stat80 ); + //bgr = new TGraphErrors( n, energy, resolution90, energyerror, resolution_error_stat90 ); + //bgr = new TGraphErrors( n, energy, resolution, energyerror, resolution_error_stat ); + //bgr = new TGraphErrors( n, energy, resolution90, energyerror, resolution_error_stat90 ); + //bgr = new TGraphErrors( n, energy, resolution2, energyerror, resolution_error_stat2 ); + //bgr = new TGraphErrors( n, energy, resolution, energyerror, resolution_error_stat ); + bgr->GetYaxis()->SetTitle("#DeltaE_{reco} / E_{reco}"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + cgr = new TGraphErrors( n, energy, resolution_hist90, energyerror, resolution_error_sys_hist90 ); + //cgr = new TGraphErrors( n, energy, resolution85, energyerror, resolution_error_sys85 ); + //cgr = new TGraphErrors( n, energy, resolution95, energyerror, resolution_error_sys95 ); + //cgr = new TGraphErrors( n, energy, resolution2, energyerror, resolution_error_sys2 ); + //cgr = new TGraphErrors( n, energy, resolution100, energyerror, resolution_error_sys100 ); + //cgr = new TGraphErrors( n, energy, resolution_hist, energyerror, resolution_error_sys_hist ); + //cgr = new TGraphErrors( n, energy, resolution2, energyerror, resolution_error_sys2 ); + cgr->GetYaxis()->SetTitle("#DeltaE_{reco} / E_{reco}"); + cgr->GetXaxis()->SetTitle("E_{true}, GeV"); + dgr = new TGraphErrors( n, energy, resolution_hist90, energyerror, resolution_error_stat_hist90 ); + //dgr = new TGraphErrors( n, energy, resolution85, energyerror, resolution_error_stat85 ); + //dgr = new TGraphErrors( n, energy, resolution95, energyerror, resolution_error_stat95 ); + //dgr = new TGraphErrors( n, energy, resolution2, energyerror, resolution_error_stat2 ); + //dgr = new TGraphErrors( n, energy, resolution100, energyerror, resolution_error_stat100 ); + //dgr = new TGraphErrors( n, energy, resolution_hist, energyerror, resolution_error_stat_hist ); + //dgr = new TGraphErrors( n, energy, resolution2, energyerror, resolution_error_stat2 ); + dgr->GetYaxis()->SetTitle("#DeltaE_{reco} / E_{reco}"); + dgr->GetXaxis()->SetTitle("E_{true}, GeV"); + egr = new TGraphErrors( n, energy, resolution_hist95, energyerror, resolution_error_sys_hist95 ); + //egr = new TGraphErrors( n, energy, resolution90, energyerror, resolution_error_sys90 ); + //egr = new TGraphErrors( n, energy, resolution100, energyerror, resolution_error_sys100 ); + //egr = new TGraphErrors( n, energy, resolution90, energyerror, resolution_error_sys90 ); + //egr = new TGraphErrors( n, energy, resolution_hist, energyerror, resolution_error_sys_hist ); + //egr = new TGraphErrors( n, energy, resolution90, energyerror, resolution_error_sys90 ); + //egr = new TGraphErrors( n, energy, resolution_hist, energyerror, resolution_error_sys_hist ); + egr->GetYaxis()->SetTitle("#DeltaE_{reco} / E_{reco}"); + egr->GetXaxis()->SetTitle("E_{true}, GeV"); + fgr = new TGraphErrors( n, energy, resolution_hist95, energyerror, resolution_error_stat_hist95 ); + //fgr = new TGraphErrors( n, energy, resolution90, energyerror, resolution_error_stat90 ); + //fgr = new TGraphErrors( n, energy, resolution100, energyerror, resolution_error_stat100 ); + //fgr = new TGraphErrors( n, energy, resolution90, energyerror, resolution_error_stat90 ); + //fgr = new TGraphErrors( n, energy, resolution_hist, energyerror, resolution_error_stat_hist ); + //fgr = new TGraphErrors( n, energy, resolution90, energyerror, resolution_error_stat90 ); + //fgr = new TGraphErrors( n, energy, resolution_hist, energyerror, resolution_error_stat_hist ); + fgr->GetYaxis()->SetTitle("#DeltaE_{reco} / E_{reco}"); + fgr->GetXaxis()->SetTitle("E_{true}, GeV"); + ggr = new TGraphErrors( n, energy, resolution_hist, energyerror, resolution_error_sys_hist ); + ggr->GetYaxis()->SetTitle("#DeltaE_{reco} / E_{reco}"); + ggr->GetXaxis()->SetTitle("E_{true}, GeV"); + hgr = new TGraphErrors( n, energy, resolution_hist, energyerror, resolution_error_stat_hist ); + hgr->GetYaxis()->SetTitle("#DeltaE_{reco} / E_{reco}"); + hgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Relative energy resolution" ); + agr->GetYaxis()->SetRangeUser(0.0, 0.30); + agr->SetTitle(fname); + + agr->SetFillColor(kCyan); + agr->SetFillStyle(3001); + agr->SetMarkerColor(kCyan); + agr->SetLineColor(kCyan); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); + agr->Draw("A 3"); + bgr->SetMarkerColor(kBlue); + bgr->SetLineColor(kBlue); + bgr->SetLineWidth(3); + bgr->SetFillColor(kCyan); + bgr->SetMarkerStyle(20); + bgr->Draw("P SAME"); + cgr->SetMarkerColor(kYellow-6); + cgr->SetFillStyle(3001); + cgr->SetLineColor(kYellow-6); + cgr->SetLineWidth(3); + cgr->SetFillColor(kYellow-6); + cgr->SetMarkerStyle(20); + cgr->Draw("3 SAME"); + dgr->SetMarkerColor(kRed); + dgr->SetLineColor(kRed); + dgr->SetLineWidth(3); + dgr->SetFillColor(kYellow-6); + dgr->SetMarkerStyle(20); + dgr->Draw("P SAME"); + egr->SetMarkerColor(kViolet-6); + egr->SetFillStyle(3001); + egr->SetLineColor(kViolet-6); + egr->SetLineWidth(3); + egr->SetFillColor(kViolet-6); + egr->SetMarkerStyle(20); + egr->Draw("3 SAME"); + fgr->SetMarkerColor(kGreen+1); + fgr->SetLineColor(kGreen+1); + fgr->SetLineWidth(3); + fgr->SetFillColor(kViolet-6); + fgr->SetMarkerStyle(20); + fgr->Draw("P SAME"); + ggr->SetMarkerColor(kMagenta-10); + ggr->SetFillStyle(3001); + ggr->SetLineColor(kMagenta-10); + ggr->SetLineWidth(3); + ggr->SetFillColor(kMagenta-10); + ggr->SetMarkerStyle(20); + ggr->Draw("3 SAME"); + hgr->SetMarkerColor(kMagenta+1); + hgr->SetLineColor(kMagenta+1); + hgr->SetLineWidth(3); + hgr->SetFillColor(kMagenta-10); + hgr->SetMarkerStyle(20); + hgr->Draw("P SAME"); + c4->Update(); + + TLegend *lsc1 = new TLegend(0.55,0.62,0.90,0.92); + lsc1->AddEntry(bgr,"fit (stat)","pl"); + lsc1->AddEntry(dgr,"hist90_2 (stat)","pl"); + lsc1->AddEntry(fgr,"hist95_2 (stat)","pl"); + lsc1->AddEntry(hgr,"hist (stat)","pl"); + //lsc1->AddEntry(bgr,"hist90 (w/o errors)","pl"); + //lsc1->AddEntry(dgr,"hist95 (w/o errors)","pl"); + //lsc1->AddEntry(fgr,"hist90_2 (stat)","pl"); + //lsc1->AddEntry(hgr,"hist95_2 (stat)","pl"); + //lsc1->AddEntry(bgr,"fit (stat)","pl"); + //lsc1->AddEntry(dgr,"hist90 (w/o errors)","pl"); + //lsc1->AddEntry(fgr,"hist95 (w/o errors)","pl"); + //lsc1->AddEntry(hgr,"hist (stat)","pl"); + //lsc1->AddEntry(bgr,"data, rms80 w/o errors","plf"); + //lsc1->AddEntry(dgr,"data, rms85 w/o errors","plf"); + //lsc1->AddEntry(fgr,"data, rms90 w/o errors","plf"); + //lsc1->AddEntry(bgr,"data, rms90 w/o errors","plf"); + //lsc1->AddEntry(dgr,"data, rms95 w/o errors","plf"); + //lsc1->AddEntry(fgr,"data, rms100 w/o errors","plf"); + //lsc1->AddEntry(bgr,"data, fit 1","plf"); + //lsc1->AddEntry(dgr,"data, fit 2 (stat)","plf"); + //lsc1->AddEntry(fgr,"data, rms90 w/o errors","plf"); + //lsc1->AddEntry(bgr,"data, rms90 w/o errors","plf"); + //lsc1->AddEntry(dgr,"data, rms100 w/o errors","plf"); + //lsc1->AddEntry(fgr,"data, rms_hist (stat)","plf"); + //lsc1->AddEntry(bgr,"data, fit 2 (stat)","plf"); + //lsc1->AddEntry(dgr,"data, rms_hist (stat)","plf"); + //lsc1->AddEntry(fgr,"data, rms90 w/o errors","plf"); + //lsc1->AddEntry(bgr,"data, fit 1","plf"); + //lsc1->AddEntry(dgr,"data, fit 2 (stat)","plf"); + //lsc1->AddEntry(fgr,"data, rms_hist (stat)","plf"); + + TLegend *lsc2 = new TLegend(0.55,0.62,0.90,0.92); + lsc2->AddEntry(bgr,"fit (stat)","pl"); + lsc2->AddEntry(dgr,"hist90_2 (stat)","pl"); + lsc2->AddEntry(fgr,"hist95_2 (stat)","pl"); + lsc2->AddEntry(hgr,"hist (stat)","pl"); + + TLegend *lsc3 = new TLegend(0.55,0.62,0.90,0.92); + lsc3->AddEntry(bgr,"fit (stat)","pl"); + lsc3->AddEntry(dgr,"hist90_2 (stat)","pl"); + lsc3->AddEntry(fgr,"hist95_2 (stat)","pl"); + lsc3->AddEntry(hgr,"hist (stat)","pl"); + + TLegend *lsc4 = new TLegend(0.55,0.62,0.90,0.92); + lsc4->AddEntry(bgr,"fit (stat)","pl"); + lsc4->AddEntry(dgr,"hist90_2 (stat)","pl"); + lsc4->AddEntry(fgr,"hist95_2 (stat)","pl"); + lsc4->AddEntry(hgr,"hist (stat)","pl"); + + c1->cd(); + lsc1->Draw(); + c2->cd(); + lsc2->Draw(); + c3->cd(); + lsc3->Draw(); + c4->cd(); + lsc4->Draw(); + +} diff --git a/graph_oldold.c b/graph_oldold.c new file mode 100644 index 0000000..e18ebe3 --- /dev/null +++ b/graph_oldold.c @@ -0,0 +1,304 @@ +void graph() { + TCanvas *c1 = new TCanvas("graph1","graph1",200,10,700,500); + TCanvas *c2 = new TCanvas("graph2","graph2",200,10,700,500); + TCanvas *c3 = new TCanvas("graph3","graph3",200,10,700,500); + TCanvas *c4 = new TCanvas("graph4","graph4",200,10,700,500); + + //c1->SetFillColor(42); + //gStyle->SetPalette(52); + c1->SetGrid(); + c2->SetGrid(); + c3->SetGrid(); + c4->SetGrid(); + //c1->GetFrame()->SetFillColor(21); + //c1->GetFrame()->SetBorderSize(12); + + const Int_t n = 16; + + Float_t energy[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t energyerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_mean[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_mean[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_meanerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_meanerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_sigma[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_sigma[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_sigmaerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_sigmaerror[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_chi[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_chi[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t linearity_error[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t absolute_error[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_stat[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_sys[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + Float_t energy2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t energyerror2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_mean2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_mean2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_meanerror2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_meanerror2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_sigma2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_sigma2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_sigmaerror2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_sigmaerror2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t mean_chi2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t rms_chi2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t linearity_error2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t absolute_error2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_stat2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error_sys2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t ratio_error2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_stat2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error_sys2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + Float_t resolution_error2[n] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + +/* + for (int i = 0; i < n; i++) { + printf( " %f ", energy[i] ); + printf( " %f ", energyerror[i] ); + printf( " %f ", mean[i] ); + printf( " %f ", meanerror[i] ); + printf( " %f ", sigma[i] ); + printf( " %f ", sigmaerror[i] ); + printf( " %f ", value[i] ); + printf( " %f ", error[i] ); + printf( "\n" ); + } +*/ + FILE *file1 = fopen("out0_5000.txt", "r"); + if ( !(long)file1 ) return; + + FILE *file2 = fopen("out1.txt", "r"); + if ( !(long)file2 ) return; + + for ( int i = 0; i < n; i++ ) { + fscanf( file1, "%f %E %E %E %E %E %E %E\n", &energy[i], &mean_mean[i], &rms_mean[i], &mean_meanerror[i], &mean_sigma[i], &rms_sigma[i], &mean_sigmaerror[i], &mean_chi[i] ); + if ( feof( file1 ) ) break; + } + + for ( int i = 0; i < n; i++ ) { + fscanf( file2, "%f %E %E %E %E %E %E %E\n", &energy2[i], &mean_mean2[i], &rms_mean2[i], &mean_meanerror2[i], &mean_sigma2[i], &rms_sigma2[i], &mean_sigmaerror2[i], &mean_chi2[i] ); + if ( feof( file2 ) ) break; + } + + for ( int i = 0; i < n; i++ ) { + + linearity_error[ i ] = sqrt( ( pow( mean_meanerror[ i ], 2 ) ) + ( pow( rms_mean[ i ], 2 ) ) ); + absolute_error[ i ] = sqrt( ( pow( mean_sigmaerror[ i ], 2 ) ) + ( pow( rms_sigma[ i ], 2 ) ) ); + + ratio[ i ] = ( mean_mean[i] - energy[i] ) / energy[i]; + ratio_error_stat[ i ] = sqrt( pow( (mean_meanerror[i])/(energy[i]), 2 ) + pow( (mean_mean[i] * energyerror[i])/(energy[i] * energy[i]), 2 ) ); + ratio_error_sys[ i ] = sqrt( pow( (rms_mean[i])/(energy[i]), 2 ) + pow( (mean_mean[i] * energyerror[i])/(energy[i] * energy[i]), 2 ) ); + ratio_error[ i ] = sqrt( ( pow( ratio_error_stat[ i ], 2 ) ) + ( pow( ratio_error_sys[ i ], 2 ) ) ); + + resolution[ i ] = mean_sigma[i] / mean_mean[i]; + resolution_error_stat[ i ] = sqrt( pow( (mean_sigmaerror[i])/(mean_mean[i]), 2 ) + pow( (mean_sigma[i] * mean_meanerror[i])/(mean_mean[i] * mean_mean[i]), 2 ) ); + resolution_error_sys[ i ] = sqrt( pow( (rms_sigma[i])/(mean_mean[i]), 2 ) + pow( (mean_sigma[i] * rms_mean[i])/(mean_mean[i] * mean_mean[i]), 2 ) ); + resolution_error[ i ] = sqrt( ( pow( resolution_error_stat[ i ], 2 ) ) + ( pow( resolution_error_sys[ i ], 2 ) ) ); + + } + + for ( int i = 0; i < n; i++ ) { + + linearity_error2[ i ] = sqrt( ( pow( mean_meanerror2[ i ], 2 ) ) + ( pow( rms_mean2[ i ], 2 ) ) ); + absolute_error2[ i ] = sqrt( ( pow( mean_sigmaerror2[ i ], 2 ) ) + ( pow( rms_sigma2[ i ], 2 ) ) ); + + ratio2[ i ] = ( mean_mean2[i] - energy2[i] ) / energy2[i]; + ratio_error_stat2[ i ] = sqrt( pow( (mean_meanerror2[i])/(energy2[i]), 2 ) + pow( (mean_mean2[i] * energyerror2[i])/(energy2[i] * energy2[i]), 2 ) ); + ratio_error_sys2[ i ] = sqrt( pow( (rms_mean2[i])/(energy2[i]), 2 ) + pow( (mean_mean2[i] * energyerror2[i])/(energy2[i] * energy2[i]), 2 ) ); + ratio_error2[ i ] = sqrt( ( pow( ratio_error_stat2[ i ], 2 ) ) + ( pow( ratio_error_sys2[ i ], 2 ) ) ); + + resolution2[ i ] = mean_sigma2[i] / mean_mean2[i]; + resolution_error_stat2[ i ] = sqrt( pow( (mean_sigmaerror2[i])/(mean_mean2[i]), 2 ) + pow( (mean_sigma2[i] * mean_meanerror2[i])/(mean_mean2[i] * mean_mean2[i]), 2 ) ); + resolution_error_sys2[ i ] = sqrt( pow( (rms_sigma2[i])/(mean_mean2[i]), 2 ) + pow( (mean_sigma2[i] * rms_mean2[i])/(mean_mean2[i] * mean_mean2[i]), 2 ) ); + resolution_error2[ i ] = sqrt( ( pow( resolution_error_stat2[ i ], 2 ) ) + ( pow( resolution_error_sys2[ i ], 2 ) ) ); + + } + + printf( "\n" ); + for (int i = 0; i < n; i++) { + printf( " %f ", energy[i] ); + printf( " %f ", energyerror[i] ); + printf( " %f ", mean_mean[i] ); + printf( " %f ", rms_mean[i] ); + printf( " %f ", mean_meanerror[i] ); + printf( " %f ", rms_meanerror[i] ); + printf( " %f ", mean_sigma[i] ); + printf( " %f ", rms_sigma[i] ); + printf( " %f ", mean_sigmaerror[i] ); + printf( " %f ", rms_sigmaerror[i] ); + printf( " %f ", linearity_error[i] ); + printf( " %f ", absolute_error[i] ); + printf( " %f ", ratio[i] ); + printf( " %f ", ratio_error[i] ); + printf( " %f ", resolution[i] ); + printf( " %f ", resolution_error[i] ); + printf( "\n" ); + } + + printf( "\n" ); + for (int i = 0; i < n; i++) { + printf( " %f ", energy2[i] ); + printf( " %f ", energyerror2[i] ); + printf( " %f ", mean_mean2[i] ); + printf( " %f ", rms_mean2[i] ); + printf( " %f ", mean_meanerror2[i] ); + printf( " %f ", rms_meanerror2[i] ); + printf( " %f ", mean_sigma2[i] ); + printf( " %f ", rms_sigma2[i] ); + printf( " %f ", mean_sigmaerror2[i] ); + printf( " %f ", rms_sigmaerror2[i] ); + printf( " %f ", linearity_error2[i] ); + printf( " %f ", absolute_error2[i] ); + printf( " %f ", ratio2[i] ); + printf( " %f ", ratio_error2[i] ); + printf( " %f ", resolution2[i] ); + printf( " %f ", resolution_error2[i] ); + printf( "\n" ); + } + +/* printf( "Here is difference:\n" ); + + Float_t v1 = 0; + Float_t v2 = 0; + Float_t v3 = 0; + + for ( int i = 0; i < n; i++ ) { + printf( " %f, %f, %f, %f \n", energy[i], value[i], value2[i], value3[i] ); + printf( " Difference between nodigi and digi20: %f \n", value2[i] - value[i] ); + v1 = v1 + ( value2[i] - value[i] ); + printf( " Difference between digi20 and digi60: %f \n", value3[i] - value2[i] ); + v2 = v2 + ( value3[i] - value2[i] ); + printf( " Difference between nodigi and digi60: %f \n", value3[i] - value[i] ); + v3 = v3 + ( value3[i] - value[i] ); + } + + printf( "Average values: %f, %f, %f \n", v1/n, v2/n, v3/n ); +*/ + TGraphErrors *agr; + TGraphErrors *bgr; + + char fname[ 100 ]; + for ( int i = 0; i < 100; i++ ) fname[ i ] = 0; + + c1->cd(); + agr = new TGraphErrors( n, energy, mean_mean, energyerror, linearity_error ); + agr->GetYaxis()->SetTitle("E_{reco}, GeV"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy2, mean_mean2, energyerror2, linearity_error2 ); + bgr->GetYaxis()->SetTitle("E_{reco}, GeV"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Linearity" ); // Linearity energy resolution // Absolute energy resolution // Relative energy resolution + agr->SetTitle(fname); + + agr->SetMarkerColor(kBlue); // kBlue // 12 + agr->SetLineColor(kBlue); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); // 21 +// agr->SetMarkerSize(2); + agr->Draw("ALP"); + bgr->SetMarkerColor(kRed); // kRed // 15 + bgr->SetLineColor(kRed); + bgr->SetLineWidth(3); + bgr->SetMarkerStyle(29); // 21 +// bgr->SetMarkerSize(2); + bgr->Draw("LPSAME"); // LPSAME + c1->Update(); + + c2->cd(); + agr = new TGraphErrors( n, energy, ratio, energyerror, ratio_error ); + agr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy2, ratio2, energyerror2, ratio_error2 ); + bgr->GetYaxis()->SetTitle("( E_{reco} - E_{true} ) / E_{true}"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Linearity" ); // Linearity energy resolution // Absolute energy resolution // Relative energy resolution + agr->GetYaxis()->SetRangeUser(-0.3,0.8); + agr->SetTitle(fname); + + agr->SetMarkerColor(kBlue); // kBlue // 12 + agr->SetLineColor(kBlue); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); // 21 +// agr->SetMarkerSize(2); + agr->Draw("ALP"); + bgr->SetMarkerColor(kRed); // kRed // 15 + bgr->SetLineColor(kRed); + bgr->SetLineWidth(3); + bgr->SetMarkerStyle(29); // 21 +// bgr->SetMarkerSize(2); + bgr->Draw("LPSAME"); // LPSAME + c2->Update(); + + c3->cd(); + agr = new TGraphErrors( n, energy, mean_sigma, energyerror, absolute_error ); + agr->GetYaxis()->SetTitle("#sigma_{reco}, GeV"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy2, mean_sigma2, energyerror2, absolute_error2 ); + bgr->GetYaxis()->SetTitle("#sigma_{reco}, GeV"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Absolute energy resolution" ); // Linearity energy resolution // Absolute energy resolution // Relative energy resolution + agr->SetTitle(fname); + + agr->SetMarkerColor(kBlue); // kBlue // 12 + agr->SetLineColor(kBlue); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); // 21 +// agr->SetMarkerSize(2); + agr->Draw("ALP"); + bgr->SetMarkerColor(kRed); // kRed // 15 + bgr->SetLineColor(kRed); + bgr->SetLineWidth(3); + bgr->SetMarkerStyle(29); // 21 +// bgr->SetMarkerSize(2); + bgr->Draw("LPSAME"); // LPSAME + c3->Update(); + + c4->cd(); + agr = new TGraphErrors( n, energy, resolution, energyerror, resolution_error ); + agr->GetYaxis()->SetTitle("#sigma_{reco} / E_{reco}"); + agr->GetXaxis()->SetTitle("E_{true}, GeV"); + bgr = new TGraphErrors( n, energy2, resolution2, energyerror2, resolution_error2 ); + bgr->GetYaxis()->SetTitle("#sigma_{reco} / E_{reco}"); + bgr->GetXaxis()->SetTitle("E_{true}, GeV"); + sprintf( fname, "Relative energy resolution" ); // Linearity energy resolution // Absolute energy resolution // Relative energy resolution +// agr->GetYaxis()->SetRangeUser(0.03,0.45); + agr->SetTitle(fname); + + agr->SetMarkerColor(kBlue); // kBlue // 12 + agr->SetLineColor(kBlue); + agr->SetLineWidth(3); + agr->SetMarkerStyle(34); // 21 +// agr->SetMarkerSize(2); + agr->Draw("ALP"); + bgr->SetMarkerColor(kRed); // kRed // 15 + bgr->SetLineColor(kRed); + bgr->SetLineWidth(3); + bgr->SetMarkerStyle(29); // 21 +// bgr->SetMarkerSize(2); + bgr->Draw("LPSAME"); // LPSAME + c4->Update(); + + TLegend *lsc = new TLegend(0.55,0.62,0.90,0.92); + lsc->AddEntry(agr,"without ANN","pl"); + lsc->AddEntry(bgr,"with ANN","pl"); + + c1->cd(); + lsc->Draw(); + c2->cd(); + lsc->Draw(); + c3->cd(); + lsc->Draw(); + c4->cd(); + lsc->Draw(); + +} diff --git a/run_fit.c b/run_fit.c new file mode 100644 index 0000000..ab48ada --- /dev/null +++ b/run_fit.c @@ -0,0 +1,538 @@ +void fit_data( const int fenergy = 5, const int nBins = 1000 ) { + + char fname[ 200 ]; + char ftempname[ 200 ]; + char fname2[ 200 ]; + +// const float cut = sqrtf( float( fenergy ) ); + +// cout << "Cut === " << cut << endl; + + for ( int i = 0; i < 200; i++ ) fname[ i ] = 0; + for ( int i = 0; i < 200; i++ ) ftempname[ i ] = 0; + for ( int i = 0; i < 200; i++ ) fname2[ i ] = 0; + + sprintf( ftempname, "gun_k0L_%dgev_FTFP_BERT_5000evt_ILD_l5_v02steel", fenergy ); + sprintf( fname, "%s.root", ftempname ); + + TH1F *hist; + + TH1F *hist_mean; + TH1F *hist_sigma; + TH1F *hist_chi_full; + TH1F *hist_chi; + TH1F *hist_meanerror; + TH1F *hist_sigmaerror; + + TCanvas *c1 = new TCanvas("c1", "c1", 1); + + gStyle->SetOptStat(0); + + const char *treeName = "tree"; + const float binLo = 0.0; + const float binHi = fenergy + 30.0; + + const int nBins_fit = 10; + const float binHi_fit = ( binHi - fenergy ) / 2.0; + const float binHi_fit_error = binHi_fit - 8.0; + +// const float cut = 2.0; //0.6 * sqrt( energy ); + + // + // Open data file + // + std::cout << "Trying to open data file... "; + TFile *file = new TFile(fname, "READ"); + if (!file) { // if error occure then exit + std::cout << "[FAIL]" << std::endl; + return; + } + std::cout << "[OK]" << std::endl; + + // + // Open file for output + // + FILE *out = fopen("2out_data.txt", "a+"); + printf("File open... "); + if (!out) { + printf("[FAIL]\n"); + return; + } else printf("[OK]\n"); + + // + // Setup a TTree + // + std::cout << "Setup a tree... "; + TTree *tree = (TTree *)file->Get(treeName); + if (!tree) { + std::cout << "[FAIL]" << std::endl; + file->Close(); + return; + } + std::cout << "[OK]" << std::endl; + + unsigned int nEvents = tree->GetEntries(); + + // + // Setup a branch + // + Float_t energy = 0; + tree->SetBranchAddress("energy", &energy); + + // + // Create a histogram and random generator + // + hist = new TH1F("hist", "hist", nBins, binLo, binHi); + + hist_mean = new TH1F("hist_mean", "hist_mean", nBins_fit, binLo, binHi); + hist_sigma = new TH1F("hist_sigma", "hist_sigma", nBins_fit, binLo, binHi_fit); + hist_chi_full = new TH1F("hist_chi_full", "hist_chi_full", nBins_fit, binLo, binHi_fit); + hist_chi = new TH1F("hist_chi", "hist_chi", nBins_fit, binLo, binHi_fit); + hist_meanerror = new TH1F("hist_meanerror", "hist_meanerror", nBins_fit, binLo, binHi_fit_error); + hist_sigmaerror = new TH1F("hist_sigmaerror", "hist_sigmaerror", nBins_fit, binLo, binHi_fit_error); + + for ( int i = 0; i GetEntry(i); + if ( energy > 0 ) hist -> Fill( energy ); + } + + cout << "Underflow hist === " << hist->GetBinContent( 0 ) << endl; + cout << "Overflow hist === " << hist->GetBinContent( nBins + 1 ) << endl; + + float mean = hist -> GetMean(); + float meanerror = hist -> GetMeanError(); + float rms = hist -> GetRMS(); + float rmserror = hist -> GetRMSError(); + cout << " 0:" + << " Mean: " << mean + << " Mean error: " << meanerror + << " RMS: " << rms + << " RMS error: " << rmserror + << endl; + + float step = 0.1; + + float mass_chi_full[ 20 ]; + for ( int i = 0; i < 20; i++ ) mass_chi_full[ i ] = 0; + + float mass_chi[ 20 ]; + for ( int i = 0; i < 20; i++ ) mass_chi[ i ] = 0; + + float mass_mean[ 20 ]; + for ( int i = 0; i < 20; i++ ) mass_mean[ i ] = 0; + float mass_sigma[ 20 ]; + for ( int i = 0; i < 20; i++ ) mass_sigma[ i ] = 0; + float mass_meanerror[ 20 ]; + for ( int i = 0; i < 20; i++ ) mass_meanerror[ i ] = 0; + float mass_sigmaerror[ 20 ]; + for ( int i = 0; i < 20; i++ ) mass_sigmaerror[ i ] = 0; + + int i_const = 10; + + for ( int i = 10; i <= 25; i++ ) { + + cout << "i === " << i << endl; + float range = i * step; + + TF1 *fitFunc = new TF1("fitFunc", "gaus", mean - range * rms, mean + range * rms); + hist -> Fit( fitFunc, "R" ); + float fitmean = fitFunc -> GetParameter(1); + float fitsigma = fitFunc -> GetParameter(2); + float fitchi = fitFunc -> GetChisquare() / fitFunc -> GetNDF(); + float fitmeanerror = fitFunc -> GetParError(1); + float fitsigmaerror = fitFunc -> GetParError(2); + + hist_chi_full -> Fill( fitchi ); + mass_chi_full[ i - i_const ] = fitchi; + + if ( fitchi < 1.5 ) { + hist_mean -> Fill( fitmean ); + mass_mean[ i - i_const ] = fitmean; + + hist_sigma -> Fill( fitsigma ); + mass_sigma[ i - i_const ] = fitsigma; + + hist_chi -> Fill( fitchi ); + mass_chi[ i - i_const ] = fitchi; + + hist_meanerror -> Fill( fitmeanerror ); + mass_meanerror[ i - i_const ] = fitmeanerror; + + hist_sigmaerror -> Fill( fitsigmaerror ); + mass_sigmaerror[ i - i_const ] = fitsigmaerror; + } + + cout << " 1:" + << " Mean: " << fitmean + << " Mean error: " << fitmeanerror + << " Sigma: " << fitsigma + << " Sigma error: " << fitsigmaerror + << " Chi2/ndf: " << fitchi + << endl; + + sprintf( fname2, "%d_%s.jpg", i, ftempname ); + c1->SaveAs( fname2 ); + for ( int j = 0; j < 200; j++ ) fname2[ j ] = 0; + + delete fitFunc; + + } + + cout << "Underflow hist_mean === " << hist_mean->GetBinContent( 0 ) << endl; + cout << "Overflow hist_mean === " << hist_mean->GetBinContent( nBins_fit + 1 ) << endl; + + cout << "Underflow hist_sigma === " << hist_sigma->GetBinContent( 0 ) << endl; + cout << "Overflow hist_sigma === " << hist_sigma->GetBinContent( nBins_fit + 1 ) << endl; + + cout << "Underflow hist_chi === " << hist_chi->GetBinContent( 0 ) << endl; + cout << "Overflow hist_chi === " << hist_chi->GetBinContent( nBins_fit + 1 ) << endl; + + cout << "Underflow hist_chi_full === " << hist_chi_full->GetBinContent( 0 ) << endl; + cout << "Overflow hist_chi_full === " << hist_chi_full->GetBinContent( nBins_fit + 1 ) << endl; + + cout << "Underflow hist_meanerror === " << hist_meanerror->GetBinContent( 0 ) << endl; + cout << "Overflow hist_meanerror === " << hist_meanerror->GetBinContent( nBins_fit + 1 ) << endl; + + cout << "Underflow hist_sigmaerror === " << hist_sigmaerror->GetBinContent( 0 ) << endl; + cout << "Overflow hist_sigmaerror === " << hist_sigmaerror->GetBinContent( nBins_fit + 1 ) << endl; + + float min_chi = 2.5; + float min = 0.0; + int i_min = 0; + for ( int i = 0; i < 20; i++ ) { + + if ( mass_chi[ i ] > 0.0 ) { + + if ( mass_chi[ i ] < min_chi ) { + min_chi = mass_chi[ i ]; + i_min = i; + } + + } + + } + +// float mean_mean = hist_mean -> GetMean(); +// float rms_mean = hist_mean -> GetRMS(); + float mean_mean = mass_mean[ i_min ]; + cout << " Mean:" + << " Mean_mean: " << mean_mean +// << " RMS_mean: " << rms_mean + << endl; + +// float mean_sigma = hist_sigma -> GetMean(); +// float rms_sigma = hist_sigma -> GetRMS(); + float mean_sigma = mass_sigma[ i_min ]; + cout << " Sigma:" + << " Mean_sigma: " << mean_sigma +// << " RMS_sigma: " << rms_sigma + << endl; + +// float mean_chi = hist_chi -> GetMean(); +// float rms_chi = hist_chi -> GetRMS(); + float mean_chi = mass_chi[ i_min ]; + cout << " Chi:" + << " Mean_chi: " << mean_chi +// << " RMS_chi: " << rms_chi + << endl; + +// float mean_meanerror = hist_meanerror -> GetMean(); +// float rms_meanerror = hist_meanerror -> GetRMS(); + float mean_meanerror = mass_meanerror[ i_min ]; + cout << " Meanerror:" + << " Mean_meanerror: " << mean_meanerror +// << " RMS_meanerror: " << rms_meanerror + << endl; + +// float mean_sigmaerror = hist_sigmaerror -> GetMean(); +// float rms_sigmaerror = hist_sigmaerror -> GetRMS(); + float mean_sigmaerror = mass_sigmaerror[ i_min ]; + cout << " Sigmaerror:" + << " Mean_sigmaerror: " << mean_sigmaerror +// << " RMS_sigmaerror: " << rms_sigmaerror + << endl; + +// fprintf( out, "%d %E %E %E %E %E %E %E %E %E %E %E %E %E %E\n", fenergy, mean, meanerror, rms, rmserror, mean_mean, rms_mean, mean_meanerror, rms_meanerror, mean_sigma, rms_sigma, mean_sigmaerror, rms_sigmaerror, mean_chi, rms_chi ); +// fprintf( out, "%d %E %E %E %E %E %E %E %E %E %E %E\n", fenergy, mean, meanerror, rms, rmserror, mean_mean, rms_mean, mean_meanerror, mean_sigma, rms_sigma, mean_sigmaerror, mean_chi ); + fprintf( out, "%d %E %E %E %E %E %E %E %E %E\n", fenergy, mean, meanerror, rms, rmserror, mean_mean, mean_meanerror, mean_sigma, mean_sigmaerror, mean_chi ); + delete hist; + fclose( out ); + file -> Close(); + + for ( int i = 0; i < 20; i++ ) printf( "%E\n", mass_chi[ i ] ); + printf("-------------------\n"); + printf( "%E\n", mass_chi[ i_min ] ); + printf( "%E\n", min_chi ); + printf("-------------------\n"); + for ( int i = 0; i < 20; i++ ) printf( "%E\n", mass_chi_full[ i ] ); + +} + +/*void fit_ann( const int fenergy = 5, const int nBins = 1000 ) { + + char fname[ 200 ]; + char ftempname[ 200 ]; + char fname2[ 200 ]; + + char fname_tree[ 200 ]; + char fname_branch[ 200 ]; + +// const float cut = sqrtf( float( fenergy ) ); + +// cout << "Cut === " << cut << endl; + + for ( int i = 0; i < 200; i++ ) fname[ i ] = 0; + for ( int i = 0; i < 200; i++ ) ftempname[ i ] = 0; + for ( int i = 0; i < 200; i++ ) fname2[ i ] = 0; + + for ( int i = 0; i < 200; i++ ) fname_tree[ i ] = 0; + for ( int i = 0; i < 200; i++ ) fname_branch[ i ] = 0; + + sprintf( ftempname, "test_ann" ); + sprintf( fname, "%s.root", ftempname ); + + TH1F *hist; + + TH1F *hist_mean; + TH1F *hist_sigma; + TH1F *hist_chi_full; + TH1F *hist_chi; + TH1F *hist_meanerror; + TH1F *hist_sigmaerror; + + TCanvas *c1 = new TCanvas("c1", "c1", 1); + + gStyle->SetOptStat(0); + + sprintf( fname_tree, "tree%d", fenergy ); + + const char *treeName = fname_tree; + const float binLo = 0.0; + const float binHi = fenergy + 20.0; + + const int nBins_fit = 10; + const float binHi_fit = ( binHi - fenergy ) / 2.0; + const float binHi_fit_error = binHi_fit - 8.0; + +// const float cut = 2.0; //0.6 * sqrt( energy ); + + // + // Open data file + // + std::cout << "Trying to open data file... "; + TFile *file = new TFile(fname, "READ"); + if (!file) { // if error occure then exit + std::cout << "[FAIL]" << std::endl; + return; + } + std::cout << "[OK]" << std::endl; + + // + // Open file for output + // + FILE *out = fopen("2out_ann.txt", "a+"); + printf("File o2en... "); + if (!out) { + printf("[FAIL]\n"); + return; + } else printf("[OK]\n"); + + // + // Setup a TTree + // + std::cout << "Setup a tree... "; + TTree *tree = (TTree *)file->Get(treeName); + if (!tree) { + std::cout << "[FAIL]" << std::endl; + file->Close(); + return; + } + std::cout << "[OK]" << std::endl; + + unsigned int nEvents = tree->GetEntries(); + + sprintf( fname_branch, "ann%d", fenergy ); + + // + // Setup a branch + // + Float_t ann = 0; + tree->SetBranchAddress(fname_branch, &ann); + + // + // Create a histogram and random generator + // + hist = new TH1F("hist", "hist", nBins, binLo, binHi); + + hist_mean = new TH1F("hist_mean", "hist_mean", nBins_fit, binLo, binHi); + hist_sigma = new TH1F("hist_sigma", "hist_sigma", nBins_fit, binLo, binHi_fit); + hist_chi_full = new TH1F("hist_chi_full", "hist_chi_full", nBins_fit, binLo, binHi_fit); + hist_chi = new TH1F("hist_chi", "hist_chi", nBins_fit, binLo, binHi_fit); + hist_meanerror = new TH1F("hist_meanerror", "hist_meanerror", nBins_fit, binLo, binHi_fit_error); + hist_sigmaerror = new TH1F("hist_sigmaerror", "hist_sigmaerror", nBins_fit, binLo, binHi_fit_error); + + for ( int i = 0; i GetEntry(i); + if ( ann > 0 ) hist -> Fill( ann ); + } + + float mean = hist -> GetMean(); + float meanerror = hist -> GetMeanError(); + float rms = hist -> GetRMS(); + float rmserror = hist -> GetRMSError(); + cout << " 0:" + << " Mean: " << mean + << " Mean error: " << meanerror + << " RMS: " << rms + << " RMS error: " << rmserror + << endl; + + float step = 0.1; + + float mass_chi_full[ 20 ]; + for ( int i = 0; i < 20; i++ ) mass_chi_full[ i ] = 0; + + float mass_chi[ 20 ]; + for ( int i = 0; i < 20; i++ ) mass_chi[ i ] = 0; + + float mass_mean[ 20 ]; + for ( int i = 0; i < 20; i++ ) mass_mean[ i ] = 0; + float mass_sigma[ 20 ]; + for ( int i = 0; i < 20; i++ ) mass_sigma[ i ] = 0; + float mass_meanerror[ 20 ]; + for ( int i = 0; i < 20; i++ ) mass_meanerror[ i ] = 0; + float mass_sigmaerror[ 20 ]; + for ( int i = 0; i < 20; i++ ) mass_sigmaerror[ i ] = 0; + + int i_const = 10; + + for ( int i = 10; i <= 25; i++ ) { + + cout << "i === " << i << endl; + float range = i * step; + + TF1 *fitFunc = new TF1("fitFunc", "gaus", mean - range * rms, mean + range * rms); + hist -> Fit( fitFunc, "R" ); + float fitmean = fitFunc -> GetParameter(1); + float fitsigma = fitFunc -> GetParameter(2); + float fitchi = fitFunc -> GetChisquare() / fitFunc -> GetNDF(); + float fitmeanerror = fitFunc -> GetParError(1); + float fitsigmaerror = fitFunc -> GetParError(2); + + hist_chi_full -> Fill( fitchi ); + mass_chi_full[ i - i_const ] = fitchi; + + if ( fitchi < 2.5 ) { + hist_mean -> Fill( fitmean ); + mass_mean[ i - i_const ] = fitmean; + + hist_sigma -> Fill( fitsigma ); + mass_sigma[ i - i_const ] = fitsigma; + + hist_chi -> Fill( fitchi ); + mass_chi[ i - i_const ] = fitchi; + + hist_meanerror -> Fill( fitmeanerror ); + mass_meanerror[ i - i_const ] = fitmeanerror; + + hist_sigmaerror -> Fill( fitsigmaerror ); + mass_sigmaerror[ i - i_const ] = fitsigmaerror; + } + + cout << " 1:" + << " Mean: " << fitmean + << " Mean error: " << fitmeanerror + << " Sigma: " << fitsigma + << " Sigma error: " << fitsigmaerror + << " Chi2/ndf: " << fitchi + << endl; + + sprintf( fname2, "%d_%s_%d.jpg", i, ftempname, fenergy ); + c1->SaveAs( fname2 ); + for ( int j = 0; j < 200; j++ ) fname2[ j ] = 0; + + delete fitFunc; + + } + + float min_chi = 2.5; + float min = 0.0; + int i_min = 0; + for ( int i = 0; i < 20; i++ ) { + + if ( mass_chi[ i ] > 0.0 ) { + + if ( mass_chi[ i ] < min_chi ) { + min_chi = mass_chi[ i ]; + i_min = i; + } + + } + + } + + float mean_mean = hist_mean -> GetMean(); + float rms_mean = hist_mean -> GetRMS(); + cout << " Mean:" + << " Mean_mean: " << mean_mean + << " RMS_mean: " << rms_mean + << endl; + + float mean_sigma = hist_sigma -> GetMean(); + float rms_sigma = hist_sigma -> GetRMS(); + cout << " Sigma:" + << " Mean_sigma: " << mean_sigma + << " RMS_sigma: " << rms_sigma + << endl; + +// float mean_chi = hist_chi -> GetMean(); +// float rms_chi = hist_chi -> GetRMS(); + float mean_chi = mass_chi[ i_min ]; + cout << " Chi:" + << " Mean_chi: " << mean_chi +// << " RMS_chi: " << rms_chi + << endl; + +// float mean_meanerror = hist_meanerror -> GetMean(); +// float rms_meanerror = hist_meanerror -> GetRMS(); + float mean_meanerror = mass_meanerror[ i_min ]; + cout << " Meanerror:" + << " Mean_meanerror: " << mean_meanerror +// << " RMS_meanerror: " << rms_meanerror + << endl; + +// float mean_sigmaerror = hist_sigmaerror -> GetMean(); +// float rms_sigmaerror = hist_sigmaerror -> GetRMS(); + float mean_sigmaerror = mass_sigmaerror[ i_min ]; + cout << " Sigmaerror:" + << " Mean_sigmaerror: " << mean_sigmaerror +// << " RMS_sigmaerror: " << rms_sigmaerror + << endl; + +// fprintf( out, "%d %E %E %E %E %E %E %E %E %E %E %E %E %E %E\n", fenergy, mean, meanerror, rms, rmserror, mean_mean, rms_mean, mean_meanerror, rms_meanerror, mean_sigma, rms_sigma, mean_sigmaerror, rms_sigmaerror, mean_chi, rms_chi ); + fprintf( out, "%d %E %E %E %E %E %E %E %E %E %E %E\n", fenergy, mean, meanerror, rms, rmserror, mean_mean, rms_mean, mean_meanerror, mean_sigma, rms_sigma, mean_sigmaerror, mean_chi ); + delete hist; + fclose( out ); + file -> Close(); + + for ( int i = 0; i < 20; i++ ) printf( "%E\n", mass_chi[ i ] ); + printf("-------------------\n"); + printf( "%E\n", mass_chi[ i_min ] ); + printf( "%E\n", min_chi ); + printf("-------------------\n"); + for ( int i = 0; i < 20; i++ ) printf( "%E\n", mass_chi_full[ i ] ); + +} +*/ +void run_fit( const int bins = 1000 ) { + +// int mass[] = { 1, 2, 3, 4, 5, 10, 15, 20, 25, 30, 40, 50, 60, 70, 80, 90 }; + int mass[] = { 5, 10, 15, 20, 25, 30, 40, 50, 60 }; + int dim = 9; // 16 + + for (int i = 0; i < dim; i++ ) { + fit_data( mass[ i ], bins ); + //fit_ann( mass[ i ], bins ); + } + +} diff --git a/run_fit_chi_ratio.c b/run_fit_chi_ratio.c new file mode 100644 index 0000000..5bf7812 --- /dev/null +++ b/run_fit_chi_ratio.c @@ -0,0 +1,266 @@ +void fit_data( const int fenergy = 5, const int nBins = 1000 ) { + + char fname[ 200 ]; + char ftempname[ 200 ]; + char fname2[ 200 ]; + + char fname3[ 200 ]; + +// const float cut = sqrtf( float( fenergy ) ); + +// cout << "Cut === " << cut << endl; + + for ( int i = 0; i < 200; i++ ) fname[ i ] = 0; + for ( int i = 0; i < 200; i++ ) ftempname[ i ] = 0; + for ( int i = 0; i < 200; i++ ) fname2[ i ] = 0; + + for ( int i = 0; i < 200; i++ ) fname3[ i ] = 0; + sprintf( ftempname, "gun_k0L_%dgev_FTFP_BERT_5000evt_ILD_l5_v02steel", fenergy ); + sprintf( fname, "%s.root", ftempname ); + + TH1F *hist; + + TH1F *hist_mean; + TH1F *hist_sigma; + TH1F *hist_chi_full; + TH1F *hist_chi; + TH1F *hist_meanerror; + TH1F *hist_sigmaerror; + + TCanvas *c1 = new TCanvas("c1", "c1", 1); + + gStyle->SetOptStat(0); + + const char *treeName = "tree"; + const float binLo = 0.0; + const float binHi = fenergy + 30.0; + + const int nBins_fit = 10; + const float binHi_fit = ( binHi - fenergy ) / 2.0; + const float binHi_fit_error = binHi_fit - 8.0; + +// const float cut = 2.0; //0.6 * sqrt( energy ); + + // + // Open data file + // + std::cout << "Trying to open data file... "; + TFile *file = new TFile(fname, "READ"); + if (!file) { // if error occure then exit + std::cout << "[FAIL]" << std::endl; + return; + } + std::cout << "[OK]" << std::endl; + + sprintf( fname3, "%d_out_data.txt", fenergy ); + // + // Open file for output + // + FILE *out = fopen(fname3, "a+"); + printf("File open... "); + if (!out) { + printf("[FAIL]\n"); + return; + } else printf("[OK]\n"); + + // + // Setup a TTree + // + std::cout << "Setup a tree... "; + TTree *tree = (TTree *)file->Get(treeName); + if (!tree) { + std::cout << "[FAIL]" << std::endl; + file->Close(); + return; + } + std::cout << "[OK]" << std::endl; + + unsigned int nEvents = tree->GetEntries(); + + // + // Setup a branch + // + Float_t energy = 0; + tree->SetBranchAddress("energy", &energy); + + // + // Create a histogram and random generator + // + hist = new TH1F("hist", "hist", nBins, binLo, binHi); + TAxis *xaxis = hist->GetXaxis(); + + hist_mean = new TH1F("hist_mean", "hist_mean", nBins_fit, binLo, binHi); + hist_sigma = new TH1F("hist_sigma", "hist_sigma", nBins_fit, binLo, binHi_fit); + hist_chi_full = new TH1F("hist_chi_full", "hist_chi_full", nBins_fit, binLo, binHi_fit); + hist_chi = new TH1F("hist_chi", "hist_chi", nBins_fit, binLo, binHi_fit); + hist_meanerror = new TH1F("hist_meanerror", "hist_meanerror", nBins_fit, binLo, binHi_fit_error); + hist_sigmaerror = new TH1F("hist_sigmaerror", "hist_sigmaerror", nBins_fit, binLo, binHi_fit_error); + + for ( int i = 0; i GetEntry(i); + if ( energy > 0 ) hist -> Fill( energy ); + } + + cout << "Underflow hist === " << hist->GetBinContent( 0 ) << endl; + cout << "Overflow hist === " << hist->GetBinContent( nBins + 1 ) << endl; + + float mean = hist -> GetMean(); + float meanerror = hist -> GetMeanError(); + float rms = hist -> GetRMS(); + float rmserror = hist -> GetRMSError(); + cout << " 0:" + << " Mean: " << mean + << " Mean error: " << meanerror + << " RMS: " << rms + << " RMS error: " << rmserror + << endl; + + float step = 0.1; + + float mass_chi_full[ 20 ]; + for ( int i = 0; i < 20; i++ ) mass_chi_full[ i ] = 0; + + float mass_chi[ 20 ]; + for ( int i = 0; i < 20; i++ ) mass_chi[ i ] = 0; + + float mass_mean[ 20 ]; + for ( int i = 0; i < 20; i++ ) mass_mean[ i ] = 0; + float mass_sigma[ 20 ]; + for ( int i = 0; i < 20; i++ ) mass_sigma[ i ] = 0; + float mass_meanerror[ 20 ]; + for ( int i = 0; i < 20; i++ ) mass_meanerror[ i ] = 0; + float mass_sigmaerror[ 20 ]; + for ( int i = 0; i < 20; i++ ) mass_sigmaerror[ i ] = 0; + + int i_const = 10; + + int integral = 0; + float fraction = 0.0; + + for ( int i = 10; i <= 25; i++ ) { + + cout << "i === " << i << endl; + float range = i * step; + + TF1 *fitFunc = new TF1("fitFunc", "gaus", mean - range * rms, mean + range * rms); + hist -> Fit( fitFunc, "R" ); + float fitmean = fitFunc -> GetParameter(1); + float fitsigma = fitFunc -> GetParameter(2); + float fitchi = fitFunc -> GetChisquare() / fitFunc -> GetNDF(); + float fitmeanerror = fitFunc -> GetParError(1); + float fitsigmaerror = fitFunc -> GetParError(2); + + integral = hist->Integral( xaxis->FindBin( mean - range * rms ), xaxis->FindBin( mean + range * rms ) ); + cout << "Integral === " << integral << endl; + // cout << "Integral Error === " << hist->IntegralError( xaxis->FindBin( mean - range * rms ), xaxis->FindBin( mean + range * rms ) ) << endl; + cout << "chi === " << fitchi << endl; + + fraction = integral / hist->GetEntries(); + + fprintf( out, "%d %d %0.1f %E %d %f\n", fenergy, int( float( i ) - 10.0 ), ( float( i ) / 10.0 ), fitchi, integral, fraction ); + + hist_chi_full -> Fill( fitchi ); + mass_chi_full[ i - i_const ] = fitchi; + + if ( fitchi < 1.5 ) { + hist_mean -> Fill( fitmean ); + mass_mean[ i - i_const ] = fitmean; + + hist_sigma -> Fill( fitsigma ); + mass_sigma[ i - i_const ] = fitsigma; + + hist_chi -> Fill( fitchi ); + mass_chi[ i - i_const ] = fitchi; + + hist_meanerror -> Fill( fitmeanerror ); + mass_meanerror[ i - i_const ] = fitmeanerror; + + hist_sigmaerror -> Fill( fitsigmaerror ); + mass_sigmaerror[ i - i_const ] = fitsigmaerror; + } + + cout << " 1:" + << " Mean: " << fitmean + << " Mean error: " << fitmeanerror + << " Sigma: " << fitsigma + << " Sigma error: " << fitsigmaerror + << " Chi2/ndf: " << fitchi + << endl; + +// sprintf( fname2, "%d_%s.jpg", i, ftempname ); +// c1->SaveAs( fname2 ); +// for ( int j = 0; j < 200; j++ ) fname2[ j ] = 0; + + delete fitFunc; + + } + + cout << "Underflow hist_mean === " << hist_mean->GetBinContent( 0 ) << endl; + cout << "Overflow hist_mean === " << hist_mean->GetBinContent( nBins_fit + 1 ) << endl; + + cout << "Underflow hist_sigma === " << hist_sigma->GetBinContent( 0 ) << endl; + cout << "Overflow hist_sigma === " << hist_sigma->GetBinContent( nBins_fit + 1 ) << endl; + + cout << "Underflow hist_chi === " << hist_chi->GetBinContent( 0 ) << endl; + cout << "Overflow hist_chi === " << hist_chi->GetBinContent( nBins_fit + 1 ) << endl; + + cout << "Underflow hist_chi_full === " << hist_chi_full->GetBinContent( 0 ) << endl; + cout << "Overflow hist_chi_full === " << hist_chi_full->GetBinContent( nBins_fit + 1 ) << endl; + + cout << "Underflow hist_meanerror === " << hist_meanerror->GetBinContent( 0 ) << endl; + cout << "Overflow hist_meanerror === " << hist_meanerror->GetBinContent( nBins_fit + 1 ) << endl; + + cout << "Underflow hist_sigmaerror === " << hist_sigmaerror->GetBinContent( 0 ) << endl; + cout << "Overflow hist_sigmaerror === " << hist_sigmaerror->GetBinContent( nBins_fit + 1 ) << endl; + + float min_chi = 2.5; + float min = 0.0; + int i_min = 0; + for ( int i = 0; i < 20; i++ ) { + + if ( mass_chi[ i ] > 0.0 ) { + + if ( mass_chi[ i ] < min_chi ) { + min_chi = mass_chi[ i ]; + i_min = i; + } + + } + + } + +// float mean_chi = hist_chi -> GetMean(); +// float rms_chi = hist_chi -> GetRMS(); + float mean_chi = mass_chi[ i_min ]; + cout << " Chi:" + << " Mean_chi: " << mean_chi +// << " RMS_chi: " << rms_chi + << endl; + +// fprintf( out, "%d %E %E %E %E %E %E %E %E %E %E %E %E %E %E\n", fenergy, mean, meanerror, rms, rmserror, mean_mean, rms_mean, mean_meanerror, rms_meanerror, mean_sigma, rms_sigma, mean_sigmaerror, rms_sigmaerror, mean_chi, rms_chi ); +// fprintf( out, "%d %E %E %E %E %E %E %E %E %E %E %E\n", fenergy, mean, meanerror, rms, rmserror, mean_mean, rms_mean, mean_meanerror, mean_sigma, rms_sigma, mean_sigmaerror, mean_chi ); + // fprintf( out, "%d %E %E %E %E %E %E %E %E %E\n", fenergy, mean, meanerror, rms, rmserror, mean_mean, mean_meanerror, mean_sigma, mean_sigmaerror, mean_chi ); + delete hist; + fclose( out ); + file -> Close(); + + for ( int i = 0; i < 20; i++ ) printf( "%E\n", mass_chi[ i ] ); + printf("-------------------\n"); + printf( "%E\n", mass_chi[ i_min ] ); + printf( "%E\n", min_chi ); + printf("-------------------\n"); + for ( int i = 0; i < 20; i++ ) printf( "%E\n", mass_chi_full[ i ] ); + +} + +void run_fit_chi_ratio( const int bins = 1000 ) { + +// int mass[] = { 1, 2, 3, 4, 5, 10, 15, 20, 25, 30, 40, 50, 60, 70, 80, 90 }; + int mass[] = { 5, 10, 15, 20, 25, 30, 40, 50, 60 }; + int dim = 9; // 16 + + for (int i = 0; i < dim; i++ ) { + fit_data( mass[ i ], bins ); + } + +} diff --git a/run_fit_rms.c b/run_fit_rms.c new file mode 100644 index 0000000..70308ae --- /dev/null +++ b/run_fit_rms.c @@ -0,0 +1,929 @@ +/* +void f4(const TH1F *const pTH1F, float &resolution, float &resolutionError, bool fixDistributionCentre, bool print) +{ + static const float FLOAT_MAX(std::numeric_limits::max()); + + if (NULL == pTH1F) + return; + + if (5 > pTH1F->GetEntries()) + { + std::cout << pTH1F->GetName() << " (" << pTH1F->GetEntries() << " entries) - skipped" << std::endl; + return; + } + + // Calculate raw properties of distribution + float sum = 0., total = 0.; + double sx = 0., sxx = 0.; + const unsigned int nbins(pTH1F->GetNbinsX()); + + for (unsigned int i = 0; i <= nbins; ++i) + { + const float binx(pTH1F->GetBinLowEdge(i) + (0.5 * pTH1F->GetBinWidth(i))); + const float yi(pTH1F->GetBinContent(i)); + sx += yi * binx; + sxx += yi * binx * binx; + total += yi; + } + + const float rawMean(sx / total); + const float rawMeanSquared(sxx / total); + const float rawRms(std::sqrt(rawMeanSquared - rawMean * rawMean)); + + sum = 0.; + unsigned int is0 = 0; + + for (unsigned int i = 0; (i <= nbins) && (sum < total / 10.); ++i) + { + sum += pTH1F->GetBinContent(i); + is0 = i; + } + + // Calculate truncated properties + float rmsmin(FLOAT_MAX), sigma(FLOAT_MAX), sigmasigma(FLOAT_MAX), frac(FLOAT_MAX), efrac(FLOAT_MAX), mean(FLOAT_MAX), low(FLOAT_MAX), rms(FLOAT_MAX); + float high(0.f); + + for (unsigned int istart = 0; istart <= is0; ++istart) + { + double sumn = 0.; + double csum = 0.; + double sumx = 0.; + double sumxx = 0.; + unsigned int iend = 0; + + for (unsigned int i = istart; (i <= nbins) && (csum < 0.9 * total); ++i) + { + const float binx(pTH1F->GetBinLowEdge(i) + (0.5 * pTH1F->GetBinWidth(i))); + const float yi(pTH1F->GetBinContent(i)); + csum += yi; + + if (sumn < 0.9 * total) + { + sumn += yi; + sumx += yi * binx; + sumxx+= yi * binx * binx; + iend = i; + } + } + + const float localMean(sumx / sumn); + const float localMeanSquared(sumxx / sumn); + const float localRms(std::sqrt(localMeanSquared - localMean * localMean)); + + if (localRms < rmsmin) + { + mean = localMean; + rms = localRms; + low = pTH1F->GetBinLowEdge(istart); + high = pTH1F->GetBinLowEdge(iend); + rmsmin = localRms; + + if (fixDistributionCentre) + { + float centre = 91.2; + + if (mean > 3500.) + { + //throw InvalidEnergyException(); + cout << "QWQWQWQWQWQWQWQWQWQWQWQWQWQWQWQWQWQWQWQWQWQWQWQW" << endl; + } + + if ((mean > 2500.) && (mean < 3500.)) + centre = 3000.; + + if ((mean > 1500.) && (mean < 2500.)) + centre = 2000.; + + if ((mean > 700.) && (mean < 1500.)) + centre = 1000.; + + if ((mean > 400.) && (mean < 700.)) + centre = 500.; + + if ((mean > 250.) && (mean < 400.)) + centre = 360.; + + if ((mean > 150.) && (mean < 250.)) + centre = 200.; + + sigma = rms / mean * sqrt(centre); + sigmasigma = sigma / std::sqrt(total); + + frac = rms / mean * std::sqrt(2) * 100.; + efrac = frac / std::sqrt(total); + } + else + { + sigma = rms; + sigmasigma = sigma / std::sqrt(total); + } + } + } + + if (print) + { + std::cout << pTH1F->GetName() << " (" << pTH1F->GetEntries() << " entries), rawrms: " << rawRms << ", rms90: " << rmsmin + << " (" << low << "-" << high << "), mean: " << mean << ", sigma: " << sigma << "+-" << sigmasigma; + (fixDistributionCentre) ? (std::cout << ", sE/E: " << frac << "+-" << efrac << std::endl) : (std::cout << std::endl); + } + + resolution = frac; + resolutionError = efrac; +} + +void f3(const TH1F *const m_histogram) +{ + static const float FLOAT_MAX(std::numeric_limits::max()); + + float m_fitRangeLow(std::numeric_limits::max()); + float m_fitRangeHigh(std::numeric_limits::max()); + float m_rMSFitRange(std::numeric_limits::max()); + + float m_fitPercentage = 90.0; + + if (NULL == m_histogram) + return; + + if (5 > m_histogram->GetEntries()) + { + std::cout << m_histogram->GetName() << " (" << m_histogram->GetEntries() << " entries) - skipped" << std::endl; + return; + } + + // Calculate raw properties of distribution (ie rms100) + float sum = 0., total = 0.; + double sx = 0., sxx = 0.; + const unsigned int nbins(m_histogram->GetNbinsX()); + + for (unsigned int i = 0; i <= nbins; ++i) + { + const float binx(m_histogram->GetBinLowEdge(i) + (0.5 * m_histogram->GetBinWidth(i))); + const float yi(m_histogram->GetBinContent(i)); + sx += yi * binx; + sxx += yi * binx * binx; + total += yi; + } + + const float rawMean(sx / total); + const float rawMeanSquared(sxx / total); + const float rawRms(std::sqrt(rawMeanSquared - rawMean * rawMean)); + + sum = 0.; + unsigned int is0 = 0; + + // The /10 comes from the fact that for rms 90 the start point for the fit must occur in the first 10% of the data. + float frac = (1 - (m_fitPercentage/100.0)); + for (unsigned int i = 0; (i <= nbins) && (sum < total * frac); ++i) + { + sum += m_histogram->GetBinContent(i); + is0 = i; + } + + // Calculate truncated properties + float rmsmin(FLOAT_MAX), mean(FLOAT_MAX), low(FLOAT_MAX); + float high(0.f); + + for (unsigned int istart = 0; istart <= is0; ++istart) + { + double sumn = 0.; + double csum = 0.; + double sumx = 0.; + double sumxx = 0.; + unsigned int iend = 0; + + for (unsigned int i = istart; (i <= nbins) && (csum < (m_fitPercentage/100) * total); ++i) + { + const float binx(m_histogram->GetBinLowEdge(i) + (0.5 * m_histogram->GetBinWidth(i))); + const float yi(m_histogram->GetBinContent(i)); + //csum is the sum of yi from istart and is used to stop the sum when this exceeds X% of data. + csum += yi; + + if (sumn < (m_fitPercentage/100) * total) + { + // These variables define the final sums required once we have considered X% of data, anything else is + // continuously overwritten. + sumn += yi; + sumx += yi * binx; + sumxx+= yi * binx * binx; + iend = i; + } + } + + const float localMean(sumx / sumn); + const float localMeanSquared(sumxx / sumn); + // Standard deviation formula + const float localRms(std::sqrt(localMeanSquared - localMean * localMean)); + + if (localRms < rmsmin) + { + mean = localMean; + if (istart==0) + { + low = 0; + m_fitRangeLow = 0; + } + else + { + low = m_histogram->GetBinLowEdge(istart); + m_fitRangeLow=m_histogram->GetBinLowEdge(istart) + (0.5 * m_histogram->GetBinWidth(istart)); + } + + high = m_histogram->GetBinLowEdge(iend); + rmsmin = localRms; + m_fitRangeHigh=m_histogram->GetBinLowEdge(iend) + (0.5 * m_histogram->GetBinWidth(iend)); + } + } + + m_rMSFitRange = rmsmin; + + std::cout << m_histogram->GetName() << " (" << m_histogram->GetEntries() << " entries), rawrms: " << rawRms << ", rmsx: " << rmsmin + << " (" << low << "-" << high << "), low_fit and high_fit " << " (" << m_fitRangeLow << "-" << m_fitRangeHigh + << "), << mean: " << mean << std::endl; +} +*/ + +void f2(const TH1F *const pTH1F, float &resolution, float &resolutionError, float &scale, float &scaleError, bool print) +{ + static const float FLOAT_MAX(std::numeric_limits::max()); + + if (NULL == pTH1F) + return; + + if (5 > pTH1F->GetEntries()) + { + std::cout << pTH1F->GetName() << " (" << pTH1F->GetEntries() << " entries) - skipped" << std::endl; + return; + } + + // Calculate raw properties of distribution + float sum = 0., total = 0.; + double sx = 0., sxx = 0.; + const unsigned int nbins(pTH1F->GetNbinsX()); + + for (unsigned int i = 0; i <= nbins; ++i) + { + const float binx(pTH1F->GetBinLowEdge(i) + (0.5 * pTH1F->GetBinWidth(i))); + const float yi(pTH1F->GetBinContent(i)); + sx += yi * binx; + sxx += yi * binx * binx; + total += yi; + } + + const float rawMean(sx / total); + const float rawMeanSquared(sxx / total); + const float rawRms(std::sqrt(rawMeanSquared - rawMean * rawMean)); + + sum = 0.; + unsigned int is0 = 0; + + for (unsigned int i = 0; (i <= nbins) && (sum < total / 10.); ++i) + { + sum += pTH1F->GetBinContent(i); + is0 = i; + } + + // Calculate truncated properties + float rmsmin(FLOAT_MAX), sigma(FLOAT_MAX), sigmasigma(FLOAT_MAX), frac(FLOAT_MAX), efrac(FLOAT_MAX), mean(FLOAT_MAX), low(FLOAT_MAX), rms(FLOAT_MAX); + float high(0.f); + + for (unsigned int istart = 0; istart <= is0; ++istart) + { + double sumn = 0.; + double csum = 0.; + double sumx = 0.; + double sumxx = 0.; + unsigned int iend = 0; + + for (unsigned int i = istart; (i <= nbins) && (csum < 0.9 * total); ++i) + { + const float binx(pTH1F->GetBinLowEdge(i) + (0.5 * pTH1F->GetBinWidth(i))); + const float yi(pTH1F->GetBinContent(i)); + csum += yi; + + if (sumn < 0.9 * total) + { + sumn += yi; + sumx += yi * binx; + sumxx+= yi * binx * binx; + iend = i; + } + } + + const float localMean(sumx / sumn); + const float localMeanSquared(sumxx / sumn); + const float localRms(std::sqrt(localMeanSquared - localMean * localMean)); + + if (localRms < rmsmin) + { + mean = localMean; + rms = localRms; + low = pTH1F->GetBinLowEdge(istart); + high = pTH1F->GetBinLowEdge(iend); + rmsmin = localRms; + + sigma = rms; + sigmasigma = sigma / std::sqrt(total); + + frac = rms / mean * std::sqrt(2) * 100.; + efrac = frac / std::sqrt(total); + } + } + + if (print) + { + std::cout << pTH1F->GetName() << " (" << pTH1F->GetEntries() << " entries), rawrms: " << rawRms << ", rms90: " << rmsmin + << " (" << low << "-" << high << "), mean: " << mean << ", sigma: " << sigma << "+-" << sigmasigma; + std::cout << ", sE/E: " << frac << "+-" << efrac << std::endl; + } + + resolution = frac; + resolutionError = efrac; + scale = mean; + scaleError = sigma; +} + +void f( TH1* h, float &value, float &a, float &b, int &l, int &r ) { + cout << "Value === " << value << endl; + cout << "Value / 100.0 === " << value / 100.0 << endl; + TAxis* axis = h -> GetXaxis(); + Int_t nbins = axis -> GetNbins(); + Int_t imean = axis -> FindBin( h -> GetMean() ); + Double_t entries = ( value / 100.0 ) * ( h -> GetEntries() ); + Double_t w = h -> GetBinContent( imean ); + Double_t x = h -> GetBinCenter( imean ); + Double_t sumw = w; + Double_t sumwx = w*x; + Double_t sumwx2 = w*x*x; + for ( Int_t i = 1; i < nbins; i++ ) { + if ( i > 0 ) { + w = h -> GetBinContent( imean - i ); + x = h -> GetBinCenter( imean - i ); + l = imean - i; + sumw += w; + sumwx += w*x; + sumwx2 += w*x*x; + } + if ( i <= nbins ) { + w = h -> GetBinContent( imean + i ); + x = h -> GetBinCenter( imean + i ); + r = imean + i; + sumw += w; + sumwx += w*x; + sumwx2 += w*x*x; + } + if ( sumw > entries ) break; + } + x = sumwx / sumw; + Double_t rms2 = TMath::Abs( ( sumwx2 / sumw ) - ( x * x ) ); + Double_t result = TMath::Sqrt( rms2 ); + printf( "RMS of central %0.f%% = %f, RMS total = %f, Mean of central %.f%% = %f, Mean total = %f\n", value, result, h -> GetRMS(), value, x, h -> GetMean() ); + a = x; + b = result; +} + +void fit_data( const int fenergy = 5, const int nBins = 1000 ) { + + char fname[ 200 ]; + char ftempname[ 200 ]; + char fname2[ 200 ]; + + for ( int i = 0; i < 200; i++ ) fname[ i ] = 0; + for ( int i = 0; i < 200; i++ ) ftempname[ i ] = 0; + for ( int i = 0; i < 200; i++ ) fname2[ i ] = 0; + + sprintf( ftempname, "gun_k0L_%dgev_FTFP_BERT_5000evt_ILD_l5_v02steel", fenergy ); + sprintf( fname, "%s.root", ftempname ); + + TH1F *hist; + //TH1F *hist90; + //TH1F *hist95; + + TH1F *hist2; + TH1F *hist3; + TH1F *hist4; + TH1F *hist5; + TH1F *hist6; + TH1F *hist7; + + TH1F *hist_mean; + TH1F *hist_sigma; + TH1F *hist_chi_full; + TH1F *hist_chi; + TH1F *hist_meanerror; + TH1F *hist_sigmaerror; + + TCanvas *c1 = new TCanvas("c1", "c1", 1); +/* TCanvas *c2 = new TCanvas("c2", "c2", 1); + TCanvas *c3 = new TCanvas("c3", "c3", 1); + TCanvas *c4 = new TCanvas("c4", "c4", 1); + + TCanvas *c5 = new TCanvas("c5", "c5", 1); + TCanvas *c6 = new TCanvas("c6", "c6", 1); + TCanvas *c7 = new TCanvas("c7", "c7", 1); + TCanvas *c8 = new TCanvas("c8", "c8", 1); + */ + gStyle->SetOptStat(0); + + const char *treeName = "tree"; + const float binLo = 0.0; + const float binHi = fenergy + 30.0; + + const int nBins_fit = 10; + const float binHi_fit = ( binHi - fenergy ) / 2.0; + const float binHi_fit_error = binHi_fit - 8.0; + + // + // Open data file + // + std::cout << "Trying to open data file... "; + TFile *file = new TFile(fname, "READ"); + if (!file) { // if error occure then exit + std::cout << "[FAIL]" << std::endl; + return; + } + std::cout << "[OK]" << std::endl; + + // + // Open file for output + // + FILE *out = fopen("2out_data.txt", "a+"); + printf("File open... "); + if (!out) { + printf("[FAIL]\n"); + return; + } else printf("[OK]\n"); + + // + // Setup a TTree + // + std::cout << "Setup a tree... "; + TTree *tree = (TTree *)file->Get(treeName); + if (!tree) { + std::cout << "[FAIL]" << std::endl; + file->Close(); + return; + } + std::cout << "[OK]" << std::endl; + + unsigned int nEvents = tree->GetEntries(); + + // + // Setup a branch + // + Float_t energy = 0; + tree->SetBranchAddress("energy", &energy); + + // + // Create a histogram and random generator + // + hist = new TH1F("hist", "hist", nBins, binLo, binHi); + + hist_mean = new TH1F("hist_mean", "hist_mean", nBins_fit, binLo, binHi); + hist_sigma = new TH1F("hist_sigma", "hist_sigma", nBins_fit, binLo, binHi_fit); + hist_chi_full = new TH1F("hist_chi_full", "hist_chi_full", nBins_fit, binLo, binHi_fit); + hist_chi = new TH1F("hist_chi", "hist_chi", nBins_fit, binLo, binHi_fit); + hist_meanerror = new TH1F("hist_meanerror", "hist_meanerror", nBins_fit, binLo, binHi_fit_error); + hist_sigmaerror = new TH1F("hist_sigmaerror", "hist_sigmaerror", nBins_fit, binLo, binHi_fit_error); + + for ( int i = 0; i GetEntry(i); + if ( energy > 0 ) hist -> Fill( energy ); + } + +// cout << "Underflow hist === " << hist->GetBinContent( 0 ) << endl; +// cout << "Overflow hist === " << hist->GetBinContent( nBins + 1 ) << endl; + + float mean = hist -> GetMean(); + float meanerror = hist -> GetMeanError(); + float rms = hist -> GetRMS(); + float rmserror = hist -> GetRMSError(); + cout << " 0:" + << " Mean: " << mean + << " Mean error: " << meanerror + << " RMS: " << rms + << " RMS error: " << rmserror + << endl; + + cout << "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" << endl; + cout << "f2:" << endl; + float res = 0.0; + float reserror = 0.0; + float sc = 0.0; + float scerror = 0.0; + bool pr = 1; + f2( hist, res, reserror, sc, scerror, pr ); + +/* cout << "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" << endl; + cout << "f3:" << endl; + f3( hist ); + + cout << "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" << endl; + cout << "f4:" << endl; + float res4 = 0.0; + float reserror4 = 0.0; + bool fix4 = 1; + bool pr4 = 1; + f4( hist, res4, reserror4, fix4, pr4 ); +*/ + cout << "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" << endl; + + cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl; + float value90 = 90.0; + float mean90 = 0; + float rms90 = 0; + int left90 = 0; + int right90 = 0; + f( hist, value90, mean90, rms90, left90, right90 ); + cout << "mean90 = " << mean90 << " and rms90 = " << rms90 << endl; + cout << "left90 = " << left90 << " and right90 = " << right90 << endl; + cout << "Left value 90 = " << hist->GetBinCenter( left90 ) << " and right value 90 = " << hist->GetBinCenter( right90 ) << endl; + + float value95 = 95.0; + float mean95 = 0; + float rms95 = 0; + int left95 = 0; + int right95 = 0; + f( hist, value95, mean95, rms95, left95, right95 ); + cout << "mean95 = " << mean95 << " and rms95 = " << rms95 << endl; + cout << "left95 = " << left95 << " and right95 = " << right95 << endl; + cout << "Left value 95 = " << hist->GetBinCenter( left95 ) << " and right value 95 = " << hist->GetBinCenter( right95 ) << endl; + + float value96 = 96.0; + float mean96 = 0; + float rms96 = 0; + int left96 = 0; + int right96 = 0; + f( hist, value96, mean96, rms96, left96, right96 ); + cout << "mean96 = " << mean96 << " and rms96 = " << rms96 << endl; + cout << "left96 = " << left96 << " and right96 = " << right96 << endl; + cout << "Left value 96 = " << hist->GetBinCenter( left96 ) << " and right value 96 = " << hist->GetBinCenter( right96 ) << endl; + + float value97 = 97.0; + float mean97 = 0; + float rms97 = 0; + int left97 = 0; + int right97 = 0; + f( hist, value97, mean97, rms97, left97, right97 ); + cout << "mean97 = " << mean97 << " and rms97 = " << rms97 << endl; + cout << "left97 = " << left97 << " and right97 = " << right97 << endl; + cout << "Left value 97 = " << hist->GetBinCenter( left97 ) << " and right value 97 = " << hist->GetBinCenter( right97 ) << endl; + + float value98 = 98.0; + float mean98 = 0; + float rms98 = 0; + int left98 = 0; + int right98 = 0; + f( hist, value98, mean98, rms98, left98, right98 ); + cout << "mean98 = " << mean98 << " and rms98 = " << rms98 << endl; + cout << "left98 = " << left98 << " and right98 = " << right98 << endl; + cout << "Left value 98 = " << hist->GetBinCenter( left98 ) << " and right value 98 = " << hist->GetBinCenter( right98 ) << endl; + + float value99 = 99.0; + float mean99 = 0; + float rms99 = 0; + int left99 = 0; + int right99 = 0; + f( hist, value99, mean99, rms99, left99, right99 ); + cout << "mean99 = " << mean99 << " and rms99 = " << rms99 << endl; + cout << "left99 = " << left99 << " and right99 = " << right99 << endl; + cout << "Left value 99 = " << hist->GetBinCenter( left99 ) << " and right value 99 = " << hist->GetBinCenter( right99 ) << endl; + cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl; + + //hist90 = new TH1F("hist90", "hist90", nBins, hist->GetBinCenter( left90 ), hist->GetBinCenter( right90 )); + //hist95 = new TH1F("hist95", "hist95", nBins, hist->GetBinCenter( left95 ), hist->GetBinCenter( right95 )); + + /*for ( int i = 0; i GetEntry(i); + if ( energy > 0 ) hist90 -> Fill( energy ); + if ( energy > 0 ) hist95 -> Fill( energy ); + }*/ + + hist2 = (TH1F*)hist->Clone(); + hist3 = (TH1F*)hist->Clone(); + hist4 = (TH1F*)hist->Clone(); + hist5 = (TH1F*)hist->Clone(); + hist6 = (TH1F*)hist->Clone(); + hist7 = (TH1F*)hist->Clone(); + + hist2->GetXaxis()->SetRange(left90, right90); + hist3->GetXaxis()->SetRange(left95, right95); + hist4->GetXaxis()->SetRange(left96, right96); + hist5->GetXaxis()->SetRange(left97, right97); + hist6->GetXaxis()->SetRange(left98, right98); + hist7->GetXaxis()->SetRange(left99, right99); + + cout << "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ" << endl; + + cout << "Underflow hist2 === " << hist2->GetBinContent( 0 ) << endl; + cout << "Overflow hist2 === " << hist2->GetBinContent( nBins + 1 ) << endl; + float mean_hist2 = hist2 -> GetMean(); + float meanerror_hist2 = hist2 -> GetMeanError(); + float rms_hist2 = hist2 -> GetRMS(); + float rmserror_hist2 = hist2 -> GetRMSError(); + cout << " 0:" + << " Mean2: " << mean_hist2 + << " Mean2 error: " << meanerror_hist2 + << " RMS2: " << rms_hist2 + << " RMS2 error: " << rmserror_hist2 + << endl; + + cout << "Underflow hist3 === " << hist3->GetBinContent( 0 ) << endl; + cout << "Overflow hist3 === " << hist3->GetBinContent( nBins + 1 ) << endl; + float mean_hist3 = hist3 -> GetMean(); + float meanerror_hist3 = hist3 -> GetMeanError(); + float rms_hist3 = hist3 -> GetRMS(); + float rmserror_hist3 = hist3 -> GetRMSError(); + cout << " 0:" + << " Mean3: " << mean_hist3 + << " Mean3 error: " << meanerror_hist3 + << " RMS3: " << rms_hist3 + << " RMS3 error: " << rmserror_hist3 + << endl; + + cout << "Underflow hist4 === " << hist4->GetBinContent( 0 ) << endl; + cout << "Overflow hist4 === " << hist4->GetBinContent( nBins + 1 ) << endl; + float mean_hist4 = hist4 -> GetMean(); + float meanerror_hist4 = hist4 -> GetMeanError(); + float rms_hist4 = hist4 -> GetRMS(); + float rmserror_hist4 = hist4 -> GetRMSError(); + cout << " 0:" + << " Mean4: " << mean_hist4 + << " Mean4 error: " << meanerror_hist4 + << " RMS4: " << rms_hist4 + << " RMS4 error: " << rmserror_hist4 + << endl; + + cout << "Underflow hist5 === " << hist5->GetBinContent( 0 ) << endl; + cout << "Overflow hist5 === " << hist5->GetBinContent( nBins + 1 ) << endl; + float mean_hist5 = hist5 -> GetMean(); + float meanerror_hist5 = hist5 -> GetMeanError(); + float rms_hist5 = hist5 -> GetRMS(); + float rmserror_hist5 = hist5 -> GetRMSError(); + cout << " 0:" + << " Mean5: " << mean_hist5 + << " Mean5 error: " << meanerror_hist5 + << " RMS5: " << rms_hist5 + << " RMS5 error: " << rmserror_hist5 + << endl; + + cout << "Underflow hist6 === " << hist6->GetBinContent( 0 ) << endl; + cout << "Overflow hist6 === " << hist6->GetBinContent( nBins + 1 ) << endl; + float mean_hist6 = hist6 -> GetMean(); + float meanerror_hist6 = hist6 -> GetMeanError(); + float rms_hist6 = hist6 -> GetRMS(); + float rmserror_hist6 = hist6 -> GetRMSError(); + cout << " 0:" + << " Mean6: " << mean_hist6 + << " Mean6 error: " << meanerror_hist6 + << " RMS6: " << rms_hist6 + << " RMS6 error: " << rmserror_hist6 + << endl; + + cout << "Underflow hist7 === " << hist7->GetBinContent( 0 ) << endl; + cout << "Overflow hist7 === " << hist7->GetBinContent( nBins + 1 ) << endl; + float mean_hist7 = hist7 -> GetMean(); + float meanerror_hist7 = hist7 -> GetMeanError(); + float rms_hist7 = hist7 -> GetRMS(); + float rmserror_hist7 = hist7 -> GetRMSError(); + cout << " 0:" + << " Mean7: " << mean_hist7 + << " Mean7 error: " << meanerror_hist7 + << " RMS7: " << rms_hist7 + << " RMS7 error: " << rmserror_hist7 + << endl; + + cout << "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ" << endl; + + float step = 0.1; + + float mass_chi_full[ 20 ]; + for ( int i = 0; i < 20; i++ ) mass_chi_full[ i ] = 0; + + float mass_chi[ 20 ]; + for ( int i = 0; i < 20; i++ ) mass_chi[ i ] = 0; + + float mass_mean[ 20 ]; + for ( int i = 0; i < 20; i++ ) mass_mean[ i ] = 0; + float mass_sigma[ 20 ]; + for ( int i = 0; i < 20; i++ ) mass_sigma[ i ] = 0; + float mass_meanerror[ 20 ]; + for ( int i = 0; i < 20; i++ ) mass_meanerror[ i ] = 0; + float mass_sigmaerror[ 20 ]; + for ( int i = 0; i < 20; i++ ) mass_sigmaerror[ i ] = 0; + + int i_const = 10; + + for ( int i = 10; i <= 25; i++ ) { + + cout << "i === " << i << endl; + float range = i * step; + + TF1 *fitFunc = new TF1("fitFunc", "gaus", mean - range * rms, mean + range * rms); + hist -> Fit( fitFunc, "R" ); + float fitmean = fitFunc -> GetParameter(1); + float fitsigma = fitFunc -> GetParameter(2); + float fitchi = fitFunc -> GetChisquare() / fitFunc -> GetNDF(); + float fitmeanerror = fitFunc -> GetParError(1); + float fitsigmaerror = fitFunc -> GetParError(2); + + hist_chi_full -> Fill( fitchi ); + mass_chi_full[ i - i_const ] = fitchi; + + if ( fitchi < 1.5 ) { + hist_mean -> Fill( fitmean ); + mass_mean[ i - i_const ] = fitmean; + + hist_sigma -> Fill( fitsigma ); + mass_sigma[ i - i_const ] = fitsigma; + + hist_chi -> Fill( fitchi ); + mass_chi[ i - i_const ] = fitchi; + + hist_meanerror -> Fill( fitmeanerror ); + mass_meanerror[ i - i_const ] = fitmeanerror; + + hist_sigmaerror -> Fill( fitsigmaerror ); + mass_sigmaerror[ i - i_const ] = fitsigmaerror; + } + + cout << " 1:" + << " Mean: " << fitmean + << " Mean error: " << fitmeanerror + << " Sigma: " << fitsigma + << " Sigma error: " << fitsigmaerror + << " Chi2/ndf: " << fitchi + << endl; + +// sprintf( fname2, "%d_%s.jpg", i, ftempname ); +// c1->SaveAs( fname2 ); +// for ( int j = 0; j < 200; j++ ) fname2[ j ] = 0; + + delete fitFunc; + + } +/* + c2 -> cd(); + hist -> SetMarkerStyle(20); + hist -> SetMarkerColor(kBlue); + hist -> SetLineColor(kBlue); + hist -> Draw("p e"); + c3 -> cd(); + hist90 -> SetMarkerStyle(20); + hist90 -> SetMarkerColor(kRed); + hist90 -> SetLineColor(kRed); + hist90 -> Draw("p e"); + c4 -> cd(); + hist95 -> SetMarkerStyle(20); + hist95 -> SetMarkerColor(kGreen); + hist95 -> SetLineColor(kGreen); + hist95 -> Draw("p e"); + + c5 -> cd(); + hist2 -> SetMarkerStyle(20); + hist2 -> SetMarkerColor(kRed); + hist2 -> SetLineColor(kRed); + hist2 -> Draw("p e"); + c6 -> cd(); + hist3 -> SetMarkerStyle(20); + hist3 -> SetMarkerColor(kGreen); + hist3 -> SetLineColor(kGreen); + hist3 -> Draw("p e"); + + c7 -> cd(); + hist->SetTitle("1"); + hist->GetYaxis()->SetTitle("Number of events"); + hist->GetXaxis()->SetTitle("Energy, GeV"); + hist -> SetMarkerStyle(20); + hist -> SetMarkerColor(kBlue); + hist -> SetLineColor(kBlue); + hist -> Draw("p e"); + hist2 -> SetMarkerStyle(20); + hist2 -> SetMarkerColor(kRed); + hist2 -> SetLineColor(kRed); + hist2 -> Draw("p e SAME"); +// hist3 -> SetMarkerStyle(20); +// hist3 -> SetMarkerColor(kGreen); +// hist3 -> SetLineColor(kGreen); +// hist3 -> Draw("p e SAME"); + + c8 -> cd(); + c8->Update(); + hist->SetTitle("Full distribution and 95% of the distribution"); + hist->GetYaxis()->SetTitle("Number of events"); + hist->GetXaxis()->SetTitle("Energy, GeV"); + hist -> SetMarkerStyle(20); + hist -> SetMarkerColor(kBlue); + hist -> SetLineColor(kBlue); + hist -> Draw("p e"); +// hist2 -> SetMarkerStyle(20); +// hist2 -> SetMarkerColor(kRed); +// hist2 -> SetLineColor(kRed); +// hist2 -> Draw("p e SAME"); + hist3 -> SetMarkerStyle(20); + hist3 -> SetMarkerColor(kGreen); + hist3 -> SetLineColor(kGreen); + hist3 -> Draw("p e SAME"); +*/ + +/* cout << "Underflow hist_mean === " << hist_mean->GetBinContent( 0 ) << endl; + cout << "Overflow hist_mean === " << hist_mean->GetBinContent( nBins_fit + 1 ) << endl; + + cout << "Underflow hist_sigma === " << hist_sigma->GetBinContent( 0 ) << endl; + cout << "Overflow hist_sigma === " << hist_sigma->GetBinContent( nBins_fit + 1 ) << endl; + + cout << "Underflow hist_chi === " << hist_chi->GetBinContent( 0 ) << endl; + cout << "Overflow hist_chi === " << hist_chi->GetBinContent( nBins_fit + 1 ) << endl; + + cout << "Underflow hist_chi_full === " << hist_chi_full->GetBinContent( 0 ) << endl; + cout << "Overflow hist_chi_full === " << hist_chi_full->GetBinContent( nBins_fit + 1 ) << endl; + + cout << "Underflow hist_meanerror === " << hist_meanerror->GetBinContent( 0 ) << endl; + cout << "Overflow hist_meanerror === " << hist_meanerror->GetBinContent( nBins_fit + 1 ) << endl; + + cout << "Underflow hist_sigmaerror === " << hist_sigmaerror->GetBinContent( 0 ) << endl; + cout << "Overflow hist_sigmaerror === " << hist_sigmaerror->GetBinContent( nBins_fit + 1 ) << endl; +*/ + float min_chi = 2.5; + float min = 0.0; + int i_min = 0; + for ( int i = 0; i < 20; i++ ) { + + if ( mass_chi[ i ] > 0.0 ) { + + if ( mass_chi[ i ] < min_chi ) { + min_chi = mass_chi[ i ]; + i_min = i; + } + + } + + } + +// float mean_mean = hist_mean -> GetMean(); +// float rms_mean = hist_mean -> GetRMS(); + float mean_mean = mass_mean[ i_min ]; + cout << " Mean:" + << " Mean_mean: " << mean_mean +// << " RMS_mean: " << rms_mean + << endl; + +// float mean_sigma = hist_sigma -> GetMean(); +// float rms_sigma = hist_sigma -> GetRMS(); + float mean_sigma = mass_sigma[ i_min ]; + cout << " Sigma:" + << " Mean_sigma: " << mean_sigma +// << " RMS_sigma: " << rms_sigma + << endl; + +// float mean_chi = hist_chi -> GetMean(); +// float rms_chi = hist_chi -> GetRMS(); + float mean_chi = mass_chi[ i_min ]; + cout << " Chi:" + << " Mean_chi: " << mean_chi +// << " RMS_chi: " << rms_chi + << endl; + +// float mean_meanerror = hist_meanerror -> GetMean(); +// float rms_meanerror = hist_meanerror -> GetRMS(); + float mean_meanerror = mass_meanerror[ i_min ]; + cout << " Meanerror:" + << " Mean_meanerror: " << mean_meanerror +// << " RMS_meanerror: " << rms_meanerror + << endl; + +// float mean_sigmaerror = hist_sigmaerror -> GetMean(); +// float rms_sigmaerror = hist_sigmaerror -> GetRMS(); + float mean_sigmaerror = mass_sigmaerror[ i_min ]; + cout << " Sigmaerror:" + << " Mean_sigmaerror: " << mean_sigmaerror +// << " RMS_sigmaerror: " << rms_sigmaerror + << endl; + +// fprintf( out, "%d %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E\n", fenergy, mean90, rms90, mean95, rms95, mean, meanerror, rms, rmserror, mean_mean, rms_mean, mean_meanerror, rms_meanerror, mean_sigma, rms_sigma, mean_sigmaerror, rms_sigmaerror, mean_chi, rms_chi ); +// fprintf( out, "%d %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E\n", fenergy, mean90, rms90, mean95, rms95, mean, meanerror, rms, rmserror, mean_mean, rms_mean, mean_meanerror, mean_sigma, rms_sigma, mean_sigmaerror, mean_chi ); + fprintf( out, "%d %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E\n", fenergy, mean_hist2, meanerror_hist2, rms_hist2, rmserror_hist2, mean_hist3, meanerror_hist3, rms_hist3, rmserror_hist3, mean_hist4, meanerror_hist4, rms_hist4, rmserror_hist4, mean_hist5, meanerror_hist5, rms_hist5, rmserror_hist5, mean_hist6, meanerror_hist6, rms_hist6, rmserror_hist6, mean_hist7, meanerror_hist7, rms_hist7, rmserror_hist7, mean, meanerror, rms, rmserror, mean_mean, mean_meanerror, mean_sigma, mean_sigmaerror, mean_chi ); + delete hist; + fclose( out ); + file -> Close(); + +/* for ( int i = 0; i < 20; i++ ) printf( "%E\n", mass_chi[ i ] ); + printf("-------------------\n"); + printf( "%E\n", mass_chi[ i_min ] ); + printf( "%E\n", min_chi ); + printf("-------------------\n"); + for ( int i = 0; i < 20; i++ ) printf( "%E\n", mass_chi_full[ i ] ); +*/ +} + +void run_fit_rms( const int bins = 1000 ) { + +// int mass[] = { 1, 2, 3, 4, 5, 10, 15, 20, 25, 30, 40, 50, 60, 70, 80, 90 }; + int mass[] = { 5, 10, 15, 20, 25, 30, 40, 50, 60 }; + int dim = 9; // 16 + + for (int i = 0; i < dim; i++ ) { + fit_data( mass[ i ], bins ); + //fit_ann( mass[ i ], bins ); + } + +} diff --git a/run_fit_rms_old.c b/run_fit_rms_old.c new file mode 100644 index 0000000..5e9f94f --- /dev/null +++ b/run_fit_rms_old.c @@ -0,0 +1,933 @@ +void f60( TH1* h, float &a, float &b ) { + TAxis* axis = h -> GetXaxis(); + Int_t nbins = axis -> GetNbins(); + Int_t imean = axis -> FindBin( h -> GetMean() ); + Double_t entries = 0.6 * ( h -> GetEntries() ); + Double_t w = h -> GetBinContent( imean ); + Double_t x = h -> GetBinCenter( imean ); + Double_t sumw = w; + Double_t sumwx = w*x; + Double_t sumwx2 = w*x*x; + for ( Int_t i = 1; i < nbins; i++ ) { + if ( i > 0 ) { + w = h -> GetBinContent( imean - i ); + x = h -> GetBinCenter( imean - i ); + sumw += w; + sumwx += w*x; + sumwx2 += w*x*x; + } + if ( i <= nbins ) { + w = h -> GetBinContent( imean + i ); + x = h -> GetBinCenter( imean + i ); + sumw += w; + sumwx += w*x; + sumwx2 += w*x*x; + } + if ( sumw > entries ) break; + } + x = sumwx / sumw; + Double_t rms2 = TMath::Abs( ( sumwx2 / sumw ) - ( x * x ) ); + Double_t result = TMath::Sqrt( rms2 ); + printf( "RMS of central 60%% = %f, RMS total = %f, Mean of central 60%% = %f, Mean total = %f\n", result, h -> GetRMS(), x, h -> GetMean() ); + a = x; + b = result; +} + +void f65( TH1* h, float &a, float &b ) { + TAxis* axis = h -> GetXaxis(); + Int_t nbins = axis -> GetNbins(); + Int_t imean = axis -> FindBin( h -> GetMean() ); + Double_t entries = 0.65 * ( h -> GetEntries() ); + Double_t w = h -> GetBinContent( imean ); + Double_t x = h -> GetBinCenter( imean ); + Double_t sumw = w; + Double_t sumwx = w*x; + Double_t sumwx2 = w*x*x; + for ( Int_t i = 1; i < nbins; i++ ) { + if ( i > 0 ) { + w = h -> GetBinContent( imean - i ); + x = h -> GetBinCenter( imean - i ); + sumw += w; + sumwx += w*x; + sumwx2 += w*x*x; + } + if ( i <= nbins ) { + w = h -> GetBinContent( imean + i ); + x = h -> GetBinCenter( imean + i ); + sumw += w; + sumwx += w*x; + sumwx2 += w*x*x; + } + if ( sumw > entries ) break; + } + x = sumwx / sumw; + Double_t rms2 = TMath::Abs( ( sumwx2 / sumw ) - ( x * x ) ); + Double_t result = TMath::Sqrt( rms2 ); + printf( "RMS of central 65%% = %f, RMS total = %f, Mean of central 65%% = %f, Mean total = %f\n", result, h -> GetRMS(), x, h -> GetMean() ); + a = x; + b = result; +} + +void f70( TH1* h, float &a, float &b ) { + TAxis* axis = h -> GetXaxis(); + Int_t nbins = axis -> GetNbins(); + Int_t imean = axis -> FindBin( h -> GetMean() ); + Double_t entries = 0.7 * ( h -> GetEntries() ); + Double_t w = h -> GetBinContent( imean ); + Double_t x = h -> GetBinCenter( imean ); + Double_t sumw = w; + Double_t sumwx = w*x; + Double_t sumwx2 = w*x*x; + for ( Int_t i = 1; i < nbins; i++ ) { + if ( i > 0 ) { + w = h -> GetBinContent( imean - i ); + x = h -> GetBinCenter( imean - i ); + sumw += w; + sumwx += w*x; + sumwx2 += w*x*x; + } + if ( i <= nbins ) { + w = h -> GetBinContent( imean + i ); + x = h -> GetBinCenter( imean + i ); + sumw += w; + sumwx += w*x; + sumwx2 += w*x*x; + } + if ( sumw > entries ) break; + } + x = sumwx / sumw; + Double_t rms2 = TMath::Abs( ( sumwx2 / sumw ) - ( x * x ) ); + Double_t result = TMath::Sqrt( rms2 ); + printf( "RMS of central 70%% = %f, RMS total = %f, Mean of central 70%% = %f, Mean total = %f\n", result, h -> GetRMS(), x, h -> GetMean() ); + a = x; + b = result; +} + +void f75( TH1* h, float &a, float &b ) { + TAxis* axis = h -> GetXaxis(); + Int_t nbins = axis -> GetNbins(); + Int_t imean = axis -> FindBin( h -> GetMean() ); + Double_t entries = 0.75 * ( h -> GetEntries() ); + Double_t w = h -> GetBinContent( imean ); + Double_t x = h -> GetBinCenter( imean ); + Double_t sumw = w; + Double_t sumwx = w*x; + Double_t sumwx2 = w*x*x; + for ( Int_t i = 1; i < nbins; i++ ) { + if ( i > 0 ) { + w = h -> GetBinContent( imean - i ); + x = h -> GetBinCenter( imean - i ); + sumw += w; + sumwx += w*x; + sumwx2 += w*x*x; + } + if ( i <= nbins ) { + w = h -> GetBinContent( imean + i ); + x = h -> GetBinCenter( imean + i ); + sumw += w; + sumwx += w*x; + sumwx2 += w*x*x; + } + if ( sumw > entries ) break; + } + x = sumwx / sumw; + Double_t rms2 = TMath::Abs( ( sumwx2 / sumw ) - ( x * x ) ); + Double_t result = TMath::Sqrt( rms2 ); + printf( "RMS of central 75%% = %f, RMS total = %f, Mean of central 75%% = %f, Mean total = %f\n", result, h -> GetRMS(), x, h -> GetMean() ); + a = x; + b = result; +} + +void f80( TH1* h, float &a, float &b ) { + TAxis* axis = h -> GetXaxis(); + Int_t nbins = axis -> GetNbins(); + Int_t imean = axis -> FindBin( h -> GetMean() ); + Double_t entries = 0.8 * ( h -> GetEntries() ); + Double_t w = h -> GetBinContent( imean ); + Double_t x = h -> GetBinCenter( imean ); + Double_t sumw = w; + Double_t sumwx = w*x; + Double_t sumwx2 = w*x*x; + for ( Int_t i = 1; i < nbins; i++ ) { + if ( i > 0 ) { + w = h -> GetBinContent( imean - i ); + x = h -> GetBinCenter( imean - i ); + sumw += w; + sumwx += w*x; + sumwx2 += w*x*x; + } + if ( i <= nbins ) { + w = h -> GetBinContent( imean + i ); + x = h -> GetBinCenter( imean + i ); + sumw += w; + sumwx += w*x; + sumwx2 += w*x*x; + } + if ( sumw > entries ) break; + } + x = sumwx / sumw; + Double_t rms2 = TMath::Abs( ( sumwx2 / sumw ) - ( x * x ) ); + Double_t result = TMath::Sqrt( rms2 ); + printf( "RMS of central 80%% = %f, RMS total = %f, Mean of central 80%% = %f, Mean total = %f\n", result, h -> GetRMS(), x, h -> GetMean() ); + a = x; + b = result; +} + +void f85( TH1* h, float &a, float &b ) { + TAxis* axis = h -> GetXaxis(); + Int_t nbins = axis -> GetNbins(); + Int_t imean = axis -> FindBin( h -> GetMean() ); + Double_t entries = 0.85 * ( h -> GetEntries() ); + Double_t w = h -> GetBinContent( imean ); + Double_t x = h -> GetBinCenter( imean ); + Double_t sumw = w; + Double_t sumwx = w*x; + Double_t sumwx2 = w*x*x; + for ( Int_t i = 1; i < nbins; i++ ) { + if ( i > 0 ) { + w = h -> GetBinContent( imean - i ); + x = h -> GetBinCenter( imean - i ); + sumw += w; + sumwx += w*x; + sumwx2 += w*x*x; + } + if ( i <= nbins ) { + w = h -> GetBinContent( imean + i ); + x = h -> GetBinCenter( imean + i ); + sumw += w; + sumwx += w*x; + sumwx2 += w*x*x; + } + if ( sumw > entries ) break; + } + x = sumwx / sumw; + Double_t rms2 = TMath::Abs( ( sumwx2 / sumw ) - ( x * x ) ); + Double_t result = TMath::Sqrt( rms2 ); + printf( "RMS of central 85%% = %f, RMS total = %f, Mean of central 85%% = %f, Mean total = %f\n", result, h -> GetRMS(), x, h -> GetMean() ); + a = x; + b = result; +} + +void f901( TH1* h, float &a, float &b ) { + TAxis* axis = h -> GetXaxis(); + Int_t nbins = axis -> GetNbins(); + Int_t imean = axis -> FindBin( h -> GetMean() ); + Double_t entries = 0.9 * ( h -> GetEntries() ); + Double_t w = h -> GetBinContent( imean ); + Double_t x = h -> GetBinCenter( imean ); + Double_t sumw = w; + Double_t sumwx = w*x; + Double_t sumwx2 = w*x*x; + for ( Int_t i = 1; i < nbins; i++ ) { + if ( i > 0 ) { + w = h -> GetBinContent( imean - i ); + x = h -> GetBinCenter( imean - i ); + sumw += w; + sumwx += w*x; + sumwx2 += w*x*x; + } + if ( i <= nbins ) { + w = h -> GetBinContent( imean + i ); + x = h -> GetBinCenter( imean + i ); + sumw += w; + sumwx += w*x; + sumwx2 += w*x*x; + } + if ( sumw > entries ) break; + } + x = sumwx; + Double_t rms2 = TMath::Abs( ( sumwx2 ) - ( x * x ) ); + Double_t result = TMath::Sqrt( rms2 ); + printf( "RMS of central 901%% = %f, RMS total = %f, Mean of central 901%% = %f, Mean total = %f\n", result, h -> GetRMS(), x, h -> GetMean() ); + a = x; + b = result; +} + +void f90( TH1* h, float &a, float &b ) { + TAxis* axis = h -> GetXaxis(); + Int_t nbins = axis -> GetNbins(); + Int_t imean = axis -> FindBin( h -> GetMean() ); + Double_t entries = 0.9 * ( h -> GetEntries() ); + Double_t w = h -> GetBinContent( imean ); + Double_t x = h -> GetBinCenter( imean ); + Double_t sumw = w; + Double_t sumwx = w*x; + Double_t sumwx2 = w*x*x; + for ( Int_t i = 1; i < nbins; i++ ) { + if ( i > 0 ) { + w = h -> GetBinContent( imean - i ); + x = h -> GetBinCenter( imean - i ); + sumw += w; + sumwx += w*x; + sumwx2 += w*x*x; + } + if ( i <= nbins ) { + w = h -> GetBinContent( imean + i ); + x = h -> GetBinCenter( imean + i ); + sumw += w; + sumwx += w*x; + sumwx2 += w*x*x; + } + if ( sumw > entries ) break; + } + x = sumwx / sumw; + Double_t rms2 = TMath::Abs( ( sumwx2 / sumw ) - ( x * x ) ); + Double_t result = TMath::Sqrt( rms2 ); + printf( "RMS of central 90%% = %f, RMS total = %f, Mean of central 90%% = %f, Mean total = %f\n", result, h -> GetRMS(), x, h -> GetMean() ); + a = x; + b = result; +} + +void f95( TH1* h, float &a, float &b ) { + TAxis* axis = h -> GetXaxis(); + Int_t nbins = axis -> GetNbins(); + Int_t imean = axis -> FindBin( h -> GetMean() ); + Double_t entries = 0.95 * ( h -> GetEntries() ); + Double_t w = h -> GetBinContent( imean ); + Double_t x = h -> GetBinCenter( imean ); + Double_t sumw = w; + Double_t sumwx = w*x; + Double_t sumwx2 = w*x*x; + for ( Int_t i = 1; i < nbins; i++ ) { + if ( i > 0 ) { + w = h -> GetBinContent( imean - i ); + x = h -> GetBinCenter( imean - i ); + sumw += w; + sumwx += w*x; + sumwx2 += w*x*x; + } + if ( i <= nbins ) { + w = h -> GetBinContent( imean + i ); + x = h -> GetBinCenter( imean + i ); + sumw += w; + sumwx += w*x; + sumwx2 += w*x*x; + } + if ( sumw > entries ) break; + } + x = sumwx / sumw; + Double_t rms2 = TMath::Abs( ( sumwx2 / sumw ) - ( x * x ) ); + Double_t result = TMath::Sqrt( rms2 ); + printf( "RMS of central 95%% = %f, RMS total = %f, Mean of central 95%% = %f, Mean total = %f\n", result, h -> GetRMS(), x, h -> GetMean() ); + a = x; + b = result; +} + +void f100( TH1* h, float &a, float &b ) { + TAxis* axis = h -> GetXaxis(); + Int_t nbins = axis -> GetNbins(); + Int_t imean = axis -> FindBin( h -> GetMean() ); + Double_t entries = 1.0 * ( h -> GetEntries() ); + Double_t w = h -> GetBinContent( imean ); + Double_t x = h -> GetBinCenter( imean ); + Double_t sumw = w; + Double_t sumwx = w*x; + Double_t sumwx2 = w*x*x; + for ( Int_t i = 1; i < nbins; i++ ) { + if ( i > 0 ) { + w = h -> GetBinContent( imean - i ); + x = h -> GetBinCenter( imean - i ); + sumw += w; + sumwx += w*x; + sumwx2 += w*x*x; + } + if ( i <= nbins ) { + w = h -> GetBinContent( imean + i ); + x = h -> GetBinCenter( imean + i ); + sumw += w; + sumwx += w*x; + sumwx2 += w*x*x; + } + if ( sumw > entries ) break; + } + x = sumwx / sumw; + Double_t rms2 = TMath::Abs( ( sumwx2 / sumw ) - ( x * x ) ); + Double_t result = TMath::Sqrt( rms2 ); + printf( "RMS of central 100%% = %f, RMS total = %f, Mean of central 100%% = %f, Mean total = %f\n", result, h -> GetRMS(), x, h -> GetMean() ); + a = x; + b = result; +} + +void fit_data( const int fenergy = 5, const int nBins = 1000 ) { + + char fname[ 200 ]; + char ftempname[ 200 ]; + char fname2[ 200 ]; + +// const float cut = sqrtf( float( fenergy ) ); + +// cout << "Cut === " << cut << endl; + + for ( int i = 0; i < 200; i++ ) fname[ i ] = 0; + for ( int i = 0; i < 200; i++ ) ftempname[ i ] = 0; + for ( int i = 0; i < 200; i++ ) fname2[ i ] = 0; + + sprintf( ftempname, "gun_k0L_%dgev_FTFP_BERT_5000evt_ILD_l5_v02steel", fenergy ); + sprintf( fname, "%s.root", ftempname ); + + TH1F *hist; + + TH1F *hist_mean; + TH1F *hist_sigma; + TH1F *hist_chi_full; + TH1F *hist_chi; + TH1F *hist_meanerror; + TH1F *hist_sigmaerror; + + TCanvas *c1 = new TCanvas("c1", "c1", 1); + + gStyle->SetOptStat(0); + + const char *treeName = "tree"; + const float binLo = 0.0; + const float binHi = fenergy + 30.0; + + const int nBins_fit = 10; + const float binHi_fit = ( binHi - fenergy ) / 2.0; + const float binHi_fit_error = binHi_fit - 8.0; + +// const float cut = 2.0; //0.6 * sqrt( energy ); + + // + // Open data file + // + std::cout << "Trying to open data file... "; + TFile *file = new TFile(fname, "READ"); + if (!file) { // if error occure then exit + std::cout << "[FAIL]" << std::endl; + return; + } + std::cout << "[OK]" << std::endl; + + // + // Open file for output + // + FILE *out = fopen("2out_data.txt", "a+"); + printf("File open... "); + if (!out) { + printf("[FAIL]\n"); + return; + } else printf("[OK]\n"); + + // + // Setup a TTree + // + std::cout << "Setup a tree... "; + TTree *tree = (TTree *)file->Get(treeName); + if (!tree) { + std::cout << "[FAIL]" << std::endl; + file->Close(); + return; + } + std::cout << "[OK]" << std::endl; + + unsigned int nEvents = tree->GetEntries(); + + // + // Setup a branch + // + Float_t energy = 0; + tree->SetBranchAddress("energy", &energy); + + // + // Create a histogram and random generator + // + hist = new TH1F("hist", "hist", nBins, binLo, binHi); + + hist_mean = new TH1F("hist_mean", "hist_mean", nBins_fit, binLo, binHi); + hist_sigma = new TH1F("hist_sigma", "hist_sigma", nBins_fit, binLo, binHi_fit); + hist_chi_full = new TH1F("hist_chi_full", "hist_chi_full", nBins_fit, binLo, binHi_fit); + hist_chi = new TH1F("hist_chi", "hist_chi", nBins_fit, binLo, binHi_fit); + hist_meanerror = new TH1F("hist_meanerror", "hist_meanerror", nBins_fit, binLo, binHi_fit_error); + hist_sigmaerror = new TH1F("hist_sigmaerror", "hist_sigmaerror", nBins_fit, binLo, binHi_fit_error); + + for ( int i = 0; i GetEntry(i); + if ( energy > 0 ) hist -> Fill( energy ); + } + + cout << "Underflow hist === " << hist->GetBinContent( 0 ) << endl; + cout << "Overflow hist === " << hist->GetBinContent( nBins + 1 ) << endl; + + float mean = hist -> GetMean(); + float meanerror = hist -> GetMeanError(); + float rms = hist -> GetRMS(); + float rmserror = hist -> GetRMSError(); + cout << " 0:" + << " Mean: " << mean + << " Mean error: " << meanerror + << " RMS: " << rms + << " RMS error: " << rmserror + << endl; + + cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl; + float mean60 = 0; + float rms60 = 0; + f60( hist, mean60, rms60 ); + cout << "mean60 = " << mean60 << " and rms60 = " << rms60 << endl; + float mean65 = 0; + float rms65 = 0; + f65( hist, mean65, rms65 ); + cout << "mean65 = " << mean65 << " and rms65 = " << rms65 << endl; + float mean70 = 0; + float rms70 = 0; + f70( hist, mean70, rms70 ); + cout << "mean70 = " << mean70 << " and rms70 = " << rms70 << endl; + float mean75 = 0; + float rms75 = 0; + f75( hist, mean75, rms75 ); + cout << "mean75 = " << mean75 << " and rms75 = " << rms75 << endl; + float mean80 = 0; + float rms80 = 0; + f80( hist, mean80, rms80 ); + cout << "mean80 = " << mean80 << " and rms80 = " << rms80 << endl; + float mean85 = 0; + float rms85 = 0; + f85( hist, mean85, rms85 ); + cout << "mean85 = " << mean85 << " and rms85 = " << rms85 << endl; + float mean90 = 0; + float rms90 = 0; + f90( hist, mean90, rms90 ); + cout << "mean90 = " << mean90 << " and rms90 = " << rms90 << endl; + + float mean901 = 0; + float rms901 = 0; + f901( hist, mean901, rms901 ); + cout << "mean901 = " << mean901 << " and rms901 = " << rms901 << endl; + + float mean95 = 0; + float rms95 = 0; + f95( hist, mean95, rms95 ); + cout << "mean95 = " << mean95 << " and rms95 = " << rms95 << endl; + float mean100 = 0; + float rms100 = 0; + f100( hist, mean100, rms100 ); + cout << "mean100 = " << mean100 << " and rms100 = " << rms100 << endl; + cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl; + + float step = 0.1; + + float mass_chi_full[ 20 ]; + for ( int i = 0; i < 20; i++ ) mass_chi_full[ i ] = 0; + + float mass_chi[ 20 ]; + for ( int i = 0; i < 20; i++ ) mass_chi[ i ] = 0; + + float mass_mean[ 20 ]; + for ( int i = 0; i < 20; i++ ) mass_mean[ i ] = 0; + float mass_sigma[ 20 ]; + for ( int i = 0; i < 20; i++ ) mass_sigma[ i ] = 0; + float mass_meanerror[ 20 ]; + for ( int i = 0; i < 20; i++ ) mass_meanerror[ i ] = 0; + float mass_sigmaerror[ 20 ]; + for ( int i = 0; i < 20; i++ ) mass_sigmaerror[ i ] = 0; + + int i_const = 10; + + for ( int i = 10; i <= 25; i++ ) { + + cout << "i === " << i << endl; + float range = i * step; + + TF1 *fitFunc = new TF1("fitFunc", "gaus", mean - range * rms, mean + range * rms); + hist -> Fit( fitFunc, "R" ); + float fitmean = fitFunc -> GetParameter(1); + float fitsigma = fitFunc -> GetParameter(2); + float fitchi = fitFunc -> GetChisquare() / fitFunc -> GetNDF(); + float fitmeanerror = fitFunc -> GetParError(1); + float fitsigmaerror = fitFunc -> GetParError(2); + + hist_chi_full -> Fill( fitchi ); + mass_chi_full[ i - i_const ] = fitchi; + + if ( fitchi < 1.5 ) { + hist_mean -> Fill( fitmean ); + mass_mean[ i - i_const ] = fitmean; + + hist_sigma -> Fill( fitsigma ); + mass_sigma[ i - i_const ] = fitsigma; + + hist_chi -> Fill( fitchi ); + mass_chi[ i - i_const ] = fitchi; + + hist_meanerror -> Fill( fitmeanerror ); + mass_meanerror[ i - i_const ] = fitmeanerror; + + hist_sigmaerror -> Fill( fitsigmaerror ); + mass_sigmaerror[ i - i_const ] = fitsigmaerror; + } + + cout << " 1:" + << " Mean: " << fitmean + << " Mean error: " << fitmeanerror + << " Sigma: " << fitsigma + << " Sigma error: " << fitsigmaerror + << " Chi2/ndf: " << fitchi + << endl; + + sprintf( fname2, "%d_%s.jpg", i, ftempname ); + c1->SaveAs( fname2 ); + for ( int j = 0; j < 200; j++ ) fname2[ j ] = 0; + + delete fitFunc; + + } + + cout << "Underflow hist_mean === " << hist_mean->GetBinContent( 0 ) << endl; + cout << "Overflow hist_mean === " << hist_mean->GetBinContent( nBins_fit + 1 ) << endl; + + cout << "Underflow hist_sigma === " << hist_sigma->GetBinContent( 0 ) << endl; + cout << "Overflow hist_sigma === " << hist_sigma->GetBinContent( nBins_fit + 1 ) << endl; + + cout << "Underflow hist_chi === " << hist_chi->GetBinContent( 0 ) << endl; + cout << "Overflow hist_chi === " << hist_chi->GetBinContent( nBins_fit + 1 ) << endl; + + cout << "Underflow hist_chi_full === " << hist_chi_full->GetBinContent( 0 ) << endl; + cout << "Overflow hist_chi_full === " << hist_chi_full->GetBinContent( nBins_fit + 1 ) << endl; + + cout << "Underflow hist_meanerror === " << hist_meanerror->GetBinContent( 0 ) << endl; + cout << "Overflow hist_meanerror === " << hist_meanerror->GetBinContent( nBins_fit + 1 ) << endl; + + cout << "Underflow hist_sigmaerror === " << hist_sigmaerror->GetBinContent( 0 ) << endl; + cout << "Overflow hist_sigmaerror === " << hist_sigmaerror->GetBinContent( nBins_fit + 1 ) << endl; + + float min_chi = 2.5; + float min = 0.0; + int i_min = 0; + for ( int i = 0; i < 20; i++ ) { + + if ( mass_chi[ i ] > 0.0 ) { + + if ( mass_chi[ i ] < min_chi ) { + min_chi = mass_chi[ i ]; + i_min = i; + } + + } + + } + +// float mean_mean = hist_mean -> GetMean(); +// float rms_mean = hist_mean -> GetRMS(); + float mean_mean = mass_mean[ i_min ]; + cout << " Mean:" + << " Mean_mean: " << mean_mean +// << " RMS_mean: " << rms_mean + << endl; + +// float mean_sigma = hist_sigma -> GetMean(); +// float rms_sigma = hist_sigma -> GetRMS(); + float mean_sigma = mass_sigma[ i_min ]; + cout << " Sigma:" + << " Mean_sigma: " << mean_sigma +// << " RMS_sigma: " << rms_sigma + << endl; + +// float mean_chi = hist_chi -> GetMean(); +// float rms_chi = hist_chi -> GetRMS(); + float mean_chi = mass_chi[ i_min ]; + cout << " Chi:" + << " Mean_chi: " << mean_chi +// << " RMS_chi: " << rms_chi + << endl; + +// float mean_meanerror = hist_meanerror -> GetMean(); +// float rms_meanerror = hist_meanerror -> GetRMS(); + float mean_meanerror = mass_meanerror[ i_min ]; + cout << " Meanerror:" + << " Mean_meanerror: " << mean_meanerror +// << " RMS_meanerror: " << rms_meanerror + << endl; + +// float mean_sigmaerror = hist_sigmaerror -> GetMean(); +// float rms_sigmaerror = hist_sigmaerror -> GetRMS(); + float mean_sigmaerror = mass_sigmaerror[ i_min ]; + cout << " Sigmaerror:" + << " Mean_sigmaerror: " << mean_sigmaerror +// << " RMS_sigmaerror: " << rms_sigmaerror + << endl; + +// fprintf( out, "%d %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E\n", fenergy, mean60, rms60, mean65, rms65, mean70, rms70, mean75, rms75, mean80, rms80, mean85, rms85, mean90, rms90, mean95, rms95, mean100, rms100, mean, meanerror, rms, rmserror, mean_mean, rms_mean, mean_meanerror, rms_meanerror, mean_sigma, rms_sigma, mean_sigmaerror, rms_sigmaerror, mean_chi, rms_chi ); +// fprintf( out, "%d %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E\n", fenergy, mean60, rms60, mean65, rms65, mean70, rms70, mean75, rms75, mean80, rms80, mean85, rms85, mean90, rms90, mean95, rms95, mean100, rms100, mean, meanerror, rms, rmserror, mean_mean, rms_mean, mean_meanerror, mean_sigma, rms_sigma, mean_sigmaerror, mean_chi ); + fprintf( out, "%d %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E %E\n", fenergy, mean60, rms60, mean65, rms65, mean70, rms70, mean75, rms75, mean80, rms80, mean85, rms85, mean90, rms90, mean95, rms95, mean100, rms100, mean, meanerror, rms, rmserror, mean_mean, mean_meanerror, mean_sigma, mean_sigmaerror, mean_chi ); + delete hist; + fclose( out ); + file -> Close(); + + for ( int i = 0; i < 20; i++ ) printf( "%E\n", mass_chi[ i ] ); + printf("-------------------\n"); + printf( "%E\n", mass_chi[ i_min ] ); + printf( "%E\n", min_chi ); + printf("-------------------\n"); + for ( int i = 0; i < 20; i++ ) printf( "%E\n", mass_chi_full[ i ] ); + +} + +/*void fit_ann( const int fenergy = 5, const int nBins = 1000 ) { + + char fname[ 200 ]; + char ftempname[ 200 ]; + char fname2[ 200 ]; + + char fname_tree[ 200 ]; + char fname_branch[ 200 ]; + +// const float cut = sqrtf( float( fenergy ) ); + +// cout << "Cut === " << cut << endl; + + for ( int i = 0; i < 200; i++ ) fname[ i ] = 0; + for ( int i = 0; i < 200; i++ ) ftempname[ i ] = 0; + for ( int i = 0; i < 200; i++ ) fname2[ i ] = 0; + + for ( int i = 0; i < 200; i++ ) fname_tree[ i ] = 0; + for ( int i = 0; i < 200; i++ ) fname_branch[ i ] = 0; + + sprintf( ftempname, "test_ann" ); + sprintf( fname, "%s.root", ftempname ); + + TH1F *hist; + + TH1F *hist_mean; + TH1F *hist_sigma; + TH1F *hist_chi_full; + TH1F *hist_chi; + TH1F *hist_meanerror; + TH1F *hist_sigmaerror; + + TCanvas *c1 = new TCanvas("c1", "c1", 1); + + gStyle->SetOptStat(0); + + sprintf( fname_tree, "tree%d", fenergy ); + + const char *treeName = fname_tree; + const float binLo = 0.0; + const float binHi = fenergy + 20.0; + + const int nBins_fit = 10; + const float binHi_fit = ( binHi - fenergy ) / 2.0; + const float binHi_fit_error = binHi_fit - 8.0; + +// const float cut = 2.0; //0.6 * sqrt( energy ); + + // + // Open data file + // + std::cout << "Trying to open data file... "; + TFile *file = new TFile(fname, "READ"); + if (!file) { // if error occure then exit + std::cout << "[FAIL]" << std::endl; + return; + } + std::cout << "[OK]" << std::endl; + + // + // Open file for output + // + FILE *out = fopen("2out_ann.txt", "a+"); + printf("File o2en... "); + if (!out) { + printf("[FAIL]\n"); + return; + } else printf("[OK]\n"); + + // + // Setup a TTree + // + std::cout << "Setup a tree... "; + TTree *tree = (TTree *)file->Get(treeName); + if (!tree) { + std::cout << "[FAIL]" << std::endl; + file->Close(); + return; + } + std::cout << "[OK]" << std::endl; + + unsigned int nEvents = tree->GetEntries(); + + sprintf( fname_branch, "ann%d", fenergy ); + + // + // Setup a branch + // + Float_t ann = 0; + tree->SetBranchAddress(fname_branch, &ann); + + // + // Create a histogram and random generator + // + hist = new TH1F("hist", "hist", nBins, binLo, binHi); + + hist_mean = new TH1F("hist_mean", "hist_mean", nBins_fit, binLo, binHi); + hist_sigma = new TH1F("hist_sigma", "hist_sigma", nBins_fit, binLo, binHi_fit); + hist_chi_full = new TH1F("hist_chi_full", "hist_chi_full", nBins_fit, binLo, binHi_fit); + hist_chi = new TH1F("hist_chi", "hist_chi", nBins_fit, binLo, binHi_fit); + hist_meanerror = new TH1F("hist_meanerror", "hist_meanerror", nBins_fit, binLo, binHi_fit_error); + hist_sigmaerror = new TH1F("hist_sigmaerror", "hist_sigmaerror", nBins_fit, binLo, binHi_fit_error); + + for ( int i = 0; i GetEntry(i); + if ( ann > 0 ) hist -> Fill( ann ); + } + + float mean = hist -> GetMean(); + float meanerror = hist -> GetMeanError(); + float rms = hist -> GetRMS(); + float rmserror = hist -> GetRMSError(); + cout << " 0:" + << " Mean: " << mean + << " Mean error: " << meanerror + << " RMS: " << rms + << " RMS error: " << rmserror + << endl; + + float step = 0.1; + + float mass_chi_full[ 20 ]; + for ( int i = 0; i < 20; i++ ) mass_chi_full[ i ] = 0; + + float mass_chi[ 20 ]; + for ( int i = 0; i < 20; i++ ) mass_chi[ i ] = 0; + + float mass_mean[ 20 ]; + for ( int i = 0; i < 20; i++ ) mass_mean[ i ] = 0; + float mass_sigma[ 20 ]; + for ( int i = 0; i < 20; i++ ) mass_sigma[ i ] = 0; + float mass_meanerror[ 20 ]; + for ( int i = 0; i < 20; i++ ) mass_meanerror[ i ] = 0; + float mass_sigmaerror[ 20 ]; + for ( int i = 0; i < 20; i++ ) mass_sigmaerror[ i ] = 0; + + int i_const = 10; + + for ( int i = 10; i <= 25; i++ ) { + + cout << "i === " << i << endl; + float range = i * step; + + TF1 *fitFunc = new TF1("fitFunc", "gaus", mean - range * rms, mean + range * rms); + hist -> Fit( fitFunc, "R" ); + float fitmean = fitFunc -> GetParameter(1); + float fitsigma = fitFunc -> GetParameter(2); + float fitchi = fitFunc -> GetChisquare() / fitFunc -> GetNDF(); + float fitmeanerror = fitFunc -> GetParError(1); + float fitsigmaerror = fitFunc -> GetParError(2); + + hist_chi_full -> Fill( fitchi ); + mass_chi_full[ i - i_const ] = fitchi; + + if ( fitchi < 2.5 ) { + hist_mean -> Fill( fitmean ); + mass_mean[ i - i_const ] = fitmean; + + hist_sigma -> Fill( fitsigma ); + mass_sigma[ i - i_const ] = fitsigma; + + hist_chi -> Fill( fitchi ); + mass_chi[ i - i_const ] = fitchi; + + hist_meanerror -> Fill( fitmeanerror ); + mass_meanerror[ i - i_const ] = fitmeanerror; + + hist_sigmaerror -> Fill( fitsigmaerror ); + mass_sigmaerror[ i - i_const ] = fitsigmaerror; + } + + cout << " 1:" + << " Mean: " << fitmean + << " Mean error: " << fitmeanerror + << " Sigma: " << fitsigma + << " Sigma error: " << fitsigmaerror + << " Chi2/ndf: " << fitchi + << endl; + + sprintf( fname2, "%d_%s_%d.jpg", i, ftempname, fenergy ); + c1->SaveAs( fname2 ); + for ( int j = 0; j < 200; j++ ) fname2[ j ] = 0; + + delete fitFunc; + + } + + float min_chi = 2.5; + float min = 0.0; + int i_min = 0; + for ( int i = 0; i < 20; i++ ) { + + if ( mass_chi[ i ] > 0.0 ) { + + if ( mass_chi[ i ] < min_chi ) { + min_chi = mass_chi[ i ]; + i_min = i; + } + + } + + } + + float mean_mean = hist_mean -> GetMean(); + float rms_mean = hist_mean -> GetRMS(); + cout << " Mean:" + << " Mean_mean: " << mean_mean + << " RMS_mean: " << rms_mean + << endl; + + float mean_sigma = hist_sigma -> GetMean(); + float rms_sigma = hist_sigma -> GetRMS(); + cout << " Sigma:" + << " Mean_sigma: " << mean_sigma + << " RMS_sigma: " << rms_sigma + << endl; + +// float mean_chi = hist_chi -> GetMean(); +// float rms_chi = hist_chi -> GetRMS(); + float mean_chi = mass_chi[ i_min ]; + cout << " Chi:" + << " Mean_chi: " << mean_chi +// << " RMS_chi: " << rms_chi + << endl; + +// float mean_meanerror = hist_meanerror -> GetMean(); +// float rms_meanerror = hist_meanerror -> GetRMS(); + float mean_meanerror = mass_meanerror[ i_min ]; + cout << " Meanerror:" + << " Mean_meanerror: " << mean_meanerror +// << " RMS_meanerror: " << rms_meanerror + << endl; + +// float mean_sigmaerror = hist_sigmaerror -> GetMean(); +// float rms_sigmaerror = hist_sigmaerror -> GetRMS(); + float mean_sigmaerror = mass_sigmaerror[ i_min ]; + cout << " Sigmaerror:" + << " Mean_sigmaerror: " << mean_sigmaerror +// << " RMS_sigmaerror: " << rms_sigmaerror + << endl; + +// fprintf( out, "%d %E %E %E %E %E %E %E %E %E %E %E %E %E %E\n", fenergy, mean, meanerror, rms, rmserror, mean_mean, rms_mean, mean_meanerror, rms_meanerror, mean_sigma, rms_sigma, mean_sigmaerror, rms_sigmaerror, mean_chi, rms_chi ); + fprintf( out, "%d %E %E %E %E %E %E %E %E %E %E %E\n", fenergy, mean, meanerror, rms, rmserror, mean_mean, rms_mean, mean_meanerror, mean_sigma, rms_sigma, mean_sigmaerror, mean_chi ); + delete hist; + fclose( out ); + file -> Close(); + + for ( int i = 0; i < 20; i++ ) printf( "%E\n", mass_chi[ i ] ); + printf("-------------------\n"); + printf( "%E\n", mass_chi[ i_min ] ); + printf( "%E\n", min_chi ); + printf("-------------------\n"); + for ( int i = 0; i < 20; i++ ) printf( "%E\n", mass_chi_full[ i ] ); + +} +*/ +void run_fit_rms_old( const int bins = 1000 ) { + +// int mass[] = { 1, 2, 3, 4, 5, 10, 15, 20, 25, 30, 40, 50, 60, 70, 80, 90 }; + int mass[] = { 5, 10, 15, 20, 25, 30, 40, 50, 60 }; + int dim = 9; // 16 + + for (int i = 0; i < dim; i++ ) { + fit_data( mass[ i ], bins ); + //fit_ann( mass[ i ], bins ); + } + +}