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