Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JCharge.cc File Reference

Example program to histogram charge distributions. More...

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

◆ main()

int main ( int argc,
char ** argv )

Definition at line 27 of file JCharge.cc.

28{
29 using namespace std;
30 using namespace JPP;
31
32 string outputFile;
33 JPMTParametersMap parametersMap;
35 int NPE;
36 int numberOfHits;
37 double precision;
38 int debug;
39
40 try {
41
42 JParser<> zap("Example program to histogram charge distributions.");
43
44 zap['o'] = make_field(outputFile) = "charge.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.01;
50 zap['d'] = make_field(debug) = 0;
51
52 zap(argc, argv);
53
54 }
55 catch(const exception &error) {
56 FATAL(error.what() << endl);
57 }
58
59 const JPMTParameters parameters = parametersMap.getPMTParameters(pmt);
60
63
64 {
65 const double dx = JPMTSignalProcessorInterface::getQmin();
66 const double xmin = 0.0 - 0.5*dx;
67 const int nx = (int) ((10.0 - xmin) / dx);
68
69 H0[1] = new TH1D("1.0", NULL, nx, xmin, xmin + nx * dx);
70 H1[1] = new TH1D("1.1", NULL, nx, xmin, xmin + nx * dx);
71 }
72 {
73 const double dx = 0.02;
74 const double xmin = parameters.threshold - parameters.thresholdBand;
75 const int nx = (int) ((10.0 - xmin) / dx);
76
77 H0[2] = new TH1D("2.0", NULL, nx, xmin, xmin + nx * dx);
78 H1[2] = new TH1D("2.1", NULL, nx, xmin, xmin + nx * dx);
79 }
80
81 H1[1]->Sumw2();
82 H1[2]->Sumw2();
83
84 int test = 1;
85
89 }) {
90
91 for (int i=1; i <= H0[test]->GetNbinsX(); ++i) {
92
93 const double npe = H0[test]->GetBinCenter(i);
94 const double p = cpu->getChargeProbability(npe,NPE);
95
96 H0[test]->SetBinContent(i,p);
97 }
98
99 if (numberOfHits > 0) {
100
101 int number_of_hits = 0;
102
103 for (int i = 0; i != numberOfHits; ++i) {
104
105 const double npe = cpu->getRandomCharge(NPE);
106
107 try {
108
109 if (cpu->applyThreshold(npe)) {
110
111 ++number_of_hits;
112
113 H1[test]->Fill(npe);
114 }
115
116 } catch (const JValueOutOfRange& exception) {
117
118 DEBUG(exception.what());
119 continue;
120 }
121 }
122
123 const double dx = (H1[test]->GetXaxis()->GetXmax() - H1[test]->GetXaxis()->GetXmin()) / H1[test]->GetXaxis()->GetNbins();
124
125 H1[test]->Scale(1.0 / (double) number_of_hits / dx);
126
127 delete cpu;
128
129 ++test;
130 }
131 }
132
133 TFile out(outputFile.c_str(), "recreate");
134
135 for (auto& i : H0) { out << *i.second; }
136 for (auto& i : H1) { out << *i.second; }
137
138 out.Write();
139 out.Close();
140
141 // test
142
143 ASSERT(numberOfHits > 0);
144
145 for (int i = 1; i != test; ++i) {
146
147 DEBUG("Test " << i << endl);
148
149 for (int ix = 1; ix <= H0[i]->GetNbinsX(); ++ix) {
150
151 const Double_t x = H0[i]->GetBinCenter (ix);
152 const Double_t y0 = H0[i]->GetBinContent(ix);
153 const Double_t y1 = H1[i]->GetBinContent(ix);
154
155 DEBUG("[" << setw(3) << ix << "]" << ' '
156 << FIXED(5,3) << x << ' '
157 << FIXED(6,4) << y0 << ' '
158 << FIXED(6,4) << y1 << endl);
159
160 ASSERT(fabs(y0 - y1) < precision);
161 }
162 }
163
164 return 0;
165}
string outputFile
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define ASSERT(A,...)
Assert macro.
Definition JMessage.hh:90
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Auxiliary class for map of PMT parameters.
const JPMTParameters & getPMTParameters(const JPMTIdentifier &id) const
Get PMT parameters.
Data structure for PMT parameters.
double thresholdBand
threshold-band [npe]
double threshold
threshold [npe]
Exception for accessing a value in a collection that is outside of its range.
Utility class to parse command line options.
Definition JParser.hh:1698
const double xmin
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary data structure for floating point format specification.
Definition JManip.hh:448
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition JParser.hh:68