Skip to content

Commit 650ced2

Browse files
authored
Merge pull request #1871 from matthewstortini/stortini/msd-updates
Stortini/msd updates
2 parents 915b109 + 170a089 commit 650ced2

4 files changed

Lines changed: 119 additions & 3 deletions

File tree

DAQ/src/MSDHitsFromDTCEvents_module.cc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ void art::MSDHitsFromDTCEvents::produce(Event& event) {
102102
for (size_t blockIndex = 0; blockIndex < decoder.block_count(); blockIndex++) {
103103
mu2e::MobileSyncDataDecoder::sync_data_t dataPacketsVec =
104104
decoder.GetMobileSyncPackets(blockIndex);
105+
// get channel ID of data block
106+
const int rocLinkID =
107+
static_cast<int>(dtcSubEvent.GetDataBlock(blockIndex)->GetHeader()->GetLinkID());
105108
// get number of hits in packet
106109
const unsigned nHitsInPacket = decoder.GetNHitsPerPacket();
107110
if (_debugLevel > 4) {
@@ -117,13 +120,15 @@ void art::MSDHitsFromDTCEvents::produce(Event& event) {
117120
mu2e::MSDHit msdHit;
118121
if (decoder.GetHitTime(&packet, hit, hitTime)) {
119122
msdHit.setTime(hitTime);
123+
msdHit.setChannelID(rocLinkID);
120124
if (decoder.GetHitTOT(&packet, hit, hitTOT)) {
121125
msdHit.setTOT(hitTOT);
122126
}
123127
msd_hits->emplace_back(msdHit);
124128
if (_debugLevel > 0) {
125-
std::cout << "Hit " << hit << " in packet: time = " << msdHit.time()
126-
<< " ns, TOT = " << msdHit.tot() << " ns" << std::endl;
129+
std::cout << "Hit " << hit << " in packet: channel ID = " << msdHit.channelID()
130+
<< " time = " << msdHit.time() << " ns, TOT = " << msdHit.tot()
131+
<< " ns" << std::endl;
127132
}
128133
}
129134
}
@@ -193,4 +198,3 @@ artdaq::Fragments art::MSDHitsFromDTCEvents::getFragments(art::Event& event) {
193198
DEFINE_ART_MODULE(art::MSDHitsFromDTCEvents)
194199

195200
// ======================================================================
196-

RecoDataProducts/inc/MSDHit.hh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ public:
1313
// setters
1414
void setTime(double time) { _time = time; }
1515
void setTOT(double tot) { _tot = tot; }
16+
void setChannelID(int id) { _channelID = id; }
1617

1718
// accessors
1819
double time() const { return _time; }
1920
double tot() const { return _tot; }
21+
int channelID() const { return _channelID; }
2022

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

3134
typedef std::vector<mu2e::MSDHit> MSDHitCollection;

Trigger/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,11 @@ cet_build_plugin(TriggerInfoToCollections art::module
5454
Offline::RecoDataProducts
5555
)
5656

57+
cet_build_plugin(MSDHitFilter art::module
58+
REG_SOURCE src/MSDHitFilter_module.cc
59+
LIBRARIES REG
60+
Offline::RecoDataProducts
61+
TRACE::MF
62+
)
63+
5764
install_source(SUBDIRS src)

Trigger/src/MSDHitFilter_module.cc

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
//
2+
// Filter for mobile sync detector hits
3+
// Michael MacKenzie, 2026
4+
//
5+
6+
// Framework
7+
#include "art/Framework/Core/EDFilter.h"
8+
#include "art/Framework/Principal/Event.h"
9+
#include "art/Framework/Principal/Handle.h"
10+
#include "fhiclcpp/ParameterSet.h"
11+
12+
// Offline
13+
#include "Offline/RecoDataProducts/inc/MSDHit.hh"
14+
15+
// C++
16+
#include <string>
17+
18+
// TRACE
19+
#include "TRACE/tracemf.h"
20+
#define TRACE_NAME "MSDHitFilter"
21+
22+
namespace mu2e {
23+
class MSDHitFilter : public art::EDFilter {
24+
public:
25+
26+
// Main configuration
27+
struct Config {
28+
using Name = fhicl::Name;
29+
using Comment = fhicl::Comment;
30+
fhicl::Atom<std::string> tag {Name("tag") , Comment("Collection tag")};
31+
fhicl::Atom<int> minHits{Name("minHits"), Comment("Minimum number of hits")};
32+
};
33+
34+
using Parameters = art::EDFilter::Table<Config>;
35+
36+
explicit MSDHitFilter(const Parameters& config);
37+
38+
39+
private:
40+
bool filter (art::Event& event) override;
41+
bool endRun (art::Run& run ) override;
42+
bool goodHit (const MSDHit& hit);
43+
44+
// Inputs
45+
std::string _tag;
46+
int _minHits = -1;
47+
48+
// Data
49+
unsigned long _nevt, _npass;
50+
51+
};
52+
53+
//-----------------------------------------------------------------------------
54+
MSDHitFilter::MSDHitFilter(const Parameters& conf)
55+
: art::EDFilter{conf}
56+
, _tag(conf().tag())
57+
, _minHits(conf().minHits())
58+
, _nevt(0)
59+
, _npass(0)
60+
{
61+
}
62+
63+
//-----------------------------------------------------------------------------
64+
// Check if the hit is accepted
65+
bool MSDHitFilter::goodHit(const MSDHit& hit) {
66+
if(!hit.hasTime()) return false; // time must be defined for the hit
67+
return true;
68+
}
69+
70+
//-----------------------------------------------------------------------------
71+
bool MSDHitFilter::filter(art::Event& event) {
72+
73+
// Count total events seen
74+
++_nevt;
75+
76+
// Filter flag
77+
bool passed = true;
78+
79+
auto handle = event.getValidHandle<MSDHitCollection>(_tag);
80+
const auto hits = handle.product();
81+
int naccepted = 0;
82+
for(const auto& hit : *hits) if(goodHit(hit)) ++naccepted;
83+
84+
passed &= naccepted >= _minHits;
85+
86+
if (passed) ++_npass;
87+
88+
// Return the result
89+
return passed;
90+
}
91+
92+
//-----------------------------------------------------------------------------
93+
bool MSDHitFilter::endRun(art::Run& run) {
94+
// Print a summary of the filter results
95+
const float rate = (_nevt > 0) ? float(_npass)/float(_nevt) : 0.f;
96+
TLOG(TLVL_DEBUG + 2) << "passed " << _npass << " events out of " << _nevt << " for a ratio of " << rate;
97+
_nevt = 0; _npass = 0; // reset for the next run
98+
return true;
99+
}
100+
}
101+
102+
DEFINE_ART_MODULE(mu2e::MSDHitFilter)

0 commit comments

Comments
 (0)