10 #include "TTreeReader.h" 11 #include "TTreeReaderValue.h" 46 static const unsigned int npar = 10;
50 #ifdef USEPROTONWEIGHT 53 const double PROTONWEIGHT = 1;
84 for(
int bz = 0; bz <= in->GetNbinsZ()+1; bz++){
85 for(
int b = 0;
b <= in->GetNbinsX()+1;
b++){
87 for(
int by = 0; by <= in->GetNbinsY()+1; by++)
88 sum += in->GetBinContent(
b, by, bz);
89 out->SetBinContent(
b, bz, sum);
93 out->SetEntries(sumsum);
97 const char *
const mcFileName,
99 const char *
const plot_name_,
100 const vector<double> & binX,
101 const vector<double> & binY,
102 const vector<double> & binZ,
112 _mcFile =
new TFile(mcFileName);
115 fprintf(
stderr,
"Failed to open %s\n", dataFileName);
119 fprintf(
stderr,
"Failed to open %s\n", mcFileName);
125 if(binX.size() < 2 || binY.size() < 2 || binZ.size() < 2){
126 fprintf(
stderr,
"Must have at least two bin boundaries per dimension\n");
143 const char *
const title =
";Distance To Stop (cm);PE/Path (cm^{-1})";
145 _mcX =
new TH3D(Form(
"mcX_%s_%s", mcFileName, dirName),
146 title,
nx, &binX[0],
ny, &binY[0],
nz, &binZ[0]);
147 _mcY =
new TH3D(Form(
"mcY_%s_%s", mcFileName, dirName),
148 title,
nx, &binX[0],
ny, &binY[0],
nz, &binZ[0]);
149 _dataX =
new TH3D(
"dataX", title,
nx, &binX[0],
ny, &binY[0],
nz, &binZ[0]);
150 _dataY =
new TH3D(
"dataY", title,
nx, &binX[0],
ny, &binY[0],
nz, &binZ[0]);
152 _maskX =
new TH3D(
"maskX", title,
nx, &binX[0],
ny, &binY[0],
nz, &binZ[0]);
153 _maskY =
new TH3D(
"maskY", title,
nx, &binX[0],
ny, &binY[0],
nz, &binZ[0]);
155 _mcXdist =
new TH2D(
"mcXdist",
"",
nx, &binX[0],
nz, &binZ[0]);
156 _mcYdist =
new TH2D(
"mcYdist",
"",
nx, &binX[0],
nz, &binZ[0]);
157 _dataXdist =
new TH2D(
"dataXdist",
"",
nx, &binX[0],
nz, &binZ[0]);
158 _dataYdist =
new TH2D(
"dataYdist",
"",
nx, &binX[0],
nz, &binZ[0]);
191 const double inv_att2,
const double dist,
192 const double rngeff,
const bool longway)
194 return (longway?rngeff:1)*
195 (attB *
exp(-dist*inv_att1) + (1-attB) *
exp(-dist*inv_att2));
224 TTreeReader * reader =
new TTreeReader(Form(
"cerenkov/%s", dir), file);
225 if(!reader->IsInvalid())
goto ok;
227 reader->SetTree(Form(
"cerenkovselection/%s", dir), file);
228 if(!reader->IsInvalid())
goto ok;
230 reader->SetTree(Form(
"cerenkovresponse/%s", dir), file);
231 if(!reader->IsInvalid())
goto ok;
233 if(strcmp(dir,
"cerenkovMuonTree"))
goto fail;
235 reader->SetTree(
"cerenkovresponse/cerenkovTree", file);
236 if(!reader->IsInvalid())
goto ok;
242 if(reader->GetEntries(
false) == 0){
243 fprintf(
stderr,
"Empty input from %s\n", file->GetName());
250 fprintf(
stderr,
"Couldn't get tree from %s, %s\n", file->GetName(),
dir);
254 static inline double clamp(
const double v,
const double mi,
const double ma)
256 return v < mi? mi: v > ma? ma:
v;
271 const vector<double> & bins,
const double val,
const int bin 283 const double binlowedge = bins[
bin];
284 const double binhigedge = bins[
bin+1];
285 const double binfrac =
clamp(( val - binlowedge)/
286 (binhigedge - binlowedge), -0.5, 1.5);
289 ans.
next = binfrac - 0.5;
293 ans.
prev = 0.5 - binfrac;
306 static void Add(TH3D *
h,
const int bx,
const int by,
const int bz,
310 const int gbin = h->GetBin(bx, by, bz);
311 h->SetBinContent(gbin, h->GetBinContent(gbin) +
w);
318 const std::vector<double> & bins)
320 static unsigned int prev = 0;
321 if(prev < bins.size()-1 && bins[
prev] < pe && bins[prev+1] > pe)
326 return prev = std::lower_bound(bins.begin(), bins.end(), pe)
331 const double y,
const double z,
336 const double zlo =
wbins[0];
340 if(!(x < xhi && x >= xlo && z < zhi && z >= zlo))
return false;
342 const int xbin = h->GetXaxis()->FindBin(x);
344 const int zbin = h->GetZaxis()->FindBin(z);
349 if(ybin-1 >= 1)
Add(h,xbin,ybin-1,zbin,bw.
prev*weight);
350 if(ybin >= 1 && ybin <= (
int)
ny)
Add(h,xbin,ybin ,zbin,bw.
curr*weight);
351 if( ybin+1 <= (
int)ny)
Add(h,xbin,ybin+1,zbin,bw.
next*weight);
368 const double cen = 500;
369 return abs(w - cen) < 100;
383 return plane >= 64*(diblock-1) &&
399 #elif defined BOTTOMTHIRD 400 return cell < 32 * 4;
401 #elif defined MIDDLETHIRD 402 return cell >= 32 * 4 && cell < 32 * 8;
403 #elif defined TOPTHIRD 404 return cell >= 32 * 8 ;
410 const float pathlength,
const float disttostop,
411 const float w,
const float PE)
416 if(isFD && !
goodfdcell(isX, cell))
return false;
420 if(!
ok_w(w, isX))
return false;
426 if(isFD && PE < 30)
return false;
435 TTreeReaderValue<float> rvPathLength(*reader,
"pathLength");
436 TTreeReaderValue<float> rvPE (*reader,
"pe");
437 TTreeReaderValue<float> rvDistToStop(*reader,
"distFromEnd");
438 TTreeReaderValue<char> rvIsX (*reader,
"isX");
439 TTreeReaderValue<float> rvw (*reader,
"w");
440 TTreeReaderValue<int> rvPlane (*reader,
"plane");
441 TTreeReaderValue<int> rvCell (*reader,
"cell");
448 printf(
"%9u %s %s\n", (
unsigned)reader->GetEntries(
false),
452 unsigned int got[
nwbins] = { 0 };
453 bool capped[
nwbins] = {
false };
454 unsigned int ncapped = 0;
455 while (reader->Next()) {
457 if(!
accepthit(
isFD, *rvIsX, *rvPlane, *rvCell, *rvPathLength, *rvDistToStop, *rvw, *rvPE))
461 const unsigned int wBin =
462 std::lower_bound(
wbins.begin(),
wbins.end(), *rvw) -
wbins.begin() - 1;
464 if(wBin >=
wbins.size())
continue;
471 if(
nwbins == ncapped)
break;
476 *rvDistToStop, (*rvPE)/(*rvPathLength), *rvw))
481 printf(
"%9u data hits accepted in w bin %d%s\n", got[
i],
482 i, capped[i]?
" (capped)": Form(
" (want %.1fx more)",
496 TH3D * notmask = (TH3D*)mask->Clone(
"notX");
497 for(
int i = 1;
i <= mask->GetNbinsX();
i++)
498 for(
int j = 1;
j <= mask->GetNbinsY();
j++)
499 for(
int k = 1; k <= mask->GetNbinsZ(); k++)
500 notmask->SetBinContent(
i,
j, k, !mask->GetBinContent(
i,
j, k));
517 printf(
"New mask for %s\n", h->GetName());
519 for(
int k = 1; k <= h->GetNbinsZ(); k++){
520 for(
int i = 1;
i <= h->GetNbinsX();
i++){
521 for(
int j = 1;
j <= h->GetNbinsY();
j++){
522 const bool newval = h->GetBinContent(
i,
j, k) >
stat_req;
523 const bool oldval = mask->GetBinContent(
i,
j, k);
524 printf(
"%c", newval?
'.':
'X');
525 if(oldval != newval){
527 mask->SetBinContent(
i,
j, k, newval);
542 return changedx || changedy;
563 const std::vector<dat> & dats,
566 double newhist[
nx][
ny][
nz];
567 memset(newhist, 0,
sizeof(
double)*
nx*
ny*
nz);
569 for(
const dat &
d : dats){
572 if(weight == 0)
continue;
577 const double scaled_pe =
d.PE *
weight;
578 if(scaled_pe < threshold)
continue;
580 const double scaled_pe_pathLength =
d.PE_PathLength *
weight;
583 const int xbin =
d.DistBin, zbin =
d.wBin;
589 if(!(ybin >= -1 && ybin < (
int)
ny+1 ))
continue;
595 #ifdef USEPROTONWEIGHT 596 if(
d.proton && PROTONWEIGHT != 1.){
597 if(ybin-1>=0) newhist[xbin][ybin-1][zbin] += bw.
prev*PROTONWEIGHT;
598 if(ybin >=0&&ybin <(
int)
ny)newhist[xbin][ybin ][zbin] += bw.
curr*PROTONWEIGHT;
599 if( ybin+1<(
int)ny)newhist[xbin][ybin+1][zbin] += bw.
next*PROTONWEIGHT;
604 if(ybin-1>=0) newhist[xbin][ybin-1][zbin] += bw.
prev;
605 if(ybin >=0&&ybin <(
int)
ny)newhist[xbin][ybin ][zbin] += bw.
curr;
606 if( ybin+1<(
int)ny)newhist[xbin][ybin+1][zbin] += bw.
next;
611 for(
unsigned int i = 0;
i <
nx;
i++){
612 for(
unsigned int j = 0;
j <
ny;
j++){
613 for(
unsigned int k = 0; k <
nz; k++){
614 tot += newhist[
i][
j][k];
615 hist->SetBinContent(
i+1,
j+1, k+1, newhist[
i][
j][k]);
619 hist->SetEntries(tot);
626 TTreeReaderValue<float> rvPathLength (*reader,
"pathLength");
627 TTreeReaderValue<float> rvPE (*reader,
"pe");
628 TTreeReaderValue<float> rvDistToStop (*reader,
"distFromEnd");
629 TTreeReaderValue<char> rvIsX (*reader,
"isX");
630 TTreeReaderValue<float> rvCerenkovPho(*reader,
"cerenkovPho");
631 TTreeReaderValue<float> rvEBirks (*reader,
"eBirks");
632 TTreeReaderValue<float> rvw (*reader,
"w");
633 TTreeReaderValue<char> rvIsProton (*reader,
"isProton");
634 TTreeReaderValue<int> rvPlane (*reader,
"plane");
635 TTreeReaderValue<int> rvCell (*reader,
"cell");
640 printf(
"%9u %s %s\n", (
unsigned)reader->GetEntries(
false),
643 unsigned int got[
nwbins] = { 0 };
644 unsigned int gotall = 0, trueprotons = 0, truemuons = 0;
645 bool capped[
nwbins] = {
false };
646 unsigned int ncapped = 0;
648 printf(
"Filling hit cache:\n");
650 while (reader->Next()) {
652 if(!
accepthit(
isFD, *rvIsX, *rvPlane, *rvCell, *rvPathLength, *rvDistToStop, *rvw, *rvPE))
continue;
654 if(*rvEBirks <= 0)
continue;
687 capped[d.
wBin] =
true;
690 if(
nwbins == ncapped)
break;
694 if(*rvIsX)
datsx.push_back(d);
695 else datsy.push_back(d);
698 (*rvPE)/(*rvPathLength), *rvw,
699 #ifdef USEPROTONWEIGHT
700 (*rvIsProton)?PROTONWEIGHT:1)){
706 if(*rvIsProton) trueprotons++;
709 if(gotall%1000000 == 0)
710 printf(
"Accepted %d hits and counting...\n", gotall);
713 printf(
"Accepted %.0f%% true protons\n", 100.*trueprotons/gotall);
714 printf(
"Accepted %.0f%% true muons\n" , 100.*truemuons /gotall);
723 printf(
"Hit cache ready\n");
726 printf(
"%9u MC hits accepted in w bin %d%s\n", got[
i],
727 i, capped[i]?
" (capped)": Form(
" (want %.1fx more)",
738 const bool changed_x,
const bool changed_y)
763 const TH2D *
const hObsDist,
const TH2D *
const hMCDist,
764 const TH3D *
const mask)
768 for(
int iZ = 1; iZ <= hMC->GetNbinsZ(); ++iZ) {
769 for(
int iX = 1;
iX <= hMC->GetNbinsX(); ++
iX) {
770 const double data_at_dist = hObsDist->GetBinContent(
iX, iZ);
771 const double mc_at_dist = hMCDist->GetBinContent(
iX, iZ);
772 const double mc_scale = data_at_dist/mc_at_dist;
774 for(
int iY = 1; iY <= hMC->GetNbinsY(); ++iY) {
775 if(mask->GetBinContent(
iX, iY, iZ) == 0)
continue;
777 const double data = hObs->GetBinContent(
iX, iY, iZ);
778 const double rawmc = hMC->GetBinContent(
iX, iY, iZ);
782 if(rawmc <= 0)
continue;
788 llike += mc - data + (data <= 0?0:data *
log (data/mc));
792 if(complain_about_problems && problems)
793 printf(
"%d low-stat MC bin%s in %s!\n",
794 problems, problems == 1?
"":
"s", hMC->GetName());
800 const bool changed_x,
const bool changed_y)
832 if(signal != SIGUSR1)
return;
867 double ndllike = 0, fdllike = 0;
868 static double old_ndllike = 0, old_fdllike = 0;
870 const bool fdchanged = old_FD !=
FD;
871 const bool ndchanged = old_ND !=
ND;
874 const bool fdchanged_x = !old_FD.
equalsx(FD);
875 const bool fdchanged_y = !old_FD.
equalsy(FD);
878 fdllike +=
calc->CalcChi2(FD, fdchanged_x, fdchanged_y);
879 old_fdllike = fdllike;
882 fdllike = old_fdllike;
886 const bool ndchanged_x = !old_ND.
equalsx(ND);
887 const bool ndchanged_y = !old_ND.
equalsy(ND);
890 ndllike +=
calc->CalcChi2(ND, ndchanged_x, ndchanged_y);
891 old_ndllike = ndllike;
894 ndllike = old_ndllike;
900 llike = ndllike + fdllike;
903 if(llike < lowest_llike){
904 lowest_llike = llike;
905 printf(
"lowest llike so far: %.9f%s\n", llike,
906 lowest_llike - llike <
epsilonll?
" (barely)":
"");
907 lowest_llike = llike;
908 memcpy(bestpars, par,
sizeof(
double)*
npar);
911 if(flag == 3)
printf(
"\n");
916 thefitter->
Plot(Form(
"intermediate%d", setn));
917 thefitter->
Plot(
"intermediatelatest");
924 static double getpar(TMinuit & mn,
const int i)
927 mn.GetParameter(i, val, err);
935 mn.GetParameter(i, val, err);
944 void mincheck(TMinuit & mn,
const bool reset =
false)
946 static double oldllike = 0;
948 if(oldllike == 0 || reset){
949 printf(
"\nllike = %8.1f\n", lowest_llike);
950 lowest_llike = 1e300;
951 memset(bestpars, 0,
sizeof(
double)*
npar);
953 else if(oldllike < lowest_llike){
954 const int prevprint = mn.fISW[4];
955 mn.Command(
"SET PRINT -1");
957 printf(
"\nllike = %8.1f, %8.5f MORE than before (%8.1f). Resetting.\n",
958 lowest_llike, lowest_llike - oldllike, oldllike);
959 for(
unsigned int i = 1;
i <=
npar;
i++)
960 mn.Command(Form(
"SET PAR %d %f\n",
i, bestpars[
i-1]));
961 mn.Command(Form(
"SET PRINT %d", prevprint));
964 else if(lowest_llike == 0){
965 printf(
"\nllike = 0 which is nonsense. Resetting.\n");
966 for(
unsigned int i = 1;
i <=
npar;
i++)
967 mn.Command(Form(
"SET PAR %d %f\n",
i, bestpars[
i-1]));
970 else if(oldllike == lowest_llike){
971 printf(
"\nllike = %8.1f, which is the same as last time\n", lowest_llike);
973 else if(oldllike - lowest_llike >
epsilonll){
974 printf(
"\nllike = %8.1f, which is %f less than last time\n",
975 lowest_llike, oldllike - lowest_llike);
978 printf(
"\nllike = %8.1f, which is barely (%g) less than last time\n",
979 lowest_llike, oldllike - lowest_llike);
982 if(lowest_llike < mn.fAmin){
983 const int prevprint = mn.fISW[4];
984 mn.Command(
"SET PRINT -1");
986 printf(
"\nNote: best = %f < fAmin = %f, using best pars instead\n",
987 lowest_llike, mn.fAmin);
988 for(
unsigned int i = 1;
i <=
npar;
i++)
989 mn.Command(Form(
"SET PAR %d %f\n",
i, bestpars[
i-1]));
990 mn.Command(Form(
"SET PRINT %d", prevprint));
1000 TwoDplots(*sample, Form(
"%s_%sfit", sample->plot_name, tag));
1001 Flatplots(*sample, Form(
"%s_3fitflat", sample->plot_name), tag);
1004 TwoDplots(*sample, Form(
"%s_%sfit", sample->plot_name, tag));
1005 Flatplots(*sample, Form(
"%s_3fitflat", sample->plot_name), tag);
1013 while(getline(std::cin, in)){
1014 if(in ==
"quit" || in ==
"exit" || in ==
".q")
break;
1015 mn.Command(in.c_str());
1023 const double v = min + (max-
min)*
R.Rndm();
1024 mn.Command(Form(
"SET PAR %d %f", p, v));
1055 mn.Command(
"SET ERR 0.5");
1058 mn.Command(
"SET WIDTH 80");
1059 mn.Command(
"SET LINES 40");
1062 mn.mnparm( 1 - 1,
"FDFx", mcparams.
FDFx, 0.01, 0.2, 2, ierr);
1063 mn.mnparm( 2 - 1,
"FDFy", mcparams.
FDFy, 0.01, 0.2, 2, ierr);
1064 mn.mnparm( 3 - 1,
"NDFx", mcparams.
NDFx, 0.01, 0, 2, ierr);
1065 mn.mnparm( 4 - 1,
"NDFy", mcparams.
NDFy, 0.01, 0, 2, ierr);
1066 mn.mnparm( 5 - 1,
"Ys", mcparams.
Ys , 10, 0, 0, ierr);
1067 mn.mnparm( 6 - 1,
"Ec", mcparams.
Ec , 0.1, 0, 0, ierr);
1068 mn.mnparm( 7 - 1,
"attB", mcparams.
attB, 0.01, 0, 1, ierr);
1069 mn.mnparm( 8 - 1,
"att1", mcparams.
att1, 10, 100, 2000, ierr);
1074 mn.mnparm( 9 - 1,
"Da12", mcparams.
att2 - mcparams.
att1, 10, 100, 2000, ierr);
1075 mn.mnparm(
npar-1,
"rngeff", mcparams.
rngeff, 0.01, 0, 1.5, ierr);
1077 fprintf(
stderr,
"Failed to set up parameters\n");
1081 mn.Command(
"SET STRATEGY 2");
1087 mn.Command(
"SET EPS 1E-6");
1089 mn.fGraphicsMode =
false;
1093 mn.Command(
"SET PAR 5 3151.04");
1094 mn.Command(
"FIX 5");
1116 printf(
"WHAT WE ARE DOING: Trying some random parameters\n");
1125 const int prevprint = mn.fISW[4];
1126 mn.Command(
"SET PRINT -1");
1127 complain_about_problems =
false;
1128 for(
int i = 0;
i < 1000;
i++){
1139 complain_about_problems =
true;
1140 mn.Command(Form(
"SET PRINT %d", prevprint));
1142 for(
int cornot = 0; cornot < 2; cornot++){
1144 if(cornot == 0) mn.Command(
"FIX 6");
1145 if(cornot == 1) mn.Command(
"RELEASE 6");
1147 if(cornot == 1 && !
float_ec)
break;
1149 printf(
"WHAT WE ARE DOING: Set masks at current value\n");
1161 printf(
"WHAT WE ARE DOING: Do a little SIMPLEX to get in a nice spot\n");
1162 mn.Command(
"SIMPLEX 100");
1165 printf(
"WHAT WE ARE DOING: See if MIGRAD helps\n");
1166 mn.Command(
"MIGRAD");
1169 for(
int i = 0;
i < 2;
i++){
1170 printf(
"WHAT WE ARE DOING: Reset masks at current value and minimize again\n");
1178 printf(
"No change in masks, so no need to minimize again\n");
1184 mn.Command(
"SIMPLEX");
1186 mn.Command(
"SEEK 300 8");
1188 mn.Command(
"MIGRAD");
1190 mn.Command(
"IMPROVE");
1196 const double oldmin = mn.fAmin;
1198 printf(
"WHAT WE ARE DOING: Scan all to make sure things are sensible\n");
1199 const double r = 0.02,
lo = 1-
r,
hi = 1+
r;
1211 const double newmin = mn.fAmin;
1212 const bool significantreduction = oldmin - newmin >
epsilonll;
1214 printf(
"SCANs reduced llike by %g%s\n", oldmin - newmin,
1215 significantreduction?
"":
" -- not significant");
1216 if(!significantreduction)
break;
1220 printf(
"WHAT WE ARE DOING: found new min, so SIMPLEX, SEEK, MIGRAD, IMPROVE\n");
1221 const double oldmin = mn.fAmin;
1222 mn.Command(
"SIMPLEX");
1224 mn.Command(
"SEEK 300 8");
1226 mn.Command(
"MIGRAD");
1228 mn.Command(
"IMPROVE");
1230 const double newmin = mn.fAmin;
1231 const bool significantreduction = oldmin - newmin >
epsilonll;
1233 printf(
"SIMPLEX, etc. reduced llike by %g%s\n", oldmin - newmin,
1234 significantreduction?
"":
" -- not significant");
1235 if(!significantreduction)
break;
1240 printf(
"WHAT WE ARE DOING: Call once more at min to make plots right\n");
1243 mn.Command(
"SET PAR 1 6.41795e-01");
1244 mn.Command(
"SET PAR 2 5.53340e-01");
1245 mn.Command(
"SET PAR 3 5.09120e-01");
1246 mn.Command(
"SET PAR 4 4.94346e-01");
1247 mn.Command(
"SET PAR 5 3.15104e+03");
1248 mn.Command(
"SET PAR 6 8.10680e-01");
1249 mn.Command(
"SET PAR 7 4.46867e-01");
1250 mn.Command(
"SET PAR 8 2.03410e+02");
1251 mn.Command(
"SET PAR 9 5.48778e+02");
1252 mn.Command(
"SET PAR 10 1.00000e+00 ");
1254 const double besta1 =
getpar(mn, 8-1), bestda =
getpar(mn, 9-1);
1256 printf(
"WHAT WE ARE DOING: Reset masks at current value\n");
1263 mn.Command(
"SIMPLEX 30");
1266 mn.Command(
"MIGRAD");
1270 mn.Command(
"FIX 8 9");
1272 mn.Command(
"FIX 5");
1273 mn.Command(
"FIX 10");
1274 mn.Command(
"SET ERR 5");
1277 const int nside = 28;
1278 const double a1step = 0.003, dastep = 0.005/4;
1279 printf(
"contcenter2: %f %f %d %f %f\n",
1280 besta1, bestda, nside, a1step, dastep);
1281 for(
int i = nside;
i >= -nside;
i--){
1282 for(
int j = -nside;
j <= nside;
j++){
1283 const double a1rat = 1 +
i*a1step;
1284 const double darat = 1 +
j*dastep;
1285 const double a1 = besta1*a1rat;
1286 const double da = bestda*darat;
1287 mn.Command(
"SET PAR 1 6.41795e-01");
1288 mn.Command(
"SET PAR 2 5.53340e-01");
1289 mn.Command(
"SET PAR 3 5.09120e-01");
1290 mn.Command(
"SET PAR 4 4.94346e-01");
1291 mn.Command(
"SET PAR 5 3.15104e+03");
1292 mn.Command(
"SET PAR 6 8.10680e-01");
1293 mn.Command(
"SET PAR 7 4.46867e-01");
1295 mn.Command(Form(
"SET PAR 8 %f", a1));
1296 mn.Command(Form(
"SET PAR 9 %f", da));
1298 mn.Command(
"FIX 1 2 3 4 5 6 7 8 9");
1303 mn.Command(
"SET STRATEGY 0");
1306 printf(
"cont: %10f %10f %10f\n", a1, da, mn.fAmin);
1310 mn.Command(
"RELEASE 7");
1311 mn.Command(
"SIMPLEX 10");
1312 mn.Command(
"MIGRAD 100");
1316 printf(
"cont2: %10f %10f %10f\n", a1, da, mn.fAmin);
1319 mn.Command(
"RELEASE 1 2 3 4");
1320 mn.Command(
"SIMPLEX 10");
1324 mn.Command(
"RELEASE 6");
1325 mn.Command(
"SIMPLEX 10");
1326 mn.Command(
"MIGRAD 50");
1329 printf(
"cont3: %10f %10f %10f\n", a1, da, lowest_llike);
1338 mn.Command(
"SIMPLEX");
1340 printf(
"WHAT WE ARE DOING: Scan all to make sure things are sensible\n");
1341 mn.Command(Form(
"SCAN 1 21 %f %f",
getpar(mn, 0)*0.98,
getpar(mn, 0)*1.02));
1342 mn.Command(Form(
"SCAN 2 21 %f %f",
getpar(mn, 1)*0.98,
getpar(mn, 1)*1.02));
1343 mn.Command(Form(
"SCAN 3 21 %f %f",
getpar(mn, 2)*0.98,
getpar(mn, 2)*1.02));
1344 mn.Command(Form(
"SCAN 4 21 %f %f",
getpar(mn, 3)*0.98,
getpar(mn, 3)*1.02));
1345 mn.Command(Form(
"SCAN 6 21 %f %f",
getpar(mn, 5)*0.98,
getpar(mn, 5)*1.02));
1346 mn.Command(Form(
"SCAN 7 21 %f %f",
getpar(mn, 6)*0.98,
getpar(mn, 6)*1.02));
1347 mn.Command(Form(
"SCAN 8 21 %f %f",
getpar(mn, 7)*0.98,
getpar(mn, 7)*1.02));
1348 mn.Command(Form(
"SCAN 9 21 %f %f",
getpar(mn, 8)*0.98,
getpar(mn, 8)*1.02));
1349 mn.Command(Form(
"SCAN 10 21 %f %f",
getpar(mn, 9)*0.98,
getpar(mn, 9)*1.02));
1351 printf(
"WHAT WE ARE DOING: Call once more at min to make plots right\n");
1356 printf(
"\n\nFD Fx: %.4f Fy: %.4f\n" 1357 "ND Fx: %.4f Fy: %.4f\n" 1358 "Ys: %.2f (by definition)\n" 1360 "attB: %6.4f att1: %6.1f att2: %6.1f\n",
static void setarand(TMinuit &mn, const int p, const double min, const double max)
std::vector< double > pebins
static bool fill_mask(TH3D *mask, TH3D *h)
const double MINPATHLENGTH
static void objfcn(__attribute__((unused)) int &np, __attribute__((unused)) double *gin, double &llike, double *par, int flag)
TSpline3 lo("lo", xlo, ylo, 12,"0")
double geterr(TMinuit &mn, const int i)
diblock
print "ROW IS " print row
void FastMCFill(TH3D *hist, const std::vector< dat > &dats, const bool isX)
void mincheck(TMinuit &mn, const bool reset=false)
std::vector< CherenkovCalc * > _ndSamples
fvar< T > fabs(const fvar< T > &x)
static binw smearbin(const vector< double > &bins, const double val, const int bin)
void Plot(const char *const tag)
static TH3D * invmask(TH3D *mask)
void AddNDSample(CherenkovCalc *calc)
static bool compare_dat(const dat &a, const dat &b)
void SetInitialParams(const params &mcparams, const enum DET det)
static double bestpars[npar]
static bool goodfdplane(const int plane)
static double llike_hist(const TH3D *const hObs, const TH3D *const hMC, const TH2D *const hObsDist, const TH2D *const hMCDist, const TH3D *const mask)
static vector< CherenkovCalc * > sfdSamples
void AddFDSample(CherenkovCalc *calc)
CherenkovCalc(const char *const dataFileName, const char *const mcFileName, const char *const dirName, const char *const plot_name, const std::vector< double > &binX, const std::vector< double > &binY, const std::vector< double > &binZ, const bool isFD_)
static const int stat_req
const double kPigtails[kCellsPerModule]
static const unsigned int npar
const XML_Char const XML_Char * data
static double clamp(const double v, const double mi, const double ma)
std::vector< double > atten_cache_long
TSpline3 hi("hi", xhi, yhi, 18,"0")
double peWeight(const bool isX, const dat &d)
static const unsigned int maxDATAhitsPERw
static const int kCellsPerModule
static const unsigned int maxMChitsPERw
double exact_atten(const double dist, const bool longway)
std::vector< double > wbins
static bool goodfdcell(__attribute__((unused)) const bool isX, __attribute__((unused)) const int cell)
static void saneProjectionXZ(TH2D *out, TH3D *in)
static CherenkovFitter * thefitter
fvar< T > exp(const fvar< T > &x)
CherenkovFitter(const params &mcparams)
printf("%d Experimental points found\n", nlines)
bool accepthit(const bool isFD, const bool isX, const int plane, const int cell, const float pathlength, const float disttostop, const float w, const float PE)
static vector< CherenkovCalc * > sndSamples
static double _exact_atten(const double attB, const double inv_att1, const double inv_att2, const double dist, const double rngeff, const bool longway)
double getpigtail(const int cell, const bool isX)
bool fill_no_overflow(TH3D *h, const double x, const double y, const double z, const double weight=1)
static float min(const float a, const float b, const float c)
__attribute__((unused)) static void Console(TMinuit &mn)
static double lowest_llike
bool equalsx(const detparams &b)
std::vector< CherenkovCalc * > _fdSamples
void fill_hit_cache_and_init_things()
static const int stat_warn_level
static bool complain_about_problems
static unsigned int getpebin(const double pe, const std::vector< double > &bins)
void Flatplots(CherenkovCalc &calc, const char *const title1, const char *const title2)
void TwoDplots(CherenkovCalc &calc, const char *const title)
std::vector< double > atten_cache_short
static double getpar(TMinuit &mn, const int i)
static void Add(TH3D *h, const int bx, const int by, const int bz, const double w)
std::vector< double > distbins
std::vector< double > extpebins
bool ok_w(const float w, const bool isX)
static const double epsilonll
static void randomparameters(TMinuit &mn)
T max(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
bool equalsy(const detparams &b)
void FillMCHistos(const detparams &mcparams, const bool changed_x, const bool changed_y)
double CalcChi2(const detparams &mcparams, const bool changed_x, const bool changed_y)
void Fit(const params &mcparams)
static TTreeReader * makereader(const char *const dir, TFile *file)
static void intermediate_plot(const int signal)