Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
trk_mainframe.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: trk_mainframe.cc
4 // Created: Wed Apr 9 08:11:16 EDT 2008
5 // Creator: davidl (on Darwin Amelia.local 8.11.1 i386)
6 //
7 
8 #include <cmath>
9 using namespace std;
10 
11 #include "trk_mainframe.h"
12 #include "hdv_mainframe.h"
13 #include "hdview2.h"
14 #include "MyProcessor.h"
15 
16 #include <CDC/DCDCWire.h>
17 #include <CDC/DCDCTrackHit.h>
19 
20 #include <TGButtonGroup.h>
21 #include <TGTextEntry.h>
22 #include <TArrow.h>
23 #include <TLatex.h>
24 #include <TGaxis.h>
25 #include <TColor.h>
26 #include <TROOT.h>
27 #include <TF1.h>
28 
29 
30 
31 // We declare this as a global since putting it in the class would
32 // require defining the DReferenceTrajectory class to ROOT
33 static vector<DReferenceTrajectory*> REFTRAJ;
34 
35 // Ditto
36 static vector<pair<const DCoordinateSystem*,double> > TRACKHITS;
37 static map<const DCoordinateSystem*,double> S_VALS;
38 
39 
40 int colors[]={kBlue, kRed, kMagenta, kGreen, kCyan};
41 int ncolors=5;
42 
43 
44 //---------------------------------
45 // trk_mainframe (Constructor)
46 //---------------------------------
47 trk_mainframe::trk_mainframe(hdv_mainframe *hdvmf, const TGWindow *p, UInt_t w, UInt_t h):TGMainFrame(p,w,h)
48 {
49  this->hdvmf = hdvmf;
50 
51  TGLayoutHints *lhints = new TGLayoutHints(kLHintsNormal, 2,2,2,2);
52  TGLayoutHints *bhints = new TGLayoutHints(kLHintsBottom|kLHintsCenterX, 2,2,2,2);
53  TGLayoutHints *bbhints = new TGLayoutHints(kLHintsTop, 2,2, -8,-8);
54  TGLayoutHints *thints = new TGLayoutHints(kLHintsTop|kLHintsCenterX, 2,2,2,2);
55  TGLayoutHints *ahints = new TGLayoutHints(kLHintsLeft|kLHintsTop, 2,2,2,2);
56  TGLayoutHints *xhints = new TGLayoutHints(kLHintsNormal|kLHintsExpandX, 2,2,2,2);
57  //TGLayoutHints *rhints = new TGLayoutHints(kLHintsRight, 2,2,2,2);
58  TGLayoutHints *dhints = new TGLayoutHints(kLHintsExpandY|kLHintsCenterY, 2,2,2,2);
59  TGLayoutHints *ehints = new TGLayoutHints(kLHintsCenterY, 2,2,2,2);
60 
61  TGHorizontalFrame *mainframe = new TGHorizontalFrame(this);
62  AddFrame(mainframe, ahints);
63 
64  //------- Left side
65  TGHorizontalFrame *leftframe = new TGHorizontalFrame(mainframe);
66  mainframe->AddFrame(leftframe, ahints);
67 
68  //------- Canvas + histo
69  TGVerticalFrame *canvasframe = new TGVerticalFrame(leftframe);
70  leftframe->AddFrame(canvasframe, bhints);
71 
72  int width=325;
73  canvas = new TRootEmbeddedCanvas("Track Canvas", canvasframe, width, (UInt_t)(2.0*width), kSunkenFrame, GetWhitePixel());
74  canvasframe->AddFrame(canvas, lhints);
75  canvas->SetScrolling(TGCanvas::kCanvasScrollBoth);
76 
77  slo = -10.0;
78  //shi = 437.0;
79  shi = 100.0;
80  resilo = -1000;
81  resihi = +1000;
82  canvas->GetCanvas()->cd();
83  canvas->GetCanvas()->Range(resilo, slo, resihi, shi);
84 
85  histocanvas = new TRootEmbeddedCanvas("Histo Canvas", canvasframe, width, (UInt_t)(width/5.0), kSunkenFrame, GetWhitePixel());
86  canvasframe->AddFrame(histocanvas, lhints);
87  histocanvas->SetScrolling(TGCanvas::kCanvasScrollBoth);
88 
89  gPad->SetGridy();
90  gPad->SetTicky();
91  gPad->SetTickx();
92  gPad->SetLeftMargin(0);
93  gPad->SetRightMargin(0);
94  gPad->SetTopMargin(0);
95  resi = new TH1D("resi", "", 30, -0.1, 0.1);
96  resi->SetStats(0);
97  resi->SetFillStyle(3002);
98  resi->SetFillColor(kMagenta);
99  resi->Draw();
100 
101  resi_lab = new TLatex(resihi-0.25*(resihi-resilo), 0.5, "#sigma=?#mum");
102  resi_lab->SetTextSize(0.02);
103  resi_lab->SetTextAlign(32);
104  resi_lab->Draw();
105 
106  //------- Hits radio buttons
107  TGVButtonGroup *hitsbuttons = new TGVButtonGroup(leftframe, "Hit");
108  leftframe->AddFrame(hitsbuttons, thints);
109  for(int i=34; i>=0; i--){
110  char title[256];
111  sprintf(title, "%2d", i);
112  TGRadioButton *but = new TGRadioButton(hitsbuttons, title);
113  hitsbuttons->AddFrame(but, bbhints);
114  }
115 
116  //------- Right side
117  TGVerticalFrame *rightframe = new TGVerticalFrame(mainframe);
118  mainframe->AddFrame(rightframe, ahints);
119 
120  //------- Controls
121  TGGroupFrame *controlsframe = new TGGroupFrame(rightframe, "Controls", kHorizontalFrame);
122  rightframe->AddFrame(controlsframe, xhints);
123 
124  //-------- Pan, Zoom, Reset
125  TGVerticalFrame *panzoomresetframe = new TGVerticalFrame(controlsframe);
126  controlsframe->AddFrame(panzoomresetframe, lhints);
127  TGHorizontalFrame *panzoomframe = new TGHorizontalFrame(panzoomresetframe);
128  panzoomresetframe->AddFrame(panzoomframe, lhints);
129 
130  //------- Pan
131  TGGroupFrame *panframe = new TGGroupFrame(panzoomframe, "Pan", kHorizontalFrame);
132  panzoomframe->AddFrame(panframe, dhints);
133  TGTextButton *panleft = new TGTextButton(panframe, "<");
134  TGVerticalFrame *updownframe = new TGVerticalFrame(panframe);
135  TGTextButton *panup = new TGTextButton(updownframe, "^");
136  TGTextButton *pandown = new TGTextButton(updownframe, "v");
137  updownframe->AddFrame(panup, dhints);
138  updownframe->AddFrame(pandown, dhints);
139  TGTextButton *panright = new TGTextButton(panframe, ">");
140  panframe->AddFrame(panleft, ehints);
141  panframe->AddFrame(updownframe, dhints);
142  panframe->AddFrame(panright, ehints);
143 
144  //------- Zoom
145  TGGroupFrame *zoomframe = new TGGroupFrame(panzoomframe, "Zoom", kVerticalFrame);
146  panzoomframe->AddFrame(zoomframe, lhints);
147  TGTextButton *zoomin = new TGTextButton(zoomframe, " + ");
148  TGTextButton *zoomout = new TGTextButton(zoomframe, " - ");
149  zoomframe->AddFrame(zoomin, lhints);
150  zoomframe->AddFrame(zoomout, lhints);
151 
152  TGTextButton *reset = new TGTextButton(panzoomresetframe, "reset");
153  panzoomresetframe->AddFrame(reset, xhints);
154 
155  slock = new TGCheckButton(panzoomresetframe,"lock s-axis");
156  panzoomresetframe->AddFrame(slock, xhints);
157  slock->Connect("Clicked()","trk_mainframe", this, "DoMyRedraw()");
158 
159  //-------- Event, Info frame
160  TGVerticalFrame *eventinfoframe = new TGVerticalFrame(controlsframe);
161  controlsframe->AddFrame(eventinfoframe, thints);
162 
163  //-------- Next, Previous
164  TGGroupFrame *prevnextframe = new TGGroupFrame(eventinfoframe, "Event", kHorizontalFrame);
165  eventinfoframe->AddFrame(prevnextframe, thints);
166  TGTextButton *prev = new TGTextButton(prevnextframe, "<-- Prev");
167  TGTextButton *next = new TGTextButton(prevnextframe, "Next -->");
168  prevnextframe->AddFrame(prev, lhints);
169  prevnextframe->AddFrame(next, lhints);
170 
171  next->Connect("Clicked()","hdv_mainframe", hdvmf, "DoNext()");
172  prev->Connect("Clicked()","hdv_mainframe", hdvmf, "DoPrev()");
173  next->Connect("Clicked()","trk_mainframe", this, "DoNewEvent()");
174  prev->Connect("Clicked()","trk_mainframe", this, "DoNewEvent()");
175 
176  //-------- Info
177  TGGroupFrame *infoframe = new TGGroupFrame(eventinfoframe, "Info", kVerticalFrame);
178  eventinfoframe->AddFrame(infoframe, thints);
179 
180  //------- Tracks to plot
181  for(int i=0; i<4; i++){
182  char title[256];
183  sprintf(title,"Track %d%s", i+1, i==0 ? " (s-axis source)":"");
184  TGGroupFrame *trackframe = new TGGroupFrame(rightframe, title, kHorizontalFrame);
185  rightframe->AddFrame(trackframe, xhints);
186 
187  //------ Color
188  TGLabel *lab = new TGLabel(trackframe," ");
189  trackframe->AddFrame(lab, dhints);
190  lab->SetBackgroundColor(gROOT->GetColor(colors[i%ncolors])->GetPixel());
191 
192  //------ Data type
193  TGVerticalFrame *datatypeframe = new TGVerticalFrame(trackframe);
194  trackframe->AddFrame(datatypeframe, thints);
195 
196  TGLabel *datatypelab = new TGLabel(datatypeframe, "Data type:");
197  datatypeframe->AddFrame(datatypelab, lhints);
198 
199  TGComboBox *datatype = new TGComboBox(datatypeframe, "DTrackCandidate", i);
200  datatypeframe->AddFrame(datatype, lhints);
201  this->datatype.push_back(datatype);
202  datatype->Resize(120,20);
203  datatype->SetUniqueID(i);
204  FillDataTypeComboBox(datatype, i==0 ? "DTrackTimeBased":"<none>");
205 
206  datatype->Connect("Selected(Int_t, Int_t)","trk_mainframe", this, "DoTagMenuUpdate(Int_t, Int_t)");
207  datatype->Connect("Selected(Int_t)","trk_mainframe", this, "DoRequestFocus(Int_t)");
208 
209  //------ Factory tag
210  TGVerticalFrame *factorytagframe = new TGVerticalFrame(trackframe);
211  trackframe->AddFrame(factorytagframe, thints);
212 
213  TGLabel *factorytaglab = new TGLabel(factorytagframe, "Factory Tag:");
214  factorytagframe->AddFrame(factorytaglab, lhints);
215 
216  TGComboBox *factorytag = new TGComboBox(factorytagframe, "<default>", i);
217  factorytagframe->AddFrame(factorytag, lhints);
218  this->factorytag.push_back(factorytag);
219  factorytag->Resize(100,20);
220  factorytag->SetUniqueID(i);
221  FillFactoryTagComboBox(factorytag, datatype, i==0 ? "ALT1":"<default>");
222 
223  factorytag->Connect("Selected(Int_t, Int_t)","trk_mainframe", this, "DoTrackNumberMenuUpdate(Int_t, Int_t)");
224  factorytag->Connect("Selected(Int_t)","trk_mainframe", this, "DoRequestFocus(Int_t)");
225 
226  //------ Track Number
227  TGVerticalFrame *tracknoframe = new TGVerticalFrame(trackframe);
228  trackframe->AddFrame(tracknoframe, thints);
229 
230  TGLabel *tracknolab = new TGLabel(tracknoframe, "Track:");
231  tracknoframe->AddFrame(tracknolab, lhints);
232 
233  TGComboBox *trackno = new TGComboBox(tracknoframe, i==0 ? "0":"", 0);
234  tracknoframe->AddFrame(trackno, lhints);
235  this->trackno.push_back(trackno);
236  trackno->Resize(85, 20);
237  trackno->SetUniqueID(i);
238 
239  trackno->Connect("Selected(Int_t)","trk_mainframe", this, "DoRequestFocus(Int_t)");
240  trackno->Connect("Selected(Int_t)","trk_mainframe", this, "DoMyRedraw()");
241  }
242 
243 
244  //------- Track Info
245  TGGroupFrame *trackinfoframe = new TGGroupFrame(rightframe, "Track Info", kVerticalFrame);
246  rightframe->AddFrame(trackinfoframe, xhints);
247 
248  //------- Hit Info
249  TGGroupFrame *hitinfoframe = new TGGroupFrame(rightframe, "Hit Info", kVerticalFrame);
250  rightframe->AddFrame(hitinfoframe, xhints);
251 
252 
253  // Finish up and map the window
254  SetWindowName("Hall-D Event Viewer:Track Inspector");
255  SetIconName("HDView:TrackInspector");
256  MapSubwindows();
257  Resize(GetDefaultSize());
258  MapWindow();
259 
260  RequestFocus();
261 
262  DoNewEvent();
263 }
264 
265 //---------------------------------
266 // ~trk_mainframe (Destructor)
267 //---------------------------------
269 {
271 }
272 
273 //---------------------------------
274 // DoNewEvent
275 //---------------------------------
277 {
278  DoUpdateMenus();
279  DoMyRedraw();
280 }
281 
282 //---------------------------------
283 // DoMyRedraw
284 //---------------------------------
286 {
287  // Delete any existing graphics objects
288  for(unsigned int i=0; i<graphics.size(); i++)delete graphics[i];
289  graphics.clear();
290 
291  // Draw hits on main canvas
293 
294  // Draw axes and scales
295  double smargin = 0.10*(shi-slo);
296  shi+=smargin;
297  slo-=smargin;
298  resihi = (shi-slo)/5.0/4.0;
299  resihi = 2.0;
300  resilo = -resihi;
301  canvas->GetCanvas()->cd();
302  canvas->GetCanvas()->Range(resilo, slo, resihi, shi);
303  DrawAxes(canvas->GetCanvas(), graphics, "wire pos(cm)", "s(cm)");
304 
305  // Draw everything
306  canvas->GetCanvas()->cd(0);
307  for(unsigned int i=0; i<graphics.size(); i++)graphics[i]->Draw();
308  canvas->GetCanvas()->Update();
309 
310  // Update the histogram
311  histocanvas->GetCanvas()->cd();
312  // Create my own gaussian fit function, in case predefined one gets lost somehow
313  static TF1 *mygaus = 0;
314  if (mygaus == 0)
315  mygaus = new TF1("mygaus", "[0]*exp(-0.5*((x-[1])/[2])**2)", -1e99, 1e99);
316  mygaus->SetParameter(0, resi->GetMaximum());
317  mygaus->SetParameter(1, resi->GetMean());
318  mygaus->SetParameter(2, resi->GetStdDev());
319  resi->Fit(mygaus,"Q");
320  double sigma = mygaus->GetParameter(2);
321 
322  // Update label (this doesn't work, but may be only a tweak away!)
323  char title[256];
324  sprintf(title, "#sigma=%3.0f#mum",sigma*1.0E4);
325  _DBG_<<title<<endl;
326  resi_lab->SetText(resi->GetXaxis()->GetXmax(), resi->GetMaximum()*0.5, title);
327  TVirtualPad *pad = gPad;
328  histocanvas->GetCanvas()->cd();
329  resi_lab->Draw();
330  pad->cd();
331 
332  histocanvas->GetCanvas()->Update();
333 }
334 
335 //---------------------------------
336 // DoHitSelect
337 //---------------------------------
339 {
340 _DBG__;
341 
342 }
343 
344 //---------------------------------
345 // DoUpdateMenus
346 //---------------------------------
348 {
349  for(unsigned int i=0; i<factorytag.size(); i++){
351  }
352 }
353 
354 //---------------------------------
355 // DoTagMenuUpdate
356 //---------------------------------
357 void trk_mainframe::DoTagMenuUpdate(Int_t widgetId, Int_t id)
358 {
359  if(widgetId>=0 && widgetId<(int)datatype.size()){
360  FillFactoryTagComboBox(factorytag[widgetId], datatype[widgetId], factorytag[widgetId]->GetTextEntry()->GetText());
361  factorytag[widgetId]->EmitVA("Selected(Int_t, Int_t)", 2, widgetId, id);
362  }
363 }
364 
365 //---------------------------------
366 // DoTrackNumberMenuUpdate
367 //---------------------------------
368 void trk_mainframe::DoTrackNumberMenuUpdate(Int_t widgetId, Int_t id)
369 {
370  if(widgetId>=0 && widgetId<(int)datatype.size()){
371  FillTrackNumberComboBox(trackno[widgetId], datatype[widgetId], factorytag[widgetId], widgetId!=0);
372  DoMyRedraw();
373  }
374 }
375 
376 //---------------------------------
377 // DoRequestFocus
378 //---------------------------------
380 {
381  RequestFocus();
382 }
383 
384 //---------------------------------
385 // FillDataTypeComboBox
386 //---------------------------------
387 void trk_mainframe::FillDataTypeComboBox(TGComboBox* cb, const string &def)
388 {
389  /// Ideally, this would feel out the factories whose
390  /// data types are based on DKinematicData. This is
391  /// not currently possbile with JANA though so we have
392  /// to simply add DTrackTimeBased, DTrackWireBased, DTrackCandidate, and DMCThrown
393  /// explicitly.
394 
395  vector<string> facnames;
396  if(def=="<none>")facnames.push_back(def);
397  facnames.push_back("DTrackTimeBased");
398  facnames.push_back("DTrackWireBased");
399  facnames.push_back("DTrackCandidate");
400  facnames.push_back("DMCThrown");
401 
402  cb->RemoveAll();
403  for(unsigned int i=0; i<facnames.size(); i++){
404  cb->AddEntry(facnames[i].c_str(), i);
405  if(def==facnames[i]){
406  cb->Select(i, kTRUE);
407  cb->GetTextEntry()->SetText(def.c_str());
408  }
409  }
410 }
411 
412 //---------------------------------
413 // FillFactoryTagComboBox
414 //---------------------------------
415 void trk_mainframe::FillFactoryTagComboBox(TGComboBox* cb, TGComboBox* datanamecb, const string &def)
416 {
417  /// Fill the given TGComboBox with the tags of the factories that
418  /// provide data of the type currently selected in the "datanamecb"
419  /// combo box.
420 
421  // Get the data type that is currently selected
422  string dataname = datanamecb->GetTextEntry()->GetText();
423 
424  // Get list of all factories
425  vector<JFactory_base*> factories;
426  gMYPROC->GetFactories(factories);
427 
428  // Loop over all factories, looking for ones with the desired
429  // data name. Add thier tags to the list
430  vector<string> tags;
431  tags.push_back("<default>");
432  for(unsigned int i=0; i<factories.size(); i++){
433  if(dataname == factories[i]->GetDataClassName()){
434  string tag = factories[i]->Tag();
435  if(tag!="")tags.push_back(tag);
436  }
437  }
438 
439  cb->RemoveAll();
440  for(unsigned int i=0; i<tags.size(); i++){
441  cb->AddEntry(tags[i].c_str(), i);
442  if(def==tags[i] || (def=="" && tags[i]=="<default>")){
443  cb->Select(i, kTRUE);
444  cb->GetTextEntry()->SetText(tags[i].c_str());
445  }
446  }
447 
448  // If "<none>" is chosen for the data type then clear the
449  // displayed area to make it more obvious that it doesn't matter
450  if(dataname=="<none>"){
451  cb->GetTextEntry()->SetText("");
452  }else{
453  string str = cb->GetTextEntry()->GetText();
454  if(str=="")cb->GetTextEntry()->SetText("<default>");
455  }
456 }
457 
458 //---------------------------------
459 // FillTrackNumberComboBox
460 //---------------------------------
461 void trk_mainframe::FillTrackNumberComboBox(TGComboBox* cb, TGComboBox* datanamecb, TGComboBox* tagcb, bool add_best_match_option)
462 {
463  /// Fill the given TGComboBox with the track numbers for the factory
464  /// currently selected in the "datanamecb" with the tag in the "tagcb"
465  /// combo boxes.
466 
467  // Get the data type and tag that are currently selected
468  string dataname = datanamecb->GetTextEntry()->GetText();
469  string tag = tagcb->GetTextEntry()->GetText();
470 
471 
472  // Get the number of rows for this factory for this event
473  int Nrows = gMYPROC->GetNrows(dataname, tag=="<default>" ? "":tag);
474 
475  // Get the currently selected value for the trackno
476  // so we can recycle it if possible.
477  string deftrackno = cb->GetTextEntry()->GetText();
478  if(deftrackno=="")deftrackno="0";
479 
480  // Add "Best Match" option if specified
481  cb->RemoveAll();
482  if(add_best_match_option){
483  cb->AddEntry("Best Match", 1001);
484  cb->Select(1001, kTRUE);
485  cb->GetTextEntry()->SetText("Best Match");
486  }
487 
488  // Add track(row) numbers
489  for(int i=0; i<Nrows; i++){
490  char str[256];
491  sprintf(str, "%d", i);
492  cb->AddEntry(str, i);
493  if(deftrackno==str){
494  cb->Select(i, kTRUE);
495  cb->GetTextEntry()->SetText(str);
496  }
497  }
498 
499  // If "<none>" is chosen for the data type then clear the
500  // displayed area to make it more obvious that it doesn't matter
501  if(dataname=="<none>" || Nrows==0){
502  cb->GetTextEntry()->SetText("");
503  }
504 }
505 
506 //-------------------
507 // DrawAxes
508 //-------------------
509 void trk_mainframe::DrawAxes(TCanvas *c, vector<TObject*> &graphics, const char *xlab, const char *ylab)
510 {
511  /// Create arrows indicating x and y axes with labels on the specified canvas
512  /// and add them to the specified container of graphics objects to be draw later.
513  double x1 = c->GetX1();
514  double x2 = c->GetX2();
515  double y1 = c->GetY1();
516  double y2 = c->GetY2();
517  double deltax = x2-x1;
518  //deltax *= c->GetYsizeReal()/c->GetXsizeReal();
519  double deltay = y2-y1;
520  double xlo = x1+0.025*deltax;
521  double xhi = xlo + 0.06*deltax;
522  double ylo = y1+0.015*deltay;
523  double yhi = ylo + 0.03*deltay;
524  TArrow *yarrow = new TArrow(xlo, ylo, xlo, yhi, 0.02, ">");
525  yarrow->SetLineWidth((Width_t)1.5);
526  graphics.push_back(yarrow);
527 
528  TLatex *ylabel = new TLatex(xlo, yhi+0.005*deltay, ylab);
529  ylabel->SetTextAlign(12);
530  ylabel->SetTextAngle(90.0);
531  ylabel->SetTextSize(0.04);
532  graphics.push_back(ylabel);
533 
534  TArrow *xarrow = new TArrow(xlo, ylo, xhi, ylo, 0.02, ">");
535  xarrow->SetLineWidth((Width_t)1.5);
536  graphics.push_back(xarrow);
537 
538  TLatex *xlabel = new TLatex(xhi+0.005*deltax, ylo, xlab);
539  xlabel->SetTextAlign(12);
540  xlabel->SetTextSize(0.04);
541  graphics.push_back(xlabel);
542 
543  // Left axis (and grid lines)
544  xlo = x1+0.08*deltax;
545  ylo = y1+0.05*deltay;
546  yhi = y1+0.95*deltay;
547  TGaxis *axis = new TGaxis(xlo , ylo, xlo, yhi, ylo, yhi, 510, "-RW");
548  graphics.push_back(axis);
549 
550  // Right axis
551  xhi = x1+0.95*deltax;
552  axis = new TGaxis(xhi , ylo, xhi, yhi, ylo, yhi, 510, "+-U");
553  graphics.push_back(axis);
554 
555  // Top axis
556  axis = new TGaxis(xlo , yhi, xhi, yhi, xlo, xhi, 510, "-R");
557  graphics.push_back(axis);
558 
559  // Bottom axis
560  axis = new TGaxis(xlo , ylo, xhi, ylo, xlo, xhi, 510, "+UW");
561  graphics.push_back(axis);
562  axis = new TGaxis(xlo+0.2*deltax, ylo, xhi, ylo, xlo+0.2*deltax, xhi, 507, "+L");
563  graphics.push_back(axis);
564 
565  // Center line
566  TLine *l = new TLine(0.0, ylo, 0.0, yhi);
567  graphics.push_back(l);
568 }
569 
570 //-------------------
571 // DrawHits
572 //-------------------
573 void trk_mainframe::DrawHits(vector<TObject*> &graphics)
574 {
575  // Find the factory name, tag, and track number for the prime track
576  string dataname = datatype[0]->GetTextEntry()->GetText();
577  string tag = factorytag[0]->GetTextEntry()->GetText();
578  string track = trackno[0]->GetTextEntry()->GetText();
579 
580  // Reset residual histogram
581  this->resi->Reset();
582 
583  if(track==""){_DBG_<<"No prime tracks!"<<endl;return;}
584  if(tag=="<default>")tag="";
585  unsigned int index = atoi(track.c_str());
586 
587  // Clear out any existing reference trajectories
588  for(unsigned int i=0; i<REFTRAJ.size(); i++)delete REFTRAJ[i];
589  REFTRAJ.clear();
590 
591  // Get the reference trajectory for the prime track
592  DReferenceTrajectory *rt=NULL;
593  vector<const DCDCTrackHit*> cdctrackhits;
594  gMYPROC->GetDReferenceTrajectory(dataname, tag, index, rt, cdctrackhits);
595  if(rt==NULL){
596  _DBG_<<"Reference trajectory unavailable for "<<dataname<<":"<<tag<<" #"<<index<<endl;
597  return;
598  }
599 
600  REFTRAJ.push_back(rt);
601 
602  // Get a list of ALL wire hits for this event
603  vector<pair<const DCoordinateSystem*,double> > allhits;
604  gMYPROC->GetAllWireHits(allhits);
605 
606  // Draw prime track
607  DrawHitsForOneTrack(graphics, allhits, rt, 0, cdctrackhits);
608 
609  // Draw other tracks
610  for(unsigned int i=1; i<datatype.size(); i++){
611  dataname = datatype[i]->GetTextEntry()->GetText();
612  tag = factorytag[i]->GetTextEntry()->GetText();
613  track = trackno[i]->GetTextEntry()->GetText();
614  if(track=="")continue;
615  if(tag=="<default>")tag="";
616  unsigned int index = atoi(track.c_str());
617  if(track=="Best Match"){
618  // Need to implement algorithm to find the best match
619  index=0;
620  }
621 
622  // Get reference trajectory for this track
623  DReferenceTrajectory *myrt=NULL;
624  gMYPROC->GetDReferenceTrajectory(dataname, tag, index, myrt, cdctrackhits);
625  if(myrt){
626  REFTRAJ.push_back(myrt);
627  DrawHitsForOneTrack(graphics, allhits, myrt, i, cdctrackhits);
628  }
629  }
630 }
631 
632 //-------------------
633 // DrawHitsForOneTrack
634 //-------------------
636  vector<TObject*> &graphics,
637  vector<pair<const DCoordinateSystem*,double> > &allhits,
639  int index,
640  vector<const DCDCTrackHit*> &cdctrackhits)
641 {
642  // Clear current hits list
643  if(index==0){
644  TRACKHITS.clear();
645  S_VALS.clear();
646  slo = shi = 20.0;
647  }
648 
649  // Get state of s-lock checkbutton
650  bool lock_s_coordinate = slock->GetState();
651 
652  // Get fdc drift time - distance function
653  vector<const DTrackFitter*> fitters;
654  eventloop->Get(fitters, "KalmanSIMD");
656  if (fitters.size() > 0)
657  fitter = dynamic_cast<const DTrackFitterKalmanSIMD *>(fitters[0]);
658 
659 
660  vector<pair<const DCoordinateSystem*,double> > &hits = index==0 ? allhits:TRACKHITS;
661 
662  // Loop over all hits and create graphics objects for each
663  for(unsigned int i=0; i<hits.size(); i++){
664  const DCoordinateSystem *wire = hits[i].first;
665  double dist = hits[i].second;
666  DVector3 pos_doca, mom_doca;
667  double s;
668  if(wire==NULL){_DBG_<<"wire==NULL!!"<<endl; continue;}
669  if(rt==NULL){_DBG_<<"rt==NULL!!"<<endl; continue;}
670  double doca = rt->DistToRT(wire, &s);
671  rt->GetLastDOCAPoint(pos_doca, mom_doca);
672  DVector3 shift = wire->udir.Cross(mom_doca);
673 
674  // The magnitude of "dist" is based on the drift time
675  // which does not yet subtract out the TOF. This can add
676  // 50-100 microns to the resolution.
677  //
678  // What is really needed here is to try different hypotheses
679  // as to the particle type. For now, we just assume its a pion
680  double mass = 0.13957;
681  double beta = 1.0/sqrt(1.0 + pow(mass/mom_doca.Mag(), 2.0))*2.998E10;
682  double tof = s/beta/1.0E-9; // in ns
683  if (fitter) {
684  double Bz = rt->FindClosestSwimStep(wire)->B[2];
685  dist = fitter->GetFDCDriftDistance(dist / 55.0e-4 - tof, Bz);
686 #if PRINT_DRIFT_DISTANCE_MAP
687  static bool print_the_map=true;
688  if (print_the_map) {
689  print_the_map = false;
690  for (double t=0; t < 2.5; t += 0.001) {
691  double d = fitter->GetFDCDriftDistance(t, Bz);
692  std::cout << d << " " << t << std::endl;
693  }
694  }
695 #endif
696  }
697  else {
698  dist -= tof*55.0E-4;
699  }
700  shift.SetMag(dist);
701 
702  // See comments in DTrack_factory_ALT1.cc::LeastSquaresB
703  double u = rt->GetLastDistAlongWire();
704  DVector3 pos_wire = wire->origin + u*wire->udir;
705  DVector3 pos_diff = pos_doca-pos_wire;
706  double sdist = pos_diff.Mag();
707  if(shift.Dot(pos_diff)<0.0){
708  shift = -shift;
709  sdist = -sdist;
710  }
711 
712  // OK. Finally, we can decide on a sign for the residual.
713  // We do this by taking the dot product of the shift with
714  // the vector pointing to the center of the wire.
715  //double sign = (shift.Dot(pos_wire)<0.0) ? -1.0:+1.0;
716  double resi = fabs(doca)-fabs(dist);
717  if(!isfinite(resi))continue;
718 #if VERBOSE_PRINT_FDC_HIT_INFO
719  std::cout
720  << "hit " << i << ": "
721  << "dist=" << dist
722  << " (" << shift[0] << "," << shift[1] << "," << shift[2] << ")"
723  << ", sdist=" << sdist
724  << " (" << pos_diff[0] << "," << pos_diff[1] << "," << pos_diff[2] << ")"
725  << ", tof=" << tof
726  << " at (" << pos_doca[0] << "," << pos_doca[1] << "," << pos_doca[2] << ")"
727  << std::endl;
728 #endif
729  // If the residual is reasonably small, consider this hit to be
730  // on this track and record it (if this is the prime track)
731  if(index==0)TRACKHITS.push_back(hits[i]);
732 
733 //_DBG_<<"resi="<<resi<<" s="<<s<<" resi*10E4="<<resi*1.0E4<<endl;
734 
735  if(index==0){
736  TMarker *m = new TMarker(sdist, s, 20);
737  m->SetMarkerSize(1.6);
738  m->SetMarkerColor(kYellow);
739  graphics.push_back(m);
740  this->resi->Fill(resi);
741 
742  // Record limits for s.
743  // NOTE: We calculate resilo and resihi from these later
744  // in DoMyRedraw().
745  if(s<slo)slo=s;
746  if(s>shi)shi=s;
747  }
748 
749  // Check if this is a CDC wire.
750  int marker_style = 20;
751  double ellipse_width = 0.8;
752  int ellipse_color = colors[index%ncolors];
753  const DCDCWire *cdcwire = dynamic_cast<const DCDCWire*>(wire);
754  if(cdcwire!=NULL && cdcwire->stereo!=0.0){
755  ellipse_width = 3.0;
756  ellipse_color += cdcwire->stereo>0.0 ? 4:-2;
757  marker_style = 5;
758  }
759 
760  // Check if this is wire is in the list of wires associated with this track
761  int ellipse_style = 1;
762  if(!WireInList(wire, cdctrackhits)){
763  ellipse_style=2;
764  ellipse_width=2.0;
765  }
766 
767  // If the lock_s_coordinate flag is set and this is not the prime track
768  // then try and replace the s-value for this hit by the one from the
769  // prime track. If this is the prime track, then record the s-value.
770  if(lock_s_coordinate){
771  if(index==0){
772  // This is prime track. Record s-value for this wire
773  S_VALS[wire] = s;
774  }else{
775  map<const DCoordinateSystem*,double>::iterator iter = S_VALS.find(wire);
776  if(iter!=S_VALS.end()){
777  s = iter->second;
778  }
779  }
780  }
781 
782  // Create ellipse for distance from wire
783  TEllipse *e = new TEllipse(sdist, s, dist, dist);
784  e->SetLineWidth((Width_t)ellipse_width);
785  e->SetLineColor(ellipse_color);
786  e->SetLineStyle(ellipse_style);
787  e->SetFillColor(19);
788  graphics.push_back(e);
789 
790  // Create marker for wire
791  TMarker *m = new TMarker(sdist, s, marker_style);
792  m->SetMarkerSize(1.5);
793  m->SetMarkerColor(colors[index%ncolors]);
794  graphics.push_back(m);
795 
796  }
797 }
798 
799 //-------------------
800 // WireInList
801 //-------------------
802 bool trk_mainframe::WireInList(const DCoordinateSystem *wire, vector<const DCDCTrackHit*> &cdctrackhits)
803 {
804  for(unsigned int i=0; i<cdctrackhits.size(); i++){
805  if(cdctrackhits[i]->wire == wire)return true;
806  }
807 
808  return false;
809 }
Definition: track.h:16
vector< TGComboBox * > datatype
Definition: trk_mainframe.h:88
TRootEmbeddedCanvas * histocanvas
Definition: trk_mainframe.h:85
int ncolors
char str[256]
trk_mainframe(hdv_mainframe *hdvmf, const TGWindow *p, UInt_t w, UInt_t h)
virtual ~trk_mainframe()
TLatex * resi_lab
Definition: trk_mainframe.h:87
TVector3 DVector3
Definition: DVector3.h:14
void DoTagMenuUpdate(Int_t widgetId, Int_t id)
TPad * pad
Definition: psc_mon.C:73
TGCheckButton * slock
Definition: trk_mainframe.h:91
sprintf(text,"Post KinFit Cut")
#define c
DVector3 GetLastDOCAPoint(void) const
double GetFDCDriftDistance(double time, double Bz) const
JEventLoop * eventloop
Definition: hdview2.cc:16
int colors[]
void DoTrackNumberMenuUpdate(Int_t widgetId, Int_t id)
double GetLastDistAlongWire(void) const
static char index(char c)
Definition: base64.cpp:115
swim_step_t * FindClosestSwimStep(const DCoordinateSystem *wire, int *istep_ptr=NULL) const
void DoHitSelect(void)
MyProcessor * gMYPROC
void DrawAxes(TCanvas *c, vector< TObject * > &graphics, const char *xlab, const char *ylab)
void DoMyRedraw(void)
TEllipse * e
double DistToRT(double x, double y, double z) const
static vector< pair< const DCoordinateSystem *, double > > TRACKHITS
vector< TGComboBox * > trackno
Definition: trk_mainframe.h:90
hdv_mainframe * hdvmf
Definition: trk_mainframe.h:82
#define _DBG_
Definition: HDEVIO.h:12
vector< TObject * > graphics
Definition: trk_mainframe.h:95
vector< TGComboBox * > factorytag
Definition: trk_mainframe.h:89
void GetDReferenceTrajectory(string dataname, string tag, unsigned int index, DReferenceTrajectory *&rt, vector< const DCDCTrackHit * > &cdchits)
void FillDataTypeComboBox(TGComboBox *cb, const string &def="DTrack")
Double_t sigma[NCHANNELS]
Definition: st_tw_resols.C:37
void GetFactories(vector< JFactory_base * > &factories)
void GetAllWireHits(vector< pair< const DCoordinateSystem *, double > > &allhits)
TRootEmbeddedCanvas * canvas
Definition: trk_mainframe.h:84
#define _DBG__
Definition: HDEVIO.h:13
void DoClearTrackInspectorPointer(void)
void DrawHitsForOneTrack(TVector3 &pos, TVector3 &mom, vector< TObject * > &graphics)
void DoNewEvent(void)
double sqrt(double)
static map< const DCoordinateSystem *, double > S_VALS
void FillTrackNumberComboBox(TGComboBox *cb, TGComboBox *datanamecb, TGComboBox *tagcb, bool add_best_match_option)
static vector< DReferenceTrajectory * > REFTRAJ
void DoRequestFocus(Int_t id)
const DTrackFitter * fitter
hdv_mainframe * hdvmf
bool WireInList(const DCoordinateSystem *wire, vector< const DCDCTrackHit * > &cdctrackhits)
locHist_NumHighLevel Draw("COLZ")
union @6::@8 u
void DoUpdateMenus(void)
void DrawHits(vector< TObject * > &graphics)
float stereo
Definition: DCDCWire.h:82
void FillFactoryTagComboBox(TGComboBox *cb, TGComboBox *datanamecb, const string &def)
unsigned int GetNrows(const string &factory, string tag)