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()
108  << ", arbitrated: " << mu.numberOfMatches(reco::Muon::SegmentAndTrackArbitration)
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 }
Vector3DBase< float, LocalTag >
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:367
DTSLRecSegment2D
Definition: DTSLRecSegment2D.h:15
MuonSubdetId::CSC
static constexpr int CSC
Definition: MuonSubdetId.h:12
DTRecSegment4D
Definition: DTRecSegment4D.h:23
TrackerMuonHitExtractor.h
MessageLogger.h
reco::Muon::SegmentAndTrackArbitration
Definition: Muon.h:190
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
amptDefaultParameters_cff.mu
mu
Definition: amptDefaultParameters_cff.py:16
relativeConstraints.station
station
Definition: relativeConstraints.py:67
edm
HLT enums.
Definition: AlignableModifier.h:19
CSCDetId::ring
int ring() const
Definition: CSCDetId.h:68
TrackerMuonHitExtractor::cscSegmentCollectionH_
edm::Handle< CSCSegmentCollection > cscSegmentCollectionH_
Definition: TrackerMuonHitExtractor.h:29
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89353
edm::Ref::get
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:232
TrackerMuonHitExtractor::inputCSCSegmentCollection_
edm::InputTag inputCSCSegmentCollection_
Definition: TrackerMuonHitExtractor.h:34
CSCSegmentCollection
makeMuonMisalignmentScenario.endcap
endcap
Definition: makeMuonMisalignmentScenario.py:320
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
TrackerMuonHitExtractor::getMuonHits
std::vector< const TrackingRecHit * > getMuonHits(const reco::Muon &mu) const
Definition: TrackerMuonHitExtractor.cc:100
reco::MuonSegmentMatch::BelongsToTrackByDR
static const unsigned int BelongsToTrackByDR
Definition: MuonSegmentMatch.h:25
CSCDetId.h
reco::Muon
Definition: Muon.h:27
edm::Ref< CSCSegmentCollection >
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
DTRecSegment2D::recHits
std::vector< const TrackingRecHit * > recHits() const override
Access to component RecHits (if any)
Definition: DTRecSegment2D.cc:86
DetId
Definition: DetId.h:17
Track.h
TrackFwd.h
LocalError::xx
float xx() const
Definition: LocalError.h:22
MuonSelectors.h
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
TrackerMuonHitExtractor::init
void init(const edm::Event &, const edm::EventSetup &)
Definition: TrackerMuonHitExtractor.cc:30
MuonSubdetId::DT
static constexpr int DT
Definition: MuonSubdetId.h:11
Point3DBase< float, LocalTag >
DTRecSegment4DCollection
DTChamberId.h
CSCSegment
Definition: CSCSegment.h:21
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
reco::Muon::NoArbitration
Definition: Muon.h:188
edm::ParameterSet
Definition: ParameterSet.h:47
LocalError
Definition: LocalError.h:12
edm::RangeMap::const_iterator
C::const_iterator const_iterator
constant access iterator type
Definition: RangeMap.h:43
CSCDetId
Definition: CSCDetId.h:26
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
makeMuonMisalignmentScenario.wheel
wheel
Definition: makeMuonMisalignmentScenario.py:319
iEvent
int iEvent
Definition: GenABIO.cc:224
DTChamberRecSegment2D
Definition: DTChamberRecSegment2D.h:31
CSCDetId::chamber
int chamber() const
Definition: CSCDetId.h:62
edm::EventSetup
Definition: EventSetup.h:57
TrackerMuonHitExtractor::dtSegmentCollectionH_
edm::Handle< DTRecSegment4DCollection > dtSegmentCollectionH_
Definition: TrackerMuonHitExtractor.h:28
MuonSubdetId.h
DTChamberId::sector
int sector() const
Definition: DTChamberId.h:49
DTRecSegment4D::hasZed
bool hasZed() const
Does it have the Z projection?
Definition: DTRecSegment4D.h:93
TrackerMuonHitExtractor::~TrackerMuonHitExtractor
~TrackerMuonHitExtractor()
Definition: TrackerMuonHitExtractor.cc:28
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
CSCDetId::endcap
int endcap() const
Definition: CSCDetId.h:85
relativeConstraints.ring
ring
Definition: relativeConstraints.py:68
TrackerMuonHitExtractor::TrackerMuonHitExtractor
TrackerMuonHitExtractor(const edm::ParameterSet &, edm::ConsumesCollector &&ic)
Definition: TrackerMuonHitExtractor.cc:16
relativeConstraints.chamber
chamber
Definition: relativeConstraints.py:53
DTRecSegment4D::hasPhi
bool hasPhi() const
Does it have the Phi projection?
Definition: DTRecSegment4D.h:90
edm::Ref::key
key_type key() const
Accessor for product key.
Definition: Ref.h:250
DTChamberId
Definition: DTChamberId.h:14
CSCDetId::station
int station() const
Definition: CSCDetId.h:79
edm::Event
Definition: Event.h:73
DTRecSegment4D::phiSegment
const DTChamberRecSegment2D * phiSegment() const
The superPhi segment: 0 if no phi projection available.
Definition: DTRecSegment4D.h:96
LocalError::yy
float yy() const
Definition: LocalError.h:24
DTChamberId::wheel
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:39
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
TrackerMuonHitExtractor::inputDTRecSegment4DCollection_
edm::InputTag inputDTRecSegment4DCollection_
Definition: TrackerMuonHitExtractor.h:33
DTChamberId::station
int station() const
Return the station number.
Definition: DTChamberId.h:42
reco::MuonSegmentMatch::BestInChamberByDR
static const unsigned int BestInChamberByDR
Definition: MuonSegmentMatch.h:17
CSCSegment::recHits
std::vector< const TrackingRecHit * > recHits() const override
Access to component RecHits (if any)
Definition: CSCSegment.cc:32