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