CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 {
42  class CmsEveMagField : public TEveMagField
43  {
44  private:
45  Float_t fField;
46  Float_t fFieldMag;
47 
48  public:
49 
50  CmsEveMagField() : TEveMagField(), fField(-3.8), fFieldMag(3.8) {}
51  virtual ~CmsEveMagField() {}
52 
53  // set current
54  void SetFieldByCurrent(Float_t avg_current)
55  {
56  fField = -3.8 * avg_current / 18160.0;
57  fFieldMag = TMath::Abs(fField);
58  }
59 
60  // get field values
61  virtual Float_t GetMaxFieldMag() const override
62  {
63  return fFieldMag;
64  }
65 
66  virtual TEveVector GetField(Float_t x, Float_t y, Float_t z) const override
67  {
68  static const Float_t barrelFac = 1.2 / 3.8;
69  static const Float_t endcapFac = 2.0 / 3.8;
70 
71  const Float_t R = sqrt(x*x+y*y);
72  const Float_t absZ = TMath::Abs(z);
73 
74  //barrel
75  if (absZ < 724.0f)
76  {
77  //inside solenoid
78  if (R < 300.0f) return TEveVector(0, 0, fField);
79 
80  // outside solinoid
81  if ((R > 461.0f && R < 490.5f) ||
82  (R > 534.5f && R < 597.5f) ||
83  (R > 637.0f && R < 700.0f))
84  {
85  return TEveVector(0, 0, -fField*barrelFac);
86  }
87  } else {
88  if ((absZ > 724.0f && absZ < 786.0f) ||
89  (absZ > 850.0f && absZ < 910.0f) ||
90  (absZ > 975.0f && absZ < 1003.0f))
91  {
92  const Float_t fac = (z >= 0 ? fField : -fField) * endcapFac / R;
93  return TEveVector(x*fac, y*fac, 0);
94  }
95  }
96  return TEveVector(0, 0, 0);
97  }
98  };
99 }
100 
101 //
102 // constants, enums and typedefs
103 //
104 
105 //
106 // static data member definitions
107 //
108 
109 //==============================================================================
110 // constructors and destructor
111 //==============================================================================
112 
114  : CmsShowMainBase(),
115  m_navigator(new FWFFNavigator(*this)),
116  m_metadataManager(new FWFFMetadataManager()),
117  m_context(new fireworks::Context(changeManager(),
118  selectionManager(),
119  eiManager(),
120  colorManager(),
121  m_metadataManager.get())),
122  m_appHelper(ps, ar),
123  m_Rint(m_appHelper.app()),
124  m_AllowStep(true),
125  m_ShowEvent(true),
126  m_firstTime(true)
127 {
128  printf("FWFFService::FWFFService CTOR\n");
129 
130  setup(m_navigator.get(), m_context.get(), m_metadataManager.get());
131 
132  eiManager()->setContext(m_context.get());
133 
134  // By default, we look up geometry and configuration in the workarea, then
135  // in the release area then in the local directory. It is also possible to
136  // override those locations by using the displayConfigurationFilename and
137  // geometryFilename in the parameterset.
138  const char *releaseBase = getenv("CMSSW_RELEASE_BASE");
139  const char *workarea = getenv("CMSSW_BASE");
140  std::string displayConfigRelFilename = "/src/Fireworks/FWInterface/macros/ffw.fwc";
141  std::string geometryRelFilename = "/src/Fireworks/FWInterface/data/cmsGeom10.root";
142 
143  std::string displayConfigFilename = "ffw.fwc";
145 
146  if (releaseBase && access((releaseBase + displayConfigFilename).c_str(), R_OK) == 0)
147  displayConfigFilename = releaseBase + displayConfigRelFilename;
148  if (workarea && access((workarea + displayConfigRelFilename).c_str(), R_OK) == 0)
149  displayConfigFilename = workarea + displayConfigRelFilename;
150 
151  if (releaseBase && access((releaseBase + geometryRelFilename).c_str(), R_OK) == 0)
152  geometryFilename = releaseBase + geometryRelFilename;
153  if (workarea && access((workarea + geometryRelFilename).c_str(), R_OK) == 0)
154  geometryFilename = workarea + geometryRelFilename;
155 
156  displayConfigFilename = ps.getUntrackedParameter<std::string>("diplayConfigFilename", displayConfigFilename);
157  geometryFilename = ps.getUntrackedParameter<std::string>("geometryFilename", geometryFilename);
158 
159  setGeometryFilename(geometryFilename);
160  setConfigFilename(displayConfigFilename);
161 
163 
164  if (!geometryFilename.empty())
165  {
166  f=boost::bind(&CmsShowMainBase::loadGeometry,this);
167  startupTasks()->addTask(f);
168  }
169 
170  m_MagField = new CmsEveMagField();
171 
172  // ----------------------------------------------------------------
173 
176 
178 
180 }
181 
183 {
184  printf("FWFFService::~FWFFService DTOR\n");
185 
186  delete m_MagField;
187 }
188 
189 
190 //==============================================================================
191 // Service watchers
192 //==============================================================================
193 
194 void
196 {
197  printf("FWFFService::postBeginJob\n");
198  // We need to enter the GUI loop in order to
199  // have all the callbacks executed. The last callback will
200  // be responsible for returning the control to CMSSW.
201  assert(m_Rint);
203  f=boost::bind(&TApplication::Terminate, m_Rint, 0);
204  startupTasks()->addTask(f);
205  // FIXME: do we really need to delay tasks like this?
207  m_Rint->Run(kTRUE);
208  // Show the GUI ...
209  gSystem->ProcessEvents();
210 }
211 
212 void
214 {
215  printf("FWFFService::postEndJob\n");
216 
217  TEveManager::Terminate();
218 }
219 
220 void
222 {
223  if (loop() && isPlaying())
224  return;
225 
227 
228  if (m_navigator->isFirstEvent())
230 
231  if (m_navigator->isLastEvent())
232  {
233  guiManager()->disableNext();
234  // force enable play events action in --port mode
235  if (!guiManager()->playEventsAction()->isEnabled())
237  }
238 }
239 //------------------------------------------------------------------------------
240 
241 void
243 {
244  // If the geometry was not picked up from a file, we try to get it from the
245  // EventSetup!
246  // FIXME: we need to check we execute only once because the view managers
247  // depend on geometry and they cannot be initialised more than once.
248  // This should actually be cleaned up so that the various view manager
249  // don't care about geometry.
250  // FIXME: we should actually be able to update the geometry when requested.
251  // this is not possible at the moment.
252  if (m_firstTime == true)
253  {
254  if (m_context->getGeom() == 0)
255  {
256  guiManager()->updateStatus("Loading geometry...");
258  iSetup.get<FWRecoGeometryRecord>().get(geoh);
259  getGeom().initMap(geoh.product()->idToName);
260  m_context->setGeom(&(getGeom()));
261  }
262 
265  setupActions();
266  m_firstTime = false;
267  }
268 
269  float current = 18160.0f;
270 
272  // bool res = iRun.getByType(runCond);
273  bool res = iRun.getByLabel("conditionsInEdm", runCond);
274  if (res && runCond.isValid())
275  {
276  printf("Got current from conds in edm %f\n", runCond->BAvgCurrent);
277  current = runCond->BAvgCurrent;
278  }
279  else
280  {
281  printf("Could not extract run-conditions get-result=%d, is-valid=%d\n", res, runCond.isValid());
282 
284  iSetup.get<RunInfoRcd>().get(sum);
285 
286  current = sum->m_avg_current;
287  printf("Got current from RunInfoRcd %f\n", sum->m_avg_current);
288  }
289 
290  static_cast<CmsEveMagField*>(m_MagField)->SetFieldByCurrent(current);
291 }
292 
293 //------------------------------------------------------------------------------
294 void
296 {
297  printf("FWFFService::postProcessEvent: Starting GUI loop.\n");
298 
299  m_metadataManager->update(new FWFFMetadataUpdateRequest(event));
300  m_navigator->setCurrentEvent(&event);
301  checkPosition();
302  draw();
303  m_Rint->Run(kTRUE);
304 }
305 
306 //------------------------------------------------------------------------------
307 
308 void
310 {
311  // Display whatever was registered so far, wait until user presses
312  // the "Step" button.
313 
314  if (m_AllowStep)
315  {
316  gEve->Redraw3D();
317  m_Rint->Run(kTRUE);
318  }
319 }
320 
321 //==============================================================================
322 // Getters for cleints
323 //==============================================================================
324 
325 TEveMagField*
327 {
328  return m_MagField;
329 }
330 
331 void
332 FWFFService::setupFieldForPropagator(TEveTrackPropagator* prop)
333 {
334  prop->SetMagFieldObj(m_MagField, kFALSE);
335 }
336 
337 void
339 {
340  gSystem->ExitLoop();
341  printf("FWFFService exiting on user request.\n");
342 
343  // Throwing exception here is bad because:
344  // a) it does not work when in a "debug step";
345  // b) does not restore terminal state.
346  // So we do exit instead for now.
347  // throw cms::Exception("UserTerminationRequest");
348  gSystem->Exit(0);
349 }
void watchPostBeginRun(PostBeginRun::slot_type const &iSlot)
bool getByLabel(std::string const &label, Handle< PROD > &result) const
Definition: Run.h:219
T getUntrackedParameter(std::string const &, T const &) const
void postBeginJob()
Definition: FWFFService.cc:195
std::auto_ptr< FWFFNavigator > m_navigator
Definition: FWFFService.h:69
static const TGPicture * info(bool iBackgroundIsBlack)
TRint * m_Rint
Definition: FWFFService.h:75
FWGUIManager * guiManager()
void watchPostEndJob(PostEndJob::slot_type const &iSlot)
void initMap(const FWRecoGeom::InfoMap &map)
Definition: FWGeometry.cc:143
FWFFService(const edm::ParameterSet &, edm::ActivityRegistry &)
Definition: FWFFService.cc:113
void postProcessEvent(const edm::Event &, const edm::EventSetup &)
Definition: FWFFService.cc:295
void enable()
Definition: CSGAction.cc:284
FWEventItemsManager * eiManager()
assert(m_qm.get())
void postBeginRun(const edm::Run &, const edm::EventSetup &)
Definition: FWFFService.cc:242
void setup(FWNavigatorBase *navigator, fireworks::Context *context, FWJobMetadataManager *metadataManager)
void updateStatus(const char *status)
void setContext(fireworks::Context *)
virtual ~FWFFService()
Definition: FWFFService.cc:182
void setGeometryFilename(const std::string &filename)
void setupFieldForPropagator(TEveTrackPropagator *prop)
Definition: FWFFService.cc:332
void watchPostProcessEvent(PostProcessEvent::slot_type const &iSlot)
bool m_AllowStep
Definition: FWFFService.h:80
bool loop() const
CmsShowTaskExecutor * startupTasks()
T sqrt(T t)
Definition: SSEVec.h:18
T Abs(T a)
Definition: MathUtil.h:49
double f[11][100]
CmsShowMainFrame * getMainFrame() const
Definition: FWGUIManager.h:201
void disablePrevious()
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
bool isValid() const
Definition: HandleBase.h:75
TEveMagField * getMagField()
Definition: FWFFService.cc:326
TEveMagField * m_MagField
Definition: FWFFService.h:77
const T & get() const
Definition: EventSetup.h:56
T const * product() const
CSGContinuousAction * playEventsAction()
std::auto_ptr< FWFFMetadataManager > m_metadataManager
Definition: FWFFService.h:70
void display(const std::string &info="")
Definition: FWFFService.cc:309
bool isPlaying() const
FWGeometry & getGeom()
boost::function0< void > TaskFunctor
void addTask(const TaskFunctor &iTask)
std::auto_ptr< fireworks::Context > m_context
Definition: FWFFService.h:71
const std::string & geometryFilename(void)
void postEndJob()
Definition: FWFFService.cc:213
void disableNext()
void setConfigFilename(const std::string &f)
virtual void checkPosition()
Definition: FWFFService.cc:221
T get(const Candidate &c)
Definition: component.h:55
Definition: Run.h:43
void watchPostBeginJob(PostBeginJob::slot_type const &iSlot)
convenience function for attaching to signal
bool m_firstTime
Definition: FWFFService.h:82