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 <functional>
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) {
53  // projections
54  m_trackBreak.addEntry(0, "Jump to proper hemisphere");
55  m_trackBreak.addEntry(1, "Stay on first point side");
56  m_trackBreak.addEntry(2, "Stay on last point side");
57 
63 
64  // colors
65  char name[32];
66  for (int i = 0; i < kFWGeomColorSize; ++i) {
67  snprintf(name, 31, "GeometryColor %d ", i);
68  m_geomColors[i] =
69  new FWLongParameter(this, name, long(colorManager()->geomColor(FWGeomColorIndex(i))), 1000l, 1100l);
70  }
71 
72  m_trackBreak.changed_.connect(std::bind(&CmsShowCommon::setTrackBreakMode, this));
75  m_gamma.changed_.connect(std::bind(&CmsShowCommon::setGamma, this));
76 
77  m_lightColorSet.StdLightBackground();
78  m_darkColorSet.StdDarkBackground();
79 }
80 
82 
84 //
85 // member functions
86 //
87 
89  if (m_context->getTrackPropagator()->GetProjTrackBreaking() != m_trackBreak.value()) {
90  m_context->getTrackPropagator()->SetProjTrackBreaking(m_trackBreak.value());
91  m_context->getTrackerTrackPropagator()->SetProjTrackBreaking(m_trackBreak.value());
92  m_context->getMuonTrackPropagator()->SetProjTrackBreaking(m_trackBreak.value());
93  gEve->Redraw3D();
94  }
95 }
96 
98  if (m_context->getTrackPropagator()->GetRnrPTBMarkers() != m_drawBreakPoints.value()) {
99  m_context->getTrackPropagator()->SetRnrPTBMarkers(m_drawBreakPoints.value());
102  gEve->Redraw3D();
103  }
104 }
105 
107 
110  m_backgroundColor.set(colorManager()->background());
111 }
112 
114  // printf("Reverting order of existing colors ...\n");
115 
116  std::vector<Color_t> colv;
117  colv.reserve(64);
118 
120  i != m_context->eventItemsManager()->end();
121  ++i) {
122  colv.push_back((*i)->defaultDisplayProperties().color());
123  }
124 
125  int vi = colv.size() - 1;
127  i != m_context->eventItemsManager()->end();
128  ++i, --vi) {
129  FWDisplayProperties prop = (*i)->defaultDisplayProperties();
130  prop.setColor(colv[vi]);
131  (*i)->setDefaultDisplayProperties(prop);
132 
133  (*i)->defaultDisplayPropertiesChanged_(*i);
134  }
135 }
136 
138  // printf("Doing random_shuffle on existing colors ...\n");
139 
140  int vi = 0;
142  i != m_context->eventItemsManager()->end();
143  ++i, ++vi) {
144  FWDisplayProperties prop = (*i)->defaultDisplayProperties();
145 
146  int col = rand() % 17; // randomize in first row of palette
147  prop.setColor(col);
148  (*i)->setDefaultDisplayProperties(prop);
149 
150  (*i)->defaultDisplayPropertiesChanged_(*i);
151  }
152 }
153 
154 void CmsShowCommon::setGeomColor(FWGeomColorIndex cidx, Color_t iColor) {
155  m_geomColors[cidx]->set(iColor);
156  m_context->colorManager()->setGeomColor(cidx, iColor);
157 }
158 
159 void CmsShowCommon::setGeomTransparency(int iTransp, bool projected) {
160  if (projected)
161  m_geomTransparency2D.set(iTransp);
162  else
163  m_geomTransparency3D.set(iTransp);
164 
165  m_context->colorManager()->setGeomTransparency(iTransp, projected);
166 }
167 
168 //____________________________________________________________________________
169 
170 namespace {
171  void addGLColorToConfig(const char* cname, const TGLColor& c, FWConfiguration& oTo) {
172  FWConfiguration pc;
173 
174  std::ostringstream sRed;
175  sRed << (int)c.GetRed();
176  pc.addKeyValue("Red", sRed.str());
177 
178  std::ostringstream sGreen;
179  sGreen << (int)c.GetGreen();
180  pc.addKeyValue("Green", sGreen.str());
181 
182  std::ostringstream sBlue;
183  sBlue << (int)c.GetBlue();
184  pc.addKeyValue("Blue", sBlue.str());
185 
186  oTo.addKeyValue(cname, pc, true);
187  }
188 
189  void setGLColorFromConfig(TGLColor& d, const FWConfiguration* iFrom) {
190  if (!iFrom)
191  return;
192  d.Arr()[0] = atoi(iFrom->valueForKey("Red")->value().c_str());
193  d.Arr()[1] = atoi(iFrom->valueForKey("Green")->value().c_str());
194  d.Arr()[2] = atoi(iFrom->valueForKey("Blue")->value().c_str());
195  // printf("22222 colors %d %d %d \n", d.Arr()[0], d.Arr()[1], d.Arr()[2]);
196  }
197 } // namespace
198 
200  m_backgroundColor.set(int(colorManager()->background()));
201 
204 
205  if (gEve) {
206  addGLColorToConfig("SelectionColorLight", m_lightColorSet.Selection(1), oTo);
207  addGLColorToConfig("HighlightColorLight", m_lightColorSet.Selection(3), oTo);
208  addGLColorToConfig("SelectionColorDark", m_darkColorSet.Selection(1), oTo);
209  addGLColorToConfig("HighlightColorDark", m_darkColorSet.Selection(3), oTo);
210  }
211 }
212 
214  for (const_iterator it = begin(), itEnd = end(); it != itEnd; ++it) {
215  (*it)->setFrom(iFrom);
216  }
217 
218  if (iFrom.valueForKey("Palette"))
219  setPalette();
220 
221  // handle old and new energy scale configuration if existing
222  if (iFrom.valueForKey("ScaleMode")) {
223  long mode = atol(iFrom.valueForKey("ScaleMode")->value().c_str());
224 
225  float convert;
226  if (iFrom.valueForKey("EnergyToLength [GeV/m]"))
227  convert = atof(iFrom.valueForKey("EnergyToLength [GeV/m]")->value().c_str());
228  else
229  convert = atof(iFrom.valueForKey("ValueToHeight [GeV/m]")->value().c_str());
230 
231  float maxH;
232  if (iFrom.valueForKey("MaximumLength [m]"))
233  maxH = atof(iFrom.valueForKey("MaximumLength [m]")->value().c_str());
234  else
235  maxH = atof(iFrom.valueForKey("MaxTowerH [m]")->value().c_str());
236 
237  int et = atoi(iFrom.valueForKey("PlotEt")->value().c_str());
239  }
240 
241  // background
244 
245  // geom colors
248 
249  for (int i = 0; i < kFWGeomColorSize; ++i)
251 
252  if (gEve) {
253  setGLColorFromConfig(m_lightColorSet.Selection(1), iFrom.valueForKey("SelectionColorLight"));
254  setGLColorFromConfig(m_lightColorSet.Selection(3), iFrom.valueForKey("HighlightColorLight"));
255  setGLColorFromConfig(m_darkColorSet.Selection(1), iFrom.valueForKey("SelectionColorDark"));
256  setGLColorFromConfig(m_darkColorSet.Selection(3), iFrom.valueForKey("HighlightColorDark"));
257  }
258 }
259 
262  cm->setPalette(m_palette.value());
263 
264  for (int i = 0; i < kFWGeomColorSize; ++i) {
267  // m_colorSelectWidget[i]->SetColorByIndex(cm->geomColor(FWGeomColorIndex(i)), kFALSE);
268  }
269 
272  i != m_context->eventItemsManager()->end();
273  ++i) {
274  (*i)->resetColor();
275  }
276 }
277 
279  int val = m_palette.value();
280  val++;
281 
284 
285  if (m_view) {
286  TGComboBox* combo = m_view->getCombo();
287  combo->Select(val, true);
288  } else {
289  m_palette.set(val);
290  setPalette();
291  }
292 }
293 
294 void CmsShowCommon::getEventCenter(float* iC) const {
295  if (m_useBeamSpot) {
297  iC[0] = float(beamSpot->x0());
298  iC[1] = float(beamSpot->y0());
299  iC[2] = float(beamSpot->z0());
300  } else {
301  iC[0] = m_externalEventCenter.fX;
302  iC[1] = m_externalEventCenter.fY;
303  iC[2] = m_externalEventCenter.fZ;
304  }
305 }
306 
307 void CmsShowCommon::setEventCenter(float x, float y, float z) {
308  m_useBeamSpot = false;
309  m_externalEventCenter.Set(x, y, z);
310  eventCenterChanged_.emit(this);
311 }
312 
314  if (!m_useBeamSpot) {
315  fwLog(fwlog::kInfo) << "CmsShowCommon re-set event center to BeamSpot\n ";
316  m_useBeamSpot = true;
318  setEventCenter(beamSpot->x0(), beamSpot->y0(), beamSpot->z0());
319  }
320 }
void resetEventCenter()
void setColor(Color_t iColor)
TGLColorSet m_lightColorSet
const_iterator begin() const
TEveTrackPropagator * getTrackPropagator() const
Definition: Context.h:62
FWBoolParameter m_drawBreakPoints
Definition: CmsShowCommon.h:95
const FWEventItemsManager * eventItemsManager() const
Definition: Context.h:56
FWLongParameter m_backgroundColor
Definition: CmsShowCommon.h:98
FWBeamSpot * getBeamSpot() const
Definition: Context.h:67
FWGeomColorIndex
void setTrackBreakMode()
FWLongParameter * m_geomColors[kFWGeomColorSize]
void setFrom(const FWConfiguration &) override
TEveTrackPropagator * getMuonTrackPropagator() const
Definition: Context.h:64
std::vector< FWParameterBase * >::const_iterator const_iterator
float float float z
FWLongParameter m_gamma
Definition: CmsShowCommon.h:99
void setGeomColor(FWGeomColorIndex, Color_t)
void setGeomTransparency(int val, bool projected)
const_iterator end() const
void setGeomTransparency(Color_t idx, bool projectedType)
FWViewEnergyScale * getEnergyScale() const
void setPalette(long long)
Color_t geomColor(FWGeomColorIndex) const
const std::string & value(unsigned int iIndex=0) const
void randomizeColors()
TEveVector m_externalEventCenter
TEveTrackPropagator * getTrackerTrackPropagator() const
Definition: Context.h:63
void SetFromCmsShowCommonConfig(long mode, float convert, float maxH, bool et)
bool addEntry(Long_t id, const std::string &txt)
void setBrightness(int)
void setGeomColor(FWGeomColorIndex, Color_t)
fireworks::Context * m_context
Definition: CmsShowCommon.h:92
def convert(infile, ofile)
const FWColorManager * colorManager() const
void switchBackground()
d
Definition: ztail.py:151
FWLongParameter m_geomTransparency3D
static Context * getInstance()
Definition: Context.cc:193
void setDrawBreakMarkers()
FWConfiguration & addKeyValue(const std::string &, const FWConfiguration &)
FWViewContext m_viewContext
~CmsShowCommon() override
void setEventCenter(float, float, float)
FWLongParameter m_geomTransparency2D
TGComboBox * getCombo()
#define fwLog(_level_)
Definition: fwLog.h:45
EPalette getPalette() const
CmsShowCommonPopup * m_view
Definition: CmsShowCommon.h:91
void permuteColors()
const FWConfiguration * valueForKey(const std::string &iKey) const
void setBackgroundAndBrightness(BackgroundColorIndex, int)
void propagatePaletteChanges() const
col
Definition: cuy.py:1009
float x
TGLColorSet m_darkColorSet
FWParameters::Long FWLongParameter
Definition: FWParameters.h:34
const_iterator begin() const
NOTE: iterator is allowed to return a null object for items that have been removed.
sigc::signal< void(T)> changed_
FWEnumParameter m_trackBreak
Definition: CmsShowCommon.h:94
const_iterator end() const
void getEventCenter(float *inC) const
void addTo(FWConfiguration &) const override
std::vector< FWEventItem * >::const_iterator const_iterator
sigc::signal< void(const CmsShowCommon *)> eventCenterChanged_
Definition: CmsShowCommon.h:84
FWColorManager * colorManager() const
Definition: Context.h:58
CmsShowCommon(fireworks::Context *)
void addTo(FWConfiguration &) const override
FWEnumParameter m_palette
void setEnergyScale(FWViewEnergyScale *)