Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:27:18

0001 // -*- C++ -*-
0002 //
0003 // Package:     Core
0004 // Class  :     FWRPZView
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:  Chris Jones
0010 //         Created:  Tue Feb 19 10:33:25 EST 2008
0011 //
0012 
0013 // system include files
0014 #include <stdexcept>
0015 #include <functional>
0016 #include <memory>
0017 
0018 #include "TGLViewer.h"
0019 #include "TGLScenePad.h"
0020 #include "TEveManager.h"
0021 #include "TEveElement.h"
0022 #include "TEveScene.h"
0023 #include "TEveProjections.h"
0024 #include "TEveProjectionAxes.h"
0025 #include "TGLabel.h"
0026 #include "TEveProjectionManager.h"
0027 #include "TEveCalo.h"
0028 
0029 // user include files
0030 #include "Fireworks/Core/interface/FWRPZView.h"
0031 #include "Fireworks/Core/interface/FWRPZViewGeometry.h"
0032 #include "Fireworks/Core/interface/FWBeamSpot.h"
0033 #include "Fireworks/Core/interface/Context.h"
0034 #include "Fireworks/Core/interface/fwLog.h"
0035 #include "Fireworks/Core/interface/FWViewContext.h"
0036 #include "Fireworks/Core/interface/FWViewContext.h"
0037 #include "Fireworks/Core/interface/FWViewEnergyScale.h"
0038 #include "Fireworks/Core/interface/CmsShowViewPopup.h"
0039 #include "Fireworks/Core/interface/CmsShowCommon.h"
0040 
0041 const float FWRPZView::s_distortF = 0.001;
0042 const float FWRPZView::s_distortFInv = 1000;
0043 //
0044 // constructors and destructor
0045 //
0046 FWRPZView::FWRPZView(TEveWindowSlot* iParent, FWViewType::EType id)
0047     : FWEveView(iParent, id, 7),
0048       m_geometryList(nullptr),
0049       m_projMgr(nullptr),
0050       m_axes(nullptr),
0051 
0052       m_calo(nullptr),
0053 
0054       m_showPixelBarrel(this, "Show Pixel Barrel", false),
0055       m_showPixelEndcap(this, "Show Pixel Endcap", false),
0056       m_showTrackerBarrel(this, "Show Tracker Barrel", false),
0057       m_showTrackerEndcap(this, "Show Tracker Endcap", false),
0058       m_showRpcEndcap(this, "Show RPC Endcap", false),
0059       m_showGEM(this, "Show GEM", false),
0060       m_showME0(this, "Show ME0", false),
0061 
0062       m_shiftOrigin(this, "Shift origin to beam-spot", false),
0063       m_fishEyeDistortion(this, "Distortion", 0., 0., 100.),
0064       m_fishEyeR(this, "FixedRadius", (double)fireworks::Context::caloR1(), 0.0, 150.0),
0065 
0066       m_caloDistortion(this, "Calo compression", 1.0, 0.01, 10.),
0067       m_muonDistortion(this, "Muon compression", 0.2, 0.01, 10.),
0068       m_showProjectionAxes(this, "Show projection axis", false),
0069       m_projectionAxesLabelSize(this, "Projection axis label size", 0.015, 0.001, 0.2),
0070       m_compressMuon(this, "Compress detectors", false),
0071       m_showHF(nullptr),
0072       m_showEndcaps(nullptr) {
0073   TEveProjection::EPType_e projType = (id == FWViewType::kRhoZ) ? TEveProjection::kPT_RhoZ : TEveProjection::kPT_RPhi;
0074 
0075   m_projMgr = new TEveProjectionManager(projType);
0076   m_projMgr->IncDenyDestroy();
0077   m_projMgr->SetImportEmpty(kTRUE);
0078 
0079   m_projMgr->GetProjection()->SetDistortion(m_fishEyeDistortion.value() * s_distortF);
0080   m_projMgr->GetProjection()->SetFixR(m_fishEyeR.value());
0081 
0082 #ifdef TEVEPROJECTIONS_DISPLACE_ORIGIN_MODE
0083   m_projMgr->GetProjection()->SetDisplaceOrigin(m_shiftOrigin.value());
0084 #endif
0085 
0086   if (id == FWViewType::kRhoPhi || id == FWViewType::kRhoPhiPF) {
0087     m_projMgr->GetProjection()->AddPreScaleEntry(0, fireworks::Context::caloR1(), 1.0);
0088     m_projMgr->GetProjection()->AddPreScaleEntry(0, 300, 0.2);
0089   } else {
0090     m_projMgr->GetProjection()->AddPreScaleEntry(0, fireworks::Context::caloR1(), 1.0);
0091     m_projMgr->GetProjection()->AddPreScaleEntry(1, 310, 1.0);
0092     m_projMgr->GetProjection()->AddPreScaleEntry(0, 370, 0.2);
0093     m_projMgr->GetProjection()->AddPreScaleEntry(1, 580, 0.2);
0094   }
0095 
0096   // camera
0097   viewerGL()->SetCurrentCamera(TGLViewer::kCameraOrthoXOY);
0098   if (TGLOrthoCamera* camera = dynamic_cast<TGLOrthoCamera*>(&(viewerGL()->CurrentCamera()))) {
0099     camera->SetZoomMax(1e6);
0100   }
0101   geoScene()->GetGLScene()->SetSelectable(kFALSE);
0102 
0103   m_axes = new TEveProjectionAxes(m_projMgr);
0104   m_axes->SetRnrState(m_showProjectionAxes.value());
0105   m_axes->SetLabelSize(m_projectionAxesLabelSize.value());
0106   m_showProjectionAxes.changed_.connect(std::bind(&FWRPZView::showProjectionAxes, this));
0107   m_projectionAxesLabelSize.changed_.connect(std::bind(&FWRPZView::projectionAxesLabelSize, this));
0108   eventScene()->AddElement(m_axes);
0109 
0110   if (id != FWViewType::kRhoZ) {
0111     m_showEndcaps = new FWBoolParameter(this, "Include EndCaps", true);
0112     m_showEndcaps->changed_.connect(std::bind(&FWRPZView::setEtaRng, this));
0113     m_showHF = new FWBoolParameter(this, "Include HF", true);
0114     m_showHF->changed_.connect(std::bind(&FWRPZView::setEtaRng, this));
0115   }
0116 
0117   m_shiftOrigin.changed_.connect(std::bind(&FWRPZView::doShiftOriginToBeamSpot, this));
0118 
0119   m_fishEyeDistortion.changed_.connect(std::bind(&FWRPZView::doFishEyeDistortion, this));
0120 
0121   m_fishEyeR.changed_.connect(std::bind(&FWRPZView::doFishEyeDistortion, this));
0122 
0123   m_caloDistortion.changed_.connect(std::bind(&FWRPZView::doPreScaleDistortion, this));
0124   m_muonDistortion.changed_.connect(std::bind(&FWRPZView::doPreScaleDistortion, this));
0125   m_compressMuon.changed_.connect(std::bind(&FWRPZView::doCompression, this, std::placeholders::_1));
0126 }
0127 
0128 FWRPZView::~FWRPZView() {
0129   m_calo->Destroy();
0130   m_projMgr->DecDenyDestroy();
0131 }
0132 
0133 //
0134 // member functions
0135 //
0136 
0137 TEveCaloViz* FWRPZView::getEveCalo() const { return static_cast<TEveCaloViz*>(m_calo); }
0138 
0139 void FWRPZView::setContext(const fireworks::Context& ctx) {
0140   FWEveView::setContext(ctx);
0141 
0142   m_geometryList = new FWRPZViewGeometry(ctx);
0143   m_geometryList->IncDenyDestroy();
0144   m_geometryList->initStdGeoElements(typeId());
0145   TEveElement* p = m_projMgr->ImportElements(m_geometryList);
0146   geoScene()->AddElement(p);
0147 
0148   TEveCaloData* data = context().getCaloData();
0149 
0150   TEveCalo3D* calo3d = new TEveCalo3D(data);
0151 
0152   m_calo = static_cast<TEveCalo2D*>(m_projMgr->ImportElements(calo3d, eventScene()));
0153 
0154   if (typeId() == FWViewType::kRhoPhiPF)
0155     m_calo->SetBarrelRadius(177);
0156   else
0157     m_calo->SetBarrelRadius(context().caloR1(false));
0158 
0159   m_calo->SetEndCapPos(context().caloZ1(false));
0160   m_calo->SetAutoRange(false);
0161   m_calo->SetScaleAbs(true);
0162 
0163   m_showPixelBarrel.changed_.connect(
0164       std::bind(&FWRPZViewGeometry::showPixelBarrel, m_geometryList, std::placeholders::_1));
0165   m_showPixelEndcap.changed_.connect(
0166       std::bind(&FWRPZViewGeometry::showPixelEndcap, m_geometryList, std::placeholders::_1));
0167   m_showTrackerBarrel.changed_.connect(
0168       std::bind(&FWRPZViewGeometry::showTrackerBarrel, m_geometryList, std::placeholders::_1));
0169   m_showTrackerEndcap.changed_.connect(
0170       std::bind(&FWRPZViewGeometry::showTrackerEndcap, m_geometryList, std::placeholders::_1));
0171   m_showRpcEndcap.changed_.connect(std::bind(&FWRPZViewGeometry::showRpcEndcap, m_geometryList, std::placeholders::_1));
0172   m_showGEM.changed_.connect(std::bind(&FWRPZViewGeometry::showGEM, m_geometryList, std::placeholders::_1));
0173   m_showME0.changed_.connect(std::bind(&FWRPZViewGeometry::showME0, m_geometryList, std::placeholders::_1));
0174 }
0175 
0176 void FWRPZView::eventBegin() {
0177   if (context().getBeamSpot()) {
0178     float c[3] = {0, 0, 0};
0179     context().commonPrefs()->getEventCenter(c);
0180 
0181     // projection center
0182     TEveVector center(c[0], c[1], c[2]);
0183     m_projMgr->GetProjection()->SetCenter(center);
0184 
0185     // camera move
0186     TGLCamera& cam = viewerGL()->CurrentCamera();
0187     cam.SetExternalCenter(true);
0188     if (typeId() != FWViewType::kRhoZ) {
0189       double r = center.Mag();
0190       cam.SetCenterVec(center.fZ, TMath::Sign(r, center.fY), 0);
0191     } else {
0192       cam.SetCenterVec(c[0], c[1], c[2]);
0193     }
0194   }
0195 }
0196 
0197 void FWRPZView::eventEnd() {
0198   float c[3];
0199   context().commonPrefs()->getEventCenter(c);
0200   m_projMgr->SetCenter(c[0], c[1], c[2]);
0201   FWEveView::eventEnd();
0202 }
0203 
0204 void FWRPZView::setupEventCenter() {
0205   float c[3];
0206   context().commonPrefs()->getEventCenter(c);
0207   m_projMgr->SetCenter(c[0], c[1], c[2]);
0208   FWEveView::setupEventCenter();
0209 }
0210 
0211 void FWRPZView::doShiftOriginToBeamSpot() {
0212 #ifdef TEVEPROJECTIONS_DISPLACE_ORIGIN_MODE
0213 
0214   TEveProjection* p = m_projMgr->GetProjection();
0215   if (p->GetDisplaceOrigin() != m_shiftOrigin.value()) {
0216     p->SetDisplaceOrigin(m_shiftOrigin.value());
0217     m_projMgr->ProjectChildren();
0218     gEve->Redraw3D();
0219   }
0220 #endif
0221 }
0222 
0223 void FWRPZView::shiftOrigin(TEveVector& center) {
0224 #ifdef TEVEPROJECTIONS_DISPLACE_ORIGIN_MODE
0225   // re-project with new center
0226   m_projMgr->GetProjection()->SetCenter(center);
0227   m_projMgr->ProjectChildren();
0228 
0229   // draw projected center
0230   float* pc = m_projMgr->GetProjection()->GetProjectedCenter();
0231   viewerGL()->CurrentCamera().SetExternalCenter(true);
0232   viewerGL()->CurrentCamera().SetCenterVec(pc[0], pc[1], pc[2]);
0233   viewerGL()->SetDrawCameraCenter(true);
0234 
0235   gEve->Redraw3D();
0236 #endif
0237 }
0238 
0239 void FWRPZView::resetOrigin() {
0240   // set center back to beam spot
0241 
0242 #ifdef TEVEPROJECTIONS_DISPLACE_ORIGIN_MODE
0243   FWBeamSpot& b = *(context().getBeamSpot());
0244   TEveVector center(b.x0(), b.y0(), b.z0());
0245   m_projMgr->GetProjection()->SetCenter(center);
0246 
0247   m_projMgr->ProjectChildren();
0248   gEve->Redraw3D();
0249 #endif
0250 }
0251 
0252 void FWRPZView::doFishEyeDistortion() {
0253   TEveProjection* p = m_projMgr->GetProjection();
0254   if (p->GetDistortion() != m_fishEyeDistortion.value() * s_distortFInv)
0255     p->SetDistortion(m_fishEyeDistortion.value() * s_distortF);
0256   if (p->GetFixR() != m_fishEyeR.value())
0257     p->SetFixR(m_fishEyeR.value());
0258 
0259   m_projMgr->ProjectChildren();
0260   gEve->Redraw3D();
0261 }
0262 
0263 void FWRPZView::doPreScaleDistortion() {
0264   if (typeId() == FWViewType::kRhoPhi || typeId() == FWViewType::kRhoPhiPF) {
0265     m_projMgr->GetProjection()->ChangePreScaleEntry(0, 1, m_caloDistortion.value());
0266     m_projMgr->GetProjection()->ChangePreScaleEntry(0, 2, m_muonDistortion.value());
0267   } else {
0268     m_projMgr->GetProjection()->ChangePreScaleEntry(0, 1, m_caloDistortion.value());
0269     m_projMgr->GetProjection()->ChangePreScaleEntry(0, 2, m_muonDistortion.value());
0270     m_projMgr->GetProjection()->ChangePreScaleEntry(1, 1, m_caloDistortion.value());
0271     m_projMgr->GetProjection()->ChangePreScaleEntry(1, 2, m_muonDistortion.value());
0272   }
0273   m_projMgr->UpdateName();
0274   m_projMgr->ProjectChildren();
0275   gEve->Redraw3D();
0276 }
0277 
0278 void FWRPZView::doCompression(bool flag) {
0279   m_projMgr->GetProjection()->SetUsePreScale(flag);
0280   m_projMgr->UpdateName();
0281   m_projMgr->ProjectChildren();
0282   gEve->Redraw3D();
0283 }
0284 
0285 void FWRPZView::importElements(TEveElement* iChildren, float iLayer, TEveElement* iProjectedParent) {
0286   float oldLayer = m_projMgr->GetCurrentDepth();
0287   m_projMgr->SetCurrentDepth(iLayer);
0288   //make sure current depth is reset even if an exception is thrown
0289   std::shared_ptr<TEveProjectionManager> sentry(
0290       m_projMgr, std::bind(&TEveProjectionManager::SetCurrentDepth, std::placeholders::_1, oldLayer));
0291   m_projMgr->ImportElements(iChildren, iProjectedParent);
0292 }
0293 
0294 void FWRPZView::addTo(FWConfiguration& iTo) const {
0295   FWEveView::addTo(iTo);
0296   TGLOrthoCamera* camera = dynamic_cast<TGLOrthoCamera*>(&(viewerGL()->CurrentCamera()));
0297   if (camera)
0298     addToOrthoCamera(camera, iTo);
0299 }
0300 
0301 void FWRPZView::setFrom(const FWConfiguration& iFrom) {
0302   FWEveView::setFrom(iFrom);
0303 
0304   TGLOrthoCamera* camera = dynamic_cast<TGLOrthoCamera*>(&(viewerGL()->CurrentCamera()));
0305   if (camera)
0306     setFromOrthoCamera(camera, iFrom);
0307 
0308   if (iFrom.version() < 7) {
0309     const FWConfiguration* value = iFrom.valueForKey("Show projection axes");
0310     if (value)
0311       m_showProjectionAxes.set(value->value() == "1");
0312   }
0313 }
0314 
0315 void FWRPZView::setEtaRng() {
0316   if (typeId() != FWViewType::kRhoZ) {
0317     // rng controllers only in RhoPhi
0318     double eta_range = context().caloMaxEta();
0319     if (!m_showHF->value())
0320       eta_range = 3.0;
0321     if (!m_showEndcaps->value())
0322       eta_range = context().caloTransEta();
0323     m_calo->SetEta(-eta_range, eta_range);
0324   }
0325 
0326   FWEveView::setupEnergyScale();
0327 }
0328 
0329 void FWRPZView::voteCaloMaxVal() {
0330   if (!m_calo->GetData()->Empty()) {
0331     m_calo->AssertCellIdCache();
0332     Float_t sumEt, sumE;
0333     TEveCaloData::CellData_t cellData;
0334     typedef std::vector<TEveCaloData::vCellId_t*> vBinCells_t;
0335     typedef std::vector<TEveCaloData::vCellId_t*>::iterator vBinCells_i;
0336 
0337     vBinCells_t cellLists = m_calo->GetBinLists();
0338     for (vBinCells_i it = cellLists.begin(); it != cellLists.end(); it++) {
0339       TEveCaloData::vCellId_t* binCells = *it;
0340       if (binCells) {
0341         sumEt = 0;
0342         sumE = 0;
0343         TEveCaloData::vCellId_i a = binCells->end();
0344 
0345         for (TEveCaloData::vCellId_i k = binCells->begin(); k != a; ++k) {
0346           m_calo->GetData()->GetCellData((*k), cellData);
0347           sumEt += cellData.Value(true);
0348           sumE += cellData.Value(false);
0349         }
0350         // printf("vote sum %f %f \n", sumEt , sumE);
0351         context().voteMaxEtAndEnergy(sumEt, sumE);
0352       }
0353     }
0354   }
0355 }
0356 
0357 void FWRPZView::showProjectionAxes() {
0358   m_axes->SetRnrState(m_showProjectionAxes.value());
0359   gEve->Redraw3D();
0360   viewerGL()->RequestDraw();
0361 }
0362 
0363 void FWRPZView::projectionAxesLabelSize() {
0364   m_axes->SetLabelSize(m_projectionAxesLabelSize.value());
0365   viewerGL()->RequestDraw();
0366 }
0367 
0368 void FWRPZView::populateController(ViewerParameterGUI& gui) const {
0369   FWEveView::populateController(gui);
0370 
0371   ViewerParameterGUI& det = gui.requestTab("Detector");
0372   ;
0373   det.addParam(&m_showPixelBarrel);
0374 
0375   if (typeId() == FWViewType::kRhoZ) {
0376     det.addParam(&m_showTrackerBarrel);
0377     det.addParam(&m_showPixelEndcap);
0378     det.addParam(&m_showRpcEndcap);
0379     bool showGEM = m_context->getGeom()->versionInfo().haveExtraDet("GEM");
0380     if (showGEM)
0381       det.addParam(&m_showGEM);
0382     bool showME0 = m_context->getGeom()->versionInfo().haveExtraDet("ME0");
0383     if (showME0)
0384       det.addParam(&m_showME0);
0385   }
0386 
0387 #ifdef TEVEPROJECTIONS_DISPLACE_ORIGIN_MODE
0388   gui.requestTab("Projection").addParam(&m_shiftOrigin);
0389 #endif
0390 
0391   gui.requestTab("Projection").addParam(&m_showProjectionAxes).addParam(&m_projectionAxesLabelSize).separator();
0392 
0393   TGCompositeFrame* f = gui.getTabContainer();
0394 
0395   f->AddFrame(new TGLabel(f, "FishEye:"));
0396   gui.addParam(&m_fishEyeDistortion).addParam(&m_fishEyeR).separator();
0397 
0398   f->AddFrame(new TGLabel(f, "PreScales:"));
0399 
0400   gui.requestTab("Projection").addParam(&m_compressMuon).addParam(&m_muonDistortion).addParam(&m_caloDistortion);
0401 
0402   if (typeId() == FWViewType::kRhoPhi || typeId() == FWViewType::kRhoPhiPF) {
0403     gui.requestTab("Calo").addParam(m_showHF).addParam(m_showEndcaps);
0404   }
0405 }