53 return a.GetValue() < b.GetValue();
95 return HptdcId * 8 + channel;
113 cout <<
"\tLoading the placement map..." << endl;
116 if (pLoadedPlacement == 0) {
124 vector<UniValue*> tdcmap_array;
125 pLoadedPlacement->
GetValue(tdcmap_array);
128 for (
size_t i = 0;
i < tdcmap_array.size();
i++) {
137 printf(
"\t\tLoaded %d TDCs\n", (
int)tdcmap_array.size());
139 if (!tdcmap_array.empty())
140 for (
size_t i = 0;
i < tdcmap_array.size();
i++)
141 delete tdcmap_array[
i];
142 delete pLoadedPlacement;
156 cout <<
"\tLoading strip map..." << endl;
159 if (pLoadedStr == 0) {
167 vector<UniValue*> stripmap_array;
168 pLoadedStr->
GetValue(stripmap_array);
170 for (
size_t i = 0;
i < stripmap_array.size();
i++) {
174 if (TDCPair ==
TDCMap.end()) {
187 if (tempstrMap->
value.at(2) == 0)
189 else if (tempstrMap->
value.at(2) == 1)
198 printf(
"\t\tLoaded %d strips\n", (
int)stripmap_array.size());
200 if (!stripmap_array.empty())
201 for (
size_t i = 0;
i < stripmap_array.size();
i++)
202 delete stripmap_array[
i];
217 cout <<
"\tLoading the INL correction from DB... " << endl;
219 "TOF2",
"TOF2_inl", nPeriod, nRun);
220 if (pLoadedInl == NULL) {
225 vector<UniValue*> inl_array;
232 while (tdcs !=
TDCMap.end()) {
233 serialtemp = tdcs->first;
237 for (
size_t iv = 0; iv < inl_array.size(); iv++) {
239 if (tempInl->
serial == serialtemp) {
241 cout <<
"\t\tINL for " << std::hex << serialtemp << std::dec <<
" are found" << endl;
245 (tdcs->second).INL[ich][ibin] = tempInl->
inl[ich][ibin];
250 if (flagtemp ==
false) {
256 (tdcs->second).INL[ich][ibin] = 0.;
262 if (!inl_array.empty())
263 for (
size_t i = 0;
i < inl_array.size();
i++)
267 cout <<
"\t\tLoading INL for TOF701 complete." << endl;
279 UInt_t fcrate, fserial, fslot, fchan, fplane, fstrip;
285 ff.open(placementMapFile.
Data(), std::fstream::in);
290 "\tMap for TOF701 is not loaded\n\tThere will be no TOF701 digits in the output file\n" ANSI_COLOR_RESET);
294 printf(
"\tReading TOF701 PlacementMap file %s\n", placementMapFile.
Data());
296 ff >> std::hex >> fcrate >> std::dec >> fslot >> std::hex >> fserial >> std::dec;
305 printf(
"\t\tLoaded %d TDCs\n", (
int)
TDCMap.size());
319 ff.open(mapFile.
Data(), std::fstream::in);
324 "\tMap for TOF701 is not loaded\n\tThere will be no TOF701 digits in the output file\n" ANSI_COLOR_RESET);
328 printf(
"\tReading TOF701 StripMap file %s\n", mapFile.
Data());
330 ff >> std::hex >> fserial >> std::dec >> fchan >> fplane >> fstrip >> side_c;
336 if (TDCPair ==
TDCMap.end()) {
339 BmnTof701Map2* elem = &((TDCPair->second).ChannelMap[fchan]);
340 elem->
plane = fplane;
341 elem->
strip = fstrip;
344 }
else if (side_c ==
'R') {
347 cerr <<
"ToF701 Error: side is not L or R" << endl;
366 printf(
"\t\tLoaded %d strips\n", nLines);
377 ff.open(placementMapFile.c_str(), std::fstream::out);
379 cerr <<
"Cannot open the file " << placementMapFile << endl;
385 ff << std::hex << std::setfill(
'0') << std::setw(8) << plit->first.first <<
'\t';
386 ff << std::dec << int(plit->first.second) <<
'\t';
387 ff << std::hex << std::setfill(
'0') << std::setw(8) << plit->second << endl;
393 ff.open(mapFile.c_str(), std::fstream::out);
395 cerr <<
"Cannot open the file " << mapFile << endl;
400 while (mapit !=
TDCMap.end()) {
402 ff << std::hex << std::setfill(
'0') << std::setw(8) << mapit->first << std::setfill(
' ') <<
'\t';
403 ff << std::dec <<
i <<
'\t';
404 ff << mapit->second.ChannelMap[
i].plane <<
'\t';
405 ff << mapit->second.ChannelMap[
i].strip <<
'\t';
406 bool side = mapit->second.ChannelMap[
i].side;
412 cerr <<
"Side is not bool." << endl;
424 fstream fList(INLFile.c_str(), std::fstream::in);
426 cerr <<
"Failed to open " << INLFile << endl;
429 TString FileINL[100];
432 TString dir =
Form(
"%s%s", getenv(
"VMCWORKDIR"),
"/input/");
433 while (!fList.eof()) {
437 fList >> FileINL[counter];
438 fstream ff(dir + FileINL[counter], std::fstream::in);
442 ff >> std::hex >> TDCSerial >> std::dec;
443 ff.ignore(100,
'\n');
447 if (TDCPair ==
TDCMap.end()) {
448 cerr <<
"Tof701: TDC " << std::setfill(
'0') << std::setw(8) << std::hex << TDCSerial << std::setfill(
' ')
450 cerr <<
" isn't in the placement map." << endl;
455 unsigned int chan_id = 0;
456 unsigned int lines_num = 0;
462 std::getline(ff, line,
'\n');
469 istringstream ss(line);
471 ss >> chan_id >> dummy;
473 cerr <<
"Tof701: Wrong INL file format." << endl;
478 cerr <<
"Tof701: Wrong channel in in the INL file" << endl;
483 double* INLelem = (TDCPair->second).INL[chan_id];
484 unsigned int i_bin = 0;
485 while (ss.tellg() != -1) {
491 cout <<
"Tof701: INL File contains too many bins in channel."
492 <<
"\tchan_id = " << chan_id <<
"\t TDC = " << std::hex << TDCSerial << endl;
496 if (ss.peek() ==
',') {
499 ss >> INLelem[i_bin];
500 if (i_bin == 0 || i_bin == 1023)
502 cout <<
"WARNING: i_bin = " << i_bin <<
"; INElem = " << INLelem[i_bin] << endl;
519 if (TDCPair ==
TDCMap.end()) {
520 cerr <<
"Tof701: TDC " << std::setfill(
'0') << std::setw(8) << std::hex << TDCSerial << std::setfill(
' ')
522 cerr <<
" isn't in the placement map." << endl;
526 fstream ff(INLFile.c_str(), std::fstream::out);
527 ff <<
"[TDC-" << std::setfill(
'0') << std::setw(8) << std::hex << TDCSerial << std::dec << std::setfill(
' ')
528 <<
"-inl_corr]" << endl;
532 double* INLelem = (TDCPair->second).INL[chan];
553 while (tdci !=
TDCMap.end()) {
555 (tdci->second).t[
i] = -1;
567 multiset<BmnTDCDigit, _Tof701TDCCompare> temp;
573 while (it != data->
end()) {
588 multiset<BmnTDCDigit, _Tof701TDCCompare>::iterator si = temp.begin();
590 while (si != temp.end()) {
597 parPair =
PlacementMap.find(std::make_pair<UInt_t, UChar_t>(si->GetSerial(), si->GetSlot()));
609 if (parPair->second == si->GetSerial()) {
623 printf(
" TDC are not in DB\n");
633 if (itTS == mapTS->end()) {
641 UInt_t TDC_Serial = parPair->second;
646 if (TDCPair ==
TDCMap.end()) {
649 cerr <<
"Warning: TDC with ID " << std::hex << TDC_Serial << std::dec <<
": no data" << endl;
683 if (si->GetLeading()) {
685 par->
t[rchan] = timeFromDigit;
688 if (par->
t[rchan] != -1) {
691 if (timeFromDigit < (par->
t[rchan]) &&
fVerbose >= 2) {
696 cout <<
"Error: negative dt" << endl;
699 multiset<BmnTDCDigit, _Tof701TDCCompare>::iterator si2 = temp.begin();
700 while (si2 != temp.end()) {
701 cout << std::hex << si2->GetSerial() <<
" " << int(si2->GetSlot()) <<
" " << std::dec
702 << int(si2->GetHptdcId()) <<
" " << int(si2->GetChannel()) <<
" "
703 << (si2->GetLeading() ?
"L" :
"T") << si2->GetValue() << endl;
707 cout <<
"Error at: " << endl;
708 cout << std::hex << si->GetSerial() <<
" " << int(si->GetSlot()) <<
" " << std::dec
709 << int(si->GetHptdcId()) <<
" " << int(si->GetChannel()) <<
" "
710 << (si->GetLeading() ?
"L" :
"T") << si->GetValue() << endl;
711 cout << std::hex << TDC_Serial << std::dec <<
" " << rchan <<
" " << (par->
t[rchan]) <<
"--"
712 << timeFromDigit << endl;
725 par->
t[rchan] + TimeShift, timeFromDigit - (par->
t[rchan]));
std::pair< UInt_t, BmnTof701TDCParameters > Tof701TDCMapElem
int Tof701GlobalNameCounter
std::pair< UInt_t, UChar_t > Tof701PlMapKey
std::map< std::pair< UInt_t, UChar_t >, UInt_t >::iterator Tof701PlMapIter
std::map< UInt_t, BmnTof701TDCParameters >::iterator Tof701TDCMapIter
char * Form(const char *fmt,...)
Bool_t setMapFromFile(TString placementMapFile, TString mapFile)
void saveINLToFile(std::string INLFile, unsigned int TDCSerial)
std::map< UInt_t, BmnTof701TDCParameters > TDCMap
void plmap_insert(UInt_t Serial, UChar_t Slot, UInt_t TDCSerial)
void FillEvent(TClonesArray *data, unordered_map< UInt_t, Long64_t > *mapTS, TClonesArray *Tof701digit)
static UShort_t ToGlobalChannel(UChar_t HptdcId, UChar_t channel)
virtual ~BmnTof701Raw2Digit()
Bool_t setRun(Int_t nPerion, Int_t nRun)
std::map< std::pair< UInt_t, UChar_t >, UInt_t > PlacementMap
void saveMapToFile(std::string placementMapFile, std::string mapFile)
void setINLFromFile(std::string INLFile)
Int_t GetEntries() const override
const char * Data() const
int GetValue(vector< UniValue * > ¶meter_value)
get value of detector parameter presented by an array
static UniDetectorParameter * GetDetectorParameter(int value_id)
get detector parameter from the database
#define TOF701_TDCVXS_TYPE
#define TOF701_CHANNEL_NUMBER
#define TOF701_BIN_NUMBER
BmnTof701Map2 ChannelMap[TOF701_CHANNEL_NUMBER]
double INL[TOF701_CHANNEL_NUMBER][TOF701_BIN_NUMBER]
double t[TOF701_CHANNEL_NUMBER]
bool operator()(const BmnTDCDigit &a, const BmnTDCDigit &b) const