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 
169  for (trackingRecHit_iterator iHit = trk->recHitsBegin(); iHit != trk->recHitsEnd(); iHit++) {
170  TrackingRecHit* hit = (*iHit)->clone();
171  selectedTrackHits->push_back( hit );
172  newExtra->add( TrackingRecHitRef( rHits, hidx++ ) );
173  }
174 
175  if (trackType == "innerTrackPlusSegments") {
176 
177  int wheel, station, sector;
178  int endcap, /*station, */ ring, chamber;
179 
180  edm::LogVerbatim("MuonTrackProducer") <<"Number of chambers: "<<muon->matches().size()
181  <<", arbitrated: "<<muon->numberOfMatches(reco::Muon::SegmentAndTrackArbitration);
182  unsigned int index_chamber = 0;
183 
184  for(std::vector<reco::MuonChamberMatch>::const_iterator chamberMatch = muon->matches().begin();
185  chamberMatch != muon->matches().end(); ++chamberMatch, index_chamber++) {
186  std::stringstream chamberStr;
187  chamberStr <<"\nchamber index: "<<index_chamber;
188 
189  int subdet = chamberMatch->detector();
190  DetId did = chamberMatch->id;
191 
192  if (subdet == MuonSubdetId::DT) {
193  DTChamberId dtdetid = DTChamberId(did);
194  wheel = dtdetid.wheel();
195  station = dtdetid.station();
196  sector = dtdetid.sector();
197  chamberStr << ", DT chamber Wh:"<<wheel<<",St:"<<station<<",Se:"<<sector;
198  }
199  else if (subdet == MuonSubdetId::CSC) {
200  CSCDetId cscdetid = CSCDetId(did);
201  endcap = cscdetid.endcap();
202  station = cscdetid.station();
203  ring = cscdetid.ring();
204  chamber = cscdetid.chamber();
205  chamberStr << ", CSC chamber End:"<<endcap<<",St:"<<station<<",Ri:"<<ring<<",Ch:"<<chamber;
206  }
207 
208  chamberStr << ", Number of segments: "<<chamberMatch->segmentMatches.size();
209  edm::LogVerbatim("MuonTrackProducer") << chamberStr.str();
210 
211  unsigned int index_segment = 0;
212 
213  for(std::vector<reco::MuonSegmentMatch>::const_iterator segmentMatch = chamberMatch->segmentMatches.begin();
214  segmentMatch != chamberMatch->segmentMatches.end(); ++segmentMatch, index_segment++) {
215 
216  float segmentX = segmentMatch->x;
217  float segmentY = segmentMatch->y ;
218  float segmentdXdZ = segmentMatch->dXdZ;
219  float segmentdYdZ = segmentMatch->dYdZ;
220  float segmentXerr = segmentMatch->xErr;
221  float segmentYerr = segmentMatch->yErr;
222  float segmentdXdZerr = segmentMatch->dXdZErr;
223  float segmentdYdZerr = segmentMatch->dYdZErr;
224 
225  CSCSegmentRef segmentCSC = segmentMatch->cscSegmentRef;
226  DTRecSegment4DRef segmentDT = segmentMatch->dtSegmentRef;
227 
228  bool segment_arbitrated_Ok = (segmentMatch->isMask(reco::MuonSegmentMatch::BestInChamberByDR) &&
229  segmentMatch->isMask(reco::MuonSegmentMatch::BelongsToTrackByDR));
230 
231  std::string ARBITRATED(" ***Arbitrated Off*** ");
232  if (segment_arbitrated_Ok) ARBITRATED = " ***ARBITRATED OK*** ";
233 
234  if (subdet == MuonSubdetId::DT) {
235  edm::LogVerbatim("MuonTrackProducer")
236  <<"\n\t segment index: "<<index_segment << ARBITRATED
237  <<"\n\t Local Position (X,Y)=("<<segmentX<<","<<segmentY<<") +/- ("<<segmentXerr<<","<<segmentYerr<<"), "
238  <<"\n\t Local Direction (dXdZ,dYdZ)=("<<segmentdXdZ<<","<<segmentdYdZ<<") +/- ("<<segmentdXdZerr<<","<<segmentdYdZerr<<")";
239 
240  if (!segment_arbitrated_Ok) continue;
241 
242  if (segmentDT.get() != 0) {
243  const DTRecSegment4D* segment = segmentDT.get();
244 
245  edm::LogVerbatim("MuonTrackProducer")<<"\t ===> MATCHING with DT segment with index = "<<segmentDT.key();
246 
247  if(segment->hasPhi()) {
248  const DTChamberRecSegment2D* phiSeg = segment->phiSegment();
249  std::vector<const TrackingRecHit*> phiHits = phiSeg->recHits();
250  for(std::vector<const TrackingRecHit*>::const_iterator ihit = phiHits.begin();
251  ihit != phiHits.end(); ++ihit) {
252  TrackingRecHit* seghit = (*ihit)->clone();
253  newTrk->appendHitPattern(*seghit);
254  // edm::LogVerbatim("MuonTrackProducer")<<"hit pattern for position "<<index_hit<<" set to:";
255  // newTrk->hitPattern().printHitPattern(index_hit, std::cout);
256  selectedTrackHits->push_back( seghit );
257  newExtra->add( TrackingRecHitRef( rHits, hidx ++ ) );
258  }
259  }
260 
261  if(segment->hasZed()) {
262  const DTSLRecSegment2D* zSeg = (*segment).zSegment();
263  std::vector<const TrackingRecHit*> zedHits = zSeg->recHits();
264  for(std::vector<const TrackingRecHit*>::const_iterator ihit = zedHits.begin();
265  ihit != zedHits.end(); ++ihit) {
266  TrackingRecHit* seghit = (*ihit)->clone();
267  newTrk->appendHitPattern(*seghit);
268  // edm::LogVerbatim("MuonTrackProducer")<<"hit pattern for position "<<index_hit<<" set to:";
269  // newTrk->hitPattern().printHitPattern(index_hit, std::cout);
270  selectedTrackHits->push_back( seghit );
271  newExtra->add( TrackingRecHitRef( rHits, hidx ++ ) );
272  }
273  }
274  } else edm::LogWarning("MuonTrackProducer")<<"\n***WARNING: UNMATCHED DT segment ! \n";
275  } // if (subdet == MuonSubdetId::DT)
276 
277  else if (subdet == MuonSubdetId::CSC) {
278  edm::LogVerbatim("MuonTrackProducer")
279  <<"\n\t segment index: "<<index_segment << ARBITRATED
280  <<"\n\t Local Position (X,Y)=("<<segmentX<<","<<segmentY<<") +/- ("<<segmentXerr<<","<<segmentYerr<<"), "
281  <<"\n\t Local Direction (dXdZ,dYdZ)=("<<segmentdXdZ<<","<<segmentdYdZ<<") +/- ("<<segmentdXdZerr<<","<<segmentdYdZerr<<")";
282 
283  if (!segment_arbitrated_Ok) continue;
284 
285  if (segmentCSC.get() != 0) {
286  const CSCSegment* segment = segmentCSC.get();
287 
288  edm::LogVerbatim("MuonTrackProducer")<<"\t ===> MATCHING with CSC segment with index = "<<segmentCSC.key();
289 
290  std::vector<const TrackingRecHit*> hits = segment->recHits();
291  for(std::vector<const TrackingRecHit*>::const_iterator ihit = hits.begin();
292  ihit != hits.end(); ++ihit) {
293  TrackingRecHit* seghit = (*ihit)->clone();
294  newTrk->appendHitPattern(*seghit);
295  // edm::LogVerbatim("MuonTrackProducer")<<"hit pattern for position "<<index_hit<<" set to:";
296  // newTrk->hitPattern().printHitPattern(index_hit, std::cout);
297  selectedTrackHits->push_back( seghit );
298  newExtra->add( TrackingRecHitRef( rHits, hidx ++ ) );
299  }
300  } else edm::LogWarning("MuonTrackProducer")<<"\n***WARNING: UNMATCHED CSC segment ! \n";
301  } // else if (subdet == MuonSubdetId::CSC)
302 
303  } // loop on vector<MuonSegmentMatch>
304  } // loop on vector<MuonChamberMatch>
305  } // if (trackType == "innerTrackPlusSegments")
306 
307  // edm::LogVerbatim("MuonTrackProducer")<<"\n printing final hit_pattern";
308  // newTrk->hitPattern().print();
309 
310  selectedTracks->push_back( *newTrk );
311  selectedTrackExtras->push_back( *newExtra );
312 
313  } // if (isGoodResult)
314  } // loop on reco::MuonCollection
315 
316  iEvent.put(selectedTracks);
317  iEvent.put(selectedTrackExtras);
318  iEvent.put(selectedTrackHits);
319 }
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:446
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)
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: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:374
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
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
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: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
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.
Definition: Track.h:109