Jpp  17.3.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JPMTSimulator.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 "TProfile.h"
9 #include "TProfile2D.h"
10 
14 
15 #include "Jeep/JParser.hh"
16 #include "Jeep/JMessage.hh"
17 
18 
19 /**
20  * \file
21  *
22  * Example program to histogram PMT simulator features.
23  * \author mdejong
24  */
25 int main(int argc, char **argv)
26 {
27  using namespace std;
28  using namespace JPP;
29 
30  string outputFile;
31  int numberOfHits;
32  JPMTParameters parameters;
33  int debug;
34 
35  try {
36 
37  JProperties properties = parameters.getProperties();
38 
39  JParser<> zap("Example program to histogram PMT simulator features.");
40 
41  zap['o'] = make_field(outputFile) = "pmt.root";
42  zap['n'] = make_field(numberOfHits) = 100;
43  zap['P'] = make_field(properties) = JPARSER::initialised();
44  zap['d'] = make_field(debug) = 0;
45 
46  zap(argc, argv);
47  }
48  catch(const exception &error) {
49  FATAL(error.what() << endl);
50  }
51 
52 
53  if (debug >= JEEP::debug_t) {
54  cout << "PMT parameters:" << endl;
55  cout << parameters.getProperties(JEquationParameters("=", "\n", "", "")) << endl;
56  }
57 
58  const JPMTAnalogueSignalProcessor cpu(parameters);
59 
60  const JPMTIdentifier pmt(1,0);
61  const JCalibration calibration;
62  const JStatus status;
63 
64  const JPMTDefaultSimulator simulator(parameters, pmt);
65 
66  JPMTData<JPMTSignal> input;
67  JPMTData<JPMTPulse> output;
68 
69 
70  TFile out(outputFile.c_str(), "recreate");
71 
72  TProfile h0("tot", NULL, 1000, parameters.threshold, 1000.0);
73  TProfile h1("hit", NULL, 1000, parameters.threshold, 1000.0);
74  TProfile2D h2("2D", NULL, 50, 0.0, 250.0, 100, 0.0, 1000.0);
75 
76 
77  for (int i = 1; i <= h1.GetNbinsX(); ++i) {
78 
79  const double t_ns = 100.0;
80  const double x = h1.GetBinCenter(i);
81  const int npe = (int) x;
82 
83  for (int i = 0; i != numberOfHits; ++i) {
84 
85  input .clear();
86  output.clear();
87 
88  input.push_back(JPMTSignal(t_ns, npe));
89 
90  simulator.processHits(pmt, calibration, status, input, output);
91 
92  double tot = 0.0;
93 
94  for (JPMTData<JPMTPulse>::const_iterator hit = output.begin(); hit != output.end(); ++hit) {
95  tot += hit->tot_ns;
96  }
97 
98  h0.Fill(x, tot);
99  h1.Fill(x, (double) output.size());
100  }
101  }
102 
103 
104  for (int i = 1; i <= h2.GetXaxis()->GetNbins(); ++i) {
105  for (int j = 1; j <= h2.GetYaxis()->GetNbins(); ++j) {
106 
107  const double t_ns = (int) h2.GetXaxis()->GetBinCenter(i);
108  const int npe = (int) h2.GetYaxis()->GetBinCenter(j);
109 
110  for (int i = 0; i != numberOfHits; ++i) {
111 
112  input .clear();
113  output.clear();
114 
115  input.push_back(JPMTSignal(0.0, npe));
116  input.push_back(JPMTSignal(t_ns, 1));
117 
118  simulator.processHits(pmt, calibration, status, input, output);
119 
120  if (!output.empty()) {
121  h2.Fill(t_ns, (double) npe, output.begin()->tot_ns);
122  }
123  }
124  }
125  }
126 
127  out.Write();
128  out.Close();
129 }
Utility class to parse command line options.
Definition: JParser.hh:1517
debug
Definition: JMessage.hh:29
int main(int argc, char *argv[])
Definition: Main.cc:15
Utility class to parse parameter values.
Definition: JProperties.hh:496
*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
Simple data structure to support I/O of equations (see class JLANG::JEquation).
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:83
string outputFile
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1993
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Utility class to parse command line options.
PMT analogue signal processor.
int j
Definition: JPolint.hh:703
int debug
debug level