46 : Algorithm( name, pSvcLocator ) {
50 declareProperty(
"ParVer", m_parVer = 1 );
51 declareProperty(
"TrackNumberCut", m_trackNumberCut = 1 );
52 declareProperty(
"Vz0Cut", m_vz0Cut = 50.0 );
53 declareProperty(
"CosThetaCut", m_cosThetaCut = 0.93 );
56 declareProperty(
"OptionPID", m_pid = 0 );
57 declareProperty(
"PidUseDedx", m_useDedx =
true );
58 declareProperty(
"PidUseTof1", m_useTof1 =
true );
59 declareProperty(
"PidUseTof2", m_useTof2 =
true );
60 declareProperty(
"PidUseTofE", m_useTofE =
false );
61 declareProperty(
"PidUseTofQ", m_useTofQ =
false );
62 declareProperty(
"PidUseEmc", m_useEmc =
false );
63 declareProperty(
"PidUseMuc", m_useMuc =
false );
66 declareProperty(
"OptionVertexFind", m_vertexFind = 0 );
67 declareProperty(
"MinDistance", m_minDistance = 100.0 );
68 declareProperty(
"MinPointX", m_minPointX = 0.1 );
69 declareProperty(
"MinPointY", m_minPointY = 0.1 );
70 declareProperty(
"MeanPointX", m_meanPointX = 0.1 );
71 declareProperty(
"MeanPointY", m_meanPointY = -0.25 );
74 declareProperty(
"ChisqCut", m_chisqCut = 200.0 );
75 declareProperty(
"TrackIteration", m_trackIteration = 5 );
76 declareProperty(
"VertexIteration", m_vertexIteration = 5 );
77 declareProperty(
"Chi2CutforTrkIter", m_chi2CutforTrkIter = 0.1 );
78 declareProperty(
"Chi2CutforSmooth", m_chi2CutforSmooth = 200.0 );
81 declareProperty(
"HadronFile", m_hadronFile = 0 );
82 declareProperty(
"DstFileName", m_fileNameDst = std::string(
"dst.txt" ) );
83 declareProperty(
"HadronFileName", m_fileNameHadron = std::string(
"hadron.txt" ) );
84 declareProperty(
"FigsName", m_figsName = std::string(
"figs.ps" ) );
89 MsgStream log(
msgSvc(), name() );
90 log << MSG::INFO <<
"in initialize()" << endmsg;
92 StatusCode sc = service(
"THistSvc", m_thsvc );
95 log << MSG::FATAL <<
"Couldn't get THistSvc" << endmsg;
99 for (
int i = 0; i < 15; i++ ) { m_sel_number[i] = 0; }
104 m_vertex_x =
new TH1D(
"x_of_vertex",
"x of vertex", 200, -5, 5 );
105 m_vertex_y =
new TH1D(
"y_of_vertex",
"y of vertex", 200, -5, 5 );
106 m_vertex_z =
new TH1D(
"z_of_vertex",
"z of vertex", 200, -10, 10 );
107 m_vertex_x_kal =
new TH1D(
"x_of_vertex_in_kal",
"x of vertex in kal", 200, -5, 5 );
108 m_vertex_y_kal =
new TH1D(
"y_of_vertex_in_kal",
"y of vertex in kal", 200, -5, 5 );
109 m_vertex_z_kal =
new TH1D(
"z_of_vertex_in_kal",
"z of vertex in kal", 200, -10, 10 );
110 if ( m_thsvc->regHist(
"/DQAHist/zhsVER/x_of_vertex", m_vertex_x ).isFailure() )
112 log << MSG::FATAL <<
"Couldn't register x of vertex " << endmsg;
115 if ( m_thsvc->regHist(
"/DQAHist/zhsVER/y_of_vertex", m_vertex_y ).isFailure() )
117 log << MSG::FATAL <<
"Couldn't register y of vertex" << endmsg;
120 if ( m_thsvc->regHist(
"/DQAHist/zhsVER/z_of_vertex", m_vertex_z ).isFailure() )
122 log << MSG::FATAL <<
"Couldn't register z of vertex" << endmsg;
125 if ( m_thsvc->regHist(
"/DQAHist/zhsVER/x_of_vertex_in_kal", m_vertex_x_kal ).isFailure() )
127 log << MSG::FATAL <<
"Couldn't register x of vertex in kal" << endmsg;
130 if ( m_thsvc->regHist(
"/DQAHist/zhsVER/y_of_vertex_in_kal", m_vertex_y_kal ).isFailure() )
132 log << MSG::FATAL <<
"Couldn't register y of vertex in kal" << endmsg;
135 if ( m_thsvc->regHist(
"/DQAHist/zhsVER/z_of_vertex_in_kal", m_vertex_z_kal ).isFailure() )
137 log << MSG::FATAL <<
"Couldn't register z of vertex in kal" << endmsg;
144 NTuplePtr nt1(
ntupleSvc(),
"FILE1/minid" );
145 if ( nt1 ) m_tuple1 = nt1;
148 m_tuple1 =
ntupleSvc()->book(
"FILE1/minid", CLID_ColumnWiseTuple,
"minimal distance" );
151 status = m_tuple1->addItem(
"xc", m_xc );
152 status = m_tuple1->addItem(
"yc", m_yc );
153 status = m_tuple1->addItem(
"zc", m_zc );
154 status = m_tuple1->addItem(
"mind", m_mind );
158 log << MSG::FATAL <<
"Cannot book N-tuple:" << long( m_tuple1 ) << endmsg;
159 return StatusCode::FAILURE;
163 NTuplePtr nt2(
ntupleSvc(),
"FILE1/chisq" );
164 if ( nt2 ) m_tuple2 = nt2;
167 m_tuple2 =
ntupleSvc()->book(
"FILE1/chisq", CLID_ColumnWiseTuple,
"chi-square of " );
170 status = m_tuple2->addItem(
"chis", m_chis );
171 status = m_tuple2->addItem(
"probs", m_probs );
172 status = m_tuple2->addItem(
"chif", m_chif );
173 status = m_tuple2->addItem(
"probf", m_probf );
177 log << MSG::FATAL <<
"Cannot book N-tuple:" << long( m_tuple2 ) << endmsg;
178 return StatusCode::FAILURE;
182 NTuplePtr nt3(
ntupleSvc(),
"FILE1/kalvtx" );
183 if ( nt3 ) m_tuple3 = nt3;
186 m_tuple3 =
ntupleSvc()->book(
"FILE1/kalvtx", CLID_ColumnWiseTuple,
"kalman vertex" );
189 status = m_tuple3->addItem(
"kvx", m_kvx );
190 status = m_tuple3->addItem(
"kvy", m_kvy );
191 status = m_tuple3->addItem(
"kvz", m_kvz );
192 status = m_tuple3->addItem(
"chik", m_chik );
193 status = m_tuple3->addItem(
"ndofk", m_ndofk );
194 status = m_tuple3->addItem(
"probk", m_probk );
198 log << MSG::FATAL <<
"Cannot book N-tuple:" << long( m_tuple3 ) << endmsg;
199 return StatusCode::FAILURE;
203 NTuplePtr nt4(
ntupleSvc(),
"FILE1/glbvtx" );
204 if ( nt4 ) m_tuple4 = nt4;
207 m_tuple4 =
ntupleSvc()->book(
"FILE1/glbvtx", CLID_ColumnWiseTuple,
"global vertex" );
210 status = m_tuple4->addItem(
"gvx", m_gvx );
211 status = m_tuple4->addItem(
"gvy", m_gvy );
212 status = m_tuple4->addItem(
"gvz", m_gvz );
213 status = m_tuple4->addItem(
"chig", m_chig );
214 status = m_tuple4->addItem(
"ndofg", m_ndofg );
215 status = m_tuple4->addItem(
"probg", m_probg );
219 log << MSG::FATAL <<
"Cannot book N-tuple:" << long( m_tuple4 ) << endmsg;
220 return StatusCode::FAILURE;
224 NTuplePtr nt5(
ntupleSvc(),
"FILE1/Pull" );
225 if ( nt5 ) m_tuple5 = nt5;
228 m_tuple5 =
ntupleSvc()->book(
"FILE1/Pull", CLID_ColumnWiseTuple,
"Pull" );
231 status = m_tuple5->addItem(
"pull_drho", m_pull_drho );
232 status = m_tuple5->addItem(
"pull_phi", m_pull_phi );
233 status = m_tuple5->addItem(
"pull_kapha", m_pull_kapha );
234 status = m_tuple5->addItem(
"pull_dz", m_pull_dz );
235 status = m_tuple5->addItem(
"pull_lamb", m_pull_lamb );
236 status = m_tuple5->addItem(
"pull_momentum", m_pull_momentum );
240 log << MSG::FATAL <<
"Cannot book N-tuple:" << long( m_tuple5 ) << endmsg;
241 return StatusCode::FAILURE;
245 NTuplePtr nt6(
ntupleSvc(),
"FILE1/MdcTrack" );
246 if ( nt6 ) m_tuple6 = nt6;
249 m_tuple6 =
ntupleSvc()->book(
"FILE1/MdcTrack", CLID_ColumnWiseTuple,
"MdcTrack" );
252 status = m_tuple6->addItem(
"MdcTrkX", m_mdcTrk_x );
253 status = m_tuple6->addItem(
"MdcTrkY", m_mdcTrk_y );
254 status = m_tuple6->addItem(
"MdcTrkZ", m_mdcTrk_z );
255 status = m_tuple6->addItem(
"MdcTrkR", m_mdcTrk_r );
256 status = m_tuple6->addItem(
"MdcTrkDrho", m_mdcTrk_dr );
257 status = m_tuple6->addItem(
"Rxy", m_rxy );
258 status = m_tuple6->addItem(
"MdcKalTrkZ", m_mdcKalTrk_z );
262 log << MSG::FATAL <<
"Cannot book N-tuple:" << long( m_tuple6 ) << endmsg;
263 return StatusCode::FAILURE;
267 NTuplePtr nt7(
ntupleSvc(),
"FILE1/PullG" );
268 if ( nt7 ) m_tuple7 = nt7;
271 m_tuple7 =
ntupleSvc()->book(
"FILE1/PullG", CLID_ColumnWiseTuple,
"Pull" );
274 status = m_tuple7->addItem(
"gpull_drho", m_gpull_drho );
275 status = m_tuple7->addItem(
"gpull_phi", m_gpull_phi );
276 status = m_tuple7->addItem(
"gpull_kapha", m_gpull_kapha );
277 status = m_tuple7->addItem(
"gpull_dz", m_gpull_dz );
278 status = m_tuple7->addItem(
"gpull_lamb", m_gpull_lamb );
282 log << MSG::FATAL <<
"Cannot book N-tuple:" << long( m_tuple7 ) << endmsg;
283 return StatusCode::FAILURE;
287 log << MSG::INFO <<
"successfully return from initialize()" << endmsg;
288 return StatusCode::SUCCESS;
295 MsgStream log(
msgSvc(), name() );
296 log << MSG::INFO <<
"in execute()" << endmsg;
301 SmartDataPtr<Event::EventHeader> eventHeader( eventSvc(),
"/Event/EventHeader" );
304 log << MSG::DEBUG <<
"run and event = " << eventHeader->runNumber() <<
" "
305 << eventHeader->eventNumber() << endmsg;
306 log << MSG::DEBUG <<
"ncharg, nneu, tottks = " << recEvent->totalCharged() <<
" , "
307 << recEvent->totalNeutral() <<
" , " << recEvent->totalTracks() << endmsg;
309 m_runNo = eventHeader->runNumber();
311 if ( eventHeader->eventNumber() % 5000 == 0 )
313 cout <<
"Event number = " << eventHeader->eventNumber() <<
" run number = " << m_runNo
319 if ( recEvent->totalCharged() < m_trackNumberCut )
return StatusCode::SUCCESS;
325 Vint icp, icm, iGood, jGood;
331 map<int, int> ParticleType;
334 for (
unsigned int i = 0; i < recEvent->totalCharged(); i++ )
336 jGood.push_back( 0 );
338 if ( !( *itTrk )->isMdcTrackValid() )
continue;
339 if ( !( *itTrk )->isMdcKalTrackValid() )
continue;
341 if ( fabs(
cos( mdcTrk->
theta() ) ) >= m_cosThetaCut )
continue;
342 if ( fabs( mdcTrk->
z() ) >= m_vz0Cut )
continue;
344 iGood.push_back( i );
348 if ( mdcTrk->
charge() > 0 )
353 else if ( mdcTrk->
charge() < 0 )
359 else if ( m_pid == 1 )
383 double prob_value[5];
391 for (
int i = 1; i < 5; i++ )
393 if ( prob_value[i] > prob_value[
max] ) {
max = i; }
398 if (
max == 0 ) ParticleType[i] = 0;
399 if (
max == 1 ) ParticleType[i] = 1;
400 if (
max == 2 ) ParticleType[i] = 2;
401 if (
max == 3 ) ParticleType[i] = 3;
402 if (
max == 4 ) ParticleType[i] = 4;
408 m_mdcTrk_x = mdcTrk->
x();
409 m_mdcTrk_y = mdcTrk->
y();
410 m_mdcTrk_z = mdcTrk->
helix( 3 );
411 m_mdcTrk_r = mdcTrk->
r();
412 m_mdcTrk_dr = mdcTrk->
helix( 0 );
413 m_mdcKalTrk_z = kalTrk->
helix()[3];
418 if ( iGood.size() < m_trackNumberCut )
return StatusCode::SUCCESS;
424 if ( m_vertexFind == 1 )
426 int nGood = iGood.size();
427 for (
int i1 = 0; i1 < nGood; i1++ )
429 int id_trk1 = iGood[i1];
439 else if ( m_pid == 1 )
443 ParticleType[id_trk1] );
445 for (
int i2 = i1 + 1; i2 < nGood; i2++ )
447 int id_trk2 = iGood[i2];
456 else if ( m_pid == 1 )
460 ParticleType[id_trk2] );
462 HepPoint3D
cross( 0., 0., 0. );
472 if ( fabs( dist ) > m_minDistance )
continue;
478 double cross_cut = 0.;
479 if ( cross_cut < 3.5 * 3.5 )
488 for (
int i = 0; i < jGood.size(); i++ )
490 if ( jGood[i] == 1 ) iGood.push_back( i );
495 if ( iGood.size() >= 2 ) m_sel_number[3]++;
496 if ( iGood.size() >= 3 ) m_sel_number[4]++;
501 HepPoint3D vx( 0., 0., 0. );
502 HepSymMatrix Evx( 3, 0 );
518 for (
int i = 0; i < iGood.size(); i++ )
520 int trk_id = iGood[i];
529 else if ( m_pid == 1 )
539 if ( !vtxfit->
Fit( 0 ) )
return StatusCode::SUCCESS;
540 m_chig = vtxfit->
chisq( 0 );
541 m_ndofg = 2 * iGood.size() - 3;
542 m_probg = TMath::Prob( m_chig, m_ndofg );
543 HepVector glvtx = vtxfit->
Vx( 0 );
549 if ( !( m_vertex_x->Fill( glvtx[0] ) ) )
551 log << MSG::FATAL <<
"Couldn't Fill x of vertex" << endmsg;
554 if ( !( m_vertex_y->Fill( glvtx[1] ) ) )
556 log << MSG::FATAL <<
"Couldn't Fill y of vertex" << endmsg;
559 if ( !( m_vertex_z->Fill( glvtx[2] ) ) )
561 log << MSG::FATAL <<
"Couldn't Fill z of vertex" << endmsg;
565 for (
int j = 0; j < iGood.size(); j++ )
567 HepVector pull( 5, 0 );
568 bool success = vtxfit->
pull( 0, j, pull );
571 m_gpull_drho = pull[0];
572 m_gpull_phi = pull[1];
573 m_gpull_kapha = pull[2];
574 m_gpull_dz = pull[3];
575 m_gpull_lamb = pull[4];
588 for (
int i = 0; i < iGood.size(); i++ )
590 int trk_id = iGood[i];
599 else if ( m_pid == 1 )
609 if ( kalvtx->
ndof() >= freedomCut )
612 for (
int i = 0; i < iGood.size(); i++ )
614 m_chif = kalvtx->
chiF( i );
615 m_chis = kalvtx->
chiS( i );
616 m_probs = TMath::Prob( m_chis, 2 );
617 m_probf = TMath::Prob( m_chif, 2 );
620 if ( kalvtx->
chiS( i ) > m_chi2CutforSmooth ) kalvtx->
remove( i );
623 if ( kalvtx->
ndof() >= freedomCut )
625 for (
int i = 0; i < iGood.size(); i++ )
629 HepVector Pull( 5, 0 );
630 Pull = kalvtx->
pull( i );
631 m_pull_drho = Pull[0];
632 m_pull_phi = Pull[1];
633 m_pull_kapha = Pull[2];
635 m_pull_lamb = Pull[4];
640 m_chik = kalvtx->
chisq();
641 m_ndofk = kalvtx->
ndof();
642 m_probk = TMath::Prob( m_chik, m_ndofk );
643 HepVector xp( 3, 0 );
650 if ( !( m_vertex_x_kal->Fill( xp[0] ) ) )
652 log << MSG::FATAL <<
"Couldn't Fill kal x of vertex" << endmsg;
655 if ( !( m_vertex_y_kal->Fill( xp[1] ) ) )
657 log << MSG::FATAL <<
"Couldn't Fill kal y of vertex" << endmsg;
660 if ( !( m_vertex_z_kal->Fill( xp[2] ) ) )
662 log << MSG::FATAL <<
"Couldn't Fill kal z of vertex" << endmsg;
668 return StatusCode::SUCCESS;
674 MsgStream log(
msgSvc(), name() );
675 log << MSG::INFO <<
"in finalize()" << endmsg;
730 // Output a TXT file and a .ps figure for storing the fit results
732 const char *file_name, *figs_name;
733 if (m_hadronFile == 0) {
734 file_name = m_fileNameDst.c_str();
735 } else if (m_hadronFile == 1) {
736 file_name = m_fileNameHadron.c_str();
739 figs_name = m_figsName.c_str();
740 myC->SaveAs(figs_name);
742 ofstream file(file_name);
744 file << getenv("BES_RELEASE") << " " << m_parVer << " " << m_runNo << endl;
745 file << MeanX << " " << MeanY << " " << MeanZ << " "<< SigmaX << " "<< SigmaY << " " <<
746 SigmaZ << endl; file << ErrMeanX << " " << ErrMeanY<< " " << ErrMeanZ << " " << ErrSigmaX <<
747 " " << ErrSigmaY << " " << ErrSigmaZ << endl; file << MeanXKal << " "<< MeanYKal << " "<<
748 MeanZKal << " "<< SigmaXKal << " " << SigmaYKal << " " << SigmaZKal << endl; file <<
749 ErrMeanXKal << " " << ErrMeanYKal<< " " << ErrMeanZKal << " " << ErrSigmaXKal << " " <<
750 ErrSigmaYKal << " " << ErrSigmaZKal << endl;*/
760 log << MSG::ALWAYS <<
"==================================" << endmsg;
761 log << MSG::ALWAYS <<
"survived event :";
762 for (
int i = 0; i < 10; i++ ) { log << MSG::ALWAYS << m_sel_number[i] <<
" "; }
763 log << MSG::ALWAYS << endmsg;
764 log << MSG::ALWAYS <<
"==================================" << endmsg;
765 return StatusCode::SUCCESS;
static ParticleID * instance()
bool IsPidInfoValid() const