This is an example of unfolding a two-dimensional distribution also using an auxiliary measurement to constrain some background
#include <iostream>
#include <cmath>
#ifndef READ_BINNING_CINT
#else
#endif
using std::cout;
void testUnfold5c()
{
TFile *outputFile=
new TFile(
"testUnfold5_histograms.root",
"recreate");
#ifdef READ_BINNING_CINT
TFile *binningSchemes=
new TFile(
"testUnfold5_binning.root");
#endif
#ifndef READ_BINNING_CINT
if(error) cout<<"error="<<error<<" from TDOMParser\n";
detectorBinning=
generatorBinning=
#else
binningSchemes->
GetObject(
"detector",detectorBinning);
binningSchemes->
GetObject(
"generator",generatorBinning);
delete binningSchemes;
#endif
if(detectorBinning) {
} else {
cout<<"could not read 'detector' binning\n";
}
if(generatorBinning) {
} else {
cout<<"could not read 'generator' binning\n";
}
detectorBinning->
FindNode(
"detectordistribution");
generatorBinning->
FindNode(
"background");
Float_t etaRec,ptRec,discr,etaGen,ptGen;
Int_t istriggered,issignal;
TFile *dataFile=
new TFile(
"testUnfold5_data.root");
if(!dataTree) {
cout<<"could not read 'data' tree\n";
}
cout<<"loop over data events\n";
if(dataTree->
GetEntry(ievent)<=0)
break;
if(istriggered) {
histDataReco->
Fill(binNumber);
}
if(issignal) {
histDataTruth->
Fill(binNumber);
} else {
histDataTruth->
Fill(binNumber);
}
}
delete dataTree;
delete dataFile;
(generatorBinning,detectorBinning,"histMCGenRec");
TFile *signalFile=
new TFile(
"testUnfold5_signal.root");
if(!signalTree) {
cout<<"could not read 'signal' tree\n";
}
cout<<"loop over MC signal events\n";
if(signalTree->
GetEntry(ievent)<=0)
break;
if(istriggered) {
}
histMCGenRec->
Fill(genBin,recBin);
}
delete signalTree;
delete signalFile;
TFile *bgrFile=
new TFile(
"testUnfold5_background.root");
if(!bgrTree) {
cout<<"could not read 'background' tree\n";
}
cout<<"loop over MC background events\n";
if(istriggered) {
(ptRec,etaRec,discr);
histMCGenRec->
Fill(genBin,recBin);
}
}
delete bgrTree;
delete bgrFile;
delete outputFile;
}
int Int_t
Signed integer 4 bytes (int).
float Float_t
Float 4 bytes (float).
virtual TXMLDocument * GetXMLDocument() const
Returns the TXMLDocument.
Int_t ParseFile(const char *filename) override
Parse the XML file where filename is the XML file name.
Int_t WriteTObject(const TObject *obj, const char *name=nullptr, Option_t *option="", Int_t bufsize=0) override
TObject * Get(const char *namecycle) override
Return pointer to object identified by namecycle.
void GetObject(const char *namecycle, T *&ptr)
Get an object with proper type checking.
A file, usually with extension .root, that stores data and code in the form of serialized objects in ...
Int_t Write(const char *name=nullptr, Int_t opt=0, Int_t bufsize=0) override
Write memory objects to this file.
TH1 is the base class of all histogram classes in ROOT.
virtual void SetDirectory(TDirectory *dir)
By default, when a histogram is created, it is added to the list of histogram objects in the current ...
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
static void SetDefaultSumw2(Bool_t sumw2=kTRUE)
When this static function is called with sumw2=kTRUE, all new histograms will automatically activate ...
Service class for 2-D histogram classes.
Int_t Fill(Double_t) override
Invalid Fill method.
A TTree represents a columnar dataset.
virtual Int_t SetBranchAddress(const char *bname, void *add, TBranch **ptr, TClass *realClass, EDataType datatype, bool isptr, bool suppressMissingBranchError)
virtual void SetBranchStatus(const char *bname, bool status=true, UInt_t *found=nullptr)
Set branch status to Process or DoNotProcess.
virtual Int_t GetEntry(Long64_t entry, Int_t getall=0)
Read all branches of entry and return total number of bytes read.
virtual Long64_t GetEntriesFast() const
Return a number greater or equal to the total number of entries in the dataset.
virtual void ResetBranchAddresses()
Tell all of our branches to drop their current objects and allocate new ones.
static TUnfoldBinningXML * ImportXML(const TXMLDocument *document, const char *name)
import a binning scheme from an XML file
Binning schemes for use with the unfolding algorithm TUnfoldDensity.
void PrintStream(std::ostream &out, Int_t indent=0, int debug=0) const
print some information about this binning tree
TH1 * CreateHistogram(const char *histogramName, Bool_t originalAxisBinning=kFALSE, Int_t **binMap=nullptr, const char *histogramTitle=nullptr, const char *axisSteering=nullptr) const
create a THxx histogram capable to hold the bins of this binning node and its children
Int_t GetGlobalBinNumber(Double_t x) const
locate a bin in a one-dimensional distribution
static TH2D * CreateHistogramOfMigrations(TUnfoldBinning const *xAxis, TUnfoldBinning const *yAxis, char const *histogramName, Bool_t originalXAxisBinning=kFALSE, Bool_t originalYAxisBinning=kFALSE, char const *histogramTitle=nullptr)
create a TH2D histogram capable to hold the bins of the two input binning schemes on the x and y axes...
TUnfoldBinning const * FindNode(char const *name) const
traverse the tree and return the first node which matches the given name
TXMLDocument contains a pointer to an xmlDoc structure, after the parser returns a tree built during ...
unsigned int binNumber(double x, double coef, DoubleArray boundaries, unsigned int nBoundaries, int nbins, int blo)
This file is part of TUnfold.
TUnfold 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.
TUnfold 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 TUnfold. If not, see http://www.gnu.org/licenses/.