62 int main(
int argc, 
char **argv)
 
   66   JLimit_t&              numberOfEvents = inputFile.getLimit();
 
   75   bool                   globalOutputOnly;
 
   83     JParser<> zap(
"Example program to examine rates as a function of time on ms-level timescales.");
 
   87     zap[
'n'] = 
make_field(numberOfEvents)      = JLimit::max();
 
   89     zap[
'C'] = 
make_field(selector)            = getROOTClassSelection<JDAQTimesliceTypes_t>();
 
   90     zap[
'T'] = 
make_field(TMax_ns,       
"Time window for local coincidences (if 0 run in L0 mode)")  =    0.0;
 
   91     zap[
'S'] = 
make_field(TMaxSelf_ns,   
"Time window for merge of double pulses")                            =   10.0;
 
   92     zap[
'B'] = 
make_field(binWidth_ms,   
"Bin width (experimental)")                                     =      1;
 
   93     zap[
'V'] = 
make_field(backVeto,      
"Apply retroactive veto.");
 
   94     zap[
'D'] = 
make_field(mode2D,        
"L1 mode: create 2D histogram with time differences of coincidences (heavy memory usage, ignored if TMax_ns = 0)");
 
   95     zap[
'O'] = 
make_field(globalOutputOnly,  
"Write only aggregate histograms");
 
   96     zap[
'M'] = 
make_field(multiplicityRange, 
"L1 mode: multiplicity range (ignored if TMax_ns = 0)")   = 
JRange<int>(2,31);
 
  103   catch(
const exception &error) {
 
  104     FATAL(error.what() << endl);
 
  110     FATAL(
"Frame time must be an integer multiple of bin width");
 
  130   pts->configure(inputFile);
 
  132   int fEnd   = pts->rbegin()->getFrameIndex();
 
  133   int fStart = pts->begin( )->getFrameIndex();
 
  135   if (fEnd > inputFile.getUpperLimit()) {
 
  136     fEnd = fStart + inputFile.getUpperLimit();
 
  140   double tStart_ms = (fStart - 1) * 
getFrameTime() / 1.0e6;
 
  142   int     runNumber   = pts->begin()->getRunNumber();
 
  144   TString runTag      = Form(
"%d" , runNumber);
 
  146   double tRun_ms = tEnd_ms - tStart_ms; 
 
  148   NOTICE(
"START/END/DURATION [s]: " << tStart_ms / 1000 << 
" " << tEnd_ms / 1000 << 
" " << tRun_ms / 1000 << endl);
 
  169   int nx = (tEnd_ms - tStart_ms) / binWidth_ms;
 
  171   int x_inf = tStart_ms;
 
  173   JManager_t RT_DOM(
new TH1F(
"RT_%", NULL, nx      , x_inf, tEnd_ms));  
 
  174   JManager_t NC_DOM(
new TH1F(
"NC_%", NULL, nx / 100, x_inf, tEnd_ms));  
 
  176   TString rt_tag = runTag + TString(
".RT_DET_%");
 
  177   TString nc_tag = runTag + TString(
".NC_DET_%"); 
 
  179   JManager_t RT_DET(
new TH1F(rt_tag, NULL, nx,       x_inf, tEnd_ms));  
 
  180   JManager_t NC_DET(
new TH1F(nc_tag, NULL, nx / 100, x_inf, tEnd_ms));  
 
  191     if (nx >= max_size) {
 
  192       FATAL(
"2D histogram size not supported by ROOT file output; limit input size (-n) below " << floor(max_size / 100.0) << endl);
 
  195     TString rt2d_tag = runTag + TString(
".RT2D_DET"); 
 
  197     hT = 
new h2d_t(rt2d_tag, NULL, nx, x_inf, tEnd_ms, ny, -TMax_ns, +TMax_ns);
 
  212   if (pts->hasNext()) {
 
  213     curr = *(pts->next());
 
  216     FATAL(
"Input file is too short.");
 
  221   for ( ; pts->hasNext() && counter != inputFile.getLimit(); ++counter) {
 
  223     STATUS(
"timeslice: " << setw(10) << counter << 
'\r'); 
DEBUG(endl);
 
  237     if (backVeto && ((in - ic) == 1)) { 
 
  239       summaryRouter.
update(nextSummary);
 
  244     for (JDAQTimeslice::const_iterator frame = curr.begin(); frame != curr.end(); ++frame) {
 
  246       const int      DOMID       = frame->getModuleID();
 
  250       TH1F* RD = RT_DOM[moduleLabel];
 
  256       if (frame->testHighRateVeto() || frame->testFIFOStatus()) {
 
  258           veto[pmt] = ( frame->testHighRateVeto(pmt) || frame->testFIFOStatus(pmt) );
 
  265       if (nextSummary != NULL) {
 
  280       int nActiveChannels = count(veto.begin(), veto.end(), 
false);
 
  282       NC_DOM[moduleLabel]->Fill(tTimeslice_ms, nActiveChannels);
 
  287       JSuperFrame2D_t& buffer = JSuperFrame2D_t::demultiplex(*frame, module);
 
  289       for (JSuperFrame2D_t::iterator i = buffer.begin(); i != buffer.end(); ++i) {
 
  290         if (veto[i->getPMTAddress()]) {
 
  297       JSuperFrame1D_t& buffer1D = JSuperFrame1D_t::multiplex(buffer);
 
  305         if (totRange_ns(h->getToT())) {
 
  310       if (data.size() > 1) {
 
  315           sort(data.begin(), data.end());
 
  323           const double tHit = p->getT();
 
  324           const double tHit_ms = tTimeslice_ms + (tHit / 1.0e6);
 
  326           if (TMax_ns == 0.0) {
 
  338             while (++q != data.end() && q->getT() - p->getT() <= TMax_ns) {}
 
  342             if (multiplicityRange(M)) {
 
  356                     double dt = JCombinatorics::getSign(__p->getPMT(), __q->getPMT()) * (__q->getT() - __p->getT());
 
  358                     hT->Fill(tHit_ms, dt, 1.0 / W);
 
  378     if (nextSummary != NULL) { 
delete nextSummary; }
 
  387   NOTICE(
"Processing histograms." << endl);
 
  389   for (JDetector::const_iterator module = 
detector.begin(); module != 
detector.end(); ++module) {
 
  393     if (RT_DOM.count(moduleLabel) && NC_DOM.count(moduleLabel)) {
 
  395       TH1F* rt = RT_DOM.at(moduleLabel);
 
  396       TH1F* nc = NC_DOM.at(moduleLabel);
 
  398       for (
int b = 1; b <= rt->GetXaxis()->GetNbins(); b++) {
 
  400         double r = rt->GetBinContent(b);
 
  401         double t = rt->GetBinCenter( b);
 
  403         RT_DET[
"SUM"]->Fill(t, 
r);
 
  408       for (
int b = 1; b <= nc->GetXaxis()->GetNbins(); b++) {
 
  410         double n = nc->GetBinContent(b);
 
  411         double t = nc->GetBinCenter(b );
 
  413         NC_DET[
"SUM"]->Fill(t, 
n);
 
  419       DEBUG(moduleLabel << 
" not active." << endl);
 
  425   NOTICE(
"Writing output file" << endl);
 
  431     NOTICE(
"Writing 1D histograms" << endl);
 
  436     NOTICE(
"Writing 2D histogram" << endl);
 
  442     if (!globalOutputOnly) {
 
  444       TString dir_tag = runTag + TString(
".Modules");
 
  446       NOTICE(
"Writing individual modules histograms" << endl);
 
  448       TDirectory* dir = out.mkdir(dir_tag);
 
  453     NOTICE(
"Closing file" << endl);