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 }
CmsShowCommonPopup.h
CmsShowCommon::m_context
fireworks::Context * m_context
Definition: CmsShowCommon.h:92
DDAxes::y
FWColorManager::kClassic
Definition: FWColorManager.h:47
FWParameterizable::const_iterator
std::vector< FWParameterBase * >::const_iterator const_iterator
Definition: FWParameterizable.h:34
fwLog
#define fwLog(_level_)
Definition: fwLog.h:45
mps_fire.i
i
Definition: mps_fire.py:428
pwdgSkimBPark_cfi.beamSpot
beamSpot
Definition: pwdgSkimBPark_cfi.py:5
fireworks::Context
Definition: Context.h:41
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
funct::false
false
Definition: Factorize.h:29
CmsShowCommon::m_view
CmsShowCommonPopup * m_view
Definition: CmsShowCommon.h:91
fireworks::Context::getMuonTrackPropagator
TEveTrackPropagator * getMuonTrackPropagator() const
Definition: Context.h:64
detailsBasic3DVector::z
float float float z
Definition: extBasic3DVector.h:14
fireworks::Context::colorManager
FWColorManager * colorManager() const
Definition: Context.h:58
cuy.col
col
Definition: cuy.py:1010
FWEveView.h
ALCARECOPromptCalibProdSiPixelAli0T_cff.mode
mode
Definition: ALCARECOPromptCalibProdSiPixelAli0T_cff.py:96
CmsShowCommon::m_geomColors
FWLongParameter * m_geomColors[kFWGeomColorSize]
Definition: CmsShowCommon.h:105
FWLongParameter
FWParameters::Long FWLongParameter
Definition: FWParameters.h:34
CmsShowCommon::m_externalEventCenter
TEveVector m_externalEventCenter
Definition: CmsShowCommon.h:113
FWEnumParameter::addEntry
bool addEntry(Long_t id, const std::string &txt)
Definition: FWEnumParameter.h:53
FWParameterizable::end
const_iterator end() const
Definition: FWParameterizable.h:38
FWColorManager::kPurple
Definition: FWColorManager.h:47
fireworks::Context::getBeamSpot
FWBeamSpot * getBeamSpot() const
Definition: Context.h:67
FWColorManager::geomColor
Color_t geomColor(FWGeomColorIndex) const
Definition: FWColorManager.cc:271
FWGenericParameter::set
void set(T iValue)
Definition: FWGenericParameter.h:70
DDAxes::x
CmsShowCommon::m_useBeamSpot
bool m_useBeamSpot
Definition: CmsShowCommon.h:112
FWParameterizable::begin
const_iterator begin() const
Definition: FWParameterizable.h:36
FWColorManager::kSpring
Definition: FWColorManager.h:47
CmsShowCommon::m_palette
FWEnumParameter m_palette
Definition: CmsShowCommon.h:100
CmsShowCommon::switchBackground
void switchBackground()
Definition: CmsShowCommon.cc:108
CmsShowCommon::m_geomTransparency3D
FWLongParameter m_geomTransparency3D
Definition: CmsShowCommon.h:104
FWGenericParameter::changed_
sigc::signal< void, T > changed_
Definition: FWGenericParameter.h:75
CmsShowCommon::setGamma
void setGamma()
Definition: CmsShowCommon.cc:106
fireworks::Context::eventItemsManager
const FWEventItemsManager * eventItemsManager() const
Definition: Context.h:56
CmsShowCommon::m_gamma
FWLongParameter m_gamma
Definition: CmsShowCommon.h:99
CmsShowCommon::setGeomTransparency
void setGeomTransparency(int val, bool projected)
Definition: CmsShowCommon.cc:159
CmsShowCommon::setEventCenter
void setEventCenter(float, float, float)
Definition: CmsShowCommon.cc:307
DDAxes::z
FWColorManager::setPalette
void setPalette(long long)
Definition: FWColorManager.cc:149
CmsShowCommon::resetEventCenter
void resetEventCenter()
Definition: CmsShowCommon.cc:313
FWConfiguration::valueForKey
const FWConfiguration * valueForKey(const std::string &iKey) const
Definition: FWConfiguration.cc:122
FWBeamSpot
Definition: FWBeamSpot.h:11
FWConfiguration::value
const std::string & value(unsigned int iIndex=0) const
Definition: FWConfiguration.cc:115
FWColorManager::switchBackground
void switchBackground()
Definition: FWColorManager.cc:204
FWColorManager::kArctic
Definition: FWColorManager.h:47
fileCollector.convert
def convert(infile, ofile)
Definition: fileCollector.py:47
funct::true
true
Definition: Factorize.h:173
FWDisplayProperties::setColor
void setColor(Color_t iColor)
Definition: FWDisplayProperties.h:62
CmsShowCommon::loopPalettes
void loopPalettes()
Definition: CmsShowCommon.cc:278
FWConfigurableParameterizable
Definition: FWConfigurableParameterizable.h:29
CmsShowCommon::setDrawBreakMarkers
void setDrawBreakMarkers()
Definition: CmsShowCommon.cc:97
FWEventItemsManager::end
const_iterator end() const
Definition: FWEventItemsManager.cc:300
FWColorManager::getPalette
EPalette getPalette() const
Definition: FWColorManager.h:76
createfilelist.int
int
Definition: createfilelist.py:10
FWColorManager::setGeomTransparency
void setGeomTransparency(Color_t idx, bool projectedType)
Definition: FWColorManager.cc:238
FWDisplayProperties.h
FWColorManager::propagatePaletteChanges
void propagatePaletteChanges() const
Definition: FWColorManager.cc:183
FWViewEnergyScale::SetFromCmsShowCommonConfig
void SetFromCmsShowCommonConfig(long mode, float convert, float maxH, bool et)
Definition: FWViewEnergyScale.cc:81
FWEventItemsManager::const_iterator
std::vector< FWEventItem * >::const_iterator const_iterator
Definition: FWEventItemsManager.h:50
CmsShowCommon::randomizeColors
void randomizeColors()
Definition: CmsShowCommon.cc:137
EgHLTOffHistBins_cfi.et
et
Definition: EgHLTOffHistBins_cfi.py:8
CmsShowCommon::addTo
void addTo(FWConfiguration &) const override
Definition: CmsShowCommon.cc:199
fwLog.h
FWColorManager::BackgroundColorIndex
BackgroundColorIndex
Definition: FWColorManager.h:73
FWColorManager
Definition: FWColorManager.h:45
CmsShowCommon::setTrackBreakMode
void setTrackBreakMode()
Definition: CmsShowCommon.cc:88
FWEventItem.h
cmsLHEtoEOSManager.l
l
Definition: cmsLHEtoEOSManager.py:204
FWDisplayProperties
Definition: FWDisplayProperties.h:28
FWColorManager::kFall
Definition: FWColorManager.h:47
FWGenericParameter::value
T value() const
Definition: FWGenericParameter.h:50
CmsShowCommon::m_backgroundColor
FWLongParameter m_backgroundColor
Definition: CmsShowCommon.h:98
FWConfiguration::addKeyValue
FWConfiguration & addKeyValue(const std::string &, const FWConfiguration &)
Definition: FWConfiguration.cc:58
fwlog::kInfo
Definition: fwLog.h:35
CmsShowCommonPopup::getCombo
TGComboBox * getCombo()
Definition: CmsShowCommonPopup.h:45
CmsShowCommon.h
FWEventItemsManager::begin
const_iterator begin() const
NOTE: iterator is allowed to return a null object for items that have been removed.
Definition: FWEventItemsManager.cc:299
CmsShowCommon::colorManager
const FWColorManager * colorManager() const
Definition: CmsShowCommon.cc:83
heppy_batch.val
val
Definition: heppy_batch.py:351
FWConfigurableParameterizable::addTo
void addTo(FWConfiguration &) const override
Definition: FWConfigurableParameterizable.cc:67
FWViewContext::setEnergyScale
void setEnergyScale(FWViewEnergyScale *)
Definition: FWViewContext.cc:27
CmsShowCommon::m_darkColorSet
TGLColorSet m_darkColorSet
Definition: CmsShowCommon.h:108
relativeConstraints.value
value
Definition: relativeConstraints.py:53
FWColorManager::setBackgroundAndBrightness
void setBackgroundAndBrightness(BackgroundColorIndex, int)
Definition: FWColorManager.cc:219
fireworks::Context::getTrackPropagator
TEveTrackPropagator * getTrackPropagator() const
Definition: Context.h:62
genVertex_cff.x
x
Definition: genVertex_cff.py:12
CmsShowCommon::m_geomTransparency2D
FWLongParameter m_geomTransparency2D
Definition: CmsShowCommon.h:103
detailsBasic3DVector::y
float float y
Definition: extBasic3DVector.h:14
FWViewEnergyScale
Definition: FWViewEnergyScale.h:34
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
fireworks::Context::getInstance
static Context * getInstance()
Definition: Context.cc:193
FWEventItemsManager.h
kFWGeomColorSize
Definition: FWColorManager.h:42
CmsShowCommon::m_drawBreakPoints
FWBoolParameter m_drawBreakPoints
Definition: CmsShowCommon.h:95
ztail.d
d
Definition: ztail.py:151
FWViewEnergyScale.h
FWConfiguration
Definition: FWConfiguration.h:31
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
fireworks::Context::getTrackerTrackPropagator
TEveTrackPropagator * getTrackerTrackPropagator() const
Definition: Context.h:63
CmsShowCommon::m_lightColorSet
TGLColorSet m_lightColorSet
Definition: CmsShowCommon.h:107
CmsShowCommon::CmsShowCommon
CmsShowCommon(fireworks::Context *)
Definition: CmsShowCommon.cc:40
FWColorManager::setGeomColor
void setGeomColor(FWGeomColorIndex, Color_t)
Definition: FWColorManager.cc:232
CmsShowCommon::setFrom
void setFrom(const FWConfiguration &) override
Definition: CmsShowCommon.cc:213
FWColorManager::kPaletteFirst
Definition: FWColorManager.h:47
CmsShowCommon::setGeomColor
void setGeomColor(FWGeomColorIndex, Color_t)
Definition: CmsShowCommon.cc:154
FWViewContext::getEnergyScale
FWViewEnergyScale * getEnergyScale() const
Definition: FWViewContext.cc:25
CmsShowCommon::m_trackBreak
FWEnumParameter m_trackBreak
Definition: CmsShowCommon.h:94
CmsShowCommon::eventCenterChanged_
sigc::signal< void, const CmsShowCommon * > eventCenterChanged_
Definition: CmsShowCommon.h:84
FWColorManager::kPaletteLast
Definition: FWColorManager.h:47
FWColorManager::setBrightness
void setBrightness(int)
Definition: FWColorManager.cc:190
FWGeomColorIndex
FWGeomColorIndex
Definition: FWColorManager.h:32
CmsShowCommon::getEventCenter
void getEventCenter(float *inC) const
Definition: CmsShowCommon.cc:294
CmsShowCommon::~CmsShowCommon
~CmsShowCommon() override
Definition: CmsShowCommon.cc:81
CmsShowCommon::setPalette
void setPalette()
Definition: CmsShowCommon.cc:260
CmsShowCommon::permuteColors
void permuteColors()
Definition: CmsShowCommon.cc:113
Context.h
CmsShowCommon::m_viewContext
FWViewContext m_viewContext
Definition: CmsShowCommon.h:110