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