Class Reference for E1039 Core & Analysis Software
KalmanDSTrk.h
Go to the documentation of this file.
1 
9 #ifndef _KalmanDSTrk_H
10 #define _KalmanDSTrk_H
11 
12 #include <GlobalConsts.h>
13 #include <jobopts_svc/JobOptsSvc.h>
14 #include <geom_svc/GeomSvc.h>
15 
16 #include "SRawEvent.h"
17 #include "KalmanTrack.h"
18 #include "KalmanFitter.h"
19 #include "FastTracklet.h"
20 #include "PatternDB.h"
21 
22 #include <list>
23 #include <vector>
24 #include <map>
25 #include <set>
26 //#include <tuple>
27 
28 #include <Math/Factory.h>
29 #include <Math/Minimizer.h>
30 #include <Math/Functor.h>
31 
32 class TGeoManager;
33 
34 class PHField;
35 class PHTimer;
36 
37 class TFile;
38 class TNtuple;
39 
41 {
42 public:
43 
44  //enum DS_LEVEL {NO_DS, ST23_DS, ST123_DS, IN_ST_DS};
46 
47  explicit KalmanDSTrk(
48  const PHField* field,
49  const TGeoManager *geom,
50  bool enable_KF = true,
51  int DS_level = KalmanDSTrk::NO_DS,
52  const std::string sim_db_name = "",
53  const std::string pattern_db_name = ""
54  );
55 
56  ~KalmanDSTrk();
57 
58  //
59  void Verbosity(const int a) {verbosity = a;}
60  int Verbosity() const {return verbosity;}
61  void printTimers();
62 
63  //Set the input event
64  int setRawEvent(SRawEvent* event_input);
65  int setRawEventWorker(SRawEvent* event_input);
66  void setRawEventDebug(SRawEvent* event_input);
67 
68  //Event quality cut
69  bool acceptEvent(SRawEvent* rawEvent);
70 
72  //Build tracklets in a station
73  void buildTrackletsInStation(int stationID, int listID, double* pos_exp = NULL, double* window = NULL);
74 
75  //Build back partial tracks using tracklets in station 2 & 3
77 
78  //Build global tracks by connecting station 23 tracklets and station 1 tracklets
79  void buildGlobalTracks();
80 
81  //Fit tracklets
82  int fitTracklet(Tracklet& tracklet);
83 
84  //Check the quality of tracklet, number of hits
85  bool acceptTracklet(Tracklet& tracklet);
86  bool hodoMask(Tracklet& tracklet);
87  bool muonID_comp(Tracklet& tracklet);
88  bool muonID_search(Tracklet& tracklet);
89  bool muonID_hodoAid(Tracklet& tracklet);
90 
91  void buildPropSegments();
92 
93  //Resolve left-right when possible
94  void resolveLeftRight(SRawEvent::hit_pair hpair, int& LR1, int& LR2);
95  void resolveLeftRight(Tracklet& tracklet, double threshold);
96  void resolveSingleLeftRight(Tracklet& tracklet);
97 
98  //Remove bad hit if needed
99  void removeBadHits(Tracklet& tracklet);
100 
101  //Reduce the list of tracklets, returns the number of elements reduced
102  int reduceTrackletList(std::list<Tracklet>& tracklets);
103 
104  //Get exp postion and window using sagitta method in station 1
105  void getSagittaWindowsInSt1(Tracklet& tracklet, double* pos_exp, double* window, int st1ID);
106  void getExtrapoWindowsInSt1(Tracklet& tracklet, double* pos_exp, double* window, int st1ID);
107 
108  //Print the distribution of tracklets at detector back/front
109  void printAtDetectorBack(int stationID, std::string outputFileName);
110 
112  //Convert Tracklet to KalmanTrack and solve left-right problem, and eventually to a SRecTrack
114 
115  //Use Kalman fitter to fit a track
116  bool fitTrack(KalmanTrack& kmtrk);
117 
118  //Resolve left right by Kalman fitting results
119  void resolveLeftRight(KalmanTrack& kmtrk);
120 
122  std::list<Tracklet>& getFinalTracklets() { return trackletsInSt[4]; }
123  std::list<Tracklet>& getBackPartials() { return trackletsInSt[3]; }
124  std::list<Tracklet>& getTrackletList(int i) { return trackletsInSt[i]; }
125  std::list<SRecTrack>& getSRecTracks() { return stracks; }
126  std::list<PropSegment>& getPropSegments(int i) { return propSegs[i]; }
127 
130  void chi2fit(int n, double x[], double y[], double& a, double& b);
131 
132  const std::string& get_pattern_db_name() const {
133  return _pattern_db_name;
134  }
135 
136  void set_pattern_db_name(const std::string& patternDbName) {
137  _pattern_db_name = patternDbName;
138  }
139 
140  const std::string& get_sim_db_name() const {
141  return _sim_db_name;
142  }
143 
144  void set_sim_db_name(const std::string& simDbName) {
145  _sim_db_name = simDbName;
146  }
147 
148 private:
149 
150  int verbosity;
151 
152  //Raw event input
153  SRawEvent* rawEvent;
154  std::vector<Hit> hitAll;
155 
156  //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
157  //Likewise for the next part
158  std::list<Tracklet> trackletsInSt[5];
159 
160  //Final SRecTrack list
161  std::list<SRecTrack> stracks;
162 
163  //Prop. tube segments for muon id purposes
164  // 0 for X-Z, 1 for Y-Z
165  std::list<PropSegment> propSegs[2];
166 
168  //Hodo. IDs for masking, 4 means we have 4 hodo stations
169  std::vector<int> detectorIDs_mask[4];
170  std::vector<int> detectorIDs_maskX[4];
171  std::vector<int> detectorIDs_maskY[4];
172  std::list<int> hitIDs_mask[4]; //hits in T/B, L/R are combined
173  std::vector<int> detectorIDs_muidHodoAid[2]; //Aux-hodoscope masking for muon ID
174 
175  //register difference hodo masking stations for different chamber detectors
176  std::vector<int> stationIDs_mask[nStations];
177 
178  //prop. tube IDs for MUID -- 0 for x-z, 1 for y-z
179  int detectorIDs_muid[2][4];
180  double z_ref_muid[2][4];
181  std::list<int> hitIDs_muid[2][4];
182  std::list<int> hitIDs_muidHodoAid[2];
183 
184  //Masking window sizes, index is the uniqueID defined by nElement*detectorID + elementID
185  double z_mask[nHodoPlanes+nPropPlanes];
186  double x_mask_min[nHodoPlanes+nPropPlanes][72];
187  double x_mask_max[nHodoPlanes+nPropPlanes][72];
188  double y_mask_min[nHodoPlanes+nPropPlanes][72];
189  double y_mask_max[nHodoPlanes+nPropPlanes][72];
190 
192  //Super plane IDs for DCs
193  std::vector<int> superIDs[nChamberPlanes/6+2];
194 
195  //Window sizes for X-U combination
196  double u_win[nChamberPlanes/6];
197  double u_costheta[nChamberPlanes/6];
198  double u_sintheta[nChamberPlanes/6];
199  double z_plane_x[nChamberPlanes/6];
200  double z_plane_u[nChamberPlanes/6];
201  double z_plane_v[nChamberPlanes/6];
202 
203  //Plane angles for all planes
204  double costheta_plane[nChamberPlanes+1];
205  double sintheta_plane[nChamberPlanes+1];
206 
207  //Z positions
208  double z_plane[nChamberPlanes+1];
209 
210  //Maximum slope and intersection in each view
211  double slope_max[nChamberPlanes+1];
212  double intersection_max[nChamberPlanes+1];
213 
214  //Resolutions of all planes
215  double resol_plane[nChamberPlanes+1];
216 
217  //Cell width of all planes
218  double spacing_plane[nChamberPlanes+1];
219 
220  //Sagitta ratio in station 1, index 0, 1, 2 are for X/U/V
221  int s_detectorID[3];
222 
223  //Current tracklets being processed
224  Tracklet tracklet_curr;
225 
226  //Least chi square fitter and functor
227  ROOT::Math::Minimizer* minimizer[2];
228  ROOT::Math::Functor fcn;
229 
230  //Kalman fitter
231  KalmanFitter* kmfitter;
232 
233  //Geometry service
234  GeomSvc* p_geomSvc;
235 
236  //Job option service
237  JobOptsSvc* p_jobOptsSvc;
238 
239  //Flag for enable Kalman fitting
240  const bool _enable_KF;
241 
242  // Dictionary search
243  int _DS_level;
244  std::string _sim_db_name;
245  std::string _pattern_db_name;
246 
247  /*
248  //typedef std::tuple<unsigned char, unsigned char, unsigned char, unsigned char> TrackletKey;
249  typedef std::tuple<unsigned int, unsigned int> TrackletKey;
250  const TrackletKey _error_key;
251 
252  typedef std::tuple<TrackletKey, TrackletKey> PartTrackKey;
253 
254  void print(TrackletKey key);
255  void print(PartTrackKey key);
256 
257  enum STATION { DC1, DC2, DC3p, DC3m};
258 
259  std::set<TrackletKey> _db_st2;
260  std::set<TrackletKey> _db_st3;
261  std::set<PartTrackKey> _db_st23;
262 
263  int LoadPatternDB (const std::string fname);
264 
265  TrackletKey EncodeTrackletKey (
266  STATION,
267  const unsigned int X, const unsigned int Xp,
268  const unsigned int U, const unsigned int Up,
269  const unsigned int V, const unsigned int Vp);
270 
271 
272  TrackletKey GetTrackletKey (const Tracklet tracklet, const STATION station);
273 
274  std::map<unsigned int, unsigned int> _detid_view;
275  */
276 
277  PatternDB* _pattern_db;
278 
279  std::map< std::string, PHTimer* > _timers;
280 
282  bool _ana_mode;
283  TFile *_fana;
284  TNtuple *_tana_Event;
285  TNtuple *_tana_St1;
286  TNtuple *_tana_St2;
287  TNtuple *_tana_St3;
288  TNtuple *_tana_St23;
289  TNtuple *_tana_St123;
290 
291 
292  int _event;
293 };
294 
295 #endif /*_KalmanDSTrk_H*/
#define nPropPlanes
Definition: GlobalConsts.h:8
#define nChamberPlanes
Definition: GlobalConsts.h:6
#define nHodoPlanes
Definition: GlobalConsts.h:7
#define nStations
Definition: GlobalConsts.h:5
#define NULL
Definition: Pdb.h:9
User interface class about the geometry of detector planes.
Definition: GeomSvc.h:164
Pattern Dictionary Filter built based on Kun Liu's ktracker.
Definition: KalmanDSTrk.h:41
void printTimers()
void chi2fit(int n, double x[], double y[], double &a, double &b)
const std::string & get_pattern_db_name() const
Definition: KalmanDSTrk.h:132
void buildBackPartialTracks()
void resolveSingleLeftRight(Tracklet &tracklet)
int Verbosity() const
Definition: KalmanDSTrk.h:60
std::list< Tracklet > & getTrackletList(int i)
Definition: KalmanDSTrk.h:124
KalmanDSTrk(const PHField *field, const TGeoManager *geom, bool enable_KF=true, int DS_level=KalmanDSTrk::NO_DS, const std::string sim_db_name="", const std::string pattern_db_name="")
Definition: KalmanDSTrk.cxx:36
std::list< Tracklet > & getFinalTracklets()
Final output.
Definition: KalmanDSTrk.h:122
void removeBadHits(Tracklet &tracklet)
bool acceptEvent(SRawEvent *rawEvent)
void printAtDetectorBack(int stationID, std::string outputFileName)
bool muonID_hodoAid(Tracklet &tracklet)
bool muonID_comp(Tracklet &tracklet)
int setRawEventWorker(SRawEvent *event_input)
void set_sim_db_name(const std::string &simDbName)
Definition: KalmanDSTrk.h:144
int setRawEvent(SRawEvent *event_input)
void resolveLeftRight(SRawEvent::hit_pair hpair, int &LR1, int &LR2)
bool fitTrack(KalmanTrack &kmtrk)
std::list< Tracklet > & getBackPartials()
Definition: KalmanDSTrk.h:123
void set_pattern_db_name(const std::string &patternDbName)
Definition: KalmanDSTrk.h:136
int fitTracklet(Tracklet &tracklet)
void setRawEventDebug(SRawEvent *event_input)
void getSagittaWindowsInSt1(Tracklet &tracklet, double *pos_exp, double *window, int st1ID)
std::list< PropSegment > & getPropSegments(int i)
Definition: KalmanDSTrk.h:126
void buildTrackletsInStation(int stationID, int listID, double *pos_exp=NULL, double *window=NULL)
Tracklet finding stuff.
bool acceptTracklet(Tracklet &tracklet)
void buildPropSegments()
void Verbosity(const int a)
Definition: KalmanDSTrk.h:59
void getExtrapoWindowsInSt1(Tracklet &tracklet, double *pos_exp, double *window, int st1ID)
SRecTrack processOneTracklet(Tracklet &tracklet)
Track fitting stuff.
bool hodoMask(Tracklet &tracklet)
bool muonID_search(Tracklet &tracklet)
void buildGlobalTracks()
const std::string & get_sim_db_name() const
Definition: KalmanDSTrk.h:140
std::list< SRecTrack > & getSRecTracks()
Definition: KalmanDSTrk.h:125
int reduceTrackletList(std::list< Tracklet > &tracklets)
transient DST object for field storage and access
Definition: PHField.h:14
high precision timer
Definition: PHTimer.h:25
PatternDB interface objects.
Definition: PatternDB.h:117
std::pair< Int_t, Int_t > hit_pair
Type of pair with two adjacent wires.
Definition: SRawEvent.h:169