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 
61 {
62 }
63 
64 
66 {
67  return m_context->colorManager();
68 }
69 //
70 // member functions
71 //
72 
73 
74 void
76 {
77  if (m_context->getTrackPropagator()->GetProjTrackBreaking() != m_trackBreak.value())
78  {
79  m_context->getTrackPropagator()->SetProjTrackBreaking(m_trackBreak.value());
80  m_context->getTrackerTrackPropagator()->SetProjTrackBreaking(m_trackBreak.value());
81  m_context->getMuonTrackPropagator()->SetProjTrackBreaking(m_trackBreak.value());
82  gEve->Redraw3D();
83  }
84 }
85 
86 
87 void
89 {
90  if (m_context->getTrackPropagator()->GetRnrPTBMarkers() != m_drawBreakPoints.value())
91  {
92  m_context->getTrackPropagator()->SetRnrPTBMarkers(m_drawBreakPoints.value());
95  gEve->Redraw3D();
96  }
97 }
98 
99 void
101 {
103 }
104 
105 void
107 {
109  m_backgroundColor.set(colorManager()->background());
110 }
111 
112 void
114 {
115  m_geomColors[cidx]->set(iColor);
116  m_context->colorManager()->setGeomColor(cidx, iColor);
117 }
118 
119 void
120 CmsShowCommon::setGeomTransparency(int iTransp, bool projected)
121 {
122  if (projected)
123  m_geomTransparency2D.set(iTransp);
124  else
125  m_geomTransparency3D.set(iTransp);
126 
127  m_context->colorManager()->setGeomTransparency(iTransp, projected);
128 }
129 
130 //____________________________________________________________________________
131 
132 namespace
133 {
134  void addGLColorToConfig(const char* cname, TGLColor& c, FWConfiguration& oTo)
135  {
136  FWConfiguration pc;
137 
138  std::ostringstream sRed;
139  sRed << (int)c.GetRed();
140  pc.addKeyValue("Red", sRed.str());
141 
142  std::ostringstream sGreen;
143  sGreen << (int)c.GetGreen();
144  pc.addKeyValue("Green", sGreen.str());
145 
146  std::ostringstream sBlue;
147  sBlue << (int)c.GetBlue();
148  pc.addKeyValue("Blue", sBlue.str());
149 
150  oTo.addKeyValue(cname, pc, true);
151  }
152 
153  void setGLColorFromConfig(TGLColor& d, const FWConfiguration* iFrom )
154  {
155  if (!iFrom) return;
156  d.Arr()[0] = atoi(iFrom->valueForKey("Red")->value().c_str());
157  d.Arr()[1] = atoi(iFrom->valueForKey("Green")->value().c_str());
158  d.Arr()[2] = atoi(iFrom->valueForKey("Blue")->value().c_str());
159  // printf("22222 colors %d %d %d \n", d.Arr()[0], d.Arr()[1], d.Arr()[2]);
160  }
161 }
162 
163 void
165 {
166  m_backgroundColor.set(int(colorManager()->background()));
167 
169  m_energyScale->addTo(oTo);
170 
171  if (gEve)
172  {
173  TGLViewer* v = gEve->GetDefaultGLViewer();
174  addGLColorToConfig("SelectionColorLight", v->RefLightColorSet().Selection(1), oTo);
175  addGLColorToConfig("HighlightColorLight", v->RefLightColorSet().Selection(3), oTo);
176  addGLColorToConfig("SelectionColorDark", v->RefDarkColorSet().Selection(1), oTo);
177  addGLColorToConfig("HighlightColorDark", v->RefDarkColorSet().Selection(3), oTo);
178  }
179 }
180 
181 void
183 {
184  for(const_iterator it =begin(), itEnd = end();
185  it != itEnd;
186  ++it) {
187  (*it)->setFrom(iFrom);
188  }
189 
190  // handle old and new energy scale configuration if existing
191  if (iFrom.valueForKey("ScaleMode"))
192  {
193  long mode = atol(iFrom.valueForKey("ScaleMode")->value().c_str());
194 
195  float convert;
196  if (iFrom.valueForKey("EnergyToLength [GeV/m]"))
197  convert = atof(iFrom.valueForKey("EnergyToLength [GeV/m]")->value().c_str());
198  else
199  convert = atof(iFrom.valueForKey("ValueToHeight [GeV/m]")->value().c_str());
200 
201  float maxH;
202  if (iFrom.valueForKey("MaximumLength [m]"))
203  maxH = atof(iFrom.valueForKey("MaximumLength [m]")->value().c_str());
204  else
205  maxH = atof(iFrom.valueForKey("MaxTowerH [m]")->value().c_str());
206 
207  int et = atoi(iFrom.valueForKey("PlotEt")->value().c_str());
208  m_energyScale->SetFromCmsShowCommonConfig(mode, convert, maxH, et);
209  }
210 
211  // background
214 
215  // geom colors
218 
219  for (int i = 0; i < kFWGeomColorSize; ++i)
221 
222  if (gEve)
223  {
224  TGLViewer* v = gEve->GetDefaultGLViewer();
225  setGLColorFromConfig(v->RefLightColorSet().Selection(1), iFrom.valueForKey("SelectionColorLight"));
226  setGLColorFromConfig(v->RefLightColorSet().Selection(3), iFrom.valueForKey("HighlightColorLight"));
227  setGLColorFromConfig(v->RefDarkColorSet().Selection(1), iFrom.valueForKey("SelectionColorDark"));
228  setGLColorFromConfig(v->RefDarkColorSet().Selection(3), iFrom.valueForKey("HighlightColorDark"));
229  }
230 }
int i
Definition: DBlmapReader.cc:9
std::vector< FWParameterBase * >::const_iterator const_iterator
const_iterator begin() const
FWBoolParameter m_drawBreakPoints
Definition: CmsShowCommon.h:81
TEveTrackPropagator * getTrackerTrackPropagator() const
Definition: Context.h:74
FWLongParameter m_backgroundColor
Definition: CmsShowCommon.h:84
FWColorManager * colorManager() const
Definition: Context.h:65
FWGeomColorIndex
void setTrackBreakMode()
FWLongParameter * m_geomColors[kFWGeomColorSize]
Definition: CmsShowCommon.h:90
TEveTrackPropagator * getTrackPropagator() const
Definition: Context.h:73
sigc::signal< void, T > changed_
const FWColorManager * colorManager() const
void convert(uint32 i, char_uint32 v)
Definition: MsgTools.h:46
FWLongParameter m_gamma
Definition: CmsShowCommon.h:85
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:78
void switchBackground()
FWLongParameter m_geomTransparency3D
Definition: CmsShowCommon.h:89
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:88
std::auto_ptr< FWViewEnergyScale > m_energyScale
Definition: CmsShowCommon.h:93
virtual void addTo(FWConfiguration &) const
void setBackgroundAndBrightness(BackgroundColorIndex, int)
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:80
volatile std::atomic< bool > shutdown_flag false
CmsShowCommon(fireworks::Context *)
virtual void addTo(FWConfiguration &) const