Class Reference for E1039 Core & Analysis Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
KalmanFastTracking.h
Go to the documentation of this file.
1 /*
2 KalmanFastTracking.h
3 
4 Fast tracking utility of Kalman filter track, used to improve the tracking speed and also for online monitoring
5 
6 Author: Kun Liu, liuk@fnal.gov
7 Created: 05-24-2013
8 */
9 
10 #ifndef _KALMANFASTTRACKING_H
11 #define _KALMANFASTTRACKING_H
12 
13 #include <GlobalConsts.h>
14 #include <geom_svc/GeomSvc.h>
15 
16 #include <list>
17 #include <vector>
18 #include <map>
19 
20 #include <Math/Factory.h>
21 #include <Math/Minimizer.h>
22 #include <Math/Functor.h>
23 
24 #include "SRawEvent.h"
25 #include "KalmanTrack.h"
26 #include "KalmanFitter.h"
27 #include "FastTracklet.h"
28 
29 class TGeoManager;
30 
31 class PHField;
32 class PHTimer;
33 
35 {
36 public:
37  explicit KalmanFastTracking(const PHField* field, const TGeoManager *geom, bool flag = true);
39 
40  //set/get verbosity
41  void Verbosity(const int a) {verbosity = a;}
42  int Verbosity() const {return verbosity;}
43  void printTimers();
44 
45  //Set the input event
46  int setRawEvent(SRawEvent* event_input);
47  void setRawEventDebug(SRawEvent* event_input);
48 
49  //Event quality cut
50  bool acceptEvent(SRawEvent* rawEvent);
51 
53  //Build tracklets in a station
54  void buildTrackletsInStation(int stationID, int listID, double* pos_exp = nullptr, double* window = nullptr);
55 
56  //Build back partial tracks using tracklets in station 2 & 3
58 
59  //Build global tracks by connecting station 23 tracklets and station 1 tracklets
60  void buildGlobalTracks();
61 
62  //Fit tracklets
63  int fitTracklet(Tracklet& tracklet);
64 
65  //Check the quality of tracklet, number of hits
66  bool acceptTracklet(Tracklet& tracklet);
67  bool hodoMask(Tracklet& tracklet);
68  bool muonID_comp(Tracklet& tracklet);
69  bool muonID_search(Tracklet& tracklet);
70  bool muonID_hodoAid(Tracklet& tracklet);
71 
72  void buildPropSegments();
73 
74  //Resolve left-right when possible
75  void resolveLeftRight(SRawEvent::hit_pair hpair, int& LR1, int& LR2);
76  void resolveLeftRight(Tracklet& tracklet, double threshold);
77  void resolveSingleLeftRight(Tracklet& tracklet);
78 
79  //Remove bad hit if needed
80  void removeBadHits(Tracklet& tracklet);
81 
82  //Reduce the list of tracklets, returns the number of elements reduced
83  int reduceTrackletList(std::list<Tracklet>& tracklets);
84 
85  //Get exp postion and window using sagitta method in station 1
86  void getSagittaWindowsInSt1(Tracklet& tracklet, double* pos_exp, double* window, int st1ID);
87  void getExtrapoWindowsInSt1(Tracklet& tracklet, double* pos_exp, double* window, int st1ID);
88 
89  //Print the distribution of tracklets at detector back/front
90  void printAtDetectorBack(int stationID, std::string outputFileName);
91 
93  //Convert Tracklet to KalmanTrack and solve left-right problem, and eventually to a SRecTrack
95 
96  //Use Kalman fitter to fit a track
97  bool fitTrack(KalmanTrack& kmtrk);
98 
99  //Resolve left right by Kalman fitting results
100  void resolveLeftRight(KalmanTrack& kmtrk);
101 
103  std::list<Tracklet>& getFinalTracklets() { return trackletsInSt[outputListIdx]; }
104  std::list<Tracklet>& getBackPartials() { return trackletsInSt[3]; }
105  std::list<Tracklet>& getTrackletList(int i) { return trackletsInSt[i]; }
106  std::list<SRecTrack>& getSRecTracks() { return stracks; }
107  std::list<PropSegment>& getPropSegments(int i) { return propSegs[i]; }
108 
110  void setOutputListID(unsigned int i) { outputListIdx = i; }
111 
113  void chi2fit(int n, double x[], double y[], double& a, double& b);
114 
115 private:
116  //verbosity following Fun4All convention
117  int verbosity;
118 
119  //Raw event input
120  SRawEvent* rawEvent;
121  std::vector<Hit> hitAll;
122 
123  //Tracklets in one event, id = 0, 1, 2 for station 0/1, 2, 3+/-, id = 3 for station 2&3 combined, id = 4 for global tracks
124  //Likewise for the next part
125  std::list<Tracklet> trackletsInSt[5];
126 
127  //Final SRecTrack list
128  std::list<SRecTrack> stracks;
129 
130  //Index of the trackletlist designated as output
131  unsigned int outputListIdx;
132 
133  //Prop. tube segments for muon id purposes
134  // 0 for X-Z, 1 for Y-Z
135  std::list<PropSegment> propSegs[2];
136 
138  //Hodo. IDs for masking, 4 means we have 4 hodo stations
139  std::vector<int> detectorIDs_mask[4];
140  std::vector<int> detectorIDs_maskX[4];
141  std::vector<int> detectorIDs_maskY[4];
142  std::list<int> hitIDs_mask[4]; //hits in T/B, L/R are combined
143  std::vector<int> detectorIDs_muidHodoAid[2]; //Aux-hodoscope masking for muon ID
144 
145  //register difference hodo masking stations for different chamber detectors
146  std::vector<int> stationIDs_mask[nStations];
147 
148  //prop. tube IDs for MUID -- 0 for x-z, 1 for y-z
149  int detectorIDs_muid[2][4];
150  double z_ref_muid[2][4];
151  std::list<int> hitIDs_muid[2][4];
152  std::list<int> hitIDs_muidHodoAid[2];
153 
154  //Masking window sizes, index is the uniqueID defined by nElement*detectorID + elementID
155  double z_mask[nHodoPlanes+nPropPlanes];
156  double x_mask_min[nHodoPlanes+nPropPlanes][72];
157  double x_mask_max[nHodoPlanes+nPropPlanes][72];
158  double y_mask_min[nHodoPlanes+nPropPlanes][72];
159  double y_mask_max[nHodoPlanes+nPropPlanes][72];
160 
162  //Super plane IDs for DCs
163  std::vector<int> superIDs[nChamberPlanes/6+2];
164 
165  //Window sizes for X-U combination
166  double u_win[nChamberPlanes/6];
167  double u_costheta[nChamberPlanes/6];
168  double u_sintheta[nChamberPlanes/6];
169  double z_plane_x[nChamberPlanes/6];
170  double z_plane_u[nChamberPlanes/6];
171  double z_plane_v[nChamberPlanes/6];
172 
173  //Plane angles for all planes
174  double costheta_plane[nChamberPlanes+1];
175  double sintheta_plane[nChamberPlanes+1];
176 
177  //Z positions
178  double z_plane[nChamberPlanes+1];
179 
180  //Maximum slope and intersection in each view
181  double slope_max[nChamberPlanes+1];
182  double intersection_max[nChamberPlanes+1];
183 
184  //Resolutions of all planes
185  double resol_plane[nChamberPlanes+1];
186 
187  //Cell width of all planes
188  double spacing_plane[nChamberPlanes+1];
189 
190  //Sagitta ratio in station 1, index 0, 1, 2 are for X/U/V
191  int s_detectorID[3];
192 
193  //Current tracklets being processed
194  Tracklet tracklet_curr;
195 
196  //Least chi square fitter and functor
197  ROOT::Math::Minimizer* minimizer[2];
198  ROOT::Math::Functor fcn;
199 
200  //Kalman fitter
201  KalmanFitter* kmfitter;
202 
203  //Geometry service
204  GeomSvc* p_geomSvc;
205 
206  //Flag for enable Kalman fitting
207  const bool enable_KF;
208 
209  //Timer
210  std::map<std::string, PHTimer*> _timers;
211 };
212 
213 #endif
int setRawEvent(SRawEvent *event_input)
std::list< Tracklet > & getTrackletList(int i)
std::list< SRecTrack > & getSRecTracks()
int fitTracklet(Tracklet &tracklet)
void getSagittaWindowsInSt1(Tracklet &tracklet, double *pos_exp, double *window, int st1ID)
#define nPropPlanes
Definition: GlobalConsts.h:8
SRecTrack processOneTracklet(Tracklet &tracklet)
Track fitting stuff.
bool acceptTracklet(Tracklet &tracklet)
void chi2fit(int n, double x[], double y[], double &a, double &b)
Tool, a simple-minded chi square fit.
transient DST object for field storage and access
Definition: PHField.h:13
#define nHodoPlanes
Definition: GlobalConsts.h:7
KalmanFastTracking(const PHField *field, const TGeoManager *geom, bool flag=true)
void resolveLeftRight(SRawEvent::hit_pair hpair, int &LR1, int &LR2)
std::list< Tracklet > & getBackPartials()
void buildTrackletsInStation(int stationID, int listID, double *pos_exp=nullptr, double *window=nullptr)
Tracklet finding stuff.
std::pair< Int_t, Int_t > hit_pair
Type of pair with two adjacent wires.
Definition: SRawEvent.h:169
#define nStations
Definition: GlobalConsts.h:5
void removeBadHits(Tracklet &tracklet)
bool muonID_search(Tracklet &tracklet)
bool acceptEvent(SRawEvent *rawEvent)
int reduceTrackletList(std::list< Tracklet > &tracklets)
void printAtDetectorBack(int stationID, std::string outputFileName)
bool muonID_hodoAid(Tracklet &tracklet)
#define nChamberPlanes
Definition: GlobalConsts.h:6
bool fitTrack(KalmanTrack &kmtrk)
std::list< PropSegment > & getPropSegments(int i)
bool muonID_comp(Tracklet &tracklet)
void setOutputListID(unsigned int i)
Set the index of the final output tracklet list.
void setRawEventDebug(SRawEvent *event_input)
void getExtrapoWindowsInSt1(Tracklet &tracklet, double *pos_exp, double *window, int st1ID)
bool hodoMask(Tracklet &tracklet)
void resolveSingleLeftRight(Tracklet &tracklet)
void Verbosity(const int a)
std::list< Tracklet > & getFinalTracklets()
Final output.
high precision timer
Definition: PHTimer.h:24