CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FWTrackHitsDetailView.cc
Go to the documentation of this file.
1 // ROOT includes
2 #include "TGLFontManager.h"
3 #include "TEveScene.h"
4 #include "TEveManager.h"
5 #include "TEveStraightLineSet.h"
6 #include "TEveTrack.h"
7 #include "TEveTrackPropagator.h"
8 #include "TEveTrans.h"
9 #include "TEveText.h"
10 #include "TEveGeoShape.h"
11 #include "TGSlider.h"
12 #include "TGButton.h"
13 #include "TGLabel.h"
14 #include "TGLViewer.h"
15 #include "TCanvas.h"
16 #include "TLatex.h"
17 #include "TLegend.h"
18 
19 // CMSSW includes
24 
25 // Fireworks includes
34 
37 
39  m_modules(0),
40  m_moduleLabels(0),
41  m_hits(0),
42  m_slider(0),
43  m_sliderListener(),
44  m_legend(0)
45 {}
46 
48 {
49 }
50 
51 void
53 {
54  {
55  TGCompositeFrame* f = new TGVerticalFrame(m_guiFrame);
56  m_guiFrame->AddFrame(f);
57  f->AddFrame(new TGLabel(f, "Module Transparency:"), new TGLayoutHints(kLHintsLeft, 2, 2, 0, 0));
58  m_slider = new TGHSlider(f, 120, kSlider1 | kScaleNo);
59  f->AddFrame(m_slider, new TGLayoutHints(kLHintsTop | kLHintsLeft, 2, 2, 1, 4));
60  m_slider->SetRange(0, 100);
61  m_slider->SetPosition(75);
62 
64  TQObject::Connect(m_slider, "PositionChanged(Int_t)", "FWIntValueListenerBase", m_sliderListener, "setValue(Int_t)");
66  }
67 
68  {
69  CSGAction* action = new CSGAction(this, "Show Module Labels");
70  TGCheckButton* b = new TGCheckButton(m_guiFrame, "Show Module Labels" );
71  b->SetState(kButtonUp, false);
72  m_guiFrame->AddFrame(b, new TGLayoutHints( kLHintsNormal, 2, 3, 1, 4));
73  TQObject::Connect(b, "Clicked()", "CSGAction", action, "activate()");
74  action->activated.connect(sigc::mem_fun(this, &FWTrackHitsDetailView::rnrLabels));
75  }
76  {
77  CSGAction* action = new CSGAction(this, " Pick Camera Center ");
78  action->createTextButton(m_guiFrame, new TGLayoutHints( kLHintsNormal, 2, 0, 1, 4));
79  action->setToolTip("Click on object in viewer to set camera center.");
80  action->activated.connect(sigc::mem_fun(this, &FWTrackHitsDetailView::pickCameraCenter));
81  }
82  makeLegend();
83 
84  TGCompositeFrame* p = (TGCompositeFrame*)m_guiFrame->GetParent();
85  p->MapSubwindows();
86  p->Layout();
87 
88  m_modules = new TEveElementList( "Modules" );
89  m_eveScene->AddElement( m_modules );
90  m_moduleLabels = new TEveElementList( "Modules" );
91  m_eveScene->AddElement( m_moduleLabels );
92  m_hits = new TEveElementList( "Hits" );
93  m_eveScene->AddElement( m_hits );
94  if( track->extra().isAvailable())
95  {
96  addModules( *track, id.item(), m_modules, true );
97  addHits( *track, id.item(), m_hits, true );
98  }
99  for( TEveElement::List_i i = m_modules->BeginChildren(), end = m_modules->EndChildren(); i != end; ++i )
100  {
101  TEveGeoShape* gs = dynamic_cast<TEveGeoShape*>(*i);
102  if (gs == 0 && (*i != 0)) {
103  std::cerr << "Got a " << typeid(**i).name() << ", expecting TEveGeoShape. ignoring (it must be the clusters)." << std::endl;
104  continue;
105  }
106  gs->SetMainTransparency(75);
107  gs->SetPickable(kFALSE);
108 
109  TString name = gs->GetElementTitle();
110  if (!name.Contains("BAD") && !name.Contains("INACTIVE") && !name.Contains("LOST")) {
111  gs->SetMainColor(kBlue);
112  }
113  TEveText* text = new TEveText(name.Data());
114  text->PtrMainTrans()->SetFrom(gs->RefMainTrans().Array());
115  text->SetFontMode(TGLFont::kPixmap);
116  text->SetFontSize(12);
117  m_moduleLabels->AddElement(text);
118  }
119  m_moduleLabels->SetRnrChildren(false);
120 
121  TEveTrackPropagator* prop = new TEveTrackPropagator();
122  prop->SetMagFieldObj(item()->context().getField(), false);
123  prop->SetStepper(TEveTrackPropagator::kRungeKutta);
124  prop->SetMaxR(123);
125  prop->SetMaxZ(300);
126  prop->SetMaxStep(1);
127  TEveTrack* trk = fireworks::prepareTrack( *track, prop );
128  trk->MakeTrack();
129  trk->SetLineWidth(2);
130  trk->SetTitle( "Track and its ref states" );
131  prop->SetRnrDaughters(kTRUE);
132  prop->SetRnrReferences(kTRUE);
133  prop->SetRnrDecay(kTRUE);
134  prop->SetRnrFV(kTRUE);
135  trk->SetMainColor(id.item()->defaultDisplayProperties().color());
136  m_eveScene->AddElement(trk);
137 
138  viewerGL()->SetStyle(TGLRnrCtx::kOutline);
139  viewerGL()->SetDrawCameraCenter(kTRUE);
140  viewerGL()->ResetCamerasAfterNextUpdate();
141  viewerGL()->UpdateScene(kFALSE);
142  gEve->Redraw3D();
143 
144  setTextInfo(id, track);
145 }
146 
147 void
149 {
150  // Callback for cmsShow change of background
151 
153 
154  // adopt label colors to background, this should be implemneted in TEveText
155  if (m_moduleLabels)
156  {
157  Color_t x = viewerGL()->GetRnrCtx()->ColorSet().Foreground().GetColorIndex();
158  for (TEveElement::List_i i=m_moduleLabels->BeginChildren(); i!=m_moduleLabels->EndChildren(); ++i)
159  (*i)->SetMainColor(x);
160  }
161 }
162 
163 void
165 {
166  viewerGL()->PickCameraCenter();
167 }
168 
169 void
171 {
172  for (TEveElement::List_i i=m_modules->BeginChildren(); i!=m_modules->EndChildren(); ++i)
173  {
174  (*i)->SetMainTransparency(x);
175  }
176  gEve->Redraw3D();
177 }
178 
179 void
181 {
182  m_infoCanvas->cd();
183 
184  float_t x = 0.02;
185  float y = 0.95;
186 
187  TLatex* latex = new TLatex( x, y, "" );
188  const double textsize( 0.07 );
189  latex->SetTextSize( 2*textsize );
190 
191  latex->DrawLatex( x, y, id.item()->modelName( id.index()).c_str());
192  y -= latex->GetTextSize()*0.6;
193 
194  latex->SetTextSize( textsize );
195  float lineH = latex->GetTextSize()*0.6;
196 
197  latex->DrawLatex( x, y, Form( " P_{T} = %.1f GeV, #eta = %0.2f, #varphi = %0.2f",
198  track->pt(), track->eta(), track->phi()));
199  y -= lineH;
200 
201  if( track->charge() > 0 )
202  latex->DrawLatex( x, y, " charge = +1" );
203  else
204  latex->DrawLatex( x, y, " charge = -1" );
205  y -= lineH;
206  y -= lineH;
207 
208  latex->DrawLatex( x, y, "Track modules:");
209  y -= lineH;
210 
211  Double_t pos[4];
212  pos[0] = x+0.05;
213  pos[2] = x+0.20;
214  Double_t boxH = 0.25*textsize;
215 
216  pos[1] = y; pos[3] = pos[1] + boxH;
217  FWDetailViewBase::drawCanvasBox( pos, kBlue );
218  latex->DrawLatex( x + 0.25, y, "Module" );
219  y -= lineH;
220 
221  pos[1] = y; pos[3] = pos[1] + boxH;
222  FWDetailViewBase::drawCanvasBox( pos, kRed );
223  latex->DrawLatex( x + 0.25, y, "LOST Module" );
224  y -= lineH;
225 
226  pos[1] = y; pos[3] = pos[1] + boxH;
228  latex->DrawLatex( x + 0.25, y, "INACTIVE Module" );
229  y -= lineH;
230 
231  pos[1] = y; pos[3] = pos[1] + boxH;
233  latex->DrawLatex( x + 0.25, y, "BAD Module" );
234  y -= lineH;
235 
236  Float_t r = 0.01;
237  Float_t r2 = 0.02;
238  y -= lineH;
239  drawCanvasDot( x + r2, y, r2, kGreen );
240  y -= r;
241  latex->DrawLatex( x + 3 * r2, y, "Pixel Hits" );
242  y -= lineH;
243 
244  drawCanvasDot( x + r2, y, r2, kRed);
245  y -= r;
246  latex->DrawLatex( x + 3 * r2, y, "Extra Pixel Hits" );
247  y -= lineH;
248 
249  m_legend->SetY2(y);
250  m_legend->Draw();
251  m_legend = 0; // Deleted together with TPad.
252 }
253 
254 void
256 {
257  m_legend = new TLegend( 0.01, 0.01, 0.99, 0.99, 0, "NDC" );
258  m_legend->SetFillColor(kWhite);
259  m_legend->SetTextSize( 0.07 );
260  m_legend->SetBorderSize( 0 );
261  m_legend->SetMargin( 0.15 );
262  m_legend->SetEntrySeparation( 0.01 );
263 
264  TEveStraightLineSet *legend = new TEveStraightLineSet( "siStripCluster" );
265  legend->SetLineWidth( 3 );
266  legend->SetLineColor( kGreen );
267  m_legend->AddEntry( legend, "Exact SiStripCluster", "l");
268 
269  TEveStraightLineSet *legend2 = new TEveStraightLineSet( "siStripCluster2" );
270  legend2->SetLineWidth( 3 );
271  legend2->SetLineColor( kRed );
272  m_legend->AddEntry( legend2, "Extra SiStripCluster", "l");
273 
274  TEveStraightLineSet *legend3 = new TEveStraightLineSet( "refStates" );
275  legend3->SetDepthTest( kFALSE );
276  legend3->SetMarkerColor( kYellow );
277  legend3->SetMarkerStyle( kPlus );
278  legend3->SetMarkerSize( 2 );
279  m_legend->AddEntry( legend3, "Inner/Outermost States", "p");
280 
281  TEveStraightLineSet *legend4 = new TEveStraightLineSet( "vertex" );
282  legend4->SetDepthTest( kFALSE );
283  legend4->SetMarkerColor( kRed );
284  legend4->SetMarkerStyle( kFullDotLarge );
285  legend4->SetMarkerSize( 2 );
286  m_legend->AddEntry( legend4, "Vertex", "p");
287 
288  TEveStraightLineSet *legend5 = new TEveStraightLineSet( "cameraCenter" );
289  legend5->SetDepthTest( kFALSE );
290  legend5->SetMarkerColor( kCyan );
291  legend5->SetMarkerStyle( kFullDotLarge );
292  legend5->SetMarkerSize( 2 );
293  m_legend->AddEntry( legend5, "Camera center", "p");
294 }
295 
296 void
297 FWTrackHitsDetailView::addTrackerHits3D( std::vector<TVector3> &points, class TEveElementList *tList, Color_t color, int size )
298 {
299  // !AT this is detail view specific, should move to track hits
300  // detail view
301 
302  TEvePointSet* pointSet = new TEvePointSet();
303  pointSet->SetMarkerSize(size);
304  pointSet->SetMarkerStyle(4);
305  pointSet->SetPickable(kTRUE);
306  pointSet->SetTitle("Pixel Hits");
307  pointSet->SetMarkerColor(color);
308 
309  for( std::vector<TVector3>::const_iterator it = points.begin(), itEnd = points.end(); it != itEnd; ++it) {
310  pointSet->SetNextPoint(it->x(), it->y(), it->z());
311  }
312  tList->AddElement(pointSet);
313 }
314 
315 void
317  const FWEventItem* iItem,
318  TEveElement* trkList,
319  bool addNearbyHits )
320 {
321  std::vector<TVector3> pixelPoints;
322  fireworks::pushPixelHits( pixelPoints, *iItem, track );
323  TEveElementList* pixels = new TEveElementList( "Pixels" );
324  trkList->AddElement( pixels );
325  if( addNearbyHits )
326  {
327  // get the extra hits
328  std::vector<TVector3> pixelExtraPoints;
329  fireworks::pushNearbyPixelHits( pixelExtraPoints, *iItem, track );
330  // draw first the others
331  addTrackerHits3D( pixelExtraPoints, pixels, kRed, 1 );
332  // then the good ones, so they're on top
333  addTrackerHits3D( pixelPoints, pixels, kGreen, 1 );
334  }
335  else
336  {
337  // just add those points with the default color
338  addTrackerHits3D( pixelPoints, pixels, iItem->defaultDisplayProperties().color(), 1 );
339  }
340 
341  // strips
342  TEveElementList* strips = new TEveElementList( "Strips" );
343  trkList->AddElement( strips );
344  fireworks::addSiStripClusters( iItem, track, strips, addNearbyHits, false );
345 }
346 
347 //______________________________________________________________________________
348 
349 void
351  const FWEventItem* iItem,
352  TEveElement* trkList,
353  bool addLostHits )
354 {
355  std::set<unsigned int> ids;
356  for( trackingRecHit_iterator recIt = track.recHitsBegin(), recItEnd = track.recHitsEnd();
357  recIt != recItEnd; ++recIt )
358  {
359  DetId detid = (*recIt)->geographicalId();
360  if( !addLostHits && !(*recIt)->isValid()) continue;
361  if( detid.rawId() != 0 )
362  {
363  TString name("");
364  switch( detid.det())
365  {
366  case DetId::Tracker:
367  switch( detid.subdetId())
368  {
369  case SiStripDetId::TIB:
370  name = "TIB ";
371  break;
372  case SiStripDetId::TOB:
373  name = "TOB ";
374  break;
375  case SiStripDetId::TID:
376  name = "TID ";
377  break;
378  case SiStripDetId::TEC:
379  name = "TEC ";
380  break;
382  name = "Pixel Barrel ";
383  break;
385  name = "Pixel Endcap ";
386  default:
387  break;
388  }
389  break;
390 
391  case DetId::Muon:
392  switch( detid.subdetId())
393  {
394  case MuonSubdetId::DT:
395  name = "DT";
396  detid = DetId( DTChamberId( detid )); // get rid of layer bits
397  break;
398  case MuonSubdetId::CSC:
399  name = "CSC";
400  break;
401  case MuonSubdetId::RPC:
402  name = "RPC";
403  break;
404  default:
405  break;
406  }
407  break;
408  default:
409  break;
410  }
411  if( ! ids.insert( detid.rawId()).second ) continue;
412  if( iItem->getGeom())
413  {
414  TEveGeoShape* shape = iItem->getGeom()->getEveShape( detid );
415  if( 0 != shape )
416  {
417  shape->SetMainTransparency( 65 );
418  shape->SetPickable( kTRUE );
419  switch(( *recIt )->type())
420  {
422  shape->SetMainColor( iItem->defaultDisplayProperties().color());
423  break;
425  name += "LOST ";
426  shape->SetMainColor( kRed );
427  break;
429  name += "INACTIVE ";
430  shape->SetMainColor( 28 );
431  break;
432  case TrackingRecHit::bad:
433  name += "BAD ";
434  shape->SetMainColor( 218 );
435  break;
436  }
437  shape->SetTitle( name + ULong_t( detid.rawId()));
438  trkList->AddElement( shape );
439  }
440  else
441  {
442  fwLog( fwlog::kInfo ) << "Failed to get shape extract for a tracking rec hit: "
443  << "\n" << fireworks::info( detid ) << std::endl;
444  }
445  }
446  }
447  }
448 }
449 
450 void
452 {
453  m_moduleLabels->SetRnrChildren(!m_moduleLabels->GetRnrChildren());
454  gEve->Redraw3D();
455 }
456 
int i
Definition: DBlmapReader.cc:9
const FWDisplayProperties & defaultDisplayProperties() const
Definition: FWEventItem.cc:451
TEveElementList * m_modules
TGLViewer * viewerGL() const
const TrackExtraRef & extra() const
reference to &quot;extra&quot; object
Definition: Track.h:97
TEveTrack * prepareTrack(const reco::Track &track, TEveTrackPropagator *propagator, const std::vector< TEveVector > &extraRefPoints=std::vector< TEveVector >())
Definition: TrackUtils.cc:70
const FWEventItem * item()
sigc::signal< void > activated
Definition: CSGAction.h:89
void addHits(const reco::Track &track, const FWEventItem *iItem, TEveElement *trkList, bool addNearbyHits)
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:139
void addTrackerHits3D(std::vector< TVector3 > &points, class TEveElementList *tList, Color_t color, int size)
bool isAvailable() const
Definition: Ref.h:275
Color_t color() const
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
U second(std::pair< T, U > const &p)
static const int CSC
Definition: MuonSubdetId.h:15
const fireworks::Context & context() const
void setTextInfo(const FWModelId &id, const reco::Track *)
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:141
void setToolTip(const std::string &tip)
Definition: CSGAction.cc:106
TEveGeoShape * getEveShape(unsigned int id) const
Definition: FWGeometry.cc:251
double pt() const
track transverse momentum
Definition: TrackBase.h:131
static void drawCanvasDot(Float_t x, Float_t y, Float_t r, Color_t)
sigc::signal< void, Int_t > valueChanged_
TGCompositeFrame * m_guiFrame
double f[11][100]
tuple text
Definition: runonSM.py:42
#define end
Definition: vmac.h:38
void pushPixelHits(std::vector< TVector3 > &pixelPoints, const FWEventItem &iItem, const reco::Track &t)
Definition: TrackUtils.cc:622
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
Definition: Track.h:63
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
void addSiStripClusters(const FWEventItem *iItem, const reco::Track &t, class TEveElement *tList, bool addNearbyClusters, bool master)
Definition: TrackUtils.cc:404
Definition: DetId.h:20
TEveElementList * m_moduleLabels
#define fwLog(_level_)
Definition: fwLog.h:51
virtual void setBackgroundColor(Color_t)
double b
Definition: hdecay.h:120
void addModules(const reco::Track &track, const FWEventItem *iItem, TEveElement *trkList, bool addLostHits)
void createTextButton(TGCompositeFrame *p, TGLayoutHints *l=0, Int_t id=-1, GContext_t norm=TGButton::GetDefaultGC()(), FontStruct_t font=TGTextButton::GetDefaultFontStruct(), UInt_t option=kRaisedFrame|kDoubleBorder)
Definition: CSGAction.cc:116
void build(const FWModelId &id, const reco::Track *)
static const int RPC
Definition: MuonSubdetId.h:16
#define REGISTER_FWDETAILVIEW(_classname_, _name_)
std::string info(const DetId &)
Definition: TrackUtils.cc:703
static Bool_t setColorSetViewer(TGLViewer *, Color_t)
FWIntValueListener * m_sliderListener
int charge() const
track electric charge
Definition: TrackBase.h:113
static const int DT
Definition: MuonSubdetId.h:14
Definition: DDAxes.h:10
Detector det() const
get the detector field from this detid
Definition: DetId.h:37
void pushNearbyPixelHits(std::vector< TVector3 > &pixelPoints, const FWEventItem &iItem, const reco::Track &t)
Definition: TrackUtils.cc:566
tuple size
Write out results.
const FWGeometry * getGeom() const
Definition: FWEventItem.cc:687
static void drawCanvasBox(Double_t *pos, Color_t fillCol, Int_t fillType=0, bool bg=kTRUE)
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.
Definition: Track.h:65