Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JToT.cc
Go to the documentation of this file.
1 
2 #include <string>
3 #include <iostream>
4 #include <iomanip>
5 
6 #include "TROOT.h"
7 #include "TFile.h"
8 #include "TH1D.h"
9 
13 
14 #include "Jeep/JPrint.hh"
15 #include "Jeep/JParser.hh"
16 #include "Jeep/JMessage.hh"
17 
18 #include "JSupport/JMeta.hh"
19 
20 
21 /**
22  * \file
23  *
24  * Example program to histogram time over threshold distributions.
25  * \author mdejong
26  */
27 int main(int argc, char **argv)
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 
60  const JCalibration calibration;
61  const JStatus status;
62  const JPMTDefaultSimulator simulator(parameters, pmt);
63  const JPMTAnalogueSignalProcessor cpu (parameters);
64 
65  JPMTData<JPMTSignal> input;
66  JPMTData<JPMTPulse> output;
67 
68  ASSERT(numberOfHits > 0);
69 
70 
71  TFile out(outputFile.c_str(), "recreate");
72 
73  const double dx = 1.0;
74  const double xmin = 0.0 - 0.5 * dx;
75  const double xmax = 255.0 + 0.5 * dx;
76  const int nx = (int) ((xmax - xmin) / dx);
77 
78  TH1D h0("h0", NULL, nx, xmin, xmax);
79  TH1D h1("h1", NULL, nx, xmin, xmax);
80  TH1D h2("h2", NULL, nx, xmin, xmax);
81  TH1D h3("h3", NULL, 500, 0.0, 100.0);
82 
83  h1.Sumw2();
84  h2.Sumw2();
85 
86  DEBUG(" ToT Probability " << endl);
87 
88  for (int i = 1; i <= h0.GetNbinsX(); ++i) {
89 
90  const double x = h0.GetBinCenter(i);
91  const double y = cpu.getTimeOverThresholdProbability(x,NPE);
92 
93  DEBUG(" "
94  << FIXED(5,1) << x << " "
95  << FIXED(6,4) << y << endl);
96 
97  h0.SetBinContent(i, y);
98  }
99 
100 
101  if (numberOfHits > 0) {
102 
103  int number_of_hits = 0;
104 
105  for (int i = 0; i != numberOfHits; ++i) {
106 
107  const double npe = cpu.getRandomCharge(NPE);
108 
109  double tot_ns;
110  try {
111 
112  tot_ns = cpu.getTimeOverThreshold(npe);
113 
114  } catch (const JValueOutOfRange& exception) {
115 
116  DEBUG(exception.what());
117  continue;
118  }
119 
120  if (tot_ns > 0.0) {
121 
122  ++number_of_hits;
123 
124  h1.Fill(tot_ns);
125 
126  }
127  }
128 
129  h1.Scale(1.0 / (double) number_of_hits / dx);
130  }
131 
132 
133  if (numberOfHits > 0) {
134 
135  int number_of_hits = 0;
136 
137  const double t_ns = 25.0;
138 
139  for (int i = 0; i != numberOfHits; ++i) {
140 
141  input .clear();
142  output.clear();
143 
144  input.push_back(JPMTSignal(t_ns, NPE));
145 
146  simulator.processHits(pmt, calibration, status, input, output);
147 
148  for (JPMTData<JPMTPulse>::const_iterator hit = output.begin(); hit != output.end(); ++hit) {
149 
150  ++number_of_hits;
151 
152  h2.Fill(hit->tot_ns);
153  h3.Fill(hit->t_ns);
154  }
155  }
156 
157  h2.Scale(1.0 / (double) number_of_hits / dx);
158  }
159 
160  out.Write();
161  out.Close();
162 
163  for (int i = 1; i <= h0.GetNbinsX(); ++i) {
164 
165  const Double_t x = h0.GetBinCenter (i);
166  const Double_t y0 = h0.GetBinContent(i);
167  const Double_t y1 = h1.GetBinContent(i);
168  const Double_t y2 = h2.GetBinContent(i);
169 
170  DEBUG("[" << setw(3) << i << "]" << ' '
171  << FIXED(5,1) << x << ' '
172  << FIXED(6,4) << y0 << ' '
173  << FIXED(6,4) << y1 << ' '
174  << FIXED(6,4) << y2 << endl);
175 
176  ASSERT(fabs(y0 - y1) < precision);
177  ASSERT(fabs(y0 - y2) < precision);
178  }
179 }
Utility class to parse command line options.
Definition: JParser.hh:1493
*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
Definition: diff-Tuna.sh:38
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:69
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:63
Auxiliary data structure for floating point format specification.
Definition: JPrint.hh:481
string outputFile
esac $JPP_DIR examples JDetector JTransitTime o $OUTPUT_FILE n N $NPE T $TTS_NS d $DEBUG for HISTOGRAM in tts tt2 pmt
Definition: JTransitTime.sh:36
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
I/O formatting auxiliaries.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
ROOT I/O of application specific meta data.
int debug
debug level
Definition: JSirene.cc:61
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Utility class to parse command line options.
PMT analogue signal processor.
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
int main(int argc, char *argv[])
Definition: Main.cpp:15