CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FWInvMassDialog.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : FWInvMassDialog
5 //
6 // Implementation:
7 // [Notes on implementation]
8 //
9 // Original Author: Matevz Tadel
10 // Created: Mon Nov 22 11:05:57 CET 2010
11 // $Id: FWInvMassDialog.cc,v 1.2 2010/12/01 16:47:09 matevz Exp $
12 //
13 
14 // system include files
15 
16 // user include files
20 
23 
24 #include "TClass.h"
25 #include "TMath.h"
26 
27 #include "TGTextView.h"
28 #include "TGButton.h"
29 
30 //
31 // constants, enums and typedefs
32 //
33 
34 //
35 // static data member definitions
36 //
37 
38 //
39 // constructors and destructor
40 //
41 
43  TGMainFrame(gClient->GetRoot(), 470, 240),
44  m_selectionMgr(sm),
45  m_text(0),
46  m_button(0)
47 {
48  SetWindowName("Invariant Mass Dialog");
49  SetCleanup(kDeepCleanup);
50 
51  m_text = new TGTextView(this);
52  AddFrame(m_text, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY, 1, 1, 1, 1));
53 
54  m_button = new TGTextButton(this, "Calculate");
55  AddFrame(m_button, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 1, 1, 1, 1));
56 
57  m_button->Connect("Clicked()","FWInvMassDialog", this, "Calculate()");
58 
59  Layout();
60  MapSubwindows();
61 }
62 
63 // FWInvMassDialog::FWInvMassDialog(const FWInvMassDialog& rhs)
64 // {
65 // // do actual copying here;
66 // }
67 
69 {
70 }
71 
73 {
74  UnmapWindow();
75 }
76 
77 //
78 // assignment operators
79 //
80 // const FWInvMassDialog& FWInvMassDialog::operator=(const FWInvMassDialog& rhs)
81 // {
82 // //An exception safe implementation is
83 // FWInvMassDialog temp(rhs);
84 // swap(rhs);
85 //
86 // return *this;
87 // }
88 
89 //
90 // member functions
91 //
92 
94 {
95  m_text->Clear();
96  m_firstLine = true;
97 }
98 
99 void FWInvMassDialog::addLine(const TString& line)
100 {
101  TGText *txt = m_text->GetText();
102 
103  if (m_firstLine)
104  {
105  txt->InsText(TGLongPosition(0, 0), line);
106  m_firstLine = false;
107  }
108  else
109  {
110  txt->InsText(TGLongPosition(0, txt->RowCount()), line);
111  }
112 }
113 
115 {
116  m_text->Update();
117 }
118 
120 {
121  const std::set<FWModelId>& sted = m_selectionMgr->selected();
122 
123  beginUpdate();
124 
125  addLine(TString::Format(" %d items in selection", (int) sted.size()));
126  addLine("");
127  addLine("--------------------------------------------------+--------------");
128  addLine(" px py pz pT | Collection");
129  addLine("--------------------------------------------------+--------------");
130 
131  TClass *rc_class = TClass::GetClass(typeid(reco::Candidate));
132  TClass *rtb_class = TClass::GetClass(typeid(reco::TrackBase));
133 
134  math::XYZVector sum;
135  double sum_len = 0;
136  double sum_len_xy = 0;
137 
138  for (std::set<FWModelId>::const_iterator i = sted.begin(); i != sted.end(); ++i)
139  {
140  TString line;
141 
142  TClass *model_class = const_cast<TClass*>(i->item()->modelType());
143  void *model_data = const_cast<void*> (i->item()->modelData(i->index()));
144 
146  bool ok_p = false;
147 
148  reco::Candidate *rc = reinterpret_cast<reco::Candidate*>
149  (model_class->DynamicCast(rc_class, model_data));
150 
151  if (rc != 0)
152  {
153  ok_p = true;
154  v.SetXYZ(rc->px(), rc->py(), rc->pz());
155  }
156  else
157  {
158  reco::TrackBase *rtb = reinterpret_cast<reco::TrackBase*>
159  (model_class->DynamicCast(rtb_class, model_data));
160 
161  if (rtb != 0)
162  {
163  ok_p = true;
164  v.SetXYZ(rtb->px(), rtb->py(), rtb->pz());
165  }
166  }
167 
168  if (ok_p)
169  {
170  sum += v;
171  sum_len += TMath::Sqrt(v.mag2());
172  sum_len_xy += TMath::Sqrt(v.perp2());
173 
174  line = TString::Format(" %+10.3f %+10.3f %+10.3f %10.3f", v.x(), v.y(), v.z(), TMath::Sqrt(v.perp2()));
175 
176  }
177  else
178  {
179  line = TString::Format(" -------- not a Candidate or TrackBase --------");
180  }
181  line += TString::Format(" | %s[%d]", i->item()->name().c_str(), i->index());
182 
183  addLine(line);
184  }
185 
186  addLine("--------------------------------------------------+--------------");
187  addLine(TString::Format(" %+10.3f %+10.3f %+10.3f %10.3f | Sum", sum.x(), sum.y(), sum.z(), TMath::Sqrt(sum.perp2())));
188  addLine("");
189  addLine(TString::Format("m = %10.3f", TMath::Sqrt(TMath::Max(0.0, sum_len * sum_len - sum.mag2()))));
190  addLine(TString::Format("mT = %10.3f", TMath::Sqrt(TMath::Max(0.0, sum_len_xy * sum_len_xy - sum.perp2()))));
191 
192  endUpdate();
193 }
194 
195 //
196 // const member functions
197 //
198 
199 //
200 // static member functions
201 //
const std::set< FWModelId > & selected() const
int i
Definition: DBlmapReader.cc:9
virtual ~FWInvMassDialog()
virtual double pz() const =0
z coordinate of momentum vector
virtual void CloseWindow()
double px() const
x coordinate of momentum vector
Definition: TrackBase.h:132
FWInvMassDialog(FWSelectionManager *sm)
TGTextView * m_text
void addLine(const TString &line)
virtual double py() const =0
y coordinate of momentum vector
double pz() const
z coordinate of momentum vector
Definition: TrackBase.h:136
virtual double px() const =0
x coordinate of momentum vector
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
TGTextButton * m_button
FWSelectionManager * m_selectionMgr
mathSSE::Vec4< T > v
double py() const
y coordinate of momentum vector
Definition: TrackBase.h:134