MpdEventManager.cxx 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974
  1. // MpdEventManager: class for event management and navigation.
  2. #include "MpdEventManager.h"
  3. #include "MpdEventManagerEditor.h"
  4. #include "constants.h"
  5. #include "TDOMParser.h"
  6. #include "TXMLEngine.h"
  7. #include "TXMLAttr.h"
  8. #include "TXMLNode.h"
  9. #include "TDatabasePDG.h"
  10. #include "TEveGeoNode.h"
  11. #include "TEveManager.h"
  12. #include "TGeoManager.h"
  13. #include <TGLViewer.h>
  14. #include <TGLCameraOverlay.h>
  15. #include <TGLLightSet.h>
  16. #include <TEveBrowser.h>
  17. #include <TObjString.h>
  18. #include <TColor.h>
  19. // XML
  20. #include <libxml/parser.h>
  21. #include <libxml/tree.h>
  22. #include <libxml/xmlschemastypes.h>
  23. #include <unistd.h>
  24. #include <cerrno>
  25. #include <iostream>
  26. #include <sstream>
  27. MpdEventManager* MpdEventManager::fgRinstance = 0;
  28. MpdEventManager* MpdEventManager::Instance() { return fgRinstance; }
  29. // convert string with hexadecimal presentation without "0x" to integer
  30. int hex_string_to_int(string hex_string)
  31. {
  32. int x;
  33. stringstream stream;
  34. stream<<hex<<hex_string;
  35. stream>>x;
  36. return x;
  37. }
  38. //______________________________________________________________________________
  39. MpdEventManager::MpdEventManager()
  40. : TEveEventManager("EventManager", ""),
  41. fRunAna(FairRunAna::Instance()),
  42. EveMCPoints(nullptr),
  43. EveMCTracks(nullptr),
  44. EveRecoPoints(nullptr),
  45. EveRecoTracks(nullptr),
  46. background_color(1),
  47. isDarkColor(true),
  48. isZDCModule(nullptr),
  49. fgShowRecoPointsIsShow(false),
  50. fgRedrawRecoPointsReqired(false),
  51. fEventEditor(nullptr),
  52. fRPhiView(0),
  53. fRhoZView(0),
  54. fMulti3DView(0),
  55. fMultiRPhiView(0),
  56. fMultiRhoZView(0),
  57. fRPhiMng(nullptr),
  58. fRhoZMng(nullptr),
  59. fRPhiGeomScene(0),
  60. fRhoZGeomScene(0),
  61. fAxesPhi(nullptr),
  62. fAxesRho(nullptr),
  63. fRPhiPlane{0, 0, 1, 0},
  64. fRhoZPlane{-1, 0, 0, 0},
  65. fEvent(0),
  66. iCurrentEvent(0),
  67. fPriOnly(kFALSE),
  68. fCurrentPDG(0),
  69. fMinEnergy(0),
  70. fMaxEnergy(25),
  71. fEvtMinEnergy(0),
  72. fEvtMaxEnergy(12),
  73. fLastUsedColor(2001),
  74. fXMLConfig("")
  75. {
  76. fgRinstance = this;
  77. AddParticlesToPdgDataBase();
  78. // set colors for particles
  79. fPDGToColor[22] = 623; // photon
  80. fPDGToColor[-2112] = 2; // anti-neutron
  81. fPDGToColor[-11] = 3; // e+
  82. fPDGToColor[-3122] = 4; // anti-lambda
  83. fPDGToColor[11] = 5; // e-
  84. fPDGToColor[-3222] = 6; // Sigma -
  85. fPDGToColor[12] = 7; // e-neutrino
  86. fPDGToColor[-3212] = 8; // Sigma0
  87. fPDGToColor[-13] = 9; // mu+
  88. fPDGToColor[-3112] = 10; // Sigma+ (PB
  89. fPDGToColor[13] = 11; // mu-
  90. fPDGToColor[-3322] = 12; // Xi0
  91. fPDGToColor[111] = 13; // pi0
  92. fPDGToColor[-3312] = 14; // Xi+
  93. fPDGToColor[211] = 15; // pi+
  94. fPDGToColor[-3334] = 16; // Omega+ (PB)
  95. fPDGToColor[-211] = 17; // pi-
  96. fPDGToColor[-15] = 18; // tau+
  97. fPDGToColor[130] = 19; // K long
  98. fPDGToColor[15] = 20; // tau -
  99. fPDGToColor[321] = 21; // K+
  100. fPDGToColor[411] = 22; // D+
  101. fPDGToColor[-321] = 23; // K-
  102. fPDGToColor[-411] = 24; // D-
  103. fPDGToColor[2112] = 25; // n
  104. fPDGToColor[421] = 26; // D0
  105. fPDGToColor[2212] = 27; // p
  106. fPDGToColor[-421] = 28; // D0
  107. fPDGToColor[-2212] = 29; // anti-proton
  108. fPDGToColor[431] = 30; // Ds+
  109. fPDGToColor[310] = 31; // K short
  110. fPDGToColor[-431] = 32; // anti Ds-
  111. fPDGToColor[221] = 33; // eta
  112. fPDGToColor[4122] = 34; // Lambda_C+
  113. fPDGToColor[3122] = 35; // Lambda
  114. fPDGToColor[24] = 36; // W+
  115. fPDGToColor[3222] = 37; // Sigma+
  116. fPDGToColor[-24] = 38; // W-
  117. fPDGToColor[3212] = 39; //Sigma0
  118. fPDGToColor[23] = 40; // Z
  119. fPDGToColor[3112] = 41; // Sigma -
  120. fPDGToColor[3322] = 42; // Xi0
  121. fPDGToColor[3312] = 43; // Xi-
  122. fPDGToColor[3334] = 44; // Omega- (PB)
  123. fPDGToColor[50000050] = 801; //Cerenkov
  124. fPDGToColor[1000010020] = 45;
  125. fPDGToColor[1000010030] = 48;
  126. fPDGToColor[1000020040] = 50;
  127. fPDGToColor[1000020030] = 55;
  128. InitColorStructure();
  129. }
  130. // return integer value of color by string storing color number, RGB triple or color name (e.g. kBlue, RGB(51,63,73), RGB(#0039E1))
  131. // support following MAIN COLOR NAMESET + some additional colors as examples:
  132. // kWhite, kBlack, kGgray,
  133. // kBlue, kAzure (темно-синий), kCyan (морской волны), kTeal (бирюзовый),
  134. // kGreen, kSpring (светло-зеленый), kGreen+2 (темно-зеленый), kSpring+2 (темно-зеленый), kKhaki
  135. // kYellow, kOrange (желтый с оттенком), kOrange+2 (оранжевый кор.), kOrange+1 (светло-оранжевый кор.), kOrange+7 (выделенно-оранжевый)
  136. // kRed, kViolet, kMagenta (бардовый), kMagenta-6 (светло-бардовый), kPink (темно-розовый)
  137. Int_t MpdEventManager::StringToColor(TString color)
  138. {
  139. color = color.ReplaceAll(" ", "");
  140. color.ToLower();
  141. // check if color is a RGB triple
  142. if (color.BeginsWith("rgb"))
  143. {
  144. // parse RGB triple
  145. if (color.Length() < 6)
  146. {
  147. cout<<color<<" - RGB triple isn't correct. Color set to default blue"<<endl;
  148. return 600;
  149. }
  150. TString triple = color(3, color.Length() - 3);
  151. triple.Remove(TString::kLeading, '('); triple.Remove(TString::kTrailing, ')');
  152. int red_rgb = -1, green_rgb = -1, blue_rgb = -1;
  153. if (triple[0] == '#')
  154. {
  155. if (triple.Length() < 7)
  156. {
  157. cout<<triple<<" - hex triple size after '#' isn't correct (should have 6 symbols). Color set to default blue"<<endl;
  158. return 600;
  159. }
  160. TString str_red = triple(1,2);
  161. TString str_green = triple(3,2);
  162. TString str_blue = triple(5,2);
  163. if ((!str_red.IsHex()) || (!str_green.IsHex()) || (!str_blue.IsHex()))
  164. {
  165. cout<<triple<<" - hex triple after '#' has not hex format. Color set to default blue"<<endl;
  166. return 600;
  167. }
  168. red_rgb = hex_string_to_int(str_red.Data());
  169. green_rgb = hex_string_to_int(str_green.Data());
  170. blue_rgb = hex_string_to_int(str_blue.Data());
  171. }
  172. else
  173. {
  174. TObjArray* pRGB = triple.Tokenize(",");
  175. if (pRGB->GetEntriesFast() < 3)
  176. {
  177. cout<<triple<<" - RGB string doesn't include color triple. Color set to default blue"<<endl;
  178. return 600;
  179. }
  180. red_rgb = ((TObjString*)pRGB->At(0))->GetString().Atoi();
  181. green_rgb = ((TObjString*)pRGB->At(1))->GetString().Atoi();
  182. blue_rgb = ((TObjString*)pRGB->At(2))->GetString().Atoi();
  183. delete pRGB;
  184. }
  185. Int_t ci = fLastUsedColor++;
  186. new TColor(ci, red_rgb/255.0F, green_rgb/255.0F, blue_rgb/255.0F);
  187. return ci;
  188. }
  189. if (color.Contains("k"))
  190. {
  191. Ssiz_t sign_index = color.First('+');
  192. if (sign_index == kNPOS)
  193. sign_index = color.First('-');
  194. TString color_name = "";
  195. if (sign_index == kNPOS)
  196. color_name = color;
  197. else
  198. color_name = color(0, sign_index);
  199. Int_t color_value;
  200. if (color_name.EqualTo("kwhite")) color_value = 0;
  201. else if (color_name.EqualTo("kblack")) color_value = 1;
  202. else if (color_name.EqualTo("kgray")) color_value = 920;
  203. else if (color_name.EqualTo("kred")) color_value = 632;
  204. else if (color_name.EqualTo("kgreen")) color_value = 416;
  205. else if (color_name.EqualTo("kblue")) color_value = 600;
  206. else if (color_name.EqualTo("kyellow")) color_value = 400;
  207. else if (color_name.EqualTo("kmagenta")) color_value = 616;
  208. else if (color_name.EqualTo("kcyan")) color_value = 432;
  209. else if (color_name.EqualTo("korange")) color_value = 800;
  210. else if (color_name.EqualTo("kspring")) color_value = 820;
  211. else if (color_name.EqualTo("kteal")) color_value = 840;
  212. else if (color_name.EqualTo("kazure")) color_value = 860;
  213. else if (color_name.EqualTo("kviolet")) color_value = 880;
  214. else if (color_name.EqualTo("kpink")) color_value = 900;
  215. else if (color_name.EqualTo("kkhaki")) color_value = 403;
  216. else
  217. {
  218. cout<<color_name<<" not found. Color set to default blue"<<endl;
  219. color_value = 600;
  220. }
  221. if ((sign_index != kNPOS) && (color.Length() > sign_index+2))
  222. {
  223. TString strNumber = color(sign_index+1, color.Length() - sign_index-1);
  224. if (strNumber.IsDigit())
  225. {
  226. if (color(sign_index) == '+')
  227. color_value += strNumber.Atoi();
  228. else
  229. color_value -= strNumber.Atoi();
  230. }
  231. }
  232. return color_value;
  233. }
  234. else
  235. return color.Atoi();
  236. }
  237. void MpdEventManager::InitColorStructure()
  238. {
  239. // check and load colors from my XML file
  240. TString coloring_xml_path = "$VMCWORKDIR/config/eventdisplay.xml";
  241. TString coloring_xsd_path = "$VMCWORKDIR/eventdisplay/coloring.xsd";
  242. gSystem->ExpandPathName(coloring_xml_path);
  243. gSystem->ExpandPathName(coloring_xsd_path);
  244. // check XML scheme
  245. if (ValidateXml(coloring_xml_path.Data(), coloring_xsd_path.Data()) == true)
  246. {
  247. xmlDoc* doc = xmlReadFile(coloring_xml_path.Data(), nullptr, 0);
  248. /* Get the root element node */
  249. xmlNode* root_element = nullptr;
  250. root_element = xmlDocGetRootElement(doc);
  251. xmlAttr* root_element_attributes = root_element->properties;
  252. xmlChar* value = xmlNodeListGetString(root_element->doc, root_element_attributes->children, 1);
  253. xmlNodePtr cur_node = root_element;
  254. if (strcmp((char*)value, "default") == 0)
  255. {
  256. cout<<"using default coloring"<<endl;
  257. gVisualizationColoring = defaultColoring;
  258. }
  259. else
  260. {
  261. structSelectedColoring* selected_coloring;
  262. structLevelColoring* level_coloring;
  263. if (strcmp((char*)value, "detector") == 0)
  264. gVisualizationColoring = selectedColoring;
  265. else
  266. gVisualizationColoring = levelColoring;
  267. cur_node = root_element->children;
  268. while (cur_node)
  269. {
  270. if ((strcmp((char*)cur_node->name, "text") != 0) //skipping elements with no attributes
  271. && (cur_node->type != XML_COMMENT_NODE))
  272. {
  273. // set colors for particle tracks
  274. if (strcmp((char*)cur_node->name, "particle") == 0)
  275. {
  276. xmlAttr* attribute = cur_node->properties;
  277. TString strPDG = "", strColor = "";
  278. while (attribute)
  279. {
  280. xmlChar* attr_value = xmlNodeListGetString(root_element->doc, attribute->children, 1);
  281. if (strcmp((char*)attribute->name,"pdg") == 0)
  282. strPDG = (char*) attr_value;
  283. if (strcmp((char*)attribute->name,"color") == 0)
  284. strColor = (char*) attr_value;
  285. attribute = attribute->next;
  286. xmlFree(attr_value);
  287. }// while (attribute)
  288. xmlFree(attribute);
  289. if ((strPDG != "") && (strColor != ""))
  290. fPDGToColor[strPDG.Atoi()] = StringToColor(strColor);
  291. cur_node = cur_node->next;
  292. continue;
  293. }
  294. if (gVisualizationColoring == selectedColoring)
  295. selected_coloring = new structSelectedColoring();
  296. else
  297. level_coloring = new structLevelColoring();
  298. xmlAttr* attribute = cur_node->properties;
  299. while (attribute)
  300. {
  301. xmlChar* attr_value = xmlNodeListGetString(root_element->doc, attribute->children, 1);
  302. if (gVisualizationColoring == selectedColoring)
  303. {
  304. if (strcmp((char*)attribute->name,"name") == 0)
  305. selected_coloring->detector_name = (char*) attr_value;
  306. if (strcmp((char*)attribute->name,"color") == 0)
  307. selected_coloring->detector_color = (char*) attr_value;
  308. if (strcmp((char*)attribute->name,"isRecursiveColoring") == 0)
  309. selected_coloring->isRecursiveColoring = (strcmp((char*)attr_value,"true") == 0);
  310. if (strcmp((char*)attribute->name,"transparency") == 0)
  311. selected_coloring->detector_transparency = atoi((char*)attr_value);
  312. }
  313. else
  314. {
  315. if (strcmp((char*)attribute->name,"color") == 0)
  316. level_coloring->fill_color = (char*) attr_value;
  317. if (strcmp((char*)attribute->name,"isFillLine") == 0)
  318. level_coloring->isFillLine = (strcmp((char*)attr_value,"true") == 0);
  319. if (strcmp((char*)attribute->name,"visibility") == 0)
  320. level_coloring->visibility = (strcmp((char*)attr_value,"true") == 0);
  321. if (strcmp((char*)attribute->name,"transparency") == 0)
  322. level_coloring->transparency = atoi((char*)attr_value);
  323. }
  324. attribute = attribute->next;
  325. xmlFree(attr_value);
  326. }// while (attribute)
  327. xmlFree(attribute);
  328. // add color parameters to array
  329. if (gVisualizationColoring == selectedColoring)
  330. vecSelectedColoring.push_back(selected_coloring);
  331. else
  332. vecLevelColoring.push_back(level_coloring);
  333. }// if ((strcmp((char*)cur_node->name, "text") != 0) && (cur_node->type != XML_COMMENT_NODE))
  334. cur_node = cur_node->next;
  335. }// while (cur_node)
  336. }
  337. xmlFree(cur_node);
  338. xmlFree(value);
  339. xmlFreeDoc(doc);
  340. }
  341. else
  342. {
  343. cout<<"Using default ROOT coloring"<<endl;
  344. gVisualizationColoring = defaultColoring;
  345. }
  346. return;
  347. }
  348. //______________________________________________________________________________
  349. void MpdEventManager::Init(Int_t visopt, Int_t vislvl, Int_t maxvisnds)
  350. {
  351. TEveManager::Create();
  352. fRunAna->Init();
  353. if (gGeoManager == nullptr)
  354. return;
  355. TGeoNode* N = gGeoManager->GetTopNode();
  356. TEveGeoTopNode* TNod = new TEveGeoTopNode(gGeoManager, N, visopt, vislvl, maxvisnds);
  357. // change color and visibility of geometry nodes
  358. if (!fXMLConfig.EqualTo(""))
  359. LoadXMLSettings();
  360. else
  361. {
  362. if (gVisualizationColoring != defaultColoring)
  363. {
  364. if (gVisualizationColoring == selectedColoring)
  365. SelectedGeometryColoring();
  366. else
  367. LevelChangeNodeProperty(N, 0);
  368. }
  369. }
  370. gEve->AddGlobalElement(TNod);
  371. gEve->FullRedraw3D(kTRUE);
  372. fEvent = gEve->AddEvent(this);
  373. // create projection managers
  374. fRPhiMng = new TEveProjectionManager(TEveProjection::kPT_RPhi);
  375. fRhoZMng = new TEveProjectionManager(TEveProjection::kPT_RhoZ);
  376. gEve->AddToListTree(fRPhiMng, kFALSE);
  377. gEve->AddToListTree(fRhoZMng, kFALSE);
  378. // create axes for viewers
  379. fAxesPhi = new TEveProjectionAxes(fRPhiMng);
  380. fAxesPhi->SetMainColor(kRed);
  381. fAxesRho = new TEveProjectionAxes(fRhoZMng);
  382. fAxesRho->SetMainColor(kRed);
  383. // first 3D viewer
  384. gEve->GetDefaultViewer()->SetElementName("3D View");
  385. // display axes
  386. //gEve->GetDefaultViewer()->GetGLViewer()->SetGuideState(TGLUtil::kAxesEdge, kTRUE, kFALSE, 0);
  387. // switch off left and right light sources for first window
  388. gEve->GetDefaultViewer()->GetGLViewer()->GetLightSet()->SetLight(TGLLightSet::kLightLeft, false);
  389. gEve->GetDefaultViewer()->GetGLViewer()->GetLightSet()->SetLight(TGLLightSet::kLightRight, false);
  390. if (!isDarkColor)
  391. gEve->GetDefaultViewer()->GetGLViewer()->UseLightColorSet();
  392. gEve->GetDefaultViewer()->GetGLViewer()->SetClearColor(background_color);
  393. // use only one View in Online mode
  394. if (isOnline)
  395. return;
  396. // ADD WINDOW in EventDisplay for RPhi projection
  397. TEveWindowSlot* RPhiSlot = TEveWindow::CreateWindowInTab(gEve->GetBrowser()->GetTabRight());
  398. TEveWindowPack* RPhiPack = RPhiSlot->MakePack();
  399. RPhiPack->SetElementName("RPhi View");
  400. RPhiPack->SetShowTitleBar(kFALSE);
  401. RPhiPack->NewSlot()->MakeCurrent();
  402. fRPhiView = gEve->SpawnNewViewer("RPhi View", "");
  403. // create scene holding projected geometry for the RPhi view
  404. fRPhiGeomScene = gEve->SpawnNewScene("RPhi", "Scene holding geometry for RPhi.");
  405. // add axes for scene of RPhi view
  406. fRPhiGeomScene->AddElement(fAxesPhi);
  407. // ADD WINDOW in EvenDisplay for RhoZ projection
  408. TEveWindowSlot* RhoZSlot = TEveWindow::CreateWindowInTab(gEve->GetBrowser()->GetTabRight());
  409. TEveWindowPack* RhoZPack = RhoZSlot->MakePack();
  410. RhoZPack->SetElementName("RhoZ View");
  411. RhoZPack->SetShowTitleBar(kFALSE);
  412. RhoZPack->NewSlot()->MakeCurrent();
  413. fRhoZView = gEve->SpawnNewViewer("RhoZ View", "");
  414. // create scene holding projected geometry for the RhoZ view.
  415. fRhoZGeomScene = gEve->SpawnNewScene("RhoZ", "Scene holding geometry for RhoZ.");
  416. // add axes for scene of RPhoZ view
  417. fRhoZGeomScene->AddElement(fAxesRho);
  418. SetViewers(fRPhiView, fRhoZView);
  419. // ADD WINDOW in EvenDisplay for MultiView
  420. TEveWindowSlot* MultiSlot = TEveWindow::CreateWindowInTab(gEve->GetBrowser()->GetTabRight());
  421. TEveWindowPack* MultiPack = MultiSlot->MakePack();
  422. MultiPack->SetElementName("Multi View");
  423. MultiPack->SetHorizontal();
  424. MultiPack->SetShowTitleBar(kFALSE);
  425. MultiPack->NewSlot()->MakeCurrent();
  426. fMulti3DView = gEve->SpawnNewViewer("3D View (multi)", "");
  427. // switch off left and right light sources for 3D MultiView
  428. fMulti3DView->GetGLViewer()->GetLightSet()->SetLight(TGLLightSet::kLightLeft, false);
  429. fMulti3DView->GetGLViewer()->GetLightSet()->SetLight(TGLLightSet::kLightRight, false);
  430. if (!isDarkColor)
  431. fMulti3DView->GetGLViewer()->UseLightColorSet();
  432. fMulti3DView->GetGLViewer()->SetClearColor(background_color);
  433. // add 3D scenes (first tab) to 3D MultiView
  434. fMulti3DView->AddScene(gEve->GetGlobalScene());
  435. fMulti3DView->AddScene(gEve->GetEventScene());
  436. // add slots for RPhi and RhoZ projections on Multi View tab
  437. MultiPack = MultiPack->NewSlot()->MakePack();
  438. MultiPack->SetShowTitleBar(kFALSE);
  439. MultiPack->NewSlot()->MakeCurrent();
  440. fMultiRPhiView = gEve->SpawnNewViewer("RPhi View (multi)", "");
  441. MultiPack->NewSlot()->MakeCurrent();
  442. fMultiRhoZView = gEve->SpawnNewViewer("RhoZ View (multi)", "");
  443. SetViewers(fMultiRPhiView, fMultiRhoZView);
  444. // don't change reposition camera on each update
  445. fRPhiView->GetGLViewer()->SetResetCamerasOnUpdate(kFALSE);
  446. fRhoZView->GetGLViewer()->SetResetCamerasOnUpdate(kFALSE);
  447. fMulti3DView->GetGLViewer()->SetResetCamerasOnUpdate(kFALSE);
  448. fMultiRPhiView->GetGLViewer()->SetResetCamerasOnUpdate(kFALSE);
  449. fMultiRhoZView->GetGLViewer()->SetResetCamerasOnUpdate(kFALSE);
  450. // from FairRoot (not checked yet)
  451. fMulti3DView->GetEveFrame()->HideAllDecorations();
  452. fMultiRPhiView->GetEveFrame()->HideAllDecorations();
  453. fMultiRhoZView->GetEveFrame()->HideAllDecorations();
  454. }//MpdEventManager::Init
  455. void MpdEventManager::SetViewers(TEveViewer* RPhi, TEveViewer* RhoZ)
  456. {
  457. RPhi->GetGLViewer()->SetCurrentCamera(TGLViewer::kCameraOrthoXOY);
  458. // set camera parameters
  459. RPhi->GetGLViewer()->GetCameraOverlay()->SetOrthographicMode(TGLCameraOverlay::kAxis);
  460. RPhi->GetGLViewer()->GetCameraOverlay()->SetShowOrthographic(kTRUE);
  461. // switch off left, right, top and bottom light sources
  462. RPhi->GetGLViewer()->GetLightSet()->SetLight(TGLLightSet::kLightLeft, false);
  463. RPhi->GetGLViewer()->GetLightSet()->SetLight(TGLLightSet::kLightRight, false);
  464. RPhi->GetGLViewer()->GetLightSet()->SetLight(TGLLightSet::kLightTop, false);
  465. RPhi->GetGLViewer()->GetLightSet()->SetLight(TGLLightSet::kLightBottom, false);
  466. if (!isDarkColor)
  467. RPhi->GetGLViewer()->UseLightColorSet();
  468. RPhi->GetGLViewer()->SetClearColor(background_color);
  469. RhoZ->GetGLViewer()->SetCurrentCamera(TGLViewer::kCameraOrthoZOY);
  470. // set camera parameters
  471. RhoZ->GetGLViewer()->GetCameraOverlay()->SetOrthographicMode(TGLCameraOverlay::kAxis);
  472. RhoZ->GetGLViewer()->GetCameraOverlay()->SetShowOrthographic(kTRUE);
  473. // switch off left, right and front light sources
  474. RhoZ->GetGLViewer()->GetLightSet()->SetLight(TGLLightSet::kLightLeft, false);
  475. RhoZ->GetGLViewer()->GetLightSet()->SetLight(TGLLightSet::kLightRight, false);
  476. RhoZ->GetGLViewer()->GetLightSet()->SetLight(TGLLightSet::kLightFront, false);
  477. if (!isDarkColor)
  478. RhoZ->GetGLViewer()->UseLightColorSet();
  479. RhoZ->GetGLViewer()->SetClearColor(background_color);
  480. RPhi->AddScene(fRPhiGeomScene);
  481. RPhi->AddScene(gEve->GetGlobalScene());
  482. RPhi->AddScene(gEve->GetEventScene());
  483. RhoZ->AddScene(fRhoZGeomScene);
  484. RhoZ->AddScene(gEve->GetGlobalScene());
  485. RhoZ->AddScene(gEve->GetEventScene());
  486. // set clip planes
  487. RPhi->GetGLViewer()->GetClipSet()->SetClipType(TGLClip::kClipPlane);
  488. RPhi->GetGLViewer()->GetClipSet()->SetClipState(TGLClip::kClipPlane, fRPhiPlane);
  489. RhoZ->GetGLViewer()->GetClipSet()->SetClipType(TGLClip::kClipPlane);
  490. RhoZ->GetGLViewer()->GetClipSet()->SetClipState(TGLClip::kClipPlane, fRhoZPlane);
  491. }
  492. // setting of geometry colors for DETECTOR COLORING MODE
  493. void MpdEventManager::SelectedGeometryColoring()
  494. {
  495. TGeoVolume* curVolume;
  496. for (UInt_t i = 0; i < vecSelectedColoring.size(); i++)
  497. {
  498. structSelectedColoring* selected_coloring = vecSelectedColoring[i];
  499. curVolume = gGeoManager->GetVolume(selected_coloring->detector_name);
  500. if (!curVolume)
  501. {
  502. cout<<"There is no volume with given name: "<<selected_coloring->detector_name<<endl;
  503. // delete wrong detector name from the array
  504. vecSelectedColoring.erase(vecSelectedColoring.begin() + i);
  505. i--;
  506. continue;
  507. }
  508. Int_t curColor = StringToColor(selected_coloring->detector_color);
  509. Int_t curTransparency = selected_coloring->detector_transparency;
  510. curVolume->SetFillColor(curColor);
  511. curVolume->SetLineColor(curColor);
  512. curVolume->SetTransparency(curTransparency);
  513. if (selected_coloring->isRecursiveColoring)
  514. {
  515. for (int j = 0; j < curVolume->GetNdaughters(); j++)
  516. {
  517. TGeoNode* child = curVolume->GetNode(j);
  518. TGeoVolume* subVolume = child->GetVolume();
  519. subVolume->SetFillColor(curColor);
  520. subVolume->SetLineColor(curColor);
  521. subVolume->SetTransparency(curTransparency);
  522. if (child->GetNdaughters() != 0)
  523. RecursiveChangeNodeProperty(child, curColor, curTransparency);
  524. }// for (int j = 0; j < curVolume->GetNdaughters(); j++)
  525. }// if (selected_coloring->isRecursiveColoring)
  526. }// for (int i = 0; i < vecSelectedColoring.size(); i++)
  527. return;
  528. }
  529. void MpdEventManager::RecursiveChangeNodeProperty(TGeoNode* node, Int_t color, int transparency)
  530. {
  531. for (int i = 0; i < node->GetNdaughters(); i++)
  532. {
  533. TGeoNode* child = node->GetDaughter(i);
  534. TGeoVolume* curVolume = child->GetVolume();
  535. curVolume->SetFillColor(color);
  536. curVolume->SetLineColor(color);
  537. curVolume->SetTransparency(transparency);
  538. if (child->GetNdaughters() != 0) RecursiveChangeNodeProperty(child, color, transparency);
  539. }
  540. }
  541. // set transparent geometry
  542. void MpdEventManager::SetTransparentGeometry(bool is_on)
  543. {
  544. switch (gVisualizationColoring)
  545. {
  546. case selectedColoring:
  547. {
  548. TGeoVolume* curVolume;
  549. for (UInt_t i = 0; i < vecSelectedColoring.size(); i++)
  550. {
  551. structSelectedColoring* selected_coloring = vecSelectedColoring[i];
  552. curVolume = gGeoManager->GetVolume(selected_coloring->detector_name);
  553. if (!curVolume)
  554. {
  555. cout<<"There is no volume with given name: "<< selected_coloring->detector_name<<endl;
  556. // delete wrong detector name from the array
  557. vecSelectedColoring.erase(vecSelectedColoring.begin() + i);
  558. i--;
  559. continue;
  560. }
  561. Int_t curTransparency = 80;
  562. if (!is_on)
  563. curTransparency = selected_coloring->detector_transparency;
  564. curVolume->SetTransparency(curTransparency);
  565. for (int j = 0; j < curVolume->GetNdaughters(); j++)
  566. {
  567. TGeoNode* child = curVolume->GetNode(j);
  568. TGeoVolume* subVolume = child->GetVolume();
  569. subVolume->SetTransparency(curTransparency);
  570. if (child->GetNdaughters() != 0)
  571. RecursiveChangeNodeTransparent(child, curTransparency);
  572. }// or (int j = 0; j < curVolume->GetNdaughters(); j++)
  573. }// for (int i = 0; i < vecSelectedColoring.size(); i++)
  574. break;
  575. }// case selectedColoring:
  576. case levelColoring:
  577. {
  578. // NOT IMPLEMENTED
  579. break;
  580. }
  581. case defaultColoring:
  582. {
  583. // NOT IMPLEMENTED
  584. break;
  585. }
  586. }// switch (gVisualizationColoring)
  587. return;
  588. }
  589. void MpdEventManager::RecursiveChangeNodeTransparent(TGeoNode* node, int transparency)
  590. {
  591. for (int i = 0; i < node->GetNdaughters(); i++)
  592. {
  593. TGeoNode* child = node->GetDaughter(i);
  594. TGeoVolume* curVolume = child->GetVolume();
  595. curVolume->SetTransparency(transparency);
  596. if (child->GetNdaughters() != 0) RecursiveChangeNodeTransparent(child, transparency);
  597. }
  598. }
  599. // hierarchical changing of nodes' properties: visibility, transparency, fill color and line color
  600. void MpdEventManager::LevelChangeNodeProperty(TGeoNode* node, int level)
  601. {
  602. for (int i = 0; i < node->GetNdaughters(); i++)
  603. {
  604. TGeoNode* child = node->GetDaughter(i);
  605. if (level < (int) vecLevelColoring.size())
  606. {
  607. TGeoVolume* curVolume = child->GetVolume();
  608. structLevelColoring* level_coloring = vecLevelColoring[level];
  609. curVolume->SetVisibility(level_coloring->visibility);
  610. curVolume->SetTransparency(level_coloring->transparency);
  611. curVolume->SetFillColor(StringToColor(level_coloring->fill_color));
  612. if (level_coloring->isFillLine) curVolume->SetLineColor(StringToColor(level_coloring->fill_color));
  613. if (child->GetNdaughters() != 0)
  614. LevelChangeNodeProperty(child, ++level);
  615. }//if (level < arr_size)
  616. }
  617. }
  618. // validate XML file with geometry colors
  619. // returns true if successful or false if XML validation failed
  620. bool MpdEventManager::ValidateXml(const char* XMLFileName, const char* XSDFileName)
  621. {
  622. bool ok = false;
  623. xmlSchemaParserCtxtPtr ctxt = xmlSchemaNewParserCtxt(XSDFileName);
  624. xmlSchemaSetParserErrors(ctxt, (xmlSchemaValidityErrorFunc) fprintf, (xmlSchemaValidityWarningFunc) fprintf, stderr);
  625. xmlSchemaPtr schema = nullptr;
  626. schema = xmlSchemaParse(ctxt);
  627. xmlSchemaFreeParserCtxt(ctxt);
  628. //xmlSchemaDump(stdout, schema); //to print schema dump
  629. xmlDoc* doc = nullptr;
  630. doc = xmlReadFile(XMLFileName, nullptr, 0);
  631. if (doc == nullptr)
  632. cout<<"Error: could not parse file"<<XMLFileName<<endl;
  633. else
  634. {
  635. xmlSchemaValidCtxtPtr cvalid = xmlSchemaNewValidCtxt(schema);
  636. xmlSchemaSetValidErrors(cvalid, (xmlSchemaValidityErrorFunc) fprintf, (xmlSchemaValidityWarningFunc) fprintf, stderr);
  637. int ret = xmlSchemaValidateDoc(cvalid, doc);
  638. if (ret == 0)
  639. {
  640. //cout<<XMLFileName<<" is validated"<<endl;
  641. ok = true;
  642. }
  643. else if (ret > 0)
  644. {
  645. cout<<XMLFileName<<" failed to validate"<<endl;
  646. }
  647. else
  648. {
  649. cout<<XMLFileName<<" validation generated an internal error"<<endl;
  650. }
  651. xmlSchemaFreeValidCtxt(cvalid);
  652. }
  653. if (schema != nullptr)
  654. xmlSchemaFree(schema);
  655. xmlSchemaCleanupTypes();
  656. return ok;
  657. }
  658. void MpdEventManager::Open()
  659. {}
  660. void MpdEventManager::Close()
  661. {}
  662. void MpdEventManager::DisplaySettings()
  663. {}
  664. void MpdEventManager::UpdateEditor()
  665. {}
  666. // MpdEventManager destructor
  667. MpdEventManager::~MpdEventManager()
  668. {
  669. if (!vecSelectedColoring.empty())
  670. {
  671. for (UInt_t i = 0; i < vecSelectedColoring.size(); i++)
  672. delete (vecSelectedColoring[i]);
  673. vecSelectedColoring.clear();
  674. }
  675. if (!vecLevelColoring.empty())
  676. {
  677. for (UInt_t i = 0; i < vecLevelColoring.size(); i++)
  678. delete (vecLevelColoring[i]);
  679. vecLevelColoring.clear();
  680. }
  681. }
  682. // go to FairRunAna event with given number for scene data getting
  683. void MpdEventManager::GotoEvent(Int_t event)
  684. {
  685. iCurrentEvent = event;
  686. fRunAna->Run((Long64_t)event);
  687. }
  688. // go to next FairRunAna event for scene data getting
  689. void MpdEventManager::NextEvent()
  690. {
  691. fRunAna->Run((Long64_t)++iCurrentEvent);
  692. }
  693. // go to previous FairRunAna event for scene data getting
  694. void MpdEventManager::PrevEvent()
  695. {
  696. fRunAna->Run((Long64_t)--iCurrentEvent);
  697. }
  698. // assign different colors for differrent particles
  699. // return integer value of color for track by particle pdg (default, white)
  700. Int_t MpdEventManager::Color(int pdg)
  701. {
  702. if (fPDGToColor.find(pdg) != fPDGToColor.end())
  703. return fPDGToColor[pdg];
  704. return 0;
  705. }
  706. // add particles to the PDG data base: Deuteron, Triton, Alpha, HE3; Cherenkov, FeedbackPhoton
  707. void MpdEventManager::AddParticlesToPdgDataBase()
  708. {
  709. TDatabasePDG* pdgDB = TDatabasePDG::Instance();
  710. const Double_t kAu2Gev = 0.9314943228;
  711. const Double_t khSlash = 1.0545726663e-27;
  712. const Double_t kErg2Gev = 1/1.6021773349e-3;
  713. const Double_t khShGev = khSlash*kErg2Gev;
  714. const Double_t kYear2Sec = 3600*24*365.25;
  715. // Ions
  716. if (!pdgDB->GetParticle(1000010020))
  717. pdgDB->AddParticle("Deuteron","Deuteron", 2*kAu2Gev+8.071e-3,kTRUE, 0, 3, "Ion", 1000010020);
  718. if (!pdgDB->GetParticle(1000010030))
  719. pdgDB->AddParticle("Triton","Triton", 3*kAu2Gev+14.931e-3, kFALSE, khShGev/(12.33*kYear2Sec), 3, "Ion", 1000010030);
  720. if (!pdgDB->GetParticle(1000020040))
  721. pdgDB->AddParticle("Alpha","Alpha", 4*kAu2Gev+2.424e-3, kTRUE, khShGev/(12.33*kYear2Sec), 6, "Ion", 1000020040);
  722. if (!pdgDB->GetParticle(1000020030))
  723. pdgDB->AddParticle("HE3","HE3", 3*kAu2Gev+14.931e-3, kFALSE, 0, 6, "Ion", 1000020030);
  724. // Special particles
  725. if (!pdgDB->GetParticle(50000050))
  726. pdgDB->AddParticle("Cherenkov","Cherenkov", 0, kFALSE, 0, 0, "Special", 50000050);
  727. if (!pdgDB->GetParticle(50000051))
  728. pdgDB->AddParticle("FeedbackPhoton","FeedbackPhoton", 0, kFALSE, 0, 0, "Special", 50000051);
  729. }
  730. void MpdEventManager::AddEventElement(TEveElement* element, ElementList element_list)
  731. {
  732. switch (element_list)
  733. {
  734. case MCPointList:
  735. {
  736. if (EveMCPoints == nullptr)
  737. {
  738. EveMCPoints = new TEveElementList("MC points");
  739. gEve->AddElement(EveMCPoints, this);
  740. EveMCPoints->SetRnrState(kFALSE);
  741. GetEventEditor()->fShowMCPoints->SetEnabled(kTRUE);
  742. }
  743. gEve->AddElement(element, EveMCPoints);
  744. break;
  745. }
  746. case MCTrackList:
  747. {
  748. if (EveMCTracks == nullptr)
  749. {
  750. EveMCTracks = new TEveElementList("MC tracks");
  751. gEve->AddElement(EveMCTracks, this);
  752. EveMCTracks->SetRnrState(kFALSE);
  753. GetEventEditor()->fShowMCTracks->SetEnabled(kTRUE);
  754. }
  755. gEve->AddElement(element, EveMCTracks);
  756. break;
  757. }
  758. case RecoPointList:
  759. {
  760. if (EveRecoPoints == nullptr)
  761. {
  762. EveRecoPoints = new TEveElementList("Reco points");
  763. gEve->AddElement(EveRecoPoints, this);
  764. EveRecoPoints->SetRnrState(kFALSE);
  765. GetEventEditor()->fShowRecoPoints->SetEnabled(kTRUE);
  766. }
  767. gEve->AddElement(element, EveRecoPoints);
  768. break;
  769. }
  770. case RecoTrackList:
  771. {
  772. if (EveRecoTracks == nullptr)
  773. {
  774. EveRecoTracks = new TEveElementList("Reco tracks");
  775. gEve->AddElement(EveRecoTracks, this);
  776. EveRecoTracks->SetRnrState(kFALSE);
  777. GetEventEditor()->fShowRecoTracks->SetEnabled(kTRUE);
  778. }
  779. gEve->AddElement(element, EveRecoTracks);
  780. break;
  781. }
  782. }// switch (element_list)
  783. }
  784. void MpdEventManager::LoadXMLSettings()
  785. {
  786. TDOMParser* Parser = new TDOMParser();
  787. Parser->SetValidate(kFALSE);
  788. Parser->ParseFile(fXMLConfig);
  789. TXMLNode* MainNode = Parser->GetXMLDocument()->GetRootNode();
  790. MpdXMLFile xmlfile(fXMLConfig,"read");
  791. MpdXMLNode* xml = xmlfile.GetRootNode();
  792. for (int i = 0; i < xml->GetNChildren(); i++)
  793. {
  794. TString nodename = xml->GetChild(i)->GetName();
  795. if (nodename.EqualTo("Detectors"))
  796. {
  797. TGeoNode* top = gGeoManager->GetTopNode();
  798. MpdXMLNode* top_xml = xml->GetChild(i)->GetChild(0);
  799. if(top_xml != nullptr)
  800. LoadXMLDetector(top, top_xml);
  801. }
  802. else if (nodename.EqualTo("MCTracksColors"))
  803. {
  804. MpdXMLNode* colors = xml->GetChild(i);
  805. for (int j = 0; j < colors->GetNChildren(); j++)
  806. {
  807. MpdXMLNode* color = colors->GetChild(j);
  808. TString pgd_code = color->GetAttrib("pdg")->GetValue();
  809. TString color_code = color->GetAttrib("color")->GetValue();
  810. fPDGToColor[pgd_code.Atoi()] = StringToColor(color_code);
  811. }
  812. }
  813. }
  814. }
  815. void MpdEventManager::LoadXMLDetector(TGeoNode* node, MpdXMLNode* xml, Int_t depth)
  816. {
  817. TString name = xml->GetAttrib("name")->GetValue();
  818. TString node_name = node->GetName();
  819. Bool_t recursive = (xml->GetAttrib("recursive")->GetValue().Length()!=0&&!name.EqualTo(node_name));
  820. if (recursive && depth == 0)
  821. return;
  822. TString color = xml->GetAttrib("color")->GetValue();
  823. if (!color.EqualTo(""))
  824. {
  825. node->GetVolume()->SetFillColor(StringToColor(color));
  826. node->GetVolume()->SetLineColor(StringToColor(color));
  827. }
  828. TString transparency = xml->GetAttrib("transparency")->GetValue();
  829. if (!transparency.EqualTo(""))
  830. node->GetVolume()->SetTransparency((Char_t)(transparency.Atoi()));
  831. if (xml->GetAttrib("recursive")->GetValue().Length()>0)
  832. {
  833. TString val = xml->GetAttrib("recursive")->GetValue();
  834. Int_t xml_depth = val.Atoi();
  835. if (recursive)
  836. xml_depth =depth-1;
  837. for (int i = 0; i < node->GetNdaughters(); i++)
  838. {
  839. TGeoNode* daughter_node = node->GetDaughter(i);
  840. LoadXMLDetector(daughter_node, xml, xml_depth);
  841. }
  842. }
  843. if (xml->GetNChildren() > 0 && !recursive)
  844. {
  845. for (int i = 0; i < node->GetNdaughters(); i++)
  846. {
  847. TString subdetector_name = node->GetDaughter(i)->GetName();
  848. for (int j = 0; j < xml->GetNChildren(); j++)
  849. {
  850. MpdXMLNode* subnode = xml->GetChild(j);
  851. TString subnode_name = subnode->GetAttrib("name")->GetValue();
  852. if (subnode_name == subdetector_name)
  853. LoadXMLDetector(node->GetDaughter(i), subnode);
  854. }
  855. }
  856. }
  857. }
  858. ClassImp(MpdEventManager)