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