CheckProducts_module.cc
Go to the documentation of this file.
12 #include "fhiclcpp/types/TupleAs.h"
13 
14 using art::EventRange;
15 using art::InputTag;
16 using art::RangeSet;
18 using fhicl::Name;
19 using fhicl::Sequence;
20 using fhicl::TupleAs;
21 using std::string;
22 using std::vector;
23 
24 namespace {
25 
26  double constexpr tolerance = std::numeric_limits<double>::epsilon();
27 
28  struct Config {
29  TupleAs<InputTag(string)> npotsTag{Name("npotsTag")};
30  TupleAs<InputTag(string)> nParticlesTag{Name("nParticlesTag")};
31  TupleAs<InputTag(string)> geomTag{Name("geomTag")};
32  TupleAs<InputTag(string)> calibTag{Name("calibTag")};
33  TupleAs<TaggedValue<double>(string, double)> trkEffRef{Name("trkEffRef")};
34  };
35 
36  class CheckProducts : public art::EDAnalyzer {
37  public:
38  using Parameters = EDAnalyzer::Table<Config>;
39  explicit CheckProducts(Parameters const& config);
40 
41  void beginRun(art::Run const& r) override;
42  void beginSubRun(art::SubRun const& r) override;
43  void
44  analyze(art::Event const&) override
45  {}
46 
47  private:
48  art::InputTag const potsTag_;
49  art::InputTag const nParticlesTag_;
50  art::InputTag const geomTag_;
51  art::InputTag const calibTag_;
52  TaggedValue<double> const trkEffRef_;
53 
54  }; // CheckProducts
55 
56  CheckProducts::CheckProducts(Parameters const& config)
57  : EDAnalyzer{config}
58  , potsTag_{config().npotsTag()}
59  , nParticlesTag_{config().nParticlesTag()}
60  , geomTag_{config().geomTag()}
61  , calibTag_{config().calibTag()}
62  , trkEffRef_{config().trkEffRef()}
63  {}
64 
65  void
66  CheckProducts::beginRun(art::Run const& r)
67  {
68  // Geometry check
69  auto const& geomH = r.getValidHandle<arttest::Geometry>(geomTag_);
70  auto const& geomRef = RangeSet::forRun(r.id());
71  BOOST_CHECK(
72  art::same_ranges(geomH.provenance()->rangeOfValidity(), geomRef));
73  BOOST_CHECK_EQUAL(geomH->run(), r.run());
74 
75  // nPOTs check
76  RangeSet nPotsRef{r.run()};
77  nPotsRef.emplace_range(0, 1, 101);
78  nPotsRef.emplace_range(1, 1, 101);
79  nPotsRef.collapse();
80  auto const& npotsH = r.getValidHandle<unsigned>(potsTag_);
81  BOOST_CHECK(
82  art::same_ranges(npotsH.provenance()->rangeOfValidity(), nPotsRef));
83  BOOST_CHECK_EQUAL(*npotsH, 200u);
84  }
85 
86  void
87  CheckProducts::beginSubRun(art::SubRun const& sr)
88  {
89  // CalibConstants check
90  auto const& calRef = RangeSet::forSubRun(sr.id());
91  auto const& calH = sr.getValidHandle<arttest::CalibConstants>(calibTag_);
92  BOOST_CHECK(art::same_ranges(calH.provenance()->rangeOfValidity(), calRef));
93 
94  // TrackEfficiency check
95  RangeSet trkEffRef{sr.run()};
96  trkEffRef.emplace_range(sr.subRun(), 1, 101);
97  auto const& trkEffH =
98  sr.getValidHandle<arttest::TrackEfficiency>(trkEffRef_.tag_);
99  BOOST_CHECK(
100  art::same_ranges(trkEffH.provenance()->rangeOfValidity(), trkEffRef));
101 
102  BOOST_CHECK_CLOSE_FRACTION(
103  trkEffH->efficiency(), trkEffRef_.value_, tolerance);
104 
105  // nParticles and TrackEfficiency RangeSet check
106  auto const& nParticlesH = sr.getValidHandle<unsigned>(nParticlesTag_);
107  BOOST_CHECK(art::same_ranges(trkEffH, nParticlesH));
108  }
109 
110 } // namespace
111 
112 DEFINE_ART_MODULE(CheckProducts)
def analyze(root, level, gtrees, gbranches, doprint)
Definition: rootstat.py:67
RunID id() const
Definition: Run.cc:24
std::string string
Definition: nybbler.cc:12
double const tolerance
Definition: Run.h:21
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:68
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:480
SubRunNumber_t subRun() const
Definition: DataViewImpl.cc:89
RunNumber_t run() const
Definition: DataViewImpl.cc:82
SubRunID id() const
Definition: SubRun.cc:21
std::enable_if_t< detail::are_handles< T, U >::value, bool > same_ranges(T const &a, U const &b)
static const double sr
Definition: Units.h:167
AdcRoiViewer::Name Name