plotThresh.C
/****************************************************************************
* Macro to plot log(Rate) vs. Threshold plots.
*
* Usage: in root...
* .x plotThresh.C
*
* Author: Brian Freeman
* Date: 11/6/14
***************************************************************************/
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
//arrays that will be used in the TGraphErrors plot
Double_t thresholds[25];
Double_t rate[25];
Double_t events[25];
Double_t delta_t[25];
Double_t dx[25];
Double_t dy[25];
//i is the array index
Int_t i=0;
//main method
void plotThresh(){
/*********************
* Get file contents
*********************/
//The file path goes here. My files were named tube[1-4].dat
//and located in the data directory
std::ifstream f( "../data/threshold.dat" );
//loop through the file stopping when there are nomore lines in the file
for( std::string line; getline( f, line );){
//the line is taken in, and variables assigned and inserted into data arrays
std::istringstream( line )>>thresholds[i]>>delta_t[i]>>events[i]>>dx[i]>>dy[i];
rate[i] = log10( events[i] / delta_t[i] ) ;
//increment the index
i++;
}
//close file resources
f.close();
f.clear();
/**************
* Plot data
**************/
//create canvas
TCanvas *c1 = new TCanvas("threshold","Log(Rate) vs Threshold",400,400,600,600);
//set options
gStyle->SetOptStat(1);
gStyle->SetOptFit(1);
c1->ToggleEventStatus();
//create single graphs
//using the arrays that I built from the data file
TGraphErrors *g = new TGraphErrors(1000 , thresholds , rate , dx, dy );
g = new TGraphErrors(i , thresholds , rate , dx, dy);
g->SetLineColor(2);//red
g->SetMarkerColor(2);//red
g->SetMarkerStyle(21);//square
//draw title
g->SetTitle("Log(Rate) vs. Threshold");
//draw graph
g->Draw("AP");
//plot labels
g->GetYaxis()->SetTitle("Log(Rate) [log(Hz)]");
g->GetXaxis()->SetTitle("Threshold [mV]");
}//end of main