63{
   67 
   69  JLimit_t&          numberOfEvents = inputFile.getLimit();
 
   71  string             detectorFile;
   72  double             TMaxLocal_ns;
   73  string             pmtFile;
   74  int                numberOfTimeslices;
   75  double             binWidth_ns;
   76  double             Pmin;
   80  
   81  string             peaks;
   82 
   83  try { 
   84 
   85    JParser<> zap(
"Example program to search for correlations between triggered events and timeslice data.");
 
   86    
   93    zap[
'N'] = 
make_field(numberOfTimeslices)  = 100;
 
   99    
  101 
  102    zap.read(argc, argv);
  103  }
  104  catch(const exception& error) {
  105    FATAL(error.what() << endl);
 
  106  }
  107 
  108  
  110 
  111  try {
  113  }
  116  }
  117  
  119 
  121 
  123  
  126  vector  <hit_type> 
data;  
 
  127  
  129 
  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);
  133  
  134  JManager_t manager(new TH1D("M_%", NULL, nx, xmin, xmax));
  135 
  137  
  139 
  141  
  142  if (selector == "") {
  143 
  149    } else {
  150      FATAL(
"No timeslice data." << endl);
 
  151    }
  152 
  153    NOTICE(
"Selected class " << ps->getClassName() << endl);
 
  154 
  155  } else {
  156 
  157    ps = zmap[selector];
  158    
  159    ps->configure(inputFile);
  160  }
  161 
  162  
  163
  164
  165
  166
  167
  168
  169
  170
  171
  172
  173
  174
  175
  176
  177
  178
  179 
  180  ps->setLimit(inputFile.getLimit());
  181 
  183 
  184  bool OOS = true; 
  185  map_type buffer;
  186    
  187  map_type peaksPerDoms;
  188  
  190 
  191  
  193  
  194  
  195  for (JDetector::const_iterator module = 
detector.begin(); module != 
detector.end(); ++module) {
 
  196    oosDomsId[module->getID()] = false;
  197  }
  198 
  199  do{    
  201      
  202      STATUS(
"event: " << setw(10) << in.getCounter() << 
'\r'); 
DEBUG(endl);
 
  203      
  205      
  206      
  207      
  208      double t0 = 0.0;
  209      bool test_OOS = false; 
  210      
  212        t0 += 
getTime(*hit, router.getPMT(*hit));
 
  213 
  214        if(oosDomsId[hit->getModuleID()]) {
  215          test_OOS = true;
  216          break;
  217        }
  218      }
  219 
  220      if(test_OOS) continue; 
  221 
  224      
  225      buffer[event->getFrameIndex()].push_back(t0);
  226    }    
  228    
  229    
  230    ps->rewind();
  231    
  232    while (ps->hasNext()) {
  233      
  234      STATUS(
"event: " << setw(10) << ps->getCounter() << 
'\r'); 
DEBUG(endl);
 
  235      
  237      
  238      map_type::const_iterator p = buffer.lower_bound(timeslice->
getFrameIndex() - numberOfTimeslices);
 
  239      map_type::const_iterator q = buffer.upper_bound(timeslice->
getFrameIndex() + numberOfTimeslices);
 
  240      
  241      int number_of_events = 0;
  242      
  243      for (map_type::const_iterator i = p; i != q; ++i) {
  244        number_of_events += i->second.size();
  245      }
  246      
  247      if (number_of_events == 0) {
  248        continue;
  249      }
  250      
  251      for (JDAQTimeslice::const_iterator frame = timeslice->begin(); frame != timeslice->end(); ++frame) {
  252          
  254        
  255        buildL1(*frame, router.getModule(frame->getModuleID()), back_inserter(data));
  256        
  257        TH1D* h1 = manager[frame->getModuleID()];
  258        
  259        for (vector<hit_type>::const_iterator hit = 
data.begin(); hit != 
data.end(); ++hit) {
 
  260          
  261          const double t1 = *hit + frame->getFrameIndex() * 
getFrameTime();
 
  262          
  263          for (map_type::const_iterator i = p; i != q; ++i) {
  264            for (map_type::mapped_type::const_iterator 
j = i->second.begin(); 
j != i->second.end(); ++
j) {
 
  265              
  266              const double t0 = *
j;
 
  267              
  268              h1->Fill(t1 - t0);
  269            }
  270          }
  271        }
  272      }
  273    }
  274 
  275    buffer.clear(); 
  276 
  278      
  279    Double_t most_OOS_peak = 0;
  280    Int_t most_OOS_ID = 0;
  281    
  282    TF1 
