Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:56:50

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/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   // The segment collections
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   //Loop over the hits of the track
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     //It's a DT Hit
0073     if (geomDet->subDetector() == GeomDetEnumerators::DT) {
0074       //Take the layer associated to this hit
0075       DTLayerId myLayer(rechit->geographicalId().rawId());
0076 
0077       int NumberOfDTSegment = 0;
0078       //Loop over segments
0079       for (segmentDT = DTSegments->begin(); segmentDT != DTSegments->end(); ++segmentDT) {
0080         //By default the chamber associated to this Segment is new
0081         bool isNewChamber = true;
0082 
0083         //Loop over segments already included in the vector of segments in the actual track
0084         for (std::vector<int>::iterator positionIt = positionDT.begin(); positionIt != positionDT.end(); positionIt++) {
0085           //If this segment has been used before isNewChamber = false
0086           if (NumberOfDTSegment == *positionIt)
0087             isNewChamber = false;
0088         }
0089 
0090         //Loop over vectors of segments associated to previous tracks
0091         for (std::vector<std::vector<int> >::iterator collect = indexCollectionDT.begin();
0092              collect != indexCollectionDT.end();
0093              ++collect) {
0094           //Loop over segments associated to a track
0095           for (std::vector<int>::iterator positionIt = (*collect).begin(); positionIt != (*collect).end();
0096                positionIt++) {
0097             //If this segment was used in a previos track then isNewChamber = false
0098             if (NumberOfDTSegment == *positionIt)
0099               isNewChamber = false;
0100           }
0101         }
0102 
0103         //If the chamber is new
0104         if (isNewChamber) {
0105           DTChamberId myChamber((*segmentDT).geographicalId().rawId());
0106           //If the layer of the hit belongs to the chamber of the 4D Segment
0107           if (myLayer.wheel() == myChamber.wheel() && myLayer.station() == myChamber.station() &&
0108               myLayer.sector() == myChamber.sector()) {
0109             //push position of the segment and tracking rechit
0110             positionDT.push_back(NumberOfDTSegment);
0111             const GeomDet* DTgeomDet = globalTrackingGeometry_->idToDet(myChamber);
0112             SelectedSegments.push_back(
0113                 MuonTransientTrackingRecHit::specificBuild(DTgeomDet, (TrackingRecHit*)&*segmentDT));
0114 
0115             //edm::LogWarning("Alignment") << "TagSeg: " << "NumberOfDTSegment " << NumberOfDTSegment << " Wheel " << myChamber.wheel() << " Sector " <<  myChamber.sector() << " Chamber " << myChamber.station() << std::endl;
0116           }
0117         }
0118         NumberOfDTSegment++;
0119       }
0120       //In case is a CSC
0121     } else if (geomDet->subDetector() == GeomDetEnumerators::CSC) {
0122       //Take the layer associated to this hit
0123       CSCDetId myLayer(rechit->geographicalId().rawId());
0124 
0125       int NumberOfCSCSegment = 0;
0126       //Loop over 4Dsegments
0127       for (segmentCSC = CSCSegments->begin(); segmentCSC != CSCSegments->end(); segmentCSC++) {
0128         //By default the chamber associated to the segment is new
0129         bool isNewChamber = true;
0130         //Loop over segments in the current track
0131         for (std::vector<int>::iterator positionIt = positionCSC.begin(); positionIt != positionCSC.end();
0132              positionIt++) {
0133           //If this segment has been used then newchamber = false
0134           if (NumberOfCSCSegment == *positionIt)
0135             isNewChamber = false;
0136         }
0137         //Loop over vectors of segments in previous tracks
0138         for (std::vector<std::vector<int> >::iterator collect = indexCollectionCSC.begin();
0139              collect != indexCollectionCSC.end();
0140              ++collect) {
0141           //Loop over segments in a track
0142           for (std::vector<int>::iterator positionIt = (*collect).begin(); positionIt != (*collect).end();
0143                positionIt++) {
0144             //If the segment was used in a previous track isNewChamber = false
0145             if (NumberOfCSCSegment == *positionIt)
0146               isNewChamber = false;
0147           }
0148         }
0149         //If the chamber is new
0150         if (isNewChamber) {
0151           CSCDetId myChamber((*segmentCSC).geographicalId().rawId());
0152           //If the chambers are the same
0153           if (myLayer.chamberId() == myChamber.chamberId()) {
0154             //push
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 }