BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
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
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
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 >> name >> group >> std::hex >> ser >> std::dec >> slot >> ch_l >> ch_h) {
78 for (Int_t planeId = 0; planeId < 16; ++planeId) {
79 if (name != planes[planeId])
80 continue;
81
82 // 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);
83
84 if (planeId / 8 == 0) {
85 DchMapValue* pCurValue = new DchMapValue;
86 pCurValue->plane = planeId;
87 pCurValue->group = group;
88 pCurValue->crate = ser;
89 pCurValue->slot = slot;
90 pCurValue->channel_low = ch_l;
91 pCurValue->channel_high = ch_h;
92 fMap1.push_back(pCurValue);
93 } else {
94 DchMapValue* pCurValue = new DchMapValue;
95 pCurValue->plane = planeId;
96 pCurValue->group = group;
97 pCurValue->crate = ser;
98 pCurValue->slot = slot;
99 pCurValue->channel_low = ch_l;
100 pCurValue->channel_high = ch_h;
101 fMap2.push_back(pCurValue);
102 }
103 }
104 }
105
106 return kBMNSUCCESS;
107}
108
109void BmnDchRaw2Digit::FillEvent(TClonesArray* tdc, unordered_map<UInt_t, Long64_t>* ts, TClonesArray* dch, Double_t t0)
110{
111
112 for (Int_t i = 0; i < tdc->GetEntriesFast(); i++) {
113 BmnTDCDigit* digit = (BmnTDCDigit*)tdc->At(i);
114 if (digit->GetType() != DCH_TDC_TYPE)
115 continue;
116 auto it = ts->find(digit->GetSerial());
117 Long64_t timeShift = (it != ts->end()) ? it->second : 0;
118 if (FindInMap(digit, dch, timeShift, t0, 1) == kBMNERROR)
119 FindInMap(digit, dch, timeShift, t0, 2);
120 }
121}
122
124{
125 // this is some Vishnevsky's magic!
126 // FIXME! What is going here?!
127 const Int_t tdc64v_tdcch2ch[2][32] = {{31, 15, 30, 14, 13, 29, 28, 12, 11, 27, 26, 10, 25, 9, 24, 8,
128 23, 7, 22, 6, 21, 5, 20, 4, 19, 3, 18, 2, 17, 1, 16, 0},
129 {31, 15, 30, 14, 29, 13, 28, 12, 27, 11, 26, 10, 25, 9, 24, 8,
130 23, 7, 22, 6, 21, 5, 20, 4, 19, 3, 18, 2, 17, 1, 16, 0}};
131 Int_t val = tdc64v_tdcch2ch[tdc - 1][ch];
132 if (tdc == 2)
133 val += 32;
134 return val;
135};
136
138{
139 vector<UniValue*> mapArr = (dchId == 1) ? fMap1 : fMap2;
140 Int_t nEntriesInMap = mapArr.size();
141 for (Int_t iMap = 0; iMap < nEntriesInMap; ++iMap) {
142 DchMapValue* map = (DchMapValue*)mapArr[iMap];
143 if (dig->GetSerial() != map->crate || dig->GetSlot() != map->slot)
144 continue;
145 UChar_t id = dig->GetHptdcId();
146 if ((id < 1) || (id > 2))
147 continue;
148 UInt_t ch = GetChTDC64v(id, dig->GetChannel());
149 if (ch > (UInt_t)map->channel_high || ch < (UInt_t)map->channel_low)
150 continue;
151 Double_t tm = dig->GetValue() / 10.0 - t0 + ts; // divide by 10 for conversion (100 ps -> ns)
152 new ((*arr)[arr->GetEntriesFast()]) BmnDchDigit(map->plane, map->group * 16 + ch - map->channel_low, tm, 0);
153 return kBMNSUCCESS;
154 }
155 return kBMNERROR;
156}
int i
Definition P4_F32vec4.h:22
int Int_t
unsigned char UChar_t
unsigned int UInt_t
double Double_t
long long Long64_t
char * Form(const char *fmt,...)
BmnStatus
Define status code.
Definition BmnEnums.h:93
@ kBMNERROR
Error.
Definition BmnEnums.h:95
@ kBMNSUCCESS
Success.
Definition BmnEnums.h:94
BmnStatus ReadMapFromDB(Int_t period, Int_t run)
BmnStatus FindInMap(BmnTDCDigit *dig, TClonesArray *arr, Long64_t ts, Double_t t0, Int_t dchId)
void FillEvent(TClonesArray *tdc, unordered_map< UInt_t, Long64_t > *ts, TClonesArray *dch, Double_t t0)
Int_t GetChTDC64v(UInt_t tdc, UInt_t ch)
vector< UniValue * > fMap1
BmnStatus ReadMapFromFile(Int_t period)
vector< UniValue * > fMap2
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_t GetEntriesFast() const
TObject * At(Int_t idx) const override
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