CGEM BOSS 6.6.5.f
BESIII Offline Software System
Loading...
Searching...
No Matches
BesMucTrig.cxx
Go to the documentation of this file.
1//---------------------------------------------------------------------------//
2//// BOOST --- BESIII Object_Oriented Simulation Tool /
3////
4////---------------------------------------------------------------------------/
5////
6////Description: muon trigger research
7////Author: Caogf
8////Created: March, 2007
9////Modified:
10////Comment:
11////
12//
13#include "Trigger/BesMucTrig.h"
14#include "Trigger/MucTrigHit.h"
15
16#include "Trigger/IBesGlobalTrigSvc.h"
17#include "Trigger/BesGlobalTrigSvc.h"
18#include "GaudiKernel/ISvcLocator.h"
19#include "GaudiKernel/Bootstrap.h"
20#include "GaudiKernel/IDataProviderSvc.h"
21
22#include <iostream>
23#include <fstream>
24
25using namespace std;
26
28{
29 m_MucTrigHit = MucTrigHit::get_Muc();
30
31 readIndex();
32}
33
35{
36}
37
39{
40 ISvcLocator* svcLocator = Gaudi::svcLocator();
41 StatusCode sc = svcLocator->service("BesGlobalTrigSvc", m_tmpSvc);
42 m_pIBGT = dynamic_cast<BesGlobalTrigSvc* >(m_tmpSvc);
43
44 //reset values
45 for(int i=0; i<8; i++)
46 {
47 nhitSegBR[i] = 0;
48 for(int j=0; j<4; j++)
49 {
50 nfireLayerBR[i][j] = 0;
51 nhitLayerBR[i][j] = 0;
52 }
53 }
54 nhitBR = 0;
55
56 for(int i=0; i<2; i++)
57 {
58 nhitEC[i] = 0;
59 for(int j=0; j<4; j++)
60 {
61 nhitSegEC[i][j] = 0;
62 for(int k=0; k<4; k++)
63 {
64 nfireLayerEC[i][j][k] = 0;
65 nhitLayerEC[i][j][k] = 0;
66 }
67 }
68 }
69
70 vIndex.clear();
71
72 m_MucTrigHit->getFastOr(); //run fastOr algorithm
73
74 //reset values and get fastOr signal from class MucTrigHit
75 for(int i=0; i<8; i++)
76 for(int j=0; j<4; j++)
77 for(int k=0; k<7; k++)
78 {
79 foBR[i][j][k] = 0;
80 foBR[i][j][k] = m_MucTrigHit->getfoBR(i, j, k);
81 if(foBR[i][j][k] == 1) {
82 nfireLayerBR[i][j] = 1; //fired layer Id of barrel
83 nhitLayerBR[i][j]+=1; //Hit number in each layer of barrel
84 nhitSegBR[i]+=1; //hit number in each segment of barrel
85 nhitBR+=1; //hit number in barrel
86 //1000: barrel, i*100: segment, j*10: gap, k: strip
87 int index = 1000 + i*100 + j*10 + k;
88 vIndex.push_back(index);
89 }
90 }
91
92 for(int i=0; i<2; i++)
93 for(int j=0; j<4; j++)
94 for(int k=0; k<4; k++)
95 for(int l=0; l<4; l++)
96 {
97 foEC[i][j][k][l] = 0;
98 foEC[i][j][k][l] = m_MucTrigHit->getfoEC(i, j, k, l);
99 if(foEC[i][j][k][l]==1) {
100 nfireLayerEC[i][j][k] = 1; //fired layer Id of endcaps
101 nhitLayerEC[i][j][k]+=1; //hit number in each layer of endcaps
102 nhitSegEC[i][j]+=1; //hit number in each segment of endcaps
103 nhitEC[i]+=1; //hit number in endcaps
104 int index;
105 //0: east endcap, 2000: west endcap, j*100: segment, k*10: gap, l: strip
106 if(i==0) index = 0 + j*100 + k*10 + l;
107 if(i==1) index = 2000 + j*100 + k*10 +l;
108 vIndex.push_back(index);
109 }
110 }
111
112 setIndex();
113 findTrack();
114}
116{
117 //find tracks in barrel
118 for(int i=0; i<8; i++)
119 {
120 trackBR[i] = 0;
121 track3lBR[i] = 0;
122 if(i!=2) {
123 for(unsigned int j=0; j<vindexb.size(); j++)
124 {
125 int ly1,ly2,ly3,ly4;
126 ly1 = vindexb[j][0];
127 ly2 = vindexb[j][1]-10;
128 ly3 = vindexb[j][2]-20;
129 ly4 = vindexb[j][3]-30;
130 if((foBR[i][0][ly1]+foBR[i][1][ly2]+foBR[i][2][ly3]+foBR[i][3][ly4])>=3) {
131 trackBR[i]++;
132 break;
133 }
134 if(foBR[i][0][ly1]==1&&foBR[i][2][ly3]==1) { trackBR[i]++; break; }
135 if(foBR[i][1][ly2]==1&&foBR[i][3][ly4]==1) { trackBR[i]++; break; }
136 }
137
138 for(unsigned int j=0; j<vindexb.size(); j++)
139 {
140 int ly1,ly2,ly3,ly4;
141 ly1 = vindexb[j][0];
142 ly2 = vindexb[j][1]-10;
143 ly3 = vindexb[j][2]-20;
144 ly4 = vindexb[j][3]-30;
145 if((foBR[i][0][ly1]+foBR[i][1][ly2]+foBR[i][2][ly3]+foBR[i][3][ly4])>=3) {
146 track3lBR[i]++;
147 break;
148 }
149 }
150 }
151 if(i==2) {
152 for(unsigned int j=0; j<vindexb3.size(); j++)
153 {
154 int ly1,ly2,ly3,ly4;
155 ly1 = vindexb3[j][0];
156 ly2 = vindexb3[j][1]-10;
157 ly3 = vindexb3[j][2]-20;
158 ly4 = vindexb3[j][3]-30;
159 if((foBR[i][0][ly1]+foBR[i][1][ly2]+foBR[i][2][ly3]+foBR[i][3][ly4])>=3) {
160 trackBR[i]++;
161 break;
162 }
163 if(foBR[i][0][ly1]==1&&foBR[i][2][ly3]==1) { trackBR[i]++; break; }
164 if(foBR[i][1][ly2]==1&&foBR[i][3][ly4]==1) { trackBR[i]++; break; }
165 }
166
167 for(unsigned int j=0; j<vindexb3.size(); j++)
168 {
169 int ly1,ly2,ly3,ly4;
170 ly1 = vindexb3[j][0];
171 ly2 = vindexb3[j][1]-10;
172 ly3 = vindexb3[j][2]-20;
173 ly4 = vindexb3[j][3]-30;
174 if((foBR[i][0][ly1]+foBR[i][1][ly2]+foBR[i][2][ly3]+foBR[i][3][ly4])>=3) {
175 track3lBR[i]++;
176 break;
177 }
178 }
179 }
180 }
181
182 //find tracks in endcaps
183 for(int i=0; i<4; i++)
184 {
185 trackEE[i] = 0;
186 trackWE[i] = 0;
187 track3lEE[i] = 0;
188 track3lWE[i] = 0;
189 for(unsigned int j=0; j<vindexe.size(); j++)
190 {
191 int ly1,ly2,ly3,ly4;
192 ly1 = vindexe[j][0];
193 ly2 = vindexe[j][1]-10;
194 ly3 = vindexe[j][2]-20;
195 ly4 = vindexe[j][3]-30;
196 //for east endcap
197 if((foEC[0][i][0][ly1]+foEC[0][i][1][ly2]+foEC[0][i][2][ly3]+foEC[0][i][3][ly4])>=3) {
198 trackEE[i]++;
199 break;
200 }
201 if(foEC[0][i][0][ly1]==1&&foEC[0][i][2][ly3]==1) { trackEE[i]++; break; }
202 if(foEC[0][i][1][ly2]==1&&foEC[0][i][3][ly4]==1) { trackEE[i]++; break; }
203 }
204
205 for(unsigned int j=0; j<vindexe.size(); j++)
206 {
207 int ly1,ly2,ly3,ly4;
208 ly1 = vindexe[j][0];
209 ly2 = vindexe[j][1]-10;
210 ly3 = vindexe[j][2]-20;
211 ly4 = vindexe[j][3]-30;
212 //for west endcap
213 if((foEC[1][i][0][ly1]+foEC[1][i][1][ly2]+foEC[1][i][2][ly3]+foEC[1][i][3][ly4])>=3) {
214 trackWE[i]++;
215 break;
216 }
217 if(foEC[1][i][0][ly1]==1&&foEC[1][i][2][ly3]==1) { trackWE[i]++; break; }
218 if(foEC[1][i][1][ly2]==1&&foEC[1][i][3][ly4]==1) { trackWE[i]++; break; }
219 }
220
221 for(unsigned int j=0; j<vindexe.size(); j++)
222 {
223 int ly1,ly2,ly3,ly4;
224 ly1 = vindexe[j][0];
225 ly2 = vindexe[j][1]-10;
226 ly3 = vindexe[j][2]-20;
227 ly4 = vindexe[j][3]-30;
228 //for east endcap
229 if((foEC[0][i][0][ly1]+foEC[0][i][1][ly2]+foEC[0][i][2][ly3]+foEC[0][i][3][ly4])>=3) {
230 track3lEE[i]++;
231 break;
232 }
233 }
234 for(unsigned int j=0; j<vindexe.size(); j++)
235 {
236 int ly1,ly2,ly3,ly4;
237 ly1 = vindexe[j][0];
238 ly2 = vindexe[j][1]-10;
239 ly3 = vindexe[j][2]-20;
240 ly4 = vindexe[j][3]-30;
241 //for west endcap
242 if((foEC[1][i][0][ly1]+foEC[1][i][1][ly2]+foEC[1][i][2][ly3]+foEC[1][i][3][ly4])>=3) {
243 track3lWE[i]++;
244 break;
245 }
246 }
247 }
248
249 //count the tracks in barrel and endcaps
250 btrack = 0;
251 etrack = 0;
252 int b3ltrack = 0, e3ltrack = 0;
253 for(int i=0; i<8; i++) { btrack = btrack + trackBR[i]; b3ltrack = b3ltrack + track3lBR[i]; }
254 for(int i=0; i<4; i++) { etrack = etrack + trackEE[i] + trackWE[i]; e3ltrack = e3ltrack + track3lWE[i] + track3lEE[i]; }
255
256 //cosmic ray experiment, MUC trigger, 3v7 or 4v8; Or use 3v7 only; Note: use 3/4 logic in both cases
257 bool mucBB3478 = false, mucBB37 = false;
258 if((track3lBR[2] > 0 && track3lBR[6] > 0) || (track3lBR[3] > 0 && track3lBR[7] > 0)) mucBB3478 = true;
259 if(track3lBR[2] > 0 && track3lBR[6] > 0) mucBB37 = true;
260
261 //set muc trigger conditions
262 m_pIBGT->setMucBB3478(mucBB3478);
263 m_pIBGT->setMucBB37(mucBB37);
264
265 //set value in service
266 m_pIBGT->setMucNtrackBR(btrack);
267 m_pIBGT->setMucNtrackEC(etrack);
268 m_pIBGT->setMucN3ltrackTotal(b3ltrack+e3ltrack);
269}
270
271std::vector<int> BesMucTrig::getNlayerSeg()
272{
273 vfireLayer.clear();
274
275 for(int i=0; i<8; i++)
276 {
277 int nlayer = 0;
278 for(int j=0; j<4; j++)
279 {
280 if(nfireLayerBR[i][j] == 1) {
281 nlayer++;
282 }
283 }
284 if(nlayer != 0) {
285 nlayer = 100 + i*10 + nlayer; //100: part(barrel), i*10: segment
286 vfireLayer.push_back(nlayer);
287 }
288 }
289
290 for(int i=0; i<2; i++)
291 for(int j=0; j<4; j++)
292 {
293 int nlayer = 0;
294 for(int k=0; k<4; k++)
295 {
296 if(nfireLayerEC[i][j][k] == 1) {
297 nlayer++;
298 }
299 }
300 if(nlayer != 0) {
301 if(i==0) nlayer = 0 + j*10 + nlayer; //0: east endcaps, j*10: jth segment
302 else nlayer = 200 + j*10 + nlayer; //200: west endcap, j*10: jth segment
303 vfireLayer.push_back(nlayer);
304 }
305 }
306 return vfireLayer;
307}
308
310{
311 int nLayerBR = 0, nLayerWE = 0, nLayerEE = 0;
312 //count the barrel fired layer number
313 for(int i=0; i<8; i++)
314 for(int j=0; j<4; j++)
315 {
316 if(nfireLayerBR[i][j] == 1) {
317 nLayerBR++;
318 }
319 }
320 //count each endcap fired layer number
321 for(int i=0; i<2; i++)
322 for(int j=0; j<4; j++)
323 for(int k=0; k<4; k++)
324 {
325 if(nfireLayerEC[i][j][k] == 1) {
326 if(i==0) nLayerEE++;
327 if(i==1) nLayerWE++;
328 }
329 }
330
331 if(part == 0) return nLayerEE;
332 if(part == 1) return nLayerBR;
333 if(part == 2) return nLayerWE;
334
335 return -1;
336}
337
338std::vector<int> BesMucTrig::getNhitLayer()
339{
340 vhitLayer.clear();
341
342 for(int i=0; i<8; i++)
343 for(int j=0; j<4; j++)
344 {
345 if(nhitLayerBR[i][j] != 0) {
346 //1000: barrel, i*100: ith segment, j*10: jth gap, nhitLayerBR[i][j]: the number of hits
347 int hit = 1000 + i*100 + j*10 + nhitLayerBR[i][j];
348 vhitLayer.push_back(hit);
349 }
350 }
351
352 for(int i=0; i<2; i++)
353 for(int j=0; j<4; j++)
354 for(int k=0; k<4; k++)
355 {
356 if(nhitLayerEC[i][j][k] != 0) {
357 int hit;
358 //0: east endcaps, j*100: jth segment, k*10: kth gap, nhitLayerEC[i][j][k]: the number of hits
359 if(i==0) hit = 0 + j*100 + k*10 + nhitLayerEC[i][j][k];
360 //2000: west endcap, j*100: jth segment, k*10: kth gap, nhitLayerEC[i][j][k]: the number of hits
361 else hit = 2000 + j*100 + k*10 + nhitLayerEC[i][j][k];
362 vhitLayer.push_back(hit);
363 }
364 }
365 return vhitLayer;
366}
367
368std::vector<int> BesMucTrig::getNhitSeg()
369{
370 vhitSeg.clear();
371
372 for(int i=0; i<8; i++)
373 {
374 if(nhitSegBR[i] != 0) {
375 //1000: barrel, i*100: ith segment,tSegBR[i]: the number of hits
376 int hit = 1000 + i*100 + nhitSegBR[i];
377 vhitSeg.push_back(hit);
378 }
379 }
380
381 for(int i=0; i<2; i++)
382 for(int j=0; j<4; j++)
383 {
384 if(nhitSegEC[i][j] != 0) {
385 int hit;
386 //0: east endcaps, j*100: jth segment, nhitSegEC[i][j]: the number of hits
387 if(i==0) hit = 0 + j*100 + nhitSegEC[i][j];
388 //2000: west endcap, j*100: jth segment, nhitSegEC[i][j]: the number of hits
389 else hit = 2000 + j*100 + nhitSegEC[i][j];
390 vhitSeg.push_back(hit);
391 }
392 }
393 return vhitSeg;
394}
395
397{
398 if(i == 1) return nhitBR;
399 if(i == 0) return nhitEC[0];
400 if(i == 2) return nhitEC[1];
401
402 return -1;
403}
404
406{
407 int total = nhitBR + nhitEC[0] + nhitEC[1];
408 return total;
409}
410
412{
413 m_pIBGT->setMucIndex(vIndex);
414}
415
417{
418 fstream infile1;
419 fstream infile2;
420 fstream infile3;
421
422 vindexb.clear();
423 vindexb3.clear();
424 vindexe.clear();
425
426 std::string filename = std::string(getenv( "TRIGGERROOT" ));
427 std::string filename1 = filename + "/data/mufield0.5_1.5GeV_cos0.76_phi456thseg_index_select.txt";
428 std::string filename2 = filename + "/data/mufield0.5_1.5GeV_cos0.76_phi234thseg_index_select.txt";
429 std::string filename3 = filename + "/data/mufield0.5_1.5GeV_ee2_index_select.txt";
430 infile1.open(filename1.c_str(), ios_base::in);
431 infile2.open(filename2.c_str(), ios_base::in);
432 infile3.open(filename3.c_str(), ios_base::in);
433
434 char line[255];
435 char* token;
436 std::string str;
437
438 if(!infile1) cout<<"open file1 failture"<<endl;
439 while(infile1) {
440 infile1.getline( line, 255 );
441 token = strtok( line, " " );
442 int num = 0;
443 std::vector<int> tmp;
444 tmp.clear();
445 do{
446 if(token) {
447 str = token;
448 token = strtok(NULL," ");
449 int Index = atoi(str.c_str());
450 if(num != 0) tmp.push_back(Index);
451 num++;
452 }
453 else continue;
454 }while (token!=NULL);
455 if(tmp.size() == 4) vindexb.push_back(tmp);
456 }
457 cout<<"total "<<vindexb.size()<<" index in barrel have been read!"<<endl;
458
459
460 if(!infile2) cout<<"open file2 failture"<<endl;
461 while(infile2) {
462 infile2.getline( line, 255 );
463 token = strtok( line, " " );
464 int num = 0;
465 std::vector<int> tmp;
466 tmp.clear();
467 do{
468 if(token) {
469 str = token;
470 token = strtok(NULL," ");
471 int Index = atoi(str.c_str());
472 if(num != 0) tmp.push_back(Index);
473 num++;
474 }
475 else continue;
476 }while (token!=NULL);
477 if(tmp.size() == 4) vindexb3.push_back(tmp);
478 }
479 cout<<"total "<<vindexb3.size()<<" index in barrel 3 have been read!"<<endl;
480
481 if(!infile3) cout<<"open file3 failture"<<endl;
482 while(infile3) {
483 infile3.getline( line, 255 );
484 token = strtok( line, " " );
485 int num = 0;
486 std::vector<int> tmp;
487 tmp.clear();
488 do{
489 if(token) {
490 str = token;
491 token = strtok(NULL," ");
492 int Index = atoi(str.c_str());
493 if(num != 0) tmp.push_back(Index);
494 num++;
495 }
496 else continue;
497 }while (token!=NULL);
498 if(tmp.size() == 4) vindexe.push_back(tmp);
499 }
500 cout<<"total "<<vindexe.size()<<" index in endcap have been read!"<<endl;
501
502 infile1.close();
503 infile2.close();
504 infile3.close();
505}
void readIndex()
Definition: BesMucTrig.cxx:416
void startMucTrig()
Definition: BesMucTrig.cxx:38
void setIndex()
Definition: BesMucTrig.cxx:411
std::vector< int > getNlayerSeg()
Definition: BesMucTrig.cxx:271
int getNlayerPart(int part)
Definition: BesMucTrig.cxx:309
void findTrack()
Definition: BesMucTrig.cxx:115
std::vector< int > getNhitLayer()
Definition: BesMucTrig.cxx:338
int getNhitTotal()
Definition: BesMucTrig.cxx:405
int getNhitPart(int i)
Definition: BesMucTrig.cxx:396
std::vector< int > getNhitSeg()
Definition: BesMucTrig.cxx:368
int getfoEC(int i, int j, int k, int l)
static MucTrigHit * get_Muc(void)
Definition: MucTrigHit.cxx:24
void getFastOr()
Definition: MucTrigHit.cxx:71
int num[96]
Definition: ranlxd.c:373