/* 173.308.02 - Advanced Physics Lab Professor: Tobias Marriage Written by Jake Mokris, 2/12/2011 This simple (not robust) macro prompts for the name of a data file (which MUST be formatted as two columns of doubles, and MUST be in the same directory as this program) and outputs a graph of the data points in ROOT. This was my macro for the photoelectric effect lab. To run it in ROOT, open ROOT and type .L bla.C++ (this compiles the code and creates a shared library) bla() (this calls the function) Again, this is merely the initial version. If you know a better way to write some or all of this program, please tell me! */ #include #include #include #include using namespace std; // This function takes a string and returns a const *char - once I get it to work... const char *convert(string s) { const int length = s.length(); char name[length+1]; for (int i = 0; i> file_string; const int length = file_string.length(); char name[length+1]; for (int i = 0; i> x_coordinate; data_file >> y_coordinate; if (!data_file.eof()) { x[i]=x_coordinate; y[i]=y_coordinate; } } cout << "Data input complete." << endl; // Close the file data_file.close(); // Create the TGraph object TGraph *graph = new TGraph(number_of_lines, x, y); // To modify the graph settings (axis titles and such), the graph must be drawn first graph->Draw(); // Make the graph fancy graph->SetMarkerStyle(20); // Sets the point marker to a filled black circle graph->GetXaxis()->SetTitle("Frequency of emitted light (10^14 Hz)"); // Set x-axis title graph->GetYaxis()->SetTitle("Photoelectron stopping voltage (V)"); // Set y-axis title graph->GetXaxis()->SetLimits(4.5,8.5); // Set x-axis range // The axis titles are initially off-center graph->GetXaxis()->CenterTitle(); graph->GetYaxis()->CenterTitle(); /* Draw options: A - Include axes P - Draw a point marker at each data point */ graph->Draw("AP"); // Redraw the graph // This fits the graph to a line ("pol1" means polynomial of degree 1) and draws it on // the graph. "WW" means ignore error bars. graph->Fit("pol1", "WW"); }