Functions
ShowerCalibrationGaloreScale_test.cc File Reference

Tests ShowerCalibrationGaloreScale service provider. More...

#include "larexamples/Services/ShowerCalibrationGalore/Providers/ShowerCalibrationGaloreScale.h"
#include "larexamples/Services/ShowerCalibrationGalore/Providers/ShowerCalibrationGalore.h"
#include "larexamples/Services/ShowerCalibrationGalore/Providers/ShowerCalibrationGaloreScaleTestHelpers.h"
#include "larcorealg/TestUtils/unit_test_base.h"
#include "test/Services/ShowerCalibrationGalore/Providers/ShowerCalibrationGaloreTests.h"
#include <iostream>

Go to the source code of this file.

Functions

int main ()
 

Detailed Description

Tests ShowerCalibrationGaloreScale service provider.

Author
Gianluca Petrillo (petri.nosp@m.llo@.nosp@m.fnal..nosp@m.gov)
Date
April 28, 2016
See also
ShowerCalibrationGaloreScale.h

Runs a test that instantiates a ShowerCalibrationGaloreScale provider with a known configuration and verifies that the same factor is returned for a nominal reconstructed shower. It also prints on screen a "standard" table of corrections, as printed by ShowerCalibrationTableTest().

Command line arguments: none.

Definition in file ShowerCalibrationGaloreScale_test.cc.

Function Documentation

int main ( void  )

Definition at line 31 of file ShowerCalibrationGaloreScale_test.cc.

31  {
32 
33  //
34  // prepare the test environment
35  //
37 
38  // provide a test name and a push a configuration for
39  // "ShowerCalibrationGaloreService" ("service_provider" is inconsequential)
41  ("ShowerCalibrationGaloreScale_test");
42  config.AddDefaultServiceConfiguration
43  ("ShowerCalibrationGaloreService", R"(
44  service_provider: "ShowerCalibrationGaloreScaleService"
45  factor: )" + std::to_string(expected.factor) + R"(
46  error: )" + std::to_string(expected.error) + R"(
47  )");
48 
49  // set up a basic testing environment with that configuration
50  auto TesterEnv = testing::CreateTesterEnvironment(config);
51 
52  // set up a service provider
53  // (ShowerCalibrationGaloreScale explicitly supports this one-step setup)
54  TesterEnv.SimpleProviderSetup<lar::example::ShowerCalibrationGaloreScale>();
55 
56  //
57  // computation of expected values
58  //
59  unsigned int nErrors = 0; // error count
60 
61  // get the provider we just set up (but accessing it by the interface)
62  auto const* Calibration
63  = TesterEnv.Provider<lar::example::ShowerCalibrationGalore>();
64 
65  //
66  // run the test
67  //
69  std::cout, Calibration, 0.0, 2.5, 0.1,
70  { 11, 13, -11, -13, 211, 111, 2112, 2212, 22 }
71  );
72 
73  std::cout << Calibration->report() << std::endl;
74 
75  auto shower = lar::example::tests::MakeShower(1.0); // shower with 1 GeV
76  auto corr = Calibration->correction(shower);
77  if (corr != expected) {
78  std::cerr << "Correction for a shower of energy "
79  << shower.Energy().at(shower.best_plane()) << " GeV is " << corr
80  << ", expected " << expected << std::endl;
81  ++nErrors;
82  }
83  auto corr_factor = Calibration->correctionFactor(shower);
84  if (corr_factor != expected.factor) {
85  std::cerr << "Correction factor for a shower of energy "
86  << shower.Energy().at(shower.best_plane()) << " GeV is " << corr_factor
87  << ", expected " << expected.factor << std::endl;
88  ++nErrors;
89  }
90 
91  return nErrors;
92 } // main()
const char expected[]
Definition: Exception_t.cc:22
A shower calibration service provider applying a uniform scale.
Class holding a configuration for a test environment.
recob::Shower MakeShower(float E, int bestPlane=2, int ID=1)
A correction factor with global uncertainty.
static Config * config
Definition: config.cpp:1054
TESTENV CreateTesterEnvironment(CONFIG &&config, ARGS...other_args)
Constructs and returns a TesterEnvironment object.
unsigned int ShowerCalibrationTableTest(Stream &&out, lar::example::ShowerCalibrationGalore const *calibration, float Emin=0.0, float Emax=2.5, float Estep=0.1, std::vector< lar::example::ShowerCalibrationGalore::PDGID_t > const &pids={11, 13, 111, 2212, 22})
Synthetic test: prints corrections for showers in a energy range.
std::string to_string(ModuleType const mt)
Definition: ModuleType.h:34
QTextStream & endl(QTextStream &s)
Interface for a shower calibration service provider.