CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FWMuonBuilder.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Muons
4 // Class : FWMuonBuilder
5 //
6 
7 #include "TEveVSDStructs.h"
8 #include "TEveTrack.h"
9 #include "TEveStraightLineSet.h"
10 #include "TEveGeoNode.h"
11 #include "TGeoArb8.h"
12 
18 
20 
23 
26 
30 
31 namespace {
32 std::vector<TEveVector> getRecoTrajectoryPoints( const reco::Muon* muon,
33  const FWEventItem* iItem )
34 {
35  std::vector<TEveVector> points;
36  const FWGeometry* geom = iItem->getGeom();
37 
38  float localTrajectoryPoint[3];
39  float globalTrajectoryPoint[3];
40 
41  const std::vector<reco::MuonChamberMatch>& matches = muon->matches();
42  for( std::vector<reco::MuonChamberMatch>::const_iterator chamber = matches.begin(),
43  chamberEnd = matches.end();
44  chamber != chamberEnd; ++chamber )
45  {
46  // expected track position
47  localTrajectoryPoint[0] = chamber->x;
48  localTrajectoryPoint[1] = chamber->y;
49  localTrajectoryPoint[2] = 0;
50 
51  unsigned int rawid = chamber->id.rawId();
52  if( geom->contains( rawid ))
53  {
54  geom->localToGlobal( rawid, localTrajectoryPoint, globalTrajectoryPoint );
55  points.push_back( TEveVector(globalTrajectoryPoint[0],
56  globalTrajectoryPoint[1],
57  globalTrajectoryPoint[2] ));
58  }
59  }
60  return points;
61 }
62 
63 //______________________________________________________________________________
64 
65 void addMatchInformation( const reco::Muon* muon,
67  TEveElement* parentList,
68  bool showEndcap )
69 {
70  std::set<unsigned int> ids;
71  const FWGeometry* geom = pb->context().getGeom();
72 
73  const std::vector<reco::MuonChamberMatch>& matches = muon->matches();
74 
75  //need to use auto_ptr since the segmentSet may not be passed to muonList
76  std::auto_ptr<TEveStraightLineSet> segmentSet( new TEveStraightLineSet );
77  // FIXME: This should be set elsewhere.
78  segmentSet->SetLineWidth( 4 );
79 
80  for( std::vector<reco::MuonChamberMatch>::const_iterator chamber = matches.begin(),
81  chambersEnd = matches.end();
82  chamber != chambersEnd; ++chamber )
83  {
84  unsigned int rawid = chamber->id.rawId();
85  float segmentLength = 0.0;
86  float segmentLimit = 0.0;
87 
88  if( geom->contains( rawid ))
89  {
90  TEveGeoShape* shape = geom->getEveShape( rawid );
91  shape->SetElementName( "Chamber" );
92  shape->RefMainTrans().Scale( 0.999, 0.999, 0.999 );
93 
94  FWGeometry::IdToInfoItr det = geom->find( rawid );
95  if( det->shape[0] == 1 ) // TGeoTrap
96  {
97  segmentLength = det->shape[3];
98  segmentLimit = det->shape[4];
99  }
100  else if( det->shape[0] == 2 ) // TGeoBBox
101  {
102  segmentLength = det->shape[3];
103  }
104  else
105  {
106  const double segmentLength = 15;
107  fwLog( fwlog::kWarning ) << Form("FWMuonBuilder: unknown shape type in muon chamber with detId=%d. Setting segment length to %.0f cm.\n", rawid, segmentLength);
108  }
109 
110  if( ids.insert( rawid ).second && // ensure that we add same chamber only once
111  ( chamber->detector() != MuonSubdetId::CSC || showEndcap ))
112  {
113  pb->setupAddElement( shape, parentList );
114  }
115 
116  for( std::vector<reco::MuonSegmentMatch>::const_iterator segment = chamber->segmentMatches.begin(),
117  segmentEnd = chamber->segmentMatches.end();
118  segment != segmentEnd; ++segment )
119  {
120  float segmentPosition[3] = { segment->x, segment->y, 0.0 };
121  float segmentDirection[3] = { segment->dXdZ, segment->dYdZ, 0.0 };
122 
123  float localSegmentInnerPoint[3];
124  float localSegmentOuterPoint[3];
125 
126  fireworks::createSegment( chamber->detector(), true,
127  segmentLength, segmentLimit,
128  segmentPosition, segmentDirection,
129  localSegmentInnerPoint, localSegmentOuterPoint );
130 
131  float globalSegmentInnerPoint[3];
132  float globalSegmentOuterPoint[3];
133 
134  geom->localToGlobal( *det, localSegmentInnerPoint, globalSegmentInnerPoint );
135  geom->localToGlobal( *det, localSegmentOuterPoint, globalSegmentOuterPoint );
136 
137  segmentSet->AddLine( globalSegmentInnerPoint[0], globalSegmentInnerPoint[1], globalSegmentInnerPoint[2],
138  globalSegmentOuterPoint[0], globalSegmentOuterPoint[1], globalSegmentOuterPoint[2] );
139  }
140  }
141  }
142 
143  if( !matches.empty() )
144  pb->setupAddElement( segmentSet.release(), parentList );
145 }
146 
147 //______________________________________________________________________________
148 
149 bool
150 buggyMuon( const reco::Muon* muon,
151  const FWGeometry* geom )
152 {
153  if( !muon->standAloneMuon().isAvailable() ||
154  !muon->standAloneMuon()->extra().isAvailable())
155  return false;
156 
157  float localTrajectoryPoint[3];
158  float globalTrajectoryPoint[3];
159 
160  const std::vector<reco::MuonChamberMatch>& matches = muon->matches();
161  for( std::vector<reco::MuonChamberMatch>::const_iterator chamber = matches.begin(),
162  chamberEnd = matches.end();
163  chamber != chamberEnd; ++chamber )
164  {
165  // expected track position
166  localTrajectoryPoint[0] = chamber->x;
167  localTrajectoryPoint[1] = chamber->y;
168  localTrajectoryPoint[2] = 0;
169 
170  unsigned int rawid = chamber->id.rawId();
171  if( geom->contains( rawid ))
172  {
173  geom->localToGlobal( rawid, localTrajectoryPoint, globalTrajectoryPoint );
174  double phi = atan2( globalTrajectoryPoint[1], globalTrajectoryPoint[0] );
175  if( cos( phi - muon->standAloneMuon()->innerPosition().phi()) < 0 )
176  return true;
177  }
178  }
179  return false;
180 }
181 
182 }
183 
184 //
185 // constructors and destructor
186 //
188 {
189 }
190 
192 {
193 }
194 
195 //
196 // member functions
197 //
198 //______________________________________________________________________________
199 
200 void
202 {
203  // if auto field estimation mode, do extra loop over muons.
204  // use both inner and outer track if available
205  if( field->getSource() == FWMagField::kNone )
206  {
207  if( fabs( iData.eta() ) > 2.0 || iData.pt() < 3 ) return;
208  if( iData.innerTrack().isAvailable())
209  {
210  double estimate = fw::estimate_field( *( iData.innerTrack()), true );
211  if( estimate >= 0 ) field->guessField( estimate );
212  }
213  if( iData.outerTrack().isAvailable() )
214  {
215  double estimate = fw::estimate_field( *( iData.outerTrack()));
216  if( estimate >= 0 ) field->guessFieldIsOn( estimate > 0.5 );
217  }
218  }
219 }
220 
221 //______________________________________________________________________________
222 
223 void
225  const reco::Muon* muon,
226  TEveElement* tList,
227  bool showEndcap,
228  bool tracksOnly )
229 {
230  calculateField( *muon, pb->context().getField());
231 
232  TEveRecTrack recTrack;
233  recTrack.fBeta = 1.;
234 
235  // If we deal with a tracker muon we use the inner track and guide it
236  // through the trajectory points from the reconstruction. Segments
237  // represent hits. Matching between hits and the trajectory shows
238  // how well the inner track matches with the muon hypothesis.
239  //
240  // In other cases we use a global muon track with a few states from
241  // the inner and outer tracks or just the outer track if it's the
242  // only option
243 
244  if( muon->isTrackerMuon() &&
245  muon->innerTrack().isAvailable() &&
246  muon->isMatchesValid() &&
247  !buggyMuon( &*muon, pb->context().getGeom()))
248  {
249  TEveTrack* trk = fireworks::prepareTrack( *(muon->innerTrack()),
251  getRecoTrajectoryPoints( muon, pb->item()));
252  trk->MakeTrack();
253  pb->setupAddElement( trk, tList );
254  if( ! tracksOnly )
255  addMatchInformation( &(*muon), pb, tList, showEndcap );
256  return;
257  }
258 
259  if( muon->isGlobalMuon() &&
260  muon->globalTrack().isAvailable())
261  {
262  std::vector<TEveVector> extraPoints;
263  if( muon->innerTrack().isAvailable() && muon->innerTrack()->extra().isAvailable())
264  {
265  extraPoints.push_back( TEveVector( muon->innerTrack()->innerPosition().x(),
266  muon->innerTrack()->innerPosition().y(),
267  muon->innerTrack()->innerPosition().z()));
268  extraPoints.push_back( TEveVector( muon->innerTrack()->outerPosition().x(),
269  muon->innerTrack()->outerPosition().y(),
270  muon->innerTrack()->outerPosition().z()));
271  }
272  if( muon->outerTrack().isAvailable() && muon->outerTrack()->extra().isAvailable())
273  {
274  extraPoints.push_back( TEveVector( muon->outerTrack()->innerPosition().x(),
275  muon->outerTrack()->innerPosition().y(),
276  muon->outerTrack()->innerPosition().z()));
277  extraPoints.push_back( TEveVector( muon->outerTrack()->outerPosition().x(),
278  muon->outerTrack()->outerPosition().y(),
279  muon->outerTrack()->outerPosition().z()));
280  }
281  TEveTrack* trk = fireworks::prepareTrack( *( muon->globalTrack()),
283  extraPoints );
284  trk->MakeTrack();
285  pb->setupAddElement( trk, tList );
286  return;
287  }
288 
289  if( muon->innerTrack().isAvailable())
290  {
291  TEveTrack* trk = fireworks::prepareTrack( *( muon->innerTrack()), pb->context().getMuonTrackPropagator());
292  trk->MakeTrack();
293  pb->setupAddElement( trk, tList );
294  return;
295  }
296 
297  if( muon->outerTrack().isAvailable())
298  {
299  TEveTrack* trk = fireworks::prepareTrack( *( muon->outerTrack()), pb->context().getMuonTrackPropagator());
300  trk->MakeTrack();
301  pb->setupAddElement( trk, tList );
302  return;
303  }
304 
305  // if got that far it means we have nothing but a candidate
306  // show it anyway.
307  TEveTrack* trk = fireworks::prepareCandidate( *muon, pb->context().getMuonTrackPropagator());
308  trk->MakeTrack();
309  pb->setupAddElement( trk, tList );
310 }
bool isAvailable() const
Definition: Ref.h:614
const fireworks::Context & context() const
TEveTrack * prepareTrack(const reco::Track &track, TEveTrackPropagator *propagator, const std::vector< TEveVector > &extraRefPoints=std::vector< TEveVector >())
Definition: TrackUtils.cc:73
virtual TrackRef innerTrack() const
Definition: Muon.h:48
IdToInfoItr find(unsigned int) const
Definition: FWGeometry.cc:358
bool isTrackerMuon() const
Definition: Muon.h:219
const FWGeometry * getGeom() const
Definition: Context.h:83
void setupAddElement(TEveElement *el, TEveElement *parent, bool set_color=true) const
bool isGlobalMuon() const
Definition: Muon.h:218
bool isMatchesValid() const
Definition: Muon.h:138
void buildMuon(FWProxyBuilderBase *, const reco::Muon *muon, TEveElement *tList, bool showEndcap, bool onlyTracks=false)
virtual ~FWMuonBuilder()
virtual double eta() const
momentum pseudorapidity
virtual double pt() const
transverse momentum
const FWEventItem * item() const
double estimate_field(const reco::Track &track, bool highQuality=false)
void calculateField(const reco::Muon &iData, FWMagField *field)
static const int CSC
Definition: MuonSubdetId.h:13
void createSegment(int detector, bool matchedSegment, float segmentLength, float segmentLimit, float *segmentPosition, float *segmentDirection, float *segmentInnerPoint, float *segmentOuterPoint)
Definition: SegmentUtils.cc:10
FWMagField * getField() const
Definition: Context.h:77
TEveGeoShape * getEveShape(unsigned int id) const
Definition: FWGeometry.cc:253
void guessField(float estimate) const
Definition: FWMagField.cc:155
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
void localToGlobal(unsigned int id, const float *local, float *global, bool translatep=true) const
Definition: FWGeometry.cc:328
bool contains(unsigned int id) const
Definition: FWGeometry.h:109
ESource getSource() const
Definition: FWMagField.h:33
virtual TrackRef outerTrack() const
reference to Track reconstructed in the muon detector only
Definition: Muon.h:51
TEveTrackPropagator * getMuonTrackPropagator() const
Definition: Context.h:75
#define fwLog(_level_)
Definition: fwLog.h:50
std::vector< MuonChamberMatch > & matches()
get muon matching information
Definition: Muon.h:140
TEveTrack * prepareCandidate(const reco::Candidate &track, TEveTrackPropagator *propagator)
void guessFieldIsOn(bool guess) const
Definition: FWMagField.cc:148
std::vector< FWGeometry::GeomDetInfo >::const_iterator IdToInfoItr
Definition: FWGeometry.h:107
const FWGeometry * getGeom() const
Definition: FWEventItem.cc:681
virtual TrackRef globalTrack() const
reference to Track reconstructed in both tracked and muon detector
Definition: Muon.h:54
Definition: DDAxes.h:10
virtual TrackRef standAloneMuon() const
reference to a stand-alone muon Track
Definition: Muon.h:52