BmnRoot
Loading...
Searching...
No Matches
BmnDchRaw2Digit.cxx
Go to the documentation of this file.
1#include "BmnDchRaw2Digit.h"
2
3#include "FairLogger.h"
4
6{
7 ReadMapFromDB(period, run);
8 // ReadMapFromFile(period);
9}
10
11BmnStatus BmnDchRaw2Digit::ReadMapFromDB(Int_t period, Int_t run)
12{
13 if (!fMap1.empty()) {
14 for (size_t i = 0; i < fMap1.size(); i++)
15 delete fMap1[i];
16 fMap1.clear();
17 }
18 if (!fMap2.empty()) {
19 for (size_t i = 0; i < fMap2.size(); i++)
20 delete fMap2[i];
21 fMap2.clear();
22 }
23
24 LOG(info) << "Loading the DCH Map from DB: Period " << period << ", Run " << run << "...";
25
26 UniDetectorParameter* pDetectorParameter1 =
27 UniDetectorParameter::GetDetectorParameter("DCH1", "DCH_mapping", period, run);
28 if (pDetectorParameter1 != NULL)
29 pDetectorParameter1->GetValue(fMap1);
30 UniDetectorParameter* pDetectorParameter2 =
31 UniDetectorParameter::GetDetectorParameter("DCH2", "DCH_mapping", period, run);
32 if (pDetectorParameter2 != NULL)
33 pDetectorParameter2->GetValue(fMap2);
34 delete pDetectorParameter1;
35 delete pDetectorParameter2;
36
37 return kBMNSUCCESS;
38}
39
40BmnStatus BmnDchRaw2Digit::ReadMapFromFile(Int_t period)
41{
42 // TString fileName = Form("DCH_map_Run%d.txt", period);
43 TString fileName = Form("DCH_map_Run%d.txt", period);
44 TString path = TString(getenv("VMCWORKDIR")) + "/input/" + fileName;
45
46 TString dummy;
47 UInt_t ser = 0;
48 Int_t ch_l = 0;
49 Int_t ch_h = 0;
50 Int_t slot = 0;
51 Int_t group = 0;
52 TString name;
53
54 TString planes[16];
55 planes[0] = "VA_1";
56 planes[1] = "VB_1";
57 planes[2] = "UA_1";
58 planes[3] = "UB_1";
59 planes[4] = "YA_1";
60 planes[5] = "YB_1";
61 planes[6] = "XA_1";
62 planes[7] = "XB_1";
63 planes[8] = "VA_2";
64 planes[9] = "VB_2";
65 planes[10] = "UA_2";
66 planes[11] = "UB_2";
67 planes[12] = "YA_2";
68 planes[13] = "YB_2";
69 planes[14] = "XA_2";
70 planes[15] = "XB_2";
71
72 ifstream inFile(path.Data());
73 if (!inFile.is_open())
74 cout << "Error opening map-file (" << path << ")!" << endl;
75 inFile >> dummy >> dummy >> dummy >> dummy >> dummy >> dummy;
76 inFile >> dummy;
77 while (!inFile.eof()) {
78 inFile >> name >> group >> std::hex >> ser >> std::dec >> slot >> ch_l >> ch_h;
79 if (!inFile.good())
80 break;
81 for (Int_t planeId = 0; planeId < 16; ++planeId) {
82 if (name != planes[planeId])
83 continue;
84
85 // printf("%s\t%d\t%d\t0x%x\t%d\t%d\t%d\n", name.Data(), planeId, group, ser, slot, ch_l, ch_h);
86
87 if (planeId / 8 == 0) {
88 DchMapValue* pCurValue = new DchMapValue;
89 pCurValue->plane = planeId;
90 pCurValue->group = group;
91 pCurValue->crate = ser;
92 pCurValue->slot = slot;
93 pCurValue->channel_low = ch_l;
94 pCurValue->channel_high = ch_h;
95 fMap1.push_back(pCurValue);
96 } else {
97 DchMapValue* pCurValue = new DchMapValue;
98 pCurValue->plane = planeId;
99 pCurValue->group = group;
100 pCurValue->crate = ser;
101 pCurValue->slot = slot;
102 pCurValue->channel_low = ch_l;
103 pCurValue->channel_high = ch_h;
104 fMap2.push_back(pCurValue);
105 }
106 }
107 }
108
109 return kBMNSUCCESS;
110}
111
112void BmnDchRaw2Digit::FillEvent(TClonesArray* tdc, unordered_map<UInt_t, Long64_t>* ts, TClonesArray* dch, Double_t t0)
113{
114
115 for (Int_t i = 0; i < tdc->GetEntriesFast(); i++) {
116 BmnTDCDigit* digit = (BmnTDCDigit*)tdc->At(i);
117 if (digit->GetType() != DCH_TDC_TYPE)
118 continue;
119 auto it = ts->find(digit->GetSerial());
120 Long64_t timeShift = (it != ts->end()) ? it->second : 0;
121 if (FindInMap(digit, dch, timeShift, t0, 1) == kBMNERROR)
122 FindInMap(digit, dch, timeShift, t0, 2);
123 }
124}
125
126Int_t BmnDchRaw2Digit::GetChTDC64v(UInt_t tdc, UInt_t ch)
127{
128 // this is some Vishnevsky's magic!
129 // FIXME! What is going here?!
130 const Int_t tdc64v_tdcch2ch[2][32] = {{31, 15, 30, 14, 13, 29, 28, 12, 11, 27, 26, 10, 25, 9, 24, 8,
131 23, 7, 22, 6, 21, 5, 20, 4, 19, 3, 18, 2, 17, 1, 16, 0},
132 {31, 15, 30, 14, 29, 13, 28, 12, 27, 11, 26, 10, 25, 9, 24, 8,
133 23, 7, 22, 6, 21, 5, 20, 4, 19, 3, 18, 2, 17, 1, 16, 0}};
134 Int_t val = tdc64v_tdcch2ch[tdc - 1][ch];
135 if (tdc == 2)
136 val += 32;
137 return val;
138};
139
140BmnStatus BmnDchRaw2Digit::FindInMap(BmnTDCDigit* dig, TClonesArray* arr, Long64_t ts, Double_t t0, Int_t dchId)
141{
142 vector<UniValue*> mapArr = (dchId == 1) ? fMap1 : fMap2;
143 Int_t nEntriesInMap = mapArr.size();
144 for (Int_t iMap = 0; iMap < nEntriesInMap; ++iMap) {
145 DchMapValue* map = (DchMapValue*)mapArr[iMap];
146 if (dig->GetSerial() != map->crate || dig->GetSlot() != map->slot)
147 continue;
148 UChar_t id = dig->GetHptdcId();
149 if ((id < 1) || (id > 2))
150 continue;
151 UInt_t ch = GetChTDC64v(id, dig->GetChannel());
152 if (ch > (UInt_t)map->channel_high || ch < (UInt_t)map->channel_low)
153 continue;
154 Double_t tm = dig->GetValue() / 10.0 - t0 + ts; // divide by 10 for conversion (100 ps -> ns)
155 new ((*arr)[arr->GetEntriesFast()]) BmnDchDigit(map->plane, map->group * 16 + ch - map->channel_low, tm, 0);
156 return kBMNSUCCESS;
157 }
158 return kBMNERROR;
159}
int i
Definition P4_F32vec4.h:22
BmnStatus
Definition BmnEnums.h:24
@ kBMNERROR
Definition BmnEnums.h:26
@ kBMNSUCCESS
Definition BmnEnums.h:25
void FillEvent(TClonesArray *tdc, unordered_map< UInt_t, Long64_t > *ts, TClonesArray *dch, Double_t t0)
UInt_t GetValue() const
Definition BmnTDCDigit.h:32
UInt_t GetSerial() const
Definition BmnTDCDigit.h:22
UChar_t GetHptdcId() const
Definition BmnTDCDigit.h:34
UChar_t GetSlot() const
Definition BmnTDCDigit.h:26
UChar_t GetChannel() const
Definition BmnTDCDigit.h:30
UChar_t GetType() const
Definition BmnTDCDigit.h:24
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 DCH_TDC_TYPE
-clang-format
name
Definition setup.py:7