Skip to content

Commit

Permalink
Add conversion from installation to offline APA numbering convention.
Browse files Browse the repository at this point in the history
  • Loading branch information
brettviren committed Jul 17, 2019
1 parent cb8e934 commit ef94032
Showing 1 changed file with 49 additions and 12 deletions.
61 changes: 49 additions & 12 deletions src/pdt_pduneadjacency_mlt.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,46 @@
#include "pdt_engines.h"
#include "pdt/ModuleTrigger.h"

/*
From Phil:
detid set inside FELIX_BR:
(m_fiber_no << 16) | (m_slot_no << 8) | m_crate_no
m_crate_no is the same as the "online" APA number ("Installation numbering" below):
Installation numbering:
APA5 APA6 APA4
beam -->
APA3 APA2 APA1
The Offline numbering:
APA1 APA3 APA5
beam -->
APA0 APA2 APA4
So, based on David's message, the mapping is:
m_crate_no candidate[8]
5 0
6 1
4 2
(m_crate_no=4 will never occur in the current system, as APA 4 isn't
instrumented with FELIX yet, but the plan is that it will be
eventually).
*/
static
int detid_to_offline_apa_number(int detid)
{
const std::vector<int> i2o_apa_map = {-1, 4, 2, 0, 5, 1, 3};
const size_t inst_apa = detid & 0x000000FF;
if (inst_apa < 0 or inst_apa > 6) { return -1; }
return i2o_apa_map[inst_apa];
}

// Fixme: TPSet holds 50MHz clocks, PDT assumes 2MHz
const int hwtick_per_internal = 25;

Expand Down Expand Up @@ -36,7 +76,14 @@ void PDUNEAdjacencyMLT_engine::ingest(const ptmp::data::TPSet& fresh)
outbound.set_detid(fresh.detid());
}

// ModuleTrigger() wants a 9-tuple of ints. First eight entries
// are what TriggerCommand() returns. The ninth is the *offline*
// APA number (not installation number).
//
// 0 1 2 3 4 5 6 7 8
// (adjacency, adcpeak, adcsum, tspan, chan1, chan2, t1, t2, apanum)
candidate_t candidate(9, 0);

// Adjacency value is outside the TPSet/TrigPrim model and is
// special to the PDT TriggerCandidate() algorithm. We've stashed
// it in TrigPrim.adcpeak in a final TrigPrim with .flag set to
Expand All @@ -50,13 +97,7 @@ void PDUNEAdjacencyMLT_engine::ingest(const ptmp::data::TPSet& fresh)
// PDT works in 2MHz clock ticks, not 50MHz
candidate[6] = special->tstart()/hwtick_per_internal;
candidate[7] = (special->tstart() + special->tspan())/hwtick_per_internal;
// Phil sets detid inside FELIX_BR with:
//
// (m_fiber_no << 16) | (m_slot_no << 8) | m_crate_no
//
// FIXME: for lack of any better understanding assume PDT wants
// APA number same as m_crate_no:
candidate[8] = fresh.detid() & 0x000000FF;
candidate[8] = detid_to_offline_apa_number(fresh.detid());
candidates.push_back(candidate);

outbound.set_chanbeg(std::min(outbound.chanbeg(), fresh.chanbeg()));
Expand All @@ -83,11 +124,6 @@ void PDUNEAdjacencyMLT_engine::operator()(const ptmp::data::TPSet& input_tpset,

// ready to process

// It is an 9-tuple of ints, with additional [8]'th entry from
// what TriggerCommand() returns
// 0 1 2 3 4 5 6 7 8
// (adjacency, adcpeak, adcsum, tspan, chan1, chan2, t1, t2, apanum)

// fixme: does MT() need any sorting of its input candidates?

int ok = ModuleTrigger(candidates);
Expand All @@ -109,6 +145,7 @@ void PDUNEAdjacencyMLT_engine::operator()(const ptmp::data::TPSet& input_tpset,

void PDUNEAdjacencyMLT_engine::clear()
{
// don't clear detid
outbound.set_tstart(0);
outbound.set_tspan(0);
outbound.set_chanbeg(0);
Expand Down

0 comments on commit ef94032

Please sign in to comment.