int DD3() { //necessary declarations char datafile[100]="DDc1c2c3.txt";//This is where you specify which text file to read in ifstream data_input; //Creating a location in memory which will point to the data file /* The following variables are used to read in the data from a text file The format of the text file is as follows */ float HV[100]; //An array of 100 elements which will contain the high voltages float Discr_L[5][100]={0}; float Discr_H[5][100]={0}; //A 2D array which will contain the raw count from the two discriminator settings, for each five counters int time[100]={0}; //Contains the run time for each measurement set float log_counts[5][100]={0}; //2D array which contains the log of the low discriminator counts float DD_Ratio[5][100]={0}; //2D array which contains the ratio of the two discriminator counts float x_errors[100]={0.0}; //Need to declare this as ROOT doesn't allow me to only give one set of errors float y_errors1[5][100]={0}; //2D array which contains the errors for the DD_Ratio float y_errors2[5][100]; //2D array which contains the error for the log of the counts int i=0, j=0, pts=0, time[100]; float y_max1[5]=0, y_min1[5]=0, y_min2[5]=0, y_max2[5]=0, HV_min=0, HV_max=0; char xtitle[100], ytitle1[100], ytitle2[100], main_title[5][100]; gStyle->SetOptStat(0); gStyle->SetErrorX(0); sprintf(xtitle, "High Voltage, [-kV]"); sprintf(ytitle1, "Threshold 50/100"); sprintf(ytitle2, "Log(Counts/s)"); //read in data from file data_input.open(datafile); while(data_input >> HV[pts] >> Discr_L[0][pts] >> Discr_H[0][pts] >> Discr_L[1][pts] >> Discr_H[1][pts] >> Discr_L[2][pts] >> Discr_H[2][pts] >> time[pts]) { pts++; } data_input.close(); for (j=0; j<3; j++) { sprintf(main_title[j], "c%d", j+1); for(i=0;i<(pts+1);i++) { DD_Ratio[j][i]=Discr_L[j][i]/Discr_H[j][i]; log_counts[j][i]=log10(Discr_L[j][i]/time[i]); y_errors1[j][i]=DD_Ratio[j][i]*sqrt(1/Discr_L[j][i]+1/Discr_H[j][i]); y_errors2[j][i]=1/sqrt(Discr_L[j][i]/time[i]); if(j==0) { HV[i] /= 1000; cout << HV[i] << endl; } } } for (j=0; j<3; j++) { y_max1[j] = find_max(DD_Ratio[j], pts+1); y_min1[j] = find_min(DD_Ratio[j], pts+1); y_max2[j] = find_max(log_counts[j], pts+1); y_min2[j] = find_min(log_counts[j], pts+1); } HV_max = find_max(HV,pts+1); HV_min = find_min(HV,pts+1); TGraphErrors *graph[5]; TGraphErrors *log_graph[5]; TH2F *h2, *h2_dum; TCanvas *c, *canvas1, *canvas2; g = (TGraphErrors*)gROOT->FindObject("graph"); if (g) g->Delete(); g=0; //initialize the graphs and set some characteristics for (j=0; j<3; j++) { graph[j] = new TGraphErrors(pts+1, HV, DD_Ratio[j], x_errors, y_errors1[j]); log_graph[j] = new TGraphErrors(pts+1, HV, log_counts[j], x_errors, y_errors2[j]); } c = (TCanvas*) gROOT->FindObject("DD"); if (c) delete c; c=0; c = (TCanvas*) gROOT->FindObject("Log"); if (c) delete c; c=0; canvas1 = new TCanvas("DD"," ",50,50,550,700); canvas1->Divide(2,3); canvas2 = new TCanvas("Log"," ",500,50,600,700); canvas2->Divide(2,3); for(j=0; j<3; j++) { canvas1->cd(j+1); h2 = (TH2F*)gROOT->FindObject("h2_dum"); if (h2) h2->Delete(); h2=0; h2_dum = new TH2F("h2_dum","", 0, 0.9*HV_min, 1.1*HV_max, 0, 0.9*y_min1[j], 1.2*y_max1[j]); h2_dum->SetXTitle(xtitle); h2_dum->SetTitleSize(0.037,"X"); h2_dum->SetTitleSize(0.035, "Y"); h2_dum->SetTitleOffset(1.5, "Y"); h2_dum->SetTitle(main_title[j]); h2_dum->SetYTitle(ytitle1); h2_dum->DrawCopy(); graph[j]->Draw("p"); graph[j]->SetMarkerColor(2); graph[j]->SetMarkerStyle(20); graph[j]->SetMarkerSize(0.4); canvas2->cd(j+1); h2 = (TH2F*)gROOT->FindObject("h2_dum"); if (h2) h2->Delete(); h2=0; cout << y_min2[j] << endl; if(y_min2[j] < 1) { y_min2[j] = 0.1*y_min2[j]; } else { y_min2[j] = 0.8*y_min2[j]; } h2_dum = new TH2F("h2_dum","", 0, 0.9*HV_min, 1.1*HV_max, 0, y_min2[j], 1.2*y_max2[j]); h2_dum->SetXTitle(xtitle); h2_dum->SetTitleSize(0.037,"X"); h2_dum->SetTitleSize(0.037, "Y"); h2_dum->SetTitleOffset(1, "Y"); h2_dum->SetTitle(main_title[j]); h2_dum->SetYTitle(ytitle2); h2_dum->DrawCopy(); log_graph[j]->Draw("p"); log_graph[j]->SetMarkerColor(2); log_graph[j]->SetMarkerStyle(20); log_graph[j]->SetMarkerSize(0.4); } } float find_max(const float *array, const int size) { float max=array[0]; for(int i=0;i array[i] ) min = array[i]; return min; }