Class Reference for E1039 Core & Analysis Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PHEveDisplay.cxx
Go to the documentation of this file.
1 /*
2  \file PHEveDisplay.cxx
3  \author Sookhyun Lee
4  \brief main display module,
5  load geometry, configure b-field, add elements.
6  \version $Revision: 1.2 $
7  \date $Date: 07/26/2016
8 */
9 
10 // STL and BOOST includes
11 #include <iostream>
12 #include <string>
13 #include <stdexcept>
14 //#include <boost/shared_ptr.hpp>
15 #include <fun4all/Fun4AllServer.h>
16 #include <phool/PHCompositeNode.h>
17 #include <phool/phool.h>
18 #include <phgeom/PHGeomUtility.h>
19 
20 // EVE class includes
21 #include "TEveManager.h"
22 #include "TEveVSDStructs.h"
23 #include "TEveGeoNode.h"
24 #include "TEveVector.h"
25 #include "TEveTrack.h"
26 #include "TEveTrackPropagator.h"
27 #include "TEvePointSet.h"
28 #include "TEveWindowManager.h"
29 #include "TEveWindow.h"
30 #include "TEveViewer.h"
31 #include "TEveBrowser.h"
32 
33 #include "TGeoManager.h"
34 #include "TGeoNode.h"
35 #include "TGeoVolume.h"
36 #include "TGeoMedium.h"
37 
38 #include "TGLViewer.h"
39 #include "TGPack.h"
40 
41 #include "TSystem.h"
42 #include "TStyle.h"
43 #include "TFile.h"
44 #include "TMath.h"
45 
46 #include <phfield/PHField.h>
47 #include "PHEveDisplay.h"
48 
49 using namespace CLHEP;
50 
52  int h,
53  bool use_fieldmap,
54  bool use_geofile,
55  const std::string& mapname,
56  const std::string& filename,
57  int verb) :
58  _top_list(NULL),
59  _dc_list(NULL),
60  _hodo_list(NULL),
61  _prop_list(NULL),
62  _dp_list(NULL),
63  _true_list(NULL),
64  cnt_prop(NULL),
65  mapped_field(NULL),
66  _width(w),
67  _height(h),
68  _use_fieldmap(use_fieldmap),
69  _use_geofile(use_geofile),
70  _jet_pt_threshold(5.0),
71  _calo_e_threshold(0.2),
72  map_filename(mapname),
73  geo_filename(filename),
74  verbosity(verb)
75 {
76  if (verbosity) std::cout << "PHEveDisplay initialized. " << std::endl;
77 
78  if (verbosity>1){
80  se->Print("NODETREE");}
81 
82 }
83 
85 {
86  try {
87  TEveManager::Terminate();
88  } catch (std::exception &e) {
89  std::cout << "Exception caught during deconstruction: " << e.what() << std::endl;
90  }
91 }
92 
93 void
94 PHEveDisplay::load_geometry(PHCompositeNode *topNode, TEveManager* geve)
95 {
96  TFile* geom = new TFile();
97  if (_use_geofile) {
98  geom = TFile::Open(geo_filename.c_str());
99  if (!geom)
100  throw std::runtime_error("Could not open sphenix_geo.root geometry file, aborting.");
101  geve->GetGeometry(geo_filename.c_str());
102  //gGeoManager->DefaultColors();
103  } else {
104  if(verbosity) {
105  std::cout << "PHEveDisplay::load_geometry:" << " Using PHGeomUtility for Geometry" << std::endl;
106  }
108  assert(gGeoManager);
109  }
110 
111  gStyle->SetPalette(1);
112  TGeoVolume* top = gGeoManager->GetTopVolume();
113  const int nd = top->GetNdaughters();
114  std::cout << "nd= " << nd << std::endl;
115  TGeoNode* node[nd];
116 
117  for (int i = 0; i < nd; i++) {
118  node[i] = top->GetNode(i);
119  std::cout << "Node " << i << " : " << node[i]->GetName() << std::endl;
120 
121  node[i]->GetVolume()->SetTransparency(95); // 0: opaque, 100: transparent
122 
123  std::string name(node[i]->GetName());
124  if (name.find("fmag") < 5 || name.find("kmag") < 5) { // make fmag
125  TGeoVolume* subvol = node[i]->GetVolume();
126  const int nsub = subvol->GetNdaughters();
127  TGeoNode* subnod[nsub];
128  for (int j = 0; j < nsub; j++) {
129  subnod[j] = subvol->GetNode(j);
130  subnod[j]->GetVolume()->SetTransparency(100);
131  }
132  }
133  }
134 
135  TGeoNode *node_c = gGeoManager->GetCurrentNode();
136  TEveGeoTopNode* tnode_c = new TEveGeoTopNode(gGeoManager, node_c);
137  gEve->AddGlobalElement(tnode_c);
138 
139 
140  if (_use_geofile) {
141  geom->Close();
142  delete geom;
143  }
144 }
145 
146 void
147 PHEveDisplay::add_elements(TEveManager* geve)
148 {
149 
150  _top_list = new TEveElementList("TOP");
151  _dc_list = new TEveElementList("DC");
152  _hodo_list = new TEveElementList("HODO");
153  _prop_list = new TEveElementList("PROP");
154  _dp_list = new TEveElementList("DP");
155  _true_list = new TEveElementList("TRUE");
156 
157  geve->AddElement(_top_list);
158  geve->AddElement(_dc_list, _top_list);
159  geve->AddElement(_hodo_list,_top_list);
160  geve->AddElement(_prop_list,_top_list);
161  geve->AddElement(_dp_list, _top_list);
162  geve->AddElement(_true_list,_top_list);
163 }
164 
165 void
167 {
168  if (_use_fieldmap) {
169  if (verbosity > 1)
170  std::cout << "PHEveDisplay::config_bfields:" << " Field from file deprecated!!" << std::endl;
171  } else {
172  if (verbosity > 1)
173  std::cout << "PHEveDisplay::config_bfields:" << " Using PHField fields for track propagation" << std::endl;
174  cnt_prop = new TEveTrackPropagator("cnt_prop", "Current Propagator", new MappedField(field));
175  cnt_prop->SetMaxStep(2);
176  }
177 
178  cnt_prop->SetStepper(TEveTrackPropagator::kRungeKutta);
179  cnt_prop->SetMaxR(300);
180  cnt_prop->SetMaxZ(2500);
181 }
182 
183 void
184 PHEveDisplay::go_fullscreen(TEveManager* geve)
185 {
186  TEveViewer* cur_win = geve->GetDefaultViewer();
187  TEveCompositeFrame* fEveFrame = cur_win->GetEveFrame();
188  TEveWindow* return_cont = fEveFrame->GetEveParentAsWindow();
189 
190  if (return_cont && ! return_cont->CanMakeNewSlots())
191  return_cont = 0;
192 
193  TEveCompositeFrameInPack* packframe = dynamic_cast<TEveCompositeFrameInPack*>(fEveFrame);
194  if (packframe) {
195  TGPack* pack = (TGPack*)(packframe->GetParent());
196  pack->HideFrame(fEveFrame);
197  }
198 
199  TGMainFrame* mf = new TGMainFrame(gClient->GetRoot(),_width,_height);
200  gVirtualX->SetMWMHints(mf->GetId(),0,0,0);
201  mf->SetCleanup(kLocalCleanup);
202 
203  TEveCompositeFrameInMainFrame *slot = new TEveCompositeFrameInMainFrame(mf, 0, mf);
204  TEveWindowSlot* ew_slot = TEveWindow::CreateDefaultWindowSlot();
205  ew_slot->PopulateEmptyFrame(slot);
206 
207  mf->AddFrame(slot, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY));
208  slot->MapWindow();
209 
210  mf->Layout();
211  mf->MapWindow();
212 
213  TEveWindow::SwapWindows(ew_slot, cur_win);
214 
215  ((TEveCompositeFrameInMainFrame*) fEveFrame)->
216  SetOriginalSlotAndContainer(ew_slot, return_cont);
217 
218  geve->GetWindowManager()->HideAllEveDecorations();
219  geve->GetWindowManager()->WindowUndocked(cur_win);
220 
221  int offset = -8;
222 
223  gVirtualX->MoveResizeWindow(mf->GetId(), 0, offset, _width, _height);
224 }
225 
227  TEveMagField(),
228  _fieldmap(field)
229 {
230 }
231 
232 TEveVectorD
233 PHEveDisplay::MappedField::GetFieldD(Double_t x, Double_t y, Double_t z) const
234 {
235  // input pos in cm; PHFiled used CLHEP units
236  double loc[4];
237  loc[0]=x*cm; loc[1]=y*cm; loc[2]=z*cm; loc[3]=0;
238  double bvec[3];
239  //_fieldmap->get_bfield(&loc[0],&bvec[0]);
240  _fieldmap->GetFieldValue(loc, bvec);
241  const double unit = tesla; // gauss, tesla
242  TEveVectorD vec(
243  bvec[0]/unit,
244  bvec[1]/unit,
245  bvec[2]/unit); // unit is Gauss (1Tesla = 10000 Gauss)
246 // std::cout
247 // << "GetFieldD: "
248 // << " { " << x << ", " << y << ", " << z << " } "
249 // << " { " << bvec[0]/tesla << ", " << bvec[1]/tesla << ", " << bvec[2]/tesla << " } "
250 // << std::endl;
251  //TEveVectorD vec(0, 0, 0); // unit is Gauss (1Tesla = 10000 Gauss)
252 
253  return vec;
254 }
255 
bool _use_fieldmap
Definition: PHEveDisplay.h:87
TEveElementList * _prop_list
Definition: PHEveDisplay.h:78
TEveElementList * _true_list
Definition: PHEveDisplay.h:80
TEveElementList * _hodo_list
Definition: PHEveDisplay.h:77
void load_geometry(PHCompositeNode *topNode, TEveManager *geve)
virtual void Print(const std::string &what="ALL") const
MappedField(const PHField *field)
static Fun4AllServer * instance()
Fun4AllServer * se
TEveElementList * _dc_list
Definition: PHEveDisplay.h:76
transient DST object for field storage and access
Definition: PHField.h:13
void config_bfields(const PHField *field)
#define NULL
Definition: Pdb.h:9
TEveElementList * _top_list
Definition: PHEveDisplay.h:75
TEveTrackPropagator * cnt_prop
Definition: PHEveDisplay.h:82
TEveElementList * _dp_list
Definition: PHEveDisplay.h:79
virtual TEveVectorD GetFieldD(Double_t x, Double_t y, Double_t z) const
static TGeoManager * GetTGeoManager(PHCompositeNode *topNode)
Main user interface: DST node -&gt; TGeoManager for downstream use.
std::string geo_filename
Definition: PHEveDisplay.h:94
PHEveDisplay(int w, int h, bool use_fieldmap, bool use_goefile, const std::string &mapname, const std::string &filename, int verb)
void add_elements(TEveManager *geve)
void go_fullscreen(TEveManager *geve)
bool _use_geofile
Definition: PHEveDisplay.h:88