BmnRoot
Loading...
Searching...
No Matches
BmnProfRawTools.h
Go to the documentation of this file.
1/*
2 *
3 * Author: Yulia Topko
4 */
5#ifndef BMNPROFRAWTOOLS_H
6#define BMNPROFRAWTOOLS_H
7
8#include <stdint.h>
9#include <bitset>
10#include <vector>
11#include <map>
12#include <iostream>
13using namespace std;
14
16public:
17
18 constexpr static const size_t ChannelCnt() {
19 return ASIC_channel;
20 }
21
22 constexpr static const size_t ChannelDigitCnt() {
23 return 6 * ASIC_channel;
24 }
25 //-------------------------------
26 //------ functions
27 //-------------------------------
28 /*
29 Data format
30 | DATA (1)| holdb_cntr | adc_num| fco | hgfedcba ch|
31 | 31 | 30 : 18 | 17 | 16 | 15 : 0 |
32 OR
33 | #Trig(0)| AA - control word | trig_cntr_psd |
34 | #Trig(0)| AB - control word | trig_cntr_nsd |
35 | 31 | 30 : 23 | 22 : 0 |
36
37 Holdb counter width = 13 * 2 = 26;
38 Holdb for every adc.
39
40 trig_p counter width = 23; in adc1
41 trig_n counter width = 23; in adc2
42 */
43
44 static void endian_swap(uint32_t& x);
45 //---------------------
46 // Return value:
47 // true - data
48 // false - trigger
49 //---------------------
50 static bool data_or_trig(const uint32_t& word);
51
52 //---------------------
53 // Return value: holdb counter
54 // if data_or_trig() = true (data)
55 //---------------------
56 static uint32_t holdb_cntr(const uint32_t& word);
57
58 //---------------------
59 // Return value: self-trigger counter
60 // if data_or_trig() = false (trigger)
61 // bool function for P and N detector side
62 //---------------------
63 static bool trig_psd(const uint32_t &word);
64
65 static bool trig_nsd(const uint32_t &word);
66
67 static uint32_t trig_cntr(const uint32_t &word);
68
69 //---------------------
70 // Return value: number of ADC:
71 // 0 - 1st ADC; 1 - 2nd ADC
72 //---------------------
73 static bool adc_num(const bitset<32>& word);
74 static bool adc_num(const uint32_t& word);
75
76 //---------------------
77 // Return value: frame
78 // 0 - data belongs to one frame;
79 // 1 - to another
80 //---------------------
81 static bool fco(const bitset<32>& word);
82 static bool fco(const uint32_t& word);
83
84 //---------------------
85 // Return value:
86 // value of N ADC channel
87 //---------------------
88 static int adc_ch(vector<bitset < 32 >> &adc_word, char channel_name);
89 static int adc_ch(vector<bitset < 32 >> &adc_word, size_t start_index, char channel_name);
90 //static int adc_ch(vector<uint32_t> &adc_word, size_t start_index, char channel_name);
91
92 template<typename UIntType>
93 static int adc_ch(UIntType * adc_word, size_t start_index, char channel_name) {
94 UIntType result = 0;
95 map<char, size_t> offsets{
96 {'A', 0},
97 {'B', 2},
98 {'C', 4},
99 {'D', 6},
100 {'E', 8},
101 {'F', 10},
102 {'G', 12},
103 {'H', 14}};
104 for (size_t i = 0; i < 6; i++) {
105 result += ((adc_word[start_index + i] >> offsets[channel_name]) & 1) << (10 - 2 * i + 1);
106 result += ((adc_word[start_index + i] >> (offsets[channel_name] + 1)) & 1) << (10 - 2 * i);
107 }
108 return result - 0x800;
109 // return result.to_ulong();
110 }
111
112 template<typename UIntType>
113 static int adc_ch(vector<UIntType> adc_word, size_t start_index, char channel_name) {
114 uint32_t result = 0;
115 map<char, size_t> offsets{
116 {'A', 0},
117 {'B', 2},
118 {'C', 4},
119 {'D', 6},
120 {'E', 8},
121 {'F', 10},
122 {'G', 12},
123 {'H', 14}};
124 for (size_t i = 0; i < 6; i++) {
125 result += ((adc_word[start_index + i] >> offsets[channel_name]) & 1) << (10 - 2 * i + 1);
126 result += ((adc_word[start_index + i] >> (offsets[channel_name] + 1)) & 1) << (10 - 2 * i);
127 }
128 return result - 0x800;
129 }
130
131 //---------------------------------------------------
132 // Tracker detector 128x128 strip mapping
133 // Y - n+ readout card 3 and 4
134 // X - p+ readout card 1 and 2
135 // Readout card #1 (X - p+ strips 1-64 ) ADC channel-E.
136 // Readout card #2 (X - p+ strips 65-128) ADC channel-F.
137 // Readout card #3 (Y - n+ strips 65-128) ADC channel-G.
138 // Readout card #4 (Y - n+ strips 1-64 ) ADC channel-H.
139 //---------------------------------------------------
140 //---- beam_tracker_map
141 static vector<int> beam_tracker_map(vector<int> &vec, char adc_channel);
142
143 //---- tracker_X1_chE
144 static vector<int> tracker_X1_chE(vector<int> &vec);
145
146 //---- tracker_X2_chF
147 static vector<int> tracker_X2_chF(vector<int> &vec);
148
149 //----- tracker_Y1_chH
150 static vector<int> tracker_Y1_chH(vector<int> &vec);
151
152 //----- tracker_Y2_chG
153 static vector<int> tracker_Y2_chG(vector<int> &vec);
154
155 //----- tracker_test_signal
156 static vector<int> tracker_tst_sgnl(vector<int> &chE, vector<int> &chF,
157 vector<int> &chH, vector<int> &chG);
158private:
159 static const size_t ASIC_channel = 32; // for the beam profilometer
160};
161
162#endif /* BMNPROFRAWTOOLS_H */
int i
Definition P4_F32vec4.h:22
static bool data_or_trig(const uint32_t &word)
static bool trig_nsd(const uint32_t &word)
static int adc_ch(vector< UIntType > adc_word, size_t start_index, char channel_name)
static vector< int > tracker_X2_chF(vector< int > &vec)
static constexpr const size_t ChannelDigitCnt()
static vector< int > beam_tracker_map(vector< int > &vec, char adc_channel)
static bool fco(const bitset< 32 > &word)
static vector< int > tracker_tst_sgnl(vector< int > &chE, vector< int > &chF, vector< int > &chH, vector< int > &chG)
static uint32_t holdb_cntr(const uint32_t &word)
static int adc_ch(UIntType *adc_word, size_t start_index, char channel_name)
static int adc_ch(vector< bitset< 32 > > &adc_word, char channel_name)
static vector< int > tracker_X1_chE(vector< int > &vec)
static vector< int > tracker_Y2_chG(vector< int > &vec)
static uint32_t trig_cntr(const uint32_t &word)
static constexpr const size_t ChannelCnt()
static bool trig_psd(const uint32_t &word)
static vector< int > tracker_Y1_chH(vector< int > &vec)
static bool adc_num(const bitset< 32 > &word)
static void endian_swap(uint32_t &x)
@ UIntType
STL namespace.