|
| 1 | +//////////////////////////////////////////////////////////////////////// |
| 2 | +// Class: MetricAnalyzer |
| 3 | +// Plugin Type: analyzer (Unknown Unknown) |
| 4 | +// File: MetricAnalyzer_module.cc |
| 5 | +// |
| 6 | +// Generated at Fri Nov 22 12:06:48 2024 by Lynn Tung using cetskelgen |
| 7 | +// from cetlib version 3.18.02. |
| 8 | +//////////////////////////////////////////////////////////////////////// |
| 9 | + |
| 10 | +#include "art/Framework/Core/EDAnalyzer.h" |
| 11 | +#include "art/Framework/Core/ModuleMacros.h" |
| 12 | +#include "art/Framework/Principal/Event.h" |
| 13 | +#include "art/Framework/Principal/Handle.h" |
| 14 | +#include "art/Framework/Principal/Run.h" |
| 15 | +#include "art/Framework/Principal/SubRun.h" |
| 16 | +#include "canvas/Utilities/InputTag.h" |
| 17 | +#include "fhiclcpp/ParameterSet.h" |
| 18 | +#include "messagefacility/MessageLogger/MessageLogger.h" |
| 19 | + |
| 20 | +#include "sbndaq-artdaq-core/Obj/SBND/pmtSoftwareTrigger.hh" |
| 21 | +#include "sbnobj/SBND/Timing/DAQTimestamp.hh" |
| 22 | + |
| 23 | +#include "art_root_io/TFileService.h" |
| 24 | +#include "TFile.h" |
| 25 | +#include "TTree.h" |
| 26 | + |
| 27 | +namespace sbndaq { |
| 28 | + class MetricAnalyzer; |
| 29 | +} |
| 30 | + |
| 31 | + |
| 32 | +class sbndaq::MetricAnalyzer : public art::EDAnalyzer { |
| 33 | +public: |
| 34 | + explicit MetricAnalyzer(fhicl::ParameterSet const& p); |
| 35 | + // The compiler-generated destructor is fine for non-base |
| 36 | + // classes without bare pointers or other resource use. |
| 37 | + |
| 38 | + // Plugins should not be copied or assigned. |
| 39 | + MetricAnalyzer(MetricAnalyzer const&) = delete; |
| 40 | + MetricAnalyzer(MetricAnalyzer&&) = delete; |
| 41 | + MetricAnalyzer& operator=(MetricAnalyzer const&) = delete; |
| 42 | + MetricAnalyzer& operator=(MetricAnalyzer&&) = delete; |
| 43 | + |
| 44 | + // Required functions. |
| 45 | + void analyze(art::Event const& e) override; |
| 46 | + |
| 47 | +private: |
| 48 | + std::string fmetric_instance_name; |
| 49 | + std::string fmetric_module_label; |
| 50 | + |
| 51 | + std::string fspectdc_module_label; |
| 52 | + uint32_t fspectdc_etrig_ch; |
| 53 | + |
| 54 | + TTree* tree; |
| 55 | + int _run, _subrun, _event; |
| 56 | + float _flash_peakpe; |
| 57 | + float _flash_peaktime; // us |
| 58 | + float _trigger_dt; // us |
| 59 | + int _timing_type; |
| 60 | + int _tdc_etrig; |
| 61 | + int _tdc_bes; |
| 62 | +}; |
| 63 | + |
| 64 | + |
| 65 | +sbndaq::MetricAnalyzer::MetricAnalyzer(fhicl::ParameterSet const& p) |
| 66 | + : EDAnalyzer{p} // , |
| 67 | + // More initializers here. |
| 68 | +{ |
| 69 | + fmetric_module_label = p.get<std::string>("metric_module_label","pmtmetricproducer"); |
| 70 | + fmetric_instance_name = p.get<std::string>("metric_instance_name",""); |
| 71 | + fspectdc_module_label = p.get<std::string>("spectdc_module_name","tdcdecoder"); |
| 72 | + fspectdc_etrig_ch = p.get<uint32_t>("spectdc_etrig_ch",4); |
| 73 | + |
| 74 | + art::ServiceHandle<art::TFileService> fs; |
| 75 | + tree = fs->make<TTree>("tree","metrictree"); |
| 76 | + tree->Branch("run",&_run,"run/I"); |
| 77 | + tree->Branch("subrun",&_subrun,"subrun/I"); |
| 78 | + tree->Branch("event",&_event,"event/I"); |
| 79 | + tree->Branch("flash_peakpe",&_flash_peakpe,"flash_peakpe/F"); |
| 80 | + tree->Branch("flash_peaktime",&_flash_peaktime,"flash_peaktime/F"); |
| 81 | + tree->Branch("trigger_dt",&_trigger_dt,"trigger_dt/F"); |
| 82 | + tree->Branch("timing_type",&_timing_type,"timing_type/I"); |
| 83 | + tree->Branch("tdc_etrig",&_tdc_etrig,"tdc_etrig/I"); |
| 84 | + tree->Branch("tdc_bes",&_tdc_bes,"tdc_bes/I"); |
| 85 | +} |
| 86 | + |
| 87 | +void sbndaq::MetricAnalyzer::analyze(art::Event const& e) |
| 88 | +{ |
| 89 | + _run = e.id().run(); |
| 90 | + _subrun = e.id().subRun(); |
| 91 | + _event = e.id().event(); |
| 92 | + |
| 93 | + // initialize tree variables |
| 94 | + _flash_peakpe = -999999999; |
| 95 | + _flash_peaktime = -999999999; |
| 96 | + _trigger_dt = -999999999; |
| 97 | + _timing_type = -1; |
| 98 | + _tdc_etrig = -999999999; |
| 99 | + _tdc_bes = -999999999; |
| 100 | + |
| 101 | + art::Handle<std::vector<sbnd::trigger::pmtSoftwareTrigger>> metricHandle; |
| 102 | + if (fmetric_instance_name.empty()) e.getByLabel(fmetric_module_label,metricHandle); |
| 103 | + else e.getByLabel(fmetric_module_label,fmetric_instance_name,metricHandle); |
| 104 | + if (!metricHandle.isValid() || metricHandle->size() == 0){ |
| 105 | + std::cout << "No Metrics found" << std::endl; |
| 106 | + tree->Fill(); |
| 107 | + return; |
| 108 | + } |
| 109 | + else{ |
| 110 | + const std::vector<sbnd::trigger::pmtSoftwareTrigger> metric_v(*metricHandle); |
| 111 | + auto metric = metric_v[0]; |
| 112 | + _trigger_dt = float(metric.trig_ts)/1e3; |
| 113 | + _flash_peakpe = metric.peakPE; |
| 114 | + _flash_peaktime = metric.peaktime; |
| 115 | + } |
| 116 | + |
| 117 | + // see if etrig exists |
| 118 | + art::Handle<std::vector<sbnd::timing::DAQTimestamp>> tdcHandle; |
| 119 | + e.getByLabel(fspectdc_module_label,tdcHandle); |
| 120 | + bool found_ett = false; |
| 121 | + |
| 122 | + if (!tdcHandle.isValid() || tdcHandle->size() == 0) |
| 123 | + std::cout << "No SPECTDC products found." << std::endl; |
| 124 | + else{ |
| 125 | + const std::vector<sbnd::timing::DAQTimestamp> tdc_v(*tdcHandle); |
| 126 | + for (size_t i=0; i<tdc_v.size(); i++){ |
| 127 | + auto tdc = tdc_v[i]; |
| 128 | + const uint32_t ch = tdc.Channel(); |
| 129 | + if (ch==fspectdc_etrig_ch) found_ett = true; |
| 130 | + if (ch==fspectdc_etrig_ch) _tdc_etrig = tdc.Timestamp()%uint64_t(1e9); |
| 131 | + if (ch==1) _tdc_bes = tdc.Timestamp()%uint64_t(1e9); |
| 132 | + } |
| 133 | + } |
| 134 | + if (found_ett) _timing_type = 0; |
| 135 | + else _timing_type = 1; |
| 136 | + |
| 137 | + tree->Fill(); |
| 138 | +} |
| 139 | + |
| 140 | +DEFINE_ART_MODULE(sbndaq::MetricAnalyzer) |
0 commit comments