BmnRoot
Loading...
Searching...
No Matches
BmnTof1Raw2Digit.cxx
Go to the documentation of this file.
1#include "BmnTof1Raw2Digit.h"
2
3// Written by JINR summer programme 2016 student Kurganov Alexander
4
5// Supervisors:
6// Vadim Babkin
7// Mikhail Rumyantsev
8// Vyatcheslav Golovatjuk
9
10typedef std::map<std::pair<UInt_t, UChar_t>, UInt_t>::iterator Tof1PlMapIter;
11typedef std::map<UInt_t, BmnTof1TDCParameters>::iterator Tof1TDCMapIter;
12typedef std::pair<UInt_t, UChar_t> Tof1PlMapKey;
13typedef std::pair<UInt_t, BmnTof1TDCParameters> Tof1TDCMapElem;
14
15using namespace std;
16
18
19// Simple constructors for the BmnTof1Map2 element class
20
21BmnTof1Map2::BmnTof1Map2(Short_t p, Short_t s, Bool_t sd)
22{
23 plane = p;
24 strip = s;
25 side = sd;
26}
27
29{
30 plane = 0;
31 strip = 0;
32 side = false;
33}
34
35// Main constructor for the BmnTof1TDCParameters()
36
38{
39 for (int i = 0; i < TOF1_CHANNEL_NUMBER; i++) {
40 for (int j = 0; j < TOF1_BIN_NUMBER; j++) {
41 INL[i][j] = 0;
42 }
43 ChannelMap[i] = BmnTof1Map2(0, 0, false);
44 t[i] = -1;
45 }
46}
47
48// A small functional class, which is used to compare two BmnTDCDigits
49// It is used to sort by time the TDCDigits in the BmnTof1Raw2Digit::FillEvent()
50
52{
53 return a.GetValue() < b.GetValue();
54}
55
56// A small function, which inserts in the placement map a key-value pair
57// Just to make everything more clear
58
59void BmnTof1Raw2Digit::plmap_insert(UInt_t Serial, UChar_t Slot, UInt_t TDCSerial)
60{
61 PlacementMap.insert(std::pair<Tof1PlMapKey, UInt_t>(Tof1PlMapKey(Serial, Slot), TDCSerial));
62}
63
64// BmnTof1Raw2Digit main constructor
65
70
71// BmnTof1Raw2Digit constructor, which also loads mapping from the DB
72
73BmnTof1Raw2Digit::BmnTof1Raw2Digit(Int_t nPeriod, Int_t nRun, Int_t verbose = 0)
74{
75 fVerbose = verbose;
76 init();
77 setRun(nPeriod, nRun);
78}
79
80// BmnTof1Raw2Digit destructor
81
83
84// BmnTof1Raw2Digit init function (called in BmnTof1Raw2Digit constructors)
85
86void BmnTof1Raw2Digit::init()
87{
88 // Nothing here
89}
90
91// A simple function to convert Hptdcid (0 -- 9) and Hptdc's channel (0 -- 8) to "global" tdc channel (0 -- 72)
92
93UShort_t BmnTof1Raw2Digit::ToGlobalChannel(UChar_t HptdcId, UChar_t channel)
94{
95 return HptdcId * 8 + channel;
96}
97
98// Loads mapping from the DB
99
100Bool_t BmnTof1Raw2Digit::setRun(Int_t nPeriod, Int_t nRun)
101{
102
103 Bool_t flag_temp = kTRUE;
104 if (fVerbose >= 1)
105 printf(ANSI_COLOR_BLUE "Loading the TOF400 Data from DB: Period %d, Run %d ...\n" ANSI_COLOR_RESET, nPeriod,
106 nRun);
107 PeriodIndex = nPeriod;
108 RunIndex = nRun;
109 // return kFALSE;
110 //--------------------------------------------------------------------------
111 // Load the TDC's map (placement map) from the DB
112 if (fVerbose >= 1)
113 cout << "\tLoading the placement map..." << endl;
114 UniDetectorParameter* pLoadedPlacement =
115 UniDetectorParameter::GetDetectorParameter("TOF1", "TOF1_TdcMap", nPeriod, nRun);
116 if (pLoadedPlacement == 0) {
117 printf(ANSI_COLOR_RED "\t\tTOF400 Crucial error: failed to load the placement map\n" ANSI_COLOR_RESET);
118 printf(ANSI_COLOR_RED
119 "\tTDCMap are not loaded\n\tThere will be no TOF400 digits in the output file\n" ANSI_COLOR_RESET);
120 flag_temp = kFALSE;
121 } else {
122 // Get the placement map
123 vector<UniValue*> tdcmap_array;
124 pLoadedPlacement->GetValue(tdcmap_array);
125 MapIntValue* temptdcMap = nullptr;
126 // loop over TDCs stored in the DB
127 for (size_t i = 0; i < tdcmap_array.size(); i++) {
128 temptdcMap = (MapIntValue*)tdcmap_array.at(i);
129 plmap_insert(temptdcMap->serial, temptdcMap->channel, temptdcMap->value);
130 // create TDC in the map
131 TDCMap.insert(Tof1TDCMapElem(temptdcMap->value, BmnTof1TDCParameters()));
132 }
133
134 // Print the result
135 if (fVerbose >= 1)
136 printf("\t\tLoaded %d TDCs\n", (int)tdcmap_array.size());
137 // Free the memory
138 if (!tdcmap_array.empty())
139 for (size_t i = 0; i < tdcmap_array.size(); i++)
140 delete tdcmap_array[i];
141 delete pLoadedPlacement;
142 // delete temptdcMap; //???
143 }
144
145 // Tof1PlMapIter parPair = PlacementMap.begin();
146 // while (parPair != PlacementMap.end()){
147 // printf ("\t%08X \t %08X \t %08X \n", parPair->first.first, parPair->first.second, parPair->second);
148 // parPair++;
149 // }
150 // getchar();
151
152 //--------------------------------------------------------------------------
153 // Load the strip mapping from the DB (TDCs channel -> plane, strip, side).
154 if (fVerbose >= 1)
155 cout << "\tLoading strip map..." << endl;
156 UniDetectorParameter* pLoadedStr =
157 UniDetectorParameter::GetDetectorParameter("TOF1", "TOF1_StripMap", nPeriod, nRun);
158 if (pLoadedStr == 0) {
159 printf(ANSI_COLOR_RED "\t\tTOF400 Crucial error: failed to load the strip map\n" ANSI_COLOR_RESET);
160 printf(ANSI_COLOR_RED
161 "\tStripMap are not loaded\n\tThere will be no TOF400 digits in the output file\n" ANSI_COLOR_RESET);
162 flag_temp = kFALSE;
163 } else {
164 // Get the str map
165 vector<UniValue*> stripmap_array;
166 pLoadedStr->GetValue(stripmap_array);
167 MapDVectorValue* tempstrMap = nullptr;
168 for (size_t i = 0; i < stripmap_array.size(); i++) {
169 tempstrMap = (MapDVectorValue*)stripmap_array.at(i);
170 // Looking for TDC in the map
171 Tof1TDCMapIter TDCPair = TDCMap.find(tempstrMap->serial);
172 if (TDCPair == TDCMap.end()) {
173 printf(ANSI_COLOR_RED "\t\tError: TDC # 0x%08x are not found in the strip map\n" ANSI_COLOR_RESET,
174 tempstrMap->serial);
175 // fill map for this TDC by under range value
176 BmnTof1Map2* elem = &((TDCPair->second).ChannelMap[tempstrMap->channel]);
177 elem->plane = -1;
178 elem->strip = -1;
179 elem->side = TOF1_LEFT;
180 }
181 // get the channel map from
182 BmnTof1Map2* elem = &((TDCPair->second).ChannelMap[tempstrMap->channel]);
183 elem->plane = tempstrMap->value.at(0);
184 elem->strip = tempstrMap->value.at(1);
185 if (tempstrMap->value.at(2) == 0)
186 elem->side = TOF1_LEFT;
187 else if (tempstrMap->value.at(2) == 1)
188 elem->side = TOF1_RIGHT;
189 // cout << std::hex << tempstrMap->serial << std::dec << " ch " << tempstrMap->channel << " -> " <<
190 // tempstrMap->value.at(0) << " " << tempstrMap->value.at(1) << " " << tempstrMap->value.at(2) <<
191 // endl;
192 }
193
194 // Print the result
195 if (fVerbose >= 1)
196 printf("\t\tLoaded %d strips\n", (int)stripmap_array.size());
197 // Free the memory
198 if (!stripmap_array.empty())
199 for (size_t i = 0; i < stripmap_array.size(); i++)
200 delete stripmap_array[i];
201 delete pLoadedStr;
202 // delete tempstrMap; // ???
203 }
204
205 // printf("Check map of TDCs\n");
206 // Tof1TDCMapIter TDCPair = TDCMap.begin();
207 // while (TDCPair != TDCMap.end()) {
208 // printf("TDC %08X; Det = %d;\n", TDCPair->first, TDCPair->second.ChannelMap[0].plane);
209 // ++TDCPair;
210 // }
211 // getchar();
212
213 //--------------------------------------------------------------------------
214 // Load Inl from DB
215 if (fVerbose >= 1)
216 cout << "\tLoading the INL correction from DB... " << endl;
218 "TOF1", "TOF1_inl", nPeriod, nRun); //(detector_name, parameter_name, period_number, run_number)
219 if (pLoadedInl == NULL) {
220 printf(ANSI_COLOR_RED "\tINL are not exist in DB\n\t!! Time information will be wrong !!\n" ANSI_COLOR_RESET);
221 flag_temp = kFALSE; //
222 } else {
223 // get INL from DB to vector
224 vector<UniValue*> inl_array;
225 pLoadedInl->GetValue(inl_array);
226 TdcInlValue* tempInl = nullptr;
227 UInt_t serialtemp;
228 Bool_t flagtemp = false;
229 Tof1TDCMapIter tdcs = TDCMap.begin();
230 // loop over TDCs in the map
231 while (tdcs != TDCMap.end()) {
232 serialtemp = tdcs->first;
233 flagtemp = false;
234
235 // looking for INL for current TDC in the INL_vector from DB
236 for (size_t iv = 0; iv < inl_array.size(); iv++) {
237 tempInl = (TdcInlValue*)inl_array.at(iv);
238 if (tempInl->serial == serialtemp) {
239 if (fVerbose >= 2)
240 cout << "\t\tINL for " << std::hex << serialtemp << std::dec << " are found" << endl;
241 flagtemp = true;
242 for (Int_t ich = 0; ich < TOF1_CHANNEL_NUMBER; ich++)
243 for (Int_t ibin = 0; ibin < TOF1_BIN_NUMBER; ibin++)
244 (tdcs->second).INL[ich][ibin] = tempInl->inl[ich][ibin];
245 }
246 }
247 if (flagtemp == false) {
248 printf(ANSI_COLOR_RED "\t\tError: INL for TDC # 0x%08x are not stored in DB\n" ANSI_COLOR_RESET,
249 serialtemp);
250 // fill INL for this TDC by zero
251 for (Int_t ich = 0; ich < TOF1_CHANNEL_NUMBER; ich++)
252 for (Int_t ibin = 0; ibin < TOF1_BIN_NUMBER; ibin++)
253 (tdcs->second).INL[ich][ibin] = 0.;
254 }
255 // increase iterator
256 tdcs++;
257 }
258 // Free the memory
259 if (!inl_array.empty())
260 for (size_t i = 0; i < inl_array.size(); i++)
261 delete inl_array[i];
262 delete pLoadedInl;
263 if (fVerbose >= 1)
264 cout << "\t\tLoading INL for TOF400 complete." << endl;
265 }
266
267 //--------------------------------------------------------------------------
268 return flag_temp;
269}
270
271// Load mapping from the file
272
273Bool_t BmnTof1Raw2Digit::setMapFromFile(TString placementMapFile, TString mapFile)
274{
275 printf("\tLoad TOF400 mapping from files... \n");
276 UInt_t fcrate, fserial, fslot, fchan, fplane, fstrip;
277 char side_c;
278 Bool_t flag_temp = kTRUE;
279
280 // 1. Placement map
281 fstream ff;
282 ff.open(placementMapFile.Data(), std::fstream::in);
283 if (ff.fail()) {
284 printf(ANSI_COLOR_RED "\t\tError: Cannot open the file %s \n" ANSI_COLOR_RESET, placementMapFile.Data());
285 printf(
287 "\tMap for TOF400 are not loaded\n\tThere will be no TOF400 digits in the output file\n" ANSI_COLOR_RESET);
288 flag_temp = kFALSE;
289 } else {
290 if (fVerbose >= 1)
291 printf("\tReading TOF400 PlacementMap file %s\n", placementMapFile.Data());
292 while (!ff.eof()) {
293 ff >> std::hex >> fcrate >> std::dec >> fslot >> std::hex >> fserial >> std::dec;
294 if (ff.eof()) {
295 break;
296 }
297 plmap_insert(fcrate, fslot, fserial);
298 TDCMap.insert(Tof1TDCMapElem(fserial, BmnTof1TDCParameters()));
299 }
300 if (fVerbose >= 1)
301 printf("\t\tLoaded %d TDCs\n", (int)TDCMap.size());
302 }
303 ff.close();
304
305 // printf ("Check map of TDCs\n");
306 // Tof1PlMapIter plit = PlacementMap.begin();
307 // while (plit != PlacementMap.end()) {
308 // printf ("TTVXS %08X; Slot %d; TDC %08X\n", plit->first.first, plit->first.second, plit->second);
309 // ++plit;
310 // }
311 // getchar();
312
313 // 2. Main map
314 Int_t nLines = 0;
315 ff.open(mapFile.Data(), std::fstream::in);
316 if (ff.fail()) {
317 printf(ANSI_COLOR_RED "\t\tError: Cannot open the file %s \n" ANSI_COLOR_RESET, mapFile.Data());
318 printf(
320 "\tMap for TOF400 are not loaded\n\tThere will be no TOF400 digits in the output file\n" ANSI_COLOR_RESET);
321 flag_temp = kFALSE;
322 } else {
323 if (fVerbose >= 1)
324 printf("\tReading TOF400 StripMap file %s\n", mapFile.Data());
325 while (!ff.eof()) {
326 ff >> std::hex >> fserial >> std::dec >> fchan >> fplane >> fstrip >> side_c;
327 nLines++;
328 if (ff.eof()) {
329 break;
330 }
331 Tof1TDCMapIter TDCPair = TDCMap.find(fserial);
332 if (TDCPair == TDCMap.end()) {
333 printf(ANSI_COLOR_RED "\t\tError: TDC # 0x%08x not found\n" ANSI_COLOR_RESET, fserial);
334 }
335 BmnTof1Map2* elem = &((TDCPair->second).ChannelMap[fchan]);
336 elem->plane = fplane;
337 elem->strip = fstrip;
338 if (side_c == 'L') {
339 elem->side = TOF1_LEFT;
340 } else if (side_c == 'R') {
341 elem->side = TOF1_RIGHT;
342 } else {
343 // cerr << "ToF1 Error: side is not L or R" << endl;
344 continue;
345 }
346 }
347 }
348 ff.close();
349 if (fVerbose >= 1)
350 printf("\t\tLoaded %d strips\n", nLines);
351
352 return flag_temp;
353}
354
355// Save mapping to file
356
357void BmnTof1Raw2Digit::saveMapToFile(string placementMapFile, string mapFile)
358{
359 fstream ff;
360
361 // 1.Placement map
362 ff.open(placementMapFile.c_str(), std::fstream::out);
363 if (ff.fail()) {
364 cerr << "Cannot open the file " << placementMapFile << endl;
365 return;
366 }
367
368 Tof1PlMapIter plit = PlacementMap.begin();
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;
373 ++plit;
374 }
375 ff.close();
376
377 // 2. Main map
378 ff.open(mapFile.c_str(), std::fstream::out);
379 if (ff.fail()) {
380 cerr << "Cannot open the file " << mapFile << endl;
381 return;
382 }
383
384 Tof1TDCMapIter mapit = TDCMap.begin();
385 while (mapit != TDCMap.end()) {
386 for (int i = 0; i < TOF1_CHANNEL_NUMBER; i++) {
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;
392 if (side == TOF1_LEFT) {
393 ff << 'L';
394 } else if (side == TOF1_RIGHT) {
395 ff << 'R';
396 } else {
397 cerr << "Side is not bool." << endl;
398 } // I don't think this can even occur
399 ff << endl;
400 }
401 ++mapit;
402 }
403}
404
405// Save INL to file
406
408{
409 fstream ff(INLFile.c_str(), std::fstream::in);
410 if (ff.fail()) {
411 cerr << "Failed to open " << INLFile << endl;
412 return;
413 }
414 unsigned int TDCSerial;
415
416 // Read the header from the file
417 // The format of the header seems to be [TDC-THESERIAL-inl_corr]
418 ff.ignore(10, '-');
419 ff >> std::hex >> TDCSerial >> std::dec;
420 ff.ignore(1000, '\n');
421
422 // Find the TDC
423 Tof1TDCMapIter TDCPair = TDCMap.find(TDCSerial);
424 if (TDCPair == TDCMap.end()) {
425 cerr << "Tof400: TDC " << std::setfill('0') << std::setw(8) << std::hex << TDCSerial << std::setfill(' ')
426 << std::dec;
427 cerr << " isn't in the placement map." << endl;
428 ff.close();
429 return;
430 }
431
432 unsigned int chan_id = 0;
433 unsigned int lines_num = 0;
434
435 while (!ff.eof()) {
436 string line;
437 char dummy;
438
439 std::getline(ff, line, '\n');
440 if (ff.eof()) {
441 break;
442 }
443 if (line == "") {
444 continue;
445 }
446 istringstream ss(line);
447
448 ss >> chan_id >> dummy;
449 if (dummy != '=') {
450 cerr << "Tof400: Wrong INL file format." << endl;
451 ff.close();
452 return;
453 }
454 if (chan_id > TOF1_CHANNEL_NUMBER) {
455 cerr << "Tof400: Wrong channel in in the INL file" << endl;
456 ff.close();
457 return;
458 }
459
460 double* INLelem = (TDCPair->second).INL[chan_id];
461
462 unsigned int i_bin = 0;
463 while (ss.tellg() != -1) {
464 if (i_bin > TOF1_BIN_NUMBER) {
465 cerr << "Tof400: INL File contains too many bins in channel." << endl;
466 ff.close();
467 return;
468 }
469 if (ss.peek() == ',') {
470 ss.ignore();
471 }
472 ss >> INLelem[i_bin];
473 i_bin++;
474 }
475 if (i_bin != TOF1_BIN_NUMBER) {
476 cout << "Warning: wrong number of bins in the INL file for channel " << chan_id << " (" << i_bin << ")"
477 << endl;
478 }
479 lines_num++;
480 }
481
482 if (lines_num != TOF1_CHANNEL_NUMBER) {
483 cout << "Warning: wrong number of lines in the INL file (" << lines_num << endl;
484 }
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;
487}
488
489// Load INL from file
490
491void BmnTof1Raw2Digit::saveINLToFile(string INLFile, unsigned int TDCSerial)
492{
493 // Find the TDC
494 Tof1TDCMapIter TDCPair = TDCMap.find(TDCSerial);
495 if (TDCPair == TDCMap.end()) {
496 cerr << "Tof400: TDC " << std::setfill('0') << std::setw(8) << std::hex << TDCSerial << std::setfill(' ')
497 << std::dec;
498 cerr << " isn't in the placement map." << endl;
499 return;
500 }
501
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;
505
506 for (int chan = 0; chan < TOF1_CHANNEL_NUMBER; chan++) {
507 ff << chan << "=";
508 double* INLelem = (TDCPair->second).INL[chan];
509 for (int bin = 0; bin < TOF1_BIN_NUMBER; bin++) {
510 ff << INLelem[bin];
511 if (bin != TOF1_BIN_NUMBER - 1) {
512 ff << ", ";
513 }
514 }
515 if (chan != TOF1_CHANNEL_NUMBER - 1) {
516 ff << endl;
517 }
518 }
519
520 ff.close();
521}
522
523// Main function. "Converts" the TObjArray *data of BmnTDCDigit to the TObjArray *output of BmnTof1Digit
524
525void BmnTof1Raw2Digit::FillEvent(TClonesArray* data, unordered_map<UInt_t, Long64_t>* mapTS, TClonesArray* output)
526{
527 // 0. Initialize: clear all the tempory times in the BmnTof1TDCParameters
528 Tof1TDCMapIter tdci = TDCMap.begin();
529 while (tdci != TDCMap.end()) {
530 for (int i = 0; i < TOF1_CHANNEL_NUMBER; i++) {
531 (tdci->second).t[i] = -1;
532 }
533 tdci++;
534 }
535
536 // 1. Filter and sort the TDC Data
537 // TODO: Well.. maybe it's better to do it NOT here?
538 // Maybe both of these should be done in the BmnRawDataDecoder?
539
540 int nOut = output->GetEntries();
541 // nOut variable is needed. GetEntries is quite a slow function,
542 // so storing the number of entries before filling the *output TObjArray works much faster
543
544 multiset<BmnTDCDigit, _Tof1TDCCompare> temp; // Create a multiset
545 // Multiset automaticly sorts the elements in it.
546 //_Tof1TDCCompare functional class is used to compare two BmnTDCDigit (see above)
547
548 // Fill the multiset from the input array (it sorts the input array)
549 TIter it = data->begin();
550 while (it != data->end()) {
551 BmnTDCDigit* obj = static_cast<BmnTDCDigit*>(*it);
552 if (obj->GetType() != TOF1_TDC_TYPE && obj->GetType() != TOF1_TDCVXS_TYPE) {
553 ++it;
554 continue;
555 } // Just skip it in case if TDC is not TDC72VHL (see TOF1_TDC_TYPE define in the .h file)
556 temp.insert(*obj);
557 // cout << std::hex << obj->GetSerial() << " " << std::dec << int(obj->GetSlot()) << " " <<
558 // int(obj->GetHptdcId()) << " " << int(obj->GetChannel()) << " " << (obj->GetLeading()?"L":"T") <<
559 // obj->GetValue() << endl;
560 ++it;
561 }
562
563 // Now a loop over the temp multiset using iterator si
564 multiset<BmnTDCDigit, _Tof1TDCCompare>::iterator si = temp.begin();
565
566 while (si != temp.end()) {
567 // Look for the crate serial and slot in the placement map
568 Tof1PlMapIter parPair = PlacementMap.begin();
569
570 // befor RUN8 BMN TOF400 are used FVME, so in the date we see serial of the trigger modules only and slot number
571 // of the TDC So pair of FVME+slot is key to get serial of TDC (for INL correction and mapping)
572 if (PeriodIndex <= 8 && RunIndex <= 5300) {
573 parPair = PlacementMap.find(std::make_pair<UInt_t, UChar_t>(si->GetSerial(), si->GetSlot()));
574 }
575
576 // Since RUN8 BMN TOF400 use TDC72VXS, so in the date we see serial of the TDC (second value of the map)
577 // But for WR correction we should to know Serial of TTVXS module in the current crate (First.first value of the
578 // map)
579 if (PeriodIndex >= 8 && RunIndex > 5300) {
580 // printf("Looking for TDC %08X in placement map\n", si->GetSerial());
581 while (parPair != PlacementMap.end()) {
582 // printf("Serial of TDC = %08X, Serial of TTVXS = %08X \n", parPair->second,
583 // parPair->first.first);
584 if (parPair->second == si->GetSerial())
585 break;
586 parPair++;
587 }
588 // getchar();
589 }
590 // In case if nothing was found
591 if (parPair == PlacementMap.end()) {
592 // Just skip it
593 si++;
594 continue;
595 // printf(" TDC are not in DB\n");
596 }
597
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()) {
604 si++;
605 continue;
606 }
607 Long64_t TimeShift = itTS->second;
608 // printf(" Time Shift = %lld\n", TimeShift);
609
610 // Get the TDC Serial for this crate serial and slot
611 UInt_t TDC_Serial = parPair->second;
612 // And look for this TDC Serial in the TDCMap to get the BmnTof1TDCParameters for this TDC
613 Tof1TDCMapIter TDCPair = TDCMap.find(TDC_Serial);
614 // In case if TDC Serial isn't in the TDCMap
615 if (TDCPair == TDCMap.end()) {
616 // Display a warning and skip. This is quite a serious error, actually
617 if (fVerbose >= 2)
618 cerr << "Warning: TDC with ID " << std::hex << TDC_Serial << std::dec << ": no data" << endl;
619 si++;
620 continue;
621 }
622
623 // Finally, get the BmnTof1TDCParameters instance for this TDC Serial
624 BmnTof1TDCParameters* par = &(TDCPair->second);
625 // And get it's channel using BmnTof1Raw2Digit::ToGlobalChannel (see above)
626 UShort_t rchan = ToGlobalChannel(si->GetHptdcId(), si->GetChannel());
627
628 // Int_t pl = par->ChannelMap[rchan].plane;
629 // if (si->GetSerial() == 0x07a9b1d6) {
630 // printf("Plane = %d\n", pl);
631 // getchar();
632 // }
633
634 // Get the time from the TDC value
635 // t = (val + INL[channel][val % 1024]) * (24ns / 1024)
636 // See TOF1_BIN_NUMBER and TOF1_MAX_TIME defines in the .h file
637 /*
638 if(par->INL[rchan][(si->GetValue()) % TOF1_BIN_NUMBER] == 0) {
639 cout << std::hex << TDC_Serial << std::dec << rchan << ":" << ((si->GetValue()) % TOF1_BIN_NUMBER) << "
640 - " << par->INL[rchan][(si->GetValue()) % TOF1_BIN_NUMBER] << endl;
641 }
642 */
643 double timeFromDigit = (si->GetValue() + par->INL[rchan][(si->GetValue()) % TOF1_BIN_NUMBER]) * TOF1_MAX_TIME
644 / double(TOF1_BIN_NUMBER);
645
646 if (si->GetLeading()) {
647 // If this is a leading TDC digit, just fill the temporary time in the BmnTof1TDCParameters.
648 par->t[rchan] = timeFromDigit;
649 } else {
650 // If this is NOT a leading TDC Digit...
651 if (par->t[rchan] != -1) {
652 // BmbTof1TDCParameters' temporary time (par->t[rchan]) has been already set
653 // This temporary time should store the leading time
654 if (timeFromDigit < (par->t[rchan]) && fVerbose >= 2) {
655 // This is impossible:
656 // Leading value is larger than the trailing time
657 // The BmnTDCDigit array has already been sorted, so this shouldn't happen
658 // But let's just make sure, this could be a serious error
659 cout << "Error: negative dt" << endl;
660
661 // Print all the TDC Digits we have loaded in the sorted order
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;
667 si2++;
668 }
669 // Print where exactly the error has occured
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;
676 } else {
677 // So we've got the Leading and Trail times and everything seems to be okay
678 // Find the BmnTof1Map2 mapping element, which stores the plane, strip and side.
679 BmnTof1Map2* elem = &(par->ChannelMap[rchan]);
680
681 // Create a new BmnTof1Digit:
682 // Plane, strip, and side are loaded from the found BmnTof1Map2
683 // Leading time is loaded from the temporary storage in the BmnTof1TDCParameters class
684 // Trailing time is just the time in current TDC Digit
685 //(See above: this piece of code is executed only if the current BmnTDCDigit is NOT leading)
686
687 new ((*output)[nOut]) BmnTof1Digit(elem->plane, elem->strip, elem->side, par->t[rchan] + TimeShift,
688 timeFromDigit - (par->t[rchan]));
689 nOut++;
690 }
691 }
692 // We don't need to do anything in case if no leading time has occured yet (if par->t[rchan] == -1)
693
694 // Finally, reset the temporary storage to prevent errors
695 par->t[rchan] = -1;
696 }
697 si++;
698 }
699 if (fVerbose >= 2)
700 printf("TOF400 : %d digits\n", nOut);
701}
std::map< std::pair< UInt_t, UChar_t >, UInt_t >::iterator Tof1PlMapIter
std::pair< UInt_t, UChar_t > Tof1PlMapKey
int Tof1GlobalNameCounter
std::map< UInt_t, BmnTof1TDCParameters >::iterator Tof1TDCMapIter
std::pair< UInt_t, BmnTof1TDCParameters > Tof1TDCMapElem
int i
Definition P4_F32vec4.h:22
#define ANSI_COLOR_RED
Definition BmnMath.h:16
#define ANSI_COLOR_RESET
Definition BmnMath.h:18
#define ANSI_COLOR_BLUE
Definition BmnMath.h:17
UInt_t GetValue() const
Definition BmnTDCDigit.h:32
UChar_t GetType() const
Definition BmnTDCDigit.h:24
Bool_t setRun(Int_t nPerion, Int_t nRun)
void saveINLToFile(std::string INLFile, unsigned int TDCSerial)
static UShort_t ToGlobalChannel(UChar_t HptdcId, UChar_t channel)
Bool_t setMapFromFile(TString placementMapFile, TString mapFile)
void setINLFromFile(std::string INLFile)
void FillEvent(TClonesArray *data, unordered_map< UInt_t, Long64_t > *mapTS, TClonesArray *tof1digit)
void saveMapToFile(std::string placementMapFile, std::string mapFile)
int GetValue(vector< UniValue * > &parameter_value)
get value of detector parameter presented by an array
static UniDetectorParameter * GetDetectorParameter(int value_id)
get detector parameter from the database
#define TOF1_TDC_TYPE
#define TOF1_RIGHT
#define TOF1_CHANNEL_NUMBER
#define TOF1_MAX_TIME
#define TOF1_TDCVXS_TYPE
#define TOF1_BIN_NUMBER
#define TOF1_LEFT
STL namespace.
BmnTof1Map2 ChannelMap[TOF1_CHANNEL_NUMBER]
double t[TOF1_CHANNEL_NUMBER]
double INL[TOF1_CHANNEL_NUMBER][TOF1_BIN_NUMBER]
vector< double > value
double inl[72][1024]
bool operator()(const BmnTDCDigit &a, const BmnTDCDigit &b) const