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
20#include "FairRootManager.h"
21#include "FairRun.h"
22#include "FairRunOnline.h"
23#include "FairRuntimeDb.h"
24#include "Logger.h"
25
26#include "TCanvas.h"
27#include "TH1.h"
28#include "TH2.h"
29#include "TList.h"
30#include "TPaveStats.h"
31#include "TProfile.h"
32#include "TROOT.h"
33#include "TString.h"
34
35#include <fstream>
36#include <iomanip>
37#include <iostream>
38
39#include <stdint.h>
40
41// -------------------------------------------------------------------------
44
45// -------------------------------------------------------------------------
47{
48 LOG(info) << "Initializing mCBM Bmon 2019 monitor algo";
49
50 return kTRUE;
51}
54{
57 if (fbSpillOn) {
60 } // if (fbSpillOn)
61 else
63
65 std::vector<ULong64_t>::iterator itBreakBeg = fvuSpillBreakBegTs.begin();
66 std::vector<ULong64_t>::iterator itBreakEnd = fvuSpillBreakEndTs.begin();
67
68 if (itBreakBeg != fvuSpillBreakBegTs.end() && itBreakEnd != fvuSpillBreakEndTs.end() && *itBreakEnd < *itBreakBeg) {
69 fvuSpillBreakMidTs.push_back((*itBreakEnd + fulFirstTsIdx) / 2);
70 ++itBreakEnd;
71 } // if( itBreakBeg != fvuSpillBreakBegTs.end() && itBreakEnd != fvuSpillBreakEndTs.end() && *itBreakEnd < *itBreakBeg )
72
73 while (itBreakBeg != fvuSpillBreakBegTs.end() && itBreakEnd != fvuSpillBreakEndTs.end()) {
74 fvuSpillBreakMidTs.push_back((*itBreakBeg + *itBreakEnd) / 2);
75 ++itBreakBeg;
76 ++itBreakEnd;
77 } // while( itBreakBeg != fvuSpillBreakBegTs.end() && itBreakEnd != fvuSpillBreakEndTs.end() )
78
79 if (itBreakBeg != fvuSpillBreakBegTs.end()) {
80 fvuSpillBreakMidTs.push_back((*itBreakBeg + fulCurrentTsIdx) / 2);
81 ++itBreakBeg;
82 } // if( itBreakBeg != fvuSpillBreakBegTs.end() )
83
84 if (itBreakBeg != fvuSpillBreakBegTs.end() || itBreakEnd != fvuSpillBreakEndTs.end()) {
85 LOG(warning) << "Size of spill breaks beginning or end did not match: " << fvuSpillBreakBegTs.size() << " VS "
86 << fvuSpillBreakEndTs.size();
87 } // if( itBreakBeg != fvuSpillBreakBegTs.end() || itBreakEnd != fvuSpillBreakEndTs.end() )
88
89 LOG(info) << "**********************************************";
90 LOG(info) << "TS index for beginning of spill breaks:";
91 for (ULong64_t uBeg : fvuSpillBreakBegTs) {
92 LOG(info) << Form("%9llu", uBeg);
93 } // for (ULong64_t uBeg : fvuSpillBreakBegTs)
94 LOG(info) << "**********************************************";
95 LOG(info) << "TS index for ending of spill breaks:";
96 for (ULong64_t uEnd : fvuSpillBreakEndTs) {
97 LOG(info) << Form("%9llu", uEnd);
98 } // for (ULong64_t uBeg : fvuSpillBreakBegTs)
99 LOG(info) << "**********************************************";
100 LOG(info) << "TS index for middle of spill breaks:";
101 for (ULong64_t uMid : fvuSpillBreakMidTs) {
102 LOG(info) << Form("%9llu", uMid);
103 } // for (ULong64_t uBeg : fvuSpillBreakBegTs)
104 LOG(info) << "**********************************************";
105}
106
107// -------------------------------------------------------------------------
109{
110 LOG(info) << "Init parameter containers for CbmMcbmSpillFindAlgo";
111 Bool_t initOK = ReInitContainers();
112
113 return initOK;
114}
116{
117 LOG(info) << "**********************************************";
118 LOG(info) << "ReInit parameter containers for CbmMcbmSpillFindAlgo";
119
120 fUnpackPar = (CbmMcbm2018TofPar*) fParCList->FindObject("CbmMcbm2018TofPar");
121 if (nullptr == fUnpackPar) return kFALSE;
122
123 Bool_t initOK = InitParameters();
124
125 return initOK;
126}
128{
129 if (nullptr == fParCList) fParCList = new TList();
130 fUnpackPar = new CbmMcbm2018TofPar("CbmMcbm2018TofPar");
131 fParCList->Add(fUnpackPar);
132
133 return fParCList;
134}
136{
137
139 LOG(info) << "Nr. of Tof GDPBs: " << fuNrOfGdpbs;
140
142 LOG(info) << "Nr. of FEES per Tof GDPB: " << fuNrOfFeePerGdpb;
143
145 LOG(info) << "Nr. of GET4 per Tof FEE: " << fuNrOfGet4PerFee;
146
148 LOG(info) << "Nr. of channels per GET4: " << fuNrOfChannelsPerGet4;
149
151 LOG(info) << "Nr. of channels per FEE: " << fuNrOfChannelsPerFee;
152
154 LOG(info) << "Nr. of GET4s: " << fuNrOfGet4;
155
157 LOG(info) << "Nr. of GET4s per GDPB: " << fuNrOfGet4PerGdpb;
158
160 LOG(info) << "Nr. of channels per GDPB: " << fuNrOfChannelsPerGdpb;
161
162 fGdpbIdIndexMap.clear();
163 for (UInt_t i = 0; i < fuNrOfGdpbs; ++i) {
165 LOG(info) << "GDPB Id of TOF " << i << " : " << std::hex << fUnpackPar->GetGdpbId(i) << std::dec;
166 } // for( UInt_t i = 0; i < fuNrOfGdpbs; ++i )
167
168 return kTRUE;
169}
170// -------------------------------------------------------------------------
171
172void CbmMcbmSpillFindAlgo::AddMsComponentToList(size_t component, UShort_t usDetectorId)
173{
175 for (UInt_t uCompIdx = 0; uCompIdx < fvMsComponentsList.size(); ++uCompIdx)
176 if (component == fvMsComponentsList[uCompIdx]) return;
177
179 fvMsComponentsList.push_back(component);
180
181 LOG(info) << "CbmMcbmSpillFindAlgo::AddMsComponentToList => Component " << component << " with detector ID 0x"
182 << std::hex << usDetectorId << std::dec << " added to list";
183}
184// -------------------------------------------------------------------------
185
186Bool_t CbmMcbmSpillFindAlgo::ProcessTs(const fles::Timeslice& ts)
187{
188 fulCurrentTsIdx = ts.index();
189 fdTsStartTime = static_cast<Double_t>(ts.descriptor(0, 0).idx);
191
193 if (0 == fulCurrentTsIdx) return kTRUE;
194
196 if (-1.0 == fdTsCoreSizeInNs) {
197 fuNbCoreMsPerTs = ts.num_core_microslices();
198 fuNbOverMsPerTs = ts.num_microslices(0) - ts.num_core_microslices();
201 LOG(info) << "Timeslice parameters: each TS has " << fuNbCoreMsPerTs << " Core MS and " << fuNbOverMsPerTs
202 << " Overlap MS, for a core duration of " << fdTsCoreSizeInNs << " ns and a full duration of "
203 << fdTsFullSizeInNs << " ns";
204
208 LOG(info) << "In each TS " << fuNbMsLoop << " MS will be looped over";
209 } // if( -1.0 == fdTsCoreSizeInNs )
210
213 // LOG(info) << Form( "TS %5d Start %12f Stop %12f", fulCurrentTsIdx, fdTsStartTime, fdTsStopTimeCore );
214
216 for (fuMsIndex = 0; fuMsIndex < fuNbMsLoop; fuMsIndex++) {
218 for (UInt_t uMsCompIdx = 0; uMsCompIdx < fvMsComponentsList.size(); ++uMsCompIdx) {
219 UInt_t uMsComp = fvMsComponentsList[uMsCompIdx];
220
221 if (kFALSE == ProcessMs(ts, uMsComp, fuMsIndex)) {
222 LOG(error) << "Failed to process ts " << fulCurrentTsIdx << " MS " << fuMsIndex << " for component " << uMsComp;
223 return kFALSE;
224 } // if( kFALSE == ProcessMs( ts, uMsCompIdx, fuMsIndex ) )
225 } // for( UInt_t uMsCompIdx = 0; uMsCompIdx < fvMsComponentsList.size(); ++uMsCompIdx )
226 } // for( fuMsIndex = 0; fuMsIndex < uNbMsLoop; fuMsIndex ++ )
227
229 if (fbMonitorMode) {
230 if (kFALSE == FillHistograms()) {
231 LOG(error) << "Failed to fill histos in ts " << fulCurrentTsIdx;
232 return kFALSE;
233 } // if( kFALSE == FillHistograms() )
234 } // if( fbMonitorMode )
235
236 return kTRUE;
237}
238
239Bool_t CbmMcbmSpillFindAlgo::ProcessMs(const fles::Timeslice& ts, size_t uMsCompIdx, size_t uMsIdx)
240{
241 auto msDescriptor = ts.descriptor(uMsCompIdx, uMsIdx);
242 fuCurrentEquipmentId = msDescriptor.eq_id;
243 const uint8_t* msContent = reinterpret_cast<const uint8_t*>(ts.content(uMsCompIdx, uMsIdx));
244
245 uint32_t uSize = msDescriptor.size;
246 fulCurrentMsIdx = msDescriptor.idx;
247 fdMsTime = (1e-9) * static_cast<double>(fulCurrentMsIdx);
248 LOG(debug) << "Microslice: " << fulCurrentMsIdx << " from EqId " << std::hex << fuCurrentEquipmentId << std::dec
249 << " has size: " << uSize;
250
251 if (0 == fvbMaskedComponents.size()) fvbMaskedComponents.resize(ts.num_components(), kFALSE);
252
253 fuCurrDpbId = static_cast<uint32_t>(fuCurrentEquipmentId & 0xFFFF);
254
255 /*
256 * Should be only for first detected TS
257 */
258 if (fulCurrentTsIdx < 10 && 0 == uMsIdx) {
259 LOG(info) << "---------------------------------------------------------------";
260 LOG(info) << "Component " << uMsCompIdx << " TS Idx " << fulCurrentTsIdx;
261 LOG(info) << "hi hv eqid flag si sv idx/start crc size offset";
262 LOG(info) << Form("%02x %02x %04x %04x %02x %02x %016lx %08x %08x %016lx",
263 static_cast<unsigned int>(msDescriptor.hdr_id), static_cast<unsigned int>(msDescriptor.hdr_ver),
264 msDescriptor.eq_id, msDescriptor.flags, static_cast<unsigned int>(msDescriptor.sys_id),
265 static_cast<unsigned int>(msDescriptor.sys_ver), static_cast<unsigned long>(msDescriptor.idx),
266 msDescriptor.crc, msDescriptor.size, static_cast<unsigned long>(msDescriptor.offset));
267 } // if( fulCurrentTsIdx < 10 && 0 == uMsIdx )
268 /*
269*/
270
272 auto it = fGdpbIdIndexMap.find(fuCurrDpbId);
273 if (it == fGdpbIdIndexMap.end()) {
274 if (kFALSE == fvbMaskedComponents[uMsCompIdx]) {
275 LOG(info) << "---------------------------------------------------------------";
276 /*
277 LOG(info) << "hi hv eqid flag si sv idx/start crc size offset";
278 LOG(info) << Form( "%02x %02x %04x %04x %02x %02x %016llx %08x %08x %016llx",
279 static_cast<unsigned int>(msDescriptor.hdr_id),
280 static_cast<unsigned int>(msDescriptor.hdr_ver), msDescriptor.eq_id, msDescriptor.flags,
281 static_cast<unsigned int>(msDescriptor.sys_id),
282 static_cast<unsigned int>(msDescriptor.sys_ver), msDescriptor.idx, msDescriptor.crc,
283 msDescriptor.size, msDescriptor.offset );
284*/
285 LOG(info) << FormatMsHeaderPrintout(msDescriptor);
286 LOG(warning) << "Could not find the gDPB index for AFCK id 0x" << std::hex << fuCurrDpbId << std::dec
287 << " in timeslice " << fulCurrentTsIdx << " in microslice " << uMsIdx << " component " << uMsCompIdx
288 << "\n"
289 << "If valid this index has to be added in the TOF "
290 "parameter file in the DbpIdArray field";
291 fvbMaskedComponents[uMsCompIdx] = kTRUE;
292 } // if( kFALSE == fvbMaskedComponents[ uMsComp ] )
293 else
294 return kTRUE;
295
298
299 return kFALSE;
300 } // if( it == fGdpbIdIndexMap.end() )
301 else
303
305 if (0 == fuCurrDpbIdx) {
310 fbSpillOn = kFALSE;
313 if (0 < fvuSpillBreakBegTs.size()) {
315 } // if( 0 < fvuSpillBreakBegTs.size() )
317 } // if( fbSpillOn && fuCountsLastInterval < fuOffSpillCountLimit )
319 fbSpillOn = kTRUE;
320 if (0 < fvuSpillBreakBegTs.size()) {
322 } // if( 0 < fvuSpillBreakBegTs.size() )
323 if (0 < fvuSpillBreakEndTs.size()) {
326 } // if( 0 < fvuSpillBreakEndTs.size() )
329 } // else if (fuOffSpillCountLimit < fuCountsLastInterval)
330
333 } // if( fdSpillCheckInterval < fdMsTime - fdLastSecondTime )
334 } // if( 0 == fuCurrDpbIdx )
335
342 } // else if( fuHistoryHistoSize < fdMsTime - fdStartTime )
343
344 // If not integer number of message in input buffer, print warning/error
345 if (0 != (uSize % kuBytesPerMessage))
346 LOG(error) << "The input microslice buffer does NOT "
347 << "contain only complete nDPB messages!";
348
349 // Compute the number of complete messages in the input microslice buffer
350 uint32_t uNbMessages = (uSize - (uSize % kuBytesPerMessage)) / kuBytesPerMessage;
351
352 // Prepare variables for the loop on contents
353 Int_t messageType = -111;
354 ULong64_t ulNbHitsTs = 0;
355 const uint64_t* pInBuff = reinterpret_cast<const uint64_t*>(msContent);
356 for (uint32_t uIdx = 0; uIdx < uNbMessages; uIdx++) {
357 // Fill message
358 uint64_t ulData = static_cast<uint64_t>(pInBuff[uIdx]);
359
361 if (0 == uIdx) { continue; } // if( 0 == uIdx )
362
363 gdpbv100::Message mess(ulData);
365 messageType = mess.getMessageType();
366
367 fuGet4Id = mess.getGdpbGenChipId();
368 fuGet4Nr = fuGet4Id / 2;
369 // UInt_t uChannelBmon = ( fuGet4Id < 32 ) ? ( fuGet4Id / 8 ) : (fuGet4Id / 8 - 1); /// December 2018 mapping
370 // UInt_t uChannelBmon = fuGet4Id / 2 + 4 * fuCurrDpbIdx; /// 2019 mapping with 320/640 Mb/s FW
371
373 LOG(warning) << "Message with Get4 ID too high: " << fuGet4Id << " VS " << fuNrOfGet4PerGdpb
374 << " set in parameters.";
375
376 switch (messageType) {
377 case gdpbv100::MSG_HIT: {
378 if (mess.getGdpbHitIs24b()) {
379 LOG(error) << "This event builder does not support 24b hit message!!!.";
380 continue;
381 } // if( getGdpbHitIs24b() )
382 else {
384
387 UInt_t uTot = mess.getGdpbHit32Tot();
388 if (0 != fuGet4Nr || uTot < fuMinTotPulser || fuMaxTotPulser < uTot) {
391 ulNbHitsTs++;
392 } // if (0 != fuGet4Nr || uTot < fuMinTotPulser || fuMaxTotPulser < uTot) {
393 } // else of if( getGdpbHitIs24b() )
394 break;
395 } // case gdpbv100::MSG_HIT:
396 case gdpbv100::MSG_EPOCH: {
397 break;
398 } // case gdpbv100::MSG_EPOCH:
399 case gdpbv100::MSG_SLOWC: {
400 break;
401 } // case gdpbv100::MSG_SLOWC:
402 case gdpbv100::MSG_SYST: {
403 break;
404 } // case gdpbv100::MSG_SYST:
409 break;
410 } // case gdpbv100::MSG_STAR_TRI_A-D
411 default:
412 LOG(error) << "Message type " << std::hex << std::setw(2) << static_cast<uint16_t>(messageType)
413 << " not included in Get4 unpacker.";
414 } // switch( mess.getMessageType() )
415 } // for (uint32_t uIdx = 0; uIdx < uNbMessages; uIdx ++)
416 fhHitsEvo->Fill(fdTsStartTime * 1e-9, ulNbHitsTs);
417
420
421 return kTRUE;
422}
423// -------------------------------------------------------------------------
425{
426 std::string sFolder = "SpillFinder";
427
428 LOG(info) << "create Histos for Bmon monitoring ";
429
431 uint32_t iNbBinsLog = 0;
433 std::vector<double> dBinsLogVector = GenerateLogBinArray(4, 9, 1, iNbBinsLog);
434 //double* dBinsLog = dBinsLogVector.data();
435 // double * dBinsLog = GenerateLogBinArray( 4, 9, 1, iNbBinsLog );
436
437 /*******************************************************************/
438 fhHitsEvo =
439 new TH1I("hHitsEvo", "Hit count evo; Time [s]; Hits Count []", fuHistoryHistoSize * 50, 0., fuHistoryHistoSize);
440 fhHitsPerSpill = new TH1I("hHitsPerSpill", "Hit count per spill; Spill; Hits Count []", 2000, 0., 2000);
441 fhSpillBreakDuration = new TH1I("hSpillBreakDuration", "Spill break duration; Spill; Duration [TS]", 2000, 0., 2000);
442 fhSpillDuration = new TH1I("hSpillDuration", "Spill duration; Spill; Duration [TS]", 2000, 0., 2000);
443
445 AddHistoToVector(fhHitsEvo, sFolder);
449
450 /*******************************************************************/
452 // delete dBinsLog;
453
454 /*******************************************************************/
455
457 // Double_t w = 10;
458 // Double_t h = 10;
459
460 /*******************************************************************/
461 /*
463 fcHitMaps = new TCanvas("cHitMaps", "Hit maps", w, h);
464 fcHitMaps->Divide(2);
465
466 fcHitMaps->cd(1);
467 gPad->SetGridx();
468 gPad->SetGridy();
469 gPad->SetLogy();
470 fhChannelMap->Draw();
471
472 fcHitMaps->cd(2);
473 gPad->SetGridx();
474 gPad->SetGridy();
475 gPad->SetLogz();
476 fhHitMapEvo->Draw("colz");
477
478 AddCanvasToVector(fcHitMaps, "canvases");
479*/
480 /*******************************************************************/
481
482 /*******************************************************************/
483
484 return kTRUE;
485}
486Bool_t CbmMcbmSpillFindAlgo::FillHistograms() { return kTRUE; }
488{
490 fhHitsEvo->Reset();
491 fhHitsPerSpill->Reset();
492 fhSpillBreakDuration->Reset();
493 fhSpillDuration->Reset();
494
495 if (kTRUE == bResetTime) {
497 fdStartTime = -1.0;
498 } // if( kTRUE == bResetTime )
499
500 return kTRUE;
501}
502// -------------------------------------------------------------------------
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_t GetNrOfGdpbs()
FIXME: replace with method returning the correspondign constants! see Star2019 parameter.
Int_t GetGdpbId(Int_t i)
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