MpdEventManagerEditor.cxx 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. // MpdEventManagerEditor
  2. //
  3. // Specialization of TGedEditor for proper update propagation to TEveManager
  4. #include "MpdEventManagerEditor.h"
  5. #include "FairRootManager.h"
  6. #include "FairRunAna.h"
  7. #include "TChain.h"
  8. #include "TFile.h"
  9. #include "TGLayout.h"
  10. #include "TGeoManager.h"
  11. #include "TString.h"
  12. #include "TEveManager.h"
  13. #include "TEveElement.h"
  14. #include "TGWindow.h"
  15. #include <TGLViewer.h>
  16. #include <TGLScenePad.h>
  17. #include "TEveBrowser.h"
  18. #include "TEveGedEditor.h"
  19. #include "TGFileDialog.h"
  20. #include "TThread.h"
  21. #include "TVirtualX.h"
  22. #include <iostream>
  23. #include <vector>
  24. using namespace std;
  25. #define MAX_ENERGY 12
  26. //______________________________________________________________________________
  27. MpdEventManagerEditor::MpdEventManagerEditor(const TGWindow* p, Int_t width, Int_t height, UInt_t options, Pixel_t back)
  28. : TGedFrame(p, width, height, options | kVerticalFrame, back),
  29. fObject(0),
  30. fEventManager(MpdEventManager::Instance()),
  31. fEventTime(nullptr),
  32. fCurrentPDG(0),
  33. fVizPri(0),
  34. fMinEnergy(0),
  35. fMaxEnergy(0),
  36. isMagnetFound(false),
  37. iThreadState(0),
  38. iEventCount(-1),
  39. isStreamSource(false),
  40. fCurrentEvent(0)
  41. {
  42. fEventManager->SetEventEditor(this);
  43. Init();
  44. }
  45. void MpdEventManagerEditor::Init()
  46. {
  47. FairRootManager* fRootManager = FairRootManager::Instance();
  48. TChain* chain = fRootManager->GetInChain();
  49. // create tab for event visualization
  50. MakeTitle("EventManager Editor");
  51. TGVerticalFrame* fInfoFrame = CreateEditorTabSubFrame("Event Info");
  52. TGCompositeFrame* title1 = new TGCompositeFrame(fInfoFrame, 250, 10, kVerticalFrame | kLHintsExpandX | kFixedWidth | kOwnBackground);
  53. // display file name (or stream name if no input file)
  54. TString InSource = "File: ";
  55. TFile* pChainFile = chain->GetFile();
  56. if (pChainFile == nullptr)
  57. {
  58. InSource = "Data Stream";
  59. isStreamSource = true;
  60. }
  61. else
  62. InSource += pChainFile->GetName();
  63. TGLabel* TFName = new TGLabel(title1, InSource.Data());
  64. title1->AddFrame(TFName);
  65. // textbox for Run ID and time cutting
  66. TGHorizontalFrame* f2 = new TGHorizontalFrame(title1);
  67. // Run Id
  68. UInt_t RunId = FairRunAna::Instance()->getRunId();
  69. TString run = TString::Format("Run Id: %d. ", RunId);
  70. TGLabel* TRunId = new TGLabel(f2, run.Data());
  71. // time cutting
  72. TGLabel* EventTimeLabel = new TGLabel(f2, " Event Time: ");
  73. fEventTime = new TGLabel(f2,"");
  74. f2->AddFrame(TRunId);
  75. f2->AddFrame(EventTimeLabel);
  76. f2->AddFrame(fEventTime);
  77. title1->AddFrame(f2);
  78. // display event time
  79. TString time = TString::Format("%.2f ns", FairRootManager::Instance()->GetEventTime());
  80. fEventTime->SetText(time.Data());
  81. // display event count and count of geometry nodes
  82. iEventCount = chain->GetEntriesFast();
  83. Int_t nodes = gGeoManager->GetNNodes();
  84. TString nevent = TString::Format("No of events: %d. No. of nodes: %d", iEventCount, nodes);
  85. TGLabel* TEvent = new TGLabel(title1, nevent.Data());
  86. title1->AddFrame(TEvent);
  87. // setting textbox for event number
  88. TGHorizontalFrame* f = new TGHorizontalFrame(title1);
  89. TGLabel* l = new TGLabel(f, "Current Event:");
  90. f->AddFrame(l, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 1, 2, 1, 1));
  91. fCurrentEvent = new TGNumberEntry(f, 0., 6, -1,
  92. TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative, TGNumberFormat::kNELLimitMinMax, 0, iEventCount-1);
  93. f->AddFrame(fCurrentEvent, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
  94. fCurrentEvent->Connect("ValueSet(Long_t)","MpdEventManagerEditor", this, "SelectEvent()");
  95. // if event count is 0 then deactivate the field for event number
  96. if (iEventCount < 1)
  97. fCurrentEvent->SetState(kFALSE);
  98. // button for saving the current image (EVE screenshot)
  99. fSave = new TGPictureButton(f, gClient->GetPicture("save.xpm"), 5);
  100. f->AddFrame(fSave, new TGLayoutHints(kLHintsLeft| kLHintsCenterY, 1, 2, 1, 1));
  101. fSave->Connect("Clicked()", "MpdEventManagerEditor", this, "SaveImage()");
  102. title1->AddFrame(f);
  103. // checkbox to display only primary particles in event
  104. fVizPri = new TGCheckButton(title1, "Primary Only");
  105. AddFrame(fVizPri, new TGLayoutHints(kLHintsTop, 3, 1, 1, 0));
  106. fVizPri->Connect("Toggled(Bool_t)", "MpdEventManagerEditor", this, "DoVizPri()");
  107. title1->AddFrame(fVizPri);
  108. // textbox to display only particles with given PDG
  109. TGHorizontalFrame* f1 = new TGHorizontalFrame(title1);
  110. TGLabel* L1 = new TGLabel(f1, "Select PDG: ");
  111. f1->AddFrame(L1, new TGLayoutHints(kLHintsLeft|kLHintsCenterY, 1, 2, 1, 1));
  112. fCurrentPDG = new TGNumberEntry(f1, 0., 12, -1,
  113. TGNumberFormat::kNESInteger, TGNumberFormat::kNEAAnyNumber, TGNumberFormat::kNELNoLimits, 0, 1);
  114. f1->AddFrame(fCurrentPDG, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
  115. fCurrentPDG->Connect("ValueSet(Long_t)","MpdEventManagerEditor", this, "SelectPDG()");
  116. title1->AddFrame(f1);
  117. // textbox for min energy cutting
  118. fMinEnergy = new TEveGValuator(title1, "Min Energy:", 90, 0);
  119. fMinEnergy->SetNELength(5);
  120. fMinEnergy->SetLabelWidth(80);
  121. fMinEnergy->Build();
  122. fMinEnergy->SetLimits(0, MAX_ENERGY, 2001, TGNumberFormat::kNESRealOne);
  123. fMinEnergy->SetToolTip("Minimum energy of displayed tracks");
  124. fMinEnergy->SetValue(0);
  125. fMinEnergy->Connect("ValueSet(Double_t)", "MpdEventManagerEditor", this, "MinEnergy()");
  126. title1->AddFrame(fMinEnergy, new TGLayoutHints(kLHintsTop, 1, 1, 1, 0));
  127. fEventManager->SetMinEnergy(0);
  128. // textbox for max energy cutting
  129. fMaxEnergy = new TEveGValuator(title1, "Max Energy:", 90, 0);
  130. fMaxEnergy->SetNELength(5);
  131. fMaxEnergy->SetLabelWidth(80);
  132. fMaxEnergy->Build();
  133. fMaxEnergy->SetLimits(0, MAX_ENERGY, 2001, TGNumberFormat::kNESRealOne);
  134. fMaxEnergy->SetToolTip("Maximum energy of displayed tracks");
  135. fMaxEnergy->SetValue(MAX_ENERGY);
  136. fMaxEnergy->Connect("ValueSet(Double_t)", "MpdEventManagerEditor", this, "MaxEnergy()");
  137. title1->AddFrame(fMaxEnergy, new TGLayoutHints(kLHintsTop, 1, 1, 1, 0));
  138. fEventManager->SetMaxEnergy(MAX_ENERGY);
  139. fGeometryFrame = new TGHorizontalFrame(title1);
  140. // button: whether show detector geometry or not
  141. fGeometry = new TGCheckButton(fGeometryFrame, "show geometry");
  142. fGeometryFrame->AddFrame(fGeometry, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 5,5,1,1));
  143. fGeometry->Connect("Toggled(Bool_t)", "MpdEventManagerEditor", this, "ShowGeometry(Bool_t)");
  144. fGeometry->SetOn();
  145. // button: whether show magnet or not
  146. TGeoVolume* magnet = gGeoManager->FindVolumeFast("Magnet");
  147. if (magnet)
  148. {
  149. isMagnetFound = true;
  150. ShowMagnetButton = new TGCheckButton(fGeometryFrame, "show magnet");
  151. fGeometryFrame->AddFrame(ShowMagnetButton, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 5,5,1,1));
  152. ShowMagnetButton->Connect("Toggled(Bool_t)", "MpdEventManagerEditor", this, "ShowMagnet(Bool_t)");
  153. ShowMagnetButton->SetOn();
  154. }
  155. title1->AddFrame(fGeometryFrame);
  156. // button for high transparency of detectors' geometry to highlight event objects
  157. TGCheckButton* fTransparency = new TGCheckButton(title1, "high transparency");
  158. title1->AddFrame(fTransparency, new TGLayoutHints(kLHintsRight | kLHintsExpandX, 5,5,1,1));
  159. fTransparency->Connect("Toggled(Bool_t)", "MpdEventManagerEditor", this, "SwitchTransparency(Bool_t)");
  160. // button for switching from black to white background
  161. TGCheckButton* backgroundButton = new TGCheckButton(title1, "light background");
  162. title1->AddFrame(backgroundButton, new TGLayoutHints(kLHintsRight | kLHintsExpandX, 5,5,1,1));
  163. backgroundButton->Connect("Toggled(Bool_t)", "MpdEventManagerEditor", this, "SwitchBackground(Bool_t)");
  164. if (!fEventManager->isDarkColor)
  165. {
  166. backgroundButton->SetOn();
  167. gEve->GetViewers()->SwitchColorSet();
  168. }
  169. // group for displaying simulation and reconstruction data
  170. TGGroupFrame* groupData = new TGGroupFrame(title1, "Show MC and reco data");
  171. groupData->SetTitlePos(TGGroupFrame::kCenter);
  172. TGHorizontalFrame* framePointsInfo = new TGHorizontalFrame(groupData);
  173. // button for show|hide MC points
  174. fShowMCPoints = new TGCheckButton(framePointsInfo, "MC points");
  175. framePointsInfo->AddFrame(fShowMCPoints, new TGLayoutHints(kLHintsNormal, 0,0,0,0));
  176. fShowMCPoints->Connect("Toggled(Bool_t)", "MpdEventManagerEditor", this, "ShowMCPoints(Bool_t)");
  177. fShowMCPoints->SetDisabledAndSelected(kFALSE);
  178. // button for show|hide reconstructed points
  179. fShowRecoPoints = new TGCheckButton(framePointsInfo, "Reco points");
  180. framePointsInfo->AddFrame(fShowRecoPoints, new TGLayoutHints(kLHintsRight, 0,0,1,0));
  181. fShowRecoPoints->Connect("Toggled(Bool_t)", "MpdEventManagerEditor", this, "ShowRecoPoints(Bool_t)");
  182. fShowRecoPoints->SetDisabledAndSelected(kFALSE);
  183. groupData->AddFrame(framePointsInfo, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 1,1,5,0));
  184. TGHorizontalFrame* frameTracksInfo = new TGHorizontalFrame(groupData);
  185. // button for show|hide MC tracks
  186. fShowMCTracks = new TGCheckButton(frameTracksInfo, "MC tracks");
  187. frameTracksInfo->AddFrame(fShowMCTracks, new TGLayoutHints(kLHintsNormal, 0,0,0,0));
  188. fShowMCTracks->Connect("Toggled(Bool_t)", "MpdEventManagerEditor", this, "ShowMCTracks(Bool_t)");
  189. fShowMCTracks->SetDisabledAndSelected(kFALSE);
  190. // button for show|hide reco tracks
  191. fShowRecoTracks = new TGCheckButton(frameTracksInfo, "Reco tracks");
  192. frameTracksInfo->AddFrame(fShowRecoTracks, new TGLayoutHints(kLHintsRight, 0,0,1,0));
  193. fShowRecoTracks->Connect("Toggled(Bool_t)", "MpdEventManagerEditor", this, "ShowRecoTracks(Bool_t)");
  194. fShowRecoTracks->SetDisabledAndSelected(kFALSE);
  195. groupData->AddFrame(frameTracksInfo, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 1,1,5,0));
  196. title1->AddFrame(groupData, new TGLayoutHints(kLHintsRight | kLHintsExpandX, 3,15,1,1));
  197. // button for update of event visualization
  198. if (fEventManager->isOnline)
  199. fUpdate = new TGTextButton(title1, "Start online display");
  200. else
  201. fUpdate = new TGTextButton(title1, "Update event");
  202. title1->AddFrame(fUpdate, new TGLayoutHints(kLHintsRight | kLHintsExpandX, 3,15,1,1));
  203. fUpdate->Connect("Clicked()", "MpdEventManagerEditor", this, "UpdateEvent()");
  204. // add all frame above to "event info" tab
  205. fInfoFrame->AddFrame(title1, new TGLayoutHints(kLHintsTop, 0, 0, 2, 0));
  206. if ((iEventCount < 1) && (!isStreamSource))
  207. {
  208. fUpdate->SetEnabled(kFALSE);
  209. return;
  210. }
  211. // read first event in Offline mode
  212. if (!fEventManager->isOnline) fEventManager->GotoEvent(0);
  213. // update tab controls
  214. Update();
  215. }
  216. // set flag: show all particles or only primary
  217. void MpdEventManagerEditor::DoVizPri()
  218. {
  219. if (fVizPri->IsOn())
  220. fEventManager->SetPriOnly(kTRUE);
  221. else
  222. fEventManager->SetPriOnly(kFALSE);
  223. }
  224. // select displaying particle by PDG code
  225. void MpdEventManagerEditor::SelectPDG()
  226. {
  227. fEventManager->SelectPDG(fCurrentPDG->GetIntNumber());
  228. }
  229. //______________________________________________________________________________
  230. void MpdEventManagerEditor::MinEnergy()
  231. {
  232. fEventManager->SetMinEnergy(fMinEnergy->GetValue());
  233. }
  234. //______________________________________________________________________________
  235. void MpdEventManagerEditor::MaxEnergy()
  236. {
  237. fEventManager->SetMaxEnergy(fMaxEnergy->GetValue());
  238. }
  239. // show or hide detector geometry
  240. void MpdEventManagerEditor::ShowGeometry(Bool_t is_show)
  241. {
  242. // set cursor HourClock
  243. gVirtualX->SetCursor(gEve->GetMainWindow()->GetId(), gVirtualX->CreateCursor(kWatch));
  244. gVirtualX->SetCursor(gEve->GetLTEFrame()->GetListTree()->GetId(), gVirtualX->CreateCursor(kWatch));
  245. gVirtualX->SetCursor(gEve->GetLTEFrame()->GetEditor()->GetId(), gVirtualX->CreateCursor(kWatch));
  246. gEve->GetGlobalScene()->SetRnrState(is_show);
  247. if (!fEventManager->isOnline)
  248. {
  249. fEventManager->GetRPhiScene()->SetRnrState(is_show);
  250. fEventManager->GetRhoZScene()->SetRnrState(is_show);
  251. }
  252. // disable "Magnet Show" box after hiding of detector geometry
  253. if (isMagnetFound)
  254. {
  255. if (!is_show)
  256. fGeometryFrame->HideFrame(ShowMagnetButton);
  257. else
  258. fGeometryFrame->ShowFrame(ShowMagnetButton);
  259. }
  260. gEve->Redraw3D();
  261. // set cursor Pointer
  262. gSystem->ProcessEvents();
  263. gVirtualX->SetCursor(gEve->GetMainWindow()->GetId(), gVirtualX->CreateCursor(kPointer));
  264. gVirtualX->SetCursor(gEve->GetLTEFrame()->GetListTree()->GetId(), gVirtualX->CreateCursor(kPointer));
  265. gVirtualX->SetCursor(gEve->GetLTEFrame()->GetEditor()->GetId(), gVirtualX->CreateCursor(kPointer));
  266. }
  267. // show or hide magnet
  268. void MpdEventManagerEditor::ShowMagnet(Bool_t is_show)
  269. {
  270. TGeoVolume* magnet = gGeoManager->FindVolumeFast("Magnet");
  271. if (!magnet)
  272. {
  273. cout<<"ERROR: There is no magnet with given name: Magnet"<<endl;
  274. return;
  275. }
  276. magnet->SetVisibility(is_show);
  277. magnet->VisibleDaughters(is_show);
  278. if (gEve->GetGlobalScene()->GetRnrState())
  279. {
  280. gEve->GetGlobalScene()->SetRnrState(kFALSE);
  281. gEve->GetGlobalScene()->SetRnrState(kTRUE);
  282. gEve->Redraw3D();
  283. }
  284. }
  285. // switch between light and dark background
  286. void MpdEventManagerEditor::SwitchBackground(Bool_t is_on)
  287. {
  288. gEve->GetViewers()->SwitchColorSet();
  289. }
  290. // set transparency to high value (80%)
  291. void MpdEventManagerEditor::SwitchTransparency(Bool_t is_on)
  292. {
  293. fEventManager->SetTransparentGeometry(is_on);
  294. if (gEve->GetGlobalScene()->GetRnrState())
  295. {
  296. gEve->GetGlobalScene()->SetRnrState(kFALSE);
  297. gEve->GetGlobalScene()->SetRnrState(kTRUE);
  298. gEve->Redraw3D();
  299. }
  300. }
  301. // show|hide MC points
  302. void MpdEventManagerEditor::ShowMCPoints(Bool_t is_show)
  303. {
  304. /*
  305. TEveElement::List_t matches;
  306. TPRegexp* regexp = new TPRegexp("(\\w+)Point\\b");
  307. Int_t numFound = fEventManager->FindChildren(matches, *regexp);
  308. if (numFound > 0)
  309. {
  310. for (TEveElement::List_i p = matches.begin(); p != matches.end(); ++p)
  311. (*p)->SetRnrState(is_show);
  312. }
  313. */
  314. TEveElement* points = fEventManager->FindChild("MC points");
  315. if (points == nullptr)
  316. {
  317. cout<<"There is no information about MC points"<<endl;
  318. fShowMCPoints->SetDisabledAndSelected(kFALSE);
  319. return;
  320. }
  321. points->SetRnrState(is_show);
  322. // highlight ZDC modules if ZDC present
  323. if (fEventManager->isZDCModule)
  324. {
  325. if (is_show)
  326. RedrawZDC(false);
  327. else
  328. RedrawZDC(true);
  329. }
  330. // redraw points
  331. gEve->Redraw3D();
  332. }
  333. bool MpdEventManagerEditor::RedrawZDC(bool isFull, bool isRedraw)
  334. {
  335. TGeoVolume* curVolume = gGeoManager->GetVolume("VETO");
  336. if (!curVolume)
  337. {
  338. cout<<"ERROR: There is no volume with given name: VETO"<<endl;
  339. return false;
  340. }
  341. else
  342. {
  343. int i = 0;
  344. for (; i < 68; i++)
  345. {
  346. TGeoNode* child = curVolume->FindNode(Form("VMDL_%d", i+1));
  347. if (child == nullptr)
  348. continue;
  349. //cout<<"Node: "<<child->GetName()<<". Number is equal "<<i<<endl;
  350. if (isFull)
  351. {
  352. if (fEventManager->isZDCModule[i] == false)
  353. {
  354. child->SetVisibility(true);
  355. child->VisibleDaughters(true);
  356. }
  357. }
  358. else
  359. {
  360. child->SetVisibility(fEventManager->isZDCModule[i]);
  361. child->VisibleDaughters(fEventManager->isZDCModule[i]);
  362. }
  363. }
  364. for (; i < 104; i++)
  365. {
  366. TGeoNode* child = curVolume->FindNode(Form("UMDL_%d", i+1-68));
  367. if (child == nullptr)
  368. continue;
  369. //cout<<"Node: "<<child->GetName()<<". Number is equal "<<i<<endl;
  370. if (isFull)
  371. {
  372. if (fEventManager->isZDCModule[i] == false)
  373. {
  374. child->SetVisibility(true);
  375. child->VisibleDaughters(true);
  376. }
  377. }
  378. else
  379. {
  380. child->SetVisibility(fEventManager->isZDCModule[i]);
  381. child->VisibleDaughters(fEventManager->isZDCModule[i]);
  382. }
  383. }
  384. if ((isFull || isRedraw) && (gEve->GetGlobalScene()->GetRnrState()))
  385. {
  386. gEve->GetGlobalScene()->SetRnrState(kFALSE);
  387. gEve->GetGlobalScene()->SetRnrState(kTRUE);
  388. return true;
  389. }
  390. }// else - ZDC detector was found
  391. return false;
  392. }
  393. //______________________________________________________________________________
  394. void MpdEventManagerEditor::ShowMCTracks(Bool_t is_show)
  395. {
  396. TEveElement* tracks = fEventManager->FindChild("MC tracks");
  397. if (tracks == nullptr)
  398. {
  399. cout<<"There is no information about MC tracks"<<endl;
  400. fShowMCTracks->SetDisabledAndSelected(kFALSE);
  401. return;
  402. }
  403. tracks->SetRnrState(is_show);
  404. gEve->Redraw3D();
  405. }
  406. //______________________________________________________________________________
  407. void MpdEventManagerEditor::ShowRecoPoints(Bool_t is_show)
  408. {
  409. TEveElement* points = fEventManager->FindChild("Reco points");
  410. if (points == nullptr)
  411. {
  412. cout<<"There is no information about reconstructed points"<<endl;
  413. fShowRecoPoints->SetDisabledAndSelected(kFALSE);
  414. return;
  415. }
  416. fEventManager->fgShowRecoPointsIsShow = is_show;
  417. // exec event visualization of selected event
  418. if (fEventManager->fgRedrawRecoPointsReqired)
  419. fEventManager->GotoEvent(fCurrentEvent->GetIntNumber());
  420. points->SetRnrState(is_show);
  421. gEve->Redraw3D();
  422. }
  423. //______________________________________________________________________________
  424. void MpdEventManagerEditor::ShowRecoTracks(Bool_t is_show)
  425. {
  426. TEveElement* tracks = fEventManager->FindChild("Reco tracks");
  427. if (tracks == nullptr)
  428. {
  429. cout<<"There is no information about reconstructed tracks"<<endl;
  430. fShowRecoTracks->SetDisabledAndSelected(kFALSE);
  431. return;
  432. }
  433. tracks->SetRnrState(is_show);
  434. gEve->Redraw3D();
  435. }
  436. void MpdEventManagerEditor::SaveImage()
  437. {
  438. const char* filetypes[] = {"PNG", "*.png", "JPG", "*.jpg", 0, 0};
  439. TGFileInfo fi;
  440. fi.fFileTypes = filetypes;
  441. fi.fIniDir = StrDup(".");
  442. new TGFileDialog(gClient->GetRoot(), gEve->GetMainWindow(), kFDSave, &fi);
  443. printf("Saving file: %s (dir: %s)\n", fi.fFilename, fi.fIniDir);
  444. gEve->GetDefaultGLViewer()-> SavePicture(fi.fFilename);
  445. return;
  446. }
  447. // update event display when setting event number in textbox
  448. void MpdEventManagerEditor::SelectEvent()
  449. {
  450. // if OFFLINE mode
  451. if (!fEventManager->isOnline)
  452. {
  453. int iOldEvent = fEventManager->GetCurrentEvent(), iNewEvent = fCurrentEvent->GetIntNumber();
  454. // exec event visualization of selected event
  455. fEventManager->GotoEvent(iNewEvent);
  456. if ((fEventManager->isZDCModule) && (fShowMCPoints->IsOn()))
  457. RedrawZDC(false);
  458. if (iOldEvent != iNewEvent)
  459. {
  460. // display event time
  461. TString time = TString::Format("%.2f ns", FairRootManager::Instance()->GetEventTime());
  462. fEventTime->SetText(time.Data());
  463. // display new min and max energy limits given by event energy range
  464. fMinEnergy->SetLimits(fEventManager->GetEvtMinEnergy(), fEventManager->GetEvtMaxEnergy(), 2001);
  465. fMinEnergy->SetValue(fEventManager->GetEvtMinEnergy());
  466. fMaxEnergy->SetLimits(fEventManager->GetEvtMinEnergy(), fEventManager->GetEvtMaxEnergy(), 2001);
  467. fMaxEnergy->SetValue(fEventManager->GetEvtMaxEnergy());
  468. }
  469. // update tab controls
  470. Update();
  471. return;
  472. }
  473. /*// update all scenes
  474. fEventManager->fRPhiView->GetGLViewer()->UpdateScene(kTRUE);
  475. fEventManager->fRhoZView->GetGLViewer()->UpdateScene(kTRUE);
  476. fEventManager->fMulti3DView->GetGLViewer()->UpdateScene(kTRUE);
  477. fEventManager->fMultiRPhiView->GetGLViewer()->UpdateScene(kTRUE);
  478. fEventManager->fMultiRhoZView->GetGLViewer()->UpdateScene(kTRUE);*/
  479. }
  480. // clicking 'Update event' button to update event display OR 'Start online display' button to start/stop online event display
  481. void MpdEventManagerEditor::UpdateEvent()
  482. {
  483. if (iThreadState == 1)
  484. {
  485. iThreadState = 0;
  486. return;
  487. }
  488. // if OFFLINE mode
  489. if (!fEventManager->isOnline)
  490. {
  491. int iOldEvent = fEventManager->GetCurrentEvent(), iNewEvent = fCurrentEvent->GetIntNumber();
  492. // exec event visualization of selected event
  493. fEventManager->GotoEvent(iNewEvent);
  494. if ((fEventManager->isZDCModule) && (fShowMCPoints->IsOn()))
  495. RedrawZDC(false);
  496. if (iOldEvent != iNewEvent)
  497. {
  498. // display event time
  499. TString time = TString::Format("%.2f ns", FairRootManager::Instance()->GetEventTime());
  500. fEventTime->SetText(time.Data());
  501. // display new min and max energy limits given by event energy range
  502. fMinEnergy->SetLimits(fEventManager->GetEvtMinEnergy(), fEventManager->GetEvtMaxEnergy(), 2001);
  503. fMinEnergy->SetValue(fEventManager->GetEvtMinEnergy());
  504. fMaxEnergy->SetLimits(fEventManager->GetEvtMinEnergy(), fEventManager->GetEvtMaxEnergy(), 2001);
  505. fMaxEnergy->SetValue(fEventManager->GetEvtMaxEnergy());
  506. }
  507. // update tab controls
  508. Update();
  509. return;
  510. }
  511. // if ONLINE mode
  512. else
  513. {
  514. // block user interface to exclude sharing of Redraw access
  515. BlockUI();
  516. // Run separate thread for Online Display
  517. ThreadParam_OnlineDisplay* par_online_display = new ThreadParam_OnlineDisplay();
  518. par_online_display->fEventManager = fEventManager;
  519. par_online_display->fManagerEditor = this;
  520. par_online_display->fRootManager = FairRootManager::Instance();
  521. par_online_display->isZDCRedraw = false;
  522. if ((fEventManager->isZDCModule) && (fShowMCPoints->IsOn()))
  523. par_online_display->isZDCRedraw = true;
  524. par_online_display->iCurrentEvent = fCurrentEvent->GetIntNumber();
  525. par_online_display->isStreamSource = isStreamSource;
  526. TThread* thread_run_online = new TThread(RunOnlineDisplay, (void*)par_online_display);
  527. iThreadState = 1;
  528. thread_run_online->Run();
  529. return;
  530. }
  531. }
  532. void MpdEventManagerEditor::BlockUI()
  533. {
  534. //fCurrentEvent->SetState(kFALSE);
  535. //fUpdate->SetEnabled(kFALSE);
  536. fUpdate->SetText("Stop online display");
  537. //fGeometry->SetEnabled(kFALSE);
  538. }
  539. void MpdEventManagerEditor::UnblockUI()
  540. {
  541. //fCurrentEvent->SetState(kTRUE);
  542. //fUpdate->SetEnabled(kTRUE);
  543. fUpdate->SetText("Start online display");
  544. //fGeometry->SetEnabled(kTRUE);
  545. }
  546. // thread function for Online Display
  547. void* RunOnlineDisplay(void* ptr)
  548. {
  549. ThreadParam_OnlineDisplay* thread_par = (ThreadParam_OnlineDisplay*) ptr;
  550. MpdEventManager* fEventManager = thread_par->fEventManager;
  551. MpdEventManagerEditor* fEditor = thread_par->fManagerEditor;
  552. FairRootManager* fRootManager = thread_par->fRootManager;
  553. int current_event = thread_par->iCurrentEvent;
  554. bool stream_source = thread_par->isStreamSource;
  555. bool isZDCRedraw = thread_par->isZDCRedraw;
  556. // get all tasks from FairRunAna
  557. FairRunAna* pRun = fEventManager->fRunAna;
  558. FairTask* pMainTask = pRun->GetMainTask();
  559. TList* taskList = pMainTask->GetListOfTasks();
  560. for (int i = current_event+1; ((stream_source) || (i < fEditor->iEventCount)); i++)
  561. {
  562. if (fEditor->iThreadState == 0)
  563. break;
  564. do
  565. {
  566. TThread::Sleep(0, 200000000);
  567. } while ((gEve->GetGlobalScene()->GetGLScene()->IsLocked()) || (gEve->GetEventScene()->GetGLScene()->IsLocked()));
  568. fRootManager->ReadEvent(i);
  569. fEventManager->SetCurrentEvent(i);
  570. // run all tasks
  571. TObjLink* lnk = taskList->FirstLink();
  572. while (lnk)
  573. {
  574. FairTask* pCurTask = (FairTask*) lnk->GetObject();
  575. pCurTask->ExecuteTask("");
  576. lnk = lnk->Next();
  577. }
  578. //fEditor->fCurrentEvent->SetIntNumber(i);
  579. // highlight ZDC modules if ZDC present
  580. if (isZDCRedraw)
  581. fEditor->RedrawZDC();
  582. // redraw points
  583. cout<<"Redrawing event #"<<i<<"..."<<endl<<endl;
  584. gEve->Redraw3D();
  585. //TThread::Sleep(1,0);
  586. //gSystem->ProcessEvents();
  587. }
  588. fEditor->UnblockUI();
  589. fEditor->iThreadState = 0;
  590. return nullptr;
  591. }
  592. ClassImp(MpdEventManagerEditor);