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
31 changes: 26 additions & 5 deletions UserTools/EBPMT/EBPMT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ bool EBPMT::Initialise(std::string configfile, DataModel &data)
bool EBPMT::Execute()
{
m_data->CStore.Get("RunCode", currentRunCode);
bool gotTankEvents = m_data->CStore.Get("FinishedTankEvents", FinishedTankEvents);
bool gotHits = m_data->CStore.Get("InProgressHits", InProgressHits);
bool gotChkey = m_data->CStore.Get("InProgressChkey", InProgressChkey);

if (!gotHits || !gotChkey)
if (!gotTankEvents || !gotHits || !gotChkey)
{
Log("EBPMT: No InProgressHits or InProgressChkey found", v_message, verbosityEBPMT);
Log("EBPMT: No FinishedTankEvents or InProgressHits or InProgressChkey found", v_message, verbosityEBPMT);
return true;
}
Log("EBPMT: got inprogress hits and chkey with size " + std::to_string(InProgressHits->size()) + " and " + std::to_string(InProgressChkey->size()), v_message, verbosityEBPMT);


Log("EBPMT: got inprogress tank events, hits and chkey with size " + std::to_string(FinishedTankEvents->size()) + ", " + std::to_string(InProgressHits->size())
+ " and " + std::to_string(InProgressChkey->size()), v_message, verbosityEBPMT);

if (exeNum % 80 == 0 && exeNum != 0)
{
Expand All @@ -62,6 +62,7 @@ bool EBPMT::Execute()
m_data->CStore.Get("InProgressRecoADCHitsAux", InProgressRecoADCHitsAux);

CorrectVMEOffset();
m_data->CStore.Set("FinishedTankEvents", FinishedTankEvents);
m_data->CStore.Set("InProgressHits", InProgressHits);
m_data->CStore.Set("InProgressChkey", InProgressChkey);
m_data->CStore.Set("InProgressHitsAux", InProgressHitsAux);
Expand Down Expand Up @@ -415,6 +416,12 @@ void EBPMT::CorrectVMEOffset()
// loop timestamps,对于每一个时间戳,检查它与它之前的时间戳的差值是否是8或者16
// 如果是,获得InProgressHits在这两个时间戳上的map的size
// 在timestamps_to_shift中记录pair,第一个时间戳是size较小的那个,第二个是较大的那个

// Comment in English using AI
// Loop over the timestamps. For each one, check whether its difference from the previous timestamp is 8 or 16 ns.
// If so, get the size of the InProgressHits map at both timestamps.
// Record the pair in timestamps_to_shift: first the timestamp with the smaller map, then the one with the larger map.

for (int i = 1; i < timestamps.size(); i++)
{
uint64_t dt = (timestamps[i] > timestamps[i - 1]) ? (timestamps[i] - timestamps[i - 1]) : (timestamps[i - 1] - timestamps[i]);
Expand Down Expand Up @@ -487,6 +494,20 @@ void EBPMT::CorrectVMEOffset()
(*InProgressRecoADCHitsAux)[LargerMapTS] = SecondRecoADCHitsAux;
InProgressRecoADCHitsAux->erase(SmallerMapTS);

if (FinishedTankEvents != nullptr && FinishedTankEvents->count(SmallerMapTS) > 0) {
std::map<std::vector<int>, std::vector<uint16_t>> FirstRaw = FinishedTankEvents->at(SmallerMapTS);
std::map<std::vector<int>, std::vector<uint16_t>> SecondRaw;

if (FinishedTankEvents->count(LargerMapTS) > 0) {
SecondRaw = FinishedTankEvents->at(LargerMapTS);
}

SecondRaw.insert(FirstRaw.begin(), FirstRaw.end());

(*FinishedTankEvents)[LargerMapTS] = SecondRaw;
FinishedTankEvents->erase(SmallerMapTS);
}

if (saveRWMWaveforms)
{
// if found SmallerMapTS in RWMRawWaveforms, then change it to LargerMapTS
Expand Down
3 changes: 3 additions & 0 deletions UserTools/EBPMT/EBPMT.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* $Date: 2024/04 $
* Contact: yuef@iaistate.edu
*
* Updated by: Anuj Gupta (2026.09.25)
*
*/

class EBPMT : public Tool
Expand Down Expand Up @@ -45,6 +47,7 @@ class EBPMT : public Tool
std::map<uint64_t, std::vector<unsigned long>> *InProgressChkey; // Key: {MTCTime}, value: vector of in progress chankeys

// only used for VME offset correction
std::map<uint64_t, std::map<std::vector<int>, std::vector<uint16_t>>>* FinishedTankEvents = nullptr; // Key: {MTCTime}, value: map of raw, uncalibrated waveforms
std::map<uint64_t, std::map<unsigned long, std::vector<Hit>> *> *InProgressHitsAux; // Key: {MTCTime}, value: map of Hit distributions
std::map<uint64_t, std::map<unsigned long, std::vector<std::vector<ADCPulse>>>> *InProgressRecoADCHits; // Key: {MTCTime}, value: map of found pulses
std::map<uint64_t, std::map<unsigned long, std::vector<std::vector<ADCPulse>>>> *InProgressRecoADCHitsAux; // Key: {MTCTime}, value: map of found pulses
Expand Down
31 changes: 30 additions & 1 deletion UserTools/EBSaver/EBSaver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,29 @@ bool EBSaver::SavePMTData(uint64_t PMTTime)
Log("EBSaver: Merged PMT data, PMTHits size " + std::to_string(PMTHits->size()), v_debug, verbosityEBSaver);
}

if (FinishedTankEvents != nullptr && FinishedTankEvents->count(PMTTime) > 0)
{
std::map<std::vector<int>, std::vector<uint16_t>> RawMap = FinishedTankEvents->at(PMTTime);
std::map<std::vector<int>, std::vector<Waveform<uint16_t>>> RawWaveformMap;

ANNIEEvent->Get("RawWaveformMap", RawWaveformMap); // keep waveforms already in this event, otherwise the map will be empty

for (const auto& apair : RawMap) {
Waveform<uint16_t> TheWave(static_cast<double>(PMTTime), apair.second);
RawWaveformMap[apair.first].push_back(TheWave);
}

ANNIEEvent->Set("RawWaveformMap", RawWaveformMap);

// Erase to prevent memory leaks as we build events
FinishedTankEvents->erase(PMTTime);
Log("EBSaver: Saved RawWaveformMap of size " + std::to_string(RawMap.size()) + " with PMTTime " + std::to_string(PMTTime), v_message, verbosityEBSaver);
}
else
{
Log("EBSaver: Could not find FinishedTankEvents for PMTTime " + std::to_string(PMTTime), v_warning, verbosityEBSaver);
}

ANNIEEvent->Set("Hits", PMTHits, true);
ANNIEEvent->Set("RecoADCData", PMTRecoADCHits);
ANNIEEvent->Set("AuxHits", PMTHitsAux, true);
Expand Down Expand Up @@ -1029,6 +1052,7 @@ bool EBSaver::SaveOrphanLAPPD(int runCode)
bool EBSaver::GotAllDataFromOriginalBuffer()
{
// got PMT data
bool gotRawTankEvents = m_data->CStore.Get("FinishedTankEvents", FinishedTankEvents);
bool gotPMTHits = m_data->CStore.Get("InProgressHits", InProgressHits);
bool gotPMTChkey = m_data->CStore.Get("InProgressChkey", InProgressChkey);
bool gotIPRecoADCHits = m_data->CStore.Get("InProgressRecoADCHits", InProgressRecoADCHits);
Expand All @@ -1038,10 +1062,12 @@ bool EBSaver::GotAllDataFromOriginalBuffer()
bool gotRWM = m_data->CStore.Get("RWMRawWaveforms", RWMRawWaveforms);
bool gotBRF = m_data->CStore.Get("BRFRawWaveforms", BRFRawWaveforms);

if (!gotPMTHits || !gotPMTChkey || !gotIPRecoADCHits || !gotIPHitsAux || !gotIPRADCH || !gotFRAS)
if (!gotRawTankEvents || !gotPMTHits || !gotPMTChkey || !gotIPRecoADCHits || !gotIPHitsAux || !gotIPRADCH || !gotFRAS)
{
Log("EBSaver: Failed to get some PMT data from buffer", v_message, verbosityEBSaver);
// print which one was failed
if (!gotRawTankEvents)
Log("EBSaver: Failed to get raw PMT Waveforms from buffer", v_message, verbosityEBSaver);
if (!gotPMTHits)
Log("EBSaver: Failed to get PMT hits from buffer", v_message, verbosityEBSaver);
if (!gotPMTChkey)
Expand Down Expand Up @@ -1179,6 +1205,7 @@ void EBSaver::SetDataObjects()
{
// after erase those data, set them back to CStore
// set PMT data
m_data->CStore.Set("FinishedTankEvents", FinishedTankEvents);
m_data->CStore.Set("InProgressHits", InProgressHits);
m_data->CStore.Set("InProgressChkey", InProgressChkey);
m_data->CStore.Set("InProgressRecoADCHits", InProgressRecoADCHits);
Expand Down Expand Up @@ -1229,12 +1256,14 @@ void EBSaver::SetDataObjects()

void EBSaver::BuildEmptyPMTData()
{
std::map<std::vector<int>, std::vector<Waveform<uint16_t>>> RawWaveformMap;
std::map<unsigned long, std::vector<Hit>> *PMTHits = new std::map<unsigned long, std::vector<Hit>>;
std::map<unsigned long, std::vector<std::vector<ADCPulse>>> PMTRecoADCHits;
std::map<unsigned long, std::vector<Hit>> *PMTHitsAux = new std::map<unsigned long, std::vector<Hit>>;
std::map<unsigned long, std::vector<std::vector<ADCPulse>>> PMTRecoADCHitsAux;
std::map<unsigned long, std::vector<int>> PMTRawAcqSize;

ANNIEEvent->Set("RawWaveformMap", RawWaveformMap);
ANNIEEvent->Set("Hits", PMTHits, true);
ANNIEEvent->Set("RecoADCData", PMTRecoADCHits);
ANNIEEvent->Set("AuxHits", PMTHitsAux, true);
Expand Down
4 changes: 4 additions & 0 deletions UserTools/EBSaver/EBSaver.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
* $Date: 2024/04 $
* Contact: yuef@iaistate.edu
*
* Updated by: Anuj Gupta (2026.09.25)
*
*/

class EBSaver : public Tool
Expand Down Expand Up @@ -131,6 +133,8 @@ class EBSaver : public Tool
int PPSMain;

// PMT related data object
std::map<uint64_t, std::map<std::vector<int>, std::vector<uint16_t>>>* FinishedTankEvents = nullptr; // Key: {MTCTime}, value: map of raw, uncalibrated waveforms

std::map<uint64_t, std::map<unsigned long, std::vector<Hit>> *> *InProgressHits; // Key: {MTCTime}, value: map of Hit distributions
std::map<uint64_t, std::vector<unsigned long>> *InProgressChkey; // Key: {MTCTime}, value: vector of in progress chankeys
std::map<uint64_t, std::map<unsigned long, std::vector<std::vector<ADCPulse>>>> *InProgressRecoADCHits; // Key: {MTCTime}, value: map of found pulses
Expand Down
Loading
Loading