Calculate energy, time and chi2 for one channel using fitted pulse shape.
Method uses HFITV.
311 if (
rms > 0.0)
break;
315 if (
rms > 0.0)
break;
319 if (
rms > 0.0)
break;
324 }
else if (
igain == 1) {
328 if (
rms > 0.0)
break;
332 if (
rms > 0.0)
break;
336 if (
rms > 0.0)
break;
362 <<
" ifit1=" << ifit1
363 <<
" ifit2=" << ifit1 + nfit - 1
369 <<
" demoCh=" << ((demo)?
"true":
"false") );
371 std::vector<float> samples =
digit->samples();
372 samples.erase(samples.begin(),samples.begin()+
m_firstSample);
374 double maxsamp = 0.0;
380 bool no_signal =
true;
381 pedestal = samples[0];
382 const double delta = 1.e-6;
384 for (
int isamp = 0; isamp < nfit; ++isamp) {
385 int j = isamp + ifit1;
387 yvec0[isamp] = samples[j];
388 if (no_signal) no_signal = (fabs(samples[j] - pedestal) < delta);
396 ATH_MSG_VERBOSE(
"Saturated ADC value yvec0[" << isamp <<
"]=" << yvec0[isamp]
401 ATH_MSG_VERBOSE(
"Zero ADC value yvec0[" << isamp <<
"]=" << yvec0[isamp]
402 <<
" RMS=" << eyvec[isamp] );
406 if (yvec0[isamp] > maxsamp) {
409 maxsamp = yvec0[isamp];
412 if (yvec0[isamp] < minsamp) {
413 minsamp = yvec0[isamp];
417 <<
", xvec=" << xvec[isamp]
418 <<
", yvec0=" << yvec0[isamp]
419 <<
", eyvec=" << eyvec[isamp] );
428 double pedg = (yvec0[0] + yvec0[nfit - 1]) / 2.0;
462 double expectedTime = 0.;
471 <<
" ipeakMax=" << ipeakMax
472 <<
" ipeakMin=" << ipeakMin
473 <<
" fixedTime=" << ((fixedTime) ?
"true" :
"false") );
475 const std::vector<double>* tpulse = &
m_dummy;
476 const std::vector<double>* ypulse = &
m_dummy;
477 const std::vector<double>* tdpulse = &
m_dummy;
478 const std::vector<double>* dpulse = &
m_dummy;
479 const std::vector<double>* tleak = &
m_dummy;
480 const std::vector<double>* yleak = &
m_dummy;
481 const std::vector<double>* tdleak = &
m_dummy;
482 const std::vector<double>* dleak = &
m_dummy;
568 double gval, gpval,
sy, syg, sygp, sg, sgp, sgg, sgpgp, sggp, serr, err2;
569 double dgg0, dgg, dggp, dgpgp, dyg, dygp,
dg, dc,
xd;
570 double sllp, sylp, slplp, dleakage, leakage;
571 double fixtau = 0.0, fixped = 0.0, fixampl = 0.0, fixchi2 =
MAX_CHI2;
572 double leaktau = 0.0, leakped = 0.0, leakampl = 0.0, leakchi2 =
MAX_CHI2;
573 double cistau = 0.0, cisped = 0.0, cisampl = 0.0, cisatau = 0.0, cischi2 =
MAX_CHI2;
582 if (tempChi2 < oldchi2) oldchi2 = tempChi2;
599 for (
int isamp = 0; isamp < nfit; ++isamp) {
600 ATH_MSG_VERBOSE (
"Lo gain leakage xvec[" << isamp <<
"]=" << xvec[isamp] );
602 leakage =
pulse(xvec[isamp], tleak, yleak);
603 dleakage =
derivative(xvec[isamp], tdleak, dleak);
606 yvec[isamp] = yvec0[isamp] - pedg;
609 <<
" yvec0[" << isamp <<
"]=" << yvec0[isamp]
610 <<
" pedg=" << pedg);
612 sllp += leakage * dleakage;
613 sylp +=
yvec[isamp] * dleakage;
614 slplp += dleakage * dleakage;
617 if (fabs(slplp) >
EPS_DG && !fixedTime) {
618 leaktau = (sllp - sylp) / slplp;
629 <<
" slplp=" << slplp
630 <<
" leaktau=" << leaktau);
640 for (
int isamp = 0; isamp < nfit; ++isamp) {
641 leakage =
pulse(xvec[isamp], tleak, yleak);
643 yvec[isamp] = yvec0[isamp] - leakage;
646 <<
" yvec0[" << isamp <<
"]=" << yvec0[isamp]
647 <<
" leakage=" << leakage );
649 err2 = eyvec[isamp] * eyvec[isamp];
652 syg +=
yvec[isamp] * gval / err2;
653 sgg += gval * gval / err2;
657 dgg0 = sg * sg - serr * sgg;
658 if (fabs(dgg0) >
EPS_DG) {
659 leakampl = (
sy * sg - serr * syg) / dgg0;
660 leakped = (syg * sg -
sy * sgg) / dgg0;
674 for (
int isamp = 0; isamp < nfit; ++isamp) {
676 leakage =
pulse(xvec[isamp], tleak, yleak);
677 xd = yvec0[isamp] - (gval + leakage);
678 leakchi2 = leakchi2 + (
xd *
xd) / (eyvec[isamp] * eyvec[isamp]);
681 <<
" yvec0[" << isamp <<
"]=" << yvec0[isamp]
683 <<
", leakage=" << leakage
687 leakchi2 = leakchi2/(nfit-3.0);
690 <<
" leakped=" << leakped
691 <<
" leakampl=" << leakampl
692 <<
" leakchi2=" << leakchi2 );
700 for (
int isamp = 0; isamp < nfit; ++isamp) {
701 leakage =
pulse(xvec[isamp], tleak, yleak);
704 yvec[isamp] = yvec0[isamp] - leakage;
707 <<
" yvec0[" << isamp <<
"]=" << yvec0[isamp]
708 <<
" leakage=" << leakage
709 <<
" yvec[" << isamp <<
"]=" <<
yvec[isamp] );
725 for (
int isamp = 0; isamp < nfit; ++isamp) {
727 gpval =
derivative(xvec[isamp], tdpulse, dpulse);
728 err2 = eyvec[isamp] * eyvec[isamp];
732 syg +=
yvec[isamp] * gval / err2;
733 sygp +=
yvec[isamp] * gpval / err2;
734 sgg += gval * gval / err2;
735 sggp += gval * gpval / err2;
736 sgpgp += gpval * gpval / err2;
740 dgg = sgg - sg * sg / serr;
741 dggp = sggp - sg * sgp / serr;
742 dgpgp = sgpgp - sgp * sgp / serr;
743 dyg = syg -
sy * sg / serr;
744 dygp = sygp -
sy * sgp / serr;
745 dg = dgg * dgpgp - dggp * dggp;
748 cisampl = (dyg * dgpgp - dygp * dggp) /
dg;
749 cisatau = (dyg * dggp - dygp * dgg) /
dg;
751 - (dyg * dgpgp * sg - dygp * dggp * sg + dyg * dggp * sgp - dygp * dgg * sgp) /
dg)
754 if (fabs(cisampl) >
EPS_DG) {
755 cistau = cisatau / cisampl;
777 <<
" sgpgp=" << sgpgp <<
endmsg;
781 <<
" sgpgp=" << sgpgp
787 <<
" cisped=" << cisped
788 <<
" cisampl=" << cisampl <<
endmsg;
797 for (
int isamp = 0; isamp < nfit; ++isamp) {
799 leakage =
pulse(xvec[isamp], tleak, yleak);
801 yvec[isamp] = yvec0[isamp] - leakage;
803 cischi2 = cischi2 + (
xd *
xd) / (eyvec[isamp] * eyvec[isamp]);
806 <<
" yvec[" << isamp <<
"]=" <<
yvec[isamp]
807 <<
" leakage=" << leakage
812 cischi2 = cischi2 / (nfit - 3.0);
818 if ((cischi2 < leakchi2) && !fixedTime) {
845 for (
int isamp = 0; isamp < nfit; ++isamp) {
848 int jsamp = (
int) xvec[isamp] - delta_peak;
851 else if (jsamp >= nfit) jsamp = nfit - 1;
861 err2 = eyvec[isamp] * eyvec[isamp];
862 sy += yvec0[isamp] / err2;
864 syg += yvec0[isamp] * gval / err2;
865 sgg += gval * gval / err2;
870 dgg0 = sg * sg - serr * sgg;
871 if (fabs(dgg0) >
EPS_DG) {
872 fixampl = (
sy * sg - serr * syg) / dgg0;
873 fixped = (syg * sg -
sy * sgg) / dgg0;
875 <<
" fixped = " << fixped );
880 <<
", fixampl = " << fixampl
881 <<
" fixped = " << fixped );
888 for (
int isamp = 0; isamp < nfit; ++isamp) {
889 dc = yvec0[isamp] -
scaledPulse(xvec[isamp], tpulse, ypulse);
890 fixchi2 = fixchi2 + (dc * dc) / (eyvec[isamp] * eyvec[isamp]);
892 <<
" yvec0[" << isamp <<
"]= " << yvec0[isamp]
893 <<
" eyvec[" << isamp <<
"]= " << eyvec[isamp]
894 <<
" fixchi2= " << fixchi2 );
896 fixchi2 = fixchi2 / (nfit - 2.0);
898 <<
" nfit=" << nfit );
913 tempChi2 = oldchi2 = -fabs(fixchi2);
926 for (
int isamp = 0; isamp < nfit; ++isamp) {
927 if ((niter == 1) && (!dolas)) {
930 int jsamp = (
int) xvec[isamp] - delta_peak;
933 else if (jsamp >= nfit) jsamp = nfit - 1;
945 gpval =
derivative(xvec[isamp], tdpulse, dpulse);
948 err2 = eyvec[isamp] * eyvec[isamp];
949 sy += yvec0[isamp] / err2;
952 syg += yvec0[isamp] * gval / err2;
953 sygp += yvec0[isamp] * gpval / err2;
954 sgg += gval * gval / err2;
955 sggp += gval * gpval / err2;
956 sgpgp += gpval * gpval / err2;
962 <<
" gpval=" << gpval
966 dgg = sgg - sg * sg / serr;
967 dggp = sggp - sg * sgp / serr;
968 dgpgp = sgpgp - sgp * sgp / serr;
969 dyg = syg -
sy * sg / serr;
970 dygp = sygp -
sy * sgp / serr;
971 dg = dgg * dgpgp - dggp * dggp;
976 ampl = (dyg * dgpgp - dygp * dggp) /
dg;
978 atau = (dyg * dggp - dygp * dgg) /
dg;
980 ped = (
sy - ((dyg * dgpgp - dygp * dggp) * sg + (dyg * dggp - dygp * dgg) * sgp) /
dg)
983 if (fabs(ampl) >
EPS_DG) {
1003 <<
" sgp=" << sgp <<
endmsg;
1007 <<
" sgg=" << sgg <<
endmsg;
1010 <<
" sgpgp=" << sgpgp <<
endmsg;
1015 <<
" dgpgp=" << dgpgp
1016 <<
" dyg*dgpgp=" << (dyg * dgpgp) <<
endmsg;
1020 <<
" dygp*dggp=" << (dygp * dggp) <<
endmsg;
1024 <<
" dyg*dggp=" << (dyg * dggp) <<
endmsg;
1028 <<
" dygp*dgg=" << (dygp * dgg) <<
endmsg;
1032 <<
" tau=" << tau <<
endmsg;
1041 for (
int isamp = 0; isamp < nfit; ++isamp) {
1042 dc = yvec0[isamp] -
scaledPulse(xvec[isamp], tpulse, ypulse);
1043 tempChi2 = tempChi2 + (dc * dc) / (eyvec[isamp] * eyvec[isamp]);
1045 <<
" yvec0[" << isamp <<
"]=" << yvec0[isamp]
1046 <<
" eyvec[" << isamp <<
"]=" << eyvec[isamp]
1048 <<
" chi2=" << tempChi2 );
1051 tempChi2 = tempChi2 / (nfit - 3.0);
1053 <<
" nfit=" << nfit );
1087 if (tempChi2 <
chi2) {
1108 <<
" chi2=" << tempChi2 );
1131 <<
" Ped=" << pedestal
1132 <<
" Amplitude=" << amplitude
1133 <<
" Chi2=" <<
chi2 );
1156 ATH_MSG_VERBOSE (
"Lo gain leakage xvec[" << isamp <<
"]=" << xvec[isamp] );
1158 leakage =
pulse(xvec[isamp], tleak, yleak);
1159 dleakage =
derivative(xvec[isamp], tdleak, dleak);
1162 yvec[isamp] = yvec0[isamp] - pedg;
1165 <<
" yvec0[" << isamp <<
"]=" << yvec0[isamp]
1166 <<
" pedg=" << pedg );
1168 sllp += leakage * dleakage;
1169 sylp +=
yvec[isamp] * dleakage;
1170 slplp += dleakage * dleakage;
1173 if (fabs(slplp) >
EPS_DG && !fixedTime) {
1174 leaktau = (sllp - sylp) / slplp;
1185 <<
" slplp=" << slplp
1186 <<
" leaktau=" << leaktau );
1200 leakage =
pulse(xvec[isamp], tleak, yleak);
1202 yvec[isamp] = yvec0[isamp] - leakage;
1205 <<
" yvec0[" << isamp <<
"]=" << yvec0[isamp]
1206 <<
" leakage=" << leakage );
1208 err2 = eyvec[isamp] * eyvec[isamp];
1209 sy +=
yvec[isamp] / err2;
1211 syg +=
yvec[isamp] * gval / err2;
1212 sgg += gval * gval / err2;
1216 dgg0 = sg * sg - serr * sgg;
1217 if (fabs(dgg0) >
EPS_DG) {
1218 leakampl = (
sy * sg - serr * syg) / dgg0;
1219 leakped = (syg * sg -
sy * sgg) / dgg0;
1222 leakped =
sy / serr;
1239 leakage =
pulse(xvec[isamp], tleak, yleak);
1240 xd = yvec0[isamp] - (gval + leakage);
1241 leakchi2 = leakchi2 + (
xd *
xd) / (eyvec[isamp] * eyvec[isamp]);
1244 <<
" yvec0[" << isamp <<
"]=" << yvec0[isamp]
1246 <<
", leakage=" << leakage
1250 leakchi2 = leakchi2 / (nfit_real - 3.0);
1253 <<
" leakped=" << leakped
1254 <<
" leakampl=" << leakampl
1255 <<
" leakchi2=" << leakchi2 );
1265 leakage =
pulse(xvec[isamp], tleak, yleak);
1268 yvec[isamp] = yvec0[isamp] - leakage;
1271 <<
" yvec0[" << isamp <<
"]=" << yvec0[isamp]
1272 <<
" leakage=" << leakage
1273 <<
" yvec[" << isamp <<
"]=" <<
yvec[isamp] );
1293 gpval =
derivative(xvec[isamp], tdpulse, dpulse);
1294 err2 = eyvec[isamp] * eyvec[isamp];
1295 sy +=
yvec[isamp] / err2;
1297 sgp += gpval / err2;
1298 syg +=
yvec[isamp] * gval / err2;
1299 sygp +=
yvec[isamp] * gpval / err2;
1300 sgg += gval * gval / err2;
1301 sggp += gval * gpval / err2;
1302 sgpgp += gpval * gpval / err2;
1306 dgg = sgg - sg * sg / serr;
1307 dggp = sggp - sg * sgp / serr;
1308 dgpgp = sgpgp - sgp * sgp / serr;
1309 dyg = syg -
sy * sg / serr;
1310 dygp = sygp -
sy * sgp / serr;
1311 dg = dgg * dgpgp - dggp * dggp;
1314 cisampl = (dyg * dgpgp - dygp * dggp) /
dg;
1315 cisatau = (dyg * dggp - dygp * dgg) /
dg;
1317 - (dyg * dgpgp * sg - dygp * dggp * sg + dyg * dggp * sgp - dygp * dgg * sgp) /
dg)
1320 if (fabs(cisampl) >
EPS_DG) {
1321 cistau = cisatau / cisampl;
1343 <<
" sgpgp=" << sgpgp <<
endmsg;
1347 <<
" sgpgp=" << sgpgp
1353 <<
" cisped=" << cisped
1354 <<
" cisampl=" << cisampl <<
endmsg;
1369 leakage =
pulse(xvec[isamp], tleak, yleak);
1371 yvec[isamp] = yvec0[isamp] - leakage;
1373 cischi2 = cischi2 + (
xd *
xd) / (eyvec[isamp] * eyvec[isamp]);
1376 <<
" yvec[" << isamp <<
"]=" <<
yvec[isamp]
1377 <<
" leakage=" << leakage
1382 cischi2=cischi2/(nfit_real-3.0);
1387 if ((cischi2 < leakchi2) && !fixedTime) {
1396 tempChi2 = leakchi2;
1422 gpval =
derivative(xvec[isamp], tdpulse, dpulse);
1424 err2 = eyvec[isamp] * eyvec[isamp];
1425 sy += yvec0[isamp] / err2;
1427 sgp += gpval / err2;
1428 syg += yvec0[isamp] * gval / err2;
1429 sygp += yvec0[isamp] * gpval / err2;
1430 sgg += gval * gval / err2;
1431 sggp += gval * gpval / err2;
1432 sgpgp += gpval * gpval / err2;
1438 <<
" gpval=" << gpval
1439 <<
" sgp=" << sgp );
1442 dgg = sgg - sg * sg / serr;
1443 dggp = sggp - sg * sgp / serr;
1444 dgpgp = sgpgp - sgp * sgp / serr;
1445 dyg = syg -
sy * sg / serr;
1446 dygp = sygp -
sy * sgp / serr;
1447 dg = dgg * dgpgp - dggp * dggp;
1452 ampl = (dyg * dgpgp - dygp * dggp) /
dg;
1454 atau = (dyg * dggp - dygp * dgg) /
dg;
1456 ped = (
sy - ((dyg * dgpgp - dygp * dggp) * sg + (dyg * dggp - dygp * dgg) * sgp) /
dg)
1459 if (fabs(ampl) >
EPS_DG) {
1479 <<
" sgp=" << sgp <<
endmsg;
1483 <<
" sgg=" << sgg <<
endmsg;
1486 <<
" sgpgp=" << sgpgp <<
endmsg;
1490 <<
" dgpgp=" << dgpgp
1491 <<
" dyg*dgpgp=" << (dyg * dgpgp) <<
endmsg;
1495 <<
" dygp*dggp=" << (dygp * dggp) <<
endmsg;
1499 <<
" dyg*dggp=" << (dyg * dggp) <<
endmsg;
1503 <<
" dygp*dgg=" << (dygp * dgg) <<
endmsg;
1507 <<
" tau=" << tau <<
endmsg;
1521 dc = yvec0[isamp] -
scaledPulse(xvec[isamp], tpulse, ypulse);
1522 tempChi2 = tempChi2 + (dc * dc) / (eyvec[isamp] * eyvec[isamp]);
1524 <<
" yvec0[" << isamp <<
"]=" << yvec0[isamp]
1525 <<
" eyvec[" << isamp <<
"]=" << eyvec[isamp]
1527 <<
" chi2=" << tempChi2 );
1530 tempChi2 = tempChi2 / (nfit_real - 3.0);
1532 <<
" nfit_real=" << nfit_real );
1563 <<
" Ped=" << pedestal
1564 <<
" Amplitude=" << amplitude
1565 <<
" Chi2=" <<
chi2 );