Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JCharge.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 "TF1.h"
9 #include "TH1D.h"
10 
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 
23 /**
24  * \file
25  *
26  * Example program to histogram charge distributions.
27  * \author mdejong & bjjung
28  */
29 int main(int argc, char **argv)
30 {
31  using namespace std;
32  using namespace JPP;
33 
34  string outputFile;
35  JPMTParametersMap parametersMap;
36  JPMTIdentifier pmt;
37  int NPE;
38  int numberOfHits;
39  double precision;
40  int debug;
41 
42  try {
43 
44  JParser<> zap("Example program to histogram time over threshold distributions.");
45 
46  zap['o'] = make_field(outputFile) = "charge.root";
47  zap['P'] = make_field(parametersMap) = JPARSER::initialised();
48  zap['p'] = make_field(pmt) = JPMTIdentifier(1,0);
49  zap['N'] = make_field(NPE) = 1;
50  zap['n'] = make_field(numberOfHits) = 1000000;
51  zap['e'] = make_field(precision) = 0.01;
52  zap['d'] = make_field(debug) = 0;
53 
54  zap(argc, argv);
55 
56  }
57  catch(const exception &error) {
58  FATAL(error.what() << endl);
59  }
60 
61  const JPMTParameters parameters = parametersMap.getPMTParameters(pmt);
62 
63  const JPMTAnalogueSignalProcessor cpu (parameters);
64 
65  ASSERT(numberOfHits > 0);
66 
67 
68  TFile out(outputFile.c_str(), "recreate");
69 
70  const double dQ = (cpu.threshold - cpu.thresholdBand) / 5.5;
71  const double Qmin = 0.0 - 0.5 * dQ;
72  const double Qmax = 10.0 + 0.5 * dQ;
73  const int nq = (int) ((Qmax - Qmin) / dQ);
74 
75  TH1D h0("h0", NULL, nq, Qmin, Qmax);
76  TH1D h1("h1", NULL, nq, Qmin, Qmax);
77 
78  h1.Sumw2();
79 
80  for (int i=1; i <= h0.GetNbinsX(); ++i) {
81 
82  const double npe = h0.GetBinCenter(i);
83  const double p = cpu.getChargeProbability(npe,NPE);
84 
85  h0.SetBinContent(i,p);
86  }
87 
88 
89  if (numberOfHits > 0) {
90 
91  int number_of_hits = 0;
92 
93  for (int i=0; i != numberOfHits; ++i) {
94 
95  const double npe = cpu.getRandomCharge(NPE);
96 
97  try {
98 
99  if (cpu.applyThreshold(npe) > cpu.BELOW_THRESHOLDBAND) {
100 
101  ++number_of_hits;
102 
103  h1.Fill(npe);
104  }
105 
106  } catch (const JValueOutOfRange& exception) {
107 
108  DEBUG(exception.what());
109  continue;
110  }
111 
112  }
113 
114  h1.Scale(1.0 / (double) number_of_hits / dQ);
115  }
116 
117  out.Write();
118  out.Close();
119 
120 
121  for (int i = 1; i <= h0.GetNbinsX(); ++i) {
122 
123  const Double_t x = h0.GetBinCenter (i);
124  const Double_t y0 = h0.GetBinContent(i);
125  const Double_t y1 = h1.GetBinContent(i);
126 
127  DEBUG("[" << setw(3) << i << "]" << ' '
128  << FIXED(5,3) << x << ' '
129  << FIXED(6,4) << y0 << ' '
130  << FIXED(6,4) << y1 << endl);
131 
132  ASSERT(fabs(y0 - y1) < precision);
133  }
134 }
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