All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OpFlashFinder_module.cc
Go to the documentation of this file.
1 // -*- mode: c++; c-basic-offset: 2; -*-
2 // Ben Jones, MIT, 2013
3 //
4 // This module finds periods of time-localized activity
5 // from the optical system, called Flashes, using OpHits as an input.
6 //
7 // Modified to make it more detector agnostic
8 // by Gleb Sinev, Duke, 2015
9 //
10 
11 // LArSoft includes
19 
20 // Framework includes
21 #include "art/Framework/Core/EDProducer.h"
22 #include "art/Framework/Core/ModuleMacros.h"
23 #include "art/Framework/Principal/Event.h"
24 #include "art/Framework/Principal/Handle.h"
25 #include "art/Framework/Services/Registry/ServiceHandle.h"
26 #include "canvas/Persistency/Common/Ptr.h"
27 #include "canvas/Persistency/Common/PtrVector.h"
28 #include "fhiclcpp/ParameterSet.h"
29 
30 // ROOT includes
31 
32 // C++ Includes
33 #include <memory>
34 #include <string>
35 
36 namespace opdet {
37 
38  class OpFlashFinder : public art::EDProducer {
39  public:
40  // Standard constructor and destructor for an ART module.
41  explicit OpFlashFinder(const fhicl::ParameterSet&);
42 
43  // The producer routine, called once per event.
44  void produce(art::Event&);
45 
46  private:
47  // The parameters we'll read from the .fcl file.
48  std::string fInputModule; // Input tag for OpHit collection
49 
50  Int_t fBinWidth;
51  Float_t fFlashThreshold;
52  Float_t fWidthTolerance;
53  Double_t fTrigCoinc;
54  };
55 
56 }
57 
58 namespace opdet {
59  DEFINE_ART_MODULE(OpFlashFinder)
60 }
61 
62 namespace opdet {
63 
64  //----------------------------------------------------------------------------
65  // Constructor
66  OpFlashFinder::OpFlashFinder(const fhicl::ParameterSet& pset) : EDProducer{pset}
67  {
68 
69  // Indicate that the Input Module comes from .fcl
70  fInputModule = pset.get<std::string>("InputModule");
71 
72  fBinWidth = pset.get<int>("BinWidth");
73  fFlashThreshold = pset.get<float>("FlashThreshold");
74  fWidthTolerance = pset.get<float>("WidthTolerance");
75  fTrigCoinc = pset.get<double>("TrigCoinc");
76 
77  produces<std::vector<recob::OpFlash>>();
78  produces<art::Assns<recob::OpFlash, recob::OpHit>>();
79  }
80 
81  //----------------------------------------------------------------------------
82  void
84  {
85  // These are the storage pointers we will put in the event
86  auto flashPtr = std::make_unique<std::vector<recob::OpFlash>>();
87  auto assnPtr = std::make_unique<art::Assns<recob::OpFlash, recob::OpHit>>();
88 
89  // This will keep track of what flashes will assoc to what ophits
90  // at the end of processing
91  std::vector<std::vector<int>> assocList;
92 
93  auto const& geometry(*lar::providerFrom<geo::Geometry>());
94 
95  auto const clock_data =
96  art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
97 
98  // Get OpHits from the event
99  auto const opHitHandle = evt.getValidHandle<std::vector<recob::OpHit>>(fInputModule);
100 
101  RunFlashFinder(*opHitHandle,
102  *flashPtr,
103  assocList,
104  fBinWidth,
105  geometry,
108  clock_data,
109  fTrigCoinc);
110 
111  // Make the associations which we noted we need
112  for (size_t i = 0; i != assocList.size(); ++i) {
113  art::PtrVector<recob::OpHit> opHitPtrVector;
114  for (size_t const hitIndex : assocList.at(i)) {
115  opHitPtrVector.emplace_back(opHitHandle, hitIndex);
116  }
117 
118  util::CreateAssn(*this, evt, *flashPtr, opHitPtrVector, *(assnPtr.get()), i);
119  }
120 
121  evt.put(std::move(flashPtr));
122  evt.put(std::move(assnPtr));
123  }
124 
125 } // namespace opdet
Utilities related to art service access.
const geo::GeometryCore * geometry
void RunFlashFinder(std::vector< recob::OpHit > const &HitVector, std::vector< recob::OpFlash > &FlashVector, std::vector< std::vector< int >> &AssocList, double const BinWidth, geo::GeometryCore const &geom, float const FlashThreshold, float const WidthTolerance, detinfo::DetectorClocksData const &ClocksData, float const TrigCoinc)
Definition: OpFlashAlg.cxx:63
bool CreateAssn(art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t index=UINT_MAX)
Creates a single one-to-one association.
void produce(art::Event &)
TCEvent evt
Definition: DataStructs.cxx:8
OpFlashFinder(const fhicl::ParameterSet &)
art framework interface to geometry description