CMS 3D CMS Logo

FWFFService.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include "boost/bind.hpp"
17 
20 
29 
30 #include "TROOT.h"
31 #include "TSystem.h"
32 #include "TRint.h"
33 #include "TEveManager.h"
34 #include "TEveEventManager.h"
35 #include "TEveTrackPropagator.h"
36 #include "TGLWidget.h"
37 
38 #include "TEveBrowser.h"
39 
40 namespace {
41  class CmsEveMagField : public TEveMagField {
42  private:
43  Float_t fField;
44  Float_t fFieldMag;
45 
46  public:
47  CmsEveMagField() : TEveMagField(), fField(-3.8), fFieldMag(3.8) {}
48  ~CmsEveMagField() override {}
49 
50  // set current
51  void SetFieldByCurrent(Float_t avg_current) {
52  fField = -3.8 * avg_current / 18160.0;
53  fFieldMag = TMath::Abs(fField);
54  }
55 
56  // get field values
57  Float_t GetMaxFieldMag() const override { return fFieldMag; }
58 
59  TEveVector GetField(Float_t x, Float_t y, Float_t z) const override {
60  static const Float_t barrelFac = 1.2 / 3.8;
61  static const Float_t endcapFac = 2.0 / 3.8;
62 
63  const Float_t R = sqrt(x * x + y * y);
64  const Float_t absZ = TMath::Abs(z);
65 
66  //barrel
67  if (absZ < 724.0f) {
68  //inside solenoid
69  if (R < 300.0f)
70  return TEveVector(0, 0, fField);
71 
72  // outside solinoid
73  if ((R > 461.0f && R < 490.5f) || (R > 534.5f && R < 597.5f) || (R > 637.0f && R < 700.0f)) {
74  return TEveVector(0, 0, -fField * barrelFac);
75  }
76  } else {
77  if ((absZ > 724.0f && absZ < 786.0f) || (absZ > 850.0f && absZ < 910.0f) || (absZ > 975.0f && absZ < 1003.0f)) {
78  const Float_t fac = (z >= 0 ? fField : -fField) * endcapFac / R;
79  return TEveVector(x * fac, y * fac, 0);
80  }
81  }
82  return TEveVector(0, 0, 0);
83  }
84  };
85 } // namespace
86 
87 //
88 // constants, enums and typedefs
89 //
90 
91 //
92 // static data member definitions
93 //
94 
95 //==============================================================================
96 // constructors and destructor
97 //==============================================================================
98 
100  : CmsShowMainBase(),
101  m_navigator(new FWFFNavigator(*this)),
102  m_metadataManager(new FWFFMetadataManager()),
103  m_context(new fireworks::Context(
104  changeManager(), selectionManager(), eiManager(), colorManager(), m_metadataManager.get())),
105  m_appHelper(ps, ar),
106  m_Rint(m_appHelper.app()),
107  m_AllowStep(true),
108  m_ShowEvent(true),
109  m_firstTime(true) {
110  printf("FWFFService::FWFFService CTOR\n");
111 
112  setup(m_navigator.get(), m_context.get(), m_metadataManager.get());
113 
114  eiManager()->setContext(m_context.get());
115 
116  // By default, we look up geometry and configuration in the workarea, then
117  // in the release area then in the local directory. It is also possible to
118  // override those locations by using the displayConfigurationFilename and
119  // geometryFilename in the parameterset.
120  const char* releaseBase = std::getenv("CMSSW_RELEASE_BASE");
121  const char* workarea = std::getenv("CMSSW_BASE");
122  std::string displayConfigRelFilename = "/src/Fireworks/FWInterface/macros/ffw.fwc";
123  std::string geometryRelFilename = "/src/Fireworks/FWInterface/data/cmsGeom10.root";
124 
125  std::string displayConfigFilename = "ffw.fwc";
127 
128  if (releaseBase && access((releaseBase + displayConfigFilename).c_str(), R_OK) == 0)
129  displayConfigFilename = releaseBase + displayConfigRelFilename;
130  if (workarea && access((workarea + displayConfigRelFilename).c_str(), R_OK) == 0)
131  displayConfigFilename = workarea + displayConfigRelFilename;
132 
133  if (releaseBase && access((releaseBase + geometryRelFilename).c_str(), R_OK) == 0)
134  geometryFilename = releaseBase + geometryRelFilename;
135  if (workarea && access((workarea + geometryRelFilename).c_str(), R_OK) == 0)
136  geometryFilename = workarea + geometryRelFilename;
137 
138  displayConfigFilename = ps.getUntrackedParameter<std::string>("diplayConfigFilename", displayConfigFilename);
140 
142  setConfigFilename(displayConfigFilename);
143 
145 
146  if (!geometryFilename.empty()) {
147  f = boost::bind(&CmsShowMainBase::loadGeometry, this);
148  startupTasks()->addTask(f);
149  }
150 
151  m_MagField = new CmsEveMagField();
152 
153  // ----------------------------------------------------------------
154 
157 
159 
161 }
162 
164  printf("FWFFService::~FWFFService DTOR\n");
165 
166  delete m_MagField;
167 }
168 
169 //==============================================================================
170 // Service watchers
171 //==============================================================================
172 
174  printf("FWFFService::postBeginJob\n");
175  // We need to enter the GUI loop in order to
176  // have all the callbacks executed. The last callback will
177  // be responsible for returning the control to CMSSW.
178  assert(m_Rint);
180  f = boost::bind(&TApplication::Terminate, m_Rint, 0);
181  startupTasks()->addTask(f);
182  // FIXME: do we really need to delay tasks like this?
184  m_Rint->Run(kTRUE);
185  // Show the GUI ...
186  gSystem->ProcessEvents();
187 }
188 
190  printf("FWFFService::postEndJob\n");
191 
192  TEveManager::Terminate();
193 }
194 
196  if (loop() && isPlaying())
197  return;
198 
200 
201  if (m_navigator->isFirstEvent())
203 
204  if (m_navigator->isLastEvent()) {
205  guiManager()->disableNext();
206  // force enable play events action in --port mode
207  if (!guiManager()->playEventsAction()->isEnabled())
209  }
210 }
211 //------------------------------------------------------------------------------
212 
213 void FWFFService::postBeginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
214  // If the geometry was not picked up from a file, we try to get it from the
215  // EventSetup!
216  // FIXME: we need to check we execute only once because the view managers
217  // depend on geometry and they cannot be initialised more than once.
218  // This should actually be cleaned up so that the various view manager
219  // don't care about geometry.
220  // FIXME: we should actually be able to update the geometry when requested.
221  // this is not possible at the moment.
222  if (m_firstTime == true) {
223  if (m_context->getGeom() == nullptr) {
224  guiManager()->updateStatus("Loading geometry...");
226  iSetup.get<FWRecoGeometryRecord>().get(geoh);
227  getGeom().initMap(geoh.product()->idToName);
228  m_context->setGeom(&(getGeom()));
229  }
230 
233  setupActions();
234  m_firstTime = false;
235  }
236 
237  float current = 18160.0f;
238 
240  // bool res = iRun.getByType(runCond);
241  bool res = iRun.getByLabel("conditionsInEdm", runCond);
242  if (res && runCond.isValid()) {
243  printf("Got current from conds in edm %f\n", runCond->BAvgCurrent);
244  current = runCond->BAvgCurrent;
245  } else {
246  printf("Could not extract run-conditions get-result=%d, is-valid=%d\n", res, runCond.isValid());
247 
249  iSetup.get<RunInfoRcd>().get(sum);
250 
251  current = sum->m_avg_current;
252  printf("Got current from RunInfoRcd %f\n", sum->m_avg_current);
253  }
254 
255  static_cast<CmsEveMagField*>(m_MagField)->SetFieldByCurrent(current);
256 }
257 
258 //------------------------------------------------------------------------------
260  printf("FWFFService::postProcessEvent: Starting GUI loop.\n");
261 
263  m_navigator->setCurrentEvent(&event);
264  checkPosition();
265  draw();
266  m_Rint->Run(kTRUE);
267 }
268 
269 //------------------------------------------------------------------------------
270 
272  // Display whatever was registered so far, wait until user presses
273  // the "Step" button.
274 
275  if (m_AllowStep) {
276  gEve->Redraw3D();
277  m_Rint->Run(kTRUE);
278  }
279 }
280 
281 //==============================================================================
282 // Getters for cleints
283 //==============================================================================
284 
285 TEveMagField* FWFFService::getMagField() { return m_MagField; }
286 
287 void FWFFService::setupFieldForPropagator(TEveTrackPropagator* prop) { prop->SetMagFieldObj(m_MagField, kFALSE); }
288 
290  gSystem->ExitLoop();
291  printf("FWFFService exiting on user request.\n");
292 
293  // Throwing exception here is bad because:
294  // a) it does not work when in a "debug step";
295  // b) does not restore terminal state.
296  // So we do exit instead for now.
297  // throw cms::Exception("UserTerminationRequest");
298  gSystem->Exit(0);
299 }
FWFFService::m_Rint
TRint * m_Rint
Definition: FWFFService.h:72
DDAxes::y
Handle.h
ESTransientHandle.h
CmsShowMainBase::setupConfiguration
void setupConfiguration()
Definition: CmsShowMainBase.cc:315
FWFFService::postEndJob
void postEndJob()
Definition: FWFFService.cc:189
RunSummaryRcd.h
edm::ESTransientHandle::product
T const * product() const
Definition: ESTransientHandle.h:51
FWFFService::FWFFService
FWFFService(const edm::ParameterSet &, edm::ActivityRegistry &)
Definition: FWFFService.cc:99
CmsShowMainBase::loadGeometry
void loadGeometry()
Definition: CmsShowMainBase.cc:388
FWRecoGeometryRecord
Definition: FWRecoGeometryRecord.h:9
FWFFService::m_metadataManager
std::unique_ptr< FWFFMetadataManager > m_metadataManager
Definition: FWFFService.h:67
CmsShowMainBase::guiManager
FWGUIManager * guiManager()
Definition: CmsShowMainBase.h:61
ESHandle.h
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
FWRecoGeometry::idToName
FWRecoGeom::InfoMap idToName
Definition: FWRecoGeometry.h:14
CmsShowMainFrame::enableNavigatorControls
void enableNavigatorControls()
Definition: CmsShowMainFrame.cc:567
FWFFService::postProcessEvent
void postProcessEvent(const edm::Event &, const edm::EventSetup &)
Definition: FWFFService.cc:259
edm::Run
Definition: Run.h:45
FWGUIManager::playEventsAction
CSGContinuousAction * playEventsAction()
Definition: FWGUIManager.cc:350
CmsShowMainBase::loop
bool loop() const
Definition: CmsShowMainBase.h:107
FWFFService::postBeginRun
void postBeginRun(const edm::Run &, const edm::EventSetup &)
Definition: FWFFService.cc:213
FWFFService::postBeginJob
void postBeginJob()
Definition: FWFFService.cc:173
cms::cuda::assert
assert(be >=bs)
info
static const TGPicture * info(bool iBackgroundIsBlack)
Definition: FWCollectionSummaryWidget.cc:152
CmsShowMainBase::setup
void setup(FWNavigatorBase *navigator, fireworks::Context *context, FWJobMetadataManager *metadataManager)
Definition: CmsShowMainBase.cc:196
Context
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
FWFFNavigator.h
DDAxes::x
FWFFMetadataManager.h
edm::Handle
Definition: AssociativeIterator.h:50
CmsShowMainBase::setConfigFilename
void setConfigFilename(const std::string &f)
Definition: CmsShowMainBase.h:74
FWGUIManager::getMainFrame
CmsShowMainFrame * getMainFrame() const
Definition: FWGUIManager.h:196
ActivityRegistry.h
FWGUIManager::updateStatus
void updateStatus(const char *status)
Definition: FWGUIManager.cc:367
FWFFMetadataUpdateRequest.h
edm::ActivityRegistry::watchPostEndJob
void watchPostEndJob(PostEndJob::slot_type const &iSlot)
Definition: ActivityRegistry.h:168
edm::EventSetup::get
T get() const
Definition: EventSetup.h:73
CmsShowMainBase::setupActions
void setupActions()
Definition: CmsShowMainBase.cc:73
Abs
T Abs(T a)
Definition: MathUtil.h:49
FWFFService::m_navigator
std::unique_ptr< FWFFNavigator > m_navigator
Definition: FWFFService.h:66
edm::ConditionsInRunBlock::BAvgCurrent
float BAvgCurrent
Definition: ConditionsInEdm.h:27
FWFFService::m_context
std::unique_ptr< fireworks::Context > m_context
Definition: FWFFService.h:68
CmsShowMainBase
Definition: CmsShowMainBase.h:49
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
DDAxes::z
edm::ActivityRegistry
Definition: ActivityRegistry.h:132
Run.h
edm::ESHandle
Definition: DTSurvey.h:22
FWFFService::quit
void quit() override
Definition: FWFFService.cc:289
edm::ActivityRegistry::watchPostBeginJob
void watchPostBeginJob(PostBeginJob::slot_type const &iSlot)
convenience function for attaching to signal
Definition: ActivityRegistry.h:156
FWFFService::~FWFFService
~FWFFService() override
Definition: FWFFService.cc:163
CmsShowMainBase::isPlaying
bool isPlaying() const
Definition: CmsShowMainBase.h:118
CmsShowMainBase::draw
void draw()
Definition: CmsShowMainBase.cc:173
CmsShowTaskExecutor.h
CmsShowMainBase::startupTasks
CmsShowTaskExecutor * startupTasks()
Definition: CmsShowMainBase.h:66
RunInfoRcd
Definition: RunSummaryRcd.h:26
FWRecoGeom.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
funct::true
true
Definition: Factorize.h:173
edm::ParameterSet
Definition: ParameterSet.h:36
FWFFService::setupFieldForPropagator
void setupFieldForPropagator(TEveTrackPropagator *prop)
Definition: FWFFService.cc:287
CmsShowMainBase::geometryFilename
const std::string & geometryFilename(void)
Definition: CmsShowMainBase.h:91
FWGUIManager::disablePrevious
void disablePrevious()
Definition: FWGUIManager.cc:358
FWFFService::m_AllowStep
bool m_AllowStep
Definition: FWFFService.h:76
FWFFService::m_MagField
TEveMagField * m_MagField
Definition: FWFFService.h:74
CmsShowMainBase::setupViewManagers
void setupViewManagers()
Definition: CmsShowMainBase.cc:107
FWFFMetadataUpdateRequest
Definition: FWFFMetadataUpdateRequest.h:7
CmsShowTaskExecutor::TaskFunctor
boost::function0< void > TaskFunctor
Definition: CmsShowTaskExecutor.h:35
FWGUIManager::disableNext
void disableNext()
Definition: FWGUIManager.cc:360
CmsShowMainBase::setGeometryFilename
void setGeometryFilename(const std::string &filename)
Definition: CmsShowMainBase.h:90
edm::ActivityRegistry::watchPostBeginRun
void watchPostBeginRun(PostBeginRun::slot_type const &iSlot)
Definition: ActivityRegistry.h:475
FWFFService::getMagField
TEveMagField * getMagField()
Definition: FWFFService.cc:285
CSGContinuousAction.h
edm::EventSetup
Definition: EventSetup.h:57
FWGeometry::initMap
void initMap(const FWRecoGeom::InfoMap &map)
Definition: FWGeometry.cc:200
get
#define get
res
Definition: Electron.h:6
FWFFNavigator
Definition: FWFFNavigator.h:11
edm::ESTransientHandle
Definition: ESTransientHandle.h:41
CmsShowTaskExecutor::startDoingTasks
void startDoingTasks() override
Definition: CmsShowTaskExecutor.cc:55
FWFFService::display
void display(const std::string &info="")
Definition: FWFFService.cc:271
RunInfo.h
FWRecoGeometryRecord.h
ConditionsInEdm.h
FWEventItemsManager::setContext
void setContext(fireworks::Context *)
Definition: FWEventItemsManager.cc:294
CmsShowTaskExecutor::addTask
void addTask(const TaskFunctor &iTask)
Definition: CmsShowTaskExecutor.cc:53
FWFFMetadataManager
Definition: FWFFMetadataManager.h:11
EventSetup.h
CmsShowMainFrame.h
FWFFService::m_firstTime
bool m_firstTime
Definition: FWFFService.h:78
FWEventItemsManager.h
edm::ActivityRegistry::watchPostProcessEvent
void watchPostProcessEvent(PostProcessEvent::slot_type const &iSlot)
Definition: ActivityRegistry.h:459
FWFFService.h
edm::Run::getByLabel
bool getByLabel(std::string const &label, Handle< PROD > &result) const
Definition: Run.h:280
fireworks
Definition: FWTauProxyBuilderBase.h:35
ParameterSet.h
FWRecoGeometry.h
CmsShowMainBase::eiManager
FWEventItemsManager * eiManager()
Definition: CmsShowMainBase.h:57
CSGAction::enable
void enable()
Definition: CSGAction.cc:269
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
dttmaxenums::R
Definition: DTTMax.h:29
CmsShowMainBase::getGeom
FWGeometry & getGeom()
Definition: CmsShowMainBase.h:92
FWViewManagerManager.h
FWGUIManager.h
Context.h
FWFFService::checkPosition
void checkPosition() override
Definition: FWFFService.cc:195