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