Skip to content

Commit 9a7dc9d

Browse files
Merge pull request #628 from SBNSoftware/feature/lynnt_pmtmetricsana
PMT (Beam) Metrics Analyzer: Allow stream labels
2 parents 136389f + 34adfcb commit 9a7dc9d

3 files changed

Lines changed: 75 additions & 22 deletions

File tree

sbndcode/Trigger/MetricAnalyzer_module.cc

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,15 @@ class sbndaq::MetricAnalyzer : public art::EDAnalyzer {
4646

4747
private:
4848
std::string fmetric_instance_name;
49-
std::string fmetric_module_label;
49+
std::vector<std::string> fmetric_module_labels;
50+
std::vector<int> fstream_labels;
5051

5152
std::string fspectdc_module_label;
5253
uint32_t fspectdc_etrig_ch;
5354

5455
TTree* tree;
5556
int _run, _subrun, _event;
57+
int _stream;
5658
float _flash_peakpe;
5759
float _flash_peaktime; // us
5860
float _trigger_dt; // us
@@ -66,7 +68,13 @@ sbndaq::MetricAnalyzer::MetricAnalyzer(fhicl::ParameterSet const& p)
6668
: EDAnalyzer{p} // ,
6769
// More initializers here.
6870
{
69-
fmetric_module_label = p.get<std::string>("metric_module_label","pmtmetricproducer");
71+
fmetric_module_labels = p.get<std::vector<std::string>>("metric_module_labels",{"pmtmetricproducer",
72+
"pmtmetricbnbzero",
73+
"pmtmetricbnblight",
74+
"pmtmetricoffbeamzero",
75+
"pmtmetricoffbeamlight",
76+
"pmtmetriccrossingsmuon"});
77+
fstream_labels = p.get<std::vector<int>>("stream_labels",{0,1,2,3,4,5});
7078
fmetric_instance_name = p.get<std::string>("metric_instance_name","");
7179
fspectdc_module_label = p.get<std::string>("spectdc_module_name","tdcdecoder");
7280
fspectdc_etrig_ch = p.get<uint32_t>("spectdc_etrig_ch",4);
@@ -76,6 +84,7 @@ sbndaq::MetricAnalyzer::MetricAnalyzer(fhicl::ParameterSet const& p)
7684
tree->Branch("run",&_run,"run/I");
7785
tree->Branch("subrun",&_subrun,"subrun/I");
7886
tree->Branch("event",&_event,"event/I");
87+
tree->Branch("stream",&_stream,"stream/I");
7988
tree->Branch("flash_peakpe",&_flash_peakpe,"flash_peakpe/F");
8089
tree->Branch("flash_peaktime",&_flash_peaktime,"flash_peaktime/F");
8190
tree->Branch("trigger_dt",&_trigger_dt,"trigger_dt/F");
@@ -91,27 +100,47 @@ void sbndaq::MetricAnalyzer::analyze(art::Event const& e)
91100
_event = e.id().event();
92101

93102
// initialize tree variables
103+
_stream = -1;
94104
_flash_peakpe = -999999999;
95105
_flash_peaktime = -999999999;
96106
_trigger_dt = -999999999;
97107
_timing_type = -1;
98108
_tdc_etrig = -999999999;
99109
_tdc_bes = -999999999;
100110

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();
111+
if (fstream_labels.size() != fmetric_module_labels.size()){
112+
std::cout << "Error: stream labels and metric module labels are not the same size" << std::endl;
107113
return;
108114
}
109-
else{
115+
116+
bool found_metrics = false;
117+
118+
size_t nlabels = fmetric_module_labels.size();
119+
for (size_t i=0; i<nlabels; i++){
120+
auto label = fmetric_module_labels[i];
121+
122+
art::Handle<std::vector<sbnd::trigger::pmtSoftwareTrigger>> metricHandle;
123+
if (fmetric_instance_name.empty()){
124+
e.getByLabel(label,metricHandle);
125+
}
126+
else{
127+
e.getByLabel(label,fmetric_instance_name,metricHandle);
128+
}
129+
130+
if (!metricHandle.isValid() || metricHandle->size() == 0)
131+
continue;
132+
found_metrics = true;
110133
const std::vector<sbnd::trigger::pmtSoftwareTrigger> metric_v(*metricHandle);
111134
auto metric = metric_v[0];
112135
_trigger_dt = float(metric.trig_ts)/1e3;
113136
_flash_peakpe = metric.peakPE;
114137
_flash_peaktime = metric.peaktime;
138+
_stream = fstream_labels[i];
139+
}
140+
if (!found_metrics){
141+
std::cout << "No Metrics found" << std::endl;
142+
tree->Fill();
143+
return;
115144
}
116145

117146
// see if etrig exists

sbndcode/Trigger/MetricFilter_module.cc

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class sbndaq::MetricFilter : public art::EDFilter {
4343

4444
private:
4545
std::string fmetric_instance_name;
46-
std::string fmetric_module_label;
46+
std::vector<std::string> fmetric_module_labels;
4747

4848
float ftime_min; // us
4949
float ftime_max; // us
@@ -58,7 +58,12 @@ sbndaq::MetricFilter::MetricFilter(fhicl::ParameterSet const& p)
5858
: EDFilter{p} // ,
5959
// More initializers here.
6060
{
61-
fmetric_module_label = p.get<std::string>("metric_module_label","pmtmetricproducer");
61+
fmetric_module_labels = p.get<std::vector<std::string>>("metric_module_labels",{"pmtmetricproducer",
62+
"pmtmetricbnbzero",
63+
"pmtmetricbnblight",
64+
"pmtmetricoffbeamzero",
65+
"pmtmetricoffbeamlight",
66+
"pmtmetriccrossingmuon"});
6267
fmetric_instance_name = p.get<std::string>("metric_instance_name","");
6368
ftime_min = p.get<float>("time_min",0);
6469
ftime_max = p.get<float>("time_max",3);
@@ -67,24 +72,38 @@ sbndaq::MetricFilter::MetricFilter(fhicl::ParameterSet const& p)
6772

6873
bool sbndaq::MetricFilter::filter(art::Event& e)
6974
{
70-
// Implementation of required member function here.
71-
art::Handle<std::vector<sbnd::trigger::pmtSoftwareTrigger>> metricHandle;
72-
if (fmetric_instance_name.empty()) e.getByLabel(fmetric_module_label,metricHandle);
73-
else e.getByLabel(fmetric_module_label,fmetric_instance_name,metricHandle);
74-
if (!metricHandle.isValid() || metricHandle->size() == 0){
75-
return false;
76-
}
77-
else{
75+
bool pass = false;
76+
77+
bool found_metrics = false;
78+
size_t nlabels = fmetric_module_labels.size();
79+
for (size_t i=0; i<nlabels; i++){
80+
auto label = fmetric_module_labels[i];
81+
82+
art::Handle<std::vector<sbnd::trigger::pmtSoftwareTrigger>> metricHandle;
83+
if (fmetric_instance_name.empty()){
84+
e.getByLabel(label,metricHandle);
85+
}
86+
else{
87+
e.getByLabel(label,fmetric_instance_name,metricHandle);
88+
}
89+
90+
if (!metricHandle.isValid() || metricHandle->size() == 0)
91+
continue;
92+
found_metrics = true;
7893
const std::vector<sbnd::trigger::pmtSoftwareTrigger> metric_v(*metricHandle);
7994
auto metric = metric_v[0];
8095
auto flash_peakpe = metric.peakPE;
8196
auto flash_peaktime = metric.peaktime; // us
8297

8398
bool pass_timing = (flash_peaktime > ftime_min) && (flash_peaktime < ftime_max);
8499
bool pass_pe = flash_peakpe > fpe_thresh;
85-
return pass_timing && pass_pe;
100+
pass = (pass_timing && pass_pe);
86101
}
87-
102+
if (!found_metrics){
103+
std::cout << "No Metrics found" << std::endl;
104+
pass=false;
105+
}
106+
return pass;
88107
}
89108

90109
DEFINE_ART_MODULE(sbndaq::MetricFilter)

sbndcode/Trigger/metricfilter.fcl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ BEGIN_PROLOG
33
metricfilter_sbnd:
44
{
55
module_type: "MetricFilter"
6-
metric_module_label: "pmtmetricproducer"
6+
metric_module_labels: ["pmtmetricproducer",
7+
"pmtmetricbnbzero",
8+
"pmtmetricbnblight",
9+
"pmtmetricoffbeamzero",
10+
"pmtmetricoffbeamlight",
11+
"pmtmetriccrossingmuon"]
712
time_min: 0
813
time_max: 3
914
pe_thresh: 50

0 commit comments

Comments
 (0)