73 using namespace KM3NETDAQ;
79 bool overwriteDetector;
81 int numberOfTimeslices;
90 JParser<> zap(
"Example program to search for correlations between triggered events and timeslice data.");
92 zap[
'f'] =
make_field(inputFile,
"input file.");
94 zap[
'a'] =
make_field(detectorFile,
"detector file.");
95 zap[
'A'] =
make_field(overwriteDetector,
"overwrite detector file provided through '-a' with correct time offsets.");
96 zap[
'n'] =
make_field(numberOfEvents) = JLimit::max();
98 zap[
'N'] =
make_field(numberOfTimeslices,
"time slice difference between triggered event and L1.") = 100;
99 zap[
'W'] =
make_field(binWidth_ns,
"bin width for output histograms." ) = 10e3;
100 zap[
'p'] =
make_field(Pmin,
"minimal probability for background to be signal.") = 1.0e-7;
101 zap[
'C'] =
make_field(selector,
"data type selection (default is all).") =
"", getROOTClassSelection<JDAQTimesliceTypes_t>();
107 catch(
const exception& error) {
108 FATAL(error.what() << endl);
124 FATAL(
"Empty detector " << detectorFile << endl);
139 const Double_t xmin = -(numberOfTimeslices + 1) *
getFrameTime() - 0.5*binWidth_ns;
140 const Double_t xmax = +(numberOfTimeslices + 1) *
getFrameTime() + 0.5*binWidth_ns;
141 const Int_t nx = (Int_t) ((xmax - xmin) / binWidth_ns);
143 JManager_t manager(
new TH1D(
"M_%", NULL, nx, xmin, xmax));
151 if (selector ==
"") {
159 FATAL(
"No timeslice data." << endl);
162 NOTICE(
"Selected class " << ps->getClassName() << endl);
168 ps->configure(inputFile);
171 ps->setLimit(inputFile.getLimit());
179 STATUS(
"event: " << setw(10) <<
in.getCounter() <<
'\r');
DEBUG(endl);
188 t0 +=
getTime(*hit, router.getPMT(*hit));
194 buffer[
event->getFrameIndex()].push_back(t0);
199 while (ps->hasNext()) {
201 STATUS(
"event: " << setw(10) << ps->getCounter() <<
'\r');
DEBUG(endl);
205 map_type::const_iterator p = buffer.lower_bound(timeslice->
getFrameIndex() - numberOfTimeslices);
206 map_type::const_iterator q = buffer.upper_bound(timeslice->
getFrameIndex() + numberOfTimeslices);
208 int number_of_events = 0;
210 for (map_type::const_iterator i = p; i != q; ++i) {
211 number_of_events += i->second.size();
214 if (number_of_events == 0) {
218 for (JDAQTimeslice::const_iterator frame = timeslice->begin(); frame != timeslice->end(); ++frame) {
222 buildL1(*frame, router.getModule(frame->getModuleID()), back_inserter(data));
224 TH1D*
h1 = manager[frame->getModuleID()];
228 const double t1 = *hit + frame->getFrameIndex() *
getFrameTime();
230 for (map_type::const_iterator i = p; i != q; ++i) {
231 for (map_type::mapped_type::const_iterator
j = i->second.begin();
j != i->second.end(); ++
j) {
233 const double t0 = *
j;
246 TF1 f1(
"f1",
"[0]*exp(-0.5*(x-[1])*(x-[1])/([2]*[2])) + [3]");
257 for (JDetector::const_iterator module =
detector.begin(); module !=
detector.end(); ++module) {
259 status[module->getID()] = DEFAULT;
261 JManager_t::iterator p = manager.find(module->getID());
263 if (p == manager.end() || p->second->GetEntries() == 0) {
265 status[module->getID()] = NODATA;
270 TH1D* h1 = p->second;
276 Double_t sigma = 250.0;
279 for (
int i = 1; i != h1->GetNbinsX(); ++i) {
281 const Double_t x = h1->GetBinCenter (i);
282 const Double_t y = h1->GetBinContent(i);
292 ymin /= h1->GetNbinsX();
294 f1.SetParameter(0, ymax);
295 f1.SetParameter(1, x0);
296 if (binWidth_ns < sigma)
297 f1.SetParameter(2, sigma);
299 f1.FixParameter(2, binWidth_ns/sqrt(12.0));
300 f1.SetParameter(3, ymin);
304 h1->Fit(&f1, option.c_str(),
"same", x0 - 5 * sigma, x0 + 5 * sigma);
308 f1.GetParameter(0) >= f1.GetParameter(3)) {
310 status[module->getID()] = IN_SYNC;
319 for (Int_t i = 1, ns = -(numberOfTimeslices + 1); i <= h1->GetNbinsX(); ++i) {
321 const Double_t x = h1->GetBinCenter (i);
322 const Double_t y = h1->GetBinContent(i);
324 while (x > (ns + 1) *
getFrameTime() - TMax_ns) { ++ns; }
328 else if (fabs(x - ns *
getFrameTime()) < 10.0 * TMax_ns)
332 DEBUG(
"Module " << setw(8) << module->getID() << endl);
336 const Double_t y = bg[i->first].getTotal() * i->second.getCount() / bg[i->first].getCount();
337 const Double_t
P = TMath::PoissonI(i->second.getTotal(), y);
339 DEBUG(
"Peak at " << setw(4) << i->first <<
" [frame time] "
341 <<
FIXED(7,1) << i->second.getTotal() <<
" / "
342 <<
FIXED(7,1) << y <<
' '
345 if (i->second.getTotal() > y && P < Pmin)
351 if (!(sn.size() == 1 &&
352 sn.begin()->first == 0)) {
354 ERROR(
"Module " << setw(8) << module->getID() <<
" number of peaks " << sn.size() << endl);
357 ERROR(
"Peak at " << setw(4) << i->first <<
" [frame time] "
359 <<
FIXED(7,1) << i->second.getTotal() <<
" / "
360 <<
FIXED(7,1) << bg[i->first].getTotal() * i->second.getCount() / bg[i->first].getCount() << endl);
363 status[module->getID()] = (sn.size() == 1 ? OUT_SYNC :
ERROR);
367 if (overwriteDetector) {
373 if (i->second != IN_SYNC) {
375 NOTICE(
"Module " << setw(8) << i->first <<
" set PMTs to out-of-sync." << endl);
379 for (JModule::iterator pmt = module.begin(); pmt != module.end(); ++pmt) {
396 if (i->second == IN_SYNC) {
399 if (i->second != IN_SYNC &&
400 i->second != NODATA) {
405 NOTICE(
"Number of modules out/in sync " << nout <<
'/' << nin << endl);
407 QAQC(nin <<
' ' << nout << endl);
Utility class to parse command line options.
Data structure for a composite optical module.
Auxiliary class to select ROOT class based on class name.
then for HISTOGRAM in h0 h1
Auxialiary class to assert type conversion.
Auxiliary class for a type holder.
Auxiliary data structure for floating point format specification.
double getTime(const Hit &hit)
Get true time of hit.
Template definition for direct access of elements in ROOT TChain.
Simple wrapper around JModuleRouter class for direct addressing of PMT data in detector data structur...
int getFrameIndex() const
Get frame index.
The template JSinglePointer class can be used to hold a pointer to an object.
Auxiliary class for defining the range of iterations of objects.
Auxiliary class to manage set of compatible ROOT objects (e.g. histograms) using unique keys...
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
double getFrameTime()
Get frame time duration.
void store(const std::string &file_name, const JDetector &detector)
Store detector to output file.
double getMaximalTime(const double R_Hz)
Get maximal time for given rate.
Auxiliary class to select JTreeScanner based on ROOT class name.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
#define QAQC(A)
QA/QC output macro.
Auxiliary data structure for L1 build parameters.
const JLimit & getLimit() const
Get limit.
do set_variable DETECTOR_TXT $WORKDIR detector
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Auxiliary data structure for floating point format specification.
int qaqc
QA/QC file descriptor.
#define DEBUG(A)
Message macros.