forked from sPHENIX-Collaboration/coresoftware
/
PHGenFitTrkProp.h
680 lines (534 loc) · 17.3 KB
/
PHGenFitTrkProp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
/*!
* \file PHGenFitTrkProp.h
* \brief Progressive pattern recgnition based on GenFit Kalman filter
* \detail using Alan Dion's HelixHough for seeding, GenFit Kalman filter to do track propagation
* \author Christof Roland & Haiwang Yu
*/
#ifndef TRACKRECO_PHGENFITTRKPROP_H
#define TRACKRECO_PHGENFITTRKPROP_H
#include "PHTrackPropagating.h"
#include <trackbase_historic/SvtxTrackMap.h>
#include <trackbase/TrkrDefs.h> // for cluskey
#include <Eigen/Core> // for Matrix
// needed, it crashes on Ubuntu using singularity with local cvmfs install
// shared pointer later on uses this, forward declaration does not cut it
#include <phgenfit/Track.h>
#include <gsl/gsl_rng.h>
// standard includes
#include <array>
#include <list>
#include <map>
#include <memory>
#include <ostream> // for basic_ostream::operator<<
#include <string> // for string
#include <utility> // for pair
#include <vector>
// forward declarations
class BbcVertexMap;
class PHCompositeNode;
class PHG4CylinderGeomContainer;
class PHTimer;
class SvtxTrack;
class TrkrCluster;
class TFile;
class TNtuple;
namespace PHGenFit
{
class Fitter;
class Measurement;
} /* namespace PHGenFit */
///
/// \class PHGenFitTrkProp
/// \brief Propagate tracklet to full track using GenFit
///
class PHGenFitTrkProp : public PHTrackPropagating
{
public:
PHGenFitTrkProp(
const std::string& name = "PHGenFitTrkProp",
unsigned int nlayers_maps = 3,
unsigned int nlayers_intt = 8,
unsigned int nlayers_tpc = 60,
unsigned int nlayers_micromegas = 0);
protected:
int Setup(PHCompositeNode* topNode) override;
int Process() override;
int End() override;
private:
/// fetch node pointers
int GetNodes(PHCompositeNode* topNode);
std::shared_ptr<PHGenFit::Track> ReFitTrack(SvtxTrack* intrack);
public:
// int Init(PHCompositeNode *topNode);
// int InitRun(PHCompositeNode *topNode);
// int process_event(PHCompositeNode *topNode);
// int End(PHCompositeNode *topNode);
struct TrackQuality
{
int nhits = 0;
float chi2 = 0;
int ndf = 0;
int nmicromegas = 0;
int ntpc = 0;
int nintt = 0;
int nmaps = 0;
TrackQuality(int nhits_, float chi2_, int ndf_)
: nhits(nhits_)
, chi2(chi2_)
, ndf(ndf_)
{
}
TrackQuality(int nhits_, float chi2_, int ndf_, int nmicromegas_, int ntpc_, int nintt_, int nmaps_)
: nhits(nhits_)
, chi2(chi2_)
, ndf(ndf_)
, nmicromegas(nmicromegas_)
, ntpc(ntpc_)
, nintt(nintt_)
, nmaps(nmaps_)
{
}
bool operator<(const TrackQuality& b) const
{
if (nhits != b.nhits)
return nhits > b.nhits;
else
return chi2 / ndf < b.chi2 / b.ndf;
}
friend std::ostream& operator<<(std::ostream& os, const PHGenFitTrkProp::TrackQuality& tq)
{
os
<< tq.nhits << ", "
<< tq.chi2 << ", " << tq.ndf << ", "
<< tq.nmicromegas << ", " << tq.ntpc << ", " << tq.nintt << ", " << tq.nmaps
<< std::endl;
return os;
}
};
typedef std::list<std::pair<TrackQuality, std::shared_ptr<PHGenFit::Track> > > MapPHGenFitTrack;
float get_search_win_phi() const
{
return _search_win_phi;
}
void set_search_win_phi(float searchWinMultiplier)
{
_search_win_phi = searchWinMultiplier;
}
bool is_do_evt_display() const
{
return _do_evt_display;
}
void set_do_evt_display(bool doEvtDisplay)
{
_do_evt_display = doEvtDisplay;
}
const std::string& get_track_fitting_alg_name() const
{
return _track_fitting_alg_name;
}
void set_track_fitting_alg_name(const std::string& trackFittingAlgName)
{
_track_fitting_alg_name = trackFittingAlgName;
}
void set_analyzing_mode(bool analyzingMode)
{
_analyzing_mode = analyzingMode;
}
float get_max_merging_deta() const
{
return _max_merging_deta;
}
void set_max_merging_deta(float maxMergingDeta)
{
_max_merging_deta = maxMergingDeta;
}
float get_max_merging_dphi() const
{
return _max_merging_dphi;
}
void set_max_merging_dphi(float maxMergingDphi)
{
_max_merging_dphi = maxMergingDphi;
}
float get_max_merging_dr() const
{
return _max_merging_dr;
}
void set_max_merging_dr(float maxMergingDr)
{
_max_merging_dr = maxMergingDr;
}
float get_max_merging_dz() const
{
return _max_merging_dz;
}
void set_max_merging_dz(float maxMergingDz)
{
_max_merging_dz = maxMergingDz;
}
float get_search_win_theta() const
{
return _search_win_theta;
}
void set_search_win_theta(float searchWinZ)
{
_search_win_theta = searchWinZ;
}
float get_max_incr_chi2() const
{
return _max_incr_chi2;
}
void set_max_incr_chi2(float maxIncrChi2)
{
_max_incr_chi2 = maxIncrChi2;
}
unsigned int get_max_consecutive_missing_layer() const
{
return _max_consecutive_missing_layer;
}
void set_max_consecutive_missing_layer(
unsigned int maxConsecutiveMissingLayer)
{
_max_consecutive_missing_layer = maxConsecutiveMissingLayer;
}
unsigned int get_min_good_track_hits() const
{
return _min_good_track_hits;
}
void set_min_good_track_hits(unsigned int minGoodTrackHits)
{
_min_good_track_hits = minGoodTrackHits;
}
unsigned int get_max_share_hits() const
{
return _max_share_hits;
}
void set_max_share_hits(unsigned int maxShareHits)
{
_max_share_hits = maxShareHits;
}
float get_max_splitting_chi2() const
{
return _max_splitting_chi2;
}
void set_max_splitting_chi2(float maxSplittingChi2)
{
_max_splitting_chi2 = maxSplittingChi2;
}
int get_init_direction() const
{
return _init_direction;
}
void set_init_direction(int initDirection)
{
_init_direction = initDirection;
}
float get_max_search_win_phi_tpc() const
{
return _max_search_win_phi_tpc;
}
void set_max_search_win_phi_tpc(float maxSearchWinPhi)
{
_max_search_win_phi_tpc = maxSearchWinPhi;
}
float get_max_search_win_theta_tpc() const
{
return _max_search_win_theta_tpc;
}
void set_max_search_win_theta_tpc(float maxSearchWinZ)
{
_max_search_win_theta_tpc = maxSearchWinZ;
}
float get_max_search_win_phi_micromegas(int layer) const
{
return _max_search_win_phi_micromegas[layer];
}
void set_max_search_win_phi_micromegas(int layer, float maxSearchWinPhi)
{
_max_search_win_phi_micromegas[layer] = maxSearchWinPhi;
}
float get_max_search_win_theta_micromegas(int layer) const
{
return _max_search_win_theta_micromegas[layer];
}
void set_max_search_win_theta_micromegas(int layer, float maxSearchWinZ)
{
_max_search_win_theta_micromegas[layer] = maxSearchWinZ;
}
float get_blowup_factor() const
{
return _blowup_factor;
}
void set_blowup_factor(float blowupFactor)
{
_blowup_factor = blowupFactor;
}
float get_max_search_win_phi_intt(int inttlayer) const
{
return _max_search_win_phi_intt[inttlayer];
}
void set_max_search_win_phi_intt(int inttlayer, float maxSearchWinPhiIntt)
{
_max_search_win_phi_intt[inttlayer] = maxSearchWinPhiIntt;
}
float get_max_search_win_phi_maps() const
{
return _max_search_win_phi_maps;
}
void set_max_search_win_phi_maps(float maxSearchWinPhiMaps)
{
_max_search_win_phi_maps = maxSearchWinPhiMaps;
}
float get_max_search_win_theta_intt(int inttlayer) const
{
return _max_search_win_theta_intt[inttlayer];
}
void set_max_search_win_theta_intt(int inttlayer, float maxSearchWinThetaIntt)
{
_max_search_win_theta_intt[inttlayer] = maxSearchWinThetaIntt;
}
float get_max_search_win_theta_maps() const
{
return _max_search_win_theta_maps;
}
void set_max_search_win_theta_maps(float maxSearchWinThetaMaps)
{
_max_search_win_theta_maps = maxSearchWinThetaMaps;
}
float get_min_search_win_phi_intt(int inttlayer) const
{
return _min_search_win_phi_intt[inttlayer];
}
void set_min_search_win_phi_intt(int inttlayer, float minSearchWinPhiIntt)
{
_min_search_win_phi_intt[inttlayer] = minSearchWinPhiIntt;
}
float get_min_search_win_phi_maps() const
{
return _min_search_win_phi_maps;
}
void set_min_search_win_phi_maps(float minSearchWinPhiMaps)
{
_min_search_win_phi_maps = minSearchWinPhiMaps;
}
float get_min_search_win_phi_tpc() const
{
return _min_search_win_phi_tpc;
}
void set_min_search_win_phi_tpc(float minSearchWinPhiTpc)
{
_min_search_win_phi_tpc = minSearchWinPhiTpc;
}
float get_min_search_win_phi_micromegas(int layer) const
{
return _min_search_win_phi_micromegas[layer];
}
void set_min_search_win_phi_micromegas(int layer, float minSearchWinPhimicromegas)
{
_min_search_win_phi_micromegas[layer] = minSearchWinPhimicromegas;
}
float get_min_search_win_theta_intt(int inttlayer) const
{
return _min_search_win_theta_intt[inttlayer];
}
void set_min_search_win_theta_intt(int inttlayer, float minSearchWinThetaIntt)
{
_min_search_win_theta_intt[inttlayer] = minSearchWinThetaIntt;
}
float get_min_search_win_theta_maps() const
{
return _min_search_win_theta_maps;
}
void set_min_search_win_theta_maps(float minSearchWinThetaMaps)
{
_min_search_win_theta_maps = minSearchWinThetaMaps;
}
float get_min_search_win_theta_tpc() const
{
return _min_search_win_theta_tpc;
}
void set_min_search_win_theta_tpc(float minSearchWinThetaTpc)
{
_min_search_win_theta_tpc = minSearchWinThetaTpc;
}
float get_min_search_win_theta_micromegas(int layer) const
{
return _min_search_win_theta_micromegas[layer];
}
void set_min_search_win_theta_micromegas(int layer, float minSearchWinThetamicromegas)
{
_min_search_win_theta_micromegas[layer] = minSearchWinThetamicromegas;
}
int get_primary_pid_guess() const
{
return _primary_pid_guess;
}
void set_primary_pid_guess(int primaryPidGuess)
{
_primary_pid_guess = primaryPidGuess;
}
void set_beam_constraint(bool beamConstraint)
{
_use_beam = beamConstraint;
}
private:
//*@name utility methods
//@{
inline bool is_maps_layer( unsigned int layer ) const
{ return layer >= _firstlayer_maps && layer < _firstlayer_maps + _nlayers_maps; }
inline bool is_intt_layer( unsigned int layer ) const
{ return layer >= _firstlayer_intt && layer < _firstlayer_intt + _nlayers_intt; }
inline bool is_tpc_layer( unsigned int layer ) const
{ return layer >= _firstlayer_tpc && layer < _firstlayer_tpc + _nlayers_tpc; }
inline bool is_micromegas_layer( unsigned int layer ) const
{ return layer >= _firstlayer_micromegas && layer < _firstlayer_micromegas + _nlayers_micromegas; }
//@}
//--------------
// InitRun Calls
//--------------
/// Init projection r
int InitializeGeometry(PHCompositeNode* topNode);
/// track propagation
int InitializePHGenFit(PHCompositeNode* topNode);
//--------------------
// Process Event Calls
//--------------------
//!
int check_track_exists(MapPHGenFitTrack::iterator, SvtxTrackMap::Iter);
//! Main function
int KalmanTrkProp();
//!
int ExportOutput();
//!
void print_timers();
//--------------------
//
//--------------------
//! KalmanTrkProp Call.
int BuildLayerZPhiHitMap(const unsigned int ivert);
//! layer: 7 bits, z: 11 bits, phi: 14 bits
unsigned int encode_cluster_index(const unsigned int layer, const float z, const float rphi);
unsigned int encode_cluster_index(const unsigned int layer, const unsigned int iz, const unsigned int irphi);
//! KalmanTrkProp Call.
int SvtxTrackToPHGenFitTracks(const SvtxTrack* svtxtrack);
// int TrackPropPatRec(PHCompositeNode* topNode,
// //const int iPHGenFitTrack, std::shared_ptr<PHGenFit::Track> &track,
// MapPHGenFitTrack::iterator &track_iter,
// const unsigned int init_layer = 0, const unsigned int end_layer = 66,
// const bool use_fitted_state_once = false);
int TrackPropPatRec(
const unsigned int ivert,
//const int iPHGenFitTrack, std::shared_ptr<PHGenFit::Track> &track,
MapPHGenFitTrack::iterator& track_iter,
const unsigned int init_layer = 0, const unsigned int end_layer = 66,
const bool use_fitted_state_once = false);
//!
//PHGenFit::Measurement* SvtxClusterToPHGenFitMeasurement(const SvtxCluster* cluster);
PHGenFit::Measurement* TrkrClusterToPHGenFitMeasurement(const TrkrCluster* cluster);
//! TrackPropPatRec Call.
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);
//! ExportOutput Call. Make SvtxTrack from PHGenFit::Track and set of clusters
//std::shared_ptr<SvtxTrack> MakeSvtxTrack(const int genfit_track_ID, const SvtxVertex * vertex = NULL);
int OutputPHGenFitTrack(MapPHGenFitTrack::iterator, SvtxTrackMap::Iter);
//------------------
// Subfunction Calls
//------------------
/// convert from inverse curvature to momentum
float kappaToPt(float kappa);
/// convert from momentum to inverse curvature
float ptToKappa(float pt);
/// convert the covariance from HelixHough coords to x,y,z,px,py,pz
void convertHelixCovarianceToEuclideanCovariance(float B, float phi,
float d, float kappa, float z0, float dzdl,
Eigen::Matrix<float, 5, 5> const& input,
Eigen::Matrix<float, 6, 6>& output);
/// translate the clusters, tracks, and vertex from one origin to another
void shift_coordinate_system(double dx, double dy, double dz);
int _event = 0;
PHTimer* _t_seeds_cleanup = nullptr;
PHTimer* _t_translate_to_PHGenFitTrack = nullptr;
PHTimer* _t_translate1 = nullptr;
PHTimer* _t_translate2 = nullptr;
PHTimer* _t_translate3 = nullptr;
PHTimer* _t_kalman_pat_rec = nullptr;
PHTimer* _t_search_clusters = nullptr;
PHTimer* _t_search_clusters_encoding = nullptr;
PHTimer* _t_search_clusters_map_iter = nullptr;
PHTimer* _t_track_propagation = nullptr;
PHTimer* _t_full_fitting = nullptr;
PHTimer* _t_output_io = nullptr;
// object storage
std::vector<std::vector<float>> _vertex; ///< working array for collision vertex list
std::vector<std::vector<float>> _vertex_error; ///< sqrt(cov)
// node pointers
BbcVertexMap* _bbc_vertexes = nullptr;
std::multimap<TrkrDefs::cluskey, unsigned int> _gftrk_hitkey_map;
PHG4CylinderGeomContainer* _geom_container_intt = nullptr;
PHG4CylinderGeomContainer* _geom_container_maps = nullptr;
bool _analyzing_mode = false;
TFile* _analyzing_file = nullptr;
TNtuple* _analyzing_ntuple = nullptr;
//! Cleanup Seeds
float _max_merging_dphi = 0.1;
float _max_merging_deta = 0.1;
float _max_merging_dr = 0.1;
float _max_merging_dz = 0.1;
//! if two seeds have common hits more than this number, merge them
unsigned int _max_share_hits = 3;
std::unique_ptr<PHGenFit::Fitter> _fitter;
//! KalmanFitterRefTrack, KalmanFitter, DafSimple, DafRef
std::string _track_fitting_alg_name = "DafRef";
int _primary_pid_guess = 211;
double _cut_min_pT = 0.2;
bool _do_evt_display = false;
unsigned int _nlayers_maps = 3;
unsigned int _nlayers_intt = 4;
unsigned int _nlayers_tpc = 48;
unsigned int _nlayers_micromegas = 0;
int _nlayers_all = 55;
unsigned int _firstlayer_maps = 0;
unsigned int _firstlayer_intt = 3;
unsigned int _firstlayer_tpc = 7;
unsigned int _firstlayer_micromegas = 55;
std::map<int, unsigned int> _layer_ilayer_map_all;
std::vector<float> _radii_all;
// TODO: might need to use layer dependent windows because micromegas are 1D measurements
std::array<float,2> _max_search_win_phi_micromegas = {{ 0.004, 0.62}};
std::array<float,2> _min_search_win_phi_micromegas = {{ 0, 0.31 }};
std::array<float,2> _max_search_win_theta_micromegas = {{ 1.24, 0.004}};
std::array<float,2> _min_search_win_theta_micromegas = {{ 0.62, 0}};
float _max_search_win_phi_tpc = 0.004;
float _min_search_win_phi_tpc = 0;
float _max_search_win_theta_tpc = 0.004;
float _min_search_win_theta_tpc = 0;
std::array<float,4> _max_search_win_phi_intt = {{ 0.2, 0.2, 0.005, 0.005 }};
std::array<float,4> _min_search_win_phi_intt = {{ 0.2, 0.2, 0, 0 }};
std::array<float,4> _max_search_win_theta_intt = {{ 0.01, 0.01, 0.2, 0.2 }};
std::array<float,4> _min_search_win_theta_intt = {{ 0, 0, 0.2, 0.2 }};
float _max_search_win_phi_maps = 0.005;
float _min_search_win_phi_maps = 0;
float _max_search_win_theta_maps = 0.04;
float _min_search_win_theta_maps = 0;
float _search_win_phi = 20;
float _search_win_theta = 20;
std::map<int, float> _search_wins_phi;
std::map<int, float> _search_wins_theta;
std::vector<std::multimap<unsigned int, TrkrDefs::cluskey>> _layer_thetaID_phiID_clusterID;
float _half_max_theta = M_PI/2;
float _half_max_phi = M_PI;
float _layer_thetaID_phiID_clusterID_phiSize = 0.12/30;
float _layer_thetaID_phiID_clusterID_zSize = 0.17/30;
MapPHGenFitTrack _PHGenFitTracks;
//! +1: inside out; -1: outside in
int _init_direction = -1;
float _blowup_factor = 1;
unsigned int _max_consecutive_missing_layer = 20;
float _max_incr_chi2 = 20;
std::map<int, float> _max_incr_chi2s;
float _max_splitting_chi2 = 20;
unsigned int _min_good_track_hits = 30;
PHCompositeNode* _topNode = nullptr;
int _ntrack = 0;
bool _use_beam;
};
#endif