60 int main(
int argc,
char **argv)
67 JLimit_t& numberOfEvents = inputFile.getLimit();
72 int numberOfTimeslices;
83 JParser<> zap(
"Example program to search for correlations between triggered events and timeslice data.");
88 zap[
'n'] =
make_field(numberOfEvents) = JLimit::max();
91 zap[
'N'] =
make_field(numberOfTimeslices) = 100;
94 zap[
'C'] =
make_field(selector) =
"", getROOTClassSelection<JDAQTimesliceTypes_t>();
100 zap.
read(argc, argv);
102 catch(
const exception& error) {
103 FATAL(error.what() << endl);
121 typedef double hit_type;
129 const Double_t xmin = -(numberOfTimeslices + 1) *
getFrameTime() - 0.5*binWidth_ns;
130 const Double_t xmax = +(numberOfTimeslices + 1) *
getFrameTime() + 0.5*binWidth_ns;
131 const Int_t nx = (Int_t) ((xmax - xmin) / binWidth_ns);
133 JManager_t manager(
new TH1D(
"M_%", NULL, nx, xmin, xmax));
141 if (selector ==
"") {
149 FATAL(
"No timeslice data." << endl);
152 NOTICE(
"Selected class " << ps->getClassName() << endl);
158 ps->configure(inputFile);
179 ps->setLimit(inputFile.getLimit());
186 map_type peaksPerDoms;
194 for (JDetector::const_iterator module =
detector.begin(); module !=
detector.end(); ++module) {
195 oosDomsId[module->getID()] =
false;
201 STATUS(
"event: " << setw(10) << in.getCounter() <<
'\r');
DEBUG(endl);
208 bool test_OOS =
false;
213 if(oosDomsId[hit->getModuleID()]) {
219 if(test_OOS)
continue;
224 buffer[
event->getFrameIndex()].push_back(t0);
231 while (ps->hasNext()) {
233 STATUS(
"event: " << setw(10) << ps->getCounter() <<
'\r');
DEBUG(endl);
237 map_type::const_iterator p = buffer.lower_bound(timeslice->
getFrameIndex() - numberOfTimeslices);
238 map_type::const_iterator q = buffer.upper_bound(timeslice->
getFrameIndex() + numberOfTimeslices);
240 int number_of_events = 0;
242 for (map_type::const_iterator i = p; i != q; ++i) {
243 number_of_events += i->second.size();
246 if (number_of_events == 0) {
250 for (JDAQTimeslice::const_iterator frame = timeslice->begin(); frame != timeslice->end(); ++frame) {
254 buildL1(*frame, router.
getModule(frame->getModuleID()), back_inserter(data));
256 TH1D* h1 = manager[frame->getModuleID()];
260 const double t1 = *hit + frame->getFrameIndex() *
getFrameTime();
262 for (map_type::const_iterator i = p; i != q; ++i) {
263 for (map_type::mapped_type::const_iterator
j = i->second.begin();
j != i->second.end(); ++
j) {
265 const double t0 = *
j;
278 Double_t most_OOS_peak = 0;
279 Int_t most_OOS_ID = 0;
281 TF1 f1(
"f1",
"[0]*exp(-0.5*(x-[1])*(x-[1])/([2]*[2])) + [3]");
289 for (JDetector::const_iterator module =
detector.begin(); module !=
detector.end(); ++module) {
293 status2[module->getID()] = DEFAULT;
295 JManager_t::iterator p = manager.find(module->getID());
297 if (p == manager.end() || p->second->GetEntries() == 0) {
299 status2[module->getID()] = NODATA;
304 TH1D* h1 = p->second;
310 Double_t sigma = 250.0;
313 for (
int i = 1; i != h1->GetNbinsX(); ++i) {
315 const Double_t x = h1->GetBinCenter (i);
316 const Double_t y = h1->GetBinContent(i);
326 ymin /= h1->GetNbinsX();
328 f1.SetParameter(0, ymax);
329 f1.SetParameter(1, x0);
330 if (binWidth_ns < sigma)
331 f1.SetParameter(2, sigma);
333 f1.FixParameter(2, binWidth_ns/sqrt(12.0));
334 f1.SetParameter(3, ymin);
338 h1->Fit(&f1, option.c_str(),
"same", x0 - 5 * sigma, x0 + 5 * sigma);
340 status = (fabs(f1.GetParameter(1)) <= 0.5*
getFrameTime() &&
341 f1.GetParameter(0) >= f1.GetParameter(3));
343 if (status) status2[module->getID()] = IN_SYNC;
350 for (Int_t i = 1, ns = -(numberOfTimeslices + 1); i <= h1->GetNbinsX(); ++i) {
352 const Double_t x = h1->GetBinCenter (i);
353 const Double_t y = h1->GetBinContent(i);
355 while (x > (ns + 1) *
getFrameTime() - TMax_ns) { ++ns; }
363 DEBUG(
"Module " << setw(8) << module->getID() << endl);
368 const Double_t P = TMath::PoissonI(i->second.getTotal(), y);
370 DEBUG(
"Peak at " << setw(4) << i->first <<
" [frame time] "
372 <<
FIXED(7,1) << i->second.getTotal() <<
" / "
373 <<
FIXED(7,1) << y <<
' '
376 if (P < Pmin && i->second.getTotal() > y)
382 if (!(sn.size() == 1 &&
383 sn.begin()->first == 0)) {
385 WARNING(
"Module " << setw(8) << module->getID() <<
" number of peaks " << sn.size() << endl);
389 const Double_t noise = bg.
getTotal() * i->second.getCount() / bg.
getCount();
391 WARNING(
"Peak at " << setw(4) << i->first <<
" [frame time] "
393 <<
FIXED(7,1) << i->second.getTotal() <<
" / "
394 <<
FIXED(7,1) << noise << endl);
396 peaksPerDoms[module->getID()].push_back(sn.size());
397 peaksPerDoms[module->getID()].push_back(i->first);
398 peaksPerDoms[module->getID()].push_back(i->second.getTotal());
399 peaksPerDoms[module->getID()].push_back(noise);
402 status2[module->getID()] = (sn.size() == 1 ? OUT_OF_SYNC :
ERROR);
409 if ((f1.GetParameter(0) > most_OOS_peak) && !(oosDomsId[module->getID()])){
411 most_OOS_peak = f1.GetParameter(0);
412 most_OOS_ID = module->getID();
417 if (most_OOS_ID != 0) {
418 oosDomsId[most_OOS_ID] =
true;
421 for (JDetector::const_iterator module =
detector.begin(); module !=
detector.end(); ++module) {
422 manager[module->getID()]->Reset(
"ICESM");
424 peaksPerDoms.clear();
432 NOTICE(
"Managing non-working and OOS DOMs." << endl);
438 parameters.
load(pmtFile.c_str());
444 if (i->second != IN_SYNC) {
446 NOTICE(
"Module " << setw(8) << i->first <<
" set QEs of all PMTs to zero." << endl);
454 ofstream out(pmtFile.c_str());
458 out << parameters << endl;
469 ofstream stream(peaks);
471 stream <<
"#DOM NB_PEAKS TIMESLICE_SHIFT SIGNAL NOISE\n";
473 for (map_type::const_iterator dom = peaksPerDoms.begin(); dom != peaksPerDoms.end(); ++dom) {
474 stream << dom->first <<
" ";
476 for (map_type::mapped_type::const_iterator data = dom->second.begin(); data != dom->second.end(); ++data) {
478 ((i%4 == 0) ? stream <<
"\n" : stream <<
" ");
490 if (i->second == IN_SYNC) {
493 if (i->second != IN_SYNC &&
494 i->second != NODATA) {
499 NOTICE(
"Number of modules out/in sync " << nout <<
'/' << nin << endl);
501 QAQC(nin <<
' ' << nout << endl);