Jpp  18.2.1-ARCA-DF-PATCH
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JPlotPDF_L1.cc File Reference
#include <string>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include "TROOT.h"
#include "TFile.h"
#include "TH1D.h"
#include "JTools/JFunction1D_t.hh"
#include "JTools/JFunctionalMap_t.hh"
#include "JTools/JAbstractHistogram.hh"
#include "JPhysics/JPDFTransformer.hh"
#include "JPhysics/JPDFTable.hh"
#include "JPhysics/JPDFTypes.hh"
#include "JPhysics/JPDFToolkit.hh"
#include "JGeometry3D/JAngle3D.hh"
#include "JGeometry3D/JRotation3D.hh"
#include "JDetector/JModule.hh"
#include "JDetector/JDetectorToolkit.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)
 Auxiliary program to determine PDF of L1 hit. More...
 

Function Documentation

int main ( int  argc,
char **  argv 
)

Auxiliary program to determine PDF of L1 hit.

Author
mdejong

Definition at line 33 of file JPlotPDF_L1.cc.

34 {
35  using namespace std;
36  using namespace JPP;
37 
38  typedef JAbstractHistogram<double> JHistogram_t;
39 
40  string inputFile;
41  string outputFile;
42  double E;
43  double R;
44  double R_Hz;
45  JAngle3D dir;
46  double T_ns;
47  JHistogram_t histogram;
48  int debug;
49 
50  try {
51 
52  JParser<> zap("Auxiliary program to determine PDF of L1 hit.");
53 
54  zap['f'] = make_field(inputFile);
55  zap['o'] = make_field(outputFile) = "pdf.root";
56  zap['E'] = make_field(E, "muon energy [GeV]") = 1.0;
57  zap['R'] = make_field(R, "distance of approach [m]");
58  zap['D'] = make_field(dir, "(theta, phi) of PMT [rad]");
59  zap['T'] = make_field(T_ns, "time window [ns]") = 10.0; // [ns]
60  zap['B'] = make_field(R_Hz, "background rate [Hz]") = 0.0;
61  zap['H'] = make_field(histogram, "histogram binning") = JHistogram_t();
62  zap['d'] = make_field(debug) = 0;
63 
64  zap(argc, argv);
65  }
66  catch(const exception &error) {
67  FATAL(error.what() << endl);
68  }
69 
70  typedef JSplineFunction1S_t JFunction1D_t;
71  typedef JMAPLIST<JPolint1FunctionalMap,
72  JPolint1FunctionalGridMap,
73  JPolint1FunctionalGridMap>::maplist JMapList_t;
74  typedef JPDFTable<JFunction1D_t, JMapList_t> JPDF_t;
75 
76  JFunction1D_t::JSupervisor supervisor(new JFunction1D_t::JDefaultResult(zero));
77 
78  const JPDFType_t pdf_t[] = { DIRECT_LIGHT_FROM_MUON,
84 
85  const int N = sizeof(pdf_t) / sizeof(pdf_t[0]);
86 
87  JPDF_t pdf[N];
88 
89  for (int i = 0; i != N; ++i) {
90 
91  try {
92 
93  const string file_name = getFilename(inputFile, pdf_t[i]);
94 
95  NOTICE("loading input from file " << file_name << "... " << flush);
96 
97  pdf[i].load(file_name.c_str());
98 
99  NOTICE("OK" << endl);
100  }
101  catch(const JException& error) {
102  FATAL(error.what() << endl);
103  }
104 
105  pdf[i].setExceptionHandler(supervisor);
106  }
107 
108  if (!histogram.is_valid()) {
109 
110  histogram = JHistogram_t(-50.0, +50.0);
111 
112  histogram.setBinWidth(0.1);
113  }
114 
115 
116  JModule module = getModule<JKM3NeT_t>(1);
117 
118  module.rotate(JRotation3D(dir));
119 
120 
121  TFile out(outputFile.c_str(), "recreate");
122 
123  TH1D h0("h0", NULL, histogram.getNumberOfBins(), histogram.getLowerLimit(), histogram.getUpperLimit());
124 
125  JSplineFunction1S_t zsp;
126 
127  for (double t1 = histogram.getLowerLimit(); t1 <= histogram.getUpperLimit(); t1 += 0.1) {
128 
129  const double t2 = t1 + T_ns;
130 
131  JFunction1D_t::result_type y1;
132  JFunction1D_t::result_type y2;
133 
134  for (int i = 0; i != N; ++i) {
135 
136  JFunction1D_t::result_type p1;
137  JFunction1D_t::result_type p2;
138 
139  // add PMTs
140 
141  for (const auto& pmt : module) {
142  p1 += pdf[i](R, pmt.getTheta(), pmt.getPhi(), t1);
143  p2 += pdf[i](R, pmt.getTheta(), pmt.getPhi(), t2);
144  }
145 
146  if (is_deltarays(pdf_t[i])) {
147  p1 *= getDeltaRaysFromMuon(E);
148  p2 *= getDeltaRaysFromMuon(E);
149  } else if (is_bremsstrahlung(pdf_t[i])) {
150  p1 *= E;
151  p2 *= E;
152  }
153 
154  y1 += p1;
155  y2 += p2;
156  }
157 
158  // add background
159 
160  y1.f += R_Hz * 1e-9; // function value
161  y1.v += R_Hz * 1e-9 * (t1 - histogram.getLowerLimit()); // integral [Tmin,t1]
162  y2.v += R_Hz * 1e-9 * (t2 - histogram.getLowerLimit()); // integral [Tmin,t2]
163 
164  zsp[t1] = y1.f * (1.0 - exp(y1.v - y2.v)); // 1 - P(0)
165  }
166 
167  zsp.compile();
168 
169  for (int ix = 1; ix <= h0.GetNbinsX(); ++ix) {
170 
171  const double t1 = h0.GetBinCenter(ix);
172 
173  try {
174 
175  const JFunction1D_t::result_type result = zsp(t1);
176 
177  const double W = exp(-result.v) * result.f / (1.0 - exp(-result.V));
178 
179  h0.SetBinContent(ix, W);
180  }
181  catch(const exception&) {}
182  }
183 
184  out.Write();
185  out.Close();
186 }
Utility class to parse command line options.
Definition: JParser.hh:1514
TPaveText * p1
then usage $script< input file >[option[primary[working directory]]] nWhere option can be E
Definition: JMuonPostfit.sh:40
direct light from EM showers
Definition: JPDFTypes.hh:29
static const JZero zero
Function object to assign zero value.
Definition: JZero.hh:105
then warning Cannot perform comparison test for histogram
string outputFile
direct light from muon
Definition: JPDFTypes.hh:26
bool is_bremsstrahlung(const int pdf)
Test if given PDF type corresponds to Cherenkov light from Bremsstrahlung.
Definition: JPDFTypes.hh:137
scattered light from muon
Definition: JPDFTypes.hh:27
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
scattered light from delta-rays
Definition: JPDFTypes.hh:33
#define NOTICE(A)
Definition: JMessage.hh:64
scattered light from EM showers
Definition: JPDFTypes.hh:30
JPDFType_t
PDF types.
Definition: JPDFTypes.hh:24
#define FATAL(A)
Definition: JMessage.hh:67
direct light from delta-rays
Definition: JPDFTypes.hh:32
p2
Definition: module-Z:fit.sh:74
then JCookie sh JDataQuality D $DETECTOR_ID R
Definition: JDataQuality.sh:41
then usage $script< input file >[option[primary[working directory]]] nWhere option can be N
Definition: JMuonPostfit.sh:40
bool is_deltarays(const int pdf)
Test if given PDF type corresponds to Cherenkov light from delta-rays.
Definition: JPDFTypes.hh:151
double getDeltaRaysFromMuon(const double E)
Equivalent EM-shower energy due to delta-rays per unit muon track length.
Definition: JPDFToolkit.hh:67
std::string getFilename(const std::string &file_name)
Get file name part, i.e. part after last JEEP::PATHNAME_SEPARATOR if any.
Definition: JeepToolkit.hh:128
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable STRING $argv[2] set_array QUANTILES set_variable FORMULA *[0] exp(-0.5 *(x-[1])*(x-[1])/([2]*[2]))" set_variable MODULE `getModule -a $DETECTOR -L "$STRING 0"` source JAcousticsToolkit.sh typeset -A TRIPODS get_tripods $WORKDIR/tripod.txt TRIPODS XMEAN
int debug
debug level