82 const double chi2 = std::numeric_limits<double>::max())
96 return chi2 != std::numeric_limits<double>::max();
128 int main(
int argc,
char **argv)
135 typedef JParallelFileScanner_t::multi_pointer_type multi_pointer_type;
138 JParallelFileScanner_t inputFile;
146 size_t numberOfPrefits;
156 JParser<> zap(
"Program to perform fit of muon energy to data.");
161 zap[
'n'] =
make_field(numberOfEvents) = JLimit::max();
163 zap[
'R'] =
make_field(roadWidth_m) = numeric_limits<double>::max();
165 zap[
'B'] =
make_field(R_Hz,
"Default background rate if no summary data are available.") = 6.0e3;
168 zap[
'x'] =
make_field(X) = JEnergyRange(1.0, 8.0);
171 zap[
'M'] =
make_field(mestimator) = EM_NORMAL, EM_LORENTZIAN, EM_LINEAR, EM_NULL;
176 catch(
const exception& error) {
177 FATAL(error.what() << endl);
204 JRegressor_t::T_ns = T_ns;
206 const JEnergy ENERGY_RESOLUTION(0.01);
209 JRegressor_t fit(pdfFile);
211 switch (mestimator) {
214 NOTICE(
"Using the normal M-Estimator." << endl);
219 NOTICE(
"Using the Lorentzian M-Estimator." << endl);
224 NOTICE(
"Using the linear M-Estimator." << endl);
229 NOTICE(
"Using the JEnergy likelihood directly." << endl);
234 FATAL(
"Invalid M-Estimator." << endl);
238 if (fit.getRmax() < roadWidth_m) {
239 roadWidth_m = fit.getRmax();
247 while (inputFile.hasNext()) {
249 STATUS(
"event: " << setw(10) << inputFile.getCounter() <<
'\r');
DEBUG(endl);
251 multi_pointer_type ps = inputFile.next();
257 summaryRouter.
update(*tev);
259 JEvt::iterator __end = evt->end();
265 if (evt->begin() != __end) {
267 copy(evt->begin(), __end, back_inserter(out));
269 if (numberOfPrefits > 0) {
270 advance(__end = evt->begin(), min(numberOfPrefits, out.size()));
273 partial_sort(evt->begin(), __end, evt->end(),
qualitySorter);
275 __end = partition(evt->begin(), __end,
JHistory::is_event(evt->begin()->getHistory()));
280 buildL0(*tev, moduleRouter,
true, back_inserter(dataL0));
283 for (JEvt::const_iterator track = evt->begin(); track != __end; ++track) {
292 for (JDataL0_t::const_iterator i = dataL0.begin(); i != dataL0.end(); ++i) {
299 top.insert(i->getPMTIdentifier());
309 for (JDetector::const_iterator module = subdetector.begin(); module != subdetector.end(); ++module) {
313 for (
size_t i = 0; i != module->size(); ++i) {
317 if (!module->getPMT(i).has(JPMT::DAQ_STATUS) &&
321 double rate_Hz = summary.
getRate(i);
323 if (rate_Hz <= 0.0) {
324 rate_Hz = summaryRouter.
getRate();
329 data.push_back(
JNPEHit(fit.getNPE(module->getPMT(i), rate_Hz), count));
336 buffer.push_back(
JNPEHit(fit.getNPE(*module, R_Hz), total));
344 if (start.
is_valid() && !buffer.empty()) {
350 if (track_start != buffer.end()) {
354 __begin = lower_bound(data.begin(), data.end(), track_start->getZ(),
make_comparator(&JNPEHit::getZ));
359 const int NDF =
distance(__begin, data.end()) - 1;
370 for (
int i = 0; i != N; ++i) {
371 result[i].x = X.getLowerLimit() + i * (X.getUpperLimit() - X.getLowerLimit()) / (N-1);
378 for (
int i = 0; i != N; ++i) {
422 }
while (
result[4].x -
result[0].x > ENERGY_RESOLUTION);
431 const double chi2 =
result[2].chi2;
432 const double E =
result[2].x.getE();
437 double noise_likelihood = 0.0;
442 noise_likelihood += log10(dom->getP());
443 nhits += dom->getN();
451 out.rbegin()->setE(correct(E));
455 out.rbegin()->setW(track->getW());