CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/Fireworks/Core/src/CmsShowCommon.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Core
00004 // Class  :     CmsShowCommon
00005 // 
00006 // Implementation:
00007 //     [Notes on implementation]
00008 //
00009 // Original Author:  Alja Mrak-Tadel
00010 //         Created:  Fri Sep 10 14:50:32 CEST 2010
00011 // $Id: CmsShowCommon.cc,v 1.16 2012/05/11 20:36:33 amraktad Exp $
00012 //
00013 
00014 // system include files
00015 #include <boost/bind.hpp>
00016 
00017 // user include files
00018 
00019 #include "TEveManager.h"
00020 #include "TEveTrackPropagator.h"
00021 #include "TGLViewer.h"
00022 #include "TEveViewer.h"
00023 
00024 #include "Fireworks/Core/interface/CmsShowCommon.h"
00025 #include "Fireworks/Core/interface/FWEveView.h"
00026 #include "Fireworks/Core/interface/Context.h"
00027 
00028 
00029 //
00030 // constructors and destructor
00031 //
00032 CmsShowCommon::CmsShowCommon(fireworks::Context* c):
00033    FWConfigurableParameterizable(2),
00034    m_context(c),  
00035    m_trackBreak(this, "     ", 2l, 0l, 2l), // do not want to render text at setter
00036    m_drawBreakPoints(this, "Show y=0 points as markers", false),
00037    m_backgroundColor(this, "backgroundColIdx", 1l, 0l, 1000l),
00038    m_gamma(this, "Brightness", 0l, -15l, 15l),
00039    m_geomTransparency2D(this, "Transparency 2D", long(colorManager()->geomTransparency(true)), 0l, 100l),
00040    m_geomTransparency3D(this, "Transparency 3D", long(colorManager()->geomTransparency(false)), 0l, 100l),
00041    m_energyScale(new FWViewEnergyScale("global", 2))
00042 {
00043    // projections 
00044    m_trackBreak.addEntry(0, "Jump to proper hemisphere");
00045    m_trackBreak.addEntry(1, "Stay on first point side");
00046    m_trackBreak.addEntry(2, "Stay on last point side");
00047 
00048    // colors
00049    char name[32];
00050    for (int i = 0; i < kFWGeomColorSize; ++i)
00051    {
00052       snprintf(name, 31, "GeometryColor %d ", i);
00053       m_geomColors[i] = new FWLongParameter(this, name   , long(colorManager()->geomColor(FWGeomColorIndex(i))), 1000l, 1100l);
00054    }  
00055 
00056    m_trackBreak.changed_.connect(boost::bind(&CmsShowCommon::setTrackBreakMode, this));
00057    m_drawBreakPoints.changed_.connect(boost::bind(&CmsShowCommon::setDrawBreakMarkers, this));
00058    m_gamma.changed_.connect(boost::bind(&CmsShowCommon::setGamma, this));
00059 }
00060 
00061 CmsShowCommon::~CmsShowCommon()
00062 {
00063 }
00064 
00065 
00066 const FWColorManager* CmsShowCommon::colorManager() const
00067 {
00068    return m_context->colorManager();
00069 }
00070 //
00071 // member functions
00072 //
00073 
00074 
00075 void
00076 CmsShowCommon::setTrackBreakMode()
00077 { 
00078    if (m_context->getTrackPropagator()->GetProjTrackBreaking() != m_trackBreak.value())
00079    {
00080       m_context->getTrackPropagator()->SetProjTrackBreaking(m_trackBreak.value());
00081       m_context->getTrackerTrackPropagator()->SetProjTrackBreaking(m_trackBreak.value());
00082       m_context->getMuonTrackPropagator()->SetProjTrackBreaking(m_trackBreak.value());
00083       gEve->Redraw3D();
00084    }
00085 }
00086 
00087 
00088 void
00089 CmsShowCommon::setDrawBreakMarkers()
00090 {
00091    if (m_context->getTrackPropagator()->GetRnrPTBMarkers() != m_drawBreakPoints.value())
00092    {
00093       m_context->getTrackPropagator()->SetRnrPTBMarkers(m_drawBreakPoints.value());
00094       m_context->getTrackerTrackPropagator()->SetRnrPTBMarkers(m_drawBreakPoints.value());
00095       m_context->getMuonTrackPropagator()->SetRnrPTBMarkers(m_drawBreakPoints.value());
00096       gEve->Redraw3D();
00097    }
00098 }
00099 
00100 void
00101 CmsShowCommon::setGamma()
00102 {
00103    m_context->colorManager()->setBrightness(m_gamma.value());
00104 }
00105 
00106 void
00107 CmsShowCommon::switchBackground()
00108 {
00109    m_context->colorManager()->switchBackground();
00110    m_backgroundColor.set(colorManager()->background());
00111 }
00112 
00113 void
00114 CmsShowCommon::setGeomColor(FWGeomColorIndex cidx, Color_t iColor)
00115 {
00116    m_geomColors[cidx]->set(iColor);
00117    m_context->colorManager()->setGeomColor(cidx, iColor);
00118 }
00119 
00120 void
00121 CmsShowCommon::setGeomTransparency(int iTransp, bool projected)
00122 {
00123    if (projected)
00124       m_geomTransparency2D.set(iTransp);
00125    else
00126       m_geomTransparency3D.set(iTransp);
00127 
00128    m_context->colorManager()->setGeomTransparency(iTransp, projected);
00129 }
00130 
00131 //____________________________________________________________________________
00132 
00133 namespace 
00134 {
00135   void addGLColorToConfig(const char* cname, TGLColor& c, FWConfiguration& oTo)
00136   {
00137     FWConfiguration pc;
00138 
00139     std::ostringstream sRed; 
00140     sRed << (int)c.GetRed();
00141     pc.addKeyValue("Red", sRed.str());
00142 
00143     std::ostringstream sGreen; 
00144     sGreen << (int)c.GetGreen();
00145     pc.addKeyValue("Green", sGreen.str());
00146 
00147     std::ostringstream sBlue; 
00148     sBlue << (int)c.GetBlue();
00149     pc.addKeyValue("Blue", sBlue.str());
00150 
00151     oTo.addKeyValue(cname, pc, true);
00152   }
00153 
00154   void setGLColorFromConfig(TGLColor& d, const FWConfiguration* iFrom )
00155   {
00156     if (!iFrom) return;
00157     d.Arr()[0] = atoi(iFrom->valueForKey("Red")->value().c_str());
00158     d.Arr()[1] = atoi(iFrom->valueForKey("Green")->value().c_str());
00159     d.Arr()[2] = atoi(iFrom->valueForKey("Blue")->value().c_str());
00160     //    printf("22222 colors %d %d %d \n",  d.Arr()[0],  d.Arr()[1], d.Arr()[2]);
00161  }
00162 }
00163 
00164 void
00165 CmsShowCommon::addTo(FWConfiguration& oTo) const
00166 {
00167   m_backgroundColor.set(int(colorManager()->background()));
00168 
00169   FWConfigurableParameterizable::addTo(oTo);
00170   m_energyScale->addTo(oTo);
00171 
00172   if (gEve)
00173   {
00174     TGLViewer* v = gEve->GetDefaultGLViewer();
00175     addGLColorToConfig("SelectionColorLight", v->RefLightColorSet().Selection(1), oTo);
00176     addGLColorToConfig("HighlightColorLight", v->RefLightColorSet().Selection(3), oTo);
00177     addGLColorToConfig("SelectionColorDark",  v->RefDarkColorSet().Selection(1), oTo);
00178     addGLColorToConfig("HighlightColorDark",  v->RefDarkColorSet().Selection(3), oTo);
00179   }
00180 }
00181 
00182 void
00183 CmsShowCommon::setFrom(const FWConfiguration& iFrom)
00184 {  
00185    for(const_iterator it =begin(), itEnd = end();
00186        it != itEnd;
00187        ++it) {
00188       (*it)->setFrom(iFrom);      
00189    }  
00190  
00191    // handle old and new energy scale configuration if existing
00192    if (iFrom.valueForKey("ScaleMode"))
00193    {
00194       long mode  = atol(iFrom.valueForKey("ScaleMode")->value().c_str());      
00195 
00196       float convert;
00197       if (iFrom.valueForKey("EnergyToLength [GeV/m]"))
00198          convert = atof(iFrom.valueForKey("EnergyToLength [GeV/m]")->value().c_str());
00199       else
00200          convert = atof(iFrom.valueForKey("ValueToHeight [GeV/m]")->value().c_str());
00201 
00202      float maxH;
00203      if (iFrom.valueForKey("MaximumLength [m]"))
00204         maxH = atof(iFrom.valueForKey("MaximumLength [m]")->value().c_str());
00205      else
00206         maxH = atof(iFrom.valueForKey("MaxTowerH [m]")->value().c_str());
00207          
00208      int et = atoi(iFrom.valueForKey("PlotEt")->value().c_str());
00209      m_energyScale->SetFromCmsShowCommonConfig(mode, convert, maxH, et);
00210   }
00211       
00212   // background
00213   FWColorManager* cm =  m_context->colorManager();
00214   cm->setBackgroundAndBrightness( FWColorManager::BackgroundColorIndex(m_backgroundColor.value()), m_gamma.value());
00215    
00216   // geom colors
00217   cm->setGeomTransparency( m_geomTransparency2D.value(), true);
00218   cm->setGeomTransparency( m_geomTransparency3D.value(), false);
00219 
00220   for (int i = 0; i < kFWGeomColorSize; ++i)
00221      cm->setGeomColor(FWGeomColorIndex(i), m_geomColors[i]->value());
00222 
00223   if (gEve)
00224   {
00225      TGLViewer* v = gEve->GetDefaultGLViewer();
00226      setGLColorFromConfig(v->RefLightColorSet().Selection(1),  iFrom.valueForKey("SelectionColorLight"));
00227      setGLColorFromConfig(v->RefLightColorSet().Selection(3),  iFrom.valueForKey("HighlightColorLight"));
00228      setGLColorFromConfig(v->RefDarkColorSet().Selection(1),  iFrom.valueForKey("SelectionColorDark"));
00229      setGLColorFromConfig(v->RefDarkColorSet().Selection(3),  iFrom.valueForKey("HighlightColorDark"));
00230   }
00231 }