Skip to content

Commit

Permalink
Merge pull request #527 from eflumerf/v10_01_00_ots
Browse files Browse the repository at this point in the history
Changes needed for mu2e_artdaq_core v1_06_02 compatibility
  • Loading branch information
kutschke authored Jul 22, 2021
2 parents 8d8086a + 3469a97 commit ce761a8
Show file tree
Hide file tree
Showing 15 changed files with 528 additions and 400 deletions.
2 changes: 1 addition & 1 deletion .muse
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# prefer to build with this environment
ENVSET p008
ENVSET p010
# add these to python path
PYTHONPATH TrackerAlignment/scripts
PYTHONPATH Trigger/python
Expand Down
14 changes: 7 additions & 7 deletions DAQ/inc/CaloDAQUtilities.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ namespace mu2e {
public:
CaloDAQUtilities(std::string ModuleName);

uint16_t getCrystalID(CalorimeterFragment::CalorimeterHitReadoutPacket& Hit){ return Hit.DIRACB & 0x0FFF;}
uint16_t getSiPMID (CalorimeterFragment::CalorimeterHitReadoutPacket& Hit){
uint16_t getCrystalID(CalorimeterFragment::CalorimeterHitReadoutPacket const& Hit){ return Hit.DIRACB & 0x0FFF;}
uint16_t getSiPMID (CalorimeterFragment::CalorimeterHitReadoutPacket const& Hit){
uint16_t crystalID = getCrystalID(Hit);
uint16_t sipmID = Hit.DIRACB >> 12;
return (crystalID * 2 + sipmID);
}

void printCaloFragmentInfo(const artdaq::Fragment& f, CalorimeterFragment& Frag);
void printCaloFragmentInfo(CalorimeterFragment const& Frag);

void printCaloFragmentHeader(DTCLib::DTC_DataHeaderPacket &Header);
void printCaloFragmentHeader(std::shared_ptr<DTCLib::DTC_DataHeaderPacket> Header);

void printCaloPulse(CalorimeterFragment::CalorimeterHitReadoutPacket& Hit);
void printCaloPulse(CalorimeterFragment::CalorimeterHitReadoutPacket const& Hit);

void printWaveform(std::vector<uint16_t>& Pulse);
void printWaveform(std::vector<uint16_t> const& Pulse);

void printAllHitInfo(int CrystalID, int SiPMID, DTCLib::DTC_DataHeaderPacket &Header, CalorimeterFragment::CalorimeterHitReadoutPacket& Hit, uint16_t& PulseMax);
void printAllHitInfo(int CrystalID, int SiPMID, std::shared_ptr<DTCLib::DTC_DataHeaderPacket> Header, CalorimeterFragment::CalorimeterHitReadoutPacket const& Hit, uint16_t PulseMax);

private:
std::string moduleName_;
Expand Down
2 changes: 1 addition & 1 deletion DAQ/src/ArtBinaryPacketsFromDigis_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#include "Offline/RecoDataProducts/inc/CrvDigiCollection.hh"
#include "Offline/RecoDataProducts/inc/StrawDigiCollection.hh"
#include "Offline/RecoDataProducts/inc/StrawHitCollection.hh"
//#include "DAQDataProducts/inc/DataBlockCollection.hh"
//#include "Offline/DAQDataProducts/inc/DataBlockCollection.hh"
#include "Offline/ProditionsService/inc/ProditionsHandle.hh"
#include "Offline/CaloConditions/inc/CaloDAQMap.hh"

Expand Down
27 changes: 13 additions & 14 deletions DAQ/src/CaloDAQUtilities.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
namespace mu2e {
CaloDAQUtilities::CaloDAQUtilities(std::string ModuleName):moduleName_(ModuleName){}

void CaloDAQUtilities::printCaloFragmentInfo(const artdaq::Fragment& f, CalorimeterFragment& cc){
void CaloDAQUtilities::printCaloFragmentInfo(CalorimeterFragment const& cc){
std::cout << std::endl;
std::cout << "ArtFragmentReader: ";
std::cout << "\tBlock Count: " << std::dec << cc.block_count() << std::endl;
std::cout << "\tByte Count: " << f.dataSizeBytes() << std::endl;
std::cout << std::endl;
std::cout << "\t"
<< "====== Example Block Sizes ======" << std::endl;
Expand All @@ -28,20 +27,20 @@ namespace mu2e {
}


void CaloDAQUtilities::printCaloFragmentHeader(DTCLib::DTC_DataHeaderPacket &Header){
void CaloDAQUtilities::printCaloFragmentHeader(std::shared_ptr<DTCLib::DTC_DataHeaderPacket> Header){

std::cout << "timestamp: " << static_cast<int>(Header.GetEventWindowTag().GetEventWindowTag(true)) << std::endl;
std::cout << "Header->SubsystemID: " << static_cast<int>(Header.GetSubsystemID()) << std::endl;
std::cout << "dtcID: " << static_cast<int>(Header.GetID()) << std::endl;
std::cout << "rocID: " << static_cast<int>(Header.GetLinkID()) << std::endl;
std::cout << "packetCount: " << static_cast<int>(Header.GetPacketCount()) << std::endl;
std::cout << "EVB mode: " << static_cast<int>(Header.GetEVBMode()) << std::endl;
std::cout << "timestamp: " << static_cast<int>(Header->GetEventWindowTag().GetEventWindowTag(true)) << std::endl;
std::cout << "Header->SubsystemID: " << static_cast<int>(Header->GetSubsystemID()) << std::endl;
std::cout << "dtcID: " << static_cast<int>(Header->GetID()) << std::endl;
std::cout << "rocID: " << static_cast<int>(Header->GetLinkID()) << std::endl;
std::cout << "packetCount: " << static_cast<int>(Header->GetPacketCount()) << std::endl;
std::cout << "EVB mode: " << static_cast<int>(Header->GetEVBMode()) << std::endl;

std::cout << std::endl;

}

void CaloDAQUtilities::printCaloPulse(CalorimeterFragment::CalorimeterHitReadoutPacket& Hit){
void CaloDAQUtilities::printCaloPulse(CalorimeterFragment::CalorimeterHitReadoutPacket const& Hit){
std::cout << "[CaloHitsFromFragments] \tChNumber "
<< (int)Hit.ChannelNumber
<< std::endl;
Expand All @@ -64,7 +63,7 @@ namespace mu2e {

}

void CaloDAQUtilities::printWaveform(std::vector<uint16_t>& Pulse){
void CaloDAQUtilities::printWaveform(std::vector<uint16_t> const& Pulse){
std::cout << "Waveform: {";
for (size_t i = 0; i < Pulse.size(); i++) {
std::cout << Pulse[i];
Expand All @@ -76,8 +75,8 @@ namespace mu2e {
}

void CaloDAQUtilities::printAllHitInfo(int CrystalID, int SiPMID,
DTCLib::DTC_DataHeaderPacket &Header,
CalorimeterFragment::CalorimeterHitReadoutPacket& Hit, uint16_t& PulseMax){
std::shared_ptr<DTCLib::DTC_DataHeaderPacket> Header,
CalorimeterFragment::CalorimeterHitReadoutPacket const& Hit, uint16_t PulseMax){

std::cout << "Crystal ID: " << CrystalID << std::endl;
std::cout << "SiPM ID: " << SiPMID << std::endl;
Expand All @@ -87,7 +86,7 @@ namespace mu2e {

// Text format: timestamp crystalID roID time nsamples samples...
// Example: 1 201 402 660 18 0 0 0 0 1 17 51 81 91 83 68 60 58 52 42 33 23 16
std::cout << "GREPMECAL: " << Header.GetEventWindowTag().GetEventWindowTag(true) << " ";
std::cout << "GREPMECAL: " << Header->GetEventWindowTag().GetEventWindowTag(true) << " ";
std::cout << CrystalID << " ";
std::cout << SiPMID << " ";
std::cout << Hit.Time << " ";
Expand Down
164 changes: 94 additions & 70 deletions DAQ/src/CaloHitsFromFragments_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "art/Framework/Principal/Handle.h"
#include "mu2e-artdaq-core/Overlays/CalorimeterFragment.hh"
#include "mu2e-artdaq-core/Overlays/FragmentType.hh"
#include "mu2e-artdaq-core/Overlays/Mu2eEventFragment.hh"

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

Expand All @@ -24,10 +25,10 @@

#include <string>

#include <array>
#include <list>
#include <memory>
#include <unordered_map>
#include <array>
#include <vector>

namespace art {
Expand Down Expand Up @@ -80,13 +81,13 @@ class art::CaloHitsFromFragments : public EDProducer {
virtual void produce(Event&);

private:
void analyze_calorimeter_(const artdaq::Fragment& f,
void analyze_calorimeter_(const mu2e::CalorimeterFragment& cc,
std::unique_ptr<mu2e::CaloHitCollection> const& calo_hits,
std::unique_ptr<mu2e::CaloHitCollection> const& caphri_hits);

void addPulse(uint16_t& crystalID, float& time, float& eDep,
std::unique_ptr<mu2e::CaloHitCollection>const& hits_calo,
std::unique_ptr<mu2e::CaloHitCollection>const& hits_caphri);
void addPulse(uint16_t& crystalID, float& time, float& eDep,
std::unique_ptr<mu2e::CaloHitCollection> const& hits_calo,
std::unique_ptr<mu2e::CaloHitCollection> const& hits_caphri);

int diagLevel_;

Expand All @@ -96,12 +97,13 @@ class art::CaloHitsFromFragments : public EDProducer {

const int hexShiftPrint = 7;

std::unordered_map<uint16_t, std::list<mu2e::CaloHit>> pulseMap_; // Temporary hack until the Calorimeter channel map is finialized
std::unordered_map<uint16_t, std::list<mu2e::CaloHit>>
pulseMap_; // Temporary hack until the Calorimeter channel map is finialized
mu2e::CaloDAQUtilities caloDAQUtil_;

std::array<float, 674 * 4> peakADC2MeV_;
std::array<float, 674 * 4> timeCalib_;
std::array<int, 4> caphriCrystalID_;
std::array<int, 4> caphriCrystalID_;
};

// ======================================================================
Expand All @@ -115,7 +117,7 @@ void art::CaloHitsFromFragments::beginRun(art::Run& Run) {
// NOW FILLING THE ARRAY WITH A DUMMY VALUE
for (size_t i = 0; i < peakADC2MeV_.size(); ++i) {
peakADC2MeV_[i] = 0.0461333;
timeCalib_ [i] = 0.;
timeCalib_[i] = 0.;
}

// FIX ME!
Expand All @@ -124,35 +126,36 @@ void art::CaloHitsFromFragments::beginRun(art::Run& Run) {
caphriCrystalID_ = {623, 624, 595, 596};
}

void art::CaloHitsFromFragments::addPulse(uint16_t& crystalID, float& time, float& eDep,
std::unique_ptr<mu2e::CaloHitCollection>const & hits_calo,
std::unique_ptr<mu2e::CaloHitCollection>const & hits_caphri) {
void art::CaloHitsFromFragments::addPulse(
uint16_t& crystalID, float& time, float& eDep,
std::unique_ptr<mu2e::CaloHitCollection> const& hits_calo,
std::unique_ptr<mu2e::CaloHitCollection> const& hits_caphri) {

bool addNewHit(true);
bool isCaphri = std::find(caphriCrystalID_.begin(), caphriCrystalID_.end(), crystalID) !=
caphriCrystalID_.end();
caphriCrystalID_.end();
size_t counter(0);
for (auto& pulse : pulseMap_[crystalID]) {
++counter;
if (std::fabs(pulse.time() - time) < deltaTPulses_){
if( (eDep / pulse.energyDep() <= pulseRatioMax_) &&
(eDep / pulse.energyDep() >= pulseRatioMin_) ) {
// combine the pulses
pulse.setTime ( (pulse.time() + time) / 2.);//probably not necessary
pulse.setEDep ( (pulse.energyDep() + eDep) / 2.);
pulse.setNSiPMs( pulse.nSiPMs()+ 1);
addNewHit = false;
}else if (eDep > pulse.energyDep()) {
pulse.setTime (time);//probably not necessary
pulse.setEDep (eDep);
addNewHit = false;
if (std::fabs(pulse.time() - time) < deltaTPulses_) {
if ((eDep / pulse.energyDep() <= pulseRatioMax_) &&
(eDep / pulse.energyDep() >= pulseRatioMin_)) {
// combine the pulses
pulse.setTime((pulse.time() + time) / 2.); // probably not necessary
pulse.setEDep((pulse.energyDep() + eDep) / 2.);
pulse.setNSiPMs(pulse.nSiPMs() + 1);
addNewHit = false;
} else if (eDep > pulse.energyDep()) {
pulse.setTime(time); // probably not necessary
pulse.setEDep(eDep);
addNewHit = false;
}

//move the pulse in the final collection
if (isCaphri){
hits_caphri->emplace_back(std::move(pulse));
}else{
hits_calo->emplace_back(std::move(pulse));
// move the pulse in the final collection
if (isCaphri) {
hits_caphri->emplace_back(std::move(pulse));
} else {
hits_calo->emplace_back(std::move(pulse));
}
break;
}
Expand All @@ -163,19 +166,15 @@ void art::CaloHitsFromFragments::addPulse(uint16_t& crystalID, float& time, floa
}

art::CaloHitsFromFragments::CaloHitsFromFragments(const art::EDProducer::Table<Config>& config) :
art::EDProducer{config}, diagLevel_(config().diagLevel()),
caloFragmentsTag_(config().caloTag()),
digiSampling_ (config().digiSampling()),
deltaTPulses_ (config().deltaTPulses()),
pulseRatioMax_ (config().pulseRatioMax()),
pulseRatioMin_ (config().pulseRatioMin()),
hitEDepMax_ (config().hitEDepMax()),
caloDAQUtil_ ("CaloHitsFromFragments")
{
pulseMap_.reserve(4000);
produces<mu2e::CaloHitCollection>();
produces<mu2e::CaloHitCollection>("caphri");
}
art::EDProducer{config}, diagLevel_(config().diagLevel()),
caloFragmentsTag_(config().caloTag()), digiSampling_(config().digiSampling()),
deltaTPulses_(config().deltaTPulses()), pulseRatioMax_(config().pulseRatioMax()),
pulseRatioMin_(config().pulseRatioMin()), hitEDepMax_(config().hitEDepMax()),
caloDAQUtil_("CaloHitsFromFragments") {
pulseMap_.reserve(4000);
produces<mu2e::CaloHitCollection>("calo");
produces<mu2e::CaloHitCollection>("caphri");
}

// ----------------------------------------------------------------------

Expand All @@ -188,23 +187,49 @@ void art::CaloHitsFromFragments::produce(Event& event) {
std::unique_ptr<mu2e::CaloHitCollection> calo_hits(new mu2e::CaloHitCollection);
std::unique_ptr<mu2e::CaloHitCollection> caphri_hits(new mu2e::CaloHitCollection);

art::Handle<artdaq::Fragments> calFragments;
size_t numCalFrags(0);
size_t totalSize = 0;
event.getByLabel(caloFragmentsTag_, calFragments);
if (!calFragments.isValid()) {
size_t numCalFrags = 0;
std::vector<art::Handle<artdaq::Fragments>> fragmentHandles = event.getMany<std::vector<artdaq::Fragment>>();

for (const auto& handle : fragmentHandles) {
if (!handle.isValid() || handle->empty()) {
continue;
}

if (diagLevel_ > 1) {
std::cout << "[CaloHitsFromFragments::produce] Fragment type of first Fragment in handle: " << static_cast<int>(handle->front().type()) << std::endl;
}
if (handle->front().type() == mu2e::detail::FragmentType::MU2EEVENT) {
for (const auto& cont : *handle) {
mu2e::Mu2eEventFragment mef(cont);
for (size_t ii = 0; ii < mef.calorimeter_block_count(); ++ii) {
auto pair = mef.calorimeterAtPtr(ii);
mu2e::CalorimeterFragment cc(pair);
analyze_calorimeter_(cc, calo_hits, caphri_hits);

totalSize += pair.second;
numCalFrags++;
}
}
} else {
if (handle->front().type() == mu2e::detail::FragmentType::CAL) {
for (auto frag : *handle) {
mu2e::CalorimeterFragment cc(frag.dataBegin(), frag.dataSizeBytes());
analyze_calorimeter_(cc, calo_hits, caphri_hits);

totalSize += frag.dataSizeBytes();
numCalFrags++;
}
}
}
}

if (numCalFrags == 0) {
std::cout << "[CaloHitsFromFragments::produce] found no Calorimeter fragments!" << std::endl;
event.put(std::move(calo_hits));
event.put(std::move(caphri_hits));
event.put(std::move(calo_hits), "calo");
event.put(std::move(caphri_hits), "caphri");
return;
}
numCalFrags = calFragments->size();
for (size_t idx = 0; idx < numCalFrags; ++idx) {
auto size = ((*calFragments)[idx]).sizeBytes(); // * sizeof(artdaq::RawDataType);
totalSize += size;
analyze_calorimeter_((*calFragments)[idx], calo_hits, caphri_hits);
// std::cout << "\tCAL Fragment " << idx << " has size " << size << std::endl;
}

if (diagLevel_ > 1) {
std::cout << std::dec << "Producer: Run " << event.run() << ", subrun " << event.subRun()
Expand All @@ -220,18 +245,17 @@ void art::CaloHitsFromFragments::produce(Event& event) {
}

// Store the calo hits in the event
event.put(std::move(calo_hits));
event.put(std::move(calo_hits), "calo");
event.put(std::move(caphri_hits), "caphri");

} // produce()

void art::CaloHitsFromFragments::analyze_calorimeter_(
const artdaq::Fragment& f, std::unique_ptr<mu2e::CaloHitCollection> const& calo_hits,
const mu2e::CalorimeterFragment& cc, std::unique_ptr<mu2e::CaloHitCollection> const& calo_hits,
std::unique_ptr<mu2e::CaloHitCollection> const& caphri_hits) {
mu2e::CalorimeterFragment cc(f);

if (diagLevel_ > 1) {
caloDAQUtil_.printCaloFragmentInfo(f, cc);
caloDAQUtil_.printCaloFragmentInfo(cc);
}

for (size_t curBlockIdx = 0; curBlockIdx < cc.block_count(); curBlockIdx++) {
Expand Down Expand Up @@ -268,7 +292,7 @@ void art::CaloHitsFromFragments::analyze_calorimeter_(
caloDAQUtil_.printCaloFragmentHeader(hdr);
}

if (hdr.GetPacketCount() == 0)
if (hdr->GetPacketCount() == 0)
continue;

auto calData = cc.GetCalorimeterData(curBlockIdx);
Expand Down Expand Up @@ -316,21 +340,21 @@ void art::CaloHitsFromFragments::analyze_calorimeter_(
size_t peakIndex = hits[hitIdx].first.IndexOfMaxDigitizerSample;
// float eDep(0);
// if (hits[hitIdx].first.IndexOfMaxDigitizerSample < hits[hitIdx].second.size()) {
// eDep = hits[hitIdx].second.at(peakIndex) * peakADC2MeV_[sipmID];
float eDep = hits[hitIdx].second * peakADC2MeV_[sipmID];
// }
float time = hits[hitIdx].first.Time + peakIndex * digiSampling_ + timeCalib_[sipmID];

//FIX ME! WE NEED TO CHECK IF TEH PULSE IS SATURATED HERE
if (eDep < hitEDepMax_){
addPulse(crystalID, time, eDep, calo_hits, caphri_hits);
// eDep = hits[hitIdx].second.at(peakIndex) * peakADC2MeV_[sipmID];
float eDep = hits[hitIdx].second * peakADC2MeV_[sipmID];
// }
float time = hits[hitIdx].first.Time + peakIndex * digiSampling_ + timeCalib_[sipmID];

// FIX ME! WE NEED TO CHECK IF TEH PULSE IS SATURATED HERE
if (eDep < hitEDepMax_) {
addPulse(crystalID, time, eDep, calo_hits, caphri_hits);
}
if (diagLevel_ > 1) {
// Until we have the final mapping, the BoardID is just a placeholder
// adc_t BoardId = cc.DBC_BoardID(pos,channelIdx);

caloDAQUtil_.printAllHitInfo(crystalID, sipmID, hdr, hits[hitIdx].first,
hits[hitIdx].second);
caloDAQUtil_.printAllHitInfo(crystalID, sipmID, hdr, hits[hitIdx].first,
hits[hitIdx].second);
} // End debug output

} // End loop over readout channels in DataBlock
Expand Down
Loading

0 comments on commit ce761a8

Please sign in to comment.