5#include <boost/program_options.hpp>
7#include <BmnADCDigit.h>
8#include <BmnGemStripDigit.h>
10#include <UniDetectorParameter.h>
12namespace po = boost::program_options;
67 for (int32_t iSt = 0; iSt < ss->GetNStations(); ++iSt) {
68 auto* st = ss->GetStation(iSt);
69 for (int32_t iMod = 0; iMod < st->GetNModules(); ++iMod) {
70 auto* mod = st->GetModule(iMod);
72 for (int32_t iLay = 0; iLay < mod->GetNStripLayers(); ++iLay) {
73 auto& lay = mod->GetStripLayer(iLay);
74 layer2MaxStrip[iLay] = lay.GetNStrips() - 1;
94 vector<string> channel_map;
95 vector<string> spec_thr;
102 po::options_description desc(
"Options");
103 desc.add_options()(
"CHANNEL_MAP.channels", po::value<vector<string>>(&channel_map)->multitoken(),
104 "ADC channel -> strip map")(
"SIGNAL_CONFIGURATION.spec_thr",
105 po::value<vector<string>>(&spec_thr)->multitoken(),
106 "ADC channel -> strip map")(
107 "SIGNAL_CONFIGURATION.Threshold", po::value<Double_t>(&final_thr)->default_value(25),
"ADC final threshold")(
108 "SIGNAL_CONFIGURATION.ThresholdDif", po::value<Double_t>(&thr_dif)->default_value(10),
"ADC final threshold")(
109 "SIGNAL_CONFIGURATION.NIterations", po::value<Int_t>(&n_iters)->default_value(5),
"ADC final threshold")(
110 "SIGNAL_CONFIGURATION.CModCut", po::value<Double_t>(&cmod_cut)->default_value(0),
"ADC final threshold");
113 po::variables_map vm;
115 LOG(info) <<
"Loading GEM Map: Period " <<
fPeriod <<
", Run " <<
fRun <<
" " << name;
116 ifstream config_file(name.
Data(), ifstream::in);
117 if (!config_file.is_open()) {
118 LOG(error) <<
"Error opening map-file (" << name <<
")!";
121 po::store(po::parse_config_file(config_file, desc), vm);
131 for (
auto& str : spec_thr) {
132 istringstream ss(str);
133 ss >> std::hex >> ser >> std::dec >> ch >> thr;
135 LOGF(debug,
"Serial 0x%08X Channel %2d Threshold %3.3f", ser, ch, thr);
139 for (
auto& str : channel_map) {
140 istringstream ss(str);
141 ss >> std::hex >> ser >> std::dec >> ch_lo >> ch_hi >>
id >> side >> type >> iStation >> iMod >> zone;
165 if (record->
Zone == 0) {
182 inner.insert(make_pair(record->
Ch_lo - 1,
nullptr));
183 inner.insert(make_pair(record->
Ch_hi, record));
184 fOuterMap.insert(make_pair(ser, move(inner)));
187 auto innerItHi = inner.find(record->
Ch_hi);
188 auto innerItLo = inner.find(record->
Ch_lo - 1);
189 if (innerItHi == inner.end())
190 inner.insert(make_pair(record->
Ch_hi, record));
191 else if (innerItHi->second ==
nullptr) {
192 inner.erase(innerItHi);
193 inner.insert(make_pair(record->
Ch_hi, record));
195 fprintf(stderr,
"Wrong %s map! Overlapping intervals for %08X!\n",
fDetName.Data(), ser);
198 if (innerItLo == inner.end())
199 inner.insert(make_pair(record->
Ch_lo - 1,
nullptr));
209 ifstream inFile(name.
Data());
210 if (!inFile.is_open()) {
211 LOG(error) <<
"Error opening map-file (" << name <<
")!";
217 while (inFile >> chan) {
229 vector<UniValue*> iiArr;
234 for (
size_t i = 0;
i < iiArr.size(); ++
i) {
242 for (
size_t i = 0;
i < iiArr.size();
i++)
250 for (
auto& inner : it.second)
280 auto innerIt = inner.lower_bound(iCh);
281 if (innerIt == inner.end())
293 MapStrip(rec, iCh, iSmpl, iLayer, strip);
297 if (strip > layer2MaxStrip[iLayer]) {
299 "fNoisyChannels strip outside range!\n\t"
300 " Station: %d, Module: %2d, Layer: %2d iStrip: %d set true",
301 iStation, iMod, iLayer, strip);
302 LOGF(debug2,
"lay : [%3d, %3d]", 0, layer2MaxStrip[iLayer]);
310 LOGF(debug,
"Chip noise channels to strip finished");
312 if ((iSt == 7) && (
fPeriod == 9))
315 for (
Int_t iMod = 0; iMod < st->GetNModules(); ++iMod) {
316 auto* mod = st->GetModule(iMod);
317 for (
Int_t iLay = 0; iLay < mod->GetNStripLayers(); ++iLay) {
319 auto& lay = mod->GetStripLayer(iLay);
320 Int_t kNBunches = lay.GetNStrips() / kNStripsInBunch;
321 for (
Int_t iBunch = 0; iBunch < kNBunches; ++iBunch) {
323 for (
Int_t iStrip = 0; iStrip < kNStripsInBunch; ++iStrip) {
324 Int_t strip = iStrip + iBunch * kNStripsInBunch;
331 mean /= kNStripsInBunch;
332 for (
Int_t iStrip = 0; iStrip < kNStripsInBunch; ++iStrip) {
333 Int_t strip = iStrip + iBunch * kNStripsInBunch;
339 if (kNThresh * mean <
Abs(curr - mean))
346 LOGF(debug,
"Marking noisy strips finished");
353 auto innerIt = inner.lower_bound(iCh);
354 if (innerIt == inner.end())
365 MapStrip(rec, iCh, iSmpl, iLayer, strip);
369 if (strip > layer2MaxStrip[iLayer]) {
371 "fNoisyChannels strip outside range!\n\t"
372 " Station: %d, Module: %2d, Layer: %2d iStrip: %d set true back",
373 iStation, iMod, iLayer, strip);
374 LOGF(debug2,
"lay : [%3d, %3d]", 0, layer2MaxStrip[iLayer]);
382 LOGF(debug,
"noisy strips to chips finished");
393 for (uint16_t iCh = 0; iCh <
fNChannels; ++iCh) {
394 auto innerIt = it->second.lower_bound(iCh);
395 if (innerIt == it->second.end())
408 MapStrip(rec, iCh, iSmpl, iLayer, strip);
410 if ((strip < 0) || (strip > layer2MaxStrip[iLayer])) {
412 "fNoisyChannels strip outside range!\n\t"
413 " Station: %d, Module: %2d, Layer: %2d iStrip: %d digi add",
414 iStation, iMod, iLayer, strip);
415 LOGF(debug2,
"info : [%3d, %3d]", 0, layer2MaxStrip[iLayer]);
424 SpecThr = itThr->second;
427 thr =
Max(thr, SpecThr);
430 fSigProf[iStation][iMod][iLayer]->Fill(strip);
BmnStatus
Define status code.
void DeleteStripNoiseArrays(SST &ss)
void InitStripNoiseArrays(SST &ss)
map< PlMapKey, Double_t > fSpecThreshMap
Double_t *** GetPedestalsRMS()
void CalcEventMods_simd()
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)
Bool_t **** fNoisyChannels
const uint16_t fNChannels
void GrabNewSerial(UInt_t serial)
const uint16_t GetNChannels()
void InitChipNoiseArrays()
const uint16_t GetNSamples()
Bool_t *** GetNoisyChipChannels()
void(BmnAdcProcessor::* PrecalcEventModsImp)(TClonesArray *adc)
vector< uint32_t > & GetSerials()
std::array< BmnGemMap, N_CH_BUF > StripMapArray
map< uint8_t, int32_t > MapLayer2MaxStrip
map< int32_t, GemMapLine * > InChanMap
void ProcessAdc(TClonesArray *silicon, Bool_t doFill)
Uses raw ADC data to either fill profile histograms or produce output digits.
BmnStatus FillEvent(TClonesArray *adc, TClonesArray *gem)
BmnGemRaw2Digit(Int_t period, Int_t run, TString mapFileName, BmnSetup bmnSetup=kBMNSETUP)
BmnStatus ReadGlobalMap(TString FileName)
void MapStrip(GemMapLine *gemM, UInt_t ch, Int_t iSmpl, Int_t &lay, Int_t &strip)
vector< StripMapArray > fBig
vector< StripMapArray > fBigHot
BmnStatus FillNoisyChannels()
BmnStatus ReadMap(TString parName, StripMapArray &m, Int_t lay, Int_t mod)
unordered_map< uint32_t, InChanMap > fOuterMap
BmnStatus ReadLocalMap(TString parName, StripMapArray &m, Int_t lay, Int_t mod)
BmnStatus FillProfiles(TClonesArray *adc)
map< KeySM, MapLayer2MaxStrip > fSM2MapMaxStrip
unique_ptr< BmnGemStripStationSet > fGemStationSet
void InitStripRanges(unique_ptr< BmnGemStripStationSet > &ss)
void SetIsGoodDigit(Bool_t tmp)
virtual Double_t GetBinContent(Int_t bin) const
Int_t GetEntriesFast() const
const char * Data() const
int GetValue(vector< UniValue * > ¶meter_value)
get value of detector parameter presented by an array
static UniDetectorParameter * GetDetectorParameter(int value_id)
get detector parameter from the database
Double_t Max(Double_t a, Double_t b)
StripMapArray * Map_arr_ptr