CMS 3D CMS Logo

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