70 int main(
int argc,
char **argv)
74 using namespace KM3NETDAQ;
82 int numberOfTimeslices;
91 JParser<> zap(
"Example program to search for correlations between triggered events and timeslice data.");
93 zap[
'f'] =
make_field(inputFile,
"input file.");
95 zap[
'a'] =
make_field(detectorFile,
"detector file.");
96 zap[
'n'] =
make_field(numberOfEvents) = JLimit::max();
98 zap[
'P'] =
make_field(pmtFile,
"optional PMT file (to set QE of PMTs).") =
"";
99 zap[
'N'] =
make_field(numberOfTimeslices,
"time slice difference between triggered event and L1.") = 100;
100 zap[
'W'] =
make_field(binWidth_ns,
"bin width for output histograms." ) = 10e3;
101 zap[
'p'] =
make_field(Pmin,
"minimal probability for background to be signal.") = 1.0e-7;
102 zap[
'C'] =
make_field(selector,
"data type selection (default is all).") =
"", getROOTClassSelection<JDAQTimesliceTypes_t>();
108 catch(
const exception& error) {
109 FATAL(error.what() << endl);
125 FATAL(
"Empty detector " << detectorFile << endl);
132 typedef double hit_type;
140 const Double_t xmin = -(numberOfTimeslices + 1) *
getFrameTime() - 0.5*binWidth_ns;
141 const Double_t xmax = +(numberOfTimeslices + 1) *
getFrameTime() + 0.5*binWidth_ns;
142 const Int_t nx = (Int_t) ((xmax - xmin) / binWidth_ns);
144 JManager_t manager(
new TH1D(
"M_%", NULL, nx, xmin, xmax));
152 if (selector ==
"") {
160 FATAL(
"No timeslice data." << endl);
163 NOTICE(
"Selected class " << ps->getClassName() << endl);
169 ps->configure(inputFile);
172 ps->setLimit(inputFile.getLimit());
180 STATUS(
"event: " << setw(10) <<
in.getCounter() <<
'\r');
DEBUG(endl);
195 buffer[
event->getFrameIndex()].push_back(t0);
200 while (ps->hasNext()) {
202 STATUS(
"event: " << setw(10) << ps->getCounter() <<
'\r');
DEBUG(endl);
206 map_type::const_iterator p = buffer.lower_bound(timeslice->
getFrameIndex() - numberOfTimeslices);
207 map_type::const_iterator q = buffer.upper_bound(timeslice->
getFrameIndex() + numberOfTimeslices);
209 int number_of_events = 0;
211 for (map_type::const_iterator i = p; i != q; ++i) {
212 number_of_events += i->second.size();
215 if (number_of_events == 0) {
219 for (JDAQTimeslice::const_iterator frame = timeslice->begin(); frame != timeslice->end(); ++frame) {
223 buildL1(*frame, router.
getModule(frame->getModuleID()), back_inserter(data));
225 TH1D*
h1 = manager[frame->getModuleID()];
229 const double t1 = *hit + frame->getFrameIndex() *
getFrameTime();
231 for (map_type::const_iterator i = p; i != q; ++i) {
232 for (map_type::mapped_type::const_iterator
j = i->second.begin();
j != i->second.end(); ++
j) {
234 const double t0 = *
j;
247 TF1 f1(
"f1",
"[0]*exp(-0.5*(x-[1])*(x-[1])/([2]*[2])) + [3]");
258 for (JDetector::const_iterator module =
detector.begin(); module !=
detector.end(); ++module) {
260 status[module->getID()] = DEFAULT;
262 JManager_t::iterator p = manager.find(module->getID());
264 if (p == manager.end() || p->second->GetEntries() == 0) {
266 status[module->getID()] = NODATA;
271 TH1D*
h1 = p->second;
277 Double_t sigma = 250.0;
280 for (
int i = 1; i != h1->GetNbinsX(); ++i) {
282 const Double_t x = h1->GetBinCenter (i);
283 const Double_t y = h1->GetBinContent(i);
293 ymin /= h1->GetNbinsX();
295 f1.SetParameter(0, ymax);
296 f1.SetParameter(1, x0);
297 if (binWidth_ns < sigma)
298 f1.SetParameter(2, sigma);
300 f1.FixParameter(2, binWidth_ns/sqrt(12.0));
301 f1.SetParameter(3, ymin);
305 h1->Fit(&f1, option.c_str(),
"same", x0 - 5 * sigma, x0 + 5 * sigma);
309 f1.GetParameter(0) >= f1.GetParameter(3)) {
311 status[module->getID()] = IN_SYNC;
320 for (Int_t i = 1, ns = -(numberOfTimeslices + 1); i <= h1->GetNbinsX(); ++i) {
322 const Double_t x = h1->GetBinCenter (i);
323 const Double_t y = h1->GetBinContent(i);
325 while (x > (ns + 1) *
getFrameTime() - TMax_ns) { ++ns; }
329 else if (fabs(x - ns *
getFrameTime()) < 10.0 * TMax_ns)
333 DEBUG(
"Module " << setw(8) << module->getID() << endl);
337 const Double_t y = bg[i->first].getTotal() * i->second.getCount() / bg[i->first].getCount();
338 const Double_t
P = TMath::PoissonI(i->second.getTotal(), y);
340 DEBUG(
"Peak at " << setw(4) << i->first <<
" [frame time] "
342 <<
FIXED(7,1) << i->second.getTotal() <<
" / "
343 <<
FIXED(7,1) << y <<
' '
346 if (i->second.getTotal() > y && P < Pmin)
352 if (!(sn.size() == 1 &&
353 sn.begin()->first == 0)) {
355 ERROR(
"Module " << setw(8) << module->getID() <<
" number of peaks " << sn.size() << endl);
358 ERROR(
"Peak at " << setw(4) << i->first <<
" [frame time] "
360 <<
FIXED(7,1) << i->second.getTotal() <<
" / "
361 <<
FIXED(7,1) << bg[i->first].getTotal() * i->second.getCount() / bg[i->first].getCount() << endl);
364 status[module->getID()] = (sn.size() == 1 ? OUT_OF_SYNC :
ERROR);
374 parameters.
load(pmtFile.c_str());
380 if (i->second != IN_SYNC) {
382 NOTICE(
"Module " << setw(8) << i->first <<
" set QEs of all PMTs to zero." << endl);
390 ofstream out(pmtFile.c_str());
394 out << parameters << endl;
407 if (i->second == IN_SYNC) {
410 if (i->second != IN_SYNC &&
411 i->second != NODATA) {
416 NOTICE(
"Number of modules out/in sync " << nout <<
'/' << nin << endl);
418 QAQC(nin <<
' ' << nout << endl);
Utility class to parse command line options.
Direct access to PMT data in detector data structure for DAQ hits.
ROOT TTree parameter settings.
Auxiliary class to select ROOT class based on class name.
esac print_variable DETECTOR INPUT_FILE OUTPUT_FILE CDF for TYPE in
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
then for HISTOGRAM in h0 h1
Auxialiary class to assert type conversion.
const JModule & getModule(const JDAQKeyHit &hit) const
Get module parameters.
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.
Template definition for direct access of elements in ROOT TChain.
Data structure for detector geometry and calibration.
Simple wrapper around JModuleRouter class for direct addressing of PMT data in detector data structur...
int getFrameIndex() const
Get frame index.
esac $JPP_DIR examples JDetector JTransitTime o $OUTPUT_FILE n N $NPE T $TTS_NS d $DEBUG for HISTOGRAM in tts tt2 pmt
The template JSinglePointer class can be used to hold a pointer to an object.
Auxiliary class to manage set of compatible ROOT objects (e.g.
Scanning of objects from a single file according a format that follows from the extension of each fil...
Auxiliary class for defining the range of iterations of objects.
I/O formatting auxiliaries.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
double getFrameTime()
Get frame time duration.
Auxiliary class for map of PMT parameters.
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
double getMaximalTime(const double R_Hz)
Get maximal time for given rate.
General purpose messaging.
Auxiliary class to select JTreeScanner based on ROOT class name.
void load(const char *file_name)
Load from input file.
Utility class to parse command line options.
#define QAQC(A)
QA/QC output macro.
Auxiliary data structure for L1 build parameters.
const JLimit & getLimit() const
Get limit.
KM3NeT DAQ constants, bit handling, etc.
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
const JPMT & getPMT(const JDAQKeyHit &hit) const
Get PMT parameters.
Auxiliary data structure for floating point format specification.
int qaqc
QA/QC file descriptor.
#define DEBUG(A)
Message macros.
int main(int argc, char *argv[])