CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/Alignment/MuonAlignmentAlgorithms/src/SegmentToTrackAssociator.cc

Go to the documentation of this file.
00001 /*
00002  *  See header file for a description of this class.
00003  *
00004  *  $Date: 2010/03/29 13:18:43 $
00005  *  $Revision: 1.2 $
00006  *  \author P. Martinez - IFCA
00007  */
00008 
00009 
00010 #include "DataFormats/TrajectorySeed/interface/TrajectorySeedCollection.h"
00011 #include "DataFormats/TrackReco/interface/Track.h"
00012 #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
00013 #include "DataFormats/MuonDetId/interface/MuonSubdetId.h"
00014 #include "DataFormats/GeometryVector/interface/LocalPoint.h"
00015 #include "DataFormats/DetId/interface/DetId.h"
00016 #include "DataFormats/Common/interface/getRef.h"
00017 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00018 #include "DataFormats/DTRecHit/interface/DTRecSegment4D.h"
00019 #include "DataFormats/TrackingRecHit/interface/RecSegment.h"
00020 #include "DataFormats/DTRecHit/interface/DTRecSegment4DCollection.h"
00021 #include "DataFormats/CSCRecHit/interface/CSCSegmentCollection.h"
00022 #include "DataFormats/RPCRecHit/interface/RPCRecHitCollection.h"
00023 #include "DataFormats/DTRecHit/interface/DTRecHitCollection.h"
00024 #include "DataFormats/CSCRecHit/interface/CSCRecHit2DCollection.h"
00025 
00026 
00027 
00028 #include "MagneticField/Engine/interface/MagneticField.h"
00029 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00030 #include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h"
00031 #include "Geometry/CommonDetUnit/interface/GlobalTrackingGeometry.h"
00032 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
00033 
00034 #include "Alignment/MuonAlignmentAlgorithms/interface/SegmentToTrackAssociator.h"
00035 
00036 
00037 #include <vector>
00038 
00039 SegmentToTrackAssociator::SegmentToTrackAssociator( const edm::ParameterSet& iConfig )
00040 {
00041 
00042   theDTSegmentLabel = iConfig.getParameter<edm::InputTag>( "segmentsDT" );
00043   theCSCSegmentLabel = iConfig.getParameter<edm::InputTag>( "segmentsCSC" );
00044     
00045 }
00046 
00047 
00048 SegmentToTrackAssociator::~SegmentToTrackAssociator();
00049 
00050 
00051 void SegmentToTrackAssociator::clear()
00052 {
00053   indexCollectionDT.clear();
00054   indexCollectionCSC.clear();
00055 }
00056 
00057 MuonTransientTrackingRecHit::MuonRecHitContainer
00058   SegmentToTrackAssociator::associate( const edm::Event& iEvent, const edm::EventSetup& iSetup, const reco::Track& track, std::string TrackRefitterType)
00059 {
00060 
00061   // The segment collections
00062   edm::Handle<DTRecSegment4DCollection> DTSegments;
00063   iEvent.getByLabel(theDTSegmentLabel, DTSegments); 
00064 
00065   edm::Handle<CSCSegmentCollection> CSCSegments;
00066   iEvent.getByLabel(theCSCSegmentLabel, CSCSegments);
00067 
00068   edm::ESHandle<GlobalTrackingGeometry> theTrackingGeometry;
00069   iSetup.get<GlobalTrackingGeometryRecord>().get( theTrackingGeometry );
00070           
00071   MuonTransientTrackingRecHit::MuonRecHitContainer SelectedSegments;
00072           
00073   DTRecSegment4DCollection::const_iterator segmentDT;
00074   CSCSegmentCollection::const_iterator segmentCSC;
00075           
00076   std::vector<int> positionDT;
00077   std::vector<int> positionCSC;
00078   std::vector<TrackingRecHit *> my4DTrack;
00079           
00080   //Loop over the hits of the track
00081   for( unsigned int counter = 0; counter != track.recHitsSize()-1; counter++ )
00082   {
00083             
00084     TrackingRecHitRef myRef = track.recHit( counter );
00085     
00086     const TrackingRecHit *rechit = myRef.get();
00087     const GeomDet* geomDet = theTrackingGeometry->idToDet( rechit->geographicalId() );
00088             
00089     //It's a DT Hit
00090     if( geomDet->subDetector() == GeomDetEnumerators::DT )
00091     {
00092             
00093       //Take the layer associated to this hit
00094       DTLayerId myLayer( rechit->geographicalId().rawId() );
00095               
00096       int NumberOfDTSegment = 0;
00097       //Loop over segments
00098       for( segmentDT = DTSegments->begin(); segmentDT != DTSegments->end(); ++segmentDT ) {
00099         
00100         //By default the chamber associated to this Segment is new
00101         bool isNewChamber = true;
00102                 
00103         //Loop over segments already included in the vector of segments in the actual track
00104         for( std::vector<int>::iterator positionIt = positionDT.begin();
00105             positionIt != positionDT.end(); positionIt++ )
00106         {
00107           //If this segment has been used before isNewChamber = false
00108           if(NumberOfDTSegment == *positionIt) isNewChamber = false;
00109         }
00110         
00111         //Loop over vectors of segments associated to previous tracks
00112         for( std::vector<std::vector<int> >::iterator collect = indexCollectionDT.begin();
00113             collect != indexCollectionDT.end(); ++collect)
00114         {
00115           //Loop over segments associated to a track
00116           for( std::vector<int>::iterator positionIt = (*collect).begin();
00117               positionIt != (*collect).end(); positionIt++ )
00118           {
00119             //If this segment was used in a previos track then isNewChamber = false
00120             if( NumberOfDTSegment == *positionIt ) isNewChamber = false;
00121           }
00122         }
00123         
00124         //If the chamber is new
00125         if( isNewChamber )
00126         {
00127           DTChamberId myChamber( (*segmentDT).geographicalId().rawId() );
00128           //If the layer of the hit belongs to the chamber of the 4D Segment
00129           if( myLayer.wheel() == myChamber.wheel() &&
00130              myLayer.station() == myChamber.station() &&
00131              myLayer.sector() == myChamber.sector() )
00132           {
00133             //push position of the segment and tracking rechit
00134             positionDT.push_back( NumberOfDTSegment );
00135             const GeomDet* DTgeomDet = theTrackingGeometry->idToDet( myChamber );
00136             SelectedSegments.push_back( MuonTransientTrackingRecHit::specificBuild( DTgeomDet, (TrackingRecHit *) &*segmentDT ) );
00137 
00138             //edm::LogWarning("Alignment") << "TagSeg: " << "NumberOfDTSegment " << NumberOfDTSegment << " Wheel " << myChamber.wheel() << " Sector " <<  myChamber.sector() << " Chamber " << myChamber.station() << std::endl;
00139 
00140           }
00141         }
00142         NumberOfDTSegment++;
00143       }
00144       //In case is a CSC
00145     }
00146     else if ( geomDet->subDetector() == GeomDetEnumerators::CSC )
00147     {
00148       
00149       //Take the layer associated to this hit
00150       CSCDetId myLayer( rechit->geographicalId().rawId() );
00151       
00152       int NumberOfCSCSegment = 0;
00153       //Loop over 4Dsegments
00154       for( segmentCSC = CSCSegments->begin(); segmentCSC != CSCSegments->end(); segmentCSC++ )
00155       {
00156         
00157         //By default the chamber associated to the segment is new
00158         bool isNewChamber = true;
00159         //Loop over segments in the current track
00160         for( std::vector<int>::iterator positionIt = positionCSC.begin();
00161             positionIt != positionCSC.end(); positionIt++ )
00162         {
00163           //If this segment has been used then newchamber = false
00164           if( NumberOfCSCSegment == *positionIt ) isNewChamber = false;
00165         }
00166         //Loop over vectors of segments in previous tracks
00167         for( std::vector<std::vector<int> >::iterator collect = indexCollectionCSC.begin();
00168             collect != indexCollectionCSC.end(); ++collect )
00169         {
00170           //Loop over segments in a track
00171           for( std::vector<int>::iterator positionIt = (*collect).begin();
00172               positionIt != (*collect).end(); positionIt++ )
00173           {
00174             //If the segment was used in a previous track isNewChamber = false
00175             if( NumberOfCSCSegment == *positionIt ) isNewChamber = false;
00176           }
00177         }
00178         //If the chamber is new
00179         if( isNewChamber )
00180         {
00181           CSCDetId myChamber( (*segmentCSC).geographicalId().rawId() );
00182           //If the chambers are the same
00183           if( myLayer.chamberId() == myChamber.chamberId() )
00184           {
00185             //push
00186             positionCSC.push_back( NumberOfCSCSegment );
00187             const GeomDet* CSCgeomDet = theTrackingGeometry->idToDet( myChamber );
00188             SelectedSegments.push_back(MuonTransientTrackingRecHit::specificBuild( CSCgeomDet, (TrackingRecHit *) &*segmentCSC ) );
00189           }
00190         }
00191         NumberOfCSCSegment++;
00192       }
00193     }
00194   }
00195   
00196   indexCollectionDT.push_back(positionDT);
00197   indexCollectionCSC.push_back(positionCSC);
00198 
00199 
00200   if ( TrackRefitterType == "CosmicLike" )
00201   {
00202     std::reverse(SelectedSegments.begin(),SelectedSegments.end());
00203   }
00204  
00205   return SelectedSegments;
00206 
00207 }
00208