2#include <boost/program_options.hpp>
6namespace po = boost::program_options;
13 fMapFileName = MapFileName;
25 for (
auto& it : fOuterMap)
26 for (
auto& inner : it.second)
32 ifstream inFile(FileName.data());
33 if (!inFile.is_open()) {
34 cout <<
"Error opening map-file (" << FileName <<
")!" << endl;
39 while (!inFile.eof()) {
43 Strips[chan] = iStrip++;
49BmnStatus BmnSiBTRaw2Digit::ReadLocalMaps()
51 for (
auto& map_el : fGlobalMap) {
54 if (it != fLocalMaps.end()) {
55 info.
strips = &(it->second);
57 string map_file_name =
60 LOGF(info,
"Reading: %s", map_file_name.data());
61 ReadLocalMap(map_file_name, strips);
73 Int_t strip_shift = 0;
80 vector<string> channel_map;
81 vector<string> spec_thr;
82 Double_t final_thr = 0;
85 Double_t cmod_cut = 0;
88 po::options_description desc(
"Options");
89 desc.add_options()(
"CHANNEL_MAP.channels", po::value<vector<string>>(&channel_map)->multitoken(),
90 "ADC channel -> strip map")(
"SIGNAL_CONFIGURATION.spec_thr",
91 po::value<vector<string>>(&spec_thr)->multitoken(),
92 "ADC channel -> strip map")(
93 "SIGNAL_CONFIGURATION.Threshold", po::value<Double_t>(&final_thr)->default_value(950),
"ADC final threshold")(
94 "SIGNAL_CONFIGURATION.ThresholdDif", po::value<Double_t>(&thr_dif)->default_value(50),
"ADC final threshold")(
95 "SIGNAL_CONFIGURATION.NIterations", po::value<Int_t>(&n_iters)->default_value(6),
"ADC final threshold")(
96 "SIGNAL_CONFIGURATION.CModCut", po::value<Double_t>(&cmod_cut)->default_value(0),
"ADC final threshold");
100 TString
name = TString(getenv(
"VMCWORKDIR")) + TString(
"/input/") + fMapFileName;
101 LOG(info) <<
"Loading SiBT Map: Period " <<
fPeriod <<
", Run " <<
fRun <<
" " <<
name;
102 ifstream config_file(
name.Data(), ifstream::in);
103 if (!config_file.is_open()) {
104 LOG(error) <<
"Error opening map-file (" <<
name <<
")!";
107 po::store(po::parse_config_file(config_file, desc), vm);
117 for (
auto& str : spec_thr) {
118 istringstream ss(str);
119 ss >> std::hex >> ser >> std::dec >> ch >>
thr;
121 LOGF(debug,
"Serial 0x%08X Channel %2d Threshold %3.3f", ser, ch,
thr);
125 for (
auto& str : channel_map) {
126 istringstream ss(str);
127 ss >> std::hex >> ser >> std::dec >> ch_lo >> strip_shift >> ch_name >> mod >> lay >> station;
132 .strip_shift = strip_shift,
133 .channel_name = ch_name,
135 .strips =
nullptr}));
149 ProcessAdc(digits, kFALSE);
161 ProcessAdc(
nullptr, kTRUE);
174 auto it = fGlobalMap.find(make_pair(
GetSerials()[iCr], iCh));
175 if (it == fGlobalMap.end())
183 for (Short_t iSmpl = 0; iSmpl <
GetNSamples(); ++iSmpl) {
185 Int_t iStrip =
MapStrip(rec, iSmpl);
192 for (Int_t iSt = 0; iSt < fSiBTStationSet->GetNStations(); ++iSt) {
193 auto* st = fSiBTStationSet->GetStation(iSt);
194 for (Int_t iMod = 0; iMod < st->GetNModules(); ++iMod) {
195 auto* mod = st->GetModule(iMod);
196 for (Int_t iLay = 0; iLay < mod->GetNStripLayers(); ++iLay) {
197 TH1F* prof =
fSigProf[iSt][iMod][iLay];
199 auto& lay = mod->GetStripLayer(iLay);
200 Int_t kNBunches = lay.GetNStrips() / kNStripsInBunch;
201 for (Int_t iBunch = 0; iBunch < kNBunches; ++iBunch) {
203 for (Int_t iStrip = 0; iStrip < kNStripsInBunch; ++iStrip) {
204 Int_t strip = iStrip + iBunch * kNStripsInBunch;
207 Double_t curr = prof->GetBinContent(strip + 1);
211 mean /= kNStripsInBunch;
212 for (Int_t iStrip = 0; iStrip < kNStripsInBunch; ++iStrip) {
213 Int_t strip = iStrip + iBunch * kNStripsInBunch;
216 Double_t curr = prof->GetBinContent(strip + 1);
219 if ((kNThresh * Abs(mean) < Abs(curr - mean)) ) {
220 LOGF(debug2,
"profile noise on iSt %d iMod %d iLay %d strip %d", iSt, iMod, iLay, strip);
231 auto it = fGlobalMap.find(make_pair(
GetSerials()[iCr], iCh));
232 if (it == fGlobalMap.end())
235 for (Short_t iSmpl = 0; iSmpl <
GetNSamples(); ++iSmpl) {
236 Int_t iStrip =
MapStrip(rec, iSmpl);
245void BmnSiBTRaw2Digit::ProcessAdc(TClonesArray* digs, Bool_t doFill)
249 auto it = fGlobalMap.find(make_pair(
GetSerials()[iCr], iCh));
250 if (it == fGlobalMap.end())
256 SpecThr = itThr->second;
259 Short_t
module = rec.module;
260 Short_t layer = rec.
layer;
262 for (Short_t iSmpl = 0; iSmpl <
GetNSamples(); ++iSmpl) {
265 LOGF(debug2,
"noisy %4d %4d %4d", iCr, iCh, iSmpl);
269 Double_t sig =
fAdc[iCr][iCh][iSmpl] -
fPedVal[iCr][iCh][iSmpl] + cs;
281 fSigProf[station][module][layer]->Fill(strip);
283 BmnSiBTDigit* resDig =
new ((*digs)[digs->GetEntriesFast()])
int MapStrip(size_t &iChar, size_t &iCh)
map< PlMapKey, Double_t > fSpecThreshMap
Double_t *** GetPedestalsRMS()
void CalcEventMods_simd()
vector< UInt_t > & GetSerials()
void SetThreshold(Double_t final_thr, Double_t thr_dif=-1, Double_t n_iters=-1, Double_t cmod_cut=-1)
Bool_t **** fNoisyChannels
void GrabNewSerial(UInt_t serial)
void InitNoiseArrays(SST &ss)
Bool_t *** GetNoisyChipChannels()
void DeleteNoiseArrays(SST &ss)
void(BmnAdcProcessor::* PrecalcEventModsImp)(TClonesArray *adc)
BmnStatus FillNoisyChannels()
BmnSiBTRaw2Digit(Int_t period, Int_t run, TString MapFileName, BmnSetup bmnSetup=kBMNSETUP)
BmnStatus FillEvent(TClonesArray *adc, TClonesArray *sts)
virtual ~BmnSiBTRaw2Digit()
BmnStatus FillProfiles(TClonesArray *adc)
static unique_ptr< BmnSiBTStationSet > Create(Int_t period, Int_t stp=0)
void SetIsGoodDigit(Bool_t tmp)
#define ADC_SIBT_N_SAMPLES