WaveformPDSAndTruthDump_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: WaveformPDSAndTruthDump
3 // Plugin Type: producer (art v2_10_03)
4 // File: WaveformPDSAndTruthDump_module.cc
5 ////////////////////////////////////////////////////////////////////////
6 
15 #include "fhiclcpp/ParameterSet.h"
23 #include <memory>
24 #include <fstream>
25 
27 
28 
30 public:
32  // The compiler-generated destructor is fine for non-base
33  // classes without bare pointers or other resource use.
34 
35  // Plugins should not be copied or assigned.
40 
41  // Required functions.
42  void analyze(art::Event const& e) override;
43 
44 private:
45  // The module name of the raw digits we're reading in
50  std::ofstream m_outputFile_pds ;
51  std::ofstream m_outputFile_true_pds;
52 };
53 
54 
56  : EDAnalyzer(p),
57  m_inputTagGEANT (p.get<std::string>("InputTagGEANT" , "largeant")),
58  m_inputTagPDS (p.get<std::string>("InputTagPDS" , "opdigi" )),
59  m_outputFilename_pds (p.get<std::string>("OutputFilePDS" ,"OutputFilePDS.txt" )),
60  m_outputFilename_true_pds(p.get<std::string>("OutputFileTruePDS","OutputFileTruePDS.txt")),
63 {
64 }
65 
67 {
69  auto const& digits_handle_pds=e.getValidHandle<std::vector<raw::OpDetWaveform>>(m_inputTagPDS);
70  std::map<int, std::pair<int, int>> channel_timestamp;
71 
72  auto& digits_pds_in = *digits_handle_pds;
73  for (auto&& digit: digits_pds_in) {
74  m_outputFile_pds << e.event() << " "
75  << digit.ChannelNumber() << " ";
76 
77  auto f = channel_timestamp.find(digit.ChannelNumber());
78  if (f == channel_timestamp.end()) {
79  channel_timestamp[digit.ChannelNumber()] = std::make_pair(digit.TimeStamp(), digit.size());
80  } else {
81  int begin_old = f->second.first;
82  int begin_new = digit.TimeStamp();
83  begin_new = (begin_old > begin_new) ? begin_new : begin_old;
84  int end_old = f->second.first+f->second.second;
85  int end_new = digit.TimeStamp()+digit.size();
86  end_new = (end_old > end_new) ? end_old : end_new;
87  f->second.first = begin_new;
88  f->second.second = end_new - begin_new;
89  }
90  for(auto const& adc: digit) {
91  m_outputFile_pds << adc << " ";
92  }
93 
94  m_outputFile_pds << "\n";
95  }
96 
97  // PDS truth
98  auto const& truth_handle_pds=e.getValidHandle<std::vector<sim::OpDetBacktrackerRecord>>(m_inputTagGEANT);
99  auto& truth_pds_in =*truth_handle_pds;
100 
101  for (auto const& interesting: channel_timestamp) {
102  int channel = interesting.first;
103  int timestamp = interesting.second.first;
104  int nticks = interesting.second.second;
105  bool found = false;
106  for (auto&& truth: truth_pds_in) {
107  if (truth.OpDetNum() != channel) continue;
108  m_outputFile_true_pds << e.event() << " "
109  << truth.OpDetNum() << " ";
110  for(int ichge=timestamp; ichge<nticks+timestamp; ++ichge){
111  m_outputFile_true_pds << truth.Photons(ichge) << " ";
112  }
113  m_outputFile_true_pds << "\n";
114  found=true;
115  break;
116  }
117  if (!found) {
118  std::cout << "didn't find this channel " << channel
119  << " timestamp " << timestamp
120  << " ticks " << nticks <<" in truth\n";
121  }
122  }
123 }
124 
125 
EventNumber_t event() const
Definition: DataViewImpl.cc:85
WaveformPDSAndTruthDump(fhicl::ParameterSet const &p)
std::string string
Definition: nybbler.cc:12
int16_t adc
Definition: CRTFragment.hh:202
STL namespace.
uint8_t channel
Definition: CRTFragment.hh:201
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
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
p
Definition: test.py:223
void analyze(art::Event const &e) override
Declaration of signal hit object.
WaveformPDSAndTruthDump & operator=(WaveformPDSAndTruthDump const &)=delete
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
LArSoft geometry interface.
Definition: ChannelGeo.h:16