CMS 3D CMS Logo

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