Plotting_DataSpectra_MakeTGraph.C
Go to the documentation of this file.
1 #pragma once
2 
5 #include "/nova/app/users/abooth/UsefulCode/colors.h"
6 
7 using namespace ana;
8 
9 
11 {
12  //std::string s_Outdir = "/nova/data/users/abooth/Year2/TR_R19-04-17-2019anaa_BoxOpening/Testing/Plots/";
13  //std::string s_Outdir = "/nova/data/users/abooth/Year2/TR_R19-04-17-2019anaa_BoxOpening/190426/Plots/";
14  std::string s_Outdir = "";
15 
16  std::vector<std::unique_ptr<Spectrum>> vec_Spec1;
17  TFile *f_File1 = new TFile(s_File1.c_str(), "READ");
18  TIter iter1(f_File1->GetListOfKeys());
19  TKey *key1;
20  while((key1=(TKey*)iter1()))
21  {
22  TString name1 = ((TObject*)key1->ReadObj())->GetName();
23  std::unique_ptr<Spectrum> spec1 = Spectrum::LoadFrom(f_File1, name1);
24  vec_Spec1.push_back(std::move(spec1));
25  }
26 
27  TFile *f_Out = new TFile((s_Outdir + "fd_spectra_TGraphs_" + s_FileAppend + ".root").c_str(), "RECREATE");
28  TCanvas *c = new TCanvas("c", "c", 800, 600);
29  for(unsigned int i = 0; i < vec_Spec1.size(); i++)
30  {
31  TH1 *h1S = vec_Spec1.at(i)->ToTH1(vec_Spec1.at(i)->POT());
32  TH1 *h1 = vec_Spec1.at(i)->ToTH1(vec_Spec1.at(i)->POT());
33  h1S->Scale(0.1, "width");
34  TGraph *g1 = graphAsymmErrorScaled(h1S, h1);
35  g1->SetName(("g1_fd_spectra_Q" + std::to_string(i)).c_str());
36 
37  g1->SetMarkerStyle(kFullSquare);
38 
39  g1->GetXaxis()->CenterTitle();
40  g1->GetYaxis()->CenterTitle();
41  g1->GetXaxis()->SetTitle(h1->GetXaxis()->GetTitle());
42  g1->GetYaxis()->SetTitle("Events / 0.1 GeV");
43 
44  g1->Draw("AP");
45 
46  c->SetName(("fd_spectra_Q" + std::to_string(i)).c_str());
47  c->Write();
48  g1->Write();
49  }
50 
51 }
52 
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
void Plotting_DataSpectra_MakeTGraph(std::string s_File1, std::string s_FileAppend)
std::string GetName(int i)
static std::unique_ptr< Spectrum > LoadFrom(TDirectory *dir, const std::string &name)
Definition: Spectrum.cxx:535
TGraph * graphAsymmErrorScaled(TH1 *histScaled, TH1 *hist, double overallScale)
Definition: Plots.cxx:980
TH1F * h1
std::string to_string(ModuleType mt)
Definition: ModuleType.h:32
enum BeamMode string