Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // Package:     Core
0004 // Class  :     CmsShowCommon
0005 //
0006 // Implementation:
0007 //     [Notes on implementation]
0008 //
0009 // Original Author:  Alja Mrak-Tadel
0010 //         Created:  Fri Sep 10 14:50:32 CEST 2010
0011 //
0012 
0013 // system include files
0014 #include <functional>
0015 #include <iostream>
0016 // user include files
0017 
0018 #include "TEveManager.h"
0019 #include "TEveTrackPropagator.h"
0020 #include "TGLViewer.h"
0021 #include "TEveViewer.h"
0022 #include "TGComboBox.h"
0023 #include "TGClient.h"
0024 #include "TGTextEntry.h"
0025 
0026 #include "Fireworks/Core/interface/CmsShowCommon.h"
0027 #include "Fireworks/Core/interface/CmsShowCommonPopup.h"
0028 #include "Fireworks/Core/interface/FWEveView.h"
0029 #include "Fireworks/Core/interface/Context.h"
0030 #include "Fireworks/Core/interface/fwLog.h"
0031 
0032 #include "Fireworks/Core/interface/FWDisplayProperties.h"
0033 #include "Fireworks/Core/interface/FWEventItemsManager.h"
0034 #include "Fireworks/Core/interface/FWEventItem.h"
0035 #include "Fireworks/Core/interface/FWViewEnergyScale.h"
0036 
0037 //
0038 // constructors and destructor
0039 //
0040 CmsShowCommon::CmsShowCommon(fireworks::Context* c)
0041     : FWConfigurableParameterizable(2),
0042       m_view(nullptr),
0043       m_context(c),
0044       m_trackBreak(this, "     ", 2l, 0l, 2l),  // do not want to render text at setter
0045       m_drawBreakPoints(this, "Show y=0 points as markers", false),
0046       m_backgroundColor(this, "backgroundColIdx", 1l, 0l, 1000l),
0047       m_gamma(this, "Brightness", 0l, -15l, 15l),
0048       m_palette(this, "Palette", 1l, 0l, 2l),
0049       m_geomTransparency2D(this, "Transparency 2D", long(colorManager()->geomTransparency(true)), 0l, 100l),
0050       m_geomTransparency3D(this, "Transparency 3D", long(colorManager()->geomTransparency(false)), 0l, 100l),
0051       m_useBeamSpot(true) {
0052   m_viewContext.setEnergyScale(new FWViewEnergyScale("global", 2));
0053   // projections
0054   m_trackBreak.addEntry(0, "Jump to proper hemisphere");
0055   m_trackBreak.addEntry(1, "Stay on first point side");
0056   m_trackBreak.addEntry(2, "Stay on last point side");
0057 
0058   m_palette.addEntry(FWColorManager::kClassic, "Classic ");
0059   m_palette.addEntry(FWColorManager::kPurple, "Purple ");
0060   m_palette.addEntry(FWColorManager::kFall, "Fall ");
0061   m_palette.addEntry(FWColorManager::kSpring, "Spring ");
0062   m_palette.addEntry(FWColorManager::kArctic, "Arctic ");
0063 
0064   // colors
0065   char name[32];
0066   for (int i = 0; i < kFWGeomColorSize; ++i) {
0067     snprintf(name, 31, "GeometryColor %d ", i);
0068     m_geomColors[i] =
0069         new FWLongParameter(this, name, long(colorManager()->geomColor(FWGeomColorIndex(i))), 1000l, 1100l);
0070   }
0071 
0072   m_trackBreak.changed_.connect(std::bind(&CmsShowCommon::setTrackBreakMode, this));
0073   m_palette.set(m_context->colorManager()->getPalette());
0074   m_drawBreakPoints.changed_.connect(std::bind(&CmsShowCommon::setDrawBreakMarkers, this));
0075   m_gamma.changed_.connect(std::bind(&CmsShowCommon::setGamma, this));
0076 
0077   m_lightColorSet.StdLightBackground();
0078   m_darkColorSet.StdDarkBackground();
0079 }
0080 
0081 CmsShowCommon::~CmsShowCommon() {}
0082 
0083 const FWColorManager* CmsShowCommon::colorManager() const { return m_context->colorManager(); }
0084 //
0085 // member functions
0086 //
0087 
0088 void CmsShowCommon::setTrackBreakMode() {
0089   if (m_context->getTrackPropagator()->GetProjTrackBreaking() != m_trackBreak.value()) {
0090     m_context->getTrackPropagator()->SetProjTrackBreaking(m_trackBreak.value());
0091     m_context->getTrackerTrackPropagator()->SetProjTrackBreaking(m_trackBreak.value());
0092     m_context->getMuonTrackPropagator()->SetProjTrackBreaking(m_trackBreak.value());
0093     gEve->Redraw3D();
0094   }
0095 }
0096 
0097 void CmsShowCommon::setDrawBreakMarkers() {
0098   if (m_context->getTrackPropagator()->GetRnrPTBMarkers() != m_drawBreakPoints.value()) {
0099     m_context->getTrackPropagator()->SetRnrPTBMarkers(m_drawBreakPoints.value());
0100     m_context->getTrackerTrackPropagator()->SetRnrPTBMarkers(m_drawBreakPoints.value());
0101     m_context->getMuonTrackPropagator()->SetRnrPTBMarkers(m_drawBreakPoints.value());
0102     gEve->Redraw3D();
0103   }
0104 }
0105 
0106 void CmsShowCommon::setGamma() { m_context->colorManager()->setBrightness(m_gamma.value()); }
0107 
0108 void CmsShowCommon::switchBackground() {
0109   m_context->colorManager()->switchBackground();
0110   m_backgroundColor.set(colorManager()->background());
0111 }
0112 
0113 void CmsShowCommon::permuteColors() {
0114   // printf("Reverting order of existing colors ...\n");
0115 
0116   std::vector<Color_t> colv;
0117   colv.reserve(64);
0118 
0119   for (FWEventItemsManager::const_iterator i = m_context->eventItemsManager()->begin();
0120        i != m_context->eventItemsManager()->end();
0121        ++i) {
0122     colv.push_back((*i)->defaultDisplayProperties().color());
0123   }
0124 
0125   int vi = colv.size() - 1;
0126   for (FWEventItemsManager::const_iterator i = m_context->eventItemsManager()->begin();
0127        i != m_context->eventItemsManager()->end();
0128        ++i, --vi) {
0129     FWDisplayProperties prop = (*i)->defaultDisplayProperties();
0130     prop.setColor(colv[vi]);
0131     (*i)->setDefaultDisplayProperties(prop);
0132 
0133     (*i)->defaultDisplayPropertiesChanged_(*i);
0134   }
0135 }
0136 
0137 void CmsShowCommon::randomizeColors() {
0138   //   printf("Doing random_shuffle on existing colors ...\n");
0139 
0140   int vi = 0;
0141   for (FWEventItemsManager::const_iterator i = m_context->eventItemsManager()->begin();
0142        i != m_context->eventItemsManager()->end();
0143        ++i, ++vi) {
0144     FWDisplayProperties prop = (*i)->defaultDisplayProperties();
0145 
0146     int col = rand() % 17;  // randomize in first row of palette
0147     prop.setColor(col);
0148     (*i)->setDefaultDisplayProperties(prop);
0149 
0150     (*i)->defaultDisplayPropertiesChanged_(*i);
0151   }
0152 }
0153 
0154 void CmsShowCommon::setGeomColor(FWGeomColorIndex cidx, Color_t iColor) {
0155   m_geomColors[cidx]->set(iColor);
0156   m_context->colorManager()->setGeomColor(cidx, iColor);
0157 }
0158 
0159 void CmsShowCommon::setGeomTransparency(int iTransp, bool projected) {
0160   if (projected)
0161     m_geomTransparency2D.set(iTransp);
0162   else
0163     m_geomTransparency3D.set(iTransp);
0164 
0165   m_context->colorManager()->setGeomTransparency(iTransp, projected);
0166 }
0167 
0168 //____________________________________________________________________________
0169 
0170 namespace {
0171   void addGLColorToConfig(const char* cname, const TGLColor& c, FWConfiguration& oTo) {
0172     FWConfiguration pc;
0173 
0174     std::ostringstream sRed;
0175     sRed << (int)c.GetRed();
0176     pc.addKeyValue("Red", sRed.str());
0177 
0178     std::ostringstream sGreen;
0179     sGreen << (int)c.GetGreen();
0180     pc.addKeyValue("Green", sGreen.str());
0181 
0182     std::ostringstream sBlue;
0183     sBlue << (int)c.GetBlue();
0184     pc.addKeyValue("Blue", sBlue.str());
0185 
0186     oTo.addKeyValue(cname, pc, true);
0187   }
0188 
0189   void setGLColorFromConfig(TGLColor& d, const FWConfiguration* iFrom) {
0190     if (!iFrom)
0191       return;
0192     d.Arr()[0] = atoi(iFrom->valueForKey("Red")->value().c_str());
0193     d.Arr()[1] = atoi(iFrom->valueForKey("Green")->value().c_str());
0194     d.Arr()[2] = atoi(iFrom->valueForKey("Blue")->value().c_str());
0195     //    printf("22222 colors %d %d %d \n",  d.Arr()[0],  d.Arr()[1], d.Arr()[2]);
0196   }
0197 }  // namespace
0198 
0199 void CmsShowCommon::addTo(FWConfiguration& oTo) const {
0200   m_backgroundColor.set(int(colorManager()->background()));
0201 
0202   FWConfigurableParameterizable::addTo(oTo);
0203   m_viewContext.getEnergyScale()->addTo(oTo);
0204 
0205   if (gEve) {
0206     addGLColorToConfig("SelectionColorLight", m_lightColorSet.Selection(1), oTo);
0207     addGLColorToConfig("HighlightColorLight", m_lightColorSet.Selection(3), oTo);
0208     addGLColorToConfig("SelectionColorDark", m_darkColorSet.Selection(1), oTo);
0209     addGLColorToConfig("HighlightColorDark", m_darkColorSet.Selection(3), oTo);
0210   }
0211 }
0212 
0213 void CmsShowCommon::setFrom(const FWConfiguration& iFrom) {
0214   for (const_iterator it = begin(), itEnd = end(); it != itEnd; ++it) {
0215     (*it)->setFrom(iFrom);
0216   }
0217 
0218   if (iFrom.valueForKey("Palette"))
0219     setPalette();
0220 
0221   // handle old and new energy scale configuration if existing
0222   if (iFrom.valueForKey("ScaleMode")) {
0223     long mode = atol(iFrom.valueForKey("ScaleMode")->value().c_str());
0224 
0225     float convert;
0226     if (iFrom.valueForKey("EnergyToLength [GeV/m]"))
0227       convert = atof(iFrom.valueForKey("EnergyToLength [GeV/m]")->value().c_str());
0228     else
0229       convert = atof(iFrom.valueForKey("ValueToHeight [GeV/m]")->value().c_str());
0230 
0231     float maxH;
0232     if (iFrom.valueForKey("MaximumLength [m]"))
0233       maxH = atof(iFrom.valueForKey("MaximumLength [m]")->value().c_str());
0234     else
0235       maxH = atof(iFrom.valueForKey("MaxTowerH [m]")->value().c_str());
0236 
0237     int et = atoi(iFrom.valueForKey("PlotEt")->value().c_str());
0238     m_viewContext.getEnergyScale()->SetFromCmsShowCommonConfig(mode, convert, maxH, et);
0239   }
0240 
0241   // background
0242   FWColorManager* cm = m_context->colorManager();
0243   cm->setBackgroundAndBrightness(FWColorManager::BackgroundColorIndex(m_backgroundColor.value()), m_gamma.value());
0244 
0245   // geom colors
0246   cm->setGeomTransparency(m_geomTransparency2D.value(), true);
0247   cm->setGeomTransparency(m_geomTransparency3D.value(), false);
0248 
0249   for (int i = 0; i < kFWGeomColorSize; ++i)
0250     cm->setGeomColor(FWGeomColorIndex(i), m_geomColors[i]->value());
0251 
0252   if (gEve) {
0253     setGLColorFromConfig(m_lightColorSet.Selection(1), iFrom.valueForKey("SelectionColorLight"));
0254     setGLColorFromConfig(m_lightColorSet.Selection(3), iFrom.valueForKey("HighlightColorLight"));
0255     setGLColorFromConfig(m_darkColorSet.Selection(1), iFrom.valueForKey("SelectionColorDark"));
0256     setGLColorFromConfig(m_darkColorSet.Selection(3), iFrom.valueForKey("HighlightColorDark"));
0257   }
0258 }
0259 
0260 void CmsShowCommon::setPalette() {
0261   FWColorManager* cm = m_context->colorManager();
0262   cm->setPalette(m_palette.value());
0263 
0264   for (int i = 0; i < kFWGeomColorSize; ++i) {
0265     FWColorManager* cm = m_context->colorManager();
0266     m_geomColors[i]->set(cm->geomColor(FWGeomColorIndex(i)));
0267     //      m_colorSelectWidget[i]->SetColorByIndex(cm->geomColor(FWGeomColorIndex(i)), kFALSE);
0268   }
0269 
0270   m_context->colorManager()->propagatePaletteChanges();
0271   for (FWEventItemsManager::const_iterator i = m_context->eventItemsManager()->begin();
0272        i != m_context->eventItemsManager()->end();
0273        ++i) {
0274     (*i)->resetColor();
0275   }
0276 }
0277 
0278 void CmsShowCommon::loopPalettes() {
0279   int val = m_palette.value();
0280   val++;
0281 
0282   if (val >= FWColorManager::kPaletteLast)
0283     val = FWColorManager::kPaletteFirst;
0284 
0285   if (m_view) {
0286     TGComboBox* combo = m_view->getCombo();
0287     combo->Select(val, true);
0288   } else {
0289     m_palette.set(val);
0290     setPalette();
0291   }
0292 }
0293 
0294 void CmsShowCommon::getEventCenter(float* iC) const {
0295   if (m_useBeamSpot) {
0296     FWBeamSpot* beamSpot = fireworks::Context::getInstance()->getBeamSpot();
0297     iC[0] = float(beamSpot->x0());
0298     iC[1] = float(beamSpot->y0());
0299     iC[2] = float(beamSpot->z0());
0300   } else {
0301     iC[0] = m_externalEventCenter.fX;
0302     iC[1] = m_externalEventCenter.fY;
0303     iC[2] = m_externalEventCenter.fZ;
0304   }
0305 }
0306 
0307 void CmsShowCommon::setEventCenter(float x, float y, float z) {
0308   m_useBeamSpot = false;
0309   m_externalEventCenter.Set(x, y, z);
0310   eventCenterChanged_.emit(this);
0311 }
0312 
0313 void CmsShowCommon::resetEventCenter() {
0314   if (!m_useBeamSpot) {
0315     fwLog(fwlog::kInfo) << "CmsShowCommon re-set event center to BeamSpot\n ";
0316     m_useBeamSpot = true;
0317     FWBeamSpot* beamSpot = fireworks::Context::getInstance()->getBeamSpot();
0318     setEventCenter(beamSpot->x0(), beamSpot->y0(), beamSpot->z0());
0319   }
0320 }