void bin() { // Premenné int Im = 1000; // Počet hodnôt v prvom histograme int bin = 10; // Počet binov v prvom histograme int Km = 1000; // Počet hodnôt v druhom histograme int bon = 100; // Počet binov v druhom histograme int cnt = 6; // Obsah binu double lima = 250; double limb = 450; double y[1000]; // Histogramy & Grafy TRandom3* rand = new TRandom3(0); TGraph* graph = new TGraph(Im); TH1D* hist[1000]; TH1D* gram = new TH1D("gram","Histogram poctu pripadov v n-tom bine",bon,lima,limb); TF1* fNorm = new TF1("fNorm","gaus",0,1); // gaus = [0]*exp(-0.5*((x-[1])/[2])**2) TF1* fNext = new TF1("fNext","gaus",0,1000); c1 = new TCanvas("c1","Sample Graph",200,10,700,500); c1->SetGrid(); // Generovanie 1000 histogramov pomocou poľa for(int k = 0; k < Km; k++){ hist[k] = new TH1D("hist","Histogram Pravdepodobnosti",bin,0,1); for (int i = 0; i < Im; i++){ y[i]=rand -> Gaus(0.5,0.1); hist[k]->Fill(y[i]); } gram->Fill(hist[k]->GetBinContent(cnt)); } // Výpis prvého histogramu double norm = Im * hist[1]->GetBinWidth(1); fNorm->SetParameter(0,norm * (1-0.1) / sqrt(2*TMath::Pi()) / 0.1); fNorm->SetParameter(1,0.5); fNorm->SetParameter(2,0.1); fNorm->SetLineColor(4); TAxis *axis = graph->GetXaxis(); axis->SetLimits(0.,1.); graph->GetHistogram()->SetMaximum(Im/2); graph->GetHistogram()->SetMinimum(0.); graph->SetTitle(""); graph->GetXaxis()->SetTitle("X"); graph->GetYaxis()->SetTitle("Y"); graph->SetLineWidth(3); graph->SetLineColor(2); graph->SetMarkerColor(1); graph->Draw(); // PA hist[1]->Draw("Same"); fNorm->Draw("Same"); // Výpis druhého histogramu /* gram->SetLineColor(2); gram->Draw(); //<----- Histogram počtu prípadov v n-tom bine norm = gram->GetBinWidth(1); double mean = gram->GetMean(); double rms = gram->GetRMS(); fNext->SetParameter(0,norm * (Km-rms) / sqrt(2*TMath::Pi()) / rms); fNext->SetParameter(1,mean); fNext->SetParameter(2,rms); fNext->SetLineColor(4); fNext->Draw("Same"); */ }