BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
BmnSiBTRaw2Digit.cxx
Go to the documentation of this file.
1// Boost
2#include <boost/program_options.hpp>
3// BmnRoot
4#include "BmnSiBTRaw2Digit.h"
5
6namespace po = boost::program_options;
7
8BmnSiBTRaw2Digit::BmnSiBTRaw2Digit(Int_t period, Int_t run, TString MapFileName, BmnSetup bmnSetup)
9 : BmnAdcProcessor(period, run, "SiBT", ADC_N_CHANNELS, ADC_SIBT_N_SAMPLES, bmnSetup)
11{
12 fMapFileName = MapFileName;
17}
18
20{
22 for (auto& it : fOuterMap)
23 for (auto& inner : it.second)
24 delete inner.second;
25}
26
28{
29 ifstream inFile(FileName.data());
30 if (!inFile.is_open()) {
31 cout << "Error opening map-file (" << FileName << ")!" << endl;
32 return kBMNERROR;
33 }
34
35 Int_t iStrip(0);
36 Int_t chan(0);
37 while (inFile >> chan) {
38 Strips[chan] = iStrip++;
39 // printf("\t\t strip %4d chan %4d\n", Strips[chan], chan);
40 }
41
42 return kBMNSUCCESS;
43}
44
46{
47 for (auto& map_el : fGlobalMap) {
48 BmnSiBTMapping& info = map_el.second;
49 auto it = fLocalMaps.find(info.channel_name);
50 if (it != fLocalMaps.end()) {
51 info.strips = &(it->second);
52 } else {
53 string map_file_name =
54 string(getenv("VMCWORKDIR")) + "/input/" + string(fDetName.Data()) + "_" + info.channel_name + ".txt";
55 StripMap strips(fNSamples, 0);
56 LOGF(info, "Reading: %s", map_file_name.data());
57 ReadLocalMap(map_file_name, strips);
58 fLocalMaps[info.channel_name] = move(strips);
59 info.strips = &(fLocalMaps[info.channel_name]);
60 }
61 }
62 return kBMNSUCCESS;
63}
64
66{
67 UInt_t ser = 0;
68 Short_t ch_lo = 0;
69 Int_t strip_shift = 0;
70 Char_t ch_name;
71 Short_t mod = 0;
72 Short_t lay = 0;
73 Short_t station = 0;
74 string dummy;
75
76 vector<string> channel_map;
77 vector<string> spec_thr;
78 Double_t final_thr = 0;
79 Double_t thr_dif = 0;
80 Int_t n_iters = 0;
81 Double_t cmod_cut = 0;
82
83 // Setup options.
84 po::options_description desc("Options");
85 desc.add_options()("CHANNEL_MAP.channels", po::value<vector<string>>(&channel_map)->multitoken(),
86 "ADC channel -> strip map")("SIGNAL_CONFIGURATION.spec_thr",
87 po::value<vector<string>>(&spec_thr)->multitoken(),
88 "ADC channel -> strip map")(
89 "SIGNAL_CONFIGURATION.Threshold", po::value<Double_t>(&final_thr)->default_value(950), "ADC final threshold")(
90 "SIGNAL_CONFIGURATION.ThresholdDif", po::value<Double_t>(&thr_dif)->default_value(50), "ADC final threshold")(
91 "SIGNAL_CONFIGURATION.NIterations", po::value<Int_t>(&n_iters)->default_value(6), "ADC final threshold")(
92 "SIGNAL_CONFIGURATION.CModCut", po::value<Double_t>(&cmod_cut)->default_value(0), "ADC final threshold");
93
94 // Load config file.
95 po::variables_map vm;
96 TString name = TString(getenv("VMCWORKDIR")) + TString("/input/") + fMapFileName;
97 LOG(info) << "Loading SiBT Map: Period " << fPeriod << ", Run " << fRun << " " << name;
98 ifstream config_file(name.Data(), ifstream::in);
99 if (!config_file.is_open()) {
100 LOG(error) << "Error opening map-file (" << name << ")!";
101 return kBMNERROR;
102 }
103 po::store(po::parse_config_file(config_file, desc), vm);
104 config_file.close();
105 po::notify(vm);
106
107 // set thresholds
108 SetThreshold(final_thr, thr_dif, n_iters, cmod_cut);
109
110 // set specific thresholds
111 Int_t ch = 0;
112 Double_t thr = 0;
113 for (auto& str : spec_thr) {
114 istringstream ss(str);
115 ss >> std::hex >> ser >> std::dec >> ch >> thr;
116 fSpecThreshMap.insert(make_pair(make_pair(ser, ch), thr));
117 LOGF(debug, "Serial 0x%08X Channel %2d Threshold %3.3f", ser, ch, thr);
118 }
119
120 // set channel map
121 for (auto& str : channel_map) {
122 istringstream ss(str);
123 ss >> std::hex >> ser >> std::dec >> ch_lo >> strip_shift >> ch_name >> mod >> lay >> station;
124 fGlobalMap.insert(make_pair(make_pair(ser, ch_lo), BmnSiBTMapping{.layer = lay,
125 .serial = ser,
126 .module = mod,
127 .channel = ch_lo,
128 .strip_shift = strip_shift,
129 .channel_name = ch_name,
130 .station = station,
131 .strips = nullptr}));
132 GrabNewSerial(ser);
133 }
134 return kBMNSUCCESS;
135}
136
138{
139 (this->*PrecalcEventModsImp)(adc);
140#ifdef BUILD_DEBUG
142#else
144#endif
145 ProcessAdc(digits, kFALSE);
146 return kBMNSUCCESS;
147}
148
150{
151 (this->*PrecalcEventModsImp)(adc);
152#ifdef BUILD_DEBUG
154#else
156#endif
157 ProcessAdc(nullptr, kTRUE);
158
159 return kBMNSUCCESS;
160}
161
163{
164 const Int_t kNStripsInBunch = GetNSamples();
165 // const Int_t kNBunches = kNStrips / kNStripsInBunch;
166 Int_t kNThresh = 3;
167 // repeat noisy channels in the physical terms (station/module/layer)
168 for (size_t iCr = 0; iCr < GetNSerials(); ++iCr) {
169 for (uint16_t iCh = 0; iCh < GetNChannels(); ++iCh) {
170 auto it = fGlobalMap.find(make_pair(GetSerials()[iCr], iCh));
171 if (it == fGlobalMap.end())
172 continue;
173
174 // InChanMapSiBT & inner = it->second;
175 // auto innerIt = inner.lower_bound(iCh);
176 // if (innerIt == inner.end())
177 // continue;
178 BmnSiBTMapping& rec = it->second;
179 for (Short_t iSmpl = 0; iSmpl < GetNSamples(); ++iSmpl) {
180 if (GetNoisyChipChannels()[iCr][iCh][iSmpl] == kTRUE) {
181 Int_t iStrip = MapStrip(rec, iSmpl);
182 fNoisyChannels[rec.station][rec.module][rec.layer][iStrip] = kTRUE;
183 }
184 }
185 }
186 }
187 // mark noisy
188 for (Int_t iSt = 0; iSt < fSiBTStationSet->GetNStations(); ++iSt) {
189 auto* st = fSiBTStationSet->GetStation(iSt);
190 for (Int_t iMod = 0; iMod < st->GetNModules(); ++iMod) {
191 auto* mod = st->GetModule(iMod);
192 for (Int_t iLay = 0; iLay < mod->GetNStripLayers(); ++iLay) {
193 TH1F* prof = fSigProf[iSt][iMod][iLay];
194 // printf("SigProf %s_%d_%d_%d\n", fDetName.Data(), iSt, iMod, iLay);
195 auto& lay = mod->GetStripLayer(iLay);
196 Int_t kNBunches = lay.GetNStrips() / kNStripsInBunch;
197 for (Int_t iBunch = 0; iBunch < kNBunches; ++iBunch) {
198 Double_t mean = 0.0;
199 for (Int_t iStrip = 0; iStrip < kNStripsInBunch; ++iStrip) {
200 Int_t strip = iStrip + iBunch * kNStripsInBunch;
201 if (fNoisyChannels[iSt][iMod][iLay][strip] == kTRUE)
202 continue;
203 Double_t curr = prof->GetBinContent(strip + 1);
204 // Double_t next = prof->GetBinContent(strip);
205 mean += curr;
206 }
207 mean /= kNStripsInBunch;
208 for (Int_t iStrip = 0; iStrip < kNStripsInBunch; ++iStrip) {
209 Int_t strip = iStrip + iBunch * kNStripsInBunch;
210 if (fNoisyChannels[iSt][iMod][iLay][strip] == kTRUE)
211 continue;
212 Double_t curr = prof->GetBinContent(strip + 1);
213 // Double_t next = prof->GetBinContent(strip);
214 // if (kNThresh * meanDiff < next - curr)
215 if ((kNThresh * Abs(mean) < Abs(curr - mean)) /* || (kNThresh * meanDiff < -next + curr)*/) {
216 LOGF(debug2, "profile noise on iSt %d iMod %d iLay %d strip %d", iSt, iMod, iLay, strip);
217 fNoisyChannels[iSt][iMod][iLay][strip] = kTRUE;
218 }
219 }
220 }
221 }
222 }
223 }
224 // repeat noisy channels back into the electronics terms
225 for (size_t iCr = 0; iCr < GetNSerials(); ++iCr) {
226 for (uint16_t iCh = 0; iCh < GetNChannels(); ++iCh) {
227 auto it = fGlobalMap.find(make_pair(GetSerials()[iCr], iCh));
228 if (it == fGlobalMap.end())
229 continue;
230 BmnSiBTMapping& rec = it->second;
231 for (Short_t iSmpl = 0; iSmpl < GetNSamples(); ++iSmpl) {
232 Int_t iStrip = MapStrip(rec, iSmpl);
233 if (fNoisyChannels[rec.station][rec.module][rec.layer][iStrip] == kTRUE)
234 GetNoisyChipChannels()[iCr][iCh][iSmpl] = kTRUE;
235 }
236 }
237 }
238 return kBMNSUCCESS;
239}
240
242{
243 for (size_t iCr = 0; iCr < GetNSerials(); ++iCr) {
244 for (uint16_t iCh = 0; iCh < GetNChannels(); ++iCh) {
245 auto it = fGlobalMap.find(make_pair(GetSerials()[iCr], iCh));
246 if (it == fGlobalMap.end())
247 continue;
248 // spec threshold
249 Double_t SpecThr(0);
250 auto itThr = fSpecThreshMap.find(make_pair(GetSerials()[iCr], iCh));
251 if (itThr != fSpecThreshMap.end())
252 SpecThr = itThr->second;
253 BmnSiBTMapping& rec = it->second;
254 Short_t station = rec.station;
255 Short_t module = rec.module;
256 Short_t layer = rec.layer;
257 Double_t cs = fCMode[iCr][iCh] - fSMode[iCr][iCh];
258 for (Short_t iSmpl = 0; iSmpl < GetNSamples(); ++iSmpl) {
259 if ((GetNoisyChipChannels()[iCr][iCh][iSmpl]
260 == kTRUE)) ///* || (fPedVal[iCr][iCh][iSmpl] == 0.0)*/) continue;
261 LOGF(debug2, "noisy %4d %4d %4d", iCr, iCh, iSmpl);
262 Int_t strip = MapStrip(rec, iSmpl);
263 // printf("%c layer %d iCh %3d iSmpl %2d, iStrip %2d\n", rec.channel_name, rec.layer,
264 // iCh, iSmpl, strip);
265 Double_t sig = fAdc[iCr][iCh][iSmpl] - fPedVal[iCr][iCh][iSmpl] + cs;
266 if (layer == 1)
267 sig = -sig;
268 // Double_t Asig = TMath::Abs(sig);
269 Double_t thr = (SpecThr > 0) ? SpecThr : FinalThr;
270 thr = Max(thr, 3.5 * GetPedestalsRMS()[iCr][iCh][iSmpl]);
271 if ((!GetApplyThreshold()) || (sig > thr)) {
272 // printf("st %d mod %d l %d strip %d ped %2.3f sig %2.3f thr %2.3f PedestalsRMS
273 // %2.3f\n",
274 // station, module, layer, strip, fPedVal[iCr][iCh][iSmpl], sig, thr,
275 // GetPedestalsRMS()[iCr][iCh][iSmpl]);
276 if (doFill) {
277 fSigProf[station][module][layer]->Fill(strip);
278 } else {
279 BmnSiBTDigit* resDig = new ((*digs)[digs->GetEntriesFast()])
280 BmnSiBTDigit(station, module, layer, strip, sig, GetPedestalsRMS()[iCr][iCh][iSmpl]);
281 resDig->SetIsGoodDigit(kTRUE);
282 }
283 }
284 }
285 }
286 }
287}
bool Bool_t
int Int_t
char Char_t
short Short_t
constexpr Bool_t kFALSE
double Double_t
constexpr Bool_t kTRUE
BmnStatus
Define status code.
Definition BmnEnums.h:93
@ kBMNERROR
Error.
Definition BmnEnums.h:95
@ kBMNSUCCESS
Success.
Definition BmnEnums.h:94
void DeleteStripNoiseArrays(SST &ss)
void InitStripNoiseArrays(SST &ss)
const uint16_t fNSamples
map< PlMapKey, Double_t > fSpecThreshMap
Double_t *** GetPedestalsRMS()
vector< Int_t > StripMap
BmnAdcProcessor(uint32_t period, uint32_t run, TString det, uint16_t nCh, const uint16_t nSmpl, BmnSetup setup=kBMNSETUP)
void SetThreshold(Double_t final_thr, Double_t thr_dif=-1, Double_t n_iters=-1, Double_t cmod_cut=-1)
Float_t *** fPedVal
Bool_t **** fNoisyChannels
void GrabNewSerial(UInt_t serial)
const uint16_t GetNChannels()
const uint16_t GetNSamples()
Bool_t *** GetNoisyChipChannels()
void(BmnAdcProcessor::* PrecalcEventModsImp)(TClonesArray *adc)
vector< uint32_t > & GetSerials()
BmnStatus FillNoisyChannels()
map< Char_t, StripMap > fLocalMaps
BmnStatus ReadLocalMap(string &FileName, StripMap &Strips)
void ProcessAdc(TClonesArray *silicon, Bool_t doFill)
Int_t MapStrip(BmnSiBTMapping &v, Short_t &iSmpl)
BmnSiBTRaw2Digit(Int_t period, Int_t run, TString MapFileName, BmnSetup bmnSetup=kBMNSETUP)
map< UInt_t, InChanMapSiBT > fOuterMap
BmnStatus FillEvent(TClonesArray *adc, TClonesArray *sts)
BmnStatus ReadLocalMaps()
map< PlMapKey, BmnSiBTMapping > fGlobalMap
// serial map
unique_ptr< BmnSiBTStationSet > fSiBTStationSet
BmnStatus FillProfiles(TClonesArray *adc)
void SetIsGoodDigit(Bool_t tmp)
virtual Double_t GetBinContent(Int_t bin) const
Int_t GetEntriesFast() const
const char * Data() const
#define ADC_SIBT_N_SAMPLES
#define ADC_N_CHANNELS
Double_t Abs(Double_t d)
Double_t Max(Double_t a, Double_t b)