176 array <double, 3> totRange_ns;
187 JParser<> zap(
"Auxiliary program to determine PMT parameters from K40 data.");
189 zap[
'f'] =
make_field(inputFile,
"input file.");
192 zap[
'a'] =
make_field(detectorFile,
"detector file.");
193 zap[
'T'] =
make_field(TMax_ns,
"time window [ns].") = 20.0;
195 zap[
't'] =
make_field(totRange_ns,
"PMT time-over-threshold range [ns].") = { 4.0, 7.0, ToTmax_ns };
196 zap[
'b'] =
make_field(background,
"background estimation method.") = rates_t, count_t, tails_t, rndms_t;
199 zap[
'D'] =
make_field(deadTime_us,
"L1 dead time (us)") = 0.0;
206 catch(
const exception &error) {
207 FATAL(error.what() << endl);
215 if (selector == JDAQTimesliceL2::Class_Name() ||
216 selector == JDAQTimesliceSN::Class_Name()) {
217 FATAL(
"Option -C <selector> " << selector <<
" not compatible with calibration method." << endl);
220 if (selector == JDAQTimeslice ::Class_Name() ||
221 selector == JDAQTimesliceL1::Class_Name()) {
229 FATAL(
"No trigger parameters from input:" << error.
what() << endl);
232 if ((selector == JDAQTimeslice ::Class_Name() && parameters.writeL1.prescale > 0) ||
233 (selector == JDAQTimesliceL1::Class_Name())) {
235 if (parameters.TMaxLocal_ns < TMax_ns) {
236 FATAL(
"Option -T <TMax_ns> = " << TMax_ns <<
" is larger than in the trigger " << parameters.TMaxLocal_ns << endl);
239 if (background == rndms_t ||
240 background == count_t) {
241 FATAL(
"Option -C <selector> " << selector <<
" incompatible with option -b <background> " << background << endl);
247 FATAL(
"Invalid option -M <multiplicity> " << multiplicity << endl);
250 if (totRange_ns[0] > totRange_ns[1] ||
251 totRange_ns[1] > totRange_ns[2]) {
252 FATAL(
"Invalid option -t <totRange_ns> " <<
JEEPZ() << totRange_ns << endl);
255 if (background == tails_t) {
258 FATAL(
"Invalid option -B <Tail_ns> " << Tail_ns << endl);
262 FATAL(
"Invalid option -B <Tail_ns> " << Tail_ns <<
"; upper limit larger than option -T <TMax_ns> " << TMax_ns << endl);
280 FATAL(
"Empty detector." << endl);
292 t0.push_back(i * 2 * TMax_ns);
313 const Double_t ymin = -floor(TMax_ns) + 0.5;
314 const Double_t ymax = +floor(TMax_ns) - 0.5;
315 const Int_t ny = (Int_t) ((ymax - ymin) / 1.0);
317 for (JDetector::iterator module =
detector.begin(); module !=
detector.end(); ++module) {
321 if (!module->empty()) {
323 NOTICE(
"Booking histograms for module " << module->
getID() << endl);
336 const double deadTime_ns = deadTime_us * 1e3;
345 for (JMultipleFileScanner_t::const_iterator i = inputFile.begin(); i != inputFile.end(); ++i) {
347 STATUS(
"Processing: " << *i << endl);
356 STATUS(
"event: " << setw(10) << counter <<
'\r');
DEBUG(endl);
368 if (background == rates_t) {
374 ERROR(
"Frame indices do not match at "
375 <<
"[counter = " << counter <<
"]"
377 <<
"[summaryslice = " << summary.
getFrameIndex() <<
"]" << endl);
383 for (JDAQTimeslice::const_iterator frame = timeslice->begin(); frame != timeslice->end(); ++frame) {
385 if (router.
hasModule(frame->getModuleID())) {
396 if (background == count_t) {
402 }
else if (background == tails_t) {
407 }
else if (background == rndms_t) {
411 }
else if (background == rates_t) {
418 rate_Hz[i] = sum.
getRate(i) * RTU;
423 FATAL(
"Summary frame of module " << frame->getModuleID() <<
" not found at frame index " << timeslice->
getFrameIndex() << endl);
435 !rateRange_Hz(rate_Hz[i])) {
440 const JHistogram& histogram = zmap[router.
getAddress(frame->getModuleID()).
first];
441 const JCombinatorics& combinatorics = histogram.getCombinatorics();
443 TH2D* h2s = histogram.h2s;
444 TH1D* h1b = histogram.h1b;
445 TH1D* h1L = histogram.h1L;
451 JSuperFrame2D_t& buffer = JSuperFrame2D_t::demultiplex(*frame, module);
453 buffer.preprocess(option, match);
455 for (JSuperFrame2D_t::iterator i = buffer.begin(); i != buffer.end(); ++i) {
456 if (veto[i->getPMTAddress()]) {
461 JSuperFrame1D_t& data = JSuperFrame1D_t::multiplex(buffer);
467 for (JSuperFrame2D_t::iterator i = buffer.begin(); i != buffer.end(); ++i) {
472 << setw(10) << frame->getModuleID() <<
' '
474 << setw(4) << frame->size() <<
' '
475 << setw(4) << ns <<
' '
476 << setw(4) << data.size() << endl;
482 size_t numberOfSignalEvents = 0;
484 double t1 = numeric_limits<double>::lowest();
486 for (vector<hit_type>::const_iterator p = data.begin(); p != data.end(); ) {
488 vector<hit_type>::const_iterator q = p;
490 while (++q != data.end() && q->getT() - p->getT() <= TMax_ns) {}
494 if (multiplicity(N)) {
496 numberOfSignalEvents += 1;
498 if (p->getT() > t1 + deadTime_ns) {
500 for (vector<hit_type>::const_iterator __p = p; __p != q; ++__p) {
501 for (vector<hit_type>::const_iterator __q = __p; ++__q != q; ) {
503 if ((__p->getToT() >= totRange_ns[0]) &&
504 (__q->getToT() >= totRange_ns[0]) &&
505 (__p->getToT() >= totRange_ns[1] ||
506 __q->getToT() >= totRange_ns[1]) &&
507 (__p->getToT() <= totRange_ns[2]) &&
508 (__q->getToT() <= totRange_ns[2])) {
510 h2s->Fill((
double) combinatorics.
getIndex(__p->getPMT(),__q->getPMT()),
526 if (background == rndms_t) {
529 *i =
hit_type(i->getPMT(),
JHit(i->getT() + t0[i->getPMT()], i->getToT()));
532 sort(data.begin(), data.end());
534 double t1 = numeric_limits<double>::lowest();
536 for (vector<hit_type>::const_iterator p = data.begin(); p != data.end(); ) {
538 vector<hit_type>::const_iterator q = p;
540 while (++q != data.end() && q->getT() - p->getT() <= TMax_ns) {}
544 if (multiplicity(N)) {
546 if (p->getT() > t1 + deadTime_ns) {
548 for (vector<hit_type>::const_iterator __p = p; __p != q; ++__p) {
549 for (vector<hit_type>::const_iterator __q = __p; ++__q != q; ) {
551 if ((__p->getToT() >= totRange_ns[0]) &&
552 (__q->getToT() >= totRange_ns[0]) &&
553 (__p->getToT() >= totRange_ns[1] ||
554 __q->getToT() >= totRange_ns[1]) &&
555 (__p->getToT() <= totRange_ns[2]) &&
556 (__q->getToT() <= totRange_ns[2])) {
558 h1b->Fill((
double) combinatorics.
getIndex(p->getPMT(),q->getPMT()), 1.0);
570 }
else if (background == rates_t ||
571 background == count_t) {
584 if (!veto[i] && !veto[
j]) {
586 const double R1 = rate_Hz[i];
587 const double R2 = rate_Hz[
j];
594 const double N =
getP((
R1) * 2 * TMax_ns * 1e-9,
595 (R2) * 2 * TMax_ns * 1e-9,
596 (Rs -
R1 - R2) * 2 * TMax_ns * 1e-9,
600 h1b->Fill((
double) combinatorics.
getIndex(i,
j), N);
614 const int pmt1 = combinatorics.
getPair(i).first;
615 const int pmt2 = combinatorics.
getPair(i).second;
617 if (!veto[pmt1] && !veto[pmt2]) {
618 h1L->Fill(i, livetime_s);
627 if (background == tails_t) {
629 const double R = (2.0*TMax_ns) / ((ymax - ymin)/ny);
633 if (hr->is_valid()) {
638 for (
int ix = 1; ix <= h1b->GetXaxis()->GetNbins(); ++ix) {
644 for (
int iy = 1; iy <= h2s->GetYaxis()->GetNbins(); ++iy) {
646 const double y = h2s->GetYaxis()->GetBinCenter(iy) ;
648 if (Tail_ns(fabs(y))) {
649 Y += h2s->GetBinContent(ix,iy);
650 W += h2s->GetBinError (ix,iy) * h2s->GetBinError(ix,iy);
655 h1b->SetBinContent(ix, Y/N * R);
656 h1b->SetBinError (ix, sqrt(W/N) * R);
669 weights_hist.GetXaxis()->SetBinLabel(2,
WS_t);
670 weights_hist.GetXaxis()->SetBinLabel(3,
WB_t);
673 weights_hist.Fill(
WS_t, (ymax - ymin)/ny);
674 weights_hist.Fill(
WB_t, 2.0*TMax_ns);