StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StVertex.cxx
1 /***************************************************************************
2  *
3  * $Id: StVertex.cxx,v 2.18 2015/10/09 17:46:15 ullrich Exp $
4  *
5  * Author: Thomas Ullrich, Sep 1999
6  ***************************************************************************
7  *
8  * Description:
9  *
10  ***************************************************************************
11  *
12  * $Log: StVertex.cxx,v $
13  * Revision 2.18 2015/10/09 17:46:15 ullrich
14  * Changed type of mIdTruth from ushort to int.
15  *
16  * Revision 2.17 2013/07/23 11:21:49 jeromel
17  * Undo past week changes
18  *
19  * Revision 2.15 2013/04/10 19:15:53 jeromel
20  * Step back from StEvent changes - previous change recoverable [Thomas OK-ed]
21  *
22  * Revision 2.13 2012/05/07 14:42:58 fisyak
23  * Add handilings for Track to Fast Detectors Matching
24  *
25  * Revision 2.12 2011/10/17 15:35:49 fisyak
26  * Comment's fix
27  *
28  * Revision 2.11 2011/10/17 00:13:49 fisyak
29  * Add handles for IdTruth info
30  *
31  * Revision 2.10 2009/11/23 16:34:08 fisyak
32  * Cleanup, remove dependence on dst tables, clean up software monitors
33  *
34  * Revision 2.9 2003/09/02 17:58:06 perev
35  * gcc 3.2 updates + WarnOff
36  *
37  * Revision 2.8 2001/05/30 17:45:55 perev
38  * StEvent branching
39  *
40  * Revision 2.7 2001/04/05 04:00:59 ullrich
41  * Replaced all (U)Long_t by (U)Int_t and all redundant ROOT typedefs.
42  *
43  * Revision 2.6 2000/03/08 14:29:54 ullrich
44  * New method probChiSquared() added.
45  *
46  * Revision 2.5 2000/02/10 16:32:19 ullrich
47  * flag changed from unsigned to signed long
48  *
49  * Revision 2.4 2000/01/11 19:22:12 ullrich
50  * Added non-const parent() method.
51  *
52  * Revision 2.3 1999/12/21 15:09:23 ullrich
53  * Modified to cope with new compiler version on Sun (CC5.0).
54  *
55  * Revision 2.2 1999/11/22 15:04:43 ullrich
56  * Forgot to fill mPosition in constructor. Fixed now.
57  *
58  * Revision 2.1 1999/10/28 22:28:07 ullrich
59  * Adapted new StArray version. First version to compile on Linux and Sun.
60  *
61  * Revision 2.0 1999/10/12 18:43:29 ullrich
62  * Completely Revised for New Version
63  *
64  **************************************************************************/
65 #include <algorithm>
66 #include "Riostream.h"
67 #include "TClass.h"
68 #include "TFile.h"
69 #include "StVertex.h"
70 #include "StTrack.h"
71 #include "StG2TrackVertexMap.h"
72 #include "TString.h"
73 #if !defined(ST_NO_NAMESPACES)
74 using std::fill_n;
75 using std::copy;
76 #endif
77 
78 ClassImp(StVertex)
79 
80 static const char rcsid[] = "$Id: StVertex.cxx,v 2.18 2015/10/09 17:46:15 ullrich Exp $";
81 UInt_t StVertex::fgNoFitPointCutForGoodTrack = 15;
83 {
84  mType = kUndefinedVtxId;
85  memset(mBeg, 0, mEnd-mBeg+1);
86 }
87 
88 Int_t
89 StVertex::operator==(const StVertex& v) const
90 {
91  return mType == v.mType &&
92  mFlag == v.mFlag &&
93  mPosition == v.mPosition &&
94  mChiSquared == v.mChiSquared;
95 }
96 
97 Int_t
98 StVertex::operator!=(const StVertex& v) const
99 {
100  return !(v == *this);
101 }
102 
103 StMatrixF
104 StVertex::covariantMatrix() const
105 {
106  StMatrixF m(3,3);
107  m(1,1) = mCovariantMatrix[0];
108  m(1,2) = m(2,1) = mCovariantMatrix[1];
109  m(2,2) = mCovariantMatrix[2];
110  m(1,3) = m(3,1) = mCovariantMatrix[3];
111  m(2,3) = m(3,2) = mCovariantMatrix[4];
112  m(3,3) = mCovariantMatrix[5];
113  return m;
114 }
115 
117 StVertex::positionError() const
118 {
119  return StThreeVectorF(::sqrt(mCovariantMatrix[0]), ::sqrt(mCovariantMatrix[2]), ::sqrt(mCovariantMatrix[5]));
120 }
121 
122 void StVertex::setParent(StTrack* val) { mParent = val; }
123 void StVertex::setCovariantMatrix(float val[6]) { copy(val, val+6, mCovariantMatrix); }
124 
125 void StVertex::Streamer(TBuffer &R__b)
126 {
127  // Stream an object of class .
128 
129  if (R__b.IsReading()) {
130  UInt_t R__s, R__c;
131  Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
132  if (R__v > 1) {
133  Class()->ReadBuffer(R__b, this, R__v, R__s, R__c);
134  return;
135  }
136  //====process old versions before automatic schema evolution
137  StMeasuredPoint::Streamer(R__b);
138  R__b >> (Int_t&)mType;
139  R__b >> mFlag;
140  Int_t dumy;
141  if (gFile && gFile->GetVersion() < 30000) {R__b >> dumy;}
142  R__b.ReadFastArray(mCovariantMatrix,6);
143  R__b >> mChiSquared;
144  R__b >> mProbChiSquared;
145  // R__b >> mParent;
146  R__b >> (StTrack*&)mParent;
147 
148  R__b.CheckByteCount(R__s, R__c, Class());
149  //====end of old versions
150 
151  }
152  else {
153  Class()->WriteBuffer(R__b,this);
154  }
155 }
156 
157 void StVertex::setIdTruth() { // match with IdTruth
158  typedef std::map< Int_t,Float_t> myMap_t;
159  typedef std::pair<Int_t,Float_t> myPair_t;
160  typedef myMap_t::const_iterator myIter_t;
161  myMap_t idTruths;
162  // Loop to store all the mc vertex keys and quality of every reco track on the vertex.
163  UInt_t Ntracks = numberOfDaughters();
164  Int_t IdVx = 0;
165  Int_t qa = 0;
166  for (UInt_t l = 0; l < Ntracks; l++) {
167  const StTrack *pTrack = daughter(l);
168  if (! pTrack) continue;
169  Int_t IdTk = pTrack->idTruth();
170  if (IdTk <= 0) continue;
171  IdVx = pTrack->idParentVx();
172  if (IdVx <= 0) continue;
173  qa = pTrack->qaTruth(); if (!qa) qa = 1;
174  idTruths[IdVx] += qa;
175  }
176  if (! idTruths.size()) return; //no simu info
177  Int_t vxBest = 0;
178  Float_t qaBest = 0, qaSum = 0;
179  for (myIter_t it=idTruths.begin(); it!=idTruths.end(); ++it) {
180  qaSum += (*it).second;
181  if ((*it).second < qaBest) continue;
182  vxBest = (*it).first; qaBest = (*it).second;
183  }
184  if (vxBest <= 0 || vxBest > 0xffff) return;
185  Int_t avgQua = 100*qaBest/(qaSum+1e-10)+0.5;
186  setIdTruth(vxBest,avgQua);
187  Int_t IdParentTk = StG2TrackVertexMap::instance()->IdParentTrack(vxBest);
188  setIdParent(IdParentTk);
189 }
190 
191 void StVertex::NotImplemented(const char *method) const {
192  cout << "StVertex::" << method << " is no implemented" << endl;
193 }
194 
195