CheckMoreProducts_module.cc
Go to the documentation of this file.
10 #include "fhiclcpp/types/TupleAs.h"
11 
12 using art::EventRange;
13 using art::InputTag;
14 using art::RangeSet;
15 using arttest::Fraction;
17 using fhicl::Name;
18 using fhicl::Sequence;
19 using fhicl::TupleAs;
20 using std::string;
21 using std::vector;
22 
23 namespace {
24 
25  double constexpr tolerance = std::numeric_limits<double>::epsilon();
26 
27  struct Config {
28  TupleAs<InputTag(string)> trkEffTag{Name("trkEffTag")};
29  TupleAs<InputTag(string)> trkEffValueTag{Name("trkEffValueTag")};
30  TupleAs<TaggedValue<unsigned>(string, unsigned)> nParticlesRef{
31  Name("nParticlesRef")};
32  TupleAs<TaggedValue<unsigned>(string, unsigned)> seenParticlesRef{
33  Name("seenParticlesRef")};
34  TupleAs<TaggedValue<double>(string, double)> particleRatioRef{
35  Name("particleRatioRef")};
36  };
37 
38  class CheckMoreProducts : public art::EDAnalyzer {
39  public:
40  using Parameters = EDAnalyzer::Table<Config>;
41  explicit CheckMoreProducts(Parameters const& config);
42 
43  void beginSubRun(art::SubRun const& r) override;
44  void
45  analyze(art::Event const&) override
46  {}
47 
48  private:
49  art::InputTag const trkEffTag_;
50  art::InputTag const trkEffValueTag_;
51  TaggedValue<unsigned> const nParticlesRef_;
52  TaggedValue<unsigned> const seenParticlesRef_;
53  TaggedValue<double> const particleRatioRef_;
54 
55  }; // CheckMoreProducts
56 
57  CheckMoreProducts::CheckMoreProducts(Parameters const& config)
58  : EDAnalyzer{config}
59  , trkEffTag_{config().trkEffTag()}
60  , trkEffValueTag_{config().trkEffValueTag()}
61  , nParticlesRef_{config().nParticlesRef()}
62  , seenParticlesRef_{config().seenParticlesRef()}
63  , particleRatioRef_{config().particleRatioRef()}
64  {}
65 
66  void
67  CheckMoreProducts::beginSubRun(art::SubRun const& sr)
68  {
69  // User-assembled TrackEfficiency check
70  auto const& trkEffH =
72  auto const& trkEffValueH = sr.getValidHandle<Fraction>(trkEffValueTag_);
73  BOOST_CHECK(art::same_ranges(trkEffH, trkEffValueH));
74  BOOST_CHECK_CLOSE_FRACTION(
75  trkEffH->efficiency(), trkEffValueH->value(), tolerance);
76 
77  // User-assembled ParticleRatio check
78  auto const seenParticles = sr.getByLabel<unsigned>(seenParticlesRef_.tag_);
79  auto const nParticles = sr.getByLabel<unsigned>(nParticlesRef_.tag_);
80  auto const& particleRatioH =
81  sr.getValidHandle<Fraction>(particleRatioRef_.tag_);
82  BOOST_CHECK_EQUAL(seenParticles, seenParticlesRef_.value_);
83  BOOST_CHECK_EQUAL(nParticles, nParticlesRef_.value_);
84  BOOST_CHECK_CLOSE_FRACTION(particleRatioH->value(),
85  particleRatioRef_.value_,
86  0.01); // 1% tolerance
87  BOOST_CHECK(art::same_ranges(particleRatioH, trkEffValueH));
88  BOOST_CHECK(!art::disjoint_ranges(particleRatioH, trkEffValueH));
89  BOOST_CHECK(art::overlapping_ranges(particleRatioH, trkEffValueH));
90  }
91 
92 } // namespace
93 
94 DEFINE_ART_MODULE(CheckMoreProducts)
def analyze(root, level, gtrees, gbranches, doprint)
Definition: rootstat.py:67
std::string string
Definition: nybbler.cc:12
double const tolerance
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:435
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:68
std::enable_if_t< detail::are_handles< T, U >::value, bool > disjoint_ranges(T const &a, U const &b)
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:480
std::enable_if_t< detail::are_handles< T, U >::value, bool > overlapping_ranges(T const &a, U const &b)
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