Skip to content

Commit 71b5f93

Browse files
authored
Merge pull request #28 from Mu2e/pgirotti/EventFilter
Added filter module to select events with at least 1 hit
2 parents 086d29a + 04fe52e commit 71b5f93

File tree

2 files changed

+127
-0
lines changed

2 files changed

+127
-0
lines changed

otsdaq-mu2e-calorimeter/ArtModules/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ cet_build_plugin(CaloiercAnalyzer art::module
4141
ROOT::Gui
4242
)
4343

44+
cet_build_plugin(CaloEventFilter art::module
45+
REG_SOURCE CaloEventFilter_module.cc
46+
LIBRARIES REG
47+
artdaq_core_mu2e::artdaq-core-mu2e_Data
48+
artdaq_core_mu2e::artdaq-core-mu2e_Data_dict
49+
artdaq_core_mu2e::artdaq-core-mu2e_Overlays
50+
artdaq::DAQdata
51+
)
52+
53+
4454

4555
install_headers()
4656
install_source()
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#include "art/Framework/Core/EDFilter.h"
2+
#include "art/Framework/Core/ModuleMacros.h"
3+
#include "art/Framework/Principal/Event.h"
4+
// #include "art/Framework/Services/Registry/ServiceHandle.h"
5+
#include "art/Framework/Principal/Handle.h"
6+
#include "art/Framework/Principal/Run.h"
7+
#include "messagefacility/MessageLogger/MessageLogger.h"
8+
9+
#include "TRACE/tracemf.h"
10+
#include "artdaq/DAQdata/Globals.hh"
11+
#define TRACE_NAME "CaloEventFilter"
12+
13+
#include "canvas/Utilities/Exception.h"
14+
#include "canvas/Utilities/InputTag.h"
15+
16+
#include <artdaq-core/Data/ContainerFragment.hh>
17+
#include "artdaq-core/Data/Fragment.hh"
18+
19+
#include "artdaq-core-mu2e/Data/CalorimeterDataDecoder.hh"
20+
#include "artdaq-core-mu2e/Data/EventHeader.hh"
21+
#include "artdaq-core-mu2e/Overlays/DTCEventFragment.hh"
22+
#include "artdaq-core-mu2e/Overlays/FragmentType.hh"
23+
24+
#include "cetlib_except/exception.h"
25+
26+
#include <iomanip>
27+
#include <sstream>
28+
#include <vector>
29+
30+
namespace mu2e {
31+
class CaloEventFilter : public art::EDFilter {
32+
public:
33+
// clang-format off
34+
struct Config {
35+
fhicl::Atom<std::string> subsystem_override {fhicl::Name("subsystemOverride" ) , fhicl::Comment("Override calo subsystem [\"calo\", \"tracker\"]"), "calo"};
36+
};
37+
// clang-format on
38+
39+
explicit CaloEventFilter(const art::EDFilter::Table<Config>& config);
40+
bool filter(art::Event& event) override;
41+
42+
artdaq::Fragments getFragments(art::Event& event);
43+
44+
private:
45+
DTCLib::DTC_Subsystem subsystem_;
46+
};
47+
} // namespace mu2e
48+
49+
mu2e::CaloEventFilter::CaloEventFilter(const art::EDFilter::Table<Config>& config)
50+
: art::EDFilter{config} {
51+
if(config().subsystem_override() == "calo") {
52+
subsystem_ = DTCLib::DTC_Subsystem::DTC_Subsystem_Calorimeter;
53+
} else if(config().subsystem_override() == "tracker") {
54+
subsystem_ = DTCLib::DTC_Subsystem::DTC_Subsystem_Tracker;
55+
}
56+
}
57+
58+
bool mu2e::CaloEventFilter::filter(art::Event& event) {
59+
artdaq::Fragments fragments = getFragments(event);
60+
for(const auto& frag : fragments) {
61+
mu2e::DTCEventFragment eventFragment(frag);
62+
const auto& caloSubEvents = eventFragment.getSubsystemData(subsystem_);
63+
// Loop over calo DTCs
64+
for(const auto& subevent : caloSubEvents) {
65+
// Loop over ROCs
66+
for(const auto& dataBlock : subevent.GetDataBlocks()) {
67+
int nPackets = dataBlock.GetHeader()->GetPacketCount();
68+
if(nPackets > 0) {
69+
// We have data!
70+
return true;
71+
}
72+
}
73+
}
74+
}
75+
76+
// Didn't find anything
77+
return false;
78+
}
79+
80+
artdaq::Fragments mu2e::CaloEventFilter::getFragments(art::Event& event) {
81+
artdaq::Fragments fragments;
82+
artdaq::FragmentPtrs containerFragments;
83+
84+
std::vector<art::Handle<artdaq::Fragments>> fragmentHandles;
85+
fragmentHandles = event.getMany<std::vector<artdaq::Fragment>>();
86+
87+
TLOG(TLVL_DEBUG + 6) << "Iterating through " << fragmentHandles.size()
88+
<< " fragment handles\n";
89+
for(const auto& handle : fragmentHandles) {
90+
if(!handle.isValid() || handle->empty()) {
91+
continue;
92+
}
93+
94+
if(handle->front().type() == artdaq::Fragment::ContainerFragmentType) {
95+
for(const auto& cont : *handle) {
96+
artdaq::ContainerFragment contf(cont);
97+
if(contf.fragment_type() != mu2e::FragmentType::DTCEVT) {
98+
break;
99+
}
100+
101+
for(size_t ii = 0; ii < contf.block_count(); ++ii) {
102+
containerFragments.push_back(contf[ii]);
103+
fragments.push_back(*containerFragments.back());
104+
}
105+
}
106+
} else {
107+
if(handle->front().type() == mu2e::FragmentType::DTCEVT) {
108+
for(auto frag : *handle) {
109+
fragments.emplace_back(frag);
110+
}
111+
}
112+
}
113+
}
114+
return fragments;
115+
}
116+
117+
DEFINE_ART_MODULE(mu2e::CaloEventFilter)

0 commit comments

Comments
 (0)