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.3.14.1 2012/12/03 06:26:26 amraktad Exp $
12 //
13 
14 // system include files
15 
16 // user include files
20 
24 
25 #include "TClass.h"
26 #include "TMath.h"
27 
28 #include "TGTextView.h"
29 #include "TGButton.h"
30 
31 //
32 // constants, enums and typedefs
33 //
34 
35 //
36 // static data member definitions
37 //
38 
39 //
40 // constructors and destructor
41 //
42 
44  TGMainFrame(gClient->GetRoot(), 470, 240),
45  m_selectionMgr(sm),
46  m_text(0),
47  m_button(0)
48 {
49  SetWindowName("Invariant Mass Dialog");
50  SetCleanup(kDeepCleanup);
51 
52  m_text = new TGTextView(this);
53  AddFrame(m_text, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY, 1, 1, 1, 1));
54 
55  m_button = new TGTextButton(this, "Calculate");
56  AddFrame(m_button, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 1, 1, 1, 1));
57 
58  m_button->Connect("Clicked()","FWInvMassDialog", this, "Calculate()");
59 
60  Layout();
61  MapSubwindows();
62 }
63 
64 // FWInvMassDialog::FWInvMassDialog(const FWInvMassDialog& rhs)
65 // {
66 // // do actual copying here;
67 // }
68 
70 {
71 }
72 
74 {
75  UnmapWindow();
76 }
77 
78 //
79 // assignment operators
80 //
81 // const FWInvMassDialog& FWInvMassDialog::operator=(const FWInvMassDialog& rhs)
82 // {
83 // //An exception safe implementation is
84 // FWInvMassDialog temp(rhs);
85 // swap(rhs);
86 //
87 // return *this;
88 // }
89 
90 //
91 // member functions
92 //
93 
95 {
96  m_text->Clear();
97  m_firstLine = true;
98 }
99 
100 void FWInvMassDialog::addLine(const TString& line)
101 {
102  TGText *txt = m_text->GetText();
103 
104  if (m_firstLine)
105  {
106  txt->InsText(TGLongPosition(0, 0), line);
107  m_firstLine = false;
108  }
109  else
110  {
111  txt->InsText(TGLongPosition(0, txt->RowCount()), line);
112  }
113 }
114 
116 {
117  m_text->Update();
118 }
119 
121 {
122  const std::set<FWModelId>& sted = m_selectionMgr->selected();
123 
124  beginUpdate();
125 
126  addLine(TString::Format(" %d items in selection", (int) sted.size()));
127  addLine("");
128  addLine("--------------------------------------------------+--------------");
129  addLine(" px py pz pT | Collection");
130  addLine("--------------------------------------------------+--------------");
131 
132  TClass *rc_class = TClass::GetClass(typeid(reco::Candidate));
133  TClass *rtb_class = TClass::GetClass(typeid(reco::TrackBase));
134 
135  math::XYZVector sum;
136  double sum_len = 0;
137  double sum_len_xy = 0;
138 
139  math::XYZVector first, second; int n = 0;
140 
141  for (std::set<FWModelId>::const_iterator i = sted.begin(); i != sted.end(); ++i, ++n)
142  {
143  TString line;
144 
145  TClass *model_class = const_cast<TClass*>(i->item()->modelType());
146  void *model_data = const_cast<void*> (i->item()->modelData(i->index()));
147 
149  bool ok_p = false;
150 
151  reco::Candidate *rc = reinterpret_cast<reco::Candidate*>
152  (model_class->DynamicCast(rc_class, model_data));
153 
154  if (rc != 0)
155  {
156  ok_p = true;
157  v.SetXYZ(rc->px(), rc->py(), rc->pz());
158  }
159  else
160  {
161  reco::TrackBase *rtb = reinterpret_cast<reco::TrackBase*>
162  (model_class->DynamicCast(rtb_class, model_data));
163 
164  if (rtb != 0)
165  {
166  ok_p = true;
167  v.SetXYZ(rtb->px(), rtb->py(), rtb->pz());
168  }
169  }
170 
171  if (ok_p)
172  {
173  sum += v;
174  sum_len += TMath::Sqrt(v.mag2());
175  sum_len_xy += TMath::Sqrt(v.perp2());
176 
177  line = TString::Format(" %+10.3f %+10.3f %+10.3f %10.3f", v.x(), v.y(), v.z(), TMath::Sqrt(v.perp2()));
178 
179  }
180  else
181  {
182  line = TString::Format(" -------- not a Candidate or TrackBase --------");
183  }
184  line += TString::Format(" | %s[%d]", i->item()->name().c_str(), i->index());
185 
186  addLine(line);
187 
188  if (n == 0) first = v; else if (n == 1) second = v;
189  }
190 
191  addLine("--------------------------------------------------+--------------");
192  addLine(TString::Format(" %+10.3f %+10.3f %+10.3f %10.3f | Sum", sum.x(), sum.y(), sum.z(), TMath::Sqrt(sum.perp2())));
193  addLine("");
194  addLine(TString::Format("m = %10.3f", TMath::Sqrt(TMath::Max(0.0, sum_len * sum_len - sum.mag2()))));
195  addLine(TString::Format("mT = %10.3f", TMath::Sqrt(TMath::Max(0.0, sum_len_xy * sum_len_xy - sum.perp2()))));
196  addLine(TString::Format("HT = %10.3f", sum_len_xy));
197 
198  if (n == 2) {
199  addLine(TString::Format("deltaPhi = %+6.4f", deltaPhi(first.Phi(), second.Phi())));
200  addLine(TString::Format("deltaEta = %+6.4f", first.Eta()- second.Eta()));
201  addLine(TString::Format("deltaR = % 6.4f", deltaR(first.Eta(), first.Phi(), second.Eta(), second.Phi())));
202  }
203 
204  endUpdate();
205 }
206 
207 //
208 // const member functions
209 //
210 
211 //
212 // static member functions
213 //
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:133
FWInvMassDialog(FWSelectionManager *sm)
U second(std::pair< T, U > const &p)
TGTextView * m_text
void addLine(const TString &line)
virtual double py() const =0
y coordinate of momentum vector
bool first
Definition: L1TdeRCT.cc:94
double pz() const
z coordinate of momentum vector
Definition: TrackBase.h:137
virtual double px() const =0
x coordinate of momentum vector
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
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:135