f1(
"f1", 
"[0]*exp(-0.5*(x-[1])*(x-[1])/([2]*[2])) + [3]");
 
  283    
  284    string option = "L";
  285    
  287      option += "Q";
  288    }
  289    
  290    for (JDetector::const_iterator module = 
detector.begin(); module != 
detector.end(); ++module) {
 
  291      
  292      bool status = false;
  293 
  294      status2[module->getID()] = DEFAULT;
  295      
  296      JManager_t::iterator p = manager.find(module->getID());
  297      
  298      if (p == manager.end() || p->second->GetEntries() == 0) {
  299 
  300        status2[module->getID()] = NODATA;
  301 
  302        continue;
  303      }
  304        
  305      TH1D* h1       = p->second;
  306          
  307      
  308      
  309      Double_t ymax  =   0.0;
  310      Double_t x0    =   0.0;    
  311      Double_t 
sigma = 250.0;    
 
  312      Double_t ymin  =   0.0;
  313      
  314      for (int i = 1; i != h1->GetNbinsX(); ++i) {
  315        
  316        const Double_t 
x = h1->GetBinCenter (i);
 
  317        const Double_t 
y = h1->GetBinContent(i);
 
  318        
  319        if (y > ymax) {
  322        }
  323        
  325      }
  326      
  327      ymin /= h1->GetNbinsX();
  328      
  329      f1.SetParameter(0, ymax);
 
  330      f1.SetParameter(1, x0);
 
  331      if (binWidth_ns < sigma) 
  332        f1.SetParameter(2, sigma);
 
  333      else
  334        f1.FixParameter(2, binWidth_ns/sqrt(12.0));
 
  335      f1.SetParameter(3, ymin);
 
  336      
  337      for (Int_t i = 0; i != 
f1.GetNpar(); ++i) {
 
  338        f1.SetParError(i, 0.0);
 
  339      }
  340 
  341      
  342      
  343      h1->Fit(&f1, option.c_str(), "same", x0 - 5 * sigma, x0 + 5 * sigma);
  344      
  346                f1.GetParameter(0)       >= 
f1.GetParameter(3)); 
 
  347 
  348      if (status) status2[module->getID()] = IN_SYNC;
  349 
  350        
  351      
  354      
  355      for (Int_t i = 1, ns = -(numberOfTimeslices + 1); i <= h1->GetNbinsX(); ++i) {
  356          
  357        const Double_t 
x = h1->GetBinCenter (i);
 
  358        const Double_t 
y = h1->GetBinContent(i);
 
  359        
  360        while (x > (ns + 1) * 
getFrameTime() - TMax_ns) { ++ns; }
 
  361        
  363          sn[ns].put(y);
  364        else
  365          bg    .put(y);
  366      }
  367 
  368      DEBUG(
"Module " << setw(8) << module->getID() << endl);
 
  369      
  371        
  372        const Double_t 
