62 FairRootManager* ioman = FairRootManager::Instance();
64 LOG (error) <<
"-E- ConvRawData::Init: "
65 <<
"RootManager not instantiated!";
70 TObjString* runN_obj =
dynamic_cast<TObjString*
>(ioman->GetObject(
"runN"));
71 TObjString* pathCalib_obj =
dynamic_cast<TObjString*
>(ioman->GetObject(
"pathCalib"));
72 TObjString* pathJSON_obj =
dynamic_cast<TObjString*
>(ioman->GetObject(
"pathJSON"));
73 TObjString* nEvents_obj =
dynamic_cast<TObjString*
>(ioman->GetObject(
"nEvents"));
74 TObjString* nStart_obj =
dynamic_cast<TObjString*
>(ioman->GetObject(
"nStart"));
75 TObjString* debug_obj =
dynamic_cast<TObjString*
>(ioman->GetObject(
"debug"));
76 TObjString* stop_obj =
dynamic_cast<TObjString*
>(ioman->GetObject(
"stop"));
77 TObjString* heartBeat_obj =
dynamic_cast<TObjString*
>(ioman->GetObject(
"heartBeat"));
78 TObjString* makeCalibration_obj =
dynamic_cast<TObjString*
>(ioman->GetObject(
"makeCalibration"));
79 TObjString* chi2Max_obj =
dynamic_cast<TObjString*
>(ioman->GetObject(
"chi2Max"));
80 TObjString* saturationLimit_obj =
dynamic_cast<TObjString*
>(ioman->GetObject(
"saturationLimit"));
81 TObjString* newFormat_obj =
dynamic_cast<TObjString*
>(ioman->GetObject(
"newFormat"));
82 TObjString* local_obj =
dynamic_cast<TObjString*
>(ioman->GetObject(
"local"));
84 FSmap =
static_cast<TMap*
>(ioman->GetObject(
"FSmap"));
87 TFile* f0 =
dynamic_cast<TFile*
>(ioman->GetObject(
"rawData"));
89 std::istringstream(runN_obj->GetString().Data()) >>
frunNumber;
90 fpathCalib = pathCalib_obj->GetString().Data();
91 fpathJSON = pathJSON_obj->GetString().Data();
92 std::istringstream(nEvents_obj->GetString().Data()) >>
fnEvents;
93 std::istringstream(nStart_obj->GetString().Data()) >>
fnStart;
94 std::istringstream(debug_obj->GetString().Data()) >>
debug;
95 std::istringstream(stop_obj->GetString().Data()) >>
stop;
96 std::istringstream(heartBeat_obj->GetString().Data()) >>
fheartBeat;
97 std::istringstream(makeCalibration_obj->GetString().Data()) >>
makeCalibration;
98 std::istringstream(chi2Max_obj->GetString().Data()) >>
chi2Max;
99 std::istringstream(saturationLimit_obj->GetString().Data()) >>
saturationLimit;
100 std::istringstream(newFormat_obj->GetString().Data()) >>
newFormat;
101 std::istringstream(local_obj->GetString().Data()) >>
local;
107 TIter next(f0->GetListOfKeys());
108 TKey *b =
new TKey();
110 while ((b = (TKey*)next()))
114 if ( name.find(
"board") == string::npos )
continue;
115 boards[name] = (TTree*)f0->Get(name.c_str());
119 ioman->Register(
"EventHeader",
"sndEventHeader",
fEventHeader, kTRUE);
130 ioman->Register(
"Digi_ScifiHits",
"DigiScifiHit_det",
fDigiSciFi, kTRUE);
132 ioman->Register(
"Digi_MuFilterHits",
"DigiMuFilterHit_det",
fDigiMuFilter, kTRUE);
133 ScifiDet =
dynamic_cast<Scifi*
> (gROOT->GetListOfGlobals()->FindObject(
"Scifi") );
138 LOG (info) <<
"Time to read CSV " << timerCSV.RealTime();
141 TStopwatch timerBMap;
146 LOG (info) <<
"Time to set the board mapping " << timerBMap.RealTime();
176 int indexSciFi{}, indexMuFilter{};
177 bool scifi =
false, mask =
false;
180 int tofpet_id{}, tofpet_channel{}, tac{}, mat{};
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{};
193 tE = high_resolution_clock::now();
198 tt = high_resolution_clock::now();
199 time_t ttp = high_resolution_clock::to_time_t(tt);
201 <<
" local time " << ctime(&ttp);
206 LOG (info) <<
"event: " <<
eventNumber <<
" timestamp: "
207 <<
fEventTree->GetLeaf(
"evtTimestamp")->GetValue();
221 for (
auto board :
boards )
223 board_id = stoi(board.first.substr(board.first.find(
"_")+1));
225 if (
boardMaps[
"Scifi"].count(board.first)!=0)
227 for (
auto it :
boardMaps[
"Scifi"][board.first])
233 else if (
boardMaps[
"MuFilter"].count(board.first)!=0) scifi =
false;
236 LOG (error) << board.first <<
" not known. Serious error, stop!";
242 for (
int n = 0; n < bt->GetLeaf(
"nHits")->GetValue(); n++ )
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);
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),
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);
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);
287 t1 = high_resolution_clock::now();
290 if (QDC>1E20) QDC = 997.;
291 if (QDC != QDC) QDC = 998.;
292 if (QDC>0) QDC = -QDC;
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.;
321 if (QDC>0) QDC = -QDC;
324 LOG (info) <<
"calibrated: tdc = " << TDC <<
", qdc = " << QDC;
325 t4 = high_resolution_clock::now();
327 counters[
"qdc"]+= duration_cast<nanoseconds>(t1 - t0).count();
328 counters[
"make"]+= duration_cast<nanoseconds>(t4-t0).count();
334 key = (tofpet_id%2)*1000 + tofpet_channel;
337 if (tmp ==
"DS_5Vert")
continue;
338 if (
debug || !(tmp.find(
"not") == string::npos))
340 LOG (info) << system <<
" " << key <<
" " << board.first <<
" " << tofpet_id
341 <<
" " << tofpet_id%2 <<
" " << tofpet_channel;
346 cout <<
"key " << key <<
" does not exist. " << endl
347 << board.first <<
" Tofpet id " << tofpet_id
348 <<
" System " << system <<
" has Tofpet map elements: {";
351 cout << it.first <<
" : " << it.second <<
", ";
355 else sipmChannel =
TofpetMap[system][key]-1;
357 nSiPMs = abs(
offMap[tmp][1]);
358 nSides = abs(
offMap[tmp][2]);
359 direction = int(
offMap[tmp][1]/nSiPMs);
360 detID =
offMap[tmp][0] + direction*int(sipmChannel/nSiPMs);
361 sipm_number = sipmChannel%(nSiPMs);
362 if ( tmp.find(
"Right") != string::npos ) sipm_number+= nSiPMs;
369 digiMuFilterStore[detID]->SetDaqID(sipm_number,n, board_id, tofpet_id, tofpet_channel);
372 LOG (info) <<
"create mu hit: " << detID <<
" " << tmp <<
" " << system
373 <<
" " << tofpet_id <<
" " <<
offMap[tmp][0] <<
" " <<
offMap[tmp][1]
374 <<
" " <<
offMap[tmp][2] <<
" " << sipmChannel <<
" " << nSiPMs
375 <<
" " << nSides <<
" " << test << endl
376 << detID <<
" " << sipm_number <<
" " << QDC <<
" " << TDC;
378 if (test>0 || detID%1000>200 || sipm_number>15)
380 cout <<
"what goes wrong? " << detID <<
" SiPM " << sipm_number <<
" system " << system
381 <<
" key " << key <<
" board " << board.first <<
" tofperID " << tofpet_id
382 <<
" tofperChannel " << tofpet_channel <<
" test " << test << endl;
384 t5 = high_resolution_clock::now();
385 counters[
"createMufi"]+= duration_cast<nanoseconds>(t5 - t4).count();
392 if (station[2]==
'Y') orientation = 0;
393 sipmLocal = (chan - mat*512);
394 sipmID = 1000000*int(station[1]-
'0') + 100000*orientation + 10000*mat
395 + 1000*(int(sipmLocal/128)) + chan%128;
401 digiSciFiStore[sipmID]->SetDaqID(0,n, board_id, tofpet_id, tofpet_channel);
403 LOG (info) <<
"create scifi hit: tdc = " << board.first <<
" " << sipmID
404 <<
" " << QDC <<
" " << TDC <<endl
405 <<
"tofpet:" <<
" " << tofpet_id <<
" " << tofpet_channel <<
" " << mat
406 <<
" " << chan << endl
407 << station[1] <<
" " << station[2] <<
" " << mat <<
" " << chan
408 <<
" " << int(chan/128)%4 <<
" " << chan%128;
409 t5 = high_resolution_clock::now();
410 counters[
"createScifi"]+= duration_cast<nanoseconds>(t5 - t4).count();
416 t6 = high_resolution_clock::now();
427 counters[
"storage"]+= duration_cast<nanoseconds>(high_resolution_clock::now() - t6).count();
428 counters[
"event"]+= duration_cast<nanoseconds>(high_resolution_clock::now() - tE).count();
432 LOG (info) <<
fnStart+1 <<
" events processed out of "
433 <<
fEventTree->GetEntries() <<
" number of events in file.";
453 int indexSciFi{}, indexMuFilter{};
454 bool scifi =
false, mask =
false;
457 int tofpet_id{}, tofpet_channel{}, tac{}, mat{};
459 double TDC{}, QDC{}, Chi2ndof{}, satur{};
462 high_resolution_clock::time_point tE{}, t0{}, t1{}, t4{}, t5{}, t6{}, tt{};
463 int system{}, key{}, sipmChannel{};
465 int nSiPMs{}, nSides{}, direction{}, detID{}, sipm_number{}, chan{}, orientation{}, sipmLocal{};
471 tE = high_resolution_clock::now();
476 tt = high_resolution_clock::now();
477 time_t ttp = high_resolution_clock::to_time_t(tt);
479 <<
" local time " << ctime(&ttp);
484 eventTime =
fEventTree->GetLeaf(
"evtTimestamp")->GetValue();
489 if (
FSmap->GetEntries()>1){
493 int((eventTime%(4*3564))/8+0.5))))->GetString().Data()));
498 int((eventTime%(4*3564))/4))))->GetString().Data()));
504 LOG (info) <<
"evtNumber per run "
505 <<
fEventTree->GetLeaf(
"evtNumber")->GetValue()
507 <<
" timestamp: " << eventTime;
521 for (
int n =0; n <
fEventTree->GetLeaf(
"nHits")->GetValue(); n++ )
523 board_id =
fEventTree->GetLeaf(
"boardId")->GetValue(n);
524 board_name =
"board_"+to_string(board_id);
526 if (
boardMaps[
"Scifi"].count(board_name)!=0)
528 for (
auto it :
boardMaps[
"Scifi"][board_name])
534 else if (
boardMaps[
"MuFilter"].count(board_name)!=0) scifi =
false;
537 LOG (error) << board_name <<
" not known. Serious error, stop!";
541 LOG (info) <<
"In scifi? " << scifi
542 <<
" " << board_id <<
" " <<
fEventTree->GetLeaf(
"tofpetId")->GetValue(n)
543 <<
" " <<
fEventTree->GetLeaf(
"tofpetChannel")->GetValue(n)
544 <<
" " <<
fEventTree->GetLeaf(
"tac")->GetValue(n)
545 <<
" " <<
fEventTree->GetLeaf(
"tCoarse")->GetValue(n)
546 <<
" " <<
fEventTree->GetLeaf(
"tFine")->GetValue(n)
547 <<
" " <<
fEventTree->GetLeaf(
"vCoarse")->GetValue(n)
548 <<
" " <<
fEventTree->GetLeaf(
"vFine")->GetValue(n);
549 t0 = high_resolution_clock::now();
550 tofpet_id =
fEventTree->GetLeaf(
"tofpetId")->GetValue(n);
551 tofpet_channel =
fEventTree->GetLeaf(
"tofpetChannel")->GetValue(n);
552 tac =
fEventTree->GetLeaf(
"tac")->GetValue(n);
556 tie(TDC,QDC,Chi2ndof,satur) =
comb_calibration(board_id, tofpet_id, tofpet_channel, tac,
564 TDC =
fEventTree->GetLeaf(
"timestamp")->GetValue(n);
565 QDC =
fEventTree->GetLeaf(
"value")->GetValue(n);
566 Chi2ndof = max(
fEventTree->GetLeaf(
"timestampCalChi2")->GetValue(n)/
fEventTree->GetLeaf(
"timestampCalDof")->GetValue(n),
567 fEventTree->GetLeaf(
"valueCalChi2")->GetValue(n)/
fEventTree->GetLeaf(
"valueCalDof")->GetValue(n));
568 satur =
fEventTree->GetLeaf(
"valueSaturation")->GetValue(n);
572 if ( TDC != TDC || QDC!=QDC) {
573 LOG (error) <<
"NAN tdc/qdc detected! Check maps!"
574 <<
" " << board_id <<
" " <<
fEventTree->GetLeaf(
"tofpetId")->GetValue(n)
575 <<
" " <<
fEventTree->GetLeaf(
"tofpetChannel")->GetValue(n)
576 <<
" " <<
fEventTree->GetLeaf(
"tac")->GetValue(n)
577 <<
" " <<
fEventTree->GetLeaf(
"tCoarse")->GetValue(n)
578 <<
" " <<
fEventTree->GetLeaf(
"tFine")->GetValue(n)
579 <<
" " <<
fEventTree->GetLeaf(
"vCoarse")->GetValue(n)
580 <<
" " <<
fEventTree->GetLeaf(
"vFine")->GetValue(n);
583 t1 = high_resolution_clock::now();
586 if (QDC>1E20) QDC = 997.;
587 if (QDC != QDC) QDC = 998.;
588 if (QDC>0) QDC = -QDC;
593 if (QDC>1E20) QDC = 987.;
594 LOG (info) <<
"inf " << board_id <<
" " <<
fEventTree->GetLeaf(
"tofpetId")->GetValue(n)
595 <<
" " <<
fEventTree->GetLeaf(
"tofpetChannel")->GetValue(n)
596 <<
" " <<
fEventTree->GetLeaf(
"tac")->GetValue(n)
597 <<
" " <<
fEventTree->GetLeaf(
"vCoarse")->GetValue(n)
598 <<
" " <<
fEventTree->GetLeaf(
"vFine")->GetValue(n)
599 <<
" " << TDC-
fEventTree->GetLeaf(
"tCoarse")->GetValue(n)
601 if (QDC != QDC) QDC = 988.;
602 LOG (info) <<
"nan " << board_id <<
" " <<
fEventTree->GetLeaf(
"tofpetId")->GetValue(n)
603 <<
" " <<
fEventTree->GetLeaf(
"tofpetChannel")->GetValue(n)
604 <<
" " <<
fEventTree->GetLeaf(
"tac")->GetValue(n)
605 <<
" " <<
fEventTree->GetLeaf(
"vCoarse")->GetValue(n)
606 <<
" " <<
fEventTree->GetLeaf(
"vFine")->GetValue(n)
607 <<
" " << TDC-
fEventTree->GetLeaf(
"tCoarse")->GetValue(n)
608 <<
" " << TDC <<
" " <<
fEventTree->GetLeaf(
"tCoarse")->GetValue(n)
610 A = int(min(QDC,
double(1000.)));
611 B = min(satur,
double(999.))/1000.;
617 if (QDC>0) QDC = -QDC;
620 LOG (info) <<
"calibrated: tdc = " << TDC <<
", qdc = " << QDC;
621 t4 = high_resolution_clock::now();
623 counters[
"qdc"]+= duration_cast<nanoseconds>(t1 - t0).count();
624 counters[
"make"]+= duration_cast<nanoseconds>(t4-t0).count();
630 key = (tofpet_id%2)*1000 + tofpet_channel;
633 if (tmp ==
"DS_5Vert")
continue;
634 if (
debug || !(tmp.find(
"not") == string::npos))
636 LOG (info) << system <<
" " << key <<
" " << board_name <<
" " << tofpet_id
637 <<
" " << tofpet_id%2 <<
" " << tofpet_channel;
642 cout <<
"key " << key <<
" does not exist. " << endl
643 << board_name <<
" Tofpet id " << tofpet_id
644 <<
" System " << system <<
" has Tofpet map elements: {";
647 cout << it.first <<
" : " << it.second <<
", ";
651 else sipmChannel =
TofpetMap[system][key]-1;
653 nSiPMs = abs(
offMap[tmp][1]);
654 nSides = abs(
offMap[tmp][2]);
655 direction = int(
offMap[tmp][1]/nSiPMs);
656 detID =
offMap[tmp][0] + direction*int(sipmChannel/nSiPMs);
657 sipm_number = sipmChannel%(nSiPMs);
658 if ( tmp.find(
"Right") != string::npos ) sipm_number+= nSiPMs;
665 digiMuFilterStore[detID]->SetDaqID(sipm_number,n, board_id, tofpet_id, tofpet_channel);
668 LOG (info) <<
"create mu hit: " << detID <<
" " << tmp <<
" " << system
669 <<
" " << tofpet_id <<
" " <<
offMap[tmp][0] <<
" " <<
offMap[tmp][1]
670 <<
" " <<
offMap[tmp][2] <<
" " << sipmChannel <<
" " << nSiPMs
671 <<
" " << nSides <<
" " << test << endl
672 << detID <<
" " << sipm_number <<
" " << QDC <<
" " << TDC;
674 if (test>0 || detID%1000>200 || sipm_number>15)
676 cout <<
"what goes wrong? " << detID <<
" SiPM " << sipm_number <<
" system " << system
677 <<
" key " << key <<
" board " << board_name <<
" tofperID " << tofpet_id
678 <<
" tofperChannel " << tofpet_channel <<
" test " << test << endl;
680 t5 = high_resolution_clock::now();
681 counters[
"createMufi"]+= duration_cast<nanoseconds>(t5 - t4).count();
688 if (station[2]==
'Y') orientation = 0;
689 sipmLocal = (chan - mat*512);
690 sipmID = 1000000*int(station[1]-
'0') + 100000*orientation + 10000*mat
691 + 1000*(int(sipmLocal/128)) + chan%128;
697 digiSciFiStore[sipmID]->SetDaqID(0,n,board_id, tofpet_id, tofpet_channel);
699 LOG (info) <<
"create scifi hit: tdc = " << board_name <<
" " << sipmID
700 <<
" " << QDC <<
" " << TDC <<endl
701 <<
"tofpet:" <<
" " << tofpet_id <<
" " << tofpet_channel <<
" " << mat
702 <<
" " << chan << endl
703 << station[1] <<
" " << station[2] <<
" " << mat <<
" " << chan
704 <<
" " << int(chan/128)%4 <<
" " << chan%128;
705 t5 = high_resolution_clock::now();
706 counters[
"createScifi"]+= duration_cast<nanoseconds>(t5 - t4).count();
711 t6 = high_resolution_clock::now();
722 counters[
"storage"]+= duration_cast<nanoseconds>(high_resolution_clock::now() - t6).count();
723 counters[
"event"]+= duration_cast<nanoseconds>(high_resolution_clock::now() - tE).count();
727 LOG (info) <<
fnStart+1 <<
" events processed out of "
728 <<
fEventTree->GetEntries() <<
" number of events in file.";
810 uint32_t bytesRead = 0;
814 ifstream jsonfile(Form(
"%s/board_mapping.json", Path.c_str()));
819 status = file.Open(Form(
"%s/board_mapping.json", Path.c_str()), OpenFlags::Read);
822 LOG (error) <<
"Error opening file";
825 file.Stat(
false, info);
826 size = info->GetSize();
827 char *buff =
new char[size];
828 status = file.Read(offset, size, buff, bytesRead);
830 for (
size_t i = 0; i < size; i++){vec.push_back(buff[i]);}
831 j = json::parse(vec);
832 status = file.Close();
839 int board_id_mu{}, s{};
843 board_id_mu = stoi(it.first.substr(it.first.find(
"_") + 1));
846 for (
auto slot :
slots )
848 if ( Path.find(
"testbeam_23") == string::npos ) s = 0;
850 tmp = x.second.substr(0, x.second.find(
"_"));
851 if ( tmp ==
"US" ) s = 1;
855 if ( Path.find(
"testbeam_24") != string::npos && x.second.substr(x.second.find(
"_")+1,1)==2) s = 3;
857 if (
slots[slot.first] == x.first )
860 boardMaps[
"MuFilter"][it.first][slot.second] = slot.first;
867 for (
int i = 1 ; i < 6; i++ )
871 offMap[Form(
"Veto_%iLeft",i)] = {10000 + (i-1)*1000+ 0, 8, 2};
872 offMap[Form(
"Veto_%iRight",i)] = {10000 + (i-1)*1000+ 0, 8, 2};
874 if (i==3)
offMap[Form(
"Veto_%iVert",i)] = {10000 + (i-1)*1000+ 6, -8, 1};
878 offMap[Form(
"DS_%iLeft",i)] = {30000 + (i-1)*1000+ 59, -1, 2};
879 offMap[Form(
"DS_%iRight",i)] = {30000 + (i-1)*1000+ 59, -1, 2};
883 offMap[Form(
"DS_%iVert",i)] = {30000 + (i-1)*1000+ 119, -1, 1};
885 offMap[Form(
"US_%iLeft",i)] = {20000 + (i-1)*1000+ 9, -8, 2};
886 offMap[Form(
"US_%iRight",i)] = {20000 + (i-1)*1000+ 9, -8, 2};
922tuple<double, double, double, double>
ConvRawData::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 = 1.0,
int TDC=0 )
924 map<string, double> par=
X_qdc[{board_id,tofpet_id,channel,tac}];
925 map<string, double> parT =
X_tdc[{board_id,tofpet_id,channel,tac,TDC}];
927 double ftdc = (-parT[
"b"]-sqrt(pow(parT[
"b"],2)
928 -4*parT[
"a"]*(parT[
"c"]-x)))/(2*parT[
"a"]);
929 double timestamp = t_coarse + ftdc;
930 double tf = timestamp - t_coarse;
932 double fqdc = - par[
"c"]*log(1+exp( par[
"a"]*pow((x-par[
"e"]),2)-par[
"b"]*(x-par[
"e"]) ))
934 double value = (v_fine-fqdc)/GQDC;
935 return make_tuple(timestamp,value,max(par[
"chi2Ndof"],parT[
"chi2Ndof"]),v_fine/par[
"d"]);
939 TH1F* h =
new TH1F(
"chi2",
"chi2", 1000, 0., 10000);
940 map<double, pair<double, double> > report{};
942 double chi2{}, chi2T{}, key{};
944 for (
auto it :
X_qdc)
946 map<string, double> par=
X_qdc[{it.first[0], it.first[1], it.first[2], it.first[3]}];
947 if (par[
"chi2Ndof"]) chi2 = par[
"chi2Ndof"];
949 map<string, double> parT =
X_tdc[{it.first[0], it.first[1], it.first[2], it.first[3], TDC}];
950 if (parT[
"chi2Ndof"]) chi2T = parT[
"chi2Ndof"];
952 key = it.first[3] +10*it.first[2] + it.first[1]*10*100 + it.first[0]*10*100*100;
953 if (report.count(key)==0) report[key] = make_pair(chi2,chi2T);
955 for (
auto it : report)
957 h->Fill(report[it.first].first);
958 h->Fill(report[it.first].second);
979 uint32_t bytesRead = 0;
980 string line, element;
983 vector<int> key_vector{};
987 vector<int> data_vector{};
988 map<string, map<int, vector<int>> > SiPMmap{};
990 map<string, int> key { {
"BM",3}, {
"DS",2}, {
"US",1}, {
"Veto",0} };
992 TString sndRoot = gSystem->Getenv(
"SNDSW_ROOT");
993 string sndswPath = sndRoot.Data();
994 string path_SiPMmap = Form(
"%s/geometry", sndswPath.c_str());
995 if (stat(path_SiPMmap.c_str(), &buffer) != 0)
997 LOG (error) <<
"Path "<< path_SiPMmap.c_str() <<
" does not exist!";
1000 for (
auto sys : key)
1002 infile.open(Form(
"%s/%s_SiPM_mapping.csv", path_SiPMmap.c_str(), sys.first.c_str()));
1003 X << infile.rdbuf();
1008 LOG (info) <<
"In " << sys.first <<
" SiPM map file: " << line;
1010 while (getline(X,line))
1012 data_vector.clear();
1013 stringstream items(line);
1015 getline(items, element,
',');
1016 SiPM = stoi(element);
1018 while (data_vector.size()<4 && getline(items, element,
','))
1020 data_vector.push_back(stoi(element));
1022 SiPMmap[sys.first][SiPM] = data_vector;
1023 if (X.peek() == EOF)
break;
1025 X.str(
string()); X.clear(); line.clear();
1026 size = 0; offset = 0; bytesRead = 0;
1027 for (
auto channel : SiPMmap[sys.first])
1029 row = channel.second;
1030 TofpetMap[sys.second][row.at(2)*1000+row.at(3)] = channel.first;
1040 infile.open(Form(
"%s/qdc_cal.csv", Path.c_str()));
1041 X << infile.rdbuf();
1046 status = file.Open(Form(
"%s/qdc_cal.csv", Path.c_str()), OpenFlags::Read);
1047 if( !status.IsOK() )
1049 LOG (error) <<
"Error opening file";
1052 file.Stat(
false, info);
1053 size = info->GetSize();
1054 char *buff =
new char[size];
1055 status = file.Read(offset, size, buff, bytesRead);
1057 status = file.Close();
1061 LOG (info) <<
"Read_csv "<<Path.c_str();
1064 LOG (info) <<
"In QDC cal file: " << line;
1065 vector<double> qdcData{};
1067 while (getline(X, line))
1070 stringstream items(line);
1071 while (getline(items, element,
','))
1073 if(iscntrl(element[0]))
break;
1074 qdcData.push_back(stof(element));
1076 if (qdcData.size()<10)
continue;
1078 key_vector = {int(qdcData[0]), int(qdcData[1]), int(qdcData[2]), int(qdcData[3])};
1079 chi2_Ndof = (qdcData[9] < 2) ? 999999. : qdcData[7]/qdcData[9];
1080 X_qdc[key_vector] = { {
"a",qdcData[4]}, {
"b",qdcData[5]}, {
"c",qdcData[6]},
1081 {
"d",qdcData[8]}, {
"e",qdcData[10]}, {
"chi2Ndof",chi2_Ndof} };
1082 if (X.peek() == EOF)
break;
1084 X.str(
string()); X.clear(); line.clear();
1085 size = 0; offset = 0; bytesRead = 0;
1089 infile.open(Form(
"%s/tdc_cal.csv", Path.c_str()));
1090 X << infile.rdbuf();
1095 status = file.Open(Form(
"%s/tdc_cal.csv", Path.c_str()), OpenFlags::Read);
1096 if( !status.IsOK() )
1098 LOG (error) <<
"Error opening file";
1101 file.Stat(
false, info);
1102 size = info->GetSize();
1103 char *buff =
new char[size];
1104 status = file.Read(offset, size, buff, bytesRead);
1106 status = file.Close();
1112 LOG (info) <<
"In TDC cal file: " << line;
1113 vector<double> tdcData{};
1115 while (getline(X, line))
1118 stringstream items(line);
1119 if (line.length()<5){
continue;}
1120 while (getline(items, element,
','))
1122 if(iscntrl(element[0]))
break;
1123 tdcData.push_back(stof(element));
1125 if (tdcData.size()<9)
continue;
1127 key_vector = {int(tdcData[0]), int(tdcData[1]), int(tdcData[2]), int(tdcData[3]), int(tdcData[4])};
1128 chi2_Ndof = (tdcData[10] < 2) ? 999999. : tdcData[8]/tdcData[10];
1129 X_tdc[key_vector] = { {
"a",tdcData[5]}, {
"b",tdcData[6]}, {
"c",tdcData[7]},
1130 {
"d",tdcData[9]}, {
"chi2Ndof",chi2_Ndof} };
1131 if (X.peek() == EOF)
break;
1133 X.str(
string()); X.clear(); line.clear();
1134 size = 0; offset = 0; bytesRead = 0;
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)