230 {
231 ISvcLocator* svcLocator = Gaudi::svcLocator();
232 StatusCode sc = svcLocator->service("BesGlobalTrigSvc", m_tmpSvc);
233 m_pIBGT = dynamic_cast<BesGlobalTrigSvc* >(m_tmpSvc);
234
235
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
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
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
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
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
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
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
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
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}