45 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"));
90 MsgStream log(
msgSvc(), name());
91 log << MSG::INFO <<
"in initialize()" << endmsg;
93 StatusCode sc=service(
"THistSvc", m_thsvc);
95 log << MSG::FATAL <<
"Couldn't get THistSvc" << endreq;
99 for(
int i = 0; i < 15; i++){
106 m_vertex_x =
new TH1D(
"x_of_vertex",
"x of vertex", 200, -5, 5);
107 m_vertex_y =
new TH1D(
"y_of_vertex",
"y of vertex", 200, -5, 5);
108 m_vertex_z =
new TH1D(
"z_of_vertex",
"z of vertex", 200, -10, 10);
109 m_vertex_x_kal =
new TH1D(
"x_of_vertex_in_kal",
"x of vertex in kal", 200, -5, 5);
110 m_vertex_y_kal =
new TH1D(
"y_of_vertex_in_kal",
"y of vertex in kal", 200, -5, 5);
111 m_vertex_z_kal =
new TH1D(
"z_of_vertex_in_kal",
"z of vertex in kal", 200, -10, 10);
112 if(m_thsvc->regHist(
"/DQAHist/zhsVER/x_of_vertex",m_vertex_x).isFailure()){
113 log << MSG::FATAL <<
"Couldn't register x of vertex " << endreq;
116 if(m_thsvc->regHist(
"/DQAHist/zhsVER/y_of_vertex",m_vertex_y).isFailure()){
117 log << MSG::FATAL <<
"Couldn't register y of vertex" << endreq;
120 if(m_thsvc->regHist(
"/DQAHist/zhsVER/z_of_vertex",m_vertex_z).isFailure()){
121 log << MSG::FATAL <<
"Couldn't register z of vertex" << endreq;
124 if(m_thsvc->regHist(
"/DQAHist/zhsVER/x_of_vertex_in_kal",m_vertex_x_kal).isFailure()){
125 log << MSG::FATAL <<
"Couldn't register x of vertex in kal" << endreq;
128 if(m_thsvc->regHist(
"/DQAHist/zhsVER/y_of_vertex_in_kal",m_vertex_y_kal).isFailure()){
129 log << MSG::FATAL <<
"Couldn't register y of vertex in kal" << endreq;
132 if(m_thsvc->regHist(
"/DQAHist/zhsVER/z_of_vertex_in_kal",m_vertex_z_kal).isFailure()){
133 log << MSG::FATAL <<
"Couldn't register z of vertex in kal" << endreq;
140 NTuplePtr nt1(
ntupleSvc(),
"FILE1/minid");
141 if(nt1) m_tuple1 = nt1;
143 m_tuple1 =
ntupleSvc()->book (
"FILE1/minid", CLID_ColumnWiseTuple,
"minimal distance");
145 status = m_tuple1->addItem(
"xc", m_xc);
146 status = m_tuple1->addItem(
"yc", m_yc);
147 status = m_tuple1->addItem(
"zc", m_zc);
148 status = m_tuple1->addItem(
"mind", m_mind);
150 log << MSG::FATAL <<
"Cannot book N-tuple:" << long(m_tuple1) << endmsg;
151 return StatusCode::FAILURE;
155 NTuplePtr nt2(
ntupleSvc(),
"FILE1/chisq");
156 if(nt2) m_tuple2 = nt2;
158 m_tuple2 =
ntupleSvc()->book (
"FILE1/chisq", CLID_ColumnWiseTuple,
"chi-square of ");
160 status = m_tuple2->addItem(
"chis", m_chis);
161 status = m_tuple2->addItem(
"probs", m_probs);
162 status = m_tuple2->addItem(
"chif", m_chif);
163 status = m_tuple2->addItem(
"probf", m_probf);
165 log << MSG::FATAL <<
"Cannot book N-tuple:" << long(m_tuple2) << endmsg;
166 return StatusCode::FAILURE;
170 NTuplePtr nt3(
ntupleSvc(),
"FILE1/kalvtx");
171 if(nt3) m_tuple3 = nt3;
173 m_tuple3 =
ntupleSvc()->book (
"FILE1/kalvtx", CLID_ColumnWiseTuple,
"kalman vertex");
175 status = m_tuple3->addItem(
"kvx", m_kvx);
176 status = m_tuple3->addItem(
"kvy", m_kvy);
177 status = m_tuple3->addItem(
"kvz", m_kvz);
178 status = m_tuple3->addItem(
"chik", m_chik);
179 status = m_tuple3->addItem(
"ndofk", m_ndofk);
180 status = m_tuple3->addItem(
"probk", m_probk);
182 log << MSG::FATAL <<
"Cannot book N-tuple:" << long(m_tuple3) << endmsg;
183 return StatusCode::FAILURE;
187 NTuplePtr nt4(
ntupleSvc(),
"FILE1/glbvtx");
188 if(nt4) m_tuple4 = nt4;
190 m_tuple4 =
ntupleSvc()->book (
"FILE1/glbvtx", CLID_ColumnWiseTuple,
"global vertex");
192 status = m_tuple4->addItem(
"gvx", m_gvx);
193 status = m_tuple4->addItem(
"gvy", m_gvy);
194 status = m_tuple4->addItem(
"gvz", m_gvz);
195 status = m_tuple4->addItem(
"chig", m_chig);
196 status = m_tuple4->addItem(
"ndofg", m_ndofg);
197 status = m_tuple4->addItem(
"probg", m_probg);
199 log << MSG::FATAL <<
"Cannot book N-tuple:" << long(m_tuple4) << endmsg;
200 return StatusCode::FAILURE;
204 NTuplePtr nt5(
ntupleSvc(),
"FILE1/Pull");
205 if(nt5) m_tuple5 = nt5;
207 m_tuple5 =
ntupleSvc()->book (
"FILE1/Pull", CLID_ColumnWiseTuple,
"Pull");
209 status = m_tuple5->addItem(
"pull_drho", m_pull_drho);
210 status = m_tuple5->addItem(
"pull_phi", m_pull_phi);
211 status = m_tuple5->addItem(
"pull_kapha", m_pull_kapha);
212 status = m_tuple5->addItem(
"pull_dz", m_pull_dz);
213 status = m_tuple5->addItem(
"pull_lamb", m_pull_lamb);
214 status = m_tuple5->addItem(
"pull_momentum", m_pull_momentum);
216 log << MSG::FATAL <<
"Cannot book N-tuple:" << long(m_tuple5) << endmsg;
217 return StatusCode::FAILURE;
221 NTuplePtr nt6(
ntupleSvc(),
"FILE1/MdcTrack");
222 if(nt6) m_tuple6 = nt6;
224 m_tuple6 =
ntupleSvc()->book (
"FILE1/MdcTrack", CLID_ColumnWiseTuple,
"MdcTrack");
226 status = m_tuple6->addItem(
"MdcTrkX", m_mdcTrk_x);
227 status = m_tuple6->addItem(
"MdcTrkY", m_mdcTrk_y);
228 status = m_tuple6->addItem(
"MdcTrkZ", m_mdcTrk_z);
229 status = m_tuple6->addItem(
"MdcTrkR", m_mdcTrk_r);
230 status = m_tuple6->addItem(
"MdcTrkDrho", m_mdcTrk_dr);
231 status = m_tuple6->addItem(
"Rxy", m_rxy);
232 status = m_tuple6->addItem(
"MdcKalTrkZ", m_mdcKalTrk_z);
234 log << MSG::FATAL <<
"Cannot book N-tuple:" << long(m_tuple6) << endmsg;
235 return StatusCode::FAILURE;
239 NTuplePtr nt7(
ntupleSvc(),
"FILE1/PullG");
240 if(nt7) m_tuple7 = nt7;
242 m_tuple7 =
ntupleSvc()->book (
"FILE1/PullG", CLID_ColumnWiseTuple,
"Pull");
244 status = m_tuple7->addItem(
"gpull_drho", m_gpull_drho);
245 status = m_tuple7->addItem(
"gpull_phi", m_gpull_phi);
246 status = m_tuple7->addItem(
"gpull_kapha", m_gpull_kapha);
247 status = m_tuple7->addItem(
"gpull_dz", m_gpull_dz);
248 status = m_tuple7->addItem(
"gpull_lamb", m_gpull_lamb);
250 log << MSG::FATAL <<
"Cannot book N-tuple:" << long(m_tuple7) << endmsg;
251 return StatusCode::FAILURE;
255 log << MSG::INFO <<
"successfully return from initialize()" <<endmsg;
256 return StatusCode::SUCCESS;
264 MsgStream log(
msgSvc(), name());
265 log << MSG::INFO <<
"in execute()" << endmsg;
270 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
273 log << MSG::DEBUG <<
"run and event = " << eventHeader->runNumber()
274 <<
" " << eventHeader->eventNumber() << endreq;
275 log << MSG::DEBUG <<
"ncharg, nneu, tottks = "
276 << recEvent->totalCharged() <<
" , "
277 << recEvent->totalNeutral() <<
" , "
278 << recEvent->totalTracks() <<endreq;
280 m_runNo = eventHeader->runNumber();
282 if (eventHeader->eventNumber() % 5000 == 0) {
283 cout <<
"Event number = " << eventHeader->eventNumber()<<
" run number = "<< m_runNo << endl;
288 if (recEvent->totalCharged() < m_trackNumberCut)
return StatusCode::SUCCESS;
294 Vint icp, icm, iGood, jGood;
300 map<int, int> ParticleType;
303 for(
unsigned int i = 0; i < recEvent->totalCharged(); i++) {
306 if(!(*itTrk)->isMdcTrackValid())
continue;
307 if(!(*itTrk)->isMdcKalTrackValid())
continue;
309 if (fabs(
cos(mdcTrk->
theta())) >= m_cosThetaCut)
continue;
310 if (fabs(mdcTrk->
z()) >= m_vz0Cut)
continue;
315 if (mdcTrk->
charge() > 0) {
318 }
else if (mdcTrk->
charge() < 0) {
322 }
else if (m_pid == 1) {
345 double prob_value[5];
353 for (
int i = 1; i < 5; i++) {
354 if (prob_value[i] > prob_value[max]) {
361 if(max == 0) ParticleType[i] = 0;
362 if(max == 1) ParticleType[i] = 1;
363 if(max == 2) ParticleType[i] = 2;
364 if(max == 3) ParticleType[i] = 3;
365 if(max == 4) ParticleType[i] =4;
371 m_mdcTrk_x = mdcTrk->
x();
372 m_mdcTrk_y = mdcTrk->
y();
373 m_mdcTrk_z = mdcTrk->
helix(3);
374 m_mdcTrk_r = mdcTrk->
r();
375 m_mdcTrk_dr = mdcTrk->
helix(0);
376 m_mdcKalTrk_z = kalTrk->
helix()[3];
381 if (iGood.size() < m_trackNumberCut)
return StatusCode::SUCCESS;
387 if (m_vertexFind == 1) {
388 int nGood = iGood.size();
389 for(
int i1 = 0; i1 < nGood; i1++) {
390 int id_trk1 = iGood[i1];
398 }
else if (m_pid == 1) {
402 for(
int i2 = i1+1; i2 < nGood; i2++) {
403 int id_trk2 = iGood[i2];
410 }
else if (m_pid == 1) {
424 if(fabs(dist) > m_minDistance)
continue;
431 if(cross_cut < 3.5 * 3.5) {
439 for(
int i =0; i < jGood.size(); i++) {
440 if(jGood[i] == 1) iGood.push_back(i);
445 if (iGood.size() >= 2) m_sel_number[3]++;
446 if (iGood.size() >= 3) m_sel_number[4]++;
452 HepSymMatrix Evx(3, 0);
468 for(
int i = 0; i < iGood.size(); i++) {
469 int trk_id = iGood[i];
476 }
else if (m_pid == 1) {
485 if(!vtxfit->
Fit(0))
return StatusCode::SUCCESS;
486 m_chig = vtxfit->
chisq(0);
487 m_ndofg = 2 * iGood.size() - 3;
488 m_probg = TMath::Prob(m_chig, m_ndofg);
489 HepVector glvtx = vtxfit->
Vx(0);
495 if(!(m_vertex_x->Fill(glvtx[0]))){
496 log << MSG::FATAL <<
"Couldn't Fill x of vertex" << endreq;
499 if(!(m_vertex_y->Fill(glvtx[1]))){
500 log << MSG::FATAL <<
"Couldn't Fill y of vertex" << endreq;
503 if(!(m_vertex_z->Fill(glvtx[2]))){
504 log << MSG::FATAL <<
"Couldn't Fill z of vertex" << endreq;
508 for (
int j = 0; j < iGood.size(); j++) {
509 HepVector pull(5, 0);
510 bool success = vtxfit->
pull(0, j, pull);
512 m_gpull_drho = pull[0];
513 m_gpull_phi = pull[1];
514 m_gpull_kapha = pull[2];
515 m_gpull_dz = pull[3];
516 m_gpull_lamb = pull[4];
529 for(
int i = 0; i < iGood.size(); i++) {
530 int trk_id = iGood[i];
537 }
else if (m_pid == 1) {
546 if(kalvtx->
ndof() >= freedomCut) {
548 for(
int i = 0; i < iGood.size(); i++) {
549 m_chif = kalvtx->
chiF(i);
550 m_chis = kalvtx->
chiS(i);
551 m_probs = TMath::Prob(m_chis, 2);
552 m_probf = TMath::Prob(m_chif, 2);
555 if(kalvtx->
chiS(i) > m_chi2CutforSmooth) kalvtx->
remove(i);
558 if(kalvtx->
ndof() >= freedomCut) {
559 for(
int i = 0; i < iGood.size(); i++) {
562 HepVector Pull(5, 0);
563 Pull = kalvtx->
pull(i);
564 m_pull_drho = Pull[0];
565 m_pull_phi = Pull[1];
566 m_pull_kapha = Pull[2];
568 m_pull_lamb = Pull[4];
573 m_chik = kalvtx->
chisq();
574 m_ndofk = kalvtx->
ndof();
575 m_probk = TMath::Prob(m_chik, m_ndofk);
583 if(!(m_vertex_x_kal->Fill(xp[0]))){
584 log << MSG::FATAL <<
"Couldn't Fill kal x of vertex" << endreq;
587 if(!(m_vertex_y_kal->Fill(xp[1]))){
588 log << MSG::FATAL <<
"Couldn't Fill kal y of vertex" << endreq;
591 if(!(m_vertex_z_kal->Fill(xp[2]))){
592 log << MSG::FATAL <<
"Couldn't Fill kal z of vertex" << endreq;
598 return StatusCode::SUCCESS;
605 MsgStream log(
msgSvc(), name());
606 log << MSG::INFO <<
"in finalize()" << endmsg;
661 // Output a TXT file and a .ps figure for storing the fit results
663 const char *file_name, *figs_name;
664 if (m_hadronFile == 0) {
665 file_name = m_fileNameDst.c_str();
666 } else if (m_hadronFile == 1) {
667 file_name = m_fileNameHadron.c_str();
670 figs_name = m_figsName.c_str();
671 myC->SaveAs(figs_name);
673 ofstream file(file_name);
675 file << getenv("BES_RELEASE") << " " << m_parVer << " " << m_runNo << endl;
676 file << MeanX << " " << MeanY << " " << MeanZ << " "<< SigmaX << " "<< SigmaY << " " << SigmaZ << endl;
677 file << ErrMeanX << " " << ErrMeanY<< " " << ErrMeanZ << " " << ErrSigmaX << " " << ErrSigmaY << " " << ErrSigmaZ << endl;
678 file << MeanXKal << " "<< MeanYKal << " "<< MeanZKal << " "<< SigmaXKal << " " << SigmaYKal << " " << SigmaZKal << endl;
679 file << ErrMeanXKal << " " << ErrMeanYKal<< " " << ErrMeanZKal << " " << ErrSigmaXKal << " " << ErrSigmaYKal << " " << ErrSigmaZKal << endl;*/
689 log << MSG::ALWAYS <<
"==================================" << endreq;
690 log << MSG::ALWAYS <<
"survived event :";
691 for(
int i = 0; i < 10; i++){
692 log << MSG::ALWAYS << m_sel_number[i] <<
" ";
694 log << MSG::ALWAYS << endreq;
695 log << MSG::ALWAYS <<
"==================================" << endreq;
696 return StatusCode::SUCCESS;
void setChiMinCut(const double chi=4)
void setRecTrack(EvtRecTrack *trk)
void setMethod(const int method)
void identify(const int pidcase)
double probElectron() const
void usePidSys(const int pidsys)
static ParticleID * instance()
bool IsPidInfoValid() const
double probProton() const