67 JLimit_t& numberOfEvents = inputFile.getLimit();
72 int numberOfTimeslices;
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);
115 FATAL(
"Empty detector " << detectorFile << endl);
122 typedef double hit_type;
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));
142 if (selector ==
"") {
150 FATAL(
"No timeslice data." << endl);
153 NOTICE(
"Selected class " << ps->getClassName() << endl);
159 ps->configure(inputFile);
162 ps->setLimit(inputFile.getLimit());
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);
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() <<
" / "
354 status[module->getID()] = (sn.size() == 1 ? OUT_OF_SYNC :
ERROR);
364 parameters.
load(pmtFile.c_str());
370 if (i->second != IN_SYNC) {
372 NOTICE(
"Module " << setw(8) << i->first <<
" set QEs of all PMTs to zero." << endl);
380 ofstream out(pmtFile.c_str());
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);