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;
336 if (
debug || !(tmp.find(
"not") == string::npos))
338 LOG (info) << system <<
" " << key <<
" " << board.first <<
" " << tofpet_id
339 <<
" " << tofpet_id%2 <<
" " << tofpet_channel;
344 cout <<
"key " << key <<
" does not exist. " << endl
345 << board.first <<
" Tofpet id " << tofpet_id
346 <<
" System " << system <<
" has Tofpet map elements: {";
349 cout << it.first <<
" : " << it.second <<
", ";
353 else sipmChannel =
TofpetMap[system][key]-1;
355 nSiPMs = abs(
offMap[tmp][1]);
356 nSides = abs(
offMap[tmp][2]);
357 direction = int(
offMap[tmp][1]/nSiPMs);
358 detID =
offMap[tmp][0] + direction*int(sipmChannel/nSiPMs);
359 sipm_number = sipmChannel%(nSiPMs);
360 if ( tmp.find(
"Right") != string::npos ) sipm_number+= nSiPMs;
367 digiMuFilterStore[detID]->SetDaqID(sipm_number,n, board_id, tofpet_id, tofpet_channel);
370 LOG (info) <<
"create mu hit: " << detID <<
" " << tmp <<
" " << system
371 <<
" " << tofpet_id <<
" " <<
offMap[tmp][0] <<
" " <<
offMap[tmp][1]
372 <<
" " <<
offMap[tmp][2] <<
" " << sipmChannel <<
" " << nSiPMs
373 <<
" " << nSides <<
" " << test << endl
374 << detID <<
" " << sipm_number <<
" " << QDC <<
" " << TDC;
376 if (test>0 || detID%1000>200 || sipm_number>15)
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;
382 t5 = high_resolution_clock::now();
383 counters[
"createMufi"]+= duration_cast<nanoseconds>(t5 - t4).count();
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;
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();
414 t6 = high_resolution_clock::now();
425 counters[
"storage"]+= duration_cast<nanoseconds>(high_resolution_clock::now() - t6).count();
426 counters[
"event"]+= duration_cast<nanoseconds>(high_resolution_clock::now() - tE).count();
430 LOG (info) <<
fnStart+1 <<
" events processed out of "
431 <<
fEventTree->GetEntries() <<
" number of events in file.";
451 int indexSciFi{}, indexMuFilter{};
452 bool scifi =
false, mask =
false;
455 int tofpet_id{}, tofpet_channel{}, tac{}, mat{};
457 double TDC{}, QDC{}, Chi2ndof{}, satur{};
460 high_resolution_clock::time_point tE{}, t0{}, t1{}, t4{}, t5{}, t6{}, tt{};
461 int system{}, key{}, sipmChannel{};
463 int nSiPMs{}, nSides{}, direction{}, detID{}, sipm_number{}, chan{}, orientation{}, sipmLocal{};
469 tE = high_resolution_clock::now();
474 tt = high_resolution_clock::now();
475 time_t ttp = high_resolution_clock::to_time_t(tt);
477 <<
" local time " << ctime(&ttp);
482 eventTime =
fEventTree->GetLeaf(
"evtTimestamp")->GetValue();
487 if (
FSmap->GetEntries()>1){
491 int((eventTime%(4*3564))/8+0.5))))->GetString().Data()));
496 int((eventTime%(4*3564))/4))))->GetString().Data()));
502 LOG (info) <<
"evtNumber per run "
503 <<
fEventTree->GetLeaf(
"evtNumber")->GetValue()
505 <<
" timestamp: " << eventTime;
519 for (
int n =0; n <
fEventTree->GetLeaf(
"nHits")->GetValue(); n++ )
521 board_id =
fEventTree->GetLeaf(
"boardId")->GetValue(n);
522 board_name =
"board_"+to_string(board_id);
524 if (
boardMaps[
"Scifi"].count(board_name)!=0)
526 for (
auto it :
boardMaps[
"Scifi"][board_name])
532 else if (
boardMaps[
"MuFilter"].count(board_name)!=0) scifi =
false;
535 LOG (error) << board_name <<
" not known. Serious error, stop!";
539 LOG (info) <<
"In scifi? " << scifi
540 <<
" " << board_id <<
" " <<
fEventTree->GetLeaf(
"tofpetId")->GetValue(n)
541 <<
" " <<
fEventTree->GetLeaf(
"tofpetChannel")->GetValue(n)
542 <<
" " <<
fEventTree->GetLeaf(
"tac")->GetValue(n)
543 <<
" " <<
fEventTree->GetLeaf(
"tCoarse")->GetValue(n)
544 <<
" " <<
fEventTree->GetLeaf(
"tFine")->GetValue(n)
545 <<
" " <<
fEventTree->GetLeaf(
"vCoarse")->GetValue(n)
546 <<
" " <<
fEventTree->GetLeaf(
"vFine")->GetValue(n);
547 t0 = high_resolution_clock::now();
548 tofpet_id =
fEventTree->GetLeaf(
"tofpetId")->GetValue(n);
549 tofpet_channel =
fEventTree->GetLeaf(
"tofpetChannel")->GetValue(n);
550 tac =
fEventTree->GetLeaf(
"tac")->GetValue(n);
554 tie(TDC,QDC,Chi2ndof,satur) =
comb_calibration(board_id, tofpet_id, tofpet_channel, tac,
562 TDC =
fEventTree->GetLeaf(
"timestamp")->GetValue(n);
563 QDC =
fEventTree->GetLeaf(
"value")->GetValue(n);
564 Chi2ndof = max(
fEventTree->GetLeaf(
"timestampCalChi2")->GetValue(n)/
fEventTree->GetLeaf(
"timestampCalDof")->GetValue(n),
565 fEventTree->GetLeaf(
"valueCalChi2")->GetValue(n)/
fEventTree->GetLeaf(
"valueCalDof")->GetValue(n));
566 satur =
fEventTree->GetLeaf(
"valueSaturation")->GetValue(n);
570 if ( TDC != TDC || QDC!=QDC) {
571 LOG (error) <<
"NAN tdc/qdc detected! Check maps!"
572 <<
" " << board_id <<
" " <<
fEventTree->GetLeaf(
"tofpetId")->GetValue(n)
573 <<
" " <<
fEventTree->GetLeaf(
"tofpetChannel")->GetValue(n)
574 <<
" " <<
fEventTree->GetLeaf(
"tac")->GetValue(n)
575 <<
" " <<
fEventTree->GetLeaf(
"tCoarse")->GetValue(n)
576 <<
" " <<
fEventTree->GetLeaf(
"tFine")->GetValue(n)
577 <<
" " <<
fEventTree->GetLeaf(
"vCoarse")->GetValue(n)
578 <<
" " <<
fEventTree->GetLeaf(
"vFine")->GetValue(n);
581 t1 = high_resolution_clock::now();
584 if (QDC>1E20) QDC = 997.;
585 if (QDC != QDC) QDC = 998.;
586 if (QDC>0) QDC = -QDC;
591 if (QDC>1E20) QDC = 987.;
592 LOG (info) <<
"inf " << board_id <<
" " <<
fEventTree->GetLeaf(
"tofpetId")->GetValue(n)
593 <<
" " <<
fEventTree->GetLeaf(
"tofpetChannel")->GetValue(n)
594 <<
" " <<
fEventTree->GetLeaf(
"tac")->GetValue(n)
595 <<
" " <<
fEventTree->GetLeaf(
"vCoarse")->GetValue(n)
596 <<
" " <<
fEventTree->GetLeaf(
"vFine")->GetValue(n)
597 <<
" " << TDC-
fEventTree->GetLeaf(
"tCoarse")->GetValue(n)
599 if (QDC != QDC) QDC = 988.;
600 LOG (info) <<
"nan " << board_id <<
" " <<
fEventTree->GetLeaf(
"tofpetId")->GetValue(n)
601 <<
" " <<
fEventTree->GetLeaf(
"tofpetChannel")->GetValue(n)
602 <<
" " <<
fEventTree->GetLeaf(
"tac")->GetValue(n)
603 <<
" " <<
fEventTree->GetLeaf(
"vCoarse")->GetValue(n)
604 <<
" " <<
fEventTree->GetLeaf(
"vFine")->GetValue(n)
605 <<
" " << TDC-
fEventTree->GetLeaf(
"tCoarse")->GetValue(n)
606 <<
" " << TDC <<
" " <<
fEventTree->GetLeaf(
"tCoarse")->GetValue(n)
608 A = int(min(QDC,
double(1000.)));
609 B = min(satur,
double(999.))/1000.;
615 if (QDC>0) QDC = -QDC;
618 LOG (info) <<
"calibrated: tdc = " << TDC <<
", qdc = " << QDC;
619 t4 = high_resolution_clock::now();
621 counters[
"qdc"]+= duration_cast<nanoseconds>(t1 - t0).count();
622 counters[
"make"]+= duration_cast<nanoseconds>(t4-t0).count();
628 key = (tofpet_id%2)*1000 + tofpet_channel;
630 if (
debug || !(tmp.find(
"not") == string::npos))
632 LOG (info) << system <<
" " << key <<
" " << board_name <<
" " << tofpet_id
633 <<
" " << tofpet_id%2 <<
" " << tofpet_channel;
638 cout <<
"key " << key <<
" does not exist. " << endl
639 << board_name <<
" Tofpet id " << tofpet_id
640 <<
" System " << system <<
" has Tofpet map elements: {";
643 cout << it.first <<
" : " << it.second <<
", ";
647 else sipmChannel =
TofpetMap[system][key]-1;
649 nSiPMs = abs(
offMap[tmp][1]);
650 nSides = abs(
offMap[tmp][2]);
651 direction = int(
offMap[tmp][1]/nSiPMs);
652 detID =
offMap[tmp][0] + direction*int(sipmChannel/nSiPMs);
653 sipm_number = sipmChannel%(nSiPMs);
654 if ( tmp.find(
"Right") != string::npos ) sipm_number+= nSiPMs;
661 digiMuFilterStore[detID]->SetDaqID(sipm_number,n, board_id, tofpet_id, tofpet_channel);
664 LOG (info) <<
"create mu hit: " << detID <<
" " << tmp <<
" " << system
665 <<
" " << tofpet_id <<
" " <<
offMap[tmp][0] <<
" " <<
offMap[tmp][1]
666 <<
" " <<
offMap[tmp][2] <<
" " << sipmChannel <<
" " << nSiPMs
667 <<
" " << nSides <<
" " << test << endl
668 << detID <<
" " << sipm_number <<
" " << QDC <<
" " << TDC;
670 if (test>0 || detID%1000>200 || sipm_number>15)
672 cout <<
"what goes wrong? " << detID <<
" SiPM " << sipm_number <<
" system " << system
673 <<
" key " << key <<
" board " << board_name <<
" tofperID " << tofpet_id
674 <<
" tofperChannel " << tofpet_channel <<
" test " << test << endl;
676 t5 = high_resolution_clock::now();
677 counters[
"createMufi"]+= duration_cast<nanoseconds>(t5 - t4).count();
684 if (station[2]==
'Y') orientation = 0;
685 sipmLocal = (chan - mat*512);
686 sipmID = 1000000*int(station[1]-
'0') + 100000*orientation + 10000*mat
687 + 1000*(int(sipmLocal/128)) + chan%128;
693 digiSciFiStore[sipmID]->SetDaqID(0,n,board_id, tofpet_id, tofpet_channel);
695 LOG (info) <<
"create scifi hit: tdc = " << board_name <<
" " << sipmID
696 <<
" " << QDC <<
" " << TDC <<endl
697 <<
"tofpet:" <<
" " << tofpet_id <<
" " << tofpet_channel <<
" " << mat
698 <<
" " << chan << endl
699 << station[1] <<
" " << station[2] <<
" " << mat <<
" " << chan
700 <<
" " << int(chan/128)%4 <<
" " << chan%128;
701 t5 = high_resolution_clock::now();
702 counters[
"createScifi"]+= duration_cast<nanoseconds>(t5 - t4).count();
707 t6 = high_resolution_clock::now();
718 counters[
"storage"]+= duration_cast<nanoseconds>(high_resolution_clock::now() - t6).count();
719 counters[
"event"]+= duration_cast<nanoseconds>(high_resolution_clock::now() - tE).count();
723 LOG (info) <<
fnStart+1 <<
" events processed out of "
724 <<
fEventTree->GetEntries() <<
" number of events in file.";
806 uint32_t bytesRead = 0;
810 ifstream jsonfile(Form(
"%s/board_mapping.json", Path.c_str()));
815 status = file.Open(Form(
"%s/board_mapping.json", Path.c_str()), OpenFlags::Read);
818 LOG (error) <<
"Error opening file";
821 file.Stat(
false, info);
822 size = info->GetSize();
823 char *buff =
new char[size];
824 status = file.Read(offset, size, buff, bytesRead);
826 for (
size_t i = 0; i < size; i++){vec.push_back(buff[i]);}
827 j = json::parse(vec);
828 status = file.Close();
835 int board_id_mu{}, s{};
839 board_id_mu = stoi(it.first.substr(it.first.find(
"_") + 1));
842 for (
auto slot :
slots )
844 if ( Path.find(
"testbeam_23") == string::npos ) s = 0;
846 tmp = x.second.substr(0, x.second.find(
"_"));
847 if ( tmp ==
"US" ) s = 1;
851 if ( Path.find(
"testbeam_24") != string::npos && x.second.substr(x.second.find(
"_")+1,1)==2) s = 3;
853 if (
slots[slot.first] == x.first )
856 boardMaps[
"MuFilter"][it.first][slot.second] = slot.first;
863 for (
int i = 1 ; i < 6; i++ )
867 offMap[Form(
"Veto_%iLeft",i)] = {10000 + (i-1)*1000+ 0, 8, 2};
868 offMap[Form(
"Veto_%iRight",i)] = {10000 + (i-1)*1000+ 0, 8, 2};
870 if (i==3)
offMap[Form(
"Veto_%iVert",i)] = {10000 + (i-1)*1000+ 6, -8, 1};
874 offMap[Form(
"DS_%iLeft",i)] = {30000 + (i-1)*1000+ 59, -1, 2};
875 offMap[Form(
"DS_%iRight",i)] = {30000 + (i-1)*1000+ 59, -1, 2};
879 offMap[Form(
"DS_%iVert",i)] = {30000 + (i-1)*1000+ 119, -1, 1};
881 offMap[Form(
"US_%iLeft",i)] = {20000 + (i-1)*1000+ 9, -8, 2};
882 offMap[Form(
"US_%iRight",i)] = {20000 + (i-1)*1000+ 9, -8, 2};
918tuple<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 )
920 map<string, double> par=
X_qdc[{board_id,tofpet_id,channel,tac}];
921 map<string, double> parT =
X_tdc[{board_id,tofpet_id,channel,tac,TDC}];
923 double ftdc = (-parT[
"b"]-sqrt(pow(parT[
"b"],2)
924 -4*parT[
"a"]*(parT[
"c"]-x)))/(2*parT[
"a"]);
925 double timestamp = t_coarse + ftdc;
926 double tf = timestamp - t_coarse;
928 double fqdc = - par[
"c"]*log(1+exp( par[
"a"]*pow((x-par[
"e"]),2)-par[
"b"]*(x-par[
"e"]) ))
930 double value = (v_fine-fqdc)/GQDC;
931 return make_tuple(timestamp,value,max(par[
"chi2Ndof"],parT[
"chi2Ndof"]),v_fine/par[
"d"]);
935 TH1F* h =
new TH1F(
"chi2",
"chi2", 1000, 0., 10000);
936 map<double, pair<double, double> > report{};
938 double chi2{}, chi2T{}, key{};
940 for (
auto it :
X_qdc)
942 map<string, double> par=
X_qdc[{it.first[0], it.first[1], it.first[2], it.first[3]}];
943 if (par[
"chi2Ndof"]) chi2 = par[
"chi2Ndof"];
945 map<string, double> parT =
X_tdc[{it.first[0], it.first[1], it.first[2], it.first[3], TDC}];
946 if (parT[
"chi2Ndof"]) chi2T = parT[
"chi2Ndof"];
948 key = it.first[3] +10*it.first[2] + it.first[1]*10*100 + it.first[0]*10*100*100;
949 if (report.count(key)==0) report[key] = make_pair(chi2,chi2T);
951 for (
auto it : report)
953 h->Fill(report[it.first].first);
954 h->Fill(report[it.first].second);
975 uint32_t bytesRead = 0;
976 string line, element;
979 vector<int> key_vector{};
983 vector<int> data_vector{};
984 map<string, map<int, vector<int>> > SiPMmap{};
986 map<string, int> key { {
"BM",3}, {
"DS",2}, {
"US",1}, {
"Veto",0} };
988 TString sndRoot = gSystem->Getenv(
"SNDSW_ROOT");
989 string sndswPath = sndRoot.Data();
990 string path_SiPMmap = Form(
"%s/geometry", sndswPath.c_str());
991 if (stat(path_SiPMmap.c_str(), &buffer) != 0)
993 LOG (error) <<
"Path "<< path_SiPMmap.c_str() <<
" does not exist!";
998 infile.open(Form(
"%s/%s_SiPM_mapping.csv", path_SiPMmap.c_str(), sys.first.c_str()));
1004 LOG (info) <<
"In " << sys.first <<
" SiPM map file: " << line;
1006 while (getline(X,line))
1008 data_vector.clear();
1009 stringstream items(line);
1011 getline(items, element,
',');
1012 SiPM = stoi(element);
1014 while (data_vector.size()<4 && getline(items, element,
','))
1016 data_vector.push_back(stoi(element));
1018 SiPMmap[sys.first][SiPM] = data_vector;
1019 if (X.peek() == EOF)
break;
1021 X.str(
string()); X.clear(); line.clear();
1022 size = 0; offset = 0; bytesRead = 0;
1023 for (
auto channel : SiPMmap[sys.first])
1025 row = channel.second;
1026 TofpetMap[sys.second][row.at(2)*1000+row.at(3)] = channel.first;
1036 infile.open(Form(
"%s/qdc_cal.csv", Path.c_str()));
1037 X << infile.rdbuf();
1042 status = file.Open(Form(
"%s/qdc_cal.csv", Path.c_str()), OpenFlags::Read);
1043 if( !status.IsOK() )
1045 LOG (error) <<
"Error opening file";
1048 file.Stat(
false, info);
1049 size = info->GetSize();
1050 char *buff =
new char[size];
1051 status = file.Read(offset, size, buff, bytesRead);
1053 status = file.Close();
1057 LOG (info) <<
"Read_csv "<<Path.c_str();
1060 LOG (info) <<
"In QDC cal file: " << line;
1061 vector<double> qdcData{};
1063 while (getline(X, line))
1066 stringstream items(line);
1067 while (getline(items, element,
','))
1069 if(iscntrl(element[0]))
break;
1070 qdcData.push_back(stof(element));
1072 if (qdcData.size()<10)
continue;
1074 key_vector = {int(qdcData[0]), int(qdcData[1]), int(qdcData[2]), int(qdcData[3])};
1075 chi2_Ndof = (qdcData[9] < 2) ? 999999. : qdcData[7]/qdcData[9];
1076 X_qdc[key_vector] = { {
"a",qdcData[4]}, {
"b",qdcData[5]}, {
"c",qdcData[6]},
1077 {
"d",qdcData[8]}, {
"e",qdcData[10]}, {
"chi2Ndof",chi2_Ndof} };
1078 if (X.peek() == EOF)
break;
1080 X.str(
string()); X.clear(); line.clear();
1081 size = 0; offset = 0; bytesRead = 0;
1085 infile.open(Form(
"%s/tdc_cal.csv", Path.c_str()));
1086 X << infile.rdbuf();
1091 status = file.Open(Form(
"%s/tdc_cal.csv", Path.c_str()), OpenFlags::Read);
1092 if( !status.IsOK() )
1094 LOG (error) <<
"Error opening file";
1097 file.Stat(
false, info);
1098 size = info->GetSize();
1099 char *buff =
new char[size];
1100 status = file.Read(offset, size, buff, bytesRead);
1102 status = file.Close();
1108 LOG (info) <<
"In TDC cal file: " << line;
1109 vector<double> tdcData{};
1111 while (getline(X, line))
1114 stringstream items(line);
1115 if (line.length()<5){
continue;}
1116 while (getline(items, element,
','))
1118 if(iscntrl(element[0]))
break;
1119 tdcData.push_back(stof(element));
1121 if (tdcData.size()<9)
continue;
1123 key_vector = {int(tdcData[0]), int(tdcData[1]), int(tdcData[2]), int(tdcData[3]), int(tdcData[4])};
1124 chi2_Ndof = (tdcData[10] < 2) ? 999999. : tdcData[8]/tdcData[10];
1125 X_tdc[key_vector] = { {
"a",tdcData[5]}, {
"b",tdcData[6]}, {
"c",tdcData[7]},
1126 {
"d",tdcData[9]}, {
"chi2Ndof",chi2_Ndof} };
1127 if (X.peek() == EOF)
break;
1129 X.str(
string()); X.clear(); line.clear();
1130 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)