All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OpticalRawDigitReformatter_module.cc
Go to the documentation of this file.
1 // Ben Jones, MIT, 2013
2 //
3 // This module finds periods of time-localized activity
4 // from the optical system, called Flashes.
5 
6 // LArSoft includes
12 
13 // Framework includes
14 #include "art/Framework/Core/EDProducer.h"
15 #include "art/Framework/Core/ModuleMacros.h"
16 #include "art/Framework/Principal/Event.h"
17 #include "art/Framework/Principal/Handle.h"
18 #include "fhiclcpp/ParameterSet.h"
19 
20 // C++ Includes
21 #include <cstring>
22 
23 namespace opdet {
24 
25  class OpticalRawDigitReformatter : public art::EDProducer {
26  public:
27  // Standard constructor and destructor for an ART module.
28  explicit OpticalRawDigitReformatter(const fhicl::ParameterSet&);
29 
30  // The producer routine, called once per event.
31  void produce(art::Event&);
32 
33  private:
34  // The parameters we'll read from the .fcl file.
35  std::string fInputModule; // Input tag for OpDet collection
36  std::string fGenModule;
37 
38  std::vector<std::string> CategoryLabels;
39  };
40 
41 }
42 
43 namespace opdet {
44  DEFINE_ART_MODULE(OpticalRawDigitReformatter)
45 }
46 
47 namespace opdet {
48 
49  //-----------------------------------------------------------------------
50  // Constructor
52  : EDProducer{pset}
53  {
54  // Indicate that the Input Module comes from .fcl
55  fInputModule = pset.get<std::string>("InputModule");
56  fGenModule = pset.get<std::string>("GenModule");
57 
58  CategoryLabels.push_back("Undefined");
59  CategoryLabels.push_back("HighGain");
60  CategoryLabels.push_back("LowGain");
61  CategoryLabels.push_back("LogicPulse");
62  CategoryLabels.push_back("FEMCosmicHighGain");
63  CategoryLabels.push_back("FEMCosmicLowGain");
64  CategoryLabels.push_back("FEMCosmicLogicPulse");
65  CategoryLabels.push_back("FEMBeamHighGain");
66  CategoryLabels.push_back("FEMBeamLowGain");
67  CategoryLabels.push_back("FEMBeamLogicPulse");
68  CategoryLabels.push_back("BeamPMTTrigger");
69  CategoryLabels.push_back("CosmicPMTTrigger");
70 
71  // One for each category
72  for (auto label : CategoryLabels)
73  produces<std::vector<raw::OpDetWaveform>>(label);
74  }
75 
76  //-----------------------------------------------------------------------
77  void
79  {
80 
81  // These are the storage pointers we will put in the event, one per category
82  std::vector<std::unique_ptr<std::vector<raw::OpDetWaveform>>> RawOpDetVecs;
83  for (unsigned int i = 0; i < CategoryLabels.size(); i++) {
84  std::unique_ptr<std::vector<raw::OpDetWaveform>> tmp(new std::vector<raw::OpDetWaveform>);
85  RawOpDetVecs.push_back(std::move(tmp));
86  }
87 
88  std::vector<const sim::BeamGateInfo*> beamGateArray;
89  try {
90  evt.getView(fGenModule, beamGateArray);
91  }
92  catch (art::Exception const& err) {
93  if (err.categoryCode() != art::errors::ProductNotFound) throw;
94  }
95 
96  // Read in the OpticalRawDigit collection from the event.
97  art::Handle<std::vector<optdata::OpticalRawDigit>> ordHandle;
98  evt.getByLabel(fInputModule, ordHandle);
99  std::vector<optdata::OpticalRawDigit> const& ord_vec(*ordHandle);
100 
101  auto const clock_data =
102  art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
103 
104  for (auto ord : ord_vec) {
105  optdata::Channel_t channel = ord.ChannelNumber();
106  optdata::TimeSlice_t timeSlice = ord.TimeSlice();
107  optdata::Frame_t frame = ord.Frame();
108  optdata::Optical_Category_t category = ord.Category();
109 
110  // Use the optical clock to conver timeSlice and frame
111  // to an absolute time
112  double timeStamp = clock_data.OpticalClock().Time(timeSlice, frame);
113 
114  RawOpDetVecs[category]->push_back(raw::OpDetWaveform(timeStamp, channel, ord));
115  }
116 
117  // Store results into the event
118  for (unsigned int i = 0; i < CategoryLabels.size(); i++) {
119  // Only store collections which contain waveforms, assign the label
120  if (RawOpDetVecs[i]->size() > 0) { evt.put(std::move(RawOpDetVecs[i]), CategoryLabels[i]); }
121  }
122  }
123 
124 } // namespace opdet
EResult err(const char *call)
enum optdata::_optical_category_t Optical_Category_t
std::size_t size(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:561
unsigned int TimeSlice_t
Definition: OpticalTypes.h:20
unsigned int Frame_t
Definition: OpticalTypes.h:21
TCEvent evt
Definition: DataStructs.cxx:8
unsigned int Channel_t
Definition: OpticalTypes.h:19
OpticalRawDigitReformatter(const fhicl::ParameterSet &)