Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
hdv_fulllistframe.cc
Go to the documentation of this file.
1 
2 #include <iostream>
3 #include <iomanip>
4 #include <sstream>
5 #include <cmath>
6 #include <fstream>
7 using namespace std;
8 
9 #include <pthread.h>
10 
11 #include <TRACKING/DMCThrown.h>
12 #include "hdv_fulllistframe.h"
13 #include "hdview2.h"
14 #include "MyProcessor.h"
15 #include "FDC/DFDCGeometry.h"
16 #include "FCAL/DFCALGeometry.h"
17 #include "DVector2.h"
18 #include "HDGEOMETRY/DGeometry.h"
19 #include <PID/DNeutralParticle.h>
22 #include <TRACKING/DMCThrown.h>
23 
24 #include <TPolyMarker.h>
25 #include <TLine.h>
26 #include <TMarker.h>
27 #include <TBox.h>
28 #include <TVector3.h>
29 #include <TGeoVolume.h>
30 #include <TGeoManager.h>
31 #include <TGLabel.h>
32 #include <TGComboBox.h>
33 #include <TGButton.h>
34 #include <TGButtonGroup.h>
35 #include <TGTextEntry.h>
36 #include <TArrow.h>
37 #include <TLatex.h>
38 #include <TColor.h>
39 #include <TG3DLine.h>
40 #include <TGListView.h>
41 #include <TGTextView.h>
42 
43 extern JApplication *japp;
44 //TGeoVolume *MOTHER = NULL;
45 //TGeoCombiTrans *MotherRotTrans = NULL;
46 
47 extern int GO;
48 
49 
50 //-------------------
51 // Constructor
52 //-------------------
53 hdv_fulllistframe::hdv_fulllistframe(hdv_mainframe *hdvmf, const TGWindow *p, UInt_t w, UInt_t h):TGMainFrame(p,w,h)
54 {
55  this->hdvmf = hdvmf;
56 
57  // First, define all of the of the graphics objects. Below that, make all
58  // of the connections to the methods so these things will work!
59 
60  // The main GUI window is divided into three sections, top, middle, and bottom.
61  // Create those frames here.
62  TGLayoutHints *lhints = new TGLayoutHints(kLHintsNormal, 2,2,2,2);
63  TGLayoutHints *chints = new TGLayoutHints(kLHintsCenterY|kLHintsCenterX, 2,2,2,2);
64  TGLayoutHints *xhints = new TGLayoutHints(kLHintsNormal|kLHintsExpandX, 2,2,2,2);
65  TGHorizontalFrame *topframe = new TGHorizontalFrame(this, w, h);
66  TGHorizontalFrame *botframe = new TGHorizontalFrame(this, w, h);
67  AddFrame(topframe, lhints);
68  AddFrame(botframe, chints);
69 
70  TGGroupFrame *trackinfo = new TGGroupFrame(topframe, "Track Info", kHorizontalFrame);
71  topframe->AddFrame(trackinfo, xhints);
72 
73  //------ Track Info ------
74  throwninfo = new TGGroupFrame(trackinfo, "Thrown", kHorizontalFrame);
75  reconinfo = new TGGroupFrame(trackinfo, "Reconstructed", kHorizontalFrame);
76  trackinfo->AddFrame(throwninfo, lhints);
77  trackinfo->AddFrame(reconinfo, lhints);
78 
79  // Column names
80  vector<string> colnames;
81  colnames.push_back("trk");
82  colnames.push_back("type");
83  colnames.push_back("p");
84  colnames.push_back("theta");
85  colnames.push_back("phi");
86  colnames.push_back("z");
87  colnames.push_back("chisq/Ndof");
88  colnames.push_back("Ndof");
89  colnames.push_back("FOM");
90  colnames.push_back("cand");
91 
92  TGTextView *tview = new TGTextView(throwninfo, 700, 400);
93  throwninfo->AddFrame(tview);
94 
95  tview->AddLine("Here is a line");
96  //tview->AdjustWidth();
97 #if 0
98 
99  // Create TGListView objects to hold the thrown the thrown and reconstructed values
100  TGListView *thrownview = new TGListView(throwninfo, 700, 400);
101  throwninfo->AddFrame(thrownview, hints);
102 
103  TGLVContainer *lvcontainer = new TGLVContainer(thrownview);
104 
105  thrownview->SetHeaders(6);
106  for(unsigned int i=0; i<colnames.size(); i++){
107  if(i<6)thrownview->SetHeader(colnames[i].c_str(), 2, 1, i);
108  }
109 
110  TGLVEntry *item = new TGLVEntry(lvcontainer, "One item", "TFolder");
111  lvcontainer->AddItem(item);
112 
113  // Create a vertical frame for each column and insert the label as the first item
114  for(unsigned int i=0; i<colnames.size(); i++){
115  // create frames
116  tf[colnames[i]] = new TGVerticalFrame(throwninfo);
117  rf[colnames[i]] = new TGVerticalFrame(reconinfo);
118  throwninfo->AddFrame(tf[colnames[i]], bhints);
119  reconinfo->AddFrame(rf[colnames[i]], bhints);
120 
121  // create column labels
122  string lab = colnames[i]+":";
123  TGLabel *tl = new TGLabel(tf[colnames[i]], lab.c_str());
124  TGLabel *rl = new TGLabel(rf[colnames[i]], lab.c_str());
125  if(i<6)tf[colnames[i]]->AddFrame(tl, chints);
126  rf[colnames[i]]->AddFrame(rl, chints);
127  vector<TGLabel*> tv;
128  vector<TGLabel*> rv;
129  tv.push_back(tl);
130  rv.push_back(rl);
131 
132  // Record the label object pointers for later use
133  thrownlabs[colnames[i]] = tv;
134  reconlabs[colnames[i]] = rv;
135  }
136 
137  // Reconstruction factory and full list button
138  TGVerticalFrame *vf = new TGVerticalFrame(reconinfo);
139  reconinfo->AddFrame(vf, yhints);
140  reconfactory = new TGComboBox(vf, "DTrackCandidate:", 0);
141  reconfactory->Resize(160,20);
142  vf->AddFrame(reconfactory, thints);
143 #endif
144 
145  //========== Close Button ===========
146  TGTextButton *close = new TGTextButton(botframe, "Close");
147  botframe->AddFrame(close, chints);
148 
149  //&&&&&&&&&&&&&&&& Connections
150  close->Connect("Clicked()","hdv_fulllistframe", this, "DoClose()");
151  this->Connect("CloseWindow()", "hdv_fulllistframe", this, "DoClose()");
152  this->DontCallClose();
153 
154  // Finish up and map the window
155  SetWindowName("Hall-D Event Viewer Full Particle Listing");
156  SetIconName("HDView");
157 
158  MapSubwindows();
159  Resize(GetDefaultSize());
160 
161  tview->Update();
162 }
163 
164 //-------------------
165 // DoClose
166 //-------------------
168 {
169  UnmapWindow();
170 }
171 
172 //-------------------
173 // UpdateTrackLabels
174 //-------------------
175 void hdv_fulllistframe::UpdateTrackLabels(vector<const DMCThrown*> &throwns, vector<const DKinematicData*> &trks)
176 {
177 #if 0
178 _DBG__;
179  //if(!IsMapped())return; // don't bother updating unless we can actually be seen
180 _DBG__;
181 
182  // Make sure there are enough labels for all of the thrown particles
183  map<string, vector<TGLabel*> >::iterator iter = thrownlabs.begin();
184  for(; iter!=thrownlabs.end(); iter++){
185 _DBG__;
186  vector<TGLabel*> &labels = iter->second;
187  unsigned int max_rows = throwns.size();
188  if(max_rows>20)max_rows=20;
189  for(unsigned int row = labels.size(); row<max_rows+1; row++){
190  stringstream ss;
191  ss<<row;
192  TGLabel *lab = new TGLabel(tf[iter->first], iter==thrownlabs.begin() ? ss.str().c_str():"--------");
193  tf[iter->first]->AddFrame(lab, new TGLayoutHints(kLHintsTop|kLHintsCenterX, 2,2,0,0));
194  labels.push_back(lab);
195 _DBG_<<"Adding row:"<<row<<endl;
196  }
197  }
198 
199  // Loop over thrown particles and fill in labels
200  int ii=0;
201  for(unsigned int i=0; i<throwns.size(); i++){
202  const DMCThrown *trk = throwns[i];
203  //if(trk->type==0)continue;
204  int row = thrownlabs["trk"].size()-(ii++)-1;
205  if(row<1)break;
206 
207  stringstream trkno, type, p, theta, phi, z;
208  trkno<<setprecision(4)<<i+1;
209  thrownlabs["trk"][row]->SetText(trkno.str().c_str());
210 
211  thrownlabs["type"][row]->SetText(ParticleType((Particle_t)trk->type));
212 
213  p<<setprecision(4)<<trk->momentum().Mag();
214  thrownlabs["p"][row]->SetText(p.str().c_str());
215 
216  theta<<setprecision(4)<<trk->momentum().Theta()*TMath::RadToDeg();
217  thrownlabs["theta"][row]->SetText(theta.str().c_str());
218 
219  double myphi = trk->momentum().Phi();
220  if(myphi<0.0)myphi+=2.0*M_PI;
221  phi<<setprecision(4)<<myphi;
222  thrownlabs["phi"][row]->SetText(phi.str().c_str());
223 
224  z<<setprecision(4)<<trk->position().Z();
225  thrownlabs["z"][row]->SetText(z.str().c_str());
226  }
227 
228  // Loop over tracks and fill in labels
229  for(unsigned int i=0; i<trks.size(); i++){
230  const DKinematicData *trk = trks[i];
231  int row = reconlabs["trk"].size()-i-1;
232  if(row<1)break;
233 
234  stringstream trkno, type, p, theta, phi, z, chisq_per_dof, Ndof;
235  stringstream fom;
236  trkno<<setprecision(4)<<i+1;
237  reconlabs["trk"][row]->SetText(trkno.str().c_str());
238 
239  double mass = trk->mass();
240  if(fabs(mass-0.13957)<1.0E-4)type<<"pi";
241  else if(fabs(mass-0.93827)<1.0E-4)type<<"proton";
242  else if(fabs(mass-0.493677)<1.0E-4)type<<"K";
243  else if(fabs(mass-0.000511)<1.0E-4)type<<"e";
244  else if (fabs(mass)<1.e-4 && fabs(trk->charge())<1.e-4) type << "gamma";
245  else type<<"q=";
246  if (fabs(trk->charge())>1.e-4){
247  type<<(trk->charge()>0 ? "+":"-");
248  }
249  reconlabs["type"][row]->SetText(type.str().c_str());
250 
251  p<<setprecision(4)<<trk->momentum().Mag();
252  reconlabs["p"][row]->SetText(p.str().c_str());
253 
254  theta<<setprecision(4)<<trk->momentum().Theta()*TMath::RadToDeg();
255  reconlabs["theta"][row]->SetText(theta.str().c_str());
256 
257  double myphi = trk->momentum().Phi();
258  if(myphi<0.0)myphi+=2.0*M_PI;
259  phi<<setprecision(4)<<myphi;
260  reconlabs["phi"][row]->SetText(phi.str().c_str());
261 
262  z<<setprecision(4)<<trk->position().Z();
263  reconlabs["z"][row]->SetText(z.str().c_str());
264 
265  // Get chisq and Ndof for DTrackTimeBased or DTrackWireBased objects
266  const DTrackTimeBased *timetrack=dynamic_cast<const DTrackTimeBased*>(trk);
267  const DTrackWireBased *track=dynamic_cast<const DTrackWireBased*>(trk);
268 
269  if(timetrack){
270  chisq_per_dof<<setprecision(4)<<timetrack->chisq/timetrack->Ndof;
271  Ndof<<timetrack->Ndof;
272  fom << timetrack->FOM;
273  }else if(track){
274  chisq_per_dof<<setprecision(4)<<track->chisq/track->Ndof;
275  Ndof<<track->Ndof;
276  fom << "N/A";
277  }else{
278  chisq_per_dof<<"N/A";
279  Ndof<<"N/A";
280  fom << "N/A";
281  }
282  reconlabs["chisq/Ndof"][row]->SetText(chisq_per_dof.str().c_str());
283  reconlabs["Ndof"][row]->SetText(Ndof.str().c_str());
284  reconlabs["FOM"][row]->SetText(fom.str().c_str());
285  }
286 #endif
287 
288  MapSubwindows();
289  Resize(GetDefaultSize());
290 }
291 
292 
Definition: track.h:16
float chisq
Chi-squared for the track (not chisq/dof!)
float chisq
Chi-squared for the track (not chisq/dof!)
hdv_fulllistframe(hdv_mainframe *hdvmf, const TGWindow *p, UInt_t w, UInt_t h)
textOut close()
const DVector3 & position(void) const
TGGroupFrame * reconinfo
static char * ParticleType(Particle_t p)
Definition: particleType.h:142
map< string, TGVerticalFrame * > rf
map< string, vector< TGLabel * > > thrownlabs
JApplication * japp
void UpdateTrackLabels(vector< const DMCThrown * > &throwns, vector< const DKinematicData * > &trks)
TEllipse * e
TGComboBox * reconfactory
TGGroupFrame * throwninfo
#define _DBG_
Definition: HDEVIO.h:12
map< string, TGVerticalFrame * > tf
int Ndof
Number of degrees of freedom in the fit.
double charge(void) const
#define _DBG__
Definition: HDEVIO.h:13
int Ndof
Number of degrees of freedom in the fit.
const DVector3 & momentum(void) const
int GO
Definition: hdview2.cc:10
hdv_mainframe * hdvmf
hdv_mainframe * hdvmf
int type
GEANT particle ID.
Definition: DMCThrown.h:20
map< string, vector< TGLabel * > > reconlabs
double mass(void) const
Particle_t
Definition: particleType.h:12