/usr/share/doc/root/test/minexam.cxx is in root-system-doc 5.34.14-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | // @(#)root/test:$Id$
// Author: Rene Brun 22/08/95
//______________________________________________________________________________
//*-*-*-*-*-*-*-*-*-*-*-*The Minuit standard test program-*-*-*-*-*-*-*-*-*
//*-* ======================== *
//*-* *
//*-* This program is the translation to C++ of the minexam program *
//*-* distributed with the Minuit/Fortran source file. *
//*-* original author Fred James *
//*-* *
//*-* Fit randomly-generated leptonic K0 decays to the *
//*-* time distribution expected for interfering K1 and K2, *
//*-* with free parameters Re(X), Im(X), DeltaM, and GammaS. *
//*-* *
//*-* This program can be run in batch mode with the makefile *
//*-* or executed interactively with the command: *
//*-* Root > .x minexam.cxx *
//*-* *
//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
void fcnk0(int &npar, double *gin, double &f, double *x, int iflag);
int minexam();
#ifndef __CINT__
#include "TVirtualFitter.h"
#include "TMath.h"
#include "TStopwatch.h"
#include <stdlib.h>
#include <stdio.h>
//______________________________________________________________________________
int main()
{
return minexam();
}
#endif
int minexam()
{
TStopwatch timer;
// Initialize TMinuit via generic fitter interface with a maximum of 5 params
TVirtualFitter *minuit = TVirtualFitter::Fitter(0, 5);
printf("Starting timer\n");
timer.Start();
minuit->SetFCN(fcnk0);
minuit->SetParameter(0, "Re(X)", 0, 0.1, 0,0);
minuit->SetParameter(1, "Im(X)", 0, 0.1, 0,0);
minuit->SetParameter(2, "Delta M", 0.535, 0.1, 0,0);
minuit->SetParameter(3, "T Kshort", 0.892, 0 , 0,0);
minuit->SetParameter(4, "T Klong", 518.3, 0 , 0,0);
//*-*- Request FCN to read in (or generate random) data (IFLAG=1)
Double_t arglist[100];
arglist[0] = 1;
minuit->ExecuteCommand("CALL FCN", arglist, 1);
minuit->FixParameter(2);
arglist[0] = 0;
minuit->ExecuteCommand("SET PRINT", arglist, 1);
minuit->ExecuteCommand("MIGRAD", arglist, 0);
minuit->ExecuteCommand("MINOS", arglist, 0);
minuit->ReleaseParameter(2);
minuit->ExecuteCommand("MIGRAD", arglist, 0);
minuit->ExecuteCommand("MINOS", arglist, 0);
arglist[0] = 3;
minuit->ExecuteCommand("CALL FCN", arglist, 1);
printf("Time at the end of job = %f seconds\n",timer.CpuTime());
return 0;
}
//______________________________________________________________________________
void fcnk0(Int_t &, Double_t *, Double_t &f, Double_t *x, Int_t iflag)
{
static Double_t thplu[50],thmin[50],t[50];
static Double_t evtp[30] = {
11., 9., 13., 13., 17., 9., 1., 7., 8., 9.,
6., 4., 6., 3., 7., 4., 7., 3., 8., 4.,
6., 5., 7., 2., 7., 1., 4., 1., 4., 5.};
static Double_t evtm[30] = {
0., 0., 0., 0., 0., 0., 0., 0., 1., 1.,
0., 2., 1., 4., 4., 2., 4., 2., 2., 0.,
2., 3., 7., 2., 3., 6., 2., 4., 1., 5.};
static Double_t sevtp, sevtm;
const Int_t nbins = 30;
const Int_t nevtot = 250;
Int_t i, nevplu, nevmin;
Double_t xre, xim, dm, gams, gaml,gamls,xr1,xr2,em,ep;
Double_t chisq, ti, thp, thm, evp, evm, chi1, chi2;
Double_t sthplu, sthmin, ehalf, th, sterm;
xre = x[0];
xim = x[1];
dm = x[2];
gams = 1/x[3];
gaml = 1/x[4];
gamls = 0.5*(gaml+gams);
// generate random data
if (iflag == 1) {
sthplu = sthmin = 0;
for (i=0;i<nbins; i++) {
t[i] = 0.1*(i+1);
ti = t[i]; ehalf = TMath::Exp(-ti*gamls);
xr1 = 1-xre;
xr2 = 1+xre;
th = (xr1*xr1 + xim*xim)*TMath::Exp(-ti*gaml);
th += (xr2*xr2 + xim*xim)*TMath::Exp(-ti*gams);
th -= 4*ehalf*xim*TMath::Sin(dm*ti);
sterm = 2*ehalf*(1-xre*xre-xim*xim)*TMath::Cos(dm*ti);
thplu[i] = th + sterm;
thmin[i] = th - sterm;
sthplu += thplu[i];
sthmin += thmin[i];
}
nevplu = Int_t(nevtot*(sthplu/(sthplu+sthmin)));
nevmin = Int_t(nevtot*(sthmin/(sthplu+sthmin)));
printf(" LEPTONIC K ZERO DECAYS\n");
printf(" PLUS, MINUS, TOTAL=%5d %5d %5d\n",nevplu,nevmin,nevtot);
printf("0 TIME THEOR+ EXPTL+ THEOR- EXPTL-\n");
sevtp = sevtm = 0;
for (i=0;i<nbins; i++) {
thplu[i] = thplu[i]*nevplu/ sthplu;
thmin[i] = thmin[i]*nevmin/ sthmin;
sevtp += evtp[i];
sevtm += evtm[i];
printf("%12.4f%12.4f%12.4f%12.4f%12.4f\n",t[i],thplu[i],evtp[i],thmin[i],evtm[i]);
}
printf(" DATA EVTS PLUS, MINUS= %10.2f%10.2f\n", sevtp,sevtm);
}
// calculate chisquared
chisq = sthplu = sthmin = 0;
for (i=0;i<nbins; i++) {
ti = t[i];
ehalf = TMath::Exp(-ti*gamls);
xr1 = 1-xre;
xr2 = 1+xre;
th = (xr1*xr1 + xim*xim)*TMath::Exp(-ti*gaml);
th += (xr2*xr2 + xim*xim)*TMath::Exp(-ti*gams);
th -= 4*ehalf*xim*TMath::Sin(dm*ti);
sterm = 2*ehalf*(1-xre*xre-xim*xim)*TMath::Cos(dm*ti);
thplu[i] = th + sterm;
thmin[i] = th - sterm;
sthplu += thplu[i];
sthmin += thmin[i];
}
thp = thm = evp = evm = 0;
if (iflag != 4) {
printf(" POSITIVE LEPTONS ,NEGATIVE LEPTONS\n");
printf(" TIME THEOR EXPTL chisq TIME THEOR EXPTL chisq\n");
}
for (i=0;i<nbins; i++) {
thplu[i] = thplu[i]*sevtp / sthplu;
thmin[i] = thmin[i]*sevtm / sthmin;
thp += thplu[i];
thm += thmin[i];
evp += evtp[i];
evm += evtm[i];
// Sum over bins until at least four events found
if (evp > 3) {
ep = evp-thp;
chi1 = (ep*ep)/evp;
chisq += chi1;
if (iflag != 4) printf(" %9.3f%9.3f%9.3f%9.3f\n",t[i],thp,evp,chi1);
thp = evp = 0;
}
if (evm > 3) {
em = evm-thm;
chi2 = (em*em)/evm;
chisq += chi2;
if (iflag != 4) {
printf(" %9.3f%9.3f%9.3f%9.3f\n"
,t[i],thm,evm,chi2);
}
thm = evm = 0;
}
}
f = chisq;
}
|