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  if (gs == nullptr && (*i != nullptr)) {
106  std::cerr << "Got a " << typeid(**i).name() << ", expecting TEveGeoShape. ignoring (it must be the clusters)." << std::endl;
107  continue;
108  }
109  gs->SetMainTransparency(75);
110  gs->SetPickable(kFALSE);
111 
112  TString name = gs->GetElementTitle();
113  if (!name.Contains("BAD") && !name.Contains("INACTIVE") && !name.Contains("LOST")) {
114  gs->SetMainColor(kBlue);
115  }
116  TEveText* text = new TEveText(name.Data());
117  text->PtrMainTrans()->SetFrom(gs->RefMainTrans().Array());
118  text->SetFontMode(TGLFont::kPixmap);
119  text->SetFontSize(12);
120  m_moduleLabels->AddElement(text);
121  }
122  m_moduleLabels->SetRnrChildren(false);
123 
124  TEveTrackPropagator* prop = new TEveTrackPropagator();
125  prop->SetMagFieldObj(item()->context().getField(), false);
126  prop->SetStepper(TEveTrackPropagator::kRungeKutta);
127  prop->SetMaxR(123);
128  prop->SetMaxZ(300);
129  prop->SetMaxStep(1);
130  TEveTrack* trk = fireworks::prepareTrack( *track, prop );
131  trk->MakeTrack();
132  trk->SetLineWidth(2);
133  trk->SetTitle( "Track and its ref states" );
134  prop->SetRnrDaughters(kTRUE);
135  prop->SetRnrReferences(kTRUE);
136  prop->SetRnrDecay(kTRUE);
137  prop->SetRnrFV(kTRUE);
138  trk->SetMainColor(id.item()->defaultDisplayProperties().color());
139  m_eveScene->AddElement(trk);
140 
141  viewerGL()->SetStyle(TGLRnrCtx::kOutline);
142  viewerGL()->SetDrawCameraCenter(kTRUE);
143  viewerGL()->ResetCamerasAfterNextUpdate();
144  viewerGL()->UpdateScene(kFALSE);
145  gEve->Redraw3D();
146 
147  setTextInfo(id, track);
148 }
149 
150 void
152 {
153  // Callback for cmsShow change of background
154 
156 
157  // adopt label colors to background, this should be implemneted in TEveText
158  if (m_moduleLabels)
159  {
160  Color_t x = viewerGL()->GetRnrCtx()->ColorSet().Foreground().GetColorIndex();
161  for (TEveElement::List_i i=m_moduleLabels->BeginChildren(); i!=m_moduleLabels->EndChildren(); ++i)
162  (*i)->SetMainColor(x);
163  }
164 }
165 
166 void
168 {
169  viewerGL()->PickCameraCenter();
170 }
171 
172 void
174 {
175  for (TEveElement::List_i i=m_modules->BeginChildren(); i!=m_modules->EndChildren(); ++i)
176  {
177  (*i)->SetMainTransparency(x);
178  }
179  gEve->Redraw3D();
180 }
181 
182 void
184 {
185  m_infoCanvas->cd();
186 
187  float_t x = 0.02;
188  float y = 0.95;
189 
190  TLatex* latex = new TLatex( x, y, "" );
191  const double textsize( 0.07 );
192  latex->SetTextSize( 2*textsize );
193 
194  latex->DrawLatex( x, y, id.item()->modelName( id.index()).c_str());
195  y -= latex->GetTextSize()*0.6;
196 
197  latex->SetTextSize( textsize );
198  float lineH = latex->GetTextSize()*0.6;
199 
200  latex->DrawLatex( x, y, Form( " P_{T} = %.1f GeV, #eta = %0.2f, #varphi = %0.2f",
201  track->pt(), track->eta(), track->phi()));
202  y -= lineH;
203 
204  if( track->charge() > 0 )
205  latex->DrawLatex( x, y, " charge = +1" );
206  else
207  latex->DrawLatex( x, y, " charge = -1" );
208  y -= lineH;
209  y -= lineH;
210 
211  latex->DrawLatex( x, y, "Track modules:");
212  y -= lineH;
213 
214  Double_t pos[4];
215  pos[0] = x+0.05;
216  pos[2] = x+0.20;
217  Double_t boxH = 0.25*textsize;
218 
219  pos[1] = y; pos[3] = pos[1] + boxH;
220  FWDetailViewBase::drawCanvasBox( pos, kBlue );
221  latex->DrawLatex( x + 0.25, y, "Module" );
222  y -= lineH;
223 
224  pos[1] = y; pos[3] = pos[1] + boxH;
225  FWDetailViewBase::drawCanvasBox( pos, kRed );
226  latex->DrawLatex( x + 0.25, y, "LOST Module" );
227  y -= lineH;
228 
229  pos[1] = y; pos[3] = pos[1] + boxH;
231  latex->DrawLatex( x + 0.25, y, "INACTIVE Module" );
232  y -= lineH;
233 
234  pos[1] = y; pos[3] = pos[1] + boxH;
236  latex->DrawLatex( x + 0.25, y, "BAD Module" );
237  y -= lineH;
238 
239  Float_t r = 0.01;
240  Float_t r2 = 0.02;
241  y -= lineH;
242  drawCanvasDot( x + r2, y, r2, kGreen );
243  y -= r;
244  latex->DrawLatex( x + 3 * r2, y, "Pixel Hits" );
245  y -= lineH;
246 
247  drawCanvasDot( x + r2, y, r2, kRed);
248  y -= r;
249  latex->DrawLatex( x + 3 * r2, y, "Extra Pixel Hits" );
250  y -= lineH;
251 
252  m_legend->SetY2(y);
253  m_legend->Draw();
254  m_legend = nullptr; // Deleted together with TPad.
255 }
256 
257 void
259 {
260  m_legend = new TLegend( 0.01, 0.01, 0.99, 0.99, nullptr, "NDC" );
261  m_legend->SetFillColor(kWhite);
262  m_legend->SetTextSize( 0.07 );
263  m_legend->SetBorderSize( 0 );
264  m_legend->SetMargin( 0.15 );
265  m_legend->SetEntrySeparation( 0.01 );
266 
267  TEveStraightLineSet *legend = new TEveStraightLineSet( "siStripCluster" );
268  legend->SetLineWidth( 3 );
269  legend->SetLineColor( kGreen );
270  m_legend->AddEntry( legend, "Exact SiStripCluster", "l");
271 
272  TEveStraightLineSet *legend2 = new TEveStraightLineSet( "siStripCluster2" );
273  legend2->SetLineWidth( 3 );
274  legend2->SetLineColor( kRed );
275  m_legend->AddEntry( legend2, "Extra SiStripCluster", "l");
276 
277  TEveStraightLineSet *legend3 = new TEveStraightLineSet( "refStates" );
278  legend3->SetDepthTest( kFALSE );
279  legend3->SetMarkerColor( kYellow );
280  legend3->SetMarkerStyle( kPlus );
281  legend3->SetMarkerSize( 2 );
282  m_legend->AddEntry( legend3, "Inner/Outermost States", "p");
283 
284  TEveStraightLineSet *legend4 = new TEveStraightLineSet( "vertex" );
285  legend4->SetDepthTest( kFALSE );
286  legend4->SetMarkerColor( kRed );
287  legend4->SetMarkerStyle( kFullDotLarge );
288  legend4->SetMarkerSize( 2 );
289  m_legend->AddEntry( legend4, "Vertex", "p");
290 
291  TEveStraightLineSet *legend5 = new TEveStraightLineSet( "cameraCenter" );
292  legend5->SetDepthTest( kFALSE );
293  legend5->SetMarkerColor( kCyan );
294  legend5->SetMarkerStyle( kFullDotLarge );
295  legend5->SetMarkerSize( 2 );
296  m_legend->AddEntry( legend5, "Camera center", "p");
297 }
298 
299 void
300 FWTrackHitsDetailView::addTrackerHits3D( std::vector<TVector3> &points, class TEveElementList *tList, Color_t color, int size )
301 {
302  // !AT this is detail view specific, should move to track hits
303  // detail view
304 
305  TEvePointSet* pointSet = new TEvePointSet();
306  pointSet->SetMarkerSize(size);
307  pointSet->SetMarkerStyle(4);
308  pointSet->SetPickable(kTRUE);
309  pointSet->SetTitle("Pixel Hits");
310  pointSet->SetMarkerColor(color);
311 
312  for( std::vector<TVector3>::const_iterator it = points.begin(), itEnd = points.end(); it != itEnd; ++it) {
313  pointSet->SetNextPoint(it->x(), it->y(), it->z());
314  }
315  tList->AddElement(pointSet);
316 }
317 
318 void
320  const FWEventItem* iItem,
321  TEveElement* trkList,
322  bool addNearbyHits )
323 {
324  std::vector<TVector3> pixelPoints;
325  fireworks::pushPixelHits( pixelPoints, *iItem, track );
326  TEveElementList* pixels = new TEveElementList( "Pixels" );
327  trkList->AddElement( pixels );
328  if( addNearbyHits )
329  {
330  // get the extra hits
331  std::vector<TVector3> pixelExtraPoints;
332  fireworks::pushNearbyPixelHits( pixelExtraPoints, *iItem, track );
333  // draw first the others
334  addTrackerHits3D( pixelExtraPoints, pixels, kRed, 1 );
335  // then the good ones, so they're on top
336  addTrackerHits3D( pixelPoints, pixels, kGreen, 1 );
337  }
338  else
339  {
340  // just add those points with the default color
341  addTrackerHits3D( pixelPoints, pixels, iItem->defaultDisplayProperties().color(), 1 );
342  }
343 
344  // strips
345  TEveElementList* strips = new TEveElementList( "Strips" );
346  trkList->AddElement( strips );
347  fireworks::addSiStripClusters( iItem, track, strips, addNearbyHits, false );
348 }
349 
350 //______________________________________________________________________________
351 
352 void
354  const FWEventItem* iItem,
355  TEveElement* trkList,
356  bool addLostHits )
357 {
358  std::set<unsigned int> ids;
359  for( trackingRecHit_iterator recIt = track.recHitsBegin(), recItEnd = track.recHitsEnd();
360  recIt != recItEnd; ++recIt )
361  {
362  DetId detid = (*recIt)->geographicalId();
363  if( !addLostHits && !(*recIt)->isValid()) continue;
364  if( detid.rawId() != 0 )
365  {
366  TString name("");
367  switch( detid.det())
368  {
369  case DetId::Tracker:
370  name = iItem->getGeom()->getTrackerTopology()->print(detid);
371  break;
372 
373  case DetId::Muon:
374  switch( detid.subdetId())
375  {
376  case MuonSubdetId::DT:
377  name = "DT";
378  detid = DetId( DTChamberId( detid )); // get rid of layer bits
379  break;
380  case MuonSubdetId::CSC:
381  name = "CSC";
382  break;
383  case MuonSubdetId::RPC:
384  name = "RPC";
385  break;
386  case MuonSubdetId::GEM:
387  name = "GEM";
388  break;
389  case MuonSubdetId::ME0:
390  name = "ME0";
391  break;
392  default:
393  break;
394  }
395  break;
396  default:
397  break;
398  }
399  if( ! ids.insert( detid.rawId()).second ) continue;
400  if( iItem->getGeom())
401  {
402  TEveGeoShape* shape = iItem->getGeom()->getEveShape( detid );
403  if( nullptr != shape )
404  {
405  shape->SetMainTransparency( 65 );
406  shape->SetPickable( kTRUE );
407  switch(( *recIt )->type())
408  {
410  shape->SetMainColor( iItem->defaultDisplayProperties().color());
411  break;
415  name += "LOST ";
416  shape->SetMainColor( kRed );
417  break;
421  name += "INACTIVE ";
422  shape->SetMainColor( 28 );
423  break;
424  case TrackingRecHit::bad:
425  name += "BAD ";
426  shape->SetMainColor( 218 );
427  break;
428  }
429  shape->SetTitle( name + ULong_t( detid.rawId()));
430  trkList->AddElement( shape );
431  }
432  else
433  {
434  fwLog( fwlog::kInfo ) << "Failed to get shape extract for a tracking rec hit: "
435  << "\n" << fireworks::info( detid ) << std::endl;
436  }
437  }
438  }
439  }
440 }
441 
442 void
444 {
445  m_moduleLabels->SetRnrChildren(!m_moduleLabels->GetRnrChildren());
446  gEve->Redraw3D();
447 }
448 
size
Write out results.
bool isAvailable() const
Definition: Ref.h:577
void setTextInfo(const FWModelId &id, const reco::Track *) override
const FWDisplayProperties & defaultDisplayProperties() const
Definition: FWEventItem.cc:453
TEveElementList * m_modules
TGLViewer * viewerGL() const
const TrackExtraRef & extra() const
reference to "extra" object
Definition: Track.h:189
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
static const int GEM
Definition: MuonSubdetId.h:15
const FWEventItem * item()
sigc::signal< void > activated
Definition: CSGAction.h:88
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:47
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:645
void addTrackerHits3D(std::vector< TVector3 > &points, class TEveElementList *tList, Color_t color, int size)
#define nullptr
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
static const int ME0
Definition: MuonSubdetId.h:16
static const int CSC
Definition: MuonSubdetId.h:13
const fireworks::Context & context() const
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:651
void setToolTip(const std::string &tip)
Definition: CSGAction.cc:116
TEveGeoShape * getEveShape(unsigned int id) const
Definition: FWGeometry.cc:270
double pt() const
track transverse momentum
Definition: TrackBase.h:621
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]
#define end
Definition: vmac.h:39
void pushPixelHits(std::vector< TVector3 > &pixelPoints, const FWEventItem &iItem, const reco::Track &t)
Definition: TrackUtils.cc:576
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
Definition: Track.h:104
void addSiStripClusters(const FWEventItem *iItem, const reco::Track &t, class TEveElement *tList, bool addNearbyClusters, bool master)
Definition: TrackUtils.cc:352
void build(const FWModelId &id, const reco::Track *) override
Definition: DetId.h:18
TEveElementList * m_moduleLabels
#define fwLog(_level_)
Definition: fwLog.h:50
double b
Definition: hdecay.h:120
void addModules(const reco::Track &track, const FWEventItem *iItem, TEveElement *trkList, bool addLostHits)
#define REGISTER_FWDETAILVIEW(_classname_, _name_,...)
static const int RPC
Definition: MuonSubdetId.h:14
std::string info(const DetId &)
Definition: TrackUtils.cc:657
col
Definition: cuy.py:1009
static Bool_t setColorSetViewer(TGLViewer *, Color_t)
FWIntValueListener * m_sliderListener
int charge() const
track electric charge
Definition: TrackBase.h:567
static const int DT
Definition: MuonSubdetId.h:12
const TrackerTopology * getTrackerTopology() const
Definition: FWGeometry.h:129
Definition: AbsArchive.cc:53
void pushNearbyPixelHits(std::vector< TVector3 > &pixelPoints, const FWEventItem &iItem, const reco::Track &t)
Definition: TrackUtils.cc:518
const FWGeometry * getGeom() const
Definition: FWEventItem.cc:683
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:109