Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:41

0001 // -*- C++ -*-
0002 //
0003 // Package:     Core
0004 // Class  :     FWInvMassDialog
0005 //
0006 // Implementation:
0007 //     [Notes on implementation]
0008 //
0009 // Original Author:  Matevz Tadel
0010 //         Created:  Mon Nov 22 11:05:57 CET 2010
0011 //
0012 
0013 // system include files
0014 
0015 // user include files
0016 #include "Fireworks/Core/interface/FWInvMassDialog.h"
0017 #include "Fireworks/Core/interface/FWSelectionManager.h"
0018 #include "Fireworks/Core/interface/FWEventItem.h"
0019 
0020 #include "DataFormats/Candidate/interface/Candidate.h"
0021 #include "DataFormats/TrackReco/interface/TrackBase.h"
0022 #include "DataFormats/Math/interface/deltaR.h"
0023 
0024 #include "TClass.h"
0025 #include "TMath.h"
0026 
0027 #include "TGTextView.h"
0028 #include "TGButton.h"
0029 
0030 //
0031 // constants, enums and typedefs
0032 //
0033 
0034 //
0035 // static data member definitions
0036 //
0037 
0038 //
0039 // constructors and destructor
0040 //
0041 
0042 FWInvMassDialog::FWInvMassDialog(FWSelectionManager *sm)
0043     : TGMainFrame(gClient->GetRoot(), 470, 240), m_selectionMgr(sm), m_text(nullptr), m_button(nullptr) {
0044   SetWindowName("Invariant Mass Dialog");
0045   SetCleanup(kDeepCleanup);
0046 
0047   m_text = new TGTextView(this);
0048   AddFrame(m_text, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY, 1, 1, 1, 1));
0049 
0050   m_button = new TGTextButton(this, "Calculate");
0051   AddFrame(m_button, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 1, 1, 1, 1));
0052 
0053   m_button->Connect("Clicked()", "FWInvMassDialog", this, "Calculate()");
0054 
0055   Layout();
0056   MapSubwindows();
0057 }
0058 
0059 // FWInvMassDialog::FWInvMassDialog(const FWInvMassDialog& rhs)
0060 // {
0061 //    // do actual copying here;
0062 // }
0063 
0064 FWInvMassDialog::~FWInvMassDialog() {}
0065 
0066 void FWInvMassDialog::CloseWindow() { UnmapWindow(); }
0067 
0068 //
0069 // assignment operators
0070 //
0071 // const FWInvMassDialog& FWInvMassDialog::operator=(const FWInvMassDialog& rhs)
0072 // {
0073 //   //An exception safe implementation is
0074 //   FWInvMassDialog temp(rhs);
0075 //   swap(rhs);
0076 //
0077 //   return *this;
0078 // }
0079 
0080 //
0081 // member functions
0082 //
0083 
0084 void FWInvMassDialog::beginUpdate() {
0085   m_text->Clear();
0086   m_firstLine = true;
0087 }
0088 
0089 void FWInvMassDialog::addLine(const TString &line) {
0090   TGText *txt = m_text->GetText();
0091 
0092   if (m_firstLine) {
0093     txt->InsText(TGLongPosition(0, 0), line);
0094     m_firstLine = false;
0095   } else {
0096     txt->InsText(TGLongPosition(0, txt->RowCount()), line);
0097   }
0098 }
0099 
0100 void FWInvMassDialog::endUpdate() { m_text->Update(); }
0101 
0102 void FWInvMassDialog::Calculate() {
0103   const std::set<FWModelId> &sted = m_selectionMgr->selected();
0104 
0105   beginUpdate();
0106 
0107   addLine(TString::Format(" %d items in selection", (int)sted.size()));
0108   addLine("");
0109   addLine("--------------------------------------------------+--------------");
0110   addLine("       px          py          pz          pT     | Collection");
0111   addLine("--------------------------------------------------+--------------");
0112 
0113   TClass *rc_class = TClass::GetClass(typeid(reco::Candidate));
0114   TClass *rtb_class = TClass::GetClass(typeid(reco::TrackBase));
0115 
0116   math::XYZVector sum;
0117   double sum_len = 0;
0118   double sum_len_xy = 0;
0119 
0120   math::XYZVector first, second;
0121   int n = 0;
0122 
0123   for (std::set<FWModelId>::const_iterator i = sted.begin(); i != sted.end(); ++i, ++n) {
0124     TString line;
0125 
0126     TClass *model_class = const_cast<TClass *>(i->item()->modelType());
0127     void *model_data = const_cast<void *>(i->item()->modelData(i->index()));
0128 
0129     math::XYZVector v;
0130     bool ok_p = false;
0131 
0132     reco::Candidate *rc = reinterpret_cast<reco::Candidate *>(model_class->DynamicCast(rc_class, model_data));
0133 
0134     if (rc != nullptr) {
0135       ok_p = true;
0136       v.SetXYZ(rc->px(), rc->py(), rc->pz());
0137     } else {
0138       reco::TrackBase *rtb = reinterpret_cast<reco::TrackBase *>(model_class->DynamicCast(rtb_class, model_data));
0139 
0140       if (rtb != nullptr) {
0141         ok_p = true;
0142         v.SetXYZ(rtb->px(), rtb->py(), rtb->pz());
0143       }
0144     }
0145 
0146     if (ok_p) {
0147       sum += v;
0148       sum_len += TMath::Sqrt(v.mag2());
0149       sum_len_xy += TMath::Sqrt(v.perp2());
0150 
0151       line = TString::Format("  %+10.3f  %+10.3f  %+10.3f  %10.3f", v.x(), v.y(), v.z(), TMath::Sqrt(v.perp2()));
0152 
0153     } else {
0154       line = TString::Format("  -------- not a Candidate or TrackBase --------");
0155     }
0156     line += TString::Format("  | %s[%d]", i->item()->name().c_str(), i->index());
0157 
0158     addLine(line);
0159 
0160     if (n == 0)
0161       first = v;
0162     else if (n == 1)
0163       second = v;
0164   }
0165 
0166   addLine("--------------------------------------------------+--------------");
0167   addLine(TString::Format(
0168       "  %+10.3f  %+10.3f  %+10.3f  %10.3f  | Sum", sum.x(), sum.y(), sum.z(), TMath::Sqrt(sum.perp2())));
0169   addLine("");
0170   addLine(TString::Format("m  = %10.3f", TMath::Sqrt(TMath::Max(0.0, sum_len * sum_len - sum.mag2()))));
0171   addLine(TString::Format("mT = %10.3f", TMath::Sqrt(TMath::Max(0.0, sum_len_xy * sum_len_xy - sum.perp2()))));
0172   addLine(TString::Format("HT = %10.3f", sum_len_xy));
0173 
0174   if (n == 2) {
0175     addLine(TString::Format("deltaPhi  = %+6.4f", deltaPhi(first.Phi(), second.Phi())));
0176     addLine(TString::Format("deltaEta  = %+6.4f", first.Eta() - second.Eta()));
0177     addLine(TString::Format("deltaR    = % 6.4f", deltaR(first.Eta(), first.Phi(), second.Eta(), second.Phi())));
0178   }
0179 
0180   endUpdate();
0181 }
0182 
0183 //
0184 // const member functions
0185 //
0186 
0187 //
0188 // static member functions
0189 //