61 PlacementMap.insert(std::pair<Tof1PlMapKey, UInt_t>(
Tof1PlMapKey(Serial, Slot), TDCSerial));
103 Bool_t flag_temp = kTRUE;
107 PeriodIndex = nPeriod;
113 cout <<
"\tLoading the placement map..." << endl;
116 if (pLoadedPlacement == 0) {
119 "\tTDCMap are not loaded\n\tThere will be no TOF400 digits in the output file\n" ANSI_COLOR_RESET);
123 vector<UniValue*> tdcmap_array;
124 pLoadedPlacement->
GetValue(tdcmap_array);
127 for (
size_t i = 0;
i < tdcmap_array.size();
i++) {
136 printf(
"\t\tLoaded %d TDCs\n", (
int)tdcmap_array.size());
138 if (!tdcmap_array.empty())
139 for (
size_t i = 0;
i < tdcmap_array.size();
i++)
140 delete tdcmap_array[
i];
141 delete pLoadedPlacement;
155 cout <<
"\tLoading strip map..." << endl;
158 if (pLoadedStr == 0) {
161 "\tStripMap are not loaded\n\tThere will be no TOF400 digits in the output file\n" ANSI_COLOR_RESET);
165 vector<UniValue*> stripmap_array;
166 pLoadedStr->
GetValue(stripmap_array);
168 for (
size_t i = 0;
i < stripmap_array.size();
i++) {
172 if (TDCPair == TDCMap.end()) {
185 if (tempstrMap->
value.at(2) == 0)
187 else if (tempstrMap->
value.at(2) == 1)
196 printf(
"\t\tLoaded %d strips\n", (
int)stripmap_array.size());
198 if (!stripmap_array.empty())
199 for (
size_t i = 0;
i < stripmap_array.size();
i++)
200 delete stripmap_array[
i];
216 cout <<
"\tLoading the INL correction from DB... " << endl;
218 "TOF1",
"TOF1_inl", nPeriod, nRun);
219 if (pLoadedInl == NULL) {
224 vector<UniValue*> inl_array;
228 Bool_t flagtemp =
false;
231 while (tdcs != TDCMap.end()) {
232 serialtemp = tdcs->first;
236 for (
size_t iv = 0; iv < inl_array.size(); iv++) {
238 if (tempInl->
serial == serialtemp) {
240 cout <<
"\t\tINL for " << std::hex << serialtemp << std::dec <<
" are found" << endl;
244 (tdcs->second).INL[ich][ibin] = tempInl->
inl[ich][ibin];
247 if (flagtemp ==
false) {
253 (tdcs->second).INL[ich][ibin] = 0.;
259 if (!inl_array.empty())
260 for (
size_t i = 0;
i < inl_array.size();
i++)
264 cout <<
"\t\tLoading INL for TOF400 complete." << endl;
275 printf(
"\tLoad TOF400 mapping from files... \n");
276 UInt_t fcrate, fserial, fslot, fchan, fplane, fstrip;
278 Bool_t flag_temp = kTRUE;
282 ff.open(placementMapFile.Data(), std::fstream::in);
287 "\tMap for TOF400 are not loaded\n\tThere will be no TOF400 digits in the output file\n" ANSI_COLOR_RESET);
291 printf(
"\tReading TOF400 PlacementMap file %s\n", placementMapFile.Data());
293 ff >> std::hex >> fcrate >> std::dec >> fslot >> std::hex >> fserial >> std::dec;
297 plmap_insert(fcrate, fslot, fserial);
301 printf(
"\t\tLoaded %d TDCs\n", (
int)TDCMap.size());
315 ff.open(mapFile.Data(), std::fstream::in);
320 "\tMap for TOF400 are not loaded\n\tThere will be no TOF400 digits in the output file\n" ANSI_COLOR_RESET);
324 printf(
"\tReading TOF400 StripMap file %s\n", mapFile.Data());
326 ff >> std::hex >> fserial >> std::dec >> fchan >> fplane >> fstrip >> side_c;
332 if (TDCPair == TDCMap.end()) {
335 BmnTof1Map2* elem = &((TDCPair->second).ChannelMap[fchan]);
336 elem->
plane = fplane;
337 elem->
strip = fstrip;
340 }
else if (side_c ==
'R') {
350 printf(
"\t\tLoaded %d strips\n", nLines);
362 ff.open(placementMapFile.c_str(), std::fstream::out);
364 cerr <<
"Cannot open the file " << placementMapFile << endl;
369 while (plit != PlacementMap.end()) {
370 ff << std::hex << std::setfill(
'0') << std::setw(8) << plit->first.first <<
'\t';
371 ff << std::dec << int(plit->first.second) <<
'\t';
372 ff << std::hex << std::setfill(
'0') << std::setw(8) << plit->second << endl;
378 ff.open(mapFile.c_str(), std::fstream::out);
380 cerr <<
"Cannot open the file " << mapFile << endl;
385 while (mapit != TDCMap.end()) {
387 ff << std::hex << std::setfill(
'0') << std::setw(8) << mapit->first << std::setfill(
' ') <<
'\t';
388 ff << std::dec <<
i <<
'\t';
389 ff << mapit->second.ChannelMap[
i].plane <<
'\t';
390 ff << mapit->second.ChannelMap[
i].strip <<
'\t';
391 bool side = mapit->second.ChannelMap[
i].side;
397 cerr <<
"Side is not bool." << endl;
409 fstream ff(INLFile.c_str(), std::fstream::in);
411 cerr <<
"Failed to open " << INLFile << endl;
414 unsigned int TDCSerial;
419 ff >> std::hex >> TDCSerial >> std::dec;
420 ff.ignore(1000,
'\n');
424 if (TDCPair == TDCMap.end()) {
425 cerr <<
"Tof400: TDC " << std::setfill(
'0') << std::setw(8) << std::hex << TDCSerial << std::setfill(
' ')
427 cerr <<
" isn't in the placement map." << endl;
432 unsigned int chan_id = 0;
433 unsigned int lines_num = 0;
439 std::getline(ff, line,
'\n');
446 istringstream ss(line);
448 ss >> chan_id >> dummy;
450 cerr <<
"Tof400: Wrong INL file format." << endl;
455 cerr <<
"Tof400: Wrong channel in in the INL file" << endl;
460 double* INLelem = (TDCPair->second).INL[chan_id];
462 unsigned int i_bin = 0;
463 while (ss.tellg() != -1) {
465 cerr <<
"Tof400: INL File contains too many bins in channel." << endl;
469 if (ss.peek() ==
',') {
472 ss >> INLelem[i_bin];
476 cout <<
"Warning: wrong number of bins in the INL file for channel " << chan_id <<
" (" << i_bin <<
")"
483 cout <<
"Warning: wrong number of lines in the INL file (" << lines_num << endl;
485 cout <<
"Tof400: INL for TDC " << std::setfill(
'0') << std::setw(8) << std::hex << TDCSerial << std::setfill(
' ')
486 << std::dec <<
" loaded succesfully from INL file." << endl;
495 if (TDCPair == TDCMap.end()) {
496 cerr <<
"Tof400: TDC " << std::setfill(
'0') << std::setw(8) << std::hex << TDCSerial << std::setfill(
' ')
498 cerr <<
" isn't in the placement map." << endl;
502 fstream ff(INLFile.c_str(), std::fstream::out);
503 ff <<
"[TDC-" << std::setfill(
'0') << std::setw(8) << std::hex << TDCSerial << std::dec << std::setfill(
' ')
504 <<
"-inl_corr]" << endl;
508 double* INLelem = (TDCPair->second).INL[chan];
529 while (tdci != TDCMap.end()) {
531 (tdci->second).t[
i] = -1;
540 int nOut = output->GetEntries();
544 multiset<BmnTDCDigit, _Tof1TDCCompare> temp;
549 TIter it = data->begin();
550 while (it != data->end()) {
564 multiset<BmnTDCDigit, _Tof1TDCCompare>::iterator si = temp.begin();
566 while (si != temp.end()) {
572 if (PeriodIndex <= 8 && RunIndex <= 5300) {
573 parPair = PlacementMap.find(std::make_pair<UInt_t, UChar_t>(si->GetSerial(), si->GetSlot()));
579 if (PeriodIndex >= 8 && RunIndex > 5300) {
581 while (parPair != PlacementMap.end()) {
584 if (parPair->second == si->GetSerial())
591 if (parPair == PlacementMap.end()) {
598 if (PeriodIndex <= 8 && RunIndex <= 5300)
599 fSerialForTS = si->GetSerial();
600 if (PeriodIndex >= 8 && RunIndex > 5300)
601 fSerialForTS = parPair->first.first;
602 auto itTS = mapTS->find(fSerialForTS);
603 if (itTS == mapTS->end()) {
607 Long64_t TimeShift = itTS->second;
611 UInt_t TDC_Serial = parPair->second;
615 if (TDCPair == TDCMap.end()) {
618 cerr <<
"Warning: TDC with ID " << std::hex << TDC_Serial << std::dec <<
": no data" << endl;
646 if (si->GetLeading()) {
648 par->
t[rchan] = timeFromDigit;
651 if (par->
t[rchan] != -1) {
654 if (timeFromDigit < (par->
t[rchan]) && fVerbose >= 2) {
659 cout <<
"Error: negative dt" << endl;
662 multiset<BmnTDCDigit, _Tof1TDCCompare>::iterator si2 = temp.begin();
663 while (si2 != temp.end()) {
664 cout << std::hex << si2->GetSerial() <<
" " << int(si2->GetSlot()) <<
" " << std::dec
665 << int(si2->GetHptdcId()) <<
" " << int(si2->GetChannel()) <<
" "
666 << (si2->GetLeading() ?
"L" :
"T") << si2->GetValue() << endl;
670 cout <<
"Error at: " << endl;
671 cout << std::hex << si->GetSerial() <<
" " << int(si->GetSlot()) <<
" " << std::dec
672 << int(si->GetHptdcId()) <<
" " << int(si->GetChannel()) <<
" "
673 << (si->GetLeading() ?
"L" :
"T") << si->GetValue() << endl;
674 cout << std::hex << TDC_Serial << std::dec <<
" " << rchan <<
" " << (par->
t[rchan]) <<
"--"
675 << timeFromDigit << endl;
688 timeFromDigit - (par->
t[rchan]));
700 printf(
"TOF400 : %d digits\n", nOut);