BmnRoot
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 <TMath.h>
25#include <TStopwatch.h>
26#include <TString.h>
27#include <TStyle.h>
28#include <TTree.h>
29// FairRoot
30#include <FairLogger.h>
31// BmnRoot
32#include "BmnADCDigit.h"
33#include "BmnAliases.h"
34#include "BmnCalibData.h"
35#include "BmnEnums.h"
36
37#include <BmnCSCStationSet.h>
39#include <BmnSiBTStationSet.h>
40#include <BmnSiProfStationSet.h>
42
43#define N_EV_FOR_PEDESTALS 500
44#define ADC_N_CHANNELS 64 // number of ADC channels
45#define ADC_PROF_N_CHANNELS 2 // number of ADC channels
46#define ADC_SIBT_N_SAMPLES 64 // number of samples in one SiBT digit
47#define ADC128_N_SAMPLES 128 // number of samples in one ADC digit //silicon
48#define ADC32_N_SAMPLES 32 // number of samples in one ADC digit //gem
49
50typedef vector<Int_t> StripMap;
51
52using std::map;
53using std::unordered_map;
54using std::vector;
55using namespace TMath;
56
58{
59 public:
60 BmnAdcProcessor(uint32_t period, uint32_t run, TString det, Int_t nCh, const Int_t nSmpl);
62
65 void PrecalcEventModsOld(TClonesArray* adc);
66 void PrecalcEventMods(TClonesArray* adc);
67 void PrecalcEventMods_simd(TClonesArray* adc);
68 void (BmnAdcProcessor::*PrecalcEventModsImp)(TClonesArray* adc);
71 // BmnStatus FillProfiles(TClonesArray *adc);
72 Double_t CalcCMS(Double_t* samples, Int_t size);
73 BmnStatus SaveFilterInfo(TFile* cTalibFile);
74 BmnStatus LoadFilterInfo(TFile* cTalibFile);
76
77 Double_t**** GetPedData() { return fPedDat; }
78
79 void SetNSerials(Int_t n) { fNSerials = n; }
80
81 void SetNChannels(Int_t n) { fNChannels = n; }
82
83 void SetApplyThreshold(bool b) { fApplyThreshold = b; }
84
86
87 Int_t GetNSerials() { return fNSerials; }
88
89 Int_t GetNChannels() { return fNChannels; }
90
91 Int_t GetNSamples() { return fNSamples; }
92
93 Float_t GetPedestal(Int_t iSer, Int_t ch, Int_t smpl) { return fPedVal[iSer][ch][smpl]; }
94
95 Float_t*** GetPedestals() { return fPedVal; }
96
97 Double_t*** GetPedestalsRMS() { return fPedCMod2; }
98
100
101 uint32_t GetPeriod() { return fPeriod; }
102
103 uint32_t GetRun() { return fRun; }
104
105 Int_t GetVerbose() { return fVerbose; }
106
107 void SetVerbose(Int_t v) { fVerbose = v; }
108
109 vector<UInt_t>& GetSerials() { return fAdcSerials; }
110
111 unordered_map<UInt_t, Int_t>& GetSerialMap() { return fSerMap; }
112
113 inline UInt_t GetBoundaryRun(UInt_t nSmpl)
114 {
115 // format for SILICON data was changed during March 2017 seance (run 1542)
116 // format for GEM was changed after March 2017 seance (run 1992)
117 // so we have to use this crutch.
118 return (nSmpl == 128) ? 1542 : 1992;
119 }
120
122
124
128 void CopyData2PedMap(TClonesArray* adc, UInt_t ev);
129 void SetThreshold(Double_t final_thr, Double_t thr_dif = -1, Double_t n_iters = -1, Double_t cmod_cut = -1);
130
131 protected:
132 Int_t fVerbose;
133 Int_t drawCnt;
134 Int_t drawCnt2d;
135 Double_t thrDif;
136 Double_t FinalThr;
137 Int_t fNIters;
138 Double_t cmodcut;
139 Double_t thrMax;
140 Int_t fNSerials;
141 vector<UInt_t> fAdcSerials;
142 const Int_t fNSamples;
143 Int_t fNChannels;
144 UInt_t fEvForPedestals;
145 Double_t**** fPedDat;
147 bool fApplyThreshold;
148 map<PlMapKey, Double_t> fSpecThreshMap; // for special cases signal amplitude
149
151 void GrabNewSerial(UInt_t serial);
152
153 template<typename cl>
154 void GrabSerialsFromMap(unordered_map<UInt_t, cl> m)
155 {
156 for (auto& it : m) {
157 UInt_t serial = it.first;
158 auto serIter = fSerMap.find(serial);
159 if (serIter == fSerMap.end()) {
160 if (fVerbose > 1)
161 printf("Adding %08X to the map, iSer = %d\n", serial, fNSerials);
162 fSerMap.insert(pair<UInt_t, Int_t>(serial, fNSerials++));
163 fAdcSerials.push_back(serial);
164 }
165 }
166 }
167
168 template<typename SST>
169 void InitNoiseArrays(SST& ss)
170 {
171 Int_t kNStations = ss->GetNStations();
172 fSigProf = new TH1F***[kNStations];
173 fNoisyChannels = new Bool_t***[kNStations];
174 for (Int_t iSt = 0; iSt < kNStations; ++iSt) {
175 auto* st = ss->GetStation(iSt);
176 UInt_t nModules = st->GetNModules();
177 fSigProf[iSt] = new TH1F**[nModules];
178 fNoisyChannels[iSt] = new Bool_t**[nModules];
179 for (UInt_t iMod = 0; iMod < nModules; ++iMod) {
180 auto* mod = st->GetModule(iMod);
181 Int_t nLayers = mod->GetNStripLayers();
182 fSigProf[iSt][iMod] = new TH1F*[nLayers];
183 fNoisyChannels[iSt][iMod] = new Bool_t*[nLayers];
184 for (Int_t iLay = 0; iLay < nLayers; ++iLay) {
185 auto& lay = mod->GetStripLayer(iLay);
186 Int_t nStrips = lay.GetNStrips();
187 TString histName;
188 histName.Form("%s_%d_%d_%d", fDetName.Data(), iSt, iMod, iLay);
189 if (fVerbose)
190 printf("SigProf %s\n", histName.Data());
191 fSigProf[iSt][iMod][iLay] = new TH1F(histName, histName, nStrips, 0, nStrips);
192 fSigProf[iSt][iMod][iLay]->SetDirectory(0);
193 fNoisyChannels[iSt][iMod][iLay] = new Bool_t[nStrips];
194 for (Int_t iStrip = 0; iStrip < nStrips; ++iStrip)
195 fNoisyChannels[iSt][iMod][iLay][iStrip] = kFALSE;
196 }
197 }
198 }
199 }
200
201 template<typename SST>
202 void DeleteNoiseArrays(SST& ss)
203 {
204 Int_t kNStations = ss->GetNStations();
205 for (Int_t iSt = 0; iSt < kNStations; ++iSt) {
206 auto* st = ss->GetStation(iSt);
207 for (Int_t iMod = 0; iMod < st->GetNModules(); ++iMod) {
208 auto* mod = st->GetModule(iMod);
209 for (Int_t iLay = 0; iLay < mod->GetNStripLayers(); ++iLay) {
210 delete fSigProf[iSt][iMod][iLay];
211 delete[] fNoisyChannels[iSt][iMod][iLay];
212 }
213 delete[] fSigProf[iSt][iMod];
214 delete[] fNoisyChannels[iSt][iMod];
215 }
216 delete[] fSigProf[iSt];
217 delete[] fNoisyChannels[iSt];
218 }
219 delete[] fNoisyChannels;
220 delete[] fSigProf;
221 }
222 Double_t workTime_cpu = 0.0;
223 Double_t workTime_real = 0.0;
224 Double_t workTime_cpu_p = 0.0;
225 Double_t workTime_real_p = 0.0;
226
227 unordered_map<UInt_t, Int_t> fSerMap;
228
229 TH1F**** fSigProf;
230 Bool_t**** fNoisyChannels;
231 // Double_t*** fAdc;
232 Float_t*** fAdc;
233 Double_t*** fPedRms; // set of calculated pedestal errors
234 // Double_t*** fPedVal; //set of calculated pedestals
235 Float_t*** fPedVal;
236 Double_t*** fPedValTemp; // set of calculated pedestals
237 // Double_t** fCMode; //set of calculated pedestal CMSs
238 Float_t** fCMode;
239 // Double_t** fCMode0; //set of calculated pedestal CMSs
240 Float_t** fCMode0;
241 // Double_t** fSMode; //set of calculated signal CMSs
242 Float_t** fSMode;
243 // Double_t** fSMode0; //set of calculated signal CMSs
244 Float_t** fSMode0;
245
246 vector<vector<TH1*>> hPedLine;
247 vector<vector<TH1*>> hCMode;
248 vector<vector<TH1*>> hSMode;
249 vector<vector<TH1*>> hPedLineSi;
250 vector<TH1*> hPedSi;
251 vector<TH1*> hCModeSi;
252 vector<TH1*> hSModeSi;
253
254 Bool_t*** fNoisyChipChannels; // set of noisy channel flags
255
256 Float_t** fNvals;
257 // UInt_t** fNvals; // number of valid (under threshold) pedestals
258 UInt_t*** fNvalsCMod; // number of valid (under threshold) pedestals
259 UInt_t*** fNvalsADC; // number of valid (under threshold) ADC signals
260 Double_t*** fPedCMod;
261 Double_t*** fPedCMod2;
262 Double_t** fSumRmsV;
263
264 TString fDetName; // it's used for .txt files name
265 uint32_t fPeriod;
266 uint32_t fRun;
267
268 private:
269 UInt_t*** fAdcProfiles;
270 TH2F* hcms;
271 TH2F* hscms_adc;
272 TH1F* hcms1;
273 TH2F* hscms1_adc;
274 TH1F* hcms1p;
275 TH1F* hscms1p_adc;
276 TH2F* hp;
277 TH2F* hfilter;
278 TH2F* hfilterMK;
279 TCanvas* canStrip;
280
281 ClassDef(BmnAdcProcessor, 1);
282};
283
284#endif /* BMNADCPROCESSOR_H */
__m128 v
Definition P4_F32vec4.h:1
__m128 m
Definition P4_F32vec4.h:27
BmnStatus
Definition BmnEnums.h:24
BmnSetup
Definition BmnEnums.h:89
void PrecalcEventMods(TClonesArray *adc)
void CalcEventMods()
Double_t *** fPedRms
Double_t **** fPedDat
data set to calculate pedestals
BmnAdcProcessor(uint32_t period, uint32_t run, TString det, Int_t nCh, const Int_t nSmpl)
BmnStatus RecalculatePedestalsAugmented()
map< PlMapKey, Double_t > fSpecThreshMap
Double_t **** GetPedData()
Double_t *** GetPedestalsRMS()
UInt_t *** fNvalsCMod
void CalcEventMods_simd()
Bool_t *** fNoisyChipChannels
void SetNSerials(Int_t n)
Double_t *** fPedCMod
void DrawDebugHists()
vector< UInt_t > & GetSerials()
Double_t *** fPedValTemp
Float_t GetPedestal(Int_t iSer, Int_t ch, Int_t smpl)
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)
void DrawDebugHists2D()
Float_t *** fPedVal
vector< TH1 * > hSModeSi
vector< TH1 * > hPedSi
vector< TH1 * > hCModeSi
vector< vector< TH1 * > > hCMode
virtual ~BmnAdcProcessor()
Bool_t **** fNoisyChannels
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 Int_t fNSamples
vector< UInt_t > fAdcSerials
list of serial id for ADC-detector
void InitNoiseArrays(SST &ss)
void PrecalcEventMods_simd(TClonesArray *adc)
void ClearDebugHists()
void PrecalcEventModsOld(TClonesArray *adc)
Bool_t *** GetNoisyChipChannels()
unordered_map< UInt_t, Int_t > & GetSerialMap()
Float_t *** GetPedestals()
vector< vector< TH1 * > > hPedLine
void DeleteNoiseArrays(SST &ss)
vector< vector< TH1 * > > hSMode
unordered_map< UInt_t, Int_t > fSerMap
ADC serials map.
vector< vector< TH1 * > > hPedLineSi
void(BmnAdcProcessor::* PrecalcEventModsImp)(TClonesArray *adc)
Double_t CalcCMS(Double_t *samples, Int_t size)
void SetEvForPedestals(UInt_t v)
void SetApplyThreshold(bool b)
static BmnStatus DrawFilterInfo(BmnCalibData *data)
BmnStatus LoadFilterInfo(TFile *cTalibFile)
UInt_t GetEvForPedestals()
BmnStatus RecalculatePedestals()
void SetNChannels(Int_t n)
UInt_t GetBoundaryRun(UInt_t nSmpl)
vector< Int_t > StripMap
Define enumerations used in tracking.
-clang-format