4#include <boost/program_options.hpp>
8#include <UniDetectorParameter.h>
10namespace po = boost::program_options;
16 , fMapFileName(mapFileName)
19 ReadGlobalMap(fMapFileName);
25 for (Byte_t
i = 0;
i < nMods;
i++) {
31 ReadLocalMap(
"X0_Bottom_Left.txt", fBigHot[2], 2, 2);
32 ReadLocalMap(
"X0_Bottom_Right.txt", fBigHot[3], 2, 3);
33 ReadLocalMap(
"X_Bottom_Left.txt", fBig[2], 0, 2);
34 ReadLocalMap(
"X_Bottom_Right.txt", fBig[3], 0, 3);
35 ReadLocalMap(
"Y0_Bottom_Left.txt", fBigHot[2], 3, 2);
36 ReadLocalMap(
"Y0_Bottom_Right.txt", fBigHot[3], 3, 3);
37 ReadLocalMap(
"Y_Bottom_Left.txt", fBig[2], 1, 2);
38 ReadLocalMap(
"Y_Bottom_Right.txt", fBig[3], 1, 3);
40 ReadLocalMap(
"X0_Top_Left.txt", fBigHot[0], 2, 0);
41 ReadLocalMap(
"X0_Top_Right.txt", fBigHot[1], 2, 1);
42 ReadLocalMap(
"X_Top_Left.txt", fBig[0], 0, 0);
43 ReadLocalMap(
"X_Top_Right.txt", fBig[1], 0, 1);
44 ReadLocalMap(
"Y0_Top_Left.txt", fBigHot[0], 3, 0);
45 ReadLocalMap(
"Y0_Top_Right.txt", fBigHot[1], 3, 1);
46 ReadLocalMap(
"Y_Top_Left.txt", fBig[0], 1, 0);
47 ReadLocalMap(
"Y_Top_Right.txt", fBig[1], 1, 1);
49 ReadMap(
"GEM_X0_middle", fMid, 2, 0);
50 ReadMap(
"GEM_Y0_middle", fMid, 3, 0);
51 ReadMap(
"GEM_X1_middle", fMid, 0, 0);
52 ReadMap(
"GEM_Y1_middle", fMid, 1, 0);
54 ReadMap(
"GEM_X0_Big_Left", fBigHot[1], 2, 1);
55 ReadMap(
"GEM_Y0_Big_Left", fBigHot[1], 3, 1);
56 ReadMap(
"GEM_X1_Big_Left", fBig[1], 0, 1);
57 ReadMap(
"GEM_Y1_Big_Left", fBig[1], 1, 1);
58 ReadMap(
"GEM_X0_Big_Right", fBigHot[0], 2, 0);
59 ReadMap(
"GEM_Y0_Big_Right", fBigHot[0], 3, 0);
60 ReadMap(
"GEM_X1_Big_Right", fBig[0], 0, 0);
61 ReadMap(
"GEM_Y1_Big_Right", fBig[0], 1, 0);
63 ReadLocalMap(
"GEM_X_small.txt", fSmall, 0, 0);
64 ReadLocalMap(
"GEM_Y_small.txt", fSmall, 1, 0);
70BmnStatus BmnGemRaw2Digit::ReadGlobalMap(TString FileName)
83 vector<string> channel_map;
84 vector<string> spec_thr;
85 Double_t final_thr = 0;
88 Double_t cmod_cut = 0;
91 po::options_description desc(
"Options");
92 desc.add_options()(
"CHANNEL_MAP.channels", po::value<vector<string>>(&channel_map)->multitoken(),
93 "ADC channel -> strip map")(
"SIGNAL_CONFIGURATION.spec_thr",
94 po::value<vector<string>>(&spec_thr)->multitoken(),
95 "ADC channel -> strip map")(
96 "SIGNAL_CONFIGURATION.Threshold", po::value<Double_t>(&final_thr)->default_value(25),
"ADC final threshold")(
97 "SIGNAL_CONFIGURATION.ThresholdDif", po::value<Double_t>(&thr_dif)->default_value(10),
"ADC final threshold")(
98 "SIGNAL_CONFIGURATION.NIterations", po::value<Int_t>(&n_iters)->default_value(5),
"ADC final threshold")(
99 "SIGNAL_CONFIGURATION.CModCut", po::value<Double_t>(&cmod_cut)->default_value(0),
"ADC final threshold");
102 po::variables_map vm;
103 TString name = TString(getenv(
"VMCWORKDIR")) + TString(
"/input/") + fMapFileName;
104 LOG(info) <<
"Loading GEM Map: Period " <<
fPeriod <<
", Run " <<
fRun <<
" " << name;
105 ifstream config_file(name.Data(), ifstream::in);
106 if (!config_file.is_open()) {
107 LOG(error) <<
"Error opening map-file (" << name <<
")!";
110 po::store(po::parse_config_file(config_file, desc), vm);
120 for (
auto& str : spec_thr) {
121 istringstream ss(str);
122 ss >> std::hex >> ser >> std::dec >> ch >>
thr;
124 LOGF(debug,
"Serial 0x%08X Channel %2d Threshold %3.3f", ser, ch,
thr);
128 for (
auto& str : channel_map) {
129 istringstream ss(str);
130 ss >> std::hex >> ser >> std::dec >> ch_lo >> ch_hi >>
id >> side >>
type >> station >> mod >> zone;
141 fMap.push_back(record);
147BmnStatus BmnGemRaw2Digit::ReadLocalMap(TString FileName,
BmnGemMap*
m, Int_t lay, Int_t mod)
149 TString
name = TString(getenv(
"VMCWORKDIR")) + TString(
"/input/") + FileName;
151 ifstream inFile(
name.Data());
152 if (!inFile.is_open()) {
153 LOG(error) <<
"Error opening map-file (" <<
name <<
")!";
158 while (!inFile.eof()) {
172 vector<UniValue*> iiArr;
177 for (
size_t i = 0;
i < iiArr.size(); ++
i) {
185 for (
size_t i = 0;
i < iiArr.size();
i++)
196 for (
size_t i = 0;
i < fBig.size();
i++) {
201 for (
size_t i = 0;
i < fMap.size();
i++)
214 ProcessAdc(
nullptr, kTRUE);
227 for (
auto& it : fMap)
228 if ((Int_t)
GetSerials()[iCr] == it->Serial && iCh >= it->Ch_lo && iCh <= it->Ch_hi) {
229 for (Int_t iSmpl = 0; iSmpl <
GetNSamples(); ++iSmpl)
235 MapStrip(it, iCh, iSmpl, station, mod, layer, strip);
241 for (Int_t iSt = 0; iSt < fGemStationSet->GetNStations(); ++iSt) {
242 if ((iSt == 7) && (
fPeriod == 9))
244 auto* st = fGemStationSet->GetStation(iSt);
245 for (Int_t iMod = 0; iMod < st->GetNModules(); ++iMod) {
246 auto* mod = st->GetModule(iMod);
247 for (Int_t iLay = 0; iLay < mod->GetNStripLayers(); ++iLay) {
248 TH1F* prof =
fSigProf[iSt][iMod][iLay];
249 auto& lay = mod->GetStripLayer(iLay);
250 Int_t kNBunches = lay.GetNStrips() / kNStripsInBunch;
251 for (Int_t iBunch = 0; iBunch < kNBunches; ++iBunch) {
253 for (Int_t iStrip = 0; iStrip < kNStripsInBunch; ++iStrip) {
254 Int_t strip = iStrip + iBunch * kNStripsInBunch;
257 Double_t curr = prof->GetBinContent(strip + 1);
261 mean /= kNStripsInBunch;
262 for (Int_t iStrip = 0; iStrip < kNStripsInBunch; ++iStrip) {
263 Int_t strip = iStrip + iBunch * kNStripsInBunch;
266 Double_t curr = prof->GetBinContent(strip + 1);
269 if (kNThresh * mean < Abs(curr - mean))
278 for (
auto& it : fMap)
279 if ((Int_t)
GetSerials()[iCr] == it->Serial && iCh >= it->Ch_lo && iCh <= it->Ch_hi)
280 for (Int_t iSmpl = 0; iSmpl <
GetNSamples(); ++iSmpl) {
285 MapStrip(it, iCh, iSmpl, station, mod, lay, strip);
295void BmnGemRaw2Digit::ProcessAdc(TClonesArray* gem, Bool_t doFill)
297 for (Int_t iCr = 0; iCr <
fNSerials; ++iCr) {
298 for (Int_t iCh = 0; iCh <
fNChannels; ++iCh) {
299 for (
auto& it : fMap) {
301 if ((Int_t)
GetSerials()[iCr] == it->Serial && iCh >= it->Ch_lo && iCh <= it->Ch_hi) {
302 for (Int_t iSmpl = 0; iSmpl <
GetNSamples(); ++iSmpl) {
310 MapStrip(it, iCh, iSmpl, station, mod, layer, strip);
321 SpecThr = itThr->second;
327 fSigProf[station][mod][layer]->Fill(strip);
354 ProcessAdc(gem, kFALSE);
358inline void BmnGemRaw2Digit::MapStrip(
GemMapLine* gemM,
367 UInt_t realChannel = ch2048;
370 UInt_t side = gemM->
Side;
375 Int_t chShift = -512;
376 realChannel += chShift;
384 if (gemM->
Zone == 0) {
385 Int_t chShift = (gemM->
Ch_lo == 0) ? 0 : -1024;
390 realChannel += chShift;
391 fBigMap = fBigHot[side];
393 fBigMap = fBig[side];
399 lay = fBigMap[realChannel].
lay;
400 strip = fBigMap[realChannel].
strip;
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 FillEvent(TClonesArray *adc, TClonesArray *gem)
BmnGemRaw2Digit(Int_t period, Int_t run, TString mapFileName, BmnSetup bmnSetup=kBMNSETUP)
BmnStatus FillNoisyChannels()
BmnStatus FillProfiles(TClonesArray *adc)
static unique_ptr< BmnGemStripStationSet > Create(Int_t period, Int_t stp=0)
void SetIsGoodDigit(Bool_t tmp)
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