Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-22 02:30:55

0001 /*
0002  *  See header file for a description of this class.
0003  *
0004  *  $Date: 2010/03/29 13:18:43 $
0005  *  $Revision: 1.2 $
0006  *  \author P. Martinez - IFCA
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/DTRecHit/interface/DTRecSegment4DCollection.h"
0020 #include "DataFormats/CSCRecHit/interface/CSCSegmentCollection.h"
0021 #include "DataFormats/RPCRecHit/interface/RPCRecHitCollection.h"
0022 #include "DataFormats/DTRecHit/interface/DTRecHitCollection.h"
0023 #include "DataFormats/CSCRecHit/interface/CSCRecHit2DCollection.h"
0024 
0025 #include "MagneticField/Engine/interface/MagneticField.h"
0026 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0027 #include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h"
0028 #include "Geometry/CommonDetUnit/interface/GlobalTrackingGeometry.h"
0029 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
0030 
0031 #include "Alignment/MuonAlignmentAlgorithms/interface/SegmentToTrackAssociator.h"
0032 
0033 #include <vector>
0034 
0035 SegmentToTrackAssociator::SegmentToTrackAssociator(const edm::ParameterSet& iConfig,
0036                                                    const GlobalTrackingGeometry* GlobalTrackingGeometry)
0037     : globalTrackingGeometry_(GlobalTrackingGeometry) {
0038   theDTSegmentLabel = iConfig.getParameter<edm::InputTag>("segmentsDT");
0039   theCSCSegmentLabel = iConfig.getParameter<edm::InputTag>("segmentsCSC");
0040 }
0041 
0042 SegmentToTrackAssociator::~SegmentToTrackAssociator() {}
0043 
0044 void SegmentToTrackAssociator::clear() {
0045   indexCollectionDT.clear();
0046   indexCollectionCSC.clear();
0047 }
0048 
0049 MuonTransientTrackingRecHit::MuonRecHitContainer SegmentToTrackAssociator::associate(const edm::Event& iEvent,
0050                                                                                      const edm::EventSetup& iSetup,
0051                                                                                      const reco::Track& track,
0052                                                                                      std::string TrackRefitterType) {
0053   // The segment collections
0054   edm::Handle<DTRecSegment4DCollection> DTSegments;
0055   iEvent.getByLabel(theDTSegmentLabel, DTSegments);
0056 
0057   edm::Handle<CSCSegmentCollection> CSCSegments;
0058   iEvent.getByLabel(theCSCSegmentLabel, CSCSegments);
0059 
0060   MuonTransientTrackingRecHit::MuonRecHitContainer SelectedSegments;
0061 
0062   DTRecSegment4DCollection::const_iterator segmentDT;
0063   CSCSegmentCollection::const_iterator segmentCSC;
0064 
0065   std::vector<int> positionDT;
0066   std::vector<int> positionCSC;
0067   std::vector<TrackingRecHit*> my4DTrack;
0068 
0069   //Loop over the hits of the track
0070   for (unsigned int counter = 0; counter != track.recHitsSize() - 1; counter++) {
0071     TrackingRecHitRef myRef = track.recHit(counter);
0072 
0073     const TrackingRecHit* rechit = myRef.get();
0074     const GeomDet* geomDet = globalTrackingGeometry_->idToDet(rechit->geographicalId());
0075 
0076     //It's a DT Hit
0077     if (geomDet->subDetector() == GeomDetEnumerators::DT) {
0078       //Take the layer associated to this hit
0079       DTLayerId myLayer(rechit->geographicalId().rawId());
0080 
0081       int NumberOfDTSegment = 0;
0082       //Loop over segments
0083       for (segmentDT = DTSegments->begin(); segmentDT != DTSegments->end(); ++segmentDT) {
0084         //By default the chamber associated to this Segment is new
0085         bool isNewChamber = true;
0086 
0087         //Loop over segments already included in the vector of segments in the actual track
0088         for (std::vector<int>::iterator positionIt = positionDT.begin(); positionIt != positionDT.end(); positionIt++) {
0089           //If this segment has been used before isNewChamber = false
0090           if (NumberOfDTSegment == *positionIt)
0091             isNewChamber = false;
0092         }
0093 
0094         //Loop over vectors of segments associated to previous tracks
0095         for (std::vector<std::vector<int> >::iterator collect = indexCollectionDT.begin();
0096              collect != indexCollectionDT.end();
0097              ++collect) {
0098           //Loop over segments associated to a track
0099           for (std::vector<int>::iterator positionIt = (*collect).begin(); positionIt != (*collect).end();
0100                positionIt++) {
0101             //If this segment was used in a previos track then isNewChamber = false
0102             if (NumberOfDTSegment == *positionIt)
0103               isNewChamber = false;
0104           }
0105         }
0106 
0107         //If the chamber is new
0108         if (isNewChamber) {
0109           DTChamberId myChamber((*segmentDT).geographicalId().rawId());
0110           //If the layer of the hit belongs to the chamber of the 4D Segment
0111           if (myLayer.wheel() == myChamber.wheel() && myLayer.station() == myChamber.station() &&
0112               myLayer.sector() == myChamber.sector()) {
0113             //push position of the segment and tracking rechit
0114             positionDT.push_back(NumberOfDTSegment);
0115             const GeomDet* DTgeomDet = globalTrackingGeometry_->idToDet(myChamber);
0116             SelectedSegments.push_back(
0117                 MuonTransientTrackingRecHit::specificBuild(DTgeomDet, (TrackingRecHit*)&*segmentDT));
0118 
0119             //edm::LogWarning("Alignment") << "TagSeg: " << "NumberOfDTSegment " << NumberOfDTSegment << " Wheel " << myChamber.wheel() << " Sector " <<  myChamber.sector() << " Chamber " << myChamber.station() << std::endl;
0120           }
0121         }
0122         NumberOfDTSegment++;
0123       }
0124       //In case is a CSC
0125     } else if (geomDet->subDetector() == GeomDetEnumerators::CSC) {
0126       //Take the layer associated to this hit
0127       CSCDetId myLayer(rechit->geographicalId().rawId());
0128 
0129       int NumberOfCSCSegment = 0;
0130       //Loop over 4Dsegments
0131       for (segmentCSC = CSCSegments->begin(); segmentCSC != CSCSegments->end(); segmentCSC++) {
0132         //By default the chamber associated to the segment is new
0133         bool isNewChamber = true;
0134         //Loop over segments in the current track
0135         for (std::vector<int>::iterator positionIt = positionCSC.begin(); positionIt != positionCSC.end();
0136              positionIt++) {
0137           //If this segment has been used then newchamber = false
0138           if (NumberOfCSCSegment == *positionIt)
0139             isNewChamber = false;
0140         }
0141         //Loop over vectors of segments in previous tracks
0142         for (std::vector<std::vector<int> >::iterator collect = indexCollectionCSC.begin();
0143              collect != indexCollectionCSC.end();
0144              ++collect) {
0145           //Loop over segments in a track
0146           for (std::vector<int>::iterator positionIt = (*collect).begin(); positionIt != (*collect).end();
0147                positionIt++) {
0148             //If the segment was used in a previous track isNewChamber = false
0149             if (NumberOfCSCSegment == *positionIt)
0150               isNewChamber = false;
0151           }
0152         }
0153         //If the chamber is new
0154         if (isNewChamber) {
0155           CSCDetId myChamber((*segmentCSC).geographicalId().rawId());
0156           //If the chambers are the same
0157           if (myLayer.chamberId() == myChamber.chamberId()) {
0158             //push
0159             positionCSC.push_back(NumberOfCSCSegment);
0160             const GeomDet* CSCgeomDet = globalTrackingGeometry_->idToDet(myChamber);
0161             SelectedSegments.push_back(
0162                 MuonTransientTrackingRecHit::specificBuild(CSCgeomDet, (TrackingRecHit*)&*segmentCSC));
0163           }
0164         }
0165         NumberOfCSCSegment++;
0166       }
0167     }
0168   }
0169 
0170   indexCollectionDT.push_back(positionDT);
0171   indexCollectionCSC.push_back(positionCSC);
0172 
0173   if (TrackRefitterType == "CosmicLike") {
0174     std::reverse(SelectedSegments.begin(), SelectedSegments.end());
0175   }
0176 
0177   return SelectedSegments;
0178 }