48 int main(
int argc,
char **argv)
52 using namespace KM3NETDAQ;
60 int numberOfTimeslices;
63 JROOTClassSelector selector;
68 JParser<> zap(
"Example program to search for correlations between triggered events and timeslice data.");
73 zap[
'n'] =
make_field(numberOfEvents) = JLimit::max();
76 zap[
'N'] =
make_field(numberOfTimeslices) = 100;
79 zap[
'C'] =
make_field(selector) =
"", getROOTClassSelection<JDAQTimesliceTypes_t>();
84 catch(
const exception& error) {
85 FATAL(error.what() << endl);
94 load(detectorFile, detector);
96 catch(
const JException& error) {
100 const JDAQHitRouter router(detector);
102 const double TMax_ns = max(binWidth_ns,
getMaximalTime(detector));
106 JBuildL0<hit_type> buildL0;
107 JBuildL1<hit_type> buildL1(TMaxLocal_ns,
true);
112 const Double_t xmin = -(numberOfTimeslices + 1) *
getFrameTime() - 0.5*binWidth_ns;
113 const Double_t xmax = +(numberOfTimeslices + 1) *
getFrameTime() + 0.5*binWidth_ns;
114 const Int_t nx = (Int_t) ((xmax - xmin) / binWidth_ns);
116 JManager_t manager(
new TH1D(
"M_%", NULL, nx, xmin, xmax));
120 JSinglePointer< JTreeScannerInterface<JDAQTimeslice> > ps;
124 if (selector ==
"") {
126 if ((ps =
new JTreeScanner< JAssertConversion<JDAQTimesliceSN, JDAQTimeslice> >(inputFile))->getEntries() != 0 ||
127 (ps =
new JTreeScanner< JAssertConversion<JDAQTimesliceL2, JDAQTimeslice> >(inputFile))->getEntries() != 0 ||
128 (ps =
new JTreeScanner< JAssertConversion<JDAQTimesliceL1, JDAQTimeslice> >(inputFile))->getEntries() != 0 ||
129 (ps =
new JTreeScanner< JAssertConversion<JDAQTimeslice, JDAQTimeslice> >(inputFile))->getEntries() != 0 ||
130 (ps =
new JTreeScanner< JAssertConversion<JDAQTimesliceL0, JDAQTimeslice> >(inputFile))->getEntries() != 0) {
132 FATAL(
"No timeslice data." << endl);
135 NOTICE(
"Selected class " << ps->getClassName() << endl);
141 ps->configure(inputFile);
149 for (JTreeScanner<JDAQEvent> in(inputFile.getFilename(), inputFile.getLimit()); in.hasNext(); ) {
151 STATUS(
"event: " << setw(10) << in.getCounter() <<
'\r');
DEBUG(endl);
160 t0 +=
getTime(*hit, router.getPMT(*hit));
166 buffer[
event->getFrameIndex()].push_back(t0);
171 while (ps->hasNext()) {
173 STATUS(
"event: " << setw(10) << ps->getCounter() <<
'\r');
DEBUG(endl);
177 map_type::const_iterator p = buffer.lower_bound(timeslice->
getFrameIndex() - numberOfTimeslices);
178 map_type::const_iterator q = buffer.upper_bound(timeslice->
getFrameIndex() + numberOfTimeslices);
180 int number_of_events = 0;
182 for (map_type::const_iterator i = p; i != q; ++i) {
183 number_of_events += i->second.size();
186 if (number_of_events == 0) {
190 for (JDAQTimeslice::const_iterator frame = timeslice->begin(); frame != timeslice->end(); ++frame) {
194 buildL1(*frame, router.getModule(frame->getModuleID()), back_inserter(data));
196 TH1D* h1 = manager[frame->getModuleID()];
200 const double t1 = *hit + frame->getFrameIndex() *
getFrameTime();
202 for (map_type::const_iterator i = p; i != q; ++i) {
203 for (map_type::mapped_type::const_iterator j = i->second.begin(); j != i->second.end(); ++j) {
205 const double t0 = *j;
217 JPMTParametersMap parameters;
220 parameters.load(pmtFile.c_str());
222 catch(
const JException& error) {}
224 TF1 f1(
"f1",
"[0]*exp(-0.5*(x-[1])*(x-[1])/([2]*[2])) + [3]");
232 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
236 JManager_t::iterator p = manager.find(module->getID());
238 if (p != manager.end()) {
240 TH1D* h1 = p->second;
242 if (h1->GetEntries() != 0) {
248 Double_t sigma = 250.0;
251 for (
int i = 1; i != h1->GetNbinsX(); ++i) {
253 const Double_t x = h1->GetBinCenter (i);
254 const Double_t y = h1->GetBinContent(i);
264 ymin /= h1->GetNbinsX();
266 f1.SetParameter(0, ymax);
267 f1.SetParameter(1, x0);
268 if (binWidth_ns < sigma)
269 f1.SetParameter(2, sigma);
271 f1.FixParameter(2, binWidth_ns/sqrt(12.0));
272 f1.SetParameter(3, ymin);
276 h1->Fit(&f1, option.c_str(),
"same", x0 - 5 * sigma, x0 + 5 * sigma);
278 status = (fabs(f1.GetParameter(1)) <= 0.5*
getFrameTime() &&
279 f1.GetParameter(0) >= f1.GetParameter(3));
282 if (h1->GetEntries() != 0) {
289 for (Int_t i = 1, ns = -(numberOfTimeslices + 1); i <= h1->GetNbinsX(); ++i) {
291 const Double_t x = h1->GetBinCenter (i);
292 const Double_t y = h1->GetBinContent(i);
294 while (x > (ns + 1) *
getFrameTime() - TMax_ns) { ++ns; }
305 const Double_t y = bg.getTotal() * i->second.getCount() / bg.getCount();
306 const Double_t P = TMath::PoissonI(i->second.getTotal(), y);
308 if (i->second.getTotal() > y && P < Pmin)
314 if (sn.size() != 1) {
316 ERROR(
"Module " << setw(8) << module->getID() <<
" number of peaks " << sn.size() <<
" != 1" << endl);
319 WARNING(
"Peak at " << setw(4) << i->first <<
" [frame time] S/N = "
320 <<
FIXED(7,1) << i->second.getTotal() <<
" / "
321 <<
FIXED(7,1) << bg.getTotal() * i->second.getCount() / bg.getCount() << endl);
325 status &= (sn.size() == 1 &&
326 sn.begin()->first == 0);
332 NOTICE(
"Module " << module->getID() <<
" set QEs of all PMTs to zero." << endl);
335 parameters[JPMTIdentifier(module->getID(), pmt)].QE = 0.0;
340 ofstream out(pmtFile.c_str());
342 parameters.comment.add(
JMeta(argc, argv));
344 out << parameters << endl;
Utility class to parse command line options.
Direct access to PMT data in detector data structure for DAQ hits.
Auxiliary class to manage set of histograms.
Structure to store the ToT mean and standard deviation of the hits produced by a nanobeacon in a sour...
Dynamic ROOT object management.
Auxiliary class for a type holder.
Auxiliary data structure for floating point format specification.
double getTime(const Hit &hit)
Get true time of hit.
Data structure for detector geometry and calibration.
int getFrameIndex() const
Get frame index.
JLimit JLimit_t
Type definition of limit.
Scanning of objects from a single file according a format that follows from the extension of each fil...
I/O formatting auxiliaries.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
double getFrameTime()
Get frame time duration.
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
double getMaximalTime(const JDetector &detector)
Get maximal time between modules in detector following causality.
General purpose messaging.
Utility class to parse command line options.
ROOT TTree parameter settings.
const JLimit & getLimit() const
Get limit.
KM3NeT DAQ constants, bit handling, etc.
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
JTriggerCounter_t next()
Increment trigger counter.
#define DEBUG(A)
Message macros.
int main(int argc, char *argv[])