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