#include "TRandom.h" void FrequenzaElettroni(int NmaxEsp = 5000, int numeroParticelle=10000) { float const pR1e = 0.1; // P(R1|e) float const pR2e = 0.8; // P(R2|e) float const pR1a = 0.9; // P(R1|a) float const pR2a = 0.05; // P(R2|a) float frazioneEle = 0.2; // float Nele_atteso = frazioneEle*numeroParticelle; float eNele_atteso = sqrt(frazioneEle*numeroParticelle*(1.-frazioneEle)); float Nalfa_atteso = numeroParticelle-Nele_atteso; float eNalfa_atteso = eNele_atteso; // se osservo solo R1: // P(nR1|e) = 0.9 // P(R1 |e) = 0.1 // P(nR1|a) = 0.1 // P(R1 |a) = 0.9 //P(e|nR1) = P(nR1|e)P(e)/[ P(nR1|e)P(e) + P(nR1|a)P(a)] = 0.9 * 0.2 /( 0.9*0.2 + 0.1*0.8 ) = 0.692 //P(a|nR1) = P(nR1|a)P(a)/[ P(nR1|e)P(e) + P(nR1|a)P(a)] = 0.1 * 0.8 /( 0.9*0.2 + 0.1*0.8 ) = 0.308 //P(e| R1) = P( R1|e)P(e)/[ P( R1|e)P(e) + P( R1|a)P(a)] = 0.1 * 0.2 /( 0.1*0.2 + 0.9*0.8 ) = 0.027 //P(a| R1) = P( R1|a)P(a)/[ P( R1|e)P(e) + P( R1|a)P(a)] = 0.9 * 0.8 /( 0.1*0.2 + 0.9*0.8 ) = 0.973 double pnR1e = 1.-pR1e; double pnR1a = 1.-pR1a; double pe_nR1 = pnR1e*frazioneEle / ( pnR1e*frazioneEle + pnR1a*(1.-frazioneEle) ); double pa_nR1 = pnR1a*(1.-frazioneEle) / ( pnR1e*frazioneEle + pnR1a*(1.-frazioneEle) ); double pe_R1 = pR1e*frazioneEle / ( pR1e*frazioneEle + pR1a*(1.-frazioneEle) ); double pa_R1 = pR1a*(1.-frazioneEle) / ( pR1e*frazioneEle + pR1a*(1.-frazioneEle) ); std::cout<<"xBayes: P(e|nR1) = "<Fill(Nele); hNeleR1 ->Fill(NeleR1); hNeleR2 ->Fill(NeleR2); hNalfa ->Fill(Nalfa); hNalfaR1->Fill(NalfaR1); hNalfaR2->Fill(NalfaR2); hNR1 ->Fill(NR1 ); hNR2 ->Fill(NR2 ); hNR1R2 ->Fill(NR1R2 ); hNR1nR2 ->Fill(NR1nR2); hNnR1R2 ->Fill(NnR1R2); hNnR1nR2 ->Fill(NnR1nR2); hPe_nR1 ->Fill(double(Nele-NeleR1)/double(NnR1R2+NnR1nR2) ); hPa_nR1 ->Fill(double(Nalfa-NalfaR1)/double(NnR1R2+NnR1nR2) ); hPe_R1 ->Fill(double(NeleR1)/double(NR1) ); hPa_R1 ->Fill(double(NalfaR1)/double(NR1)); //DA MC pe_nR1R2_MC = double(Ne_nR1R2)/double(NnR1R2); pe_R1R2_MC = double(Ne_R1R2) /double(NR1R2); pe_nR1nR2_MC = double(Ne_nR1nR2)/double(NnR1nR2); pe_R1nR2_MC = double(Ne_R1nR2)/double(NR1nR2); //DA MC pa_nR1R2_MC = double(Na_nR1R2)/double(NnR1R2); pa_R1R2_MC = double(Na_R1R2) /double(NR1R2); pa_nR1nR2_MC = double(Na_nR1nR2)/double(NnR1nR2); pa_R1nR2_MC = double(Na_R1nR2)/double(NR1nR2); hPe_R1R2 ->Fill(pe_R1R2_MC ); hPe_nR1R2 ->Fill(pe_nR1R2_MC ); hPe_R1nR2 ->Fill(pe_R1nR2_MC ); hPe_nR1nR2 ->Fill(pe_nR1nR2_MC ); hPa_R1R2 ->Fill(pa_R1R2_MC ); hPa_nR1R2 ->Fill(pa_nR1R2_MC ); hPa_R1nR2 ->Fill(pa_R1nR2_MC ); hPa_nR1nR2 ->Fill(pa_nR1nR2_MC ); //// stimo frazioneElettroni //// nota NR1 = N x fe x P(R1|e) - N x fe x P(R1|a) + N x P(R1|a) => N x fe ( P(R1|e) - P(R1|a) ) = NR1 - N P(R1|a) float fe_fromR1 = ( (double(NR1)-numeroParticelle*pR1a) /double(numeroParticelle) ) /( pR1e - pR1a ); hfe_fromR1->Fill(fe_fromR1); //// stimo frazioneElettroni //// nota NR2 = N x fe x P(R2|e) - N x fe x P(R2|a) + N x P(R2|a) => N x fe ( P(R2|e) - P(R2|a) ) = NR2 - N P(R2|a) float fe_fromR2 = ( (double(NR2)-numeroParticelle*pR2a) /double(numeroParticelle) ) /( pR2e - pR2a ); hfe_fromR2->Fill(fe_fromR2); // media delle due stime (derivate da NR1 e da NR2) hfe_fromR12->Fill((fe_fromR1+fe_fromR2)/2.); // osservo le correlazioni hfe_fromR1_fromR2->Fill(fe_fromR2,fe_fromR1); Nesp++; } TCanvas* cT = new TCanvas("cT","Truth",800,800); cT->Divide(2,3); cT->cd(1); hNele->Draw(); cT->cd(2); hNalfa->Draw(); cT->cd(3); hNeleR1->Draw(); cT->cd(4); hNalfaR1->Draw(); cT->cd(5); hNeleR2->Draw(); cT->cd(6); hNalfaR2->Draw(); TCanvas* cR = new TCanvas("cR","Detectors",800,800); cR->Divide(2,3); cR->cd(1); hNR1->Draw(); cR->cd(2); hNR2->Draw(); cR->cd(3); hNR1R2->Draw(); cR->cd(4); hNR1nR2->Draw(); cR->cd(5); hNnR1R2->Draw(); cR->cd(6); hNnR1nR2->Draw(); TCanvas* cB = new TCanvas("cB","Bayes",800,600); cB->Divide(2,2); cB->cd(1); hPe_nR1->Draw(); cB->cd(2); hPa_nR1 ->Draw(); cB->cd(3); hPe_R1 ->Draw(); cB->cd(4); hPa_R1 ->Draw(); TCanvas* cF = new TCanvas("cF","Frazione Elettroni",800,600); cF->Divide(2,2); cF->cd(1); hfe_fromR1->Fit("gaus"); cF->cd(2); hfe_fromR2->Fit("gaus"); cF->cd(3); hfe_fromR12->Fit("gaus"); cF->cd(4); hfe_fromR1_fromR2->Draw("zcol"); TCanvas* cPe = new TCanvas("cPe","Electron Purity in samples",800,600); cPe->Divide(2,2); cPe->cd(1); hPe_R1R2->Draw(); cPe->cd(2); hPe_nR1R2->Draw(); cPe->cd(3); hPe_R1nR2->Draw(); cPe->cd(4); hPe_nR1nR2->Draw(); TCanvas* cPa = new TCanvas("cPa","Alfa Purity in samples",800,600); cPa->Divide(2,2); cPa->cd(1); hPa_R1R2->Draw(); cPa->cd(2); hPa_nR1R2->Draw(); cPa->cd(3); hPa_R1nR2->Draw(); cPa->cd(4); hPa_nR1nR2->Draw(); }