4#include <boost/program_options.hpp>
8namespace po = boost::program_options;
12 , fMapFileName(MapFileName)
28 for (
auto& it : fOuterMap)
29 for (
auto& inner : it.second)
38 Short_t chan_shift = 0;
44 vector<string> channel_map;
45 vector<string> spec_thr;
46 Double_t final_thr = 0;
49 Double_t cmod_cut = 0;
52 po::options_description desc(
"Options");
53 desc.add_options()(
"CHANNEL_MAP.channels", po::value<vector<string>>(&channel_map)->multitoken(),
54 "ADC channel -> strip map")(
"SIGNAL_CONFIGURATION.spec_thr",
55 po::value<vector<string>>(&spec_thr)->multitoken(),
56 "ADC channel -> strip map")(
57 "SIGNAL_CONFIGURATION.Threshold", po::value<Double_t>(&final_thr)->default_value(30),
"ADC final threshold")(
58 "SIGNAL_CONFIGURATION.ThresholdDif", po::value<Double_t>(&thr_dif)->default_value(15),
"ADC final threshold")(
59 "SIGNAL_CONFIGURATION.NIterations", po::value<Int_t>(&n_iters)->default_value(5),
"ADC final threshold")(
60 "SIGNAL_CONFIGURATION.CModCut", po::value<Double_t>(&cmod_cut)->default_value(0),
"ADC final threshold");
64 TString name = TString(getenv(
"VMCWORKDIR")) + TString(
"/input/") + fMapFileName;
65 LOG(info) <<
"name " << name;
66 LOG(info) <<
"Loading CSC Map: Period " <<
fPeriod <<
", Run " <<
fRun <<
" " << name;
67 ifstream config_file(name.Data(), ifstream::in);
68 if (!config_file.is_open()) {
69 LOG(error) <<
"Error opening map-file (" << name <<
")!";
72 po::store(po::parse_config_file(config_file, desc), vm);
82 for (
auto& str : spec_thr) {
83 istringstream ss(str);
84 ss >> std::hex >> ser >> std::dec >> ch >>
thr;
86 LOGF(debug,
"Serial 0x%08X Channel %2d Threshold %3.3f", ser, ch,
thr);
90 for (
auto& str : channel_map) {
91 istringstream ss(str);
92 ss >> std::hex >> ser >> std::dec >> ch_lo >> ch_hi >> chan_shift >> station >> mod >> lay >> prefix;
103 auto itLM = fLocalMapsMap.find(make_pair(prefix, mod));
104 if (itLM == fLocalMapsMap.end()) {
105 auto p = fLocalMapsMap.insert(make_pair(make_pair(prefix, mod),
LocalCSC()));
106 p.first->second.shift_map.insert(make_pair(make_pair(mod, lay), chan_shift));
109 lcsc.
shift_map.insert(make_pair(make_pair(mod, lay), chan_shift));
113 auto it = fOuterMap.find(ser);
114 if (it == fOuterMap.end()) {
116 inner.insert(make_pair(record->
channel_low - 1,
nullptr));
118 fOuterMap.insert(make_pair(ser, move(inner)));
122 auto innerItLo = inner.find(record->
channel_low - 1);
123 if (innerItHi == inner.end()) {
126 if (innerItHi->second ==
nullptr) {
127 inner.erase(innerItHi);
135 if (innerItLo == inner.end()) {
136 inner.insert(make_pair(record->
channel_low - 1,
nullptr));
144BmnStatus BmnCscRaw2Digit::ReadLocalMap(
string& FileName, Int_t* Layers, Int_t* Strips, Int_t& iLay, Int_t& ChanShift)
146 ifstream inFile(FileName.data());
147 if (!inFile.is_open()) {
148 cout <<
"Error opening map-file (" << FileName <<
")!" << endl;
153 while (!inFile.eof()) {
157 Int_t chan2048 = chan + ChanShift;
159 Layers[chan2048] = iLay;
160 Strips[chan2048] = iStrip++;
165BmnStatus BmnCscRaw2Digit::ReadLocalMaps()
167 for (
auto& map_el : fLocalMapsMap) {
168 const string& prefix = map_el.first.first;
172 for (
auto& p : info.shift_map) {
173 Int_t iMod = p.first.first;
174 Int_t iLay = p.first.second;
175 Int_t chan_shift = p.second;
176 Int_t written_layer = ((iMod == 1) && (
fPeriod < 8)) ? ((iLay + 2) % 4) : iLay;
177 string map_file_name =
string(getenv(
"VMCWORKDIR")) +
"/input/" +
string(
fDetName.Data()) + prefix +
"m"
181 printf(
"Error reading %s\n", map_file_name.data());
189void BmnCscRaw2Digit::MatchMaps()
191 for (
auto& gl : fOuterMap) {
193 for (
auto& inner : gl.second) {
199 auto lmIt = fLocalMapsMap.find(make_pair(
m->prefix,
m->module));
200 if (lmIt == fLocalMapsMap.end())
202 m->local_map = &(lmIt->second);
215 ProcessAdc(digits, kFALSE);
227 ProcessAdc(
nullptr, kTRUE);
241 if (it == fOuterMap.end())
245 auto innerIt = inner.lower_bound(iCh);
246 if (innerIt == inner.end())
251 for (Int_t iSmpl = 0; iSmpl <
GetNSamples(); ++iSmpl) {
258 MapStrip(rec, iCh, iSmpl, station, module, layer, strip);
266 for (Int_t iSt = 0; iSt < fCscStationSet->GetNStations(); ++iSt) {
267 auto* st = fCscStationSet->GetStation(iSt);
268 for (UInt_t iMod = 0; iMod < (UInt_t)st->GetNModules(); ++iMod) {
269 auto* mod = st->GetModule(iMod);
270 for (Int_t iLay = 0; iLay < mod->GetNStripLayers(); ++iLay) {
271 auto& lay = mod->GetStripLayer(iLay);
272 Int_t kNBunches = lay.GetNStrips() / kNStripsInBunch;
273 TH1F* prof =
fSigProf[iSt][iMod][iLay];
274 for (Int_t iBunch = 0; iBunch < kNBunches; ++iBunch) {
276 for (Int_t iStrip = 0; iStrip < kNStripsInBunch - 1; ++iStrip) {
277 Int_t strip = iStrip + iBunch * kNStripsInBunch;
281 Double_t next = prof->GetBinContent(strip + 1);
284 mean /= kNStripsInBunch;
285 for (Int_t iStrip = 0; iStrip < kNStripsInBunch - 1; ++iStrip) {
286 Int_t strip = iStrip + iBunch * kNStripsInBunch;
290 Double_t next = prof->GetBinContent(strip + 1);
292 if (kNThresh * mean < Abs(next - mean))
301 if (it == fOuterMap.end())
305 auto innerIt = inner.lower_bound(iCh);
306 if (innerIt == inner.end())
311 for (Int_t iSmpl = 0; iSmpl <
GetNSamples(); ++iSmpl) {
316 MapStrip(rec, iCh, iSmpl, station, module, layer, strip);
338 module = cscM->module;
347void BmnCscRaw2Digit::ProcessAdc(TClonesArray* digs, Bool_t doFill)
351 if (it == fOuterMap.end())
354 auto innerIt = it->second.lower_bound(iCh);
355 if (innerIt == it->second.end())
361 for (Int_t iSmpl = 0; iSmpl <
GetNSamples(); ++iSmpl) {
368 SpecThr = itThr->second;
373 MapStrip(rec, iCh, iSmpl, station, module, layer, strip);
383 Double_t sig =
fAdc[iCr][iCh][iSmpl] -
fPedVal[iCr][iCh][iSmpl] + cs;
389 fSigProf[station][module][layer]->Fill(strip);
391 BmnCSCDigit* 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 GrabSerialsFromMap(unordered_map< UInt_t, cl > m)
void InitNoiseArrays(SST &ss)
Bool_t *** GetNoisyChipChannels()
void DeleteNoiseArrays(SST &ss)
void(BmnAdcProcessor::* PrecalcEventModsImp)(TClonesArray *adc)
static unique_ptr< BmnCSCStationSet > Create(Int_t period, Int_t stp=0)
BmnStatus FillNoisyChannels()
BmnCscRaw2Digit(Int_t period, Int_t run, TString MapFileName, BmnSetup bmnSetup=kBMNSETUP)
BmnStatus FillProfiles(TClonesArray *adc)
BmnStatus FillEvent(TClonesArray *adc, TClonesArray *csc)
void SetIsGoodDigit(Bool_t tmp)
map< Int_t, BmnCscMapping * > InChanMapCSC
map< Int_t, BmnCscMapping * > InChanMapCSC
NLOHMANN_BASIC_JSON_TPL_DECLARATION std::string to_string(const NLOHMANN_BASIC_JSON_TPL &j)
user-defined to_string function for JSON values
Short_t Int_t channel_low
map< pair< Short_t, Short_t >, Short_t > shift_map
Int_t channel2layer[N_CSC_CHANNELS]
Int_t channel2strip[N_CSC_CHANNELS]