Class Reference for E1039 Core & Analysis Software
GFFitter.cxx
Go to the documentation of this file.
1 #include "GFFitter.h"
2 
3 #include <GenFit/DAF.h>
4 #include <GenFit/EventDisplay.h>
5 #include <GenFit/FieldManager.h>
6 #include <GenFit/FitStatus.h>
7 #include <GenFit/KalmanFitter.h>
8 #include <GenFit/KalmanFitterRefTrack.h>
9 #include <GenFit/MaterialEffects.h>
10 #include <GenFit/TGeoMaterialInterface.h>
11 
12 namespace SQGenFit
13 {
14 GFFitter::GFFitter(): _verbosity(0), _kmfitter(nullptr), _display(nullptr)
15 {}
16 
18 {
19  if(_kmfitter != nullptr) delete _kmfitter;
20  if(_display != nullptr) delete _display;
21 }
22 
23 void GFFitter::setVerbosity(unsigned int v)
24 {
25  _verbosity = v;
26  if(_kmfitter != nullptr) _kmfitter->setDebugLvl(_verbosity);
27 }
28 
29 void GFFitter::init(GFField* field, const TString& fitter_choice)
30 {
31  genfit::FieldManager::getInstance()->init(field);
32  genfit::MaterialEffects::getInstance()->init(new genfit::TGeoMaterialInterface());
33 
34  _fitterTy = fitter_choice;
35  if(fitter_choice == "KalmanFitterRefTrack")
36  _kmfitter = new genfit::KalmanFitterRefTrack();
37  else if(fitter_choice == "KalmanFitter")
38  _kmfitter = new genfit::KalmanFitter();
39  else if(fitter_choice == "DafSimple")
40  _kmfitter = new genfit::DAF(false);
41  else if(fitter_choice == "DafRef")
42  _kmfitter = new genfit::DAF(true);
43  else
44  _kmfitter = new genfit::KalmanFitter();
45 
46  _kmfitter->setMaxIterations(10);
47  _kmfitter->setDebugLvl(_verbosity);
48 }
49 
50 int GFFitter::processTrack(GFTrack& track, bool display)
51 {
52  //check before fit
53  try
54  {
55  track.checkConsistency();
56  }
57  catch(genfit::Exception& e)
58  {
59  std::cerr << "Track consistency error before fit: " << e.what() << std::endl;
60  return -1;
61  }
62 
63  //Do the fit
64  genfit::Track* gftrack = track.getGenFitTrack();
65  try
66  {
67  _kmfitter->processTrack(gftrack);
68  }
69  catch(genfit::Exception& e)
70  {
71  std::cerr << "Track fitting failed: " << e.what() << std::endl;
72  return -2;
73  }
74 
75  //check after fit
76  try
77  {
78  track.checkConsistency();
79  }
80  catch(genfit::Exception& e)
81  {
82  std::cerr << "Track consistency error after fit: " << e.what() << std::endl;
83  return -3;
84  }
85 
86  genfit::AbsTrackRep* rep = gftrack->getCardinalRep();
87  if(!gftrack->getFitStatus(rep)->isFitConverged())
88  {
89  std::cerr << "Fit failed to converge." << std::endl;
90  return -4;
91  }
92 
93  if(display)
94  {
95  if(_display == nullptr) _display = genfit::EventDisplay::getInstance();
96  _display->addEvent(gftrack);
97  }
98 
99  return 0;
100 }
101 
103 {
104  if(_display != nullptr) _display->open();
105 }
106 
107 }
void init(GFField *field, const TString &fitter_choice="KalmanFitterRefTrack")
Definition: GFFitter.cxx:29
void setVerbosity(unsigned int v)
Definition: GFFitter.cxx:23
int processTrack(GFTrack &track, bool display=false)
Definition: GFFitter.cxx:50
genfit::Track * getGenFitTrack()
Definition: GFTrack.h:57
void checkConsistency()
Definition: GFTrack.h:50