/
TrackDetectorAssociator.cc
1078 lines (946 loc) · 50.6 KB
/
TrackDetectorAssociator.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
// -*- C++ -*-
//
// Package: TrackAssociator
// Class: TrackDetectorAssociator
//
/*
Description: <one line class summary>
Implementation:
<Notes on implementation>
*/
//
// Original Author: Dmytro Kovalskyi
// Created: Fri Apr 21 10:59:41 PDT 2006
//
//
#include "TrackingTools/TrackAssociator/interface/TrackDetectorAssociator.h"
#include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
#include "TrackingTools/TrackAssociator/interface/DetIdInfo.h"
#include "TrackingTools/Records/interface/DetIdAssociatorRecord.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Utilities/interface/isFinite.h"
#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/DetId/interface/DetId.h"
#include "DataFormats/TrackReco/interface/Track.h"
#include "DataFormats/TrackReco/interface/TrackExtra.h"
#include "DataFormats/CaloTowers/interface/CaloTower.h"
#include "DataFormats/CaloTowers/interface/CaloTowerCollection.h"
#include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
#include "DataFormats/EgammaReco/interface/SuperCluster.h"
#include "DataFormats/DTRecHit/interface/DTRecHitCollection.h"
#include "DataFormats/EcalDetId/interface/EBDetId.h"
#include "DataFormats/DTRecHit/interface/DTRecSegment4DCollection.h"
#include "DataFormats/DTRecHit/interface/DTRecSegment2D.h"
#include "DataFormats/CSCRecHit/interface/CSCSegmentCollection.h"
#include "DataFormats/GEMRecHit/interface/GEMSegmentCollection.h"
#include "DataFormats/GEMRecHit/interface/ME0SegmentCollection.h"
// calorimeter and muon infos
#include "Geometry/CommonDetUnit/interface/GeomDet.h"
#include "Geometry/Records/interface/CaloGeometryRecord.h"
#include "Geometry/Records/interface/MuonGeometryRecord.h"
#include "Geometry/DTGeometry/interface/DTGeometry.h"
#include "Geometry/CSCGeometry/interface/CSCGeometry.h"
#include "Geometry/GEMGeometry/interface/GEMGeometry.h"
#include "Geometry/GEMGeometry/interface/ME0Geometry.h"
#include "Geometry/GEMGeometry/interface/GEMEtaPartitionSpecs.h"
#include "TrackPropagation/SteppingHelixPropagator/interface/SteppingHelixPropagator.h"
#include <stack>
#include <set>
#include "DataFormats/Math/interface/LorentzVector.h"
#include "Math/VectorUtil.h"
#include <algorithm>
#include "SimDataFormats/TrackingHit/interface/PSimHit.h"
#include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
#include "SimDataFormats/Track/interface/SimTrackContainer.h"
#include "SimDataFormats/Vertex/interface/SimVertexContainer.h"
#include "SimDataFormats/CaloHit/interface/PCaloHit.h"
#include "SimDataFormats/CaloHit/interface/PCaloHitContainer.h"
using namespace reco;
TrackDetectorAssociator::TrackDetectorAssociator() {
ivProp_ = nullptr;
useDefaultPropagator_ = false;
}
TrackDetectorAssociator::~TrackDetectorAssociator() = default;
void TrackDetectorAssociator::setPropagator(const Propagator* ptr) {
ivProp_ = ptr;
cachedTrajectory_.setPropagator(ivProp_);
}
void TrackDetectorAssociator::useDefaultPropagator() { useDefaultPropagator_ = true; }
void TrackDetectorAssociator::init(const edm::EventSetup& iSetup, const AssociatorParameters& parameters) {
// access the calorimeter geometry
theCaloGeometry_ = &iSetup.getData(parameters.theCaloGeometryToken);
// get the tracking Geometry
theTrackingGeometry_ = &iSetup.getData(parameters.theTrackingGeometryToken);
if (useDefaultPropagator_ && (!defProp_ || theMagneticFieldWatcher_.check(iSetup))) {
// setup propagator
const MagneticField* bField = &iSetup.getData(parameters.bFieldToken);
auto prop = std::make_unique<SteppingHelixPropagator>(bField, anyDirection);
prop->setMaterialMode(false);
prop->applyRadX0Correction(true);
// prop->setDebug(true); // tmp
defProp_ = std::move(prop);
setPropagator(defProp_.get());
}
ecalDetIdAssociator_ = &iSetup.getData(parameters.ecalDetIdAssociatorToken);
hcalDetIdAssociator_ = &iSetup.getData(parameters.hcalDetIdAssociatorToken);
hoDetIdAssociator_ = &iSetup.getData(parameters.hoDetIdAssociatorToken);
caloDetIdAssociator_ = &iSetup.getData(parameters.caloDetIdAssociatorToken);
muonDetIdAssociator_ = &iSetup.getData(parameters.muonDetIdAssociatorToken);
preshowerDetIdAssociator_ = &iSetup.getData(parameters.preshowerDetIdAssociatorToken);
}
TrackDetMatchInfo TrackDetectorAssociator::associate(const edm::Event& iEvent,
const edm::EventSetup& iSetup,
const FreeTrajectoryState& fts,
const AssociatorParameters& parameters) {
return associate(iEvent, iSetup, parameters, &fts);
}
TrackDetMatchInfo TrackDetectorAssociator::associate(const edm::Event& iEvent,
const edm::EventSetup& iSetup,
const AssociatorParameters& parameters,
const FreeTrajectoryState* innerState,
const FreeTrajectoryState* outerState) {
TrackDetMatchInfo info;
if (!parameters.useEcal && !parameters.useCalo && !parameters.useHcal && !parameters.useHO && !parameters.useMuon &&
!parameters.usePreshower)
throw cms::Exception("ConfigurationError")
<< "Configuration error! No subdetector was selected for the track association.";
SteppingHelixStateInfo trackOrigin(*innerState);
info.stateAtIP = *innerState;
cachedTrajectory_.setStateAtIP(trackOrigin);
init(iSetup, parameters);
// get track trajectory
// ECAL points (EB+EE)
// If the phi angle between a track entrance and exit points is more
// than 2 crystals, it is possible that the track will cross 3 crystals
// and therefore one has to check at least 3 points along the track
// trajectory inside ECAL. In order to have a chance to cross 4 crystalls
// in the barrel, a track should have P_t as low as 3 GeV or smaller
// If it's necessary, number of points along trajectory can be increased
info.setCaloGeometry(theCaloGeometry_);
cachedTrajectory_.reset_trajectory();
// estimate propagation outer boundaries based on
// requested sub-detector information. For now limit
// propagation region only if muon matching is not
// requested.
double HOmaxR = hoDetIdAssociator_->volume().maxR();
double HOmaxZ = hoDetIdAssociator_->volume().maxZ();
double minR = ecalDetIdAssociator_->volume().minR();
double minZ = preshowerDetIdAssociator_->volume().minZ();
cachedTrajectory_.setMaxHORadius(HOmaxR);
cachedTrajectory_.setMaxHOLength(HOmaxZ * 2.);
cachedTrajectory_.setMinDetectorRadius(minR);
cachedTrajectory_.setMinDetectorLength(minZ * 2.);
if (parameters.useMuon) {
double maxR = muonDetIdAssociator_->volume().maxR();
double maxZ = muonDetIdAssociator_->volume().maxZ();
cachedTrajectory_.setMaxDetectorRadius(maxR);
cachedTrajectory_.setMaxDetectorLength(maxZ * 2.);
} else {
cachedTrajectory_.setMaxDetectorRadius(HOmaxR);
cachedTrajectory_.setMaxDetectorLength(HOmaxZ * 2.);
}
// If track extras exist and outerState is before HO maximum, then use outerState
if (outerState) {
if (outerState->position().perp() < HOmaxR && std::abs(outerState->position().z()) < HOmaxZ) {
LogTrace("TrackAssociator") << "Using outerState as trackOrigin at Rho=" << outerState->position().perp()
<< " Z=" << outerState->position().z() << "\n";
trackOrigin = SteppingHelixStateInfo(*outerState);
} else if (innerState) {
LogTrace("TrackAssociator") << "Using innerState as trackOrigin at Rho=" << innerState->position().perp()
<< " Z=" << innerState->position().z() << "\n";
trackOrigin = SteppingHelixStateInfo(*innerState);
}
}
if (trackOrigin.momentum().mag() == 0)
return info;
if (edm::isNotFinite(trackOrigin.momentum().x()) or edm::isNotFinite(trackOrigin.momentum().y()) or
edm::isNotFinite(trackOrigin.momentum().z()))
return info;
if (!cachedTrajectory_.propagateAll(trackOrigin))
return info;
// get trajectory in calorimeters
cachedTrajectory_.findEcalTrajectory(ecalDetIdAssociator_->volume());
cachedTrajectory_.findHcalTrajectory(hcalDetIdAssociator_->volume());
cachedTrajectory_.findHOTrajectory(hoDetIdAssociator_->volume());
cachedTrajectory_.findPreshowerTrajectory(preshowerDetIdAssociator_->volume());
info.trkGlobPosAtEcal = getPoint(cachedTrajectory_.getStateAtEcal().position());
info.trkGlobPosAtHcal = getPoint(cachedTrajectory_.getStateAtHcal().position());
info.trkGlobPosAtHO = getPoint(cachedTrajectory_.getStateAtHO().position());
info.trkMomAtEcal = cachedTrajectory_.getStateAtEcal().momentum();
info.trkMomAtHcal = cachedTrajectory_.getStateAtHcal().momentum();
info.trkMomAtHO = cachedTrajectory_.getStateAtHO().momentum();
if (parameters.useEcal)
fillEcal(iEvent, info, parameters);
if (parameters.useCalo)
fillCaloTowers(iEvent, info, parameters);
if (parameters.useHcal)
fillHcal(iEvent, info, parameters);
if (parameters.useHO)
fillHO(iEvent, info, parameters);
if (parameters.usePreshower)
fillPreshower(iEvent, info, parameters);
if (parameters.useMuon)
fillMuon(iEvent, info, parameters);
if (parameters.truthMatch)
fillCaloTruth(iEvent, info, parameters);
return info;
}
void TrackDetectorAssociator::fillEcal(const edm::Event& iEvent,
TrackDetMatchInfo& info,
const AssociatorParameters& parameters) {
const std::vector<SteppingHelixStateInfo>& trajectoryStates = cachedTrajectory_.getEcalTrajectory();
for (std::vector<SteppingHelixStateInfo>::const_iterator itr = trajectoryStates.begin();
itr != trajectoryStates.end();
itr++)
LogTrace("TrackAssociator") << "ECAL trajectory point (rho, z, phi): " << itr->position().perp() << ", "
<< itr->position().z() << ", " << itr->position().phi();
std::vector<GlobalPoint> coreTrajectory;
for (std::vector<SteppingHelixStateInfo>::const_iterator itr = trajectoryStates.begin();
itr != trajectoryStates.end();
itr++)
coreTrajectory.push_back(itr->position());
if (coreTrajectory.empty()) {
LogTrace("TrackAssociator") << "ECAL track trajectory is empty; moving on\n";
info.isGoodEcal = false;
return;
}
info.isGoodEcal = true;
// Find ECAL crystals
edm::Handle<EBRecHitCollection> EBRecHits;
iEvent.getByToken(parameters.EBRecHitsToken, EBRecHits);
if (!EBRecHits.isValid())
throw cms::Exception("FatalError") << "Unable to find EBRecHitCollection in the event!\n";
edm::Handle<EERecHitCollection> EERecHits;
iEvent.getByToken(parameters.EERecHitsToken, EERecHits);
if (!EERecHits.isValid())
throw cms::Exception("FatalError") << "Unable to find EERecHitCollection in event!\n";
std::set<DetId> ecalIdsInRegion;
if (parameters.accountForTrajectoryChangeCalo) {
// get trajectory change with respect to initial state
DetIdAssociator::MapRange mapRange =
getMapRange(cachedTrajectory_.trajectoryDelta(CachedTrajectory::IpToEcal), parameters.dREcalPreselection);
ecalIdsInRegion = ecalDetIdAssociator_->getDetIdsCloseToAPoint(coreTrajectory[0], mapRange);
} else
ecalIdsInRegion = ecalDetIdAssociator_->getDetIdsCloseToAPoint(coreTrajectory[0], parameters.dREcalPreselection);
LogTrace("TrackAssociator") << "ECAL hits in the region: " << ecalIdsInRegion.size();
if (parameters.dREcalPreselection > parameters.dREcal)
ecalIdsInRegion = ecalDetIdAssociator_->getDetIdsInACone(ecalIdsInRegion, coreTrajectory, parameters.dREcal);
LogTrace("TrackAssociator") << "ECAL hits in the cone: " << ecalIdsInRegion.size();
info.crossedEcalIds = ecalDetIdAssociator_->getCrossedDetIds(ecalIdsInRegion, coreTrajectory);
const std::vector<DetId>& crossedEcalIds = info.crossedEcalIds;
LogTrace("TrackAssociator") << "ECAL crossed hits " << crossedEcalIds.size();
// add EcalRecHits
for (std::vector<DetId>::const_iterator itr = crossedEcalIds.begin(); itr != crossedEcalIds.end(); itr++) {
std::vector<EcalRecHit>::const_iterator ebHit = (*EBRecHits).find(*itr);
std::vector<EcalRecHit>::const_iterator eeHit = (*EERecHits).find(*itr);
if (ebHit != (*EBRecHits).end())
info.crossedEcalRecHits.push_back(&*ebHit);
else if (eeHit != (*EERecHits).end())
info.crossedEcalRecHits.push_back(&*eeHit);
else
LogTrace("TrackAssociator") << "Crossed EcalRecHit is not found for DetId: " << itr->rawId();
}
for (std::set<DetId>::const_iterator itr = ecalIdsInRegion.begin(); itr != ecalIdsInRegion.end(); itr++) {
std::vector<EcalRecHit>::const_iterator ebHit = (*EBRecHits).find(*itr);
std::vector<EcalRecHit>::const_iterator eeHit = (*EERecHits).find(*itr);
if (ebHit != (*EBRecHits).end())
info.ecalRecHits.push_back(&*ebHit);
else if (eeHit != (*EERecHits).end())
info.ecalRecHits.push_back(&*eeHit);
else
LogTrace("TrackAssociator") << "EcalRecHit from the cone is not found for DetId: " << itr->rawId();
}
}
void TrackDetectorAssociator::fillCaloTowers(const edm::Event& iEvent,
TrackDetMatchInfo& info,
const AssociatorParameters& parameters) {
// use ECAL and HCAL trajectories to match a tower. (HO isn't used for matching).
std::vector<GlobalPoint> trajectory;
const std::vector<SteppingHelixStateInfo>& ecalTrajectoryStates = cachedTrajectory_.getEcalTrajectory();
const std::vector<SteppingHelixStateInfo>& hcalTrajectoryStates = cachedTrajectory_.getHcalTrajectory();
for (std::vector<SteppingHelixStateInfo>::const_iterator itr = ecalTrajectoryStates.begin();
itr != ecalTrajectoryStates.end();
itr++)
trajectory.push_back(itr->position());
for (std::vector<SteppingHelixStateInfo>::const_iterator itr = hcalTrajectoryStates.begin();
itr != hcalTrajectoryStates.end();
itr++)
trajectory.push_back(itr->position());
if (trajectory.empty()) {
LogTrace("TrackAssociator") << "HCAL trajectory is empty; moving on\n";
info.isGoodCalo = false;
return;
}
info.isGoodCalo = true;
// find crossed CaloTowers
edm::Handle<CaloTowerCollection> caloTowers;
iEvent.getByToken(parameters.caloTowersToken, caloTowers);
if (!caloTowers.isValid())
throw cms::Exception("FatalError") << "Unable to find CaloTowers in event!\n";
std::set<DetId> caloTowerIdsInRegion;
if (parameters.accountForTrajectoryChangeCalo) {
// get trajectory change with respect to initial state
DetIdAssociator::MapRange mapRange =
getMapRange(cachedTrajectory_.trajectoryDelta(CachedTrajectory::IpToHcal), parameters.dRHcalPreselection);
caloTowerIdsInRegion = caloDetIdAssociator_->getDetIdsCloseToAPoint(trajectory[0], mapRange);
} else
caloTowerIdsInRegion = caloDetIdAssociator_->getDetIdsCloseToAPoint(trajectory[0], parameters.dRHcalPreselection);
LogTrace("TrackAssociator") << "Towers in the region: " << caloTowerIdsInRegion.size();
auto caloTowerIdsInAConeBegin = caloTowerIdsInRegion.begin();
auto caloTowerIdsInAConeEnd = caloTowerIdsInRegion.end();
std::set<DetId> caloTowerIdsInAConeTmp;
if (!caloDetIdAssociator_->selectAllInACone(parameters.dRHcal)) {
caloTowerIdsInAConeTmp =
caloDetIdAssociator_->getDetIdsInACone(caloTowerIdsInRegion, trajectory, parameters.dRHcal);
caloTowerIdsInAConeBegin = caloTowerIdsInAConeTmp.begin();
caloTowerIdsInAConeEnd = caloTowerIdsInAConeTmp.end();
}
LogTrace("TrackAssociator") << "Towers in the cone: "
<< std::distance(caloTowerIdsInAConeBegin, caloTowerIdsInAConeEnd);
info.crossedTowerIds = caloDetIdAssociator_->getCrossedDetIds(caloTowerIdsInRegion, trajectory);
const std::vector<DetId>& crossedCaloTowerIds = info.crossedTowerIds;
LogTrace("TrackAssociator") << "Towers crossed: " << crossedCaloTowerIds.size();
// add CaloTowers
for (std::vector<DetId>::const_iterator itr = crossedCaloTowerIds.begin(); itr != crossedCaloTowerIds.end(); itr++) {
CaloTowerCollection::const_iterator tower = (*caloTowers).find(*itr);
if (tower != (*caloTowers).end())
info.crossedTowers.push_back(&*tower);
else
LogTrace("TrackAssociator") << "Crossed CaloTower is not found for DetId: " << (*itr).rawId();
}
for (std::set<DetId>::const_iterator itr = caloTowerIdsInAConeBegin; itr != caloTowerIdsInAConeEnd; itr++) {
CaloTowerCollection::const_iterator tower = (*caloTowers).find(*itr);
if (tower != (*caloTowers).end())
info.towers.push_back(&*tower);
else
LogTrace("TrackAssociator") << "CaloTower from the cone is not found for DetId: " << (*itr).rawId();
}
}
void TrackDetectorAssociator::fillPreshower(const edm::Event& iEvent,
TrackDetMatchInfo& info,
const AssociatorParameters& parameters) {
std::vector<GlobalPoint> trajectory;
const std::vector<SteppingHelixStateInfo>& trajectoryStates = cachedTrajectory_.getPreshowerTrajectory();
for (std::vector<SteppingHelixStateInfo>::const_iterator itr = trajectoryStates.begin();
itr != trajectoryStates.end();
itr++)
trajectory.push_back(itr->position());
if (trajectory.empty()) {
LogTrace("TrackAssociator") << "Preshower trajectory is empty; moving on\n";
return;
}
std::set<DetId> idsInRegion =
preshowerDetIdAssociator_->getDetIdsCloseToAPoint(trajectory[0], parameters.dRPreshowerPreselection);
LogTrace("TrackAssociator") << "Number of Preshower Ids in the region: " << idsInRegion.size();
info.crossedPreshowerIds = preshowerDetIdAssociator_->getCrossedDetIds(idsInRegion, trajectory);
LogTrace("TrackAssociator") << "Number of Preshower Ids in crossed: " << info.crossedPreshowerIds.size();
}
void TrackDetectorAssociator::fillHcal(const edm::Event& iEvent,
TrackDetMatchInfo& info,
const AssociatorParameters& parameters) {
const std::vector<SteppingHelixStateInfo>& trajectoryStates = cachedTrajectory_.getHcalTrajectory();
std::vector<GlobalPoint> coreTrajectory;
for (std::vector<SteppingHelixStateInfo>::const_iterator itr = trajectoryStates.begin();
itr != trajectoryStates.end();
itr++)
coreTrajectory.push_back(itr->position());
if (coreTrajectory.empty()) {
LogTrace("TrackAssociator") << "HCAL trajectory is empty; moving on\n";
info.isGoodHcal = false;
return;
}
info.isGoodHcal = true;
// find crossed Hcals
edm::Handle<HBHERecHitCollection> collection;
iEvent.getByToken(parameters.HBHEcollToken, collection);
if (!collection.isValid())
throw cms::Exception("FatalError") << "Unable to find HBHERecHits in event!\n";
std::set<DetId> idsInRegion;
if (parameters.accountForTrajectoryChangeCalo) {
// get trajectory change with respect to initial state
DetIdAssociator::MapRange mapRange =
getMapRange(cachedTrajectory_.trajectoryDelta(CachedTrajectory::IpToHcal), parameters.dRHcalPreselection);
idsInRegion = hcalDetIdAssociator_->getDetIdsCloseToAPoint(coreTrajectory[0], mapRange);
} else
idsInRegion = hcalDetIdAssociator_->getDetIdsCloseToAPoint(coreTrajectory[0], parameters.dRHcalPreselection);
LogTrace("TrackAssociator") << "HCAL hits in the region: " << idsInRegion.size() << "\n"
<< DetIdInfo::info(idsInRegion, nullptr);
auto idsInAConeBegin = idsInRegion.begin();
auto idsInAConeEnd = idsInRegion.end();
std::set<DetId> idsInAConeTmp;
if (!hcalDetIdAssociator_->selectAllInACone(parameters.dRHcal)) {
idsInAConeTmp = hcalDetIdAssociator_->getDetIdsInACone(idsInRegion, coreTrajectory, parameters.dRHcal);
idsInAConeBegin = idsInAConeTmp.begin();
idsInAConeEnd = idsInAConeTmp.end();
}
LogTrace("TrackAssociator") << "HCAL hits in the cone: " << std::distance(idsInAConeBegin, idsInAConeEnd) << "\n"
<< DetIdInfo::info(std::set<DetId>(idsInAConeBegin, idsInAConeEnd), nullptr);
info.crossedHcalIds = hcalDetIdAssociator_->getCrossedDetIds(idsInRegion, coreTrajectory);
const std::vector<DetId>& crossedIds = info.crossedHcalIds;
LogTrace("TrackAssociator") << "HCAL hits crossed: " << crossedIds.size() << "\n"
<< DetIdInfo::info(crossedIds, nullptr);
// add Hcal
for (std::vector<DetId>::const_iterator itr = crossedIds.begin(); itr != crossedIds.end(); itr++) {
HBHERecHitCollection::const_iterator hit = (*collection).find(*itr);
if (hit != (*collection).end())
info.crossedHcalRecHits.push_back(&*hit);
else
LogTrace("TrackAssociator") << "Crossed HBHERecHit is not found for DetId: " << itr->rawId();
}
for (std::set<DetId>::const_iterator itr = idsInAConeBegin; itr != idsInAConeEnd; itr++) {
HBHERecHitCollection::const_iterator hit = (*collection).find(*itr);
if (hit != (*collection).end())
info.hcalRecHits.push_back(&*hit);
else
LogTrace("TrackAssociator") << "HBHERecHit from the cone is not found for DetId: " << itr->rawId();
}
}
void TrackDetectorAssociator::fillHO(const edm::Event& iEvent,
TrackDetMatchInfo& info,
const AssociatorParameters& parameters) {
const std::vector<SteppingHelixStateInfo>& trajectoryStates = cachedTrajectory_.getHOTrajectory();
std::vector<GlobalPoint> coreTrajectory;
for (std::vector<SteppingHelixStateInfo>::const_iterator itr = trajectoryStates.begin();
itr != trajectoryStates.end();
itr++)
coreTrajectory.push_back(itr->position());
if (coreTrajectory.empty()) {
LogTrace("TrackAssociator") << "HO trajectory is empty; moving on\n";
info.isGoodHO = false;
return;
}
info.isGoodHO = true;
// find crossed HOs
edm::Handle<HORecHitCollection> collection;
iEvent.getByToken(parameters.HOcollToken, collection);
if (!collection.isValid())
throw cms::Exception("FatalError") << "Unable to find HORecHits in event!\n";
std::set<DetId> idsInRegion;
if (parameters.accountForTrajectoryChangeCalo) {
// get trajectory change with respect to initial state
DetIdAssociator::MapRange mapRange =
getMapRange(cachedTrajectory_.trajectoryDelta(CachedTrajectory::IpToHO), parameters.dRHcalPreselection);
idsInRegion = hoDetIdAssociator_->getDetIdsCloseToAPoint(coreTrajectory[0], mapRange);
} else
idsInRegion = hoDetIdAssociator_->getDetIdsCloseToAPoint(coreTrajectory[0], parameters.dRHcalPreselection);
LogTrace("TrackAssociator") << "idsInRegion.size(): " << idsInRegion.size();
auto idsInAConeBegin = idsInRegion.begin();
auto idsInAConeEnd = idsInRegion.end();
std::set<DetId> idsInAConeTmp;
if (!hoDetIdAssociator_->selectAllInACone(parameters.dRHcal)) {
idsInAConeTmp = hoDetIdAssociator_->getDetIdsInACone(idsInRegion, coreTrajectory, parameters.dRHcal);
idsInAConeBegin = idsInAConeTmp.begin();
idsInAConeEnd = idsInAConeTmp.end();
}
LogTrace("TrackAssociator") << "idsInACone.size(): " << std::distance(idsInAConeBegin, idsInAConeEnd);
info.crossedHOIds = hoDetIdAssociator_->getCrossedDetIds(idsInRegion, coreTrajectory);
const std::vector<DetId>& crossedIds = info.crossedHOIds;
// add HO
for (std::vector<DetId>::const_iterator itr = crossedIds.begin(); itr != crossedIds.end(); itr++) {
HORecHitCollection::const_iterator hit = (*collection).find(*itr);
if (hit != (*collection).end())
info.crossedHORecHits.push_back(&*hit);
else
LogTrace("TrackAssociator") << "Crossed HORecHit is not found for DetId: " << itr->rawId();
}
for (std::set<DetId>::const_iterator itr = idsInAConeBegin; itr != idsInAConeEnd; itr++) {
HORecHitCollection::const_iterator hit = (*collection).find(*itr);
if (hit != (*collection).end())
info.hoRecHits.push_back(&*hit);
else
LogTrace("TrackAssociator") << "HORecHit from the cone is not found for DetId: " << itr->rawId();
}
}
FreeTrajectoryState TrackDetectorAssociator::getFreeTrajectoryState(const MagneticField* bField,
const SimTrack& track,
const SimVertex& vertex) {
GlobalVector vector(track.momentum().x(), track.momentum().y(), track.momentum().z());
GlobalPoint point(vertex.position().x(), vertex.position().y(), vertex.position().z());
int charge = track.type() > 0 ? -1 : 1; // lepton convention
if (abs(track.type()) == 211 || // pion
abs(track.type()) == 321 || // kaon
abs(track.type()) == 2212)
charge = track.type() < 0 ? -1 : 1;
return getFreeTrajectoryState(bField, vector, point, charge);
}
FreeTrajectoryState TrackDetectorAssociator::getFreeTrajectoryState(const MagneticField* bField,
const GlobalVector& momentum,
const GlobalPoint& vertex,
const int charge) {
GlobalTrajectoryParameters tPars(vertex, momentum, charge, bField);
ROOT::Math::SMatrixIdentity id;
AlgebraicSymMatrix66 covT(id);
covT *= 1e-6; // initialize to sigma=1e-3
CartesianTrajectoryError tCov(covT);
return FreeTrajectoryState(tPars, tCov);
}
FreeTrajectoryState TrackDetectorAssociator::getFreeTrajectoryState(const MagneticField* bField,
const reco::Track& track) {
GlobalVector vector(track.momentum().x(), track.momentum().y(), track.momentum().z());
GlobalPoint point(track.vertex().x(), track.vertex().y(), track.vertex().z());
GlobalTrajectoryParameters tPars(point, vector, track.charge(), bField);
// FIX THIS !!!
// need to convert from perigee to global or helix (curvilinear) frame
// for now just an arbitrary matrix.
ROOT::Math::SMatrixIdentity id;
AlgebraicSymMatrix66 covT(id);
covT *= 1e-6; // initialize to sigma=1e-3
CartesianTrajectoryError tCov(covT);
return FreeTrajectoryState(tPars, tCov);
}
DetIdAssociator::MapRange TrackDetectorAssociator::getMapRange(const std::pair<float, float>& delta, const float dR) {
DetIdAssociator::MapRange mapRange;
mapRange.dThetaPlus = dR;
mapRange.dThetaMinus = dR;
mapRange.dPhiPlus = dR;
mapRange.dPhiMinus = dR;
if (delta.first > 0)
mapRange.dThetaPlus += delta.first;
else
mapRange.dThetaMinus += std::abs(delta.first);
if (delta.second > 0)
mapRange.dPhiPlus += delta.second;
else
mapRange.dPhiMinus += std::abs(delta.second);
LogTrace("TrackAssociator") << "Selection range: (dThetaPlus, dThetaMinus, dPhiPlus, dPhiMinus, dRPreselection): "
<< mapRange.dThetaPlus << ", " << mapRange.dThetaMinus << ", " << mapRange.dPhiPlus
<< ", " << mapRange.dPhiMinus << ", " << dR;
return mapRange;
}
void TrackDetectorAssociator::getTAMuonChamberMatches(std::vector<TAMuonChamberMatch>& matches,
const AssociatorParameters& parameters) {
// Strategy:
// Propagate through the whole detector, estimate change in eta and phi
// along the trajectory, add this to dRMuon and find DetIds around this
// direction using the map. Then propagate fast to each surface and apply
// final matching criteria.
// get the direction first
SteppingHelixStateInfo trajectoryPoint = cachedTrajectory_.getStateAtHcal();
// If trajectory point at HCAL is not valid, try to use the outer most state of the
// trajectory instead.
if (!trajectoryPoint.isValid())
trajectoryPoint = cachedTrajectory_.getOuterState();
if (!trajectoryPoint.isValid()) {
LogTrace("TrackAssociator")
<< "trajectory position at HCAL is not valid. Assume the track cannot reach muon detectors and skip it";
return;
}
GlobalVector direction = trajectoryPoint.momentum().unit();
LogTrace("TrackAssociator") << "muon direction: " << direction
<< "\n\t and corresponding point: " << trajectoryPoint.position() << "\n";
DetIdAssociator::MapRange mapRange =
getMapRange(cachedTrajectory_.trajectoryDelta(CachedTrajectory::FullTrajectory), parameters.dRMuonPreselection);
// and find chamber DetIds
std::set<DetId> muonIdsInRegion = muonDetIdAssociator_->getDetIdsCloseToAPoint(trajectoryPoint.position(), mapRange);
LogTrace("TrackAssociator") << "Number of chambers to check: " << muonIdsInRegion.size();
for (std::set<DetId>::const_iterator detId = muonIdsInRegion.begin(); detId != muonIdsInRegion.end(); detId++) {
const GeomDet* geomDet = muonDetIdAssociator_->getGeomDet(*detId);
TrajectoryStateOnSurface stateOnSurface = cachedTrajectory_.propagate(&geomDet->surface());
if (!stateOnSurface.isValid()) {
LogTrace("TrackAssociator") << "Failed to propagate the track; moving on\n\t"
<< "Element is not crosssed: " << DetIdInfo::info(*detId, nullptr) << "\n";
continue;
}
LocalPoint localPoint = geomDet->surface().toLocal(stateOnSurface.freeState()->position());
LocalError localError = stateOnSurface.localError().positionError();
float distanceX = 0.f;
float distanceY = 0.f;
if (const CSCChamber* cscChamber = dynamic_cast<const CSCChamber*>(geomDet)) {
const CSCChamberSpecs* chamberSpecs = cscChamber->specs();
if (!chamberSpecs) {
LogTrace("TrackAssociator") << "Failed to get CSCChamberSpecs from CSCChamber; moving on\n";
continue;
}
const CSCLayerGeometry* layerGeometry = chamberSpecs->oddLayerGeometry(1);
if (!layerGeometry) {
LogTrace("TrackAssociator") << "Failed to get CSCLayerGeometry from CSCChamberSpecs; moving on\n";
continue;
}
const CSCWireTopology* wireTopology = layerGeometry->wireTopology();
if (!wireTopology) {
LogTrace("TrackAssociator") << "Failed to get CSCWireTopology from CSCLayerGeometry; moving on\n";
continue;
}
float wideWidth = wireTopology->wideWidthOfPlane();
float narrowWidth = wireTopology->narrowWidthOfPlane();
float length = wireTopology->lengthOfPlane();
// If slanted, there is no y offset between local origin and symmetry center of wire plane
float yOfFirstWire = std::abs(wireTopology->wireAngle()) > 1.E-06f ? -0.5 * length : wireTopology->yOfWire(1);
// y offset between local origin and symmetry center of wire plane
float yCOWPOffset = yOfFirstWire + 0.5f * length;
// tangent of the incline angle from inside the trapezoid
float tangent = (wideWidth - narrowWidth) / (2.f * length);
// y position wrt bottom of trapezoid
float yPrime = localPoint.y() + std::abs(yOfFirstWire);
// half trapezoid width at y' is 0.5 * narrowWidth + x side of triangle with the above tangent and side y'
float halfWidthAtYPrime = 0.5f * narrowWidth + yPrime * tangent;
distanceX = std::abs(localPoint.x()) - halfWidthAtYPrime;
distanceY = std::abs(localPoint.y() - yCOWPOffset) - 0.5f * length;
} else if (dynamic_cast<const GEMChamber*>(geomDet) || dynamic_cast<const GEMSuperChamber*>(geomDet)) {
const TrapezoidalPlaneBounds* bounds = dynamic_cast<const TrapezoidalPlaneBounds*>(&geomDet->surface().bounds());
float wideWidth = bounds->width();
float narrowWidth = 2.f * bounds->widthAtHalfLength() - wideWidth;
float length = bounds->length();
float tangent = (wideWidth - narrowWidth) / (2.f * length);
float halfWidthAtY = tangent * localPoint.y() + 0.5f * narrowWidth;
distanceX = std::abs(localPoint.x()) - halfWidthAtY;
distanceY = std::abs(localPoint.y()) - 0.5f * length;
} else {
distanceX = std::abs(localPoint.x()) - 0.5f * geomDet->surface().bounds().width();
distanceY = std::abs(localPoint.y()) - 0.5f * geomDet->surface().bounds().length();
}
if ((distanceX < parameters.muonMaxDistanceX && distanceY < parameters.muonMaxDistanceY) ||
(distanceX * distanceX <
localError.xx() * parameters.muonMaxDistanceSigmaX * parameters.muonMaxDistanceSigmaX &&
distanceY * distanceY <
localError.yy() * parameters.muonMaxDistanceSigmaY * parameters.muonMaxDistanceSigmaY)) {
LogTrace("TrackAssociator") << "found a match: " << DetIdInfo::info(*detId, nullptr) << "\n";
TAMuonChamberMatch match;
match.tState = stateOnSurface;
match.localDistanceX = distanceX;
match.localDistanceY = distanceY;
match.id = *detId;
matches.push_back(match);
} else {
LogTrace("TrackAssociator") << "chamber is too far: " << DetIdInfo::info(*detId, nullptr)
<< "\n\tdistanceX: " << distanceX << "\t distanceY: " << distanceY
<< "\t sigmaX: " << distanceX / sqrt(localError.xx())
<< "\t sigmaY: " << distanceY / sqrt(localError.yy()) << "\n";
}
}
}
void TrackDetectorAssociator::fillMuon(const edm::Event& iEvent,
TrackDetMatchInfo& info,
const AssociatorParameters& parameters) {
// Get the segments from the event
edm::Handle<DTRecSegment4DCollection> dtSegments;
iEvent.getByToken(parameters.dtSegmentsToken, dtSegments);
if (!dtSegments.isValid())
throw cms::Exception("FatalError") << "Unable to find DTRecSegment4DCollection in event!\n";
edm::Handle<CSCSegmentCollection> cscSegments;
iEvent.getByToken(parameters.cscSegmentsToken, cscSegments);
if (!cscSegments.isValid())
throw cms::Exception("FatalError") << "Unable to find CSCSegmentCollection in event!\n";
edm::Handle<GEMSegmentCollection> gemSegments;
if (parameters.useGEM)
iEvent.getByToken(parameters.gemSegmentsToken, gemSegments);
edm::Handle<ME0SegmentCollection> me0Segments;
if (parameters.useME0)
iEvent.getByToken(parameters.me0SegmentsToken, me0Segments);
///// get a set of DetId's in a given direction
// check the map of available segments
// if there is no segments in a given direction at all,
// then there is no point to fly there.
//
// MISSING
// Possible solution: quick search for presence of segments
// for the set of DetIds
// get a set of matches corresponding to muon chambers
std::vector<TAMuonChamberMatch> matchedChambers;
LogTrace("TrackAssociator") << "Trying to Get ChamberMatches" << std::endl;
getTAMuonChamberMatches(matchedChambers, parameters);
LogTrace("TrackAssociator") << "Chambers matched: " << matchedChambers.size() << "\n";
// Iterate over all chamber matches and fill segment matching
// info if it's available
for (std::vector<TAMuonChamberMatch>::iterator matchedChamber = matchedChambers.begin();
matchedChamber != matchedChambers.end();
matchedChamber++) {
const GeomDet* geomDet = muonDetIdAssociator_->getGeomDet((*matchedChamber).id);
// DT chamber
if (const DTChamber* chamber = dynamic_cast<const DTChamber*>(geomDet)) {
// Get the range for the corresponding segments
DTRecSegment4DCollection::range range = dtSegments->get(chamber->id());
// Loop over the segments of this chamber
for (DTRecSegment4DCollection::const_iterator segment = range.first; segment != range.second; segment++) {
if (addTAMuonSegmentMatch(*matchedChamber, &(*segment), parameters)) {
matchedChamber->segments.back().dtSegmentRef = DTRecSegment4DRef(dtSegments, segment - dtSegments->begin());
}
}
}
// CSC Chamber
else if (const CSCChamber* chamber = dynamic_cast<const CSCChamber*>(geomDet)) {
// Get the range for the corresponding segments
CSCSegmentCollection::range range = cscSegments->get(chamber->id());
// Loop over the segments
for (CSCSegmentCollection::const_iterator segment = range.first; segment != range.second; segment++) {
if (addTAMuonSegmentMatch(*matchedChamber, &(*segment), parameters)) {
matchedChamber->segments.back().cscSegmentRef = CSCSegmentRef(cscSegments, segment - cscSegments->begin());
}
}
} else {
// GEM Chamber
if (parameters.useGEM) {
if (const GEMSuperChamber* chamber = dynamic_cast<const GEMSuperChamber*>(geomDet)) {
// Get the range for the corresponding segments
GEMSegmentCollection::range range = gemSegments->get(chamber->id());
// Loop over the segments
for (GEMSegmentCollection::const_iterator segment = range.first; segment != range.second; segment++) {
if (addTAMuonSegmentMatch(*matchedChamber, &(*segment), parameters)) {
matchedChamber->segments.back().gemSegmentRef =
GEMSegmentRef(gemSegments, segment - gemSegments->begin());
}
}
}
}
// ME0 Chamber
if (parameters.useME0) {
if (const ME0Chamber* chamber = dynamic_cast<const ME0Chamber*>(geomDet)) {
// Get the range for the corresponding segments
ME0SegmentCollection::range range = me0Segments->get(chamber->id());
// Loop over the segments
for (ME0SegmentCollection::const_iterator segment = range.first; segment != range.second; segment++) {
if (addTAMuonSegmentMatch(*matchedChamber, &(*segment), parameters)) {
matchedChamber->segments.back().me0SegmentRef =
ME0SegmentRef(me0Segments, segment - me0Segments->begin());
}
}
}
}
}
info.chambers.push_back(*matchedChamber);
}
}
bool TrackDetectorAssociator::addTAMuonSegmentMatch(TAMuonChamberMatch& matchedChamber,
const RecSegment* segment,
const AssociatorParameters& parameters) {
LogTrace("TrackAssociator") << "Segment local position: " << segment->localPosition() << "\n"
<< std::hex << segment->geographicalId().rawId() << "\n";
const GeomDet* chamber = muonDetIdAssociator_->getGeomDet(matchedChamber.id);
TrajectoryStateOnSurface trajectoryStateOnSurface = matchedChamber.tState;
GlobalPoint segmentGlobalPosition = chamber->toGlobal(segment->localPosition());
LogTrace("TrackAssociator") << "Segment global position: " << segmentGlobalPosition
<< " \t (R_xy,eta,phi): " << segmentGlobalPosition.perp() << ","
<< segmentGlobalPosition.eta() << "," << segmentGlobalPosition.phi() << "\n";
LogTrace("TrackAssociator") << "\teta hit: " << segmentGlobalPosition.eta()
<< " \tpropagator: " << trajectoryStateOnSurface.freeState()->position().eta() << "\n"
<< "\tphi hit: " << segmentGlobalPosition.phi()
<< " \tpropagator: " << trajectoryStateOnSurface.freeState()->position().phi()
<< std::endl;
bool isGood = false;
bool isDTWithoutY = false;
const DTRecSegment4D* dtseg = dynamic_cast<const DTRecSegment4D*>(segment);
if (dtseg && (!dtseg->hasZed()))
isDTWithoutY = true;
float deltaPhi(std::abs(segmentGlobalPosition.phi() - trajectoryStateOnSurface.freeState()->position().phi()));
if (deltaPhi > float(M_PI))
deltaPhi = std::abs(deltaPhi - float(M_PI) * 2.f);
float deltaEta = std::abs(segmentGlobalPosition.eta() - trajectoryStateOnSurface.freeState()->position().eta());
if (isDTWithoutY) {
isGood = deltaPhi < parameters.dRMuon;
// Be in chamber
isGood &= deltaEta < .3f;
} else
isGood = deltaEta * deltaEta + deltaPhi * deltaPhi < parameters.dRMuon * parameters.dRMuon;
if (isGood) {
TAMuonSegmentMatch muonSegment;
muonSegment.segmentGlobalPosition = getPoint(segmentGlobalPosition);
muonSegment.segmentLocalPosition = getPoint(segment->localPosition());
muonSegment.segmentLocalDirection = getVector(segment->localDirection());
muonSegment.segmentLocalErrorXX = segment->localPositionError().xx();
muonSegment.segmentLocalErrorYY = segment->localPositionError().yy();
muonSegment.segmentLocalErrorXY = segment->localPositionError().xy();
muonSegment.segmentLocalErrorDxDz = segment->localDirectionError().xx();
muonSegment.segmentLocalErrorDyDz = segment->localDirectionError().yy();
// DANGEROUS - compiler cannot guaranty parameters ordering
// AlgebraicSymMatrix segmentCovMatrix = segment->parametersError();
// muonSegment.segmentLocalErrorXDxDz = segmentCovMatrix[2][0];
// muonSegment.segmentLocalErrorYDyDz = segmentCovMatrix[3][1];
muonSegment.segmentLocalErrorXDxDz = -999.f;
muonSegment.segmentLocalErrorYDyDz = -999.f;
muonSegment.hasZed = true;
muonSegment.hasPhi = true;
// timing information
muonSegment.t0 = 0.f;
if (dtseg) {
if ((dtseg->hasPhi()) && (!isDTWithoutY)) {
int phiHits = dtseg->phiSegment()->specificRecHits().size();
// int zHits = dtseg->zSegment()->specificRecHits().size();
int hits = 0;
double t0 = 0.;
// TODO: cuts on hit numbers not optimized in any way yet...
if (phiHits > 5 && dtseg->phiSegment()->ist0Valid()) {
t0 += dtseg->phiSegment()->t0() * phiHits;
hits += phiHits;
LogTrace("TrackAssociator") << " Phi t0: " << dtseg->phiSegment()->t0() << " hits: " << phiHits;
}
// the z segments seem to contain little useful information...
// if (zHits>3) {
// t0+=s->zSegment()->t0()*zHits;
// hits+=zHits;
// LogTrace("TrackAssociator") << " Z t0: " << s->zSegment()->t0() << " hits: " << zHits << std::endl;
// }
if (hits)
muonSegment.t0 = t0 / hits;
// LogTrace("TrackAssociator") << " --- t0: " << muonSegment.t0 << std::endl;
} else {
// check and set dimensionality
if (isDTWithoutY)
muonSegment.hasZed = false;
if (!dtseg->hasPhi())
muonSegment.hasPhi = false;
}
}
matchedChamber.segments.push_back(muonSegment);
}
return isGood;
}
//********************** NON-CORE CODE ******************************//
void TrackDetectorAssociator::fillCaloTruth(const edm::Event& iEvent,
TrackDetMatchInfo& info,
const AssociatorParameters& parameters) {
// get list of simulated tracks and their vertices
using namespace edm;
Handle<SimTrackContainer> simTracks;
iEvent.getByToken(parameters.simTracksToken, simTracks);
if (!simTracks.isValid())
throw cms::Exception("FatalError") << "No simulated tracks found\n";
Handle<SimVertexContainer> simVertices;
iEvent.getByToken(parameters.simVerticesToken, simVertices);
if (!simVertices.isValid())
throw cms::Exception("FatalError") << "No simulated vertices found\n";
// get sim calo hits
Handle<PCaloHitContainer> simEcalHitsEB;
iEvent.getByToken(parameters.simEcalHitsEBToken, simEcalHitsEB);
if (!simEcalHitsEB.isValid())
throw cms::Exception("FatalError") << "No simulated ECAL EB hits found\n";
Handle<PCaloHitContainer> simEcalHitsEE;
iEvent.getByToken(parameters.simEcalHitsEEToken, simEcalHitsEE);
if (!simEcalHitsEE.isValid())
throw cms::Exception("FatalError") << "No simulated ECAL EE hits found\n";
Handle<PCaloHitContainer> simHcalHits;
iEvent.getByToken(parameters.simHcalHitsToken, simHcalHits);
if (!simHcalHits.isValid())
throw cms::Exception("FatalError") << "No simulated HCAL hits found\n";
// find truth partner
SimTrackContainer::const_iterator simTrack = simTracks->begin();
for (; simTrack != simTracks->end(); ++simTrack) {
math::XYZVector simP3(simTrack->momentum().x(), simTrack->momentum().y(), simTrack->momentum().z());
math::XYZVector recoP3(info.stateAtIP.momentum().x(), info.stateAtIP.momentum().y(), info.stateAtIP.momentum().z());
if (ROOT::Math::VectorUtil::DeltaR(recoP3, simP3) < 0.1)
break;
}
if (simTrack != simTracks->end()) {
info.simTrack = &(*simTrack);
float ecalTrueEnergy(0);
float hcalTrueEnergy(0);
// loop over calo hits
for (PCaloHitContainer::const_iterator hit = simEcalHitsEB->begin(); hit != simEcalHitsEB->end(); ++hit)
if (hit->geantTrackId() == info.simTrack->genpartIndex())
ecalTrueEnergy += hit->energy();
for (PCaloHitContainer::const_iterator hit = simEcalHitsEE->begin(); hit != simEcalHitsEE->end(); ++hit)
if (hit->geantTrackId() == info.simTrack->genpartIndex())
ecalTrueEnergy += hit->energy();
for (PCaloHitContainer::const_iterator hit = simHcalHits->begin(); hit != simHcalHits->end(); ++hit)
if (hit->geantTrackId() == info.simTrack->genpartIndex())
hcalTrueEnergy += hit->energy();
info.ecalTrueEnergy = ecalTrueEnergy;
info.hcalTrueEnergy = hcalTrueEnergy;
info.hcalTrueEnergyCorrected = hcalTrueEnergy;
if (std::abs(info.trkGlobPosAtHcal.eta()) < 1.3f)
info.hcalTrueEnergyCorrected = hcalTrueEnergy * 113.2f;
else if (std::abs(info.trkGlobPosAtHcal.eta()) < 3.0f)
info.hcalTrueEnergyCorrected = hcalTrueEnergy * 167.2f;
}
}
TrackDetMatchInfo TrackDetectorAssociator::associate(const edm::Event& iEvent,
const edm::EventSetup& iSetup,
const reco::Track& track,
const AssociatorParameters& parameters,
Direction direction /*= Any*/) {
double currentStepSize = cachedTrajectory_.getPropagationStep();
const MagneticField* bField = &iSetup.getData(parameters.bFieldToken);
if (track.extra().isNull()) {
if (direction != InsideOut)
throw cms::Exception("FatalError") << "No TrackExtra information is available and association is done with "
"something else than InsideOut track.\n"
<< "Either change the parameter or provide needed data!\n";
LogTrace("TrackAssociator") << "Track Extras not found\n";
FreeTrajectoryState initialState = trajectoryStateTransform::initialFreeState(track, bField);
return associate(iEvent, iSetup, parameters, &initialState); // 5th argument is null pointer
}
LogTrace("TrackAssociator") << "Track Extras found\n";
FreeTrajectoryState innerState = trajectoryStateTransform::innerFreeState(track, bField);
FreeTrajectoryState outerState = trajectoryStateTransform::outerFreeState(track, bField);
FreeTrajectoryState referenceState = trajectoryStateTransform::initialFreeState(track, bField);
LogTrace("TrackAssociator") << "inner track state (rho, z, phi):" << track.innerPosition().Rho() << ", "
<< track.innerPosition().z() << ", " << track.innerPosition().phi() << "\n";
LogTrace("TrackAssociator") << "innerFreeState (rho, z, phi):" << innerState.position().perp() << ", "
<< innerState.position().z() << ", " << innerState.position().phi() << "\n";
LogTrace("TrackAssociator") << "outer track state (rho, z, phi):" << track.outerPosition().Rho() << ", "
<< track.outerPosition().z() << ", " << track.outerPosition().phi() << "\n";
LogTrace("TrackAssociator") << "outerFreeState (rho, z, phi):" << outerState.position().perp() << ", "
<< outerState.position().z() << ", " << outerState.position().phi() << "\n";