diff --git a/fles/mcbm2018/CMakeLists.txt b/fles/mcbm2018/CMakeLists.txt index 12c2612487d6d2cc64e5ec2a8d5400ec34a6880a..ae02f061b71de82498e8810b8854ea5f57d23fe8 100644 --- a/fles/mcbm2018/CMakeLists.txt +++ b/fles/mcbm2018/CMakeLists.txt @@ -91,6 +91,8 @@ Set(SRCS monitor/CbmMcbm2018MonitorSts.cxx monitor/CbmMcbm2018MonitorMuch.cxx monitor/CbmMcbm2018MonitorMuchLite.cxx + monitor/CbmMcbm2018MonitorAlgoMuchLite.cxx + monitor/CbmMcbm2018MonitorTaskMuchLite.cxx # monitor/CbmMcbm2018MonitorTrd.cxx monitor/CbmMcbm2018MonitorTof.cxx monitor/CbmMcbm2018MonitorTofPulser.cxx diff --git a/fles/mcbm2018/CbmFlibMcbm2018LinkDef.h b/fles/mcbm2018/CbmFlibMcbm2018LinkDef.h index 6b863655de232be5a335b4142bf7e6a9492ca3e9..ea95ccbbca4c7cc8a7b2bc08ce5243416893bf90 100644 --- a/fles/mcbm2018/CbmFlibMcbm2018LinkDef.h +++ b/fles/mcbm2018/CbmFlibMcbm2018LinkDef.h @@ -40,6 +40,8 @@ #pragma link C++ class CbmMcbm2018MonitorSts; #pragma link C++ class CbmMcbm2018MonitorMuch; #pragma link C++ class CbmMcbm2018MonitorMuchLite; +#pragma link C++ class CbmMcbm2018MonitorAlgoMuchLite; +#pragma link C++ class CbmMcbm2018MonitorTaskMuchLite; //#pragma link C++ class CbmMcbm2018MonitorTrd; #pragma link C++ class CbmMcbm2018MonitorTof; #pragma link C++ class CbmMcbm2018MonitorTofPulser; diff --git a/fles/mcbm2018/monitor/CbmMcbm2018MonitorAlgoMuchLite.cxx b/fles/mcbm2018/monitor/CbmMcbm2018MonitorAlgoMuchLite.cxx new file mode 100644 index 0000000000000000000000000000000000000000..40c9bad9b2bda89bb3dba6f980f83a8e450c53b6 --- /dev/null +++ b/fles/mcbm2018/monitor/CbmMcbm2018MonitorAlgoMuchLite.cxx @@ -0,0 +1,1563 @@ +#include "CbmMcbm2018MonitorAlgoMuchLite.h" + +// Data +// +// // CbmRoot +#include "CbmFormatMsHeaderPrintout.h" +#include "CbmHistManager.h" +#include "CbmMcbm2018MuchPar.h" + +// // FairRoot +#include "FairLogger.h" +#include "FairRootManager.h" +#include "FairRun.h" +#include "FairRunOnline.h" +#include "FairRuntimeDb.h" +// +// // Root +#include "TClonesArray.h" +#include "THttpServer.h" +#include "TMath.h" +#include "TProfile.h" +#include "TROOT.h" +#include "TRandom.h" +#include "TString.h" +#include "TStyle.h" +#include <TFile.h> + +// C++11 +#include <bitset> + +// C/C++ +#include <iomanip> +#include <iostream> + +#include <stdint.h> + + +/*Bool_t bMcbmResetAlgoMuchLite = kFALSE; + Bool_t bMcbm2018WriteAlgoMuchLite = kFALSE; + Bool_t bMcbm2018ScanNoisyAlgoMuchLite = kFALSE;*/ + +CbmMcbm2018MonitorAlgoMuchLite::CbmMcbm2018MonitorAlgoMuchLite() + : CbmStar2019Algo() + , fbMuchMode(kFALSE) + , fvbMaskedComponents() + , fvmHitsInMs() + , fsHistoFilename("data/HistosMonitorMuch.root") + , fbPrintMessages(kFALSE) + , fPrintMessCtrl(stsxyter::MessagePrintMask::msg_print_Human) + , fulCurrentTsIdx(0) + , fuNbCoreMsPerTs(0) + , fuNrOfDpbs(0) + , fDpbIdIndexMap() + , fvbCrobActiveFlag() + , fuNbFebs(0) + , fuNbStsXyters(0) + , fmMsgCounter() + , fUnpackParMuch(NULL) + , fuCurrentEquipmentId(0) + , fuCurrDpbId(0) + , fuCurrDpbIdx(0) + , fiRunStartDateTimeSec(-1) + , fiBinSizeDatePlots(-1) + , fvulCurrentTsMsb() + , fvuCurrentTsMsbCycle() + , fvuInitialHeaderDone() + , fvuInitialTsMsbCycleHeader() + , fvuElinkLastTsHit() + , fvulChanLastHitTime() + , fvdChanLastHitTime() + , fvdPrevMsTime() + , fvdMsTime() + , fvdChanLastHitTimeInMs() + , fvusChanLastHitAdcInMs() + , fvmAsicHitsInMs() + , fvmFebHitsInMs() + , fiTimeIntervalRateUpdate(10) + , fviFebTimeSecLastRateUpdate() + , fviFebCountsSinceLastRateUpdate() + , fvdFebChanCountsSinceLastRateUpdate() + , Counter(0) + , Counter1(0) + , fHM(new CbmHistManager()) + , fhMuchMessType(NULL) + , fhMuchSysMessType(NULL) + , fhMuchFebChanAdcRaw_combined(NULL) + , fhMuchMessTypePerDpb(NULL) + , fhMuchSysMessTypePerDpb(NULL) + , fhStatusMessType(NULL) + , fhMsStatusFieldType(NULL) + , fhMuchHitsElinkPerDpb(NULL) + , fhRate(NULL) + , fhRateAdcCut(NULL) + , fHistPadDistr() + , fRealHistPadDistr() + , fhMuchFebChanCntRaw() + , fhMuchFebChanAdcRaw() + , fhMuchFebChanAdcRawProf() + , fhMuchFebChanRawTs() + , fhMuchFebChanHitRateEvo() + , fhMuchFebChanHitRateProf() + , fhMuchFebHitRateEvo() + , fhMuchFebHitRateEvo_mskch() + , fhMuchFebHitRateEvo_mskch_adccut() + , fhMuchFebHitRateEvo_WithoutDupli() + , fdMuchFebChanLastTimeForDist() + , fhMuchFebChanDistT() + , fhMuchFebDuplicateHitProf() + , fcMsSizeAll(NULL) + , fvMsComponentsList() + , fuMaxNbMicroslices(100) + , fvuChanNbHitsInMs() + , fuNbOverMsPerTs(0) +{ +} + +CbmMcbm2018MonitorAlgoMuchLite::~CbmMcbm2018MonitorAlgoMuchLite() {} +Bool_t CbmMcbm2018MonitorAlgoMuchLite::Init() +{ + LOG(info) << "Initializing flib StsXyter unpacker for MUCH"; + + FairRootManager* ioman = FairRootManager::Instance(); + if (ioman == NULL) { LOG(fatal) << "No FairRootManager instance"; } + + return kTRUE; +} + +void CbmMcbm2018MonitorAlgoMuchLite::Reset() {} + +void CbmMcbm2018MonitorAlgoMuchLite::Finish() +{ + + LOG(info) << "-------------------------------------"; + LOG(info) << "CbmMcbm2018MonitorAlgoMuchLite statistics are "; + LOG(info) << " Hit messages: " << fmMsgCounter[stsxyter::MessType::Hit] << "\n" + << " Ts MSB messages: " << fmMsgCounter[stsxyter::MessType::TsMsb] << "\n" + << " Dummy messages: " << fmMsgCounter[stsxyter::MessType::Dummy] << "\n" + << " Epoch messages: " << fmMsgCounter[stsxyter::MessType::Epoch] << "\n" + << " Empty messages: " << fmMsgCounter[stsxyter::MessType::Empty]; + + LOG(info) << "-------------------------------------"; + + SaveAllHistos(fsHistoFileFullname); + //SaveAllHistos(); +} + +Bool_t CbmMcbm2018MonitorAlgoMuchLite::InitContainers() +{ + LOG(info) << "Init parameter containers for CbmMcbm2018MonitorAlgoMuchLite"; + + Bool_t bInit = InitMuchParameters(); + //LOG(info) << "bInit ok."; + //if (kTRUE == bInit) CreateHistograms(); + + return bInit; +} + +Bool_t CbmMcbm2018MonitorAlgoMuchLite::ReInitContainers() +{ + LOG(info) << "ReInit parameter containers for CbmMcbm2018MonitorAlgoMuchLite"; + + return InitMuchParameters(); +} + +TList* CbmMcbm2018MonitorAlgoMuchLite::GetParList() +{ + if (nullptr == fParCList) fParCList = new TList(); + fUnpackParMuch = new CbmMcbm2018MuchPar("CbmMcbm2018MuchPar"); + fParCList->Add(fUnpackParMuch); + + return fParCList; +} + +Bool_t CbmMcbm2018MonitorAlgoMuchLite::InitMuchParameters() +{ + + fUnpackParMuch = (CbmMcbm2018MuchPar*) fParCList->FindObject("CbmMcbm2018MuchPar"); + if (nullptr == fUnpackParMuch) { + LOG(info) << "Much parameters could not be initialized"; + return kFALSE; + } + + fuNrOfDpbs = fUnpackParMuch->GetNrOfDpbs(); + LOG(info) << "Nr. of MUCH DPBs: " << fuNrOfDpbs; + + fDpbIdIndexMap.clear(); + for (UInt_t uDpb = 0; uDpb < fuNrOfDpbs; ++uDpb) { + fDpbIdIndexMap[fUnpackParMuch->GetDpbId(uDpb)] = uDpb; + LOG(info) << "Eq. ID for DPB #" << std::setw(2) << uDpb << " = 0x" << std::setw(4) << std::hex + << fUnpackParMuch->GetDpbId(uDpb) << std::dec << " => " << fDpbIdIndexMap[fUnpackParMuch->GetDpbId(uDpb)]; + } // for( UInt_t uDpb = 0; uDpb < fuNrOfDpbs; ++uDpb ) + + fuNbFebs = fUnpackParMuch->GetNrOfFebs(); + LOG(info) << "Nr. of FEBs: " << fuNbFebs; + + fuNbStsXyters = fUnpackParMuch->GetNrOfAsics(); + LOG(info) << "Nr. of StsXyter ASICs: " << fuNbStsXyters; + + fvbCrobActiveFlag.resize(fuNrOfDpbs); + //fvdFebAdcGain.resize( fuNrOfDpbs ); + // //fvdFebAdcOffs.resize( fuNrOfDpbs ); + for (UInt_t uDpb = 0; uDpb < fuNrOfDpbs; ++uDpb) { + fvbCrobActiveFlag[uDpb].resize(fUnpackParMuch->GetNbCrobsPerDpb()); + //fvdFebAdcGain[ uDpb ].resize( fUnpackParMuch->GetNbCrobsPerDpb() ); + // //fvdFebAdcOffs[ uDpb ].resize( fUnpackParMuch->GetNbCrobsPerDpb() ); + for (UInt_t uCrobIdx = 0; uCrobIdx < fUnpackParMuch->GetNbCrobsPerDpb(); ++uCrobIdx) { + fvbCrobActiveFlag[uDpb][uCrobIdx] = fUnpackParMuch->IsCrobActive(uDpb, uCrobIdx); + // fvdFebAdcGain[ uDpb ][ uCrobIdx ].resize( fUnpackParMuch->GetNbFebsPerCrob(), 0.0 ); + // //fvdFebAdcOffs[ uDpb ][ uCrobIdx ].resize( fUnpackParMuch->GetNbFebsPerCrob(), 0.0 ); + } // for( UInt_t uCrobIdx = 0; uCrobIdx < fUnpackParMuch->GetNbCrobsPerDpb(); ++uCrobIdx ) + } // for( UInt_t uDpb = 0; uDpb < fuNrOfDpbs; ++uDpb ) + + for (UInt_t uDpb = 0; uDpb < fuNrOfDpbs; ++uDpb) { + for (UInt_t uCrobIdx = 0; uCrobIdx < fUnpackParMuch->GetNbCrobsPerDpb(); ++uCrobIdx) { + LOG(info) << Form("DPB #%02u CROB #%02u Active: ", uDpb, uCrobIdx) << fvbCrobActiveFlag[uDpb][uCrobIdx]; + } // for( UInt_t uCrobIdx = 0; uCrobIdx < fUnpackParMuch->GetNbCrobsPerDpb(); ++uCrobIdx ) + } // for( UInt_t uDpb = 0; uDpb < fuNrOfDpbs; ++uDpb ) + + if (fbBinningFw) LOG(info) << "Unpacking data in bin sorter FW mode"; + else + LOG(info) << "Unpacking data in full time sorter FW mode (legacy)"; + + // Internal status initialization + LOG(info) << "Internal status initialization"; + fvulCurrentTsMsb.resize(fuNrOfDpbs); + fvuCurrentTsMsbCycle.resize(fuNrOfDpbs); + fvuInitialHeaderDone.resize(fuNrOfDpbs); + fvuInitialTsMsbCycleHeader.resize(fuNrOfDpbs); + fvuElinkLastTsHit.resize(fuNrOfDpbs); + for (UInt_t uDpb = 0; uDpb < fuNrOfDpbs; ++uDpb) { + fvulCurrentTsMsb[uDpb] = 0; + fvuCurrentTsMsbCycle[uDpb] = 0; + fvuInitialHeaderDone[uDpb] = kFALSE; + fvuInitialTsMsbCycleHeader[uDpb] = 0; + } // for( UInt_t uDpb = 0; uDpb < fuNrOfDpbs; ++uDpb ) + LOG(info) << "ongoing internal status initialization"; + + fvdPrevMsTime.resize(kiMaxNbFlibLinks); + fvulChanLastHitTime.resize(fuNbStsXyters); + fvdChanLastHitTime.resize(fuNbStsXyters); + fvdMsTime.resize(fuMaxNbMicroslices); + fvuChanNbHitsInMs.resize(fuNbFebs); + fvdChanLastHitTimeInMs.resize(fuNbFebs); + fvusChanLastHitAdcInMs.resize(fuNbFebs); + fvmAsicHitsInMs.resize(fuNbFebs); + + //fvdMsTime.resize( fuMaxNbMicroslices ); + //fvuChanNbHitsInMs.resize( fuNbStsXyters ); + //fvdChanLastHitTimeInMs.resize( fuNbStsXyters ); + //fvusChanLastHitAdcInMs.resize( fuNbStsXyters ); + //fvmAsicHitsInMs.resize( fuNbStsXyters ); + + for (UInt_t uXyterIdx = 0; uXyterIdx < fuNbFebs; ++uXyterIdx) { + fvulChanLastHitTime[uXyterIdx].resize(fUnpackParMuch->GetNbChanPerAsic()); + fvdChanLastHitTime[uXyterIdx].resize(fUnpackParMuch->GetNbChanPerAsic()); + fvuChanNbHitsInMs[uXyterIdx].resize(fUnpackParMuch->GetNbChanPerAsic()); + fvdChanLastHitTimeInMs[uXyterIdx].resize(fUnpackParMuch->GetNbChanPerAsic()); + fvusChanLastHitAdcInMs[uXyterIdx].resize(fUnpackParMuch->GetNbChanPerAsic()); + fvmAsicHitsInMs[uXyterIdx].clear(); + + for (UInt_t uChan = 0; uChan < fUnpackParMuch->GetNbChanPerAsic(); ++uChan) { + fvulChanLastHitTime[uXyterIdx][uChan] = 0; + fvdChanLastHitTime[uXyterIdx][uChan] = -1.0; + + fvuChanNbHitsInMs[uXyterIdx][uChan].resize(fuMaxNbMicroslices); + fvdChanLastHitTimeInMs[uXyterIdx][uChan].resize(fuMaxNbMicroslices); + fvusChanLastHitAdcInMs[uXyterIdx][uChan].resize(fuMaxNbMicroslices); + for (UInt_t uMsIdx = 0; uMsIdx < fuMaxNbMicroslices; ++uMsIdx) { + fvuChanNbHitsInMs[uXyterIdx][uChan][uMsIdx] = 0; + fvdChanLastHitTimeInMs[uXyterIdx][uChan][uMsIdx] = -1.0; + fvusChanLastHitAdcInMs[uXyterIdx][uChan][uMsIdx] = 0; + } // for( UInt_t uMsIdx = 0; uMsIdx < fuMaxNbMicroslices; ++uMsIdx ) + } // for( UInt_t uChan = 0; uChan < fUnpackParMuch->GetNbChanPerAsic(); ++uChan ) + } // for( UInt_t uXyterIdx = 0; uXyterIdx < fuNbStsXyters; ++uXyterIdx ) + + LOG(info) << "CbmMcbm2018MonitorAlgoMuchLite::ReInitContainers => Changed " + "fvuChanNbHitsInMs size " + << fvuChanNbHitsInMs.size() << " VS " << fuNbFebs; + LOG(info) << "CbmMcbm2018MonitorAlgoMuchLite::ReInitContainers => Changed " + "fvuChanNbHitsInMs size " + << fvuChanNbHitsInMs[0].size() << " VS " << fUnpackParMuch->GetNbChanPerAsic(); + LOG(info) << "CbmMcbm2018MonitorAlgoMuchLite::ReInitContainers => Changed " + "fvuChanNbHitsInMs size " + << fvuChanNbHitsInMs[0][0].size() << " VS " << fuMaxNbMicroslices; + + fvmFebHitsInMs.resize(fuNbFebs); + fviFebTimeSecLastRateUpdate.resize(fuNbFebs, -1); + fviFebCountsSinceLastRateUpdate.resize(fuNbFebs, -1); + fvdFebChanCountsSinceLastRateUpdate.resize(fuNbFebs); + fdMuchFebChanLastTimeForDist.resize(fuNbFebs); + for (UInt_t uFebIdx = 0; uFebIdx < fuNbFebs; ++uFebIdx) { + fvmFebHitsInMs[uFebIdx].clear(); + fvdFebChanCountsSinceLastRateUpdate[uFebIdx].resize(fUnpackParMuch->GetNbChanPerFeb(), 0.0); + fdMuchFebChanLastTimeForDist[uFebIdx].resize(fUnpackParMuch->GetNbChanPerFeb(), -1.0); + } // for( UInt_t uFebIdx = 0; uFebIdx < fuNbFebs; ++uFebIdx ) + + ///----------------- SXM 2.0 Logic Error Tagging --------------------/// + // SmxErrInitializeVariables(); + ///------------------------------------------------------------------/// + + return kTRUE; +} + +/* void CbmMcbm2018MonitorAlgoMuchLite::SetNbMsInTs(size_t uCoreMsNb, + size_t uOverlapMsNb) { + fuNbCoreMsPerTs = uCoreMsNb; + fuNbOverMsPerTs = uOverlapMsNb; + //LOG(info) <<" fuNbCoreMsPerTs "<<fuNbCoreMsPerTs<<" fuNbOverMsPerTs "<<fuNbOverMsPerTs; + UInt_t uNbMsTotal = fuNbCoreMsPerTs + fuNbOverMsPerTs; + + if (fuMaxNbMicroslices < uNbMsTotal) { + fuMaxNbMicroslices = uNbMsTotal; + fvdMsTime.resize(fuMaxNbMicroslices); + fvuChanNbHitsInMs.resize(fuNbStsXyters); + fvdChanLastHitTimeInMs.resize(fuNbStsXyters); + fvusChanLastHitAdcInMs.resize(fuNbStsXyters); + for (UInt_t uXyterIdx = 0; uXyterIdx < fuNbStsXyters; ++uXyterIdx) { + fvuChanNbHitsInMs[uXyterIdx].resize(fUnpackParMuch->GetNbChanPerAsic()); + fvdChanLastHitTimeInMs[uXyterIdx].resize( + fUnpackParMuch->GetNbChanPerAsic()); + fvusChanLastHitAdcInMs[uXyterIdx].resize( + fUnpackParMuch->GetNbChanPerAsic()); + for (UInt_t uChan = 0; uChan < fUnpackParMuch->GetNbChanPerAsic(); + ++uChan) { + fvuChanNbHitsInMs[uXyterIdx][uChan].resize(fuMaxNbMicroslices); + fvdChanLastHitTimeInMs[uXyterIdx][uChan].resize(fuMaxNbMicroslices); + fvusChanLastHitAdcInMs[uXyterIdx][uChan].resize(fuMaxNbMicroslices); + for (UInt_t uMsIdx = 0; uMsIdx < fuMaxNbMicroslices; ++uMsIdx) { + fvuChanNbHitsInMs[uXyterIdx][uChan][uMsIdx] = 0; + fvdChanLastHitTimeInMs[uXyterIdx][uChan][uMsIdx] = -1.0; + fvusChanLastHitAdcInMs[uXyterIdx][uChan][uMsIdx] = 0; + LOG(info) << "CbmMcbm2018MonitorMuchLite::DoUnpack => Changed " + "fvuChanNbHitsInMs size " + << fvuChanNbHitsInMs.size() << " VS " << fuNbStsXyters; + LOG(info) << "CbmMcbm2018MonitorMuchLite::DoUnpack => Changed " + "fvuChanNbHitsInMs size " + << fvuChanNbHitsInMs[0].size() << " VS " + << fUnpackParMuch->GetNbChanPerAsic(); + LOG(info) << "CbmMcbm2018MonitorMuchLite::DoUnpack => Changed " + "fvuChanNbHitsInMs size " + << fvuChanNbHitsInMs[0][0].size() << " VS " << fuMaxNbMicroslices; + } // if( fuMaxNbMicroslices < uNbMsTotal ) + } + } + } +} */ + + +void CbmMcbm2018MonitorAlgoMuchLite::AddMsComponentToList(size_t component, UShort_t /*usDetectorId*/) +{ + /// Check for duplicates and ignore if it is the case + for (UInt_t uCompIdx = 0; uCompIdx < fvMsComponentsList.size(); ++uCompIdx) + if (component == fvMsComponentsList[uCompIdx]) return; + + /// Check if this does not go above hardcoded limits + if (kiMaxNbFlibLinks <= component) { + LOG(error) << "CbmMcbm2018MonitorAlgoMuchLite::AddMsComponentToList => " + << "Ignored the addition of component " << component << " as it is above the hadcoded limit of " + << static_cast<Int_t>(kiMaxNbFlibLinks) << " !!!!!!!!! " + << "\n" + << " To change this behavior check kiMaxNbFlibLinks in " + "CbmMcbm2018MonitorAlgoMuchLite.cxx"; + return; + } // if( kiMaxNbFlibLinks <= component ) + + + /// Add to list + fvMsComponentsList.push_back(component); + LOG(info) << "CbmMcbm2018MonitorAlgoMuchLite::AddMsComponentToList => Added component: " << component; + + /// Create MS size monitoring histos + if (NULL == fhMsSz[component]) { + TString sMsSzName = Form("MsSz_link_%02lu", component); + TString sMsSzTitle = Form("Size of MS for nDPB of link %02lu; Ms Size [bytes]", component); + fhMsSz[component] = new TH1F(sMsSzName.Data(), sMsSzTitle.Data(), 160000, 0., 20000.); + fHM->Add(sMsSzName.Data(), fhMsSz[component]); + + sMsSzName = Form("MsSzTime_link_%02lu", component); + sMsSzTitle = Form("Size of MS vs time for gDPB of link %02lu; Time[s] ; Ms Size [bytes]", component); + fhMsSzTime[component] = new TProfile(sMsSzName.Data(), sMsSzTitle.Data(), 15000, 0., 300.); + fHM->Add(sMsSzName.Data(), fhMsSzTime[component]); + + if (NULL != fcMsSizeAll) { + fcMsSizeAll->cd(1 + component); + gPad->SetLogy(); + fhMsSzTime[component]->Draw("hist le0"); + } // if( NULL != fcMsSizeAll ) + LOG(info) << "Added MS size histo for component: " << component << " (DPB)"; + + // THttpServer* server = FairRunOnline::Instance()->GetHttpServer(); + // if (server) { + //server->Register("/FlibRaw", fhMsSz[component]); //closed by me + AddHistoToVector(fhMsSz[component], "FlibRaw"); + //server->Register("/FlibRaw", fhMsSzTime[component]);// closed by me + AddHistoToVector(fhMsSzTime[component], "FlibRaw"); + // } // if( server ) + } // if( NULL == fhMsSz[ component ] ) +} + + +Bool_t CbmMcbm2018MonitorAlgoMuchLite::CreateHistograms() +{ + TString sHistName {""}; + TString title {""}; + + sHistName = "hMessageType"; + title = "Nb of message for each type; Type"; + fhMuchMessType = new TH1I(sHistName, title, 6, 0., 6.); + fhMuchMessType->GetXaxis()->SetBinLabel(1, "Dummy"); + fhMuchMessType->GetXaxis()->SetBinLabel(2, "Hit"); + fhMuchMessType->GetXaxis()->SetBinLabel(3, "TsMsb"); + fhMuchMessType->GetXaxis()->SetBinLabel(4, "Epoch"); + fhMuchMessType->GetXaxis()->SetBinLabel(5, "Status"); + fhMuchMessType->GetXaxis()->SetBinLabel(6, "Empty"); + + + sHistName = "hSysMessType"; + title = "Nb of system message for each type; System Type"; + fhMuchSysMessType = new TH1I(sHistName, title, 17, 0., 17.); + + sHistName = "hMuchFebChanAdcRaw_combined"; + title = "ADC hist combined"; + fhMuchFebChanAdcRaw_combined = + new TH1I(sHistName, title, stsxyter::kuHitNbAdcBins, -0.5, stsxyter::kuHitNbAdcBins - 0.5); + + LOG(debug) << "Initialized 1st Histo"; + sHistName = "hMessageTypePerDpb"; + title = "Nb of message of each type for each DPB; DPB; Type"; + fhMuchMessTypePerDpb = new TH2I(sHistName, title, fuNrOfDpbs, 0, fuNrOfDpbs, 6, 0., 6.); + fhMuchMessTypePerDpb->GetYaxis()->SetBinLabel(1, "Dummy"); + fhMuchMessTypePerDpb->GetYaxis()->SetBinLabel(2, "Hit"); + fhMuchMessTypePerDpb->GetYaxis()->SetBinLabel(3, "TsMsb"); + fhMuchMessTypePerDpb->GetYaxis()->SetBinLabel(4, "Epoch"); + fhMuchMessTypePerDpb->GetYaxis()->SetBinLabel(5, "Status"); + fhMuchMessTypePerDpb->GetYaxis()->SetBinLabel(6, "Empty"); + + for (UInt_t uModuleId = 0; uModuleId < 2; ++uModuleId) { + /// Raw Ts Distribution + sHistName = Form("HistPadDistr_Module_%01u", uModuleId); + title = Form("Pad distribution for, Module #%01u; ", uModuleId); + + //Below for Rectangular Module shape VS + fHistPadDistr.push_back(new TH2I(sHistName, title, 23, -0.5, 22.5, 97, -0.5, 96.5)); + + sHistName = Form("RealHistPadDistr_Module_%01u", uModuleId); + title = Form("Progressive Pad distribution for, Module #%01u; ", uModuleId); + //Below for Progressive Geometry Module shape VS + fRealHistPadDistr.push_back(new TH2D(sHistName, title, 500, -0.5, 499.5, 1000, -0.5, 999.5)); + + + /// FEB wise Duplicate Hit profile for each Module (If same hit at same time, same channel and same FEB) + sHistName = Form("hMuchFebDuplicateHitProf_%01u", uModuleId); + title = Form("FEB wise Duplicate Hit for Module #%01u; FEB []; Hit []", uModuleId); + if (uModuleId == 0) + //fhMuchFebDuplicateHitProf.push_back( new TProfile(sHistName, title,fUnpackParMuch->GetNrOfFebsInGemA(), -0.5, fUnpackParMuch->GetNrOfFebsInGemA() - 0.5 ) ); + fhMuchFebDuplicateHitProf.push_back(new TProfile(sHistName, title, 18, -0.5, 18 - 0.5)); + if (uModuleId == 1) + //fhMuchFebDuplicateHitProf.push_back( new TProfile(sHistName, title,fUnpackParMuch->GetNrOfFebsInGemB(), -0.5, fUnpackParMuch->GetNrOfFebsInGemB() - 0.5 ) ); + fhMuchFebDuplicateHitProf.push_back(new TProfile(sHistName, title, 18, -0.5, 18 - 0.5)); + } + + sHistName = "hRate"; + title = "Rate in kHz"; + fhRate = new TH1I(sHistName, title, 10000, -0.5, 9999.5); + + sHistName = "hRateAdcCut"; + title = "Rate in kHz with Adc cut"; + fhRateAdcCut = new TH1I(sHistName, title, 10000, -0.5, 9999.5); + + + sHistName = "hFEBcount"; + title = "Count vs FEB number; FEB Number; Count"; + fhFEBcount = new TH1I(sHistName, title, 40, -0.5, 39.5); + + + sHistName = "hSysMessTypePerDpb"; + title = "Nb of system message of each type for each DPB; DPB; System Type"; + fhMuchSysMessTypePerDpb = new TH2I(sHistName, title, fuNrOfDpbs, 0, fuNrOfDpbs, 17, 0., 17.); + + sHistName = "hStatusMessType"; + title = "Nb of status message of each type for each DPB; ASIC; Status Type"; + fhStatusMessType = new TH2I(sHistName, title, fuNbStsXyters, 0, fuNbStsXyters, 16, 0., 16.); + + + sHistName = "hMsStatusFieldType"; + title = "For each flag in the MS header, ON/OFF counts; Flag bit []; ON/OFF; MS []"; + fhMsStatusFieldType = new TH2I(sHistName, title, 16, -0.5, 15.5, 2, -0.5, 1.5); + + //For mCBM March 2019 data taking we will have only one eLink enable for each FEB + sHistName = "hMuchHitsElinkPerDpb"; + title = "Nb of hit messages per eLink for each DPB; DPB; eLink; Hits nb []"; + fhMuchHitsElinkPerDpb = new TH2I(sHistName, title, fuNrOfDpbs, 0, fuNrOfDpbs, 42, 0., 42.); + + LOG(debug) << "Initialized 2nd Histo"; + /* + // Number of rate bins = + // 9 for the sub-unit decade + // + 9 for each unit of each decade * 10 for the subdecade range + // + 1 for the closing bin top edge + const Int_t iNbDecadesRate = 9; + const Int_t iNbStepsDecade = 9; + const Int_t iNbSubStepsInStep = 10; + const Int_t iNbBinsRate = iNbStepsDecade + + iNbStepsDecade * iNbSubStepsInStep * iNbDecadesRate + + 1; + Double_t dBinsRate[iNbBinsRate]; + // First fill sub-unit decade + for( Int_t iSubU = 0; iSubU < iNbStepsDecade; iSubU ++ ) + dBinsRate[ iSubU ] = 0.1 * ( 1 + iSubU ); + std::cout << std::endl; + // Then fill the main decades + Double_t dSubstepSize = 1.0 / iNbSubStepsInStep; + for( Int_t iDecade = 0; iDecade < iNbDecadesRate; iDecade ++) + { + Double_t dBase = std::pow( 10, iDecade ); + Int_t iDecadeIdx = iNbStepsDecade + + iDecade * iNbStepsDecade * iNbSubStepsInStep; + for( Int_t iStep = 0; iStep < iNbStepsDecade; iStep++ ) + { + Int_t iStepIdx = iDecadeIdx + iStep * iNbSubStepsInStep; + for( Int_t iSubStep = 0; iSubStep < iNbSubStepsInStep; iSubStep++ ) + { + dBinsRate[ iStepIdx + iSubStep ] = dBase * (1 + iStep) + + dBase * dSubstepSize * iSubStep; + } // for( Int_t iSubStep = 0; iSubStep < iNbSubStepsInStep; iSubStep++ ) + } // for( Int_t iStep = 0; iStep < iNbStepsDecade; iStep++ ) + } // for( Int_t iDecade = 0; iDecade < iNbDecadesRate; iDecade ++) + dBinsRate[ iNbBinsRate - 1 ] = std::pow( 10, iNbDecadesRate ); +*/ + LOG(debug) << "Initialized 3rd Histo"; + ///++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++/// + //UInt_t uAlignedLimit = fuLongHistoNbSeconds - (fuLongHistoNbSeconds % fuLongHistoBinSizeSec); + // UInt_t uAlignedLimit = 0; + + // UInt_t uNbBinEvo = (32768 + 1) * 2; + // Double_t dMaxEdgeEvo = stsxyter::kdClockCycleNs + // * static_cast< Double_t >( uNbBinEvo ) / 2.0; + // Double_t dMinEdgeEvo = dMaxEdgeEvo * -1.0; + + //UInt_t uNbBinDt = static_cast<UInt_t>( (fdCoincMax - fdCoincMin )/stsxyter::kdClockCycleNs ); + + // Miscroslice properties histos + for (Int_t component = 0; component < kiMaxNbFlibLinks; component++) { + fhMsSz[component] = NULL; + fhMsSzTime[component] = NULL; + } // for( Int_t component = 0; component < kiMaxNbFlibLinks; component ++ ) + + /// All histos per FEB: with channels or ASIC as axis!! + // fhMuchFebChanDtCoinc.resize( fuNbFebs ); + // fhMuchFebChanCoinc.resize( fuNbFebs ); + for (UInt_t uFebIdx = 0; uFebIdx < fuNbFebs; ++uFebIdx) { + /// Channel counts + sHistName = Form("hMuchFebChanCntRaw_%03u", uFebIdx); + title = Form("Hits Count per channel, FEB #%03u; Channel; Hits []", uFebIdx); + fhMuchFebChanCntRaw.push_back( + new TH1I(sHistName, title, fUnpackParMuch->GetNbChanPerFeb(), -0.5, fUnpackParMuch->GetNbChanPerFeb() - 0.5)); + + //sHistName = Form( "hMuchFebChanCntRawGood_%03u", uFebIdx ); + //title = Form( "Hits Count per channel in good MS (SX2 bug flag off), FEB #%03u; Channel; Hits []", uFebIdx ); + //fhMuchFebChanCntRawGood.push_back( new TH1I(sHistName, title, + // fUnpackParMuch->GetNbChanPerFeb(), -0.5, fUnpackParMuch->GetNbChanPerFeb() - 0.5 ) ); + + sHistName = Form("fhMuchFebSpill_%03u", uFebIdx); + title = Form("Time distribution of hits, FEB #%03u; Time ; Counts ", uFebIdx); + fhMuchFebSpill.push_back(new TH1I(sHistName, title, 1000, 0, 1000)); + + + sHistName = Form("hMuchChannelTime_FEB%03u", uFebIdx); + title = Form("Time vs Channel, FEB #%03u; TIME(s) ; CHANNEL ", uFebIdx); + fhMuchChannelTime.push_back(new TH2I(sHistName, title, 1000, 0, 1000, 129, -0.5, 128.5)); + + + sHistName = Form("hMuchFebADC_%03u", uFebIdx); + title = Form("CHANNEL vs ADC, FEB #%03u; CHANNEL ; ADC ", uFebIdx); + fhMuchFebADC.push_back(new TH2I(sHistName, title, 129, -0.5, 128.5, 34, -0.5, 33.5)); + + + /// Raw Adc Distribution + sHistName = Form("hMuchFebChanAdcRaw_%03u", uFebIdx); + title = Form("Raw Adc distribution per channel, FEB #%03u; Channel []; Adc " + "[]; Hits []", + uFebIdx); + fhMuchFebChanAdcRaw.push_back(new TH2I(sHistName, title, fUnpackParMuch->GetNbChanPerFeb(), -0.5, + fUnpackParMuch->GetNbChanPerFeb() - 0.5, stsxyter::kuHitNbAdcBins, -0.5, + stsxyter::kuHitNbAdcBins - 0.5)); + + /// Raw Adc Distribution profile + sHistName = Form("hMuchFebChanAdcRawProfc_%03u", uFebIdx); + title = Form("Raw Adc prodile per channel, FEB #%03u; Channel []; Adc []", uFebIdx); + fhMuchFebChanAdcRawProf.push_back( + new TProfile(sHistName, title, fUnpackParMuch->GetNbChanPerFeb(), -0.5, fUnpackParMuch->GetNbChanPerFeb() - 0.5)); + + /// Cal Adc Distribution + //sHistName = Form( "hMuchFebChanAdcCal_%03u", uFebIdx ); + //title = Form( "Cal. Adc distribution per channel, FEB #%03u; Channel []; Adc [e-]; Hits []", uFebIdx ); + //fhMuchFebChanAdcCal.push_back( new TH2I(sHistName, title, + // fUnpackParMuch->GetNbChanPerFeb(), -0.5, fUnpackParMuch->GetNbChanPerFeb() - 0.5, + // 50, 0., 100000. ) ); + + /// Cal Adc Distribution profile + //sHistName = Form( "hMuchFebChanAdcCalProfc_%03u", uFebIdx ); + //title = Form( "Cal. Adc prodile per channel, FEB #%03u; Channel []; Adc [e-]", uFebIdx ); + //fhMuchFebChanAdcCalProf.push_back( new TProfile(sHistName, title, + // fUnpackParMuch->GetNbChanPerFeb(), -0.5, fUnpackParMuch->GetNbChanPerFeb() - 0.5 ) ); + + /// Raw Ts Distribution + sHistName = Form("hMuchFebChanRawTs_%03u", uFebIdx); + title = Form("Raw Timestamp distribution per channel, FEB #%03u; Channel " + "[]; Ts []; Hits []", + uFebIdx); + fhMuchFebChanRawTs.push_back(new TH2I(sHistName, title, fUnpackParMuch->GetNbChanPerFeb(), -0.5, + fUnpackParMuch->GetNbChanPerFeb() - 0.5, stsxyter::kuHitNbTsBins, -0.5, + stsxyter::kuHitNbTsBins - 0.5)); + + /// Hit rates evo per channel + sHistName = Form("hMuchFebChanRateEvo_%03u", uFebIdx); + title = Form("Hits per second & channel in FEB #%03u; Time [s]; Channel []; Hits []", uFebIdx); + fhMuchFebChanHitRateEvo.push_back(new TH2I(sHistName, title, 1800, 0, 1800, fUnpackParMuch->GetNbChanPerFeb(), -0.5, + fUnpackParMuch->GetNbChanPerFeb() - 0.5)); + + /// Hit rates profile per channel + sHistName = Form("hMuchFebChanRateProf_%03u", uFebIdx); + title = Form("Hits per second for each channel in FEB #%03u; Channel []; Hits/s []", uFebIdx); + fhMuchFebChanHitRateProf.push_back( + new TProfile(sHistName, title, fUnpackParMuch->GetNbChanPerFeb(), -0.5, fUnpackParMuch->GetNbChanPerFeb() - 0.5)); + + /// Hit rates evo per StsXyter + // sHistName = Form( "hMuchFebAsicRateEvo_%03u", uFebIdx ); + // title = Form( "Hits per second & StsXyter in FEB #%03u; Time [s]; Asic []; Hits []", uFebIdx ); + // fhMuchFebAsicHitRateEvo.push_back( new TH2I( sHistName, title, 1800, 0, 1800, + // fUnpackParMuch->GetNbAsicsPerFeb(), -0.5, fUnpackParMuch->GetNbAsicsPerFeb() - 0.5 ) ); + + /// Hit rates evo per FEB + sHistName = Form("hMuchFebRateEvo_%03u", uFebIdx); + title = Form("Hits per second in FEB #%03u; Time [s]; Hits []", uFebIdx); + fhMuchFebHitRateEvo.push_back(new TH1I(sHistName, title, 1800, 0, 1800)); + + + /// Hit rates evo per FEB for Mask Channel + sHistName = Form("hMuchFebRateEvo_mskch_%03u", uFebIdx); + title = Form("Hits per second in FEB #%03u; Time [s]; Hits []", uFebIdx); + fhMuchFebHitRateEvo_mskch.push_back(new TH1I(sHistName, title, 1800, 0, 1800)); + + /// Hit rates evo per FEB for Mask Channel with ADC Cut + sHistName = Form("hMuchFebRateEvo_mskch_adcut_%03u", uFebIdx); + title = Form("Hits per second in FEB #%03u; Time [s]; Hits []", uFebIdx); + fhMuchFebHitRateEvo_mskch_adccut.push_back(new TH1I(sHistName, title, 1800, 0, 1800)); + + /// Hit rates evo per FEB + sHistName = Form("hMuchFebRateEvo_WithoutDupli_%03u", uFebIdx); + title = Form("Hits per second in FEB #%03u; Time [s]; Hits []", uFebIdx); + fhMuchFebHitRateEvo_WithoutDupli.push_back(new TH1I(sHistName, title, 50000, 0, 5000)); + + /// Hit rates evo per channel, 1 minute bins, 24h + //sHistName = Form( "hMuchFebChanRateEvoLong_%03u", uFebIdx ); + //title = Form( "Hits per second & channel in FEB #%03u; Time [min]; Channel []; Hits []", uFebIdx ); + //fhMuchFebChanHitRateEvoLong.push_back( new TH2D( sHistName, title, + // fuLongHistoBinNb, -0.5, uAlignedLimit - 0.5, + // fUnpackParMuch->GetNbChanPerFeb(), -0.5, fUnpackParMuch->GetNbChanPerFeb() - 0.5 ) ); + + /// Hit rates evo per channel, 1 minute bins, 24h + //sHistName = Form( "hMuchFebAsicRateEvoLong_%03u", uFebIdx ); + //title = Form( "Hits per second & StsXyter in FEB #%03u; Time [min]; Asic []; Hits []", uFebIdx ); + //fhMuchFebAsicHitRateEvoLong.push_back( new TH2D( sHistName, title, + // fuLongHistoBinNb, -0.5, uAlignedLimit - 0.5, + // fUnpackParMuch->GetNbAsicsPerFeb(), -0.5, fUnpackParMuch->GetNbAsicsPerFeb() - 0.5 ) ); + + /// Hit rates evo per FEB, 1 minute bins, 24h + //sHistName = Form( "hMuchFebRateEvoLong_%03u", uFebIdx ); + //title = Form( "Hits per second in FEB #%03u; Time [min]; Hits []", uFebIdx ); + //fhMuchFebHitRateEvoLong.push_back( new TH1D(sHistName, title, + // fuLongHistoBinNb, -0.5, uAlignedLimit - 0.5 ) ); + + /// Distance between hits on same channel + sHistName = Form("hMuchFebChanDistT_%03u", uFebIdx); + title = Form("Time distance between hits on same channel in between FEB " + "#%03u; Time difference [ns]; Channel []; ", + uFebIdx); + fhMuchFebChanDistT.push_back(new TH2I(sHistName, title, 1000, -0.5, 6250.0 - 0.5, fUnpackParMuch->GetNbChanPerFeb(), + -0.5, fUnpackParMuch->GetNbChanPerFeb() - 0.5)); + + } // for( UInt_t uFebIdx = 0; uFebIdx < fuNbFebs; ++uFebIdx ) + + ///++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++/// + fhDpbMsErrors = + new TH2I("fhDpbMsErrors", "; DPB []; Error type []; Counts []", fuNrOfDpbs, 0, fuNrOfDpbs, 4, -0.5, 3.5); + ///++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++/// + + // Miscroslice properties histos + for (Int_t component = 0; component < kiMaxNbFlibLinks; component++) { + fhMsSz[component] = NULL; + fhMsSzTime[component] = NULL; + } // for( Int_t component = 0; component < kiMaxNbFlibLinks; component ++ ) + + LOG(debug) << "Initialized 6th Histo before FairRunOnlne Instance"; + // THttpServer* server = FairRunOnline::Instance()->GetHttpServer(); + // if (server) { + for (UInt_t uModuleId = 0; uModuleId < 2; ++uModuleId) { + // server->Register("/MuchRaw", fHistPadDistr[uModuleId] ); + // server->Register("/MuchRaw", fRealHistPadDistr[uModuleId] ); + // server->Register("/MuchFeb", fhMuchFebDuplicateHitProf[uModuleId] ); + } + + // server->Register("/MuchRaw", fhRate ); + // server->Register("/MuchRaw", fhRateAdcCut ); + // server->Register("/MuchRaw", fhFEBcount); //closed by me + AddHistoToVector(fhMuchMessType, "MuchRaw"); + // server->Register("/MuchRaw", fhMuchMessType); //closed by me + AddHistoToVector(fhMuchMessType, "MuchRaw"); + // server->Register("/MuchRaw", fhMuchSysMessType ); + //server->Register("/MuchRaw", fhMuchMessTypePerDpb); //closed by me + AddHistoToVector(fhMuchMessTypePerDpb, "MuchRaw"); + //server->Register("/MuchRaw", fhMuchSysMessTypePerDpb); //closed by me + AddHistoToVector(fhMuchSysMessTypePerDpb, "MuchRaw"); + // server->Register("/MuchRaw", fhStatusMessType ); + //server->Register("/MuchRaw", fhMsStatusFieldType); // closed by me + AddHistoToVector(fhMsStatusFieldType, "MuchRaw"); + //server->Register("/MuchRaw", fhMuchHitsElinkPerDpb); // closed by me + AddHistoToVector(fhMuchHitsElinkPerDpb, "MuchRaw"); + //server->Register("/MuchRaw", fhMuchFebChanAdcRaw_combined); // closed by me + AddHistoToVector(fhMuchFebChanAdcRaw_combined, "MuchRaw"); + for (UInt_t uFebIdx = 0; uFebIdx < fuNbFebs; ++uFebIdx) { + if (kTRUE == fUnpackParMuch->IsFebActive(uFebIdx)) { + //server->Register("/MuchFeb", fhMuchFebChanCntRaw[uFebIdx]); //closed by me + AddHistoToVector(fhMuchFebChanCntRaw[uFebIdx], "MuchFeb"); + //server->Register("/MuchFeb", fhMuchFebSpill[uFebIdx]); // closed by me + AddHistoToVector(fhMuchFebSpill[uFebIdx], "MuchFeb"); + //server->Register("/MuchFeb", fhMuchFebADC[uFebIdx]); // closed by me + AddHistoToVector(fhMuchFebADC[uFebIdx], "MuchFeb"); + //server->Register("/MuchFeb", fhMuchChannelTime[uFebIdx]); // closed by me + AddHistoToVector(fhMuchChannelTime[uFebIdx], "MuchFeb"); + + //server->Register("/MuchFeb", fhMuchFebChanCntRawGood[ uFebIdx ] ); + //// server->Register("/MuchFeb", fhMuchFebChanAdcRaw[ uFebIdx ] ); + // server->Register("/MuchFeb", fhMuchFebChanAdcRawProf[ uFebIdx ] ); + //server->Register("/MuchFeb", fhMuchFebChanAdcCal[ uFebIdx ] ); + //server->Register("/MuchFeb", fhMuchFebChanAdcCalProf[ uFebIdx ] ); + //// server->Register("/MuchFeb", fhMuchFebChanRawTs[ uFebIdx ] ); + //server->Register("/MuchFeb", fhMuchFebChanHitRateEvo[ uFebIdx ] ); + // server->Register("/MuchFeb", fhMuchFebChanHitRateProf[ uFebIdx ] ); + //server->Register("/MuchFeb", fhMuchFebAsicHitRateEvo[ uFebIdx ] ); + // server->Register("/MuchFeb", fhMuchFebHitRateEvo[ uFebIdx ] ); + //// server->Register("/MuchFeb", fhMuchFebHitRateEvo_mskch[ uFebIdx ] ); + // server->Register("/MuchFeb", fhMuchFebHitRateEvo_mskch_adccut[ uFebIdx ] ); + // server->Register("/MuchFeb", fhMuchFebHitRateEvo_WithoutDupli[ uFebIdx ] ); + LOG(debug) << "Initialized fhMuchFebHitRateEvo_WithoutDupli number " << uFebIdx; + /*server->Register("/MuchFeb", fhMuchFebChanHitRateEvoLong[ uFebIdx ] ); + server->Register("/MuchFeb", fhMuchFebAsicHitRateEvoLong[ uFebIdx ] ); + server->Register("/MuchFeb", fhMuchFebHitRateEvoLong[ uFebIdx ] ); + server->Register("/MuchFeb", fhMuchFebChanDistT[ uFebIdx ] );*/ + + } // if( kTRUE == fUnpackParMuch->IsFebActive( uFebIdx ) ) + //server->Register("/MuchRaw", fhDpbMsErrors); //closed by me + AddHistoToVector(fhDpbMsErrors, "MuchRaw"); + } // for( UInt_t uFebIdx = 0; uFebIdx < fuNbFebs; ++uFebIdx ) + + // LOG(debug) << "Initialized FEB 8th Histo"; + /*server->RegisterCommand("/Reset_All", "bMcbm2018ResetAlgoMuchLite=kTRUE"); + server->RegisterCommand("/Write_All", "bMcbm2018WriteAlgoMuchLite=kTRUE"); + server->RegisterCommand("/ScanNoisyCh", "bMcbm2018ScanNoisyAlgoMuchLite=kTRUE"); + server->Restrict("/Reset_All", "allow=admin"); + server->Restrict("/Write_All", "allow=admin"); + server->Restrict("/ScanNoisyCh", "allow=admin"); */ + // } // if( server ) + + LOG(debug) << "Initialized All Histos 8th Histo"; + /** Create summary Canvases for mCBM 2019 **/ + Double_t w = 10; + Double_t h = 10; + LOG(debug) << "Initialized 7th Histo before Summary per FEB"; + + TCanvas* cChannel = new TCanvas(Form("CHANNELS"), + Form("CHANNELS")); //, + // w, h); + cChannel->Divide(4, 9); + // Summary per FEB + for (UInt_t uFebIdx = 0; uFebIdx < fuNbFebs; ++uFebIdx) { + if (kTRUE == fUnpackParMuch->IsFebActive(uFebIdx)) { + cChannel->cd(uFebIdx + 1); + //// gPad->SetGridx(); + // gPad->SetGridy(); + gPad->SetLogy(); + fhMuchFebChanCntRaw[uFebIdx]->Draw(); + + } // if( kTRUE == fUnpackParMuch->IsFebActive( uFebIdx ) ) + } // for( UInt_t uFebIdx = 0; uFebIdx < fuNbFebs; ++uFebIdx ) + + //server->Register("/canvases", cChannel); //closed by me + AddCanvasToVector(cChannel, "canvases"); + //All Feb hit rate together on one Canvas + + TCanvas* cspill = new TCanvas(Form("SPILLS"), Form("SPILLS")); //,w, h); + cspill->Divide(4, 9); + + for (UInt_t uFebIdx = 0; uFebIdx < fuNbFebs; ++uFebIdx) { + if (kTRUE == fUnpackParMuch->IsFebActive(uFebIdx)) { + UInt_t flPad = 1 + uFebIdx; + cspill->cd(flPad); + //gPad->SetGridx(); + //gPad->SetGridy(); + // gPad->SetLogy(); + fhMuchFebSpill[uFebIdx]->Draw(); + } + // server->Register("/canvases", cspill); + } + // server->Register("/canvases", cspill); //closed by me + AddCanvasToVector(cspill, "canvases"); + + TCanvas* cadc = new TCanvas(Form("ADC"), Form("ADC"), w, h); + cadc->Divide(4, 9); + + for (UInt_t uFebIdx = 0; uFebIdx < fuNbFebs; ++uFebIdx) { + if (kTRUE == fUnpackParMuch->IsFebActive(uFebIdx)) { + UInt_t flPad = 1 + uFebIdx; + cadc->cd(flPad); + //gPad->SetGridx(); + //gPad->SetGridy(); + //gPad->SetLogy(); + fhMuchFebADC[uFebIdx]->Draw("colz"); + } + } + //server->Register("/canvases", cadc); //closed by me + AddCanvasToVector(cadc, "canvases"); + TCanvas* cChanneltime = new TCanvas(Form("ChannelvsTime"), Form("ChannelvsTime"), w, h); + cChanneltime->Divide(4, 9); + + for (UInt_t uFebIdx = 0; uFebIdx < fuNbFebs; ++uFebIdx) { + if (kTRUE == fUnpackParMuch->IsFebActive(uFebIdx)) { + UInt_t flPad = 1 + uFebIdx; + cChanneltime->cd(flPad); + //gPad->SetGridx(); + //gPad->SetGridy(); + //gPad->SetLogy(); + fhMuchChannelTime[uFebIdx]->Draw("colz"); + } + } + // server->Register("/canvases", cChanneltime); //closed by me + AddCanvasToVector(cChanneltime, "canvases"); + //====================================================================// + LOG(debug) << "Initialized Last Histo before exiting CreateHistograms"; + //====================================================================// + /** Recovers/Create Ms Size Canvase for CERN 2016 **/ + // Try to recover canvas in case it was created already by another monitor + // If not existing, create it + fcMsSizeAll = dynamic_cast<TCanvas*>(gROOT->FindObject("cMsSizeAll")); + if (NULL == fcMsSizeAll) { + fcMsSizeAll = new TCanvas("cMsSizeAll", + "Evolution of MS size in last 300 s"); //, w, h); + fcMsSizeAll->Divide(1, 8); + LOG(info) << "Created MS size canvas in Much monitor"; + //server->Register("/canvases", fcMsSizeAll); //closed by me + AddCanvasToVector(fcMsSizeAll, "canvases"); + } // if( NULL == fcMsSizeAll ) + else + LOG(info) << "Recovered MS size canvas in Much monitor"; + //====================================================================// + + /*****************************/ + return kTRUE; +} + +Bool_t CbmMcbm2018MonitorAlgoMuchLite::ProcessTs(const fles::Timeslice& ts) +{ + fulCurrentTsIdx = ts.index(); + fdTsStartTime = static_cast<Double_t>(ts.descriptor(0, 0).idx); + + /// Ignore First TS as first MS is typically corrupt + if (0 == fulCurrentTsIdx) return kTRUE; + + /// On first TS, extract the TS parameters from header (by definition stable over time) + if (-1.0 == fdTsCoreSizeInNs) { + fuNbCoreMsPerTs = ts.num_core_microslices(); + fuNbOverMsPerTs = ts.num_microslices(0) - ts.num_core_microslices(); + fdTsCoreSizeInNs = fdMsSizeInNs * (fuNbCoreMsPerTs); + fdTsFullSizeInNs = fdMsSizeInNs * (fuNbCoreMsPerTs + fuNbOverMsPerTs); + LOG(info) << "Timeslice parameters: each TS has " << fuNbCoreMsPerTs << " Core MS and " << fuNbOverMsPerTs + << " Overlap MS, for a core duration of " << fdTsCoreSizeInNs << " ns and a full duration of " + << fdTsFullSizeInNs << " ns"; + + /// Ignore overlap ms if flag set by user + fuNbMsLoop = fuNbCoreMsPerTs; + if (kFALSE == fbIgnoreOverlapMs) fuNbMsLoop += fuNbOverMsPerTs; + LOG(info) << "In each TS " << fuNbMsLoop << " MS will be looped over"; + } // if( -1.0 == fdTsCoreSizeInNs ) + + /// Compute time of TS core end + fdTsStopTimeCore = fdTsStartTime + fdTsCoreSizeInNs; + // LOG(info) << Form( "TS %5d Start %12f Stop %12f", fulCurrentTsIdx, fdTsStartTime, fdTsStopTimeCore ); + + /// Loop over core microslices (and overlap ones if chosen) + for (fuMsIndex = 0; fuMsIndex < fuNbMsLoop; fuMsIndex++) { + /// Loop over registered components + for (UInt_t uMsCompIdx = 0; uMsCompIdx < fvMsComponentsList.size(); ++uMsCompIdx) { + UInt_t uMsComp = fvMsComponentsList[uMsCompIdx]; + + if (kFALSE == ProcessMs(ts, uMsComp, fuMsIndex)) { + LOG(error) << "Failed to process ts " << fulCurrentTsIdx << " MS " << fuMsIndex << " for component " << uMsComp; + return kFALSE; + } // if( kFALSE == ProcessMs( ts, uMsCompIdx, fuMsIndex ) ) + // LOG(info) << "TS index : " << fulCurrentTsIdx << " end processing MS"; + } // for( UInt_t uMsCompIdx = 0; uMsCompIdx < fvMsComponentsList.size(); ++uMsCompIdx ) + /* + /// Sort the buffers of hits + std::sort( fvmHitsInMs.begin(), fvmHitsInMs.end() ); + + /// Add the hits to the output buffer as Digis + for( auto itHitIn = fvmHitsInMs.begin(); itHitIn < fvmHitsInMs.end(); ++itHitIn ) + { + UInt_t uFebIdx = itHitIn->GetAsic() / fUnpackPar->GetNbAsicsPerFeb() + + ( itHitIn->GetDpb() * fUnpackPar->GetNbCrobsPerDpb() + itHitIn->GetCrob() ) + * fUnpackPar->GetNbFebsPerCrob(); + UInt_t uChanInFeb = itHitIn->GetChan() + + fUnpackPar->GetNbChanPerAsic() * (itHitIn->GetAsic() % fUnpackPar->GetNbAsicsPerFeb()); + + ULong64_t ulTimeInNs = static_cast< ULong64_t >( itHitIn->GetTs() * stsxyter::kdClockCycleNs - fdTimeOffsetNs ); + + fDigiVect.push_back( CbmTofDigi( fviFebAddress[ uFebIdx ], uChanInFeb, ulTimeInNs, itHitIn->GetAdc() ) ); + } // for( auto itHitIn = fvmHitsInMs.begin(); itHitIn < fvmHitsInMs.end(); ++itHitIn ) +*/ + /// Clear the buffer of hits + fvmHitsInMs.clear(); + } // for( fuMsIndex = 0; fuMsIndex < uNbMsLoop; fuMsIndex ++ ) + + /// Clear buffers to prepare for the next TS + fvmHitsInMs.clear(); + /* + for( UInt_t uDpb = 0; uDpb < fuNrOfDpbs; ++uDpb ) + { + fvmHitsInMs[ uDpb ].clear(); + } // for( UInt_t uDpb = 0; uDpb < fuNrOfDpbs; ++uDpb ) +*/ + /// Fill plots if in monitor mode + if (fbMonitorMode) { + //if (kFALSE == FillHistograms()) { + /* if (kFALSE == CreateHistograms()) { + LOG(error) << "Failed to fill histos in ts " << fulCurrentTsIdx; + return kFALSE; + }*/ // if( kFALSE == FillHistograms() ) //closed by me + } // if( fbMonitorMode ) + + return kTRUE; +} + +Bool_t CbmMcbm2018MonitorAlgoMuchLite::ProcessMs(const fles::Timeslice& ts, size_t uMsComp, size_t uMsIdx) +{ + auto msDescriptor = ts.descriptor(uMsComp, uMsIdx); + fuCurrentEquipmentId = msDescriptor.eq_id; + const uint8_t* msContent = reinterpret_cast<const uint8_t*>(ts.content(uMsComp, uMsIdx)); + + fulCurrentTsIdx = ts.index(); + if (0 == fvbMaskedComponents.size()) fvbMaskedComponents.resize(ts.num_components(), kFALSE); + + if (0 == fulCurrentTsIdx && 0 == uMsIdx) { + /* + LOG(info) << "hi hv eqid flag si sv idx/start crc size offset"; + LOG(info) << Form( "%02x %02x %04x %04x %02x %02x %016llx %08x %08x %016llx", + static_cast<unsigned int>(msDescriptor.hdr_id), + static_cast<unsigned int>(msDescriptor.hdr_ver), msDescriptor.eq_id, msDescriptor.flags, + static_cast<unsigned int>(msDescriptor.sys_id), + static_cast<unsigned int>(msDescriptor.sys_ver), msDescriptor.idx, msDescriptor.crc, + msDescriptor.size, msDescriptor.offset ); +*/ + LOG(info) << FormatMsHeaderPrintout(msDescriptor); + } // if( 0 == fulCurrentTsIndex && 0 == uMsIdx ) + if (kFALSE == fvbMaskedComponents[uMsComp] && 0 == uMsIdx) { + auto it = fDpbIdIndexMap.find(fuCurrentEquipmentId); + if (fDpbIdIndexMap.end() == it) { + LOG(warning) << "Could not find the sDPB index for AFCK id 0x" << std::hex << fuCurrentEquipmentId << std::dec + << " component " << uMsComp << "\n" + << "If valid this index has to be added in the TOF parameter file in " + "the RocIdArray field" + << "\n" + << "For now we remove it from the list of components analyzed"; + fvbMaskedComponents[uMsComp] = kTRUE; + } // if( fDpbIdIndexMap.end() == it ) + + } // if( kFALSE == fvbMaskedComponents[ uMsComp ] && 0 == uMsIdx ) + + if (kTRUE == fvbMaskedComponents[uMsComp]) return kTRUE; + + uint32_t uSize = msDescriptor.size; + fulCurrentMsIdx = msDescriptor.idx; + Double_t dMsTime = (1e-9) * static_cast<double>(fulCurrentMsIdx); + LOG(debug) << "Microslice: " << fulCurrentMsIdx << " from EqId " << std::hex << fuCurrentEquipmentId << std::dec + << " has size: " << uSize; + + fuCurrDpbId = static_cast<uint32_t>(fuCurrentEquipmentId & 0xFFFF); + fuCurrDpbIdx = fDpbIdIndexMap[fuCurrDpbId]; + //LOG(info) <<" fuCurrDpbIdx "<<fuCurrDpbIdx<<" fuCurrDpbId "<<fuCurrDpbId; + + if (uMsComp < kiMaxNbFlibLinks) { + if (fdStartTimeMsSz < 0) fdStartTimeMsSz = dMsTime; + fhMsSz[uMsComp]->Fill(uSize); + fhMsSzTime[uMsComp]->Fill(dMsTime - fdStartTimeMsSz, uSize); + } // if( uMsComp < kiMaxNbFlibLinks ) + + /// Plots in [X/s] update + if (static_cast<Int_t>(fvdPrevMsTime[uMsComp]) < static_cast<Int_t>(dMsTime)) { + /// "new second" + UInt_t uFebIdxOffset = fUnpackParMuch->GetNbFebsPerDpb() * fuCurrDpbIdx; + for (UInt_t uFebIdx = 0; uFebIdx < fUnpackParMuch->GetNbFebsPerDpb(); ++uFebIdx) { + UInt_t uFebIdxInSyst = uFebIdxOffset + uFebIdx; + + /// Ignore first interval is not clue how late the data taking was started + if (0 == fviFebTimeSecLastRateUpdate[uFebIdxInSyst]) { + fviFebTimeSecLastRateUpdate[uFebIdxInSyst] = static_cast<Int_t>(dMsTime); + fviFebCountsSinceLastRateUpdate[uFebIdxInSyst] = 0; + for (UInt_t uChan = 0; uChan < fUnpackParMuch->GetNbChanPerFeb(); ++uChan) + fvdFebChanCountsSinceLastRateUpdate[uFebIdxInSyst][uChan] = 0.0; + continue; + } // if( 0 == fviFebTimeSecLastRateUpdate[uFebIdxInSyst] ) + + Int_t iTimeInt = static_cast<Int_t>(dMsTime) - fviFebTimeSecLastRateUpdate[uFebIdxInSyst]; + if (fiTimeIntervalRateUpdate <= iTimeInt) { + /// Jump empty FEBs without looping over channels + if (0 == fviFebCountsSinceLastRateUpdate[uFebIdxInSyst]) { + fviFebTimeSecLastRateUpdate[uFebIdxInSyst] = static_cast<Int_t>(dMsTime); + continue; + } // if( 0 == fviFebCountsSinceLastRateUpdate[uFebIdxInSyst] ) + + for (UInt_t uChan = 0; uChan < fUnpackParMuch->GetNbChanPerFeb(); ++uChan) { + fhMuchFebChanHitRateProf[uFebIdxInSyst]->Fill(uChan, fvdFebChanCountsSinceLastRateUpdate[uFebIdxInSyst][uChan] + / iTimeInt); + fvdFebChanCountsSinceLastRateUpdate[uFebIdxInSyst][uChan] = 0.0; + } // for( UInt_t uChan = 0; uChan < fUnpackParMuch->GetNbChanPerFeb(); ++uChan ) + + fviFebTimeSecLastRateUpdate[uFebIdxInSyst] = static_cast<Int_t>(dMsTime); + fviFebCountsSinceLastRateUpdate[uFebIdxInSyst] = 0; + } // if( fiTimeIntervalRateUpdate <= iTimeInt ) + } // for( UInt_t uFebIdx = 0; uFebIdx < fUnpackParMuch->GetNbFebsPerDpb(); ++uFebIdx ) + } // if( static_cast<Int_t>( fvdMsTime[ uMsCompIdx ] ) < static_cast<Int_t>( dMsTime ) ) + + // Store MS time for coincidence plots + fvdPrevMsTime[uMsComp] = dMsTime; + + /// Check Flags field of MS header + uint16_t uMsHeaderFlags = msDescriptor.flags; + for (UInt_t uBit = 0; uBit < 16; ++uBit) + fhMsStatusFieldType->Fill(uBit, (uMsHeaderFlags >> uBit) & 0x1); + + /** Check the current TS_MSb cycle and correct it if wrong **/ + UInt_t uTsMsbCycleHeader = std::floor(fulCurrentMsIdx / (stsxyter::kulTsCycleNbBins * stsxyter::kdClockCycleNs)) + - fvuInitialTsMsbCycleHeader[fuCurrDpbIdx]; + + /// => Quick and dirty hack for binning FW!!! + if (kTRUE == fbBinningFw) + uTsMsbCycleHeader = std::floor(fulCurrentMsIdx / (stsxyter::kulTsCycleNbBinsBinning * stsxyter::kdClockCycleNs)) + - fvuInitialTsMsbCycleHeader[fuCurrDpbIdx]; + + if (kFALSE == fvuInitialHeaderDone[fuCurrDpbIdx]) { + fvuInitialTsMsbCycleHeader[fuCurrDpbIdx] = uTsMsbCycleHeader; + fvuInitialHeaderDone[fuCurrDpbIdx] = kTRUE; + } // if( kFALSE == fvuInitialHeaderDone[ fuCurrDpbIdx ] ) + else if (uTsMsbCycleHeader != fvuCurrentTsMsbCycle[fuCurrDpbIdx] && 4194303 != fvulCurrentTsMsb[fuCurrDpbIdx]) { + /* + LOG(warning) << "TS MSB cycle from MS header does not match current cycle from data " + << "for TS " << std::setw( 12 ) << fulCurrentTsIdx + << " MS " << std::setw( 12 ) << fulCurrentMsIdx + << " MsInTs " << std::setw( 3 ) << uMsIdx + << " ====> " << fvuCurrentTsMsbCycle[ fuCurrDpbIdx ] + << " VS " << uTsMsbCycleHeader; +*/ + fvuCurrentTsMsbCycle[fuCurrDpbIdx] = uTsMsbCycleHeader; + } + + // If not integer number of message in input buffer, print warning/error + if (0 != (uSize % kuBytesPerMessage)) + LOG(error) << "The input microslice buffer does NOT " + << "contain only complete nDPB messages!"; + + // Compute the number of complete messages in the input microslice buffer + uint32_t uNbMessages = (uSize - (uSize % kuBytesPerMessage)) / kuBytesPerMessage; + + // Prepare variables for the loop on contents + const uint32_t* pInBuff = reinterpret_cast<const uint32_t*>(msContent); + + for (uint32_t uIdx = 0; uIdx < uNbMessages; ++uIdx) { + // Fill message + uint32_t ulData = static_cast<uint32_t>(pInBuff[uIdx]); + + stsxyter::Message mess(static_cast<uint32_t>(ulData & 0xFFFFFFFF)); + + // Print message if requested + if (fbPrintMessages) mess.PrintMess(std::cout, fPrintMessCtrl); + /* + if( 1000 == fulCurrentTsIdx ) + { + mess.PrintMess( std::cout, fPrintMessCtrl ); + } // if( 0 == fulCurrentTsIdx ) +*/ + stsxyter::MessType typeMess = mess.GetMessType(); + fmMsgCounter[typeMess]++; + // fhMuchMessType->Fill( static_cast< uint16_t > (typeMess) ); + // fhMuchMessTypePerDpb->Fill( fuCurrDpbIdx, static_cast< uint16_t > (typeMess) ); + + switch (typeMess) { + case stsxyter::MessType::Hit: { + // Extract the eLink and Asic indices => Should GO IN the fill method now that obly hits are link/asic specific! + UShort_t usElinkIdx = mess.GetLinkIndex(); + /// => Quick and dirty hack for binning FW!!! + if (kTRUE == fbBinningFw) usElinkIdx = mess.GetLinkIndexHitBinning(); + + UInt_t uCrobIdx = usElinkIdx / fUnpackParMuch->GetNbElinkPerCrob(); + Int_t uFebIdx = fUnpackParMuch->ElinkIdxToFebIdx(usElinkIdx); + // if(usElinkIdx!=0) + //LOG(info) <<" usElinkIdx "<<usElinkIdx<<" uCrobIdx "<<uCrobIdx<<" uFebIdx "<<uFebIdx; + if (kTRUE == fbMuchMode) uFebIdx = usElinkIdx; + fhMuchHitsElinkPerDpb->Fill(fuCurrDpbIdx, usElinkIdx); + if (-1 == uFebIdx) { + LOG(warning) << "CbmMcbm2018MonitorMuchLite::DoUnpack => " + << "Wrong elink Idx! Elink raw " << Form("%d remap %d", usElinkIdx, uFebIdx); + continue; + } // if( -1 == uFebIdx ) + //LOG(info) << " uCrobIdx "<<uCrobIdx<<" fUnpackParMuch->ElinkIdxToAsicIdx( usElinkIdx ) "<<fUnpackParMuch->ElinkIdxToAsicIdx( usElinkIdx )<<" usElinkIdx "<<usElinkIdx; + UInt_t uAsicIdx = + (fuCurrDpbIdx * fUnpackParMuch->GetNbCrobsPerDpb() + uCrobIdx) * fUnpackParMuch->GetNbAsicsPerCrob() + + fUnpackParMuch->ElinkIdxToAsicIdx(usElinkIdx); + + FillHitInfo(mess, usElinkIdx, uAsicIdx, uMsIdx); + break; + } // case stsxyter::MessType::Hit : + case stsxyter::MessType::TsMsb: { + FillTsMsbInfo(mess, uIdx, uMsIdx); + break; + } // case stsxyter::MessType::TsMsb : + case stsxyter::MessType::Epoch: { + // The first message in the TS is a special ones: EPOCH + FillEpochInfo(mess); + + if (0 < uIdx) + LOG(info) << "CbmMcbm2018MonitorMuchLite::DoUnpack => " + << "EPOCH message at unexpected position in MS: message " << uIdx << " VS message 0 expected!"; + break; + } // case stsxyter::MessType::TsMsb : + case stsxyter::MessType::Status: { + // UShort_t usElinkIdx = mess.GetStatusLink(); // commented 03.07.20 FU unused + // UInt_t uCrobIdx = usElinkIdx / fUnpackParMuch->GetNbElinkPerCrob(); // commented 03.07.20 FU unused + // Int_t uFebIdx = fUnpackParMuch->ElinkIdxToFebIdx( usElinkIdx ); + // UInt_t uAsicIdx = ( fuCurrDpbIdx * fUnpackParMuch->GetNbCrobsPerDpb() + uCrobIdx // commented 03.07.20 FU unused + // ) * fUnpackParMuch->GetNbAsicsPerCrob() + // + fUnpackParMuch->ElinkIdxToAsicIdx( usElinkIdx ); + + // UShort_t usStatusField = mess.GetStatusStatus(); // commented 03.07.20 FU unused + + // fhStatusMessType->Fill( uAsicIdx, usStatusField ); + /// Always print status messages... or not? + if (fbPrintMessages) { + std::cout << Form("DPB %2u TS %12llu MS %12llu mess %5u ", fuCurrDpbIdx, fulCurrentTsIdx, fulCurrentMsIdx, + uIdx); + mess.PrintMess(std::cout, fPrintMessCtrl); + } // if( fbPrintMessages ) + // FillTsMsbInfo( mess ); + break; + } // case stsxyter::MessType::Status + case stsxyter::MessType::Empty: { + // FillTsMsbInfo( mess ); + break; + } // case stsxyter::MessType::Empty : + case stsxyter::MessType::EndOfMs: { + if (mess.IsMsErrorFlagOn()) { + fhDpbMsErrors->Fill(fuCurrDpbIdx, mess.GetMsErrorType()); + } // if( pMess[uIdx].IsMsErrorFlagOn() ) + break; + } // case stsxyter::MessType::EndOfMs : + case stsxyter::MessType::Dummy: { + break; + } // case stsxyter::MessType::Dummy / ReadDataAck / Ack : + default: { + LOG(fatal) << "CbmMcbm2018MonitorMuchLite::DoUnpack => " + << "Unknown message type, should never happen, stopping " + "here! Type found was: " + << static_cast<int>(typeMess); + } + } // switch( mess.GetMessType() ) + } // for( uint32_t uIdx = 0; uIdx < uNbMessages; ++uIdx ) + + //LOG(info) << "TS index: " << fulCurrentTsIdx << "a processing MS done"; + return kTRUE; +} + +void CbmMcbm2018MonitorAlgoMuchLite::FillHitInfo(stsxyter::Message mess, const UShort_t& /*usElinkIdx*/, + const UInt_t& uAsicIdx, const UInt_t& uMsIdx) +{ + UShort_t usChan = mess.GetHitChannel(); + UShort_t usRawAdc = mess.GetHitAdc(); + // UShort_t usFullTs = mess.GetHitTimeFull(); + // UShort_t usTsOver = mess.GetHitTimeOver(); + UShort_t usRawTs = mess.GetHitTime(); + //Below FebID is according to FEB Position in Module GEM A or Module GEM B (Carefully write MUCH Par file) + Int_t FebId = fUnpackParMuch->GetFebId(uAsicIdx); + + /// => Quick and dirty hack for binning FW!!! + if (kTRUE == fbBinningFw) usRawTs = mess.GetHitTimeBinning(); + + // UInt_t uFebIdx = uAsicIdx / fUnpackParMuch->GetNbAsicsPerFeb(); + //For MUCH each FEB has one StsXyter + UInt_t uFebIdx = uAsicIdx; + // UInt_t uCrobIdx = usElinkIdx / fUnpackParMuch->GetNbElinkPerCrob(); + // UInt_t uAsicInFeb = uAsicIdx % fUnpackParMuch->GetNbAsicsPerFeb(); + UInt_t uChanInFeb = usChan + fUnpackParMuch->GetNbChanPerAsic() * (uAsicIdx % fUnpackParMuch->GetNbAsicsPerFeb()); + Int_t ModuleNr = fUnpackParMuch->GetModule(uAsicIdx); + Int_t sector = fUnpackParMuch->GetPadXA(FebId, usChan); + Int_t channel = fUnpackParMuch->GetPadYA(FebId, usChan); + + //Convert into Real X Y Position + // Double_t ActualX = fUnpackParMuch->GetRealX(channel+97*sector); + // Double_t ActualY = fUnpackParMuch->GetRealPadSize(channel+97*sector); + Double_t ActualX = fUnpackParMuch->GetRealX(channel, sector); + Double_t ActualY = fUnpackParMuch->GetRealPadSize(channel, sector); + + //Converting Module (Small side up) + ActualX = 1000 - ActualX; + channel = 96 - channel; + + LOG(debug) << "Module Nr " << ModuleNr << " Sector Nr " << sector << " Channel Nr " << channel << "Actual X " + << ActualX << "Actual Y " << ActualY << "uAsicIdx " << uAsicIdx; + + + // fHistPadDistr[ModuleNr]->Fill(sector, channel); + // fRealHistPadDistr[ModuleNr]->Fill(ActualY, ActualX); + + //Double_t dCalAdc = fvdFebAdcOffs[ fuCurrDpbIdx ][ uCrobIdx ][ uFebIdx ] + // + (usRawAdc - 1)* fvdFebAdcGain[ fuCurrDpbIdx ][ uCrobIdx ][ uFebIdx ]; + fhFEBcount->Fill(uFebIdx); + // fhMuchFebSpill[uFebIdx] ->Fill(usRawTs); + fhMuchFebChanCntRaw[uFebIdx]->Fill(uChanInFeb); + // fhMuchFebChanAdcRaw[ uFebIdx ]->Fill( uChanInFeb, usRawAdc ); + // fhMuchFebChanAdcRawProf[ uFebIdx ]->Fill( uChanInFeb, usRawAdc ); + //fhMuchFebChanAdcCal[ uFebIdx ]->Fill( uChanInFeb, dCalAdc ); + //fhMuchFebChanAdcCalProf[ uFebIdx ]->Fill( uChanInFeb, dCalAdc ); + // fhMuchFebChanRawTs[ uFebIdx ]->Fill( usChan, usRawTs ); + //fhMuchFebChanMissEvt[ uFebIdx ]->Fill( usChan, mess.IsHitMissedEvts() ); + // fhMuchFebChanAdcRaw_combined->Fill(usRawAdc); + + + fhMuchFebADC[uFebIdx]->Fill(usChan, usRawAdc); + // Compute the Full time stamp + // ULong64_t ulOldHitTime = fvulChanLastHitTime[ uAsicIdx ][ usChan ]; // commented 03.07.20 FU unused + // Long64_t dOldHitTime = fvdChanLastHitTime[ uAsicIdx ][ usChan ]; + + // Use TS w/o overlap bits as they will anyway come from the TS_MSB + fvulChanLastHitTime[uAsicIdx][usChan] = usRawTs; + + fvulChanLastHitTime[uAsicIdx][usChan] += + static_cast<ULong64_t>(stsxyter::kuHitNbTsBins) * static_cast<ULong64_t>(fvulCurrentTsMsb[fuCurrDpbIdx]) + + static_cast<ULong64_t>(stsxyter::kulTsCycleNbBins) * static_cast<ULong64_t>(fvuCurrentTsMsbCycle[fuCurrDpbIdx]); + + /// => Quick and dirty hack for binning FW!!! + if (kTRUE == fbBinningFw) + fvulChanLastHitTime[uAsicIdx][usChan] = + usRawTs + + static_cast<ULong64_t>(stsxyter::kuHitNbTsBinsBinning) * static_cast<ULong64_t>(fvulCurrentTsMsb[fuCurrDpbIdx]) + + static_cast<ULong64_t>(stsxyter::kulTsCycleNbBinsBinning) + * static_cast<ULong64_t>(fvuCurrentTsMsbCycle[fuCurrDpbIdx]); + + + // Convert the Hit time in bins to Hit time in ns + Long64_t dHitTimeNs = fvulChanLastHitTime[uAsicIdx][usChan] * stsxyter::kdClockCycleNs; + + // Store new value of Hit time in ns + fvdChanLastHitTime[uAsicIdx][usChan] = fvulChanLastHitTime[uAsicIdx][usChan] * stsxyter::kdClockCycleNs; + // For StsXyter2.0 Duplicate Hit Error + //Int_t ModuleNr = fUnpackParMuch->GetModule(uAsicIdx); + /* + fhMuchFebDuplicateHitProf[ModuleNr]->Fill(FebId,0); + if( ulOldHitTime == fvulChanLastHitTime[uAsicIdx][usChan] ) + fhMuchFebDuplicateHitProf[ModuleNr]->Fill(FebId,1); +*/ + + /* + LOG(info) << " Asic " << std::setw( 2 ) << uAsicIdx + << " Channel " << std::setw( 3 ) << usChan + << " Diff to last hit " << std::setw( 12 ) << ( fvulChanLastHitTime[ uAsicIdx ][ usChan ] - ulOldHitTime) + << " in s " << std::setw( 12 ) << ( fvdChanLastHitTime[ uAsicIdx ][ usChan ] - dOldHitTime) * 1e-9; +*/ + // Pulser and MS + fvuChanNbHitsInMs[uAsicIdx][usChan][uMsIdx]++; + fvdChanLastHitTimeInMs[uAsicIdx][usChan][uMsIdx] = dHitTimeNs; + fvusChanLastHitAdcInMs[uAsicIdx][usChan][uMsIdx] = usRawAdc; + /* + fvmChanHitsInTs[ uAsicIdx ][ usChan ].insert( stsxyter::FinalHit( fvulChanLastHitTime[ uAsicIdx ][ usChan ], + usRawAdc, uAsicIdx, usChan ) ); +*/ + fvmHitsInMs.push_back(stsxyter::FinalHit(fvulChanLastHitTime[uAsicIdx][usChan], usRawAdc, uAsicIdx, usChan)); + + // Check Starting point of histos with time as X axis + if (-1 == fdStartTime) fdStartTime = fvdChanLastHitTime[uAsicIdx][usChan]; + + Int_t constime = (fvdChanLastHitTime[uAsicIdx][usChan] - prevtime_new); + + if (constime < 10000000) { + if (usRawAdc > 1) { Counter1++; } + Counter++; + } + else { + //fhRate->Fill(Counter); + // fhRateAdcCut->Fill(Counter1); + Counter = 0; + Counter1 = 0; + prevtime_new = fvdChanLastHitTime[uAsicIdx][usChan]; + } + + + // Fill histos with time as X axis + Double_t dTimeSinceStartSec = (fvdChanLastHitTime[uAsicIdx][usChan] - fdStartTime) * 1e-9; //uTimeBin + // Double_t dTimeSinceStartMin = dTimeSinceStartSec / 60.0; + + fviFebCountsSinceLastRateUpdate[uFebIdx]++; + fvdFebChanCountsSinceLastRateUpdate[uFebIdx][uChanInFeb] += 1; + + // fhMuchFebChanHitRateEvo[ uFebIdx ]->Fill( dTimeSinceStartSec, uChanInFeb ); + //fhMuchFebAsicHitRateEvo[ uFebIdx ]->Fill( dTimeSinceStartSec, uAsicInFeb ); + // fhMuchFebHitRateEvo[ uFebIdx ]->Fill( dTimeSinceStartSec ); + // fhMuchFebHitRateEvo_mskch[ uFebIdx ]->Fill( dTimeSinceStartSec ); + // if(usRawAdc>1)fhMuchFebHitRateEvo_mskch_adccut[ uFebIdx ]->Fill( dTimeSinceStartSec ); + //fhMuchFebChanHitRateEvoLong[ uFebIdx ]->Fill( dTimeSinceStartMin, uChanInFeb, 1.0/60.0 ); + //fhMuchFebAsicHitRateEvoLong[ uFebIdx ]->Fill( dTimeSinceStartMin, uAsicInFeb, 1.0/60.0 ); + //fhMuchFebHitRateEvoLong[ uFebIdx ]->Fill( dTimeSinceStartMin, 1.0/60.0 ); + + fhMuchFebSpill[uFebIdx]->Fill(dTimeSinceStartSec); + fhMuchFebChanCntRaw[uFebIdx]->Fill(usChan); + fhMuchChannelTime[uFebIdx]->Fill(dTimeSinceStartSec, usChan); + + /* + if( mess.IsHitMissedEvts() ) + { + fhMuchFebChanMissEvtEvo[ uFebIdx ]->Fill( dTimeSinceStartSec, uChanInFeb ); + fhMuchFebAsicMissEvtEvo[ uFebIdx ]->Fill( dTimeSinceStartSec, uAsicInFeb ); + fhMuchFebMissEvtEvo[ uFebIdx ]->Fill( dTimeSinceStartSec ); + } // if( mess.IsHitMissedEvts() ) + //if(fvdChanLastHitTime[ uAsicIdx ][ usChan ] == prevTime && uAsicIdx == prevAsic && usChan == prevChan) + */ + if (fvdChanLastHitTime[uAsicIdx][usChan] == prevTime && usChan == prevChan) { + //fDupliCount++; + } + else { + // fhMuchFebHitRateEvo_WithoutDupli[ uFebIdx ]->Fill( dTimeSinceStartSec ); + } + prevTime = fvdChanLastHitTime[uAsicIdx][usChan]; + prevChan = usChan; + prevAsic = uAsicIdx; +} + +void CbmMcbm2018MonitorAlgoMuchLite::FillTsMsbInfo(stsxyter::Message mess, UInt_t /*uMessIdx*/, UInt_t /*uMsIdx*/) +{ + UInt_t uVal = mess.GetTsMsbVal(); + /// => Quick and dirty hack for binning FW!!! + if (kTRUE == fbBinningFw) uVal = mess.GetTsMsbValBinning(); + + // Update Status counters + if (uVal < fvulCurrentTsMsb[fuCurrDpbIdx]) { + + fvuCurrentTsMsbCycle[fuCurrDpbIdx]++; + } // if( uVal < fvulCurrentTsMsb[fuCurrDpbIdx] ) + fvulCurrentTsMsb[fuCurrDpbIdx] = uVal; + /* + ULong64_t ulNewTsMsbTime = static_cast< ULong64_t >( stsxyter::kuHitNbTsBins ) + * static_cast< ULong64_t >( fvulCurrentTsMsb[fuCurrDpbIdx]) + + static_cast< ULong64_t >( stsxyter::kulTsCycleNbBins ) + * static_cast< ULong64_t >( fvuCurrentTsMsbCycle[fuCurrDpbIdx] ); +*/ +} + +void CbmMcbm2018MonitorAlgoMuchLite::FillEpochInfo(stsxyter::Message /*mess*/) +{ + // UInt_t uVal = mess.GetEpochVal(); + // UInt_t uCurrentCycle = uVal % stsxyter::kulTsCycleNbBins; +} + +void CbmMcbm2018MonitorAlgoMuchLite::SaveAllHistos(TString sFileName) +{ + /// Save old global file and folder pointer to avoid messing with FairRoot + TFile* oldFile = gFile; + TDirectory* oldDir = gDirectory; + + TFile* histoFile = NULL; + if ("" != sFileName) { + // open separate histo file in recreate mode + histoFile = new TFile(sFileName, "RECREATE"); + histoFile->cd(); + } // if( "" != sFileName ) + + /***************************/ + gDirectory->mkdir("Much_Raw"); + gDirectory->cd("Much_Raw"); + + for (UInt_t uModuleId = 0; uModuleId < 2; ++uModuleId) { + // fHistPadDistr[uModuleId]->Write(); + // fRealHistPadDistr[uModuleId]->Write(); + // fhMuchFebDuplicateHitProf[uModuleId]->Write(); + } + // fhRate->Write(); + // fhRateAdcCut->Write(); + fhFEBcount->Write(); + // fhMuchMessType->Write(); + // fhMuchSysMessType->Write(); + // fhMuchMessTypePerDpb->Write(); + // fhMuchSysMessTypePerDpb->Write(); + // fhStatusMessType->Write(); + fhMsStatusFieldType->Write(); + fhMuchHitsElinkPerDpb->Write(); + // fhMuchFebChanAdcRaw_combined->Write(); + fhDpbMsErrors->Write(); + gDirectory->cd(".."); + /***************************/ + + /***************************/ + gDirectory->mkdir("Much_Feb"); + gDirectory->cd("Much_Feb"); + for (UInt_t uFebIdx = 0; uFebIdx < fuNbFebs; ++uFebIdx) { + if (kTRUE == fUnpackParMuch->IsFebActive(uFebIdx)) { + fhMuchFebChanCntRaw[uFebIdx]->Write(); + fhMuchFebSpill[uFebIdx]->Write(); + fhMuchChannelTime[uFebIdx]->Write(); + fhMuchFebADC[uFebIdx]->Write(); + //fhMuchFebChanCntRawGood[ uFebIdx ]->Write(); + // fhMuchFebChanAdcRaw[ uFebIdx ]->Write(); + // fhMuchFebChanAdcRawProf[ uFebIdx ]->Write(); + //fhMuchFebChanAdcCal[ uFebIdx ]->Write(); + //fhMuchFebChanAdcCalProf[ uFebIdx ]->Write(); + // fhMuchFebChanRawTs[ uFebIdx ]->Write(); + // fhMuchFebChanHitRateProf[ uFebIdx ]->Write(); + //fhMuchFebAsicHitRateEvo[ uFebIdx ]->Write(); + // fhMuchFebHitRateEvo[ uFebIdx ]->Write(); + // fhMuchFebHitRateEvo_mskch[ uFebIdx ]->Write(); + // fhMuchFebHitRateEvo_mskch_adccut[ uFebIdx ]->Write(); + // fhMuchFebHitRateEvo_WithoutDupli[ uFebIdx ]->Write(); + /*fhMuchFebChanHitRateEvoLong[ uFebIdx ]->Write(); + fhMuchFebAsicHitRateEvoLong[ uFebIdx ]->Write(); + fhMuchFebHitRateEvoLong[ uFebIdx ]->Write(); + fhMuchFebChanDistT[ uFebIdx ]->Write(); + for( UInt_t uFebIdxB = uFebIdx; uFebIdxB < fuNbFebs; ++uFebIdxB ) + { + fhMuchFebChanDtCoinc[ uFebIdx ][ uFebIdxB ]->Write(); + fhMuchFebChanCoinc[ uFebIdx ][ uFebIdxB ]->Write(); + } // for( UInt_t uFebIdxB = uFebIdx; uFebIdxB < fuNbFebs; ++uFebIdxB )*/ + } // if( kTRUE == fUnpackParMuch->IsFebActive( uFebIdx ) ) + } // for( UInt_t uFebIdx = 0; uFebIdx < fuNbFebs; ++uFebIdx ) + gDirectory->cd(".."); + /***************************/ + + /***************************/ + // Flib Histos + gDirectory->mkdir("Flib_Raw"); + gDirectory->cd("Flib_Raw"); + for (UInt_t uLinks = 0; uLinks < kiMaxNbFlibLinks; uLinks++) { + TString sMsSzName = Form("MsSz_link_%02u", uLinks); + if (fHM->Exists(sMsSzName.Data())) fHM->H1(sMsSzName.Data())->Write(); + + sMsSzName = Form("MsSzTime_link_%02u", uLinks); + if (fHM->Exists(sMsSzName.Data())) fHM->P1(sMsSzName.Data())->Write(); + } // for( UInt_t uLinks = 0; uLinks < 16; uLinks ++) + + /***************************/ + + if ("" != sFileName) { + // Restore original directory position + histoFile->Close(); + } // if( "" != sFileName ) + + /// Restore old global file and folder pointer to avoid messing with FairRoot + gFile = oldFile; + gDirectory = oldDir; +} + +void CbmMcbm2018MonitorAlgoMuchLite::ResetAllHistos() +{ + LOG(info) << "Reseting all Much histograms."; + + for (UInt_t uModuleId = 0; uModuleId < 2; ++uModuleId) { + //fHistPadDistr[uModuleId]->Reset(); + //fRealHistPadDistr[uModuleId]->Reset(); + fhMuchFebDuplicateHitProf[uModuleId]->Reset(); + } + // fhRate->Reset(); + // fhRateAdcCut->Reset(); + fhFEBcount->Reset(); + // fhMuchMessType->Reset(); + // fhMuchSysMessType->Reset(); + // fhMuchMessTypePerDpb->Reset(); + // fhMuchSysMessTypePerDpb->Reset(); + // fhStatusMessType->Reset(); + fhMsStatusFieldType->Reset(); + fhMuchHitsElinkPerDpb->Reset(); + // fhMuchFebChanAdcRaw_combined->Reset(); + fhDpbMsErrors->Reset(); + + for (UInt_t uFebIdx = 0; uFebIdx < fuNbFebs; ++uFebIdx) { + if (kTRUE == fUnpackParMuch->IsFebActive(uFebIdx)) { + fhMuchFebChanCntRaw[uFebIdx]->Reset(); + fhMuchFebSpill[uFebIdx]->Reset(); + fhMuchChannelTime[uFebIdx]->Reset(); + fhMuchFebADC[uFebIdx]->Reset(); + //fhMuchFebChanCntRawGood[ uFebIdx ]->Reset(); + //// fhMuchFebChanAdcRaw[ uFebIdx ]->Reset(); + //fhMuchFebChanAdcRawProf[ uFebIdx ]->Reset(); + //fhMuchFebChanAdcCal[ uFebIdx ]->Reset(); + //fhMuchFebChanAdcCalProf[ uFebIdx ]->Reset(); + ////fhMuchFebChanRawTs[ uFebIdx ]->Reset(); + // fhMuchFebChanHitRateEvo[ uFebIdx ]->Reset(); + // fhMuchFebChanHitRateProf[ uFebIdx ]->Reset(); + //fhMuchFebAsicHitRateEvo[ uFebIdx ]->Reset(); + //// fhMuchFebHitRateEvo[ uFebIdx ]->Reset(); + // fhMuchFebHitRateEvo_mskch[ uFebIdx ]->Reset(); + // fhMuchFebHitRateEvo_mskch_adccut[ uFebIdx ]->Reset(); + // fhMuchFebHitRateEvo_WithoutDupli[ uFebIdx ]->Reset(); + /*fhMuchFebChanHitRateEvoLong[ uFebIdx ]->Reset(); + fhMuchFebAsicHitRateEvoLong[ uFebIdx ]->Reset(); + fhMuchFebHitRateEvoLong[ uFebIdx ]->Reset(); + fhMuchFebChanDistT[ uFebIdx ]->Reset(); + for( UInt_t uFebIdxB = uFebIdx; uFebIdxB < fuNbFebs; ++uFebIdxB ) + { + fhMuchFebChanDtCoinc[ uFebIdx ][ uFebIdxB ]->Reset(); + fhMuchFebChanCoinc[ uFebIdx ][ uFebIdxB ]->Reset(); + } // for( UInt_t uFebIdxB = uFebIdx; uFebIdxB < fuNbFebs; ++uFebIdxB )*/ + } // if( kTRUE == fUnpackParMuch->IsFebActive( uFebIdx ) ) + } // for( UInt_t uFebIdx = 0; uFebIdx < fuNbFebs; ++uFebIdx ) + + for (UInt_t uLinks = 0; uLinks < kiMaxNbFlibLinks; ++uLinks) { + TString sMsSzName = Form("MsSz_link_%02u", uLinks); + if (fHM->Exists(sMsSzName.Data())) fHM->H1(sMsSzName.Data())->Reset(); + + sMsSzName = Form("MsSzTime_link_%02u", uLinks); + if (fHM->Exists(sMsSzName.Data())) fHM->P1(sMsSzName.Data())->Reset(); + } // for( UInt_t uLinks = 0; uLinks < kiMaxNbFlibLinks; ++uLinks ) + + fdStartTime = -1; + fdStartTimeMsSz = -1; +} + +void CbmMcbm2018MonitorAlgoMuchLite::SetRunStart(Int_t dateIn, Int_t timeIn, Int_t iBinSize) +{ + TDatime* fRunStartDateTime = new TDatime(dateIn, timeIn); + fiRunStartDateTimeSec = fRunStartDateTime->Convert(); + fiBinSizeDatePlots = iBinSize; + + LOG(info) << "Assigned new MUCH Run Start Date-Time: " << fRunStartDateTime->AsString(); +} + +///------------------------------------------------------------------/// +Bool_t CbmMcbm2018MonitorAlgoMuchLite::ScanForNoisyChannels(Double_t dNoiseThreshold) +{ + for (UInt_t uFebIdx = 0; uFebIdx < fuNbFebs; ++uFebIdx) { + if (kTRUE == fUnpackParMuch->IsFebActive(uFebIdx)) { + LOG(info) << Form(" ------------------ Noisy channels scan for FEB %2d ------------", uFebIdx); + for (UInt_t uAsicIdx = 0; uAsicIdx < fUnpackParMuch->GetNbAsicsPerFeb(); ++uAsicIdx) + for (UInt_t uChanIdx = 0; uChanIdx < fUnpackParMuch->GetNbChanPerAsic(); ++uChanIdx) { + UInt_t uChanInFeb = uAsicIdx * fUnpackParMuch->GetNbChanPerAsic() + uChanIdx; + if (dNoiseThreshold < fhMuchFebChanHitRateProf[uFebIdx]->GetBinContent(1 + uChanInFeb)) + LOG(info) << Form("Noisy Channel ASIC %d channel %3d (%4d) level %6.0f", uAsicIdx, uChanIdx, uChanInFeb, + fhMuchFebChanHitRateProf[uFebIdx]->GetBinContent(1 + uChanInFeb)); + + } // for( UInt_t uChanIdx = 0; uChanIdx < fUnpackParMuch->GetNbChanPerAsic(); ++uChanIdx ) + + LOG(info) << " ---------------------------------------------------------------"; + } // if( kTRUE == fUnpackParMuch->IsFebActive( uFebIdx ) ) + } // for( UInt_t uFebIdx = 0; uFebIdx < fuNbFebs; ++uFebIdx ) + return kTRUE; +} + +//-----------------------------------------------------------------// + +ClassImp(CbmMcbm2018MonitorAlgoMuchLite) diff --git a/fles/mcbm2018/monitor/CbmMcbm2018MonitorAlgoMuchLite.h b/fles/mcbm2018/monitor/CbmMcbm2018MonitorAlgoMuchLite.h new file mode 100644 index 0000000000000000000000000000000000000000..92f6916e2886d8ce0752e3b1d199cf708f88b59f --- /dev/null +++ b/fles/mcbm2018/monitor/CbmMcbm2018MonitorAlgoMuchLite.h @@ -0,0 +1,309 @@ +// ----------------------------------------------------------------------------- +// ----- ----- +// ----- CbmMcbm2018MonitorMuchLite ----- +// ----- Created 11/05/18 by P.-A. Loizeau ----- +// ----- Modified 07/12/18 by Ajit Kumar ----- +// ----- Modified 05/03/19 by Vikas Singhal ----- +// ----- ----- +// ----------------------------------------------------------------------------- + +#ifndef CbmMcbm2018MonitorAlgoMuchLite_H +#define CbmMcbm2018MonitorAlgoMuchLite_H + +#ifndef __CINT__ +#include "Timeslice.hpp" +#endif + +// Data +#include "StsXyterFinalHit.h" +#include "StsXyterMessage.h" + +// CbmRoot +#include "CbmHistManager.h" +#include "CbmMcbmUnpack.h" +#include "CbmMuchBeamTimeDigi.h" +#include "CbmStar2019Algo.h" + +// C++11 +#include <chrono> + +// C/C++ +#include <map> +#include <set> +#include <vector> + +class CbmMcbm2018MuchPar; +//class CbmCern2017UnpackParSts; + +class CbmMcbm2018MonitorAlgoMuchLite : public CbmStar2019Algo<CbmMuchBeamTimeDigi> { +public: + CbmMcbm2018MonitorAlgoMuchLite(); + CbmMcbm2018MonitorAlgoMuchLite(const CbmMcbm2018MonitorAlgoMuchLite&); + CbmMcbm2018MonitorAlgoMuchLite operator=(const CbmMcbm2018MonitorAlgoMuchLite&); + ~CbmMcbm2018MonitorAlgoMuchLite(); + + + virtual Bool_t Init(); + + virtual void Reset(); + + virtual void Finish(); + + Bool_t InitContainers(); + + Bool_t ReInitContainers(); + TList* GetParList(); + Bool_t InitParameters(); + Bool_t InitMuchParameters(); + + Bool_t ProcessTs(const fles::Timeslice& ts); + Bool_t ProcessTs(const fles::Timeslice& ts, size_t /*component*/) { return ProcessTs(ts); } + //Bool_t ProcessMs(const fles::Timeslice& ts, size_t uMsCompIdx, size_t uMsIdx); + + void AddMsComponentToList(size_t component, UShort_t usDetectorId); + Bool_t CreateHistograms(); + void SaveMuchHistos(TString sFileName = ""); + void ResetMuchHistos(); + inline void SetMonitorMode(Bool_t bFlagIn = kTRUE) { fbMonitorMode = bFlagIn; } + inline void SetHistoryHistoSize(UInt_t inHistorySizeSec = 1800) { fuHistoryHistoSize = inHistorySizeSec; } + inline void SetSpillThreshold(UInt_t uCntLimit) { fuOffSpillCountLimit = uCntLimit; } + //void SetNbMsInTs(size_t uCoreMsNb, size_t uOverlapMsNb); + //void SetMsOverlap(size_t uOverlapMsNb = 1) { fuNbOverMsPerTs = uOverlapMsNb; } + //size_t GetMsOverlap() { return fuNbOverMsPerTs; } + Bool_t ProcessMs(const fles::Timeslice& ts, size_t uMsCompIdx, size_t uMsIdx); + + void SetRunStart(Int_t dateIn, Int_t timeIn, Int_t iBinSize = 5); + void FillHitInfo(stsxyter::Message mess, const UShort_t& usElinkIdx, const UInt_t& uAsicIdx, const UInt_t& uMsIdx); + + /*void + FillTsMsbInfo(stsxyter::Message mess, UInt_t uMessIdx = 0, UInt_t uMsIdx = 0); + void FillEpochInfo(stsxyter::Message mess); + + void + FillTsMsbInfo(stsxyter::Message mess, UInt_t uMessIdx = 0, UInt_t uMsIdx = 0); + void FillEpochInfo(stsxyter::Message mess); + + + + Bool_t ScanForNoisyChannels(Double_t dNoiseThreshold = 1e3); */ + + void ResetAllHistos(); + void SaveAllHistos(TString sFileName = ""); + void SaveHistos(TString sFileName = ""); + void SetHistoFileName(TString sFileName = "data/SetupHistos.root") { fsHistoFileFullname = sFileName; } + + void SetPrintMessage(Bool_t bPrintMessOn = kTRUE, + stsxyter::MessagePrintMask ctrl = stsxyter::MessagePrintMask::msg_print_Hex + | stsxyter::MessagePrintMask::msg_print_Human) + { + fbPrintMessages = bPrintMessOn; + fPrintMessCtrl = ctrl; + } + //void SetLongDurationLimits( UInt_t uDurationSeconds = 3600, UInt_t uBinSize = 1 ); + //void SetEnableCoincidenceMaps( Bool_t bEnableCoincidenceMapsOn = kTRUE ) { fbEnableCoincidenceMaps = bEnableCoincidenceMapsOn; } + //void SetCoincidenceBorder( Double_t dCenterPos, Double_t dBorderVal ); + //void SetFebChanCoincidenceLimitNs( Double_t dLimitIn ) { fdFebChanCoincidenceLimit = dLimitIn; } + //void UseNoiseLimitsSmx2LogicError( Bool_t bUseNoise = kTRUE ) { fbSmx2ErrorUseNoiseLevels = bUseNoise; } + + void SetMuchMode(Bool_t bMuchMode = kTRUE) { fbMuchMode = bMuchMode; } + + // void SetTimeBin( size_t uTimeBin ); + void UseDaqBuffer(Bool_t) {}; //Virtual function in Mother Class, Need to update accordingly. VS + + /// => Quick and dirty hack for binning FW!!! + void SetBinningFwFlag(Bool_t bEnable = kTRUE) { fbBinningFw = bEnable; } + Bool_t ScanForNoisyChannels(Double_t dNoiseThreshold = 1e3); + +private: + // Parameters + // Control flags + Bool_t fbMonitorMode = kFALSE; //! Switch ON the filling of a minimal set of histograms + Bool_t fbMuchMode; + std::vector<Bool_t> fvbMaskedComponents; + /// Hits time-sorting + std::vector<stsxyter::FinalHit> + fvmHitsInMs; //! All hits (time in bins, ADC in bins, asic, channel) in last TS, sorted with "<" operator + TString fsHistoFilename; + /// Task configuration values + Bool_t fbPrintMessages; + stsxyter::MessagePrintMask fPrintMessCtrl; + ULong64_t fulCurrentTsIdx; + size_t fuNbCoreMsPerTs; //! + UInt_t fuNrOfDpbs; //! Total number of STS DPBs in system + std::map<UInt_t, UInt_t> fDpbIdIndexMap; //! Map of DPB Identifier to DPB index + std::vector<std::vector<Bool_t>> + fvbCrobActiveFlag; //! Array to hold the active flag for all CROBs, [ NbDpb ][ NbCrobPerDpb ] + UInt_t fuNbFebs; //! Number of StsXyter ASICs + UInt_t fuNbStsXyters; //! Number of StsXyter ASICs + std::map<stsxyter::MessType, UInt_t> fmMsgCounter; + CbmMcbm2018MuchPar* fUnpackParMuch; //! + + /// => Quick and dirty hack for binning FW!!! + Bool_t fbBinningFw = kTRUE; + + // CbmMcbm2018MuchPar* fUnpackPar = nullptr; //! + + Double_t fdTsStartTime = -1.0; //! Time in ns of current TS from the index of the first MS first component + Double_t fdTsStopTimeCore = + -1.0; //! End Time in ns of current TS Core from the index of the first MS first component + + UInt_t fuMsIndex = 0; //! Index of current MS within the TS + + /// Histograms related variables + UInt_t fuHistoryHistoSize = 3600; /** Size in seconds of the evolution histograms **/ + UInt_t fuOffSpillCountLimit = 200; + + Bool_t fbIgnoreOverlapMs; //! /** Ignore Overlap Ms: all fuOverlapMsNb MS at the end of timeslice **/ + // Unpacking and mapping + //std::vector< std::vector< std::vector< Double_t > > > fvdFebAdcGain; //! ADC gain in e-/b, [ NbDpb ][ NbCrobPerDpb ][ NbFebsPerCrob ] + //std::vector< std::vector< std::vector< Double_t > > > fvdFebAdcOffs; //! ADC offset in e-, [ NbDpb ][ NbCrobPerDpb ][ NbFebsPerCrob ] + + // Constants + static const Int_t kiMaxNbFlibLinks = 32; + static const UInt_t kuBytesPerMessage = 4; + + /// Internal Control/status of monitor + /// Histo File name and path + TString fsHistoFileFullname; + //Bool_t fbEnableCoincidenceMaps; + /// TS/MS info + ULong64_t fulCurrentMsIdx; + /// Current data properties + UInt_t fuCurrentEquipmentId; //! Current equipment ID, tells from which DPB the current MS is originating + UInt_t fuCurrDpbId; //! Temp holder until Current equipment ID is properly filled in MS + UInt_t fuCurrDpbIdx; //! Index of the DPB from which the MS currently unpacked is coming + Int_t fiRunStartDateTimeSec; //! Start of run time since "epoch" in s, for the plots with date as X axis + Int_t fiBinSizeDatePlots; //! Bin size in s for the plots with date as X axis + + /// Data format control + std::vector<ULong64_t> fvulCurrentTsMsb; //! Current TS MSB for each DPB + std::vector<UInt_t> fvuCurrentTsMsbCycle; //! Current TS MSB cycle for DPB + std::vector<UInt_t> fvuInitialHeaderDone; //! Flag set after seeing MS header in 1st MS for DPB + std::vector<UInt_t> fvuInitialTsMsbCycleHeader; //! TS MSB cycle from MS header in 1st MS for DPB + std::vector<UInt_t> fvuElinkLastTsHit; //! TS from last hit for DPB + /// Hits comparison + std::vector<std::vector<ULong64_t>> fvulChanLastHitTime; //! Last hit time in bins for each Channel + //std::vector< std::vector< ULong64_t > > fvdChanLastHitTime; //! Last hit time in ns for each Channel + std::vector<std::vector<Double_t>> fvdChanLastHitTime; //! Last hit time in ns for each Channel + std::vector<Double_t> fvdPrevMsTime; //! Header time of previous MS per link + std::vector<Double_t> fvdMsTime; //! Header time of each MS + std::vector<std::vector<std::vector<Double_t>>> + fvdChanLastHitTimeInMs; //! Last hit time in bins in each MS for each Channel + std::vector<std::vector<std::vector<UShort_t>>> + fvusChanLastHitAdcInMs; //! Last hit ADC in bins in each MS for each Channel + + std::vector<std::vector<stsxyter::FinalHit>> + fvmAsicHitsInMs; //! All hits (time in bins, ADC in bins, asic, channel) in last TS, per ASIC, sorted with "<" operator + std::vector<std::vector<stsxyter::FinalHit>> + fvmFebHitsInMs; //! All hits (time in bins, ADC in bins, asic, channel) in last TS, per FEB, sorted with "<" operator + /// Mean Rate per channel plots + Int_t fiTimeIntervalRateUpdate; + std::vector<Int_t> fviFebTimeSecLastRateUpdate; + std::vector<Int_t> fviFebCountsSinceLastRateUpdate; + std::vector<std::vector<Double_t>> fvdFebChanCountsSinceLastRateUpdate; + /// Rate evolution histos + //Bool_t fbLongHistoEnable; + //UInt_t fuLongHistoNbSeconds; + //UInt_t fuLongHistoBinSizeSec; + //UInt_t fuLongHistoBinNb; + UInt_t Counter; + UInt_t Counter1; + /// Coincidences in sorted hits + //Double_t fdCoincCenter; // ns + //Double_t fdCoincBorder; // ns, +/- + //Double_t fdCoincMin; // ns + //Double_t fdCoincMax; // ns + + /// Histograms + CbmHistManager* fHM; //! Histogram manager + TH1* fhMuchMessType; + TH1* fhMuchSysMessType; + TH1* fhMuchFebChanAdcRaw_combined; + TH2* fhMuchMessTypePerDpb; + TH2* fhMuchSysMessTypePerDpb; + TH2* fhStatusMessType; + TH2* fhMsStatusFieldType; + TH2* fhMuchHitsElinkPerDpb; + + TH1* fhRate; + TH1* fhRateAdcCut; + TH1* fhFEBcount = nullptr; + // std::vector<TH1 *> fhMuchFebChanRateEvo; + + /// Plots per FEB-8 + //UInt_t kuNbAsicPerFeb = 1; + + std::vector<TH2*> fHistPadDistr; + std::vector<TH2*> fRealHistPadDistr; + + //Double_t fdFebChanCoincidenceLimit; // ns + std::vector<TH1*> fhMuchFebChanCntRaw; + std::vector<TH1*> fhMuchFebSpill = {}; + std::vector<TH2*> fhMuchFebADC = {}; + //std::vector<TH1 *> fhMuchFebChanCntRawGood; + std::vector<TH2*> fhMuchFebChanAdcRaw; + std::vector<TProfile*> fhMuchFebChanAdcRawProf; + //std::vector<TH2 *> fhMuchFebChanAdcCal; + //std::vector<TProfile*> fhMuchFebChanAdcCalProf; + std::vector<TH2*> fhMuchFebChanRawTs; + std::vector<TH2*> fhMuchChannelTime = {}; + //std::vector<TH2*> fhMuchFebChanMissEvt; + //std::vector<TH2*> fhMuchFebChanMissEvtEvo; + //std::vector<TH2*> fhMuchFebAsicMissEvtEvo; + //std::vector<TH1*> fhMuchFebMissEvtEvo; + std::vector<TH2*> fhMuchFebChanHitRateEvo; + std::vector<TProfile*> fhMuchFebChanHitRateProf; + //std::vector<TH2*> fhMuchFebAsicHitRateEvo; + std::vector<TH1*> fhMuchFebHitRateEvo; + std::vector<TH1*> fhMuchFebHitRateEvo_mskch; + std::vector<TH1*> fhMuchFebHitRateEvo_mskch_adccut; + std::vector<TH1*> fhMuchFebHitRateEvo_WithoutDupli; + //std::vector<TH2*> fhMuchFebChanHitRateEvoLong; + //std::vector<TH2*> fhMuchFebAsicHitRateEvoLong; + //std::vector<TH1*> fhMuchFebHitRateEvoLong; + std::vector<std::vector<Double_t>> fdMuchFebChanLastTimeForDist; + std::vector<TH2*> fhMuchFebChanDistT; + //std::vector< std::vector<TH1*> > fhMuchFebChanDtCoinc; + //std::vector< std::vector<TH2*> > fhMuchFebChanCoinc; + std::vector<TProfile*> fhMuchFebDuplicateHitProf; + + /// Binning FW error flag + TH2* fhDpbMsErrors = nullptr; + + TCanvas* fcMsSizeAll; + + // FLES containers + std::vector<size_t> fvMsComponentsList; //! + + /// Coincidence histos + UInt_t fuMaxNbMicroslices; + + TH1* fhMsSz[kiMaxNbFlibLinks]; + TProfile* fhMsSzTime[kiMaxNbFlibLinks]; + + // std::vector< std::vector< std::multiset< stsxyter::FinalHit > > > fvmChanHitsInTs; //! All hits (time & ADC) in bins in last TS for each Channel + /// Starting state book-keeping + //Long64_t fdStartTime; /** Time of first valid hit (TS_MSB available), used as reference for evolution plots**/ + Long64_t prevtime_new; /** previous time for consecutive hit time**/ + Long64_t prevTime; /** previous time for consecutive hit time**/ + UInt_t prevAsic; /** previous asic**/ + UInt_t prevChan; /** previous channel**/ + Double_t fdStartTime; /** Time of first valid hit (TS_MSB available), used as reference for evolution plots**/ + Double_t fdStartTimeMsSz; /** Time of first microslice, used as reference for evolution plots**/ + std::chrono::steady_clock::time_point + ftStartTimeUnix; /** Time of run Start from UNIX system, used as reference for long evolution plots against reception time **/ + + std::vector<std::vector<std::vector<UInt_t>>> fvuChanNbHitsInMs; //! Number of hits in each MS for each Channel + + // Methods later going into Algo + size_t fuNbOverMsPerTs; //! + + + void FillTsMsbInfo(stsxyter::Message mess, UInt_t uMessIdx = 0, UInt_t uMsIdx = 0); + void FillEpochInfo(stsxyter::Message mess); + + + ClassDef(CbmMcbm2018MonitorAlgoMuchLite, 1) +}; + +#endif // CbmMcbm2018MonitorAlgoMuchLite_H diff --git a/fles/mcbm2018/monitor/CbmMcbm2018MonitorTaskMuchLite.cxx b/fles/mcbm2018/monitor/CbmMcbm2018MonitorTaskMuchLite.cxx new file mode 100644 index 0000000000000000000000000000000000000000..1a8d017aed816ed2c9a7f52e87398d9ef35aca8d --- /dev/null +++ b/fles/mcbm2018/monitor/CbmMcbm2018MonitorTaskMuchLite.cxx @@ -0,0 +1,387 @@ +#include "CbmMcbm2018MonitorTaskMuchLite.h" + +#include "CbmMcbm2018MonitorAlgoMuchLite.h" +#include "CbmMcbm2018MuchPar.h" + +#include "FairLogger.h" +#include "FairParGenericSet.h" +#include "FairRootManager.h" +#include "FairRun.h" +#include "FairRunOnline.h" +#include "FairRuntimeDb.h" + +#include "TCanvas.h" +#include "THttpServer.h" +#include "TList.h" +#include "TROOT.h" +#include "TString.h" +#include <TFile.h> + +#include <chrono> +#include <fstream> +#include <iomanip> +#include <iostream> + +#include <stdint.h> + +Bool_t bMcbm2018ResetTaskMuchLite = kFALSE; +Bool_t bMcbm2018WriteTaskMuchLite = kFALSE; +Bool_t bMcbm2018ScanNoisyTaskMuchLite = kFALSE; + +CbmMcbm2018MonitorTaskMuchLite::CbmMcbm2018MonitorTaskMuchLite() + : CbmMcbmUnpack() + , fbMonitorMode(kTRUE) + , fbDebugMonitorMode(kFALSE) + , fuHistoryHistoSize(3600) + , fsHistoFilename("data/HistosMonitorMuch.root") + , fuOffSpillCountLimit(200) + , fulTsCounter(0) + , fMonitorAlgo(nullptr) +{ + fMonitorAlgo = new CbmMcbm2018MonitorAlgoMuchLite(); +} + +CbmMcbm2018MonitorTaskMuchLite::~CbmMcbm2018MonitorTaskMuchLite() { delete fMonitorAlgo; } + +Bool_t CbmMcbm2018MonitorTaskMuchLite::Init() +{ + LOG(info) << "CbmMcbm2018MonitorTaskMuchLite::Init"; + LOG(info) << "Initializing Much 2019 Monitor"; + + return kTRUE; +} + +void CbmMcbm2018MonitorTaskMuchLite::SetParContainers() +{ + LOG(info) << "Setting parameter containers for " << GetName(); + + TList* parCList = fMonitorAlgo->GetParList(); + + for (Int_t iparC = 0; iparC < parCList->GetEntries(); ++iparC) { + FairParGenericSet* tempObj = (FairParGenericSet*) (parCList->At(iparC)); + parCList->Remove(tempObj); + + std::string sParamName {tempObj->GetName()}; + FairParGenericSet* newObj = + dynamic_cast<FairParGenericSet*>(FairRun::Instance()->GetRuntimeDb()->getContainer(sParamName.data())); + + if (nullptr == newObj) { + LOG(error) << "Failed to obtain parameter container " << sParamName << ", for parameter index " << iparC; + return; + } // if( nullptr == newObj ) + + parCList->AddAt(newObj, iparC); + // delete tempObj; + } // for( Int_t iparC = 0; iparC < parCList->GetEntries(); ++iparC ) + + /*fUnpackParMuch = + (CbmMcbm2018MuchPar*) (FairRun::Instance()->GetRuntimeDb()->getContainer( + "CbmMcbm2018MuchPar")); */ +} + +Bool_t CbmMcbm2018MonitorTaskMuchLite::InitContainers() +{ + LOG(info) << "Init parameter containers for " << GetName(); + + /// Control flags + CbmMcbm2018MuchPar* pUnpackPar = + dynamic_cast<CbmMcbm2018MuchPar*>(FairRun::Instance()->GetRuntimeDb()->getContainer("CbmMcbm2018MuchPar")); + if (nullptr == pUnpackPar) { + LOG(error) << "Failed to obtain parameter container CbmMcbm2018MuchPar"; + return kFALSE; + } // if( nullptr == pUnpackPar ) + /* + fbMonitorMode = pUnpackPar->GetMonitorMode(); + LOG(info) << "Monitor mode: " + << ( fbMonitorMode ? "ON" : "OFF" ); + + fbDebugMonitorMode = pUnpackPar->GetDebugMonitorMode(); + LOG(info) << "Debug Monitor mode: " + << ( fbDebugMonitorMode ? "ON" : "OFF" ); +*/ + + Bool_t initOK = fMonitorAlgo->InitContainers(); + LOG(info) << "after initOK"; + + /// Transfer parameter values set from calling macro + fMonitorAlgo->SetMonitorMode(fbMonitorMode); + fMonitorAlgo->SetHistoryHistoSize(fuHistoryHistoSize); + //fMonitorAlgo->SetPulserTotLimits(fuMinTotPulser, fuMaxTotPulser); + fMonitorAlgo->SetSpillThreshold(fuOffSpillCountLimit); + + /// Histos creation, obtain pointer on them and add them to the HTTP server + /// Trigger histo creation on all associated algos + LOG(info) << "before creating histogram"; + initOK &= fMonitorAlgo->CreateHistograms(); + LOG(info) << "created histograms"; + /// Obtain vector of pointers on each histo from the algo (+ optionally desired folder) + std::vector<std::pair<TNamed*, std::string>> vHistos = fMonitorAlgo->GetHistoVector(); + /// Obtain vector of pointers on each canvas from the algo (+ optionally desired folder) + std::vector<std::pair<TCanvas*, std::string>> vCanvases = fMonitorAlgo->GetCanvasVector(); + + /// Register the histos in the HTTP server + THttpServer* server = FairRunOnline::Instance()->GetHttpServer(); + if (nullptr != server) { + for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) { + // LOG(info) << "Registering " << vHistos[ uHisto ].first->GetName() + // << " in " << vHistos[ uHisto ].second.data(); + server->Register(Form("/%s", vHistos[uHisto].second.data()), vHistos[uHisto].first); + } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto ) + + for (UInt_t uCanv = 0; uCanv < vCanvases.size(); ++uCanv) { + // LOG(info) << "Registering " << vCanvases[ uCanv ].first->GetName() + // << " in " << vCanvases[ uCanv ].second.data(); + server->Register(Form("/%s", vCanvases[uCanv].second.data()), + gROOT->FindObject((vCanvases[uCanv].first)->GetName())); + } // for( UInt_t uCanv = 0; uCanv < vCanvases.size(); ++uCanv ) + + server->RegisterCommand("/Reset_All", "bMcbm2018ResetTaskMuchLite=kTRUE"); + server->RegisterCommand("/Write_All", "bMcbm2018WriteTaskMuchLite=kTRUE"); + server->RegisterCommand("/ScanNoisyCh", "bMcbm2018ScanNoisyTaskMuchLite=kTRUE"); + server->Restrict("/Reset_All", "allow=admin"); + server->Restrict("/Write_All", "allow=admin"); + server->Restrict("/ScanNoisyCh", "allow=admin"); + + } // if( nullptr != server ) + + return initOK; +} + +Bool_t CbmMcbm2018MonitorTaskMuchLite::ReInitContainers() +{ + LOG(info) << "ReInit parameter containers for " << GetName(); + Bool_t initOK = fMonitorAlgo->ReInitContainers(); + + return initOK; +} + +/* Bool_t CbmMcbm2018MonitorTaskMuchLite::InitMuchParameters() { + + fuNrOfDpbs = fUnpackParMuch->GetNrOfDpbs(); + LOG(info) << "Nr. of MUCH DPBs: " << fuNrOfDpbs; + + fDpbIdIndexMap.clear(); + for (UInt_t uDpb = 0; uDpb < fuNrOfDpbs; ++uDpb) { + fDpbIdIndexMap[fUnpackParMuch->GetDpbId(uDpb)] = uDpb; + LOG(info) << "Eq. ID for DPB #" << std::setw(2) << uDpb << " = 0x" + << std::setw(4) << std::hex << fUnpackParMuch->GetDpbId(uDpb) + << std::dec << " => " + << fDpbIdIndexMap[fUnpackParMuch->GetDpbId(uDpb)]; + } // for( UInt_t uDpb = 0; uDpb < fuNrOfDpbs; ++uDpb ) + + fuNbFebs = fUnpackParMuch->GetNrOfFebs(); + LOG(info) << "Nr. of FEBs: " << fuNbFebs; + + fuNbStsXyters = fUnpackParMuch->GetNrOfAsics(); + LOG(info) << "Nr. of StsXyter ASICs: " << fuNbStsXyters; + + fvbCrobActiveFlag.resize(fuNrOfDpbs); + //fvdFebAdcGain.resize( fuNrOfDpbs ); + //fvdFebAdcOffs.resize( fuNrOfDpbs ); + for (UInt_t uDpb = 0; uDpb < fuNrOfDpbs; ++uDpb) { + fvbCrobActiveFlag[uDpb].resize(fUnpackParMuch->GetNbCrobsPerDpb()); + //fvdFebAdcGain[ uDpb ].resize( fUnpackParMuch->GetNbCrobsPerDpb() ); + //fvdFebAdcOffs[ uDpb ].resize( fUnpackParMuch->GetNbCrobsPerDpb() ); + for (UInt_t uCrobIdx = 0; uCrobIdx < fUnpackParMuch->GetNbCrobsPerDpb(); + ++uCrobIdx) { + fvbCrobActiveFlag[uDpb][uCrobIdx] = + fUnpackParMuch->IsCrobActive(uDpb, uCrobIdx); + // fvdFebAdcGain[ uDpb ][ uCrobIdx ].resize( fUnpackParMuch->GetNbFebsPerCrob(), 0.0 ); + //fvdFebAdcOffs[ uDpb ][ uCrobIdx ].resize( fUnpackParMuch->GetNbFebsPerCrob(), 0.0 ); + } // for( UInt_t uCrobIdx = 0; uCrobIdx < fUnpackParMuch->GetNbCrobsPerDpb(); ++uCrobIdx ) + } // for( UInt_t uDpb = 0; uDpb < fuNrOfDpbs; ++uDpb ) + + for (UInt_t uDpb = 0; uDpb < fuNrOfDpbs; ++uDpb) { + for (UInt_t uCrobIdx = 0; uCrobIdx < fUnpackParMuch->GetNbCrobsPerDpb(); + ++uCrobIdx) { + LOG(info) << Form("DPB #%02u CROB #%02u Active: ", uDpb, uCrobIdx) + << fvbCrobActiveFlag[uDpb][uCrobIdx]; + } // for( UInt_t uCrobIdx = 0; uCrobIdx < fUnpackParMuch->GetNbCrobsPerDpb(); ++uCrobIdx ) + } // for( UInt_t uDpb = 0; uDpb < fuNrOfDpbs; ++uDpb ) + + if (fbBinningFw) + LOG(info) << "Unpacking data in bin sorter FW mode"; + else + LOG(info) << "Unpacking data in full time sorter FW mode (legacy)"; + + // Internal status initialization + fvulCurrentTsMsb.resize(fuNrOfDpbs); + fvuCurrentTsMsbCycle.resize(fuNrOfDpbs); + fvuInitialHeaderDone.resize(fuNrOfDpbs); + fvuInitialTsMsbCycleHeader.resize(fuNrOfDpbs); + fvuElinkLastTsHit.resize(fuNrOfDpbs); + for (UInt_t uDpb = 0; uDpb < fuNrOfDpbs; ++uDpb) { + fvulCurrentTsMsb[uDpb] = 0; + fvuCurrentTsMsbCycle[uDpb] = 0; + fvuInitialHeaderDone[uDpb] = kFALSE; + fvuInitialTsMsbCycleHeader[uDpb] = 0; + } // for( UInt_t uDpb = 0; uDpb < fuNrOfDpbs; ++uDpb ) + + fvdPrevMsTime.resize(kiMaxNbFlibLinks); + fvulChanLastHitTime.resize(fuNbStsXyters); + fvdChanLastHitTime.resize(fuNbStsXyters); + fvdMsTime.resize(fuMaxNbMicroslices); + fvuChanNbHitsInMs.resize(fuNbFebs); + fvdChanLastHitTimeInMs.resize(fuNbFebs); + fvusChanLastHitAdcInMs.resize(fuNbFebs); + fvmAsicHitsInMs.resize(fuNbFebs); + + //fvdMsTime.resize( fuMaxNbMicroslices ); + //fvuChanNbHitsInMs.resize( fuNbStsXyters ); + //fvdChanLastHitTimeInMs.resize( fuNbStsXyters ); + //fvusChanLastHitAdcInMs.resize( fuNbStsXyters ); + //fvmAsicHitsInMs.resize( fuNbStsXyters ); + + for (UInt_t uXyterIdx = 0; uXyterIdx < fuNbFebs; ++uXyterIdx) { + fvulChanLastHitTime[uXyterIdx].resize(fUnpackParMuch->GetNbChanPerAsic()); + fvdChanLastHitTime[uXyterIdx].resize(fUnpackParMuch->GetNbChanPerAsic()); + fvuChanNbHitsInMs[uXyterIdx].resize(fUnpackParMuch->GetNbChanPerAsic()); + fvdChanLastHitTimeInMs[uXyterIdx].resize( + fUnpackParMuch->GetNbChanPerAsic()); + fvusChanLastHitAdcInMs[uXyterIdx].resize( + fUnpackParMuch->GetNbChanPerAsic()); + fvmAsicHitsInMs[uXyterIdx].clear(); + + for (UInt_t uChan = 0; uChan < fUnpackParMuch->GetNbChanPerAsic(); + ++uChan) { + fvulChanLastHitTime[uXyterIdx][uChan] = 0; + fvdChanLastHitTime[uXyterIdx][uChan] = -1.0; + + fvuChanNbHitsInMs[uXyterIdx][uChan].resize(fuMaxNbMicroslices); + fvdChanLastHitTimeInMs[uXyterIdx][uChan].resize(fuMaxNbMicroslices); + fvusChanLastHitAdcInMs[uXyterIdx][uChan].resize(fuMaxNbMicroslices); + for (UInt_t uMsIdx = 0; uMsIdx < fuMaxNbMicroslices; ++uMsIdx) { + fvuChanNbHitsInMs[uXyterIdx][uChan][uMsIdx] = 0; + fvdChanLastHitTimeInMs[uXyterIdx][uChan][uMsIdx] = -1.0; + fvusChanLastHitAdcInMs[uXyterIdx][uChan][uMsIdx] = 0; + } // for( UInt_t uMsIdx = 0; uMsIdx < fuMaxNbMicroslices; ++uMsIdx ) + } // for( UInt_t uChan = 0; uChan < fUnpackParMuch->GetNbChanPerAsic(); ++uChan ) + } // for( UInt_t uXyterIdx = 0; uXyterIdx < fuNbStsXyters; ++uXyterIdx ) + + LOG(info) << "CbmMcbm2018MonitorTaskMuchLite::ReInitContainers => Changed " + "fvuChanNbHitsInMs size " + << fvuChanNbHitsInMs.size() << " VS " << fuNbFebs; + LOG(info) << "CbmMcbm2018MonitorTaskMuchLite::ReInitContainers => Changed " + "fvuChanNbHitsInMs size " + << fvuChanNbHitsInMs[0].size() << " VS " + << fUnpackParMuch->GetNbChanPerAsic(); + LOG(info) << "CbmMcbm2018MonitorTaskMuchLite::ReInitContainers => Changed " + "fvuChanNbHitsInMs size " + << fvuChanNbHitsInMs[0][0].size() << " VS " << fuMaxNbMicroslices; + + fvmFebHitsInMs.resize(fuNbFebs); + fviFebTimeSecLastRateUpdate.resize(fuNbFebs, -1); + fviFebCountsSinceLastRateUpdate.resize(fuNbFebs, -1); + fvdFebChanCountsSinceLastRateUpdate.resize(fuNbFebs); + fdMuchFebChanLastTimeForDist.resize(fuNbFebs); + for (UInt_t uFebIdx = 0; uFebIdx < fuNbFebs; ++uFebIdx) { + fvmFebHitsInMs[uFebIdx].clear(); + fvdFebChanCountsSinceLastRateUpdate[uFebIdx].resize( + fUnpackParMuch->GetNbChanPerFeb(), 0.0); + fdMuchFebChanLastTimeForDist[uFebIdx].resize( + fUnpackParMuch->GetNbChanPerFeb(), -1.0); + } // for( UInt_t uFebIdx = 0; uFebIdx < fuNbFebs; ++uFebIdx ) + + ///----------------- SXM 2.0 Logic Error Tagging --------------------/// + // SmxErrInitializeVariables(); + ///------------------------------------------------------------------/// + + return kTRUE; +} */ + +void CbmMcbm2018MonitorTaskMuchLite::AddMsComponentToList(size_t component, UShort_t usDetectorId) +{ + fMonitorAlgo->AddMsComponentToList(component, usDetectorId); +} + +Bool_t CbmMcbm2018MonitorTaskMuchLite::DoUnpack(const fles::Timeslice& ts, size_t /*component*/) +{ + if (bMcbm2018ResetTaskMuchLite) { + fMonitorAlgo->ResetAllHistos(); + bMcbm2018ResetTaskMuchLite = kFALSE; + } // if( bMcbm2018ResetMuchLite ) + if (bMcbm2018WriteTaskMuchLite) { + fMonitorAlgo->SaveAllHistos(fsHistoFilename); + bMcbm2018WriteTaskMuchLite = kFALSE; + } // if( bMcbm2018WriteMuchLite ) + if (bMcbm2018ScanNoisyTaskMuchLite) { + fMonitorAlgo->ScanForNoisyChannels(); + bMcbm2018ScanNoisyTaskMuchLite = kFALSE; + } // if( bMcbm2018WriteMuchLite ) + + + /* if (fbMonitorMode && bMcbm2018MonitorTaskMuchResetHistos) { + LOG(info) << "Reset Much Monitor histos "; + fMonitorAlgo->ResetAllHistos(); + bMcbm2018MonitorTaskMuchResetHistos = kFALSE; + } // if( fbMonitorMode && bMcbm2018MonitorTaskT0ResetHistos ) */ //closed by me + + if (kFALSE == fMonitorAlgo->ProcessTs(ts)) { + //if (kFALSE == fMonitorAlgo->ProcessMuchMs(ts)) { + LOG(error) << "Failed processing TS " << ts.index() << " in unpacker algorithm class"; + return kTRUE; + } // if( kFALSE == fMonitorAlgo->ProcessTs( ts ) ) + + /// Cleqr the digis vector in case it was filled + std::vector<CbmMuchBeamTimeDigi> vDigi = fMonitorAlgo->GetVector(); + fMonitorAlgo->ClearVector(); + + if (0 == fulTsCounter % 10000) LOG(info) << "Processed " << fulTsCounter << "TS"; + fulTsCounter++; + + return kTRUE; +} + + +void CbmMcbm2018MonitorTaskMuchLite::Reset() {} + +void CbmMcbm2018MonitorTaskMuchLite::Finish() +{ + /// Obtain vector of pointers on each histo from the algo (+ optionally desired folder) + std::vector<std::pair<TNamed*, std::string>> vHistos = fMonitorAlgo->GetHistoVector(); + + /// Save old global file and folder pointer to avoid messing with FairRoot + TFile* oldFile = gFile; + TDirectory* oldDir = gDirectory; + + TFile* histoFile = nullptr; + + // open separate histo file in recreate mode + histoFile = new TFile(fsHistoFilename, "RECREATE"); + histoFile->cd(); + + /// Save the histograms in a file + for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) { + /// Make sure we end up in chosen folder + TString sFolder = vHistos[uHisto].second.data(); + if (nullptr == gDirectory->Get(sFolder)) gDirectory->mkdir(sFolder); + gDirectory->cd(sFolder); + + /// Write plot + vHistos[uHisto].first->Write(); + + histoFile->cd(); + } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto ) + + /// Restore old global file and folder pointer to avoid messing with FairRoot + gFile = oldFile; + gDirectory = oldDir; + + histoFile->Close(); +} + +void CbmMcbm2018MonitorTaskMuchLite::SetIgnoreOverlapMs(Bool_t bFlagIn) { fMonitorAlgo->SetIgnoreOverlapMs(bFlagIn); } + +/*void CbmMcbm2018MonitorTaskMuchLite::SetChannelMap(UInt_t uChan0, + UInt_t uChan1, + UInt_t uChan2, + UInt_t uChan3, + UInt_t uChan4, + UInt_t uChan5, + UInt_t uChan6, + UInt_t uChan7) { + fMonitorAlgo->SetChannelMap( + uChan0, uChan1, uChan2, uChan3, uChan4, uChan5, uChan6, uChan7); +} */ + +ClassImp(CbmMcbm2018MonitorTaskMuchLite) diff --git a/fles/mcbm2018/monitor/CbmMcbm2018MonitorTaskMuchLite.h b/fles/mcbm2018/monitor/CbmMcbm2018MonitorTaskMuchLite.h new file mode 100644 index 0000000000000000000000000000000000000000..dd320252a160eca0f4e88ed87d7b2f435ee5b037 --- /dev/null +++ b/fles/mcbm2018/monitor/CbmMcbm2018MonitorTaskMuchLite.h @@ -0,0 +1,126 @@ +// ----------------------------------------------------------------------------- +// ----- ----- +// ----- CbmMcbm2018MonitorMuchLite ----- +// ----- Created 11/05/18 by P.-A. Loizeau ----- +// ----- Modified 07/12/18 by Ajit Kumar ----- +// ----- Modified 05/03/19 by Vikas Singhal ----- +// ----- ----- +// ----------------------------------------------------------------------------- + +#ifndef CbmMcbm2018MonitorTaskMuchLite_H +#define CbmMcbm2018MonitorTaskMuchLite_H + +#ifndef __CINT__ +#include "Timeslice.hpp" +#endif + +// Data +#include "StsXyterFinalHit.h" +#include "StsXyterMessage.h" + +// CbmRoot +#include "CbmHistManager.h" +#include "CbmMcbm2018MonitorAlgoMuchLite.h" +#include "CbmMcbmUnpack.h" + +// C++11 +#include <chrono> + +// C/C++ +#include <map> +#include <set> +#include <vector> + +class CbmMcbm2018MuchPar; +//class CbmCern2017UnpackParSts; + +class CbmMcbm2018MonitorTaskMuchLite : public CbmMcbmUnpack { +public: + CbmMcbm2018MonitorTaskMuchLite(); + //CbmMcbm2018MonitorTaskMuchLite(const CbmMcbm2018MonitorTaskMuchLite&) = delete; + //CbmMcbm2018MonitorTaskMuchLite operator=(const CbmMcbm2018MonitorTaskMuchLite&) = delete; + virtual ~CbmMcbm2018MonitorTaskMuchLite(); + + + virtual Bool_t Init(); + // #ifndef __CINT__ + virtual Bool_t DoUnpack(const fles::Timeslice& ts, size_t component); + //#endif + virtual void Reset(); + + virtual void Finish(); + + void SetParContainers(); + + Bool_t InitContainers(); + + Bool_t ReInitContainers(); + + void AddMsComponentToList(size_t component, UShort_t usDetectorId); + void SetNbMsInTs(size_t /*uCoreMsNb*/, size_t /*uOverlapMsNb*/) {}; + // Algo settings setters + inline void SetMonitorMode(Bool_t bFlagIn = kTRUE) { fbMonitorMode = bFlagIn; } + void SetIgnoreOverlapMs(Bool_t bFlagIn = kTRUE); + //void SetMsOverlap(size_t uOverlapMsNb = 1) { fuNbOverMsPerTs = uOverlapMsNb; } + //size_t GetMsOverlap() { return fuNbOverMsPerTs; } + + //void SetRunStart(Int_t dateIn, Int_t timeIn, Int_t iBinSize = 5); + + //void ResetAllHistos(); + //void SaveAllHistos(TString sFileName = ""); + //void SaveHistos(TString sFileName = ""); + inline void SetHistoryHistoSize(UInt_t inHistorySizeSec = 1800) { fuHistoryHistoSize = inHistorySizeSec; } + inline void SetHistoFileName(TString sFileName = "data/SetupHistos.root") { fsHistoFilename = sFileName; } + inline void SetSpillThreshold(UInt_t uCntLimit) { fuOffSpillCountLimit = uCntLimit; } + + void SetPrintMessage(Bool_t bPrintMessOn = kTRUE, + stsxyter::MessagePrintMask ctrl = stsxyter::MessagePrintMask::msg_print_Hex + | stsxyter::MessagePrintMask::msg_print_Human) + { + fbPrintMessages = bPrintMessOn; + fPrintMessCtrl = ctrl; + } + //void SetLongDurationLimits( UInt_t uDurationSeconds = 3600, UInt_t uBinSize = 1 ); + //void SetEnableCoincidenceMaps( Bool_t bEnableCoincidenceMapsOn = kTRUE ) { fbEnableCoincidenceMaps = bEnableCoincidenceMapsOn; } + //void SetCoincidenceBorder( Double_t dCenterPos, Double_t dBorderVal ); + //void SetFebChanCoincidenceLimitNs( Double_t dLimitIn ) { fdFebChanCoincidenceLimit = dLimitIn; } + //void UseNoiseLimitsSmx2LogicError( Bool_t bUseNoise = kTRUE ) { fbSmx2ErrorUseNoiseLevels = bUseNoise; } + + void SetMuchMode(Bool_t bMuchMode = kTRUE) { fbMuchMode = bMuchMode; } + + // void SetTimeBin( size_t uTimeBin ); + // void UseDaqBuffer( + // Bool_t) {}; //Virtual function in Mother Class, Need to update accordingly. VS + + /// => Quick and dirty hack for binning FW!!! + void SetBinningFwFlag(Bool_t bEnable = kTRUE) { fbBinningFw = bEnable; } + +private: + // Parameters + // Control flags + Bool_t fbMonitorMode; + Bool_t fbDebugMonitorMode; + Bool_t fbMuchMode; + + /// => Quick and dirty hack for binning FW!!! + Bool_t fbBinningFw = kFALSE; + + + /// Histograms related variables + UInt_t fuHistoryHistoSize = 3600; /** Size in seconds of the evolution histograms **/ + TString fsHistoFilename; + UInt_t fuOffSpillCountLimit = 200; + uint64_t fulTsCounter; + Bool_t fbPrintMessages; + //size_t fuNbOverMsPerTs; + stsxyter::MessagePrintMask fPrintMessCtrl; + + //CbmMcbm2018MonitorTaskMuchLite(const CbmMcbm2018MonitorTaskMuchLite&); + //CbmMcbm2018MonitorTaskMuchLite operator=(const CbmMcbm2018MonitorTaskMuchLite&); + + CbmMcbm2018MonitorAlgoMuchLite* fMonitorAlgo; + + ClassDef(CbmMcbm2018MonitorTaskMuchLite, 1) +}; + +#endif // CbmMcbm2018MonitorTaskMuchLite_H diff --git a/macro/beamtime/mcbm2020/MonitorMuchBinning.C b/macro/beamtime/mcbm2020/MonitorMuchBinning.C index 056c0202d263808ab457f4871cec5a3b0ec6cc85..7d01fb12bc9b176cf7c6a804db67f50973ec296d 100644 --- a/macro/beamtime/mcbm2020/MonitorMuchBinning.C +++ b/macro/beamtime/mcbm2020/MonitorMuchBinning.C @@ -53,11 +53,14 @@ void MonitorMuchBinning(TString inFile = "", TString sHostname = "en02", Int_t n std::cout << ">>> Cern2017Monitor: Initialising..." << std::endl; // MUCH Gem Monitor - // CbmMcbm2018MonitorMuch* monitorMuch = new CbmMcbm2018MonitorMuch(); - CbmMcbm2018MonitorMuchLite* monitorMuch = new CbmMcbm2018MonitorMuchLite(); + // CbmMcbm2018MonitorMuch* monitorMuch = new CbmMcbm2018MonitorMuch(); + CbmMcbm2018MonitorTaskMuchLite* monitorMuch = new CbmMcbm2018MonitorTaskMuchLite(); + // Below Older Direct Much Monitoring Class + // CbmMcbm2018MonitorMuchLite* monitorMuch = new CbmMcbm2018MonitorMuchLite(); monitorMuch->SetHistoFileName(sHistoFile); // monitorSts->SetPrintMessage(); - monitorMuch->SetMsOverlap(1); + // Below function not implemented for Task and Algo based MUCH Monitor. + // monitorMuch->SetMsOverlap(1); // monitorMuch->SetEnableCoincidenceMaps( kFALSE ); // monitorSts->SetLongDurationLimits( 3600, 10 ); // monitorSts->SetLongDurationLimits( 7200, 60 );