Skip to content

Commit

Permalink
Commiting some of @tvami's suggestions. Code is looking better, am co…
Browse files Browse the repository at this point in the history
…mmitting the rest in a sec
  • Loading branch information
rodwyer100 committed Sep 21, 2024
1 parent 3b6e48b commit 568689e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 18 deletions.
40 changes: 31 additions & 9 deletions TrigScint/src/TrigScint/Firmware/hitproducer_hw.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ void hitproducer_hw(ap_uint<14> FIFO[NHITS][5],Hit outHit[NHITS],ap_uint<8> Peds

#pragma HLS PIPELINE

//The QIE11 card takes an analogue SiPM PE count
//and converts electron counts from it via a piecewise
//exponential curve into an ADC. Depending on the shunts
//you use, you can affect the gain; the gains and variable
//values determined here are motived primarily by those required
//to get the MIP distribution seen in the 2022 beam.
//The next variables show where each linear portion of the
//exponential map start in charge count (edges_) and their slope;
//the hitmaker delinearized the adc counts, integrates over five clockcycles
//and forms a hit.

/// Indices of first bin of each subrange
ap_uint<14> nbins_[5] = {0, 16, 36, 57, 64};

Expand All @@ -82,10 +93,15 @@ void hitproducer_hw(ap_uint<14> FIFO[NHITS][5],Hit outHit[NHITS],ap_uint<8> Peds
outHit[i].Time=0;
outHit[i].Amp=0;
ap_uint<14> word1=FIFO[i][0];ap_uint<14> word2=FIFO[i][1];ap_uint<14> word3=FIFO[i][2];
ap_uint<14> word4=FIFO[i][3];ap_uint<14> word5=FIFO[i][4];ap_uint<14> word6=FIFO[i][5];
ap_uint<14> word4=FIFO[i][3];ap_uint<14> word5=FIFO[i][4];
ap_uint<16> charge1;ap_uint<16> charge2;ap_uint<16> charge3;
ap_uint<16> charge4;ap_uint<16> charge5;ap_uint<16> charge6;

ap_uint<16> charge4;ap_uint<16> charge5;

//An identical procedure is used for all 5 clockcylces. Namely you extract the adc value from the adc+tdc
//concatenated value you get from the raw strwam via (word1>>6); You then use what integer multiple of
//64 it is to determine which linear segment you are on, and v1 (the remainder) to determine how far
//along that linear segment your charge carried you. Together that gets you charge.

ap_uint<14> rr = (word1>>6)/64;
ap_uint<14> v1 = (word1>>6)%64;
ap_uint<14> ss = 1*(v1>nbins_[1])+1*(v1>nbins_[2])+1*(v1>nbins_[3]);
Expand All @@ -110,15 +126,21 @@ void hitproducer_hw(ap_uint<14> FIFO[NHITS][5],Hit outHit[NHITS],ap_uint<8> Peds
v1 = (word5>>6)%64;
ss = 1*(v1>nbins_[1])+1*(v1>nbins_[2])+1*(v1>nbins_[3]);
charge5 = edges_[4*rr+ss]+(v1-nbins_[ss])*sense_[4*rr+ss]+sense_[4*rr+ss]/2-1;

rr = (word6>>6)/64;
v1 = (word6>>6)%64;
ss = 1*(v1>nbins_[1])+1*(v1>nbins_[2])+1*(v1>nbins_[3]);
charge6 = edges_[4*rr+ss]+(v1-nbins_[ss])*sense_[4*rr+ss]+sense_[4*rr+ss]/2-1;

outHit[i].bID=i;

//You now are creating an output hit. The time of the hit is determined by the last part of the concatenated
//streamed tdc, which is 6 bits and therefore you mask the word1 with 63 (which is 111111 in binary) so as only
//to keep the tdc.

outHit[i].Time=(word1 & 63);
outHit[i].Amp=((charge1+charge2+charge3+charge4+charge5+charge6-36)*.00625);

//The 36 remaining here is an artefact of the mapping that the charges have to adcs; its not particularly
//meaningful except that it establishes that 0 adc corresponds to 0 charge. The .00625 value is a value
//which is conglomerate but relates to the number of PE's produced; it will change based on the number of shunts
//employed during a run.

outHit[i].Amp=((charge1+charge2+charge3+charge4+charge5-36)*.00625);
}

return;
Expand Down
13 changes: 7 additions & 6 deletions TrigScint/src/TrigScint/TrigScintFirmwareHitProducer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ void TrigScintFirmwareHitProducer::configure(framework::config::Parameters &ps)
}

void TrigScintFirmwareHitProducer::produce(framework::Event &event) {
// This processor takes in TS QIE digis and outputs a rec hit collection. It does so
// using hitproducer_hw, which is a validated piece
// of HLS code whose purpose is to emulate existing reconstruction
// software in firmware for triggering. I will more fully explain the
// operation and choices made in hitproducer_hw in hitproducer_hw
if(doTest_){
const auto rechits{event.getCollection<ldmx::TrigScintHit>(
testCollection_, inputPassName_)};
Expand All @@ -47,7 +52,7 @@ void TrigScintFirmwareHitProducer::produce(framework::Event &event) {
const auto digis{event.getCollection<trigscint::TrigScintQIEDigis>(
inputCollection_, inputPassName_)};
Hit outHit[NHITS];
ap_uint<14> FIFO[NCHAN][5];
ap_uint<14> FIFO[NCHAN][NTIMES];
ap_uint<8> Peds[NCHAN];
for(int i = 0; i < NCHAN; i++){
Peds[i]=0;
Expand All @@ -57,17 +62,14 @@ void TrigScintFirmwareHitProducer::produce(framework::Event &event) {
FIFO[i][3]=(Peds[i]<<6)+63;
FIFO[i][4]=(Peds[i]<<6)+63;
}
std::cout<<"DID I GET HERE 3"<<std::endl;
for(const auto &digi : digis) {
std::vector<int> adcs=digi.getADC();
std::vector<int> tdcs=digi.getTDC();
for(int i = 0;i<5;i++){
for(int i = 0;i<NTIMES;i++){
FIFO[(int)(digi.getChanID())][i]=(ap_uint<14>)((adcs[i]<<6)+(tdcs[i]));
}
}
std::cout<<"DID I GET HERE 4"<<std::endl;
hitproducer_hw(FIFO,outHit,Peds);
std::cout<<"DID I GET HERE 5"<<std::endl;
std::vector<ldmx::TrigScintHit> trigScintHits;
for(int i=0;i<NHITS;i++){
if(outHit[i].Amp>=3){
Expand All @@ -82,7 +84,6 @@ void TrigScintFirmwareHitProducer::produce(framework::Event &event) {
trigScintHits.push_back(hit);
}
}
std::cout<<"DID I GET HERE 6"<<std::endl;
event.add(outputCollection_, trigScintHits);
return;
}
Expand Down
3 changes: 0 additions & 3 deletions TrigScint/src/TrigScint/TrigScintFirmwareTracker.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ void TrigScintFirmwareTracker::produce(framework::Event &event) {
(digi.getBarID() >= 0)) {
ap_int<12> bID = (ap_int<12>)(digi.getBarID());
ap_int<12> Amp = (ap_int<12>)(digi.getPE());
int index = count;
if (occupied[(int)digi.getBarID()] >= 0) {
if (HPad1[(int)occupied[(int)digi.getBarID()]].Amp < digi.getPE()) {
HPad1[(int)occupied[(int)digi.getBarID()]].bID =
Expand Down Expand Up @@ -164,7 +163,6 @@ void TrigScintFirmwareTracker::produce(framework::Event &event) {
(digi.getBarID() >= 0)) {
ap_int<12> bID = (ap_int<12>)(digi.getBarID());
ap_int<12> Amp = (ap_int<12>)(digi.getPE());
int index = count;
if (occupied[(int)digi.getBarID()] >= 0) {
if (HPad2[(int)occupied[(int)digi.getBarID()]].Amp < digi.getPE()) {
HPad2[(int)occupied[(int)digi.getBarID()]].bID =
Expand Down Expand Up @@ -195,7 +193,6 @@ void TrigScintFirmwareTracker::produce(framework::Event &event) {
(digi.getBarID() >= 0)) {
ap_int<12> bID = (ap_int<12>)(digi.getBarID());
ap_int<12> Amp = (ap_int<12>)(digi.getPE());
int index = count;
if (occupied[(int)digi.getBarID()] >= 0) {
if (HPad3[(int)occupied[(int)digi.getBarID()]].Amp < digi.getPE()) {
HPad3[(int)occupied[(int)digi.getBarID()]].bID =
Expand Down

0 comments on commit 568689e

Please sign in to comment.