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  :     FWLegoViewBase
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:  Chris Jones
0010 //         Created:  Thu Feb 21 11:22:41 EST 2008
0011 //
0012 
0013 // system include files
0014 #include <functional>
0015 
0016 #include "TAxis.h"
0017 #include "TH2.h"
0018 
0019 #include "TGLViewer.h"
0020 #include "TGLLightSet.h"
0021 #include "TGLPerspectiveCamera.h"
0022 #include "TGLOrthoCamera.h"
0023 #include "TEveManager.h"
0024 #include "TEveElement.h"
0025 #include "TEveScene.h"
0026 #include "TEveCalo.h"
0027 #include "TEveTrans.h"
0028 #include "TEveScene.h"
0029 #include "TEveCaloLegoOverlay.h"
0030 
0031 // user include files
0032 #include "Fireworks/Core/interface/FWGLEventHandler.h"
0033 #include "Fireworks/Core/interface/FWConfiguration.h"
0034 #include "Fireworks/Core/interface/FWLegoViewBase.h"
0035 #include "Fireworks/Core/interface/FWViewEnergyScale.h"
0036 #include "Fireworks/Core/interface/FWViewContext.h"
0037 #include "Fireworks/Core/interface/CmsShowViewPopup.h"
0038 #include "Fireworks/Core/interface/fw3dlego_xbins.h"
0039 
0040 //
0041 // constants, enums and typedefs
0042 //
0043 
0044 //
0045 // static data member definitions
0046 //
0047 
0048 //
0049 // constructors and destructor
0050 //
0051 FWLegoViewBase::FWLegoViewBase(TEveWindowSlot* iParent, FWViewType::EType typeId)
0052     : FWEveView(iParent, typeId),
0053       m_lego(nullptr),
0054       m_overlay(nullptr),
0055       m_autoRebin(this, "Auto rebin on zoom-out", false),
0056       m_pixelsPerBin(this, "Pixels per bin", 10., 1., 20.),
0057       m_projectionMode(this, "Projection", 0l, 0l, 2l),
0058       m_cell2DMode(this, "Cell2DMode", 1l, 1l, 2l),
0059       m_drawValuesIn2D(this, "Draw Cell2D threshold (pixels)", 40l, 16l, 1200l),
0060       m_showOverlay(this, "Draw scales", true) {
0061   viewerGL()->SetCurrentCamera(TGLViewer::kCameraOrthoXOY);
0062   viewerGL()->GetLightSet()->SetUseSpecular(false);
0063 
0064   m_projectionMode.addEntry(0, "Auto");
0065   m_projectionMode.addEntry(1, "3D");
0066   m_projectionMode.addEntry(2, "2D");
0067 
0068   m_cell2DMode.addEntry(1, "Plain");
0069   m_cell2DMode.addEntry(2, "Outline");
0070   if (typeId == FWViewType::kLegoHF)
0071     m_cell2DMode.set(2);  // different default for HF view
0072 
0073   m_autoRebin.changed_.connect(std::bind(&FWLegoViewBase::setAutoRebin, this));
0074   m_pixelsPerBin.changed_.connect(std::bind(&FWLegoViewBase::setPixelsPerBin, this));
0075   m_drawValuesIn2D.changed_.connect(std::bind(&FWLegoViewBase::setFontSizein2D, this));
0076   m_showOverlay.changed_.connect(std::bind(&FWLegoViewBase::showOverlay, this));
0077   m_projectionMode.changed_.connect(std::bind(&FWLegoViewBase::setProjectionMode, this));
0078   m_cell2DMode.changed_.connect(std::bind(&FWLegoViewBase::setCell2DMode, this));
0079 }
0080 
0081 FWLegoViewBase::~FWLegoViewBase() {
0082   viewerGL()->RemoveOverlayElement(m_overlay);
0083   m_lego->Destroy();
0084 }
0085 
0086 TEveCaloViz* FWLegoViewBase::getEveCalo() const { return static_cast<TEveCaloViz*>(m_lego); }
0087 
0088 void FWLegoViewBase::setContext(const fireworks::Context& ctx) {
0089   FWEveView::setContext(ctx);
0090 
0091   TEveCaloData* data;
0092   if (typeId() == FWViewType::kLego) {
0093     data = static_cast<TEveCaloData*>(ctx.getCaloData());
0094   } else if (typeId() == FWViewType::kLegoHF) {
0095     data = static_cast<TEveCaloData*>(ctx.getCaloDataHF());
0096   } else {
0097     // create empty data locally instead of context
0098     TEveCaloDataHist* hdata = new TEveCaloDataHist();
0099     hdata->IncDenyDestroy();
0100 
0101     Bool_t status = TH1::AddDirectoryStatus();
0102     TH1::AddDirectory(kFALSE);  //Keeps histogram from going into memory
0103     TH2F* dummy =
0104         new TH2F("background", "background", fw3dlego::xbins_n - 1, fw3dlego::xbins, 72, -1 * TMath::Pi(), TMath::Pi());
0105 
0106     TH1::AddDirectory(status);
0107     Int_t sliceIndex = hdata->AddHistogram(dummy);
0108     (hdata)->RefSliceInfo(sliceIndex).Setup("background", 0., 0);
0109     data = hdata;
0110   }
0111 
0112   data->GetEtaBins()->SetNdivisions(710);
0113   data->GetPhiBins()->SetNdivisions(510);
0114   data->GetEtaBins()->SetTitleFont(120);
0115   data->GetEtaBins()->SetTitle("h");
0116   data->GetPhiBins()->SetTitleFont(120);
0117   data->GetPhiBins()->SetTitle("f");
0118   data->GetEtaBins()->SetLabelSize(0.02);
0119   data->GetEtaBins()->SetTitleSize(0.03);
0120 
0121   m_lego = new TEveCaloLego(data);
0122   m_lego->Set2DMode((TEveCaloLego::E2DMode_e)m_cell2DMode.value());
0123   m_lego->SetDrawNumberCellPixels(m_drawValuesIn2D.value());
0124   m_lego->SetAutoRebin(m_autoRebin.value());
0125   m_lego->SetPixelsPerBin(m_pixelsPerBin.value());
0126 
0127   m_lego->InitMainTrans();
0128   m_lego->RefMainTrans().SetScale(TMath::TwoPi(), TMath::TwoPi(), TMath::Pi());
0129   m_lego->SetScaleAbs(true);
0130 
0131   // set flat in 2D
0132   m_lego->SetHasFixedHeightIn2DMode(true);
0133   m_lego->SetFixedHeightValIn2DMode(0.001);
0134   eventScene()->AddElement(m_lego);
0135 
0136   TEveLegoEventHandler* eh = dynamic_cast<TEveLegoEventHandler*>(viewerGL()->GetEventHandler());
0137   if (eh)
0138     eh->SetLego(m_lego);
0139 
0140   m_overlay = new TEveCaloLegoOverlay();
0141   m_overlay->SetCaloLego(m_lego);
0142   m_overlay->SetShowPlane(kFALSE);
0143   m_overlay->SetScalePosition(0.8, 0.6);
0144   m_overlay->SetShowScales(true);  //temporary
0145   viewerGL()->AddOverlayElement(m_overlay);
0146 }
0147 
0148 void FWLegoViewBase::setAutoRebin() {
0149   m_lego->SetAutoRebin(m_autoRebin.value());
0150   m_lego->ElementChanged(kTRUE, kTRUE);
0151 }
0152 
0153 void FWLegoViewBase::setPixelsPerBin() {
0154   m_lego->SetPixelsPerBin((Int_t)(m_pixelsPerBin.value()));
0155   m_lego->ElementChanged(kTRUE, kTRUE);
0156 }
0157 
0158 void FWLegoViewBase::showOverlay() {
0159   if (m_overlay)
0160     m_overlay->SetShowScales(m_showOverlay.value());
0161   viewerGL()->Changed();
0162   gEve->Redraw3D();
0163 }
0164 
0165 //_______________________________________________________________________________
0166 
0167 void FWLegoViewBase::setFrom(const FWConfiguration& iFrom) {
0168   FWEveView::setFrom(iFrom);
0169 
0170   // cell 2D style
0171   if (iFrom.version() < 5) {
0172     const FWConfiguration* value = iFrom.valueForKey("Cell2DMode");
0173     if (value != nullptr) {
0174       int mode;
0175       std::istringstream s(value->value());
0176       s >> mode;
0177       m_cell2DMode.set(mode);
0178     }
0179   }
0180 
0181   // view controller parameters, changed name in version 4
0182   if (iFrom.version() < 4) {
0183     bool xb; /* double xd;
0184       {
0185          std::istringstream s(iFrom.valueForKey("Lego auto scale")->value());
0186          s >> xb; m_energyScaleMode.set(xb ? FWEveView::kAutoScale : FWEveView::kFixedScale);
0187       }
0188       {
0189          std::istringstream s(iFrom.valueForKey("Lego scale GeV)")->value());
0190          s >> xd; m_energyMaxAbsVal.set(xd);
0191          }*/
0192     {
0193       std::istringstream s(iFrom.valueForKey("Show scales")->value());
0194       s >> xb;
0195       m_showOverlay.set(xb);
0196     }
0197     {
0198       std::istringstream s(iFrom.valueForKey("Show scales")->value());
0199       s >> xb;
0200       m_showOverlay.set(xb);
0201     }
0202     {
0203       std::istringstream s(iFrom.valueForKey("Auto rebin on zoom")->value());
0204       s >> xb;
0205       m_autoRebin.set(xb);
0206     }
0207   }
0208 
0209   //
0210   // camera restore
0211 
0212   if (iFrom.version() > 1) {
0213     bool topView = true;
0214     std::string stateName("topView");
0215     stateName += typeName();
0216     assert(nullptr != iFrom.valueForKey(stateName));
0217     std::istringstream s(iFrom.valueForKey(stateName)->value());
0218     s >> topView;
0219 
0220     if (topView) {
0221       viewerGL()->SetCurrentCamera(TGLViewer::kCameraOrthoXOY);
0222       TGLOrthoCamera* camera = dynamic_cast<TGLOrthoCamera*>(&(viewerGL()->RefCamera(TGLViewer::kCameraOrthoXOY)));
0223       setFromOrthoCamera(camera, iFrom);
0224     } else {
0225       viewerGL()->SetCurrentCamera(TGLViewer::kCameraPerspXOY);
0226       TGLPerspectiveCamera* camera =
0227           dynamic_cast<TGLPerspectiveCamera*>(&(viewerGL()->RefCamera(TGLViewer::kCameraPerspXOY)));
0228       setFromPerspectiveCamera(camera, typeName(), iFrom);
0229     }
0230   } else {
0231     // reset camera if version not supported
0232     viewerGL()->ResetCamerasAfterNextUpdate();
0233   }
0234 }
0235 
0236 void FWLegoViewBase::addTo(FWConfiguration& iTo) const {
0237   FWEveView::addTo(iTo);
0238 
0239   bool topView = viewerGL()->CurrentCamera().IsOrthographic();
0240   std::ostringstream s;
0241   s << topView;
0242   std::string name = "topView";
0243   iTo.addKeyValue(name + typeName(), FWConfiguration(s.str()));
0244 
0245   if (topView) {
0246     TGLOrthoCamera* camera = dynamic_cast<TGLOrthoCamera*>(&(viewerGL()->RefCamera(TGLViewer::kCameraOrthoXOY)));
0247     addToOrthoCamera(camera, iTo);
0248   } else {
0249     TGLPerspectiveCamera* camera =
0250         dynamic_cast<TGLPerspectiveCamera*>(&(viewerGL()->RefCamera(TGLViewer::kCameraPerspXOY)));
0251     addToPerspectiveCamera(camera, typeName(), iTo);
0252   }
0253 }
0254 
0255 void FWLegoViewBase::setFontSizein2D() {
0256   m_lego->SetDrawNumberCellPixels(m_drawValuesIn2D.value());
0257   m_lego->ElementChanged(kTRUE, kTRUE);
0258 }
0259 
0260 void FWLegoViewBase::setProjectionMode() {
0261   m_lego->SetProjection((TEveCaloLego::EProjection_e)m_projectionMode.value());
0262   m_lego->ElementChanged();
0263   viewerGL()->Changed();
0264   gEve->Redraw3D();
0265 }
0266 
0267 void FWLegoViewBase::setCell2DMode() {
0268   m_lego->Set2DMode((TEveCaloLego::E2DMode_e)m_cell2DMode.value());
0269   m_lego->ElementChanged();
0270   viewerGL()->Changed();
0271   gEve->Redraw3D();
0272 }
0273 
0274 void FWLegoViewBase::populateController(ViewerParameterGUI& gui) const {
0275   FWEveView::populateController(gui);
0276 
0277   gui.requestTab("Style").separator().addParam(&m_projectionMode).addParam(&m_cell2DMode).addParam(&m_drawValuesIn2D);
0278 
0279   gui.requestTab("Scales").separator().addParam(&m_showOverlay);
0280 
0281   gui.requestTab("Rebin").addParam(&m_autoRebin).addParam(&m_pixelsPerBin);
0282 }