File indexing completed on 2024-04-06 11:56:50
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "DataFormats/TrajectorySeed/interface/TrajectorySeedCollection.h"
0010 #include "DataFormats/TrackReco/interface/Track.h"
0011 #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
0012 #include "DataFormats/MuonDetId/interface/MuonSubdetId.h"
0013 #include "DataFormats/GeometryVector/interface/LocalPoint.h"
0014 #include "DataFormats/DetId/interface/DetId.h"
0015 #include "DataFormats/Common/interface/getRef.h"
0016 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0017 #include "DataFormats/DTRecHit/interface/DTRecSegment4D.h"
0018 #include "DataFormats/TrackingRecHit/interface/RecSegment.h"
0019 #include "DataFormats/RPCRecHit/interface/RPCRecHitCollection.h"
0020 #include "DataFormats/DTRecHit/interface/DTRecHitCollection.h"
0021 #include "DataFormats/CSCRecHit/interface/CSCRecHit2DCollection.h"
0022
0023 #include "MagneticField/Engine/interface/MagneticField.h"
0024 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0025 #include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h"
0026 #include "Geometry/CommonDetUnit/interface/GlobalTrackingGeometry.h"
0027 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
0028
0029 #include "Alignment/MuonAlignmentAlgorithms/interface/SegmentToTrackAssociator.h"
0030
0031 #include <vector>
0032
0033 SegmentToTrackAssociator::SegmentToTrackAssociator(const edm::ParameterSet& iConfig,
0034 const GlobalTrackingGeometry* GlobalTrackingGeometry,
0035 edm::ConsumesCollector& iC)
0036 : globalTrackingGeometry_(GlobalTrackingGeometry),
0037 theDTSegmentLabel(iConfig.getParameter<edm::InputTag>("segmentsDT")),
0038 theCSCSegmentLabel(iConfig.getParameter<edm::InputTag>("segmentsCSC")),
0039 tokenDTSegment_(iC.consumes<DTRecSegment4DCollection>(theDTSegmentLabel)),
0040 tokenCSCSegment_(iC.consumes<CSCSegmentCollection>(theCSCSegmentLabel)) {}
0041
0042 void SegmentToTrackAssociator::clear() {
0043 indexCollectionDT.clear();
0044 indexCollectionCSC.clear();
0045 }
0046
0047 MuonTransientTrackingRecHit::MuonRecHitContainer SegmentToTrackAssociator::associate(const edm::Event& iEvent,
0048 const edm::EventSetup& iSetup,
0049 const reco::Track& track,
0050 std::string TrackRefitterType) {
0051
0052 const edm::Handle<DTRecSegment4DCollection>& DTSegments = iEvent.getHandle(tokenDTSegment_);
0053
0054 const edm::Handle<CSCSegmentCollection>& CSCSegments = iEvent.getHandle(tokenCSCSegment_);
0055
0056 MuonTransientTrackingRecHit::MuonRecHitContainer SelectedSegments;
0057
0058 DTRecSegment4DCollection::const_iterator segmentDT;
0059 CSCSegmentCollection::const_iterator segmentCSC;
0060
0061 std::vector<int> positionDT;
0062 std::vector<int> positionCSC;
0063 std::vector<TrackingRecHit*> my4DTrack;
0064
0065
0066 for (unsigned int counter = 0; counter != track.recHitsSize() - 1; counter++) {
0067 TrackingRecHitRef myRef = track.recHit(counter);
0068
0069 const TrackingRecHit* rechit = myRef.get();
0070 const GeomDet* geomDet = globalTrackingGeometry_->idToDet(rechit->geographicalId());
0071
0072
0073 if (geomDet->subDetector() == GeomDetEnumerators::DT) {
0074
0075 DTLayerId myLayer(rechit->geographicalId().rawId());
0076
0077 int NumberOfDTSegment = 0;
0078
0079 for (segmentDT = DTSegments->begin(); segmentDT != DTSegments->end(); ++segmentDT) {
0080
0081 bool isNewChamber = true;
0082
0083
0084 for (std::vector<int>::iterator positionIt = positionDT.begin(); positionIt != positionDT.end(); positionIt++) {
0085
0086 if (NumberOfDTSegment == *positionIt)
0087 isNewChamber = false;
0088 }
0089
0090
0091 for (std::vector<std::vector<int> >::iterator collect = indexCollectionDT.begin();
0092 collect != indexCollectionDT.end();
0093 ++collect) {
0094
0095 for (std::vector<int>::iterator positionIt = (*collect).begin(); positionIt != (*collect).end();
0096 positionIt++) {
0097
0098 if (NumberOfDTSegment == *positionIt)
0099 isNewChamber = false;
0100 }
0101 }
0102
0103
0104 if (isNewChamber) {
0105 DTChamberId myChamber((*segmentDT).geographicalId().rawId());
0106
0107 if (myLayer.wheel() == myChamber.wheel() && myLayer.station() == myChamber.station() &&
0108 myLayer.sector() == myChamber.sector()) {
0109
0110 positionDT.push_back(NumberOfDTSegment);
0111 const GeomDet* DTgeomDet = globalTrackingGeometry_->idToDet(myChamber);
0112 SelectedSegments.push_back(
0113 MuonTransientTrackingRecHit::specificBuild(DTgeomDet, (TrackingRecHit*)&*segmentDT));
0114
0115
0116 }
0117 }
0118 NumberOfDTSegment++;
0119 }
0120
0121 } else if (geomDet->subDetector() == GeomDetEnumerators::CSC) {
0122
0123 CSCDetId myLayer(rechit->geographicalId().rawId());
0124
0125 int NumberOfCSCSegment = 0;
0126
0127 for (segmentCSC = CSCSegments->begin(); segmentCSC != CSCSegments->end(); segmentCSC++) {
0128
0129 bool isNewChamber = true;
0130
0131 for (std::vector<int>::iterator positionIt = positionCSC.begin(); positionIt != positionCSC.end();
0132 positionIt++) {
0133
0134 if (NumberOfCSCSegment == *positionIt)
0135 isNewChamber = false;
0136 }
0137
0138 for (std::vector<std::vector<int> >::iterator collect = indexCollectionCSC.begin();
0139 collect != indexCollectionCSC.end();
0140 ++collect) {
0141
0142 for (std::vector<int>::iterator positionIt = (*collect).begin(); positionIt != (*collect).end();
0143 positionIt++) {
0144
0145 if (NumberOfCSCSegment == *positionIt)
0146 isNewChamber = false;
0147 }
0148 }
0149
0150 if (isNewChamber) {
0151 CSCDetId myChamber((*segmentCSC).geographicalId().rawId());
0152
0153 if (myLayer.chamberId() == myChamber.chamberId()) {
0154
0155 positionCSC.push_back(NumberOfCSCSegment);
0156 const GeomDet* CSCgeomDet = globalTrackingGeometry_->idToDet(myChamber);
0157 SelectedSegments.push_back(
0158 MuonTransientTrackingRecHit::specificBuild(CSCgeomDet, (TrackingRecHit*)&*segmentCSC));
0159 }
0160 }
0161 NumberOfCSCSegment++;
0162 }
0163 }
0164 }
0165
0166 indexCollectionDT.push_back(positionDT);
0167 indexCollectionCSC.push_back(positionCSC);
0168
0169 if (TrackRefitterType == "CosmicLike") {
0170 std::reverse(SelectedSegments.begin(), SelectedSegments.end());
0171 }
0172
0173 return SelectedSegments;
0174 }