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;
46 Algorithm (name, pSvcLocator)
49 declareProperty(
"Output", m_output = 0);
50 declareProperty(
"TrackNumberCut", m_trackNumberCut = 1);
51 declareProperty(
"CosThetaCut", m_cosThetaCut=0.93);
52 declareProperty(
"Vz0Cut", m_vz0Cut = 40.0);
54 declareProperty(
"FitMethod", m_fitMethod = 0);
56 declareProperty(
"Chi2CutOfGlobal", m_globalChisqCut = 200.0);
59 declareProperty(
"ChisqCut", m_chisqCut = 200.0);
60 declareProperty(
"TrackIteration", m_trackIteration = 5);
61 declareProperty(
"VertexIteration", m_vertexIteration = 5);
62 declareProperty(
"Chi2CutforTrkIter", m_chi2CutforTrkIter = 0.1);
63 declareProperty(
"FreedomCut", m_freedomCut = 1);
64 declareProperty(
"Chi2CutforSmooth", m_chi2CutforSmooth = 200.0);
73 MsgStream log(
msgSvc(), name());
74 log << MSG::INFO <<
"in initialize()" << endmsg;
76 for(
int i = 0; i < 15; i++){
83 NTuplePtr nt1(
ntupleSvc(),
"FILE999/glbvtx");
84 if(nt1) m_tuple1 = nt1;
86 m_tuple1 =
ntupleSvc()->book (
"FILE999/glbvtx", CLID_ColumnWiseTuple,
"global vertex");
88 status = m_tuple1->addItem(
"gvx", m_gvx);
89 status = m_tuple1->addItem(
"gvy", m_gvy);
90 status = m_tuple1->addItem(
"gvz", m_gvz);
91 status = m_tuple1->addItem(
"chig", m_chig);
92 status = m_tuple1->addItem(
"ndofg", m_ndofg);
93 status = m_tuple1->addItem(
"probg", m_probg);
95 log << MSG::ERROR <<
"Cannot book N-tuple:" << long(m_tuple1) << endmsg;
96 return StatusCode::FAILURE;
100 NTuplePtr nt2(
ntupleSvc(),
"FILE999/chisq");
101 if(nt2) m_tuple2 = nt2;
103 m_tuple2 =
ntupleSvc()->book (
"FILE999/chisq", CLID_ColumnWiseTuple,
"chi-square of ");
105 status = m_tuple2->addItem(
"chis", m_chis);
106 status = m_tuple2->addItem(
"probs", m_probs);
107 status = m_tuple2->addItem(
"chif", m_chif);
108 status = m_tuple2->addItem(
"probf", m_probf);
110 log << MSG::ERROR <<
"Cannot book N-tuple:" << long(m_tuple2) << endmsg;
111 return StatusCode::FAILURE;
115 NTuplePtr nt3(
ntupleSvc(),
"FILE999/Pull");
116 if(nt3) m_tuple3 = nt3;
118 m_tuple3 =
ntupleSvc()->book (
"FILE999/Pull", CLID_ColumnWiseTuple,
"Pull");
120 status = m_tuple3->addItem(
"pull_drho", m_pull_drho);
121 status = m_tuple3->addItem(
"pull_phi", m_pull_phi);
122 status = m_tuple3->addItem(
"pull_kapha", m_pull_kapha);
123 status = m_tuple3->addItem(
"pull_dz", m_pull_dz);
124 status = m_tuple3->addItem(
"pull_lamb", m_pull_lamb);
125 status = m_tuple3->addItem(
"pull_momentum", m_pull_momentum);
127 log << MSG::ERROR <<
"Cannot book N-tuple:" << long(m_tuple3) << endmsg;
128 return StatusCode::FAILURE;
132 NTuplePtr nt4(
ntupleSvc(),
"FILE999/kalvtx");
133 if(nt4) m_tuple4 = nt4;
135 m_tuple4 =
ntupleSvc()->book (
"FILE999/kalvtx", CLID_ColumnWiseTuple,
"kalman vertex");
137 status = m_tuple4->addItem(
"kvx", m_kvx);
138 status = m_tuple4->addItem(
"kvy", m_kvy);
139 status = m_tuple4->addItem(
"kvz", m_kvz);
140 status = m_tuple4->addItem(
"chik", m_chik);
141 status = m_tuple4->addItem(
"ndofk", m_ndofk);
142 status = m_tuple4->addItem(
"probk", m_probk);
144 log << MSG::ERROR <<
"Cannot book N-tuple:" << long(m_tuple4) << endmsg;
145 return StatusCode::FAILURE;
150 log << MSG::INFO <<
"successfully return from initialize()" <<endmsg;
151 return StatusCode::SUCCESS;
155StatusCode PrimaryVertex::RegisterEvtRecPrimaryVertex(
157 DataObject *aEvtRecEvent;
158 eventSvc()->findObject(
"/Event/EvtRec",aEvtRecEvent);
159 if (aEvtRecEvent==
NULL) {
161 StatusCode sc = eventSvc()->registerObject(
"/Event/EvtRec",aEvtRecEvent);
162 if(sc!=StatusCode::SUCCESS) {
163 log << MSG::FATAL <<
"Could not register EvtRecEvent" <<endreq;
164 return StatusCode::FAILURE;
167 SmartIF<IDataManagerSvc> dataManSvc(eventSvc());
168 DataObject *aEvtRecPrimaryVertex;
169 eventSvc()->findObject(
"/Event/EvtRec/EvtRecPrimaryVertex",aEvtRecPrimaryVertex);
170 if(aEvtRecPrimaryVertex !=
NULL) {
172 dataManSvc->clearSubTree(
"/Event/EvtRec/EvtRecPrimaryVertex");
173 eventSvc()->unregisterObject(
"/Event/EvtRec/EvtRecPrimaryVertex");
175 StatusCode sc = eventSvc()->registerObject(
"/Event/EvtRec/EvtRecPrimaryVertex",
176 aNewEvtRecPrimaryVertex);
177 if (sc != StatusCode::SUCCESS) {
178 log << MSG::FATAL <<
"Could not register EvtRecPrimaryVertex in TDS!" << endreq;
179 return StatusCode::FAILURE;
182 return StatusCode::SUCCESS;
188void PrimaryVertex::SelectGoodChargedTracks(
189 SmartDataPtr<EvtRecEvent>& recEvent,
190 SmartDataPtr<EvtRecTrackCol>& recTrackCol,
192 assert(recEvent->totalCharged() <= recTrackCol->size());
193 for (
unsigned int i = 0; i < recEvent->totalCharged(); i++) {
195 if(!(*itTrk)->isMdcTrackValid())
continue;
196 if(!(*itTrk)->isMdcKalTrackValid())
continue;
198 if (fabs(
cos(mdcTrk->
theta())) >= m_cosThetaCut)
continue;
199 if (fabs(mdcTrk->
z()) >= m_vz0Cut)
continue;
200 iGood.push_back((*itTrk)->trackId());
201 if (mdcTrk->
charge() > 0) {
202 icp.push_back((*itTrk)->trackId());
203 }
else if (mdcTrk->
charge() < 0) {
204 icm.push_back((*itTrk)->trackId());
211 HepSymMatrix Evx(3, 0);
225 MsgStream log(
msgSvc(), name());
226 log << MSG::INFO <<
"in execute()" << endmsg;
232 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
235 log << MSG::DEBUG <<
"run and event = " << eventHeader->runNumber()
236 <<
" " << eventHeader->eventNumber() << endreq;
237 log << MSG::DEBUG <<
"ncharg, nneu, tottks = "
238 << recEvent->totalCharged() <<
" , " << recEvent->totalNeutral() <<
" , "
239 << recEvent->totalTracks() <<endreq;
248 StatusCode sc = RegisterEvtRecPrimaryVertex(aNewEvtRecPrimaryVertex, log);
249 if (sc != StatusCode::SUCCESS) {
254 if (recEvent->totalCharged() < m_trackNumberCut) {
255 return StatusCode::SUCCESS;
259 Vint icp, icm, iGood;
260 SelectGoodChargedTracks(recEvent, recTrackCol, icp, icm, iGood);
263 if (iGood.size() < m_trackNumberCut) {
264 return StatusCode::SUCCESS;
273 if (m_fitMethod == 0) {
277 for (
int i = 0; i < iGood.size(); i++) {
278 int trk_id = iGood[i];
285 trkidlis.push_back(trk_id);
288 if(!vtxfit->
Fit(0))
return StatusCode::SUCCESS;
289 if(vtxfit->
chisq(0) > m_globalChisqCut)
return StatusCode::SUCCESS;
291 m_chig = vtxfit->
chisq(0);
292 m_ndofg = 2 * iGood.size() - 3;
293 m_probg = TMath::Prob(m_chig, m_ndofg);
294 HepVector glvtx = vtxfit->
Vx(0);
315 aNewEvtRecPrimaryVertex->
setNTracks(iGood.size());
318 aNewEvtRecPrimaryVertex->
setNdof(2 * iGood.size() - 3);
324 }
else if (m_fitMethod == 1) {
333 for(
int i = 0; i < iGood.size(); i++) {
334 int trk_id = iGood[i];
344 if(kalvtx->
ndof() >= m_freedomCut) {
346 for(
int i = 0; i < iGood.size(); i++) {
348 m_chif = kalvtx->
chiF(i);
349 m_chis = kalvtx->
chiS(i);
350 m_probs = TMath::Prob(m_chis, 2);
351 m_probf = TMath::Prob(m_chif, 2);
354 if(kalvtx->
chiS(i) > m_chi2CutforSmooth) kalvtx->
remove(i);
357 if(kalvtx->
ndof() >= m_freedomCut) {
358 for(
int i = 0; i < iGood.size(); i++) {
361 HepVector Pull(5, 0);
362 Pull = kalvtx->
pull(i);
364 m_pull_drho = Pull[0];
365 m_pull_phi = Pull[1];
366 m_pull_kapha = Pull[2];
368 m_pull_lamb = Pull[4];
374 m_chik = kalvtx->
chisq();
375 m_ndofk = kalvtx->
ndof();
376 m_probk = TMath::Prob(m_chik, m_ndofk);
404 aNewEvtRecPrimaryVertex->
setVertex(kalvtx->
x());
410 return StatusCode::SUCCESS;
417 MsgStream log(
msgSvc(), name());
418 log << MSG::INFO <<
"in finalize()" << endmsg;
420 log << MSG::ALWAYS <<
"==================================" << endreq;
421 log << MSG::ALWAYS <<
"survived event :";
422 for(
int i = 0; i < 10; i++){
423 log << MSG::ALWAYS << m_sel_number[i] <<
" ";
425 log << MSG::ALWAYS << endreq;
426 log << MSG::ALWAYS <<
"==================================" << endreq;
427 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)
PrimaryVertex(const std::string &name, ISvcLocator *pSvcLocator)
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