110 #include "TH1Helper.h"
111 #include "StFtpcVertex.hh"
112 #include "StFtpcTrackingParams.hh"
113 #include "StFtpcPoint.hh"
114 #include "StMessMgr.h"
116 #include "St_DataSet.h"
117 #include "St_DataSetIter.h"
118 #include "tables/St_g2t_vertex_Table.h"
120 #include "StVertex.h"
155 StFtpcVertex::StFtpcVertex(TObjArray *hits, TH1F *vtx_pos)
159 Int_t numFppoints = hits->GetEntriesFast();
161 Double_t *rmap =
new Double_t[StFtpcTrackingParams::Instance()->NumberOfPadRows()*6*numFppoints];
162 Double_t *zmap =
new Double_t[StFtpcTrackingParams::Instance()->NumberOfPadRows()];
163 Int_t *mapMax =
new Int_t[StFtpcTrackingParams::Instance()->NumberOfPadRows()*6];
164 Int_t *myhist =
new Int_t[StFtpcTrackingParams::Instance()->HistoBins()];
165 Double_t hratio=StFtpcTrackingParams::Instance()->HistoBins()/(StFtpcTrackingParams::Instance()->HistoMax()-StFtpcTrackingParams::Instance()->HistoMin());
167 for(Int_t iii=0; iii<StFtpcTrackingParams::Instance()->HistoBins(); iii++) {
171 for(Int_t ii=0; ii<120; ii++) mapMax[ii]=0;
173 for(Int_t i=0; i<numFppoints;i++) {
177 rmap[(thispoint->GetPadRow()-1)+StFtpcTrackingParams::Instance()->NumberOfPadRows()*(thispoint->GetSector()-1)+120*mapMax[(thispoint->GetPadRow()-1)+StFtpcTrackingParams::Instance()->NumberOfPadRows()*(thispoint->GetSector()-1)]]=::sqrt(thispoint->GetX()*thispoint->GetX()+thispoint->GetY()*thispoint->GetY());
178 zmap[thispoint->GetPadRow()-1]=thispoint->GetZ();
179 mapMax[(thispoint->GetPadRow()-1)+StFtpcTrackingParams::Instance()->NumberOfPadRows()*(thispoint->GetSector()-1)]++;
182 for(Int_t secI=0; secI<6; secI++) {
184 for(Int_t rowOut=0; rowOut<19; rowOut++) {
186 for(Int_t rowIn=rowOut+1; rowIn<StFtpcTrackingParams::Instance()->NumberOfPadRows(); rowIn++) {
188 if(rowIn<StFtpcTrackingParams::Instance()->NumberOfPadRowsPerSide() || rowOut>=StFtpcTrackingParams::Instance()->NumberOfPadRowsPerSide()) {
190 for(Int_t iOut=0; iOut<mapMax[rowOut+StFtpcTrackingParams::Instance()->NumberOfPadRows()*secI]; iOut++) {
191 Double_t ri=rmap[rowOut+StFtpcTrackingParams::Instance()->NumberOfPadRows()*secI+120*iOut];
193 for(Int_t iIn=0; iIn<mapMax[(rowIn)+StFtpcTrackingParams::Instance()->NumberOfPadRows()*secI]; iIn++) {
194 Double_t rj=rmap[rowIn+StFtpcTrackingParams::Instance()->NumberOfPadRows()*secI+120*iIn];
197 Double_t intersect=(rj*zmap[rowOut]-ri*zmap[rowIn])/(rj-ri);
200 vtx_pos->Fill(intersect);
203 if(intersect>StFtpcTrackingParams::Instance()->HistoMin() && intersect<StFtpcTrackingParams::Instance()->HistoMax()) {
204 myhist[int((intersect-StFtpcTrackingParams::Instance()->HistoMin())*hratio)]++;
214 Int_t maxBin=StFtpcTrackingParams::Instance()->HistoBins()/2, maxHeight=0;
219 for(Int_t hindex=1; hindex<StFtpcTrackingParams::Instance()->HistoBins()-1; hindex++) {
221 if(myhist[hindex]>maxHeight && myhist[hindex]>=myhist[hindex-1] && myhist[hindex]>=myhist[hindex+1]) {
223 maxHeight=myhist[hindex];
228 if((myhist[maxBin] == 0)
229 || (myhist[maxBin+1] == 0)
230 || (myhist[maxBin-1] == 0)
231 || (myhist[maxBin] <= myhist[maxBin+1])
232 || (myhist[maxBin] <= myhist[maxBin-1])) {
235 vertex=(myhist[maxBin]*((maxBin+0.5)/hratio+StFtpcTrackingParams::Instance()->HistoMin())
236 + myhist[maxBin-1]*((maxBin-0.5)/hratio+StFtpcTrackingParams::Instance()->HistoMin())
237 + myhist[maxBin+1]*((maxBin+1.5)/hratio+StFtpcTrackingParams::Instance()->HistoMin()))
238 / (myhist[maxBin]+myhist[maxBin-1]+myhist[maxBin+1]);
244 sigma = sqrt (1 / ((2 * ::log((
double)myhist[maxBin])) -
245 (::log((
double)myhist[maxBin+1]) +
246 ::log((
double)myhist[maxBin-1]))));
247 vertex = ((maxBin+0.5)/hratio+StFtpcTrackingParams::Instance()->HistoMin()) +
248 sigma*sigma/(hratio*hratio) * (::log((
double)myhist[maxBin+1]) -
249 ::log((
double)myhist[maxBin-1]));
263 cerr <<
"vertex not found, setting to 0!" << endl;
268 SetZ((Double_t) vertex);
269 SetZerr((Double_t) sigma);
276 StFtpcVertex::StFtpcVertex(
St_DataSet *
const geant)
282 St_g2t_vertex *g2t_vertex = (St_g2t_vertex *) geantI.Find(
"g2t_vertex");
285 g2t_vertex_st *vertex = g2t_vertex->GetTable();
286 SetX((Double_t) vertex->ge_x[0]);
287 SetY((Double_t) vertex->ge_x[1]);
288 SetZ((Double_t) vertex->ge_x[2]);
289 LOG_INFO <<
"Using primary vertex coordinates (Geant): " << endm;
293 Double_t dummy = 0.0;
297 LOG_INFO <<
"Using primary vertex coordinates (Default): " << endm;
310 StFtpcVertex::StFtpcVertex(
StVertex *vertex)
314 SetX(vertex->position().x());
315 SetY(vertex->position().y());
316 SetZ(vertex->position().z());
317 SetXerr(vertex->positionError().x());
318 SetYerr(vertex->positionError().y());
319 SetZerr(vertex->positionError().z());
321 SetIFlag(vertex->flag());
322 SetId(vertex->type());
326 StFtpcVertex::StFtpcVertex(TObjArray *tracks,
StFtpcVertex *vertex, Char_t hemisphere)
330 TH1F x_hist(
"x_hist",
"x position of estimated vertex", 200, -10., 10.);
331 TH1F y_hist(
"y_hist",
"y position of estimated vertex", 200, -10., 10.);
332 TH1F z_hist(
"z_hist",
"z position of estimated vertex", 200, -75., 75.);
334 TF1 gauss_x(
"gauss_x",
"gaus", -10., 10.);
335 TF1 gauss_y(
"gauss_y",
"gaus", -10., 10.);
336 TF1 gauss_z(
"gauss_z",
"gaus", -75., 75.);
350 for (Int_t i = 0; i < tracks->GetEntriesFast(); i++) {
354 if (track->GetHemisphere() == hemisphere && track->GetDca() < StFtpcTrackingParams::Instance()->MaxDcaVertex()) {
355 z_hist.Fill(track->z(track->
pathLength(v.GetX(), v.GetY())));
362 low = z_hist.GetXaxis()->GetBinCenter(z_hist.GetMaximumBin())-20;
363 upp = z_hist.GetXaxis()->GetBinCenter(z_hist.GetMaximumBin())+20;
364 h1h.Set(&z_hist,low,upp);
365 if (h1h.GetNonZeros()<=2) {
367 SetZerr(h1h.GetRMS());
369 z_hist.Fit(&gauss_z,
"QN",
"", low, upp);
370 SetZ(gauss_z.GetParameter(1));
371 SetZerr(gauss_z.GetParameter(2));
374 for (Int_t i = 0; i < tracks->GetEntriesFast(); i++) {
378 if (track->GetHemisphere() == hemisphere && track->GetDca() < StFtpcTrackingParams::Instance()->MaxDcaVertex()) {
382 x_hist.Fill(track->
x(pl));
383 y_hist.Fill(track->y(pl));
388 low = x_hist.GetXaxis()->GetBinCenter(x_hist.GetMaximumBin())-3;
389 upp = x_hist.GetXaxis()->GetBinCenter(x_hist.GetMaximumBin())+3;
390 h1h.Set(&x_hist,low,upp);
391 if (h1h.GetNonZeros()<=2) {
393 SetXerr(h1h.GetRMS());
395 x_hist.Fit(&gauss_x,
"QN",
"", low,upp);
396 SetX(gauss_x.GetParameter(1));
397 SetXerr(gauss_x.GetParameter(2));
400 low = y_hist.GetXaxis()->GetBinCenter(y_hist.GetMaximumBin())-3;
401 upp = y_hist.GetXaxis()->GetBinCenter(y_hist.GetMaximumBin())+3;
402 h1h.Set(&y_hist,low,upp);
403 if (h1h.GetNonZeros()<=2) {
405 SetYerr(h1h.GetRMS());
407 y_hist.Fit(&gauss_y,
"QN",
"", low, upp);
408 SetY(gauss_y.GetParameter(1));
409 SetYerr(gauss_y.GetParameter(2));
411 if (GetX()==0 && GetY()==0 && GetZ()==0) {
420 StFtpcVertex::StFtpcVertex(Double_t pos[6], Int_t iFlag, Int_t
id)
424 SetX((Double_t) pos[0]);
425 SetY((Double_t) pos[1]);
426 SetZ((Double_t) pos[2]);
427 SetXerr((Double_t) pos[3]);
428 SetYerr((Double_t) pos[4]);
429 SetZerr((Double_t) pos[5]);
436 StFtpcVertex::StFtpcVertex(Double_t pos[3], Double_t err[3], Int_t iFlag, Int_t
id)
440 SetX((Double_t) pos[0]);
441 SetY((Double_t) pos[1]);
442 SetZ((Double_t) pos[2]);
443 SetXerr((Double_t) err[0]);
444 SetYerr((Double_t) err[1]);
445 SetZerr((Double_t) err[2]);
452 StFtpcVertex::StFtpcVertex(Double_t x, Double_t y, Double_t z, Double_t x_err, Double_t y_err, Double_t z_err, Int_t iFlag, Int_t
id)
468 StFtpcVertex::~StFtpcVertex()
482 SetXerr(vertex.GetXerr());
483 SetYerr(vertex.GetYerr());
484 SetZerr(vertex.GetZerr());
486 SetIFlag(vertex.GetIFlag());
487 SetId(vertex.GetId());
495 if (
this != &vertex) {
499 SetXerr(vertex.GetXerr());
500 SetYerr(vertex.GetYerr());
501 SetZerr(vertex.GetZerr());
503 SetIFlag(vertex.GetIFlag());
504 SetId(vertex.GetId());
511 Int_t StFtpcVertex::CheckVertex()
515 if (GetIFlag() == 1) {
517 LOG_INFO <<
"Using primary vertex from StEvent (" << *
this <<
") for Ftpc tracking." << endm;
520 else if (GetIFlag() == 101) {
522 LOG_INFO <<
"Using Tpc preVertex estimation (" << *
this <<
") for Ftpc tracking." << endm;
525 else if (GetIFlag() == 0) {
527 LOG_WARN <<
"No vertex found. Use (" << *
this <<
")." << endm;
532 LOG_WARN <<
"Error in vertex calculation - no tracking." << endm;
540 if (GetAbsZ() > StFtpcTrackingParams::Instance()->MaxVertexPosZWarning()) {
542 if (GetAbsZ() > StFtpcTrackingParams::Instance()->PadRowPosZ(0)) {
543 LOG_ERROR <<
"Found vertex lies inside of one Ftpc. No Ftpc tracking possible." << endm;
549 else if (GetAbsZ() > StFtpcTrackingParams::Instance()->MaxVertexPosZError()) {
550 LOG_ERROR <<
"Found vertex is more than "
551 << StFtpcTrackingParams::Instance()->MaxVertexPosZError()
552 <<
" cm off from z = 0. Ftpc tracking makes no sense." << endm;
558 LOG_WARN <<
"Found vertex is more than "
559 << StFtpcTrackingParams::Instance()->MaxVertexPosZWarning()
560 <<
" cm off from z = 0 but Ftpc tracking is still possible." << endm;
565 if (GetRadius2() >= StFtpcTrackingParams::Instance()->InnerRadius()) {
566 LOG_ERROR <<
"Found vertex x-z-position is greater than "
567 << StFtpcTrackingParams::Instance()->InnerRadius()
568 <<
" cm (inner Ftpc radius). No Ftpc tracking possible." << endm;
577 ostream& operator<< (ostream& s,
const StFtpcVertex &vertex)
581 return s <<
"x = " << vertex.GetX() <<
"+-" << vertex.GetXerr() <<
", "
582 <<
"y = " << vertex.GetY() <<
"+-" << vertex.GetYerr() <<
", "
583 <<
"z = " << vertex.GetZ() <<
"+-" << vertex.GetZerr();
double x(double s) const
coordinates of helix at point s
pair< double, double > pathLength(double r) const
path length at given r (cylindrical r)