-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathTrackExtenderWithMTD.cc
1611 lines (1397 loc) · 70.5 KB
/
TrackExtenderWithMTD.cc
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
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/stream/EDProducer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "RecoMTD/DetLayers/interface/MTDDetLayerGeometry.h"
#include "RecoMTD/Records/interface/MTDRecoGeometryRecord.h"
#include "MagneticField/Engine/interface/MagneticField.h"
#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
#include "TrackingTools/KalmanUpdators/interface/Chi2MeasurementEstimator.h"
#include "DataFormats/TrackerRecHit2D/interface/MTDTrackingRecHit.h"
#include "RecoMTD/DetLayers/interface/MTDTrayBarrelLayer.h"
#include "TrackingTools/DetLayers/interface/ForwardDetLayer.h"
#include "DataFormats/ForwardDetId/interface/BTLDetId.h"
#include "DataFormats/ForwardDetId/interface/ETLDetId.h"
#include "DataFormats/ForwardDetId/interface/MTDChannelIdentifier.h"
#include "Geometry/CommonTopologies/interface/PixelTopology.h"
#include "DataFormats/GeometryVector/interface/GlobalPoint.h"
#include "TrackingTools/PatternTools/interface/Trajectory.h"
#include "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"
#include "TrackingTools/TransientTrack/interface/TransientTrack.h"
#include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h"
#include "TrackingTools/Records/interface/TransientTrackRecord.h"
#include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHit.h"
#include "RecoMTD/TransientTrackingRecHit/interface/MTDTransientTrackingRecHitBuilder.h"
#include "TrackingTools/Records/interface/TransientRecHitRecord.h"
#include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
#include "TrackingTools/GeomPropagators/interface/Propagator.h"
#include "TrackingTools/PatternTools/interface/TSCBLBuilderWithPropagator.h"
#include "RecoTracker/TransientTrackingRecHit/interface/Traj2TrackHits.h"
#include "TrackingTools/TrackRefitter/interface/TrackTransformer.h"
#include <sstream>
#include "Geometry/CommonTopologies/interface/Topology.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "DataFormats/Math/interface/GeantUnits.h"
#include "DataFormats/Math/interface/LorentzVector.h"
#include "CLHEP/Units/GlobalPhysicalConstants.h"
#include "DataFormats/Math/interface/Rounding.h"
#include "DataFormats/VertexReco/interface/VertexFwd.h"
#include "DataFormats/VertexReco/interface/Vertex.h"
using namespace std;
using namespace edm;
using namespace reco;
namespace {
constexpr float c_cm_ns = geant_units::operators::convertMmToCm(CLHEP::c_light); // [mm/ns] -> [cm/ns]
constexpr float c_inv = 1.0f / c_cm_ns;
class MTDHitMatchingInfo {
public:
MTDHitMatchingInfo() {
hit = nullptr;
estChi2 = std::numeric_limits<float>::max();
timeChi2 = std::numeric_limits<float>::max();
}
//Operator used to sort the hits while performing the matching step at the MTD
inline bool operator<(const MTDHitMatchingInfo& m2) const {
//only for good matching in time use estChi2, otherwise use mostly time compatibility
constexpr float chi2_cut = 10.f;
constexpr float low_weight = 3.f;
constexpr float high_weight = 8.f;
if (timeChi2 < chi2_cut && m2.timeChi2 < chi2_cut)
return chi2(low_weight) < m2.chi2(low_weight);
else
return chi2(high_weight) < m2.chi2(high_weight);
}
inline float chi2(float timeWeight = 1.f) const { return estChi2 + timeWeight * timeChi2; }
const MTDTrackingRecHit* hit;
float estChi2;
float timeChi2;
};
class TrackSegments {
public:
TrackSegments() {
sigmaTofs_.reserve(30); // observed upper limit on nSegments
};
inline uint32_t addSegment(float tPath, float tMom2, float sigmaMom) {
segmentPathOvc_.emplace_back(tPath * c_inv);
segmentMom2_.emplace_back(tMom2);
segmentSigmaMom_.emplace_back(sigmaMom);
nSegment_++;
LogTrace("TrackExtenderWithMTD") << "addSegment # " << nSegment_ << " s = " << tPath
<< " p = " << std::sqrt(tMom2) << " sigma_p = " << sigmaMom
<< " sigma_p/p = " << sigmaMom / std::sqrt(tMom2) * 100 << " %";
return nSegment_;
}
inline float computeTof(float mass_inv2) const {
float tof(0.f);
for (uint32_t iSeg = 0; iSeg < nSegment_; iSeg++) {
float gammasq = 1.f + segmentMom2_[iSeg] * mass_inv2;
float beta = std::sqrt(1.f - 1.f / gammasq);
tof += segmentPathOvc_[iSeg] / beta;
LogTrace("TrackExtenderWithMTD") << " TOF Segment # " << iSeg + 1 << " p = " << std::sqrt(segmentMom2_[iSeg])
<< " tof = " << tof;
#ifdef EDM_ML_DEBUG
float sigma_tof = segmentPathOvc_[iSeg] * segmentSigmaMom_[iSeg] /
(segmentMom2_[iSeg] * sqrt(segmentMom2_[iSeg] + 1 / mass_inv2) * mass_inv2);
LogTrace("TrackExtenderWithMTD") << "TOF Segment # " << iSeg + 1 << std::fixed << std::setw(6)
<< " tof segment = " << segmentPathOvc_[iSeg] / beta << std::scientific
<< "+/- " << sigma_tof << std::fixed
<< "(rel. err. = " << sigma_tof / (segmentPathOvc_[iSeg] / beta) * 100
<< " %)";
#endif
}
return tof;
}
inline float computeSigmaTof(float mass_inv2) {
float sigmatof = 0.;
// remove previously calculated sigmaTofs
sigmaTofs_.clear();
// compute sigma(tof) on each segment first by propagating sigma(p)
// also add diagonal terms to sigmatof
float sigma = 0.;
for (uint32_t iSeg = 0; iSeg < nSegment_; iSeg++) {
sigma = segmentPathOvc_[iSeg] * segmentSigmaMom_[iSeg] /
(segmentMom2_[iSeg] * sqrt(segmentMom2_[iSeg] + 1 / mass_inv2) * mass_inv2);
sigmaTofs_.push_back(sigma);
sigmatof += sigma * sigma;
}
// compute sigma on sum of tofs assuming full correlation between segments
for (uint32_t iSeg = 0; iSeg < nSegment_; iSeg++) {
for (uint32_t jSeg = iSeg + 1; jSeg < nSegment_; jSeg++) {
sigmatof += 2 * sigmaTofs_[iSeg] * sigmaTofs_[jSeg];
}
}
return sqrt(sigmatof);
}
inline uint32_t size() const { return nSegment_; }
inline uint32_t removeFirstSegment() {
if (nSegment_ > 0) {
segmentPathOvc_.erase(segmentPathOvc_.begin());
segmentMom2_.erase(segmentMom2_.begin());
nSegment_--;
}
return nSegment_;
}
inline std::pair<float, float> getSegmentPathAndMom2(uint32_t iSegment) const {
if (iSegment >= nSegment_) {
throw cms::Exception("TrackExtenderWithMTD") << "Requesting non existing track segment #" << iSegment;
}
return std::make_pair(segmentPathOvc_[iSegment], segmentMom2_[iSegment]);
}
uint32_t nSegment_ = 0;
std::vector<float> segmentPathOvc_;
std::vector<float> segmentMom2_;
std::vector<float> segmentSigmaMom_;
std::vector<float> sigmaTofs_;
};
struct TrackTofPidInfo {
float tmtd;
float tmtderror;
float pathlength;
float betaerror;
float dt;
float dterror;
float dterror2;
float dtchi2;
float dt_best;
float dterror_best;
float dtchi2_best;
float gammasq_pi;
float beta_pi;
float dt_pi;
float sigma_dt_pi;
float gammasq_k;
float beta_k;
float dt_k;
float sigma_dt_k;
float gammasq_p;
float beta_p;
float dt_p;
float sigma_dt_p;
float prob_pi;
float prob_k;
float prob_p;
};
enum class TofCalc { kCost = 1, kSegm = 2, kMixd = 3 };
enum class SigmaTofCalc { kCost = 1, kSegm = 2, kMixd = 3 };
const TrackTofPidInfo computeTrackTofPidInfo(float magp2,
float length,
TrackSegments trs,
float t_mtd,
float t_mtderr,
float t_vtx,
float t_vtx_err,
bool addPIDError = true,
TofCalc choice = TofCalc::kCost,
SigmaTofCalc sigma_choice = SigmaTofCalc::kCost) {
constexpr float m_pi = 0.13957018f;
constexpr float m_pi_inv2 = 1.0f / m_pi / m_pi;
constexpr float m_k = 0.493677f;
constexpr float m_k_inv2 = 1.0f / m_k / m_k;
constexpr float m_p = 0.9382720813f;
constexpr float m_p_inv2 = 1.0f / m_p / m_p;
TrackTofPidInfo tofpid;
tofpid.tmtd = t_mtd;
tofpid.tmtderror = t_mtderr;
tofpid.pathlength = length;
auto deltat = [&](const float mass_inv2, const float betatmp) {
float res(1.f);
switch (choice) {
case TofCalc::kCost:
res = tofpid.pathlength / betatmp * c_inv;
break;
case TofCalc::kSegm:
res = trs.computeTof(mass_inv2);
break;
case TofCalc::kMixd:
res = trs.computeTof(mass_inv2) + tofpid.pathlength / betatmp * c_inv;
break;
}
return res;
};
auto sigmadeltat = [&](const float mass_inv2) {
float res(1.f);
switch (sigma_choice) {
case SigmaTofCalc::kCost:
// sigma(t) = sigma(p) * |dt/dp| = sigma(p) * DeltaL/c * m^2 / (p^2 * E)
res = tofpid.pathlength * c_inv * trs.segmentSigmaMom_[trs.nSegment_ - 1] /
(magp2 * sqrt(magp2 + 1 / mass_inv2) * mass_inv2);
break;
case SigmaTofCalc::kSegm:
res = trs.computeSigmaTof(mass_inv2);
break;
case SigmaTofCalc::kMixd:
float res1 = tofpid.pathlength * c_inv * trs.segmentSigmaMom_[trs.nSegment_ - 1] /
(magp2 * sqrt(magp2 + 1 / mass_inv2) * mass_inv2);
float res2 = trs.computeSigmaTof(mass_inv2);
res = sqrt(res1 * res1 + res2 * res2 + 2 * res1 * res2);
}
return res;
};
tofpid.gammasq_pi = 1.f + magp2 * m_pi_inv2;
tofpid.beta_pi = std::sqrt(1.f - 1.f / tofpid.gammasq_pi);
tofpid.dt_pi = deltat(m_pi_inv2, tofpid.beta_pi);
tofpid.sigma_dt_pi = sigmadeltat(m_pi_inv2);
tofpid.gammasq_k = 1.f + magp2 * m_k_inv2;
tofpid.beta_k = std::sqrt(1.f - 1.f / tofpid.gammasq_k);
tofpid.dt_k = deltat(m_k_inv2, tofpid.beta_k);
tofpid.sigma_dt_k = sigmadeltat(m_k_inv2);
tofpid.gammasq_p = 1.f + magp2 * m_p_inv2;
tofpid.beta_p = std::sqrt(1.f - 1.f / tofpid.gammasq_p);
tofpid.dt_p = deltat(m_p_inv2, tofpid.beta_p);
tofpid.sigma_dt_p = sigmadeltat(m_p_inv2);
tofpid.dt = tofpid.tmtd - tofpid.dt_pi - t_vtx; //assume by default the pi hypothesis
tofpid.dterror2 = tofpid.tmtderror * tofpid.tmtderror + t_vtx_err * t_vtx_err;
tofpid.betaerror = 0.f;
if (addPIDError) {
tofpid.dterror2 = tofpid.dterror2 + (tofpid.dt_p - tofpid.dt_pi) * (tofpid.dt_p - tofpid.dt_pi);
tofpid.betaerror = tofpid.beta_p - tofpid.beta_pi;
} else {
// only add sigma(TOF) if not considering mass hp. uncertainty
tofpid.dterror2 = tofpid.dterror2 + tofpid.sigma_dt_pi * tofpid.sigma_dt_pi;
}
tofpid.dterror = sqrt(tofpid.dterror2);
tofpid.dtchi2 = (tofpid.dt * tofpid.dt) / tofpid.dterror2;
tofpid.dt_best = tofpid.dt;
tofpid.dterror_best = tofpid.dterror;
tofpid.dtchi2_best = tofpid.dtchi2;
tofpid.prob_pi = -1.f;
tofpid.prob_k = -1.f;
tofpid.prob_p = -1.f;
if (!addPIDError) {
//*TODO* deal with heavier nucleons and/or BSM case here?
const float dterror2_wo_sigmatof = tofpid.dterror2 - tofpid.sigma_dt_pi * tofpid.sigma_dt_pi;
float chi2_pi = tofpid.dtchi2;
float chi2_k = (tofpid.tmtd - tofpid.dt_k - t_vtx) * (tofpid.tmtd - tofpid.dt_k - t_vtx) /
(dterror2_wo_sigmatof + tofpid.sigma_dt_k * tofpid.sigma_dt_k);
float chi2_p = (tofpid.tmtd - tofpid.dt_p - t_vtx) * (tofpid.tmtd - tofpid.dt_p - t_vtx) /
(dterror2_wo_sigmatof + tofpid.sigma_dt_p * tofpid.sigma_dt_p);
float rawprob_pi = exp(-0.5f * chi2_pi);
float rawprob_k = exp(-0.5f * chi2_k);
float rawprob_p = exp(-0.5f * chi2_p);
float normprob = 1.f / (rawprob_pi + rawprob_k + rawprob_p);
tofpid.prob_pi = rawprob_pi * normprob;
tofpid.prob_k = rawprob_k * normprob;
tofpid.prob_p = rawprob_p * normprob;
float prob_heavy = 1.f - tofpid.prob_pi;
constexpr float heavy_threshold = 0.75f;
if (prob_heavy > heavy_threshold) {
if (chi2_k < chi2_p) {
tofpid.dt_best = (tofpid.tmtd - tofpid.dt_k - t_vtx);
tofpid.dtchi2_best = chi2_k;
} else {
tofpid.dt_best = (tofpid.tmtd - tofpid.dt_p - t_vtx);
tofpid.dtchi2_best = chi2_p;
}
}
}
return tofpid;
}
bool getTrajectoryStateClosestToBeamLine(const Trajectory& traj,
const reco::BeamSpot& bs,
const Propagator* thePropagator,
TrajectoryStateClosestToBeamLine& tscbl) {
// get the state closest to the beamline
TrajectoryStateOnSurface stateForProjectionToBeamLineOnSurface =
traj.closestMeasurement(GlobalPoint(bs.x0(), bs.y0(), bs.z0())).updatedState();
if (!stateForProjectionToBeamLineOnSurface.isValid()) {
edm::LogError("CannotPropagateToBeamLine") << "the state on the closest measurement isnot valid. skipping track.";
return false;
}
const FreeTrajectoryState& stateForProjectionToBeamLine = *stateForProjectionToBeamLineOnSurface.freeState();
TSCBLBuilderWithPropagator tscblBuilder(*thePropagator);
tscbl = tscblBuilder(stateForProjectionToBeamLine, bs);
return tscbl.isValid();
}
bool trackPathLength(const Trajectory& traj,
const TrajectoryStateClosestToBeamLine& tscbl,
const Propagator* thePropagator,
float& pathlength,
TrackSegments& trs) {
pathlength = 0.f;
bool validpropagation = true;
float oldp = traj.measurements().begin()->updatedState().globalMomentum().mag();
float pathlength1 = 0.f;
float pathlength2 = 0.f;
//add pathlength layer by layer
for (auto it = traj.measurements().begin(); it != traj.measurements().end() - 1; ++it) {
const auto& propresult = thePropagator->propagateWithPath(it->updatedState(), (it + 1)->updatedState().surface());
float layerpathlength = std::abs(propresult.second);
if (layerpathlength == 0.f) {
validpropagation = false;
}
pathlength1 += layerpathlength;
// sigma(p) from curvilinear error (on q/p)
float sigma_p = sqrt((it + 1)->updatedState().curvilinearError().matrix()(0, 0)) *
(it + 1)->updatedState().globalMomentum().mag2();
trs.addSegment(layerpathlength, (it + 1)->updatedState().globalMomentum().mag2(), sigma_p);
LogTrace("TrackExtenderWithMTD") << "TSOS " << std::fixed << std::setw(4) << trs.size() << " R_i " << std::fixed
<< std::setw(14) << it->updatedState().globalPosition().perp() << " z_i "
<< std::fixed << std::setw(14) << it->updatedState().globalPosition().z()
<< " R_e " << std::fixed << std::setw(14)
<< (it + 1)->updatedState().globalPosition().perp() << " z_e " << std::fixed
<< std::setw(14) << (it + 1)->updatedState().globalPosition().z() << " p "
<< std::fixed << std::setw(14) << (it + 1)->updatedState().globalMomentum().mag()
<< " dp " << std::fixed << std::setw(14)
<< (it + 1)->updatedState().globalMomentum().mag() - oldp;
oldp = (it + 1)->updatedState().globalMomentum().mag();
}
//add distance from bs to first measurement
auto const& tscblPCA = tscbl.trackStateAtPCA();
auto const& aSurface = traj.direction() == alongMomentum ? traj.firstMeasurement().updatedState().surface()
: traj.lastMeasurement().updatedState().surface();
pathlength2 = thePropagator->propagateWithPath(tscblPCA, aSurface).second;
if (pathlength2 == 0.f) {
validpropagation = false;
}
pathlength = pathlength1 + pathlength2;
float sigma_p = sqrt(tscblPCA.curvilinearError().matrix()(0, 0)) * tscblPCA.momentum().mag2();
trs.addSegment(pathlength2, tscblPCA.momentum().mag2(), sigma_p);
LogTrace("TrackExtenderWithMTD") << "TSOS " << std::fixed << std::setw(4) << trs.size() << " R_e " << std::fixed
<< std::setw(14) << tscblPCA.position().perp() << " z_e " << std::fixed
<< std::setw(14) << tscblPCA.position().z() << " p " << std::fixed << std::setw(14)
<< tscblPCA.momentum().mag() << " dp " << std::fixed << std::setw(14)
<< tscblPCA.momentum().mag() - oldp << " sigma_p = " << std::fixed << std::setw(14)
<< sigma_p << " sigma_p/p = " << std::fixed << std::setw(14)
<< sigma_p / tscblPCA.momentum().mag() * 100 << " %";
return validpropagation;
}
bool trackPathLength(const Trajectory& traj,
const reco::BeamSpot& bs,
const Propagator* thePropagator,
float& pathlength,
TrackSegments& trs) {
pathlength = 0.f;
TrajectoryStateClosestToBeamLine tscbl;
bool tscbl_status = getTrajectoryStateClosestToBeamLine(traj, bs, thePropagator, tscbl);
if (!tscbl_status)
return false;
return trackPathLength(traj, tscbl, thePropagator, pathlength, trs);
}
} // namespace
template <class TrackCollection>
class TrackExtenderWithMTDT : public edm::stream::EDProducer<> {
public:
typedef typename TrackCollection::value_type TrackType;
typedef edm::View<TrackType> InputCollection;
TrackExtenderWithMTDT(const ParameterSet& pset);
template <class H, class T>
void fillValueMap(edm::Event& iEvent, const H& handle, const std::vector<T>& vec, const edm::EDPutToken& token) const;
void produce(edm::Event& ev, const edm::EventSetup& es) final;
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
TransientTrackingRecHit::ConstRecHitContainer tryBTLLayers(const TrajectoryStateOnSurface&,
const Trajectory& traj,
const float,
const float,
const TrackSegments&,
const MTDTrackingDetSetVector&,
const MTDDetLayerGeometry*,
const MagneticField* field,
const Propagator* prop,
const reco::BeamSpot& bs,
const float vtxTime,
const bool matchVertex,
MTDHitMatchingInfo& bestHit) const;
TransientTrackingRecHit::ConstRecHitContainer tryETLLayers(const TrajectoryStateOnSurface&,
const Trajectory& traj,
const float,
const float,
const TrackSegments&,
const MTDTrackingDetSetVector&,
const MTDDetLayerGeometry*,
const MagneticField* field,
const Propagator* prop,
const reco::BeamSpot& bs,
const float vtxTime,
const bool matchVertex,
MTDHitMatchingInfo& bestHit) const;
void fillMatchingHits(const DetLayer*,
const TrajectoryStateOnSurface&,
const Trajectory&,
const float,
const float,
const TrackSegments&,
const MTDTrackingDetSetVector&,
const Propagator*,
const reco::BeamSpot&,
const float&,
const bool,
TransientTrackingRecHit::ConstRecHitContainer&,
MTDHitMatchingInfo&) const;
RefitDirection::GeometricalDirection checkRecHitsOrdering(
TransientTrackingRecHit::ConstRecHitContainer const& recHits) const {
if (!recHits.empty()) {
GlobalPoint first = gtg_->idToDet(recHits.front()->geographicalId())->position();
GlobalPoint last = gtg_->idToDet(recHits.back()->geographicalId())->position();
// maybe perp2?
auto rFirst = first.mag2();
auto rLast = last.mag2();
if (rFirst < rLast)
return RefitDirection::insideOut;
if (rFirst > rLast)
return RefitDirection::outsideIn;
}
LogDebug("TrackExtenderWithMTD") << "Impossible to determine the rechits order" << endl;
return RefitDirection::undetermined;
}
reco::Track buildTrack(const reco::TrackRef&,
const Trajectory&,
const Trajectory&,
const reco::BeamSpot&,
const MagneticField* field,
const Propagator* prop,
bool hasMTD,
float& pathLength,
float& tmtdOut,
float& sigmatmtdOut,
GlobalPoint& tmtdPosOut,
float& tofpi,
float& tofk,
float& tofp,
float& sigmatofpi,
float& sigmatofk,
float& sigmatofp) const;
reco::TrackExtra buildTrackExtra(const Trajectory& trajectory) const;
string dumpLayer(const DetLayer* layer) const;
private:
edm::EDPutToken btlMatchChi2Token_;
edm::EDPutToken etlMatchChi2Token_;
edm::EDPutToken btlMatchTimeChi2Token_;
edm::EDPutToken etlMatchTimeChi2Token_;
edm::EDPutToken npixBarrelToken_;
edm::EDPutToken npixEndcapToken_;
edm::EDPutToken outermostHitPositionToken_;
edm::EDPutToken pOrigTrkToken_;
edm::EDPutToken betaOrigTrkToken_;
edm::EDPutToken t0OrigTrkToken_;
edm::EDPutToken sigmat0OrigTrkToken_;
edm::EDPutToken pathLengthOrigTrkToken_;
edm::EDPutToken tmtdOrigTrkToken_;
edm::EDPutToken sigmatmtdOrigTrkToken_;
edm::EDPutToken tmtdPosOrigTrkToken_;
edm::EDPutToken tofpiOrigTrkToken_;
edm::EDPutToken tofkOrigTrkToken_;
edm::EDPutToken tofpOrigTrkToken_;
edm::EDPutToken sigmatofpiOrigTrkToken_;
edm::EDPutToken sigmatofkOrigTrkToken_;
edm::EDPutToken sigmatofpOrigTrkToken_;
edm::EDPutToken assocOrigTrkToken_;
edm::EDGetTokenT<InputCollection> tracksToken_;
edm::EDGetTokenT<TrajTrackAssociationCollection> trajTrackAToken_;
edm::EDGetTokenT<MTDTrackingDetSetVector> hitsToken_;
edm::EDGetTokenT<reco::BeamSpot> bsToken_;
edm::EDGetTokenT<GlobalPoint> genVtxPositionToken_;
edm::EDGetTokenT<float> genVtxTimeToken_;
edm::EDGetTokenT<VertexCollection> vtxToken_;
const bool updateTraj_, updateExtra_, updatePattern_;
const std::string mtdRecHitBuilder_, propagator_, transientTrackBuilder_;
std::unique_ptr<MeasurementEstimator> theEstimator;
std::unique_ptr<TrackTransformer> theTransformer;
edm::ESHandle<TransientTrackBuilder> builder_;
edm::ESGetToken<TransientTrackBuilder, TransientTrackRecord> builderToken_;
edm::ESHandle<TransientTrackingRecHitBuilder> hitbuilder_;
edm::ESGetToken<TransientTrackingRecHitBuilder, TransientRecHitRecord> hitbuilderToken_;
edm::ESHandle<GlobalTrackingGeometry> gtg_;
edm::ESGetToken<GlobalTrackingGeometry, GlobalTrackingGeometryRecord> gtgToken_;
edm::ESGetToken<MTDDetLayerGeometry, MTDRecoGeometryRecord> dlgeoToken_;
edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> magfldToken_;
edm::ESGetToken<Propagator, TrackingComponentsRecord> propToken_;
edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> ttopoToken_;
const float estMaxChi2_;
const float estMaxNSigma_;
const float btlChi2Cut_;
const float btlTimeChi2Cut_;
const float etlChi2Cut_;
const float etlTimeChi2Cut_;
const bool useVertex_;
const bool useSimVertex_;
const float dzCut_;
const float bsTimeSpread_;
static constexpr float trackMaxBtlEta_ = 1.5;
};
template <class TrackCollection>
TrackExtenderWithMTDT<TrackCollection>::TrackExtenderWithMTDT(const ParameterSet& iConfig)
: tracksToken_(consumes<InputCollection>(iConfig.getParameter<edm::InputTag>("tracksSrc"))),
trajTrackAToken_(consumes<TrajTrackAssociationCollection>(iConfig.getParameter<edm::InputTag>("trjtrkAssSrc"))),
hitsToken_(consumes<MTDTrackingDetSetVector>(iConfig.getParameter<edm::InputTag>("hitsSrc"))),
bsToken_(consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamSpotSrc"))),
updateTraj_(iConfig.getParameter<bool>("updateTrackTrajectory")),
updateExtra_(iConfig.getParameter<bool>("updateTrackExtra")),
updatePattern_(iConfig.getParameter<bool>("updateTrackHitPattern")),
mtdRecHitBuilder_(iConfig.getParameter<std::string>("MTDRecHitBuilder")),
propagator_(iConfig.getParameter<std::string>("Propagator")),
transientTrackBuilder_(iConfig.getParameter<std::string>("TransientTrackBuilder")),
estMaxChi2_(iConfig.getParameter<double>("estimatorMaxChi2")),
estMaxNSigma_(iConfig.getParameter<double>("estimatorMaxNSigma")),
btlChi2Cut_(iConfig.getParameter<double>("btlChi2Cut")),
btlTimeChi2Cut_(iConfig.getParameter<double>("btlTimeChi2Cut")),
etlChi2Cut_(iConfig.getParameter<double>("etlChi2Cut")),
etlTimeChi2Cut_(iConfig.getParameter<double>("etlTimeChi2Cut")),
useVertex_(iConfig.getParameter<bool>("useVertex")),
useSimVertex_(iConfig.getParameter<bool>("useSimVertex")),
dzCut_(iConfig.getParameter<double>("dZCut")),
bsTimeSpread_(iConfig.getParameter<double>("bsTimeSpread")) {
if (useVertex_) {
if (useSimVertex_) {
genVtxPositionToken_ = consumes<GlobalPoint>(iConfig.getParameter<edm::InputTag>("genVtxPositionSrc"));
genVtxTimeToken_ = consumes<float>(iConfig.getParameter<edm::InputTag>("genVtxTimeSrc"));
} else
vtxToken_ = consumes<VertexCollection>(iConfig.getParameter<edm::InputTag>("vtxSrc"));
}
theEstimator = std::make_unique<Chi2MeasurementEstimator>(estMaxChi2_, estMaxNSigma_);
theTransformer = std::make_unique<TrackTransformer>(iConfig.getParameterSet("TrackTransformer"), consumesCollector());
btlMatchChi2Token_ = produces<edm::ValueMap<float>>("btlMatchChi2");
etlMatchChi2Token_ = produces<edm::ValueMap<float>>("etlMatchChi2");
btlMatchTimeChi2Token_ = produces<edm::ValueMap<float>>("btlMatchTimeChi2");
etlMatchTimeChi2Token_ = produces<edm::ValueMap<float>>("etlMatchTimeChi2");
npixBarrelToken_ = produces<edm::ValueMap<int>>("npixBarrel");
npixEndcapToken_ = produces<edm::ValueMap<int>>("npixEndcap");
outermostHitPositionToken_ = produces<edm::ValueMap<float>>("generalTrackOutermostHitPosition");
pOrigTrkToken_ = produces<edm::ValueMap<float>>("generalTrackp");
betaOrigTrkToken_ = produces<edm::ValueMap<float>>("generalTrackBeta");
t0OrigTrkToken_ = produces<edm::ValueMap<float>>("generalTrackt0");
sigmat0OrigTrkToken_ = produces<edm::ValueMap<float>>("generalTracksigmat0");
pathLengthOrigTrkToken_ = produces<edm::ValueMap<float>>("generalTrackPathLength");
tmtdOrigTrkToken_ = produces<edm::ValueMap<float>>("generalTracktmtd");
sigmatmtdOrigTrkToken_ = produces<edm::ValueMap<float>>("generalTracksigmatmtd");
tmtdPosOrigTrkToken_ = produces<edm::ValueMap<GlobalPoint>>("generalTrackmtdpos");
tofpiOrigTrkToken_ = produces<edm::ValueMap<float>>("generalTrackTofPi");
tofkOrigTrkToken_ = produces<edm::ValueMap<float>>("generalTrackTofK");
tofpOrigTrkToken_ = produces<edm::ValueMap<float>>("generalTrackTofP");
sigmatofpiOrigTrkToken_ = produces<edm::ValueMap<float>>("generalTrackSigmaTofPi");
sigmatofkOrigTrkToken_ = produces<edm::ValueMap<float>>("generalTrackSigmaTofK");
sigmatofpOrigTrkToken_ = produces<edm::ValueMap<float>>("generalTrackSigmaTofP");
assocOrigTrkToken_ = produces<edm::ValueMap<int>>("generalTrackassoc");
builderToken_ = esConsumes<TransientTrackBuilder, TransientTrackRecord>(edm::ESInputTag("", transientTrackBuilder_));
hitbuilderToken_ =
esConsumes<TransientTrackingRecHitBuilder, TransientRecHitRecord>(edm::ESInputTag("", mtdRecHitBuilder_));
gtgToken_ = esConsumes<GlobalTrackingGeometry, GlobalTrackingGeometryRecord>();
dlgeoToken_ = esConsumes<MTDDetLayerGeometry, MTDRecoGeometryRecord>();
magfldToken_ = esConsumes<MagneticField, IdealMagneticFieldRecord>();
propToken_ = esConsumes<Propagator, TrackingComponentsRecord>(edm::ESInputTag("", propagator_));
ttopoToken_ = esConsumes<TrackerTopology, TrackerTopologyRcd>();
produces<edm::OwnVector<TrackingRecHit>>();
produces<reco::TrackExtraCollection>();
produces<TrackCollection>();
}
template <class TrackCollection>
void TrackExtenderWithMTDT<TrackCollection>::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc, transDesc;
desc.add<edm::InputTag>("tracksSrc", edm::InputTag("generalTracks"));
desc.add<edm::InputTag>("trjtrkAssSrc", edm::InputTag("generalTracks"));
desc.add<edm::InputTag>("hitsSrc", edm::InputTag("mtdTrackingRecHits"));
desc.add<edm::InputTag>("beamSpotSrc", edm::InputTag("offlineBeamSpot"));
desc.add<edm::InputTag>("genVtxPositionSrc", edm::InputTag("genParticles:xyz0"));
desc.add<edm::InputTag>("genVtxTimeSrc", edm::InputTag("genParticles:t0"));
desc.add<edm::InputTag>("vtxSrc", edm::InputTag("offlinePrimaryVertices4D"));
desc.add<bool>("updateTrackTrajectory", true);
desc.add<bool>("updateTrackExtra", true);
desc.add<bool>("updateTrackHitPattern", true);
desc.add<std::string>("TransientTrackBuilder", "TransientTrackBuilder");
desc.add<std::string>("MTDRecHitBuilder", "MTDRecHitBuilder");
desc.add<std::string>("Propagator", "PropagatorWithMaterialForMTD");
TrackTransformer::fillPSetDescription(transDesc,
false,
"KFFitterForRefitInsideOut",
"KFSmootherForRefitInsideOut",
"PropagatorWithMaterialForMTD",
"alongMomentum",
true,
"WithTrackAngle",
"MuonRecHitBuilder",
"MTDRecHitBuilder");
desc.add<edm::ParameterSetDescription>("TrackTransformer", transDesc);
desc.add<double>("estimatorMaxChi2", 500.);
desc.add<double>("estimatorMaxNSigma", 10.);
desc.add<double>("btlChi2Cut", 50.);
desc.add<double>("btlTimeChi2Cut", 10.);
desc.add<double>("etlChi2Cut", 50.);
desc.add<double>("etlTimeChi2Cut", 10.);
desc.add<bool>("useVertex", false);
desc.add<bool>("useSimVertex", false);
desc.add<double>("dZCut", 0.1);
desc.add<double>("bsTimeSpread", 0.2);
descriptions.add("trackExtenderWithMTDBase", desc);
}
template <class TrackCollection>
template <class H, class T>
void TrackExtenderWithMTDT<TrackCollection>::fillValueMap(edm::Event& iEvent,
const H& handle,
const std::vector<T>& vec,
const edm::EDPutToken& token) const {
auto out = std::make_unique<edm::ValueMap<T>>();
typename edm::ValueMap<T>::Filler filler(*out);
filler.insert(handle, vec.begin(), vec.end());
filler.fill();
iEvent.put(token, std::move(out));
}
template <class TrackCollection>
void TrackExtenderWithMTDT<TrackCollection>::produce(edm::Event& ev, const edm::EventSetup& es) {
//this produces pieces of the track extra
Traj2TrackHits t2t;
theTransformer->setServices(es);
TrackingRecHitRefProd hitsRefProd = ev.getRefBeforePut<TrackingRecHitCollection>();
reco::TrackExtraRefProd extrasRefProd = ev.getRefBeforePut<reco::TrackExtraCollection>();
gtg_ = es.getHandle(gtgToken_);
auto geo = es.getTransientHandle(dlgeoToken_);
auto magfield = es.getTransientHandle(magfldToken_);
builder_ = es.getHandle(builderToken_);
hitbuilder_ = es.getHandle(hitbuilderToken_);
auto propH = es.getTransientHandle(propToken_);
const Propagator* prop = propH.product();
auto httopo = es.getTransientHandle(ttopoToken_);
const TrackerTopology& ttopo = *httopo;
auto output = std::make_unique<TrackCollection>();
auto extras = std::make_unique<reco::TrackExtraCollection>();
auto outhits = std::make_unique<edm::OwnVector<TrackingRecHit>>();
std::vector<float> btlMatchChi2;
std::vector<float> etlMatchChi2;
std::vector<float> btlMatchTimeChi2;
std::vector<float> etlMatchTimeChi2;
std::vector<int> npixBarrel;
std::vector<int> npixEndcap;
std::vector<float> outermostHitPosition;
std::vector<float> pOrigTrkRaw;
std::vector<float> betaOrigTrkRaw;
std::vector<float> t0OrigTrkRaw;
std::vector<float> sigmat0OrigTrkRaw;
std::vector<float> pathLengthsOrigTrkRaw;
std::vector<float> tmtdOrigTrkRaw;
std::vector<float> sigmatmtdOrigTrkRaw;
std::vector<GlobalPoint> tmtdPosOrigTrkRaw;
std::vector<float> tofpiOrigTrkRaw;
std::vector<float> tofkOrigTrkRaw;
std::vector<float> tofpOrigTrkRaw;
std::vector<float> sigmatofpiOrigTrkRaw;
std::vector<float> sigmatofkOrigTrkRaw;
std::vector<float> sigmatofpOrigTrkRaw;
std::vector<int> assocOrigTrkRaw;
auto const tracksH = ev.getHandle(tracksToken_);
const auto& trjtrks = ev.get(trajTrackAToken_);
//MTD hits DetSet
const auto& hits = ev.get(hitsToken_);
//beam spot
const auto& bs = ev.get(bsToken_);
const Vertex* pv = nullptr;
if (useVertex_ && !useSimVertex_) {
auto const& vtxs = ev.get(vtxToken_);
if (!vtxs.empty())
pv = &vtxs[0];
}
std::unique_ptr<math::XYZTLorentzVectorF> genPV(nullptr);
if (useVertex_ && useSimVertex_) {
const auto& genVtxPosition = ev.get(genVtxPositionToken_);
const auto& genVtxTime = ev.get(genVtxTimeToken_);
genPV = std::make_unique<math::XYZTLorentzVectorF>(
genVtxPosition.x(), genVtxPosition.y(), genVtxPosition.z(), genVtxTime);
}
float vtxTime = 0.f;
if (useVertex_) {
if (useSimVertex_ && genPV) {
vtxTime = genPV->t();
} else if (pv)
vtxTime = pv->t(); //already in ns
}
std::vector<unsigned> track_indices;
unsigned itrack = 0;
for (const auto& trjtrk : trjtrks) {
const Trajectory& trajs = *trjtrk.key;
const reco::TrackRef& track = trjtrk.val;
LogTrace("TrackExtenderWithMTD") << "TrackExtenderWithMTD: extrapolating track " << itrack
<< " p/pT = " << track->p() << " " << track->pt() << " eta = " << track->eta();
LogTrace("TrackExtenderWithMTD") << "TrackExtenderWithMTD: sigma_p = "
<< sqrt(track->covariance()(0, 0)) * track->p2()
<< " sigma_p/p = " << sqrt(track->covariance()(0, 0)) * track->p() * 100 << " %";
float trackVtxTime = 0.f;
if (useVertex_) {
float dz;
if (useSimVertex_)
dz = std::abs(track->dz(math::XYZPoint(*genPV)));
else
dz = std::abs(track->dz(pv->position()));
if (dz < dzCut_)
trackVtxTime = vtxTime;
}
reco::TransientTrack ttrack(track, magfield.product(), gtg_);
auto thits = theTransformer->getTransientRecHits(ttrack);
TransientTrackingRecHit::ConstRecHitContainer mtdthits;
MTDHitMatchingInfo mBTL, mETL;
if (trajs.isValid()) {
// get the outermost trajectory point on the track
TrajectoryStateOnSurface tsos = builder_->build(track).outermostMeasurementState();
TrajectoryStateClosestToBeamLine tscbl;
bool tscbl_status = getTrajectoryStateClosestToBeamLine(trajs, bs, prop, tscbl);
if (tscbl_status) {
float pmag2 = tscbl.trackStateAtPCA().momentum().mag2();
float pathlength0;
TrackSegments trs0;
trackPathLength(trajs, tscbl, prop, pathlength0, trs0);
const auto& btlhits = tryBTLLayers(tsos,
trajs,
pmag2,
pathlength0,
trs0,
hits,
geo.product(),
magfield.product(),
prop,
bs,
trackVtxTime,
trackVtxTime != 0.f,
mBTL);
mtdthits.insert(mtdthits.end(), btlhits.begin(), btlhits.end());
// in the future this should include an intermediate refit before propagating to the ETL
// for now it is ok
const auto& etlhits = tryETLLayers(tsos,
trajs,
pmag2,
pathlength0,
trs0,
hits,
geo.product(),
magfield.product(),
prop,
bs,
trackVtxTime,
trackVtxTime != 0.f,
mETL);
mtdthits.insert(mtdthits.end(), etlhits.begin(), etlhits.end());
}
#ifdef EDM_ML_DEBUG
else {
LogTrace("TrackExtenderWithMTD") << "Failing getTrajectoryStateClosestToBeamLine, no search for hits in MTD!";
}
#endif
}
auto ordering = checkRecHitsOrdering(thits);
if (ordering == RefitDirection::insideOut) {
thits.insert(thits.end(), mtdthits.begin(), mtdthits.end());
} else {
std::reverse(mtdthits.begin(), mtdthits.end());
mtdthits.insert(mtdthits.end(), thits.begin(), thits.end());
thits.swap(mtdthits);
}
const auto& trajwithmtd =
mtdthits.empty() ? std::vector<Trajectory>(1, trajs) : theTransformer->transform(ttrack, thits);
float pMap = 0.f, betaMap = 0.f, t0Map = 0.f, sigmat0Map = -1.f, pathLengthMap = -1.f, tmtdMap = 0.f,
sigmatmtdMap = -1.f, tofpiMap = 0.f, tofkMap = 0.f, tofpMap = 0.f, sigmatofpiMap = -1.f, sigmatofkMap = -1.f,
sigmatofpMap = -1.f;
GlobalPoint tmtdPosMap{0., 0., 0.};
int iMap = -1;
for (const auto& trj : trajwithmtd) {
const auto& thetrj = (updateTraj_ ? trj : trajs);
float pathLength = 0.f, tmtd = 0.f, sigmatmtd = -1.f, tofpi = 0.f, tofk = 0.f, tofp = 0.f, sigmatofpi = -1.f,
sigmatofk = -1.f, sigmatofp = -1.f;
GlobalPoint tmtdPos{0., 0., 0.};
LogTrace("TrackExtenderWithMTD") << "TrackExtenderWithMTD: refit track " << itrack << " p/pT = " << track->p()
<< " " << track->pt() << " eta = " << track->eta();
reco::Track result = buildTrack(track,
thetrj,
trj,
bs,
magfield.product(),
prop,
!trajwithmtd.empty() && !mtdthits.empty(),
pathLength,
tmtd,
sigmatmtd,
tmtdPos,
tofpi,
tofk,
tofp,
sigmatofpi,
sigmatofk,
sigmatofp);
if (result.ndof() >= 0) {
/// setup the track extras
reco::TrackExtra::TrajParams trajParams;
reco::TrackExtra::Chi2sFive chi2s;
size_t hitsstart = outhits->size();
if (updatePattern_) {
t2t(trj, *outhits, trajParams, chi2s); // this fills the output hit collection
} else {
t2t(thetrj, *outhits, trajParams, chi2s);
}
size_t hitsend = outhits->size();
extras->push_back(buildTrackExtra(trj)); // always push back the fully built extra, update by setting in track
extras->back().setHits(hitsRefProd, hitsstart, hitsend - hitsstart);
extras->back().setTrajParams(trajParams, chi2s);
//create the track
output->push_back(result);
btlMatchChi2.push_back(mBTL.hit ? mBTL.estChi2 : -1.f);
etlMatchChi2.push_back(mETL.hit ? mETL.estChi2 : -1.f);
btlMatchTimeChi2.push_back(mBTL.hit ? mBTL.timeChi2 : -1.f);
etlMatchTimeChi2.push_back(mETL.hit ? mETL.timeChi2 : -1.f);
pathLengthMap = pathLength;
tmtdMap = tmtd;
sigmatmtdMap = sigmatmtd;
tmtdPosMap = tmtdPos;
auto& backtrack = output->back();
iMap = output->size() - 1;
pMap = backtrack.p();
betaMap = backtrack.beta();
t0Map = backtrack.t0();
sigmat0Map = std::copysign(std::sqrt(std::abs(backtrack.covt0t0())), backtrack.covt0t0());
tofpiMap = tofpi;
tofkMap = tofk;
tofpMap = tofp;
sigmatofpiMap = sigmatofpi;
sigmatofkMap = sigmatofk;
sigmatofpMap = sigmatofp;
reco::TrackExtraRef extraRef(extrasRefProd, extras->size() - 1);
backtrack.setExtra((updateExtra_ ? extraRef : track->extra()));
for (unsigned ihit = hitsstart; ihit < hitsend; ++ihit) {
backtrack.appendHitPattern((*outhits)[ihit], ttopo);
}
#ifdef EDM_ML_DEBUG
LogTrace("TrackExtenderWithMTD") << "TrackExtenderWithMTD: hit pattern of refitted track";
for (int i = 0; i < backtrack.hitPattern().numberOfAllHits(reco::HitPattern::TRACK_HITS); i++) {
backtrack.hitPattern().printHitPattern(reco::HitPattern::TRACK_HITS, i, std::cout);