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 
24 
30 
32 
33 #include <vector>
34 
36  theDTSegmentLabel = iConfig.getParameter<edm::InputTag>("segmentsDT");
37  theCSCSegmentLabel = iConfig.getParameter<edm::InputTag>("segmentsCSC");
38 }
39 
41 
43  indexCollectionDT.clear();
44  indexCollectionCSC.clear();
45 }
46 
48  const edm::EventSetup& iSetup,
49  const reco::Track& track,
50  std::string TrackRefitterType) {
51  // The segment collections
53  iEvent.getByLabel(theDTSegmentLabel, DTSegments);
54 
56  iEvent.getByLabel(theCSCSegmentLabel, CSCSegments);
57 
58  edm::ESHandle<GlobalTrackingGeometry> theTrackingGeometry;
59  iSetup.get<GlobalTrackingGeometryRecord>().get(theTrackingGeometry);
60 
62 
65 
66  std::vector<int> positionDT;
67  std::vector<int> positionCSC;
68  std::vector<TrackingRecHit*> my4DTrack;
69 
70  //Loop over the hits of the track
71  for (unsigned int counter = 0; counter != track.recHitsSize() - 1; counter++) {
72  TrackingRecHitRef myRef = track.recHit(counter);
73 
74  const TrackingRecHit* rechit = myRef.get();
75  const GeomDet* geomDet = theTrackingGeometry->idToDet(rechit->geographicalId());
76 
77  //It's a DT Hit
78  if (geomDet->subDetector() == GeomDetEnumerators::DT) {
79  //Take the layer associated to this hit
80  DTLayerId myLayer(rechit->geographicalId().rawId());
81 
82  int NumberOfDTSegment = 0;
83  //Loop over segments
84  for (segmentDT = DTSegments->begin(); segmentDT != DTSegments->end(); ++segmentDT) {
85  //By default the chamber associated to this Segment is new
86  bool isNewChamber = true;
87 
88  //Loop over segments already included in the vector of segments in the actual track
89  for (std::vector<int>::iterator positionIt = positionDT.begin(); positionIt != positionDT.end(); positionIt++) {
90  //If this segment has been used before isNewChamber = false
91  if (NumberOfDTSegment == *positionIt)
92  isNewChamber = false;
93  }
94 
95  //Loop over vectors of segments associated to previous tracks
96  for (std::vector<std::vector<int> >::iterator collect = indexCollectionDT.begin();
97  collect != indexCollectionDT.end();
98  ++collect) {
99  //Loop over segments associated to a track
100  for (std::vector<int>::iterator positionIt = (*collect).begin(); positionIt != (*collect).end();
101  positionIt++) {
102  //If this segment was used in a previos track then isNewChamber = false
103  if (NumberOfDTSegment == *positionIt)
104  isNewChamber = false;
105  }
106  }
107 
108  //If the chamber is new
109  if (isNewChamber) {
110  DTChamberId myChamber((*segmentDT).geographicalId().rawId());
111  //If the layer of the hit belongs to the chamber of the 4D Segment
112  if (myLayer.wheel() == myChamber.wheel() && myLayer.station() == myChamber.station() &&
113  myLayer.sector() == myChamber.sector()) {
114  //push position of the segment and tracking rechit
115  positionDT.push_back(NumberOfDTSegment);
116  const GeomDet* DTgeomDet = theTrackingGeometry->idToDet(myChamber);
117  SelectedSegments.push_back(
119 
120  //edm::LogWarning("Alignment") << "TagSeg: " << "NumberOfDTSegment " << NumberOfDTSegment << " Wheel " << myChamber.wheel() << " Sector " << myChamber.sector() << " Chamber " << myChamber.station() << std::endl;
121  }
122  }
123  NumberOfDTSegment++;
124  }
125  //In case is a CSC
126  } else if (geomDet->subDetector() == GeomDetEnumerators::CSC) {
127  //Take the layer associated to this hit
128  CSCDetId myLayer(rechit->geographicalId().rawId());
129 
130  int NumberOfCSCSegment = 0;
131  //Loop over 4Dsegments
132  for (segmentCSC = CSCSegments->begin(); segmentCSC != CSCSegments->end(); segmentCSC++) {
133  //By default the chamber associated to the segment is new
134  bool isNewChamber = true;
135  //Loop over segments in the current track
136  for (std::vector<int>::iterator positionIt = positionCSC.begin(); positionIt != positionCSC.end();
137  positionIt++) {
138  //If this segment has been used then newchamber = false
139  if (NumberOfCSCSegment == *positionIt)
140  isNewChamber = false;
141  }
142  //Loop over vectors of segments in previous tracks
143  for (std::vector<std::vector<int> >::iterator collect = indexCollectionCSC.begin();
144  collect != indexCollectionCSC.end();
145  ++collect) {
146  //Loop over segments in a track
147  for (std::vector<int>::iterator positionIt = (*collect).begin(); positionIt != (*collect).end();
148  positionIt++) {
149  //If the segment was used in a previous track isNewChamber = false
150  if (NumberOfCSCSegment == *positionIt)
151  isNewChamber = false;
152  }
153  }
154  //If the chamber is new
155  if (isNewChamber) {
156  CSCDetId myChamber((*segmentCSC).geographicalId().rawId());
157  //If the chambers are the same
158  if (myLayer.chamberId() == myChamber.chamberId()) {
159  //push
160  positionCSC.push_back(NumberOfCSCSegment);
161  const GeomDet* CSCgeomDet = theTrackingGeometry->idToDet(myChamber);
162  SelectedSegments.push_back(
163  MuonTransientTrackingRecHit::specificBuild(CSCgeomDet, (TrackingRecHit*)&*segmentCSC));
164  }
165  }
166  NumberOfCSCSegment++;
167  }
168  }
169  }
170 
171  indexCollectionDT.push_back(positionDT);
172  indexCollectionCSC.push_back(positionCSC);
173 
174  if (TrackRefitterType == "CosmicLike") {
175  std::reverse(SelectedSegments.begin(), SelectedSegments.end());
176  }
177 
178  return SelectedSegments;
179 }
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:97
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
C::const_iterator const_iterator
constant access iterator type
Definition: RangeMap.h:43
int iEvent
Definition: GenABIO.cc:224
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:232
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:488
MuonTransientTrackingRecHit::MuonRecHitContainer associate(const edm::Event &, const edm::EventSetup &, const reco::Track &, std::string)
TrackingRecHitRef recHit(size_t i) const
Get i-th hit on the track.
Definition: Track.h:94
T get() const
Definition: EventSetup.h:73
const GeomDet * idToDet(DetId) const override
DetId geographicalId() const
virtual SubDetector subDetector() const
Which subdetector.
Definition: GeomDet.cc:38
static MuonRecHitPointer specificBuild(const GeomDet *geom, const TrackingRecHit *rh)
std::vector< MuonRecHitPointer > MuonRecHitContainer
SegmentToTrackAssociator(const edm::ParameterSet &)