CMS 3D CMS Logo

FWPFCandidateDetailView.cc
Go to the documentation of this file.
1 // ROOT includes
2 #include "TEveScene.h"
3 #include "TEveManager.h"
4 #include "TEveStraightLineSet.h"
5 #include "TEveTrack.h"
6 #include "TEveTrackPropagator.h"
7 #include "TEveTrans.h"
8 #include "TEveText.h"
9 #include "TEveGeoShape.h"
10 #include "TGLViewer.h"
11 #include "TGLScenePad.h"
12 #include "TCanvas.h"
13 #include "TLatex.h"
14 #include "TLegend.h"
15 
16 #include "TH2.h"
17 
18 #include "TAxis.h"
19 #include "TGSlider.h"
20 #include "TGButton.h"
21 #include "TGLabel.h"
22 #include "TGLCameraOverlay.h"
23 
24 // boost includes
25 #include "boost/bind.hpp"
26 
29 
39 
41 
48 
49 
51  m_range(1),
52  m_candidate(nullptr),
53  m_legend(nullptr),
54  m_slider(nullptr),
55  m_sliderListener(),
56  m_eventList(nullptr),
57  m_plotEt(true),
58  m_rnrHcal(true)
59 {}
60 
62 {
63 }
64 
65 
67 {
68  return m_candidate->eta();
69 }
70 
72 {
73  return m_candidate->phi();
74 }
75 
77 {
78  float dx = m_candidate->eta() - x;
79  float dy = m_candidate->phi() - y;
80  float sd = TMath::Sqrt(dx*dx + dy*dy);
81  return sd < m_range;
82 }
83 
84 //______________________________________________________________________________
85 
86 void
88 {
89  m_legend = new TLegend( 0.01, 0.01, 0.99, 0.99, nullptr, "NDC" );
90  m_legend->SetFillColor(kWhite);
91  m_legend->SetTextSize( 0.07 );
92  m_legend->SetBorderSize( 0 );
93  m_legend->SetMargin( 0.15 );
94  m_legend->SetEntrySeparation( 0.01 );
95 }
96 
97 //______________________________________________________________________________
98 
99 void
101 {
102  static float kSliderRangeFactor = 0.2;
103 
104  m_range = x * kSliderRangeFactor;
105 
107 
108 
109  gEve->Redraw3D();
110 }
111 
112 //______________________________________________________________________________
113 
114 void
116 {
117  m_infoCanvas->cd();
118 
119  float_t x = 0.02;
120  float y = 0.95;
121 
122  TLatex* latex = new TLatex( x, y, "" );
123  const double textsize( 0.07 );
124  latex->SetTextSize( textsize );
125 
126  latex->DrawLatex( x, y, id.item()->modelName( id.index()).c_str());
127  y -= latex->GetTextSize()*0.6;
128 
129  latex->SetTextSize( textsize );
130  float lineH = latex->GetTextSize()*0.6;
131 
132  latex->DrawLatex( x, y, Form( " P_{T} = %.1f GeV, #eta = %0.2f, #varphi = %0.2f",
133  track->pt(), track->eta(), track->phi()));
134  y -= lineH;
135 
136  if( track->charge() > 0 )
137  latex->DrawLatex( x, y, " charge = +1" );
138  else
139  latex->DrawLatex( x, y, " charge = -1" );
140  y -= lineH;
141  y -= lineH;
142 
143  m_legend->SetY2(y);
144  m_legend->Draw();
145  m_legend = nullptr; // Deleted together with TPad.
146 }
147 
148 void
150 {
151  printf("plotEt = %d \n", m_plotEt);
152  m_plotEt = !m_plotEt;
154 }
155 
156 void
158 {
159  printf("rnrHcal = %d \n", m_rnrHcal);
160  m_rnrHcal = !m_rnrHcal;
162 }
163 
164 //______________________________________________________________________________
165 
166 void
168 {
169  m_candidate = candidate;
170 
171  // ROOT GUI
172  //
173  {
174  TGCompositeFrame* f = new TGVerticalFrame(m_guiFrame);
175  m_guiFrame->AddFrame(f);
176  f->AddFrame(new TGLabel(f, "Rng:"), new TGLayoutHints(kLHintsLeft, 2, 2, 0, 0));
177  m_slider = new TGHSlider(f, 120, kSlider1 | kScaleNo);
178  f->AddFrame(m_slider, new TGLayoutHints(kLHintsTop | kLHintsLeft, 2, 2, 1, 4));
179  m_slider->SetRange(1, 50);
180  m_slider->SetPosition(8);
181 
183  TQObject::Connect(m_slider, "PositionChanged(Int_t)", "FWIntValueListenerBase", m_sliderListener, "setValue(Int_t)");
185  {
186  CSGAction* action = new CSGAction(this, "Scale Et");
187  TGCheckButton* b = new TGCheckButton(m_guiFrame, action->getName().c_str() );
188  b->SetState(kButtonDown, true);
189  m_guiFrame->AddFrame(b, new TGLayoutHints( kLHintsNormal, 2, 3, 1, 4));
190  TQObject::Connect(b, "Clicked()", "CSGAction", action, "activate()");
191  action->activated.connect(sigc::mem_fun(this, &FWPFCandidateDetailView::plotEtChanged));
192  }
193  {
194  CSGAction* action = new CSGAction(this, "RnrHcal");
195  TGCheckButton* b = new TGCheckButton(m_guiFrame, action->getName().c_str() );
196  b->SetState(kButtonDown, true);
197  m_guiFrame->AddFrame(b, new TGLayoutHints( kLHintsNormal, 2, 3, 1, 4));
198  TQObject::Connect(b, "Clicked()", "CSGAction", action, "activate()");
199  action->activated.connect(sigc::mem_fun(this, &FWPFCandidateDetailView::rnrHcalChanged));
200  }
201 
202  }
203  makeLegend();
204  setTextInfo(id, candidate);
205 
206  TGCompositeFrame* p = (TGCompositeFrame*)m_guiFrame->GetParent();
207  p->MapSubwindows();
208  p->Layout();
209 
211  // GL stuff
212 
213 
214  m_candidate = candidate;
215 
216  try {
219  event->getByLabel(edm::InputTag("particleFlowRecHitECAL"), ecalH);
220  if (ecalH.product()) voteMaxEtEVal(ecalH.product());
221 
223  event->getByLabel(edm::InputTag("particleFlowRecHitHBHEHO"),hcalH);
224  if (hcalH.product()) voteMaxEtEVal(hcalH.product());
225  }
226  catch(const cms::Exception& iE) {
227  std::cerr << iE.what();
228  }
229 
230  m_eveScene->GetGLScene()->SetSelectable(false);
231  m_eventList = new TEveElementList("PFDetailView");
232  m_eveScene->AddElement(m_eventList);
233 
234 
235  viewerGL()->SetStyle(TGLRnrCtx::kOutline);
236  viewerGL()->SetCurrentCamera(TGLViewer::kCameraOrthoXOY);
237 
238  TGLCameraOverlay* co = viewerGL()->GetCameraOverlay();
239  co->SetShowOrthographic(kTRUE);
240  co->SetOrthographicMode(TGLCameraOverlay::kAxis);
241 
242  viewerGL()->ResetCamerasAfterNextUpdate();
243  try {
245  }
246  catch (...) {
247  printf("unknown exception \n");
248  }
249 
250  viewerGL()->UpdateScene(kFALSE);
251 
252  gEve->Redraw3D();
253 
254  // gEve->AddToListTree(m_eventList, true);//debug, used with --eve option
255 }
256 
257 
258 //______________________________________________________________________________
259 
260 void FWPFCandidateDetailView::voteMaxEtEVal( const std::vector<reco::PFRecHit> *hits)
261 {
262  if (!hits) return;
263 
264  // FIXME: require access to geometry while reading from reco file
265  if ( (!hits->empty()) && hits->front().hasCaloCell())
266  for (std::vector<reco::PFRecHit>::const_iterator it = hits->begin(); it != hits->end(); ++it)
267  {
268  TEveVector centre(it->position().x(), it->position().y(), it->position().z());
269  float E = it->energy();
270  float Et = FWPFMaths::calculateEt( centre, E );
271  item()->context().voteMaxEtAndEnergy(Et , E );
272  }
273 }
274 
275 
276 //______________________________________________________________________________
277 
278 void FWPFCandidateDetailView::addTracks( const std::vector<reco::PFRecTrack> *tracks)
279 {
280  for (std::vector<reco::PFRecTrack>::const_iterator it = tracks->begin(); it != tracks->end(); ++it)
281  {
283  /*
284  if (!isPntInRng(it->trackRef().innerMomentum().Eta(), it->position().Phi()))
285  continue;
286 
287  TEveLine* line = new TEveLine("Track");
288  line->SetMainColor(kYellow);
289  int N = it->nTrajectoryPoints();
290 
291  for (int p = 0 ; p<N; ++p) {
292  pos = track.extrapolatedPoint(p).position();
293 
294  if( pos.Eta() !=0 and pos.Phi() !=0)
295  line->SetNextPoint(pos.Eta(), pos.Phi(), 0);
296  }
297  m_eventList->AddElement(line);
298  */
299 
300  }
301 }
302 
303 //______________________________________________________________________________
304 
305 void FWPFCandidateDetailView::addClusters( const std::vector<reco::PFCluster> *cluster)
306 {
307  if (!cluster) return;
308 
309  Color_t col = kViolet+9;
310 
311  TEveStraightLineSet* ls = new TEveStraightLineSet("cluster_ls");
312  ls->SetMainColor(col);
313  m_eventList->AddElement(ls);
314 
315  TEvePointSet* ps = new TEvePointSet("cluster_ps");
316  ps->SetMainColor(col);
317  ps->SetMarkerStyle(2);
318  ps->SetMarkerSize(0.005);
319  m_eventList->AddElement(ps);
320 
321  for (std::vector<reco::PFCluster>::const_iterator it = cluster->begin(); it != cluster->end(); ++it)
322  {
323  if (!isPntInRng(it->position().Eta(), it->position().Phi()))
324  continue;
325 
326  ps->SetNextPoint(it->position().Eta(), it->position().Phi(), 0);
327 
328  /*
329  const std::vector< reco::PFRecHitFraction >& fractions = it->recHitFractions();
330  for (std::vector< reco::PFRecHitFraction >::const_iterator fi = fractions.begin(); fi != fractions.end(); ++fi)
331  {
332  // !!! AMT can't get fi->recHitRef().position()
333  // ls->AddLine(it->position().Eta(), it->position().Phi(), 0,
334  // fi->recHitRef().position().Eta(), fi->recHitRef().position().Phi(), 0);
335  }
336  */
337 
338  }
339 }
340 namespace {
341 void WrapTwoPi(std::vector<TEveVector>& hc, float y)
342 {
343 
344  if (TMath::Abs(hc[0].fY) < 2)
345  return;
346 
347 
348  if (hc[0].fY > 0 && hc[1].fY > 0 && hc[2].fY > 0 && hc[3].fY > 0 )
349  return;
350  if (hc[0].fY < 0 && hc[1].fY < 0 && hc[2].fY < 0 && hc[3].fY < 0 )
351  return;
352 
353 
354  for (int i = 0; i < 4; ++i)
355  if (y > 0 && hc[i].fY < 0)
356  hc[i].fY += TMath::TwoPi();
357  else if (y < 0 && hc[i].fY > 0)
358  hc[i].fY -= TMath::TwoPi();
359 
360 }
361 }
362 //______________________________________________________________________________
363 namespace
364 {
365 TEveStraightLineSet::Line_t* AddLineToLineSet(TEveStraightLineSet* ls, const std::vector< TEveVector >& pnts, int i0, int i1)
366 {
367  if (false) {
368  printf("add line \n");
369  pnts[i0].Dump();
370  pnts[i1].Dump();
371  }
372  return ls->AddLine(pnts[i0], pnts[i1]);
373  // return ls->AddLine(pnts[i0].Eta(),pnts[i0].Phi(), 0 , pnts[i1].Eta(),pnts[i1].Phi(), 0);
374 }
375 }
376 void FWPFCandidateDetailView::addHits( const std::vector<reco::PFRecHit> *hits)
377 {
378 
379  TEveStraightLineSet* lsOutline = ( TEveStraightLineSet*)m_eventList->FindChild("outlines");
380 
381  TEvePointSet* ps = new TEvePointSet("test");
382  m_eventList->AddElement(ps);
383  ps->SetMainColor(kOrange);
384 
385  // FIXME, requires access to geometry
386  if ( (!hits->empty()) && hits->front().hasCaloCell())
387  for (std::vector<reco::PFRecHit>::const_iterator it = hits->begin(); it != hits->end(); ++it)
388  {
389  const auto & corners = it->getCornersXYZ();
390  if (!isPntInRng(corners[0].eta(), corners[0].phi()))
391  continue;
392 
393  std::vector<TEveVector> hc;
394  for (int k = 0; k < 4; ++k) {
395  hc.push_back(TEveVector(corners[k].eta(), corners[k].phi(), 0));
396  // ps->SetNextPoint(corners[k].eta(),corners[k].phi(),0 ); //debug
397  }
398 
399  WrapTwoPi(hc, corners[0].phi());
400 
401  AddLineToLineSet(lsOutline, hc, 0, 1);
402  AddLineToLineSet(lsOutline, hc, 1, 2);
403  AddLineToLineSet(lsOutline, hc, 2, 3);
404  AddLineToLineSet(lsOutline, hc, 3, 0);
405 
406 
407  // get scaled corners
408  TEveVector centerOfGravity = hc[0] + hc[1] + hc[2] + hc[3];
409  centerOfGravity *= 0.25;
410 
411  std::vector<TEveVector> radialVectors;
412  for (int k = 0; k < 4; ++k)
413  radialVectors.push_back(TEveVector(hc[k] - centerOfGravity));
414 
415  float factor = 1;
416  if (m_plotEt) {
417  float Et = FWPFMaths::calculateEt( TEveVector(corners[0].x(), corners[0].y(), corners[0].z()), it->energy());
418  factor = Et/context().getMaxEnergyInEvent(m_plotEt);
419  }
420  else
421  factor = it->energy()/context().getMaxEnergyInEvent(false);
422 
423 
424  std::vector<TEveVector> scaledCorners;
425  for (int k = 0; k < 4; ++k) {
426  radialVectors[k] *= factor;
427  scaledCorners.push_back(TEveVector(radialVectors[k] + centerOfGravity));
428  }
429 
430  TEveStraightLineSet* ls = ( TEveStraightLineSet*)m_eventList->FindChild(Form("%d_rechit", it->depth() ));
431  AddLineToLineSet(ls, scaledCorners, 0, 1);
432  AddLineToLineSet(ls, scaledCorners, 1, 2);
433  AddLineToLineSet(ls, scaledCorners, 2, 3);
434  // AddLineToLineSet(ls, scaledCorners, 3, 0);
435  TEveStraightLineSet::Line_t* li = AddLineToLineSet(ls, scaledCorners, 3, 0);
436  ls->AddMarker(centerOfGravity, li->fId);
437 
438  }
439 }
440 
441 
442 //______________________________________________________________________________
443 
444 
446 {
447  if (m_eventList->HasChildren()) m_eventList->DestroyElements();
448 
449 
450  for (int depth = 0; depth < 6; ++depth)
451  {
452  TEveStraightLineSet* ls = new TEveStraightLineSet(Form("%d_rechit", depth));
453 
454  if (depth == 0 ) ls->SetLineColor(kGray);
455  else if (depth == 1 ) ls->SetLineColor(kRed);
456  else if (depth == 2 ) ls->SetLineColor(kGreen);
457  else if (depth == 3 ) ls->SetLineColor(kMagenta);
458  else if (depth == 4 ) ls->SetLineColor(kOrange);
459  else if (depth == 5 ) ls->SetLineColor(kYellow);
460 
461  ls->SetMarkerStyle(1);
462  m_eventList->AddElement(ls);
463  }
464 
465  TEveStraightLineSet* ls = new TEveStraightLineSet("outlines");
466  ls->SetLineColor(kGray);
467  ls->SetMainTransparency(80);
468  m_eventList->AddElement(ls);
469 
470 
472 
473 
474  //
475  // recHits
476  //
477  try {
479  event->getByLabel(edm::InputTag("particleFlowRecHitECAL"), ecalH);
480  addHits(ecalH.product());
481  }
482  catch(const cms::Exception& iE) {
483  std::cerr << iE.what();
484  }
485 
486  if (m_rnrHcal) {
487  try {
489  event->getByLabel(edm::InputTag("particleFlowRecHitHF"), ecalH);
490  addHits(ecalH.product());
491  }
492  catch(const cms::Exception& iE) {
493  std::cerr << iE.what();
494  }
495 
496 
497  try {
499  event->getByLabel(edm::InputTag("particleFlowRecHitHBHEHO"),hcalH);
500  addHits(hcalH.product());
501  }
502  catch (const cms::Exception& iE) {
503  std::cerr << iE.what();
504  }
505 
506  }
507 
508 
509  //
510  // clusters
511  //
512  try {
514  event->getByLabel(edm::InputTag("particleFlowClusterECAL"), ecalClustersH);
515  addClusters(ecalClustersH.product());
516  }
517  catch (const cms::Exception& iE) {
518  std::cerr << iE.what();
519  }
520 
521  //
522  // tracks
523  //
524  try {
526  event->getByLabel(edm::InputTag("pfTrack"),trackH);
527  addTracks(trackH.product());
528  }
529  catch (const cms::Exception& iE) {
530  std::cerr << iE.what();
531  }
532 
533 }
534 
const std::string & getName() const
Definition: CSGAction.cc:81
const double TwoPi
bool isPntInRng(float x, float y)
double eta() const final
momentum pseudorapidity
FWIntValueListener * m_sliderListener
void voteMaxEtAndEnergy(float Et, float energy) const
Definition: Context.cc:183
const FWEventItem * item()
sigc::signal< void > activated
Definition: CSGAction.h:88
void setTextInfo(const FWModelId &id, const reco::PFCandidate *) override
double pt() const final
transverse momentum
int charge() const final
electric charge
Definition: LeafCandidate.h:91
char const * what() const override
Definition: Exception.cc:141
#define nullptr
const fireworks::Context & context() const
const fireworks::Context & context() const
Definition: FWEventItem.h:128
T Abs(T a)
Definition: MathUtil.h:49
sigc::signal< void, Int_t > valueChanged_
double f[11][100]
float getMaxEnergyInEvent(bool isEt) const
Definition: Context.cc:199
float calculateEt(const TEveVector &centre, float e)
Definition: FWPFMaths.cc:115
void voteMaxEtEVal(const std::vector< reco::PFRecHit > *hits)
int k[5][pyjets_maxn]
const edm::EventBase * getCurrentEvent() const
def ls(path, rec=False)
Definition: eostools.py:349
T const * product() const
Definition: Handle.h:81
static FWGUIManager * getGUIManager()
double sd
const reco::PFCandidate * m_candidate
double b
Definition: hdecay.h:120
void addHits(const std::vector< reco::PFRecHit > *)
#define REGISTER_FWDETAILVIEW(_classname_, _name_,...)
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:40
void addClusters(const std::vector< reco::PFCluster > *)
susybsm::HSCParticleCollection hc
Definition: classes.h:25
col
Definition: cuy.py:1010
void build(const FWModelId &id, const reco::PFCandidate *) override
double phi() const final
momentum azimuthal angle
void addTracks(const std::vector< reco::PFRecTrack > *)