CMS 3D CMS Logo

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