Please read tips for efficient and successful posting and posting code
_ROOT Version:6.18/04
Platform: Linux
Compiler: C++ I think
So I am having issues with making a TGraph from only 2 points. The code used to work but now it is no longer plotting anything but a signal point.
Here is the code.
#include "TString.h"
#include "TF1.h"
#include "TH1F.h"
#include "TMath.h"
#include "TLegend.h"
#include "TFile.h"
#include "TAxis.h"
#include "fstream"
#include "TGraph.h"
void S9_Calib(const int PieTot =16,int Run = 957,TString Type ="S9",TString Serial = "3252-21" , TString ListRaw = "Pie", bool SaveIt = false)
{
for(int Pienum =0;Pienum < PieTot;Pienum++)
{
//Load Data file
TString inname = Form("/data/x1/Detector/SiWinter20/Data/%s/%s/CentroidData/",Type.Data(),Serial.Data());
inname += Form("%s-%s_Run%i_%s%02i.txt",Type.Data(),Serial.Data(), Run,ListRaw.Data(),Pienum);
ifstream in;
in.open(inname);
const int peak = 2;
double channel[peak];
double ped = 0;
double alpha = 5486;
double energy[peak];
int NPeak = 0;
//Setting Varibles to be graphed
while (in.good())
{
in >>channel[NPeak];
if (NPeak == 0)
{
energy[NPeak] = ped;
}
else
{
energy[NPeak] = alpha;
}
NPeak++;
}
cout << channel[0]<<endl;
cout << channel[1]<<endl;
cout << energy[0]<<endl;
cout << energy[1]<<endl;
//Setting Up Canvas
TString canname = Form("%s-%s_Run%i_%s%02i_Channel_to_Energy_Fit",Type.Data(),Serial.Data(),Run,ListRaw.Data(),Pienum);
TCanvas *can = (TCanvas*)gROOT->FindObject(canname);
if(!can) {can = new TCanvas(canname,canname,605,5,1000,800); can->Divide(1,1,1e-4,1e-4);}
can->cd();
//Setting labels
TH1F *hblank = (TH1F*)gROOT->FindObject("hblank_f");
if(!hblank)
{
TH1F *hblank =new TH1F("hblank_f","",4096,0,4096);
hblank->SetTitle("");
}
double ylow = -2, yhigh = 10, xlow = -1, xhigh = 4096;
hblank->GetXaxis()->SetRangeUser(xlow,xhigh); hblank->GetYaxis()->SetRangeUser(ylow,yhigh);
hblank->GetXaxis()->CenterTitle(1); hblank->GetYaxis()->CenterTitle(1);
hblank->GetYaxis()->SetTitle("Energy (MeV)");
hblank->GetXaxis()->SetTitle("Channel Number");
hblank->GetXaxis()->SetTitleSize(0.05); hblank->GetYaxis()->SetTitleSize(0.05);
hblank->GetXaxis()->SetTitleOffset(0.7); hblank->GetYaxis()->SetTitleOffset(0.7);
hblank->GetXaxis()->SetLabelSize(0.04); hblank->GetYaxis()->SetLabelSize(0.04);
hblank->SetTitle(canname);
hblank->Draw();
TGraph *myg = new TGraph(peak,channel,energy);
myg->SetMarkerStyle(20);
myg->Draw("P");
//Setting Fits
TF1 *fit_pol = new TF1(Form("Fit_Run%i_%s%02i",Run,ListRaw.Data(),Pienum),"pol1",xlow,xhigh);
myg->Fit(fit_pol,"0nq");
fit_pol->Draw("Same");
//Saving if SaveIt is True
if (SaveIt)
{
TString fitnamePath = Form("/data/x1/Detector/SiWinter20/Data/%s/%s/CalibData/",Type.Data(),Serial.Data());
fitnamePath += Form("Calib_Run%i_%s.root",Run,ListRaw.Data());
TFile *fit_cal = new TFile(fitnamePath,"update");
fit_pol->Write("",TObject::kOverwrite);
fit_cal->Close();
}
}
}
For the Pie00 case we have the .txt file reading
104
1022.58
I am unsure why its no longer plotting the points. Please let me know where I went wrong with the code.