BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
BmnAdcProcessor.h
Go to the documentation of this file.
1//
2// Base class for processing data from ADC strip detectors
3// It's used for pedestal calculation
4//
5
6#ifndef BMNADCPROCESSOR_H
7#define BMNADCPROCESSOR_H
8
9// STL
10#include <bitset>
11#include <fstream>
12#include <iostream>
13#include <list>
14#include <map>
15#include <memory>
16#include <unordered_map>
17#include <vector>
18// ROOT
19#include <TCanvas.h>
20#include <TClonesArray.h>
21#include <TColor.h>
22#include <TFile.h>
23#include <TH2F.h>
24#include <TStopwatch.h>
25#include <TString.h>
26// FairRoot
27#include <FairLogger.h>
28// BmnRoot
29#include "BmnADCDigit.h"
30#include "BmnAliases.h"
31#include "BmnCalibData.h"
32#include "BmnEnums.h"
33
34#include <BmnCSCStationSet.h>
36#include <BmnSiBTStationSet.h>
37#include <BmnSiProfStationSet.h>
39
40#define N_EV_FOR_PEDESTALS 500
41#define ADC_N_CHANNELS 64 // number of ADC channels
42#define ADC_PROF_N_CHANNELS 2 // number of ADC channels
43#define ADC_SIBT_N_SAMPLES 64 // number of samples in one SiBT digit
44#define ADC128_N_SAMPLES 128 // number of samples in one ADC digit //silicon
45#define ADC32_N_SAMPLES 32 // number of samples in one ADC digit //gem
46
47using std::map;
48using std::unordered_map;
49using std::vector;
50
52{
53 public:
54 BmnAdcProcessor(uint32_t period,
55 uint32_t run,
56 TString det,
57 uint16_t nCh,
58 const uint16_t nSmpl,
59 BmnSetup setup = kBMNSETUP);
61
69 // BmnStatus FillProfiles(TClonesArray *adc);
70 Double_t CalcCMS(Double_t* samples, Int_t size);
74
75 Double_t**** GetPedData() { return fPedDat; }
76
77 void SetApplyThreshold(bool b) { fApplyThreshold = b; }
78
80
81 size_t GetNSerials() { return fAdcSerials.size(); }
82
83 const uint16_t GetNChannels() { return fNChannels; }
84
85 const uint16_t GetNSamples() { return fNSamples; }
86
87 Float_t GetPedestal(uint32_t iSer, Int_t ch, Int_t smpl) { return fPedVal[iSer][ch][smpl]; }
88
89 Float_t*** GetPedestals() { return fPedVal; }
90
92
94
95 uint32_t GetPeriod() { return fPeriod; }
96
97 uint32_t GetRun() { return fRun; }
98
100
102
103 vector<uint32_t>& GetSerials() { return fAdcSerials; }
104
105 unordered_map<uint32_t, size_t>& GetSerialMap() { return fSerMap; }
106
107 inline uint32_t GetBoundaryRun(uint16_t nSmpl)
108 {
109 // format for SILICON data was changed during March 2017 seance (run 1542)
110 // format for GEM was changed after March 2017 seance (run 1992)
111 // so we have to use this crutch.
112 return (nSmpl == 128) ? 1542 : 1992;
113 }
114
115 void SetEvForPedestals(uint32_t v) { fEvForPedestals = v; }
116
117 uint32_t GetEvForPedestals() { return fEvForPedestals; }
118
120
124 void CopyData2PedMap(TClonesArray* adc, UInt_t ev);
125 void SetThreshold(Double_t final_thr, Double_t thr_dif = -1, Double_t n_iters = -1, Double_t cmod_cut = -1);
126
127 protected:
128 typedef std::tuple<uint16_t, uint16_t, uint8_t> KeySML; // station, module, layer
129 typedef std::tuple<uint16_t, uint16_t> KeySM; // station, module
130 typedef vector<Int_t> StripMap;
139 vector<uint32_t> fAdcSerials; ///< list of serial id for ADC-detector
140 const uint16_t fNSamples;
141 const uint16_t fNChannels;
142 uint32_t fEvForPedestals;
143 Double_t**** fPedDat; ///< data set to calculate pedestals
144 bool fApplyThreshold;
145 map<PlMapKey, Double_t> fSpecThreshMap; // for special cases signal amplitude
146
148 void GrabNewSerial(UInt_t serial);
149
150 template<typename cl>
151 void GrabSerialsFromMap(unordered_map<UInt_t, cl> m)
152 {
153 for (auto& it : m) {
154 UInt_t serial = it.first;
155 GrabNewSerial(serial);
156 // auto serIter = fSerMap.find(serial);
157 // if (serIter == fSerMap.end()) {
158 // if (fVerbose > 1)
159 // printf("Adding %08X to the map, iSer = %d\n", serial, GetNSerials());
160 // fSerMap.insert(pair<UInt_t, Int_t>(serial, GetNSerials()));
161 // fAdcSerials.push_back(serial);
162 // }
163 }
164 }
165
166 template<typename SST>
168 {
169 Int_t kNStations = ss->GetNStations();
170 fSigProf = new TH1F***[kNStations];
171 fNoisyChannels = new Bool_t***[kNStations];
172 for (Int_t iSt = 0; iSt < kNStations; ++iSt) {
173 auto* st = ss->GetStation(iSt);
174 UInt_t nModules = st->GetNModules();
175 fSigProf[iSt] = new TH1F**[nModules];
176 fNoisyChannels[iSt] = new Bool_t**[nModules];
177 for (UInt_t iMod = 0; iMod < nModules; ++iMod) {
178 auto* mod = st->GetModule(iMod);
179 Int_t nLayers = mod->GetNStripLayers();
180 fSigProf[iSt][iMod] = new TH1F*[nLayers];
181 fNoisyChannels[iSt][iMod] = new Bool_t*[nLayers];
182 for (Int_t iLay = 0; iLay < nLayers; ++iLay) {
183 auto& lay = mod->GetStripLayer(iLay);
184 Int_t nStrips = lay.GetNStrips();
185 TString histName;
186 histName.Form("%s_%d_%d_%d", fDetName.Data(), iSt, iMod, iLay);
187 if (fVerbose)
188 printf("SigProf %s strips %d\n", histName.Data(), nStrips);
189 fSigProf[iSt][iMod][iLay] = new TH1F(histName, histName, nStrips, 0, nStrips);
190 fSigProf[iSt][iMod][iLay]->SetDirectory(0);
191 fNoisyChannels[iSt][iMod][iLay] = new Bool_t[nStrips];
192 for (Int_t iStrip = 0; iStrip < nStrips; ++iStrip)
193 fNoisyChannels[iSt][iMod][iLay][iStrip] = kFALSE;
194 }
195 }
196 }
197 }
198
199 template<typename SST>
201 {
202 Int_t kNStations = ss->GetNStations();
203 for (Int_t iSt = 0; iSt < kNStations; ++iSt) {
204 auto* st = ss->GetStation(iSt);
205 for (Int_t iMod = 0; iMod < st->GetNModules(); ++iMod) {
206 auto* mod = st->GetModule(iMod);
207 for (Int_t iLay = 0; iLay < mod->GetNStripLayers(); ++iLay) {
208 delete fSigProf[iSt][iMod][iLay];
209 delete[] fNoisyChannels[iSt][iMod][iLay];
210 }
211 delete[] fSigProf[iSt][iMod];
212 delete[] fNoisyChannels[iSt][iMod];
213 }
214 delete[] fSigProf[iSt];
215 delete[] fNoisyChannels[iSt];
216 }
217 delete[] fNoisyChannels;
218 delete[] fSigProf;
219 }
224
225 unordered_map<UInt_t, size_t> fSerMap; ///< ADC serials map
226
227 TH1F**** fSigProf;
229 // Double_t*** fAdc;
230 Float_t*** fAdc;
231 Double_t*** fPedRms; // set of calculated pedestal errors
232 // Double_t*** fPedVal; //set of calculated pedestals
233 Float_t*** fPedVal;
234 Double_t*** fPedValTemp; // set of calculated pedestals
235 // Double_t** fCMode; //set of calculated pedestal CMSs
236 Float_t** fCMode;
237 // Double_t** fCMode0; //set of calculated pedestal CMSs
239 // Double_t** fSMode; //set of calculated signal CMSs
240 Float_t** fSMode;
241 // Double_t** fSMode0; //set of calculated signal CMSs
243
244 vector<vector<TH1*>> hPedLine;
245 vector<vector<TH1*>> hCMode;
246 vector<vector<TH1*>> hSMode;
247 vector<vector<TH1*>> hPedLineSi;
248 vector<TH1*> hPedSi;
249 vector<TH1*> hCModeSi;
250 vector<TH1*> hSModeSi;
251
252 Bool_t*** fNoisyChipChannels; // set of noisy channel flags
253
254 Float_t** fNvals;
255 // UInt_t** fNvals; // number of valid (under threshold) pedestals
256 UInt_t*** fNvalsCMod; // number of valid (under threshold) pedestals
257 UInt_t*** fNvalsADC; // number of valid (under threshold) ADC signals
261
262 TString fDetName; // it's used for .txt files name
263 uint32_t fPeriod;
264 uint32_t fRun;
266
267 private:
269 TH2F* hcms;
271 TH1F* hcms1;
273 TH1F* hcms1p;
275 TH2F* hp;
276 TH2F* hfilter;
279
281};
282
283#endif /* BMNADCPROCESSOR_H */
__m128 v
Definition P4_F32vec4.h:1
__m128 m
Definition P4_F32vec4.h:27
bool Bool_t
int Int_t
unsigned int UInt_t
float Float_t
constexpr Bool_t kFALSE
double Double_t
#define ClassDef(name, id)
BmnStatus
Define status code.
Definition BmnEnums.h:93
BmnSetup
Define experimental setup.
Definition BmnEnums.h:165
@ kBMNSETUP
Definition BmnEnums.h:166
unordered_map< UInt_t, size_t > fSerMap
ADC serials map.
TString & GetDetName()
void DeleteStripNoiseArrays(SST &ss)
void PrecalcEventMods(TClonesArray *adc)
void CalcEventMods()
void InitStripNoiseArrays(SST &ss)
Double_t *** fPedRms
Double_t **** fPedDat
data set to calculate pedestals
const uint16_t fNSamples
uint32_t GetPeriod()
BmnStatus RecalculatePedestalsAugmented()
map< PlMapKey, Double_t > fSpecThreshMap
Double_t **** GetPedData()
Double_t *** GetPedestalsRMS()
UInt_t *** fAdcProfiles
UInt_t *** fNvalsCMod
void CalcEventMods_simd()
Bool_t *** fNoisyChipChannels
Double_t *** fPedCMod
vector< Int_t > StripMap
void DrawDebugHists()
Double_t *** fPedValTemp
BmnAdcProcessor(uint32_t period, uint32_t run, TString det, uint16_t nCh, const uint16_t nSmpl, BmnSetup setup=kBMNSETUP)
Double_t *** fPedCMod2
void SetThreshold(Double_t final_thr, Double_t thr_dif=-1, Double_t n_iters=-1, Double_t cmod_cut=-1)
BmnStatus SaveFilterInfo(TFile *cTalibFile)
std::tuple< uint16_t, uint16_t, uint8_t > KeySML
void DrawDebugHists2D()
Float_t *** fPedVal
vector< TH1 * > hSModeSi
vector< TH1 * > hPedSi
vector< uint32_t > fAdcSerials
list of serial id for ADC-detector
vector< TH1 * > hCModeSi
void SetEvForPedestals(uint32_t v)
vector< vector< TH1 * > > hCMode
virtual ~BmnAdcProcessor()
unordered_map< uint32_t, size_t > & GetSerialMap()
Bool_t **** fNoisyChannels
const uint16_t fNChannels
void CopyData2PedMap(TClonesArray *adc, UInt_t ev)
void SetVerbose(Int_t v)
Double_t ** fSumRmsV
void GrabSerialsFromMap(unordered_map< UInt_t, cl > m)
void GrabNewSerial(UInt_t serial)
const uint16_t GetNChannels()
void InitChipNoiseArrays()
std::tuple< uint16_t, uint16_t > KeySM
void PrecalcEventMods_simd(TClonesArray *adc)
const uint16_t GetNSamples()
void ClearDebugHists()
Float_t GetPedestal(uint32_t iSer, Int_t ch, Int_t smpl)
Bool_t *** GetNoisyChipChannels()
Float_t *** GetPedestals()
vector< vector< TH1 * > > hPedLine
vector< vector< TH1 * > > hSMode
vector< vector< TH1 * > > hPedLineSi
void(BmnAdcProcessor::* PrecalcEventModsImp)(TClonesArray *adc)
Double_t CalcCMS(Double_t *samples, Int_t size)
void SetApplyThreshold(bool b)
static BmnStatus DrawFilterInfo(BmnCalibData *data)
BmnStatus LoadFilterInfo(TFile *cTalibFile)
uint32_t GetBoundaryRun(uint16_t nSmpl)
uint32_t GetEvForPedestals()
vector< uint32_t > & GetSerials()
BmnStatus RecalculatePedestals()
const char * Data() const
void Form(const char *fmt,...)
Define enumerations used in tracking.