BOSS 7.0.1
BESIII Offline Software System
Loading...
Searching...
No Matches
TrigMdc.cxx
Go to the documentation of this file.
1#include <iostream>
2#include <fstream>
3#include "TrigEvent/TrigMdc.h"
4#include <stdlib.h>
5using namespace std;
6
7TrigMdc::TrigMdc(const char* name) : m_name(name){
8 // hit
9 m_mdchit_one = new int*[24];
10 for (int i = 0; i < 24; i++) m_mdchit_one[i] = new int[256];
11 m_mdchit_sone = new int*[24];
12 for (int i = 0; i < 24; i++) m_mdchit_sone[i] = new int[256];
13 m_mdchit_pre = new int*[24];
14 for(int i=0; i<24; i++) m_mdchit_pre[i] = new int[256];
15 m_mdchit_aft = new int*[24];
16 for(int i=0; i<24; i++) m_mdchit_aft[i] = new int[256];
17 m_mdchit_win = new uint32_t*[24];
18 for(int i=0; i<24; i++) m_mdchit_win[i] = new uint32_t[256];
19 // tsf
20 m_mdctsf_one = new int*[6];
21 for (int i=0; i<6; i++) m_mdctsf_one[i] = new int[256];
22 m_mdctsf_sone = new int*[6];
23 for (int i=0; i<6; i++) m_mdctsf_sone[i] = new int[256];
24 m_mdctsf_pre = new int*[6];
25 for(int i=0; i<6; i++) m_mdctsf_pre[i] = new int[256];
26 m_mdctsf_aft = new int*[6];
27 for(int i=0; i<6; i++) m_mdctsf_aft[i] = new int[256];
28 m_mdctsf_win = new uint32_t*[6];
29 for(int i=0; i<6; i++) m_mdctsf_win[i] = new uint32_t[256];
30 // ltrk
31 m_mdcltrk_one = new int[128];
32 m_mdcltrk_sone = new int[128];
33 m_mdcltrk_pre = new int[128];
34 m_mdcltrk_aft = new int[128];
35 m_mdcltrk_win = new uint32_t[128];
36 // strk
37 m_mdcstrk_one = new int[128];
38 m_mdcstrk_sone = new int[128];
39 m_mdcstrk_pre = new int[128];
40 m_mdcstrk_aft = new int[128];
41 m_mdcstrk_win = new uint32_t[128];
42 // ltrk in ltrk counter
43 m_mdcltrkc_one = new int[132];
44 m_mdcltrkc_sone= new int[132];
45 // strk in strk counter
46 m_mdcstrkc_one = new int[132];
47 m_mdcstrkc_sone = new int[132];
48 // trigger condition
49 m_mdcTrigCondi = new int[10];
50
51 filename = getenv("TRIGEVENTROOT");
52 filename += "/dat/trig_mdc.txt";
53 ifstream inputfile;
54 inputfile.open(filename.c_str());
55 string data[6];
56 std::vector<uint32_t> vtmp;
57 uint32_t mark = 226;
58 for(uint32_t i = 0; i < 6; i++) inputfile >> data[i];
59 for(uint32_t j = 0; j < 4680; j++) {
60 for(uint32_t k = 0; k < 6; k++) inputfile >> data[k];
61 if((uint32_t (atoi(data[0].c_str())) != mark) || j == 4679) {
62 if(j == 4679) {
63 for(int m = 1; m < 6; m++) vtmp.push_back(atoi(data[m].c_str()));
64 }
65 typedef pair<uint32_t, vector<uint32_t> > vpair;
66 m_datamap.insert(vpair(mark,vtmp));
67 mark = atoi(data[0].c_str());
68 vtmp.clear();
69 }
70 if((uint32_t (atoi(data[0].c_str())) == mark) && j != 4679) {
71 for(int l = 1; l < 6; l++) vtmp.push_back(atoi(data[l].c_str()));
72 }
73 }
74}
75
77 delete m_mdchit_one;
78 delete m_mdctsf_one;
79 delete m_mdchit_sone;
80 delete m_mdctsf_sone;
81
82 delete m_mdchit_pre;
83 // delete m_mdchit_aft;
84
85 delete m_mdcltrk_one;
86 delete m_mdcstrk_one;
87 delete m_mdcltrkc_one;
88 delete m_mdcstrkc_one;
89
90 delete m_mdcltrk_sone;
91 delete m_mdcstrk_sone;
92 delete m_mdcltrkc_sone;
93 delete m_mdcstrkc_sone;
94
95 delete m_mdcTrigCondi;
96}
97
99 //initialize
100 for(int i = 0; i < 24; i++)
101 for(int j = 0; j < 256; j++)
102 {
103 m_mdchit_one[i][j] = 0;
104 m_mdchit_sone[i][j] = 0;
105 m_mdchit_pre[i][j] = 0;
106 m_mdchit_aft[i][j] = 0;
107 m_mdchit_win[i][j] = 0;
108 if(i < 6) {
109 m_mdctsf_one[i][j] = 0;
110 m_mdctsf_sone[i][j] = 0;
111 m_mdctsf_pre[i][j] = 0;
112 m_mdctsf_aft[i][j] = 0;
113 m_mdctsf_win[i][j] = 0;
114 }
115 }
116 for(int k = 0; k < 132; k++)
117 {
118 if(k < 10) m_mdcTrigCondi[k] = 0;
119 m_mdcltrkc_one[k] = 0;
120 m_mdcstrkc_one[k] = 0;
121 m_mdcltrkc_sone[k] = 0;
122 m_mdcstrkc_sone[k] = 0;
123 if(k < 128) {
124 m_mdcltrk_one[k] = 0;
125 m_mdcltrk_sone[k] = 0;
126 m_mdcltrk_pre[k] = 0;
127 m_mdcltrk_aft[k] = 0;
128 m_mdcltrk_win[k] = 0;
129
130 m_mdcstrk_one[k] = 0;
131 m_mdcstrk_sone[k] = 0;
132 m_mdcstrk_pre[k] = 0;
133 m_mdcstrk_aft[k] = 0;
134 m_mdcstrk_win[k] = 0;
135
136 }
137 }
138}
139
140void TrigMdc::setMdcTrigData( uint32_t boardId, uint32_t window, uint32_t datasize, const uint32_t* data){
141 if(datasize%window != 0) cerr<<"ERROR: The data size is not completed in time windows"<<endl;
142 uint32_t periods = datasize/window;
143 std::map<uint32_t, std::vector<uint32_t> >::iterator iter=m_datamap.begin();
144 for(; iter != m_datamap.end(); iter++){
145 if(iter->first != boardId) continue;
146 std::vector<uint32_t>::iterator iter1 = iter->second.begin();
147 for(; iter1 != iter->second.end(); iter1+=5){
148 uint32_t byteId = *(iter1+0) -1;
149 uint32_t bitId = *(iter1+1);
150 int layerId = *(iter1+2) -1;
151 int wireId = *(iter1+3) -1;
152 uint32_t data_type = *(iter1+4);
153 int seriesOne = -100;
154 bool firstSOne = true; // this is a flag of first continue "1" signals
155 bool flag_firstone(true), flag_lastone(true); // whether to book up or down
156 for(uint32_t i=0; i<window; i++){
157 if(layerId < 0 || wireId < 0) continue;
158 if((iter->first) >= 226 && (iter->first) <= 233){ // TKF1-8 information
159 if(data_type == 1){ // hit
160 if((data[byteId + i*periods] >> bitId) & 1){
161 if(layerId >= 36 && layerId <= 39 ){
162 if(flag_firstone && (i-seriesOne!=1) && (i!=0)){ m_mdchit_pre[layerId-16][wireId] = i+1; flag_firstone = false;}
163 if( ((i-seriesOne)!=1) && (m_mdchit_aft[layerId-16][wireId]!=0) ) flag_lastone = false;
164 if( (flag_firstone==false) && ((i-seriesOne)==1) && flag_lastone) m_mdchit_aft[layerId-16][wireId]=i+1;
165 if(((i-seriesOne)==1) && firstSOne) m_mdchit_sone[layerId-16][wireId] += 1;
166 if(m_mdchit_sone[layerId-16][wireId] != 0 && (i-seriesOne) != 1) firstSOne = false;
167 seriesOne = i;
168 m_mdchit_one[layerId-16][wireId] += 1;
169 m_mdchit_win[layerId-16][wireId] += 1<<i;
170 }
171 else {
172 if(flag_firstone && (i-seriesOne!=1) && (i!=0)){ m_mdchit_pre[layerId][wireId] = i+1; flag_firstone = false;}
173 if( ((i-seriesOne)!=1) && (m_mdchit_aft[layerId][wireId]!=0) ) flag_lastone = false;
174 if( (flag_firstone==false) && ((i-seriesOne)==1) && flag_lastone) m_mdchit_aft[layerId][wireId]=i+1;
175 if(((i-seriesOne) == 1) && firstSOne) m_mdchit_sone[layerId][wireId] += 1;
176 if(m_mdchit_sone[layerId][wireId] != 0 && (i-seriesOne) != 1) firstSOne = false;
177 seriesOne = i;
178 m_mdchit_one[layerId][wireId] += 1;
179 m_mdchit_win[layerId][wireId] += 1<<i;
180 }
181 }
182 }
183 if(data_type == 0) { // TSF
184 if((data[byteId + i*periods] >> bitId) & 1) {
185 if(layerId == 10) {
186 if(flag_firstone && (i-seriesOne!=1) && (i!=0)){ m_mdctsf_pre[2][wireId] = i+1; flag_firstone = false;}
187 if( ((i-seriesOne)!=1) && (m_mdctsf_aft[2][wireId]!=0) ) flag_lastone = false;
188 if( (flag_firstone==false) && ((i-seriesOne)==1) && flag_lastone) m_mdctsf_aft[2][wireId]=i+1;
189
190 if((i-seriesOne) == 1 && firstSOne) m_mdctsf_sone[2][wireId] += 1;
191 if(m_mdctsf_sone[2][wireId] != 0 && (i-seriesOne) != 1) firstSOne = false;
192 seriesOne = i;
193 m_mdctsf_one[2][wireId] += 1;
194 m_mdctsf_win[2][wireId] += 1<<i;
195 }
196 if(layerId == 14) {
197 if(flag_firstone && (i-seriesOne!=1) && (i!=0)){ m_mdctsf_pre[3][wireId] = i+1; flag_firstone = false;}
198 if( ((i-seriesOne)!=1) && (m_mdctsf_aft[3][wireId]!=0) ) flag_lastone = false;
199 if( (flag_firstone==false) && ((i-seriesOne)==1) && flag_lastone) m_mdctsf_aft[3][wireId]=i+1;
200
201 if((i-seriesOne) == 1 && firstSOne) m_mdctsf_sone[3][wireId] += 1;
202 if(m_mdctsf_sone[3][wireId] != 0 && (i-seriesOne) != 1) firstSOne = false;
203 seriesOne = i;
204 m_mdctsf_one[3][wireId] += 1;
205 m_mdctsf_win[3][wireId] += 1<<i;
206 }
207 if(layerId == 17) {
208 if(flag_firstone && (i-seriesOne!=1) && (i!=0)){ m_mdctsf_pre[4][wireId] = i+1; flag_firstone = false;}
209 if( ((i-seriesOne)!=1) && (m_mdctsf_aft[4][wireId]!=0) ) flag_lastone = false;
210 if( (flag_firstone==false) && ((i-seriesOne)==1) && flag_lastone) m_mdctsf_aft[4][wireId]=i+1;
211
212 if((i-seriesOne) == 1 && firstSOne) m_mdctsf_sone[4][wireId] += 1;
213 if(m_mdctsf_sone[4][wireId] != 0 && (i-seriesOne) != 1) firstSOne = false;
214 seriesOne = i;
215 m_mdctsf_one[4][wireId] += 1;
216 m_mdctsf_win[4][wireId] += 1<<i;
217 }
218 if(layerId == 37) {
219 if(flag_firstone && (i-seriesOne!=1) && (i!=0)){ m_mdctsf_pre[5][wireId] = i+1; flag_firstone = false;}
220 if( ((i-seriesOne)!=1) && (m_mdctsf_aft[5][wireId]!=0) ) flag_lastone = false;
221 if( (flag_firstone==false) && ((i-seriesOne)==1) && flag_lastone) m_mdctsf_aft[5][wireId]=i+1;
222
223 if((i-seriesOne) == 1 && firstSOne) m_mdctsf_sone[5][wireId] += 1;
224 if(m_mdctsf_sone[5][wireId] != 0 && (i-seriesOne) != 1) firstSOne = false;
225 seriesOne = i;
226 m_mdctsf_one[5][wireId] += 1;
227 m_mdctsf_win[5][wireId] += 1<<i;
228 }
229 }
230 }
231 if(data_type == 2) { // LTK
232 if((data[byteId + i*periods] >> bitId) & 1) {
233 if(flag_firstone && (i-seriesOne!=1) && (i!=0)){ m_mdcltrk_pre[wireId] = i+1; flag_firstone = false;}
234 if( ((i-seriesOne)!=1) && (m_mdcltrk_aft[wireId]!=0) ) flag_lastone = false;
235 if( (flag_firstone==false) && ((i-seriesOne)==1) && flag_lastone) m_mdcltrk_aft[wireId]=i+1;
236
237 if((i-seriesOne) == 1 && firstSOne) m_mdcltrk_sone[wireId] += 1;
238 if(m_mdcltrk_sone[wireId] != 0 && (i-seriesOne) != 1) firstSOne = false;
239 seriesOne = i;
240 m_mdcltrk_one[wireId] += 1;
241 m_mdcltrk_win[wireId] += 1<<i;
242 }
243 }
244 if(data_type == 3) { // STK
245 if((data[byteId + i*periods] >> bitId) & 1) {
246 if(flag_firstone && (i-seriesOne!=1) && (i!=0)){ m_mdcstrk_pre[wireId] = i+1; flag_firstone = false;}
247 if( ((i-seriesOne)!=1) && (m_mdcstrk_aft[wireId]!=0) ) flag_lastone = false;
248 if( (flag_firstone==false) && ((i-seriesOne)==1) && flag_lastone) m_mdcstrk_aft[wireId]=i+1;
249
250 if((i-seriesOne) == 1 && firstSOne) m_mdcstrk_sone[wireId] += 1;
251 if(m_mdcstrk_sone[wireId] != 0 && (i-seriesOne) != 1) firstSOne = false;
252 seriesOne = i;
253 m_mdcstrk_one[wireId] += 1;
254 m_mdcstrk_win[wireId] += 1<<i;
255 }
256 }
257 } // end of TKF1-8
258
259 if((iter->first) == 234) { // ITKF information
260 if(data_type == 0) {
261 if((data[byteId + i*periods] >> bitId) & 1) {
262 if(layerId == 2) {
263 if((i - seriesOne) == 1 && firstSOne) m_mdctsf_sone[0][wireId] += 1;
264 if(m_mdctsf_sone[0][wireId] != 0 && (i - seriesOne) != 1) firstSOne = false;
265 seriesOne = i;
266 m_mdctsf_one[0][wireId] += 1;
267 }
268 if(layerId == 6) {
269 if((i - seriesOne) == 1 && firstSOne) m_mdctsf_sone[1][wireId] += 1;
270 if(m_mdctsf_sone[1][wireId] != 0 && (i - seriesOne) != 1) firstSOne = false;
271 seriesOne = i;
272 m_mdctsf_one[1][wireId] += 1;
273 }
274 }
275 }
276 if(data_type == 1) {
277 if((data[byteId + i*periods] >> bitId) & 1) {
278 if((i - seriesOne) == 1 && firstSOne) m_mdchit_sone[layerId][wireId] += 1;
279 if(m_mdchit_sone[layerId][wireId] != 0 && (i - seriesOne) != 1) firstSOne = false;
280 seriesOne = i;
281 m_mdchit_one[layerId][wireId] += 1;
282 }
283 }
284 if(data_type == 4) {
285 if((data[byteId + i*periods] >> bitId) & 1) {
286 m_mdcTrigCondi[wireId] = 1;
287 }
288 }
289 } // end of ITKF
290
291 if((iter->first) == 235 || (iter->first) == 236) { // LTKC or STKC information
292 if(data_type == 2) {
293 if((data[byteId + i*periods] >> bitId) & 1) {
294 if((i - seriesOne) == 1 && firstSOne) m_mdcltrkc_sone[wireId] += 1;
295 if(m_mdcltrkc_sone[wireId] != 0 && (i - seriesOne) != 1) firstSOne = false;
296 seriesOne = i;
297 m_mdcltrkc_one[wireId] += 1;
298 if(wireId >= 128) m_mdcTrigCondi[wireId - 126] = 1;
299 }
300 }
301 if(data_type == 3) {
302 if((data[byteId + i*periods] >> bitId) & 1) {
303 if((i - seriesOne) == 1 && firstSOne) m_mdcstrkc_sone[wireId] += 1;
304 if(m_mdcstrkc_sone[wireId] != 0 && (i - seriesOne) != 1) firstSOne = false;
305 seriesOne = i;
306 m_mdcstrkc_one[wireId] += 1;
307 if(wireId >= 128) m_mdcTrigCondi[wireId - 122] = 1;
308 }
309 }
310 } //end of LTKC or STKC
311
312 } // loop in windows
313
314 }
315 }
316}
317
319 cout<<"The number of board is "<<m_datamap.size()<<endl;
320 std::map<uint32_t, std::vector<uint32_t> >::iterator iter = m_datamap.begin();
321 if(iter->first == 0xe2)
322 cout<<"The data size of E2 board is "<<iter->second.size()<<endl;
323
324 for(int i = 0; i < 24; i++)
325 for(int j = 0; j < 256; j++)
326 {
327 m_mdchit_one[i][j] = 0;
328 m_mdchit_sone[i][j] = 0;
329 cout<<"MDC hits: "<<i<<" "<<j<<" "<<m_mdchit_one[i][j]<<endl;
330 cout<<"MDC hits: "<<i<<" "<<j<<" "<<m_mdchit_sone[i][j]<<endl;
331 if(i < 6) {
332 m_mdctsf_one[i][j] = 0;
333 m_mdctsf_sone[i][j] = 0;
334 cout<<"MDC tsf: "<<i<<" "<<j<<" "<<m_mdctsf_one[i][j]<<endl;
335 cout<<"MDC tsf: "<<i<<" "<<j<<" "<<m_mdctsf_sone[i][j]<<endl;
336 }
337 }
338 for(int k = 0; k < 132; k++)
339 {
340 m_mdcltrkc_one[k] = 0;
341 m_mdcstrkc_one[k] = 0;
342 m_mdcltrkc_sone[k] = 0;
343 m_mdcstrkc_sone[k] = 0;
344 cout<<"MDC ltrkc: "<<k<<" "<<m_mdcltrkc_one[k]<<endl;
345 cout<<"MDC strkc: "<<k<<" "<<m_mdcstrkc_one[k]<<endl;
346 cout<<"MDC ltrkc: "<<k<<" "<<m_mdcltrkc_sone[k]<<endl;
347 cout<<"MDC strkc: "<<k<<" "<<m_mdcstrkc_sone[k]<<endl;
348 if(k < 128) {
349 m_mdcltrk_one[k] = 0;
350 m_mdcstrk_one[k] = 0;
351 m_mdcltrk_sone[k] = 0;
352 m_mdcstrk_sone[k] = 0;
353 cout<<"MDC ltrk: "<<k<<" "<<m_mdcltrk_one[k]<<endl;
354 cout<<"MDC strk: "<<k<<" "<<m_mdcstrk_one[k]<<endl;
355 cout<<"MDC ltrk: "<<k<<" "<<m_mdcltrk_sone[k]<<endl;
356 cout<<"MDC strk: "<<k<<" "<<m_mdcstrk_sone[k]<<endl;
357 }
358 }
359}
TTree * data
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
virtual ~TrigMdc()
Definition: TrigMdc.cxx:76
TrigMdc(const char *name)
Definition: TrigMdc.cxx:7
void initialize()
Definition: TrigMdc.cxx:98
void print()
Definition: TrigMdc.cxx:318
void setMdcTrigData(uint32_t boardId, uint32_t window, uint32_t datasize, const uint32_t *data)
Definition: TrigMdc.cxx:140