26 std::string filename = std::string(getenv(
"TRIGGERROOT" ));
27 filename += std::string(
"/data/tm/TM_BARREL.pat");
28 std::ifstream infile( filename.c_str() );
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;
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() );
48 std::vector<int> tof_tmp;
49 std::vector<int> emc_tmp;
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);
58 for(
int i = i_tofId_l; i <= i_tofId_h; i++) {
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);
70 for(
int i = i_emcId_l; i <= i_emcId_h; i++) {
74 m_tm_barrel.push_back(tof_tmp);
75 m_tm_barrel.push_back(emc_tmp);
79 std::cout <<
"Can not open file: " << filename <<
" in BesTMTrig. " << std::endl;
82 filename = std::string(getenv(
"TRIGGERROOT" ));
83 filename += std::string(
"/data/tm/TM_EAST_ENDCAP.pat");
84 std::ifstream infile1( filename.c_str() );
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;
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() );
104 std::vector<int> tof_tmp;
105 std::vector<int> emc_tmp;
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);
114 for(
int i = i_tofId_l; i <= i_tofId_h; i++) {
115 tof_tmp.push_back(i);
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);
126 for(
int i = i_emcId_l; i <= i_emcId_h; i++) {
127 emc_tmp.push_back(i);
130 m_tm_ecap.push_back(tof_tmp);
131 m_tm_ecap.push_back(emc_tmp);
135 std::cout <<
"Can not open file: " << filename <<
" in BesTMTrig. " << std::endl;
139 filename = std::string(getenv(
"TRIGGERROOT" ));
140 filename += std::string(
"/data/tm/TM_WEST_ENDCAP.pat");
141 std::ifstream infile2( filename.c_str() );
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;
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() );
161 std::vector<int> tof_tmp;
162 std::vector<int> emc_tmp;
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);
171 for(
int i = i_tofId_l; i <= i_tofId_h; i++) {
172 tof_tmp.push_back(i);
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);
183 for(
int i = i_emcId_l; i <= i_emcId_h; i++) {
184 emc_tmp.push_back(i);
187 m_tm_wcap.push_back(tof_tmp);
188 m_tm_wcap.push_back(emc_tmp);
192 std::cout <<
"Can not open file: " << filename <<
" in BesTMTrig. " << std::endl;
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;
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;
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;
231 ISvcLocator* svcLocator = Gaudi::svcLocator();
232 StatusCode sc = svcLocator->service(
"BesGlobalTrigSvc", m_tmpSvc);
236 std::vector<int> tm_mdcstrkId;
237 std::vector<int> tm_mdcltrkId;
240 for(
unsigned int i = 0; i < mdcstrkId.size(); i++)
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);
245 for(
unsigned int i = 0; i < mdcltrkId.size(); i++)
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);
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;
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]);
262 if(
iter->first == 1) {
263 for(
unsigned int i = 0; i <
iter->second.size(); i++){
264 tm_btofhitId.push_back(
iter->second[i]);
267 if(
iter->first == 2) {
268 for(
unsigned int i = 0; i <
iter->second.size(); i++){
269 tm_wtofhitId.push_back(
iter->second[i]);
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;
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++)
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);
288 if(
iter->first == 0) {
289 for(
unsigned int i = 0; i <
iter->second.size(); i++)
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);
296 if(
iter->first == 2) {
297 for(
unsigned int i = 0; i <
iter->second.size(); i++)
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);
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++) {
322 BTOF_EMC_MATCH[i] = 0;
323 ETOF_EMC_MATCH[i] = 0;
324 WTOF_EMC_MATCH[i] = 0;
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; }
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; }
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; }
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; }
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; }
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; }
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;
360 if(ETOF_MATCH[i] == 1) NCTrk++;
361 if(WTOF_MATCH[i] == 1) NCTrk++;
364 if(ETOF_EMC_MATCH[i] == 1) NCTrk++;
365 if(WTOF_EMC_MATCH[i] == 1) NCTrk++;
371 bool ATrk_BB =
false;
374 bool BTrk_BB =
false;
377 bool CTrk_BB =
false;
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;
386 for(
int i = 0; i < 64; i++) {
387 if(BTOF_MATCH[i] == 1) {
388 for(
int j=0; j < 7; j++)
399 if(BTOF_MATCH[
id] == 1) ATrk_BB =
true;
402 if(BTOF_EMC_MATCH[i] == 1) {
403 for(
int j=0; j < 7; j++)
414 if(BTOF_EMC_MATCH[
id] == 1) BTrk_BB =
true;
418 if((ETOF_MATCH[i] == 1) || (WTOF_MATCH[i] == 1)) {
419 for(
int j=0; j < 7; j++)
430 if((ETOF_MATCH[
id] == 1) || (WTOF_MATCH[
id] == 1)) CTrk_BB =
true;
435 if((ETOF_EMC_MATCH[i] == 1) || (WTOF_EMC_MATCH[i] == 1)) {
436 for(
int j=0; j < 7; j++)
447 if((ETOF_EMC_MATCH[
id] == 1) || (WTOF_EMC_MATCH[
id] == 1)) CTrk_BB =
true;