StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFtpcVertex.cc
1 // $Id: StFtpcVertex.cc,v 1.25 2009/11/23 16:38:11 fisyak Exp $
2 // $Log: StFtpcVertex.cc,v $
3 // Revision 1.25 2009/11/23 16:38:11 fisyak
4 // Remove dependence on dst_vertex_st
5 //
6 // Revision 1.24 2008/05/13 12:23:33 jcs
7 // set FTPC calibration vertex flag: 0 = fit successful, 1 = fit unsuccessful
8 //
9 // Revision 1.23 2008/05/12 22:15:54 jcs
10 // cleanup comments
11 //
12 // Revision 1.22 2007/01/15 08:23:02 jcs
13 // replace printf, cout and gMesMgr with Logger commands
14 //
15 // Revision 1.21 2004/04/06 18:59:21 oldi
16 // New constructor which takes input data from StVertex added.
17 //
18 // Revision 1.20 2004/02/12 19:37:11 oldi
19 // *** empty log message ***
20 //
21 // Revision 1.19 2004/01/28 01:41:33 jeromel
22 // *** empty log message ***
23 //
24 // Revision 1.18 2003/12/05 04:10:54 perev
25 // Fix typo, h1h.Set(&x_hist,low,upp) to h1h.Set(&y_hist,low,uppx)
26 //
27 // Revision 1.17 2003/10/23 04:17:31 perev
28 // Protection aginst bad TH1::Fit added
29 //
30 // Revision 1.16 2003/09/02 17:58:17 perev
31 // gcc 3.2 updates + WarnOff
32 //
33 // Revision 1.15 2003/05/20 18:35:10 oldi
34 // Cuts for vertex estimation introduced (globDca < 1 cm, multiplicity >= 200).
35 //
36 // Revision 1.14 2003/01/13 18:09:26 perev
37 // remove Clear of histogram. It is TNamed method.
38 //
39 // Revision 1.13 2002/11/06 13:47:59 oldi
40 // IFlag and Id added as data members.
41 // New functionality introduced (to clean up StFtpcTrackMaker.cxx).
42 //
43 // Revision 1.12 2002/10/31 13:42:55 oldi
44 // Code cleanup.
45 //
46 // Revision 1.11 2002/10/11 15:45:50 oldi
47 // Get FTPC geometry and dimensions from database.
48 // No field fit activated: Returns momentum = 0 but fits a helix.
49 // Bug in TrackMaker fixed (events with z_vertex > outer_ftpc_radius were cut).
50 // QA histograms corrected (0 was supressed).
51 // Code cleanup (several lines of code changed due to *params -> Instance()).
52 // cout -> gMessMgr.
53 //
54 // Revision 1.10 2002/06/04 13:43:52 oldi
55 // Minor change: 'west' -> 'hemisphere' (just a naming convention)
56 //
57 // Revision 1.9 2002/04/29 15:50:29 oldi
58 // All tracking parameters moved to StFtpcTrackingParameters.cc/hh.
59 // In a future version the actual values should be moved to an .idl file (the
60 // interface should be kept as is in StFtpcTrackingParameters.cc/hh).
61 //
62 // Revision 1.8 2002/04/05 16:51:16 oldi
63 // Cleanup of MomentumFit (StFtpcMomentumFit is now part of StFtpcTrack).
64 // Each Track inherits from StHelix, now.
65 // Therefore it is possible to calculate, now:
66 // - residuals
67 // - vertex estimations obtained by back extrapolations of FTPC tracks
68 // Chi2 was fixed.
69 // Many additional minor (and major) changes.
70 //
71 // Revision 1.7 2001/07/12 13:05:02 oldi
72 // QA histogram of FTPC vertex estimation is generated.
73 // FTPC vertex estimation is stored as pre vertex (id = 301) in any case, now.
74 //
75 // Revision 1.6 2001/01/25 15:22:39 oldi
76 // Review of the complete code.
77 // Fix of several bugs which caused memory leaks:
78 // - Tracks were not allocated properly.
79 // - Tracks (especially split tracks) were not deleted properly.
80 // - TClonesArray seems to have a problem (it could be that I used it in a
81 // wrong way). I changed all occurences to TObjArray which makes the
82 // program slightly slower but much more save (in terms of memory usage).
83 // Speed up of HandleSplitTracks() which is now 12.5 times faster than before.
84 // Cleanup.
85 //
86 // Revision 1.5 2000/11/28 14:00:53 hummler
87 // protect vertex finder against nan
88 //
89 // Revision 1.4 2000/11/10 18:39:25 oldi
90 // Changes due to replacement of StThreeVector by TVector3.
91 // New constructor added to find the main vertex with given point array.
92 //
93 // Revision 1.3 2000/06/13 14:35:00 oldi
94 // Changed cout to gMessMgr->Message().
95 //
96 // Revision 1.2 2000/05/15 14:28:15 oldi
97 // problem of preVertex solved: if no main vertex is found (z = NaN) StFtpcTrackMaker stops with kStWarn,
98 // refitting procedure completed and included in StFtpcTrackMaker (commented),
99 // new constructor of StFtpcVertex due to refitting procedure,
100 // minor cosmetic changes
101 //
102 // Revision 1.1 2000/05/10 13:39:34 oldi
103 // Initial version of StFtpcTrackMaker
104 //
105 
106 //----------Author: Holm G. H&uuml;ummler, Markus D. Oldenburg
107 //----------Last Modified: 24.07.2000
108 //----------Copyright: &copy MDO Production 1999
109 
110 #include "TH1Helper.h"
111 #include "StFtpcVertex.hh"
112 #include "StFtpcTrackingParams.hh"
113 #include "StFtpcPoint.hh"
114 #include "StMessMgr.h"
115 
116 #include "St_DataSet.h"
117 #include "St_DataSetIter.h"
118 #include "tables/St_g2t_vertex_Table.h"
119 
120 #include "StVertex.h"
121 
122 #include "TF1.h"
123 
125 // //
126 // StFtpcVertex class - representation of the main vertex for the FTPC. //
127 // //
128 // This class contains the coordinates of the main vertex plus the usual //
129 // getters and setter. It is just a wrapper of the Staf tables. //
130 // //
132 
133 ClassImp(StFtpcVertex)
134 
135 
137 {
138  // Default constructor.
139 
140  SetX(0.);
141  SetY(0.);
142  SetZ(0.);
143 
144  SetXerr(0.);
145  SetYerr(0.);
146  SetZerr(0.);
147 
148  SetIFlag(0);
149  SetId(0);
150 
151  return;
152 }
153 
154 
155 StFtpcVertex::StFtpcVertex(TObjArray *hits, TH1F *vtx_pos)
156 {
157  // Constructor with TObjArray of ftpc points - fits vertex from points
158 
159  Int_t numFppoints = hits->GetEntriesFast();
160 
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());
166 
167  for(Int_t iii=0; iii<StFtpcTrackingParams::Instance()->HistoBins(); iii++) {
168  myhist[iii]=0;
169  }
170 
171  for(Int_t ii=0; ii<120; ii++) mapMax[ii]=0;
172 
173  for(Int_t i=0; i<numFppoints;i++) {
174 
175  StFtpcPoint *thispoint = (StFtpcPoint *)hits->At(i);
176 
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)]++;
180  }
181 
182  for(Int_t secI=0; secI<6; secI++) {
183 
184  for(Int_t rowOut=0; rowOut<19; rowOut++) {
185 
186  for(Int_t rowIn=rowOut+1; rowIn<StFtpcTrackingParams::Instance()->NumberOfPadRows(); rowIn++) {
187 
188  if(rowIn<StFtpcTrackingParams::Instance()->NumberOfPadRowsPerSide() || rowOut>=StFtpcTrackingParams::Instance()->NumberOfPadRowsPerSide()) {
189 
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];
192 
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];
195 
196  if(rj>ri) {
197  Double_t intersect=(rj*zmap[rowOut]-ri*zmap[rowIn])/(rj-ri);
198 
199  if (vtx_pos) {
200  vtx_pos->Fill(intersect);
201  }
202 
203  if(intersect>StFtpcTrackingParams::Instance()->HistoMin() && intersect<StFtpcTrackingParams::Instance()->HistoMax()) {
204  myhist[int((intersect-StFtpcTrackingParams::Instance()->HistoMin())*hratio)]++;
205  }
206  }
207  }
208  }
209  }
210  }
211  }
212  }
213 
214  Int_t maxBin=StFtpcTrackingParams::Instance()->HistoBins()/2, maxHeight=0;
215 
216  Double_t vertex = 0.;
217  Double_t sigma = 0.;
218 
219  for(Int_t hindex=1; hindex<StFtpcTrackingParams::Instance()->HistoBins()-1; hindex++) {
220 
221  if(myhist[hindex]>maxHeight && myhist[hindex]>=myhist[hindex-1] && myhist[hindex]>=myhist[hindex+1]) {
222  maxBin=hindex;
223  maxHeight=myhist[hindex];
224  }
225  }
226 
227  // check if Gaussfit will fail
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])) {
233 
234  // use weighted mean instead
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]);
239  }
240 
241  else {
242 
243  // do gaussfit
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]));
250  }
251 
252  delete[] myhist;
253  delete[] mapMax;
254  delete[] zmap;
255  delete[] rmap;
256 
257  SetX(0.);
258  SetY(0.);
259  SetXerr(0.);
260  SetYerr(0.);
261 
262  if(vertex*0 != 0) {
263  cerr << "vertex not found, setting to 0!" << endl;
264  vertex = 0.;
265  sigma = 0.;
266  }
267 
268  SetZ((Double_t) vertex);
269  SetZerr((Double_t) sigma);
270 
271  SetIFlag(0);
272  SetId(0);
273 }
274 
275 
276 StFtpcVertex::StFtpcVertex(St_DataSet *const geant)
277 {
278  // Obsolete constructor taking vertex from geant.
279 
280  if (geant) {
281  St_DataSetIter geantI(geant);
282  St_g2t_vertex *g2t_vertex = (St_g2t_vertex *) geantI.Find("g2t_vertex");
283 
284  if (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;
290  }
291 
292  else {
293  Double_t dummy = 0.0;
294  SetX(dummy);
295  SetY(dummy);
296  SetZ(dummy);
297  LOG_INFO << "Using primary vertex coordinates (Default): " << endm;
298  }
299 
300  SetXerr(0.);
301  SetYerr(0.);
302  SetZerr(0.);
303 
304  SetIFlag(0);
305  SetId(0);
306  }
307 }
308 
309 
310 StFtpcVertex::StFtpcVertex(StVertex *vertex)
311 {
312  // constructor from StVertex
313 
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());
320 
321  SetIFlag(vertex->flag());
322  SetId(vertex->type());
323 }
324 
325 
326 StFtpcVertex::StFtpcVertex(TObjArray *tracks, StFtpcVertex *vertex, Char_t hemisphere)
327 {
328  // constructor from track array
329 
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.);
333 
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.);
337 
338  StFtpcVertex v;
339 
340  if (vertex == 0) {
341  // set nominal vertex to 0, 0, 0 if no nominal vertex is given
342  v = StFtpcVertex(0., 0., 0., 0., 0., 0.);
343  }
344 
345  else {
346  v = *vertex;
347  }
348 
349  TH1Helper h1h;
350  for (Int_t i = 0; i < tracks->GetEntriesFast(); i++) {
351 
352  StFtpcTrack *track = (StFtpcTrack*)tracks->At(i);
353 
354  if (track->GetHemisphere() == hemisphere && track->GetDca() < StFtpcTrackingParams::Instance()->MaxDcaVertex()) {
355  z_hist.Fill(track->z(track->pathLength(v.GetX(), v.GetY())));
356  }
357  }
358 
359 
360  // fit only 20 cm in both directions of maximum
361  double low,upp;
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) { //Bad case, fit will fail
366  SetZ(h1h.GetMean());
367  SetZerr(h1h.GetRMS());
368  } else {
369  z_hist.Fit(&gauss_z, "QN", "", low, upp);
370  SetZ(gauss_z.GetParameter(1));
371  SetZerr(gauss_z.GetParameter(2));
372  }
373 
374  for (Int_t i = 0; i < tracks->GetEntriesFast(); i++) {
375 
376  StFtpcTrack *track = (StFtpcTrack*)tracks->At(i);
377 
378  if (track->GetHemisphere() == hemisphere && track->GetDca() < StFtpcTrackingParams::Instance()->MaxDcaVertex()) {
379  StThreeVector<Double_t> rv(0, 0, GetZ());
380  StThreeVector<Double_t> nv(0,0,1);
381  Double_t pl = track->pathLength(rv, nv);
382  x_hist.Fill(track->x(pl));
383  y_hist.Fill(track->y(pl));
384  }
385  }
386 
387  // fit only 3 cm in both directions of maximum
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) { //Bad case, fit will fail
392  SetX(h1h.GetMean());
393  SetXerr(h1h.GetRMS());
394  } else {
395  x_hist.Fit(&gauss_x, "QN", "", low,upp);
396  SetX(gauss_x.GetParameter(1));
397  SetXerr(gauss_x.GetParameter(2));
398  }
399  // fit only 3 cm in both directions of maximum
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) { //Bad case, fit will fail
404  SetY(h1h.GetMean());
405  SetYerr(h1h.GetRMS());
406  } else {
407  y_hist.Fit(&gauss_y, "QN", "", low, upp);
408  SetY(gauss_y.GetParameter(1));
409  SetYerr(gauss_y.GetParameter(2));
410  }
411  if (GetX()==0 && GetY()==0 && GetZ()==0) {
412  SetIFlag(1);
413  } else {
414  SetIFlag(0);
415  }
416  SetId(0);
417 }
418 
419 
420 StFtpcVertex::StFtpcVertex(Double_t pos[6], Int_t iFlag, Int_t id)
421 {
422  // constructor from Doubles
423 
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]);
430 
431  SetIFlag(iFlag);
432  SetId(id);
433 }
434 
435 
436 StFtpcVertex::StFtpcVertex(Double_t pos[3], Double_t err[3], Int_t iFlag, Int_t id)
437 {
438  // constructor from Doubles with errors
439 
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]);
446 
447  SetIFlag(iFlag);
448  SetId(id);
449 }
450 
451 
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)
453 {
454  // constructor from Doubles with errors
455 
456  SetX(x);
457  SetY(y);
458  SetZ(z);
459  SetXerr(x_err);
460  SetYerr(y_err);
461  SetZerr(z_err);
462 
463  SetIFlag(iFlag);
464  SetId(id);
465 }
466 
467 
468 StFtpcVertex::~StFtpcVertex()
469 {
470  // Destructor.
471  // Does nothing except destruct.
472 }
473 
474 
475 StFtpcVertex::StFtpcVertex(const StFtpcVertex &vertex)
476 {
477  // Copy constructor.
478 
479  SetX(vertex.GetX());
480  SetY(vertex.GetY());
481  SetZ(vertex.GetZ());
482  SetXerr(vertex.GetXerr());
483  SetYerr(vertex.GetYerr());
484  SetZerr(vertex.GetZerr());
485 
486  SetIFlag(vertex.GetIFlag());
487  SetId(vertex.GetId());
488 }
489 
490 
491 StFtpcVertex& StFtpcVertex::operator=(const StFtpcVertex &vertex)
492 {
493  // Assignment operator.
494 
495  if (this != &vertex) { // beware of self assignment: vertex = vertex
496  SetX(vertex.GetX());
497  SetY(vertex.GetY());
498  SetZ(vertex.GetZ());
499  SetXerr(vertex.GetXerr());
500  SetYerr(vertex.GetYerr());
501  SetZerr(vertex.GetZerr());
502 
503  SetIFlag(vertex.GetIFlag());
504  SetId(vertex.GetId());
505  }
506 
507  return *this;
508 }
509 
510 
511 Int_t StFtpcVertex::CheckVertex()
512 {
513  // Perform tests to see if this vertex is usable for tracking.
514 
515  if (GetIFlag() == 1) {
516  // TPC Vertex used
517  LOG_INFO << "Using primary vertex from StEvent (" << *this << ") for Ftpc tracking." << endm;
518  }
519 
520  else if (GetIFlag() == 101) {
521  // TPC preVertex used
522  LOG_INFO << "Using Tpc preVertex estimation (" << *this << ") for Ftpc tracking." << endm;
523  }
524 
525  else if (GetIFlag() == 0) {
526  // No vertex found, therefore set to (0., 0., 0.) to make FTPC tracking possible.
527  LOG_WARN << "No vertex found. Use (" << *this << ")." << endm;
528  }
529 
530  // Check for the position of the main vertex
531  if (CoordIsNan()) {
532  LOG_WARN << "Error in vertex calculation - no tracking." << endm;
533 
534  // No tracking!
535  return 1;
536  }
537 
538  // Test if vertex is within the desired range.
539 
540  if (GetAbsZ() > StFtpcTrackingParams::Instance()->MaxVertexPosZWarning()) {
541 
542  if (GetAbsZ() > StFtpcTrackingParams::Instance()->PadRowPosZ(0)) {
543  LOG_ERROR << "Found vertex lies inside of one Ftpc. No Ftpc tracking possible." << endm;
544 
545  // No tracking!
546  return 1;
547  }
548 
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;
553  // No tracking!
554  return 1;
555  }
556 
557  else {
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;
561  // Do tracking.
562  }
563  }
564 
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;
569  // No tracking!
570  return 1;
571  }
572 
573  return 0;
574 }
575 
576 
577 ostream& operator<< (ostream& s, const StFtpcVertex &vertex)
578 {
579  // cout
580 
581  return s << "x = " << vertex.GetX() << "+-" << vertex.GetXerr() << ", "
582  << "y = " << vertex.GetY() << "+-" << vertex.GetYerr() << ", "
583  << "z = " << vertex.GetZ() << "+-" << vertex.GetZerr();
584 }
double x(double s) const
coordinates of helix at point s
Definition: StHelix.hh:182
pair< double, double > pathLength(double r) const
path length at given r (cylindrical r)
Definition: StHelix.cc:351