Reconstruction_module.cc
Go to the documentation of this file.
1 // vim: set sw=2 expandtab :
9 #include "fhiclcpp/types/Atom.h"
10 #include "fhiclcpp/types/Name.h"
11 #include "fhiclcpp/types/Table.h"
12 #include "fhiclcpp/types/TupleAs.h"
13 #include "hep_concurrency/tsan.h"
14 
15 #include <atomic>
16 #include <memory>
17 #include <string>
18 #include <vector>
19 
20 #include <unistd.h>
21 
22 using namespace art;
23 using namespace std;
24 
25 namespace arttest {
26 
27  class Reconstruction : public SharedFilter {
28  public:
29  struct Config {
31  fhicl::Atom<double> threshold{fhicl::Name("energyThreshold")};
32  };
34  explicit Reconstruction(Parameters const&, ProcessingFrame const&);
35 
36  private:
37  void beginSubRun(SubRun&, ProcessingFrame const&) override;
38  void endSubRun(SubRun&, ProcessingFrame const&) override;
39  bool filter(Event&, ProcessingFrame const&) override;
40 
41  double const threshold_;
43  std::atomic<unsigned> numerator_{};
44  std::atomic<unsigned> denominator_{};
45  };
46 
47  Reconstruction::Reconstruction(Parameters const& config,
48  ProcessingFrame const&)
49  : SharedFilter{config}
50  , threshold_{config().threshold()}
51  , particleEnergiesTkn_{consumes<vector<double>>(config().inputTag())}
52  {
53  produces<arttest::CalibConstants, InSubRun>("CalibConstants");
54  produces<arttest::TrackEfficiency, InSubRun>("TrackEfficiency");
55  async<InEvent>();
56  }
57 
58  void
60  {
61  sr.put(make_unique<arttest::CalibConstants>(sr.subRun()),
62  "CalibConstants",
63  fullSubRun());
64  }
65 
66  void
68  {
69  sr.put(make_unique<arttest::TrackEfficiency>(numerator_.load(),
70  denominator_.load()),
71  "TrackEfficiency",
72  subRunFragment());
73  numerator_ = 0u;
74  denominator_ = 0u;
75  }
76 
77  bool
79  {
80  auto const& particleEnergies = *e.getValidHandle(particleEnergiesTkn_);
81  bool pass = false;
82  for (auto const& val : particleEnergies) {
83  if (val >= threshold_) {
84  pass = true;
85  ++numerator_;
86  break;
87  }
88  }
89  ++denominator_;
90  return pass;
91  }
92 
93 } // namespace arttest
94 
STL namespace.
void beginSubRun(SubRun &, ProcessingFrame const &) override
const HLTPathStatus pass
std::atomic< unsigned > numerator_
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:68
bool filter(Event &, ProcessingFrame const &) override
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:480
SubRunNumber_t subRun() const
Definition: DataViewImpl.cc:89
std::atomic< unsigned > denominator_
constexpr auto subRunFragment()
void endSubRun(SubRun &, ProcessingFrame const &) override
constexpr auto fullSubRun()
ProductToken< vector< double > > const particleEnergiesTkn_
ProductID put(std::unique_ptr< PROD > &&edp, FullSemantic< Level::Run > const semantic)
Definition: DataViewImpl.h:692
static const double sr
Definition: Units.h:167
AdcRoiViewer::Name Name