12#include <MicrosliceDescriptor.hpp>
15#include <FairRunOnline.h>
18#include <RtypesCore.h>
25#include <boost/math/special_functions/math_fwd.hpp>
45 auto modulepair = pair.second.find(moduleid);
46 auto histo = modulepair->second;
47 fillHisto(digi, pair.first, moduleid, histo);
52 auto modulepair = pair.second.find(moduleid);
53 auto histo = modulepair->second;
72 auto histo = pair->second.find(moduleid)->second;
73 histo->Fill(
static_cast<uint32_t
>(type));
81 auto histo = pair->second.find(moduleid)->second;
90 auto histo = pair->second.find(moduleid)->second;
102 auto histoBomPerRawRate = pairBomPerRawRate->second.find(moduleid)->second;
103 auto histoBomRate = pairBomRate->second.find(moduleid)->second;
104 auto histoRawRate = pairRawRate->second.find(moduleid)->second;
107 if (histoRawRate->GetBinContent(modifiedBin) != 0)
108 histoBomPerRawRate->SetBinContent(modifiedBin, histoBomRate->GetBinContent(modifiedBin)
109 / histoRawRate->GetBinContent(modifiedBin));
120 auto histo = pair->second.find(moduleid)->second;
122 histo->Fill(
static_cast<uint32_t
>(flag));
127 LOG(info) << Class_Name() <<
"::Finish() - ";
133 TFile* oldFile = gFile;
134 TDirectory* oldDir = gDirectory;
150 LOG(info) << Class_Name() <<
"::Finish() nHistos " << nhistos <<
" written to " <<
fOutfilename.data();
158 for (
auto modulepair : modulemap) {
166 fModuleOrientation.emplace(std::pair<uint32_t, uint8_t>(modulepair.first, parmoddigi->GetOrientation()));
167 fModuleNrRows.emplace(std::pair<uint32_t, uint8_t>(modulepair.first, parmoddigi->GetNofRows()));
168 fModuleNrColumns.emplace(std::pair<uint32_t, uint8_t>(modulepair.first, parmoddigi->GetNofColumns()));
174 if (FairRun::Instance()->IsA() == FairRunOnline::Class()) {
175 auto run =
static_cast<FairRunOnline*
>(FairRun::Instance());
181 TFile* oldFile = gFile;
182 TDirectory* oldDir = gDirectory;
197 std::string histoname =
"";
198 std::shared_ptr<TH1> newhisto =
nullptr;
203 auto nchannels = nrows * ncols;
206 histoname =
"ModuleId_" + std::to_string(moduleid) +
"-";
215 if (rotation % 2 == 0) {
216 newhisto = std::make_shared<TH2I>(histoname.data(), histoname.data(), ncols, -0.5, (ncols - 0.5), nrows, -0.5,
218 newhisto->SetXTitle(
"Pad column");
219 newhisto->SetYTitle(
"Pad row");
223 newhisto = std::make_shared<TH2I>(histoname.data(), histoname.data(), nrows, -0.5, (nrows - 0.5), ncols, -0.5,
225 newhisto->SetXTitle(
"Pad row");
226 newhisto->SetYTitle(
"Pad column");
233 newhisto = std::make_shared<TH1I>(histoname.data(), histoname.data(),
fSpadic->GetDynamicRange(), 0 - 0.5,
234 fSpadic->GetDynamicRange() - 0.5);
235 newhisto->SetXTitle(
"MaxAdc [ADC units]");
236 newhisto->SetYTitle(
"Counts");
239 newhisto = std::make_shared<TH1I>(histoname.data(), histoname.data(),
242 newhisto->SetXTitle(
"CbmTrdDigi eTriggerType");
243 newhisto->SetYTitle(
"Counts");
252 newhisto = std::make_shared<TH1I>(histoname.data(), histoname.data(), nchannels, -0.5, (nchannels - 0.5));
253 newhisto->SetXTitle(
"ChannelId");
254 newhisto->SetYTitle(
"Counts");
257 newhisto = std::make_shared<TH2I>(histoname.data(), histoname.data(), nchannels, -0.5, (nchannels - 0.5), 3500,
259 newhisto->SetXTitle(
"ChannelId");
260 newhisto->SetYTitle(
"#DeltaT(Digi(n)-Digi(n-1)) [ns]");
263 newhisto = std::make_shared<TH2I>(histoname.data(), histoname.data(), nchannels, -0.5, (nchannels - 0.5),
264 nchannels, -0.5, (nchannels - 0.5));
265 newhisto->SetXTitle(
"NT AddressChannel");
266 newhisto->SetYTitle(
"ST AddressChannel");
270 LOG(debug) << Class_Name() <<
"::CreateHisto() HistoDigi " <<
static_cast<size_t>(kHisto) <<
" Module " << moduleid
271 <<
" initialized as " << histoname.data();
281 std::string histoname =
"";
282 std::shared_ptr<TH1> newhisto =
nullptr;
287 auto nchannels = nrows * ncols;
289 histoname =
"ModuleId_" + std::to_string(moduleid) +
"-";
296 newhisto = std::make_shared<TH2I>(histoname.data(), histoname.data(), 32, -0.5, 31.5, 520, -260, 260);
297 newhisto->SetXTitle(
"ADC Sample [CC]");
298 newhisto->SetYTitle(
"ADC Value [a.u.]");
303 newhisto = std::make_shared<TH2I>(histoname.data(), histoname.data(), 42, -0.5, 41.5, 16, -0.5, 15.5);
304 newhisto->SetXTitle(
"ElinkId");
305 newhisto->SetYTitle(
"eLink-ChannelId");
308 newhisto = std::make_shared<TH1I>(histoname.data(), histoname.data(), 42, -0.5, 41.5);
309 newhisto->SetXTitle(
"ElinkId");
310 newhisto->SetYTitle(
"Counts");
313 newhisto = std::make_shared<TH1F>(histoname.data(), histoname.data(), 200, 0.0, 100.0);
314 newhisto->SetXTitle(
"ADC signal std. deviation [#sigma]");
315 newhisto->SetYTitle(
"Counts");
318 newhisto = std::make_shared<TH2I>(histoname.data(), histoname.data(), nchannels, -0.5, (nchannels - 0.5), 601,
320 newhisto->SetXTitle(
"ChannelId");
321 newhisto->SetYTitle(
"ADC Value(Sample-0) [a.u.]");
324 newhisto = std::make_shared<TH1I>(histoname.data(), histoname.data(),
327 newhisto->SetXTitle(
"Spadic::eTriggerType");
328 newhisto->SetYTitle(
"Counts");
331 newhisto = std::make_shared<TH1D>(histoname.data(), histoname.data(),
kTimeplotLenghtSeconds * 10 + 1, -0.05,
333 newhisto->SetXTitle(
"Time t [s]");
334 newhisto->SetYTitle(
"Rate [Hz]");
336 default:
return;
break;
338 LOG(debug) << Class_Name() <<
"::CreateHisto() HistoRaw " <<
static_cast<size_t>(kHisto) <<
" Module " << moduleid
339 <<
"initialized as " << histoname.data();
350 std::string histoname =
"";
351 std::shared_ptr<TH1> newhisto =
nullptr;
354 histoname =
"ModuleId_" + std::to_string(moduleid) +
"-";
360 newhisto = std::make_shared<TH1I>(histoname.data(), histoname.data(), nbins, -0.5, nbins - 0.5);
361 newhisto->SetXTitle(
"Info message type");
362 newhisto->SetYTitle(
"Counts");
375 auto nbins =
static_cast<uint32_t
>(fles::MicrosliceFlags::DataError) + 1;
376 newhisto = std::make_shared<TH1I>(histoname.data(), histoname.data(), nbins, -0.5, nbins - 0.5);
377 newhisto->SetXTitle(
"#muSlice info/error flags");
378 newhisto->SetYTitle(
"Counts");
379 newhisto->GetXaxis()->SetBinLabel((
static_cast<int>(fles::MicrosliceFlags::CrcValid) + 1),
"CrcValid");
380 newhisto->GetXaxis()->SetBinLabel((
static_cast<int>(fles::MicrosliceFlags::OverflowFlim) + 1),
"OverflowFlim");
381 newhisto->GetXaxis()->SetBinLabel((
static_cast<int>(fles::MicrosliceFlags::OverflowUser) + 1),
"OverflowUser");
382 newhisto->GetXaxis()->SetBinLabel((
static_cast<int>(fles::MicrosliceFlags::DataError) + 1),
"DataError");
388 newhisto = std::make_shared<TH1D>(histoname.data(), histoname.data(),
kTimeplotLenghtSeconds * 10 + 1, -0.05,
390 newhisto->SetXTitle(
"Time t [s]");
391 newhisto->SetYTitle(
"Rate [Hz]");
394 default:
return;
break;
396 LOG(debug) << Class_Name() <<
"::CreateHisto() HistoOther " <<
static_cast<size_t>(kHisto) <<
" Module " << moduleid
397 <<
"initialized as " << histoname.data();
423 auto triggertype = triggerpair.first;
424 auto isMultihit = triggerpair.second;
432 histo->Fill(addresspair.second, addresspair.first);
442 histo->Fill(addresspair.second, addresspair.first);
448 histo->Fill(addresspair.second, addresspair.first);
482 histo->Fill(
static_cast<int>(triggertype));
488 default:
return;
break;
529 default:
return;
break;
536 for (
size_t isample = 0; isample < raw->
GetSamples()->
size(); isample++) {
537 histo->Fill(isample, raw->
GetSamples()->at(isample));
549 std::vector<size_t> channelsvec(nchannels, 0);
550 if (channelid > nchannels)
return 0;
551 channelsvec.at(channelid) = digi->
GetTime();
552 auto pair = std::make_pair(moduleid, channelsvec);
558 auto prevtime = modulevecpair->second.at(channelid);
559 modulevecpair->second.at(channelid) = digi->
GetTime();
560 auto dt = digi->
GetTime() - prevtime;
568 Double_t newDigiTime = digi->
GetTime();
574 for (
int iDigi = nTrdDigis - 1; iDigi > 0; --iDigi) {
577 Double_t refDigiTime = digiRef.
GetTime();
588 if (refDigiTime < newDigiTime - 500 )
break;
595 std::string histoname =
"";
617 std::string histoname =
"";
638 std::string histoname =
"";
653 std::string histoname = histo->GetName();
655 auto startpos = histoname.find_first_of(
"-");
659 auto length = histoname.find_first_of(
"_", startpos) - startpos;
660 auto histotype = histoname.substr(startpos, length);
671 auto nrows =
static_cast<uint32_t
>(
fModuleNrRows.find(moduleid)->second);
672 auto ncols =
static_cast<uint32_t
>(
fModuleNrColumns.find(moduleid)->second);
675 uint32_t rotatedid = doRotate ? (channelid * (-1) + (nrows * ncols) - 1) : channelid;
677 auto row = rotatedid / ncols;
678 auto col = rotatedid % ncols;
682 return std::make_pair(row, col);
685 return std::make_pair(col, row);
695 std::float_t dev = 0;
698 dev += (sample - mean) * (sample - mean);
707 switch (typemappair.first) {
709 for (
auto histopair : typemappair.second) {
710 histopair.second->Reset(
"ICESM");
717 switch (typemappair.first) {
721 for (
auto histopair : typemappair.second) {
722 histopair.second->Reset(
"ICESM");
ClassImp(CbmConverterManager)
Monitor class to monitor the data from the Trd unpacker algorithms.
static constexpr size_t size()
int32_t GetAddressModule() const
Getter module address in the experiment.
static std::pair< eTriggerType, bool > GetTriggerPair(const int32_t triggerValue)
Get the trigger combination, i.e. St or Nt and is multihit or not (true/false)
int32_t GetTriggerType() const
Channel trigger type. SPADIC specific see CbmTrdTriggerType.
int32_t GetAddressChannel() const
Getter read-out id.
double GetTime() const
Getter for physical time [ns]. Accounts for clock representation of each ASIC. In SPADIC case physica...
double GetCharge() const
Common purpose charge getter.
Describe TRD module ASIC settings (electronic gain, delays, etc)
Definition of chamber gain conversion for one TRD module.
Describe TRD module ASIC settings (electronic gain, delays, etc)
virtual const CbmTrdParMod * GetModulePar(Int_t detId) const
std::map< Int_t, CbmTrdParMod * > GetModuleMap()
Base class for storing raw information which comes from the Spadic v2.2 trough flib or from a tsa fil...
uint8_t GetNrSamples() const
uint8_t GetHitType() const
const std::vector< int16_t > * GetSamples() const
uint8_t GetElinkId() const
uint8_t GetChannelId() const
std::pair< uint32_t, uint32_t > getRowAndCol(uint32_t moduleid, uint32_t channelid)
Get the row and column ids (potentially rotated chambers are adjusted to humand readable rotations)
void Finish()
Actions at the end of the run, e.g. write histos to file if flag is set.
static std::string getTypeName(eDigiHistos kHisto)
Get the Type Name for the given histo.
virtual ~CbmTrdUnpackMonitor()
Destroy the Cbm Trd Unpack Task object.
CbmTrdUnpackMonitor()
Create the Cbm Trd Unpack AlgoBase object.
void fillSamplesHisto(std::shared_ptr< TH1 > histo, CbmTrdRawMessageSpadic *raw)
Fill the passed histo with the samples as function of time.
std::vector< eDigiHistos > fActiveDigiHistos
Enums of Digi histos to be activated.
std::map< uint32_t, uint8_t > fModuleNrColumns
Map with the number of columns of the modules. Performance helper to not go through the extraction fr...
std::string getHistoName(eDigiHistos kHisto)
Get the Histo Name for the given histo.
void adjustTimeplots(uint64_t newtime)
Adjust the boundaries of all timeplots to contain newtime.
virtual void fillHisto(CbmTrdDigi *digi, eDigiHistos kHisto, uint32_t moduleid, std::shared_ptr< TH1 > histo)
Fill the given histo with the information from the digi.
void fillNtCorrHisto(std::shared_ptr< TH1 > histo, CbmTrdDigi *digi)
Fill the NeighborTrigger Checking Histogram.
eDigiHistos
Enum for the predefined digi histograms.
virtual void createHisto(eDigiHistos kHisto)
Create the actual TH1 shared_ptrs of the Digi histos.
std::vector< eRawHistos > fActiveRawHistos
Enums of Raw histos to be activated.
std::map< uint32_t, std::vector< size_t > > fLastDigiTimeMap
Map with the last digi time for each channel of a given module.
std::string getHistoType(std::shared_ptr< TH1 > histo)
Get the Histo Type, i.e. "Digi/Raw/Other", deduced from the histo name.
std::vector< uint32_t > fModuleIdsVec
Vector with the unique module Ids.
Bool_t Init(CbmTrdParSetDigi *digiParSet, CbmTrdParSetAsic *asicParSet=nullptr)
Init all required parameter informations.
uint64_t fCurrentTimesliceStartTimeNs
Variable which holds the start time in ns of the current timeslice.
static const uint32_t kTimeplotLenghtSeconds
Constant which defines the lenght of the time axis in seconds of plots which display a quantity over ...
std::shared_ptr< CbmTrdSpadic > fSpadic
std::vector< eOtherHistos > fActiveOtherHistos
Enums of Raw histos to be activated.
std::vector< CbmTrdDigi > * fDigiOutputVec
Variable which holds a reference to the TRD digi output vector (for correlations)
uint64_t fCurrentTimeplotStartNs
Variable which holds the start time in ns of the current time axis of plots which display a quantity ...
std::map< eDigiHistos, std::map< uint32_t, std::shared_ptr< TH1 > > > fDigiHistoMap
Digi histogram pointers stored in a map together with the module id.
void FillHisto(Spadic::MsInfoType type, uint32_t moduleid)
Fill the given histo with the information on the info type.
std::map< uint32_t, uint8_t > fModuleNrRows
Map with the number of rows of the modules. Performance helper to not go through the extraction from ...
bool fDoWriteToFile
Flag whether to write histos to file or not, gets activated if a output filename gets set.
std::double_t getDeltaT(CbmTrdDigi *digi)
Get the time difference between this digi and the previous one from the channel of this digi.
std::map< uint32_t, uint8_t > fModuleOrientation
Map with the orientations of the modules. Performance helper to not go through the extraction from Pa...
void FillHistos(CbmTrdDigi *digi, CbmTrdRawMessageSpadic *raw=nullptr)
fill the stored digi histograms
eOtherHistos
Enum for the predefined other histograms.
std::map< eRawHistos, std::map< uint32_t, std::shared_ptr< TH1 > > > fRawHistoMap
Raw histogram pointers stored in a map together with the module id.
eRawHistos
Enum for the predefined raw histograms.
THttpServer * fHistoServer
Pointer to the histogram server, in case we run the online monitoring, the pointer is automatically d...
std::float_t getSamplesStdDev(CbmTrdRawMessageSpadic *raw)
Extract the std deviation of all samples in the message.
uint64_t fLastRawTime
Variable which holds the time in ns of the last processed raw message.
void resetTimeplots()
Reset the contents of all timeplots.
std::string fOutfilename
File name for the output file.
void addHistoToMap(std::shared_ptr< TH1 > histo, std::map< histotype, std::map< uint32_t, std::shared_ptr< TH1 > > > *histomap, uint32_t moduleid, histotype kHisto)
std::map< eOtherHistos, std::map< uint32_t, std::shared_ptr< TH1 > > > fOtherHistoMap
Other histogram pointers stored in a map together with the module id.
virtual void createHistos()
Create the actual TH1 shared_ptrs.
size_t writeHistosToFile(std::map< histotype, std::map< uint32_t, std::shared_ptr< TH1 > > > *histomap, TFile *file)
@ kUNU
Unused request. 100. .... .... .... cccc.
@ kChannelBufM
Channel buffer full and multihit from kEPO msg.
@ kChannelBuf
Channel buffer full from kEPO msg.
@ kNInfMsgs
Number of different info messages.
@ kBOM
Buffer overflow count. 11nn nnnn nnnn nnnn cccc.
@ kMIS
Missing request. 101. .... .... .... ....
@ kOrdFifoBuf
Multi-hit but ordering buffer full from kEPO msg.
@ kBUF
Buffer full. 011b b... .... .... cccc.
@ kMSB
Message build error. 010. .... .... .... cccc.
@ kNeigh
Neighbor trigger.
@ kSandN
Self and neighbor trigger at the same time.