BmnRoot
Loading...
Searching...
No Matches
BmnProfRaw2Digit.cxx
Go to the documentation of this file.
1#include "BmnProfRaw2Digit.h"
2
5{
6 // fVerbose = 2;
7 cout << "Loading Profilometer Map: Period " << period << ", Run " << run << "..." << endl;
8 string dir = string(getenv("VMCWORKDIR")) + "/input/";
9 fLocalMapFileName = dir + string(Form("Prof_map_run_%d.json", period));
10 fGlobalMapFileName = dir + string(Form("Prof_map_run_%d_global.txt", period));
11 ReadLocalMapFile(fLocalMapFileName);
12 ReadGlobalMapFile(fGlobalMapFileName);
13
14 InitArrays();
15 fSiProfStationSet = GetProfStationSet(period);
16 InitNoiseArrays(fSiProfStationSet);
17 // thrMax = 1200;
18 // thrDif = 100;
19 thrMax = 1250;
20 thrDif = 400;
21 fStartIter = 0;
22 fNIters = 4;
23}
24
29
30unique_ptr<BmnSiProfStationSet> BmnProfRaw2Digit::GetProfStationSet(Int_t period)
31{
32 TString gPathConfig = getenv("VMCWORKDIR");
33 TString xmlConfFileName;
34 switch (period) {
35 case 8:
36 xmlConfFileName = "ProfRun8.xml";
37 break;
38 default:
39 printf("Error! Unknown config!\n");
40 return nullptr;
41 break;
42 }
43 TString gPathSiliconConfig = gPathConfig + "/parameters/profilometer/XMLConfigs/";
44 return std::make_unique<BmnSiProfStationSet>(gPathSiliconConfig + xmlConfFileName);
45}
46
47BmnStatus BmnProfRaw2Digit::ReadGlobalMapFile(string name)
48{
49 string dummy;
50 uint32_t ser = 0;
51 uint16_t ch = 0;
52 uint16_t station = 0;
53 uint16_t mod = 0;
54 uint16_t layer = 0;
55 ifstream inFile(name);
56 if (!inFile.is_open())
57 cout << "Error opening map-file (" << name << ")!" << endl;
58 for (Int_t i = 0; i < 2; ++i)
59 getline(inFile, dummy); // comment line in input file
60 while (!inFile.eof()) {
61 inFile >> std::hex >> ser >> std::dec >> ch >> station >> mod >> layer;
62 if (!inFile.good())
63 break;
64 auto it = fChannelMaps.find(mod);
65 if (it == fChannelMaps.end())
66 continue;
67 auto itLayer = it->second.find(layer);
68 if (itLayer == it->second.end())
69 continue;
70 ProfiLocal& LayerInfo = itLayer->second;
71
72 auto itGlobal = fGlobalMap.find(make_pair(ser, ch));
73 if (itGlobal == fGlobalMap.end()) {
74 auto pair = fGlobalMap.insert(make_pair(make_pair(ser, ch), ProfiInfo{station, mod, &LayerInfo}));
75 GrabNewSerial(ser);
76 itGlobal = pair.first;
77 }
78 if (fVerbose > 1)
79 cout << "ser: " << std::hex << ser << std::dec << " ch: " << ch << endl;
80 }
81 return kBMNSUCCESS;
82}
83
84BmnStatus BmnProfRaw2Digit::ReadLocalMapFile(string name)
85{
86 try {
87 pt::ptree conf;
88 pt::read_json(name, conf);
89 pt::ptree pads = conf.get_child("modules");
90 for (auto v = pads.begin(); v != pads.end(); v++) {
91 // cout << " channels " << (*v).second.get_optional<Int_t>("nAsicChannels") << endl;
92 // cout << " mod " << (*v).second.get_optional<uint16_t>("moduleNumber") << endl;
93 uint8_t mod = (*v).second.get<uint8_t>("moduleNumber");
94 pt::ptree maps = (*v).second.get_child("channelMapping");
95 for (auto m = maps.begin(); m != maps.end(); m++) {
96
97 auto modIter = fChannelMaps.find(mod);
98 if (modIter == fChannelMaps.end()) {
99 if (fVerbose > 0)
100 printf("adding %d to the map\n", mod);
101 auto pair = fChannelMaps.insert(make_pair(mod, LayerIdProfiMap{}));
102 modIter = pair.first;
103 }
104 auto& localMap = modIter->second;
105 ProfiLocal loc{.ChannelName = (*m).second.get<char>("adcChName"),
106 .LayerType = (*m).second.get<char>("layerType")};
107 loc.LayerId = (loc.LayerType == 'p') ? 0 : 1;
108 auto locPair = localMap.insert(make_pair(loc.LayerId, loc));
109 if (fVerbose > 0)
110 printf("adding %d : %d to the map\n", mod, loc.LayerId);
111 auto& stripArray = locPair.first->second.StripMap;
112 pt::ptree strips = (*m).second.get_child("stripsMapping");
113 for (auto stripNode = strips.begin(); stripNode != strips.end(); stripNode++) {
114 auto it = (*stripNode).second.begin();
115 // cout << it->second.get_value<int>() << " : " <<
116 // (++it)->second.get_value<int>()<< endl;
117 int stripId = (it)->second.get_value<int16_t>();
118 int chanlId = (++it)->second.get_value<int16_t>();
119 stripArray[chanlId] = stripId;
120 }
121 }
122 }
123 } catch (boost::exception& e) {
124 cerr << boost::diagnostic_information(e);
125 cout << "Unable to parse the channel map!\n" << endl;
126 return kBMNERROR;
127 }
128 return kBMNSUCCESS;
129}
130
131BmnStatus BmnProfRaw2Digit::FillEvent(TClonesArray* adc, TClonesArray* csc)
132{
133 (this->*PrecalcEventModsImp)(adc);
134#ifdef BUILD_DEBUG
136#else
138#endif
139 ProcessAdc(adc, csc, kFALSE);
140 return kBMNSUCCESS;
141}
142
144{
145 (this->*PrecalcEventModsImp)(adc);
146#ifdef BUILD_DEBUG
148#else
150#endif
151 ProcessAdc(adc, nullptr, kTRUE);
152
153 return kBMNSUCCESS;
154}
155
156void BmnProfRaw2Digit::MapStrip(ProfiInfo& info,
157 uint16_t ch,
158 Int_t iSmpl,
159 uint16_t& station,
160 uint16_t& mod,
161 uint16_t& lay,
162 int16_t& strip)
163{
164 ProfiLocal* layerInfo = info.Layer;
165 station = info.StationId;
166 mod = info.ModuleId;
167 lay = layerInfo->LayerId;
168 strip = layerInfo->StripMap[iSmpl];
169}
170
172{
173 // const Int_t kNStripsInBunch = GetNSamples();
174 // const Int_t kNBunches = kNStrips / kNStripsInBunch;
175 const Int_t kNThresh = 3;
176
177 for (Int_t iCr = 0; iCr < GetNSerials(); ++iCr)
178 for (Int_t iCh = 0; iCh < GetNChannels(); ++iCh) {
179 auto it = fGlobalMap.find(make_pair(GetSerials()[iCr], iCh));
180 if (it == fGlobalMap.end())
181 continue;
182 ProfiInfo& info = it->second;
183 for (Int_t iSmpl = 0; iSmpl < GetNSamples(); ++iSmpl)
184 if (GetNoisyChipChannels()[iCr][iCh][iSmpl] == kTRUE) {
185 uint16_t station = 0;
186 uint16_t module = 0;
187 uint16_t layer = 0;
188 int16_t strip = -1;
189 MapStrip(info, iCh, iSmpl, station, module, layer, strip);
190 if (strip < 0)
191 continue;
192 fNoisyChannels[station][module][layer][strip] = kTRUE;
193 }
194 }
195 for (Int_t iSt = 0; iSt < fSiProfStationSet->GetNStations(); ++iSt) {
196 auto* st = fSiProfStationSet->GetStation(iSt);
197 for (Int_t iMod = 0; iMod < st->GetNModules(); ++iMod) {
198 auto* mod = st->GetModule(iMod);
199 for (Int_t iLay = 0; iLay < mod->GetNStripLayers(); ++iLay) {
200 auto& lay = mod->GetStripLayer(iLay);
201 TH1F* prof = fSigProf[iSt][iMod][iLay];
202 Double_t mean = 0.0;
203 for (Int_t iStrip = 0; iStrip < lay.GetNStrips(); ++iStrip) {
204 if (fNoisyChannels[iSt][iMod][iLay][iStrip] == kTRUE)
205 continue;
206 // Double_t curr = prof->GetBinContent(iStrip);
207 Double_t next = prof->GetBinContent(iStrip + 1);
208 mean += next;
209 }
210 if (mean > 0)
211 mean /= lay.GetNStrips();
212 for (Int_t iStrip = 0; iStrip < lay.GetNStrips(); ++iStrip) {
213 if (fNoisyChannels[iSt][iMod][iLay][iStrip] == kTRUE)
214 continue;
215 // Double_t curr = prof->GetBinContent(iStrip);
216 Double_t next = prof->GetBinContent(iStrip + 1);
217 // if (kNThresh * meanDiff < next - curr)
218 if (kNThresh * mean < Abs(next - mean))
219 fNoisyChannels[iSt][iMod][iLay][iStrip] = kTRUE;
220 }
221 }
222 }
223 }
224 for (Int_t iCr = 0; iCr < GetNSerials(); ++iCr)
225 for (Int_t iCh = 0; iCh < GetNChannels(); ++iCh) {
226 auto it = fGlobalMap.find(make_pair(GetSerials()[iCr], iCh));
227 if (it == fGlobalMap.end())
228 continue;
229 ProfiInfo& info = it->second;
230 for (Int_t iSmpl = 0; iSmpl < GetNSamples(); ++iSmpl)
231 if (GetNoisyChipChannels()[iCr][iCh][iSmpl] == kTRUE) {
232 uint16_t station = 0;
233 uint16_t module = 0;
234 uint16_t layer = 0;
235 int16_t strip = -1;
236 MapStrip(info, iCh, iSmpl, station, module, layer, strip);
237 if (strip < 0)
238 continue;
239 if (fNoisyChannels[station][module][layer][strip] == kTRUE)
240 GetNoisyChipChannels()[iCr][iCh][iSmpl] = kTRUE;
241 }
242 }
243
244 return kBMNSUCCESS;
245}
246
247void BmnProfRaw2Digit::ProcessAdc(TClonesArray* adc, TClonesArray* arr, Bool_t doFill)
248{
249 Double_t FinalThr = thrMax - (fNIters - 1) * thrDif;
250 for (Int_t iCr = 0; iCr < fNSerials; ++iCr) {
251 for (Int_t iCh = 0; iCh < fNChannels; ++iCh) {
252 auto it = fGlobalMap.find(make_pair(GetSerials()[iCr], iCh));
253 if (it == fGlobalMap.end())
254 continue;
255 ProfiInfo& info = it->second;
256 // Double_t cs = fCMode[iCr][iCh] - fSMode[iCr][iCh];
257 for (Int_t iSmpl = 0; iSmpl < GetNSamples(); ++iSmpl) {
258 if (GetNoisyChipChannels()[iCr][iCh][iSmpl] == kTRUE)
259 continue;
260 uint16_t station = 0;
261 uint16_t module = 0;
262 uint16_t layer = 0;
263 int16_t strip = -1;
264 MapStrip(info, iCh, iSmpl, station, module, layer, strip);
265 if (strip < 0)
266 continue;
267 // board1 1200, 1600
268 // board2 1200, 1400
269 // spec threshold
270 Double_t SpecThr(0);
271 if (station == 0) {
272 if (layer == 0)
273 SpecThr = 1200;
274 else
275 SpecThr = 1600;
276 } else {
277 if (layer == 0)
278 SpecThr = 1200;
279 else
280 SpecThr = 1400;
281 }
282 Double_t sig = fAdc[iCr][iCh][iSmpl]; // - fPedVal[iCr][iCh][iSmpl] + cs;
283 // Double_t Asig = TMath::Abs(sig);
284 Double_t thr = Max(SpecThr, Max(FinalThr, 3.5 * GetPedestalsRMS()[iCr][iCh][iSmpl]));
285 if (((sig > thr) && (info.Layer->LayerType == 'p')) || ((sig < -thr) && (info.Layer->LayerType == 'n')))
286 {
287 if (doFill) {
288 fSigProf[station][module][layer]->Fill(strip);
289 } else {
290 // printf("st %d mod %d l %d strip %d ped %2.3f sig %2.3f thr %2.3f \n",
291 // station, module ,layer, strip, fPedVal[iCr][iCh][iSmpl], sig, thr);
292 BmnSiProfDigit* resDig = new ((*arr)[arr->GetEntriesFast()])
293 BmnSiProfDigit(station, module, layer, strip, sig, GetPedestalsRMS()[iCr][iCh][iSmpl]);
294 resDig->SetIsGoodDigit(kTRUE);
295 }
296 }
297 }
298 }
299 }
300}
const float thr
map< uint16_t, ProfiLocal > LayerIdProfiMap
__m128 v
Definition P4_F32vec4.h:1
int i
Definition P4_F32vec4.h:22
__m128 m
Definition P4_F32vec4.h:27
BmnStatus
Definition BmnEnums.h:24
@ kBMNERROR
Definition BmnEnums.h:26
@ kBMNSUCCESS
Definition BmnEnums.h:25
Double_t *** GetPedestalsRMS()
vector< UInt_t > & GetSerials()
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()
static unique_ptr< BmnSiProfStationSet > GetProfStationSet(Int_t period)
BmnStatus FillProfiles(TClonesArray *adc)
BmnProfRaw2Digit(Int_t period, Int_t run)
BmnStatus FillEvent(TClonesArray *adc, TClonesArray *csc)
void SetIsGoodDigit(Bool_t tmp)
#define ADC_PROF_N_CHANNELS
#define ADC32_N_SAMPLES
-clang-format
ProfiLocal * Layer
uint16_t StationId
uint16_t ModuleId
int16_t StripMap[BmnProfRawTools::ChannelCnt()]
uint16_t LayerId