StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StMuEmcPosition.cxx
1 #include "StMuEmcPosition.h"
2 #include <math.h>
3 #include "SystemOfUnits.h"
4 #include "PhysicalConstants.h"
5 #include "StPhysicalHelixD.hh"
6 
7 #include "StMcEvent.hh"
8 #include "StMcEventTypes.hh"
9 #include "StMcEventMaker/StMcEventMaker.h"
10 #include "StEvent.h"
11 #include "StEventTypes.h"
12 #include "StEmcUtil/geometry/StEmcGeom.h"
13 #include "StEEmcUtil/EEmcGeom/EEmcGeomSimple.h"
14 
15 //StMuDstMaker:
16 #include "StMuDSTMaker/COMMON/StMuTrack.h"
17 
18 
19  ClassImp(StMuEmcPosition)
20 
21  StMuEmcPosition::StMuEmcPosition():TObject()
22 {
23  mGeom[0] = StEmcGeom::getEmcGeom("bemc");
24  mGeom[1] = StEmcGeom::getEmcGeom("bprs");
25  mGeom[2] = StEmcGeom::getEmcGeom("bsmde");
26  mGeom[3] = StEmcGeom::getEmcGeom("bsmdp");
27 }
28 
29 StMuEmcPosition::~StMuEmcPosition()
30 {
31 }
32 
33 bool StMuEmcPosition::projTrack(StThreeVectorD* atFinal, StThreeVectorD* momentumAtFinal,
34  const StMuTrack* track, double magField, double radius, int option)
35 {
36  StThreeVectorD Zero(0,0,0);
37  *atFinal=Zero;
38  *momentumAtFinal=Zero;
39 
40  /* this was for StTrack
41  const StThreeVectorF& origin = track->geometry()->origin();
42  const StThreeVectorF& momentum = track->geometry()->momentum();
43  double charge = track->geometry()->charge();
44  StPhysicalHelixD helix(momentum, origin, magField*tesla, charge);
45  */
46  StPhysicalHelixD helix = track->outerHelix();
47  const StThreeVectorF momentum = track->momentum();
48  pairD pathLength = helix.pathLength(radius);
49  double charge = track->charge();
50 
51  double s,s1,s2;
52  s=0;
53  s1 = pathLength.first;
54  s2 = pathLength.second;
55 
56  bool goProj;
57  goProj = kFALSE;
58 
59  if (finite(s1) == 0 && finite(s2) == 0) { return kFALSE;} // StjTrack couldn't be projected!
60 
61  if (option == 1) // Selects positive path lenght to project track forwards along its helix relative to
62  // first point of track. The smaller solution is taken when both are positive
63  {
64  if (s1 >= 0 && s2 >= 0) {s = s1; goProj = kTRUE; }
65  if (s1 >= 0 && s2 < 0) { s = s1; goProj = kTRUE; }
66  if (s1 < 0 && s2 >= 0) { s = s2; goProj = kTRUE; }
67  }
68 
69  if (option == -1) // Selects negative path lenght to project track backwards along its helix relative to
70  // first point of track. The smaller absolute solution is taken when both are negative
71  {
72  if (s1 <= 0 && s2 <= 0) { s = s2; goProj = kTRUE; }
73  if (s1 <= 0 && s2 > 0) { s = s1; goProj = kTRUE; }
74  if (s1 > 0 && s2 <= 0) { s = s2; goProj = kTRUE; }
75  }
76 
77  if (goProj)
78  {
79  *atFinal = helix.at( s );
80  *momentumAtFinal = helix.momentumAt( s, magField*tesla );
81  if (charge == 0) *momentumAtFinal = momentum;
82  }
83  return goProj;
84 }
85 
86 bool StMuEmcPosition::projTrack(StThreeVectorD* atFinal, StThreeVectorD* momentumAtFinal,
87  StMcTrack* mcTrack, double magField, double radius, int option)
88 {
89  StThreeVectorD Zero(0,0,0);
90  *atFinal=Zero;
91  *momentumAtFinal=Zero;
92 
93  const StThreeVectorF& origin = mcTrack->startVertex()->position();
94  const StThreeVectorF& momentum = mcTrack->momentum();
95  double charge = mcTrack->particleDefinition()->charge();
96  StPhysicalHelixD helix(momentum, origin, magField*tesla, charge);
97  pairD pathLength = helix.pathLength(radius);
98 
99  double s,s1,s2;
100  s=0;
101  s1 = pathLength.first;
102  s2 = pathLength.second;
103 
104  bool goProj;
105  goProj = kFALSE;
106 
107  if (finite(s1) == 0 && finite(s2) == 0) { return kFALSE;} // StjTrack couldn't be projected!
108 
109  if (option == 1) // Selects positive path lenght to project track forwards along its helix relative to
110  // first point of track. The smaller solution is taken when both are positive
111  {
112  if (s1 >= 0 && s2 >= 0) { s = s1; goProj = kTRUE; }
113  if (s1 >= 0 && s2 < 0) { s = s1; goProj = kTRUE; }
114  if (s1 < 0 && s2 >= 0) { s = s2; goProj = kTRUE; }
115  }
116 
117  if (option == -1) // Selects negative path lenght to project track backwards along its helix relative to
118  // first point of track. The smaller absolute solution is taken when both are negative
119  {
120  if (s1 <= 0 && s2 <= 0) { s = s2; goProj = kTRUE; }
121  if (s1 <= 0 && s2 > 0) { s = s1; goProj = kTRUE; }
122  if (s1 > 0 && s2 <= 0) { s = s2; goProj = kTRUE; }
123  }
124 
125  if (goProj)
126  {
127  *atFinal = helix.at( s );
128  *momentumAtFinal = helix.momentumAt( s, magField*tesla );
129  if (charge == 0) *momentumAtFinal = momentum;
130  }
131  return goProj;
132 }
133 
134 bool StMuEmcPosition::trackOnEmc( StThreeVectorD* position, StThreeVectorD* momentum, const StMuTrack* track, double magField, double emcRadius )
135 {
136  return trackOnBEmc(position, momentum, track, magField, emcRadius);
137 }
138 
139 bool StMuEmcPosition::trackOnBEmc( StThreeVectorD* position, StThreeVectorD* momentum, const StMuTrack* track, double magField, double emcRadius )
140 {
141  // There's no check for primary or secondary tracks
142 
143  /* this was for StTrack
144  if (!track->geometry()) return kFALSE;
145  const StThreeVectorD& origin = track->geometry()->origin();
146  */
147  StPhysicalHelixD helix = track->outerHelix();
148  const StThreeVectorD& origin = helix.origin();
149 
150 
151  float xO = origin.x();
152  float yO = origin.y();
153  float distToOrigin = ::sqrt( ::pow(xO, 2) + ::pow(yO, 2) );
154  if ( distToOrigin < emcRadius )
155  {
156  bool projTrackOk = projTrack( position, momentum, track, magField, emcRadius );
157  if ( projTrackOk )
158  {
159  int m = 0, e = 0, s = 0;
160  float phi = position->phi();
161  float eta = position->pseudoRapidity();
162  if ( mGeom[0]->getBin(phi, eta, m, e, s) == 0 && s != -1 ) return kTRUE;
163  }
164  }
165 
166  return kFALSE;
167 }
168 
170  StMcTrack* mcTrack, double magField, double emcRadius )
171 {
172  return trackOnBEmc(position, momentum, mcTrack, magField, emcRadius );
173 }
174 
176  StMcTrack* mcTrack, double magField, double emcRadius )
177 {
178  float startVertexX = mcTrack->startVertex()->position().x();
179  float startVertexY = mcTrack->startVertex()->position().y();
180  float startVtxToOrigin = ::sqrt( ::pow( startVertexX, 2 ) + ::pow( startVertexY, 2 ) );
181 
182  if ( !mcTrack->stopVertex() && startVtxToOrigin < emcRadius )
183  {
184  bool projTrackOk = projTrack( position, momentum, mcTrack, magField, emcRadius );
185  if ( projTrackOk )
186  {
187  int m = 0, e = 0, s = 0;
188  float phi = position->phi();
189  float eta = position->pseudoRapidity();
190  if ( mGeom[0]->getBin(phi, eta, m, e, s) == 0 && s != -1 ) return kTRUE;
191  }
192  }
193 
194  // Checking if stopVertex exists
195  float stopVtxToOrigin = -1;
196  if ( mcTrack->stopVertex() )
197  {
198  float stopVertexX = mcTrack->stopVertex()->position().x();
199  float stopVertexY = mcTrack->stopVertex()->position().y();
200  stopVtxToOrigin = ::sqrt( ::pow( stopVertexX,2 ) + ::pow(stopVertexY,2) );
201  }
202 
203  if (stopVtxToOrigin >= emcRadius)
204  {
205  bool projTrackOk = projTrack( position, momentum, mcTrack, magField, emcRadius );
206  if ( projTrackOk )
207  {
208  int m = 0, e = 0, s = 0;
209  float phi = position->phi();
210  float eta = position->pseudoRapidity();
211  if ( mGeom[0]->getBin(phi, eta, m, e, s) == 0 && s != -1 ) return kTRUE;
212  }
213  }
214 
215  return kFALSE;
216 }
217 
218 // Project track onto EEMC at SMD depth (magnetic field must be in Tesla)
219 bool StMuEmcPosition::trackOnEEmc(StThreeVectorD* position, StThreeVectorD* momentum, const StMuTrack* track, double magField, double z) const
220 {
221  if (track->eta() < 0) return false;
222  StPhysicalHelixD outerHelix = track->outerHelix();
223  if (fabs(outerHelix.origin().z()) > fabs(z)) return false;
224  StThreeVectorD r(0,0,z);
225  StThreeVectorD n(0,0,1);
226  double s = outerHelix.pathLength(r,n);
227  if (!finite(s)) return false;
228  if (s == StHelix::NoSolution) return false;
229  if (s < 0) return false;
230  *position = outerHelix.at(s);
231  int sector, subsector, etabin;
232  if (!EEmcGeomSimple::Instance().getTower(position->xyz(), sector, subsector, etabin)) return false;
233  *momentum = outerHelix.momentumAt(s, magField*tesla);
234  return true;
235 }
236 
237 int StMuEmcPosition::getTowerEtaPhi( double eta, double phi, float* towerEta, float* towerPhi )
238 {
239  *towerEta = 0; *towerPhi = 0;
240  float tempTowerEta = 0, tempTowerPhi = 0;
241  int m = 0, e = 0, s = 0, towerId = -1;
242 
243  mGeom[0]->getBin(phi, eta, m, e, s);
244  if (m==0) return -1;
245  if (s<0) s=1;
246  mGeom[0]->getId(m, e, s, towerId);
247  mGeom[0]->getEtaPhi(towerId, tempTowerEta, tempTowerPhi);
248  *towerEta = tempTowerEta;
249  *towerPhi = tempTowerPhi;
250  return 0;
251 }
252 
253 int StMuEmcPosition::getNextTowerId(float Eta, float Phi, int nTowersdEta, int nTowersdPhi)
254 {
255  int m,e,s;
256  mGeom[0]->getBin( Phi, Eta, m, e, s );
257  if(m>0 && m<=120)
258  {
259  if(s<0) s=1;
260  return getNextTowerId(m,e,s,nTowersdEta,nTowersdPhi);
261  }
262  return 0;
263 }
264 
265 int StMuEmcPosition::getNextTowerId(int id, int nTowersdEta, int nTowersdPhi)
266 {
267  if(id<1 || id>4800) return 0;
268  int m,e,s;
269  mGeom[0]->getBin(id,m,e,s);
270  return getNextTowerId(m,e,s,nTowersdEta,nTowersdPhi);
271 }
272 
273 int StMuEmcPosition::getNextTowerId(int m, int e, int s, int nTowersdEta, int nTowersdPhi)
274 {
275  if(m<1 || m>120) return 0;
276  if(e<1 || e>20) return 0;
277  if(s<1 || s>2) return 0;
278  return getNextId(1,m,e,s,nTowersdEta,nTowersdPhi);
279 }
280 
281 int StMuEmcPosition::getNextId(int det,int m, int e, int s, int nEta, int nPhi)
282 {
283  if(det<1 || det>4) return 0;
284  if(m<1 || m>120) return 0;
285  if(s<1 || s>mGeom[det-1]->NSub()) return 0;
286  if(e<1 || e>mGeom[det-1]->NEta()) return 0;
287 
288  int ef=e+nEta;
289  int sf=s+nPhi;
290  int mf=m;
291 
292  int NE=mGeom[det-1]->NEta();
293  int NS=mGeom[det-1]->NSub();
294 
295  if(abs(ef)>NE) return 0;
296 
297  do
298  {
299  if(sf<=0)
300  {
301  sf += NS;
302  mf--;
303  if(mf==60) mf = 120;
304  if(mf==0) mf = 60;
305  }
306  if(sf>NS)
307  {
308  sf -= NS;
309  mf++;
310  if(mf==61) mf = 1;
311  if(mf==121) mf = 61;
312  }
313  } while(sf<=0 || sf>NS);
314 
315  if(ef<=0)
316  {
317  ef = 1-ef;
318  sf = NS-sf+1;
319  if(ef>NE) return 0;
320  int rid,etmp,stmp;
321  float eta,phi;
322  mGeom[det-1]->getId(mf, ef, sf, rid);
323  mGeom[det-1]->getEtaPhi(rid, eta, phi);
324  mGeom[det-1]->getBin(phi,-eta,mf,etmp,stmp);
325  }
326 
327  int rid;
328  if(mf<1 || mf>120) return 0;
329  if(ef<1 || ef>NE) return 0;
330  if(sf<1 || sf>NS) return 0;
331  mGeom[det-1]->getId(mf, ef, sf, rid);
332  return rid;
333 
334 }
335 
336 float StMuEmcPosition::getDistTowerToTrack( double trackEta, double trackPhi,
337  int nTowersdEta, int nTowersdPhi )
338 
339 {
340  int towerId = 0;
341  float towerEta = 0, towerToTrackdEta = 0;
342  float towerPhi = 0, towerToTrackdPhi = 0;
343  float mdistTowerToTrack = 0;
344 
345  towerId = getNextTowerId( trackEta, trackPhi, nTowersdEta, nTowersdPhi );
346  if (towerId != 0)
347  {
348  // Getting eta and phi of neighbour tower
349  mGeom[0]->getEtaPhi(towerId, towerEta, towerPhi);
350  towerToTrackdEta = towerEta-trackEta;
351  towerToTrackdPhi = towerPhi-trackPhi;
352 
353  mdistTowerToTrack = ::sqrt( ::pow(towerToTrackdEta, 2) + ::pow(towerToTrackdPhi, 2) );
354 
355  return mdistTowerToTrack;
356  }
357  else
358  return -1;
359 }
360 
362 {
363  StThreeVectorF Zero(0,0,0);
364  if(TowerId<1 || TowerId>4800) return Zero;
365 
366  float xTower,yTower,zTower;
367  //StThreeVectorF position = vertex->position(); //modified to work with StMuDst instead of StEvent
368  mGeom[0]->getXYZ(TowerId, xTower, yTower, zTower);
369  StThreeVectorF towerPosition(xTower, yTower, zTower);
370  StThreeVectorF PositionFromVertex = towerPosition - position;
371 
372  return PositionFromVertex;
373 }
374 
376 {
377  StThreeVectorF Zero(0,0,0);
378  if(TowerId<1 || TowerId>4800) return Zero;
379 
380  float xTower,yTower,zTower;
381  StThreeVectorF position = vertex->position();
382  mGeom[0]->getXYZ(TowerId, xTower, yTower, zTower);
383  StThreeVectorF towerPosition(xTower, yTower, zTower);
384  StThreeVectorF PositionFromVertex = towerPosition - position;
385 
386  return PositionFromVertex;
387 }
388 
390 {
391  StThreeVectorF p=getPosFromVertex(vertex,TowerId );
392  return p.theta();
393 }
394 
396 {
397  StThreeVectorF p=getPosFromVertex(vertex,TowerId );
398  return p.theta();
399 }
400 
402 {
403  StThreeVectorF p=getPosFromVertex(vertex,TowerId );
404  return p.pseudoRapidity();
405 }
406 
408 {
409  StThreeVectorF p=getPosFromVertex(vertex,TowerId );
410  return p.pseudoRapidity();
411 }
412 
414 {
415  StThreeVectorF p=getPosFromVertex(vertex,TowerId );
416  return p.phi();
417 }
418 
420 {
421  StThreeVectorF p=getPosFromVertex(vertex,TowerId );
422  return p.phi();
423 }
float getPhiFromVertex(const StThreeVectorF &, int)
Return phi of the tower considering the collision vertex.
float getDistTowerToTrack(double, double, int, int)
Return distance from track to center of one tower.
static EEmcGeomSimple & Instance()
returns a reference to a static instance of EEmcGeomSimple
Monte Carlo Track class All information on a simulated track is stored in this class: kinematics...
Definition: StMcTrack.hh:144
float getEtaFromVertex(const StThreeVectorF &, int)
Return eta of the tower considering the collision vertex.
bool trackOnBEmc(StThreeVectorD *, StThreeVectorD *, const StMuTrack *, double, double=225.405)
StjTrack projection utility.
pair< double, double > pathLength(double r) const
path length at given r (cylindrical r)
Definition: StHelix.cc:351
Short_t charge() const
Returns charge.
Definition: StMuTrack.h:255
StThreeVectorF getPosFromVertex(const StThreeVectorF &, int)
Return Position from collision vertex.
int getTowerEtaPhi(double, double, float *, float *)
Return tower eta/phi.
Double_t eta() const
Returns pseudo rapidity at point of dca to primary vertex.
Definition: StMuTrack.h:257
float getThetaFromVertex(const StThreeVectorF &, int)
Return theta of the tower considering the collision vertex.
const StThreeVector< double > & origin() const
-sign(q*B);
Definition: StHelix.hh:224
const StThreeVectorF & momentum() const
Returns 3-momentum at dca to primary vertex.
Definition: StMuTrack.h:260
bool trackOnEEmc(StThreeVectorD *position, StThreeVectorD *momentum, const StMuTrack *track, double magField=0.5, double z=kEEmcZSMD) const
Project track into EEMC at SMD depth (magnetic field must be in Tesla)
Int_t getBin(const Float_t phi, const Float_t eta, Int_t &m, Int_t &e, Int_t &s) const
Definition: StEmcGeom.h:321
StPhysicalHelixD outerHelix() const
Returns outer helix (last measured point)
Definition: StMuTrack.cxx:412
int getNextId(int, int, int, int, int, int)
Return neighbor id (works for all detectors 1=bemc, 2=bprs, 3=bsmde, 4=bsmdp)
bool projTrack(StThreeVectorD *, StThreeVectorD *, const StMuTrack *, double, double=225.405, int=1)
StjTrack projection utility.
bool trackOnEmc(StThreeVectorD *, StThreeVectorD *, const StMuTrack *, double, double=225.405)
StjTrack projection utility.
int getNextTowerId(float, float, int, int)
Return neighbor tower id&#39;s.