CbmRoot
Loading...
Searching...
No Matches
CbmMcbmSpillFindAlgo.cxx
Go to the documentation of this file.
1/* Copyright (C) 2019-2021 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Pierre-Alain Loizeau [committer] */
4
5// -----------------------------------------------------------------------------
6// ----- -----
7// ----- CbmMcbmSpillFindAlgo -----
8// ----- Created 10.02.2019 by P.-A. Loizeau -----
9// ----- -----
10// -----------------------------------------------------------------------------
11
13
14#include "CbmFlesHistosTools.h"
16#include "CbmMcbm2018TofPar.h"
17#include "CbmTofAddress.h"
18#include "CbmTofDetectorId_v14a.h" // in cbmdata/tof
19#include "FairRootManager.h"
20#include "FairRun.h"
21#include "FairRunOnline.h"
22#include "FairRuntimeDb.h"
23#include "Logger.h"
24#include "TCanvas.h"
25#include "TH1.h"
26#include "TH2.h"
27#include "TList.h"
28#include "TPaveStats.h"
29#include "TProfile.h"
30#include "TROOT.h"
31#include "TString.h"
32
33#include <cstdint>
34#include <fstream>
35#include <iomanip>
36#include <iostream>
37
38// -------------------------------------------------------------------------
41
42// -------------------------------------------------------------------------
44{
45 LOG(info) << "Initializing mCBM Bmon 2019 monitor algo";
46
47 return kTRUE;
48}
51{
54 if (fbSpillOn) {
57 } // if (fbSpillOn)
58 else
60
62 std::vector<ULong64_t>::iterator itBreakBeg = fvuSpillBreakBegTs.begin();
63 std::vector<ULong64_t>::iterator itBreakEnd = fvuSpillBreakEndTs.begin();
64
65 if (itBreakBeg != fvuSpillBreakBegTs.end() && itBreakEnd != fvuSpillBreakEndTs.end() && *itBreakEnd < *itBreakBeg) {
66 fvuSpillBreakMidTs.push_back((*itBreakEnd + fulFirstTsIdx) / 2);
67 ++itBreakEnd;
68 } // if( itBreakBeg != fvuSpillBreakBegTs.end() && itBreakEnd != fvuSpillBreakEndTs.end() && *itBreakEnd < *itBreakBeg )
69
70 while (itBreakBeg != fvuSpillBreakBegTs.end() && itBreakEnd != fvuSpillBreakEndTs.end()) {
71 fvuSpillBreakMidTs.push_back((*itBreakBeg + *itBreakEnd) / 2);
72 ++itBreakBeg;
73 ++itBreakEnd;
74 } // while( itBreakBeg != fvuSpillBreakBegTs.end() && itBreakEnd != fvuSpillBreakEndTs.end() )
75
76 if (itBreakBeg != fvuSpillBreakBegTs.end()) {
77 fvuSpillBreakMidTs.push_back((*itBreakBeg + fulCurrentTsIdx) / 2);
78 ++itBreakBeg;
79 } // if( itBreakBeg != fvuSpillBreakBegTs.end() )
80
81 if (itBreakBeg != fvuSpillBreakBegTs.end() || itBreakEnd != fvuSpillBreakEndTs.end()) {
82 LOG(warning) << "Size of spill breaks beginning or end did not match: " << fvuSpillBreakBegTs.size() << " VS "
83 << fvuSpillBreakEndTs.size();
84 } // if( itBreakBeg != fvuSpillBreakBegTs.end() || itBreakEnd != fvuSpillBreakEndTs.end() )
85
86 LOG(info) << "**********************************************";
87 LOG(info) << "TS index for beginning of spill breaks:";
88 for (ULong64_t uBeg : fvuSpillBreakBegTs) {
89 LOG(info) << Form("%9llu", uBeg);
90 } // for (ULong64_t uBeg : fvuSpillBreakBegTs)
91 LOG(info) << "**********************************************";
92 LOG(info) << "TS index for ending of spill breaks:";
93 for (ULong64_t uEnd : fvuSpillBreakEndTs) {
94 LOG(info) << Form("%9llu", uEnd);
95 } // for (ULong64_t uBeg : fvuSpillBreakBegTs)
96 LOG(info) << "**********************************************";
97 LOG(info) << "TS index for middle of spill breaks:";
98 for (ULong64_t uMid : fvuSpillBreakMidTs) {
99 LOG(info) << Form("%9llu", uMid);
100 } // for (ULong64_t uBeg : fvuSpillBreakBegTs)
101 LOG(info) << "**********************************************";
102}
103
104// -------------------------------------------------------------------------
106{
107 LOG(info) << "Init parameter containers for CbmMcbmSpillFindAlgo";
108 Bool_t initOK = ReInitContainers();
109
110 return initOK;
111}
113{
114 LOG(info) << "**********************************************";
115 LOG(info) << "ReInit parameter containers for CbmMcbmSpillFindAlgo";
116
117 fUnpackPar = (CbmMcbm2018TofPar*) fParCList->FindObject("CbmMcbm2018TofPar");
118 if (nullptr == fUnpackPar) return kFALSE;
119
120 Bool_t initOK = InitParameters();
121
122 return initOK;
123}
125{
126 if (nullptr == fParCList) fParCList = new TList();
127 fUnpackPar = new CbmMcbm2018TofPar("CbmMcbm2018TofPar");
128 fParCList->Add(fUnpackPar);
129
130 return fParCList;
131}
133{
134
135 fuNrOfGdpbs = fUnpackPar->GetNrOfGdpbs();
136 LOG(info) << "Nr. of Tof GDPBs: " << fuNrOfGdpbs;
137
138 fuNrOfFeePerGdpb = fUnpackPar->GetNrOfFeesPerGdpb();
139 LOG(info) << "Nr. of FEES per Tof GDPB: " << fuNrOfFeePerGdpb;
140
141 fuNrOfGet4PerFee = fUnpackPar->GetNrOfGet4PerFee();
142 LOG(info) << "Nr. of GET4 per Tof FEE: " << fuNrOfGet4PerFee;
143
144 fuNrOfChannelsPerGet4 = fUnpackPar->GetNrOfChannelsPerGet4();
145 LOG(info) << "Nr. of channels per GET4: " << fuNrOfChannelsPerGet4;
146
148 LOG(info) << "Nr. of channels per FEE: " << fuNrOfChannelsPerFee;
149
151 LOG(info) << "Nr. of GET4s: " << fuNrOfGet4;
152
154 LOG(info) << "Nr. of GET4s per GDPB: " << fuNrOfGet4PerGdpb;
155
157 LOG(info) << "Nr. of channels per GDPB: " << fuNrOfChannelsPerGdpb;
158
159 fGdpbIdIndexMap.clear();
160 for (UInt_t i = 0; i < fuNrOfGdpbs; ++i) {
161 fGdpbIdIndexMap[fUnpackPar->GetGdpbId(i)] = i;
162 LOG(info) << "GDPB Id of TOF " << i << " : " << std::hex << fUnpackPar->GetGdpbId(i) << std::dec;
163 } // for( UInt_t i = 0; i < fuNrOfGdpbs; ++i )
164
165 return kTRUE;
166}
167// -------------------------------------------------------------------------
168
169void CbmMcbmSpillFindAlgo::AddMsComponentToList(size_t component, UShort_t usDetectorId)
170{
172 for (UInt_t uCompIdx = 0; uCompIdx < fvMsComponentsList.size(); ++uCompIdx)
173 if (component == fvMsComponentsList[uCompIdx]) return;
174
176 fvMsComponentsList.push_back(component);
177
178 LOG(info) << "CbmMcbmSpillFindAlgo::AddMsComponentToList => Component " << component << " with detector ID 0x"
179 << std::hex << usDetectorId << std::dec << " added to list";
180}
181// -------------------------------------------------------------------------
182
183Bool_t CbmMcbmSpillFindAlgo::ProcessTs(const fles::Timeslice& ts)
184{
185 fulCurrentTsIdx = ts.index();
186 fdTsStartTime = static_cast<Double_t>(ts.descriptor(0, 0).idx);
188
190 if (0 == fulCurrentTsIdx) return kTRUE;
191
193 if (-1.0 == fdTsCoreSizeInNs) {
194 fuNbCoreMsPerTs = ts.num_core_microslices();
195 fuNbOverMsPerTs = ts.num_microslices(0) - ts.num_core_microslices();
198 LOG(info) << "Timeslice parameters: each TS has " << fuNbCoreMsPerTs << " Core MS and " << fuNbOverMsPerTs
199 << " Overlap MS, for a core duration of " << fdTsCoreSizeInNs << " ns and a full duration of "
200 << fdTsFullSizeInNs << " ns";
201
205 LOG(info) << "In each TS " << fuNbMsLoop << " MS will be looped over";
206 } // if( -1.0 == fdTsCoreSizeInNs )
207
210 // LOG(info) << Form( "TS %5d Start %12f Stop %12f", fulCurrentTsIdx, fdTsStartTime, fdTsStopTimeCore );
211
213 for (fuMsIndex = 0; fuMsIndex < fuNbMsLoop; fuMsIndex++) {
215 for (UInt_t uMsCompIdx = 0; uMsCompIdx < fvMsComponentsList.size(); ++uMsCompIdx) {
216 UInt_t uMsComp = fvMsComponentsList[uMsCompIdx];
217
218 if (kFALSE == ProcessMs(ts, uMsComp, fuMsIndex)) {
219 LOG(error) << "Failed to process ts " << fulCurrentTsIdx << " MS " << fuMsIndex << " for component " << uMsComp;
220 return kFALSE;
221 } // if( kFALSE == ProcessMs( ts, uMsCompIdx, fuMsIndex ) )
222 } // for( UInt_t uMsCompIdx = 0; uMsCompIdx < fvMsComponentsList.size(); ++uMsCompIdx )
223 } // for( fuMsIndex = 0; fuMsIndex < uNbMsLoop; fuMsIndex ++ )
224
226 if (fbMonitorMode) {
227 if (kFALSE == FillHistograms()) {
228 LOG(error) << "Failed to fill histos in ts " << fulCurrentTsIdx;
229 return kFALSE;
230 } // if( kFALSE == FillHistograms() )
231 } // if( fbMonitorMode )
232
233 return kTRUE;
234}
235
236Bool_t CbmMcbmSpillFindAlgo::ProcessMs(const fles::Timeslice& ts, size_t uMsCompIdx, size_t uMsIdx)
237{
238 auto msDescriptor = ts.descriptor(uMsCompIdx, uMsIdx);
239 fuCurrentEquipmentId = msDescriptor.eq_id;
240 const uint8_t* msContent = reinterpret_cast<const uint8_t*>(ts.content(uMsCompIdx, uMsIdx));
241
242 uint32_t uSize = msDescriptor.size;
243 fulCurrentMsIdx = msDescriptor.idx;
244 fdMsTime = (1e-9) * static_cast<double>(fulCurrentMsIdx);
245 LOG(debug) << "Microslice: " << fulCurrentMsIdx << " from EqId " << std::hex << fuCurrentEquipmentId << std::dec
246 << " has size: " << uSize;
247
248 if (0 == fvbMaskedComponents.size()) fvbMaskedComponents.resize(ts.num_components(), kFALSE);
249
250 fuCurrDpbId = static_cast<uint32_t>(fuCurrentEquipmentId & 0xFFFF);
251
252 /*
253 * Should be only for first detected TS
254 */
255 if (fulCurrentTsIdx < 10 && 0 == uMsIdx) {
256 LOG(info) << "---------------------------------------------------------------";
257 LOG(info) << "Component " << uMsCompIdx << " TS Idx " << fulCurrentTsIdx;
258 LOG(info) << "hi hv eqid flag si sv idx/start crc size offset";
259 LOG(info) << Form("%02x %02x %04x %04x %02x %02x %016lx %08x %08x %016lx",
260 static_cast<unsigned int>(msDescriptor.hdr_id), static_cast<unsigned int>(msDescriptor.hdr_ver),
261 msDescriptor.eq_id, msDescriptor.flags, static_cast<unsigned int>(msDescriptor.sys_id),
262 static_cast<unsigned int>(msDescriptor.sys_ver), static_cast<unsigned long>(msDescriptor.idx),
263 msDescriptor.crc, msDescriptor.size, static_cast<unsigned long>(msDescriptor.offset));
264 } // if( fulCurrentTsIdx < 10 && 0 == uMsIdx )
265 /*
266*/
267
269 auto it = fGdpbIdIndexMap.find(fuCurrDpbId);
270 if (it == fGdpbIdIndexMap.end()) {
271 if (kFALSE == fvbMaskedComponents[uMsCompIdx]) {
272 LOG(info) << "---------------------------------------------------------------";
273 /*
274 LOG(info) << "hi hv eqid flag si sv idx/start crc size offset";
275 LOG(info) << Form( "%02x %02x %04x %04x %02x %02x %016llx %08x %08x %016llx",
276 static_cast<unsigned int>(msDescriptor.hdr_id),
277 static_cast<unsigned int>(msDescriptor.hdr_ver), msDescriptor.eq_id, msDescriptor.flags,
278 static_cast<unsigned int>(msDescriptor.sys_id),
279 static_cast<unsigned int>(msDescriptor.sys_ver), msDescriptor.idx, msDescriptor.crc,
280 msDescriptor.size, msDescriptor.offset );
281*/
282 LOG(info) << FormatMsHeaderPrintout(msDescriptor);
283 LOG(warning) << "Could not find the gDPB index for AFCK id 0x" << std::hex << fuCurrDpbId << std::dec
284 << " in timeslice " << fulCurrentTsIdx << " in microslice " << uMsIdx << " component " << uMsCompIdx
285 << "\n"
286 << "If valid this index has to be added in the TOF "
287 "parameter file in the DbpIdArray field";
288 fvbMaskedComponents[uMsCompIdx] = kTRUE;
289 } // if( kFALSE == fvbMaskedComponents[ uMsComp ] )
290 else
291 return kTRUE;
292
295
296 return kFALSE;
297 } // if( it == fGdpbIdIndexMap.end() )
298 else
300
302 if (0 == fuCurrDpbIdx) {
307 fbSpillOn = kFALSE;
310 if (0 < fvuSpillBreakBegTs.size()) {
312 } // if( 0 < fvuSpillBreakBegTs.size() )
314 } // if( fbSpillOn && fuCountsLastInterval < fuOffSpillCountLimit )
316 fbSpillOn = kTRUE;
317 if (0 < fvuSpillBreakBegTs.size()) {
319 } // if( 0 < fvuSpillBreakBegTs.size() )
320 if (0 < fvuSpillBreakEndTs.size()) {
323 } // if( 0 < fvuSpillBreakEndTs.size() )
326 } // else if (fuOffSpillCountLimit < fuCountsLastInterval)
327
330 } // if( fdSpillCheckInterval < fdMsTime - fdLastSecondTime )
331 } // if( 0 == fuCurrDpbIdx )
332
339 } // else if( fuHistoryHistoSize < fdMsTime - fdStartTime )
340
341 // If not integer number of message in input buffer, print warning/error
342 if (0 != (uSize % kuBytesPerMessage))
343 LOG(error) << "The input microslice buffer does NOT "
344 << "contain only complete nDPB messages!";
345
346 // Compute the number of complete messages in the input microslice buffer
347 uint32_t uNbMessages = (uSize - (uSize % kuBytesPerMessage)) / kuBytesPerMessage;
348
349 // Prepare variables for the loop on contents
350 Int_t messageType = -111;
351 ULong64_t ulNbHitsTs = 0;
352 const uint64_t* pInBuff = reinterpret_cast<const uint64_t*>(msContent);
353 for (uint32_t uIdx = 0; uIdx < uNbMessages; uIdx++) {
354 // Fill message
355 uint64_t ulData = static_cast<uint64_t>(pInBuff[uIdx]);
356
358 if (0 == uIdx) { continue; } // if( 0 == uIdx )
359
360 gdpbv100::Message mess(ulData);
362 messageType = mess.getMessageType();
363
364 fuGet4Id = mess.getGdpbGenChipId();
365 fuGet4Nr = fuGet4Id / 2;
366 // UInt_t uChannelBmon = ( fuGet4Id < 32 ) ? ( fuGet4Id / 8 ) : (fuGet4Id / 8 - 1); /// December 2018 mapping
367 // UInt_t uChannelBmon = fuGet4Id / 2 + 4 * fuCurrDpbIdx; /// 2019 mapping with 320/640 Mb/s FW
368
370 LOG(warning) << "Message with Get4 ID too high: " << fuGet4Id << " VS " << fuNrOfGet4PerGdpb
371 << " set in parameters.";
372
373 switch (messageType) {
374 case gdpbv100::MSG_HIT: {
375 if (mess.getGdpbHitIs24b()) {
376 LOG(error) << "This event builder does not support 24b hit message!!!.";
377 continue;
378 } // if( getGdpbHitIs24b() )
379 else {
381
384 UInt_t uTot = mess.getGdpbHit32Tot();
385 if (0 != fuGet4Nr || uTot < fuMinTotPulser || fuMaxTotPulser < uTot) {
388 ulNbHitsTs++;
389 } // if (0 != fuGet4Nr || uTot < fuMinTotPulser || fuMaxTotPulser < uTot) {
390 } // else of if( getGdpbHitIs24b() )
391 break;
392 } // case gdpbv100::MSG_HIT:
393 case gdpbv100::MSG_EPOCH: {
394 break;
395 } // case gdpbv100::MSG_EPOCH:
396 case gdpbv100::MSG_SLOWC: {
397 break;
398 } // case gdpbv100::MSG_SLOWC:
399 case gdpbv100::MSG_SYST: {
400 break;
401 } // case gdpbv100::MSG_SYST:
406 break;
407 } // case gdpbv100::MSG_STAR_TRI_A-D
408 default:
409 LOG(error) << "Message type " << std::hex << std::setw(2) << static_cast<uint16_t>(messageType)
410 << " not included in Get4 unpacker.";
411 } // switch( mess.getMessageType() )
412 } // for (uint32_t uIdx = 0; uIdx < uNbMessages; uIdx ++)
413 fhHitsEvo->Fill(fdTsStartTime * 1e-9, ulNbHitsTs);
414
417
418 return kTRUE;
419}
420// -------------------------------------------------------------------------
422{
423 std::string sFolder = "SpillFinder";
424
425 LOG(info) << "create Histos for Bmon monitoring ";
426
428 uint32_t iNbBinsLog = 0;
430 std::vector<double> dBinsLogVector = GenerateLogBinArray(4, 9, 1, iNbBinsLog);
431 //double* dBinsLog = dBinsLogVector.data();
432 // double * dBinsLog = GenerateLogBinArray( 4, 9, 1, iNbBinsLog );
433
434 /*******************************************************************/
435 fhHitsEvo =
436 new TH1I("hHitsEvo", "Hit count evo; Time [s]; Hits Count []", fuHistoryHistoSize * 50, 0., fuHistoryHistoSize);
437 fhHitsPerSpill = new TH1I("hHitsPerSpill", "Hit count per spill; Spill; Hits Count []", 2000, 0., 2000);
438 fhSpillBreakDuration = new TH1I("hSpillBreakDuration", "Spill break duration; Spill; Duration [TS]", 2000, 0., 2000);
439 fhSpillDuration = new TH1I("hSpillDuration", "Spill duration; Spill; Duration [TS]", 2000, 0., 2000);
440
442 AddHistoToVector(fhHitsEvo, sFolder);
446
447 /*******************************************************************/
449 // delete dBinsLog;
450
451 /*******************************************************************/
452
454 // Double_t w = 10;
455 // Double_t h = 10;
456
457 /*******************************************************************/
458 /*
460 fcHitMaps = new TCanvas("cHitMaps", "Hit maps", w, h);
461 fcHitMaps->Divide(2);
462
463 fcHitMaps->cd(1);
464 gPad->SetGridx();
465 gPad->SetGridy();
466 gPad->SetLogy();
467 fhChannelMap->Draw();
468
469 fcHitMaps->cd(2);
470 gPad->SetGridx();
471 gPad->SetGridy();
472 gPad->SetLogz();
473 fhHitMapEvo->Draw("colz");
474
475 AddCanvasToVector(fcHitMaps, "canvases");
476*/
477 /*******************************************************************/
478
479 /*******************************************************************/
480
481 return kTRUE;
482}
485{
487 fhHitsEvo->Reset();
488 fhHitsPerSpill->Reset();
489 fhSpillBreakDuration->Reset();
490 fhSpillDuration->Reset();
491
492 if (kTRUE == bResetTime) {
494 fdStartTime = -1.0;
495 } // if( kTRUE == bResetTime )
496
497 return kTRUE;
498}
499// -------------------------------------------------------------------------
std::vector< double > GenerateLogBinArray(uint32_t uNbDecadesLog, uint32_t uNbStepsDecade, uint32_t uNbSubStepsInStep, uint32_t &uNbBinsLog, int32_t iStartExp, bool bAddZeroStart)
std::string FormatMsHeaderPrintout(const fles::MicrosliceDescriptor &msDescriptor)
int Int_t
bool Bool_t
UInt_t fuCurrDpbId
Current equipment ID, tells from which DPB the current MS is originating.
ULong64_t fulCurrentTsIdx
First TS index, forward point set ~30 years...
UInt_t fuGet4Id
Bin size in s for the plots with date as X axis.
Bool_t ProcessMs(const fles::Timeslice &ts, size_t uMsCompIdx, size_t uMsIdx)
UInt_t fuNrOfGdpbs
Readout chain dimensions and mapping.
Double_t fdTsStopTimeCore
Time in ns of current TS from the index of the first MS first component.
std::vector< Bool_t > fvbMaskedComponents
Switch ON the filling of a additional set of histograms.
Bool_t ProcessTs(const fles::Timeslice &ts)
std::map< UInt_t, UInt_t > fGdpbIdIndexMap
Total number of GDPBs in the system.
UInt_t fuNrOfChannelsPerGdpb
Number of GET4s per GDPB.
UInt_t fuNrOfGet4
Number of channels in each FEE.
UInt_t fuMinTotPulser
Number of channels per GDPB.
UInt_t fuNrOfGet4PerGdpb
Total number of Get4 chips in the system.
Bool_t fbMonitorMode
Control flags.
UInt_t fuGet4Nr
running number (0 to fuNrOfGet4PerGdpb) of the Get4 chip of a unique GDPB for current message
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Double_t fdMsTime
End Time in ns of current TS Core from the index of the first MS first component.
std::vector< ULong64_t > fvuSpillBreakMidTs
UInt_t fuNrOfGet4PerFee
Number of FEBs per GDPB.
Bool_t ResetHistograms(Bool_t bResetTime=kTRUE)
Bool_t fbSpillOn
Time of run Start from UNIX system, used as reference for long evolution plots against reception time...
CbmMcbm2018TofPar * fUnpackPar
Settings from parameter file.
UInt_t fuNrOfChannelsPerGet4
Number of GET4s per FEE.
UInt_t fuHistoryHistoSize
Histograms related variables.
std::vector< ULong64_t > fvuSpillBreakBegTs
std::vector< ULong64_t > fvuSpillBreakEndTs
Double_t fdStartTime
running number (0 to fuNrOfGet4) of the Get4 chip in the system for current message
static const UInt_t kuBytesPerMessage
UInt_t fuNrOfFeePerGdpb
gDPB ID to index map
UInt_t fuCurrDpbIdx
Temp holder until Current equipment ID is properly filled in MS.
UInt_t fuMsIndex
Start Time in ns of current MS from its index field in header.
UInt_t fuNrOfChannelsPerFee
Number of channels in each GET4.
void AddHistoToVector(TNamed *pointer, std::string sFolder="")
std::vector< size_t > fvMsComponentsList
uint16_t getGdpbHitIs24b() const
uint16_t getGdpbHit32Tot() const
bool isStarTrigger() const
Returns true is message type is MSG_STAR_TRI_A, _B, _C, _D (STAR Trigger message)
uint16_t getGdpbGenChipId() const
uint8_t getMessageType() const
Returns the message type. Valid for all message types. 4 bit.
const uint32_t kuChipIdMergedEpoch