diff --git a/macro/run/run_unpack_online.C b/macro/run/run_unpack_online.C index 049c02a66daa2700dccb3b1a4f696c098ac747b9..1f4bc17ba3aeebdec87ab185a9b830dead8c92bf 100644 --- a/macro/run/run_unpack_online.C +++ b/macro/run/run_unpack_online.C @@ -30,7 +30,7 @@ #include <TSystem.h> #endif -std::shared_ptr<CbmTrdUnpackMonitor> GetTrdMonitor(std::string treefilename); +std::shared_ptr<CbmTrdUnpackMonitor> GetTrdMonitor(std::string treefilename, bool fasp = false); std::shared_ptr<CbmTrdSpadic> GetTrdSpadic(bool useAvgBaseline = false); std::shared_ptr<CbmStsUnpackMonitor> GetStsMonitor(std::string treefilename, bool bDebugMode = false); std::shared_ptr<CbmRichUnpackMonitor> GetRichMonitor(std::string treefilename, bool bDebugMode = false); @@ -202,9 +202,9 @@ void run_unpack_online(std::vector<std::string> publisher = {"tcp://localhost:55 // ------------- // ---- TRDFASP2D ---- - std::shared_ptr<CbmTrdUnpackConfigFasp2D> trdfasp2dconfig = nullptr; + std::shared_ptr<CbmTrdUnpackFaspConfig> trdfasp2dconfig = nullptr; - trdfasp2dconfig = std::make_shared<CbmTrdUnpackConfigFasp2D>(trdsetuptag.Data()); + trdfasp2dconfig = std::make_shared<CbmTrdUnpackFaspConfig>(trdsetuptag.Data()); if (trdfasp2dconfig) { // trdfasp2dconfig->SetDebugState(); trdfasp2dconfig->SetDoWriteOutput(); @@ -223,6 +223,7 @@ void run_unpack_online(std::vector<std::string> publisher = {"tcp://localhost:55 std::string parfilesbasepathTrdfasp2d = Form("%s/parameters/trd", srcDir.Data()); trdfasp2dconfig->SetParFilesBasePath(parfilesbasepathTrdfasp2d); trdfasp2dconfig->SetSystemTimeOffset(-1800); // [ns] value to be updated + trdfasp2dconfig->SetMonitor(dynamic_pointer_cast<CbmTrdUnpackFaspMonitor>(GetTrdMonitor(outfilename, 1))); } // ------------- @@ -324,7 +325,7 @@ void run_unpack_online(std::vector<std::string> publisher = {"tcp://localhost:55 * @brief Get the Trd Monitor. Extra function to keep default macro part more silent. * @return std::shared_ptr<CbmTrdUnpackMonitor> */ -std::shared_ptr<CbmTrdUnpackMonitor> GetTrdMonitor(std::string treefilename) +std::shared_ptr<CbmTrdUnpackMonitor> GetTrdMonitor(std::string treefilename, bool fasp = false) { // ----- Output filename and path ------------------------------------- std::string outpath = ""; @@ -368,12 +369,20 @@ std::shared_ptr<CbmTrdUnpackMonitor> GetTrdMonitor(std::string treefilename) std::vector<CbmTrdUnpackMonitor::eOtherHistos> otherhistovec = {CbmTrdUnpackMonitor::eOtherHistos::kSpadic_Info_Types, CbmTrdUnpackMonitor::eOtherHistos::kMs_Flags}; - auto monitor = std::make_shared<CbmTrdUnpackMonitor>(); - monitor->SetActiveHistos(digihistovec); - monitor->SetActiveHistos(rawhistovec); - monitor->SetActiveHistos(otherhistovec); - monitor->SetWriteToFile(outfilename.data()); - + if (!fasp) { // SPADIC monitor + auto monitor = std::make_shared<CbmTrdUnpackMonitor>(); + monitor->SetActiveHistos(digihistovec); + monitor->SetActiveHistos(rawhistovec); + monitor->SetActiveHistos(otherhistovec); + monitor->SetWriteToFile(outfilename.data()); + } + else { // FASP monitoring settings + auto monitor = std::make_shared<CbmTrdUnpackFaspMonitor>(); + monitor->SetActiveHistos(digihistovec); + //monitor->SetActiveHistos(rawhistovec); + //monitor->SetActiveHistos(otherhistovec); + monitor->SetWriteToFile(outfilename.data()); + } return monitor; } diff --git a/macro/run/run_unpack_tsa.C b/macro/run/run_unpack_tsa.C index d22c2533acb7bc9d0f9113e9636b4d40a33ce2a3..fd3314440503f9bbfb4562a43d15466323923c9c 100644 --- a/macro/run/run_unpack_tsa.C +++ b/macro/run/run_unpack_tsa.C @@ -28,7 +28,7 @@ #include <TSystem.h> #endif -std::shared_ptr<CbmTrdUnpackMonitor> GetTrdMonitor(std::string treefilename); +std::shared_ptr<CbmTrdUnpackMonitor> GetTrdMonitor(std::string treefilename, bool fasp = false); std::shared_ptr<CbmTrdSpadic> GetTrdSpadic(bool useAvgBaseline = false); std::shared_ptr<CbmStsUnpackMonitor> GetStsMonitor(std::string treefilename, bool bDebugMode = false); std::shared_ptr<CbmRichUnpackMonitor> GetRichMonitor(std::string treefilename, bool bDebugMode = false); @@ -214,9 +214,9 @@ void run_unpack_tsa(std::vector<std::string> infile = {"test.tsa"}, UInt_t runid // ------------- // ---- TRDFASP2D ---- - std::shared_ptr<CbmTrdUnpackConfigFasp2D> trdfasp2dconfig = nullptr; + std::shared_ptr<CbmTrdUnpackFaspConfig> trdfasp2dconfig = nullptr; - trdfasp2dconfig = std::make_shared<CbmTrdUnpackConfigFasp2D>(trdsetuptag.Data()); + trdfasp2dconfig = std::make_shared<CbmTrdUnpackFaspConfig>(trdsetuptag.Data()); if (trdfasp2dconfig) { // trdfasp2dconfig->SetDebugState(); trdfasp2dconfig->SetDoWriteOutput(); @@ -235,6 +235,7 @@ void run_unpack_tsa(std::vector<std::string> infile = {"test.tsa"}, UInt_t runid std::string parfilesbasepathTrdfasp2d = Form("%s/parameters/trd", srcDir.Data()); trdfasp2dconfig->SetParFilesBasePath(parfilesbasepathTrdfasp2d); trdfasp2dconfig->SetSystemTimeOffset(-1800); // [ns] value to be updated + trdfasp2dconfig->SetMonitor(dynamic_pointer_cast<CbmTrdUnpackFaspMonitor>(GetTrdMonitor(outfilename, 1))); } // ------------- @@ -328,7 +329,7 @@ void run_unpack_tsa(std::vector<std::string> infile = {"test.tsa"}, UInt_t runid * @brief Get the Trd Monitor. Extra function to keep default macro part more silent. * @return std::shared_ptr<CbmTrdUnpackMonitor> */ -std::shared_ptr<CbmTrdUnpackMonitor> GetTrdMonitor(std::string treefilename) +std::shared_ptr<CbmTrdUnpackMonitor> GetTrdMonitor(std::string treefilename, bool fasp) { // ----- Output filename and path ------------------------------------- std::string outpath = ""; @@ -371,12 +372,21 @@ std::shared_ptr<CbmTrdUnpackMonitor> GetTrdMonitor(std::string treefilename) std::vector<CbmTrdUnpackMonitor::eOtherHistos> otherhistovec = {CbmTrdUnpackMonitor::eOtherHistos::kSpadic_Info_Types, CbmTrdUnpackMonitor::eOtherHistos::kMs_Flags}; - - auto monitor = std::make_shared<CbmTrdUnpackMonitor>(); - monitor->SetActiveHistos(digihistovec); - monitor->SetActiveHistos(rawhistovec); - monitor->SetActiveHistos(otherhistovec); - monitor->SetWriteToFile(outfilename.data()); + std::shared_ptr<CbmTrdUnpackMonitor> monitor(nullptr); + if (!fasp) { // SPADIC monitor + monitor = std::make_shared<CbmTrdUnpackMonitor>(); + monitor->SetActiveHistos(digihistovec); + monitor->SetActiveHistos(rawhistovec); + monitor->SetActiveHistos(otherhistovec); + monitor->SetWriteToFile(outfilename.data()); + } + else { // FASP monitoring settings + monitor = std::make_shared<CbmTrdUnpackFaspMonitor>(); + monitor->SetActiveHistos(digihistovec); + //monitor->SetActiveHistos(rawhistovec); + //monitor->SetActiveHistos(otherhistovec); + monitor->SetWriteToFile(outfilename.data()); + } return monitor; } diff --git a/reco/detectors/trd/CMakeLists.txt b/reco/detectors/trd/CMakeLists.txt index e9a9fc03226d6db00a4329d57e27d3a2e40c1b9b..7eed7e333fa33c704293fbf7642555b805b6514d 100644 --- a/reco/detectors/trd/CMakeLists.txt +++ b/reco/detectors/trd/CMakeLists.txt @@ -63,6 +63,7 @@ unpack/CbmTrdUnpackMonitor.cxx unpack/CbmTrdUnpackFaspAlgo.cxx unpack/CbmTrdUnpackFaspConfig.cxx +unpack/CbmTrdUnpackFaspMonitor.cxx qa/CbmTrdClusterizerFastQa.cxx qa/CbmTrdHitDensityQa.cxx diff --git a/reco/detectors/trd/CbmTrdRecoLinkDef.h b/reco/detectors/trd/CbmTrdRecoLinkDef.h index 1744870f32cd33be4a8e63df4d62d7dd721436f1..122fb9cdcc08fed1d05ce82ca0bbaab96abe2763 100644 --- a/reco/detectors/trd/CbmTrdRecoLinkDef.h +++ b/reco/detectors/trd/CbmTrdRecoLinkDef.h @@ -37,6 +37,7 @@ #pragma link C++ class CbmTrdUnpackFaspAlgo + ; #pragma link C++ class CbmTrdUnpackFaspConfig + ; +#pragma link C++ class CbmTrdUnpackFaspMonitor + ; #pragma link C++ class CbmTrdElectronsTrainAnn + ; #pragma link C++ class CbmTrdSetTracksPidWkn + ; diff --git a/reco/detectors/trd/unpack/CbmTrdUnpackFaspAlgo.cxx b/reco/detectors/trd/unpack/CbmTrdUnpackFaspAlgo.cxx index 33fe4a095dd7980ed55b4e633154db63030a6ef5..b5c97dc7d9578828e1bec9fd3487c249001353b5 100644 --- a/reco/detectors/trd/unpack/CbmTrdUnpackFaspAlgo.cxx +++ b/reco/detectors/trd/unpack/CbmTrdUnpackFaspAlgo.cxx @@ -69,6 +69,11 @@ Bool_t CbmTrdUnpackFaspAlgo::initParSet(FairParGenericSet* parset) fModuleId.emplace_back(digi.first); // setPar->printParams(); LOG(info) << GetName() << "::initParSet - for container " << parset->ClassName() << " modules " << fModuleId.size(); + + if (fMonitor) { + LOG(info) << fName << "::initParSet(CbmTrdParSetDigi) - Forwarding ParSetDigi to the monitor"; + fMonitor->Init(fDigiSet); + } } else if (strcmp(parset->ClassName(), "CbmTrdParSetGas") == 0) { CbmTrdParSetGas* setPar = static_cast<CbmTrdParSetGas*>(parset); @@ -264,6 +269,7 @@ bool CbmTrdUnpackFaspAlgo::pushDigis(std::vector<CbmTrdUnpackFaspAlgo::CbmTrdFas CbmTrdDigi* digi = new CbmTrdDigi(pad, lchT, lchR, imess->tlab); digi->SetAddressModule(imess->cri); digis.push_back(digi); + if (fMonitor) fMonitor->FillHistos(digi); } delete imess; } diff --git a/reco/detectors/trd/unpack/CbmTrdUnpackFaspAlgo.h b/reco/detectors/trd/unpack/CbmTrdUnpackFaspAlgo.h index 64e9fd12615661418b3c993e627a5471776d7808..4a10e8582a8d215c4e6883e86f044275c165122e 100644 --- a/reco/detectors/trd/unpack/CbmTrdUnpackFaspAlgo.h +++ b/reco/detectors/trd/unpack/CbmTrdUnpackFaspAlgo.h @@ -26,6 +26,7 @@ #include "CbmTrdDigi.h" #include "CbmTrdParFasp.h" #include "CbmTrdParSetAsic.h" +#include "CbmTrdUnpackFaspMonitor.h" #include "Timeslice.hpp" // timeslice @@ -108,12 +109,13 @@ public: */ virtual std::vector<std::pair<std::string, std::shared_ptr<FairParGenericSet>>>* GetParContainerRequest(std::string geoTag, std::uint32_t runId); + void PrintAsicMapping(); - /** - * @brief Introduce fasp index mapping - */ + /** @brief Introduce fasp index mapping*/ void SetAsicMapping(const std::map<uint32_t, uint8_t[NFASPMOD]>& map); - void PrintAsicMapping(); + /** @brief Set a predefined monitor + * @param monitor predefined unpacking monitor */ + void SetMonitor(std::shared_ptr<CbmTrdUnpackFaspMonitor> monitor) { fMonitor = monitor; } protected: /** @brief Get message type from the FASP word */ @@ -128,7 +130,9 @@ protected: ULong64_t fTime[NCRI]; /** @brief Finish function for this algorithm base clase */ - void finish() { return; } + void finish() { + if (fMonitor) fMonitor->Finish(); + } /** * @brief Additional initialisation function for all BaseR derived algorithms. @@ -181,11 +185,13 @@ protected: private: void prt_wd(uint32_t w); std::map<uint32_t, uint8_t[NFASPMOD]>* fFaspMap = nullptr; + /** @brief Potential (online) monitor for the unpacking process */ + std::shared_ptr<CbmTrdUnpackFaspMonitor> fMonitor = nullptr; std::vector<Int_t> fModuleId; CbmTrdParSetAsic fAsicPar; CbmTrdParSetDigi* fDigiSet = nullptr; - ClassDef(CbmTrdUnpackFaspAlgo, 2) // unpack FASP read-out detectors + ClassDef(CbmTrdUnpackFaspAlgo, 3) // unpack FASP read-out detectors }; #endif // CbmTrdUnpackFaspAlgo_H diff --git a/reco/detectors/trd/unpack/CbmTrdUnpackFaspConfig.cxx b/reco/detectors/trd/unpack/CbmTrdUnpackFaspConfig.cxx index 6d071530e330e0f9bdd074c30f51826dd47eee4d..682bbe89572d74dc39aba107fa6cbb73331f3cf1 100644 --- a/reco/detectors/trd/unpack/CbmTrdUnpackFaspConfig.cxx +++ b/reco/detectors/trd/unpack/CbmTrdUnpackFaspConfig.cxx @@ -37,6 +37,9 @@ void CbmTrdUnpackFaspConfig::InitAlgo() fAlgo->SetAsicMapping(fFaspMap); /*if (fDoLog) */ fAlgo->PrintAsicMapping(); + // If we have a monitor in the config add it to the algo + if (fMonitor) fAlgo->SetMonitor(fMonitor); + // Now we have all information required to initialise the algorithm fAlgo->Init(); } diff --git a/reco/detectors/trd/unpack/CbmTrdUnpackFaspConfig.h b/reco/detectors/trd/unpack/CbmTrdUnpackFaspConfig.h index 013a5d6571fdb27f56ca8cebc8b857dbe1cd963f..ec9435808ac9d71200f38d8fb5a61f7aa5b6aad3 100644 --- a/reco/detectors/trd/unpack/CbmTrdUnpackFaspConfig.h +++ b/reco/detectors/trd/unpack/CbmTrdUnpackFaspConfig.h @@ -23,6 +23,7 @@ #include "CbmTrdDigi.h" #include "CbmTrdParFasp.h" #include "CbmTrdUnpackFaspAlgo.h" +#include "CbmTrdUnpackFaspMonitor.h" #include <FairLogger.h> #include <Logger.h> @@ -60,9 +61,10 @@ public: /** @brief Assignment operator - not implemented **/ CbmTrdUnpackFaspConfig& operator=(const CbmTrdUnpackFaspConfig&) = delete; - /** - * @brief Initialize the algorithm, include all calibration for Trd FASP. - */ + /** @brief Get the monitor. */ + std::shared_ptr<CbmTrdUnpackFaspMonitor> GetMonitor() { return fMonitor; } + + /** @brief Initialize the algorithm, include all calibration for Trd FASP.*/ void InitAlgo(); /** @brief define fasp mapping for each module @@ -71,6 +73,10 @@ public: */ void SetFaspMapping(int modAddress, uint8_t faspMap[NFASPMOD]); + /** @brief Add a monitor to the unpacker. + * @param value CbmTrdUnpackFaspMonitor */ + void SetMonitor(std::shared_ptr<CbmTrdUnpackFaspMonitor> value) { fMonitor = value; } + protected: /** * @brief Choose the derived unpacker algorithm to be used for the DAQ output to Digi translation. If algo was already set manually by the user this algorithm is used. @@ -81,8 +87,10 @@ protected: private: std::map<uint32_t, uint8_t[NFASPMOD]> fFaspMap; ///> DAQ packing of FASP id + /** @brief pointer to the monitor object */ + std::shared_ptr<CbmTrdUnpackFaspMonitor> fMonitor = nullptr; - ClassDef(CbmTrdUnpackFaspConfig, 4) + ClassDef(CbmTrdUnpackFaspConfig, 5) }; #endif // CbmTrdUnpackFaspConfig_H diff --git a/reco/detectors/trd/unpack/CbmTrdUnpackFaspMonitor.cxx b/reco/detectors/trd/unpack/CbmTrdUnpackFaspMonitor.cxx new file mode 100644 index 0000000000000000000000000000000000000000..07cbb6b776a4407361b91bf48df3aa189538ee3f --- /dev/null +++ b/reco/detectors/trd/unpack/CbmTrdUnpackFaspMonitor.cxx @@ -0,0 +1,512 @@ +/* Copyright (C) 2021 Goethe-University Frankfurt, Frankfurt + SPDX-License-Identifier: GPL-3.0-only + Authors: Pascal Raisig [committer] */ + +#include "CbmTrdUnpackFaspMonitor.h" + +#include "CbmTrdDigi.h" +#include "CbmTrdParModDigi.h" +#include "CbmTrdRawMessageSpadic.h" + +#include <MicrosliceDescriptor.hpp> + +#include <FairRun.h> +#include <FairRunOnline.h> +#include <Logger.h> + +#include <RtypesCore.h> +#include <TFile.h> +#include <TH1.h> +#include <TH2.h> +#include <TProfile.h> + +#include <boost/math/special_functions/math_fwd.hpp> + +#include <cstdint> +#include <iostream> +#include <memory> +#include <numeric> +#include <string> +#include <utility> +#include <vector> + +#include <cmath> + +CbmTrdUnpackFaspMonitor::CbmTrdUnpackFaspMonitor(/* args */) {} + +CbmTrdUnpackFaspMonitor::~CbmTrdUnpackFaspMonitor() {} + +// ---- FillHistos ---- +void CbmTrdUnpackFaspMonitor::FillHistos(CbmTrdDigi* digi) +{ + auto moduleid = digi->GetAddressModule(); + for (auto pair : fDigiHistoMap) { + auto modulepair = pair.second.find(moduleid); + auto histo = modulepair->second; + fillHisto(digi, pair.first, moduleid, histo); + } +} + +void CbmTrdUnpackFaspMonitor::Finish() +{ + LOG(info) << Class_Name() << "::Finish() - "; + + if (fDoWriteToFile) { + size_t nhistos = 0; + + /// Save old global file and folder pointer to avoid messing with FairRoot + TFile* oldFile = gFile; + TDirectory* oldDir = gDirectory; + + /// (Re-)Create ROOT file to store the histos + TFile histofile(fOutfilename.data(), "RECREATE"); + + nhistos += writeHistosToFile(&fDigiHistoMap, &histofile); + nhistos += writeHistosToFile(&fRawHistoMap, &histofile); + + /// Restore old global file and folder pointer to avoid messing with FairRoot + gFile = oldFile; + gDirectory = oldDir; + + // histofile->Close(); + histofile.Close(); + + LOG(info) << Class_Name() << "::Finish() nHistos " << nhistos << " written to " << fOutfilename.data(); + } +} + +// ---- Init ---- +Bool_t CbmTrdUnpackFaspMonitor::Init(CbmTrdParSetDigi* digiParSet) +{ + auto modulemap = digiParSet->GetModuleMap(); + for (auto modulepair : modulemap) { + auto parmoddigi = static_cast<CbmTrdParModDigi*>(modulepair.second); + + fModuleIdsVec.emplace_back(modulepair.first); + + fModuleOrientation.emplace(std::pair<std::uint32_t, std::uint8_t>(modulepair.first, parmoddigi->GetOrientation())); + fModuleNrRows.emplace(std::pair<std::uint32_t, std::uint8_t>(modulepair.first, parmoddigi->GetNofRows())); + fModuleNrColumns.emplace(std::pair<std::uint32_t, std::uint8_t>(modulepair.first, parmoddigi->GetNofColumns())); + } + + if (fModuleOrientation.empty() || fModuleNrRows.empty() || fModuleNrColumns.empty()) return kFALSE; + + // Check if there is a HttpServer and if so we later on register the created histograms in it. + if (FairRun::Instance()->IsA() == FairRunOnline::Class()) { + auto run = static_cast<FairRunOnline*>(FairRun::Instance()); + + fHistoServer = run->GetHttpServer(); + } + + createHistos(); + + return kTRUE; +} + +// ---- createHisto ---- +void CbmTrdUnpackFaspMonitor::createHisto(eDigiHistos kHisto) +{ + std::string histoname = ""; + std::shared_ptr<TH1> newhisto = nullptr; + + for (auto moduleid : fModuleIdsVec) { + auto ncols = fModuleNrColumns.find(moduleid)->second; + auto nrows = fModuleNrRows.find(moduleid)->second; + auto nchannels = nrows * ncols; + + histoname = "ModuleId_" + std::to_string(moduleid) + "-"; + histoname += getTypeName(kHisto) + "_"; + histoname += getHistoName(kHisto); + + printf("AB :: createHisto(%s)\n", histoname.c_str()); + switch (kHisto) { + case eDigiHistos::kMap: + newhisto = std::make_shared<TH2I>(histoname.data(), histoname.data(), ncols, -0.5, (ncols - 0.5), nrows, -0.5, + (nrows - 0.5)); + newhisto->SetXTitle("Pad column"); + newhisto->SetYTitle("Pad row"); + break; + + case eDigiHistos::kCharge: + newhisto = std::make_shared<TH1I>(histoname.data(), histoname.data(), 4095, 0.5, + 4095.5); + newhisto->SetXTitle("Sgn [ADU]"); + newhisto->SetYTitle("Counts"); + break; + case eDigiHistos::kChannel: + newhisto = std::make_shared<TH1I>(histoname.data(), histoname.data(), nchannels, -0.5, (nchannels - 0.5)); + newhisto->SetXTitle("ChannelId"); + newhisto->SetYTitle("Counts"); + break; + case eDigiHistos::kDigiDeltaT: + newhisto = std::make_shared<TH2I>(histoname.data(), histoname.data(), nchannels, -0.5, (nchannels - 0.5), 3500, + -2e6, 5e6); + newhisto->SetXTitle("ChannelId"); + newhisto->SetYTitle("#DeltaT(Digi(n)-Digi(n-1)) [ns]"); + break; + default: return; + } + LOG(debug) << Class_Name() << "::CreateHisto() HistoDigi " << static_cast<size_t>(kHisto) << " Module " << moduleid + << " initialized as " << histoname.data(); + if (newhisto) { addHistoToMap<eDigiHistos>(newhisto, &fDigiHistoMap, moduleid, kHisto); } + } +} +// +// // ---- createHisto ---- +// void CbmTrdUnpackFaspMonitor::createHisto(eRawHistos kHisto) +// { +// std::string histoname = ""; +// std::shared_ptr<TH1> newhisto = nullptr; +// +// for (auto moduleid : fModuleIdsVec) { +// auto ncols = fModuleNrColumns.find(moduleid)->second; +// auto nrows = fModuleNrRows.find(moduleid)->second; +// auto nchannels = nrows * ncols; +// +// histoname = "ModuleId_" + std::to_string(moduleid) + "-"; +// histoname += getTypeName(kHisto) + "_"; +// histoname += getHistoName(kHisto); +// switch (kHisto) { +// case eRawHistos::kSignalshape: +// case eRawHistos::kSignalshape_St: +// case eRawHistos::kSignalshape_Nt: +// newhisto = std::make_shared<TH2I>(histoname.data(), histoname.data(), 32, -0.5, 31.5, 520, -260, 260); +// newhisto->SetXTitle("ADC Sample [CC]"); +// newhisto->SetYTitle("ADC Value [a.u.]"); +// break; +// case eRawHistos::kMap: +// case eRawHistos::kMap_St: +// case eRawHistos::kMap_Nt: +// newhisto = std::make_shared<TH2I>(histoname.data(), histoname.data(), 42, -0.5, 41.5, 16, -0.5, 15.5); +// newhisto->SetXTitle("ElinkId"); +// newhisto->SetYTitle("eLink-ChannelId"); +// break; +// case eRawHistos::kElinkId: +// newhisto = std::make_shared<TH1I>(histoname.data(), histoname.data(), 42, -0.5, 41.5); +// newhisto->SetXTitle("ElinkId"); +// newhisto->SetYTitle("Counts"); +// break; +// case eRawHistos::kSampleDistStdDev: +// newhisto = std::make_shared<TH1F>(histoname.data(), histoname.data(), 200, 0.0, 100.0); +// newhisto->SetXTitle("ADC signal std. deviation [#sigma]"); +// newhisto->SetYTitle("Counts"); +// break; +// case eRawHistos::kSample0perChannel: +// newhisto = std::make_shared<TH2I>(histoname.data(), histoname.data(), nchannels, -0.5, (nchannels - 0.5), 601, +// -300, 300); +// newhisto->SetXTitle("ChannelId"); +// newhisto->SetYTitle("ADC Value(Sample-0) [a.u.]"); +// break; +// case eRawHistos::kHitType: +// newhisto = std::make_shared<TH1I>(histoname.data(), histoname.data(), +// static_cast<Int_t>(Spadic::eTriggerType::kGlobal) + 1, -0.5, +// (static_cast<Int_t>(Spadic::eTriggerType::kSandN) + 0.5)); +// newhisto->SetXTitle("Spadic::eTriggerType"); +// newhisto->SetYTitle("Counts"); +// break; +// default: return; break; +// } +// LOG(debug) << Class_Name() << "::CreateHisto() HistoRaw " << static_cast<size_t>(kHisto) << " Module " << moduleid +// << "initialized as " << histoname.data(); +// /** @todo the part below is in principle copy paste for all histo types, so we should be able to move this to a single function */ +// if (newhisto) { addHistoToMap<eRawHistos>(newhisto, &fRawHistoMap, moduleid, kHisto); } +// } +// } +// +// // ---- createHisto ---- +// void CbmTrdUnpackFaspMonitor::createHisto(eOtherHistos kHisto) +// { +// std::string histoname = ""; +// std::shared_ptr<TH1> newhisto = nullptr; +// +// for (auto moduleid : fModuleIdsVec) { +// histoname = "ModuleId_" + std::to_string(moduleid) + "-"; +// histoname += getTypeName(kHisto) + "_"; +// histoname += getHistoName(kHisto); +// switch (kHisto) { +// case eOtherHistos::kSpadic_Info_Types: { +// auto nbins = static_cast<std::uint32_t>(Spadic::MsInfoType::kNInfMsgs); +// newhisto = std::make_shared<TH1I>(histoname.data(), histoname.data(), nbins, -0.5, nbins - 0.5); +// newhisto->SetXTitle("Info message type"); +// newhisto->SetYTitle("Counts"); +// newhisto->GetXaxis()->SetBinLabel((static_cast<int>(Spadic::MsInfoType::kBOM) + 1), "BOM"); +// newhisto->GetXaxis()->SetBinLabel((static_cast<int>(Spadic::MsInfoType::kMSB) + 1), "MSB"); +// newhisto->GetXaxis()->SetBinLabel((static_cast<int>(Spadic::MsInfoType::kBUF) + 1), "BUF"); +// newhisto->GetXaxis()->SetBinLabel((static_cast<int>(Spadic::MsInfoType::kUNU) + 1), "UNU"); +// newhisto->GetXaxis()->SetBinLabel((static_cast<int>(Spadic::MsInfoType::kMIS) + 1), "MIS"); +// newhisto->GetXaxis()->SetBinLabel((static_cast<int>(Spadic::MsInfoType::kChannelBuf) + 1), "ChBuf"); +// newhisto->GetXaxis()->SetBinLabel((static_cast<int>(Spadic::MsInfoType::kOrdFifoBuf) + 1), "OrdFifoBuf"); +// newhisto->GetXaxis()->SetBinLabel((static_cast<int>(Spadic::MsInfoType::kChannelBufM) + 1), "ChBufMH"); +// ; +// break; +// } +// case eOtherHistos::kMs_Flags: { +// auto nbins = static_cast<std::uint32_t>(fles::MicrosliceFlags::DataError) + 1; +// newhisto = std::make_shared<TH1I>(histoname.data(), histoname.data(), nbins, -0.5, nbins - 0.5); +// newhisto->SetXTitle("#muSlice info/error flags"); +// newhisto->SetYTitle("Counts"); +// newhisto->GetXaxis()->SetBinLabel((static_cast<int>(fles::MicrosliceFlags::CrcValid) + 1), "CrcValid"); +// newhisto->GetXaxis()->SetBinLabel((static_cast<int>(fles::MicrosliceFlags::OverflowFlim) + 1), "OverflowFlim"); +// newhisto->GetXaxis()->SetBinLabel((static_cast<int>(fles::MicrosliceFlags::OverflowUser) + 1), "OverflowUser"); +// newhisto->GetXaxis()->SetBinLabel((static_cast<int>(fles::MicrosliceFlags::DataError) + 1), "DataError"); +// break; +// } +// default: return; break; +// } +// LOG(debug) << Class_Name() << "::CreateHisto() HistoOther " << static_cast<size_t>(kHisto) << " Module " << moduleid +// << "initialized as " << histoname.data(); +// +// if (newhisto) { addHistoToMap<eOtherHistos>(newhisto, &fOtherHistoMap, moduleid, kHisto); } +// } +// } +// +// // ---- createHistos ---- +// void CbmTrdUnpackFaspMonitor::createHistos() +// { +// for (auto kHisto : fActiveDigiHistos) { +// createHisto(kHisto); +// } +// for (auto kHisto : fActiveRawHistos) { +// createHisto(kHisto); +// } +// for (auto kHisto : fActiveOtherHistos) { +// createHisto(kHisto); +// } +// } +// +// // ---- fillHisto ---- +// void CbmTrdUnpackFaspMonitor::fillHisto(CbmTrdDigi* digi, eDigiHistos kHisto, std::uint32_t moduleid, +// std::shared_ptr<TH1> histo) +// { +// auto triggerpair = digi->GetTriggerPair(digi->GetTriggerType()); +// auto triggertype = triggerpair.first; +// auto isMultihit = triggerpair.second; +// switch (kHisto) { +// case eDigiHistos::kMap_St: { +// if (triggertype != CbmTrdDigi::eTriggerType::kSelf) { return; } +// else { +// auto addresspair = getRowAndCol(moduleid, digi->GetAddressChannel()); +// histo->Fill(addresspair.second, addresspair.first); +// break; +// } +// } +// case eDigiHistos::kMap_Nt: { +// if (triggertype != CbmTrdDigi::eTriggerType::kNeighbor) { return; } +// else { +// auto addresspair = getRowAndCol(moduleid, digi->GetAddressChannel()); +// histo->Fill(addresspair.second, addresspair.first); +// break; +// } +// } +// case eDigiHistos::kMap: { +// auto addresspair = getRowAndCol(moduleid, digi->GetAddressChannel()); +// histo->Fill(addresspair.second, addresspair.first); +// break; +// } +// +// case eDigiHistos::kCharge: histo->Fill(digi->GetCharge()); break; +// case eDigiHistos::kCharge_St: +// if (triggertype != CbmTrdDigi::eTriggerType::kSelf) { return; } +// histo->Fill(digi->GetCharge()); +// break; +// case eDigiHistos::kCharge_Nt: +// if (triggertype != CbmTrdDigi::eTriggerType::kNeighbor) { return; } +// histo->Fill(digi->GetCharge()); +// break; +// +// case eDigiHistos::kChannel: histo->Fill(digi->GetAddressChannel()); break; +// case eDigiHistos::kChannel_St: +// if (triggertype != CbmTrdDigi::eTriggerType::kSelf) { return; } +// histo->Fill(digi->GetAddressChannel()); +// break; +// case eDigiHistos::kChannel_Nt: +// if (triggertype != CbmTrdDigi::eTriggerType::kNeighbor) { return; } +// histo->Fill(digi->GetAddressChannel()); +// break; +// +// case eDigiHistos::kTriggerType: { +// if (isMultihit) histo->Fill(static_cast<int>(CbmTrdDigi::eTriggerType::kMulti)); +// histo->Fill(static_cast<int>(triggertype)); +// break; +// } +// case eDigiHistos::kDigiDeltaT: histo->Fill(digi->GetAddressChannel(), getDeltaT(digi)); break; +// +// default: return; break; +// } +// } +// +// // ---- fillHisto ---- +// void CbmTrdUnpackFaspMonitor::fillHisto(CbmTrdRawMessageSpadic* raw, eRawHistos kHisto, std::shared_ptr<TH1> histo, +// CbmTrdDigi* digi) +// { +// auto triggertype = static_cast<Spadic::eTriggerType>(raw->GetHitType()); +// switch (kHisto) { +// case eRawHistos::kSignalshape: fillSamplesHisto(histo, raw); break; +// case eRawHistos::kSignalshape_St: +// if (triggertype != Spadic::eTriggerType::kSelf && triggertype != Spadic::eTriggerType::kSandN) return; +// fillSamplesHisto(histo, raw); +// break; +// case eRawHistos::kSignalshape_Nt: +// if (triggertype != Spadic::eTriggerType::kNeigh) return; +// fillSamplesHisto(histo, raw); +// break; +// case eRawHistos::kMap: histo->Fill(raw->GetElinkId(), raw->GetChannelId()); break; +// case eRawHistos::kMap_St: +// if (triggertype != Spadic::eTriggerType::kSelf && triggertype != Spadic::eTriggerType::kSandN) return; +// histo->Fill(raw->GetElinkId(), raw->GetChannelId()); +// break; +// case eRawHistos::kMap_Nt: +// if (triggertype != Spadic::eTriggerType::kNeigh) return; +// histo->Fill(raw->GetElinkId(), raw->GetChannelId()); +// break; +// case eRawHistos::kElinkId: histo->Fill(raw->GetElinkId()); break; +// case eRawHistos::kSampleDistStdDev: histo->Fill(getSamplesStdDev(raw)); break; +// case eRawHistos::kSample0perChannel: { +// if (!digi) return; +// histo->Fill(digi->GetAddressChannel(), raw->GetSamples()->at(0)); +// break; +// } +// case eRawHistos::kHitType: histo->Fill(static_cast<int>(raw->GetHitType())); break; +// default: return; break; +// } +// } +// +// // ---- fillSamplesHisto ---- +// void CbmTrdUnpackFaspMonitor::fillSamplesHisto(std::shared_ptr<TH1> histo, CbmTrdRawMessageSpadic* raw) +// { +// for (size_t isample = 0; isample < raw->GetSamples()->size(); isample++) { +// histo->Fill(isample, raw->GetSamples()->at(isample)); +// } +// } +// +// // ---- getDeltaT ---- +// std::double_t CbmTrdUnpackFaspMonitor::getDeltaT(CbmTrdDigi* digi) +// { +// auto moduleid = digi->GetAddressModule(); +// auto channelid = digi->GetAddressChannel(); +// auto modulevecpair = fLastDigiTimeMap.find(moduleid); +// if (modulevecpair == fLastDigiTimeMap.end()) { +// auto nchannels = fModuleNrColumns.find(moduleid)->second * fModuleNrRows.find(moduleid)->second; +// std::vector<size_t> channelsvec(nchannels, 0); +// if (channelid > nchannels) return 0; +// channelsvec.at(channelid) = digi->GetTime(); +// auto pair = std::make_pair(moduleid, channelsvec); +// fLastDigiTimeMap.emplace(pair); +// return digi->GetTime(); +// ; +// } +// else { +// auto prevtime = modulevecpair->second.at(channelid); +// modulevecpair->second.at(channelid) = digi->GetTime(); +// auto dt = digi->GetTime() - prevtime; +// return dt; +// } +// } +// +// // ---- getHistoName ---- +// std::string CbmTrdUnpackFaspMonitor::getHistoName(eDigiHistos kHisto) +// { +// std::string histoname = ""; +// +// switch (kHisto) { +// case eDigiHistos::kMap: histoname += "Map"; break; +// case eDigiHistos::kMap_St: histoname += "Map_St"; break; +// case eDigiHistos::kMap_Nt: histoname += "Map_Nt"; break; +// case eDigiHistos::kCharge: histoname += "Charge"; break; +// case eDigiHistos::kCharge_St: histoname += "Charge_St"; break; +// case eDigiHistos::kCharge_Nt: histoname += "Charge_Nt"; break; +// case eDigiHistos::kChannel: histoname += "Channel"; break; +// case eDigiHistos::kChannel_St: histoname += "Channel_St"; break; +// case eDigiHistos::kChannel_Nt: histoname += "Channel_Nt"; break; +// case eDigiHistos::kTriggerType: histoname += "TriggerType"; break; +// case eDigiHistos::kDigiDeltaT: histoname += "DigiDeltaT"; break; +// } +// return histoname; +// } +// +// // ---- getHistoName ---- +// std::string CbmTrdUnpackFaspMonitor::getHistoName(eRawHistos kHisto) +// { +// std::string histoname = ""; +// +// switch (kHisto) { +// case eRawHistos::kSignalshape: histoname += "Signalshape"; break; +// case eRawHistos::kSignalshape_St: histoname += "Signalshape_St"; break; +// case eRawHistos::kSignalshape_Nt: histoname += "Signalshape_Nt"; break; +// case eRawHistos::kMap: histoname += "Map"; break; +// case eRawHistos::kMap_St: histoname += "Map_St"; break; +// case eRawHistos::kMap_Nt: histoname += "Map_Nt"; break; +// case eRawHistos::kElinkId: histoname += "ElinkId"; break; +// case eRawHistos::kSampleDistStdDev: histoname += "SampleDistStdDev"; break; +// case eRawHistos::kSample0perChannel: histoname += "Sample0perChannel"; break; +// case eRawHistos::kHitType: histoname += "HitType"; break; +// } +// return histoname; +// } +// +// // ---- getHistoName ---- +// std::string CbmTrdUnpackFaspMonitor::getHistoName(eOtherHistos kHisto) +// { +// std::string histoname = ""; +// +// switch (kHisto) { +// case eOtherHistos::kSpadic_Info_Types: histoname += "Spadic_Info_Types"; break; +// case eOtherHistos::kMs_Flags: histoname += "Ms_Flags"; break; +// } +// return histoname; +// } +// +// // ---- getHistoType ---- +// std::string CbmTrdUnpackFaspMonitor::getHistoType(std::shared_ptr<TH1> histo) +// { +// std::string histoname = histo->GetName(); +// // The type follows on the module id separated by the first occurance of "-" +// auto startpos = histoname.find_first_of("-"); +// // Now we are positioned at "-" so we move one further to get the correct place +// startpos++; +// // Extract the type from the rest of the string +// auto length = histoname.find_first_of("_", startpos) - startpos; +// auto histotype = histoname.substr(startpos, length); +// +// return histotype; +// } +// +// // ---- getRowAndCol ---- +// std::pair<std::uint32_t, std::uint32_t> CbmTrdUnpackFaspMonitor::getRowAndCol(std::uint32_t moduleid, +// std::uint32_t channelid) +// { +// // Check if we have to rotate the address, is true in case of 180(2) or 270(3) degree rotation +// bool doRotate = fModuleOrientation.find(moduleid)->second / 2; +// bool isYsensitive = fModuleOrientation.find(moduleid)->second % 2; +// auto nrows = static_cast<std::uint32_t>(fModuleNrRows.find(moduleid)->second); +// auto ncols = static_cast<std::uint32_t>(fModuleNrColumns.find(moduleid)->second); +// +// // Potentially rotate the address +// std::uint32_t rotatedid = doRotate ? (channelid * (-1) + (nrows * ncols) - 1) : channelid; +// +// auto row = rotatedid / ncols; +// auto col = rotatedid % ncols; +// +// // In case we have a chamber with the columns along x we return row,col +// if (!isYsensitive) return std::make_pair(row, col); +// else +// // In case we have a chamber with the columns along y we return col,row +// return std::make_pair(col, row); +// } +// +// // ---- getSamplesStdDev ---- +// std::float_t CbmTrdUnpackFaspMonitor::getSamplesStdDev(CbmTrdRawMessageSpadic* raw) +// { +// std::float_t sum = std::accumulate(raw->GetSamples()->begin(), raw->GetSamples()->end(), 0); +// +// std::float_t mean = sum / raw->GetNrSamples(); +// +// std::float_t dev = 0; +// +// for (auto sample : *raw->GetSamples()) { +// dev += (sample - mean) * (sample - mean); +// } +// return std::sqrt(1.0 / raw->GetNrSamples() * dev); +// } + +ClassImp(CbmTrdUnpackFaspMonitor) diff --git a/reco/detectors/trd/unpack/CbmTrdUnpackFaspMonitor.h b/reco/detectors/trd/unpack/CbmTrdUnpackFaspMonitor.h new file mode 100644 index 0000000000000000000000000000000000000000..35d327482d5f1e14ac95de77cfb499ffd198eebd --- /dev/null +++ b/reco/detectors/trd/unpack/CbmTrdUnpackFaspMonitor.h @@ -0,0 +1,125 @@ +/* Copyright (C) 2022 Horia Hulubei National Institute of Physics and Nuclear Engineering, Bucharest + SPDX-License-Identifier: GPL-3.0-only + Authors: Alexandru Bercuci [committer] */ + +/** + * @file CbmTrdUnpackFaspMonitor.h + * @author Alexandru Bercuci (abercuci@niham.nipne.ro) + * @brief Monitor class for the unpacker algorithms (CbmTrdUnpackFasp) of FASP data + * @version 0.1 + * @date 2022-03-08 + * + * @copyright Copyright (c) 2022 + * + * This class can be attached to an unpacker algorithm class. It will + * CbmTrdDigi and CbmTrdRawMessageSpadic + * + * +*/ + +#ifndef CbmTrdUnpackFaspMonitor_H +#define CbmTrdUnpackFaspMonitor_H + +#include "CbmTrdDigi.h" +#include "CbmTrdParSetDigi.h" +#include "CbmTrdSpadic.h" +#include "CbmTrdUnpackMonitor.h" + +#include <MicrosliceDescriptor.hpp> +#include <Timeslice.hpp> + +#include <FairRunOnline.h> +#include <FairTask.h> +#include <Logger.h> + +#include <Rtypes.h> // for types +#include <RtypesCore.h> +#include <TFile.h> +#include <TH1.h> +#include <THttpServer.h> // for histogram server + +#include <cstdint> +#include <map> +#include <memory> +#include <string> +#include <vector> + +#include <cmath> + +class CbmTrdUnpackFaspMonitor : public CbmTrdUnpackMonitor { +public: +// /** @brief Enum for the predefined digi histograms. */ +// enum class eDigiHistos : size_t +// { +// kMap = 0, +// kMap_St, +// kMap_Nt, +// kChannel, +// kChannel_St, +// kChannel_Nt, +// kCharge, +// kCharge_St, +// kCharge_Nt, +// kTriggerType, +// kDigiDeltaT +// }; +// +// /** @brief Enum for the predefined raw histograms. */ +// enum class eRawHistos : size_t +// { +// kSignalshape = 0, +// kSignalshape_St, +// kSignalshape_Nt, +// kMap, +// kMap_St, +// kMap_Nt, +// kElinkId, +// kSampleDistStdDev, +// kSample0perChannel, +// kHitType, +// }; +// +// /** @brief Enum for the predefined other histograms. */ +// enum class eOtherHistos : size_t +// { +// kSpadic_Info_Types = 0, +// kMs_Flags +// }; + + /** @brief Create the Cbm Trd Unpack AlgoBase object */ + CbmTrdUnpackFaspMonitor(/* args */); + + /** @brief Destroy the Cbm Trd Unpack Task object */ + virtual ~CbmTrdUnpackFaspMonitor(); + + /** @brief Copy constructor - not implemented **/ + CbmTrdUnpackFaspMonitor(const CbmTrdUnpackFaspMonitor&) = delete; + + /** @brief Assignment operator - not implemented **/ + CbmTrdUnpackFaspMonitor& operator=(const CbmTrdUnpackFaspMonitor&) = delete; + + /** @brief fill the stored digi histograms @param digi pointer to the digi @param raw pointer to the raw msg */ + void FillHistos(CbmTrdDigi* digi); + + /** @brief Actions at the end of the run, e.g. write histos to file if flag is set. */ + void Finish(); + + // Runtime functions + /** @brief Init all required parameter informations */ + Bool_t Init(CbmTrdParSetDigi* digiParSet); + + /** @brief transfer the enums for the histos to be activated to the member vector */ + void SetActiveHistos(std::vector<eDigiHistos> vec) { fActiveDigiHistos.swap(vec); } + + /** @brief transfer the enums for the histos to be activated to the member vector */ + void SetActiveHistos(std::vector<eRawHistos> vec) { fActiveRawHistos.swap(vec); } + +protected: + /** @brief Create the actual TH1 shared_ptrs of the Digi histos */ + void createHisto(eDigiHistos kHisto); + +private: + ClassDef(CbmTrdUnpackFaspMonitor, 1) +}; + +#endif // CbmTrdUnpackFaspMonitor_H diff --git a/reco/detectors/trd/unpack/CbmTrdUnpackMonitor.h b/reco/detectors/trd/unpack/CbmTrdUnpackMonitor.h index efd6e61db05dad2a12e68b14b81e2257f8b5221d..f06701d8cd9d95160d0271a5606c6075c05a354b 100644 --- a/reco/detectors/trd/unpack/CbmTrdUnpackMonitor.h +++ b/reco/detectors/trd/unpack/CbmTrdUnpackMonitor.h @@ -198,16 +198,16 @@ protected: } /** @brief Create the actual TH1 shared_ptrs */ - void createHistos(); + virtual void createHistos(); /** @brief Create the actual TH1 shared_ptrs of the Digi histos */ - void createHisto(eDigiHistos kHisto); + virtual void createHisto(eDigiHistos kHisto); /** @brief Create the actual TH1 shared_ptrs of the Raw histos */ - void createHisto(eRawHistos kHisto); + virtual void createHisto(eRawHistos kHisto); /** @brief Create the actual TH1 shared_ptrs of the Others histos */ - void createHisto(eOtherHistos kHisto); + virtual void createHisto(eOtherHistos kHisto); /** * @brief Fill the given histo with the information from the digi @@ -217,7 +217,7 @@ protected: * @param[in] moduleid Unique module Id from which the digi came * @param[out] histo pointer to the histo (we do not want to extract it a snd time from the map) */ - void fillHisto(CbmTrdDigi* digi, eDigiHistos kHisto, std::uint32_t moduleid, std::shared_ptr<TH1> histo); + virtual void fillHisto(CbmTrdDigi* digi, eDigiHistos kHisto, std::uint32_t moduleid, std::shared_ptr<TH1> histo); /** * @brief Fill the given histo with the information from the raw message