CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FWMuonDetailView.cc
Go to the documentation of this file.
1 
2 // -*- C++ -*-
3 //
4 // Package: Calo
5 // Class : FWMuonDetailView
6 //
7 
8 // ROOT includes
9 #include "TLatex.h"
10 #include "TEveCalo.h"
11 #include "TEveStraightLineSet.h"
12 #include "TEvePointSet.h"
13 #include "TEveScene.h"
14 #include "TEveViewer.h"
15 #include "TGLViewer.h"
16 #include "TCanvas.h"
17 #include "TEveCaloLegoOverlay.h"
18 #include "TRootEmbeddedCanvas.h"
19 
20 // Fireworks includes
27 
29 //
30 // constructors and destructor
31 //
33  m_data(0),
34  m_builder(0)
35 {
36 }
37 
39 {
40  m_eveViewer->GetGLViewer()->DeleteOverlayElements(TGLOverlayElement::kUser);
41  if (m_data) m_data->DecDenyDestroy();
42  delete m_builder;
43 }
44 
45 //
46 // member functions
47 //
48 void FWMuonDetailView::build(const FWModelId &id, const reco::Muon* iMuon)
49 {
50  if(0==iMuon) return;
51 
52  double eta = iMuon->eta();
53  double phi = iMuon->phi();
54  if ( iMuon->isEnergyValid() )
55  {
56  eta = iMuon->calEnergy().ecal_position.eta();
57  phi = iMuon->calEnergy().ecal_position.phi();
58  }
59 
60  m_builder = new FWECALDetailViewBuilder(id.item()->getEvent(), id.item()->getGeom(),
61  eta, phi, 10);
62 
64  if ( iMuon->isEnergyValid() ) {
65  std::vector<DetId> ids;
66  ids.push_back(iMuon->calEnergy().ecal_id);
67  m_builder->setColor(kYellow,ids);
68  }
69 
70  TEveCaloLego* lego = m_builder->build();
71  m_data = lego->GetData();
72  m_data->IncDenyDestroy();
73  m_eveScene->AddElement(lego);
74  addSceneInfo(iMuon, m_eveScene);
75 
76  // draw axis at the window corners
77  TEveCaloLegoOverlay* overlay = new TEveCaloLegoOverlay();
78  overlay->SetShowPlane(kFALSE);
79  overlay->SetShowPerspective(kFALSE);
80  overlay->SetCaloLego(lego);
81  overlay->SetShowScales(0); // temporary
82  viewerGL()->AddOverlayElement(overlay);
83 
84  // set event handler and flip camera to top view at beginning
85  viewerGL()->SetCurrentCamera(TGLViewer::kCameraOrthoXOY);
86  FWGLEventHandler* eh =
87  new FWGLEventHandler((TGWindow*)viewerGL()->GetGLWidget(), (TObject*)viewerGL(), lego);
88  viewerGL()->SetEventHandler(eh);
89 
90  viewerGL()->ResetCamerasAfterNextUpdate();
91  viewerGL()->UpdateScene(kFALSE);
92  gEve->Redraw3D();
93 
94  setTextInfo(id, iMuon);
95 }
96 
97 void
99 {
100  m_infoCanvas->cd();
101  double y0 = 0.95;
102  double x0 = 0.02;
103 
104  TLatex* latex = new TLatex(x0, y0, "");
105  const double textsize(0.05);
106  latex->SetTextSize(2*textsize);
107 
108  float_t x = x0;
109  float y = y0;
110  float fontsize = latex->GetTextSize()*0.6;
111 
112  latex->DrawLatex(x, y, id.item()->modelName(id.index()).c_str() );
113  y -= fontsize;
114  latex->SetTextSize(textsize);
115  fontsize = latex->GetTextSize()*0.6;
116 
117  latex->DrawLatex(x, y, Form(" p_{T} = %.1f GeV, #eta = %0.2f, #varphi = %0.2f",
118  muon->pt(), muon->eta(), muon->phi()) );
119  y -= fontsize;
120  // summary
121  if (muon->charge() > 0)
122  latex->DrawLatex(x, y, " charge = +1");
123  else
124  latex->DrawLatex(x, y, " charge = -1");
125  y -= fontsize;
126 
127  if (muon->isEnergyValid() )
128  {
129  // delta phi/eta in
130  latex->DrawLatex(x, y, "ECAL energy in:");
131  y -= fontsize;
132  latex->DrawLatex(x, y, Form(" crossed crystalls = %.3f",
133  muon->calEnergy().em) );
134  y -= fontsize;
135  latex->DrawLatex(x, y, Form(" 3x3 crystall shape = %.3f",
136  muon->calEnergy().emS9) );
137  y -= fontsize;
138  latex->DrawLatex(x, y, Form(" 5x5 crystall shape = %.3f",
139  muon->calEnergy().emS25) );
140  }
141  m_builder->makeLegend(0.02, y);
142 }
143 
144 void
145 FWMuonDetailView::addSceneInfo(const reco::Muon *i, TEveElementList* tList)
146 {
147  // muon direction at vertex
148 
149  bool barrel = fabs(i->eta())<1.5;
150  if ( i->isEnergyValid() ) barrel = fabs(i->calEnergy().ecal_position.eta()) < 1.5;
151 
152  Double_t x(0), y(0);
153  Double_t delta(0.01);
154  TEveStraightLineSet *direction = new TEveStraightLineSet("Direction at vertex");
155  direction->SetPickable(kTRUE);
156  direction->SetTitle("Muon direction at vertex");
157  direction->SetPickable(kTRUE);
158  if (barrel) {
159  x = i->eta();
160  y = i->phi();
161  }else{
162  x = 310*fabs(tan(i->theta()))*cos(i->phi());
163  y = 310*fabs(tan(i->theta()))*sin(i->phi());
164  }
165  direction->AddLine(x-delta,y-delta,0,x+delta,y+delta,0);
166  direction->AddLine(x-delta,y+delta,0,x+delta,y-delta,0);
167  direction->SetLineColor(kYellow);
168  direction->SetDepthTest(kFALSE);
169  tList->AddElement(direction);
170 
171  if (! i->isEnergyValid() ) return;
172 
173  // ecal position
174  TEveStraightLineSet *ecalposition = new TEveStraightLineSet("ecal position");
175  ecalposition->SetPickable(kTRUE);
176  ecalposition->SetTitle("Muon position at ECAL surface");
177  if ( barrel ) {
178  x = i->calEnergy().ecal_position.eta();
179  y = i->calEnergy().ecal_position.phi();
180  } else {
181  x = i->calEnergy().ecal_position.x();
182  y = i->calEnergy().ecal_position.y();
183  }
184  ecalposition->AddLine(x-delta,y,0,x+delta,y,0);
185  ecalposition->AddLine(x,y-delta,0,x,y+delta,0);
186  ecalposition->AddLine(x,y,0-delta,x,y,0+delta);
187  ecalposition->SetLineColor(kRed);
188  ecalposition->SetLineWidth(2);
189  ecalposition->SetDepthTest(kFALSE);
190  tList->AddElement(ecalposition);
191 
192  // hcal position
193  TEveStraightLineSet *hcalposition = new TEveStraightLineSet("hcal position");
194  hcalposition->SetPickable(kTRUE);
195  hcalposition->SetTitle("Muon position at HCAL surface");
196  if ( barrel ) {
197  x = i->calEnergy().hcal_position.eta();
198  y = i->calEnergy().hcal_position.phi();
199  } else {
200  x = i->calEnergy().hcal_position.x();
201  y = i->calEnergy().hcal_position.y();
202  }
203  hcalposition->AddLine(x-delta,y,0,x+delta,y,0);
204  hcalposition->AddLine(x,y-delta,0,x,y+delta,0);
205  hcalposition->AddLine(x,y,0-delta,x,y,0+delta);
206  hcalposition->SetLineColor(kBlue);
207  hcalposition->SetLineWidth(2);
208  hcalposition->SetDepthTest(kFALSE);
209  tList->AddElement(hcalposition);
210 
211  // draw a line connecting the two positions
212  TEveStraightLineSet *lines = new TEveStraightLineSet("Muon trajectory in ECAL","Muon trajectory in ECAL");
213  lines->SetPickable(kTRUE);
214  if ( barrel ) {
215  lines->AddLine(i->calEnergy().ecal_position.eta(),
216  i->calEnergy().ecal_position.phi(),
217  0,
218  i->calEnergy().hcal_position.eta(),
219  i->calEnergy().hcal_position.phi(),
220  0);
221  } else {
222  lines->AddLine(i->calEnergy().ecal_position.x(),
223  i->calEnergy().ecal_position.y(),
224  0,
225  i->calEnergy().hcal_position.x(),
226  i->calEnergy().hcal_position.y(),
227  0);
228  }
229  lines->SetLineColor(kRed);
230  lines->SetDepthTest(kFALSE);
231  tList->AddElement(lines);
232 }
233 
234 
dbl * delta
Definition: mlp_gen.cc:36
int i
Definition: DBlmapReader.cc:9
virtual void build(const FWModelId &id, const reco::Muon *)
TEveCaloData * m_data
TGLViewer * viewerGL() const
double makeLegend(double x0=0.02, double y0=0.95, Color_t clustered1=kGreen+1, Color_t clustered2=kTeal, Color_t supercluster=kYellow)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
const FWEventItem * item()
float emS9
energy deposited in 3x3 ECAL crystal shape around central crystal
Definition: MuonEnergy.h:18
#define REGISTER_FWDETAILVIEW(_classname_, _name_,...)
virtual double eta() const
momentum pseudorapidity
virtual double pt() const
transverse momentum
float emS25
energy deposited in 5x5 ECAL crystal shape around central crystal
Definition: MuonEnergy.h:20
virtual ~FWMuonDetailView()
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
void addSceneInfo(const reco::Muon *i, TEveElementList *tList)
FWECALDetailViewBuilder * m_builder
math::XYZPointF hcal_position
Definition: MuonEnergy.h:44
bool isEnergyValid() const
Definition: Muon.h:109
virtual double theta() const
momentum polar angle
MuonEnergy calEnergy() const
get energy deposition information
Definition: Muon.h:111
void showSuperClusters(Color_t color1=kGreen+2, Color_t color2=kTeal)
virtual void setTextInfo(const FWModelId &, const reco::Muon *)
void setColor(Color_t color, const std::vector< DetId > &detIds)
DetId ecal_id
DetId of the central ECAL crystal.
Definition: MuonEnergy.h:47
math::XYZPointF ecal_position
Trajectory position at the calorimeter.
Definition: MuonEnergy.h:43
virtual double phi() const
momentum azimuthal angle