Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Conversion.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Conversion.cc
1 #include "Conversion.h"
2 #include "SVReco.h"
3 #include "VtxRegressor.h"
5 #include <phool/getClass.h>
6 #include <phgenfit/Track.h>
8 #include <trackbase_historic/SvtxCluster.h>
9 #include <trackbase_historic/SvtxHitMap.h>
11 #include <trackbase_historic/SvtxVertex_v1.h>
14 #include <TRandom3.h>
15 #include <assert.h>
16 
17 
18 const float Conversion::_kElectronRestM=.0005109989461;
19 
21  this->trackeval=trackeval;
22  this->verbosity=verbosity;
23  _refit_phgf_tracks.first=NULL;
24  _refit_phgf_tracks.second=NULL;
25  pairTruthReco1.second=0;
26  pairTruthReco2.second=0;
27  pairTruthReco1.first=0;
28  pairTruthReco2.first=0;
29 }
31  this->vtx=vtx;
32  this->verbosity=verbosity;
33  _refit_phgf_tracks.first=NULL;
34  _refit_phgf_tracks.second=NULL;
35  pairTruthReco1.second=0;
36  pairTruthReco2.second=0;
37  pairTruthReco1.first=0;
38  pairTruthReco2.first=0;
39 }
40 
42  this->trackeval=trackeval;
43  this->vtx=vtx;
44  this->verbosity=verbosity;
45  _refit_phgf_tracks.first=NULL;
46  _refit_phgf_tracks.second=NULL;
47  pairTruthReco1.second=0;
48  pairTruthReco2.second=0;
49  pairTruthReco1.first=0;
50  pairTruthReco2.first=0;
51 }
52 
54  if(recoVertex) delete recoVertex;
55  if(recoPhoton) delete recoPhoton;
56  if(truthSvtxVtx) delete truthSvtxVtx;
57  if (_refit_phgf_tracks.first) delete _refit_phgf_tracks.first;
58  if (_refit_phgf_tracks.second) delete _refit_phgf_tracks.second;
59  _refit_phgf_tracks.first=NULL;
60  _refit_phgf_tracks.second=NULL;
61  recoVertex=NULL;
62  recoPhoton=NULL;
63  truthSvtxVtx=NULL;
64  //dont delete the points as you are not the owner and did not make your own copies
65 }
66 
68  if (e1)
69  {
70  if (e2&&verbosity>0)
71  {
72  std::cout<<"WARNING in Conversion oversetting conversion electrons"<<std::endl;
73  }
74  else{
75  e2=e;
76  pairTruthReco2.second=e->get_track_id();
77  }
78  }
79  else{
80  e1=e;
81  pairTruthReco1.second=e->get_track_id();
82  }
83 }
84 
85 
87  if (hasPair())
88  {
89  if (e1->get_pid()<0)
90  {
91  PHG4Particle *temp = e1;
92  e1=e2;
93  e2=temp;
94  }
95  if (e1->get_pid()<0)
96  {
97  if (verbosity>0)
98  {
99  std::cout<<"Warning in Conversion bad charges in conversion"<<std::endl;
100  }
101  return false;
102  }
103  }
104  else{
105  if (!e1)
106  {
107  if (verbosity>0)
108  {
109  std::cout<<"Warning in Conversion no truth tracks set"<<std::endl;
110  }
111  return false;
112  }
113  else if (e1->get_pid()<0) return false;
114  }
115  return true;
116 }
117 
119  setElectron();
120  return e1;
121 }
122 
124  if(setElectron()){
125  return e2;
126  }
127  else{
128  return e1;
129  }
130 }
131 
133  bool r =true;
134  if(!photon) photon=parent;
135  else{
136  if(!(*photon==*parent)) cerr<<"Bad photon matching!"<<endl;
137  r=false;
138  }
139  return r;
140 }
141 
143  if(!setParent(parent)) cerr<<"Bad photon matching during primary photon set"<<endl;
144  if(photon->get_track_id()==parent->get_primary_id()){
146  }
147  else{
148  primaryPhoton=truthinfo->GetParticle(parent->get_primary_id());
149  }
150 }
151 
152 void Conversion::setRecoTrack(int truthID, SvtxTrack* recoTrack){
153  if(!recoTrack)return;
154  setElectron();
155  setRecoTracks();
156  if (e1&&e1->get_track_id()==truthID&&!reco1)
157  {
158  reco1=recoTrack;
159  pairTruthReco1.first=e1->get_track_id();
160  pairTruthReco1.second=recoTrack->get_id();
161  }
162  else if (e2&&e2->get_track_id()==truthID&&!reco2)
163  {
164  reco2=recoTrack;
165  pairTruthReco2.first=e2->get_track_id();
166  pairTruthReco2.second=recoTrack->get_id();
167  }
168 }
169 
171  this->trackeval=trackeval;
172  setElectron();
173  if (e1)
174  {
175  reco1=trackeval->best_track_from(e1);
176  }
177  if (e2)
178  {
179  reco2=trackeval->best_track_from(e2);
180  }
181  if(reco2==reco1){
182  reco2=NULL;
183  }
184  int r=0;
185  if (reco1)
186  {
187  r++;
188  pairTruthReco1.first = e1->get_track_id();
189  pairTruthReco1.second = reco1->get_id();
190  }
191  if (reco2)
192  {
193  r++;
194  pairTruthReco2.first = e2->get_track_id();
195  pairTruthReco2.second = reco2->get_id();
196  }
197  setRecoPhoton();
198  return r;
199 }
200 
202  assert(trackeval);
203  if (e1)
204  {
205  reco1=trackeval->best_track_from(e1); // have not checked that these are in range
206  }
207  if (e2)
208  {
210  }
211  if(reco2==reco1){
212  reco2=NULL;
213  }
214  int r=0;
215  if (reco1)
216  {
217  r++;
218  pairTruthReco1.first = e1->get_track_id();
219  pairTruthReco1.second = reco1->get_id();
220  }
221  if (reco2)
222  {
223  r++;
224  pairTruthReco2.first = e2->get_track_id();
225  pairTruthReco2.second = reco2->get_id();
226  }
227  setRecoPhoton();
228  return r;
229 }
230 
231 SvtxTrack* Conversion::getRecoTrack(unsigned truthID) const{
232  if (pairTruthReco1.second==truthID)
233  {
234  if(reco1&&reco1->get_id()==pairTruthReco1.first)
235  return reco1;
236  else if(reco2&&reco2->get_id()==pairTruthReco1.first)
237  return reco2;
238  }
239  else if (pairTruthReco2.second==truthID)
240  {
241  if(reco1&&reco1->get_id()==pairTruthReco2.first)
242  return reco1;
243  else if(reco2&&reco2->get_id()==pairTruthReco2.first)
244  return reco2;
245  }
246  return NULL;
247 }
248 
249 TLorentzVector* Conversion::setRecoPhoton(){
250  if (reco1&&reco2)
251  {
252  TLorentzVector tlv1(reco1->get_px(),reco1->get_py(),reco1->get_pz(),
254  TLorentzVector tlv2(reco2->get_px(),reco2->get_py(),reco2->get_pz(),
256  if (recoPhoton) delete recoPhoton;
257  recoPhoton= new TLorentzVector(tlv1+tlv2);
258  }
259  return recoPhoton;
260 }
261 
262 TLorentzVector* Conversion::getRecoPhoton(){
263  return setRecoPhoton();
264 }
265 
266 TLorentzVector* Conversion::getRecoPhoton(SvtxTrack* reco1, SvtxTrack* reco2){
267  if(!(reco1&&reco2)) return NULL;
268  TLorentzVector tlv1(reco1->get_px(),reco1->get_py(),reco1->get_pz(),
269  sqrt(_kElectronRestM*_kElectronRestM+reco1->get_p()*reco1->get_p()));
270  TLorentzVector tlv2(reco2->get_px(),reco2->get_py(),reco2->get_pz(),
271  sqrt(_kElectronRestM*_kElectronRestM+reco2->get_p()*reco2->get_p()));
272  return new TLorentzVector(tlv1+tlv2);
273 }
274 
276  std::pair<TLorentzVector*,TLorentzVector*> refit_tlvs =getRefitRecoTlvs();
277  if (refit_tlvs.first&&refit_tlvs.second)
278  {
279  if(recoPhoton) delete recoPhoton;
280  recoPhoton= new TLorentzVector(*refit_tlvs.first + *refit_tlvs.second);
281  }
282  return recoPhoton;
283 }
284 
285 std::pair<TLorentzVector*,TLorentzVector*> Conversion::getRecoTlvs(){
286  std::pair<TLorentzVector*,TLorentzVector*> r;
287  switch(recoCount()){
288  case 2:
289  r.first = new TLorentzVector();
290  r.first->SetPxPyPzE (reco1->get_px(),reco1->get_py(),reco1->get_pz(),
292  r.second = new TLorentzVector();
293  r.second->SetPxPyPzE (reco2->get_px(),reco2->get_py(),reco2->get_pz(),
295  break;
296  case 1:
297  if(reco1){
298  r.first = new TLorentzVector();
299  r.first->SetPxPyPzE (reco1->get_px(),reco1->get_py(),reco1->get_pz(),
301  r.second = NULL;
302  }
303  else{
304  r.first = NULL;
305  r.second = new TLorentzVector ();
306  r.second->SetPxPyPzE(reco2->get_px(),reco2->get_py(),reco2->get_pz(),
308  }
309  break;
310  default:
311  r.first=NULL;
312  r.second=NULL;
313  break;
314  }
315  return r;
316 }
317 
318 std::pair<TLorentzVector*,TLorentzVector*> Conversion::getRefitRecoTlvs(){
319  std::pair<TLorentzVector*,TLorentzVector*> r;
320  if (_refit_phgf_tracks.first&&_refit_phgf_tracks.second)
321  {
322  r.first = new TLorentzVector();
323  r.first->SetVectM (_refit_phgf_tracks.first->get_mom(),_kElectronRestM);
324  r.second = new TLorentzVector();
325  r.second->SetVectM (_refit_phgf_tracks.second->get_mom(),_kElectronRestM);
326  }
327  else{
328  r.first=NULL;
329  r.second=NULL;
330  }
331  return r;
332 }
333 
335  return photon;
336 }
337 
338 
340  if(!reco1){
341  assert(trackeval);
343  if(!reco1){
344  return -1;
345  }
346  }
347  return reco1->get_cal_cluster_id(SvtxTrack::CAL_LAYER(1));//id of the emcal
348 }
349 
351  if(!reco1){
352  return -1;
353  }
354  else return reco1->get_cal_cluster_id(SvtxTrack::CAL_LAYER(1));//id of the emcal
355 }
356 
358  this->trackeval=trackeval;
359  if (!reco1)
360  {
361  reco1=trackeval->best_track_from(e1);
362  if(!reco1){
363  cout<<"bad reco"<<endl;
364  return -1;
365  }
366  }
367  return reco1->get_cal_cluster_id(SvtxTrack::CAL_LAYER(1));//id of the emcal
368 }
369 
370 std::pair<int,int> Conversion::get_cluster_ids(){
371  switch(recoCount()){
372  case 2:
374  break;
375  case 1:
376  if (reco1)
377  {
378  return std::pair<int,int>(reco1->get_cal_cluster_id(SvtxTrack::CAL_LAYER(1)),-1);
379  }
380  else return std::pair<int,int>(reco2->get_cal_cluster_id(SvtxTrack::CAL_LAYER(1)),-1);
381  break;
382  default:
383  return std::pair<int,int>(-1,-1);
384  break;
385  }
386 }
387 
388 
389 
390 bool Conversion::hasSilicon(SvtxClusterMap* svtxClusterMap){
391  switch(recoCount()){
392  case 2:
393  {
394  SvtxCluster *c1 = svtxClusterMap->get(*(reco1->begin_clusters()));
395  SvtxCluster *c2 = svtxClusterMap->get(*(reco2->begin_clusters()));
396  return c1->get_layer()<=_kNSiliconLayer||c2->get_layer()<=_kNSiliconLayer;
397  }
398  break;
399  case 1:
400  {
401  SvtxCluster *c1;
402  if (reco1)
403  {
404  c1 = svtxClusterMap->get(*(reco1->begin_clusters()));
405  }
406  else{
407  c1 = svtxClusterMap->get(*(reco2->begin_clusters()));
408  }
409  return c1->get_layer()<=_kNSiliconLayer;
410  }
411  break;
412  default:
413  return false;
414  break;
415  }
416 }
417 
418 float Conversion::vtxTrackRZ(TVector3 vertpos){
419  float d1=vtxTrackRZ(vertpos,reco1);
420  float d2=vtxTrackRZ(vertpos,reco2);
421  return d1>d2?d1:d2;
422 }
423 float Conversion::vtxTrackRZ(TVector3 vertpos,SvtxTrack* reco1,SvtxTrack* reco2){
424  float d1=vtxTrackRZ(vertpos,reco1);
425  float d2=vtxTrackRZ(vertpos,reco2);
426  return d1>d2?d1:d2;
427 }
428 
429 float Conversion::vtxTrackRPhi(TVector3 vertpos){
430  float d1=vtxTrackRPhi(vertpos,reco1);
431  float d2=vtxTrackRPhi(vertpos,reco2);
432  return d1>d2?d1:d2;
433 }
434 
435 float Conversion::vtxTrackRPhi(TVector3 vertpos,SvtxTrack* reco1,SvtxTrack* reco2){
436  float d1=vtxTrackRPhi(vertpos,reco1);
437  float d2=vtxTrackRPhi(vertpos,reco2);
438  return d1>d2?d1:d2;
439 }
440 float Conversion::vtxTrackRZ(TVector3 recoVertPos,SvtxTrack *track){
441  float dR = sqrt(recoVertPos.x()*recoVertPos.x()+recoVertPos.y()*recoVertPos.y())-sqrt(track->get_x()*track->get_x()+track->get_y()*track->get_y());
442  float dZ = recoVertPos.z()-track->get_z();
443  return sqrt(dR*dR+dZ*dZ);
444 }
445 
446 float Conversion::vtxTrackRPhi(TVector3 recoVertPos,SvtxTrack *track){
447  float vtxR=sqrt(recoVertPos.x()*recoVertPos.x()+recoVertPos.y()*recoVertPos.y());
448  float trackR=sqrt(track->get_x()*track->get_x()+track->get_y()*track->get_y());
449  return sqrt(vtxR*vtxR+trackR*trackR-2*vtxR*trackR*cos(recoVertPos.Phi()-track->get_phi()));
450 }
451 
452 int Conversion::trackDLayer(SvtxClusterMap* svtxClusterMap,SvtxHitMap *hitmap){
453  if (recoCount()==2){
454  SvtxCluster *c1 = svtxClusterMap->get(*(reco1->begin_clusters()));
455  SvtxCluster *c2 = svtxClusterMap->get(*(reco2->begin_clusters()));
456  SvtxHit *h1 = hitmap->get(*(c1->begin_hits()));
457  SvtxHit *h2 = hitmap->get(*(c2->begin_hits()));
458  int l1 = h1->get_layer();
459  int l2 = h2->get_layer();
460  return abs(l1-l2);
461  }
462  else return -1;
463 }
464 
466  if(reco1->get_dca()>reco2->get_dca()) return reco2->get_dca();
467  else return reco1->get_dca();
468 }
469 
471  if (recoCount()==2){
472  TrkrCluster *c1 = clusterMap->findCluster(*(reco1->begin_cluster_keys()));
473  TrkrCluster *c2 = clusterMap->findCluster(*(reco2->begin_cluster_keys()));
474  unsigned l1 = TrkrDefs::getLayer(c1->getClusKey());
475  unsigned l2 = TrkrDefs::getLayer(c2->getClusKey());
476  return abs(l1-l2);
477  }
478  else return -1;
479 }
481  TrkrCluster *c1 = clusterMap->findCluster(*(reco1->begin_cluster_keys()));
482  TrkrCluster *c2 = clusterMap->findCluster(*(reco2->begin_cluster_keys()));
483  unsigned l1 = TrkrDefs::getLayer(c1->getClusKey());
484  unsigned l2 = TrkrDefs::getLayer(c2->getClusKey());
485  return abs(l1-l2);
486 }
487 
488 int Conversion::firstLayer(SvtxClusterMap* svtxClusterMap,SvtxHitMap *hitmap){
489  switch(recoCount()){
490  case 2:
491  {
492  SvtxCluster *c1 = svtxClusterMap->get(*(reco1->begin_clusters()));
493  SvtxCluster *c2 = svtxClusterMap->get(*(reco2->begin_clusters()));
494  SvtxHit *h1 = hitmap->get(*(c1->begin_hits()));
495  SvtxHit *h2 = hitmap->get(*(c2->begin_hits()));
496  if(h1->get_layer()>h2->get_layer()){
497  return h2->get_layer();
498  }
499  else return h1->get_layer();
500  }
501  case 1:
502  {
503  if (reco1)return svtxClusterMap->get(*(reco1->begin_clusters()))->get_layer();
504  else return svtxClusterMap->get(*(reco2->begin_clusters()))->get_layer();
505  }
506  default:
507  return -1;
508  }
509 }
510 
512  switch(recoCount()){
513  case 2:
514  {
515  TrkrCluster *c1 = clusterMap->findCluster(*(reco1->begin_cluster_keys()));
516  TrkrCluster *c2 = clusterMap->findCluster(*(reco2->begin_cluster_keys()));
517  unsigned l1 = TrkrDefs::getLayer(c1->getClusKey());
518  unsigned l2 = TrkrDefs::getLayer(c2->getClusKey());
519  //maybe i need this? TrkrDefs::hitsetkey hitsetkey = TrkrDefs::getHitSetKeyFromClusKey(cluskey);
520  if(l1>l2){
521  return l1;
522  }
523  else return l2;
524  }
525  case 1:
526  {
528  else return TrkrDefs::getLayer(*(reco2->begin_cluster_keys()));
529  }
530  default:
531  return -1;
532  }
533 }
534 
535 double Conversion::dist(PHG4VtxPoint *recovtx,SvtxClusterMap* svtxClusterMap){
536  SvtxCluster *c1 = svtxClusterMap->get(*(reco1->begin_clusters()));
537  SvtxCluster *c2 = svtxClusterMap->get(*(reco2->begin_clusters()));
538  double r1 = sqrt(abs(c1->get_x()-recovtx->get_x())+abs(c1->get_y()-recovtx->get_y())+abs(c1->get_z()-recovtx->get_z()));
539  double r2 = sqrt(abs(c2->get_x()-recovtx->get_x())+abs(c2->get_y()-recovtx->get_y())+abs(c2->get_z()-recovtx->get_z()));
540  if (r1>r2)
541  {
542  return r1;
543  }
544  else return r2;
545 }
546 
547 double Conversion::dist(TVector3 *recovtx,SvtxClusterMap* svtxClusterMap){
548  SvtxCluster *c1 = svtxClusterMap->get(*(reco1->begin_clusters()));
549  SvtxCluster *c2 = svtxClusterMap->get(*(reco2->begin_clusters()));
550  double r1 = sqrt(abs(c1->get_x()-recovtx->x())+abs(c1->get_y()-recovtx->y())+abs(c1->get_z()-recovtx->z()));
551  double r2 = sqrt(abs(c2->get_x()-recovtx->x())+abs(c2->get_y()-recovtx->y())+abs(c2->get_z()-recovtx->z()));
552  if (r1>r2)
553  {
554  return r1;
555  }
556  else return r2;
557 }
558 
559 double Conversion::dist(TVector3 *recovtx,TrkrClusterContainer* clusterMap){
560  TrkrCluster *c1 = clusterMap->findCluster(*(reco1->begin_cluster_keys()));
561  TrkrCluster *c2 = clusterMap->findCluster(*(reco2->begin_cluster_keys()));
562  double r1 = sqrt(abs(c1->getX()-recovtx->x())+abs(c1->getY()-recovtx->y())+abs(c1->getZ()-recovtx->z()));
563  double r2 = sqrt(abs(c2->getX()-recovtx->x())+abs(c2->getY()-recovtx->y())+abs(c2->getZ()-recovtx->z()));
564  if (r1>r2)
565  {
566  return r1;
567  }
568  else return r2;
569 }
570 
572  cout<<"Conversion with truth info:\n";
573  if (e1) e1->identify();
574  if (e2) e2->identify();
575  if (vtx) recoVertex->Print();
576  if (recoPhoton) recoPhoton->Print();
577 }
579  cout<<"Conversion with reco info:\n";
580  if (reco1) reco1->identify();
581  if (reco2) reco2->identify();
582  if (vtx) vtx->identify();
583  if (photon) photon->identify();
584 }
585 
587  if(!recoPhoton) cerr<<"No photon reconstructed"<<endl;
588  else{
589  cout<<"Truth Track: ";e1->identify();
590  cout<<"Reco Track: ";getRecoTrack(e1->get_track_id())->identify();
591  cout<<"Truth Track: ";e2->identify();
592  cout<<"Reco Track: ";getRecoTrack(e2->get_track_id())->identify();
593  cout<<"Truth Photon: ";photon->identify();
594  cout<<"Reco Photon: ";recoPhoton->Print();
595  }
596 }
597 void Conversion::PrintPhotonRecoInfo(TLorentzVector *tlv_photon,TLorentzVector *tlv_electron, TLorentzVector *tlv_positron,float mass){
598  if(!recoPhoton) cerr<<"No photon reconstructed"<<endl;
599  else{
600  cout<<"Truth Track: ";tlv_electron->Print();
601  cout<<"Reco Track: ";reco1->identify();
602  cout<<"Truth Track: ";tlv_positron->Print();
603  cout<<"Reco Track: ";reco2->identify();
604  cout<<"Truth Photon: ";tlv_photon->Print();
605  cout<<"Reco Photon with mass: "<<mass<<": ";recoPhoton->Print();
606  }
607 }
608 
609 /*This is deprecated
610  * float Conversion::setRecoVtx(SvtxVertex *recovtx,SvtxClusterMap* svtxClusterMap){
611  recoVertex=recovtx;
612  SvtxCluster *c1 = svtxClusterMap->get(*(reco1->begin_clusters()));
613  SvtxCluster *c2 = svtxClusterMap->get(*(reco2->begin_clusters()));
614  float r1 = sqrt(abs(c1->get_x()-recovtx->get_x())+abs(c1->get_y()-recovtx->get_y())+abs(c1->get_z()-recovtx->get_z()));
615  float r2 = sqrt(abs(c2->get_x()-recovtx->get_x())+abs(c2->get_y()-recovtx->get_y())+abs(c2->get_z()-recovtx->get_z()));
616  if (r1>r2)
617  {
618  return r1;
619  }
620  else return r2;
621  }*/
622 
624  if (recoCount()==2)
625  {
626  static const double eps = 0.000001;
627  TVector3 u(reco1->get_px(),reco1->get_py(),reco1->get_pz());
628  TVector3 v(reco2->get_px(),reco2->get_py(),reco2->get_pz());
629  TVector3 w(reco1->get_x()-reco2->get_x(),reco1->get_x()-reco2->get_y(),reco1->get_x()-reco2->get_z());
630 
631  double a = u.Dot(u);
632  double b = u.Dot(v);
633  double c = v.Dot(v);
634  double d = u.Dot(w);
635  double e = v.Dot(w);
636 
637  double D = a*c - b*b;
638  double sc, tc;
639  // compute the line parameters of the two closest points
640  if (D < eps) { // the lines are almost parallel
641  sc = 0.0;
642  tc = (b>c ? d/b : e/c); // use the largest denominator
643  }
644  else {
645  sc = (b*e - c*d) / D;
646  tc = (a*e - b*d) / D;
647  }
648  // get the difference of the two closest points
649  u*=sc;
650  v*=tc;
651  w+=u;
652  w-=v;
653  return w.Mag(); // return the closest distance
654  }
655  else return -1;
656 }
657 
659  if (recoCount()==2)
660  {
661  return fabs(reco1->get_eta()-reco2->get_eta());
662  }
663  else return -1.;
664 }
665 
667  static const double eps = 0.000001;
668  TVector3 u(reco1->get_px(),reco1->get_py(),reco1->get_pz());
669  TVector3 v(reco2->get_px(),reco2->get_py(),reco2->get_pz());
670  TVector3 w(reco1->get_x()-reco2->get_x(),reco1->get_x()-reco2->get_y(),reco1->get_x()-reco2->get_z());
671 
672  double a = u.Dot(u);
673  double b = u.Dot(v);
674  double c = v.Dot(v);
675  double d = u.Dot(w);
676  double e = v.Dot(w);
677 
678  double D = a*c - b*b;
679  double sc, tc;
680  // compute the line parameters of the two closest points
681  if (D < eps) { // the lines are almost parallel
682  sc = 0.0;
683  tc = (b>c ? d/b : e/c); // use the largest denominator
684  }
685  else {
686  sc = (b*e - c*d) / D;
687  tc = (a*e - b*d) / D;
688  }
689  // get the difference of the two closest points
690  u*=sc;
691  v*=tc;
692  w+=u;
693  w-=v;
694  return w.Mag(); // return the closest distance
695 }
696 
698  return fabs(reco1->get_eta()-reco2->get_eta());
699 }
700 
702  switch(recoCount()){
703  case 2:
704  if (reco1->get_pt()<reco2->get_pt())
705  {
706  return reco1->get_pt();
707  }
708  else return reco2->get_pt();
709  break;
710  case 1:
711  if (reco1)
712  {
713  return reco1->get_pt();
714  }
715  else return reco2->get_pt();
716  break;
717  default:
718  return -1;
719  break;
720  }
721 }
722 
723 std::pair<float,float> Conversion::getTrackpTs(){
724  switch(recoCount()){
725  case 2:
726  return std::pair<float,float>(reco1->get_pt(),reco2->get_pt());
727  case 1:
728  if (reco1) return std::pair<float,float>(reco1->get_pt(),-1);
729  else return std::pair<float,float>(-1,reco2->get_pt());
730  break;
731  default:
732  return std::pair<float,float>(-1,-1);
733  break;
734  }
735 }
736 
737 std::pair<float,float> Conversion::getTrackEtas(){
738  switch(recoCount()){
739  case 2:
740  return std::pair<float,float>(reco1->get_eta(),reco2->get_eta());
741  case 1:
742  if (reco1) return std::pair<float,float>(reco1->get_eta(),-1);
743  else return std::pair<float,float>(-1,reco2->get_eta());
744  break;
745  default:
746  return std::pair<float,float>(-1,-1);
747  break;
748  }
749 }
750 
751 std::pair<float,float> Conversion::getTrackPhis(){
752  switch(recoCount()){
753  case 2:
754  return std::pair<float,float>(reco1->get_phi(),reco2->get_phi());
755  case 1:
756  if (reco1) return std::pair<float,float>(reco1->get_phi(),-1);
757  else return std::pair<float,float>(-1,reco2->get_phi());
758  break;
759  default:
760  return std::pair<float,float>(-1,-1);
761  break;
762  }
763 }
764 /*This is the ideal case but I do not have RaveVtx to SvtxVertex matching yet
765  * genfit::GFRaveVertex* Conversion::getSecondaryVertex(SVReco* vertexer){
766  if(recoCount()==2){
767  if (recoVertex) delete recoVertex;
768  recoVertex= vertexer->findSecondaryVertex(reco1,reco2);
769  }
770  return recoVertex;
771  }*/
773  if(recoCount()==2){
774  //this might seg fault
775  if(recoVertex) delete recoVertex;
777  }
778  return recoVertex;
779 }
780 
782  if(!recoVertex) {
783  cerr<<"WARNING: no vertex to correct"<<endl;
784  return NULL;
785  }
786  if (recoCount()!=2)
787  {
788  cerr<<"WARNING: no reco tracks to do vertex correction"<<endl;
789  return NULL;
790  }
791 
792  TVector3 nextPos = recoVertex->getPos();
793  nextPos.SetMagThetaPhi(regressor->regress(reco1,reco2,recoVertex),nextPos.Theta(),nextPos.Phi());
794 
795  using namespace genfit;
796  // GFRaveVertex* temp = recoVertex;
797  std::vector<GFRaveTrackParameters*> tracks;
798  for(unsigned i =0; i<recoVertex->getNTracks();i++){
799  tracks.push_back(recoVertex->getParameters(i));
800  }
802  // delete temp; //this caused outside references to seg fault //TODO shared_ptr is better
803  return recoVertex;
804 }
805 
807  if(!recoVertex) {
808  cerr<<"WARNING: no vertex to correct"<<endl;
809  return NULL;
810  }
811  if (!(reco1&&reco2))
812  {
813  cerr<<"WARNING: no reco tracks to do vertex correction"<<endl;
814  return NULL;
815  }
816 
817  TVector3 nextPos = recoVertex->getPos();
818  nextPos.SetMagThetaPhi(regressor->regress(reco1,reco2,recoVertex),nextPos.Theta(),nextPos.Phi());
819 
820  using namespace genfit;
821  // GFRaveVertex* temp = recoVertex;
822  std::vector<GFRaveTrackParameters*> tracks;
823  for(unsigned i =0; i<recoVertex->getNTracks();i++){
824  tracks.push_back(recoVertex->getParameters(i));
825  }
826  recoVertex = new GFRaveVertex(nextPos,recoVertex->getCov(),tracks,recoVertex->getNdf(),recoVertex->getChi2(),recoVertex->getId());
827  // delete temp; //this caused outside references to seg fault //TODO shared_ptr is better
828  return recoVertex;
829 }
830 
831 std::pair<PHGenFit::Track*,PHGenFit::Track*> Conversion::getPHGFTracks(SVReco* vertexer){
832  std::pair<PHGenFit::Track*,PHGenFit::Track*> r;
833  r.first = vertexer->getPHGFTrack(reco1);
834  r.second = vertexer->getPHGFTrack(reco2);
835  return r;
836 }
837 
838 std::pair<PHGenFit::Track*,PHGenFit::Track*> Conversion::refitTracksTruthVtx(SVReco* vertexer,SvtxVertex* seedVtx){
839  PHG4VtxPointToSvtxVertex(seedVtx);
840  if(_refit_phgf_tracks.first) delete _refit_phgf_tracks.first;
841  if(_refit_phgf_tracks.second) delete _refit_phgf_tracks.second;
844  return _refit_phgf_tracks;
845 }
846 
847 std::pair<PHGenFit::Track*,PHGenFit::Track*> Conversion::refitTracksTruthVtx(SVReco* vertexer){
849  if(_refit_phgf_tracks.first) delete _refit_phgf_tracks.first;
850  if(_refit_phgf_tracks.second) delete _refit_phgf_tracks.second;
853  return _refit_phgf_tracks;
854 }
855 std::pair<PHGenFit::Track*,PHGenFit::Track*> Conversion::refitTracks(SVReco* vertexer){
856  if (!recoVertex) getSecondaryVertex(vertexer);
857  if(!recoVertex)
858  {
859  cerr<<"WARNING: No vertex to refit tracks"<<endl;
860  }
861  else{
862  if(_refit_phgf_tracks.first) delete _refit_phgf_tracks.first;
863  if(_refit_phgf_tracks.second) delete _refit_phgf_tracks.second;
865  _refit_phgf_tracks.second=vertexer->refitTrack(recoVertex,reco2);
866  }
867  return _refit_phgf_tracks;
868 }
869 
870 std::pair<PHGenFit::Track*,PHGenFit::Track*> Conversion::refitTracks(SVReco* vertexer, SvtxVertex* recoVtx){
871  if (!recoVtx)
872  {
873  cerr<<"WARNING: No vertex to refit tracks"<<endl;
874  }
875  else{
876  if(_refit_phgf_tracks.first) delete _refit_phgf_tracks.first;
877  if(_refit_phgf_tracks.second) delete _refit_phgf_tracks.second;
878  _refit_phgf_tracks.first=vertexer->refitTrack(recoVtx,reco1);
879  _refit_phgf_tracks.second=vertexer->refitTrack(recoVtx,reco2);
880  }
881  return _refit_phgf_tracks;
882 }
883 
885  truthSvtxVtx = new SvtxVertex_v1();
890  truthSvtxVtx->set_chisq(1.);
892 
893  TRandom3 rand(0);
894  double ae = 0.0007; //7 um
895  double i = 0.003;//30 um
896  double d = rand.Gaus(0, ae);
897  double g = rand.Gaus(0, ae);
898  double h = rand.Gaus(0, i);
899  truthSvtxVtx->set_error(0,0,ae*ae);
900  truthSvtxVtx->set_error(1,1,d*d+ae*ae);
901  truthSvtxVtx->set_error(2,2,g*g+h*h+i*i);
902  truthSvtxVtx->set_error(0,1,ae*d);
903  truthSvtxVtx->set_error(1,0,ae*d);
904  truthSvtxVtx->set_error(2,0,ae*g);
905  truthSvtxVtx->set_error(0,2,ae*g);
906  truthSvtxVtx->set_error(1,2,d*g+ae*h);
907  truthSvtxVtx->set_error(2,1,d*g+ae*h);
908  switch(recoCount()){
909  case 2:
912  case 1:
913  if (reco1) return truthSvtxVtx->insert_track(reco1->get_id());
914  else return truthSvtxVtx->insert_track(reco2->get_id());
915  break;
916  default:
917  break;
918  }
919 }
920 
922  truthSvtxVtx = new SvtxVertex_v1();
927  truthSvtxVtx->set_chisq(1.);
929 
930  for (int i = 0; i < 3; ++i)
931  {
932  for (int j = 0; j < 3; ++j)
933  {
934  truthSvtxVtx->set_error(i,j,seedVtx->get_error(i,j));
935  }
936  }
937  switch(recoCount()){
938  case 2:
941  case 1:
942  if (reco1) return truthSvtxVtx->insert_track(reco1->get_id());
943  else return truthSvtxVtx->insert_track(reco2->get_id());
944  break;
945  default:
946  break;
947  }
948 }
949