All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OpDetWaveformMaker.cc
Go to the documentation of this file.
1 /**
2  * \file OpDetWaveformMaker.cc
3  *
4  *
5  * Author:
6  */
7 
8 #include <iostream>
9 #include <array>
10 
11 #include "canvas/Utilities/InputTag.h"
12 #include "core/SelectionBase.hh"
13 #include "core/Event.hh"
14 #include "core/Experiment.hh"
15 #include "core/ProviderManager.hh"
16 
19 #include "fhiclcpp/ParameterSet.h"
20 
21 #include "TH1D.h"
22 #include "TGraph.h"
23 
24 namespace ana {
25  namespace SBNOsc {
26 
27 /**
28  * \class OpDetWaveformMaker
29  * \brief Electron neutrino event selection
30  */
32 public:
33  /** Constructor. */
35 
36  /**
37  * Initialization.
38  *
39  * \param config A configuration, as a FHiCL ParameterSet object
40  */
41  void Initialize(fhicl::ParameterSet* config=NULL) {
42  fOpDetWaveformTag = config ? config->get<std::string>("OpDetWaveformTag", "opdaq") : "opdaq";
43  clock_freq = fProviderManager->GetDetectorClocksProvider()->OpticalClock().Frequency();
44  std::cout << "CLOCK FREQ: " << clock_freq << std::endl;
45  event_ind = 0;
46  }
47 
48  /** Finalize and write objects to the output file. */
49  void Finalize() {
50  }
51 
52  /**
53  * Process one event.
54  *
55  * \param ev A single event, as a gallery::Event
56  * \param Reconstructed interactions
57  * \return True to keep event
58  */
59  bool ProcessEvent(const gallery::Event& ev, const std::vector<event::Interaction> &truth, std::vector<event::RecoInteraction>& reco) {
60  const std::vector<raw::OpDetWaveform> &waveforms = *ev.getValidHandle<std::vector<raw::OpDetWaveform>>(fOpDetWaveformTag);
61  //std::map<raw::Channel_t, std::pair<std::vector<float>, std::vector<float>>> waveform_plots;
62  std::map<raw::Channel_t, std::vector<std::pair<float, float>>> waveform_data;
63  std::map<raw::Channel_t, std::vector<float>> wf_start_times;
64  std::map<raw::Channel_t, std::vector<float>> wf_periods;
65  for (const raw::OpDetWaveform &wfconst: waveforms) {
66  raw::OpDetWaveform wf = wfconst;
67  //if (waveform_plots.count(wf.ChannelNumber()) > 0) {
68  // std::cout << "Multi-waveform output! Channel: " << wf.ChannelNumber() << " Event: " << event_ind << std::endl;
69  //}
70  for (unsigned i = 0; i < wf.Waveform().size(); i++) {
71  waveform_data[wf.ChannelNumber()].push_back({i / clock_freq + wf.TimeStamp(), (float)wf.Waveform()[i]});
72  }
73  wf_start_times[wf.ChannelNumber()].push_back(wf.TimeStamp());
74  wf_periods[wf.ChannelNumber()].push_back( wf.Waveform().size() / clock_freq);
75  }
76 
77  // now sort each one
78  //for (auto &wf_data_pair: waveform_data) {
79  // std::sort(wf_data_pair.second.begin(), wf_data_pair.second.end(), [](auto lhs, auto rhs) {return lhs.first < rhs.first;});
80  //}
81  std::map<raw::Channel_t, std::pair<std::vector<float>, std::vector<float>>> waveform_plots;
82  for (auto &wf_data_pair: waveform_data) {
83  for (auto data_pair: wf_data_pair.second) {
84  waveform_plots[wf_data_pair.first].first.push_back(data_pair.first);
85  waveform_plots[wf_data_pair.first].second.push_back(data_pair.second);
86  }
87  }
88 
89  for (auto &start_time_pair: wf_start_times) {
90  std::cout << "Event: " << event_ind << " Channel: " << start_time_pair.first << std::endl;
91  const std::vector<float> &wf_period = wf_periods.at(start_time_pair.first);
92  for (unsigned i = 0; i < start_time_pair.second.size(); i++) {
93  std::cout << start_time_pair.second[i] << " (" << wf_period[i] <<") ";
94 
95  }
96  std::cout << std::endl;
97  }
98 
99  std::vector<TGraph *> plots;
100  for (auto &plot_info: waveform_plots) {
101  TGraph *plot = new TGraph(plot_info.second.first.size(), &plot_info.second.first[0], &plot_info.second.second[0]);
102  plot->SetName((std::string("Waveform ch: ") + std::to_string(plot_info.first) + " ev: " + std::to_string(event_ind)).c_str());
103  plot->SetTitle((std::string("Waveform ch: ") + std::to_string(plot_info.first) + " ev: " + std::to_string(event_ind)).c_str());
104  plots.push_back(plot);
105  }
106  fOutputFile->cd();
107  for (TGraph *plot: plots) {
108  plot->Write();
109  delete plot;
110  }
111  event_ind += 1;
112 
113  return false;
114  }
115 
116 protected:
117  std::string fOpDetWaveformTag;
118  float clock_freq;
119  unsigned event_ind;
120 };
121 
122  } // namespace SBNOsc
123 } // namespace ana
125 
TFile * fOutputFile
The output ROOT file.
process_name opflashCryoW ana
std::vector< ADC_Count_t > & Waveform()
process_name plot
bool ProcessEvent(const gallery::Event &ev, const std::vector< event::Interaction > &truth, std::vector< event::RecoInteraction > &reco)
Electron neutrino event selection.
process_name standard_reco_uboone reco
std::vector< PlotDef > plots
Definition: demo.h:54
#define DECLARE_SBN_PROCESSOR(classname)
Base class for event selections.
const detinfo::DetectorClocksStandard * GetDetectorClocksProvider() const
void Initialize(fhicl::ParameterSet *config=NULL)
std::string to_string(WindowPattern const &pattern)
ProviderManager * fProviderManager
Interface for provider access.
BEGIN_PROLOG could also be cout