CMS 3D CMS Logo

SegmentToTrackAssociator.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * $Date: 2010/03/29 13:18:43 $
5  * $Revision: 1.2 $
6  * \author P. Martinez - IFCA
7  */
8 
9 
25 
26 
27 
33 
35 
36 
37 #include <vector>
38 
40 {
41 
42  theDTSegmentLabel = iConfig.getParameter<edm::InputTag>( "segmentsDT" );
43  theCSCSegmentLabel = iConfig.getParameter<edm::InputTag>( "segmentsCSC" );
44 
45 }
46 
47 
49 
50 
52 {
53  indexCollectionDT.clear();
54  indexCollectionCSC.clear();
55 }
56 
59 {
60 
61  // The segment collections
63  iEvent.getByLabel(theDTSegmentLabel, DTSegments);
64 
66  iEvent.getByLabel(theCSCSegmentLabel, CSCSegments);
67 
68  edm::ESHandle<GlobalTrackingGeometry> theTrackingGeometry;
69  iSetup.get<GlobalTrackingGeometryRecord>().get( theTrackingGeometry );
70 
72 
75 
76  std::vector<int> positionDT;
77  std::vector<int> positionCSC;
78  std::vector<TrackingRecHit *> my4DTrack;
79 
80  //Loop over the hits of the track
81  for( unsigned int counter = 0; counter != track.recHitsSize()-1; counter++ )
82  {
83 
84  TrackingRecHitRef myRef = track.recHit( counter );
85 
86  const TrackingRecHit *rechit = myRef.get();
87  const GeomDet* geomDet = theTrackingGeometry->idToDet( rechit->geographicalId() );
88 
89  //It's a DT Hit
90  if( geomDet->subDetector() == GeomDetEnumerators::DT )
91  {
92 
93  //Take the layer associated to this hit
94  DTLayerId myLayer( rechit->geographicalId().rawId() );
95 
96  int NumberOfDTSegment = 0;
97  //Loop over segments
98  for( segmentDT = DTSegments->begin(); segmentDT != DTSegments->end(); ++segmentDT ) {
99 
100  //By default the chamber associated to this Segment is new
101  bool isNewChamber = true;
102 
103  //Loop over segments already included in the vector of segments in the actual track
104  for( std::vector<int>::iterator positionIt = positionDT.begin();
105  positionIt != positionDT.end(); positionIt++ )
106  {
107  //If this segment has been used before isNewChamber = false
108  if(NumberOfDTSegment == *positionIt) isNewChamber = false;
109  }
110 
111  //Loop over vectors of segments associated to previous tracks
112  for( std::vector<std::vector<int> >::iterator collect = indexCollectionDT.begin();
113  collect != indexCollectionDT.end(); ++collect)
114  {
115  //Loop over segments associated to a track
116  for( std::vector<int>::iterator positionIt = (*collect).begin();
117  positionIt != (*collect).end(); positionIt++ )
118  {
119  //If this segment was used in a previos track then isNewChamber = false
120  if( NumberOfDTSegment == *positionIt ) isNewChamber = false;
121  }
122  }
123 
124  //If the chamber is new
125  if( isNewChamber )
126  {
127  DTChamberId myChamber( (*segmentDT).geographicalId().rawId() );
128  //If the layer of the hit belongs to the chamber of the 4D Segment
129  if( myLayer.wheel() == myChamber.wheel() &&
130  myLayer.station() == myChamber.station() &&
131  myLayer.sector() == myChamber.sector() )
132  {
133  //push position of the segment and tracking rechit
134  positionDT.push_back( NumberOfDTSegment );
135  const GeomDet* DTgeomDet = theTrackingGeometry->idToDet( myChamber );
136  SelectedSegments.push_back( MuonTransientTrackingRecHit::specificBuild( DTgeomDet, (TrackingRecHit *) &*segmentDT ) );
137 
138  //edm::LogWarning("Alignment") << "TagSeg: " << "NumberOfDTSegment " << NumberOfDTSegment << " Wheel " << myChamber.wheel() << " Sector " << myChamber.sector() << " Chamber " << myChamber.station() << std::endl;
139 
140  }
141  }
142  NumberOfDTSegment++;
143  }
144  //In case is a CSC
145  }
146  else if ( geomDet->subDetector() == GeomDetEnumerators::CSC )
147  {
148 
149  //Take the layer associated to this hit
150  CSCDetId myLayer( rechit->geographicalId().rawId() );
151 
152  int NumberOfCSCSegment = 0;
153  //Loop over 4Dsegments
154  for( segmentCSC = CSCSegments->begin(); segmentCSC != CSCSegments->end(); segmentCSC++ )
155  {
156 
157  //By default the chamber associated to the segment is new
158  bool isNewChamber = true;
159  //Loop over segments in the current track
160  for( std::vector<int>::iterator positionIt = positionCSC.begin();
161  positionIt != positionCSC.end(); positionIt++ )
162  {
163  //If this segment has been used then newchamber = false
164  if( NumberOfCSCSegment == *positionIt ) isNewChamber = false;
165  }
166  //Loop over vectors of segments in previous tracks
167  for( std::vector<std::vector<int> >::iterator collect = indexCollectionCSC.begin();
168  collect != indexCollectionCSC.end(); ++collect )
169  {
170  //Loop over segments in a track
171  for( std::vector<int>::iterator positionIt = (*collect).begin();
172  positionIt != (*collect).end(); positionIt++ )
173  {
174  //If the segment was used in a previous track isNewChamber = false
175  if( NumberOfCSCSegment == *positionIt ) isNewChamber = false;
176  }
177  }
178  //If the chamber is new
179  if( isNewChamber )
180  {
181  CSCDetId myChamber( (*segmentCSC).geographicalId().rawId() );
182  //If the chambers are the same
183  if( myLayer.chamberId() == myChamber.chamberId() )
184  {
185  //push
186  positionCSC.push_back( NumberOfCSCSegment );
187  const GeomDet* CSCgeomDet = theTrackingGeometry->idToDet( myChamber );
188  SelectedSegments.push_back(MuonTransientTrackingRecHit::specificBuild( CSCgeomDet, (TrackingRecHit *) &*segmentCSC ) );
189  }
190  }
191  NumberOfCSCSegment++;
192  }
193  }
194  }
195 
196  indexCollectionDT.push_back(positionDT);
197  indexCollectionCSC.push_back(positionCSC);
198 
199 
200  if ( TrackRefitterType == "CosmicLike" )
201  {
202  std::reverse(SelectedSegments.begin(),SelectedSegments.end());
203  }
204 
205  return SelectedSegments;
206 
207 }
208 
T getParameter(std::string const &) const
size_t recHitsSize() const
Get number of RecHits. (Warning, this includes invalid hits, which are not physical hits)...
Definition: Track.h:119
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
virtual const GeomDet * idToDet(DetId) const
int iEvent
Definition: GenABIO.cc:230
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:244
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:416
MuonTransientTrackingRecHit::MuonRecHitContainer associate(const edm::Event &, const edm::EventSetup &, const reco::Track &, std::string)
const T & get() const
Definition: EventSetup.h:56
TrackingRecHitRef recHit(size_t i) const
Get i-th hit on the track.
Definition: Track.h:114
DetId geographicalId() const
virtual SubDetector subDetector() const
Which subdetector.
Definition: GeomDet.cc:44
static MuonRecHitPointer specificBuild(const GeomDet *geom, const TrackingRecHit *rh)
std::vector< MuonRecHitPointer > MuonRecHitContainer
SegmentToTrackAssociator(const edm::ParameterSet &)