Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions DAQ/src/MSDHitsFromDTCEvents_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ void art::MSDHitsFromDTCEvents::produce(Event& event) {
for (size_t blockIndex = 0; blockIndex < decoder.block_count(); blockIndex++) {
mu2e::MobileSyncDataDecoder::sync_data_t dataPacketsVec =
decoder.GetMobileSyncPackets(blockIndex);
// get channel ID of data block
const int rocLinkID =
static_cast<int>(dtcSubEvent.GetDataBlock(blockIndex)->GetHeader()->GetLinkID());
// get number of hits in packet
const unsigned nHitsInPacket = decoder.GetNHitsPerPacket();
if (_debugLevel > 4) {
Expand All @@ -117,13 +120,15 @@ void art::MSDHitsFromDTCEvents::produce(Event& event) {
mu2e::MSDHit msdHit;
if (decoder.GetHitTime(&packet, hit, hitTime)) {
msdHit.setTime(hitTime);
msdHit.setChannelID(rocLinkID);
if (decoder.GetHitTOT(&packet, hit, hitTOT)) {
msdHit.setTOT(hitTOT);
}
msd_hits->emplace_back(msdHit);
if (_debugLevel > 0) {
std::cout << "Hit " << hit << " in packet: time = " << msdHit.time()
<< " ns, TOT = " << msdHit.tot() << " ns" << std::endl;
std::cout << "Hit " << hit << " in packet: channel ID = " << msdHit.channelID()
<< " time = " << msdHit.time() << " ns, TOT = " << msdHit.tot()
<< " ns" << std::endl;
}
}
}
Expand Down Expand Up @@ -193,4 +198,3 @@ artdaq::Fragments art::MSDHitsFromDTCEvents::getFragments(art::Event& event) {
DEFINE_ART_MODULE(art::MSDHitsFromDTCEvents)

// ======================================================================

3 changes: 3 additions & 0 deletions RecoDataProducts/inc/MSDHit.hh
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ public:
// setters
void setTime(double time) { _time = time; }
void setTOT(double tot) { _tot = tot; }
void setChannelID(int id) { _channelID = id; }

// accessors
double time() const { return _time; }
double tot() const { return _tot; }
int channelID() const { return _channelID; }

// check if field is present in payload
bool hasTime() const { return _time >= 0; }
Expand All @@ -26,6 +28,7 @@ private:
// data members
double _time{-1.0}; // time of hit
double _tot{-1.0}; // time-over-threshold
int _channelID{-1}; // channel ID
};

typedef std::vector<mu2e::MSDHit> MSDHitCollection;
Expand Down
7 changes: 7 additions & 0 deletions Trigger/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,11 @@ cet_build_plugin(TriggerInfoToCollections art::module
Offline::RecoDataProducts
)

cet_build_plugin(MSDHitFilter art::module
REG_SOURCE src/MSDHitFilter_module.cc
LIBRARIES REG
Offline::RecoDataProducts
TRACE::MF
)

install_source(SUBDIRS src)
100 changes: 100 additions & 0 deletions Trigger/src/MSDHitFilter_module.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
//
// Filter for mobile sync detector hits
// Michael MacKenzie, 2026
//

// Framework
#include "art/Framework/Core/EDFilter.h"
#include "art/Framework/Principal/Event.h"
#include "art/Framework/Principal/Handle.h"
#include "fhiclcpp/ParameterSet.h"

// Offline
#include "Offline/RecoDataProducts/inc/MSDHit.hh"

// C++
#include <string>

// TRACE
#include "TRACE/tracemf.h"
#define TRACE_NAME "MSDHitFilter"

namespace mu2e {
class MSDHitFilter : public art::EDFilter {
public:

// Main configuration
struct Config {
using Name = fhicl::Name;
using Comment = fhicl::Comment;
fhicl::Atom<std::string> tag {Name("tag") , Comment("Collection tag")};
fhicl::Atom<int> minHits{Name("minHits"), Comment("Minimum number of hits")};
};

using Parameters = art::EDFilter::Table<Config>;

explicit MSDHitFilter(const Parameters& config);


private:
bool filter (art::Event& event) override;
bool endRun (art::Run& run ) override;
bool goodHit (const MSDHit& hit);

// Inputs
std::string _tag;
int _minHits = -1;

// Data
unsigned long _nevt, _npass;

};

//-----------------------------------------------------------------------------
MSDHitFilter::MSDHitFilter(const Parameters& conf)
: art::EDFilter{conf}
, _tag(conf().tag())
, _minHits(conf().minHits())
, _nevt(0)
, _npass(0)
{
}

//-----------------------------------------------------------------------------
// Check if the hit is accepted
bool MSDHitFilter::goodHit(const MSDHit& hit) {
if(!hit.hasTime()) return false; // time must be defined for the hit
return true;
}

//-----------------------------------------------------------------------------
bool MSDHitFilter::filter(art::Event& event) {

// Count total events seen
++_nevt;

// Filter flag
bool passed = true;

auto handle = event.getValidHandle<MSDHitCollection>(_tag);
const auto hits = handle.product();
int naccepted = 0;
for(const auto& hit : *hits) if(goodHit(hit)) ++naccepted;

passed &= naccepted >= _minHits;

// Return the result
return passed;
}

//-----------------------------------------------------------------------------
bool MSDHitFilter::endRun(art::Run& run) {
// Print a summary of the filter results
const float rate = (_nevt > 0) ? float(_npass)/float(_nevt) : 0.f;
TLOG(TLVL_DEBUG + 2) << "passed " << _npass << " events out of " << _nevt << " for a ratio of " << rate;
_nevt = 0; _npass = 0; // reset for the next run
return true;
}
}

DEFINE_ART_MODULE(mu2e::MSDHitFilter)