Jpp  17.2.1-pre0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JSquid.cc
Go to the documentation of this file.
1 
2 #include <string>
3 #include <iostream>
4 #include <iomanip>
5 #include <map>
6 
7 #include "TROOT.h"
8 #include "TFile.h"
9 #include "TH1D.h"
10 
11 #include "JTools/JQuantile.hh"
12 #include "JTools/JRange.hh"
13 
14 #include "JROOT/JManager.hh"
15 #include "JROOT/JRootToolkit.hh"
16 
17 #include "JDAQ/JDAQEventIO.hh"
18 #include "JDetector/JDetector.hh"
21 #include "JPhysics/JConstants.hh"
22 
24 #include "JSupport/JSupport.hh"
25 
26 #include "Jeep/JParser.hh"
27 #include "Jeep/JMessage.hh"
28 
29 
30 /**
31  * \file
32  *
33  * Example program to histogram string and floor time difference.
34  * \author mdejong
35  */
36 int main(int argc, char **argv)
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
Direct access to PMT data in detector data structure for DAQ hits.
int main(int argc, char *argv[])
Definition: Main.cc:15
ROOT TTree parameter settings of various packages.
#define STATUS(A)
Definition: JMessage.hh:63
Detector data structure.
Definition: JDetector.hh:89
Template const_iterator.
Definition: JDAQEvent.hh:68
const JModule & getModule(const JDAQKeyHit &hit) const
Get module parameters.
Dynamic ROOT object management.
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
double getTime(const Hit &hit)
Get true time of hit.
string outputFile
Data structure for detector geometry and calibration.
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
void Write(TDirectory &out, const bool wm=false)
Write objects to file.
Definition: JManager.hh:295
Physics constants.
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Scanning of objects from multiple files according a format that follows from the extension of each fi...
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
Auxiliary class to define a range between two values.
General purpose class for object reading from a list of file names.
Utility class to parse command line options.
#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
const JPMT & getPMT(const JDAQKeyHit &hit) const
Get PMT parameters.
int qaqc
QA/QC file descriptor.
double getZ() const
Get z position.
Definition: JVector3D.hh:115
int debug
debug level
JTriggerCounter_t next()
Increment trigger counter.
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62