95 JLimit_t& numberOfEvents = inputFile.getLimit();
98 bool overwriteDetector;
100 int numberOfTimeslices;
110 JParser<> zap(
"Example program to search for correlations between triggered events and timeslice data.");
112 zap[
'f'] =
make_field(inputFile,
"input file.");
114 zap[
'a'] =
make_field(detectorFile,
"detector file.");
115 zap[
'A'] =
make_field(overwriteDetector,
"overwrite detector file provided through '-a' with module (PMT) status.");
116 zap[
'n'] =
make_field(numberOfEvents) = JLimit::max();
117 zap[
'T'] =
make_field(TMaxLocal_ns,
"time window for local coincidences (L1),") = 20.0;
118 zap[
'N'] =
make_field(numberOfTimeslices,
"time slice difference between triggered event and L1.") = 100;
119 zap[
'W'] =
make_field(binWidth_ns,
"bin width for output histograms." ) = 10e3;
120 zap[
'D'] =
make_field(deadTime_us,
"L1 dead time (us)") = 200.0;
121 zap[
'p'] =
make_field(Pmin,
"minimal probability for background to be signal.") = 1.0e-7;
122 zap[
'C'] =
make_field(selector,
"data type selection (default is all).") =
"", getROOTClassSelection<JDAQTimesliceTypes_t>();
128 catch(
const exception& error) {
129 FATAL(error.what() << endl);
143 FATAL(
"Empty detector " << detectorFile << endl);
149 const double BOOST = 20.0;
150 const double deadTime_ns = deadTime_us * 1e3;
152 NOTICE(
"Time window " <<
FIXED(7,1) << TMax_ns <<
" [ns]" << endl);
162 const Double_t
xmin = -(numberOfTimeslices + 1) *
getFrameTime() - 0.5*binWidth_ns;
163 const Double_t
xmax = +(numberOfTimeslices + 1) *
getFrameTime() + 0.5*binWidth_ns;
164 const Int_t nx = (Int_t) ((
xmax -
xmin) / binWidth_ns);
166 JManager_t manager(
new TH1D(
"M_%", NULL, nx,
xmin,
xmax));
174 if (selector ==
"") {
182 FATAL(
"No timeslice data." << endl);
185 NOTICE(
"Selected class " << ps->getClassName() << endl);
191 ps->configure(inputFile);
194 ps->setLimit(inputFile.getLimit());
202 if (in.getCounter()%1000 == 0) {
203 STATUS(
"event: " << setw(10) << in.getCounter() <<
'\r');
DEBUG(endl);
213 t0 +=
getTime(*hit, router.getPMT(*hit));
219 buffer[
event->getFrameIndex()].push_back(t0);
224 while (ps->hasNext()) {
226 if (ps->getCounter()%1000 == 0) {
227 STATUS(
"event: " << setw(10) << ps->getCounter() <<
'\r');
DEBUG(endl);
232 map_type::const_iterator p = buffer.lower_bound(timeslice->
getFrameIndex() - numberOfTimeslices);
233 map_type::const_iterator q = buffer.upper_bound(timeslice->
getFrameIndex() + numberOfTimeslices);
235 int number_of_events = 0;
237 for (map_type::const_iterator i = p; i != q; ++i) {
238 number_of_events += i->second.size();
241 if (number_of_events == 0) {
245 for (JDAQTimeslice::const_iterator frame = timeslice->begin(); frame != timeslice->end(); ++frame) {
249 buildL1(*frame, router.getModule(frame->getModuleID()), back_inserter(
data));
251 TH1D* h1 = manager[frame->getModuleID()];
253 double t1 = numeric_limits<double>::lowest();
257 const double t2 = *hit + frame->getFrameIndex() *
getFrameTime();
259 if (t2 > t1 + deadTime_ns) {
261 for (map_type::const_iterator i = p; i != q; ++i) {
262 for (map_type::mapped_type::const_iterator t0 = i->second.begin(); t0 != i->second.end(); ++t0) {
277 TF1
f1(
"f1",
"[0]*exp(-0.5*(x-[1])*(x-[1])/([2]*[2])) + [3]");
288 for (JDetector::const_iterator module =
detector.begin(); module !=
detector.end(); ++module) {
290 if (module->getFloor() != 0) {
292 status[module->getID()] = DEFAULT;
294 JManager_t::iterator p = manager.find(module->getID());
296 if (p == manager.end() || p->second->GetEntries() == 0) {
298 status[module->getID()] = NODATA;
303 TH1D* h1 = p->second;
309 Double_t
sigma = 250.0;
312 for (
int i = 1; i != h1->GetNbinsX(); ++i) {
314 const Double_t
x = h1->GetBinCenter (i);
315 const Double_t
y = h1->GetBinContent(i);
325 ymin /= h1->GetNbinsX();
327 f1.SetParameter(0, ymax);
328 f1.SetParameter(1, x0);
329 if (binWidth_ns <
sigma)
332 f1.FixParameter(2, binWidth_ns/sqrt(12.0));
333 f1.SetParameter(3, ymin);
335 for (Int_t i = 0; i !=
f1.GetNpar(); ++i) {
336 f1.SetParError(i, 0.0);
341 h1->Fit(&
f1, option.c_str(),
"same", x0 - 5 *
sigma, x0 + 5 *
sigma);
344 f1.GetParameter(0) >=
f1.GetParameter(3)) {
346 status[module->getID()] = IN_SYNC;
355 << setw(10) << module->getID() <<
' '
356 <<
FIXED(15,3) <<
f1.GetParameter(1) <<
' '
357 <<
FIXED(12,3) <<
f1.GetParameter(0) <<
' '
358 <<
FIXED(12,3) <<
f1.GetParameter(3) <<
' '
359 <<
FIXED(12,3) << fm <<
' '
360 << status[module->getID()] << endl);
367 for (Int_t i = 1,
ns = -(numberOfTimeslices + 1); i <= h1->GetNbinsX(); ++i) {
369 const Double_t
x = h1->GetBinCenter (i);
370 const Double_t
y = h1->GetBinContent(i);
384 const Double_t
y = getBackground(i->second, bg[i->first]);
385 const Double_t P = TMath::PoissonI(i->second.getTotal(),
y);
387 if (
debug >=
debug_t || status[module->getID()] != IN_SYNC) {
388 cout <<
"Module/peak " << setw(10) << module->getID() <<
' '
389 << setw(4) << i->first <<
' '
396 <<
FIXED(7,1) << i->second.getTotal() <<
" / "
399 << (i->second.getTotal() >
y && P < Pmin && i->first != 0 ?
"***" :
"") << endl;
402 if (i->second.getTotal() >
y && P < Pmin)
408 if (!(sn.size() == 1 &&
409 sn.begin()->first == 0)) {
411 status[module->getID()] = (sn.size() == 1 ? OUT_SYNC :
ERROR);
413 ERROR(
"Module/error "
414 << setw(10) << module->getID() <<
' '
415 <<
"number of peaks " << sn.size() <<
' '
416 <<
"peak " << (sn.size() == 1 ?
MAKE_CSTRING(sn.begin()->first) :
"?") <<
' '
417 << status[module->getID()] << endl);
422 if (overwriteDetector) {
428 if (i->second != IN_SYNC &&
429 i->second != NODATA) {
431 NOTICE(
"Module " << setw(8) << i->first <<
" set out-of-sync." << endl);
437 for (JModule::iterator pmt = module.begin(); pmt != module.end(); ++pmt) {
454 if (i->second == IN_SYNC) {
457 if (i->second != IN_SYNC &&
458 i->second != NODATA) {
463 NOTICE(
"Number of modules out/in sync " << nout <<
'/' << nin << endl);
465 QAQC(nin <<
' ' << nout << endl);
#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
#define MAKE_CSTRING(A)
Make C-string.
Simple wrapper around JModuleRouter class for direct addressing of PMT data in detector data structur...
Data structure for a composite optical module.
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.
static const int MODULE_OUT_OF_SYNC
Enable (disable) synchronous signal from this module if this status bit is 0 (1);.
const JPolynome f1(1.0, 2.0, 3.0)
Function.
double getTime(const Hit &hit)
Get true time of hit.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
void store(const std::string &file_name, const JDetector &detector)
Store detector to output file.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
KM3NeT DAQ data structures and auxiliaries.
double getFrameTime()
Get frame time duration.
double getMaximalTime(const double R_Hz)
Get maximal time for given rate.
std::map< int, range_type > map_type
static const int OUT_OF_SYNC
Enable (disable) synchronous signal from this PMT if this status bit is 0 (1);.
Auxiliary data structure for floating point format specification.
int getStatus() const
Get status.
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.
Auxiliary data structure for L1 build parameters.
Auxiliary data structure for floating point format specification.