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
1 change: 1 addition & 0 deletions DAQ/fcl/prolog.fcl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ DAQ : {
minEDep : 0.0006 ## in MeV
debugMode : false
debugBits : [ "bit0:0" ]
mnidToSkip : [ ] ## by default all panels are good
fillHistograms : false
}
}
Expand Down
134 changes: 75 additions & 59 deletions DAQ/src/StrawDigisFromArtdaqFragments_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,11 @@ void mu2e::StrawDigisFromArtdaqFragments::print_(const std::string& Message, con
}

//-----------------------------------------------------------------------------
// HEX print of a fragment, the data has to be in 2-byte words
// HEX print of a fragment, the Mu2e data come in 2-byte words
//-----------------------------------------------------------------------------
void mu2e::StrawDigisFromArtdaqFragments::print_fragment(const artdaq::Fragment* Frag) {
ushort* buf = (ushort*) (Frag->dataBegin());
int nw = buf[0]/2;
int nw = Frag->dataSizeBytes()/2;
int loc = 0;

for (int i=0; i<nw; i++) {
Expand Down Expand Up @@ -293,7 +293,7 @@ void mu2e::StrawDigisFromArtdaqFragments::produce(art::Event& event) {
auto fragmentHandles = event.getMany<std::vector<artdaq::Fragment>>();

if (debugMode_ > 0) {
std::string msg = std::format("n(fragments):{}",fragmentHandles.size());
std::string msg = std::format("n_fragment_collections):{}",fragmentHandles.size());
print_(msg);
}

Expand All @@ -315,8 +315,13 @@ void mu2e::StrawDigisFromArtdaqFragments::produce(art::Event& event) {
// each artdaq fragment corresponds to a single DTC, or a plane
// loop over them
//-----------------------------------------------------------------------------
int nfrag = handle->size();
for (int ifrag=0; ifrag<nfrag; ifrag++) {
int n_fragments = handle->size();

if (debugMode_) {
print_(std::format("-- next fragment collection with n_fragments:{}",n_fragments));
}

for (int ifrag=0; ifrag<n_fragments; ifrag++) {
const artdaq::Fragment* frag = &handle->at(ifrag);

if (debugMode_ and (debugBit_[0] > 0)) {
Expand All @@ -325,7 +330,10 @@ void mu2e::StrawDigisFromArtdaqFragments::produce(art::Event& event) {
frag->typeString(),sizeof(DTCLib::DTC_SubEventHeader)));
print_fragment(frag);
}

//-----------------------------------------------------------------------------
// skip CFO fragment (type = 12)
//-----------------------------------------------------------------------------
if (frag->type() == mu2e::FragmentType::CFO) continue;
uint8_t* fdata = (uint8_t*) (frag->dataBegin());
if (not missingDTCHeaders_) {
//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -376,16 +384,36 @@ void mu2e::StrawDigisFromArtdaqFragments::produce(art::Event& event) {
// trust that but watch if it changes
// so far, any corruptions we saw were contained withing the ROC payload, and nhits
// was a reliable number
// 2026-03-20: don't store waveforms if only one packet per hit
//-----------------------------------------------------------------------------
mu2e::TrackerDataDecoder::TrackerDataPacket* h0;
h0 = (mu2e::TrackerDataDecoder::TrackerDataPacket*) (roc_data+packet_size);
//-----------------------------------------------------------------------------
// don't expect zero ADC packets, the error seen was that one of the ROCs just
// doesn't send the second packet at all... work under that assumption
//-----------------------------------------------------------------------------
if (h0->NumADCPackets == 0) {
print_(std::format("ERROR: dtc_id:{} link_id:{} N(ADC packets) = 0, skip ROC data",
dtc_id,(int) rdh->linkID));

roc_data += (rdh->packetCount+1)*packet_size;
continue;
}
nADCPackets_ = h0->NumADCPackets;
nSamples_ = 3+12*nADCPackets_;
np_per_hit_ = nADCPackets_+1;
}
uint32_t link_id = rdh->linkID;
nhits = rdh->packetCount/(nADCPackets_+1);

//-----------------------------------------------------------------------------
// there should not be more than 255 hits per ROC, if nhits>=255 it is a corruption,
// stop processing of the event
//-----------------------------------------------------------------------------
if (nhits > 255) {
print_(std::format("ERROR: nhits:{}, skip event",nhits));
break;
}

const TrkPanelMap::Row* tpm(nullptr);
if (not keyOnMnid_) {
tpm = _trackerPanelMap->panel_map_by_online_ind(dtc_id,link_id);
Expand Down Expand Up @@ -413,6 +441,11 @@ void mu2e::StrawDigisFromArtdaqFragments::produce(art::Event& event) {

int offset = (ihit*np_per_hit_+1)*packet_size; // in bytes
hit_data = (mu2e::TrackerDataDecoder::TrackerDataPacket*) (roc_data+offset);
if (roc_data+offset >= last_address) {
print_(std::format("ERROR: dtc_id:{} link_id:{} roc_data:{} offset:{} last_address:{} , SKIPPING",
dtc_id, link_id, (void*) roc_data, offset, (void*) last_address));
break;
}
//-----------------------------------------------------------------------------
// at this point, check consistency between the channel_id, dtc_id and link_id for a given run
// panel ID is a derivative of the DTC ID and the link iD
Expand All @@ -422,9 +455,9 @@ void mu2e::StrawDigisFromArtdaqFragments::produce(art::Event& event) {
uint16_t channel = static_cast<uint16_t>(hit_data->StrawIndex);
uint16_t chid = mu2e::StrawId(channel).straw(); // channel ID within the panel

if (chid > StrawId::_nstraws) {
print_(std::format("ERROR: hit with corrupted chid:{:04x} : straw:{} / dtc_id:{} link_id:{}, SKIPPING",
hit_data->StrawIndex, chid, dtc_id, link_id));
if (chid >= StrawId::_nstraws) {
if (debugBit_[52] == 0) print_(std::format("ERROR: hit with corrupted chid:{:04x} : straw:{} / dtc_id:{} link_id:{}, SKIPPING",
hit_data->StrawIndex, chid, dtc_id, link_id));
continue;
}

Expand All @@ -436,7 +469,7 @@ void mu2e::StrawDigisFromArtdaqFragments::produce(art::Event& event) {
//-----------------------------------------------------------------------------
// bad mnid. Likely, corrupted data block. For now, skip the hit data and proceed with the next hit
//-----------------------------------------------------------------------------
print_(std::format("ERROR: corrupted mnid:{}, skip hit data",mnid));
if (debugBit_[51] == 0) print_(std::format("ERROR: corrupted mnid:{}, skip hit data",mnid));
continue;
}
}
Expand All @@ -450,28 +483,6 @@ void mu2e::StrawDigisFromArtdaqFragments::produce(art::Event& event) {
//-----------------------------------------------------------------------------
digi_flag = mu2e::StrawDigiFlag::corrupted;
}
// uint16_t panel_id;
// if (0 < minnesota_map_.count(mnid)){
// panel_id = minnesota_map_[mnid];
// }
// //-----------------------------------------------------------------------------
// // in case of a single channel ID error no need to skip the rest of the ROC data -
// // force geographical address and mark the produced digi
// //-----------------------------------------------------------------------------
// else{
// print_(std::format("ERROR: hit chid:{:04x} inconsistent with the dtc_id:{} and link_id:{}\n", hit_data->StrawIndex, dtc_id, link_id));
// mn_id = channel_map_[dtc_id][link_id];
// if (mn_id == StrawDigisFromArtdaqFragments::invalid_minnesota_){
// std::string msg = "encountered invalid PanelID";
// throw cet::exception("StrawDigisFromArtdaqFragments") << msg << std::endl;
// }
// if (minnesota_map_.count(mn_id) < 1){
// std::string msg = "undefined minnesota number in fallback mapping:" + std::to_string(mn_id);
// throw cet::exception("StrawDigisFromArtdaqFragments") << msg << std::endl;
// }
// panel_id = minnesota_map_[mn_id];
// digi_flag = mu2e::StrawDigiFlag::corrupted;
// }

if (hit_data->NumADCPackets != nADCPackets_) {
int np = hit_data->NumADCPackets;
Expand Down Expand Up @@ -507,35 +518,40 @@ void mu2e::StrawDigisFromArtdaqFragments::produce(art::Event& event) {
auto digi = straw_digis->back();
digi.digiFlag() = digi_flag;
//------------------------------------------------------------------------------
// the corresponding waveform
// the corresponding waveform, store only if at least the second packet is present (nSamples_ = 15 or more)
//-----------------------------------------------------------------------------
if (saveWaveforms_) {
std::vector<uint16_t> wf(nSamples_);

wf[0] = hit_data->ADC00;
wf[1] = hit_data->ADC01();
wf[2] = hit_data->ADC02;

auto npackets = 0;
auto idx = 2;
auto adc_packet = (mu2e::TrackerDataDecoder::TrackerADCPacket*)((char*) hit_data + 16); // the packet size is 16 bytes
while (npackets < nADCPackets_) {
wf[++idx] = adc_packet->ADC0;
wf[++idx] = adc_packet->ADC1();
wf[++idx] = adc_packet->ADC2;
wf[++idx] = adc_packet->ADC3;
wf[++idx] = adc_packet->ADC4();
wf[++idx] = adc_packet->ADC5;
wf[++idx] = adc_packet->ADC6;
wf[++idx] = adc_packet->ADC7();
wf[++idx] = adc_packet->ADC8;
wf[++idx] = adc_packet->ADC9;
wf[++idx] = adc_packet->ADC10();
wf[++idx] = adc_packet->ADC11;
npackets++;
adc_packet++;
if (nSamples_ <= 3) {
print_(std::format("ERROR: nSamples:{}, do not store waveforms",nSamples_));
}
else {
std::vector<uint16_t> wf(nSamples_);

wf[0] = hit_data->ADC00;
wf[1] = hit_data->ADC01();
wf[2] = hit_data->ADC02;

auto npackets = 0;
auto idx = 2;
auto adc_packet = (mu2e::TrackerDataDecoder::TrackerADCPacket*)((char*) hit_data + 16); // the packet size is 16 bytes
while (npackets < nADCPackets_) {
wf[++idx] = adc_packet->ADC0;
wf[++idx] = adc_packet->ADC1();
wf[++idx] = adc_packet->ADC2;
wf[++idx] = adc_packet->ADC3;
wf[++idx] = adc_packet->ADC4();
wf[++idx] = adc_packet->ADC5;
wf[++idx] = adc_packet->ADC6;
wf[++idx] = adc_packet->ADC7();
wf[++idx] = adc_packet->ADC8;
wf[++idx] = adc_packet->ADC9;
wf[++idx] = adc_packet->ADC10();
wf[++idx] = adc_packet->ADC11;
npackets++;
adc_packet++;
}
straw_digi_adcs->emplace_back(wf);
}
straw_digi_adcs->emplace_back(wf);
}
}
}
Expand Down
52 changes: 51 additions & 1 deletion DAQ/src/StrawHitFilter_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
#include <memory>
#include <map>

#include "Offline/ProditionsService/inc/ProditionsHandle.hh"
#include "Offline/TrackerConditions/inc/TrackerPanelMap.hh"

namespace mu2e {
class StrawHitFilter : public art::EDFilter {
public:
Expand All @@ -40,6 +43,7 @@ namespace mu2e {
fhicl::Atom<float> maxDt {Name("maxDt" ), Comment("max abs(DT)")};
fhicl::Atom<float> minEDep {Name("minEDep" ), Comment("min EDep")};
fhicl::Atom<int> minNGoodHits {Name("minNGoodHits" ), Comment("minNStrawDigis")};
fhicl::Sequence<int> channelsToSkip{Name("channelsToSkip"), Comment("a list of channels to skip")};
fhicl::Atom<bool> fillHistograms{Name("fillHistograms"), Comment("fill histogrms, default:false")};
};

Expand All @@ -50,6 +54,11 @@ namespace mu2e {
TH1F* dt ;
TH1F* edep;
} _hist[2];
// channels disabled from the trigger
struct Channel_t {
int mnid;
int straw;
};

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

Expand All @@ -75,14 +84,17 @@ namespace mu2e {
float _maxDt;
float _minEDep;
int _minNGoodHits;
std::vector<Channel_t> _channelsToSkip; // channels not to look at when searching for good hits
int _fillHistograms;

int _nevt;
int _nevp;
int _nsht;
int _nshg;

const mu2e::StrawHitCollection* _shc;
const mu2e::StrawHitCollection* _shc;
ProditionsHandle<TrackerPanelMap> _tpm_h;
const TrackerPanelMap* _trkPanelMap;

const art::Event* _event;
int _rn;
Expand Down Expand Up @@ -112,6 +124,23 @@ namespace mu2e {
sscanf(key,"bit%i:%i",&index,&value);
_debugBit[index] = value;
}
//-----------------------------------------------------------------------------
// parse channels to skip
//-----------------------------------------------------------------------------
int ndat = conf().channelsToSkip().size();
for (int i=0; i<ndat; i+=2) {
Channel_t ch;
ch.mnid = conf().channelsToSkip().at(i);
ch.straw = conf().channelsToSkip().at(i+1);
_channelsToSkip.push_back(ch);
}

int n_disabled_channels = _channelsToSkip.size();
for (int i=0; i<n_disabled_channels; i++) {
Channel_t* ch = & _channelsToSkip[i];
std::cout << std::format("disabled : mnid:MN{:03d} straw:{:02d}\n",ch->mnid, ch->straw);
}

_run_initialized = false;
}

Expand Down Expand Up @@ -194,6 +223,8 @@ namespace mu2e {

_event = &ArtEvent; // should always be the first line

_trkPanelMap = &_tpm_h.get(_event->id());

if (_debugMode) print_("-- START");

++_nevt;
Expand All @@ -216,6 +247,25 @@ namespace mu2e {

for (int i = 0; i<_nsht; ++i) {
const mu2e::StrawHit* sh = &_shc->at(i);

int pln = sh->strawId().plane();
int pnl = sh->strawId().panel();
const TrkPanelMap::Row* tpm = _trkPanelMap->panel_map_by_offline_ind(pln,pnl);
int hit_mnid = tpm->mnid();

bool skip = false;

int n_disabled_channels = _channelsToSkip.size();
for (int i=0; i<n_disabled_channels; i++) {
Channel_t* ch = & _channelsToSkip[i];
if ((hit_mnid == ch->mnid) and (sh->strawId().straw() == ch->straw)) {
skip = true;
break;
}
}

if (skip) continue;

if (fabs(sh->dt()) > _maxDt ) continue;
if (sh->energyDep() < _minEDep) continue;
_nshg++;
Expand Down
17 changes: 14 additions & 3 deletions RecoDataProducts/inc/StrawHit.hh
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,32 @@ namespace mu2e {
TrkTypes::TDCTimes _time; // (ns)
TrkTypes::TOTTimes _tot; // (ns)
float _energyDep; // (MeV)
float _digital_pmp; // adcs
float _digital_pedestal; // adcs

public:

StrawHit():
_strawId(StrawId(-1)),
_time{0.0,0.0},
_tot{0.0,0.0},
_energyDep(0.){
_energyDep(0.),
_digital_pmp(0.0),
_digital_pedestal(0.0){
}

// Constructor for a hit that came from an unpacked digi, either
// from data or from the full MC chain.
StrawHit( StrawId strawId,
TrkTypes::TDCTimes const& time,
TrkTypes::TOTTimes const& tot,
float energyDep ):
float energyDep ,
float digital_pmp,
float digital_pedestal):
_strawId(strawId),_time(time),_tot(tot),
_energyDep(energyDep) {
_energyDep(energyDep),
_digital_pmp(digital_pmp),
_digital_pedestal(digital_pedestal){
}

// Accessors
Expand All @@ -53,6 +61,9 @@ namespace mu2e {
float TOT(StrawEnd end=StrawEnd::cal) const { return _tot[end];}
float energyDep() const { return _energyDep; }

float digitalPulseHeight() const { return _digital_pmp; }
float digitalPedestal() const { return _digital_pedestal; }

// Accept compiler generated versions of d'tor, copy c'tor, assignment operator.
bool operator==(StrawHit const& other) const {
return (_strawId==other._strawId&&
Expand Down
Loading