Class Reference for E1039 Core & Analysis Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
VertexFit.h
Go to the documentation of this file.
1 #ifndef _VERTEXFIT_H
2 #define _VERTEXFIT_H
3 
4 /*
5 VertexFit.h
6 
7 Definition of the Vertex fit of dimuon events, this package is aimed at:
8 1. Use closest distance method to find z0 for two muon tracks
9 2. Use vertex fit to fit the z0 --- will be implemented in next version
10 
11 Reference: CBM-SOFT-note-2006-001, by S. Gorbunov and I. Kisel, with some minor
12 modifications
13 
14 Author: Kun Liu, liuk@fnal.gov
15 Created: 2-8-2012
16 */
17 
18 // Fun4All includes
19 #include <fun4all/SubsysReco.h>
20 #include <GlobalConsts.h>
21 
22 #include <iostream>
23 #include <vector>
24 
25 #include <TFile.h>
26 #include <TTree.h>
27 #include <TMatrixD.h>
28 
29 #include "KalmanUtil.h"
30 #include "SRecEvent.h"
31 #include "FastTracklet.h"
32 #include "GenFitExtrapolator.h"
33 
34 class KalmanTrack;
35 class KalmanFilter;
36 class PHField;
37 class TGeoManager;
38 class JobOptsSvc;
39 
40 class VtxPar
41 {
42 public:
44  {
45  _r.ResizeTo(3, 1);
46  _cov.ResizeTo(3, 3);
47 
48  _r.Zero();
49  _cov.Zero();
50  }
51 
52  void print()
53  {
54  SMatrix::printMatrix(_r, "Vertex position:");
55  SMatrix::printMatrix(_cov, "Vertex covariance:");
56  }
57 
58  TMatrixD _r;
59  TMatrixD _cov;
60 };
61 
62 class VertexFit : public SubsysReco
63 {
64 public:
65  VertexFit(const std::string& name = "VertexFit");
66  ~VertexFit();
67 
68  int Init(PHCompositeNode *topNode);
69  int InitRun(PHCompositeNode *topNode);
70  int process_event(PHCompositeNode *topNode);
71  int End(PHCompositeNode *topNode);
72 
74  void enableOptimization() { optimize = true; }
75 
77  void setControlParameter(int nMaxIteration, double tolerance)
78  {
79  _max_iteration = nMaxIteration;
80  _tolerance = tolerance;
81  }
82 
84  int setRecEvent(SRecEvent* recEvent, int sign1 = 1, int sign2 = -1);
85 
87  void init();
88  void addHypothesis(double z, double sigz = 50.) { z_start.push_back(z); sig_z_start.push_back(sigz); }
89  void setStartingVertex(double z_start, double sigz_start);
90 
92  void addTrack(int index, SRecTrack& _track);
93  void addTrack(int index, KalmanTrack& _track);
94  void addTrack(int index, TrkPar& _trkpar);
95 
97  int processOnePair();
98 
100  int findVertex();
101  double findDimuonVertexFast(SRecTrack& track1, SRecTrack& track2);
102  double findSingleMuonVertex(SRecTrack& _track);
103  double findSingleMuonVertex(Node& _node_start);
104  double findSingleMuonVertex(TrkPar& _trkpar_start);
105 
107  double getVertexZ0() { return _vtxpar_curr._r[2][0]; }
108  double getVXChisq() { return _chisq_vertex; }
109  double getKFChisq() { return _chisq_kalman; }
110  int getNTracks() { return _trkpar_curr.size(); }
111 
113  void updateVertex();
114 
116  void bookEvaluation(std::string evalFileName = "vtx_eval.root");
117  void fillEvaluation();
118 
120  void print();
121 
122  const std::string& get_eval_file_name() const {
123  return evalFileName;
124  }
125 
126  void set_eval_file_name(const std::string& evalFileName) {
127  this->evalFileName = evalFileName;
128  }
129 
130 private:
131 
132  int InitField(PHCompositeNode *topNode);
133 
134  int InitGeom(PHCompositeNode *topNode);
135 
136  int MakeNodes(PHCompositeNode *topNode);
137 
138  int GetNodes(PHCompositeNode *topNode);
139 
141  std::vector<TrkPar> _trkpar_curr;
142 
144  VtxPar _vtxpar_curr;
145 
147  Node _node_vertex;
148 
150  KalmanFilter* _kmfit;
151 
153  double _chisq_vertex;
154  double _chisq_kalman;
155 
157  std::vector<double> z_start;
158  std::vector<double> sig_z_start;
159 
161  std::vector<double> z_vertex;
162  std::vector<double> r_vertex;
163  std::vector<double> chisq_km;
164  std::vector<double> chisq_vx;
165 
167  int _max_iteration;
168  double _tolerance;
169 
171  GenFitExtrapolator _extrapolator;
172 
174  bool optimize;
175 
176  TGeoManager * _t_geo_manager;
177 
178  SRecEvent* _recEvent;
179 
181  std::string evalFileName;
182  TFile* evalFile;
183  TTree* evalTree;
184 
185  int runID;
186  int eventID;
187  int targetPos;
188  int nPos;
189  int nNeg;
190  int p_idx_eval;
191  int m_idx_eval;
192  int choice_eval;
193  int choice_by_kf_eval;
194  int choice_by_vx_eval;
195 
196  int nStart;
197  double z_start_eval[50];
198  int nIter_eval[50];
199  double chisq_kf_eval[50];
200  double chisq_vx_eval[50];
201  double z_vertex_eval[50];
202  double r_vertex_eval[50];
203 
204  double m_chisq_kf_eval;
205  double s_chisq_kf_eval;
206  double m_z_vertex_eval;
207  double s_z_vertex_eval;
208 };
209 
210 #endif
int getNTracks()
Definition: VertexFit.h:110
double getVXChisq()
Definition: VertexFit.h:108
VertexFit(const std::string &name="VertexFit")
Definition: VertexFit.cxx:89
int setRecEvent(SRecEvent *recEvent, int sign1=1, int sign2=-1)
Set the SRecEvent, main external call the use vertex fit.
Definition: VertexFit.cxx:255
void addTrack(int index, SRecTrack &_track)
Add one track parameter set into the fit.
Definition: VertexFit.cxx:523
void setStartingVertex(double z_start, double sigz_start)
Definition: VertexFit.cxx:450
void addHypothesis(double z, double sigz=50.)
Definition: VertexFit.h:88
int processOnePair()
After setting both tracks and hypothesis, start the iteration.
Definition: VertexFit.cxx:466
static void printMatrix(const TMatrixD &m)
Definition: KalmanUtil.cxx:17
transient DST object for field storage and access
Definition: PHField.h:13
VtxPar()
Definition: VertexFit.h:43
void print()
Definition: VertexFit.h:52
double findDimuonVertexFast(SRecTrack &track1, SRecTrack &track2)
Definition: VertexFit.cxx:405
void fillEvaluation()
Definition: VertexFit.cxx:690
double getVertexZ0()
Gets.
Definition: VertexFit.h:107
void setControlParameter(int nMaxIteration, double tolerance)
Set the convergence control parameters.
Definition: VertexFit.h:77
double findSingleMuonVertex(SRecTrack &_track)
Definition: VertexFit.cxx:627
void init()
Initialize and reset.
Definition: VertexFit.cxx:433
double getKFChisq()
Definition: VertexFit.h:109
int findVertex()
Find the primary vertex.
Definition: VertexFit.cxx:538
void set_eval_file_name(const std::string &evalFileName)
Definition: VertexFit.h:126
int End(PHCompositeNode *topNode)
Called at the end of all processing.
Definition: VertexFit.cxx:201
TMatrixD _r
Definition: VertexFit.h:58
int InitRun(PHCompositeNode *topNode)
Definition: VertexFit.cxx:145
const std::string & get_eval_file_name() const
Definition: VertexFit.h:122
void bookEvaluation(std::string evalFileName="vtx_eval.root")
Evaluation.
Definition: VertexFit.cxx:664
int process_event(PHCompositeNode *topNode)
Definition: VertexFit.cxx:183
void enableOptimization()
Enable the optimization of final dimuon vertex z position.
Definition: VertexFit.h:74
int Init(PHCompositeNode *topNode)
Definition: VertexFit.cxx:138
void print()
Debugging output.
Definition: VertexFit.cxx:746
void updateVertex()
Core function, update the vertex prediction according to the track info.
Definition: VertexFit.cxx:593
TMatrixD _cov
Definition: VertexFit.h:59