13 #include <TClonesArray.h>
15 #include <TSpectrum.h>
17 #include "StEvent/StDcaGeometry.h"
18 #include "StEvent/StEvent.h"
19 #include "StGenericVertexMaker/StGenericVertexFinder.h"
20 #include "StMuDSTMaker/COMMON/StMuPrimaryVertex.h"
21 #include "St_base/StMessMgr.h"
22 #include "St_db_Maker/St_db_Maker.h"
23 #include "StarRoot/TRMatrix.h"
24 #include "StarRoot/TRSymMatrix.h"
42 mVertexConstrain(false),
44 mVertexFitMode(fitMode),
45 mSeedFinderType(seedFinder),
52 using ObjectiveFunc_t = void (*)(
int&,
double*,
double&,
double*, int);
54 ObjectiveFunc_t fcn_minuit;
60 case VertexFit_t::Beamline1D:
65 case VertexFit_t::Beamline3D:
69 case VertexFit_t::NoBeamline:
71 fcn_minuit = &StGenericVertexFinder::fcnCalcChi2DCAs;
75 mMinuit =
new TMinuit(nFitParams);
76 mMinuit->SetPrintLevel(-1);
77 mMinuit->SetMaxIterations(1000);
78 mMinuit->SetFCN(fcn_minuit);
83 StGenericVertexFinder::~StGenericVertexFinder()
85 delete mMinuit; mMinuit =
nullptr;
96 for(UInt_t i=0;i<mVertexList.size(); i++) {
99 event->addPrimaryVertex(primV,mVertexOrderMethod);
102 LOG_INFO <<
"StGenericVertexFinder::FillStEvent: Added " << mVertexList.size()
103 <<
" primary vertices using ordering method: " << mVertexOrderMethod << endm;
110 for(UInt_t i=0;i<
event->numberOfPrimaryVertices(); i++)
111 mVertexList.push_back(*(event->primaryVertex(i)));
125 TSpectrum tSpectrum(200);
127 TH1F fVtx(
"fVtx",
"z-dca distribution", 2500, -250, 250);
130 static double zWindow = 2;
134 double xyzp[6], covXyzp[21];
136 trackDca->GetXYZ(xyzp, covXyzp);
138 double offset = 0.5 * xyzp[5]/trackDca->pt();
139 double sigmaZ = std::sqrt(covXyzp[5] + offset*offset);
140 sigmaZ += fVtx.GetBinWidth(1);
144 int bin_first = fVtx.FindBin(xyzp[2] - 5*sigmaZ);
145 int bin_last = fVtx.FindBin(xyzp[2] + 5*sigmaZ);
147 for (
int iBin = bin_first; iBin <= bin_last; ++iBin)
149 double z = fVtx.GetBinCenter(iBin);
150 fVtx.AddBinContent(iBin, (TMath::Erfc((z - xyzp[2] - zWindow)/sigmaZ) - TMath::Erfc((z - xyzp[2] + zWindow)/sigmaZ))/2.);
154 int npeaks = tSpectrum.Search(&fVtx, 3,
"nodraw", std::min(0.1, 5./mDCAs.size()) );
156 auto* peaks = tSpectrum.GetPositionX();
158 return std::vector<double>(peaks, peaks + npeaks);
165 mVertexList.push_back(vtx);
168 void StGenericVertexFinder::UsePCT(
bool usePCT)
170 LOG_WARN <<
"StGenericVertexFinder::UsePCT() not implemented for this vertex finder." << endm;
171 LOG_WARN <<
"StGenericVertexFinder::Expect Post-crossing tracks to be used by default in old finders." << endm;
174 int StGenericVertexFinder::size()
const
176 return mVertexList.size();
183 return (idx<(
int)mVertexList.size())? (
StPrimaryVertex*)(&(mVertexList[idx])) : 0;
187 void StGenericVertexFinder::InitRun(
int run_number,
const St_db_Maker* db_maker)
189 LOG_INFO <<
"StGenericVertexFinder::InitRun(run_number=" << run_number <<
")" << endm;
192 bool prerequisites = db_maker && star_vertex::requiresBeamline(
mVertexFitMode);
195 if (!prerequisites)
return;
197 const TDataSet* dbDataSet =
const_cast<St_db_Maker*
>(db_maker)->GetDataBase(
"Calibrations/rhic/vertexSeed");
199 vertexSeed_st* vSeed = dbDataSet ?
static_cast<St_vertexSeed*
>(dbDataSet->FindObject(
"vertexSeed"))->GetTable() : nullptr;
202 LOG_FATAL <<
"Vertex fit w/ beamline requested but 'Calibrations/rhic/vertexSeed' table not found" << endm;
210 void StGenericVertexFinder::Clear()
216 void StGenericVertexFinder::result(TClonesArray& stMuDstPrimaryVertices)
218 stMuDstPrimaryVertices.Clear();
234 static double scale = 100;
242 double dist = dca->thelix().Dca( &point.x(), &err2);
243 double chi2 = dist*dist/err2;
245 f += scale*(1. - TMath::Exp(-chi2/scale));
254 static double scale = 100;
282 double dx = point.x() - bl.x0;
283 double dy = point.y() - bl.y0;
284 double zv = point.z();
291 double kx2_ky2_1 = kx2 + ky2 + 1;
292 double ky_dy_zv = ky*dy + zv;
293 double kx_dx_zv = kx*dx + zv;
294 double ky_dy_zv_2 = ky_dy_zv*ky_dy_zv;
295 double kx_dx_zv_2 = kx_dx_zv*kx_dx_zv;
299 ( (ky2 + 1)*dx - kx*ky*dy - kx*zv)/kx2_ky2_1,
300 ( - kx*ky*dx + (kx2 + 1)*dy - ky*zv)/kx2_ky2_1,
301 ( - kx*dx - ky*dy + (kx2 + ky2)*zv)/kx2_ky2_1
304 double dist_mag = dist_vec.mag();
313 if (dist_mag < 1e-7)
return 0;
316 double denom_sqrt = kx2_ky2_1 * sqrt( ( (kx*dy - ky*dx)*(kx*dy - ky*dx) + (ky*zv - dy)*(ky*zv - dy) + (kx*zv - dx)*(kx*zv - dx) ) /kx2_ky2_1);
317 double denom = kx2_ky2_1 * denom_sqrt;
320 double jacobian[4] = {
321 ( -(ky2 + 1)*dx + kx*ky*dy + kx*zv ) / denom_sqrt,
322 ( kx*ky*dx - (kx2 + 1)*dy + ky*zv ) / denom_sqrt,
324 ( kx*ky_dy_zv_2 - kx*(ky2 + 1)*dx*dx + (kx2 - ky2 - 1)*dx*ky_dy_zv ) / denom,
325 ( ky*kx_dx_zv_2 - ky*(kx2 + 1)*dy*dy - (kx2 - ky2 + 1)*dy*kx_dx_zv ) / denom
329 double variance_x0 = bl.err_x0*bl.err_x0;
330 double variance_y0 = bl.err_y0*bl.err_y0;
331 double variance_dxdz = bl.err_dxdz*bl.err_dxdz;
332 double variance_dydz = bl.err_dydz*bl.err_dydz;
334 double covBeamline[10] = {
338 0, 0, 0, variance_dydz
345 double chi2 = dist_mag*dist_mag/covarianceMprime[0];
364 if (trackDcas.size() == 0) {
365 LOG_WARN <<
"StGenericVertexFinder::CalcVertexSeed: Empty container with track DCAs. "
366 "Returning default seed: StThreeVectorD(0, 0, 0)" << endm;
371 double xyzp[6], covXyzp[21];
375 trackDca->GetXYZ(xyzp, covXyzp);
377 double x_weight = 1./covXyzp[0];
378 double y_weight = 1./covXyzp[2];
379 double z_weight = 1./covXyzp[5];
381 vertexSeed +=
StThreeVectorD(xyzp[0]*x_weight, xyzp[1]*y_weight, xyzp[2]*z_weight);
385 vertexSeed.set(vertexSeed.x()/totalWeigth.x(), vertexSeed.y()/totalWeigth.y(), vertexSeed.z()/totalWeigth.z());
392 void StGenericVertexFinder::NoVertexConstraint()
394 mVertexConstrain =
false;
396 LOG_INFO <<
"StGenericVertexFinder::No Vertex Constraint" << endm;
408 LOG_INFO <<
"BeamLine constraints:\n"
409 <<
"weight: " <<
mBeamline.weight <<
"\n"
virtual double CalcChi2DCAs(const StThreeVectorD &point)
Caclulates total chi2 for the track DCAs stored in mDCAs and a point.
void UseVertexConstraint(const vertexSeed_st &beamline)
double CalcChi2DCAsBeamline(const StThreeVectorD &point)
Caclulates total chi2 for the beamline and track DCAs stored in mDCAs and a point.
double CalcChi2Beamline(const StThreeVectorD &point)
Caclulates chi2 for the beamline and a point.
double beamX(double z) const
double beamY(double z) const
void FillStEvent(StEvent *)
std::vector< double > FindSeeds_TSpectrum()
static void fcnCalcChi2DCAsBeamline1D(int &npar, double *gin, double &f, double *par, Int_t iflag)
A static interface to CalcChi2DCAs(...) with x and y fixed by beamline equation.
StThreeVectorD CalcVertexSeed(const StDcaList &trackDcas)
static void fcnCalcChi2DCAsBeamline(int &npar, double *gin, double &f, double *par, int iflag)
A static interface to CalcChi2DCAsBeamline(...)
VertexFit_t mVertexFitMode
The type of vertex fit to use in derived concrete implementation.
static StGenericVertexFinder * sSelf
By default point to invalid object.
StGenericVertexFinder()
Default initialization with unspecified seed finder and fitting mode.