CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EveService.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Fireworks/Eve
4 // Class : EveService
5 //
6 // Implementation:
7 // [Notes on implementation]
8 //
9 // Original Author: Matevz Tadel
10 // Created: Fri Jun 25 18:57:39 CEST 2010
11 //
12 
13 // system include files
14 #include <iostream>
15 
16 // user include files
18 
21 
22 #include "TROOT.h"
23 #include "TSystem.h"
24 #include "TColor.h"
25 #include "TStyle.h"
26 #include "TEnv.h"
27 
28 // To extract coil current from ConditionsDB
33 
34 // To extract coil current from ConditionsInEdm
38 
39 #include "TROOT.h"
40 #include "TSystem.h"
41 #include "TRint.h"
42 #include "TEveManager.h"
43 #include "TEveEventManager.h"
44 #include "TEveTrackPropagator.h"
45 
46 // GUI widgets
47 #include "TEveBrowser.h"
48 #include "TGFrame.h"
49 #include "TGButton.h"
50 #include "TGLabel.h"
51 
52 namespace
53 {
54  class CmsEveMagField : public TEveMagField
55  {
56  private:
57  Float_t fField;
58  Float_t fFieldMag;
59 
60  public:
61 
62  CmsEveMagField() : TEveMagField(), fField(-3.8), fFieldMag(3.8) {}
63  virtual ~CmsEveMagField() {}
64 
65  // set current
66  void SetFieldByCurrent(Float_t avg_current)
67  {
68  fField = -3.8 * avg_current / 18160.0;
69  fFieldMag = TMath::Abs(fField);
70  }
71 
72  // get field values
73  virtual Float_t GetMaxFieldMag() const override
74  {
75  return fFieldMag;
76  }
77 
78  virtual TEveVector GetField(Float_t x, Float_t y, Float_t z) const override
79  {
80  static const Float_t barrelFac = 1.2 / 3.8;
81  static const Float_t endcapFac = 2.0 / 3.8;
82 
83  const Float_t R = sqrt(x*x+y*y);
84  const Float_t absZ = TMath::Abs(z);
85 
86  //barrel
87  if (absZ < 724.0f)
88  {
89  //inside solenoid
90  if (R < 300.0f) return TEveVector(0, 0, fField);
91 
92  // outside solinoid
93  if ((R > 461.0f && R < 490.5f) ||
94  (R > 534.5f && R < 597.5f) ||
95  (R > 637.0f && R < 700.0f))
96  {
97  return TEveVector(0, 0, -fField*barrelFac);
98  }
99  } else {
100  if ((absZ > 724.0f && absZ < 786.0f) ||
101  (absZ > 850.0f && absZ < 910.0f) ||
102  (absZ > 975.0f && absZ < 1003.0f))
103  {
104  const Float_t fac = (z >= 0 ? fField : -fField) * endcapFac / R;
105  return TEveVector(x*fac, y*fac, 0);
106  }
107  }
108  return TEveVector(0, 0, 0);
109  }
110  };
111 }
112 
113 //
114 // constants, enums and typedefs
115 //
116 
117 //
118 // static data member definitions
119 //
120 
121 //==============================================================================
122 // constructors and destructor
123 //==============================================================================
124 
126  m_EveManager(0), m_Rint(0),
127  m_MagField(0),
128  m_AllowStep(true), m_ShowEvent(true),
129  m_ContinueButton(0), m_StepButton(0), m_StepLabel(0)
130 {
131  printf("EveService::EveService CTOR\n");
132 
133  std::cout <<" gApplication "<< gApplication <<std::endl;
134  std::cout <<" is batch " << gROOT->IsBatch() <<std::endl;
135  std::cout <<" display " << gSystem->Getenv("DISPLAY") <<std::endl;
136 
137  const char* dummyArgvArray[] = {"cmsRun"};
138  char** dummyArgv = const_cast<char**>(dummyArgvArray);
139  int dummyArgc = 1;
140 
141  m_Rint = new TRint("App", &dummyArgc, dummyArgv);
142  assert(TApplication::GetApplications()->GetSize());
143 
144  gROOT->SetBatch(kFALSE);
145  std::cout<<"calling NeedGraphicsLibs()"<<std::endl;
146  TApplication::NeedGraphicsLibs();
147 
148  m_EveManager = TEveManager::Create();
149 
150  m_EveManager->AddEvent(new TEveEventManager("Event", "Event Data"));
151 
152  m_MagField = new CmsEveMagField();
153 
155 
156  // ----------------------------------------------------------------
157 
160 
162 
164 }
165 
167 {
168  printf("EveService::~EveService DTOR\n");
169 
170  delete m_MagField;
171 }
172 
173 
174 //==============================================================================
175 // Service watchers
176 //==============================================================================
177 
179 {
180  printf("EveService::postBeginJob\n");
181 
182  // Show the GUI ...
183  gSystem->ProcessEvents();
184 }
185 
187 {
188  printf("EveService::postEndJob\n");
189 
190  TEveManager::Terminate();
191 }
192 
193 //------------------------------------------------------------------------------
194 
196 {
197  float current = 18160.0f;
198  /*
199  try
200  {
201  edm::Handle<edm::ConditionsInRunBlock> runCond;
202  bool res = iRun.getByLabel("conditionsInEdm", runCond);
203  if (res && runCond.isValid())
204  {
205  printf("Got current from conds in edm %f\n", runCond->BAvgCurrent);
206  current = runCond->BAvgCurrent;
207  }
208  else
209  {
210  printf("Could not extract run-conditions get-result=%d, is-valid=%d\n", res, runCond.isValid());
211 
212  edm::ESHandle<RunInfo> sum;
213  iSetup.get<RunInfoRcd>().get(sum);
214 
215  current = sum->m_avg_current;
216  printf("Got current from RunInfoRcd %f\n", sum->m_avg_current);
217  }
218  }
219  catch (...)
220  {
221  }
222  */
223  printf("RunInfo not available \n");
224  static_cast<CmsEveMagField*>(m_MagField)->SetFieldByCurrent(current);
225 }
226 
227 //------------------------------------------------------------------------------
228 
230 {
231  printf("EveService::postProcessEvent: Starting GUI loop.\n");
232 
233  m_StepButton->SetEnabled(kFALSE);
234  m_ContinueButton->SetEnabled(kFALSE);
235  m_StepLabel->SetText("");
236 
237  if (m_ShowEvent)
238  {
239  gEve->Redraw3D();
240  m_Rint->Run(kTRUE);
241  }
242  m_ShowEvent = true;
243  m_AllowStep = true;
244 
245  gEve->GetCurrentEvent()->DestroyElements();
246 }
247 
248 //------------------------------------------------------------------------------
249 
251 {
252  // Display whatever was registered so far, wait until user presses
253  // the "Step" button.
254 
255  if (m_AllowStep)
256  {
257  m_ContinueButton->SetEnabled(kTRUE);
258  m_StepButton->SetEnabled(kTRUE);
259  m_StepLabel->SetText(info.c_str());
260  gEve->Redraw3D();
261  m_Rint->Run(kTRUE);
262  }
263 }
264 
265 //==============================================================================
266 // Getters for cleints
267 //==============================================================================
268 
270 {
271  gEve = m_EveManager;
272  return m_EveManager;
273 }
274 
275 TEveMagField* EveService::getMagField()
276 {
277  return m_MagField;
278 }
279 void EveService::setupFieldForPropagator(TEveTrackPropagator* prop)
280 {
281  prop->SetMagFieldObj(m_MagField, kFALSE);
282 }
283 
284 //==============================================================================
285 // Redirectors to gEve
286 //==============================================================================
287 
288 void EveService::AddElement(TEveElement* el)
289 {
290  m_EveManager->AddElement(el);
291 }
292 
293 void EveService::AddGlobalElement(TEveElement* el)
294 {
295  m_EveManager->AddGlobalElement(el);
296 }
297 
298 //==============================================================================
299 // GUI Builders and callback slots
300 //==============================================================================
301 
302 namespace
303 {
304  TGTextButton*
305  MkTxtButton(TGCompositeFrame* p, const char* txt, Int_t width=0,
306  Int_t lo=0, Int_t ro=0, Int_t to=0, Int_t bo=0)
307  {
308  // Create a standard button.
309  // If width is not zero, the fixed-width flag is set.
310 
311  TGTextButton* b = new TGTextButton(p, txt);
312  if (width > 0) {
313  b->SetWidth(width);
314  b->ChangeOptions(b->GetOptions() | kFixedWidth);
315  }
316  p->AddFrame(b, new TGLayoutHints(kLHintsNormal, lo,ro,to,bo));
317  return b;
318  }
319 }
320 
322 {
323  const TString cls("EveService");
324 
325  TEveBrowser *browser = gEve->GetBrowser();
326  browser->StartEmbedding(TRootBrowser::kBottom);
327 
328  TGMainFrame *mf = new TGMainFrame(gClient->GetRoot(), 400, 100, kVerticalFrame);
329 
330  TGHorizontalFrame* f = new TGHorizontalFrame(mf);
331  mf->AddFrame(f, new TGLayoutHints(kLHintsExpandX, 0,0,2,2));
332 
333  MkTxtButton(f, "Exit", 100, 2, 2)->
334  Connect("Clicked()", cls, this, "slotExit()");
335 
336  MkTxtButton(f, "Next Event", 100, 2, 2)->
337  Connect("Clicked()", cls, this, "slotNextEvent()");
338 
339  m_ContinueButton = MkTxtButton(f, "Continue", 100, 2, 2);
340  m_ContinueButton->Connect("Clicked()", cls, this, "slotContinue()");
341 
342  m_StepButton = MkTxtButton(f, "Step", 100, 2, 2);
343  m_StepButton->Connect("Clicked()", cls, this, "slotStep()");
344 
345  m_StepLabel = new TGLabel(mf, "");
346  m_StepLabel->SetTextJustify(kTextTop | kTextLeft);
347  mf->AddFrame(m_StepLabel, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY, 2, 2, 2, 2));
348 
349  mf->SetCleanup(kDeepCleanup);
350  mf->Layout();
351  mf->MapSubwindows();
352  mf->MapWindow();
353 
354  browser->StopEmbedding("EventCtrl");
355 }
356 
358 {
359  gSystem->ExitLoop();
360  printf("EveService exiting on user request.\n");
361 
362  // Throwing exception here is bad because:
363  // a) it does not work when in a "debug step";
364  // b) does not restore terminal state.
365  // So we do exit instead for now.
366  // throw cms::Exception("UserTerminationRequest");
367 
368  gSystem->Exit(0);
369 }
370 
372 {
373  gSystem->ExitLoop();
374  m_ShowEvent = false;
375  m_AllowStep = false;
376 }
377 
379 {
380  gSystem->ExitLoop();
381  m_AllowStep = false;
382 }
383 
385 {
386  gSystem->ExitLoop();
387 }
void postEvent(edm::StreamContext const &)
Definition: EveService.cc:229
void postBeginJob()
Definition: EveService.cc:178
static const TGPicture * info(bool iBackgroundIsBlack)
TGLabel * m_StepLabel
Definition: EveService.h:99
void watchPostEndJob(PostEndJob::slot_type const &iSlot)
void slotContinue()
Definition: EveService.cc:378
EveService(const edm::ParameterSet &, edm::ActivityRegistry &)
Definition: EveService.cc:125
void watchPostEvent(PostEvent::slot_type const &iSlot)
assert(m_qm.get())
void postEndJob()
Definition: EveService.cc:186
TGTextButton * m_ContinueButton
Definition: EveService.h:97
void slotExit()
Definition: EveService.cc:357
void watchPostGlobalBeginRun(PostGlobalBeginRun::slot_type const &iSlot)
T sqrt(T t)
Definition: SSEVec.h:18
TEveMagField * getMagField()
Definition: EveService.cc:275
T Abs(T a)
Definition: MathUtil.h:49
double f[11][100]
TGTextButton * m_StepButton
Definition: EveService.h:98
void slotStep()
Definition: EveService.cc:384
void display(const std::string &info="")
Definition: EveService.cc:250
bool m_ShowEvent
Definition: EveService.h:95
void postGlobalBeginRun(edm::GlobalContext const &)
Definition: EveService.cc:195
TEveManager * getManager()
Definition: EveService.cc:269
TEveManager * m_EveManager
Definition: EveService.h:89
double b
Definition: hdecay.h:120
void createEventNavigationGUI()
Definition: EveService.cc:321
void setupFieldForPropagator(TEveTrackPropagator *prop)
Definition: EveService.cc:279
bool m_AllowStep
Definition: EveService.h:94
void AddElement(TEveElement *el)
Definition: EveService.cc:288
virtual ~EveService()
Definition: EveService.cc:166
void slotNextEvent()
Definition: EveService.cc:371
tuple cout
Definition: gather_cfg.py:145
TEveMagField * m_MagField
Definition: EveService.h:92
void AddGlobalElement(TEveElement *el)
Definition: EveService.cc:293
TRint * m_Rint
Definition: EveService.h:90
void watchPostBeginJob(PostBeginJob::slot_type const &iSlot)
convenience function for attaching to signal