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