#ifndef HEP_HepVertex
#include <HepVertex.h>
#endif
#include <HepVtxTrackHelix.h>
#include <iostream>
#include <TSystem.h>
using namespace std;
#ifndef __CINT__
ClassImp(HepVertex);
#endif
HepVertex::HepVertex() {
fPos.SetXYZ(0, 0, 1);
fDaughters = new TRefArray;
fErrX = 0;
fErrY = 0;
fErrZ = 0;
fNDaughters = -999;
}
HepVertex::HepVertex(Int_t Id, Float_t X, Float_t Y, Float_t Z,
Float_t Chi2, Int_t NDoF) :
fId(Id), fChi2(Chi2), fNDoF(NDoF) {
fPos.SetXYZ(X, Y, Z);
fDaughters = new TRefArray;
fType = kInvalid;
fErrX = 0;
fErrY = 0;
fErrZ = 0;
fNDaughters = -999;
}
HepVertex::~HepVertex() {
delete fDaughters; fDaughters = 0;
}
void HepVertex::Clear(Option_t *option) {
fPos.SetXYZ(0, 0, 1);
fType = kInvalid;
fErrX = 0;
fErrY = 0;
fErrZ = 0;
delete fDaughters; fDaughters = 0;
fNDaughters = -999;
}
void HepVertex::AddDaughter(HepVtxTrackHelix *trk) {
fDaughters->Add((TObject*)trk);
HepVertex *vtx = trk->ProducedAt();
if ( vtx != 0 ) {
Error("AddDaughter",
"Track points already to a different vertex. Abort");
gSystem->Abort(0);
}
trk->SetVertex(this);
}
void HepVertex::Print(Option_t *option) const {
TString opt = option;
opt.ToLower();
if ( !opt.Contains("nohead") ) PrintHeader();
cout.setf(ios::showpoint | ios::fixed, ios::floatfield);
cout.precision(3);
cout.width(4); cout << fId;
cout.width(12); cout << X();
cout.width(12); cout << Y();
cout.width(12); cout << Z();
cout.width(15); cout << GetVtxTypeStr()->Data();
cout.width(6); cout << GetNDaughters();
cout.width(9); cout << fChi2 << "/";
cout.width(3); cout << fNDoF;
cout << endl;
if ( !opt.Contains("nohead") ) PrintFooter();
if ( opt.Contains("daughters") ) {
TIter next_trk(GetDaughters());
HepVtxTrackHelix *trk = 0;
cout << endl << "Vtx daughters:" << endl;
HepVtxTrackHelix::PrintHeader();
while ( (trk=(HepVtxTrackHelix*)next_trk()) ) {
trk->Print("nohead");
}
HepVtxTrackHelix::PrintFooter();
}
}
void HepVertex::PrintHeader() {
cout << "---------------------------------------------------------------------------" << endl
<< " Id X (cm) Y (cm) Z (cm) Type Ntrk Chi2/DoF " << endl
<< "---------------------------------------------------------------------------" << endl;
}
void HepVertex::PrintFooter() {
cout << "---------------------------------------------------------------------------" << endl;
}
TString* HepVertex::GetVtxTypeStr() const {
TString *type = new TString("");
if ( fType & kInvalid ) {
type->Append("invalid");
} else if ( fType & kDummy ) {
type->Append("dummy");
} else if ( fType & kNotSpecified ) {
type->Append("not specified");
} else if ( fType & kPrimary ) {
type->Append("primary");
} else if ( fType & kPileUp ) {
type->Append("pile-up");
} else if ( fType & kSecondary ) {
type->Append("sec");
if ( fType & kTrkKink ) type->Append(",kink");
if ( fType & kConversion ) type->Append(",conv");
if ( fType & kV0Vtx ) type->Append(",V0");
if ( fType & kV0K0s ) type->Append(",K0s");
if ( fType & kV0Lambda ) type->Append(",Lambda");
if ( fType & kV0LambdaBar ) type->Append(",LambdaBar");
if ( fType & kV0Rho ) type->Append(",Rho");
} else {
Error("GetVtxTypeStr", "Unknown vertex type %d. Abort!", fType);
gSystem->Abort(0);
}
return type;
}
Int_t HepVertex::Compare(const TObject *obj) const {
Float_t chi2 = GetChi2overNDoF();
if ( chi2 > ((HepVertex*)obj)->GetChi2overNDoF() ) return -1;
if ( chi2 == ((HepVertex*)obj)->GetChi2overNDoF() ) return 0;
if ( chi2 < ((HepVertex*)obj)->GetChi2overNDoF() ) return 1;
return 0;
}