CMS 3D CMS Logo

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 //
12 
13 // system include files
14 
15 // user include files
19 
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(nullptr),
46  m_button(nullptr)
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  math::XYZVector first, second; int n = 0;
139 
140  for (std::set<FWModelId>::const_iterator i = sted.begin(); i != sted.end(); ++i, ++n)
141  {
142  TString line;
143 
144  TClass *model_class = const_cast<TClass*>(i->item()->modelType());
145  void *model_data = const_cast<void*> (i->item()->modelData(i->index()));
146 
148  bool ok_p = false;
149 
150  reco::Candidate *rc = reinterpret_cast<reco::Candidate*>
151  (model_class->DynamicCast(rc_class, model_data));
152 
153  if (rc != nullptr)
154  {
155  ok_p = true;
156  v.SetXYZ(rc->px(), rc->py(), rc->pz());
157  }
158  else
159  {
160  reco::TrackBase *rtb = reinterpret_cast<reco::TrackBase*>
161  (model_class->DynamicCast(rtb_class, model_data));
162 
163  if (rtb != nullptr)
164  {
165  ok_p = true;
166  v.SetXYZ(rtb->px(), rtb->py(), rtb->pz());
167  }
168  }
169 
170  if (ok_p)
171  {
172  sum += v;
173  sum_len += TMath::Sqrt(v.mag2());
174  sum_len_xy += TMath::Sqrt(v.perp2());
175 
176  line = TString::Format(" %+10.3f %+10.3f %+10.3f %10.3f", v.x(), v.y(), v.z(), TMath::Sqrt(v.perp2()));
177 
178  }
179  else
180  {
181  line = TString::Format(" -------- not a Candidate or TrackBase --------");
182  }
183  line += TString::Format(" | %s[%d]", i->item()->name().c_str(), i->index());
184 
185  addLine(line);
186 
187  if (n == 0) first = v; else if (n == 1) second = v;
188  }
189 
190  addLine("--------------------------------------------------+--------------");
191  addLine(TString::Format(" %+10.3f %+10.3f %+10.3f %10.3f | Sum", sum.x(), sum.y(), sum.z(), TMath::Sqrt(sum.perp2())));
192  addLine("");
193  addLine(TString::Format("m = %10.3f", TMath::Sqrt(TMath::Max(0.0, sum_len * sum_len - sum.mag2()))));
194  addLine(TString::Format("mT = %10.3f", TMath::Sqrt(TMath::Max(0.0, sum_len_xy * sum_len_xy - sum.perp2()))));
195  addLine(TString::Format("HT = %10.3f", sum_len_xy));
196 
197  if (n == 2) {
198  addLine(TString::Format("deltaPhi = %+6.4f", deltaPhi(first.Phi(), second.Phi())));
199  addLine(TString::Format("deltaEta = %+6.4f", first.Eta()- second.Eta()));
200  addLine(TString::Format("deltaR = % 6.4f", deltaR(first.Eta(), first.Phi(), second.Eta(), second.Phi())));
201  }
202 
203  endUpdate();
204 }
205 
206 //
207 // const member functions
208 //
209 
210 //
211 // static member functions
212 //
const std::set< FWModelId > & selected() const
virtual double pz() const =0
z coordinate of momentum vector
double px() const
x coordinate of momentum vector
Definition: TrackBase.h:627
#define nullptr
~FWInvMassDialog() override
FWInvMassDialog(FWSelectionManager *sm)
U second(std::pair< T, U > const &p)
virtual double py() const =0
y coordinate of momentum vector
TGTextView * m_text
void addLine(const TString &line)
void CloseWindow() override
double pz() const
z coordinate of momentum vector
Definition: TrackBase.h:639
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
T Max(T a, T b)
Definition: MathUtil.h:44
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
TGTextButton * m_button
virtual double px() const =0
x coordinate of momentum vector
FWSelectionManager * m_selectionMgr
double py() const
y coordinate of momentum vector
Definition: TrackBase.h:633