72 MsgStream log(
msgSvc(), name() );
74 log << MSG::INFO <<
"in initialize()" << endmsg;
77 NTuplePtr nt1(
ntupleSvc(),
"FILE1/vxyz" );
78 if ( nt1 ) m_tuple1 = nt1;
81 m_tuple1 =
ntupleSvc()->book(
"FILE1/vxyz", CLID_ColumnWiseTuple,
"ks N-Tuple example" );
84 status = m_tuple1->addItem(
"vx0", m_vx0 );
85 status = m_tuple1->addItem(
"vy0", m_vy0 );
86 status = m_tuple1->addItem(
"vz0", m_vz0 );
87 status = m_tuple1->addItem(
"vr0", m_vr0 );
88 status = m_tuple1->addItem(
"rvxy0", m_rvxy0 );
89 status = m_tuple1->addItem(
"rvz0", m_rvz0 );
90 status = m_tuple1->addItem(
"rvphi0", m_rvphi0 );
94 log << MSG::ERROR <<
" Cannot book N-tuple:" << long( m_tuple1 ) << endmsg;
95 return StatusCode::FAILURE;
99 NTuplePtr nt2(
ntupleSvc(),
"FILE1/photon" );
100 if ( nt2 ) m_tuple2 = nt2;
103 m_tuple2 =
ntupleSvc()->book(
"FILE1/photon", CLID_ColumnWiseTuple,
"ks N-Tuple example" );
106 status = m_tuple2->addItem(
"dthe", m_dthe );
107 status = m_tuple2->addItem(
"dphi", m_dphi );
108 status = m_tuple2->addItem(
"dang", m_dang );
109 status = m_tuple2->addItem(
"eraw", m_eraw );
113 log << MSG::ERROR <<
" Cannot book N-tuple:" << long( m_tuple2 ) << endmsg;
114 return StatusCode::FAILURE;
118 NTuplePtr nt3(
ntupleSvc(),
"FILE1/etot" );
119 if ( nt3 ) m_tuple3 = nt3;
122 m_tuple3 =
ntupleSvc()->book(
"FILE1/etot", CLID_ColumnWiseTuple,
"ks N-Tuple example" );
125 status = m_tuple3->addItem(
"m2gg", m_m2gg );
126 status = m_tuple3->addItem(
"etot", m_etot );
130 log << MSG::ERROR <<
" Cannot book N-tuple:" << long( m_tuple3 ) << endmsg;
131 return StatusCode::FAILURE;
136 NTuplePtr nt4(
ntupleSvc(),
"FILE1/fit4c" );
137 if ( nt4 ) m_tuple4 = nt4;
141 ntupleSvc()->book(
"FILE1/fit4c", CLID_ColumnWiseTuple,
"ks N-Tuple example" );
144 status = m_tuple4->addItem(
"chi2", m_chi1 );
145 status = m_tuple4->addItem(
"mpi0", m_mpi0 );
149 log << MSG::ERROR <<
" Cannot book N-tuple:" << long( m_tuple4 ) << endmsg;
150 return StatusCode::FAILURE;
157 NTuplePtr nt5(
ntupleSvc(),
"FILE1/fit5c" );
158 if ( nt5 ) m_tuple5 = nt5;
162 ntupleSvc()->book(
"FILE1/fit5c", CLID_ColumnWiseTuple,
"ks N-Tuple example" );
165 status = m_tuple5->addItem(
"chi2", m_chi2 );
166 status = m_tuple5->addItem(
"mrh0", m_mrh0 );
167 status = m_tuple5->addItem(
"mrhp", m_mrhp );
168 status = m_tuple5->addItem(
"mrhm", m_mrhm );
172 log << MSG::ERROR <<
" Cannot book N-tuple:" << long( m_tuple5 ) << endmsg;
173 return StatusCode::FAILURE;
177 NTuplePtr nt6(
ntupleSvc(),
"FILE1/geff" );
178 if ( nt6 ) m_tuple6 = nt6;
181 m_tuple6 =
ntupleSvc()->book(
"FILE1/geff", CLID_ColumnWiseTuple,
"ks N-Tuple example" );
184 status = m_tuple6->addItem(
"fcos", m_fcos );
185 status = m_tuple6->addItem(
"elow", m_elow );
189 log << MSG::ERROR <<
" Cannot book N-tuple:" << long( m_tuple6 ) << endmsg;
190 return StatusCode::FAILURE;
195 if ( m_checkDedx == 1 )
197 NTuplePtr nt7(
ntupleSvc(),
"FILE1/dedx" );
198 if ( nt7 ) m_tuple7 = nt7;
201 m_tuple7 =
ntupleSvc()->book(
"FILE1/dedx", CLID_ColumnWiseTuple,
"ks N-Tuple example" );
204 status = m_tuple7->addItem(
"ptrk", m_ptrk );
205 status = m_tuple7->addItem(
"chie", m_chie );
206 status = m_tuple7->addItem(
"chimu", m_chimu );
207 status = m_tuple7->addItem(
"chipi", m_chipi );
208 status = m_tuple7->addItem(
"chik", m_chik );
209 status = m_tuple7->addItem(
"chip", m_chip );
210 status = m_tuple7->addItem(
"probPH", m_probPH );
211 status = m_tuple7->addItem(
"normPH", m_normPH );
212 status = m_tuple7->addItem(
"ghit", m_ghit );
213 status = m_tuple7->addItem(
"thit", m_thit );
217 log << MSG::ERROR <<
" Cannot book N-tuple:" << long( m_tuple7 ) << endmsg;
218 return StatusCode::FAILURE;
223 if ( m_checkTof == 1 )
225 NTuplePtr nt8(
ntupleSvc(),
"FILE1/tofe" );
226 if ( nt8 ) m_tuple8 = nt8;
229 m_tuple8 =
ntupleSvc()->book(
"FILE1/tofe", CLID_ColumnWiseTuple,
"ks N-Tuple example" );
232 status = m_tuple8->addItem(
"ptrk", m_ptot_etof );
233 status = m_tuple8->addItem(
"cntr", m_cntr_etof );
234 status = m_tuple8->addItem(
"ph", m_ph_etof );
235 status = m_tuple8->addItem(
"rhit", m_rhit_etof );
236 status = m_tuple8->addItem(
"qual", m_qual_etof );
237 status = m_tuple8->addItem(
"te", m_te_etof );
238 status = m_tuple8->addItem(
"tmu", m_tmu_etof );
239 status = m_tuple8->addItem(
"tpi", m_tpi_etof );
240 status = m_tuple8->addItem(
"tk", m_tk_etof );
241 status = m_tuple8->addItem(
"tp", m_tp_etof );
245 log << MSG::ERROR <<
" Cannot book N-tuple:" << long( m_tuple8 ) << endmsg;
246 return StatusCode::FAILURE;
251 if ( m_checkTof == 1 )
253 NTuplePtr nt9(
ntupleSvc(),
"FILE1/tof1" );
254 if ( nt9 ) m_tuple9 = nt9;
257 m_tuple9 =
ntupleSvc()->book(
"FILE1/tof1", CLID_ColumnWiseTuple,
"ks N-Tuple example" );
260 status = m_tuple9->addItem(
"ptrk", m_ptot_btof1 );
261 status = m_tuple9->addItem(
"cntr", m_cntr_btof1 );
262 status = m_tuple9->addItem(
"ph", m_ph_btof1 );
263 status = m_tuple9->addItem(
"zhit", m_zhit_btof1 );
264 status = m_tuple9->addItem(
"qual", m_qual_btof1 );
265 status = m_tuple9->addItem(
"te", m_te_btof1 );
266 status = m_tuple9->addItem(
"tmu", m_tmu_btof1 );
267 status = m_tuple9->addItem(
"tpi", m_tpi_btof1 );
268 status = m_tuple9->addItem(
"tk", m_tk_btof1 );
269 status = m_tuple9->addItem(
"tp", m_tp_btof1 );
273 log << MSG::ERROR <<
" Cannot book N-tuple:" << long( m_tuple9 ) << endmsg;
274 return StatusCode::FAILURE;
279 if ( m_checkTof == 1 )
281 NTuplePtr nt10(
ntupleSvc(),
"FILE1/tof2" );
282 if ( nt10 ) m_tuple10 = nt10;
286 ntupleSvc()->book(
"FILE1/tof2", CLID_ColumnWiseTuple,
"ks N-Tuple example" );
289 status = m_tuple10->addItem(
"ptrk", m_ptot_btof2 );
290 status = m_tuple10->addItem(
"cntr", m_cntr_btof2 );
291 status = m_tuple10->addItem(
"ph", m_ph_btof2 );
292 status = m_tuple10->addItem(
"zhit", m_zhit_btof2 );
293 status = m_tuple10->addItem(
"qual", m_qual_btof2 );
294 status = m_tuple10->addItem(
"te", m_te_btof2 );
295 status = m_tuple10->addItem(
"tmu", m_tmu_btof2 );
296 status = m_tuple10->addItem(
"tpi", m_tpi_btof2 );
297 status = m_tuple10->addItem(
"tk", m_tk_btof2 );
298 status = m_tuple10->addItem(
"tp", m_tp_btof2 );
302 log << MSG::ERROR <<
" Cannot book N-tuple:" << long( m_tuple10 ) << endmsg;
303 return StatusCode::FAILURE;
308 NTuplePtr nt11(
ntupleSvc(),
"FILE1/pid" );
309 if ( nt11 ) m_tuple11 = nt11;
312 m_tuple11 =
ntupleSvc()->book(
"FILE1/pid", CLID_ColumnWiseTuple,
"ks N-Tuple example" );
315 status = m_tuple11->addItem(
"ptrk", m_ptrk_pid );
316 status = m_tuple11->addItem(
"cost", m_cost_pid );
317 status = m_tuple11->addItem(
"dedx", m_dedx_pid );
318 status = m_tuple11->addItem(
"tof1", m_tof1_pid );
319 status = m_tuple11->addItem(
"tof2", m_tof2_pid );
320 status = m_tuple11->addItem(
"prob", m_prob_pid );
324 log << MSG::ERROR <<
" Cannot book N-tuple:" << long( m_tuple11 ) << endmsg;
325 return StatusCode::FAILURE;
333 log << MSG::INFO <<
"successfully return from initialize()" << endmsg;
334 return StatusCode::SUCCESS;
342 MsgStream log(
msgSvc(), name() );
343 log << MSG::INFO <<
"in execute()" << endmsg;
345 SmartDataPtr<Event::EventHeader> eventHeader( eventSvc(),
"/Event/EventHeader" );
346 int runNo = eventHeader->runNumber();
347 int event = eventHeader->eventNumber();
348 log << MSG::DEBUG <<
"run, evtnum = " <<
runNo <<
" , " <<
event << endmsg;
349 cout <<
"event " <<
event << endl;
354 log << MSG::DEBUG <<
"ncharg, nneu, tottks = " << evtRecEvent->totalCharged() <<
" , "
355 << evtRecEvent->totalNeutral() <<
" , " << evtRecEvent->totalTracks() << endmsg;
362 Vint iGood, ipip, ipim;
372 Hep3Vector xorigin( 0, 0, 0 );
383 SmartIF<IVertexDbSvc> m_vtxSvc;
384 m_vtxSvc = serviceLocator()->service(
"VertexDbSvc" );
385 if ( m_vtxSvc->isVertexValid() )
388 double* dbv = m_vtxSvc->PrimaryVertex();
389 double* vv = m_vtxSvc->SigmaPrimaryVertex();
390 xorigin.setX( dbv[0] );
391 xorigin.setY( dbv[1] );
392 xorigin.setZ( dbv[2] );
395 for (
int i = 0; i < evtRecEvent->totalCharged(); i++ )
398 if ( !( *itTrk )->isMdcTrackValid() )
continue;
400 double pch = mdcTrk->
p();
401 double x0 = mdcTrk->
x();
402 double y0 = mdcTrk->
y();
403 double z0 = mdcTrk->
z();
404 double theta0 = mdcTrk->
theta();
405 double phi0 = mdcTrk->
helix( 1 );
406 double xv = xorigin.x();
407 double yv = xorigin.y();
408 double Rxy = ( x0 - xv ) *
cos( phi0 ) + ( y0 - yv ) *
sin( phi0 );
414 HepVector a = mdcTrk->
helix();
415 HepSymMatrix Ea = mdcTrk->
err();
417 HepPoint3D IP( xorigin[0], xorigin[1], xorigin[2] );
418 VFHelix helixip( point0, a, Ea );
420 HepVector vecipa = helixip.
a();
421 double Rvxy0 = fabs( vecipa[0] );
422 double Rvz0 = vecipa[3];
423 double Rvphi0 = vecipa[1];
432 if ( fabs( Rvz0 ) >= 10.0 )
continue;
433 if ( fabs( Rvxy0 ) >= 1.0 )
continue;
434 if ( fabs(
cos( theta0 ) ) >= 0.93 )
continue;
436 iGood.push_back( i );
437 nCharge += mdcTrk->
charge();
443 int nGood = iGood.size();
444 log << MSG::DEBUG <<
"ngood, totcharge = " << nGood <<
" , " << nCharge << endmsg;
445 if ( ( nGood != 2 ) || ( nCharge != 0 ) ) {
return StatusCode::SUCCESS; }
450 for (
int i = evtRecEvent->totalCharged(); i < evtRecEvent->totalTracks(); i++ )
453 if ( !( *itTrk )->isEmcShowerValid() )
continue;
455 Hep3Vector emcpos( emcTrk->
x(), emcTrk->
y(), emcTrk->
z() );
460 for (
int j = 0; j < evtRecEvent->totalCharged(); j++ )
463 if ( !( *jtTrk )->isExtTrackValid() )
continue;
468 double angd = extpos.angle( emcpos );
469 double thed = extpos.theta() - emcpos.theta();
470 double phid = extpos.deltaPhi( emcpos );
471 thed = fmod( thed + CLHEP::twopi + CLHEP::twopi +
pi, CLHEP::twopi ) - CLHEP::pi;
472 phid = fmod( phid + CLHEP::twopi + CLHEP::twopi +
pi, CLHEP::twopi ) - CLHEP::pi;
480 if ( dang >= 200 )
continue;
481 double eraw = emcTrk->
energy();
484 dthe = dthe * 180 / ( CLHEP::pi );
485 dphi = dphi * 180 / ( CLHEP::pi );
486 dang = dang * 180 / ( CLHEP::pi );
495 if ( eraw <= ( m_energyThreshold / 2 ) )
continue;
499 if ( eraw <= m_energyThreshold )
continue;
504 if ( fabs( dang ) < m_gammaAngleCut )
continue;
517 int nGam = iGam.size();
519 log << MSG::DEBUG <<
"num Good Photon " << nGam <<
" , " << evtRecEvent->totalNeutral()
521 if ( nGam < 2 ) {
return StatusCode::SUCCESS; }
530 if ( m_checkDedx == 1 )
532 for (
int i = 0; i < nGood; i++ )
535 if ( !( *itTrk )->isMdcTrackValid() )
continue;
536 if ( !( *itTrk )->isMdcDedxValid() )
continue;
539 m_ptrk = mdcTrk->
p();
541 m_chie = dedxTrk->
chiE();
542 m_chimu = dedxTrk->
chiMu();
543 m_chipi = dedxTrk->
chiPi();
544 m_chik = dedxTrk->
chiK();
545 m_chip = dedxTrk->
chiP();
548 m_probPH = dedxTrk->
probPH();
549 m_normPH = dedxTrk->
normPH();
558 if ( m_checkTof == 1 )
560 for (
int i = 0; i < nGood; i++ )
563 if ( !( *itTrk )->isMdcTrackValid() )
continue;
564 if ( !( *itTrk )->isTofTrackValid() )
continue;
567 SmartRefVector<RecTofTrack> tofTrkCol = ( *itTrk )->tofTrack();
569 double ptrk = mdcTrk->
p();
571 SmartRefVector<RecTofTrack>::iterator iter_tof = tofTrkCol.begin();
572 for ( ; iter_tof != tofTrkCol.end(); iter_tof++ )
575 status->
setStatus( ( *iter_tof )->status() );
579 if ( status->
layer() != 0 )
continue;
580 double path = ( *iter_tof )->path();
581 double tof = ( *iter_tof )->tof();
582 double ph = ( *iter_tof )->ph();
583 double rhit = ( *iter_tof )->zrhit();
584 double qual = 0.0 + ( *iter_tof )->quality();
585 double cntr = 0.0 + ( *iter_tof )->tofID();
587 for (
int j = 0; j < 5; j++ )
589 double gb = ptrk /
xmass[j];
590 double beta = gb / sqrt( 1 + gb * gb );
591 texp[j] = 10 * path / beta /
velc;
598 m_te_etof = tof - texp[0];
599 m_tmu_etof = tof - texp[1];
600 m_tpi_etof = tof - texp[2];
601 m_tk_etof = tof - texp[3];
602 m_tp_etof = tof - texp[4];
608 if ( status->
layer() == 1 )
610 double path = ( *iter_tof )->path();
611 double tof = ( *iter_tof )->tof();
612 double ph = ( *iter_tof )->ph();
613 double rhit = ( *iter_tof )->zrhit();
614 double qual = 0.0 + ( *iter_tof )->quality();
615 double cntr = 0.0 + ( *iter_tof )->tofID();
617 for (
int j = 0; j < 5; j++ )
619 double gb = ptrk /
xmass[j];
620 double beta = gb / sqrt( 1 + gb * gb );
621 texp[j] = 10 * path / beta /
velc;
629 m_te_btof1 = tof - texp[0];
630 m_tmu_btof1 = tof - texp[1];
631 m_tpi_btof1 = tof - texp[2];
632 m_tk_btof1 = tof - texp[3];
633 m_tp_btof1 = tof - texp[4];
637 if ( status->
layer() == 2 )
639 double path = ( *iter_tof )->path();
640 double tof = ( *iter_tof )->tof();
641 double ph = ( *iter_tof )->ph();
642 double rhit = ( *iter_tof )->zrhit();
643 double qual = 0.0 + ( *iter_tof )->quality();
644 double cntr = 0.0 + ( *iter_tof )->tofID();
646 for (
int j = 0; j < 5; j++ )
648 double gb = ptrk /
xmass[j];
649 double beta = gb / sqrt( 1 + gb * gb );
650 texp[j] = 10 * path / beta /
velc;
658 m_te_btof2 = tof - texp[0];
659 m_tmu_btof2 = tof - texp[1];
660 m_tpi_btof2 = tof - texp[2];
661 m_tk_btof2 = tof - texp[3];
662 m_tp_btof2 = tof - texp[4];
678 for (
int i = 0; i < nGam; i++ )
682 double eraw = emcTrk->
energy();
683 double phi = emcTrk->
phi();
684 double the = emcTrk->
theta();
685 HepLorentzVector ptrk;
686 ptrk.setPx( eraw *
sin( the ) *
cos( phi ) );
687 ptrk.setPy( eraw *
sin( the ) *
sin( phi ) );
688 ptrk.setPz( eraw *
cos( the ) );
693 pGam.push_back( ptrk );
700 for (
int i = 0; i < nGood; i++ )
719 m_ptrk_pid = mdcTrk->
p();
720 m_cost_pid =
cos( mdcTrk->
theta() );
721 m_dedx_pid = pid->
chiDedx( 2 );
722 m_tof1_pid = pid->
chiTof1( 2 );
723 m_tof2_pid = pid->
chiTof2( 2 );
734 ( *itTrk )->mdcKalTrack();
740 if ( mdcKalTrk->
charge() > 0 )
742 ipip.push_back( iGood[i] );
743 HepLorentzVector ptrk;
744 ptrk.setPx( mdcKalTrk->
px() );
745 ptrk.setPy( mdcKalTrk->
py() );
746 ptrk.setPz( mdcKalTrk->
pz() );
747 double p3 = ptrk.mag();
748 ptrk.setE( sqrt( p3 * p3 +
mpi *
mpi ) );
752 ppip.push_back( ptrk );
756 ipim.push_back( iGood[i] );
757 HepLorentzVector ptrk;
758 ptrk.setPx( mdcKalTrk->
px() );
759 ptrk.setPy( mdcKalTrk->
py() );
760 ptrk.setPz( mdcKalTrk->
pz() );
761 double p3 = ptrk.mag();
762 ptrk.setE( sqrt( p3 * p3 +
mpi *
mpi ) );
766 ppim.push_back( ptrk );
796 int npip = ipip.size();
797 int npim = ipim.size();
798 if ( npip * npim != 1 )
return StatusCode::SUCCESS;
806 HepLorentzVector pTot;
807 for (
int i = 0; i < nGam - 1; i++ )
809 for (
int j = i + 1; j < nGam; j++ )
811 HepLorentzVector p2g = pGam[i] + pGam[j];
812 pTot = ppip[0] + ppim[0];
820 RecMdcKalTrack* pipTrk = ( *( evtRecTrkCol->begin() + ipip[0] ) )->mdcKalTrack();
821 RecMdcKalTrack* pimTrk = ( *( evtRecTrkCol->begin() + ipim[0] ) )->mdcKalTrack();
838 HepSymMatrix Evx( 3, 0 );
855 if ( !vtxfit->
Fit( 0 ) )
return StatusCode::SUCCESS;
871 HepLorentzVector
ecms( 0.034, 0, 0, 3.097 );
873 double chisq = 9999.;
876 for (
int i = 0; i < nGam - 1; i++ )
878 RecEmcShower* g1Trk = ( *( evtRecTrkCol->begin() + iGam[i] ) )->emcShower();
879 for (
int j = i + 1; j < nGam; j++ )
881 RecEmcShower* g2Trk = ( *( evtRecTrkCol->begin() + iGam[j] ) )->emcShower();
888 bool oksq = kmfit->
Fit();
891 double chi2 = kmfit->
chisq();
905 RecEmcShower* g1Trk = ( *( evtRecTrkCol->begin() + ig1 ) )->emcShower();
906 RecEmcShower* g2Trk = ( *( evtRecTrkCol->begin() + ig2 ) )->emcShower();
913 bool oksq = kmfit->
Fit();
916 HepLorentzVector ppi0 = kmfit->
pfit( 2 ) + kmfit->
pfit( 3 );
918 m_chi1 = kmfit->
chisq();
933 HepLorentzVector
ecms( 0.034, 0, 0, 3.097 );
934 double chisq = 9999.;
937 for (
int i = 0; i < nGam - 1; i++ )
939 RecEmcShower* g1Trk = ( *( evtRecTrkCol->begin() + iGam[i] ) )->emcShower();
940 for (
int j = i + 1; j < nGam; j++ )
942 RecEmcShower* g2Trk = ( *( evtRecTrkCol->begin() + iGam[j] ) )->emcShower();
950 if ( !kmfit->
Fit( 0 ) )
continue;
951 if ( !kmfit->
Fit( 1 ) )
continue;
952 bool oksq = kmfit->
Fit();
955 double chi2 = kmfit->
chisq();
966 log << MSG::INFO <<
" chisq = " << chisq << endmsg;
970 RecEmcShower* g1Trk = ( *( evtRecTrkCol->begin() + ig1 ) )->emcShower();
971 RecEmcShower* g2Trk = ( *( evtRecTrkCol->begin() + ig2 ) )->emcShower();
980 bool oksq = kmfit->
Fit();
983 HepLorentzVector ppi0 = kmfit->
pfit( 2 ) + kmfit->
pfit( 3 );
984 HepLorentzVector prho0 = kmfit->
pfit( 0 ) + kmfit->
pfit( 1 );
985 HepLorentzVector prhop = ppi0 + kmfit->
pfit( 0 );
986 HepLorentzVector prhom = ppi0 + kmfit->
pfit( 1 );
988 m_chi2 = kmfit->
chisq();
992 double eg1 = ( kmfit->
pfit( 2 ) ).e();
993 double eg2 = ( kmfit->
pfit( 3 ) ).e();
994 double fcos =
abs( eg1 - eg2 ) / ppi0.rho();
1001 if ( fabs( prho0.m() - 0.770 ) < 0.150 )
1003 if ( fabs( fcos ) < 0.99 )
1005 m_fcos = ( eg1 - eg2 ) / ppi0.rho();
1006 m_elow = ( eg1 < eg2 ) ? eg1 : eg2;
1014 return StatusCode::SUCCESS;