#include #include "TFile.h" #include "TH1F.h" #include "TF1.h" #include "TCanvas.h" void minimal() { TFile* file = TFile::Open("minimal.root", "READ"); TH1F* hist = (TH1F*) file->Get("run1396_hippo_elastic_scattering_beam_left_hit"); std::cout << hist->GetName() << std::endl; std::cout << hist->GetListOfFunctions()->At(1)->GetName() << std::endl; std::cout << hist->GetListOfFunctions()->At(2)->GetName() << std::endl; std::cout << hist->GetListOfFunctions()->At(3)->GetName() << std::endl; TCanvas* canvas = new TCanvas("canvas", "canvas"); gPad->SetLogy(); hist->Draw(); ((TF1*) hist->GetListOfFunctions()->At(1))->SetLineColor(1); ((TF1*) hist->GetListOfFunctions()->At(2))->SetLineColor(2); ((TF1*) hist->GetListOfFunctions()->At(3))->SetLineColor(3); ((TF1*) hist->GetListOfFunctions()->At(1))->SetLineStyle(2); ((TF1*) hist->GetListOfFunctions()->At(2))->SetLineStyle(2); ((TF1*) hist->GetListOfFunctions()->At(3))->SetLineStyle(2); ((TF1*) hist->GetListOfFunctions()->At(1))->Draw("same"); ((TF1*) hist->GetListOfFunctions()->At(2))->Draw("same"); ((TF1*) hist->GetListOfFunctions()->At(3))->Draw("same"); TF1* component_A = (TF1*) hist->GetListOfFunctions()->At(2); TF1* component_B = (TF1*) hist->GetListOfFunctions()->At(3); gROOT->GetListOfFunctions()->Add(component_A); gROOT->GetListOfFunctions()->Add(component_B); component_A->SetParNames("Constant_A", "Mean_A", "Sigma_A"); // Why are these two lines necessary?! component_B->SetParNames("Constant_B", "Mean_B", "Sigma_B"); // Why are these two lines necessary?! TF1* difference = new TF1("difference", Form("abs(%s-%s)", component_A->GetName(), component_B->GetName()), 0, 10000); difference->SetNpx(10000); difference->Draw("same"); std::cout << difference->GetMinimumX() << std::endl; }