//included modules #include "Riostream.h" //prototyoe void yatzi_root_script() { //Replaces this file with nothing TString dir = gSystem->UnixPathName(gInterpreter->GetCurrentMacroName()); dir.ReplaceAll("yatzi_root_script.cpp",""); dir.ReplaceAll("/./","/"); ifstream in; //opens data file from the C++ program in.open(Form("%sYatzyValues.txt",dir.Data())); // all colummns in the datafile. Float_t x,y,z,w,v,j,k,l,i,g,h,p,s,t,a,m,n,o; Int_t nlines = 0; //creates a root file TFile *f = new TFile("YatzyValues.root","RECREATE"); //creates all our different histograms TH1F *h1 = new TH1F("h1","Distribution over the value of 1 in 1000000 throws",6,0,6); TH1F *h2 = new TH1F("h2","Distribution over the value of 2 in 1000000 throws",12,0,15); TH1F *h3 = new TH1F("h3","Distribution over the value of 3 in 1000000 throws",18,0,25); TH1F *h4 = new TH1F("h4","Distribution over the value of 4 in 1000000 throws",24,0,30); TH1F *h5 = new TH1F("h5","Distribution over the value of 5 in 1000000 throws",30,0,50); TH1F *h6 = new TH1F("h6","Distribution over the value of 6 in 1000000 throws",36,0,40); TH1F *h7 = new TH1F("h7","Distribution over the value of the six first values without bonus in 1000000 throws",126,0,126); TH1F *h8 = new TH1F("h8","Distribution over the value of a pair in 1000000 throws",12,0,20); TH1F *h9 = new TH1F("h9","Distribution over the value of 3 alike in 1000000 throws",18,0,20); TH1F *h10 = new TH1F("h10","Distribution over the value of 4 alike in 1000000 throws",24,0,30); TH1F *h11 = new TH1F("h11","Distribution over the value of two pairs in 1000000 throws",22,0,30); TH1F *h12 = new TH1F("h12","Distribution over the value of a full house in 1000000 throws",28,0,40); TH1F *h13 = new TH1F("h13","Distribution over the final value in a yatzy game in 1000000 games",400,0,400); //makes the values of each column in the datafile fit into the defined histograms while (1) { in >> x >> y >> z >> w >> v >> j >> k >> l >> i >> g >> h >> p >> s >> t >> a >> m >> n >> o; if (!in.good()) break; if (nlines < 5) printf("x=%8f, y=%8f, z=%8f, w=%8f, v=%8f, j=%8f, k=%8f, l=%8f, i=%8f, g=%8f, h=%8f, p=%8f, s=%8f, t=%8f, a=%8f, m=%8f, n=%8f,o=%8f",x); //Fills the different histograms with the values in each column h1->Fill(x); h2->Fill(y); h3->Fill(z); h4->Fill(w); h5->Fill(v); h6->Fill(j); h7->Fill(k); h8->Fill(i); h9->Fill(g); h10->Fill(h); h11->Fill(p); h12->Fill(s); h13->Fill(o); nlines++; } //Prints the different values printf(" found %d points\n",nlines); //Gives names to the axises in the histograms h1->GetXaxis()->SetTitle("Number of points in game"); h1->GetYaxis()->SetTitle("Number of recordings"); h2->GetXaxis()->SetTitle("Number of points in game"); h2->GetYaxis()->SetTitle("Number of recordings"); h3->GetXaxis()->SetTitle("Number of points in game"); h3->GetYaxis()->SetTitle("Number of recordings"); h4->GetXaxis()->SetTitle("Number of points in game"); h4->GetYaxis()->SetTitle("Number of recordings"); h5->GetXaxis()->SetTitle("Number of points in game"); h5->GetYaxis()->SetTitle("Number of recordings"); h6->GetXaxis()->SetTitle("Number of points in game"); h6->GetYaxis()->SetTitle("Number of recordings"); h7->GetXaxis()->SetTitle("Number of points in game"); h7->GetYaxis()->SetTitle("Number of recordings"); h8->GetXaxis()->SetTitle("Number of points in game"); h8->GetYaxis()->SetTitle("Number of recordings"); h9->GetXaxis()->SetTitle("Number of points in game"); h9->GetYaxis()->SetTitle("Number of recordings"); h10->GetXaxis()->SetTitle("Number of points in game"); h10->GetYaxis()->SetTitle("Number of recordings"); h11->GetXaxis()->SetTitle("Number of points in game"); h11->GetYaxis()->SetTitle("Number of recordings"); h12->GetXaxis()->SetTitle("Number of points in game"); h12->GetYaxis()->SetTitle("Number of recordings"); h13->GetXaxis()->SetTitle("Number of points in game"); h13->GetYaxis()->SetTitle("Number of recordings"); in.close(); // Writes the different hisograms f->Write(); }