y = bg.getTotal() * i->second.getCount() / bg.getCount();
 
  373        const Double_t P = TMath::PoissonI(i->second.getTotal(), y);
  374 
  375        DEBUG(
"Peak at " << setw(4) << i->first << 
" [frame time] " 
  376              << "S/N = "
  377              << 
FIXED(7,1) << i->second.getTotal() << 
" / " 
  378              << 
FIXED(7,1) << y                    << 
' ' 
  380        
  381        if (P < Pmin && i->second.getTotal() > y) 
  382          ++i;               
  383        else
  384          sn.erase(i++);     
  385      }
  386      
  387      if (!(sn.size()         == 1 &&
  388            sn.begin()->first == 0)) {
  389        
  390        WARNING(
"Module " << setw(8) << module->getID() << 
" number of peaks " << sn.size() << endl);
 
  391        
  393          
  394          const Double_t noise = bg.getTotal() * i->second.getCount() / bg.getCount();
  395       
  396          WARNING(
"Peak at " << setw(4) << i->first << 
" [frame time] " 
  397                  << "S/N = "
  398                  << 
FIXED(7,1) << i->second.getTotal()                                 << 
" / " 
  399                  << 
FIXED(7,1) << noise << endl);
 
  400          
  401          peaksPerDoms[module->getID()].push_back(sn.size());
  402          peaksPerDoms[module->getID()].push_back(i->first);
  403          peaksPerDoms[module->getID()].push_back(i->second.getTotal());
  404          peaksPerDoms[module->getID()].push_back(noise);
  405        }
  406 
  407        status2[module->getID()] = (sn.size() == 1 ? OUT_SYNC : 
ERROR);
 
  408      }
  409      
  410 
  411      
  412      if (!status) {
  413        
  414        if ((
f1.GetParameter(0) > most_OOS_peak) && !(oosDomsId[module->getID()])){
 
  415          
  416          most_OOS_peak = 
f1.GetParameter(0);
 
  417          most_OOS_ID = module->getID();
  418        }
  419      }
  420    }
  421    
  422    if (most_OOS_ID != 0) {
  423      oosDomsId[most_OOS_ID] = true;
  424   
  425      
  426      for (JDetector::const_iterator module = 
detector.begin(); module != 
detector.end(); ++module) {
 
  427        manager[module->getID()]->Reset("ICESM");
  428      }
  429      peaksPerDoms.clear();
  430    }
  431    else{
  432      OOS = false;
  433    }
  434  }while(OOS);
  435    
  436  
  437  NOTICE(
"Managing non-working and OOS DOMs." << endl);
 
  438  if (pmtFile != "") {
  439 
  441 
  442    try {
  443      parameters.
load(pmtFile.c_str());
 
  444    }
  446 
  448 
  449      if (i->second != IN_SYNC) {
  450 
  451        NOTICE(
"Module " << setw(8) << i->first << 
" set QEs of all PMTs to zero." << endl);
 
  452 
  455        }
  456      }
  457    }
  458 
  459    ofstream out(pmtFile.c_str());
  460 
  462 
  463    out << parameters << endl;
  464 
  465    out.close();
  466  }
  467  
  470  }
  471 
  472  
  473  if (peaks != ""){
  474    ofstream stream(peaks);
  475 
  476    stream << "#DOM NB_PEAKS TIMESLICE_SHIFT SIGNAL NOISE\n";
  477    
  478    for (map_type::const_iterator dom = peaksPerDoms.begin(); dom != peaksPerDoms.end(); ++dom) {
  479      stream << dom->first << "  ";
  480      int i = 1;
  481      for (map_type::mapped_type::const_iterator data = dom->second.begin(); data != dom->second.end(); ++data) {
  483        ((i%4 == 0) ? stream << "\n" : stream <<  "  ");
  484        i++;
  485      }
  486    }
  487    stream.close();
  488  }
  489 
  490  
  491  int nin  = 0;
  492  int nout = 0;
  493 
  495    if (i->second == IN_SYNC) {
  496      ++nin;
  497    }
  498    if (i->second != IN_SYNC &&
  499        i->second != NODATA) {
  500      ++nout;
  501    }
  502  }
  503 
  504  NOTICE(
"Number of modules out/in sync " << nout << 
'/' << nin << endl);
 
  505 
  506  QAQC(nin << 
' ' << nout << endl);
 
  507 
  508  return 0;
  509 
  510}
#define DEBUG(A)
Message macros.
 
#define QAQC(A)
QA/QC output macro.
 
int qaqc
QA/QC file descriptor.
 
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
 
Simple wrapper around JModuleRouter class for direct addressing of PMT data in detector data structur...
 
Auxiliary class for map of PMT parameters.
 
Auxialiary class to assert type conversion.
 
The template JSinglePointer class can be used to hold a pointer to an object.
 
Utility class to parse command line options.
 
Auxiliary class to manage set of compatible ROOT objects (e.g. histograms) using unique keys.
 
Template definition for direct access of elements in ROOT TChain.
 
int getFrameIndex() const
Get frame index.
 
JTriggerCounter_t next()
Increment trigger counter.
 
const JPolynome f1(1.0, 2.0, 3.0)
Function.
 
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
 
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
 
std::set< JROOTClassSelector > getROOTClassSelection(const bool option=false)
Get ROOT class selection.
 
const char * getTime()
Get current local time conform ISO-8601 standard.
 
KM3NeT DAQ data structures and auxiliaries.
 
double getFrameTime()
Get frame time duration.
 
double getMaximalTime(const double R_Hz)
Get maximal time for given rate.
 
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
 
std::map< int, range_type > map_type
 
Auxiliary data structure for floating point format specification.
 
Auxiliary data structure to unify weights of acoustics data according to the number of pings per emit...
 
void load(const char *file_name)
Load from input file.
 
Auxiliary class for a type holder.
 
Auxiliary class to select ROOT class based on class name.
 
Auxiliary class to select JTreeScanner based on ROOT class name.
 
Auxiliary class for defining the range of iterations of objects.
 
static counter_type max()
Get maximum counter value.
 
Auxiliary data structure for L1 build parameters.
 
Auxiliary data structure for floating point format specification.