ATLAS Offline Software
Loading...
Searching...
No Matches
ShapeFitter.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include "TMinuit.h"
7
10
12#include "LArSamplesMon/Data.h"
14
15#include <iostream>
16using std::cout;
17using std::endl;
18
19using namespace LArSamples;
20
21namespace LArSamples {
22 namespace FitterData {
24 const AbsShape* data;
27 unsigned int minNDof;
28 }
29}
30
31
32bool ShapeFitter::fit(const AbsShape& data, const AbsShape& reference, double& k, double& deltaT, double& chi2,
33 const ScaledErrorData* sed) const
34{
35 TMinuit* minuit = new TMinuit(1); //initialize TMinuit with 1 param
36 gMinuit->SetFCN(adjusted_reference);
37
38 FitterData::fitter = this;
41 FitterData::sed = sed;
42
43 double nData = (data.time(data.nPoints() - 1) - data.time(0))/Definitions::samplingInterval;
44 double nRef = (reference.time(data.nPoints() - 1) - reference.time(0))/Definitions::samplingInterval;
45
46 FitterData::minNDof = (nData < nRef ? ((unsigned int)nData+1)/2 : ((unsigned int)nRef+1)/2); // we want at least n/2 samples in range
47 //std::cout << minNDof << std::endl;
48 Double_t arglist[10];
49 Int_t ierflg = 0;
50
51 arglist[0] = -1;
52 gMinuit->mnexcm("SET PRINT",arglist,1,ierflg);
53 arglist[0] = 0;
54 gMinuit->mnexcm("SET NOW", arglist,0,ierflg);
55
56 arglist[0] = 1;
57 minuit->mnexcm("SET ERR", arglist, 1, ierflg);
58 minuit->mnparm(0, "deltaT", 0, Definitions::samplingInterval/24, -5*(double)Definitions::samplingInterval, 5*(double)Definitions::samplingInterval, ierflg);
59
60 arglist[0] = 500;
61 arglist[1] = 1.;
62 minuit->mnexcm("MIGRAD", arglist, 2, ierflg);
63
64 Double_t edm, errdef;
65 Int_t nvpar, nparx, icstat;
66 minuit->mnstat(chi2, edm, errdef, nvpar, nparx, icstat);
67
68 double err, low, high;
69 int iuint;
70 TString name;
71 minuit->mnpout(0, name, deltaT, err, low, high, iuint);
72 delete minuit;
73 return m_c2c.bestRescale(data, reference, k, chi2, deltaT, sed);
74}
75
76
77void ShapeFitter::adjusted_reference(Int_t& /*nPar*/, Double_t* /*grad*/, Double_t& f, Double_t* par, Int_t /*iflag*/)
78{
79 double deltaT = par[0], k = 1;
80 //std::cout << "Eval at " << deltaT << std::endl;
81 if (!FitterData::fitter->chi2Calc().bestRescale(*FitterData::data, *FitterData::reference, k, f, deltaT,
83 //std::cout << "-> " << k << " " << deltaT << " " << f << std::endl;
84}
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
static void adjusted_reference(Int_t &nPar, Double_t *grad, Double_t &f, Double_t *par, Int_t iflag)
const Chi2Calc & chi2Calc() const
Definition ShapeFitter.h:36
bool fit(const LArSamples::AbsShape &data, const AbsShape &reference, double &k, double &deltaT, double &chi2, const ScaledErrorData *sed=0) const
double chi2(TH1 *h0, TH1 *h1)
const ShapeFitter * fitter
const AbsShape * data
const ScaledErrorData * sed
const AbsShape * reference