Jpp  19.1.0-rc.1
the software that should make you happy
Functions
JToT.cc File Reference

Example program to histogram time over threshold distributions. More...

#include <string>
#include <iostream>
#include <iomanip>
#include "TROOT.h"
#include "TFile.h"
#include "TH1D.h"
#include "JDetector/JPMTParameters.hh"
#include "JDetector/JPMTAnalogueSignalProcessor.hh"
#include "JDetector/JPMTDefaultSimulator.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"
#include "JSupport/JMeta.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Example program to histogram time over threshold distributions.

Author
mdejong

Definition in file JToT.cc.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 27 of file JToT.cc.

28 {
29  using namespace std;
30  using namespace JPP;
31 
32  string outputFile;
33  JPMTParametersMap parametersMap;
34  JPMTIdentifier pmt;
35  int NPE;
36  int numberOfHits;
37  double precision;
38  int debug;
39 
40  try {
41 
42  JParser<> zap("Example program to histogram time over threshold distributions.");
43 
44  zap['o'] = make_field(outputFile) = "tot.root";
45  zap['P'] = make_field(parametersMap) = JPARSER::initialised();
46  zap['p'] = make_field(pmt) = JPMTIdentifier(1,0);
47  zap['N'] = make_field(NPE) = 1;
48  zap['n'] = make_field(numberOfHits) = 1000000;
49  zap['e'] = make_field(precision) = 0.005;
50  zap['d'] = make_field(debug) = 0;
51 
52  zap(argc, argv);
53  }
54  catch(const exception &error) {
55  FATAL(error.what() << endl);
56  }
57 
58  const JPMTParameters parameters = parametersMap.getPMTParameters(pmt);
59 
61  const JStatus status;
62  const JPMTDefaultSimulator simulator(parameters, pmt);
63  const JPMTAnalogueSignalProcessor cpu (parameters);
64 
66  JPMTData<JPMTPulse> output;
67 
68 
69  TFile out(outputFile.c_str(), "recreate");
70 
71  const double dx = 1.0;
72  const double xmin = 0.0 - 0.5 * dx;
73  const double xmax = round(parameters.saturation) - 0.5*dx;
74  const int nx = (int) ((xmax - xmin) / dx);
75 
76  TH1D h0("h0", NULL, nx, xmin, xmax);
77  TH1D h1("h1", NULL, nx, xmin, xmax);
78  TH1D h2("h2", NULL, nx, xmin, xmax);
79  TH1D h3("h3", NULL, 500, 0.0, 100.0);
80 
81  h1.Sumw2();
82  h2.Sumw2();
83 
84  DEBUG(" ToT Probability " << endl);
85 
86  for (int i = 1; i <= h0.GetNbinsX(); ++i) {
87 
88  const double x = h0.GetBinCenter(i);
89  const double y = cpu.getTimeOverThresholdProbability(x,NPE);
90 
91  DEBUG(" "
92  << FIXED(7,3) << x << " "
93  << FIXED(7,5) << y << endl);
94 
95  h0.SetBinContent(i, y);
96  }
97 
98 
99  if (numberOfHits > 0) {
100 
101  int number_of_hits = 0;
102 
103  for (int i = 0; i != numberOfHits; ++i) {
104 
105  const double npe = cpu.getRandomCharge(NPE);
106 
107  double tot_ns;
108 
109  try {
110  tot_ns = cpu.getTimeOverThreshold(npe);
111  } catch (const JValueOutOfRange& exception) {
112  continue;
113  }
114 
115  if (tot_ns > 0.0) {
116 
117  ++number_of_hits;
118 
119  h1.Fill(tot_ns);
120 
121  }
122  }
123 
124  h1.Scale(1.0 / (double) number_of_hits / dx);
125  }
126 
127 
128  if (numberOfHits > 0) {
129 
130  int number_of_hits = 0;
131 
132  const double t_ns = 25.0;
133 
134  for (int i = 0; i != numberOfHits; ++i) {
135 
136  input .clear();
137  output.clear();
138 
139  input.push_back(JPMTSignal(t_ns, NPE));
140 
141  simulator.processHits(pmt, calibration, status, input, output);
142 
143  for (JPMTData<JPMTPulse>::const_iterator hit = output.begin(); hit != output.end(); ++hit) {
144 
145  ++number_of_hits;
146 
147  h2.Fill(hit->tot_ns);
148  h3.Fill(hit->t_ns);
149  }
150  }
151 
152  h2.Scale(1.0 / (double) number_of_hits / dx);
153  }
154 
155  out.Write();
156  out.Close();
157 
158  ASSERT(numberOfHits > 0);
159 
160  for (int i = 1; i <= h0.GetNbinsX(); ++i) {
161 
162  const Double_t x = h0.GetBinCenter (i);
163  const Double_t y0 = h0.GetBinContent(i);
164  const Double_t y1 = h1.GetBinContent(i);
165  const Double_t y2 = h2.GetBinContent(i);
166 
167  DEBUG("[" << setw(3) << i << "]" << ' '
168  << FIXED(5,1) << x << ' '
169  << FIXED(6,4) << y0 << ' '
170  << FIXED(6,4) << y1 << ' '
171  << FIXED(6,4) << y2 << endl);
172 
173  ASSERT(fabs(y0 - y1) < precision);
174  ASSERT(fabs(y0 - y2) < precision);
175  }
176 }
string outputFile
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level
Definition: JSirene.cc:69
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2158
Data structure for time calibration.
Template data structure for PMT I/O.
std::vector< JElement_t >::const_iterator const_iterator
Auxiliary class for map of PMT parameters.
const JPMTParameters & getPMTParameters(const JPMTIdentifier &id) const
Get PMT parameters.
Data structure for PMT parameters.
double saturation
saturation [ns]
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:180
Utility class to parse command line options.
Definition: JParser.hh:1714
const double xmax
Definition: JQuadrature.cc:24
const double xmin
Definition: JQuadrature.cc:23
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JSTDTypes.hh:14
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:448
Calibration.
Definition: JHead.hh:330
Data structure for PMT analogue signal.
Auxiliary class for handling status.
Definition: JStatus.hh:39
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:84