WaveformsToTree_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: WaveformsToTree
3 // Plugin Type: producer (art v2_10_03)
4 // File: WaveformsToTree_module.cc
5 ////////////////////////////////////////////////////////////////////////
6 
13 #include "art_root_io/TFileService.h"
15 
17 #include "fhiclcpp/ParameterSet.h"
19 
22 
23 #include <memory>
24 #include <fstream>
25 
26 #include "TTree.h"
27 
29 public:
30  explicit WaveformsToTree(fhicl::ParameterSet const & p);
31  // The compiler-generated destructor is fine for non-base
32  // classes without bare pointers or other resource use.
33 
34  // Plugins should not be copied or assigned.
35  WaveformsToTree(WaveformsToTree const &) = delete;
36  WaveformsToTree(WaveformsToTree &&) = delete;
37  WaveformsToTree & operator = (WaveformsToTree const &) = delete;
39 
40  // Required functions.
41  void analyze(art::Event const& e) override;
42 
43  void beginJob() override;
44 
45  void endJob() override { m_tree->Write(); }
46 private:
47  // The module name of the raw digits we're reading in
50  TTree* m_tree;
51  std::vector<std::vector<int> > m_waveforms;
52  std::vector<int> m_chans;
53 };
54 
55 
57  : EDAnalyzer(p),
58  m_inputTag(p.get<std::string>("InputTag", "daq")),
59  m_maxChannels(p.get<int>("MaxChannels"))
60 {
61 }
62 
64 {
66  m_tree = tfs->make<TTree>("WaveformTree","title");
67  m_tree->Branch<std::vector<std::vector<int> > >("waveforms", &m_waveforms);
68  m_tree->Branch("chans", &m_chans);
69 }
70 
72 {
73  m_waveforms.clear();
74  m_chans.clear();
75 
76  auto const& digits_handle=e.getValidHandle<std::vector<raw::RawDigit>>(m_inputTag);
77  auto& digits_in =*digits_handle;
78 
79  int nChan=0;
81  for(auto&& digit: digits_in){
82  bool isCollection=geo->SignalType(digit.Channel())==geo::kCollection;
83  if(!isCollection) continue;
84  if(nChan++ > m_maxChannels) break;
85 
86  m_chans.push_back(digit.Channel());
87  std::vector<int> waveform;
88  for(auto const& adc: digit.ADCs()){
89  waveform.push_back(adc);
90  }
91  m_waveforms.push_back(std::move(waveform));
92  }
93  m_tree->Fill();
94 }
95 
void endJob() override
std::vector< int > m_chans
std::string string
Definition: nybbler.cc:12
void beginJob() override
int16_t adc
Definition: CRTFragment.hh:202
STL namespace.
SigType_t SignalType(geo::PlaneID const &pid) const
Returns the type of signal on the channels of specified TPC plane.
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
art framework interface to geometry description
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
def move(depos, offset)
Definition: depos.py:107
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
p
Definition: test.py:223
std::vector< std::vector< int > > m_waveforms
WaveformsToTree(fhicl::ParameterSet const &p)
WaveformsToTree & operator=(WaveformsToTree const &)=delete
void analyze(art::Event const &e) override
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
LArSoft geometry interface.
Definition: ChannelGeo.h:16
Signal from collection planes.
Definition: geo_types.h:146