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  muonsToken(consumes<reco::MuonCollection>(parset.getParameter< edm::InputTag >("muonsTag"))),
17  inputDTRecSegment4DToken_(consumes<DTRecSegment4DCollection>(parset.getParameter<edm::InputTag>("inputDTRecSegment4DCollection"))),
18  inputCSCSegmentToken_(consumes<CSCSegmentCollection>(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 
166  // edm::LogVerbatim("MuonTrackProducer")<<"\n printing initial hit_pattern";
167  // trk->hitPattern().print();
168  unsigned int nHitsToAdd = 0;
169  for (trackingRecHit_iterator iHit = trk->recHitsBegin(); iHit != trk->recHitsEnd(); iHit++) {
170  TrackingRecHit* hit = (*iHit)->clone();
171  selectedTrackHits->push_back( hit );
172  ++nHitsToAdd;
173  }
174  newExtra->setHits( rHits, hidx, nHitsToAdd );
175  hidx += nHitsToAdd;
176  if (trackType == "innerTrackPlusSegments") {
177 
178  int wheel, station, sector;
179  int endcap, /*station, */ ring, chamber;
180 
181  edm::LogVerbatim("MuonTrackProducer") <<"Number of chambers: "<<muon->matches().size()
182  <<", arbitrated: "<<muon->numberOfMatches(reco::Muon::SegmentAndTrackArbitration);
183  unsigned int index_chamber = 0;
184 
185  for(std::vector<reco::MuonChamberMatch>::const_iterator chamberMatch = muon->matches().begin();
186  chamberMatch != muon->matches().end(); ++chamberMatch, index_chamber++) {
187  std::stringstream chamberStr;
188  chamberStr <<"\nchamber index: "<<index_chamber;
189 
190  int subdet = chamberMatch->detector();
191  DetId did = chamberMatch->id;
192 
193  if (subdet == MuonSubdetId::DT) {
194  DTChamberId dtdetid = DTChamberId(did);
195  wheel = dtdetid.wheel();
196  station = dtdetid.station();
197  sector = dtdetid.sector();
198  chamberStr << ", DT chamber Wh:"<<wheel<<",St:"<<station<<",Se:"<<sector;
199  }
200  else if (subdet == MuonSubdetId::CSC) {
201  CSCDetId cscdetid = CSCDetId(did);
202  endcap = cscdetid.endcap();
203  station = cscdetid.station();
204  ring = cscdetid.ring();
205  chamber = cscdetid.chamber();
206  chamberStr << ", CSC chamber End:"<<endcap<<",St:"<<station<<",Ri:"<<ring<<",Ch:"<<chamber;
207  }
208 
209  chamberStr << ", Number of segments: "<<chamberMatch->segmentMatches.size();
210  edm::LogVerbatim("MuonTrackProducer") << chamberStr.str();
211 
212  unsigned int index_segment = 0;
213 
214  for(std::vector<reco::MuonSegmentMatch>::const_iterator segmentMatch = chamberMatch->segmentMatches.begin();
215  segmentMatch != chamberMatch->segmentMatches.end(); ++segmentMatch, index_segment++) {
216 
217  float segmentX = segmentMatch->x;
218  float segmentY = segmentMatch->y ;
219  float segmentdXdZ = segmentMatch->dXdZ;
220  float segmentdYdZ = segmentMatch->dYdZ;
221  float segmentXerr = segmentMatch->xErr;
222  float segmentYerr = segmentMatch->yErr;
223  float segmentdXdZerr = segmentMatch->dXdZErr;
224  float segmentdYdZerr = segmentMatch->dYdZErr;
225 
226  CSCSegmentRef segmentCSC = segmentMatch->cscSegmentRef;
227  DTRecSegment4DRef segmentDT = segmentMatch->dtSegmentRef;
228 
229  bool segment_arbitrated_Ok = (segmentMatch->isMask(reco::MuonSegmentMatch::BestInChamberByDR) &&
230  segmentMatch->isMask(reco::MuonSegmentMatch::BelongsToTrackByDR));
231 
232  std::string ARBITRATED(" ***Arbitrated Off*** ");
233  if (segment_arbitrated_Ok) ARBITRATED = " ***ARBITRATED OK*** ";
234 
235  if (subdet == MuonSubdetId::DT) {
236  edm::LogVerbatim("MuonTrackProducer")
237  <<"\n\t segment index: "<<index_segment << ARBITRATED
238  <<"\n\t Local Position (X,Y)=("<<segmentX<<","<<segmentY<<") +/- ("<<segmentXerr<<","<<segmentYerr<<"), "
239  <<"\n\t Local Direction (dXdZ,dYdZ)=("<<segmentdXdZ<<","<<segmentdYdZ<<") +/- ("<<segmentdXdZerr<<","<<segmentdYdZerr<<")";
240 
241  if (!segment_arbitrated_Ok) continue;
242 
243  if (segmentDT.get() != 0) {
244  const DTRecSegment4D* segment = segmentDT.get();
245 
246  edm::LogVerbatim("MuonTrackProducer")<<"\t ===> MATCHING with DT segment with index = "<<segmentDT.key();
247 
248  if(segment->hasPhi()) {
249  const DTChamberRecSegment2D* phiSeg = segment->phiSegment();
250  std::vector<const TrackingRecHit*> phiHits = phiSeg->recHits();
251  unsigned int nHitsAdded = 0;
252  for(std::vector<const TrackingRecHit*>::const_iterator ihit = phiHits.begin();
253  ihit != phiHits.end(); ++ihit) {
254  TrackingRecHit* seghit = (*ihit)->clone();
255  newTrk->appendHitPattern(*seghit);
256  // edm::LogVerbatim("MuonTrackProducer")<<"hit pattern for position "<<index_hit<<" set to:";
257  // newTrk->hitPattern().printHitPattern(index_hit, std::cout);
258  selectedTrackHits->push_back( seghit );
259  ++nHitsAdded;
260  }
261  newExtra->setHits( rHits, hidx, nHitsAdded );
262  hidx += nHitsAdded;
263  }
264 
265  if(segment->hasZed()) {
266  const DTSLRecSegment2D* zSeg = (*segment).zSegment();
267  std::vector<const TrackingRecHit*> zedHits = zSeg->recHits();
268  unsigned int nHitsAdded = 0;
269  for(std::vector<const TrackingRecHit*>::const_iterator ihit = zedHits.begin();
270  ihit != zedHits.end(); ++ihit) {
271  TrackingRecHit* seghit = (*ihit)->clone();
272  newTrk->appendHitPattern(*seghit);
273  // edm::LogVerbatim("MuonTrackProducer")<<"hit pattern for position "<<index_hit<<" set to:";
274  // newTrk->hitPattern().printHitPattern(index_hit, std::cout);
275  selectedTrackHits->push_back( seghit );
276  ++nHitsAdded;
277  }
278  newExtra->setHits( rHits, hidx, nHitsAdded );
279  hidx += nHitsAdded;
280  }
281  } else edm::LogWarning("MuonTrackProducer")<<"\n***WARNING: UNMATCHED DT segment ! \n";
282  } // if (subdet == MuonSubdetId::DT)
283 
284  else if (subdet == MuonSubdetId::CSC) {
285  edm::LogVerbatim("MuonTrackProducer")
286  <<"\n\t segment index: "<<index_segment << ARBITRATED
287  <<"\n\t Local Position (X,Y)=("<<segmentX<<","<<segmentY<<") +/- ("<<segmentXerr<<","<<segmentYerr<<"), "
288  <<"\n\t Local Direction (dXdZ,dYdZ)=("<<segmentdXdZ<<","<<segmentdYdZ<<") +/- ("<<segmentdXdZerr<<","<<segmentdYdZerr<<")";
289 
290  if (!segment_arbitrated_Ok) continue;
291 
292  if (segmentCSC.get() != 0) {
293  const CSCSegment* segment = segmentCSC.get();
294 
295  edm::LogVerbatim("MuonTrackProducer")<<"\t ===> MATCHING with CSC segment with index = "<<segmentCSC.key();
296 
297  std::vector<const TrackingRecHit*> hits = segment->recHits();
298  unsigned int nHitsAdded = 0;
299  for(std::vector<const TrackingRecHit*>::const_iterator ihit = hits.begin();
300  ihit != hits.end(); ++ihit) {
301  TrackingRecHit* seghit = (*ihit)->clone();
302  newTrk->appendHitPattern(*seghit);
303  // edm::LogVerbatim("MuonTrackProducer")<<"hit pattern for position "<<index_hit<<" set to:";
304  // newTrk->hitPattern().printHitPattern(index_hit, std::cout);
305  selectedTrackHits->push_back( seghit );
306  ++nHitsAdded;
307  }
308  newExtra->setHits( rHits, hidx, nHitsAdded );
309  hidx += nHitsAdded;
310  } else edm::LogWarning("MuonTrackProducer")<<"\n***WARNING: UNMATCHED CSC segment ! \n";
311  } // else if (subdet == MuonSubdetId::CSC)
312 
313  } // loop on vector<MuonSegmentMatch>
314  } // loop on vector<MuonChamberMatch>
315  } // if (trackType == "innerTrackPlusSegments")
316 
317  // edm::LogVerbatim("MuonTrackProducer")<<"\n printing final hit_pattern";
318  // newTrk->hitPattern().print();
319 
320  selectedTracks->push_back( *newTrk );
321  selectedTrackExtras->push_back( *newExtra );
322 
323  } // if (isGoodResult)
324  } // loop on reco::MuonCollection
325 
326  iEvent.put(selectedTracks);
327  iEvent.put(selectedTrackExtras);
328  iEvent.put(selectedTrackHits);
329 }
int chamber() const
Definition: CSCDetId.h:81
float xx() const
Definition: LocalError.h:24
edm::EDGetTokenT< DTRecSegment4DCollection > inputDTRecSegment4DToken_
std::vector< std::string > selectionTags
std::string dump(unsigned int indent=0) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
void setHits(TrackingRecHitRefProd const &prod, unsigned firstH, unsigned int nH)
const DTChamberRecSegment2D * phiSegment() const
The superPhi segment: 0 if no phi projection available.
edm::EDGetTokenT< reco::MuonCollection > muonsToken
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:13
T y() const
Definition: PV3DBase.h:63
bool innerOk() const
return true if the innermost hit is valid
Definition: Track.h:50
PropagationDirection
key_type key() const
Accessor for product key.
Definition: Ref.h:266
const math::XYZPoint & outerPosition() const
position of the outermost hit
Definition: Track.h:65
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
SelectionType
Selector type.
Definition: MuonSelectors.h:17
const math::XYZPoint & innerPosition() const
position of the innermost hit
Definition: Track.h:55
int endcap() const
Definition: CSCDetId.h:106
int iEvent
Definition: GenABIO.cc:230
static const int CSC
Definition: MuonSubdetId.h:13
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:113
virtual std::vector< const TrackingRecHit * > recHits() const
Access to component RecHits (if any)
T sqrt(T t)
Definition: SSEVec.h:48
CovarianceMatrix outerStateCovariance() const
outermost trajectory state curvilinear errors
Definition: Track.h:75
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:94
bool appendHitPattern(const TrackingRecHit &hit)
append a single hit to the HitPattern
Definition: TrackBase.h:394
static const unsigned int BestInChamberByDR
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:242
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:104
virtual std::vector< const TrackingRecHit * > recHits() const
Access to component RecHits (if any)
Definition: CSCSegment.cc:30
RefProd< PROD > getRefBeforePut()
Definition: Event.h:133
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:88
bool hasZed() const
Does it have the Z projection?
Definition: DetId.h:18
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
Definition: TrackExtraFwd.h:11
edm::OwnVector< TrackingRecHit > TrackingRecHitCollection
collection of TrackingRecHits
void setExtra(const TrackExtraRef &ref)
set reference to &quot;extra&quot; object
Definition: Track.h:184
const math::XYZVector & outerMomentum() const
momentum vector at the outermost hit position
Definition: Track.h:70
bool outerOk() const
return true if the outermost hit is valid
Definition: Track.h:45
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:80
static const unsigned int BelongsToTrackByDR
const edm::ParameterSet parset_
int sector() const
Definition: DTChamberId.h:61
const math::XYZVector & innerMomentum() const
momentum vector at the innermost hit position
Definition: Track.h:60
PropagationDirection seedDirection() const
direction of how the hits were sorted in the original seed
Definition: Track.h:204
int station() const
Definition: CSCDetId.h:99
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
unsigned int innerDetId() const
DetId of the detector on which surface the innermost state is located.
Definition: Track.h:99
edm::EDGetTokenT< CSCSegmentCollection > inputCSCSegmentToken_
boost::remove_cv< typename boost::remove_reference< argument_type >::type >::type key_type
Definition: Ref.h:170
TrackingRecHitCollection::base::const_iterator trackingRecHit_iterator
iterator over a vector of reference to TrackingRecHit in the same collection
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.
Definition: Track.h:109