CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CmsShowCommon.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : CmsShowCommon
5 //
6 // Implementation:
7 // [Notes on implementation]
8 //
9 // Original Author: Alja Mrak-Tadel
10 // Created: Fri Sep 10 14:50:32 CEST 2010
11 //
12 
13 // system include files
14 #include <boost/bind.hpp>
15 
16 // user include files
17 
18 #include "TEveManager.h"
19 #include "TEveTrackPropagator.h"
20 #include "TGLViewer.h"
21 #include "TEveViewer.h"
22 
26 
27 
28 //
29 // constructors and destructor
30 //
33  m_context(c),
34  m_trackBreak(this, " ", 2l, 0l, 2l), // do not want to render text at setter
35  m_drawBreakPoints(this, "Show y=0 points as markers", false),
36  m_backgroundColor(this, "backgroundColIdx", 1l, 0l, 1000l),
37  m_gamma(this, "Brightness", 0l, -15l, 15l),
38  m_geomTransparency2D(this, "Transparency 2D", long(colorManager()->geomTransparency(true)), 0l, 100l),
39  m_geomTransparency3D(this, "Transparency 3D", long(colorManager()->geomTransparency(false)), 0l, 100l),
40  m_energyScale(new FWViewEnergyScale("global", 2))
41 {
42  // projections
43  m_trackBreak.addEntry(0, "Jump to proper hemisphere");
44  m_trackBreak.addEntry(1, "Stay on first point side");
45  m_trackBreak.addEntry(2, "Stay on last point side");
46 
47  // colors
48  char name[32];
49  for (int i = 0; i < kFWGeomColorSize; ++i)
50  {
51  snprintf(name, 31, "GeometryColor %d ", i);
52  m_geomColors[i] = new FWLongParameter(this, name , long(colorManager()->geomColor(FWGeomColorIndex(i))), 1000l, 1100l);
53  }
54 
55  m_trackBreak.changed_.connect(boost::bind(&CmsShowCommon::setTrackBreakMode, this));
57  m_gamma.changed_.connect(boost::bind(&CmsShowCommon::setGamma, this));
58 
59  m_lightColorSet.StdLightBackground();
60  m_darkColorSet .StdDarkBackground();
61 }
62 
64 {
65 }
66 
67 
69 {
70  return m_context->colorManager();
71 }
72 //
73 // member functions
74 //
75 
76 
77 void
79 {
80  if (m_context->getTrackPropagator()->GetProjTrackBreaking() != m_trackBreak.value())
81  {
82  m_context->getTrackPropagator()->SetProjTrackBreaking(m_trackBreak.value());
83  m_context->getTrackerTrackPropagator()->SetProjTrackBreaking(m_trackBreak.value());
84  m_context->getMuonTrackPropagator()->SetProjTrackBreaking(m_trackBreak.value());
85  gEve->Redraw3D();
86  }
87 }
88 
89 
90 void
92 {
93  if (m_context->getTrackPropagator()->GetRnrPTBMarkers() != m_drawBreakPoints.value())
94  {
95  m_context->getTrackPropagator()->SetRnrPTBMarkers(m_drawBreakPoints.value());
98  gEve->Redraw3D();
99  }
100 }
101 
102 void
104 {
106 }
107 
108 void
110 {
112  m_backgroundColor.set(colorManager()->background());
113 }
114 
115 void
117 {
118  m_geomColors[cidx]->set(iColor);
119  m_context->colorManager()->setGeomColor(cidx, iColor);
120 }
121 
122 void
123 CmsShowCommon::setGeomTransparency(int iTransp, bool projected)
124 {
125  if (projected)
126  m_geomTransparency2D.set(iTransp);
127  else
128  m_geomTransparency3D.set(iTransp);
129 
130  m_context->colorManager()->setGeomTransparency(iTransp, projected);
131 }
132 
133 //____________________________________________________________________________
134 
135 namespace
136 {
137  void addGLColorToConfig(const char* cname, const TGLColor& c, FWConfiguration& oTo)
138  {
139  FWConfiguration pc;
140 
141  std::ostringstream sRed;
142  sRed << (int)c.GetRed();
143  pc.addKeyValue("Red", sRed.str());
144 
145  std::ostringstream sGreen;
146  sGreen << (int)c.GetGreen();
147  pc.addKeyValue("Green", sGreen.str());
148 
149  std::ostringstream sBlue;
150  sBlue << (int)c.GetBlue();
151  pc.addKeyValue("Blue", sBlue.str());
152 
153  oTo.addKeyValue(cname, pc, true);
154  }
155 
156  void setGLColorFromConfig(TGLColor& d, const FWConfiguration* iFrom )
157  {
158  if (!iFrom) return;
159  d.Arr()[0] = atoi(iFrom->valueForKey("Red")->value().c_str());
160  d.Arr()[1] = atoi(iFrom->valueForKey("Green")->value().c_str());
161  d.Arr()[2] = atoi(iFrom->valueForKey("Blue")->value().c_str());
162  // printf("22222 colors %d %d %d \n", d.Arr()[0], d.Arr()[1], d.Arr()[2]);
163  }
164 }
165 
166 void
168 {
169  m_backgroundColor.set(int(colorManager()->background()));
170 
172  m_energyScale->addTo(oTo);
173 
174  if (gEve)
175  {
176  addGLColorToConfig("SelectionColorLight", m_lightColorSet.Selection(1), oTo);
177  addGLColorToConfig("HighlightColorLight", m_lightColorSet.Selection(3), oTo);
178  addGLColorToConfig("SelectionColorDark", m_darkColorSet .Selection(1), oTo);
179  addGLColorToConfig("HighlightColorDark", m_darkColorSet .Selection(3), oTo);
180  }
181 }
182 
183 void
185 {
186  for(const_iterator it =begin(), itEnd = end();
187  it != itEnd;
188  ++it) {
189  (*it)->setFrom(iFrom);
190  }
191 
192  // handle old and new energy scale configuration if existing
193  if (iFrom.valueForKey("ScaleMode"))
194  {
195  long mode = atol(iFrom.valueForKey("ScaleMode")->value().c_str());
196 
197  float convert;
198  if (iFrom.valueForKey("EnergyToLength [GeV/m]"))
199  convert = atof(iFrom.valueForKey("EnergyToLength [GeV/m]")->value().c_str());
200  else
201  convert = atof(iFrom.valueForKey("ValueToHeight [GeV/m]")->value().c_str());
202 
203  float maxH;
204  if (iFrom.valueForKey("MaximumLength [m]"))
205  maxH = atof(iFrom.valueForKey("MaximumLength [m]")->value().c_str());
206  else
207  maxH = atof(iFrom.valueForKey("MaxTowerH [m]")->value().c_str());
208 
209  int et = atoi(iFrom.valueForKey("PlotEt")->value().c_str());
210  m_energyScale->SetFromCmsShowCommonConfig(mode, convert, maxH, et);
211  }
212 
213  // background
216 
217  // geom colors
220 
221  for (int i = 0; i < kFWGeomColorSize; ++i)
223 
224  if (gEve)
225  {
226  setGLColorFromConfig(m_lightColorSet.Selection(1), iFrom.valueForKey("SelectionColorLight"));
227  setGLColorFromConfig(m_lightColorSet.Selection(3), iFrom.valueForKey("HighlightColorLight"));
228  setGLColorFromConfig(m_darkColorSet .Selection(1), iFrom.valueForKey("SelectionColorDark"));
229  setGLColorFromConfig(m_darkColorSet .Selection(3), iFrom.valueForKey("HighlightColorDark"));
230  }
231 }
int i
Definition: DBlmapReader.cc:9
TGLColorSet m_lightColorSet
Definition: CmsShowCommon.h:96
std::vector< FWParameterBase * >::const_iterator const_iterator
const_iterator begin() const
FWBoolParameter m_drawBreakPoints
Definition: CmsShowCommon.h:85
TEveTrackPropagator * getTrackerTrackPropagator() const
Definition: Context.h:74
FWLongParameter m_backgroundColor
Definition: CmsShowCommon.h:88
FWColorManager * colorManager() const
Definition: Context.h:65
FWGeomColorIndex
void setTrackBreakMode()
FWLongParameter * m_geomColors[kFWGeomColorSize]
Definition: CmsShowCommon.h:94
TEveTrackPropagator * getTrackPropagator() const
Definition: Context.h:73
sigc::signal< void, T > changed_
const FWColorManager * colorManager() const
FWLongParameter m_gamma
Definition: CmsShowCommon.h:89
void setGeomColor(FWGeomColorIndex, Color_t)
void setGeomTransparency(int val, bool projected)
void setGeomTransparency(Color_t idx, bool projectedType)
virtual ~CmsShowCommon()
const_iterator end() const
bool addEntry(Long_t id, const std::string &txt)
void setBrightness(int)
void setGeomColor(FWGeomColorIndex, Color_t)
fireworks::Context * m_context
Definition: CmsShowCommon.h:82
void switchBackground()
FWLongParameter m_geomTransparency3D
Definition: CmsShowCommon.h:93
void setDrawBreakMarkers()
TEveTrackPropagator * getMuonTrackPropagator() const
Definition: Context.h:75
FWConfiguration & addKeyValue(const std::string &, const FWConfiguration &)
const std::string & value(unsigned int iIndex=0) const
FWLongParameter m_geomTransparency2D
Definition: CmsShowCommon.h:92
std::auto_ptr< FWViewEnergyScale > m_energyScale
Definition: CmsShowCommon.h:99
virtual void addTo(FWConfiguration &) const
void setBackgroundAndBrightness(BackgroundColorIndex, int)
TGLColorSet m_darkColorSet
Definition: CmsShowCommon.h:97
FWParameters::Long FWLongParameter
Definition: FWParameters.h:35
virtual void setFrom(const FWConfiguration &)
const FWConfiguration * valueForKey(const std::string &iKey) const
FWEnumParameter m_trackBreak
Definition: CmsShowCommon.h:84
volatile std::atomic< bool > shutdown_flag false
CmsShowCommon(fireworks::Context *)
virtual void addTo(FWConfiguration &) const