CbmRoot
Loading...
Searching...
No Matches
CbmTrdUnpackFaspMonitor.cxx
Go to the documentation of this file.
1/* Copyright (C) 2022 Horia Hulubei National Institute of Physics and Nuclear Engineering, Bucharest
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Alexandru Bercuci [committer] */
4
6
7#include "CbmTrdDigi.h"
8#include "CbmTrdParFasp.h"
9
10#include <MicrosliceDescriptor.hpp>
11
12#include <FairRun.h>
13#include <FairRunOnline.h>
14#include <Logger.h>
15
16#include <RtypesCore.h>
17#include <TFile.h>
18#include <TH1.h>
19#include <TH2.h>
20#include <TProfile.h>
21#include <TROOT.h>
22
23#include <boost/math/special_functions/math_fwd.hpp>
24
25#include <cmath>
26#include <cstdint>
27#include <iostream>
28#include <memory>
29#include <numeric>
30#include <string>
31#include <utility>
32#include <vector>
33
34//_________________________________________________________________________
36
37//_________________________________________________________________________
39
40//_________________________________________________________________________
42{
43 auto moduleid = digi->GetAddressModule();
44 for (auto pair : fDigiHistoMap) {
45 auto modulepair = pair.second.find(moduleid);
46 auto histo = modulepair->second;
47 fillHisto(digi, pair.first, moduleid, histo);
48 }
49}
50
51//_________________________________________________________________________
53{
54 LOG(info) << Class_Name() << "::Finish() - ";
55
56 if (fDoWriteToFile) {
57 size_t nhistos = 0;
58
60 TFile* oldFile = gFile;
61 TDirectory* oldDir = gDirectory;
62
64 TFile histofile(fOutfilename.data(), "UPDATE");
65
66 nhistos += writeHistosToFile(&fDigiHistoMap, &histofile);
67 nhistos += writeHistosToFile(&fRawHistoMap, &histofile);
68
70 gFile = oldFile;
71 gDirectory = oldDir;
72
73 // histofile->Close();
74 histofile.Close();
75
76 LOG(info) << Class_Name() << "::Finish() nHistos " << nhistos << " written to " << fOutfilename.data();
77 }
78}
79
80//_________________________________________________________________________
82{
83
84 if (!fModuleDef.size()) return kFALSE;
85
86 // Check if there is a HttpServer and if so we later on register the created histograms in it.
87 if (FairRun::Instance()->IsA() == FairRunOnline::Class()) {
88 auto run = static_cast<FairRunOnline*>(FairRun::Instance());
89
90 fHistoServer = run->GetHttpServer();
91 }
92
93 // Purge the module list. Remove non-FASP modules
94 auto it = fModuleDef.begin();
95 while (it != fModuleDef.end()) {
96 size_t nchs = std::get<0>((*it).second).size();
97 if (nchs == 0)
98 it = fModuleDef.erase(it);
99 else
100 it++;
101 }
102
104 TFile* oldFile = gFile;
105 TDirectory* oldDir = gDirectory;
106 gROOT->cd();
107
108 createHistos();
109
111 gFile = oldFile;
112 gDirectory = oldDir;
113
114 return kTRUE;
115}
116
117//_________________________________________________________________________________
119{
120 int ncol(-1), modAddress(-1);
121 std::shared_ptr<TH1> histo = nullptr;
122
123 std::vector<int> faspAddress;
124 for (int idet(0); idet < set->GetNrOfModules(); idet++) {
125 CbmTrdParModAsic* par = (CbmTrdParModAsic*) set->GetModulePar(set->GetModuleId(idet));
126 if (par->GetAsicType() != CbmTrdDigi::eCbmTrdAsicType::kFASP) continue;
127
128 par->GetAsicAddresses(&faspAddress);
129 for (auto address : faspAddress) {
130 CbmTrdParFasp* fasp = (CbmTrdParFasp*) par->GetAsicPar(address);
131
132 if (modAddress != address / 1000) {
133 modAddress = address / 1000;
134 auto modpair = fDigiHistoMap[eDigiHistos::kMap_St];
135 if (modpair.find(modAddress) == modpair.end()) continue;
136 if (!(histo = modpair[modAddress])) continue;
137
138 if (fModuleDef.find(modAddress) == fModuleDef.end()) continue;
139 ncol = std::get<1>(fModuleDef[modAddress]);
140 }
141 for (int ich(0); ich < NFASPCH; ich++) {
142 const CbmTrdParFaspChannel* faspCh = fasp->GetChannel(ich);
143 int pad = fasp->GetPadAddress(ich), row = pad / ncol, col = pad % ncol;
144 if (faspCh->IsMasked()) histo->Fill(col + (faspCh->HasPairingR() ? 1 : -1) * 0.25, row);
145 }
146 }
147 }
148}
149
150//_________________________________________________________________________
152{
153 auto moduleDef = fModuleDef.find(madd);
154 if (moduleDef == fModuleDef.end()) {
155 LOG(warning) << Class_Name() << "::addParam(CbmTrdParSetAsic*) Module " << madd << " not in the list ! Skip.";
156 return;
157 }
158
159 std::vector<int32_t> chToFaspMapping(NFASPMOD * NFASPCH, -1);
160 std::vector<Int_t> add;
161 asics->GetAsicAddresses(&add);
162 for (auto afasp : add) {
163 CbmTrdParFasp* fasp = (CbmTrdParFasp*) asics->GetAsicPar(afasp);
164
165 int faspid(afasp % 1000), ich(faspid * 100);
166 for (auto ach : fasp->GetChannelAddresses()) {
167 chToFaspMapping[ach] = ich;
168 ich++;
169 }
170 }
171 std::get<0>((*moduleDef).second) = chToFaspMapping;
172}
173
174//_________________________________________________________________________
176{
177 auto moduleDef = fModuleDef.find(madd);
178 if (moduleDef == fModuleDef.end())
179 fModuleDef.emplace(madd, std::make_tuple(std::vector<int32_t>(), pp->GetNofColumns(), pp->GetNofRows()));
180 else {
181 LOG(warning) << Class_Name() << "::addParam(CbmTrdParModDigi*) Module " << madd
182 << " already loaded ! Replacing pad-plane definition.";
183 std::get<1>((*moduleDef).second) = pp->GetNofColumns();
184 std::get<2>((*moduleDef).second) = pp->GetNofRows();
185 }
186}
187
188//_________________________________________________________________________
190{
191 std::string histoname = "";
192 std::shared_ptr<TH1> newhisto = nullptr;
193
194 for (auto moduleDef : fModuleDef) {
195 auto modId = moduleDef.first;
196 auto ncols = std::get<1>(moduleDef.second);
197 auto nrows = std::get<2>(moduleDef.second);
198 auto nchs = nrows * ncols;
199
200 histoname = getTypeName(kHisto) + getHistoName(kHisto) + "Fasp";
201 switch (kHisto) {
203 newhisto = std::make_shared<TH2I>(histoname.data(), Form("%s %d", histoname.data(), modId), 2 * ncols, -0.5,
204 (ncols - 0.5), nrows, -0.5, (nrows - 0.5));
205 newhisto->SetXTitle("COL (pad)");
206 newhisto->SetYTitle("ROW (pad)");
207 newhisto->SetZTitle("Yield");
208 break;
209
211 histoname = getTypeName(kHisto) + "MaskFasp";
212 newhisto = std::make_shared<TH2I>(histoname.data(), Form("%s %d", histoname.data(), modId), 2 * ncols, -0.5,
213 (ncols - 0.5), nrows, -0.5, (nrows - 0.5));
214 newhisto->SetXTitle("COL (pad)");
215 newhisto->SetYTitle("ROW (pad)");
216 newhisto->SetZTitle("Mask");
217 break;
218
220 newhisto = std::make_shared<TH2I>(histoname.data(), Form("%s %d", histoname.data(), modId), 2 * nchs, -0.5,
221 (nchs - 0.5), 4095, 0.5, 4095.5);
222 newhisto->SetXTitle("Pad-Id");
223 newhisto->SetYTitle("Sgn [ADU]");
224 newhisto->SetZTitle("Yield");
225 break;
227 newhisto = std::make_shared<TH2I>(histoname.data(), Form("%s %d", histoname.data(), modId), NFASPMOD, -0.5,
228 (NFASPMOD - 0.5), NFASPCH, -0.5, NFASPCH - 0.5);
229 newhisto->SetXTitle("FASP-Id");
230 newhisto->SetYTitle("FASP-Ch");
231 newhisto->SetZTitle("Yield");
232 break;
234 const int npointsDecade = 40;
235 const int nb = 6 * npointsDecade;
236 double xa[nb + 1], base = std::pow(10, 1. / npointsDecade);
237 for (int i(-2 * npointsDecade), j(0); i <= 4 * npointsDecade; i++, j++)
238 xa[j] = std::pow(base, i);
239 newhisto = std::make_shared<TH2I>(histoname.data(), Form("%s %d", histoname.data(), modId), 2 * nchs, -0.5,
240 (nchs - 0.5), nb, xa);
241 newhisto->SetXTitle("Pad-Id");
242 newhisto->SetYTitle("Rate_{SGN} [kHz]");
243 newhisto->SetZTitle("Yield");
244 break;
245 }
246 default: return;
247 }
248 LOG(debug) << Class_Name() << "::CreateHisto() HistoDigi " << static_cast<size_t>(kHisto) << " Module " << modId
249 << " initialized as " << histoname.data();
250 if (newhisto) {
251 addHistoToMap<eDigiHistos>(newhisto, &fDigiHistoMap, modId, kHisto);
252 }
253 }
254}
255
256//_________________________________________________________________________
257void CbmTrdUnpackFaspMonitor::fillHisto(CbmTrdDigi* d, eDigiHistos kHisto, std::uint32_t moduleid,
258 std::shared_ptr<TH1> histo)
259{
260 auto modDef = fModuleDef[moduleid];
261 int pad = d->GetAddressChannel(), ncol = std::get<1>(modDef), row = pad / ncol, col = pad % ncol, dtime,
262 cht = 2 * pad, chr = cht + 1;
263 double t, r = d->GetCharge(t, dtime);
264 switch (kHisto) {
266 if (t > 0) histo->Fill(col - 0.25, row);
267 if (r > 0) histo->Fill(col + 0.25, row);
268 break;
269
271 if (t > 0) histo->Fill(pad - 0.25, t);
272 if (r > 0) histo->Fill(pad + 0.25, r);
273 break;
274
276 int fasp, faspid = -1, faspch = -1;
277 if (t > 0) {
278 if ((fasp = std::get<0>(modDef).at(cht)) < 0) {
279 LOG(debug) << Class_Name() << "::fillHisto() Missing FASP params for pad-T " << pad;
280 }
281 else {
282 faspid = fasp / 100;
283 faspch = fasp % 100;
284 histo->Fill(faspid, faspch);
285 }
286 }
287
288 if (r > 0) {
289 if ((fasp = std::get<0>(modDef).at(chr)) < 0) {
290 LOG(debug) << Class_Name() << "::fillHisto() Missing FASP params for pad-R " << pad;
291 }
292 else {
293 faspid = fasp / 100;
294 faspch = fasp % 100;
295 histo->Fill(faspid, faspch);
296 }
297 }
298 break;
299 }
301 if (t > 0) histo->Fill(pad - 0.25, fFaspInvClk / getDeltaT(moduleid, cht, d->GetTimeDAQ()));
302 if (r > 0) histo->Fill(pad + 0.25, fFaspInvClk / getDeltaT(moduleid, chr, d->GetTimeDAQ() + dtime));
303 break;
304
305 default: return;
306 }
307}
308
309//_________________________________________________________________________
310std::uint64_t CbmTrdUnpackFaspMonitor::getDeltaT(uint32_t modid, int32_t ch, uint64_t daqt)
311{
312 auto modulevecpair = fLastDigiTimeMap.find(modid);
313 if (modulevecpair == fLastDigiTimeMap.end()) {
314 auto modDef = fModuleDef[modid];
315 int ncol = std::get<1>(modDef), nrow = std::get<2>(modDef), nchs = 2 * ncol * nrow;
316 std::vector<size_t> channelsvec(nchs, 0);
317
318 if (ch > nchs) return 0;
319 channelsvec.at(ch) = daqt;
320 auto pair = std::make_pair(modid, channelsvec);
321 fLastDigiTimeMap.emplace(pair);
322 return daqt;
323 }
324 else {
325 auto prevtime = modulevecpair->second.at(ch);
326 modulevecpair->second.at(ch) = daqt;
327 auto dt = daqt - prevtime;
328 return dt;
329 }
330}
331
ClassImp(CbmConverterManager)
Monitor class for the unpacker algorithms (CbmTrdUnpackFasp) of FASP data.
int32_t GetAddressModule() const
Getter module address in the experiment.
uint64_t GetTimeDAQ() const
Getter for global DAQ time [clk]. Differs for each ASIC. In FASP case DAQ time is already stored in f...
Definition CbmTrdDigi.h:158
int32_t GetAddressChannel() const
Getter read-out id.
double GetCharge() const
Common purpose charge getter.
virtual std::vector< Int_t > GetChannelAddresses() const
Definition of FASP channel calibration container.
Bool_t HasPairingR() const
Query pad pairing type.
bool IsMasked() const
Definition of FASP parameters.
const CbmTrdParFaspChannel * GetChannel(Int_t pad_address, UChar_t pair) const
Query the calibration for one FASP RO channel.
int GetPadAddress(Int_t ich) const
Describe TRD module ASIC settings (electronic gain, delays, etc)
virtual void GetAsicAddresses(std::vector< Int_t > *a) const
Query the ASICs in the module for their DAQ address. It applies to the list of ASICs....
virtual CbmTrdDigi::eCbmTrdAsicType GetAsicType() const
Query the type of ASICs in the list.
virtual const CbmTrdParAsic * GetAsicPar(Int_t address) const
Look for the ASIC parameters of a given DAQ id It applies to the list of ASICs.
Definition of chamber gain conversion for one TRD module.
Int_t GetNofRows() const
Int_t GetNofColumns() const
Describe TRD module ASIC settings (electronic gain, delays, etc)
virtual ~CbmTrdUnpackFaspMonitor()
Destroy the Cbm Trd Unpack Task object.
virtual void fillHisto(CbmTrdDigi *digi, eDigiHistos kHisto, std::uint32_t moduleid, std::shared_ptr< TH1 > histo)
Fill the given histo with the information from the digi. Reimplement from CbmTrdUnpackMonitor.
const double fFaspInvClk
save 1/clk for the FASP FEE in kHz
CbmTrdUnpackFaspMonitor()
Create the Cbm Trd Unpack AlgoBase object.
void MapMaskedChannels(const CbmTrdParSetAsic *asics)
Special call for monitoring the masked channel map.
void FillHistos(CbmTrdDigi *digi)
fill the stored digi histograms
std::map< uint32_t, std::tuple< std::vector< int32_t >, uint8_t, uint8_t > > fModuleDef
Map of definitions for each module under monitoring : std::get<0> : pad to FASP channel mapping std::...
void Finish()
Actions at the end of the run, e.g. write histos to file if flag is set.
void createHisto(eDigiHistos kHisto)
Create the actual TH1 shared_ptrs of the Digi histos.
Bool_t Init()
Init all required parameter informations.
virtual std::uint64_t getDeltaT(uint32_t modid, int32_t ch=-1, uint64_t daqt=0)
Paralell implementation of the omonime function from CbmTrdUnpackMonitor for the case of FASP digis....
void addParam(uint32_t madd, const CbmTrdParModAsic *asics)
Init module and link asics properties.
static std::string getTypeName(eDigiHistos kHisto)
Get the Type Name for the given histo.
std::string getHistoName(eDigiHistos kHisto)
Get the Histo Name for the given histo.
eDigiHistos
Enum for the predefined digi histograms.
std::map< std::uint32_t, std::vector< size_t > > fLastDigiTimeMap
Map with the last digi time for each channel of a given module.
std::map< eDigiHistos, std::map< std::uint32_t, std::shared_ptr< TH1 > > > fDigiHistoMap
Digi histogram pointers stored in a map together with the module id.
std::map< eRawHistos, std::map< std::uint32_t, std::shared_ptr< TH1 > > > fRawHistoMap
Raw histogram pointers stored in a map together with the module id.
bool fDoWriteToFile
Flag whether to write histos to file or not, gets activated if a output filename gets set.
THttpServer * fHistoServer
Pointer to the histogram server, in case we run the online monitoring, the pointer is automatically d...
size_t writeHistosToFile(std::map< histotype, std::map< std::uint32_t, std::shared_ptr< TH1 > > > *histomap, TFile *file)
void addHistoToMap(std::shared_ptr< TH1 > histo, std::map< histotype, std::map< std::uint32_t, std::shared_ptr< TH1 > > > *histomap, std::uint32_t moduleid, histotype kHisto)
std::string fOutfilename
File name for the output file.
virtual void createHistos()
Create the actual TH1 shared_ptrs.
#define NFASPCH
#define NFASPMOD