1#include "CLHEP/Vector/LorentzVector.h"
2#include "CLHEP/Geometry/Point3D.h"
3#ifndef ENABLE_BACKWARDS_COMPATIBILITY
6#include "GaudiKernel/MsgStream.h"
7#include "GaudiKernel/SmartDataPtr.h"
8#include "GaudiKernel/IDataManagerSvc.h"
33using CLHEP::HepLorentzVector;
36const double xmass[5] = {0.000511, 0.105658, 0.139570, 0.493677, 0.938272};
38const double mpi0 = 0.134976;
41typedef std::vector<int>
Vint;
42typedef std::vector<HepLorentzVector>
Vp4;
47 Algorithm (name, pSvcLocator)
50 declareProperty(
"Output", m_output = 0);
51 declareProperty(
"TrackNumberCut", m_trackNumberCut = 1);
52 declareProperty(
"CosThetaCut", m_cosThetaCut=0.93);
53 declareProperty(
"Vz0Cut", m_vz0Cut = 40.0);
55 declareProperty(
"FitMethod", m_fitMethod = 0);
57 declareProperty(
"Chi2CutOfGlobal", m_globalChisqCut = 200.0);
60 declareProperty(
"ChisqCut", m_chisqCut = 200.0);
61 declareProperty(
"TrackIteration", m_trackIteration = 5);
62 declareProperty(
"VertexIteration", m_vertexIteration = 5);
63 declareProperty(
"Chi2CutforTrkIter", m_chi2CutforTrkIter = 0.1);
64 declareProperty(
"FreedomCut", m_freedomCut = 1);
65 declareProperty(
"Chi2CutforSmooth", m_chi2CutforSmooth = 200.0);
74 MsgStream log(
msgSvc(), name());
75 log << MSG::INFO <<
"in initialize()" << endmsg;
77 for(
int i = 0; i < 15; i++){
84 NTuplePtr nt1(
ntupleSvc(),
"FILE999/glbvtx");
85 if(nt1) m_tuple1 = nt1;
87 m_tuple1 =
ntupleSvc()->book (
"FILE999/glbvtx", CLID_ColumnWiseTuple,
"global vertex");
89 status = m_tuple1->addItem(
"gvx", m_gvx);
90 status = m_tuple1->addItem(
"gvy", m_gvy);
91 status = m_tuple1->addItem(
"gvz", m_gvz);
92 status = m_tuple1->addItem(
"chig", m_chig);
93 status = m_tuple1->addItem(
"ndofg", m_ndofg);
94 status = m_tuple1->addItem(
"probg", m_probg);
96 log << MSG::ERROR <<
"Cannot book N-tuple:" << long(m_tuple1) << endmsg;
97 return StatusCode::FAILURE;
101 NTuplePtr nt2(
ntupleSvc(),
"FILE999/chisq");
102 if(nt2) m_tuple2 = nt2;
104 m_tuple2 =
ntupleSvc()->book (
"FILE999/chisq", CLID_ColumnWiseTuple,
"chi-square of ");
106 status = m_tuple2->addItem(
"chis", m_chis);
107 status = m_tuple2->addItem(
"probs", m_probs);
108 status = m_tuple2->addItem(
"chif", m_chif);
109 status = m_tuple2->addItem(
"probf", m_probf);
111 log << MSG::ERROR <<
"Cannot book N-tuple:" << long(m_tuple2) << endmsg;
112 return StatusCode::FAILURE;
116 NTuplePtr nt3(
ntupleSvc(),
"FILE999/Pull");
117 if(nt3) m_tuple3 = nt3;
119 m_tuple3 =
ntupleSvc()->book (
"FILE999/Pull", CLID_ColumnWiseTuple,
"Pull");
121 status = m_tuple3->addItem(
"pull_drho", m_pull_drho);
122 status = m_tuple3->addItem(
"pull_phi", m_pull_phi);
123 status = m_tuple3->addItem(
"pull_kapha", m_pull_kapha);
124 status = m_tuple3->addItem(
"pull_dz", m_pull_dz);
125 status = m_tuple3->addItem(
"pull_lamb", m_pull_lamb);
126 status = m_tuple3->addItem(
"pull_momentum", m_pull_momentum);
128 log << MSG::ERROR <<
"Cannot book N-tuple:" << long(m_tuple3) << endmsg;
129 return StatusCode::FAILURE;
133 NTuplePtr nt4(
ntupleSvc(),
"FILE999/kalvtx");
134 if(nt4) m_tuple4 = nt4;
136 m_tuple4 =
ntupleSvc()->book (
"FILE999/kalvtx", CLID_ColumnWiseTuple,
"kalman vertex");
138 status = m_tuple4->addItem(
"kvx", m_kvx);
139 status = m_tuple4->addItem(
"kvy", m_kvy);
140 status = m_tuple4->addItem(
"kvz", m_kvz);
141 status = m_tuple4->addItem(
"chik", m_chik);
142 status = m_tuple4->addItem(
"ndofk", m_ndofk);
143 status = m_tuple4->addItem(
"probk", m_probk);
145 log << MSG::ERROR <<
"Cannot book N-tuple:" << long(m_tuple4) << endmsg;
146 return StatusCode::FAILURE;
151 log << MSG::INFO <<
"successfully return from initialize()" <<endmsg;
152 return StatusCode::SUCCESS;
156StatusCode PrimaryVertex::RegisterEvtRecPrimaryVertex(
158 DataObject *aEvtRecEvent;
159 eventSvc()->findObject(
"/Event/EvtRec",aEvtRecEvent);
160 if (aEvtRecEvent==
NULL) {
162 StatusCode sc = eventSvc()->registerObject(
"/Event/EvtRec",aEvtRecEvent);
163 if(sc!=StatusCode::SUCCESS) {
164 log << MSG::FATAL <<
"Could not register EvtRecEvent" <<endreq;
165 return StatusCode::FAILURE;
168 SmartIF<IDataManagerSvc> dataManSvc(eventSvc());
169 DataObject *aEvtRecPrimaryVertex;
170 eventSvc()->findObject(
"/Event/EvtRec/EvtRecPrimaryVertex",aEvtRecPrimaryVertex);
171 if(aEvtRecPrimaryVertex !=
NULL) {
173 dataManSvc->clearSubTree(
"/Event/EvtRec/EvtRecPrimaryVertex");
174 eventSvc()->unregisterObject(
"/Event/EvtRec/EvtRecPrimaryVertex");
176 StatusCode sc = eventSvc()->registerObject(
"/Event/EvtRec/EvtRecPrimaryVertex",
177 aNewEvtRecPrimaryVertex);
178 if (sc != StatusCode::SUCCESS) {
179 log << MSG::FATAL <<
"Could not register EvtRecPrimaryVertex in TDS!" << endreq;
180 return StatusCode::FAILURE;
183 return StatusCode::SUCCESS;
189void PrimaryVertex::SelectGoodChargedTracks(
190 SmartDataPtr<EvtRecEvent>& recEvent,
191 SmartDataPtr<EvtRecTrackCol>& recTrackCol,
193 assert(recEvent->totalCharged() <= recTrackCol->size());
194 for (
unsigned int i = 0; i < recEvent->totalCharged(); i++) {
196 if(!(*itTrk)->isMdcTrackValid())
continue;
197 if(!(*itTrk)->isMdcKalTrackValid())
continue;
199 if (fabs(
cos(mdcTrk->
theta())) >= m_cosThetaCut)
continue;
200 if (fabs(mdcTrk->
z()) >= m_vz0Cut)
continue;
201 iGood.push_back((*itTrk)->trackId());
202 if (mdcTrk->
charge() > 0) {
203 icp.push_back((*itTrk)->trackId());
204 }
else if (mdcTrk->
charge() < 0) {
205 icm.push_back((*itTrk)->trackId());
212 HepSymMatrix Evx(3, 0);
226 MsgStream log(
msgSvc(), name());
227 log << MSG::INFO <<
"in execute()" << endmsg;
233 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
236 log << MSG::DEBUG <<
"run and event = " << eventHeader->runNumber()
237 <<
" " << eventHeader->eventNumber() << endreq;
238 log << MSG::DEBUG <<
"ncharg, nneu, tottks = "
239 << recEvent->totalCharged() <<
" , " << recEvent->totalNeutral() <<
" , "
240 << recEvent->totalTracks() <<endreq;
249 StatusCode sc = RegisterEvtRecPrimaryVertex(aNewEvtRecPrimaryVertex, log);
250 if (sc != StatusCode::SUCCESS) {
255 if (recEvent->totalCharged() < m_trackNumberCut) {
256 return StatusCode::SUCCESS;
260 Vint icp, icm, iGood;
261 SelectGoodChargedTracks(recEvent, recTrackCol, icp, icm, iGood);
264 if (iGood.size() < m_trackNumberCut) {
265 return StatusCode::SUCCESS;
274 if (m_fitMethod == 0) {
278 for (
int i = 0; i < iGood.size(); i++) {
279 int trk_id = iGood[i];
286 trkidlis.push_back(trk_id);
289 if(!vtxfit->
Fit(0))
return StatusCode::SUCCESS;
290 if(vtxfit->
chisq(0) > m_globalChisqCut)
return StatusCode::SUCCESS;
292 m_chig = vtxfit->
chisq(0);
293 m_ndofg = 2 * iGood.size() - 3;
294 m_probg = TMath::Prob(m_chig, m_ndofg);
295 HepVector glvtx = vtxfit->
Vx(0);
316 aNewEvtRecPrimaryVertex->
setNTracks(iGood.size());
319 aNewEvtRecPrimaryVertex->
setNdof(2 * iGood.size() - 3);
325 }
else if (m_fitMethod == 1) {
334 for(
int i = 0; i < iGood.size(); i++) {
335 int trk_id = iGood[i];
345 if(kalvtx->
ndof() >= m_freedomCut) {
347 for(
int i = 0; i < iGood.size(); i++) {
349 m_chif = kalvtx->
chiF(i);
350 m_chis = kalvtx->
chiS(i);
351 m_probs = TMath::Prob(m_chis, 2);
352 m_probf = TMath::Prob(m_chif, 2);
355 if(kalvtx->
chiS(i) > m_chi2CutforSmooth) kalvtx->
remove(i);
358 if(kalvtx->
ndof() >= m_freedomCut) {
359 for(
int i = 0; i < iGood.size(); i++) {
362 HepVector Pull(5, 0);
363 Pull = kalvtx->
pull(i);
365 m_pull_drho = Pull[0];
366 m_pull_phi = Pull[1];
367 m_pull_kapha = Pull[2];
369 m_pull_lamb = Pull[4];
375 m_chik = kalvtx->
chisq();
376 m_ndofk = kalvtx->
ndof();
377 m_probk = TMath::Prob(m_chik, m_ndofk);
405 aNewEvtRecPrimaryVertex->
setVertex(kalvtx->
x());
411 return StatusCode::SUCCESS;
418 MsgStream log(
msgSvc(), name());
419 log << MSG::INFO <<
"in finalize()" << endmsg;
421 log << MSG::ALWAYS <<
"==================================" << endreq;
422 log << MSG::ALWAYS <<
"survived event :";
423 for(
int i = 0; i < 10; i++){
424 log << MSG::ALWAYS << m_sel_number[i] <<
" ";
426 log << MSG::ALWAYS << endreq;
427 log << MSG::ALWAYS <<
"==================================" << endreq;
428 return StatusCode::SUCCESS;
double cos(const BesAngle a)
EvtRecTrackCol::iterator EvtRecTrackIterator
HepGeom::Point3D< double > HepPoint3D
std::vector< HepLorentzVector > Vp4
void InitVertexParameter(VertexParameter &vxpar)
const HepVector & helix() const
static void setPidType(PidType pidType)
const HepSymMatrix & err() const
const double theta() const
void setTrackIdList(const std::vector< int > &trackIdList)
void setVertex(const HepVector &vtx)
void setFitMethod(int fitMethod)
void setErrorVertex(const HepSymMatrix &Evtx)
void setChi2(double chi2)
void setNTracks(int nTracks)
void setIsValid(bool isValid)
double pullmomentum(const int k)
void setChisqCut(const double chicut)
void addTrack(const HTrackParameter)
double chiF(const int k) const
std::vector< int > trackIDList() 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)
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)
HepSymMatrix Evx(int n) const
static VertexFit * instance()
void setEvx(const HepSymMatrix &eVx)
void setVx(const HepPoint3D &vx)
_EXTERN_ std::string EvtRecEvent
_EXTERN_ std::string EvtRecTrackCol