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();
149 FairLogger *
logger = FairLogger::GetLogger();
179 int indexSciFi{}, indexMuFilter{};
180 bool scifi =
false, mask =
false;
183 int tofpet_id{}, tofpet_channel{}, tac{}, mat{};
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{};
196 tE = high_resolution_clock::now();
201 tt = high_resolution_clock::now();
202 time_t ttp = high_resolution_clock::to_time_t(tt);
204 <<
" local time " << ctime(&ttp);
209 LOG (info) <<
"event: " <<
eventNumber <<
" timestamp: "
210 <<
fEventTree->GetLeaf(
"evtTimestamp")->GetValue();
224 for (
auto board :
boards )
226 board_id = stoi(board.first.substr(board.first.find(
"_")+1));
228 if (
boardMaps[
"Scifi"].count(board.first)!=0)
230 for (
auto it :
boardMaps[
"Scifi"][board.first])
236 else if (
boardMaps[
"MuFilter"].count(board.first)!=0) scifi =
false;
239 LOG (error) << board.first <<
" not known. Serious error, stop!";
245 for (
int n = 0; n < bt->GetLeaf(
"nHits")->GetValue(); n++ )
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);
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),
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);
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);
290 t1 = high_resolution_clock::now();
293 if (QDC>1E20) QDC = 997.;
294 if (QDC != QDC) QDC = 998.;
295 if (QDC>0) QDC = -QDC;
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.;
324 if (QDC>0) QDC = -QDC;
327 LOG (info) <<
"calibrated: tdc = " << TDC <<
", qdc = " << QDC;
328 t4 = high_resolution_clock::now();
330 counters[
"qdc"]+= duration_cast<nanoseconds>(t1 - t0).count();
331 counters[
"make"]+= duration_cast<nanoseconds>(t4-t0).count();
337 key = (tofpet_id%2)*1000 + tofpet_channel;
339 if (
debug || !tmp.find(
"not") == string::npos )
341 LOG (info) << system <<
" " << key <<
" " << board.first <<
" " << tofpet_id
342 <<
" " << tofpet_id%2 <<
" " << tofpet_channel;
347 cout <<
"key " << key <<
" does not exist. " << endl
348 << board.first <<
" Tofpet id " << tofpet_id
349 <<
" System " << system <<
" has Tofpet map elements: {";
352 cout << it.first <<
" : " << it.second <<
", ";
356 else sipmChannel =
TofpetMap[system][key]-1;
358 nSiPMs = abs(
offMap[tmp][1]);
359 nSides = abs(
offMap[tmp][2]);
360 direction = int(
offMap[tmp][1]/nSiPMs);
361 detID =
offMap[tmp][0] + direction*int(sipmChannel/nSiPMs);
362 sipm_number = sipmChannel%(nSiPMs);
363 if ( tmp.find(
"Right") != string::npos ) sipm_number+= nSiPMs;
370 digiMuFilterStore[detID]->SetDaqID(sipm_number,n, board_id, tofpet_id, tofpet_channel);
373 LOG (info) <<
"create mu hit: " << detID <<
" " << tmp <<
" " << system
374 <<
" " << tofpet_id <<
" " <<
offMap[tmp][0] <<
" " <<
offMap[tmp][1]
375 <<
" " <<
offMap[tmp][2] <<
" " << sipmChannel <<
" " << nSiPMs
376 <<
" " << nSides <<
" " << test << endl
377 << detID <<
" " << sipm_number <<
" " << QDC <<
" " << TDC;
379 if (test>0 || detID%1000>200 || sipm_number>15)
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;
385 t5 = high_resolution_clock::now();
386 counters[
"createMufi"]+= duration_cast<nanoseconds>(t5 - t4).count();
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;
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();
417 t6 = high_resolution_clock::now();
428 counters[
"storage"]+= duration_cast<nanoseconds>(high_resolution_clock::now() - t6).count();
429 counters[
"event"]+= duration_cast<nanoseconds>(high_resolution_clock::now() - tE).count();
433 LOG (info) <<
fnStart+1 <<
" events processed out of "
434 <<
fEventTree->GetEntries() <<
" number of events in file.";
454 int indexSciFi{}, indexMuFilter{};
455 bool scifi =
false, mask =
false;
458 int tofpet_id{}, tofpet_channel{}, tac{}, mat{};
460 double TDC{}, QDC{}, Chi2ndof{}, satur{};
463 high_resolution_clock::time_point tE{}, t0{}, t1{}, t4{}, t5{}, t6{}, tt{};
464 int system{}, key{}, sipmChannel{};
466 int nSiPMs{}, nSides{}, direction{}, detID{}, sipm_number{}, chan{}, orientation{}, sipmLocal{};
472 tE = high_resolution_clock::now();
477 tt = high_resolution_clock::now();
478 time_t ttp = high_resolution_clock::to_time_t(tt);
480 <<
" local time " << ctime(&ttp);
485 eventTime =
fEventTree->GetLeaf(
"evtTimestamp")->GetValue();
490 if (
FSmap->GetEntries()>1){
494 int((eventTime%(4*3564))/8+0.5))))->GetString().Data()));
499 int((eventTime%(4*3564))/4))))->GetString().Data()));
505 LOG (info) <<
"evtNumber per run "
506 <<
fEventTree->GetLeaf(
"evtNumber")->GetValue()
508 <<
" timestamp: " << eventTime;
522 for (
int n =0; n <
fEventTree->GetLeaf(
"nHits")->GetValue(); n++ )
524 board_id =
fEventTree->GetLeaf(
"boardId")->GetValue(n);
525 board_name =
"board_"+to_string(board_id);
527 if (
boardMaps[
"Scifi"].count(board_name)!=0)
529 for (
auto it :
boardMaps[
"Scifi"][board_name])
535 else if (
boardMaps[
"MuFilter"].count(board_name)!=0) scifi =
false;
538 LOG (error) << board_name <<
" not known. Serious error, stop!";
542 LOG (info) <<
"In scifi? " << scifi
543 <<
" " << board_id <<
" " <<
fEventTree->GetLeaf(
"tofpetId")->GetValue(n)
544 <<
" " <<
fEventTree->GetLeaf(
"tofpetChannel")->GetValue(n)
545 <<
" " <<
fEventTree->GetLeaf(
"tac")->GetValue(n)
546 <<
" " <<
fEventTree->GetLeaf(
"tCoarse")->GetValue(n)
547 <<
" " <<
fEventTree->GetLeaf(
"tFine")->GetValue(n)
548 <<
" " <<
fEventTree->GetLeaf(
"vCoarse")->GetValue(n)
549 <<
" " <<
fEventTree->GetLeaf(
"vFine")->GetValue(n);
550 t0 = high_resolution_clock::now();
551 tofpet_id =
fEventTree->GetLeaf(
"tofpetId")->GetValue(n);
552 tofpet_channel =
fEventTree->GetLeaf(
"tofpetChannel")->GetValue(n);
553 tac =
fEventTree->GetLeaf(
"tac")->GetValue(n);
557 tie(TDC,QDC,Chi2ndof,satur) =
comb_calibration(board_id, tofpet_id, tofpet_channel, tac,
565 TDC =
fEventTree->GetLeaf(
"timestamp")->GetValue(n);
566 QDC =
fEventTree->GetLeaf(
"value")->GetValue(n);
567 Chi2ndof = max(
fEventTree->GetLeaf(
"timestampCalChi2")->GetValue(n)/
fEventTree->GetLeaf(
"timestampCalDof")->GetValue(n),
568 fEventTree->GetLeaf(
"valueCalChi2")->GetValue(n)/
fEventTree->GetLeaf(
"valueCalDof")->GetValue(n));
569 satur =
fEventTree->GetLeaf(
"valueSaturation")->GetValue(n);
573 if ( TDC != TDC || QDC!=QDC) {
574 LOG (error) <<
"NAN tdc/qdc detected! Check maps!"
575 <<
" " << board_id <<
" " <<
fEventTree->GetLeaf(
"tofpetId")->GetValue(n)
576 <<
" " <<
fEventTree->GetLeaf(
"tofpetChannel")->GetValue(n)
577 <<
" " <<
fEventTree->GetLeaf(
"tac")->GetValue(n)
578 <<
" " <<
fEventTree->GetLeaf(
"tCoarse")->GetValue(n)
579 <<
" " <<
fEventTree->GetLeaf(
"tFine")->GetValue(n)
580 <<
" " <<
fEventTree->GetLeaf(
"vCoarse")->GetValue(n)
581 <<
" " <<
fEventTree->GetLeaf(
"vFine")->GetValue(n);
584 t1 = high_resolution_clock::now();
587 if (QDC>1E20) QDC = 997.;
588 if (QDC != QDC) QDC = 998.;
589 if (QDC>0) QDC = -QDC;
594 if (QDC>1E20) QDC = 987.;
595 LOG (info) <<
"inf " << board_id <<
" " <<
fEventTree->GetLeaf(
"tofpetId")->GetValue(n)
596 <<
" " <<
fEventTree->GetLeaf(
"tofpetChannel")->GetValue(n)
597 <<
" " <<
fEventTree->GetLeaf(
"tac")->GetValue(n)
598 <<
" " <<
fEventTree->GetLeaf(
"vCoarse")->GetValue(n)
599 <<
" " <<
fEventTree->GetLeaf(
"vFine")->GetValue(n)
600 <<
" " << TDC-
fEventTree->GetLeaf(
"tCoarse")->GetValue(n)
602 if (QDC != QDC) QDC = 988.;
603 LOG (info) <<
"nan " << board_id <<
" " <<
fEventTree->GetLeaf(
"tofpetId")->GetValue(n)
604 <<
" " <<
fEventTree->GetLeaf(
"tofpetChannel")->GetValue(n)
605 <<
" " <<
fEventTree->GetLeaf(
"tac")->GetValue(n)
606 <<
" " <<
fEventTree->GetLeaf(
"vCoarse")->GetValue(n)
607 <<
" " <<
fEventTree->GetLeaf(
"vFine")->GetValue(n)
608 <<
" " << TDC-
fEventTree->GetLeaf(
"tCoarse")->GetValue(n)
609 <<
" " << TDC <<
" " <<
fEventTree->GetLeaf(
"tCoarse")->GetValue(n)
611 A = int(min(QDC,
double(1000.)));
612 B = min(satur,
double(999.))/1000.;
618 if (QDC>0) QDC = -QDC;
621 LOG (info) <<
"calibrated: tdc = " << TDC <<
", qdc = " << QDC;
622 t4 = high_resolution_clock::now();
624 counters[
"qdc"]+= duration_cast<nanoseconds>(t1 - t0).count();
625 counters[
"make"]+= duration_cast<nanoseconds>(t4-t0).count();
631 key = (tofpet_id%2)*1000 + tofpet_channel;
633 if (
debug || !tmp.find(
"not") == string::npos )
635 LOG (info) << system <<
" " << key <<
" " << board_name <<
" " << tofpet_id
636 <<
" " << tofpet_id%2 <<
" " << tofpet_channel;
641 cout <<
"key " << key <<
" does not exist. " << endl
642 << board_name <<
" Tofpet id " << tofpet_id
643 <<
" System " << system <<
" has Tofpet map elements: {";
646 cout << it.first <<
" : " << it.second <<
", ";
650 else sipmChannel =
TofpetMap[system][key]-1;
652 nSiPMs = abs(
offMap[tmp][1]);
653 nSides = abs(
offMap[tmp][2]);
654 direction = int(
offMap[tmp][1]/nSiPMs);
655 detID =
offMap[tmp][0] + direction*int(sipmChannel/nSiPMs);
656 sipm_number = sipmChannel%(nSiPMs);
657 if ( tmp.find(
"Right") != string::npos ) sipm_number+= nSiPMs;
664 digiMuFilterStore[detID]->SetDaqID(sipm_number,n, board_id, tofpet_id, tofpet_channel);
667 LOG (info) <<
"create mu hit: " << detID <<
" " << tmp <<
" " << system
668 <<
" " << tofpet_id <<
" " <<
offMap[tmp][0] <<
" " <<
offMap[tmp][1]
669 <<
" " <<
offMap[tmp][2] <<
" " << sipmChannel <<
" " << nSiPMs
670 <<
" " << nSides <<
" " << test << endl
671 << detID <<
" " << sipm_number <<
" " << QDC <<
" " << TDC;
673 if (test>0 || detID%1000>200 || sipm_number>15)
675 cout <<
"what goes wrong? " << detID <<
" SiPM " << sipm_number <<
" system " << system
676 <<
" key " << key <<
" board " << board_name <<
" tofperID " << tofpet_id
677 <<
" tofperChannel " << tofpet_channel <<
" test " << test << endl;
679 t5 = high_resolution_clock::now();
680 counters[
"createMufi"]+= duration_cast<nanoseconds>(t5 - t4).count();
687 if (station[2]==
'Y') orientation = 0;
688 sipmLocal = (chan - mat*512);
689 sipmID = 1000000*int(station[1]-
'0') + 100000*orientation + 10000*mat
690 + 1000*(int(sipmLocal/128)) + chan%128;
696 digiSciFiStore[sipmID]->SetDaqID(0,n,board_id, tofpet_id, tofpet_channel);
698 LOG (info) <<
"create scifi hit: tdc = " << board_name <<
" " << sipmID
699 <<
" " << QDC <<
" " << TDC <<endl
700 <<
"tofpet:" <<
" " << tofpet_id <<
" " << tofpet_channel <<
" " << mat
701 <<
" " << chan << endl
702 << station[1] <<
" " << station[2] <<
" " << mat <<
" " << chan
703 <<
" " << int(chan/128)%4 <<
" " << chan%128;
704 t5 = high_resolution_clock::now();
705 counters[
"createScifi"]+= duration_cast<nanoseconds>(t5 - t4).count();
710 t6 = high_resolution_clock::now();
721 counters[
"storage"]+= duration_cast<nanoseconds>(high_resolution_clock::now() - t6).count();
722 counters[
"event"]+= duration_cast<nanoseconds>(high_resolution_clock::now() - tE).count();
726 LOG (info) <<
fnStart+1 <<
" events processed out of "
727 <<
fEventTree->GetEntries() <<
" number of events in file.";
809 uint32_t bytesRead = 0;
813 ifstream jsonfile(Form(
"%s/board_mapping.json", Path.c_str()));
818 status = file.Open(Form(
"%s/board_mapping.json", Path.c_str()), OpenFlags::Read);
821 LOG (error) <<
"Error opening file";
824 file.Stat(
false, info);
825 size = info->GetSize();
826 char *buff =
new char[size];
827 status = file.Read(offset, size, buff, bytesRead);
829 for (
int i = 0; i < size; i++){vec.push_back(buff[i]);}
830 j = json::parse(vec);
831 status = file.Close();
838 int board_id_mu{}, s{};
842 board_id_mu = stoi(it.first.substr(it.first.find(
"_") + 1));
845 for (
auto slot :
slots )
847 if ( Path.find(
"testbeam_23") == string::npos ) s = 0;
849 tmp = x.second.substr(0, x.second.find(
"_"));
850 if ( tmp ==
"US" ) s = 1;
851 if ( tmp==
"DS" ) s = 2;
852 if (
slots[slot.first] == x.first )
855 boardMaps[
"MuFilter"][it.first][slot.second] = slot.first;
862 for (
int i = 1 ; i < 6; i++ )
866 offMap[Form(
"Veto_%iLeft",i)] = {10000 + (i-1)*1000+ 0, 8, 2};
867 offMap[Form(
"Veto_%iRight",i)] = {10000 + (i-1)*1000+ 0, 8, 2};
869 if (i==3)
offMap[Form(
"Veto_%iVert",i)] = {10000 + (i-1)*1000+ 6, -8, 1};
873 offMap[Form(
"DS_%iLeft",i)] = {30000 + (i-1)*1000+ 59, -1, 2};
874 offMap[Form(
"DS_%iRight",i)] = {30000 + (i-1)*1000+ 59, -1, 2};
878 offMap[Form(
"DS_%iVert",i)] = {30000 + (i-1)*1000+ 119, -1, 1};
880 offMap[Form(
"US_%iLeft",i)] = {20000 + (i-1)*1000+ 9, -8, 2};
881 offMap[Form(
"US_%iRight",i)] = {20000 + (i-1)*1000+ 9, -8, 2};
917tuple<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 )
919 map<string, double> par=
X_qdc[{board_id,tofpet_id,channel,tac}];
920 map<string, double> parT =
X_tdc[{board_id,tofpet_id,channel,tac,TDC}];
922 double ftdc = (-parT[
"b"]-sqrt(pow(parT[
"b"],2)
923 -4*parT[
"a"]*(parT[
"c"]-x)))/(2*parT[
"a"]);
924 double timestamp = t_coarse + ftdc;
925 double tf = timestamp - t_coarse;
927 double fqdc = - par[
"c"]*log(1+exp( par[
"a"]*pow((x-par[
"e"]),2)-par[
"b"]*(x-par[
"e"]) ))
929 double value = (v_fine-fqdc)/GQDC;
930 return make_tuple(timestamp,value,max(par[
"chi2Ndof"],parT[
"chi2Ndof"]),v_fine/par[
"d"]);
934 TH1F* h =
new TH1F(
"chi2",
"chi2", 1000, 0., 10000);
935 map<double, pair<double, double> > report{};
937 double chi2{}, chi2T{}, key{};
939 for (
auto it :
X_qdc)
941 map<string, double> par=
X_qdc[{it.first[0], it.first[1], it.first[2], it.first[3]}];
942 if (par[
"chi2Ndof"]) chi2 = par[
"chi2Ndof"];
944 map<string, double> parT =
X_tdc[{it.first[0], it.first[1], it.first[2], it.first[3], TDC}];
945 if (parT[
"chi2Ndof"]) chi2T = parT[
"chi2Ndof"];
947 key = it.first[3] +10*it.first[2] + it.first[1]*10*100 + it.first[0]*10*100*100;
948 if (report.count(key)==0) report[key] = make_pair(chi2,chi2T);
950 for (
auto it : report)
952 h->Fill(report[it.first].first);
953 h->Fill(report[it.first].second);
974 uint32_t bytesRead = 0;
975 string line, element;
978 vector<int> key_vector{};
982 vector<int> data_vector{};
983 map<string, map<int, vector<int>> > SiPMmap{};
985 map<string, int> key { {
"BM",3}, {
"DS",2}, {
"US",1}, {
"Veto",0} };
987 TString sndRoot = gSystem->Getenv(
"SNDSW_ROOT");
988 string sndswPath = sndRoot.Data();
989 string path_SiPMmap = Form(
"%s/geometry", sndswPath.c_str());
990 if (stat(path_SiPMmap.c_str(), &buffer) != 0)
992 LOG (error) <<
"Path "<< path_SiPMmap.c_str() <<
" does not exist!";
997 infile.open(Form(
"%s/%s_SiPM_mapping.csv", path_SiPMmap.c_str(), sys.first.c_str()));
1003 LOG (info) <<
"In " << sys.first <<
" SiPM map file: " << line;
1005 while (getline(X,line))
1007 data_vector.clear();
1008 stringstream items(line);
1010 getline(items, element,
',');
1011 SiPM = stoi(element);
1013 while (data_vector.size()<4 && getline(items, element,
','))
1015 data_vector.push_back(stoi(element));
1017 SiPMmap[sys.first][SiPM] = data_vector;
1018 if (X.peek() == EOF)
break;
1020 X.str(
string()); X.clear(); line.clear();
1021 size = 0; offset = 0; bytesRead = 0;
1022 for (
auto channel : SiPMmap[sys.first])
1024 row = channel.second;
1025 TofpetMap[sys.second][row.at(2)*1000+row.at(3)] = channel.first;
1035 infile.open(Form(
"%s/qdc_cal.csv", Path.c_str()));
1036 X << infile.rdbuf();
1041 status = file.Open(Form(
"%s/qdc_cal.csv", Path.c_str()), OpenFlags::Read);
1042 if( !status.IsOK() )
1044 LOG (error) <<
"Error opening file";
1047 file.Stat(
false, info);
1048 size = info->GetSize();
1049 char *buff =
new char[size];
1050 status = file.Read(offset, size, buff, bytesRead);
1052 status = file.Close();
1056 LOG (info) <<
"Read_csv "<<Path.c_str();
1059 LOG (info) <<
"In QDC cal file: " << line;
1060 vector<double> qdcData{};
1062 while (getline(X, line))
1065 stringstream items(line);
1066 while (getline(items, element,
','))
1068 if(iscntrl(element[0]))
break;
1069 qdcData.push_back(stof(element));
1071 if (qdcData.size()<10)
continue;
1073 key_vector = {int(qdcData[0]), int(qdcData[1]), int(qdcData[2]), int(qdcData[3])};
1074 chi2_Ndof = (qdcData[9] < 2) ? 999999. : qdcData[7]/qdcData[9];
1075 X_qdc[key_vector] = { {
"a",qdcData[4]}, {
"b",qdcData[5]}, {
"c",qdcData[6]},
1076 {
"d",qdcData[8]}, {
"e",qdcData[10]}, {
"chi2Ndof",chi2_Ndof} };
1077 if (X.peek() == EOF)
break;
1079 X.str(
string()); X.clear(); line.clear();
1080 size = 0; offset = 0; bytesRead = 0;
1084 infile.open(Form(
"%s/tdc_cal.csv", Path.c_str()));
1085 X << infile.rdbuf();
1090 status = file.Open(Form(
"%s/tdc_cal.csv", Path.c_str()), OpenFlags::Read);
1091 if( !status.IsOK() )
1093 LOG (error) <<
"Error opening file";
1096 file.Stat(
false, info);
1097 size = info->GetSize();
1098 char *buff =
new char[size];
1099 status = file.Read(offset, size, buff, bytesRead);
1101 status = file.Close();
1107 LOG (info) <<
"In TDC cal file: " << line;
1108 vector<double> tdcData{};
1110 while (getline(X, line))
1113 stringstream items(line);
1114 if (line.length()<5){
continue;}
1115 while (getline(items, element,
','))
1117 if(iscntrl(element[0]))
break;
1118 tdcData.push_back(stof(element));
1120 if (tdcData.size()<9)
continue;
1122 key_vector = {int(tdcData[0]), int(tdcData[1]), int(tdcData[2]), int(tdcData[3]), int(tdcData[4])};
1123 chi2_Ndof = (tdcData[10] < 2) ? 999999. : tdcData[8]/tdcData[10];
1124 X_tdc[key_vector] = { {
"a",tdcData[5]}, {
"b",tdcData[6]}, {
"c",tdcData[7]},
1125 {
"d",tdcData[9]}, {
"chi2Ndof",chi2_Ndof} };
1126 if (X.peek() == EOF)
break;
1128 X.str(
string()); X.clear(); line.clear();
1129 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)