diff --git a/core/data/psd/CbmPsdDigi.cxx b/core/data/psd/CbmPsdDigi.cxx index 124ad925f7397f6bfac6b839f98ad8c4f31949c3..16f6668fdc36864e3aed15def51bd2eef7c8cda5 100644 --- a/core/data/psd/CbmPsdDigi.cxx +++ b/core/data/psd/CbmPsdDigi.cxx @@ -22,30 +22,61 @@ CbmPsdDigi::CbmPsdDigi() {} // --- Constructor with assignment -CbmPsdDigi::CbmPsdDigi(UInt_t address, Double_t edep, Double_t time) : fdEdep(edep), fdTime(time), fuAddress(address) {} +CbmPsdDigi::CbmPsdDigi(UInt_t address, Double_t time, Double_t edep) : fuAddress(address), fdTime(time), fdEdep(edep){} // --- Constructor with module and section number CbmPsdDigi::CbmPsdDigi(UInt_t moduleId, UInt_t sectionId, Double_t edep, Double_t time) - : fdEdep(edep) + : fuAddress(0) , fdTime(time) - , fuAddress(0) + , fdEdep(edep) { fuAddress = CbmPsdAddress::GetAddress(moduleId, sectionId); } // --- Copy constructor -CbmPsdDigi::CbmPsdDigi(const CbmPsdDigi& digiIn) - : fdEdep(digiIn.fdEdep) - , fdTime(digiIn.fdTime) - , fuAddress(digiIn.fuAddress) +CbmPsdDigi::CbmPsdDigi(const CbmPsdDigi& other) + : fuAddress(other.fuAddress) + , fdTime(other.fdTime) + , fdEdep(other.fdEdep) + , fuZL(other.fuZL) + , fdAccum(other.fdAccum) + , fdAdcTime(other.fdAdcTime) + + , fdEdepWfm(other.fdEdepWfm) + , fdAmpl(other.fdAmpl) + , fuTimeMax(other.fuTimeMax) + + , fdFitAmpl(other.fdFitAmpl) + , fdFitZL(other.fdFitZL) + , fdFitEdep(other.fdFitEdep) + , fdFitR2(other.fdFitR2) + , fdFitTimeMax(other.fdFitTimeMax) { } // --- Move constructor -CbmPsdDigi::CbmPsdDigi(CbmPsdDigi&& other) : fdEdep(other.fdEdep), fdTime(other.fdTime), fuAddress(other.fuAddress) {} +CbmPsdDigi::CbmPsdDigi(CbmPsdDigi&& other) + : fuAddress(other.fuAddress) + , fdTime(other.fdTime) + , fdEdep(other.fdEdep) + , fuZL(other.fuZL) + , fdAccum(other.fdAccum) + , fdAdcTime(other.fdAdcTime) + + , fdEdepWfm(other.fdEdepWfm) + , fdAmpl(other.fdAmpl) + , fuTimeMax(other.fuTimeMax) + + , fdFitAmpl(other.fdFitAmpl) + , fdFitZL(other.fdFitZL) + , fdFitEdep(other.fdFitEdep) + , fdFitR2(other.fdFitR2) + , fdFitTimeMax(other.fdFitTimeMax) +{ +} // --- Destructor @@ -53,12 +84,25 @@ CbmPsdDigi::~CbmPsdDigi() {} // --- Assignment operator -CbmPsdDigi& CbmPsdDigi::operator=(const CbmPsdDigi& rhs) +CbmPsdDigi& CbmPsdDigi::operator=(const CbmPsdDigi& other) { - if (this != &rhs) { - fdEdep = rhs.fdEdep; - fdTime = rhs.fdTime; - fuAddress = rhs.fuAddress; + if (this != &other) { + fuAddress = other.fuAddress; + fdTime = other.fdTime; + fdEdep = other.fdEdep; + fuZL = other.fuZL; + fdAccum = other.fdAccum; + fdAdcTime = other.fdAdcTime; + + fdEdepWfm = other.fdEdepWfm; + fdAmpl = other.fdAmpl; + fuTimeMax = other.fuTimeMax; + + fdFitAmpl = other.fdFitAmpl; + fdFitZL = other.fdFitZL; + fdFitEdep = other.fdFitEdep; + fdFitR2 = other.fdFitR2; + fdFitTimeMax = other.fdFitTimeMax; } return *this; } @@ -68,9 +112,22 @@ CbmPsdDigi& CbmPsdDigi::operator=(const CbmPsdDigi& rhs) CbmPsdDigi& CbmPsdDigi::operator=(CbmPsdDigi&& other) { if (this != &other) { - fdEdep = other.fdEdep; - fdTime = other.fdTime; fuAddress = other.fuAddress; + fdTime = other.fdTime; + fdEdep = other.fdEdep; + fuZL = other.fuZL; + fdAccum = other.fdAccum; + fdAdcTime = other.fdAdcTime; + + fdEdepWfm = other.fdEdepWfm; + fdAmpl = other.fdAmpl; + fuTimeMax = other.fuTimeMax; + + fdFitAmpl = other.fdFitAmpl; + fdFitZL = other.fdFitZL; + fdFitEdep = other.fdFitEdep; + fdFitR2 = other.fdFitR2; + fdFitTimeMax = other.fdFitTimeMax; } return *this; } @@ -86,10 +143,11 @@ void CbmPsdDigi::SetAddress(UInt_t moduleId, UInt_t sectionId) // --- Info to string std::string CbmPsdDigi::ToString() const { - TString string = Form("CbmPsdDigi: address = 0x%08X Charge = %f Time = %f", fuAddress, fdEdep, fdTime); + TString string = Form("CbmPsdDigi: address = 0x%08X Charge = %.2f Time = %.2f", fuAddress, fdEdep, fdTime); return string.Data(); } + // --- Custom Streamer void CbmPsdDigi::Streamer(TBuffer& R__b) { @@ -119,6 +177,26 @@ void CbmPsdDigi::Streamer(TBuffer& R__b) R__b >> fdEdepWfm; R__b.CheckByteCount(R__s, R__c, CbmPsdDigi::IsA()); } + else if (5 == R__v) { + R__b >> fuAddress; + R__b >> fdTime; + R__b >> fdEdep; + R__b >> fuZL; + R__b >> fdAccum; + R__b >> fdAdcTime; + + R__b >> fdEdepWfm; + R__b >> fdAmpl; + R__b >> fuTimeMax; + + R__b >> fdFitAmpl; + R__b >> fdFitZL; + R__b >> fdFitEdep; + R__b >> fdFitR2; + R__b >> fdFitTimeMax; + + R__b.CheckByteCount(R__s, R__c, CbmPsdDigi::IsA()); + } } else { // The function WriteVersion does not return the version number @@ -150,7 +228,28 @@ void CbmPsdDigi::Streamer(TBuffer& R__b) R__b << fdEdepWfm; R__b.SetByteCount(R__c, kTRUE); } + if (5 == version) { + R__b << fuAddress; + R__b << fdTime; + R__b << fdEdep; + R__b << fuZL; + R__b << fdAccum; + R__b << fdAdcTime; + + R__b << fdEdepWfm; + R__b << fdAmpl; + R__b << fuTimeMax; + + R__b << fdFitAmpl; + R__b << fdFitZL; + R__b << fdFitEdep; + R__b << fdFitR2; + R__b << fdFitTimeMax; + + R__b.SetByteCount(R__c, kTRUE); + } } } + ClassImp(CbmPsdDigi) diff --git a/core/data/psd/CbmPsdDigi.h b/core/data/psd/CbmPsdDigi.h index 3f097332a8b2801f1a29975ae8815a8265953679..f511e00cb0a2ed9631c9ef2ce59199ba8c08bb26 100644 --- a/core/data/psd/CbmPsdDigi.h +++ b/core/data/psd/CbmPsdDigi.h @@ -11,10 +11,9 @@ ** \brief Data class for PSD digital information ** \version 1.0 ** - ** The information is encoded into 3*4 bytes (2 Double_t + 1 UInt_t). ** Unique Address: 32 bits following CbmPsdAddress - ** Energy deposition: 32 bits double - ** Time: 32 bits double + ** Time: 64 bits double + ** Energy deposition: 64 bits double **/ #ifndef CBMPSDDIGI_H @@ -45,7 +44,7 @@ public: ** @param edep Energy deposition ** @param time Time [ns] **/ - CbmPsdDigi(UInt_t address, Double_t edep, Double_t time); + CbmPsdDigi(UInt_t address, Double_t time, Double_t edep); /** @brief Constructor with detailed assignment. @@ -54,7 +53,7 @@ public: ** @param edep Energy deposition ** @param time Time [ns] **/ - CbmPsdDigi(UInt_t moduleId, UInt_t sectionId, Double_t edep, Double_t time); + CbmPsdDigi(UInt_t moduleId, UInt_t sectionId, Double_t time, Double_t edep); /** Copy constructor **/ @@ -77,10 +76,22 @@ public: ~CbmPsdDigi(); + /** @brief Class name (static) + ** @return CbmPsdDigi + **/ + static const char* GetClassName() { return "CbmPsdDigi"; } + + /** @brief Address ** @return Unique channel address (see CbmPsdAddress) **/ - Int_t GetAddress() const { return fuAddress; }; + UInt_t GetAddress() const { return fuAddress; }; + + + /** @brief Time + ** @return Time [ns] + **/ + Double_t GetTime() const { return fdTime; }; /** @brief Charge @@ -91,12 +102,6 @@ public: Double_t GetCharge() const { return fdEdep; }; - /** @brief Class name (static) - ** @return CbmPsdDigi - **/ - static const char* GetClassName() { return "CbmPsdDigi"; } - - /** @brief Energy deposit ** @return Energy deposit **/ @@ -121,17 +126,11 @@ public: static ECbmModuleId GetSystem() { return ECbmModuleId::kPsd; } - /** @brief Time - ** @return Time [ns] - **/ - Double_t GetTime() const { return fdTime; }; - - /** Modifiers **/ - void SetAddress(Int_t address) { fuAddress = address; }; + void SetAddress(UInt_t address) { fuAddress = address; }; void SetAddress(UInt_t moduleId, UInt_t sectionId); - void SetEdep(Double_t edep) { fdEdep = edep; } void SetTime(Double_t time) { fdTime = time; } + void SetEdep(Double_t edep) { fdEdep = edep; } /** @brief String output @@ -139,47 +138,59 @@ public: **/ std::string ToString() const; - //additional - UInt_t GetAmpl() const { return fuAmpl; }; - UInt_t GetZL() const { return fuZL; }; - Double_t GetEdepWfm() const { return fdEdepWfm; }; - void SetAmpl(UInt_t ampl) { fuAmpl = ampl; } - void SetZL(UInt_t zl) { fuZL = zl; } - void SetEdepWfm(Double_t edep) { fdEdepWfm = edep; } + UInt_t fuAddress = 0; /// Unique channel address + Double_t fdTime = -1.; /// Time of measurement [ns] + Double_t fdEdep = 0.; /// Energy deposition from FPGA [MeV] + UInt_t fuZL = 0; /// ZeroLevel from waveform [adc counts] + Double_t fdAccum = 0; /// FPGA FEE Accumulator + Double_t fdAdcTime = -1.; /// Adc time of measurement + + Double_t fdEdepWfm = 0.; /// Energy deposition from waveform [MeV] + Double_t fdAmpl = 0.; /// Amplitude from waveform [mV] + UInt_t fuTimeMax = 0; /// Time of maximum in waveform [adc samples] + + Double_t fdFitAmpl = 0.; /// Amplitude from fit of waveform [mV] + Double_t fdFitZL = 0.; /// ZeroLevel from fit of waveform [adc counts] + Double_t fdFitEdep = 0.; /// Energy deposition from fit of waveform [MeV] + Double_t fdFitR2 = 999.; /// Quality of waveform fit [] -- good near 0 + Double_t fdFitTimeMax = -1.; /// Time of maximum in fit of waveform [adc samples] + + + //LEGACY Float_t ffFitHarmonic1 = 0.; Float_t ffFitHarmonic2 = 0.; - Float_t ffFitR2 = 999.; - Float_t ffFitEdep = 0.; + Float_t ffFitR2 = 999.; + Float_t ffFitEdep = 0.; + UInt_t fuAmpl = 0; -private: - Double_t fdEdep = 0.; /// Energy deposition - Double_t fdTime = -1.; /// Time of measurement - UInt_t fuAddress = 0; /// Unique channel address - //additional - UInt_t fuAmpl = 0; - UInt_t fuZL = 0; - Double_t fdEdepWfm = 0.; +private: /// BOOST serialization interface friend class boost::serialization::access; template<class Archive> void serialize(Archive& ar, const unsigned int /*version*/) { - ar& ffFitHarmonic1; - ar& ffFitHarmonic2; - ar& ffFitR2; - ar& ffFitEdep; - ar& fdEdep; - ar& fdTime; ar& fuAddress; - ar& fuAmpl; + ar& fdTime; + ar& fdEdep; ar& fuZL; + ar& fdAccum; + ar& fdAdcTime; + ar& fdEdepWfm; + ar& fdAmpl; + ar& fuTimeMax; + + ar& fdFitAmpl; + ar& fdFitZL; + ar& fdFitEdep; + ar& fdFitR2; + ar& fdFitTimeMax; } - ClassDefNV(CbmPsdDigi, 4); + ClassDefNV(CbmPsdDigi, 5); }; #endif // CBMPSDDIGI_H diff --git a/core/data/raw/PsdGbtReader-v1.00.cxx b/core/data/raw/PsdGbtReader-v1.00.cxx index daba087ddcd116834b431f8e82110be2f3c05435..ed10df9f9017cc19d9c1035592a7780a0b748bb6 100644 --- a/core/data/raw/PsdGbtReader-v1.00.cxx +++ b/core/data/raw/PsdGbtReader-v1.00.cxx @@ -24,8 +24,9 @@ namespace PsdDataV100 void PsdGbtReader::ReadMsHeader() { MsHdr.clear(); - save_buffer.push_back(std::to_string(buffer[word_index])); - save_buffer.push_back(std::to_string(buffer[word_index + 1])); + save_buffer<<std::hex + <<std::setfill('0')<<std::setw(16)<<buffer[word_index]<<std::endl + <<std::setfill('0')<<std::setw(16)<<buffer[word_index+1]<<std::endl; MsHdr.uMagicWord = (buffer[word_index] >> 32) & 0xff; MsHdr.ulMicroSlice = ((buffer[word_index] & 0xffffff) << 40) | (buffer[word_index + 1] & 0xffffffffff); @@ -37,8 +38,9 @@ namespace PsdDataV100 void PsdGbtReader::ReadPackHeader() { PackHdr.clear(); - save_buffer.push_back(std::to_string(buffer[word_index])); - save_buffer.push_back(std::to_string(buffer[word_index + 1])); + save_buffer<<std::hex + <<std::setfill('0')<<std::setw(16)<<buffer[word_index]<<std::endl + <<std::setfill('0')<<std::setw(16)<<buffer[word_index+1]<<std::endl; buffer_shift = 0; PackHdr.uHitsNumber = (buffer[word_index] >> buffer_shift) & (((static_cast<uint16_t>(1)) << PackHdr.HNs) - 1); @@ -61,8 +63,9 @@ namespace PsdDataV100 void PsdGbtReader::ReadHitHeader() { HitHdr.clear(); - save_buffer.push_back(std::to_string(buffer[word_index])); - save_buffer.push_back(std::to_string(buffer[word_index + 1])); + save_buffer<<std::hex + <<std::setfill('0')<<std::setw(16)<<buffer[word_index]<<std::endl + <<std::setfill('0')<<std::setw(16)<<buffer[word_index+1]<<std::endl; buffer_shift = 8; HitHdr.uFeeAccum = (buffer[word_index] >> buffer_shift) & (((static_cast<uint32_t>(1)) << HitHdr.FAs) - 1); @@ -83,8 +86,9 @@ namespace PsdDataV100 void PsdGbtReader::ReadHitData() { - save_buffer.push_back(std::to_string(buffer[word_index])); - save_buffer.push_back(std::to_string(buffer[word_index + 1])); + save_buffer<<std::hex + <<std::setfill('0')<<std::setw(16)<<buffer[word_index]<<std::endl + <<std::setfill('0')<<std::setw(16)<<buffer[word_index+1]<<std::endl; uint16_t wfm_point = 0; wfm_point = ((buffer[word_index] >> 8) & 0xffff); @@ -102,7 +106,8 @@ namespace PsdDataV100 void PsdGbtReader::ReadMsTrailer() { - save_buffer.push_back(std::to_string(buffer[word_index])); + save_buffer<<std::hex + <<std::setfill('0')<<std::setw(16)<<buffer[word_index]<<std::endl; MsTrlr.uEmpty0 = buffer[word_index]; word_index++; @@ -112,9 +117,7 @@ namespace PsdDataV100 int PsdGbtReader::ReadMs() { - - - save_buffer.clear(); + std::stringstream().swap(save_buffer); //bool word_is_Ms_header = false; //ReadMsHeader(); @@ -135,7 +138,6 @@ namespace PsdDataV100 word_is_Pack_header = false; if (print) printf("End of microslice\n"); word_index -= 2; - save_buffer.pop_back(); break; //return 1; } else { @@ -169,8 +171,7 @@ namespace PsdDataV100 void PsdGbtReader::PrintSaveBuff() { - for (auto& elem : save_buffer) - printf("%s\n", elem.c_str()); + printf("%s\n", save_buffer.str().c_str()); } void PsdGbtReader::PrintOut() diff --git a/core/data/raw/PsdGbtReader-v1.00.h b/core/data/raw/PsdGbtReader-v1.00.h index 27f69cc02c8438a7ba50b09deda401922a40917c..9d463d5159946b2e2f01a5864b5eba3e4c4b9322 100644 --- a/core/data/raw/PsdGbtReader-v1.00.h +++ b/core/data/raw/PsdGbtReader-v1.00.h @@ -11,6 +11,8 @@ #include <cstdint> // for uint16_t, uint64_t, uint32_t #include <string> // for string #include <vector> // for vector +#include <sstream> // for sstream +#include <iomanip> // for setw, setfill #include <stdint.h> // for uint64_t, uint32_t @@ -32,7 +34,7 @@ namespace PsdDataV100 buffer = input; word_index = 0; } - std::vector<std::string> save_buffer; + std::stringstream save_buffer; struct PsdMsHeader MsHdr; struct PsdPackHeader PackHdr; diff --git a/fles/mcbm2018/unpacker/CbmMcbm2018UnpackerAlgoPsd.cxx b/fles/mcbm2018/unpacker/CbmMcbm2018UnpackerAlgoPsd.cxx index b426221b4675f280a825ed78c44e834240ed66b6..44409d020a1312ced3f9335f816043ea3e920803 100644 --- a/fles/mcbm2018/unpacker/CbmMcbm2018UnpackerAlgoPsd.cxx +++ b/fles/mcbm2018/unpacker/CbmMcbm2018UnpackerAlgoPsd.cxx @@ -206,6 +206,7 @@ Bool_t CbmMcbm2018UnpackerAlgoPsd::ProcessTs(const fles::Timeslice& ts) fdTsStopTimeCore = fdTsStartTime + fdTsCoreSizeInNs; // LOG(info) << Form( "TS %5d Start %12f Stop %12f", fulCurrentTsIdx, fdTsStartTime, fdTsStopTimeCore ); + fDigiVect.clear(); /// Loop over core microslices (and overlap ones if chosen) for (fuMsIndex = 0; fuMsIndex < fuNbMsLoop; fuMsIndex++) { /// Loop over registered components @@ -218,6 +219,16 @@ Bool_t CbmMcbm2018UnpackerAlgoPsd::ProcessTs(const fles::Timeslice& ts) } // for( UInt_t uMsCompIdx = 0; uMsCompIdx < fvMsComponentsList.size(); ++uMsCompIdx ) } // for( fuMsIndex = 0; fuMsIndex < uNbMsLoop; fuMsIndex ++ ) + +for (auto &elem : fDigiVect) +{ + + if ( elem.GetSectionID() <10 && elem.fuZL < 100) { printf("NOWW %s %u %f %f\n", elem.ToString().c_str(), elem.fuZL, elem.fdAmpl, elem.ffFitEdep ); /*PsdReader.PrintSaveBuff();*/ } + + +} + + /// Sort the buffers of hits due to the time offsets applied std::sort(fDigiVect.begin(), fDigiVect.end(), [](const CbmPsdDigi& a, const CbmPsdDigi& b) -> bool { return a.GetTime() < b.GetTime(); }); @@ -293,7 +304,7 @@ Bool_t CbmMcbm2018UnpackerAlgoPsd::ProcessMs(const fles::Timeslice& ts, size_t u // Prepare variables for the loop on contents const uint64_t* pInBuff = reinterpret_cast<const uint64_t*>(msContent); - /* +/* if (uSize != 0) { printf("%u = %u 64bit messages\n", uSize, uNbMessages); for(uint32_t line_iter = 0; line_iter<uNbMessages; line_iter++){ @@ -302,42 +313,64 @@ Bool_t CbmMcbm2018UnpackerAlgoPsd::ProcessMs(const fles::Timeslice& ts, size_t u } */ - /* - if (uSize != 0) { + if ((fair::Logger::Logging(fair::Severity::debug)) && (uNbMessages > 1)){ printf("%u = %u 64bit messages\n", uSize, uNbMessages); - for(uint32_t line_iter = 0; line_iter<uNbMessages-1; line_iter+=2){ + for(uint32_t line_iter = 0; line_iter<uNbMessages-2; line_iter+=2){ printf("%010lx", (pInBuff[line_iter] &0xffffffffff)); printf("%010lx", (pInBuff[line_iter+1]&0xffffffffff)); printf(" %u - %u", line_iter+1, line_iter+2); printf("\n"); } - printf("%020lx %u\n", pInBuff[uNbMessages], uNbMessages); + printf("%020lx %u\n", pInBuff[uNbMessages-1], uNbMessages); } -*/ - if (uSize > 8) { //more than one 64 bit word + // every 80bit gbt word is decomposed into two 64bit words + if (uNbMessages > 1) { //more than one 64 bit word switch (fuRawDataVersion) { - case 000: { +// -------------------------------------------------------------------------------------------------- + case 100: { - PsdDataV000::PsdGbtReader PsdReader(pInBuff); - //PsdReader.SetPrintOutMode(true); + PsdDataV100::PsdGbtReader PsdReader(pInBuff); + //if (fair::Logger::Logging(fair::Severity::debug)) PsdReader.SetPrintOutMode(true); while (PsdReader.GetTotalGbtWordsRead() < uNbMessages) { - int ReadResult = PsdReader.ReadEventFles(); - if (PsdReader.EvHdrAb.uHitsNumber > fviPsdChUId.size()) { - LOG(error) << "too many triggered channels! In header: " << PsdReader.EvHdrAb.uHitsNumber - << " in PSD: " << fviPsdChUId.size(); - break; - } - + int ReadResult = PsdReader.ReadMs(); + if (fair::Logger::Logging(fair::Severity::debug)) { printf("\n"); PsdReader.PrintOut(); /*PsdReader.PrintSaveBuff();*/ } if (ReadResult == 0) { + + double prev_hit_time = (double) fulCurrentMsIdx + PsdReader.VectPackHdr.at(0).uAdcTime * 12.5; //in ns //hit loop - for (int hit_iter = 0; hit_iter < PsdReader.EvHdrAb.uHitsNumber; hit_iter++) { - UInt_t uHitChannel = PsdReader.VectHitHdr.at(hit_iter).uHitChannel; - UInt_t uSignalCharge = PsdReader.VectHitHdr.at(hit_iter).uSignalCharge; - UInt_t uZeroLevel = PsdReader.VectHitHdr.at(hit_iter).uZeroLevel; + for (uint64_t hit_iter = 0; hit_iter < PsdReader.VectHitHdr.size(); hit_iter++) { + if (PsdReader.VectPackHdr.size() != PsdReader.VectHitHdr.size()) { + LOG(error) << "Different vector headers sizes!" + << " in VectPackHdr " << PsdReader.VectPackHdr.size() << " in VectHitHdr " + << PsdReader.VectHitHdr.size() << "\n"; + break; + } + + uint8_t uHitChannel = PsdReader.VectHitHdr.at(hit_iter).uHitChannel; + uint8_t uLinkIndex = PsdReader.VectPackHdr.at(hit_iter).uLinkIndex; + uint32_t uSignalCharge = PsdReader.VectHitHdr.at(hit_iter).uSignalCharge; + uint16_t uZeroLevel = PsdReader.VectHitHdr.at(hit_iter).uZeroLevel; + double dHitTime = (double) fulCurrentMsIdx + PsdReader.VectPackHdr.at(hit_iter).uAdcTime * 12.5; //in ns + //double dHitTime = PsdReader.MsHdr.ulMicroSlice*1000. + PsdReader.VectPackHdr.at(hit_iter).uAdcTime*12.5; //in ns std::vector<uint16_t> uWfm = PsdReader.VectHitData.at(hit_iter).uWfm; + int32_t iHitAmlpitude = 0; + int32_t iHitChargeWfm = 0; + uint8_t uHitTimeMax = 0; + if (!uWfm.empty()) { + iHitChargeWfm = std::accumulate(uWfm.begin(), uWfm.end(), 0); + iHitChargeWfm -= uZeroLevel * uWfm.size(); + + auto const max_iter = std::max_element(uWfm.begin(), uWfm.end()); + assert(max_iter != uWfm.end()); + if (max_iter == uWfm.end()) break; + + uHitTimeMax = std::distance(uWfm.begin(), max_iter); + iHitAmlpitude = *max_iter - uZeroLevel; + } + if (uHitChannel >= fviPsdChUId.size()) { LOG(error) << "hit channel number out of range! channel index: " << uHitChannel << " max: " << fviPsdChUId.size(); @@ -348,44 +381,43 @@ Bool_t CbmMcbm2018UnpackerAlgoPsd::ProcessMs(const fles::Timeslice& ts, size_t u UInt_t uRpdChId = uChId; //Should be map(uChId) TODO UInt_t uChanUId = fviPsdChUId[uRpdChId]; //unique ID - UInt_t uHitAmlpitude = 0; - UInt_t uHitChargeWfm = 0; - for (UInt_t wfm_iter = 0; wfm_iter < uWfm.size(); wfm_iter++) { - if (uWfm.at(wfm_iter) > uHitAmlpitude) uHitAmlpitude = uWfm.at(wfm_iter); - uHitChargeWfm += uWfm.at(wfm_iter) - uZeroLevel; - } - uHitAmlpitude -= uZeroLevel; - - //printf("0x%08x %u %u %u %f %f\n", uChanUId, uChId, CbmPsdAddress::GetModuleId(uChanUId), CbmPsdAddress::GetSectionId(uChanUId), (double)PsdReader.VectHitHdr.at(hit_iter).uSignalCharge, (double)PsdReader.EvHdrAc.uAdcTime ); + double dEdep = (double) uSignalCharge / fUnpackPar->GetMipCalibration(uHitChannel); // ->now in MeV + double dEdepWfm = (double) iHitChargeWfm / fUnpackPar->GetMipCalibration(uHitChannel); // ->now in MeV + double dAmpl = (double) iHitAmlpitude / 16.5; // -> now in mV - Double_t dAdcTime = - (double) PsdReader.EvHdrAb.ulMicroSlice + (double) PsdReader.EvHdrAc.uAdcTime * 12.5 - fdTimeOffsetNs; + CbmPsdDigi digi; + digi.fuAddress = uChanUId; + digi.fdTime = dHitTime; + digi.fdEdep = dEdep; + digi.fuZL = uZeroLevel; + digi.fdAccum = (double) PsdReader.VectHitHdr.at(hit_iter).uFeeAccum; + digi.fdAdcTime = (double) PsdReader.VectPackHdr.at(hit_iter).uAdcTime; + digi.fdEdepWfm = dEdepWfm; + digi.fdAmpl = dAmpl; + digi.fuTimeMax = uHitTimeMax; + digi.ffFitEdep = uWfm.back(); - LOG(debug) << Form("Insert 0x%08x digi with charge ", uChanUId) << uSignalCharge - << Form(", at %u,", PsdReader.EvHdrAc.uAdcTime) - << " epoch: " << PsdReader.EvHdrAb.ulMicroSlice; + fDigiVect.emplace_back(digi); - //fDigiVect.emplace_back(uChanUId, (double) uSignalCharge, dAdcTime); - fDigiVect.emplace_back(uHitChannel, (double) uSignalCharge, dAdcTime); - fDigiVect.back().SetAmpl(uHitAmlpitude); - fDigiVect.back().SetEdepWfm(uHitChargeWfm); - fDigiVect.back().SetZL(uZeroLevel); + //DEBUG + if( dHitTime < prev_hit_time ) printf("negative time!\n"); + //DEBUG END + prev_hit_time = dHitTime; + //DEBUG } // for(int hit_iter = 0; hit_iter < PsdReader.EvHdrAb.uHitsNumber; hit_iter++) } else if (ReadResult == 1) { - LOG(error) << "no event headers in message!"; + LOG(error) << "no pack headers in message!"; break; } else if (ReadResult == 2) { - LOG(error) << "check number of waveform points! In header: " << PsdReader.HitHdr.uWfmPoints - << " should be: " << 8; + LOG(error) << "wrong channel! In header: " << PsdReader.HitHdr.uHitChannel; break; } else if (ReadResult == 3) { - LOG(error) << "wrong amount of hits read! In header: " << PsdReader.EvHdrAb.uHitsNumber - << " in hit vector: " << PsdReader.VectHitHdr.size(); + LOG(error) << "check number of waveform points! In header: " << PsdReader.HitHdr.uWfmWords - 1; break; } else { @@ -393,6 +425,7 @@ Bool_t CbmMcbm2018UnpackerAlgoPsd::ProcessMs(const fles::Timeslice& ts, size_t u break; } + } // while(PsdReader.GetTotalGbtWordsRead()<uNbMessages) if (uNbMessages != PsdReader.GetTotalGbtWordsRead()) @@ -400,60 +433,31 @@ Bool_t CbmMcbm2018UnpackerAlgoPsd::ProcessMs(const fles::Timeslice& ts, size_t u << " in microslice " << uNbMessages << " by PsdReader " << PsdReader.GetTotalGbtWordsRead() << "\n"; - if (fulCurrentMsIdx != PsdReader.EvHdrAb.ulMicroSlice) - LOG(error) << "Wrong MS index!" - << " in microslice " << fulCurrentMsIdx << " by PsdReader " << PsdReader.EvHdrAb.ulMicroSlice - << "\n"; break; - } - - case 100: { + } // case 100 +// -------------------------------------------------------------------------------------------------- +// -------------------------------------------------------------------------------------------------- + case 000: { - PsdDataV100::PsdGbtReader PsdReader(pInBuff); + PsdDataV000::PsdGbtReader PsdReader(pInBuff); //PsdReader.SetPrintOutMode(true); - //printf("\n"); - //PsdReader.PrintOut(); - //PsdReader.PrintSaveBuff(); - - //if (fair::Logger::Logging(fair::Severity::debug)) PsdReader.SetPrintOutMode(true); - // every 80bit gbt word is decomposed into two 64bit words - while (PsdReader.GetTotalGbtWordsRead() < uNbMessages) { - int ReadResult = PsdReader.ReadMs(); + int ReadResult = PsdReader.ReadEventFles(); + if (PsdReader.EvHdrAb.uHitsNumber > fviPsdChUId.size()) { + LOG(error) << "too many triggered channels! In header: " << PsdReader.EvHdrAb.uHitsNumber + << " in PSD: " << fviPsdChUId.size(); + break; + } if (ReadResult == 0) { //hit loop - for (uint64_t hit_iter = 0; hit_iter < PsdReader.VectHitHdr.size(); hit_iter++) { - if (PsdReader.VectPackHdr.size() != PsdReader.VectHitHdr.size()) { - LOG(error) << "Different vector headers sizes!" - << " in VectPackHdr " << PsdReader.VectPackHdr.size() << " in VectHitHdr " - << PsdReader.VectHitHdr.size() << "\n"; - break; - } - - uint8_t uHitChannel = PsdReader.VectHitHdr.at(hit_iter).uHitChannel; - // uint8_t uLinkIndex = PsdReader.VectPackHdr.at(hit_iter).uLinkIndex; - uint32_t uSignalCharge = PsdReader.VectHitHdr.at(hit_iter).uSignalCharge; - uint16_t uZeroLevel = PsdReader.VectHitHdr.at(hit_iter).uZeroLevel; - double dHitTime = (double) fulCurrentMsIdx + PsdReader.VectPackHdr.at(hit_iter).uAdcTime * 12.5; //in ns - //double dHitTime = PsdReader.MsHdr.ulMicroSlice*1000. + PsdReader.VectPackHdr.at(hit_iter).uAdcTime*12.5; //in ns + for (int hit_iter = 0; hit_iter < PsdReader.EvHdrAb.uHitsNumber; hit_iter++) { + UInt_t uHitChannel = PsdReader.VectHitHdr.at(hit_iter).uHitChannel; + UInt_t uSignalCharge = PsdReader.VectHitHdr.at(hit_iter).uSignalCharge; + UInt_t uZeroLevel = PsdReader.VectHitHdr.at(hit_iter).uZeroLevel; std::vector<uint16_t> uWfm = PsdReader.VectHitData.at(hit_iter).uWfm; - int32_t iHitAmlpitude = 0; - int32_t iHitChargeWfm = 0; - if (!uWfm.empty()) { - iHitChargeWfm = std::accumulate(uWfm.begin(), uWfm.end(), 0); - iHitChargeWfm -= uZeroLevel * uWfm.size(); - - auto const max_iter = std::max_element(uWfm.begin(), uWfm.end()); - assert(max_iter != uWfm.end()); - if (max_iter == uWfm.end()) break; - - // uint8_t hit_time_max = std::distance(uWfm.begin(), max_iter); - iHitAmlpitude = *max_iter - uZeroLevel; - } - if (uHitChannel >= fviPsdChUId.size()) { LOG(error) << "hit channel number out of range! channel index: " << uHitChannel << " max: " << fviPsdChUId.size(); @@ -464,29 +468,47 @@ Bool_t CbmMcbm2018UnpackerAlgoPsd::ProcessMs(const fles::Timeslice& ts, size_t u UInt_t uRpdChId = uChId; //Should be map(uChId) TODO UInt_t uChanUId = fviPsdChUId[uRpdChId]; //unique ID - double dEdep = (double) uSignalCharge / fUnpackPar->GetMipCalibration(uHitChannel); // ->now in MeV - double dEdepWfm = (double) iHitChargeWfm / fUnpackPar->GetMipCalibration(uHitChannel); // ->now in MeV - //double dAmpl = (double) iHitAmlpitude / 16.5; // -> now in mV - double dAmpl = uWfm.back(); + UInt_t uHitAmlpitude = 0; + UInt_t uHitChargeWfm = 0; + for (UInt_t wfm_iter = 0; wfm_iter < uWfm.size(); wfm_iter++) { + if (uWfm.at(wfm_iter) > uHitAmlpitude) uHitAmlpitude = uWfm.at(wfm_iter); + uHitChargeWfm += uWfm.at(wfm_iter) - uZeroLevel; + } + uHitAmlpitude -= uZeroLevel; + + //printf("0x%08x %u %u %u %f %f\n", uChanUId, uChId, CbmPsdAddress::GetModuleId(uChanUId), CbmPsdAddress::GetSectionId(uChanUId), (double)PsdReader.VectHitHdr.at(hit_iter).uSignalCharge, (double)PsdReader.EvHdrAc.uAdcTime ); + + Double_t dAdcTime = + (double) PsdReader.EvHdrAb.ulMicroSlice + (double) PsdReader.EvHdrAc.uAdcTime * 12.5 - fdTimeOffsetNs; - fDigiVect.emplace_back(uChanUId, dEdep, dHitTime); + LOG(debug) << Form("Insert 0x%08x digi with charge ", uChanUId) << uSignalCharge + << Form(", at %u,", PsdReader.EvHdrAc.uAdcTime) + << " epoch: " << PsdReader.EvHdrAb.ulMicroSlice; - fDigiVect.back().SetAmpl(dAmpl); - fDigiVect.back().SetEdepWfm(dEdepWfm); - fDigiVect.back().SetZL(uZeroLevel); + CbmPsdDigi digi; + digi.fuAddress = uChanUId; + digi.fdTime = dAdcTime; + digi.fdEdep = (double) uSignalCharge; + digi.fuAmpl = uHitAmlpitude; + digi.fdEdepWfm = (double) uHitChargeWfm; + digi.fuZL = uZeroLevel; + + fDigiVect.emplace_back(digi); } // for(int hit_iter = 0; hit_iter < PsdReader.EvHdrAb.uHitsNumber; hit_iter++) } else if (ReadResult == 1) { - LOG(error) << "no pack headers in message!"; + LOG(error) << "no event headers in message!"; break; } else if (ReadResult == 2) { - LOG(error) << "wrong channel! In header: " << PsdReader.HitHdr.uHitChannel; + LOG(error) << "check number of waveform points! In header: " << PsdReader.HitHdr.uWfmPoints + << " should be: " << 8; break; } else if (ReadResult == 3) { - LOG(error) << "check number of waveform points! In header: " << PsdReader.HitHdr.uWfmWords - 1; + LOG(error) << "wrong amount of hits read! In header: " << PsdReader.EvHdrAb.uHitsNumber + << " in hit vector: " << PsdReader.VectHitHdr.size(); break; } else { @@ -494,7 +516,6 @@ Bool_t CbmMcbm2018UnpackerAlgoPsd::ProcessMs(const fles::Timeslice& ts, size_t u break; } - } // while(PsdReader.GetTotalGbtWordsRead()<uNbMessages) if (uNbMessages != PsdReader.GetTotalGbtWordsRead()) @@ -502,11 +523,18 @@ Bool_t CbmMcbm2018UnpackerAlgoPsd::ProcessMs(const fles::Timeslice& ts, size_t u << " in microslice " << uNbMessages << " by PsdReader " << PsdReader.GetTotalGbtWordsRead() << "\n"; + if (fulCurrentMsIdx != PsdReader.EvHdrAb.ulMicroSlice) + LOG(error) << "Wrong MS index!" + << " in microslice " << fulCurrentMsIdx << " by PsdReader " << PsdReader.EvHdrAb.ulMicroSlice + << "\n"; break; - } - } + }//case 000 +// -------------------------------------------------------------------------------------------------- + + } // switch + + } //if(uNbMessages > 1) - } //if(uSize > 8) return kTRUE; diff --git a/reco/detectors/psd/CbmPsdMCbmHitProducer.cxx b/reco/detectors/psd/CbmPsdMCbmHitProducer.cxx index a1ddaee03ee5c908fffeb01f6262f234052609e5..9d2d823c821945e6b1a3c4cc90ab806730787de0 100644 --- a/reco/detectors/psd/CbmPsdMCbmHitProducer.cxx +++ b/reco/detectors/psd/CbmPsdMCbmHitProducer.cxx @@ -136,7 +136,6 @@ void CbmPsdMCbmHitProducer::ProcessDigi(CbmEvent* event, Int_t digiIndex) { const CbmPsdDigi* digi = fDigiMan->Get<CbmPsdDigi>(digiIndex); if (digi == nullptr) return; - if (digi->GetAddress() < 0) return; if (isInEnRange(digi->GetEdep())) { AddHit(event, digi->GetTime(), digi->GetEdep(), digi->GetModuleID(), digi->GetSectionID(), digiIndex); }