All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
crt_detsimalg_test.cxx
Go to the documentation of this file.
1 /**
2  * \brief Basic unit tests for the CRT detector simulation
3  *
4  * \author Marco Del Tutto
5  */
6 
7 #include <iostream> // for output before message facility is set up
8 #include <string>
9 #include <memory> // std::unique_ptr<>
10 #include <utility> // std::move(), std::forward()
11 #include <map>
12 #include <type_traits> // std::add_rvalue_reference()
13 #include <stdexcept> // std::logic_error
14 
16 #include "CLHEP/Random/JamesRandom.h"
19 
20 constexpr long SEED = 0;
21 
22 using Parameters = fhicl::Table<sbnd::crt::CRTDetSimParams>;
23 
24 Parameters get_parameters(int argc, char const** argv) {
25 
26  int iParam = 0;
27 
28  // first argument: configuration file (mandatory)
29  std::string config_path;
30  if (++iParam < argc) config_path = argv[iParam];
31 
32 
33  char const* fhicl_env = getenv("FHICL_FILE_PATH");
34  std::string search_path = fhicl_env? std::string(fhicl_env) + ":": ".:";
36 
37  fhicl::intermediate_table table;
38  table = fhicl::parse_document(argv[iParam], policy);
39 
40  // translate into a parameter set
41  fhicl::ParameterSet params;
42  params = fhicl::ParameterSet::make(table);
43 
44  fhicl::ParameterSet p = params.get<fhicl::ParameterSet>("testcrtsim");
45 
46  // std::cout << "p " << p.to_string() << std::endl;
47 
48  Parameters detsim_params(p.template get<fhicl::ParameterSet>("DetSimParams"));
49 
50  return detsim_params;
51 }
52 
53 int main(int argc, char const** argv) {
54 
55  int errors = 0;
56 
57  //
58  // Read parameters
59  //
60  Parameters detsim_params = get_parameters(argc, argv);
61 
62 
63  //
64  // Create DetSimAlg class
65  //
66  CLHEP::HepJamesRandom engine(SEED);
67 
68  sbnd::crt::CRTDetSimAlg detsim_alg(detsim_params,
69  engine,
70  0.);
71 
72  //
73  // Time response
74  //
75  uint32_t ts = detsim_alg.getChannelTriggerTicks(10000, // true time, ns
76  30, // PEs
77  50); // distance to readout
78 
79  std::cout << "ts " << ts << std::endl;
80 
81  // if (ts) {
82  // std::cout << "Signal saturated with a 1.5 MeV deposited energy?" << std::endl;
83  // errors++;
84  // }
85 
86 
87  //
88  // Charge response
89  //
90  long npe0, npe1;
91  double q0, q1;
92  detsim_alg.ChargeResponse(1.5*1e-3, // 1.5 MeV deposited energy
93  5, // 5 cm distance to fiber 0
94  5, // 5 cm distance to fiber 1
95  50, // 50 cm distance to readout
96  npe0, npe1, q0, q1);
97 
98  std::cout << "npe0 " << npe0
99  << "\nnpe1 " << npe1
100  << "\nq0 " << q0
101  << "\nq1 " << q1 << std::endl;
102 
103  if (q0 == detsim_alg.Params().AdcSaturation() or q1 == detsim_alg.Params().AdcSaturation()) {
104  std::cout << "Signal saturated with a 1.5 MeV deposited energy?" << std::endl;
105  errors++;
106  }
107 
108  if (q0 < 0 or q1 < 0) {
109  std::cout << "Predicted ADCs are negative?" << std::endl;
110  errors++;
111  }
112 
113 
114  //
115  // Waveform emulation
116  //
117 
118  double original_adc = 2000;
119  uint16_t adc = detsim_alg.WaveformEmulation(10, // time delay
120  original_adc); // adc
121 
122  std::cout << "original_adc " << original_adc
123  << "\nadc " << adc << std::endl;
124 
125  if (adc > static_cast<uint16_t>(original_adc)) {
126  std::cout << "ADC value after waveform emulation is larger?" << std::endl;
127  errors++;
128  }
129 
130 
131 
132 
133  return errors;
134 
135 }
136 
137 
uint32_t getChannelTriggerTicks(float t0, float npeMean, float r)
Parameters get_parameters(int argc, char const **argv)
pdgs p
Definition: selectors.fcl:22
fhicl::Atom< uint32_t > AdcSaturation
void ChargeResponse(double eDep, double d0, double d1, double distToReadout, long &npe0, long &npe1, double &q0, double &q1)
fhicl::Table< sbnd::crt::CRTDetSimParams > Parameters
do i e
constexpr long SEED
Basic unit tests for the CRT detector simulation.
int main(int argc, char **argv)
Base class for unit tests using FHiCL configuration.
uint16_t WaveformEmulation(const uint32_t &time_delay, const double &adc)
BEGIN_PROLOG could also be cout