CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MuonTrackProducer.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  muonsTag(parset.getParameter< edm::InputTag >("muonsTag")),
17  inputDTRecSegment4DCollection_(parset.getParameter<edm::InputTag>("inputDTRecSegment4DCollection")),
18  inputCSCSegmentCollection_(parset.getParameter<edm::InputTag>("inputCSCSegmentCollection")),
19  selectionTags(parset.getParameter< std::vector<std::string> >("selectionTags")),
20  trackType(parset.getParameter< std::string >("trackType")),
21  parset_(parset)
22 {
23  edm::LogVerbatim("MuonTrackProducer") << "constructing MuonTrackProducer" << parset_.dump();
24  produces<reco::TrackCollection>();
25  produces<reco::TrackExtraCollection>();
26  produces<TrackingRecHitCollection>();
27 }
28 
30 }
31 
33 {
37 
38  std::auto_ptr<reco::TrackCollection> selectedTracks(new reco::TrackCollection);
39  std::auto_ptr<reco::TrackExtraCollection> selectedTrackExtras( new reco::TrackExtraCollection() );
40  std::auto_ptr<TrackingRecHitCollection> selectedTrackHits( new TrackingRecHitCollection() );
41 
45 
48 
49  edm::LogVerbatim("MuonTrackProducer") <<"\nThere are "<< dtSegmentCollectionH_->size()<<" DT segments.";
50  unsigned int index_dt_segment = 0;
52  segment != dtSegmentCollectionH_->end(); ++segment , index_dt_segment++) {
53  LocalPoint segmentLocalPosition = segment->localPosition();
54  LocalVector segmentLocalDirection = segment->localDirection();
55  LocalError segmentLocalPositionError = segment->localPositionError();
56  LocalError segmentLocalDirectionError = segment->localDirectionError();
57  DetId geoid = segment->geographicalId();
58  DTChamberId dtdetid = DTChamberId(geoid);
59  int wheel = dtdetid.wheel();
60  int station = dtdetid.station();
61  int sector = dtdetid.sector();
62 
63  float segmentX = segmentLocalPosition.x();
64  float segmentY = segmentLocalPosition.y();
65  float segmentdXdZ = segmentLocalDirection.x()/segmentLocalDirection.z();
66  float segmentdYdZ = segmentLocalDirection.y()/segmentLocalDirection.z();
67  float segmentXerr = sqrt(segmentLocalPositionError.xx());
68  float segmentYerr = sqrt(segmentLocalPositionError.yy());
69  float segmentdXdZerr = sqrt(segmentLocalDirectionError.xx());
70  float segmentdYdZerr = sqrt(segmentLocalDirectionError.yy());
71 
72  edm::LogVerbatim("MuonTrackProducer")
73  <<"\nDT segment index :"<<index_dt_segment
74  <<"\nchamber Wh:"<<wheel<<",St:"<<station<<",Se:"<<sector
75  <<"\nLocal Position (X,Y)=("<<segmentX<<","<<segmentY<<") +/- ("<<segmentXerr<<","<<segmentYerr<<"), "
76  <<"Local Direction (dXdZ,dYdZ)=("<<segmentdXdZ<<","<<segmentdYdZ<<") +/- ("<<segmentdXdZerr<<","<<segmentdYdZerr<<")";
77  }
78 
79  edm::LogVerbatim("MuonTrackProducer") <<"\nThere are "<< cscSegmentCollectionH_->size()<<" CSC segments.";
80  unsigned int index_csc_segment = 0;
82  segment != cscSegmentCollectionH_->end(); ++segment , index_csc_segment++) {
83  LocalPoint segmentLocalPosition = segment->localPosition();
84  LocalVector segmentLocalDirection = segment->localDirection();
85  LocalError segmentLocalPositionError = segment->localPositionError();
86  LocalError segmentLocalDirectionError = segment->localDirectionError();
87 
88  DetId geoid = segment->geographicalId();
89  CSCDetId cscdetid = CSCDetId(geoid);
90  int endcap = cscdetid.endcap();
91  int station = cscdetid.station();
92  int ring = cscdetid.ring();
93  int chamber = cscdetid.chamber();
94 
95  float segmentX = segmentLocalPosition.x();
96  float segmentY = segmentLocalPosition.y();
97  float segmentdXdZ = segmentLocalDirection.x()/segmentLocalDirection.z();
98  float segmentdYdZ = segmentLocalDirection.y()/segmentLocalDirection.z();
99  float segmentXerr = sqrt(segmentLocalPositionError.xx());
100  float segmentYerr = sqrt(segmentLocalPositionError.yy());
101  float segmentdXdZerr = sqrt(segmentLocalDirectionError.xx());
102  float segmentdYdZerr = sqrt(segmentLocalDirectionError.yy());
103 
104  edm::LogVerbatim("MuonTrackProducer")
105  <<"\nCSC segment index :"<<index_csc_segment
106  <<"\nchamber Endcap:"<<endcap<<",St:"<<station<<",Ri:"<<ring<<",Ch:"<<chamber
107  <<"\nLocal Position (X,Y)=("<<segmentX<<","<<segmentY<<") +/- ("<<segmentXerr<<","<<segmentYerr<<"), "
108  <<"Local Direction (dXdZ,dYdZ)=("<<segmentdXdZ<<","<<segmentdYdZ<<") +/- ("<<segmentdXdZerr<<","<<segmentdYdZerr<<")";
109  }
110 
111  edm::LogVerbatim("MuonTrackProducer") <<"\nThere are "<< muonCollectionH->size() <<" reco::Muons.";
112  unsigned int muon_index = 0;
113  for(reco::MuonCollection::const_iterator muon = muonCollectionH->begin();
114  muon != muonCollectionH->end(); ++muon, muon_index++) {
115  edm::LogVerbatim("MuonTrackProducer") <<"\n******* muon index : "<<muon_index;
116 
117  std::vector<bool> isGood;
118  for(unsigned int index=0; index<selectionTags.size(); ++index) {
119  isGood.push_back(false);
120 
122  isGood[index] = muon::isGoodMuon(*muon, muonType);
123  }
124 
125  bool isGoodResult=true;
126  for(unsigned int index=0; index<isGood.size(); ++index) {
127  edm::LogVerbatim("MuonTrackProducer") << "selectionTag = "<<selectionTags[index]<< ": "<<isGood[index]<<"\n";
128  isGoodResult *= isGood[index];
129  }
130 
131  if (isGoodResult) {
132  // new copy of Track
133  reco::TrackRef trackref;
134  if (trackType == "innerTrack") {
135  if (muon->innerTrack().isNonnull()) trackref = muon->innerTrack();
136  else continue;
137  }
138  else if (trackType == "outerTrack") {
139  if (muon->outerTrack().isNonnull()) trackref = muon->outerTrack();
140  else continue;
141  }
142  else if (trackType == "globalTrack") {
143  if (muon->globalTrack().isNonnull()) trackref = muon->globalTrack();
144  else continue;
145  }
146  else if (trackType == "innerTrackPlusSegments") {
147  if (muon->innerTrack().isNonnull()) trackref = muon->innerTrack();
148  else continue;
149  }
150 
151  const reco::Track* trk = &(*trackref);
152  // pointer to old track:
153  reco::Track* newTrk = new reco::Track(*trk);
154 
155  newTrk->setExtra( reco::TrackExtraRef( rTrackExtras, idx++ ) );
156  PropagationDirection seedDir = trk->seedDirection();
157  // new copy of track Extras
158  reco::TrackExtra * newExtra = new reco::TrackExtra( trk->outerPosition(), trk->outerMomentum(),
159  trk->outerOk(), trk->innerPosition(),
160  trk->innerMomentum(), trk->innerOk(),
161  trk->outerStateCovariance(), trk->outerDetId(),
162  trk->innerStateCovariance(), trk->innerDetId() , seedDir ) ;
163 
164  // new copy of the silicon hits; add hit refs to Extra and hits to hit collection
165  unsigned int index_hit = 0;
166 
167  // edm::LogVerbatim("MuonTrackProducer")<<"\n printing initial hit_pattern";
168  // trk->hitPattern().print();
169 
170  for (trackingRecHit_iterator iHit = trk->recHitsBegin(); iHit != trk->recHitsEnd(); iHit++) {
171  TrackingRecHit* hit = (*iHit)->clone();
172  index_hit++;
173  selectedTrackHits->push_back( hit );
174  newExtra->add( TrackingRecHitRef( rHits, hidx++ ) );
175  }
176 
177  if (trackType == "innerTrackPlusSegments") {
178 
179  int wheel, station, sector;
180  int endcap, /*station, */ ring, chamber;
181 
182  edm::LogVerbatim("MuonTrackProducer") <<"Number of chambers: "<<muon->matches().size()
183  <<", arbitrated: "<<muon->numberOfMatches(reco::Muon::SegmentAndTrackArbitration);
184  unsigned int index_chamber = 0;
185 
186  for(std::vector<reco::MuonChamberMatch>::const_iterator chamberMatch = muon->matches().begin();
187  chamberMatch != muon->matches().end(); ++chamberMatch, index_chamber++) {
188  std::stringstream chamberStr;
189  chamberStr <<"\nchamber index: "<<index_chamber;
190 
191  int subdet = chamberMatch->detector();
192  DetId did = chamberMatch->id;
193 
194  if (subdet == MuonSubdetId::DT) {
195  DTChamberId dtdetid = DTChamberId(did);
196  wheel = dtdetid.wheel();
197  station = dtdetid.station();
198  sector = dtdetid.sector();
199  chamberStr << ", DT chamber Wh:"<<wheel<<",St:"<<station<<",Se:"<<sector;
200  }
201  else if (subdet == MuonSubdetId::CSC) {
202  CSCDetId cscdetid = CSCDetId(did);
203  endcap = cscdetid.endcap();
204  station = cscdetid.station();
205  ring = cscdetid.ring();
206  chamber = cscdetid.chamber();
207  chamberStr << ", CSC chamber End:"<<endcap<<",St:"<<station<<",Ri:"<<ring<<",Ch:"<<chamber;
208  }
209 
210  chamberStr << ", Number of segments: "<<chamberMatch->segmentMatches.size();
211  edm::LogVerbatim("MuonTrackProducer") << chamberStr.str();
212 
213  unsigned int index_segment = 0;
214 
215  for(std::vector<reco::MuonSegmentMatch>::const_iterator segmentMatch = chamberMatch->segmentMatches.begin();
216  segmentMatch != chamberMatch->segmentMatches.end(); ++segmentMatch, index_segment++) {
217 
218  float segmentX = segmentMatch->x;
219  float segmentY = segmentMatch->y ;
220  float segmentdXdZ = segmentMatch->dXdZ;
221  float segmentdYdZ = segmentMatch->dYdZ;
222  float segmentXerr = segmentMatch->xErr;
223  float segmentYerr = segmentMatch->yErr;
224  float segmentdXdZerr = segmentMatch->dXdZErr;
225  float segmentdYdZerr = segmentMatch->dYdZErr;
226 
227  CSCSegmentRef segmentCSC = segmentMatch->cscSegmentRef;
228  DTRecSegment4DRef segmentDT = segmentMatch->dtSegmentRef;
229 
230  bool segment_arbitrated_Ok = (segmentMatch->isMask(reco::MuonSegmentMatch::BestInChamberByDR) &&
231  segmentMatch->isMask(reco::MuonSegmentMatch::BelongsToTrackByDR));
232 
233  std::string ARBITRATED(" ***Arbitrated Off*** ");
234  if (segment_arbitrated_Ok) ARBITRATED = " ***ARBITRATED OK*** ";
235 
236  if (subdet == MuonSubdetId::DT) {
237  edm::LogVerbatim("MuonTrackProducer")
238  <<"\n\t segment index: "<<index_segment << ARBITRATED
239  <<"\n\t Local Position (X,Y)=("<<segmentX<<","<<segmentY<<") +/- ("<<segmentXerr<<","<<segmentYerr<<"), "
240  <<"\n\t Local Direction (dXdZ,dYdZ)=("<<segmentdXdZ<<","<<segmentdYdZ<<") +/- ("<<segmentdXdZerr<<","<<segmentdYdZerr<<")";
241 
242  if (!segment_arbitrated_Ok) continue;
243 
244  if (segmentDT.get() != 0) {
245  const DTRecSegment4D* segment = segmentDT.get();
246 
247  edm::LogVerbatim("MuonTrackProducer")<<"\t ===> MATCHING with DT segment with index = "<<segmentDT.key();
248 
249  if(segment->hasPhi()) {
250  const DTChamberRecSegment2D* phiSeg = segment->phiSegment();
251  std::vector<const TrackingRecHit*> phiHits = phiSeg->recHits();
252  for(std::vector<const TrackingRecHit*>::const_iterator ihit = phiHits.begin();
253  ihit != phiHits.end(); ++ihit) {
254  TrackingRecHit* seghit = (*ihit)->clone();
255  newTrk->setHitPattern( *seghit, index_hit);
256  // edm::LogVerbatim("MuonTrackProducer")<<"hit pattern for position "<<index_hit<<" set to:";
257  // newTrk->hitPattern().printHitPattern(index_hit, std::cout);
258  index_hit++;
259  selectedTrackHits->push_back( seghit );
260  newExtra->add( TrackingRecHitRef( rHits, hidx ++ ) );
261  }
262  }
263 
264  if(segment->hasZed()) {
265  const DTSLRecSegment2D* zSeg = (*segment).zSegment();
266  std::vector<const TrackingRecHit*> zedHits = zSeg->recHits();
267  for(std::vector<const TrackingRecHit*>::const_iterator ihit = zedHits.begin();
268  ihit != zedHits.end(); ++ihit) {
269  TrackingRecHit* seghit = (*ihit)->clone();
270  newTrk->setHitPattern( *seghit, index_hit);
271  // edm::LogVerbatim("MuonTrackProducer")<<"hit pattern for position "<<index_hit<<" set to:";
272  // newTrk->hitPattern().printHitPattern(index_hit, std::cout);
273  index_hit++;
274  selectedTrackHits->push_back( seghit );
275  newExtra->add( TrackingRecHitRef( rHits, hidx ++ ) );
276  }
277  }
278  } else edm::LogWarning("MuonTrackProducer")<<"\n***WARNING: UNMATCHED DT segment ! \n";
279  } // if (subdet == MuonSubdetId::DT)
280 
281  else if (subdet == MuonSubdetId::CSC) {
282  edm::LogVerbatim("MuonTrackProducer")
283  <<"\n\t segment index: "<<index_segment << ARBITRATED
284  <<"\n\t Local Position (X,Y)=("<<segmentX<<","<<segmentY<<") +/- ("<<segmentXerr<<","<<segmentYerr<<"), "
285  <<"\n\t Local Direction (dXdZ,dYdZ)=("<<segmentdXdZ<<","<<segmentdYdZ<<") +/- ("<<segmentdXdZerr<<","<<segmentdYdZerr<<")";
286 
287  if (!segment_arbitrated_Ok) continue;
288 
289  if (segmentCSC.get() != 0) {
290  const CSCSegment* segment = segmentCSC.get();
291 
292  edm::LogVerbatim("MuonTrackProducer")<<"\t ===> MATCHING with CSC segment with index = "<<segmentCSC.key();
293 
294  std::vector<const TrackingRecHit*> hits = segment->recHits();
295  for(std::vector<const TrackingRecHit*>::const_iterator ihit = hits.begin();
296  ihit != hits.end(); ++ihit) {
297  TrackingRecHit* seghit = (*ihit)->clone();
298  newTrk->setHitPattern( *seghit, index_hit);
299  // edm::LogVerbatim("MuonTrackProducer")<<"hit pattern for position "<<index_hit<<" set to:";
300  // newTrk->hitPattern().printHitPattern(index_hit, std::cout);
301  index_hit++;
302  selectedTrackHits->push_back( seghit );
303  newExtra->add( TrackingRecHitRef( rHits, hidx ++ ) );
304  }
305  } else edm::LogWarning("MuonTrackProducer")<<"\n***WARNING: UNMATCHED CSC segment ! \n";
306  } // else if (subdet == MuonSubdetId::CSC)
307 
308  } // loop on vector<MuonSegmentMatch>
309  } // loop on vector<MuonChamberMatch>
310  } // if (trackType == "innerTrackPlusSegments")
311 
312  // edm::LogVerbatim("MuonTrackProducer")<<"\n printing final hit_pattern";
313  // newTrk->hitPattern().print();
314 
315  selectedTracks->push_back( *newTrk );
316  selectedTrackExtras->push_back( *newExtra );
317 
318  } // if (isGoodResult)
319  } // loop on reco::MuonCollection
320 
321  iEvent.put(selectedTracks);
322  iEvent.put(selectedTrackExtras);
323  iEvent.put(selectedTrackHits);
324 }
int chamber() const
Definition: CSCDetId.h:70
float xx() const
Definition: LocalError.h:24
edm::InputTag inputCSCSegmentCollection_
std::vector< std::string > selectionTags
std::string dump(unsigned int indent=0) const
const DTChamberRecSegment2D * phiSegment() const
The superPhi segment: 0 if no phi projection available.
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:10
T y() const
Definition: PV3DBase.h:63
bool innerOk() const
return true if the innermost hit is valid
Definition: Track.h:40
PropagationDirection
const math::XYZPoint & outerPosition() const
position of the outermost hit
Definition: Track.h:47
SelectionType
Selector type.
Definition: MuonSelectors.h:18
const math::XYZPoint & innerPosition() const
position of the innermost hit
Definition: Track.h:42
int endcap() const
Definition: CSCDetId.h:95
C::const_iterator const_iterator
constant access iterator type
Definition: RangeMap.h:45
int iEvent
Definition: GenABIO.cc:243
static const int CSC
Definition: MuonSubdetId.h:15
edm::Handle< CSCSegmentCollection > cscSegmentCollectionH_
float yy() const
Definition: LocalError.h:26
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
virtual std::vector< const TrackingRecHit * > recHits() const
Access to component RecHits (if any)
edm::Ref< TrackingRecHitCollection > TrackingRecHitRef
persistent reference to a TrackingRecHit
T sqrt(T t)
Definition: SSEVec.h:48
CovarianceMatrix outerStateCovariance() const
outermost trajectory state curvilinear errors
Definition: Track.h:51
T z() const
Definition: PV3DBase.h:64
edm::Handle< DTRecSegment4DCollection > dtSegmentCollectionH_
unsigned int outerDetId() const
DetId of the detector on which surface the outermost state is located.
Definition: Track.h:59
static const unsigned int BestInChamberByDR
bool hasPhi() const
Does it have the Phi projection?
virtual void produce(edm::Event &, const edm::EventSetup &)
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
Definition: Track.h:63
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
RefProd< PROD > getRefBeforePut()
Definition: Event.h:106
bool isGoodMuon(const reco::Muon &muon, SelectionType type, reco::Muon::ArbitrationType arbitrationType=reco::Muon::SegmentAndTrackArbitration)
main GoodMuon wrapper call
virtual TrackingRecHit * clone() const =0
MuonTrackProducer(const edm::ParameterSet &)
int ring() const
Definition: CSCDetId.h:77
bool hasZed() const
Does it have the Z projection?
Definition: DetId.h:20
void setHitPattern(const C &c)
set hit patterns from vector of hit references
Definition: TrackBase.h:246
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
Definition: TrackExtraFwd.h:9
edm::OwnVector< TrackingRecHit > TrackingRecHitCollection
collection of TrackingRecHits
void setExtra(const TrackExtraRef &ref)
set reference to &quot;extra&quot; object
Definition: Track.h:95
const math::XYZVector & outerMomentum() const
momentum vector at the outermost hit position
Definition: Track.h:49
bool outerOk() const
return true if the outermost hit is valid
Definition: Track.h:38
edm::InputTag inputDTRecSegment4DCollection_
SelectionType selectionTypeFromString(const std::string &label)
Definition: MuonSelectors.cc:9
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
edm::Handle< reco::MuonCollection > muonCollectionH
CovarianceMatrix innerStateCovariance() const
innermost trajectory state curvilinear errors
Definition: Track.h:53
key_type key() const
Accessor for product key.
Definition: Ref.h:266
edm::InputTag muonsTag
void add(const TrackingRecHitRef &r)
add a reference to a RecHit
static const unsigned int BelongsToTrackByDR
const edm::ParameterSet parset_
int sector() const
Definition: DTChamberId.h:63
const math::XYZVector & innerMomentum() const
momentum vector at the innermost hit position
Definition: Track.h:45
PropagationDirection seedDirection() const
direction of how the hits were sorted in the original seed
Definition: Track.h:105
int station() const
Definition: CSCDetId.h:88
static const int DT
Definition: MuonSubdetId.h:14
boost::remove_cv< typename boost::remove_reference< argument_type >::type >::type key_type
Definition: Ref.h:170
int station() const
Return the station number.
Definition: DTChamberId.h:53
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:242
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:47
T x() const
Definition: PV3DBase.h:62
unsigned int innerDetId() const
DetId of the detector on which surface the innermost state is located.
Definition: Track.h:61
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.
Definition: Track.h:65