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