BOSS 7.0.4
BESIII Offline Software System
Loading...
Searching...
No Matches
BesTMTrig.cxx
Go to the documentation of this file.
1//---------------------------------------------------------------------------//
2//// BOOST --- BESIII Object_Oriented Simulation Tool /
3////
4////---------------------------------------------------------------------------/
5////
6////Description:
7////Author: Caogf
8////Created: Sep, 2008
9////Modified:
10////Comment:
11////
12//
13#include "Trigger/BesTMTrig.h"
14#include <algorithm>
15#include <iostream>
16#include <fstream>
17#include "Trigger/IBesGlobalTrigSvc.h"
18#include "Trigger/BesGlobalTrigSvc.h"
19#include "GaudiKernel/ISvcLocator.h"
20#include "GaudiKernel/Bootstrap.h"
21#include "GaudiKernel/IDataProviderSvc.h"
22#include <map>
23
25 char line[255];
26 std::string filename = std::string(getenv( "TRIGGERROOT" ));
27 filename += std::string("/data/tm/TM_BARREL.pat");
28 std::ifstream infile( filename.c_str() );
29 if(infile) {
30 while(infile) {
31 infile.getline(line,255);
32 if(line[0] == '#') continue;
33 std::string mdcId, tofId_l, tofId_h, emcId_l, emcId_h;
34 char* token = strtok( line, " " );
35 if ( token ) { mdcId = token; token = strtok( NULL, " " );} else continue;
36 if ( token ) { tofId_l = token; token = strtok( NULL, " " );} else continue;
37 if ( token ) { tofId_h = token; token = strtok( NULL, " " );} else continue;
38 if ( token ) { emcId_l = token; token = strtok( NULL, " " );} else continue;
39 if ( token ) { emcId_h = token; token = strtok( NULL, " " );} else continue;
40 if ( token != NULL ) continue;
41 //Convert to int
42 //int i_mdcId = atoi( mdcId.c_str() );
43 int i_tofId_l = atoi( tofId_l.c_str() );
44 int i_tofId_h = atoi( tofId_h.c_str() );
45 int i_emcId_l = atoi( emcId_l.c_str() );
46 int i_emcId_h = atoi( emcId_h.c_str() );
47 //std::cout << "MdcId TofId_L TofId_H EmcId_L EmcId_H: " << i_mdcId << ", " << i_tofId_l <<", " << i_tofId_h << ", " << i_emcId_l << ", " << i_emcId_h << std::endl;
48 std::vector<int> tof_tmp;
49 std::vector<int> emc_tmp;
50 //for tof
51 if(i_tofId_l > i_tofId_h) {
52 for(int i = i_tofId_l; i <= (i_tofId_h + 88); i++) {
53 if(i >= 88) tof_tmp.push_back(i - 88);
54 else tof_tmp.push_back(i);
55 }
56 }
57 else {
58 for(int i = i_tofId_l; i <= i_tofId_h; i++) {
59 tof_tmp.push_back(i);
60 }
61 }
62 //for emc
63 if(i_emcId_l > i_emcId_h) {
64 for(int i = i_emcId_l; i <= (i_emcId_h + 30); i++) {
65 if(i >= 30) emc_tmp.push_back(i - 30);
66 else emc_tmp.push_back(i);
67 }
68 }
69 else {
70 for(int i = i_emcId_l; i <= i_emcId_h; i++) {
71 emc_tmp.push_back(i);
72 }
73 }
74 m_tm_barrel.push_back(tof_tmp);
75 m_tm_barrel.push_back(emc_tmp);
76 }
77 }
78 else {
79 std::cout << "Can not open file: " << filename << " in BesTMTrig. " << std::endl;
80 }
81 //read track match east endcap
82 filename = std::string(getenv( "TRIGGERROOT" ));
83 filename += std::string("/data/tm/TM_EAST_ENDCAP.pat");
84 std::ifstream infile1( filename.c_str() );
85 if(infile1) {
86 while(infile1) {
87 infile1.getline(line,255);
88 if(line[0] == '#') continue;
89 std::string mdcId, tofId_l, tofId_h, emcId_l, emcId_h;
90 char* token = strtok( line, " " );
91 if ( token ) { mdcId = token; token = strtok( NULL, " " );} else continue;
92 if ( token ) { tofId_l = token; token = strtok( NULL, " " );} else continue;
93 if ( token ) { tofId_h = token; token = strtok( NULL, " " );} else continue;
94 if ( token ) { emcId_l = token; token = strtok( NULL, " " );} else continue;
95 if ( token ) { emcId_h = token; token = strtok( NULL, " " );} else continue;
96 if ( token != NULL ) continue;
97 //Convert to int
98 //int i_mdcId = atoi( mdcId.c_str() );
99 int i_tofId_l = atoi( tofId_l.c_str() );
100 int i_tofId_h = atoi( tofId_h.c_str() );
101 int i_emcId_l = atoi( emcId_l.c_str() );
102 int i_emcId_h = atoi( emcId_h.c_str() );
103 //std::cout << "MdcId TofId_L TofId_H EmcId_L EmcId_H: " << i_mdcId << ", " << i_tofId_l <<", " << i_tofId_h << ", " << i_emcId_l << ", " << i_emcId_h << std::endl;
104 std::vector<int> tof_tmp;
105 std::vector<int> emc_tmp;
106 //for tof
107 if(i_tofId_l > i_tofId_h) {
108 for(int i = i_tofId_l; i <= (i_tofId_h + 24); i++) {
109 if(i >= 24) tof_tmp.push_back(i - 24);
110 else tof_tmp.push_back(i);
111 }
112 }
113 else {
114 for(int i = i_tofId_l; i <= i_tofId_h; i++) {
115 tof_tmp.push_back(i);
116 }
117 }
118 //for emc
119 if(i_emcId_l > i_emcId_h) {
120 for(int i = i_emcId_l; i <= (i_emcId_h + 16); i++) {
121 if(i >= 16) emc_tmp.push_back(i - 16);
122 else emc_tmp.push_back(i);
123 }
124 }
125 else {
126 for(int i = i_emcId_l; i <= i_emcId_h; i++) {
127 emc_tmp.push_back(i);
128 }
129 }
130 m_tm_ecap.push_back(tof_tmp);
131 m_tm_ecap.push_back(emc_tmp);
132 }
133 }
134 else {
135 std::cout << "Can not open file: " << filename << " in BesTMTrig. " << std::endl;
136 }
137
138 //read track match west endcap
139 filename = std::string(getenv( "TRIGGERROOT" ));
140 filename += std::string("/data/tm/TM_WEST_ENDCAP.pat");
141 std::ifstream infile2( filename.c_str() );
142 if(infile2) {
143 while(infile2) {
144 infile2.getline(line,255);
145 if(line[0] == '#') continue;
146 std::string mdcId, tofId_l, tofId_h, emcId_l, emcId_h;
147 char* token = strtok( line, " " );
148 if ( token ) { mdcId = token; token = strtok( NULL, " " );} else continue;
149 if ( token ) { tofId_l = token; token = strtok( NULL, " " );} else continue;
150 if ( token ) { tofId_h = token; token = strtok( NULL, " " );} else continue;
151 if ( token ) { emcId_l = token; token = strtok( NULL, " " );} else continue;
152 if ( token ) { emcId_h = token; token = strtok( NULL, " " );} else continue;
153 if ( token != NULL ) continue;
154 //Convert to int
155 //int i_mdcId = atoi( mdcId.c_str() );
156 int i_tofId_l = atoi( tofId_l.c_str() );
157 int i_tofId_h = atoi( tofId_h.c_str() );
158 int i_emcId_l = atoi( emcId_l.c_str() );
159 int i_emcId_h = atoi( emcId_h.c_str() );
160 //std::cout << "MdcId TofId_L TofId_H EmcId_L EmcId_H: " << i_mdcId << ", " << i_tofId_l <<", " << i_tofId_h << ", " << i_emcId_l << ", " << i_emcId_h << std::endl;
161 std::vector<int> tof_tmp;
162 std::vector<int> emc_tmp;
163 //for tof
164 if(i_tofId_l > i_tofId_h) {
165 for(int i = i_tofId_l; i <= (i_tofId_h + 24); i++) {
166 if(i >= 24) tof_tmp.push_back(i - 24);
167 else tof_tmp.push_back(i);
168 }
169 }
170 else {
171 for(int i = i_tofId_l; i <= i_tofId_h; i++) {
172 tof_tmp.push_back(i);
173 }
174 }
175 //for emc
176 if(i_emcId_l > i_emcId_h) {
177 for(int i = i_emcId_l; i <= (i_emcId_h + 16); i++) {
178 if(i >= 16) emc_tmp.push_back(i - 16);
179 else emc_tmp.push_back(i);
180 }
181 }
182 else {
183 for(int i = i_emcId_l; i <= i_emcId_h; i++) {
184 emc_tmp.push_back(i);
185 }
186 }
187 m_tm_wcap.push_back(tof_tmp);
188 m_tm_wcap.push_back(emc_tmp);
189 }
190 }
191 else {
192 std::cout << "Can not open file: " << filename << " in BesTMTrig. " << std::endl;
193 }
194 infile.close();
195 infile1.close();
196 infile2.close();
197 //dump();
198}
199
201}
202
204 std::cout << "The size of barrel vector: " << m_tm_barrel.size() << std::endl;
205 std::cout << "The size of east endcap vector: " << m_tm_ecap.size() << std::endl;
206 std::cout << "The size of west endcap vector: " << m_tm_wcap.size() << std::endl;
207 std::cout << "--------------------------- BARREL -----------------------------" << std::endl;
208 for(unsigned int i = 0; i < m_tm_barrel.size(); i+=2) {
209 std::cout << "MdcId is " << i/2 << " TofId size " << m_tm_barrel[i].size() <<
210 " Id " << m_tm_barrel[i][0] << " " << m_tm_barrel[i][m_tm_barrel[i].size() - 1] << std::endl;
211 std::cout << "MdcId is " << i/2 << " EmcId size " << m_tm_barrel[i+1].size() <<
212 " Id " << m_tm_barrel[i+1][0] << " " << m_tm_barrel[i+1][m_tm_barrel[i+1].size() - 1] << std::endl;
213 }
214 std::cout << "--------------------------- EAST ENDCAP -----------------------------" << std::endl;
215 for(unsigned int i = 0; i < m_tm_ecap.size(); i+=2) {
216 std::cout << "MdcId is " << i/2 << " TofId size " << m_tm_ecap[i].size() <<
217 " Id " << m_tm_ecap[i][0] << " " << m_tm_ecap[i][m_tm_ecap[i].size() - 1] << std::endl;
218 std::cout << "MdcId is " << i/2 << " EmcId size " << m_tm_ecap[i+1].size() <<
219 " Id " << m_tm_ecap[i+1][0] << " " << m_tm_ecap[i+1][m_tm_ecap[i+1].size() - 1] << std::endl;
220 }
221 std::cout << "--------------------------- WEST ENDCAP -----------------------------" << std::endl;
222 for(unsigned int i = 0; i < m_tm_wcap.size(); i+=2) {
223 std::cout << "MdcId is " << i/2 << " TofId size " << m_tm_wcap[i].size() <<
224 " Id " << m_tm_wcap[i][0] << " " << m_tm_wcap[i][m_tm_wcap[i].size() - 1] << std::endl;
225 std::cout << "MdcId is " << i/2 << " EmcId size " << m_tm_wcap[i+1].size() <<
226 " Id " << m_tm_wcap[i+1][0] << " " << m_tm_wcap[i+1][m_tm_wcap[i+1].size() - 1] << std::endl;
227 }
228}
229
231 ISvcLocator* svcLocator = Gaudi::svcLocator();
232 StatusCode sc = svcLocator->service("BesGlobalTrigSvc", m_tmpSvc);
233 m_pIBGT = dynamic_cast<BesGlobalTrigSvc* >(m_tmpSvc);
234
235 //find mdc track id used in track match
236 std::vector<int> tm_mdcstrkId;
237 std::vector<int> tm_mdcltrkId;
238 std::vector<int> mdcstrkId = m_pIBGT->getMdcStrkId();
239 std::vector<int> mdcltrkId = m_pIBGT->getMdcLtrkId();
240 for(unsigned int i = 0; i < mdcstrkId.size(); i++)
241 {
242 int trackId = int (mdcstrkId[i]/2);
243 if(find(tm_mdcstrkId.begin(),tm_mdcstrkId.end(),trackId) == tm_mdcstrkId.end()) tm_mdcstrkId.push_back(trackId);
244 }
245 for(unsigned int i = 0; i < mdcltrkId.size(); i++)
246 {
247 int trackId = int (mdcltrkId[i]/2);
248 if(find(tm_mdcltrkId.begin(),tm_mdcltrkId.end(),trackId) == tm_mdcltrkId.end()) tm_mdcltrkId.push_back(trackId);
249 }
250 //find tof track id used in track match
251 std::map<int,std::vector<int>,greater<int> > tofHit;
252 std::vector<int> tm_btofhitId;
253 std::vector<int> tm_etofhitId;
254 std::vector<int> tm_wtofhitId;
255 tofHit = m_pIBGT->getTofHitPos();
256 for(std::map<int,std::vector<int>,greater<int> >::iterator iter = tofHit.begin(); iter != tofHit.end(); iter++) {
257 if(iter->first == 0) {
258 for(unsigned int i = 0; i < iter->second.size(); i++){
259 tm_etofhitId.push_back(iter->second[i]);
260 }
261 }
262 if(iter->first == 1) {
263 for(unsigned int i = 0; i < iter->second.size(); i++){
264 tm_btofhitId.push_back(iter->second[i]);
265 }
266 }
267 if(iter->first == 2) {
268 for(unsigned int i = 0; i < iter->second.size(); i++){
269 tm_wtofhitId.push_back(iter->second[i]);
270 }
271 }
272 }
273 //find emc track id used in track match
274 std::map<int,std::vector<complex<int> >, greater<int> > emcHit;
275 std::vector<int> tm_bemcClusId;
276 std::vector<int> tm_eemcClusId;
277 std::vector<int> tm_wemcClusId;
278 emcHit = m_pIBGT->getEmcClusId();
279 for(std::map<int,std::vector<complex<int> >, greater<int> >::iterator iter = emcHit.begin(); iter != emcHit.end(); iter++) {
280 if(iter->first == 1) {
281 for(unsigned int i = 0; i < iter->second.size(); i++)
282 {
283 // cout<<"barrel theta is "<<(iter->second[i]).real()<<" phi is "<<(iter->second[i]).imag()<<endl;
284 int crystalId = iter->second[i].imag();
285 if(find(tm_bemcClusId.begin(),tm_bemcClusId.end(),crystalId) == tm_bemcClusId.end()) tm_bemcClusId.push_back(crystalId);
286 }
287 }
288 if(iter->first == 0) {
289 for(unsigned int i = 0; i < iter->second.size(); i++)
290 {
291 // cout<<"east theta is "<<(iter->second[i]).real()<<" phi is "<<(iter->second[i]).imag()<<endl;
292 int crystalId = int ((iter->second[i].imag())/2);
293 if(find(tm_eemcClusId.begin(),tm_eemcClusId.end(),crystalId) == tm_eemcClusId.end()) tm_eemcClusId.push_back(crystalId);
294 }
295 }
296 if(iter->first == 2) {
297 for(unsigned int i = 0; i < iter->second.size(); i++)
298 {
299 //cout<<"west theta is "<<(iter->second[i]).real()<<" phi is "<<(iter->second[i]).imag()<<endl;
300 int crystalId = int ((iter->second[i].imag())/2);
301 if(find(tm_wemcClusId.begin(),tm_wemcClusId.end(),crystalId) == tm_wemcClusId.end()) tm_wemcClusId.push_back(crystalId);
302 }
303 }
304 }
305 //start track match
306 int BTOF_MATCH[64];
307 int ETOF_MATCH[64];
308 int WTOF_MATCH[64];
309 int BEMC_MATCH[64];
310 int EEMC_MATCH[64];
311 int WEMC_MATCH[64];
312 int BTOF_EMC_MATCH[64];
313 int ETOF_EMC_MATCH[64];
314 int WTOF_EMC_MATCH[64];
315 for(int i = 0; i < 64; i++) {
316 BTOF_MATCH[i] = 0;
317 ETOF_MATCH[i] = 0;
318 WTOF_MATCH[i] = 0;
319 BEMC_MATCH[i] = 0;
320 EEMC_MATCH[i] = 0;
321 WEMC_MATCH[i] = 0;
322 BTOF_EMC_MATCH[i] = 0;
323 ETOF_EMC_MATCH[i] = 0;
324 WTOF_EMC_MATCH[i] = 0;
325 }
326 for(unsigned int i = 0; i < tm_mdcltrkId.size(); i++) {
327 int cellId = tm_mdcltrkId[i];
328 for(unsigned int j = 0; j < (m_tm_barrel[2*cellId]).size(); j++) {
329 if(find(tm_btofhitId.begin(),tm_btofhitId.end(),m_tm_barrel[2*cellId][j]) != tm_btofhitId.end()) { BTOF_MATCH[cellId] = 1; break; }
330 }
331 for(unsigned int j = 0; j < (m_tm_barrel[2*cellId+1]).size(); j++) {
332 if(find(tm_bemcClusId.begin(),tm_bemcClusId.end(),m_tm_barrel[2*cellId+1][j]) != tm_bemcClusId.end()) { BEMC_MATCH[cellId] = 1; break; }
333 }
334 }
335 for(unsigned int i = 0; i < tm_mdcstrkId.size(); i++) {
336 int cellId = tm_mdcstrkId[i];
337 for(unsigned int j = 0; j < (m_tm_ecap[2*cellId]).size(); j++) {
338 if(find(tm_etofhitId.begin(),tm_etofhitId.end(),m_tm_ecap[2*cellId][j]) != tm_etofhitId.end()) { ETOF_MATCH[cellId] = 1; break; }
339 }
340 for(unsigned int j = 0; j < (m_tm_ecap[2*cellId+1]).size(); j++) {
341 if(find(tm_eemcClusId.begin(),tm_eemcClusId.end(),m_tm_ecap[2*cellId+1][j]) != tm_eemcClusId.end()) { EEMC_MATCH[cellId] = 1; break; }
342 }
343 for(unsigned int j = 0; j < (m_tm_wcap[2*cellId]).size(); j++) {
344 if(find(tm_wtofhitId.begin(),tm_wtofhitId.end(),m_tm_wcap[2*cellId][j]) != tm_wtofhitId.end()) { WTOF_MATCH[cellId] = 1; break; }
345 }
346 for(unsigned int j = 0; j < (m_tm_wcap[2*cellId+1]).size(); j++) {
347 if(find(tm_wemcClusId.begin(),tm_wemcClusId.end(),m_tm_wcap[2*cellId+1][j]) != tm_wemcClusId.end()) { WEMC_MATCH[cellId] = 1; break; }
348 }
349 }
350 //count track number
351 int NATrk = 0;
352 int NBTrk = 0;
353 int NCTrk = 0;
354 for(int i = 0; i < 64; i++) {
355 if(BTOF_MATCH[i] == 1) NATrk++;
356 if((BTOF_MATCH[i] == 1) && (BEMC_MATCH[i] == 1)) { BTOF_EMC_MATCH[i] = 1; NBTrk++; }
357 if((ETOF_MATCH[i] == 1) && (EEMC_MATCH[i] == 1)) ETOF_EMC_MATCH[i] = 1;
358 if((WTOF_MATCH[i] == 1) && (WEMC_MATCH[i] == 1)) WTOF_EMC_MATCH[i] = 1;
359 if(m_pIBGT->getEndCapMode() == 0) {
360 if(ETOF_MATCH[i] == 1) NCTrk++;
361 if(WTOF_MATCH[i] == 1) NCTrk++;
362 }
363 else {
364 if(ETOF_EMC_MATCH[i] == 1) NCTrk++;
365 if(WTOF_EMC_MATCH[i] == 1) NCTrk++;
366 }
367 }
368 //set trigger conditions
369 bool NATrk1 = false;
370 bool NATrk2 = false;
371 bool ATrk_BB = false;
372 bool NBTrk1 = false;
373 bool NBTrk2 = false;
374 bool BTrk_BB = false;
375 bool NCTrk1 = false;
376 bool NCTrk2 = false;
377 bool CTrk_BB = false;
378
379 if(NATrk >= 1) NATrk1 = true;
380 if(NATrk >= 2) NATrk2 = true;
381 if(NBTrk >= 1) NBTrk1 = true;
382 if(NBTrk >= 2) NBTrk2 = true;
383 if(NCTrk >= 1) NCTrk1 = true;
384 if(NCTrk >= 2) NCTrk2 = true;
385
386 for(int i = 0; i < 64; i++) {
387 if(BTOF_MATCH[i] == 1) {
388 for(int j=0; j < 7; j++)
389 {
390 int id;
391 if((i+j+29) > 63)
392 {
393 id = i+j+29-64;
394 }
395 else
396 {
397 id = i+j+29;
398 }
399 if(BTOF_MATCH[id] == 1) ATrk_BB = true;
400 }
401 }
402 if(BTOF_EMC_MATCH[i] == 1) {
403 for(int j=0; j < 7; j++)
404 {
405 int id;
406 if((i+j+29) > 63)
407 {
408 id = i+j+29-64;
409 }
410 else
411 {
412 id = i+j+29;
413 }
414 if(BTOF_EMC_MATCH[id] == 1) BTrk_BB = true;
415 }
416 }
417 if(m_pIBGT->getEndCapMode() == 0) {
418 if((ETOF_MATCH[i] == 1) || (WTOF_MATCH[i] == 1)) {
419 for(int j=0; j < 7; j++)
420 {
421 int id;
422 if((i+j+29) > 63)
423 {
424 id = i+j+29-64;
425 }
426 else
427 {
428 id = i+j+29;
429 }
430 if((ETOF_MATCH[id] == 1) || (WTOF_MATCH[id] == 1)) CTrk_BB = true;
431 }
432 }
433 }
434 else {
435 if((ETOF_EMC_MATCH[i] == 1) || (WTOF_EMC_MATCH[i] == 1)) {
436 for(int j=0; j < 7; j++)
437 {
438 int id;
439 if((i+j+29) > 63)
440 {
441 id = i+j+29-64;
442 }
443 else
444 {
445 id = i+j+29;
446 }
447 if((ETOF_EMC_MATCH[id] == 1) || (WTOF_EMC_MATCH[id] == 1)) CTrk_BB = true;
448 }
449 }
450 }
451 }
452
453 m_pIBGT->setTMNATrk1(NATrk1);
454 m_pIBGT->setTMNATrk2(NATrk2);
455 m_pIBGT->setTMATrkBB(ATrk_BB);
456 m_pIBGT->setTMNBTrk1(NBTrk1);
457 m_pIBGT->setTMNBTrk2(NBTrk2);
458 m_pIBGT->setTMBTrkBB(BTrk_BB);
459 m_pIBGT->setTMNCTrk1(NCTrk1);
460 m_pIBGT->setTMNCTrk2(NCTrk2);
461 m_pIBGT->setTMCTrkBB(CTrk_BB);
462}
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
map< int, vector< complex< int > >, greater< int > > getEmcClusId()
map< int, vector< int >, greater< int > > getTofHitPos()
void dump()
Definition: BesTMTrig.cxx:203
void startTMTrig()
Definition: BesTMTrig.cxx:230