175{
176 int indexSciFi{}, indexMuFilter{};
177 bool scifi =
false, mask =
false;
179 TTree* bt;
180 int tofpet_id{}, tofpet_channel{},
tac{}, mat{};
181 string station;
182 double TDC{}, QDC{}, Chi2ndof{}, satur{};
185 high_resolution_clock::time_point tE{},
t0{},
t1{}, t4{}, t5{}, t6{}, tt{};
186 int system{},
key{}, sipmChannel{};
188 int nSiPMs{}, nSides{},
direction{}, detID{}, sipm_number{}, chan{}, orientation{}, sipmLocal{};
189 int sipmID{};
191
192
193 tE = high_resolution_clock::now();
194
196 if ( eventNumber%fheartBeat == 0 )
197 {
198 tt = high_resolution_clock::now();
199 time_t ttp = high_resolution_clock::to_time_t(tt);
201 <<
" local time " <<
ctime(&ttp);
202 }
203
206 LOG (info) <<
"event: " <<
eventNumber <<
" timestamp: "
207 <<
fEventTree->GetLeaf(
"evtTimestamp")->GetValue();
208
210 {
211 delete it.second;
212 }
215 {
216 delete it.second;
217 }
219
220
221 for (
auto board :
boards )
222 {
226 {
228 {
229 station = it.first;
230 mat = it.second;
231 }
232 }
234 else
235 {
236 LOG (error) <<
board.first <<
" not known. Serious error, stop!";
237 break;
238 }
240 bt->GetEvent(eventNumber);
241
242 for (
int n = 0;
n < bt->GetLeaf(
"nHits")->GetValue();
n++ )
243 {
244 mask = false;
245 LOG (info) <<
"In scifi? " <<
scifi
246 <<
" " <<
board_id <<
" " << bt->GetLeaf(
"tofpetId")->GetValue(n)
247 << " " << bt->GetLeaf("tofpetChannel")->GetValue(n)
248 << " " << bt->GetLeaf("tac")->GetValue(n)
249 << " " << bt->GetLeaf("tCoarse")->GetValue(n)
250 << " " << bt->GetLeaf("tFine")->GetValue(n)
251 << " " << bt->GetLeaf("vCoarse")->GetValue(n)
252 << " " << bt->GetLeaf("vFine")->GetValue(n);
253 t0 = high_resolution_clock::now();
254 tofpet_id = bt->GetLeaf("tofpetId")->GetValue(n);
255 tofpet_channel = bt->GetLeaf("tofpetChannel")->GetValue(n);
256 tac = bt->GetLeaf(
"tac")->GetValue(n);
257
258
259 if (makeCalibration)
260 tie(TDC,QDC,Chi2ndof,satur) =
comb_calibration(board_id, tofpet_id, tofpet_channel, tac,
261 bt->GetLeaf("vCoarse")->GetValue(n),
262 bt->GetLeaf("vFine")->GetValue(n),
263 bt->GetLeaf("tCoarse")->GetValue(n),
264 bt->GetLeaf("tFine")->GetValue(n),
265 1.0, 0);
266 else
267 {
268 TDC = bt->GetLeaf("timestamp")->GetValue(n);
269 QDC = bt->GetLeaf("value")->GetValue(n);
270 Chi2ndof =
max(bt->GetLeaf(
"timestampCalChi2")->GetValue(n)/bt->GetLeaf(
"timestampCalDof")->GetValue(n),
271 bt->GetLeaf("valueCalChi2")->GetValue(n)/bt->GetLeaf("valueCalDof")->GetValue(n));
272 satur = bt->GetLeaf("valueSaturation")->GetValue(n);
273 }
274
275
276 if ( TDC != TDC || QDC!=QDC) {
277 LOG (error) << "NAN tdc/qdc detected! Check maps!"
278 <<
" " <<
board_id <<
" " << bt->GetLeaf(
"tofpetId")->GetValue(n)
279 << " " << bt->GetLeaf("tofpetChannel")->GetValue(n)
280 << " " << bt->GetLeaf("tac")->GetValue(n)
281 << " " << bt->GetLeaf("tCoarse")->GetValue(n)
282 << " " << bt->GetLeaf("tFine")->GetValue(n)
283 << " " << bt->GetLeaf("vCoarse")->GetValue(n)
284 << " " << bt->GetLeaf("vFine")->GetValue(n);
285 }
286
287 t1 = high_resolution_clock::now();
288 if ( Chi2ndof > chi2Max )
289 {
290 if (QDC>1E20) QDC = 997.;
291 if (QDC != QDC) QDC = 998.;
292 if (QDC>0) QDC = -QDC;
293 mask = true;
294 }
295 else if (satur > saturationLimit || QDC>1E20 || QDC != QDC)
296 {
297 if (QDC>1E20) QDC = 987.;
298 LOG (info) <<
"inf " <<
board_id <<
" " << bt->GetLeaf(
"tofpetId")->GetValue(n)
299 << " " << bt->GetLeaf("tofpetChannel")->GetValue(n)
300 << " " << bt->GetLeaf("tac")->GetValue(n)
301 << " " << bt->GetLeaf("vCoarse")->GetValue(n)
302 << " " << bt->GetLeaf("vFine")->GetValue(n)
303 << " " << TDC-bt->GetLeaf("tCoarse")->GetValue(n)
305 if (QDC != QDC) QDC = 988.;
306 LOG (info) <<
"nan " <<
board_id <<
" " << bt->GetLeaf(
"tofpetId")->GetValue(n)
307 << " " << bt->GetLeaf("tofpetChannel")->GetValue(n)
308 << " " << bt->GetLeaf("tac")->GetValue(n)
309 << " " << bt->GetLeaf("vCoarse")->GetValue(n)
310 << " " << bt->GetLeaf("vFine")->GetValue(n)
311 << " " << TDC-bt->GetLeaf("tCoarse")->GetValue(n)
312 << " " << TDC << " " << bt->GetLeaf("tCoarse")->GetValue(n)
314 A =
int(min(QDC,
double(1000.)));
315 B = min(satur,
double(999.))/1000.;
317 mask = true;
318 }
319 else if ( Chi2ndof > chi2Max )
320 {
321 if (QDC>0) QDC = -QDC;
322 mask = true;
323 }
324 LOG (info) << "calibrated: tdc = " << TDC << ", qdc = " << QDC;
325 t4 = high_resolution_clock::now();
326
327 counters[
"qdc"]+= duration_cast<nanoseconds>(t1 - t0).count();
328 counters[
"make"]+= duration_cast<nanoseconds>(t4-t0).count();
329
330
331 if (!scifi)
332 {
334 key = (tofpet_id%2)*1000 + tofpet_channel;
336 if (debug || !(
tmp.find(
"not") == string::npos))
337 {
338 LOG (info) << system <<
" " <<
key <<
" " <<
board.first <<
" " << tofpet_id
339 << " " << tofpet_id%2 << " " << tofpet_channel;
340 }
341 sipmChannel = 99;
342 if ( TofpetMap[system].
count(key) == 0)
343 {
344 cout <<
"key " <<
key <<
" does not exist. " << endl
345 <<
board.first <<
" Tofpet id " << tofpet_id
346 << " System " << system << " has Tofpet map elements: {";
348 {
349 cout << it.first << " : " << it.second << ", ";
350 }
351 cout << "}\n";
352 }
354
355 nSiPMs = abs(offMap[tmp][1]);
356 nSides = abs(offMap[tmp][2]);
359 sipm_number = sipmChannel%(nSiPMs);
360 if (
tmp.find(
"Right") != string::npos ) sipm_number+= nSiPMs;
362 {
364 }
367 digiMuFilterStore[detID]->SetDaqID(sipm_number,n, board_id, tofpet_id, tofpet_channel);
369
370 LOG (info) <<
"create mu hit: " << detID <<
" " <<
tmp <<
" " << system
372 <<
" " <<
offMap[
tmp][2] <<
" " << sipmChannel <<
" " << nSiPMs
373 <<
" " << nSides <<
" " <<
test << endl
374 << detID << " " << sipm_number << " " << QDC << " " << TDC;
375
376 if (test>0 || detID%1000>200 || sipm_number>15)
377 {
378 cout << "what goes wrong? " << detID << " SiPM " << sipm_number << " system " << system
379 <<
" key " <<
key <<
" board " <<
board.first <<
" tofperID " << tofpet_id
380 <<
" tofperChannel " << tofpet_channel <<
" test " <<
test << endl;
381 }
382 t5 = high_resolution_clock::now();
383 counters[
"createMufi"]+= duration_cast<nanoseconds>(t5 - t4).count();
384 }
385
386 else
387 {
389 orientation = 1;
390 if (station[2]=='Y') orientation = 0;
391 sipmLocal = (chan - mat*512);
392 sipmID = 1000000*
int(station[1]-
'0') + 100000*orientation + 10000*mat
393 + 1000*(
int(sipmLocal/128)) + chan%128;
395 {
397 }
399 digiSciFiStore[sipmID]->SetDaqID(0,n, board_id, tofpet_id, tofpet_channel);
401 LOG (info) <<
"create scifi hit: tdc = " <<
board.first <<
" " << sipmID
402 << " " << QDC << " " << TDC <<endl
403 << "tofpet:" << " " << tofpet_id << " " << tofpet_channel << " " << mat
404 << " " << chan << endl
405 << station[1] << " " << station[2] << " " << mat << " " << chan
406 <<
" " <<
int(chan/128)%4 <<
" " << chan%128;
407 t5 = high_resolution_clock::now();
408 counters[
"createScifi"]+= duration_cast<nanoseconds>(t5 - t4).count();
409 }
410 }
411 }
412
414 t6 = high_resolution_clock::now();
416 {
418 indexSciFi+= 1;
419 }
421 {
423 indexMuFilter+= 1;
424 }
425 counters[
"storage"]+= duration_cast<nanoseconds>(high_resolution_clock::now() - t6).count();
426 counters[
"event"]+= duration_cast<nanoseconds>(high_resolution_clock::now() - tE).count();
427
428
429
430 LOG (info) <<
fnStart+1 <<
" events processed out of "
431 <<
fEventTree->GetEntries() <<
" number of events in file.";
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447}
std::map< std::string, double > counters
std::tuple< double, double, double, double > comb_calibration(int board_id, int tofpet_id, int channel, int tac, uint16_t v_coarse, uint16_t v_fine, int64_t t_coarse, uint16_t t_fine, double GQDC, int TDC)
std::map< int, MuFilterHit * > digiMuFilterStore
std::map< std::string, TTree * > boards
std::map< int, sndScifiHit * > digiSciFiStore
int channel_func(int tofpet_id, int tofpet_channel, int position)
direction(event)
Event direction cut.