Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 
0002 // ROOT includes
0003 #include "TLatex.h"
0004 #include "TEveCalo.h"
0005 #include "TEveStraightLineSet.h"
0006 #include "TEvePointSet.h"
0007 #include "TEveScene.h"
0008 #include "TEveViewer.h"
0009 #include "TGLViewer.h"
0010 #include "TGLOverlay.h"
0011 #include "TCanvas.h"
0012 #include "TLegend.h"
0013 #include "TEveCaloLegoOverlay.h"
0014 #include "TRootEmbeddedCanvas.h"
0015 
0016 // Fireworks includes
0017 #include "Fireworks/Calo/interface/FWECALDetailViewBase.h"
0018 #include "Fireworks/Calo/interface/FWECALDetailViewBuilder.h"
0019 #include "Fireworks/Core/interface/FWColorManager.h"
0020 #include "Fireworks/Core/interface/FWModelId.h"
0021 #include "Fireworks/Core/interface/FWEventItem.h"
0022 #include "Fireworks/Core/interface/FWGLEventHandler.h"
0023 
0024 // CMSSW includes
0025 #include "DataFormats/Candidate/interface/Candidate.h"
0026 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
0027 
0028 template <typename T>
0029 FWECALDetailViewBase<T>::FWECALDetailViewBase() : m_data(nullptr), m_builder(nullptr), m_legend(nullptr) {}
0030 template <typename T>
0031 FWECALDetailViewBase<T>::~FWECALDetailViewBase() {
0032   FWDetailViewGL<T>::m_eveViewer->GetGLViewer()->DeleteOverlayElements(TGLOverlayElement::kUser);
0033 
0034   delete m_builder;
0035   if (m_data)
0036     m_data->DecDenyDestroy();
0037 }
0038 
0039 template <typename T>
0040 void FWECALDetailViewBase<T>::build(const FWModelId& id, const T* element) {
0041   double eta = element->eta();
0042   double phi = element->phi();
0043 
0044   // build ECAL objects
0045   m_builder = new FWECALDetailViewBuilder(id.item()->getEvent(), id.item()->getGeom(), eta, phi, 25);
0046 
0047   TEveCaloLego* lego = m_builder->build();
0048   m_data = lego->GetData();
0049   m_data->IncDenyDestroy();  // needed ???
0050   FWDetailViewGL<T>::m_eveScene->AddElement(lego);
0051 
0052   m_legend = new TLegend(0.01, 0.01, 0.99, 0.99, nullptr, "NDC");
0053   m_legend->SetTextSize(0.075);
0054   m_legend->SetBorderSize(0);
0055   m_legend->SetMargin(0.15);
0056   m_legend->SetEntrySeparation(0.05);
0057 
0058   // draw axis at the window corners
0059   if (true) {
0060     TEveCaloLegoOverlay* overlay = new TEveCaloLegoOverlay();
0061     overlay->SetShowPlane(kFALSE);
0062     overlay->SetShowPerspective(kFALSE);
0063     overlay->SetCaloLego(lego);
0064     overlay->SetShowScales(true);  // temporary
0065 
0066     FWDetailViewGL<T>::viewerGL()->AddOverlayElement(overlay);
0067   }
0068   // set event handler and flip camera to top view at beginning
0069   FWDetailViewGL<T>::viewerGL()->SetCurrentCamera(TGLViewer::kCameraOrthoXOY);
0070   FWGLEventHandler* eh = new FWGLEventHandler(
0071       (TGWindow*)FWDetailViewGL<T>::viewerGL()->GetGLWidget(), (TObject*)FWDetailViewGL<T>::viewerGL(), lego);
0072   FWDetailViewGL<T>::viewerGL()->SetEventHandler(eh);
0073   FWDetailViewGL<T>::viewerGL()->ResetCamerasAfterNextUpdate();
0074   FWDetailViewGL<T>::viewerGL()->UpdateScene(kFALSE);
0075   gEve->Redraw3D();
0076 
0077   setTextInfo(id, element);
0078 }
0079 
0080 template <typename T>
0081 void FWECALDetailViewBase<T>::setTextInfo(const FWModelId& id, const T* element) {
0082   FWDetailViewGL<T>::m_infoCanvas->cd();
0083 
0084   float_t x = 0.02;
0085   float y = 0.95;
0086 
0087   TLatex* latex = new TLatex(x, y, "");
0088   const double textsize(0.1);
0089   latex->SetTextSize(textsize);
0090 
0091   latex->DrawLatex(x, y, id.item()->modelName(id.index()).c_str());
0092   y -= latex->GetTextSize() * 0.8;
0093 
0094   latex->SetTextSize(textsize * 0.8);
0095   float lineH = latex->GetTextSize() * 0.6;
0096 
0097   latex->DrawLatex(x, y, Form("#eta = %0.2f", element->eta()));
0098   y -= lineH;
0099   latex->DrawLatex(x, y, Form("#phi = %0.2f", element->phi()));
0100   y -= lineH;
0101   // summary
0102   if (element->charge() > 0)
0103     latex->DrawLatex(x, y, "charge = +1");
0104   else
0105     latex->DrawLatex(x, y, "charge = -1");
0106   y -= lineH;
0107 
0108   m_legend->SetY2(y);
0109   m_legend->Draw();
0110   m_legend = nullptr;  // Deleted together with TPad.
0111 }