StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
DcaService.cxx
1 // //
3 // DcaService //
4 // Author: G. Van Buren, BNL //
5 // Tool to re-calculate DCAs for strangeMuDst classes //
6 // //
8 
9 #include "DcaService.h"
10 #include "StXiMuDst.hh"
11 #include "TMath.h"
12 #include "TDataMember.h"
13 #include "TRealData.h"
14 #include "phys_constants.h"
15 #include "math_constants.h"
16 #include "TClass.h"
17 #include "StMessMgr.h"
18 #include <cassert>
19 
20 Long_t GGetOffset(TClass* cl, TDataMember* that);
21 
22 ClassImp(DcaService)
23 
24 double DcaService::B = 0.0;
25 StThreeVectorD DcaService::PrimVertex(0.,0.,0.);
26 StThreeVectorD DcaService::Origin(0.,0.,0.);
27 StHelixD DcaService::Track(0.,0.,0.,DcaService::Origin,0);
28 Long_t DcaService::offsetDcaXiToPrimVertex = 0;
29 Long_t DcaService::offsetDcaBachelorToPrimVertex = 0;
30 Long_t DcaService::offsetDcaPosToPrimVertex = 0;
31 Long_t DcaService::offsetDcaNegToPrimVertex = 0;
32 
33 void DcaService::initOffsets() {
34  offsetDcaXiToPrimVertex = 0;
35  offsetDcaBachelorToPrimVertex = 0;
36  offsetDcaPosToPrimVertex = 0;
37  offsetDcaNegToPrimVertex = 0;
38 }
39 
40 void DcaService::setPrimVertex(StStrangeEvMuDst* ev) {
41  PrimVertex.setX(ev->primaryVertexX());
42  PrimVertex.setY(ev->primaryVertexY());
43  PrimVertex.setZ(ev->primaryVertexZ());
44 }
45 
46 double DcaService::dcaToPrimVertex(int charge, Float_t x, Float_t y, Float_t z,
47  Float_t px, Float_t py, Float_t pz) {
48  // Given a charge, position and momentum, calculate DCA to primary vertex
49  double pt = TMath::Sqrt(px*px + py*py);
50  double bcharge = ((double) charge)*B;
51  double curvature = TMath::Abs(bcharge)*C_D_CURVATURE/pt;
52  double dip = TMath::ATan(pz/pt);
53  int h = ((bcharge > 0) ? -1 : 1);
54  double phase = TMath::ATan2(py,px) - (h*C_PI_2);
55  Origin.setX(x);
56  Origin.setY(y);
57  Origin.setZ(z);
58  Track.setParameters(curvature, dip, phase, Origin, h);
59  return Track.distance(PrimVertex);
60 }
61 
62 double DcaService::dcaXiToPrimVertex(StXiMuDst* xi) {
63  return dcaToPrimVertex(xi->charge(),
64  xi->decayVertexXiX(), xi->decayVertexXiY(), xi->decayVertexXiZ(),
65  xi->momXiX(), xi->momXiY(), xi->momXiZ());
66 }
67 
68 double DcaService::dcaBachelorToPrimVertex(StXiMuDst* xi) {
69  return dcaToPrimVertex(xi->charge(),
70  xi->decayVertexXiX(), xi->decayVertexXiY(), xi->decayVertexXiZ(),
71  xi->momBachelorX(), xi->momBachelorY(), xi->momBachelorZ());
72 }
73 
74 double DcaService::dcaPosToPrimVertex(StV0MuDst* v0) {
75  return dcaToPrimVertex(1,
76  v0->decayVertexV0X(), v0->decayVertexV0Y(), v0->decayVertexV0Z(),
77  v0->momPosX(), v0->momPosY(), v0->momPosZ());
78 }
79 
80 double DcaService::dcaNegToPrimVertex(StV0MuDst* v0) {
81  return dcaToPrimVertex(-1,
82  v0->decayVertexV0X(), v0->decayVertexV0Y(), v0->decayVertexV0Z(),
83  v0->momNegX(), v0->momNegY(), v0->momNegZ());
84 }
85 
86 double DcaService::signIt() {
87  // Give a sign of negative if the primary vertex is outside
88  // the curvature of the track.
89  StThreeVectorD p1 = Track.at(Track.pathLength(PrimVertex));
90  StThreeVectorD p2(p1.x()-Track.xcenter(),
91  p1.y()-Track.ycenter(),0);
92  StThreeVectorD p3(PrimVertex.x()-Track.xcenter(),
93  PrimVertex.y()-Track.ycenter(),0);
94  if (p3.mag2() > p2.mag2()) return -1.0;
95  return 1.0;
96 }
97 
98 void DcaService::replaceDca(TObject* obj, Float_t dca, Long_t& offset, TClass* cl,
99  const char* memname) {
100  if (!offset) {
101  offset = GGetOffset(cl,cl->GetDataMember(memname));
102  if (!offset) LOG_WARN << Form("OFFSET NOT FOUND: %s in %s\n",
103  memname,cl->GetName()) << endm;
104  }
105  Float_t* cf = (Float_t*) obj;
106  Float_t* dcaptr = (Float_t*) (((Long_t) cf) + offset);
107  *dcaptr = dca;
108 }
109 
110 void DcaService::replaceDcaXiToPrimVertex(StXiMuDst* xi,Float_t dca) {
111  replaceDca(xi,dca,offsetDcaXiToPrimVertex,xi->Class(),
112  "mDcaXiToPrimVertex");
113 }
114 
115 void DcaService::replaceDcaBachelorToPrimVertex(StXiMuDst* xi,Float_t dca) {
116  replaceDca(xi,dca,offsetDcaBachelorToPrimVertex,xi->Class(),
117  "mDcaBachelorToPrimVertex");
118 }
119 
120 void DcaService::replaceDcaPosToPrimVertex(StV0MuDst* v0,Float_t dca) {
121  replaceDca(v0,dca,offsetDcaPosToPrimVertex,v0->Class(),
122  "mDcaPosToPrimVertex");
123 }
124 
125 void DcaService::replaceDcaNegToPrimVertex(StV0MuDst* v0,Float_t dca) {
126  replaceDca(v0,dca,offsetDcaNegToPrimVertex,v0->Class(),
127  "mDcaNegToPrimVertex");
128 }
129 
130 void DcaService::fixDcaXiToPrimVertex(StStrangeMuDstMaker* mk) {
131  initEvent(mk);
132  for( Int_t j=0; j<mk->GetNXi(); j++ ) {
133  fixDcaXiToPrimVertex(mk->GetXi(j));
134  }
135 }
136 
137 void DcaService::fixSignedDcaXiToPrimVertex(StStrangeMuDstMaker* mk) {
138  initEvent(mk);
139  for( Int_t j=0; j<mk->GetNXi(); j++ ) {
140  fixSignedDcaXiToPrimVertex(mk->GetXi(j));
141  }
142 }
143 
144 void DcaService::fixSignedDcaBachelorToPrimVertex(StStrangeMuDstMaker* mk) {
145  initEvent(mk);
146  for( Int_t j=0; j<mk->GetNXi(); j++ ) {
147  fixSignedDcaBachelorToPrimVertex(mk->GetXi(j));
148  }
149 }
150 
151 void DcaService::fixSignedDcaPosToPrimVertex(StStrangeMuDstMaker* mk) {
152  initEvent(mk);
153  for( Int_t j=0; j<mk->GetNV0(); j++ ) {
154  fixSignedDcaPosToPrimVertex(mk->GetV0(j));
155  }
156 }
157 
158 void DcaService::fixSignedDcaNegToPrimVertex(StStrangeMuDstMaker* mk) {
159  initEvent(mk);
160  for( Int_t j=0; j<mk->GetNV0(); j++ ) {
161  fixSignedDcaNegToPrimVertex(mk->GetV0(j));
162  }
163 }
164 
166  initEvent(mk);
167  for( Int_t j=0; j<mk->GetNXi(); j++ ) {
168  StXiMuDst* xi = mk->GetXi(j);
169  fixSignedDcaXiToPrimVertex(xi);
170  fixSignedDcaBachelorToPrimVertex(xi);
171  fixSignedDcaPosToPrimVertex(xi);
172  fixSignedDcaNegToPrimVertex(xi);
173  }
174 }
175 
177  initEvent(mk);
178  for( Int_t j=0; j<mk->GetNV0(); j++ ) {
179  StV0MuDst* v0 = mk->GetV0(j);
180  fixSignedDcaPosToPrimVertex(v0);
181  fixSignedDcaNegToPrimVertex(v0);
182  }
183 }
184 
185 
186 // Providing this function separately because we should really be
187 // using TDataMember::GetOffset(), but it doesn't work in all versions.
188 // This code is copied from that used in version 1.12 of TDataMember.
189 
190 Long_t GGetOffset(TClass* cl, TDataMember* that) {
191  //case of a compiled class
192  //Note that the offset cannot be computed in case of an abstract class
193  //for which the list of real data has not yet been computed via
194  //a real daughter class.
195  char dmbracket[256];
196  sprintf(dmbracket,"%s[",that->GetName());
197  cl->BuildRealData();
198  TIter next(cl->GetListOfRealData());
199  TRealData *rdm;
200  while ((rdm = (TRealData*)next())) {
201  char *rdmc = (char*)rdm->GetName();
202  //next statement required in case a class and one of its parent class
203  //have data members with the same name
204  if (that->IsaPointer() && rdmc[0] == '*') rdmc++;
205 
206  if (rdm->GetDataMember() != that) continue;
207  if (strcmp(rdmc,that->GetName()) == 0) {
208  return rdm->GetThisOffset();
209  }
210  if (strcmp(rdm->GetName(),that->GetName()) == 0) {
211  if (rdm->IsObject()) {
212  return rdm->GetThisOffset();
213  }
214  }
215  if (strstr(rdm->GetName(),dmbracket)) {
216  return rdm->GetThisOffset();
217  }
218  }
219  return 0;
220 }
221 
222 //_____________________________________________________________________________
223 // $Id: DcaService.cxx,v 3.5 2009/09/02 19:39:44 genevb Exp $
224 // $Log: DcaService.cxx,v $
225 // Revision 3.5 2009/09/02 19:39:44 genevb
226 // Fixes to pointer and string conversions (RT ticket 1612), prep for 64-bit
227 //
228 // Revision 3.4 2009/08/28 16:37:53 fine
229 // fix the compilation issues under SL5_64_bits gcc 4.3.2
230 //
231 // Revision 3.3 2007/07/12 20:01:47 fisyak
232 // Add includes for ROOT 5.16
233 //
234 // Revision 3.2 2007/05/19 00:35:55 genevb
235 // use STAR logger
236 //
237 // Revision 3.1 2002/08/13 19:18:54 genevb
238 // Introduction of DcaService
239 //
240 //
241 
Float_t momPosZ() const
Momentum components of pos. daughter.
Definition: StV0MuDst.hh:124
static void fixSignedDcasV0s(StStrangeMuDstMaker *mk)
All DCAs for V0s.
Definition: DcaService.cxx:176
Float_t momXiZ()
Momentum components of Xi/Omega at decay vertex.
Definition: StXiMuDst.hh:120
Int_t charge() const
Particle charge.
Definition: StXiMuDst.hh:101
Float_t primaryVertexZ() const
Primary vtx position coordinates.
Float_t momBachelorZ() const
Momentum components of bachelor.
Definition: StXiMuDst.hh:115
C++ STL includes.
Definition: AgUStep.h:47
Float_t decayVertexV0Z() const
Coordinates of decay vertex.
Definition: StV0MuDst.hh:113
Float_t momNegZ() const
Momentum components of neg. daughter.
Definition: StV0MuDst.hh:127
Float_t decayVertexXiZ() const
Coordinates of decay vertex.
Definition: StXiMuDst.hh:105
static void fixSignedDcasXis(StStrangeMuDstMaker *mk)
All DCAs for Xis.
Definition: DcaService.cxx:165