Skip to content
Snippets Groups Projects
Verified Commit 597232de authored by Tobias Triffterer's avatar Tobias Triffterer :house_with_garden:
Browse files

Example for Analysis Script

This is a small script to show the students how to analyze the data
using ROOT and RooFit.
parent ea74aba1
No related branches found
No related tags found
No related merge requests found
/**
* @file example.C
*
* @author Tobias Triffterer
*
* @brief Sample ROOT Analysis Script
*
* Rutherford Experiment Lab Course Online
* Copyright © 2021 Ruhr-Universität Bochum, Institut für Experimentalphysik I
* https://www.ep1.ruhr-uni-bochum.de/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
**/
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooDataHist.h"
#include "RooGaussian.h"
#include "RooPlot.h"
#include "TH1F.h"
using namespace RooFit;
void fitModel(TFile* file)
{
TH1F* ADC = dynamic_cast<TH1F*>(file->Get("ADC"));
if (ADC == nullptr)
{
std::cerr << "Error: Cannot find histogram stored by Fp311Online software!" << std::endl;
return;
}
const double normFitRangeLowEnd = -0.5;
const double normFitRangeHighEnd = 4095.5;
RooRealVar SignalFraction("A", "Signal Fraction", 0, 1000000);
RooRealVar ConstantUnderground("B", "Constant Unterground", 0, 1000000);
RooRealVar NoiseFraction("C", "Noise Fraction", 0, 1000000);
RooRealVar NoiseWidth("D", "Negative Inverse Noise Width", -1.0, 0.0);
RooRealVar PeakPosition("µ", "Peak Position", -0.5, 4095.5);
RooRealVar PeakWidth("σ", "Peak Width", 0.1, 1000);
RooRealVar x("x", "ADC Conversions", -0.5, 4095.5);
x.setBins(4096);
x.setRange("full", -0.5, 4095.5);
x.setRange("fitrange", normFitRangeLowEnd, normFitRangeHighEnd);
RooUniform Underground("Underground", "Underground", RooArgSet(x));
RooExponential Noise("Noise", "Noise", x, NoiseWidth);
RooGaussian Signal("Signal", "Signal", x, PeakPosition, PeakWidth);
RooAddPdf model("RutherfordModel", "Fp311 Online Model", RooArgList(Signal, Underground, Noise), RooArgList(SignalFraction, ConstantUnderground, NoiseFraction));
RooDataHist histo("histo", "ADC Conversions", x, Import(*ADC));
RooPlot* plot = x.frame(Title("Measurement Result with Fit"));
histo.plotOn(plot);
model.fitTo(histo, NormRange("fitrange"));
model.plotOn(plot, NormRange("fitrange"));
plot->Draw();
std::cout << "\n\nResult of fitting model to histogram:\n" << std::endl;
std::cout << "Number of events in fit: " << SignalFraction.getVal() + ConstantUnderground.getVal() + NoiseFraction.getVal() << std::endl;
std::cout << "Number of events in histogram: = " << ADC->GetEntries() << std::endl;
std::cout << "\nNumber of signal events in Gauß peak: " << SignalFraction.getVal() << " ± " << SignalFraction.getError() << std::endl;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment