Jpp  17.2.1-pre0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JSquid.cc File Reference

Example program to histogram string and floor time difference. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include "TROOT.h"
#include "TFile.h"
#include "TH1D.h"
#include "JTools/JQuantile.hh"
#include "JTools/JRange.hh"
#include "JROOT/JManager.hh"
#include "JROOT/JRootToolkit.hh"
#include "JDAQ/JDAQEventIO.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JDAQHitRouter.hh"
#include "JPhysics/JConstants.hh"
#include "JSupport/JMultipleFileScanner.hh"
#include "JSupport/JSupport.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Example program to histogram string and floor time difference.

Author
mdejong

Definition in file JSquid.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 36 of file JSquid.cc.

37 {
38  using namespace std;
39  using namespace JPP;
40  using namespace KM3NETDAQ;
41 
42  typedef JRange<double> JRange_t;
43 
45  JLimit_t& numberOfEvents = inputFile.getLimit();
46  string outputFile;
47  string detectorFile;
48  JRange_t T_ns;
49  double Wmin;
50  double Qmin;
51  int qaqc;
52  int debug;
53 
54  try {
55 
56  JParser<> zap("Example program to histogram string and floor time difference.");
57 
58  zap['f'] = make_field(inputFile);
59  zap['o'] = make_field(outputFile) = "squid.root";
60  zap['a'] = make_field(detectorFile);
61  zap['n'] = make_field(numberOfEvents) = JLimit::max();
62  zap['T'] = make_field(T_ns, "Time window for coincidences [ns]") = JRange_t(-50.0, +200.0);
63  zap['W'] = make_field(Wmin, "Minimal number of entries") = 10.0;
64  zap['q'] = make_field(Qmin, "Minimal fraction of coincidences") = 0.5;
65  zap['Q'] = make_field(qaqc) = 0;
66  zap['d'] = make_field(debug) = 2;
67 
68  zap(argc, argv);
69  }
70  catch(const exception& error) {
71  FATAL(error.what() << endl);
72  }
73 
74  cout.tie(&cerr);
75 
77 
78  try {
79  load(detectorFile, detector);
80  }
81  catch(const JException& error) {
82  FATAL(error);
83  }
84 
85  const JDAQHitRouter router(detector);
86 
87  JManager<JLocation, TH1D> H1(new TH1D("%", NULL, 200, -1.0e3, +1.0e3));
88 
89  while (inputFile.hasNext()) {
90 
91  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
92 
93  JDAQEvent* event = inputFile.next();
94 
96 
97  for (JDAQEvent::const_iterator<JDAQTriggeredHit> hit = event->begin<JDAQTriggeredHit>(); hit != event->end<JDAQTriggeredHit>(); ++hit) {
98  buffer[router.getModule(*hit)].put(getTime(*hit, router.getPMT(*hit)) + router.getModule(*hit).getZ() * getInverseSpeedOfLight());
99  }
100 
101  if (buffer.size() >= 2u) {
102  for (map<JLocation, JQuantile>::const_iterator q = buffer.begin(), p = q++; q != buffer.end(); ++p, ++q) {
103  if (p->first.getString() == q->first.getString() && p->first.getFloor() + 1 == q->first.getFloor()) {
104  H1[p->first]->Fill(q->second.getMean() - p->second.getMean());
105  }
106  }
107  }
108  }
109  STATUS(endl);
110 
111 
112  TFile out(outputFile.c_str(), "recreate");
113 
114  out << H1;
115 
116  out.Write();
117  out.Close();
118 
119 
120  int nin = 0;
121  int nout = 0;
122 
123  for (const auto& i : H1) {
124 
125  Double_t W = 0.0;
126 
127  TH1D* h1 = i.second;
128 
129  if (h1->GetSumOfWeights() > Wmin) {
130 
131  for (Int_t ix = 1; ix <= h1->GetXaxis()->GetNbins(); ++ix) {
132 
133  const Double_t x = h1->GetBinCenter (ix);
134  const Double_t y = h1->GetBinContent(ix);
135 
136  if (T_ns(x)) {
137  W += y;
138  }
139  }
140 
141  DEBUG(i.first << ' ' << FIXED(6,0) << W << '/' << FIXED(6,0) << h1->GetSumOfWeights() << endl);
142 
143  if (W / h1->GetSumOfWeights() >= Qmin)
144  nin += 1;
145  else
146  nout += 1;
147  }
148  }
149 
150  NOTICE("Number of modules out/in micro-sync " << nout << '/' << nin << endl);
151 
152  QAQC(nin << ' ' << nout << endl);
153 
154  return 0;
155 }
Utility class to parse command line options.
Definition: JParser.hh:1517
General exception.
Definition: JException.hh:23
#define STATUS(A)
Definition: JMessage.hh:63
Detector data structure.
Definition: JDetector.hh:89
Template const_iterator.
Definition: JDAQEvent.hh:68
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
double getTime(const Hit &hit)
Get true time of hit.
string outputFile
Simple wrapper around JModuleRouter class for direct addressing of PMT data in detector data structur...
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
Type definition of range.
Definition: JHead.hh:41
Auxiliary class to manage set of compatible ROOT objects (e.g. histograms) using unique keys...
Definition: JManager.hh:43
Detector file.
Definition: JHead.hh:226
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1993
#define NOTICE(A)
Definition: JMessage.hh:64
#define FATAL(A)
Definition: JMessage.hh:67
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
General purpose class for object reading from a list of file names.
#define QAQC(A)
QA/QC output macro.
Definition: JMessage.hh:100
const double getInverseSpeedOfLight()
Get inverse speed of light.
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
do set_variable DETECTOR_TXT $WORKDIR detector
double u[N+1]
Definition: JPolint.hh:776
int qaqc
QA/QC file descriptor.
int debug
debug level
JTriggerCounter_t next()
Increment trigger counter.
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62