4#include "CLHEP/Vector/LorentzVector.h"
5#include "CLHEP/Geometry/Point3D.h"
6#ifndef ENABLE_BACKWARDS_COMPATIBILITY
9#include "GaudiKernel/MsgStream.h"
10#include "GaudiKernel/SmartDataPtr.h"
11#include "GaudiKernel/IDataManagerSvc.h"
22#include "GaudiKernel/ITHistSvc.h"
34using CLHEP::HepLorentzVector;
37const double xmass[5] = {0.000511, 0.105658, 0.139570, 0.493677, 0.938272};
40typedef std::vector<int>
Vint;
41typedef std::vector<HepLorentzVector>
Vp4;
46 Algorithm (name, pSvcLocator)
51 declareProperty(
"ParVer", m_parVer = 1);
52 declareProperty(
"TrackNumberCut", m_trackNumberCut = 1);
53 declareProperty(
"Vz0Cut", m_vz0Cut = 50.0);
54 declareProperty(
"CosThetaCut", m_cosThetaCut=0.93);
57 declareProperty(
"OptionPID", m_pid = 0);
58 declareProperty(
"PidUseDedx", m_useDedx =
true);
59 declareProperty(
"PidUseTof1", m_useTof1 =
true);
60 declareProperty(
"PidUseTof2", m_useTof2 =
true);
61 declareProperty(
"PidUseTofE", m_useTofE =
false);
62 declareProperty(
"PidUseTofQ", m_useTofQ =
false);
63 declareProperty(
"PidUseEmc", m_useEmc =
false);
64 declareProperty(
"PidUseMuc", m_useMuc =
false);
67 declareProperty(
"OptionVertexFind", m_vertexFind = 0);
68 declareProperty(
"MinDistance", m_minDistance = 100.0);
69 declareProperty(
"MinPointX", m_minPointX = 0.1);
70 declareProperty(
"MinPointY", m_minPointY = 0.1);
71 declareProperty(
"MeanPointX", m_meanPointX = 0.1);
72 declareProperty(
"MeanPointY", m_meanPointY = -0.25);
75 declareProperty(
"ChisqCut", m_chisqCut = 200.0);
76 declareProperty(
"TrackIteration", m_trackIteration = 5);
77 declareProperty(
"VertexIteration", m_vertexIteration = 5);
78 declareProperty(
"Chi2CutforTrkIter", m_chi2CutforTrkIter = 0.1);
79 declareProperty(
"Chi2CutforSmooth", m_chi2CutforSmooth = 200.0);
82 declareProperty(
"HadronFile", m_hadronFile = 0);
83 declareProperty(
"DstFileName", m_fileNameDst = std::string(
"dst.txt"));
84 declareProperty(
"HadronFileName", m_fileNameHadron = std::string(
"hadron.txt"));
85 declareProperty(
"FigsName", m_figsName = std::string(
"figs.ps"));
91 MsgStream log(
msgSvc(), name());
92 log << MSG::INFO <<
"in initialize()" << endmsg;
94 StatusCode sc=service(
"THistSvc", m_thsvc);
96 log << MSG::FATAL <<
"Couldn't get THistSvc" << endreq;
100 for(
int i = 0; i < 15; i++){
107 m_vertex_x =
new TH1D(
"x_of_vertex",
"x of vertex", 200, -5, 5);
108 m_vertex_y =
new TH1D(
"y_of_vertex",
"y of vertex", 200, -5, 5);
109 m_vertex_z =
new TH1D(
"z_of_vertex",
"z of vertex", 200, -10, 10);
110 m_vertex_x_kal =
new TH1D(
"x_of_vertex_in_kal",
"x of vertex in kal", 200, -5, 5);
111 m_vertex_y_kal =
new TH1D(
"y_of_vertex_in_kal",
"y of vertex in kal", 200, -5, 5);
112 m_vertex_z_kal =
new TH1D(
"z_of_vertex_in_kal",
"z of vertex in kal", 200, -10, 10);
113 if(m_thsvc->regHist(
"/DQAHist/zhsVER/x_of_vertex",m_vertex_x).isFailure()){
114 log << MSG::FATAL <<
"Couldn't register x of vertex " << endreq;
117 if(m_thsvc->regHist(
"/DQAHist/zhsVER/y_of_vertex",m_vertex_y).isFailure()){
118 log << MSG::FATAL <<
"Couldn't register y of vertex" << endreq;
121 if(m_thsvc->regHist(
"/DQAHist/zhsVER/z_of_vertex",m_vertex_z).isFailure()){
122 log << MSG::FATAL <<
"Couldn't register z of vertex" << endreq;
125 if(m_thsvc->regHist(
"/DQAHist/zhsVER/x_of_vertex_in_kal",m_vertex_x_kal).isFailure()){
126 log << MSG::FATAL <<
"Couldn't register x of vertex in kal" << endreq;
129 if(m_thsvc->regHist(
"/DQAHist/zhsVER/y_of_vertex_in_kal",m_vertex_y_kal).isFailure()){
130 log << MSG::FATAL <<
"Couldn't register y of vertex in kal" << endreq;
133 if(m_thsvc->regHist(
"/DQAHist/zhsVER/z_of_vertex_in_kal",m_vertex_z_kal).isFailure()){
134 log << MSG::FATAL <<
"Couldn't register z of vertex in kal" << endreq;
141 NTuplePtr nt1(
ntupleSvc(),
"FILE1/minid");
142 if(nt1) m_tuple1 = nt1;
144 m_tuple1 =
ntupleSvc()->book (
"FILE1/minid", CLID_ColumnWiseTuple,
"minimal distance");
146 status = m_tuple1->addItem(
"xc", m_xc);
147 status = m_tuple1->addItem(
"yc", m_yc);
148 status = m_tuple1->addItem(
"zc", m_zc);
149 status = m_tuple1->addItem(
"mind", m_mind);
151 log << MSG::FATAL <<
"Cannot book N-tuple:" << long(m_tuple1) << endmsg;
152 return StatusCode::FAILURE;
156 NTuplePtr nt2(
ntupleSvc(),
"FILE1/chisq");
157 if(nt2) m_tuple2 = nt2;
159 m_tuple2 =
ntupleSvc()->book (
"FILE1/chisq", CLID_ColumnWiseTuple,
"chi-square of ");
161 status = m_tuple2->addItem(
"chis", m_chis);
162 status = m_tuple2->addItem(
"probs", m_probs);
163 status = m_tuple2->addItem(
"chif", m_chif);
164 status = m_tuple2->addItem(
"probf", m_probf);
166 log << MSG::FATAL <<
"Cannot book N-tuple:" << long(m_tuple2) << endmsg;
167 return StatusCode::FAILURE;
171 NTuplePtr nt3(
ntupleSvc(),
"FILE1/kalvtx");
172 if(nt3) m_tuple3 = nt3;
174 m_tuple3 =
ntupleSvc()->book (
"FILE1/kalvtx", CLID_ColumnWiseTuple,
"kalman vertex");
176 status = m_tuple3->addItem(
"kvx", m_kvx);
177 status = m_tuple3->addItem(
"kvy", m_kvy);
178 status = m_tuple3->addItem(
"kvz", m_kvz);
179 status = m_tuple3->addItem(
"chik", m_chik);
180 status = m_tuple3->addItem(
"ndofk", m_ndofk);
181 status = m_tuple3->addItem(
"probk", m_probk);
183 log << MSG::FATAL <<
"Cannot book N-tuple:" << long(m_tuple3) << endmsg;
184 return StatusCode::FAILURE;
188 NTuplePtr nt4(
ntupleSvc(),
"FILE1/glbvtx");
189 if(nt4) m_tuple4 = nt4;
191 m_tuple4 =
ntupleSvc()->book (
"FILE1/glbvtx", CLID_ColumnWiseTuple,
"global vertex");
193 status = m_tuple4->addItem(
"gvx", m_gvx);
194 status = m_tuple4->addItem(
"gvy", m_gvy);
195 status = m_tuple4->addItem(
"gvz", m_gvz);
196 status = m_tuple4->addItem(
"chig", m_chig);
197 status = m_tuple4->addItem(
"ndofg", m_ndofg);
198 status = m_tuple4->addItem(
"probg", m_probg);
200 log << MSG::FATAL <<
"Cannot book N-tuple:" << long(m_tuple4) << endmsg;
201 return StatusCode::FAILURE;
205 NTuplePtr nt5(
ntupleSvc(),
"FILE1/Pull");
206 if(nt5) m_tuple5 = nt5;
208 m_tuple5 =
ntupleSvc()->book (
"FILE1/Pull", CLID_ColumnWiseTuple,
"Pull");
210 status = m_tuple5->addItem(
"pull_drho", m_pull_drho);
211 status = m_tuple5->addItem(
"pull_phi", m_pull_phi);
212 status = m_tuple5->addItem(
"pull_kapha", m_pull_kapha);
213 status = m_tuple5->addItem(
"pull_dz", m_pull_dz);
214 status = m_tuple5->addItem(
"pull_lamb", m_pull_lamb);
215 status = m_tuple5->addItem(
"pull_momentum", m_pull_momentum);
217 log << MSG::FATAL <<
"Cannot book N-tuple:" << long(m_tuple5) << endmsg;
218 return StatusCode::FAILURE;
222 NTuplePtr nt6(
ntupleSvc(),
"FILE1/MdcTrack");
223 if(nt6) m_tuple6 = nt6;
225 m_tuple6 =
ntupleSvc()->book (
"FILE1/MdcTrack", CLID_ColumnWiseTuple,
"MdcTrack");
227 status = m_tuple6->addItem(
"MdcTrkX", m_mdcTrk_x);
228 status = m_tuple6->addItem(
"MdcTrkY", m_mdcTrk_y);
229 status = m_tuple6->addItem(
"MdcTrkZ", m_mdcTrk_z);
230 status = m_tuple6->addItem(
"MdcTrkR", m_mdcTrk_r);
231 status = m_tuple6->addItem(
"MdcTrkDrho", m_mdcTrk_dr);
232 status = m_tuple6->addItem(
"Rxy", m_rxy);
233 status = m_tuple6->addItem(
"MdcKalTrkZ", m_mdcKalTrk_z);
235 log << MSG::FATAL <<
"Cannot book N-tuple:" << long(m_tuple6) << endmsg;
236 return StatusCode::FAILURE;
240 NTuplePtr nt7(
ntupleSvc(),
"FILE1/PullG");
241 if(nt7) m_tuple7 = nt7;
243 m_tuple7 =
ntupleSvc()->book (
"FILE1/PullG", CLID_ColumnWiseTuple,
"Pull");
245 status = m_tuple7->addItem(
"gpull_drho", m_gpull_drho);
246 status = m_tuple7->addItem(
"gpull_phi", m_gpull_phi);
247 status = m_tuple7->addItem(
"gpull_kapha", m_gpull_kapha);
248 status = m_tuple7->addItem(
"gpull_dz", m_gpull_dz);
249 status = m_tuple7->addItem(
"gpull_lamb", m_gpull_lamb);
251 log << MSG::FATAL <<
"Cannot book N-tuple:" << long(m_tuple7) << endmsg;
252 return StatusCode::FAILURE;
256 log << MSG::INFO <<
"successfully return from initialize()" <<endmsg;
257 return StatusCode::SUCCESS;
260#define DEB cout << __FILE__ << ":" << __LINE__ << endl;
265 MsgStream log(
msgSvc(), name());
266 log << MSG::INFO <<
"in execute()" << endmsg;
271 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
274 log << MSG::DEBUG <<
"run and event = " << eventHeader->runNumber()
275 <<
" " << eventHeader->eventNumber() << endreq;
276 log << MSG::DEBUG <<
"ncharg, nneu, tottks = "
277 << recEvent->totalCharged() <<
" , "
278 << recEvent->totalNeutral() <<
" , "
279 << recEvent->totalTracks() <<endreq;
281 m_runNo = eventHeader->runNumber();
283 if (eventHeader->eventNumber() % 5000 == 0) {
284 cout <<
"Event number = " << eventHeader->eventNumber()<<
" run number = "<< m_runNo << endl;
289 if (recEvent->totalCharged() < m_trackNumberCut)
return StatusCode::SUCCESS;
295 Vint icp, icm, iGood, jGood;
301 map<int, int> ParticleType;
304 for(
unsigned int i = 0; i < recEvent->totalCharged(); i++) {
307 if(!(*itTrk)->isMdcTrackValid())
continue;
308 if(!(*itTrk)->isMdcKalTrackValid())
continue;
310 if (fabs(
cos(mdcTrk->
theta())) >= m_cosThetaCut)
continue;
311 if (fabs(mdcTrk->
z()) >= m_vz0Cut)
continue;
316 if (mdcTrk->
charge() > 0) {
319 }
else if (mdcTrk->
charge() < 0) {
323 }
else if (m_pid == 1) {
346 double prob_value[5];
354 for (
int i = 1; i < 5; i++) {
355 if (prob_value[i] > prob_value[
max]) {
362 if(
max == 0) ParticleType[i] = 0;
363 if(
max == 1) ParticleType[i] = 1;
364 if(
max == 2) ParticleType[i] = 2;
365 if(
max == 3) ParticleType[i] = 3;
366 if(
max == 4) ParticleType[i] =4;
372 m_mdcTrk_x = mdcTrk->
x();
373 m_mdcTrk_y = mdcTrk->
y();
374 m_mdcTrk_z = mdcTrk->
helix(3);
375 m_mdcTrk_r = mdcTrk->
r();
376 m_mdcTrk_dr = mdcTrk->
helix(0);
377 m_mdcKalTrk_z = kalTrk->
helix()[3];
382 if (iGood.size() < m_trackNumberCut)
return StatusCode::SUCCESS;
388 if (m_vertexFind == 1) {
389 int nGood = iGood.size();
390 for(
int i1 = 0; i1 < nGood; i1++) {
391 int id_trk1 = iGood[i1];
399 }
else if (m_pid == 1) {
403 for(
int i2 = i1+1; i2 < nGood; i2++) {
404 int id_trk2 = iGood[i2];
411 }
else if (m_pid == 1) {
425 if(fabs(dist) > m_minDistance)
continue;
432 if(cross_cut < 3.5 * 3.5) {
440 for(
int i =0; i < jGood.size(); i++) {
441 if(jGood[i] == 1) iGood.push_back(i);
446 if (iGood.size() >= 2) m_sel_number[3]++;
447 if (iGood.size() >= 3) m_sel_number[4]++;
453 HepSymMatrix Evx(3, 0);
469 for(
int i = 0; i < iGood.size(); i++) {
470 int trk_id = iGood[i];
477 }
else if (m_pid == 1) {
486 if(!vtxfit->
Fit(0))
return StatusCode::SUCCESS;
487 m_chig = vtxfit->
chisq(0);
488 m_ndofg = 2 * iGood.size() - 3;
489 m_probg = TMath::Prob(m_chig, m_ndofg);
490 HepVector glvtx = vtxfit->
Vx(0);
496 if(!(m_vertex_x->Fill(glvtx[0]))){
497 log << MSG::FATAL <<
"Couldn't Fill x of vertex" << endreq;
500 if(!(m_vertex_y->Fill(glvtx[1]))){
501 log << MSG::FATAL <<
"Couldn't Fill y of vertex" << endreq;
504 if(!(m_vertex_z->Fill(glvtx[2]))){
505 log << MSG::FATAL <<
"Couldn't Fill z of vertex" << endreq;
509 for (
int j = 0; j < iGood.size(); j++) {
510 HepVector pull(5, 0);
511 bool success = vtxfit->
pull(0, j, pull);
513 m_gpull_drho = pull[0];
514 m_gpull_phi = pull[1];
515 m_gpull_kapha = pull[2];
516 m_gpull_dz = pull[3];
517 m_gpull_lamb = pull[4];
530 for(
int i = 0; i < iGood.size(); i++) {
531 int trk_id = iGood[i];
538 }
else if (m_pid == 1) {
547 if(kalvtx->
ndof() >= freedomCut) {
549 for(
int i = 0; i < iGood.size(); i++) {
550 m_chif = kalvtx->
chiF(i);
551 m_chis = kalvtx->
chiS(i);
552 m_probs = TMath::Prob(m_chis, 2);
553 m_probf = TMath::Prob(m_chif, 2);
556 if(kalvtx->
chiS(i) > m_chi2CutforSmooth) kalvtx->
remove(i);
559 if(kalvtx->
ndof() >= freedomCut) {
560 for(
int i = 0; i < iGood.size(); i++) {
563 HepVector Pull(5, 0);
564 Pull = kalvtx->
pull(i);
565 m_pull_drho = Pull[0];
566 m_pull_phi = Pull[1];
567 m_pull_kapha = Pull[2];
569 m_pull_lamb = Pull[4];
574 m_chik = kalvtx->
chisq();
575 m_ndofk = kalvtx->
ndof();
576 m_probk = TMath::Prob(m_chik, m_ndofk);
584 if(!(m_vertex_x_kal->Fill(xp[0]))){
585 log << MSG::FATAL <<
"Couldn't Fill kal x of vertex" << endreq;
588 if(!(m_vertex_y_kal->Fill(xp[1]))){
589 log << MSG::FATAL <<
"Couldn't Fill kal y of vertex" << endreq;
592 if(!(m_vertex_z_kal->Fill(xp[2]))){
593 log << MSG::FATAL <<
"Couldn't Fill kal z of vertex" << endreq;
599 return StatusCode::SUCCESS;
606 MsgStream log(
msgSvc(), name());
607 log << MSG::INFO <<
"in finalize()" << endmsg;
662 // Output a TXT file and a .ps figure for storing the fit results
664 const char *file_name, *figs_name;
665 if (m_hadronFile == 0) {
666 file_name = m_fileNameDst.c_str();
667 } else if (m_hadronFile == 1) {
668 file_name = m_fileNameHadron.c_str();
671 figs_name = m_figsName.c_str();
672 myC->SaveAs(figs_name);
674 ofstream file(file_name);
676 file << getenv("BES_RELEASE") << " " << m_parVer << " " << m_runNo << endl;
677 file << MeanX << " " << MeanY << " " << MeanZ << " "<< SigmaX << " "<< SigmaY << " " << SigmaZ << endl;
678 file << ErrMeanX << " " << ErrMeanY<< " " << ErrMeanZ << " " << ErrSigmaX << " " << ErrSigmaY << " " << ErrSigmaZ << endl;
679 file << MeanXKal << " "<< MeanYKal << " "<< MeanZKal << " "<< SigmaXKal << " " << SigmaYKal << " " << SigmaZKal << endl;
680 file << ErrMeanXKal << " " << ErrMeanYKal<< " " << ErrMeanZKal << " " << ErrSigmaXKal << " " << ErrSigmaYKal << " " << ErrSigmaZKal << endl;*/
690 log << MSG::ALWAYS <<
"==================================" << endreq;
691 log << MSG::ALWAYS <<
"survived event :";
692 for(
int i = 0; i < 10; i++){
693 log << MSG::ALWAYS << m_sel_number[i] <<
" ";
695 log << MSG::ALWAYS << endreq;
696 log << MSG::ALWAYS <<
"==================================" << endreq;
697 return StatusCode::SUCCESS;
HepGeom::Point3D< double > HepPoint3D
std::vector< HepLorentzVector > Vp4
double cos(const BesAngle a)
EvtRecTrackCol::iterator EvtRecTrackIterator
EvtVector3R cross(const EvtVector3R &p1, const EvtVector3R &p2)
const HepVector & helix() const
static void setPidType(PidType pidType)
const HepSymMatrix & err() const
const double theta() const
const HepVector helix() const
......
double minDistanceTwoHelix(const HTrackParameter G, HepPoint3D &pos)
double pullmomentum(const int k)
void setChisqCut(const double chicut)
void addTrack(const HTrackParameter)
double chiF(const int k) const
double chiS(const int k) const
void initVertex(const VertexParameter vtx)
HepVector pull(const int k)
void setTrackIterationCut(const double chicut)
void setTrackIteration(const int num)
static KalmanVertexFit * instance()
void setVertexIteration(const int num)
int methodProbability() const
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
void AddTrack(const int number, const double mass, const RecMdcTrack *trk)
HepVector Vx(int n) const
void AddVertex(int number, VertexParameter vpar, std::vector< int > lis)
bool pull(int n, int itk, HepVector &p)
static VertexFit * instance()
void setEvx(const HepSymMatrix &eVx)
void setVx(const HepPoint3D &vx)
_EXTERN_ std::string EvtRecEvent
_EXTERN_ std::string EvtRecTrackCol