CMS 3D CMS Logo

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 #include <iostream>
16 // user include files
17 
18 #include "TEveManager.h"
19 #include "TEveTrackPropagator.h"
20 #include "TGLViewer.h"
21 #include "TEveViewer.h"
22 #include "TGComboBox.h"
23 #include "TGClient.h"
24 #include "TGTextEntry.h"
25 
31 
36 
37 //
38 // constructors and destructor
39 //
42  m_view(nullptr),
43  m_context(c),
44  m_trackBreak(this, " ", 2l, 0l, 2l), // do not want to render text at setter
45  m_drawBreakPoints(this, "Show y=0 points as markers", false),
46  m_backgroundColor(this, "backgroundColIdx", 1l, 0l, 1000l),
47  m_gamma(this, "Brightness", 0l, -15l, 15l),
48  m_palette(this, "Palette", 1l, 0l, 2l ),
49  m_geomTransparency2D(this, "Transparency 2D", long(colorManager()->geomTransparency(true)), 0l, 100l),
50  m_geomTransparency3D(this, "Transparency 3D", long(colorManager()->geomTransparency(false)), 0l, 100l),
51  m_useBeamSpot(true)
52 {
54  // projections
55  m_trackBreak.addEntry(0, "Jump to proper hemisphere");
56  m_trackBreak.addEntry(1, "Stay on first point side");
57  m_trackBreak.addEntry(2, "Stay on last point side");
58 
64 
65  // colors
66  char name[32];
67  for (int i = 0; i < kFWGeomColorSize; ++i)
68  {
69  snprintf(name, 31, "GeometryColor %d ", i);
70  m_geomColors[i] = new FWLongParameter(this, name , long(colorManager()->geomColor(FWGeomColorIndex(i))), 1000l, 1100l);
71  }
72 
73  m_trackBreak.changed_.connect(boost::bind(&CmsShowCommon::setTrackBreakMode, this));
76  m_gamma.changed_.connect(boost::bind(&CmsShowCommon::setGamma, this));
77 
78  m_lightColorSet.StdLightBackground();
79  m_darkColorSet .StdDarkBackground();
80 }
81 
83 {
84 }
85 
86 
88 {
89  return m_context->colorManager();
90 }
91 //
92 // member functions
93 //
94 
95 
96 void
98 {
99  if (m_context->getTrackPropagator()->GetProjTrackBreaking() != m_trackBreak.value())
100  {
101  m_context->getTrackPropagator()->SetProjTrackBreaking(m_trackBreak.value());
102  m_context->getTrackerTrackPropagator()->SetProjTrackBreaking(m_trackBreak.value());
103  m_context->getMuonTrackPropagator()->SetProjTrackBreaking(m_trackBreak.value());
104  gEve->Redraw3D();
105  }
106 }
107 
108 
109 
110 
111 void
113 {
114  if (m_context->getTrackPropagator()->GetRnrPTBMarkers() != m_drawBreakPoints.value())
115  {
116  m_context->getTrackPropagator()->SetRnrPTBMarkers(m_drawBreakPoints.value());
119  gEve->Redraw3D();
120  }
121 }
122 
123 void
125 {
127 }
128 
129 void
131 {
133  m_backgroundColor.set(colorManager()->background());
134 }
135 
136 
137 void
139 {
140  // printf("Reverting order of existing colors ...\n");
141 
142  std::vector<Color_t> colv;
143  colv.reserve(64);
144 
146  i != m_context->eventItemsManager()->end(); ++i)
147  {
148  colv.push_back((*i)->defaultDisplayProperties().color());
149  }
150 
151  int vi = colv.size() - 1;
153  i != m_context->eventItemsManager()->end(); ++i, --vi)
154  {
155  FWDisplayProperties prop = (*i)->defaultDisplayProperties();
156  prop.setColor(colv[vi]);
157  (*i)->setDefaultDisplayProperties(prop);
158 
159  (*i)->defaultDisplayPropertiesChanged_(*i);
160  }
161  }
162 
163 void
165 {
166  // printf("Doing random_shuffle on existing colors ...\n");
167 
168  int vi = 0;
170  i != m_context->eventItemsManager()->end(); ++i, ++vi)
171  {
172  FWDisplayProperties prop = (*i)->defaultDisplayProperties();
173 
174  int col = rand() % 17; // randomize in first row of palette
175  prop.setColor(col);
176  (*i)->setDefaultDisplayProperties(prop);
177 
178  (*i)->defaultDisplayPropertiesChanged_(*i);
179  }
180 }
181 
182 void
184 {
185  m_geomColors[cidx]->set(iColor);
186  m_context->colorManager()->setGeomColor(cidx, iColor);
187 }
188 
189 void
190 CmsShowCommon::setGeomTransparency(int iTransp, bool projected)
191 {
192  if (projected)
193  m_geomTransparency2D.set(iTransp);
194  else
195  m_geomTransparency3D.set(iTransp);
196 
197  m_context->colorManager()->setGeomTransparency(iTransp, projected);
198 }
199 
200 //____________________________________________________________________________
201 
202 namespace
203 {
204  void addGLColorToConfig(const char* cname, const TGLColor& c, FWConfiguration& oTo)
205  {
206  FWConfiguration pc;
207 
208  std::ostringstream sRed;
209  sRed << (int)c.GetRed();
210  pc.addKeyValue("Red", sRed.str());
211 
212  std::ostringstream sGreen;
213  sGreen << (int)c.GetGreen();
214  pc.addKeyValue("Green", sGreen.str());
215 
216  std::ostringstream sBlue;
217  sBlue << (int)c.GetBlue();
218  pc.addKeyValue("Blue", sBlue.str());
219 
220  oTo.addKeyValue(cname, pc, true);
221  }
222 
223  void setGLColorFromConfig(TGLColor& d, const FWConfiguration* iFrom )
224  {
225  if (!iFrom) return;
226  d.Arr()[0] = atoi(iFrom->valueForKey("Red")->value().c_str());
227  d.Arr()[1] = atoi(iFrom->valueForKey("Green")->value().c_str());
228  d.Arr()[2] = atoi(iFrom->valueForKey("Blue")->value().c_str());
229  // printf("22222 colors %d %d %d \n", d.Arr()[0], d.Arr()[1], d.Arr()[2]);
230  }
231 }
232 
233 void
235 {
236  m_backgroundColor.set(int(colorManager()->background()));
237 
240 
241  if (gEve)
242  {
243  addGLColorToConfig("SelectionColorLight", m_lightColorSet.Selection(1), oTo);
244  addGLColorToConfig("HighlightColorLight", m_lightColorSet.Selection(3), oTo);
245  addGLColorToConfig("SelectionColorDark", m_darkColorSet .Selection(1), oTo);
246  addGLColorToConfig("HighlightColorDark", m_darkColorSet .Selection(3), oTo);
247  }
248 }
249 
250 void
252 {
253  for(const_iterator it =begin(), itEnd = end();
254  it != itEnd;
255  ++it) {
256  (*it)->setFrom(iFrom);
257  }
258 
259  if (iFrom.valueForKey("Palette"))
260  setPalette();
261 
262  // handle old and new energy scale configuration if existing
263  if (iFrom.valueForKey("ScaleMode"))
264  {
265  long mode = atol(iFrom.valueForKey("ScaleMode")->value().c_str());
266 
267  float convert;
268  if (iFrom.valueForKey("EnergyToLength [GeV/m]"))
269  convert = atof(iFrom.valueForKey("EnergyToLength [GeV/m]")->value().c_str());
270  else
271  convert = atof(iFrom.valueForKey("ValueToHeight [GeV/m]")->value().c_str());
272 
273  float maxH;
274  if (iFrom.valueForKey("MaximumLength [m]"))
275  maxH = atof(iFrom.valueForKey("MaximumLength [m]")->value().c_str());
276  else
277  maxH = atof(iFrom.valueForKey("MaxTowerH [m]")->value().c_str());
278 
279  int et = atoi(iFrom.valueForKey("PlotEt")->value().c_str());
280  m_viewContext.getEnergyScale()->SetFromCmsShowCommonConfig(mode, convert, maxH, et);
281  }
282 
283  // background
286 
287  // geom colors
290 
291  for (int i = 0; i < kFWGeomColorSize; ++i)
293 
294  if (gEve)
295  {
296  setGLColorFromConfig(m_lightColorSet.Selection(1), iFrom.valueForKey("SelectionColorLight"));
297  setGLColorFromConfig(m_lightColorSet.Selection(3), iFrom.valueForKey("HighlightColorLight"));
298  setGLColorFromConfig(m_darkColorSet .Selection(1), iFrom.valueForKey("SelectionColorDark"));
299  setGLColorFromConfig(m_darkColorSet .Selection(3), iFrom.valueForKey("HighlightColorDark"));
300  }
301 }
302 
303 
304 
305 void
307 {
309  cm->setPalette(m_palette.value());
310 
311  for (int i = 0 ; i < kFWGeomColorSize; ++i) {
314  // m_colorSelectWidget[i]->SetColorByIndex(cm->geomColor(FWGeomColorIndex(i)), kFALSE);
315  }
316 
319  i != m_context->eventItemsManager()->end(); ++i)
320  {
321  (*i)->resetColor();
322  }
323 }
324 
325 
326 void
328 {
329  int val = m_palette.value();
330  val++;
331 
332  if (val >= FWColorManager::kPaletteLast)
334 
335  if (m_view)
336  {
337  TGComboBox* combo = m_view->getCombo();
338  combo->Select(val, true);
339  }
340  else
341  {
342  m_palette.set(val);
343  setPalette();
344  }
345 }
346 
347 void CmsShowCommon::getEventCenter(float* iC) const
348 {
349  if (m_useBeamSpot) {
351  iC[0] = float(beamSpot->x0());
352  iC[1] = float(beamSpot->y0());
353  iC[2] = float(beamSpot->z0());
354  }
355  else {
356  iC[0] = m_externalEventCenter.fX;
357  iC[1] = m_externalEventCenter.fY;
358  iC[2] = m_externalEventCenter.fZ;
359  }
360 }
361 
362 void CmsShowCommon::setEventCenter(float x, float y , float z)
363 {
364  m_useBeamSpot = false;
365  m_externalEventCenter.Set(x, y, z);
366  eventCenterChanged_.emit(this);
367 }
368 
369 
371 {
372  if (!m_useBeamSpot) {
373  fwLog( fwlog::kInfo ) << "CmsShowCommon re-set event center to BeamSpot\n ";
374  m_useBeamSpot = true;
376  setEventCenter(beamSpot->x0(), beamSpot->y0(), beamSpot->z0());
377  }
378 }
void addTo(FWConfiguration &) const override
void resetEventCenter()
void setColor(Color_t iColor)
TGLColorSet m_lightColorSet
std::vector< FWParameterBase * >::const_iterator const_iterator
sigc::signal< void, const CmsShowCommon * > eventCenterChanged_
Definition: CmsShowCommon.h:88
double x0() const
Definition: FWBeamSpot.cc:30
const FWEventItemsManager * eventItemsManager() const
Definition: Context.h:61
const_iterator begin() const
FWBoolParameter m_drawBreakPoints
double z0() const
Definition: FWBeamSpot.cc:40
double y0() const
Definition: FWBeamSpot.cc:35
TEveTrackPropagator * getTrackerTrackPropagator() const
Definition: Context.h:74
FWLongParameter m_backgroundColor
FWColorManager * colorManager() const
Definition: Context.h:65
FWGeomColorIndex
#define nullptr
FWViewEnergyScale * getEnergyScale() const
void getEventCenter(float *inC) const
void setTrackBreakMode()
FWLongParameter * m_geomColors[kFWGeomColorSize]
void setFrom(const FWConfiguration &) override
TEveTrackPropagator * getTrackPropagator() const
Definition: Context.h:73
sigc::signal< void, T > changed_
const FWColorManager * colorManager() const
FWLongParameter m_gamma
void setGeomColor(FWGeomColorIndex, Color_t)
void setGeomTransparency(int val, bool projected)
void setGeomTransparency(Color_t idx, bool projectedType)
void setPalette(long long)
void randomizeColors()
FWBeamSpot * getBeamSpot() const
Definition: Context.h:78
TEveVector m_externalEventCenter
void addTo(FWConfiguration &) const override
void SetFromCmsShowCommonConfig(long mode, float convert, float maxH, bool et)
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:97
def convert(infile, ofile)
void switchBackground()
FWLongParameter m_geomTransparency3D
static Context * getInstance()
Definition: Context.cc:243
void setDrawBreakMarkers()
TEveTrackPropagator * getMuonTrackPropagator() const
Definition: Context.h:75
FWConfiguration & addKeyValue(const std::string &, const FWConfiguration &)
FWViewContext m_viewContext
~CmsShowCommon() override
void setEventCenter(float, float, float)
const std::string & value(unsigned int iIndex=0) const
FWLongParameter m_geomTransparency2D
TGComboBox * getCombo()
const_iterator begin() const
NOTE: iterator is allowed to return a null object for items that have been removed.
#define fwLog(_level_)
Definition: fwLog.h:50
CmsShowCommonPopup * m_view
Definition: CmsShowCommon.h:96
void permuteColors()
et
define resolution functions of each parameter
void setBackgroundAndBrightness(BackgroundColorIndex, int)
void propagatePaletteChanges() const
col
Definition: cuy.py:1010
Signal rand(Signal arg)
Definition: vlib.cc:442
TGLColorSet m_darkColorSet
FWParameters::Long FWLongParameter
Definition: FWParameters.h:35
const FWConfiguration * valueForKey(const std::string &iKey) const
FWEnumParameter m_trackBreak
Definition: CmsShowCommon.h:99
Color_t geomColor(FWGeomColorIndex) const
EPalette getPalette() const
std::vector< FWEventItem * >::const_iterator const_iterator
CmsShowCommon(fireworks::Context *)
const_iterator end() const
FWEnumParameter m_palette
void setEnergyScale(FWViewEnergyScale *)