Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JCharge.cc File Reference

Example program to histogram charge distributions. More...

#include <string>
#include <iostream>
#include <iomanip>
#include "TROOT.h"
#include "TFile.h"
#include "TF1.h"
#include "TH1D.h"
#include "JDetector/JPMTParametersMap.hh"
#include "JDetector/JPMTAnalogueSignalProcessor.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 charge distributions.

Author
mdejong & bjjung

Definition in file JCharge.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 29 of file JCharge.cc.

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:1500
*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:66
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:445
string outputFile
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
int debug
debug level
Definition: JSirene.cc:63
#define FATAL(A)
Definition: JMessage.hh:67
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62