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