Jpp - the software that should make you happy
 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 "TH1D.h"
#include "JDetector/JPMTParametersMap.hh"
#include "JDetector/JPMTAnalogueSignalProcessor.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 charge distributions.

Author
mdejong & bjjung

Definition in file JCharge.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 24 of file JCharge.cc.

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