MarlinTPC  1.2.0
MMRefitTool.h
1 #ifndef MMREFITTOOL_H
2 #define MMREFITTOOL_H
3 
4 // C++
5 #include <iostream>
6 #include <string>
7 #include <vector>
8 #include <map>
9 
10 // ROOT
11 #include "Math/ParamFunctor.h"
12 #include <Minuit2/FCNBase.h>
13 #include <TMath.h>
14 
15 //LCIO
16 #include "lcio.h"
17 #include "EVENT/TrackerPulse.h"
18 #include <EVENT/LCFloatVec.h>
19 #include <IMPL/TrackerPulseImpl.h>
20 #include <IMPL/TrackerHitImpl.h>
21 #include <IMPL/TrackImpl.h>
22 
23 // GEAR
24 #include <gear/TPCParameters.h>
25 #include <gear/TPCModule.h>
26 #include <gearimpl/GlobalPadIndex.h>
27 
28 //MARLIN
29 #include <marlin/Global.h>
30 
31 // Other
32 #include "MMPadResponseFunction.h"
33 #include "TrackFitterFactory.h"
34 #include "TrackFitterBase.h"
35 #include "LCObjectCopier.h"
36 
37 
38 namespace marlintpc
39 {
40 
41  /* This is a tool for calculating the chi2 of all the hits in a track, and the track itself. It is used to find the optimal PRF parameters
42  * on an event-by-event basis as a means of calibration.
43  *
44  * Author: P. Hayman, Carleton University
45  */
46 
47  class MMRefitTool : public ROOT::Minuit2::FCNBase
48  {
49 
50  public:
51 
52  //Fit Type: 0 = straight track
53  // 1 = helical track
54  MMRefitTool(int fitType, int nPar, std::string prfType, bool rowDep, const IMPL::TrackImpl* seed, bool fitTrack, int normType, bool padHits);
55 
56  ~MMRefitTool()
57  {
58  trackFitter = NULL;
59  std::vector<MMPadResponseFunction>().swap(_prfs);
60  std::map<int, int>().swap(_moduleList);
61  };
62  MMRefitTool( const MMRefitTool& other)
63  {
64  _fit_type = other._fit_type;
65  _nPar = other._nPar;
66  _prfType = other._prfType;
67  _rowDep = other._rowDep;
68  _moduleDep = other._moduleDep;
69  _seedTrack = other._seedTrack;
70  _fitTrack = other._fitTrack;
71  _normType = other._normType;
72  _padHits = other._padHits;
73  _moduleList = other._moduleList;
74  _theErrorDef = other._theErrorDef;
75  _prfs = other._prfs;
76 
77  if(_fit_type == 0)
80  else if(_fit_type == 1)
83  }
84 
85  MMRefitTool &operator=( const MMRefitTool& other )
86  {
87  _fit_type = other._fit_type;
88  _nPar = other._nPar;
89  _prfType = other._prfType;
90  _rowDep = other._rowDep;
91  _moduleDep = other._moduleDep;
92  _seedTrack = other._seedTrack;
93  _fitTrack = other._fitTrack;
94  _normType = other._normType;
95  _padHits = other._padHits;
96  _moduleList = other._moduleList;
97  _theErrorDef = other._theErrorDef;
98  _prfs = other._prfs;
99  if(_fit_type == 0)
100  trackFitter = TrackFitterFactory::getTrackFitter(
102  else if(_fit_type == 1)
103  trackFitter = TrackFitterFactory::getTrackFitter(
105  return *this;
106  }
107 
108  void setModules(const std::vector<int>& modules)
109  {
110  _moduleDep = true;
111 
112  for(unsigned int i = 0; i < modules.size(); i++)
113  _moduleList[modules[i]] = i;
114  };
115 
116  // Required functions from inheritance.
117  virtual double Up() const{
118  return _theErrorDef;
119  };
120 
121  double operator()(const std::vector<double>& x) const {
122  double * xx = new double[x.size()];
123  for(unsigned int i = 0; i < x.size(); i++) xx[i] = x[i];
124  return (*this)(xx);
125  };
126 
127  //The main chi2 function
128  double operator()(const double* x) const ;
129 
130  void SetErrorDef(double def){
131  _theErrorDef = def;
132  };
133 
134  std::vector<double> retrievePar(const double* x);
135  std::vector<double> retrieveChi2(const double* x);
136 
137  private:
138 
139  int _fit_type;
140  int _nPar;
141  std::string _prfType;
142  bool _rowDep;
143  bool _moduleDep;
144  const IMPL::TrackImpl * _seedTrack;
145  bool _fitTrack;
146  int _normType;
147  bool _padHits;
148 
149  std::map<int, int> _moduleList;
150 
151  double _theErrorDef;
152  TrackFitterBase * trackFitter;
153 
154  //Vector containing pre-built PRF objects for easy access
155  std::vector<MMPadResponseFunction> _prfs;
156 
157  void padData(const EVENT::TrackerPulse * , const EVENT::LCObjectVec& , std::vector< std::pair <double, float> >& ) const;
158  double calcRowDep(const double * x, int index, int row) const;
159 
160  };//End MMRefitTool class
161 
162 }//End namespace marlintpc
163 
164 #endif
static const unsigned char LINEARREGRESSION
Linear regression for a straight line.
Definition: TrackFitterBase.h:61
static const unsigned char SIMPLEHELIXFIT
Simple Helix Fit from V.Karimaeki: "Effective circle fitting for particle trajectories".
Definition: TrackFitterBase.h:65
Definition: MMRefitTool.h:47
static TrackFitterBase * getTrackFitter(unsigned char fitterType, EVENT::LCParameters const *collectionParameters, EVENT::LCEvent const *event=0)
Get a track fitter and reinitialise its parameters.
Definition: TrackFitterFactory.cc:23
The TrackFitterBase is a virtual class from which the actual track fitters are derived.
Definition: TrackFitterBase.h:44