67   JLimit_t&          numberOfEvents = inputFile.getLimit();
 
   72   int                numberOfTimeslices;
 
   75   JROOTClassSelector selector;
 
   81     JParser<> zap(
"Example program to search for correlations between triggered events and timeslice data.");
 
   86     zap[
'n'] = 
make_field(numberOfEvents)      = JLimit::max();
 
   89     zap[
'N'] = 
make_field(numberOfTimeslices)  = 100;
 
   92     zap[
'C'] = 
make_field(selector)            = 
"", getROOTClassSelection<JDAQTimesliceTypes_t>();
 
   98   catch(
const exception& error) {
 
   99     FATAL(error.what() << endl);
 
  108     load(detectorFile, detector);
 
  110   catch(
const JException& error) {
 
  114   if (detector.empty()) {
 
  115     FATAL(
"Empty detector " << detectorFile << endl);
 
  118   const JDAQHitRouter router(detector);
 
  120   const double TMax_ns = max(binWidth_ns, 
getMaximalTime(detector));
 
  122   typedef  double    hit_type;
 
  124   JBuildL0<hit_type> buildL0;
 
  125   JBuildL1<hit_type> buildL1(JBuildL1Parameters(TMaxLocal_ns, 
true));
 
  130   const Double_t xmin = -(numberOfTimeslices + 1) * 
getFrameTime() - 0.5*binWidth_ns;
 
  131   const Double_t xmax = +(numberOfTimeslices + 1) * 
getFrameTime() + 0.5*binWidth_ns;
 
  132   const Int_t    nx   = (Int_t) ((xmax - xmin) / binWidth_ns);
 
  134   JManager_t manager(
new TH1D(
"M_%", NULL, nx, xmin, xmax));
 
  138   JSinglePointer< JTreeScannerInterface<JDAQTimeslice> > ps;
 
  142   if (selector == 
"") {
 
  144     if ((ps = 
new JTreeScanner< JAssertConversion<JDAQTimesliceSN, JDAQTimeslice> >(inputFile))->getEntries() != 0 ||
 
  145         (ps = 
new JTreeScanner< JAssertConversion<JDAQTimesliceL2, JDAQTimeslice> >(inputFile))->getEntries() != 0 ||
 
  146         (ps = 
new JTreeScanner< JAssertConversion<JDAQTimesliceL1, JDAQTimeslice> >(inputFile))->getEntries() != 0 ||
 
  147         (ps = 
new JTreeScanner< JAssertConversion<JDAQTimeslice,   JDAQTimeslice> >(inputFile))->getEntries() != 0 ||
 
  148         (ps = 
new JTreeScanner< JAssertConversion<JDAQTimesliceL0, JDAQTimeslice> >(inputFile))->getEntries() != 0) {
 
  150       FATAL(
"No timeslice data." << endl);
 
  153     NOTICE(
"Selected class " << ps->getClassName() << endl);
 
  159     ps->configure(inputFile);
 
  162   ps->setLimit(inputFile.getLimit());
 
  168   for (JTreeScanner<JDAQEvent> in(inputFile.getFilename()); in.hasNext(); ) {
 
  170     STATUS(
"event: " << setw(10) << in.getCounter() << 
'\r'); 
DEBUG(endl);
 
  179       t0 += 
getTime(*hit, router.getPMT(*hit));
 
  185     buffer[
event->getFrameIndex()].push_back(t0);
 
  190   while (ps->hasNext()) {
 
  192     STATUS(
"event: " << setw(10) << ps->getCounter() << 
'\r'); 
DEBUG(endl);
 
  196     map_type::const_iterator p = buffer.lower_bound(timeslice->
getFrameIndex() - numberOfTimeslices);
 
  197     map_type::const_iterator q = buffer.upper_bound(timeslice->
getFrameIndex() + numberOfTimeslices);
 
  199     int number_of_events = 0;
 
  201     for (map_type::const_iterator i = p; i != q; ++i) {
 
  202       number_of_events += i->second.size();
 
  205     if (number_of_events == 0) {
 
  209     for (JDAQTimeslice::const_iterator frame = timeslice->begin(); frame != timeslice->end(); ++frame) {
 
  213       buildL1(*frame, router.getModule(frame->getModuleID()), back_inserter(data));
 
  215       TH1D* h1 = manager[frame->getModuleID()];
 
  219         const double t1 = *hit + frame->getFrameIndex() * 
getFrameTime();
 
  221         for (map_type::const_iterator i = p; i != q; ++i) {
 
  222           for (map_type::mapped_type::const_iterator 
j = i->second.begin(); 
j != i->second.end(); ++
j) {
 
  224             const double t0 = *
j;
 
  237   TF1 f1(
"f1", 
"[0]*exp(-0.5*(x-[1])*(x-[1])/([2]*[2])) + [3]");
 
  248   for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
 
  250     status[module->getID()] = DEFAULT;
 
  252     JManager_t::iterator p = manager.find(module->getID());
 
  254     if (p == manager.end() || p->second->GetEntries() == 0) { 
 
  256       status[module->getID()] = NODATA;
 
  261     TH1D* h1 = p->second;
 
  267     Double_t sigma = 250.0;    
 
  270     for (
int i = 1; i != h1->GetNbinsX(); ++i) {
 
  272       const Double_t x = h1->GetBinCenter (i);
 
  273       const Double_t y = h1->GetBinContent(i);
 
  283     ymin /= h1->GetNbinsX();
 
  285     f1.SetParameter(0, ymax);
 
  286     f1.SetParameter(1, x0);
 
  287     if (binWidth_ns < sigma) 
 
  288       f1.SetParameter(2, sigma);
 
  290       f1.FixParameter(2, binWidth_ns/sqrt(12.0));
 
  291     f1.SetParameter(3, ymin);
 
  295     h1->Fit(&f1, option.c_str(), 
"same", x0 - 5 * sigma, x0 + 5 * sigma);
 
  299         f1.GetParameter(0)       >= f1.GetParameter(3)) {    
 
  301       status[module->getID()] = IN_SYNC;
 
  310     for (Int_t i = 1, ns = -(numberOfTimeslices + 1); i <= h1->GetNbinsX(); ++i) {
 
  312       const Double_t x = h1->GetBinCenter (i);
 
  313       const Double_t y = h1->GetBinContent(i);
 
  315       while (x > (ns + 1) * 
getFrameTime() - TMax_ns) { ++ns; }
 
  323     DEBUG(
"Module " << setw(8) << module->getID() << endl);
 
  327       const Double_t y = bg.getTotal() * i->second.getCount() / bg.getCount();
 
  328       const Double_t P = TMath::PoissonI(i->second.getTotal(), y);
 
  330       DEBUG(
"Peak at " << setw(4) << i->first << 
" [frame time] "  
  332             << 
FIXED(7,1) << i->second.getTotal() << 
" / " 
  333             << 
FIXED(7,1) << y                    << 
' '  
  336       if (i->second.getTotal() > y && P < Pmin)
 
  342     if (!(sn.size()         == 1 && 
 
  343           sn.begin()->first == 0)) {
 
  345       WARNING(
"Module " << setw(8) << module->getID() << 
" number of peaks " << sn.size() << endl);
 
  348         WARNING(
"Peak at " << setw(4) << i->first << 
" [frame time] " 
  350                 << 
FIXED(7,1) << i->second.getTotal()                                 << 
" / " 
  351                 << 
FIXED(7,1) << bg.getTotal() * i->second.getCount() / bg.getCount() << endl);
 
  354       status[module->getID()] = (sn.size() == 1 ? OUT_OF_SYNC : 
ERROR);
 
  361     JPMTParametersMap parameters;
 
  364       parameters.load(pmtFile.c_str());
 
  366     catch(
const JException& error) {}
 
  370       if (i->second != IN_SYNC) {
 
  372         NOTICE(
"Module " << setw(8) << i->first << 
" set QEs of all PMTs to zero." << endl);
 
  375           parameters[JPMTIdentifier(i->first, pmt)].QE = 0.0;
 
  380     ofstream out(pmtFile.c_str());
 
  382     parameters.comment.add(
JMeta(argc, argv));
 
  384     out << parameters << endl;
 
  397     if (i->second == IN_SYNC) {
 
  400     if (i->second != IN_SYNC && 
 
  401         i->second != NODATA) {
 
  406   NOTICE(
"Number of modules out/in sync " << nout << 
'/' << nin << endl);
 
  408   QAQC(nin << 
' ' << nout << endl);