CMS 3D CMS Logo

TrackerMuonHitExtractor.cc
Go to the documentation of this file.
1 //
2 // modified & integrated by Giovanni Abbiendi
3 // from code by Arun Luthra:
4 // UserCode/luthra/MuonTrackSelector/src/MuonTrackSelector.cc
5 //
14 #include <sstream>
15 
17  : inputDTRecSegment4DToken_(
18  ic.consumes<DTRecSegment4DCollection>(parset.getParameter<edm::InputTag>("inputDTRecSegment4DCollection"))),
19  inputCSCSegmentToken_(
20  ic.consumes<CSCSegmentCollection>(parset.getParameter<edm::InputTag>("inputCSCSegmentCollection"))),
21  inputDTRecSegment4DCollection_(parset.getParameter<edm::InputTag>("inputDTRecSegment4DCollection")),
22  inputCSCSegmentCollection_(parset.getParameter<edm::InputTag>("inputCSCSegmentCollection")) {}
23 
25  : inputDTRecSegment4DCollection_(parset.getParameter<edm::InputTag>("inputDTRecSegment4DCollection")),
26  inputCSCSegmentCollection_(parset.getParameter<edm::InputTag>("inputCSCSegmentCollection")) {}
27 
29 
33 
34  edm::LogVerbatim("TrackerMuonHitExtractor") << "\nThere are " << dtSegmentCollectionH_->size() << " DT segments.";
35  unsigned int index_dt_segment = 0;
37  segment != dtSegmentCollectionH_->end();
38  ++segment, index_dt_segment++) {
39  LocalPoint segmentLocalPosition = segment->localPosition();
40  LocalVector segmentLocalDirection = segment->localDirection();
41  LocalError segmentLocalPositionError = segment->localPositionError();
42  LocalError segmentLocalDirectionError = segment->localDirectionError();
43  DetId geoid = segment->geographicalId();
44  DTChamberId dtdetid = DTChamberId(geoid);
45  int wheel = dtdetid.wheel();
46  int station = dtdetid.station();
47  int sector = dtdetid.sector();
48 
49  float segmentX = segmentLocalPosition.x();
50  float segmentY = segmentLocalPosition.y();
51  float segmentdXdZ = segmentLocalDirection.x() / segmentLocalDirection.z();
52  float segmentdYdZ = segmentLocalDirection.y() / segmentLocalDirection.z();
53  float segmentXerr = sqrt(segmentLocalPositionError.xx());
54  float segmentYerr = sqrt(segmentLocalPositionError.yy());
55  float segmentdXdZerr = sqrt(segmentLocalDirectionError.xx());
56  float segmentdYdZerr = sqrt(segmentLocalDirectionError.yy());
57 
58  edm::LogVerbatim("TrackerMuonHitExtractor")
59  << "\nDT segment index :" << index_dt_segment << "\nchamber Wh:" << wheel << ",St:" << station
60  << ",Se:" << sector << "\nLocal Position (X,Y)=(" << segmentX << "," << segmentY << ") +/- (" << segmentXerr
61  << "," << segmentYerr << "), "
62  << "Local Direction (dXdZ,dYdZ)=(" << segmentdXdZ << "," << segmentdYdZ << ") +/- (" << segmentdXdZerr << ","
63  << segmentdYdZerr << ")";
64  }
65 
66  edm::LogVerbatim("TrackerMuonHitExtractor") << "\nThere are " << cscSegmentCollectionH_->size() << " CSC segments.";
67  unsigned int index_csc_segment = 0;
69  segment != cscSegmentCollectionH_->end();
70  ++segment, index_csc_segment++) {
71  LocalPoint segmentLocalPosition = segment->localPosition();
72  LocalVector segmentLocalDirection = segment->localDirection();
73  LocalError segmentLocalPositionError = segment->localPositionError();
74  LocalError segmentLocalDirectionError = segment->localDirectionError();
75 
76  DetId geoid = segment->geographicalId();
77  CSCDetId cscdetid = CSCDetId(geoid);
78  int endcap = cscdetid.endcap();
79  int station = cscdetid.station();
80  int ring = cscdetid.ring();
81  int chamber = cscdetid.chamber();
82 
83  float segmentX = segmentLocalPosition.x();
84  float segmentY = segmentLocalPosition.y();
85  float segmentdXdZ = segmentLocalDirection.x() / segmentLocalDirection.z();
86  float segmentdYdZ = segmentLocalDirection.y() / segmentLocalDirection.z();
87  float segmentXerr = sqrt(segmentLocalPositionError.xx());
88  float segmentYerr = sqrt(segmentLocalPositionError.yy());
89  float segmentdXdZerr = sqrt(segmentLocalDirectionError.xx());
90  float segmentdYdZerr = sqrt(segmentLocalDirectionError.yy());
91 
92  edm::LogVerbatim("TrackerMuonHitExtractor")
93  << "\nCSC segment index :" << index_csc_segment << "\nchamber Endcap:" << endcap << ",St:" << station
94  << ",Ri:" << ring << ",Ch:" << chamber << "\nLocal Position (X,Y)=(" << segmentX << "," << segmentY << ") +/- ("
95  << segmentXerr << "," << segmentYerr << "), "
96  << "Local Direction (dXdZ,dYdZ)=(" << segmentdXdZ << "," << segmentdYdZ << ") +/- (" << segmentdXdZerr << ","
97  << segmentdYdZerr << ")";
98  }
99 }
100 std::vector<const TrackingRecHit *> TrackerMuonHitExtractor::getMuonHits(const reco::Muon &mu) const {
101  std::vector<const TrackingRecHit *> ret;
102 
103  int wheel, station, sector;
104  int endcap, /*station, */ ring, chamber;
105 
106  edm::LogVerbatim("TrackerMuonHitExtractor")
107  << "Number of chambers: " << mu.matches().size()
109  << ", tot (no arbitration): " << mu.numberOfMatches(reco::Muon::NoArbitration);
110  unsigned int index_chamber = 0;
111  int n_segments_noArb = 0;
112 
113  for (std::vector<reco::MuonChamberMatch>::const_iterator chamberMatch = mu.matches().begin();
114  chamberMatch != mu.matches().end();
115  ++chamberMatch, index_chamber++) {
116  std::stringstream chamberStr;
117  chamberStr << "\nchamber index: " << index_chamber;
118 
119  int subdet = chamberMatch->detector();
120  DetId did = chamberMatch->id;
121 
122  if (subdet == MuonSubdetId::DT) {
123  DTChamberId dtdetid = DTChamberId(did);
124  wheel = dtdetid.wheel();
125  station = dtdetid.station();
126  sector = dtdetid.sector();
127  chamberStr << ", DT chamber Wh:" << wheel << ",St:" << station << ",Se:" << sector;
128  } else if (subdet == MuonSubdetId::CSC) {
129  CSCDetId cscdetid = CSCDetId(did);
130  endcap = cscdetid.endcap();
131  station = cscdetid.station();
132  ring = cscdetid.ring();
133  chamber = cscdetid.chamber();
134  chamberStr << ", CSC chamber End:" << endcap << ",St:" << station << ",Ri:" << ring << ",Ch:" << chamber;
135  }
136 
137  chamberStr << ", Number of segments: " << chamberMatch->segmentMatches.size();
138  edm::LogVerbatim("TrackerMuonHitExtractor") << chamberStr.str();
139  n_segments_noArb = n_segments_noArb + chamberMatch->segmentMatches.size();
140 
141  unsigned int index_segment = 0;
142 
143  for (std::vector<reco::MuonSegmentMatch>::const_iterator segmentMatch = chamberMatch->segmentMatches.begin();
144  segmentMatch != chamberMatch->segmentMatches.end();
145  ++segmentMatch, index_segment++) {
146  float segmentX = segmentMatch->x;
147  float segmentY = segmentMatch->y;
148  float segmentdXdZ = segmentMatch->dXdZ;
149  float segmentdYdZ = segmentMatch->dYdZ;
150  float segmentXerr = segmentMatch->xErr;
151  float segmentYerr = segmentMatch->yErr;
152  float segmentdXdZerr = segmentMatch->dXdZErr;
153  float segmentdYdZerr = segmentMatch->dYdZErr;
154 
155  CSCSegmentRef segmentCSC = segmentMatch->cscSegmentRef;
156  DTRecSegment4DRef segmentDT = segmentMatch->dtSegmentRef;
157 
158  bool segment_arbitrated_Ok = (segmentMatch->isMask(reco::MuonSegmentMatch::BestInChamberByDR) &&
159  segmentMatch->isMask(reco::MuonSegmentMatch::BelongsToTrackByDR));
160 
161  std::string ARBITRATED(" ***Arbitrated Off*** ");
162  if (segment_arbitrated_Ok)
163  ARBITRATED = " ***ARBITRATED OK*** ";
164 
165  if (subdet == MuonSubdetId::DT) {
166  edm::LogVerbatim("TrackerMuonHitExtractor")
167  << "\n\t segment index: " << index_segment << ARBITRATED << "\n\t Local Position (X,Y)=(" << segmentX
168  << "," << segmentY << ") +/- (" << segmentXerr << "," << segmentYerr << "), "
169  << "\n\t Local Direction (dXdZ,dYdZ)=(" << segmentdXdZ << "," << segmentdYdZ << ") +/- (" << segmentdXdZerr
170  << "," << segmentdYdZerr << ")";
171 
172  // with the following line the DT segments failing standard arbitration
173  // are skipped
174  if (!segment_arbitrated_Ok)
175  continue;
176 
177  if (segmentDT.get() != nullptr) {
178  const DTRecSegment4D *segment = segmentDT.get();
179 
180  edm::LogVerbatim("TrackerMuonHitExtractor")
181  << "\t ===> MATCHING with DT segment with index = " << segmentDT.key();
182 
183  if (segment->hasPhi()) {
184  const DTChamberRecSegment2D *phiSeg = segment->phiSegment();
185  std::vector<const TrackingRecHit *> phiHits = phiSeg->recHits();
186  for (std::vector<const TrackingRecHit *>::const_iterator ihit = phiHits.begin(); ihit != phiHits.end();
187  ++ihit) {
188  ret.push_back(*ihit);
189  }
190  }
191 
192  if (segment->hasZed()) {
193  const DTSLRecSegment2D *zSeg = (*segment).zSegment();
194  std::vector<const TrackingRecHit *> zedHits = zSeg->recHits();
195  for (std::vector<const TrackingRecHit *>::const_iterator ihit = zedHits.begin(); ihit != zedHits.end();
196  ++ihit) {
197  ret.push_back(*ihit);
198  }
199  }
200  } else
201  edm::LogWarning("TrackerMuonHitExtractor") << "\n***WARNING: UNMATCHED DT segment ! \n";
202  } // if (subdet == MuonSubdetId::DT)
203 
204  else if (subdet == MuonSubdetId::CSC) {
205  edm::LogVerbatim("TrackerMuonHitExtractor")
206  << "\n\t segment index: " << index_segment << ARBITRATED << "\n\t Local Position (X,Y)=(" << segmentX
207  << "," << segmentY << ") +/- (" << segmentXerr << "," << segmentYerr << "), "
208  << "\n\t Local Direction (dXdZ,dYdZ)=(" << segmentdXdZ << "," << segmentdYdZ << ") +/- (" << segmentdXdZerr
209  << "," << segmentdYdZerr << ")";
210 
211  // with the following line the CSC segments failing standard arbitration
212  // are skipped
213  if (!segment_arbitrated_Ok)
214  continue;
215 
216  if (segmentCSC.get() != nullptr) {
217  const CSCSegment *segment = segmentCSC.get();
218 
219  edm::LogVerbatim("TrackerMuonHitExtractor")
220  << "\t ===> MATCHING with CSC segment with index = " << segmentCSC.key();
221 
222  std::vector<const TrackingRecHit *> hits = segment->recHits();
223  for (std::vector<const TrackingRecHit *>::const_iterator ihit = hits.begin(); ihit != hits.end(); ++ihit) {
224  ret.push_back(*ihit);
225  }
226  } else
227  edm::LogWarning("TrackerMuonHitExtractor") << "\n***WARNING: UNMATCHED CSC segment ! \n";
228  } // else if (subdet == MuonSubdetId::CSC)
229 
230  } // loop on vector<MuonSegmentMatch>
231  } // loop on vector<MuonChamberMatch>
232 
233  edm::LogVerbatim("TrackerMuonHitExtractor") << "\n N. matched Segments before arbitration = " << n_segments_noArb;
234 
235  return ret;
236 }
int chamber() const
Definition: CSCDetId.h:68
edm::InputTag inputDTRecSegment4DCollection_
float xx() const
Definition: LocalError.h:24
std::vector< const TrackingRecHit * > getMuonHits(const reco::Muon &mu) const
const DTChamberRecSegment2D * phiSegment() const
The superPhi segment: 0 if no phi projection available.
T y() const
Definition: PV3DBase.h:63
key_type key() const
Accessor for product key.
Definition: Ref.h:263
edm::Handle< CSCSegmentCollection > cscSegmentCollectionH_
int endcap() const
Definition: CSCDetId.h:93
C::const_iterator const_iterator
constant access iterator type
Definition: RangeMap.h:43
int iEvent
Definition: GenABIO.cc:224
float yy() const
Definition: LocalError.h:26
T sqrt(T t)
Definition: SSEVec.h:18
T z() const
Definition: PV3DBase.h:64
const int mu
Definition: Constants.h:22
static const unsigned int BestInChamberByDR
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:243
bool hasPhi() const
Does it have the Phi projection?
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:480
void init(const edm::Event &, const edm::EventSetup &)
edm::Handle< DTRecSegment4DCollection > dtSegmentCollectionH_
int ring() const
Definition: CSCDetId.h:75
bool hasZed() const
Does it have the Z projection?
Definition: DetId.h:18
std::vector< const TrackingRecHit * > recHits() const override
Access to component RecHits (if any)
Definition: CSCSegment.cc:30
std::vector< MuonChamberMatch > & matches()
get muon matching information
Definition: Muon.h:144
int numberOfMatches(ArbitrationType type=SegmentAndTrackArbitration) const
get number of chambers with matched segments
static const unsigned int BelongsToTrackByDR
TrackerMuonHitExtractor(const edm::ParameterSet &, edm::ConsumesCollector &&ic)
HLT enums.
int sector() const
Definition: DTChamberId.h:61
std::vector< const TrackingRecHit * > recHits() const override
Access to component RecHits (if any)
int station() const
Definition: CSCDetId.h:86
static constexpr int DT
Definition: MuonSubdetId.h:12
int station() const
Return the station number.
Definition: DTChamberId.h:51
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:45
static constexpr int CSC
Definition: MuonSubdetId.h:13
T x() const
Definition: PV3DBase.h:62