CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FWElectronDetailView.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Electrons
4 // Class : FWElectronDetailView
5 //
6 
7 // ROOT includes
8 #include "TLatex.h"
9 #include "TEveCalo.h"
10 #include "TEveStraightLineSet.h"
11 #include "TEvePointSet.h"
12 #include "TEveScene.h"
13 #include "TEveViewer.h"
14 #include "TGLViewer.h"
15 #include "TGLOverlay.h"
16 #include "TCanvas.h"
17 #include "TLegend.h"
18 #include "TEveCaloLegoOverlay.h"
19 #include "TRootEmbeddedCanvas.h"
20 
21 // Fireworks includes
28 
29 // CMSSW includes
33 
34 
35 //
36 // constructors and destructor
37 //
39  m_data(0),
40  m_builder(0),
41  m_legend(0)
42 {
43 }
44 
46 {
47  m_eveViewer->GetGLViewer()->DeleteOverlayElements(TGLOverlayElement::kUser);
48 
49  delete m_builder;
50  if (m_data) m_data->DecDenyDestroy();
51 }
52 
53 //
54 // member functions
55 //
56 void
58 {
59  if( !iElectron ) return;
60  // If SuperCluster reference is not stored,
61  // take eta and phi of a Candidate
62  double eta = 0;
63  double phi = 0;
64  if( iElectron->superCluster().isAvailable() ) {
65  eta = iElectron->caloPosition().eta();
66  phi = iElectron->caloPosition().phi();
67  }
68  else
69  {
70  eta = iElectron->eta();
71  phi = iElectron->phi();
72  }
73 
74  // build ECAL objects
75  m_builder = new FWECALDetailViewBuilder( id.item()->getEvent(), id.item()->getGeom(),
76  eta, phi, 25);
77 
79  if( iElectron->superCluster().isAvailable() )
80  m_builder->showSuperCluster( *(iElectron->superCluster() ), kYellow);
81  TEveCaloLego* lego = m_builder->build();
82  m_data = lego->GetData();
83  m_eveScene->AddElement( lego );
84 
85  m_legend = new TLegend(0.01, 0.01, 0.99, 0.99, 0, "NDC");
86  m_legend->SetTextSize(0.075);
87  m_legend->SetBorderSize(0);
88  m_legend->SetMargin(0.15);
89  m_legend->SetEntrySeparation(0.05);
90 
91  // add Electron specific details
92  if( iElectron->superCluster().isAvailable() ) {
93  addTrackPointsInCaloData( iElectron, lego );
94  drawCrossHair( iElectron, lego, m_eveScene );
95  addSceneInfo( iElectron, m_eveScene );
96  }
97 
98  // draw axis at the window corners
99  if (1)
100  {
101  TEveCaloLegoOverlay* overlay = new TEveCaloLegoOverlay();
102  overlay->SetShowPlane( kFALSE );
103  overlay->SetShowPerspective( kFALSE );
104  overlay->SetCaloLego( lego );
105  overlay->SetShowScales( 1 ); // temporary
106  viewerGL()->AddOverlayElement( overlay );
107  }
108  // set event handler and flip camera to top view at beginning
109  viewerGL()->SetCurrentCamera( TGLViewer::kCameraOrthoXOY );
110  FWGLEventHandler* eh =
111  new FWGLEventHandler( (TGWindow*)viewerGL()->GetGLWidget(), (TObject*)viewerGL(), lego );
112  viewerGL()->SetEventHandler( eh );
113  viewerGL()->ResetCamerasAfterNextUpdate();
114  viewerGL()->UpdateScene(kFALSE);
115  gEve->Redraw3D();
116 
117  setTextInfo( id, iElectron );
118 }
119 
120 double
122 {
123  return electron.deltaEtaSuperClusterTrackAtVtx();
124 }
125 
126 double
128 {
129  return electron.deltaPhiSuperClusterTrackAtVtx();
130 }
131 
132 void
134 {
135  m_infoCanvas->cd();
136 
137  float_t x = 0.02;
138  float_t x2 = 0.52;
139  float y = 0.95;
140 
141  TLatex* latex = new TLatex( x, y, "" );
142  const double textsize( 0.05 );
143  latex->SetTextSize( 2*textsize );
144 
145  latex->DrawLatex( x, y, id.item()->modelName( id.index() ).c_str() );
146  y -= latex->GetTextSize()*0.6;
147 
148  latex->SetTextSize( textsize );
149  float lineH = latex->GetTextSize()*0.6;
150 
151  latex->DrawLatex( x, y, Form( " E_{T} = %.1f GeV, #eta = %0.2f, #varphi = %0.2f",
152  electron->et(), electron->eta(), electron->phi()) );
153  y -= lineH;
154  // summary
155  if( electron->charge() > 0 )
156  latex->DrawLatex( x, y, " charge = +1" );
157  else
158  latex->DrawLatex( x, y, " charge = -1" );
159  y -= lineH;
160 
161  if( electron->superCluster().isAvailable() ) {
162  // delta phi/eta in
163  latex->DrawLatex( x, y, "SuperCluster vs inner state extrapolation" );
164  y -= lineH;
165  latex->DrawLatex( x, y, TString::Format(" #Delta#eta_{in} = %.3f", electron->deltaEtaSuperClusterTrackAtVtx()) );
166  latex->DrawLatex( x2, y, TString::Format("#Delta#varphi_{in} = %.3f", electron->deltaPhiSuperClusterTrackAtVtx()) );
167  y -= lineH;
168 
169  // delta phi/eta out
170  latex->DrawLatex( x, y, "SeedCluster vs outer state extrapolation" );
171  y -= lineH;
172 
173  latex->DrawLatex( x, y, TString::Format(" #Delta#eta_{out} = %.3f", electron->deltaEtaSeedClusterTrackAtCalo()) );
174  latex->DrawLatex( x2, y, TString::Format(" #Delta#varphi_{out} = %.3f", electron->deltaPhiSeedClusterTrackAtCalo()) );
175  y -= 2*lineH;
176  } else {
177  latex->DrawLatex( x, y, "Ref to SuperCluster is not available" );
178  }
179 
180  latex->DrawLatex(x, y, TString::Format(" Tracker driven seed: %s", electron->trackerDrivenSeed() ? "YES" : "NO"));
181  y -= lineH;
182  latex->DrawLatex(x, y, TString::Format(" ECAL driven seed: %s", electron->ecalDrivenSeed() ? "YES" : "NO"));
183  y -= lineH;
184 
185  y = m_builder->makeLegend( 0.02, y );
186  y -= lineH;
187 
188  m_legend->SetY2(y);
189  m_legend->Draw();
190  m_legend = 0; // Deleted together with TPad.
191 }
192 
193 void
194 FWElectronDetailView::drawCrossHair (const reco::GsfElectron* i, TEveCaloLego *lego, TEveElementList* tList)
195 {
196  unsigned int subdetId( 0 );
197 
198  if( !i->superCluster()->seed()->hitsAndFractions().empty() )
199  subdetId = i->superCluster()->seed()->hitsAndFractions().front().first.subdetId();
200 
201  double ymax = lego->GetPhiMax();
202  double ymin = lego->GetPhiMin();
203  double xmax = lego->GetEtaMax();
204  double xmin = lego->GetEtaMin();
205 
206  // draw crosshairs for track intersections
207 
208  {
209  const double eta = i->superCluster()->seed()->position().eta() -
211  const double phi = i->superCluster()->seed()->position().phi() -
213 
214  TEveStraightLineSet *trackpositionAtCalo = new TEveStraightLineSet("sc trackpositionAtCalo");
215  trackpositionAtCalo->SetPickable(kTRUE);
216  trackpositionAtCalo->SetTitle("Track position at Calo propagating from the outermost state");
217  if (subdetId == EcalBarrel)
218  {
219  trackpositionAtCalo->AddLine(eta, ymin, 0, eta, ymax, 0);
220  trackpositionAtCalo->AddLine(xmin, phi, 0, xmax, phi, 0);
221  }
222  else if (subdetId == EcalEndcap)
223  {
224  TVector3 pos;
225  pos.SetPtEtaPhi(i->superCluster()->seed()->position().rho(), eta, phi);
226  trackpositionAtCalo->AddLine(pos.X(), ymin, 0, pos.X(), ymax, 0);
227  trackpositionAtCalo->AddLine(xmin, pos.Y(), 0, xmax,pos.Y(),0);
228  }
229  trackpositionAtCalo->SetDepthTest(kFALSE);
230  trackpositionAtCalo->SetLineColor(kBlue);
231  tList->AddElement(trackpositionAtCalo);
232 
233  m_legend->AddEntry(trackpositionAtCalo, "From outermost state", "l");
234  }
235  //
236  // pin position
237  //
238  {
239  TEveStraightLineSet *pinposition = new TEveStraightLineSet("pin position");
240  pinposition->SetPickable(kTRUE);
241  pinposition->SetTitle("Track position at Calo propagating from the innermost state");
242  Double_t eta = i->caloPosition().eta() - deltaEtaSuperClusterTrackAtVtx(*i);
243  Double_t phi = i->caloPosition().phi() - deltaPhiSuperClusterTrackAtVtx(*i);
244 
245  if (subdetId == EcalBarrel)
246  {
247  pinposition->AddLine(eta, ymax, 0, eta, ymin, 0);
248  pinposition->AddLine(xmin, phi, 0, xmax, phi, 0);
249  }
250  else if (subdetId == EcalEndcap)
251  {
252  TVector3 pos;
253  pos.SetPtEtaPhi(i->caloPosition().rho(), eta, phi);
254  pinposition->AddLine(pos.X(),ymin, 0, pos.X(), ymax, 0);
255  pinposition->AddLine(xmin, pos.Y(), 0, xmax, pos.Y(), 0);
256  }
257  pinposition->SetDepthTest(kFALSE);
258  pinposition->SetLineColor(kRed);
259  tList->AddElement(pinposition);
260 
261  m_legend->AddEntry(pinposition, "From innermost state", "l");
262  }
263 }
264 
265 Bool_t
266 FWElectronDetailView::checkRange( Double_t &em, Double_t& eM, Double_t &pm, Double_t& pM,
267  Double_t eta, Double_t phi )
268 {
269  Bool_t changed = kFALSE;
270 
271  //check eta
272  if (eta < em)
273  {
274  em = eta;
275  changed = kTRUE;
276  }
277  else if (eta > eM)
278  {
279  eM = eta;
280  changed = kTRUE;
281  }
282 
283  // check phi
284  if (phi < pm)
285  {
286  pm = phi;
287  changed = kTRUE;
288  }
289  else if (phi > pM)
290  {
291  pM = phi;
292  changed = kTRUE;
293  }
294  return changed;
295 }
296 
297 void
299 {
300  unsigned int subdetId(0);
301 
302  if ( !i->superCluster()->seed()->hitsAndFractions().empty() )
303  subdetId = i->superCluster()->seed()->hitsAndFractions().front().first.subdetId();
304 
305  TEveCaloDataVec* data = (TEveCaloDataVec*)lego->GetData();
306  Double_t em, eM, pm, pM;
307  data->GetEtaLimits(em, eM);
308  data->GetPhiLimits(pm, pM);
309  data->IncDenyDestroy();
310  Bool_t changed = kFALSE;
311  // add cells in third layer if necessary
312 
313  // trackpositionAtCalo
314  {
315  double eta = i->superCluster()->seed()->position().eta() -
317  double phi = i->superCluster()->seed()->position().phi() -
319 
320  if (subdetId == EcalBarrel)
321  {
322  if (checkRange(em, eM, pm, pM, eta, phi))
323  changed = kTRUE;
324  }
325  else if (subdetId == EcalEndcap) {
326  TVector3 pos;
327  pos.SetPtEtaPhi(i->superCluster()->seed()->position().rho(),eta, phi);
328  if (checkRange(em, eM, pm, pM, pos.X(), pos.Y()))
329  changed = kTRUE;
330 
331  }
332  }
333  // pinposition
334  {
335  double eta = i->caloPosition().eta() - deltaEtaSuperClusterTrackAtVtx(*i);
336  double phi = i->caloPosition().phi() - deltaPhiSuperClusterTrackAtVtx(*i);
337  if (subdetId == EcalBarrel)
338  {
339  if (checkRange(em, eM, pm, pM, eta, phi))
340  changed = kTRUE;
341  }
342  else if (subdetId == EcalEndcap) {
343  TVector3 pos;
344  pos.SetPtEtaPhi(i->caloPosition().rho(), eta, phi);
345  if (checkRange(em, eM, pm, pM, pos.X(), pos.Y()))
346  changed = kTRUE;
347  }
348  }
349  if (changed)
350  {
351  data->AddTower(em, eM, pm, pM);
352  data->FillSlice(2, 0); data->DataChanged();
353 
354  lego->ComputeBBox();
355  Double_t legoScale = ((eM - em) < (pM - pm)) ? (eM - em) : (pM - pm);
356  lego->InitMainTrans();
357  lego->RefMainTrans().SetScale(legoScale, legoScale, legoScale*0.5);
358  lego->RefMainTrans().SetPos((eM+em)*0.5, (pM+pm)*0.5, 0);
359  lego->ElementChanged(true);
360  }
361 }
362 
363 void
365 {
366  unsigned int subdetId(0);
367 
368  if ( !i->superCluster()->seed()->hitsAndFractions().empty() )
369  subdetId = i->superCluster()->seed()->hitsAndFractions().front().first.subdetId();
370 
371  // centroids
372  Double_t x(0), y(0), z(0);
373  Double_t delta(0.02);
374  if (subdetId == EcalEndcap) delta = 2.5;
375  TEveStraightLineSet *scposition = new TEveStraightLineSet("sc position");
376  scposition->SetPickable(kTRUE);
377  scposition->SetTitle("Super cluster centroid");
378  if (subdetId == EcalBarrel) {
379  x = i->caloPosition().eta();
380  y = i->caloPosition().phi();
381  } else if (subdetId == EcalEndcap) {
382  x = i->caloPosition().x();
383  y = i->caloPosition().y();
384  }
385  scposition->AddLine(x-delta,y,z,x+delta,y,z);
386  scposition->AddLine(x,y-delta,z,x,y+delta,z);
387  scposition->AddLine(x,y,z-delta,x,y,z+delta);
388  scposition->SetLineColor(kBlue);
389  scposition->SetLineWidth(2);
390  scposition->SetDepthTest(kFALSE);
391  tList->AddElement(scposition);
392 
393  scposition->SetMarkerColor(kBlue);
394  scposition->SetMarkerStyle(2);
395  m_legend->AddEntry(scposition, "Super cluster centroid", "p");
396 
397  // seed position
398  TEveStraightLineSet *seedposition = new TEveStraightLineSet("seed position");
399  seedposition->SetTitle("Seed cluster centroid");
400  seedposition->SetPickable(kTRUE);
401  if (subdetId == EcalBarrel) {
402  x = i->superCluster()->seed()->position().eta();
403  y = i->superCluster()->seed()->position().phi();
404  } else if (subdetId == EcalEndcap) {
405  x = i->superCluster()->seed()->position().x();
406  y = i->superCluster()->seed()->position().y();
407  }
408  seedposition->AddLine(x-delta,y-delta,z,x+delta,y+delta,z);
409  seedposition->AddLine(x-delta,y+delta,z,x+delta,y-delta,z);
410  seedposition->SetLineColor(kRed);
411  seedposition->SetLineWidth(2);
412  seedposition->SetDepthTest(kFALSE);
413  tList->AddElement(seedposition);
414 
415  seedposition->SetMarkerColor(kRed);
416  seedposition->SetMarkerStyle(5);
417  m_legend->AddEntry(seedposition, "Seed cluster centroid", "p");
418 
419  // electron direction (show it if it's within
420  // the area of interest)
421  if ( fabs(i->phi()-i->caloPosition().phi())< 25*0.0172 &&
422  fabs(i->eta()-i->caloPosition().eta())< 25*0.0172 )
423  {
424  TEveStraightLineSet *eldirection = new TEveStraightLineSet("seed position");
425  eldirection->SetTitle("Electron direction at vertex");
426  eldirection->SetPickable(kTRUE);
427  if (subdetId == EcalBarrel) {
428  x = i->eta();
429  y = i->phi();
430  }else{
431  x = 310*fabs(tan(i->theta()))*cos(i->phi());
432  y = 310*fabs(tan(i->theta()))*sin(i->phi());
433  }
434  eldirection->AddLine(x-delta,y-delta,z,x+delta,y+delta,z);
435  eldirection->AddLine(x-delta,y+delta,z,x+delta,y-delta,z);
436  eldirection->SetLineColor(kGreen);
437  eldirection->SetDepthTest(kFALSE);
438  tList->AddElement(eldirection);
439 
440  eldirection->SetMarkerColor(kGreen);
441  eldirection->SetMarkerStyle(5);
442  m_legend->AddEntry(eldirection, "Direction at vertex", "p");
443  }
444 }
445 
dbl * delta
Definition: mlp_gen.cc:36
bool isAvailable() const
Definition: Ref.h:576
void showSuperCluster(const reco::SuperCluster &cluster, Color_t color=kYellow)
int i
Definition: DBlmapReader.cc:9
double makeLegend(double x0=0.02, double y0=0.95, Color_t clustered1=kGreen+1, Color_t clustered2=kTeal, Color_t supercluster=kYellow)
virtual void setTextInfo(const FWModelId &id, const reco::GsfElectron *)
virtual double et() const
transverse energy
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
const FWEventItem * item()
Bool_t checkRange(Double_t &, Double_t &, Double_t &, Double_t &, Double_t, Double_t)
#define REGISTER_FWDETAILVIEW(_classname_, _name_,...)
virtual double eta() const
momentum pseudorapidity
FWECALDetailViewBuilder * m_builder
float deltaEtaSuperClusterTrackAtVtx() const
Definition: GsfElectron.h:247
float deltaPhiSeedClusterTrackAtCalo() const
Definition: GsfElectron.h:251
virtual SuperClusterRef superCluster() const
reference to a SuperCluster
Definition: GsfElectron.h:182
float deltaPhiSuperClusterTrackAtVtx() const
Definition: GsfElectron.h:250
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
virtual int charge() const
electric charge
Definition: LeafCandidate.h:91
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
virtual double theta() const
momentum polar angle
void showSuperClusters(Color_t color1=kGreen+2, Color_t color2=kTeal)
math::XYZPoint caloPosition() const
Definition: GsfElectron.h:323
virtual void build(const FWModelId &id, const reco::GsfElectron *)
void drawCrossHair(const reco::GsfElectron *, TEveCaloLego *, TEveElementList *)
Geom::Phi< T > phi() const
double deltaEtaSuperClusterTrackAtVtx(const reco::GsfElectron &)
float deltaEtaSeedClusterTrackAtCalo() const
Definition: GsfElectron.h:248
void addSceneInfo(const reco::GsfElectron *i, TEveElementList *tList)
double deltaPhiSuperClusterTrackAtVtx(const reco::GsfElectron &)
bool trackerDrivenSeed() const
Definition: GsfElectron.h:187
void addTrackPointsInCaloData(const reco::GsfElectron *, TEveCaloLego *)
virtual double phi() const
momentum azimuthal angle
bool ecalDrivenSeed() const
Definition: GsfElectron.h:186