ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHGenFitTrkProp.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHGenFitTrkProp.h
1 
8 #ifndef TRACKRECO_PHGENFITTRKPROP_H
9 #define TRACKRECO_PHGENFITTRKPROP_H
10 
11 #include "PHTrackPropagating.h"
12 
14 
15 #include <trackbase/TrkrDefs.h> // for cluskey
16 
17 #include <Eigen/Core> // for Matrix
18 // needed, it crashes on Ubuntu using singularity with local cvmfs install
19 // shared pointer later on uses this, forward declaration does not cut it
20 #include <phgenfit/Track.h>
21 #include <gsl/gsl_rng.h>
22 
23 // standard includes
24 #include <array>
25 #include <list>
26 #include <map>
27 #include <memory>
28 #include <ostream> // for basic_ostream::operator<<
29 #include <string> // for string
30 #include <utility> // for pair
31 #include <vector>
32 
33 // forward declarations
34 class BbcVertexMap;
35 class PHCompositeNode;
37 class PHTimer;
38 class SvtxTrack;
39 class TrkrCluster;
40 
41 class TFile;
42 class TNtuple;
43 
44 namespace PHGenFit
45 {
46 class Fitter;
47 class Measurement;
48 } /* namespace PHGenFit */
49 
55 {
56  public:
58  const std::string& name = "PHGenFitTrkProp",
59  unsigned int nlayers_maps = 3,
60  unsigned int nlayers_intt = 8,
61  unsigned int nlayers_tpc = 60,
62  unsigned int nlayers_micromegas = 0);
63 
64  protected:
65  int Setup(PHCompositeNode* topNode) override;
66 
67  int Process() override;
68 
69  int End() override;
70 
71  private:
73  int GetNodes(PHCompositeNode* topNode);
74 
75  std::shared_ptr<PHGenFit::Track> ReFitTrack(SvtxTrack* intrack);
76 
77  public:
78  // int Init(PHCompositeNode *topNode);
79  // int InitRun(PHCompositeNode *topNode);
80  // int process_event(PHCompositeNode *topNode);
81  // int End(PHCompositeNode *topNode);
82 
83  struct TrackQuality
84  {
85  int nhits = 0;
86  float chi2 = 0;
87  int ndf = 0;
88  int nmicromegas = 0;
89  int ntpc = 0;
90  int nintt = 0;
91  int nmaps = 0;
92 
93  TrackQuality(int nhits_, float chi2_, int ndf_)
94  : nhits(nhits_)
95  , chi2(chi2_)
96  , ndf(ndf_)
97  {
98  }
99 
100  TrackQuality(int nhits_, float chi2_, int ndf_, int nmicromegas_, int ntpc_, int nintt_, int nmaps_)
101  : nhits(nhits_)
102  , chi2(chi2_)
103  , ndf(ndf_)
104  , nmicromegas(nmicromegas_)
105  , ntpc(ntpc_)
106  , nintt(nintt_)
107  , nmaps(nmaps_)
108  {
109  }
110 
111  bool operator<(const TrackQuality& b) const
112  {
113  if (nhits != b.nhits)
114  return nhits > b.nhits;
115  else
116  return chi2 / ndf < b.chi2 / b.ndf;
117  }
118 
119  friend std::ostream& operator<<(std::ostream& os, const PHGenFitTrkProp::TrackQuality& tq)
120  {
121  os
122  << tq.nhits << ", "
123  << tq.chi2 << ", " << tq.ndf << ", "
124  << tq.nmicromegas << ", " << tq.ntpc << ", " << tq.nintt << ", " << tq.nmaps
125  << std::endl;
126 
127  return os;
128  }
129  };
130 
131  typedef std::list<std::pair<TrackQuality, std::shared_ptr<PHGenFit::Track> > > MapPHGenFitTrack;
132 
133  float get_search_win_phi() const
134  {
135  return _search_win_phi;
136  }
137 
138  void set_search_win_phi(float searchWinMultiplier)
139  {
140  _search_win_phi = searchWinMultiplier;
141  }
142 
143  bool is_do_evt_display() const
144  {
145  return _do_evt_display;
146  }
147 
148  void set_do_evt_display(bool doEvtDisplay)
149  {
150  _do_evt_display = doEvtDisplay;
151  }
152 
153  const std::string& get_track_fitting_alg_name() const
154  {
156  }
157 
158  void set_track_fitting_alg_name(const std::string& trackFittingAlgName)
159  {
160  _track_fitting_alg_name = trackFittingAlgName;
161  }
162 
163  void set_analyzing_mode(bool analyzingMode)
164  {
165  _analyzing_mode = analyzingMode;
166  }
167 
168  float get_max_merging_deta() const
169  {
170  return _max_merging_deta;
171  }
172 
173  void set_max_merging_deta(float maxMergingDeta)
174  {
175  _max_merging_deta = maxMergingDeta;
176  }
177 
178  float get_max_merging_dphi() const
179  {
180  return _max_merging_dphi;
181  }
182 
183  void set_max_merging_dphi(float maxMergingDphi)
184  {
185  _max_merging_dphi = maxMergingDphi;
186  }
187 
188  float get_max_merging_dr() const
189  {
190  return _max_merging_dr;
191  }
192 
193  void set_max_merging_dr(float maxMergingDr)
194  {
195  _max_merging_dr = maxMergingDr;
196  }
197 
198  float get_max_merging_dz() const
199  {
200  return _max_merging_dz;
201  }
202 
203  void set_max_merging_dz(float maxMergingDz)
204  {
205  _max_merging_dz = maxMergingDz;
206  }
207 
208  float get_search_win_theta() const
209  {
210  return _search_win_theta;
211  }
212 
213  void set_search_win_theta(float searchWinZ)
214  {
215  _search_win_theta = searchWinZ;
216  }
217 
218  float get_max_incr_chi2() const
219  {
220  return _max_incr_chi2;
221  }
222 
223  void set_max_incr_chi2(float maxIncrChi2)
224  {
225  _max_incr_chi2 = maxIncrChi2;
226  }
227 
229  {
231  }
232 
234  unsigned int maxConsecutiveMissingLayer)
235  {
236  _max_consecutive_missing_layer = maxConsecutiveMissingLayer;
237  }
238 
239  unsigned int get_min_good_track_hits() const
240  {
241  return _min_good_track_hits;
242  }
243 
244  void set_min_good_track_hits(unsigned int minGoodTrackHits)
245  {
246  _min_good_track_hits = minGoodTrackHits;
247  }
248 
249  unsigned int get_max_share_hits() const
250  {
251  return _max_share_hits;
252  }
253 
254  void set_max_share_hits(unsigned int maxShareHits)
255  {
256  _max_share_hits = maxShareHits;
257  }
258 
260  {
261  return _max_splitting_chi2;
262  }
263 
264  void set_max_splitting_chi2(float maxSplittingChi2)
265  {
266  _max_splitting_chi2 = maxSplittingChi2;
267  }
268 
269  int get_init_direction() const
270  {
271  return _init_direction;
272  }
273 
274  void set_init_direction(int initDirection)
275  {
276  _init_direction = initDirection;
277  }
278 
280  {
282  }
283 
284  void set_max_search_win_phi_tpc(float maxSearchWinPhi)
285  {
286  _max_search_win_phi_tpc = maxSearchWinPhi;
287  }
288 
290  {
292  }
293 
294  void set_max_search_win_theta_tpc(float maxSearchWinZ)
295  {
296  _max_search_win_theta_tpc = maxSearchWinZ;
297  }
299  {
301  }
302 
303  void set_max_search_win_phi_micromegas(int layer, float maxSearchWinPhi)
304  {
305  _max_search_win_phi_micromegas[layer] = maxSearchWinPhi;
306  }
307 
309  {
311  }
312 
313  void set_max_search_win_theta_micromegas(int layer, float maxSearchWinZ)
314  {
315  _max_search_win_theta_micromegas[layer] = maxSearchWinZ;
316  }
317 
318  float get_blowup_factor() const
319  {
320  return _blowup_factor;
321  }
322 
323  void set_blowup_factor(float blowupFactor)
324  {
325  _blowup_factor = blowupFactor;
326  }
327 
328  float get_max_search_win_phi_intt(int inttlayer) const
329  {
330  return _max_search_win_phi_intt[inttlayer];
331  }
332 
333  void set_max_search_win_phi_intt(int inttlayer, float maxSearchWinPhiIntt)
334  {
335  _max_search_win_phi_intt[inttlayer] = maxSearchWinPhiIntt;
336  }
337 
339  {
341  }
342 
343  void set_max_search_win_phi_maps(float maxSearchWinPhiMaps)
344  {
345  _max_search_win_phi_maps = maxSearchWinPhiMaps;
346  }
347 
348  float get_max_search_win_theta_intt(int inttlayer) const
349  {
350  return _max_search_win_theta_intt[inttlayer];
351  }
352 
353  void set_max_search_win_theta_intt(int inttlayer, float maxSearchWinThetaIntt)
354  {
355  _max_search_win_theta_intt[inttlayer] = maxSearchWinThetaIntt;
356  }
357 
359  {
361  }
362 
363  void set_max_search_win_theta_maps(float maxSearchWinThetaMaps)
364  {
365  _max_search_win_theta_maps = maxSearchWinThetaMaps;
366  }
367 
368  float get_min_search_win_phi_intt(int inttlayer) const
369  {
370  return _min_search_win_phi_intt[inttlayer];
371  }
372 
373  void set_min_search_win_phi_intt(int inttlayer, float minSearchWinPhiIntt)
374  {
375  _min_search_win_phi_intt[inttlayer] = minSearchWinPhiIntt;
376  }
377 
379  {
381  }
382 
383  void set_min_search_win_phi_maps(float minSearchWinPhiMaps)
384  {
385  _min_search_win_phi_maps = minSearchWinPhiMaps;
386  }
387 
389  {
391  }
392 
393  void set_min_search_win_phi_tpc(float minSearchWinPhiTpc)
394  {
395  _min_search_win_phi_tpc = minSearchWinPhiTpc;
396  }
397 
399  {
401  }
402 
403  void set_min_search_win_phi_micromegas(int layer, float minSearchWinPhimicromegas)
404  {
405  _min_search_win_phi_micromegas[layer] = minSearchWinPhimicromegas;
406  }
407 
408  float get_min_search_win_theta_intt(int inttlayer) const
409  {
410  return _min_search_win_theta_intt[inttlayer];
411  }
412 
413  void set_min_search_win_theta_intt(int inttlayer, float minSearchWinThetaIntt)
414  {
415  _min_search_win_theta_intt[inttlayer] = minSearchWinThetaIntt;
416  }
417 
419  {
421  }
422 
423  void set_min_search_win_theta_maps(float minSearchWinThetaMaps)
424  {
425  _min_search_win_theta_maps = minSearchWinThetaMaps;
426  }
427 
429  {
431  }
432 
433  void set_min_search_win_theta_tpc(float minSearchWinThetaTpc)
434  {
435  _min_search_win_theta_tpc = minSearchWinThetaTpc;
436  }
437 
439  {
441  }
442 
443  void set_min_search_win_theta_micromegas(int layer, float minSearchWinThetamicromegas)
444  {
445  _min_search_win_theta_micromegas[layer] = minSearchWinThetamicromegas;
446  }
447 
449  {
450  return _primary_pid_guess;
451  }
452 
453  void set_primary_pid_guess(int primaryPidGuess)
454  {
455  _primary_pid_guess = primaryPidGuess;
456  }
457 
458  void set_beam_constraint(bool beamConstraint)
459  {
460  _use_beam = beamConstraint;
461  }
462 
463  private:
464 
465  //*@name utility methods
467  inline bool is_maps_layer( unsigned int layer ) const
468  { return layer >= _firstlayer_maps && layer < _firstlayer_maps + _nlayers_maps; }
469 
470  inline bool is_intt_layer( unsigned int layer ) const
471  { return layer >= _firstlayer_intt && layer < _firstlayer_intt + _nlayers_intt; }
472 
473  inline bool is_tpc_layer( unsigned int layer ) const
474  { return layer >= _firstlayer_tpc && layer < _firstlayer_tpc + _nlayers_tpc; }
475 
476  inline bool is_micromegas_layer( unsigned int layer ) const
477  { return layer >= _firstlayer_micromegas && layer < _firstlayer_micromegas + _nlayers_micromegas; }
479 
480  //--------------
481  // InitRun Calls
482  //--------------
483 
485  int InitializeGeometry(PHCompositeNode* topNode);
486 
488  int InitializePHGenFit(PHCompositeNode* topNode);
489 
490  //--------------------
491  // Process Event Calls
492  //--------------------
493 
495  int check_track_exists(MapPHGenFitTrack::iterator, SvtxTrackMap::Iter);
496 
498  int KalmanTrkProp();
499 
501  int ExportOutput();
502 
504  void print_timers();
505 
506  //--------------------
507  //
508  //--------------------
509 
511  int BuildLayerZPhiHitMap(const unsigned int ivert);
512 
514  unsigned int encode_cluster_index(const unsigned int layer, const float z, const float rphi);
515 
516  unsigned int encode_cluster_index(const unsigned int layer, const unsigned int iz, const unsigned int irphi);
517 
519  int SvtxTrackToPHGenFitTracks(const SvtxTrack* svtxtrack);
520 
521  // int TrackPropPatRec(PHCompositeNode* topNode,
522  // //const int iPHGenFitTrack, std::shared_ptr<PHGenFit::Track> &track,
523  // MapPHGenFitTrack::iterator &track_iter,
524  // const unsigned int init_layer = 0, const unsigned int end_layer = 66,
525  // const bool use_fitted_state_once = false);
526  int TrackPropPatRec(
527  const unsigned int ivert,
528  //const int iPHGenFitTrack, std::shared_ptr<PHGenFit::Track> &track,
529  MapPHGenFitTrack::iterator& track_iter,
530  const unsigned int init_layer = 0, const unsigned int end_layer = 66,
531  const bool use_fitted_state_once = false);
532 
534  //PHGenFit::Measurement* SvtxClusterToPHGenFitMeasurement(const SvtxCluster* cluster);
536 
538  std::vector<TrkrDefs::cluskey> SearchHitsNearBy(const unsigned int ivert, const unsigned int layer, const float z_center, const float phi_center, const float z_window, const float phi_window);
539 
541  //std::shared_ptr<SvtxTrack> MakeSvtxTrack(const int genfit_track_ID, const SvtxVertex * vertex = NULL);
542  int OutputPHGenFitTrack(MapPHGenFitTrack::iterator, SvtxTrackMap::Iter);
543 
544  //------------------
545  // Subfunction Calls
546  //------------------
547 
549  float kappaToPt(float kappa);
550 
552  float ptToKappa(float pt);
553 
556  float d, float kappa, float z0, float dzdl,
557  Eigen::Matrix<float, 5, 5> const& input,
558  Eigen::Matrix<float, 6, 6>& output);
559 
561  void shift_coordinate_system(double dx, double dy, double dz);
562 
563  int _event = 0;
566  PHTimer* _t_translate1 = nullptr;
567  PHTimer* _t_translate2 = nullptr;
568  PHTimer* _t_translate3 = nullptr;
575  PHTimer* _t_output_io = nullptr;
576 
577  // object storage
578 
579  std::vector<std::vector<float>> _vertex;
580  std::vector<std::vector<float>> _vertex_error;
581 
582  // node pointers
584 
585  std::multimap<TrkrDefs::cluskey, unsigned int> _gftrk_hitkey_map;
586 
589 
590  bool _analyzing_mode = false;
591  TFile* _analyzing_file = nullptr;
592  TNtuple* _analyzing_ntuple = nullptr;
593 
595  float _max_merging_dphi = 0.1;
596  float _max_merging_deta = 0.1;
597  float _max_merging_dr = 0.1;
598  float _max_merging_dz = 0.1;
599 
601  unsigned int _max_share_hits = 3;
602 
603  std::unique_ptr<PHGenFit::Fitter> _fitter;
604 
606  std::string _track_fitting_alg_name = "DafRef";
607 
609  double _cut_min_pT = 0.2;
610 
611  bool _do_evt_display = false;
612 
613  unsigned int _nlayers_maps = 3;
614  unsigned int _nlayers_intt = 4;
615  unsigned int _nlayers_tpc = 48;
616  unsigned int _nlayers_micromegas = 0;
617 
618  int _nlayers_all = 55;
619 
620  unsigned int _firstlayer_maps = 0;
621  unsigned int _firstlayer_intt = 3;
622  unsigned int _firstlayer_tpc = 7;
623  unsigned int _firstlayer_micromegas = 55;
624 
625  std::map<int, unsigned int> _layer_ilayer_map_all;
626  std::vector<float> _radii_all;
627 
628  // TODO: might need to use layer dependent windows because micromegas are 1D measurements
629  std::array<float,2> _max_search_win_phi_micromegas = {{ 0.004, 0.62}};
630  std::array<float,2> _min_search_win_phi_micromegas = {{ 0, 0.31 }};
631  std::array<float,2> _max_search_win_theta_micromegas = {{ 1.24, 0.004}};
632  std::array<float,2> _min_search_win_theta_micromegas = {{ 0.62, 0}};
633 
634  float _max_search_win_phi_tpc = 0.004;
638 
639  std::array<float,4> _max_search_win_phi_intt = {{ 0.2, 0.2, 0.005, 0.005 }};
640  std::array<float,4> _min_search_win_phi_intt = {{ 0.2, 0.2, 0, 0 }};
641  std::array<float,4> _max_search_win_theta_intt = {{ 0.01, 0.01, 0.2, 0.2 }};
642  std::array<float,4> _min_search_win_theta_intt = {{ 0, 0, 0.2, 0.2 }};
643 
648 
649  float _search_win_phi = 20;
650  float _search_win_theta = 20;
651  std::map<int, float> _search_wins_phi;
652  std::map<int, float> _search_wins_theta;
653 
654  std::vector<std::multimap<unsigned int, TrkrDefs::cluskey>> _layer_thetaID_phiID_clusterID;
655 
660 
663  int _init_direction = -1;
664  float _blowup_factor = 1;
665 
667  float _max_incr_chi2 = 20;
668  std::map<int, float> _max_incr_chi2s;
669 
671 
672  unsigned int _min_good_track_hits = 30;
673 
675  int _ntrack = 0;
676  bool _use_beam;
677 
678 };
679 
680 #endif