Hey Rooters,
I recently recognized that there exists a wonderful package in ROOT that allows one to make a fit for a more dimensional data set.
I tried it instantaneously, cause this was exactly what I needed for my analysis. Unfortunatly my code didn’t work that well and I don’t know why.
So here is my code together with the command lines that ROOT gave back to me…
Maybe one of you can help me…
code:
--------------------------------------------------------start
#include “Riostream.h”
#include “TROOT.h”
#include “TApplication.h”
#include “TCanvas.h”
#include “TH1.h”
#include “TSystem.h”
#include “TBrowser.h”
#include “TFile.h”
#include “TRandom.h”
#include “TMultiDimFit.h”
#include “TVectorD.h”
#include
#include
#include
#include
#include
void multifit() {
////open new file////
TFile *output = new TFile(“output.root”,“recreate”);
////prepare datasample////
TChain chainTP1(“T”);
chainTP1.Add(“wholedataTP1.root”);
const Double_t pi = 3.14159265; //define the number PI
const Double_t tp1 = 0.914;
Double_t en, sz, xc, yc, ximp, yimp, coszen, el, id;
Double_t dist; //distance from center of field of view
Double_t logsz; //logarithm of size to the base 10
Double_t logen; //logarith of energy*1000 to the base 10
Double_t imp; //impact distance
Double_t elrad; //elevation in radians
Double_t sinel; //sinus of elevation
Double_t logsinel;
Double_t x[3];
chainTP1.SetBranchAddress(“id”, &id);
chainTP1.SetBranchAddress(“en”, &en);
chainTP1.SetBranchAddress(“sz”, &sz);
chainTP1.SetBranchAddress(“xc”, &xc);
chainTP1.SetBranchAddress(“yc”, &yc);
chainTP1.SetBranchAddress(“ximp”, &ximp);
chainTP1.SetBranchAddress(“yimp”, &yimp);
chainTP1.SetBranchAddress(“el”, &el);
////create multidim fitter////
TMultiDimFit *multifit = new TMultiDimFit(3,TMultiDimFit::kMonomials,"");
Int_t mPowers[] = {5,2,1};
multifit->SetMaxPowers(mPowers);
multifit->SetMaxFunctions(500);
multifit->SetMaxStudy(500);
multifit->SetMaxTerms(15);
multifit->SetPowerLimit(3);
//multifit->SetMinAngle(45);
//multifit->SetMaxAngle(5);
multifit->SetMinRelativeError(0.1);
Double_t d,e;
////fitting////
Int_t nEntriesTP1 = (Int_t)chainTP1.GetEntries();
for (Int_t i=0; iAddRow(x,d,E=0);
}
multifit->Print(“s”);
multifit->MakeHistograms();
multifit->FindParameterization("");
multifit->Print(“rc”);
//TBrowser browser = new TBrowser(“browser”,“browsing multifit”);
//multifit->Browse(browser);
multifit->MakeCode();
output->Write();
output->Close();
//delete output;
//delete multifit;
}
----------------------------------------------------------------------end
and root gave me the following answer:
----------------------------------------------------------------------start
root [0] .x multifit.C
Warning: Automatic variable E is allocated multifit.C:90:
Sample statistics:
D 1 2 3
Max: -311.2601 0 -314.2 -316
Min: -311.294 0 -inf -316
Mean: -311.2855 0 -inf -316
Function Sum Squares: 7.532e+10
Results of Parameterisation:
Total reduction of square residuals nan
Relative precision obtained: nan
Error obtained: nan
Multiple correlation coefficient: nan
Reduced Chi square over sample: nan
Maximum residual value: -1e+11
Minimum residual value: 1e+11
Estimated root mean square: nan
Maximum powers used: 5 2 1
Function codes of candidate functions.
1: considered, 2: too little contribution, 3: accepted.
3333333333 3333300000 0000000000 000000
Loop over candidates stopped because max number of terms reached
Coefficients:
Value Error Powers
0 nan nan 0 0 0
1 nan nan 1 0 0
2 nan nan 2 0 0
3 nan nan 0 1 0
4 nan nan 3 0 0
5 nan nan 1 1 0
6 nan nan 4 0 0
7 nan nan 2 1 0
8 nan nan 0 0 1
9 nan nan 5 0 0
10 nan nan 0 2 0
11 nan nan 3 1 0
12 nan nan 1 0 1
13 nan nan 1 2 0
14 nan nan 4 1 0
root [1]
-------------------------------------------------------------------end
You see, there are a lot of "not a number"s and "infinity"s where there shouldn’t be…
I’m glad about every piece of help here…
Thanks a lot,
Chris