Jpp
Functions
JToT.cc File Reference
#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"

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 25 of file JToT.cc.

26 {
27  using namespace std;
28  using namespace JPP;
29 
30  string outputFile;
31  JPMTParameters parameters;
32  int NPE;
33  int numberOfHits;
34  double precision;
35  int debug;
36 
37  try {
38 
39  JProperties properties = parameters.getProperties();
40 
41  JParser<> zap("Example program to histogram time over threshold distributions.");
42 
43  zap['o'] = make_field(outputFile) = "tot.root";
44  zap['P'] = make_field(properties) = JPARSER::initialised();
45  zap['N'] = make_field(NPE) = 1;
46  zap['n'] = make_field(numberOfHits) = 1000000;
47  zap['e'] = make_field(precision) = 0.005;
48  zap['d'] = make_field(debug) = 0;
49 
50  zap(argc, argv);
51  }
52  catch(const exception &error) {
53  FATAL(error.what() << endl);
54  }
55 
56 
57  if (debug >= JEEP::debug_t) {
58  cout << "PMT parameters:" << endl;
59  cout << parameters.getProperties(JEquationParameters("=", "\n", "", "")) << endl;
60  }
61 
62  const JPMTAnalogueSignalProcessor cpu(parameters);
63 
64  const JPMTIdentifier pmt(1,0);
65  const JCalibration calibration;
66 
67  const JPMTDefaultSimulator simulator(parameters, pmt);
68 
69  JPMTData<JPMTSignal> input;
70  JPMTData<JPMTPulse> output;
71 
72  ASSERT(numberOfHits > 0);
73 
74 
75  TFile out(outputFile.c_str(), "recreate");
76 
77  const double xmin = -0.5;
78  const double xmax = 255.5;
79  const double dx = 1.0;
80  const int nx = (int) ((xmax - xmin) / dx);
81 
82  TH1D h0("h0", NULL, nx, xmin, xmax);
83  TH1D h1("h1", NULL, nx, xmin, xmax);
84  TH1D h2("h2", NULL, nx, xmin, xmax);
85  TH1D h3("h3", NULL, 500, 0.0, 100.0);
86 
87  h1.Sumw2();
88  h2.Sumw2();
89 
90  DEBUG(" ToT npe dP/dnpe dP/dToT" << endl);
91 
92  for (int i = 1; i <= h0.GetNbinsX(); ++i) {
93 
94  const double x = h0.GetBinCenter(i);
95  const double npe = cpu.getNPE(x);
96  const double y = cpu.getProbability(npe, NPE);
97  const double v = cpu.getDerivative(npe);
98 
99  DEBUG(" "
100  << FIXED(5,1) << x << " "
101  << FIXED(7,3) << npe << " "
102  << FIXED(5,3) << y << " "
103  << FIXED(6,4) << y*v << endl);
104 
105  h0.SetBinContent(i, y*v);
106  }
107 
108 
109  if (numberOfHits > 0) {
110 
111  int number_of_hits = 0;
112 
113  for (int i = 0; i != numberOfHits; ++i) {
114 
115  const double npe = cpu.getRandomAmplitude(NPE);
116 
117  if (cpu.applyThreshold(npe)) {
118 
119  const double tot_ns = cpu.getTimeOverThreshold(npe);
120 
121  ++number_of_hits;
122 
123  h1.Fill(tot_ns);
124  }
125  }
126 
127  h1.Scale(1.0 / (double) number_of_hits / dx);
128  }
129 
130 
131  if (numberOfHits > 0) {
132 
133  int number_of_hits = 0;
134 
135  const double t_ns = 25.0;
136 
137  for (int i = 0; i != numberOfHits; ++i) {
138 
139  input .clear();
140  output.clear();
141 
142  input.push_back(JPMTSignal(t_ns, NPE));
143 
144  simulator.processHits(pmt, calibration, input, output);
145 
146  for (JPMTData<JPMTPulse>::const_iterator hit = output.begin(); hit != output.end(); ++hit) {
147 
148  ++number_of_hits;
149 
150  h2.Fill(hit->tot_ns);
151  h3.Fill(hit->t_ns);
152  }
153  }
154 
155  h2.Scale(1.0 / (double) number_of_hits / dx);
156  }
157 
158  out.Write();
159  out.Close();
160 
161  for (int i = 1; i <= h0.GetNbinsX(); ++i) {
162 
163  const Double_t x = h0.GetBinCenter (i);
164  const Double_t y0 = h0.GetBinContent(i);
165  const Double_t y1 = h1.GetBinContent(i);
166  const Double_t y2 = h2.GetBinContent(i);
167 
168  DEBUG("[" << setw(3) << i << "]" << ' '
169  << FIXED(5,1) << x << ' '
170  << FIXED(6,4) << y0 << ' '
171  << FIXED(6,4) << y1 << ' '
172  << FIXED(6,4) << y2 << endl);
173 
174  ASSERT(fabs(y0 - y1) < precision);
175  ASSERT(fabs(y0 - y2) < precision);
176  }
177 }
FIXED
Auxiliary data structure for floating point format specification.
Definition: JPrint.hh:481
ASSERT
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
JPARSER::initialised
Empty structure for specification of parser element that is initialised (i.e.
Definition: JParser.hh:63
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
debug
int debug
debug level
Definition: JSirene.cc:59
JTOOLS::v
data_type v[N+1][M+1]
Definition: JPolint.hh:707
JLANG::JEquationParameters
Simple data structure to support I/O of equations (see class JLANG::JEquation).
Definition: JEquationParameters.hh:20
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
JEEP::JProperties
Utility class to parse parameter values.
Definition: JProperties.hh:496
DEBUG
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
std
Definition: jaanetDictionary.h:36
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
outputFile
string outputFile
Definition: JDAQTimesliceSelector.cc:37
JEEP::debug_t
debug
Definition: JMessage.hh:29