All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ShowerCalibrationGaloreScale_test.cc
Go to the documentation of this file.
1 /**
2  * @file ShowerCalibrationGaloreScale_test.cc
3  * @brief Tests ShowerCalibrationGaloreScale service provider
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date April 28, 2016
6  * @see ShowerCalibrationGaloreScale.h
7  *
8  * Runs a test that instantiates a ShowerCalibrationGaloreScale provider with
9  * a known configuration and verifies that the same factor is returned for
10  * a nominal reconstructed shower.
11  * It also prints on screen a "standard" table of corrections, as printed by
12  * ShowerCalibrationTableTest().
13  *
14  * Command line arguments: none.
15  *
16  */
17 
18 
19 // LArSoft libraries
25 
26 // C/C++ standard libraries
27 #include <iostream>
28 
29 
30 //------------------------------------------------------------------------------
31 int main() {
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");
43  ("ShowerCalibrationGaloreService", R"( service_provider: "ShowerCalibrationGaloreScaleService" factor: )" + std::to_string(expected.factor) + R"( error: )" + std::to_string(expected.error) + R"( )");
44 
45  // set up a basic testing environment with that configuration
46  auto TesterEnv = testing::CreateTesterEnvironment(config);
47 
48  // set up a service provider
49  // (ShowerCalibrationGaloreScale explicitly supports this one-step setup)
50  TesterEnv.SimpleProviderSetup<lar::example::ShowerCalibrationGaloreScale>();
51 
52  //
53  // computation of expected values
54  //
55  unsigned int nErrors = 0; // error count
56 
57  // get the provider we just set up (but accessing it by the interface)
58  auto const* Calibration
59  = TesterEnv.Provider<lar::example::ShowerCalibrationGalore>();
60 
61  //
62  // run the test
63  //
65  std::cout, Calibration, 0.0, 2.5, 0.1,
66  { 11, 13, -11, -13, 211, 111, 2112, 2212, 22 }
67  );
68 
69  std::cout << Calibration->report() << std::endl;
70 
71  auto shower = lar::example::tests::MakeShower(1.0); // shower with 1 GeV
72  auto corr = Calibration->correction(shower);
73  if (corr != expected) {
74  std::cerr << "Correction for a shower of energy "
75  << shower.Energy().at(shower.best_plane()) << " GeV is " << corr
76  << ", expected " << expected << std::endl;
77  ++nErrors;
78  }
79  auto corr_factor = Calibration->correctionFactor(shower);
80  if (corr_factor != expected.factor) {
81  std::cerr << "Correction factor for a shower of energy "
82  << shower.Energy().at(shower.best_plane()) << " GeV is " << corr_factor
83  << ", expected " << expected.factor << std::endl;
84  ++nErrors;
85  }
86 
87  return nErrors;
88 } // main()
89 
BEGIN_PROLOG could also be cerr
A shower calibration service provider applying a uniform scale.
Test functions for ShowerCalibrationGalore service providers.
Class holding a configuration for a test environment.
Specialization of helper classes for LArSoft tests.
recob::Shower MakeShower(float E, int bestPlane=2, int ID=1)
process_name shower
Definition: cheaterreco.fcl:51
A correction factor with global uncertainty.
void AddDefaultServiceConfiguration(std::string service_name, std::string service_cfg)
Adds a default configuration for the specified service.
Shower calibration service provider applying a uniform energy scale.
TESTENV CreateTesterEnvironment(CONFIG &&config, ARGS...other_args)
Constructs and returns a TesterEnvironment object.
Interface for a shower calibration service provider.
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(WindowPattern const &pattern)
int main(int argc, char **argv)
Base class for unit tests using FHiCL configuration.
BEGIN_PROLOG could also be cout
Interface for a shower calibration service provider.