MCTrueView.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////
2 /// \file MCTrueView.cxx
3 /// \brief A window that gives full list of MC particles, allowing user to
4 /// turn hits on and off in other views.
5 /// \author jpaley@anl.gov
6 /// \version $Id: MCTrueView.cxx,v 1.5 2012-08-14 19:32:16 ricken Exp $
7 ///////////////////////////////////////////////////////////////////////////
8 #include <algorithm>
9 #include <map>
10 #include <string>
11 
12 #include "TCanvas.h"
13 #include "TDatabasePDG.h"
14 #include "TGButton.h"
15 #include "TGClient.h"
16 #include "TGFrame.h"
17 #include "TGLabel.h"
18 #include "TGLayout.h"
19 #include "TGWindow.h"
20 #include "TGScrollBar.h"
21 #include "TGTextBuffer.h"
22 #include "TGTextView.h"
23 #include "TParticle.h"
24 #include "TParticlePDG.h"
25 #include "TQObject.h"
26 #include "RQ_OBJECT.h"
27 
31 #include "EventDisplay/Style.h"
34 #include "Simulation/FLSHit.h"
35 #include "Simulation/FLSHitList.h"
36 #include "Simulation/Particle.h"
39 #include "Utilities/NTree.h"
40 #include "MCCheater/BackTracker.h"
41 
43 
44 namespace evd
45 {
46 
47  static std::vector<sim::Particle> gsPartList;
48  static std::map<int,int> gsCharge;
49  static std::map<int,int> gsNFLSHit;
50  static std::map<int,bool> gsHiLite;
51  static std::map<int,float> gsPartMom;
52  static std::map<int,float> gsPartEDep;
53  static std::map<int,float> gsPartTime;
54 
55  MCTrueView::MCTrueView(TGMainFrame* mf) :
56  evdb::ObjListCanvas(mf),
57  fFirstParticle(0),
58  //fCurrEvent(-1),
59  fBigFrame(new TGHorizontalFrame(mf, 40, 20)),
60  fL1(kLHintsLeft|kLHintsTop|kLHintsExpandX, 2, 2, 2, 2),
61  fL2(kLHintsLeft, 4, 4, 4, 4),
62  fL3(kLHintsRight, 4, 4, 4, 4),
63  fL4(kLHintsLeft|kLHintsExpandY, 4, 4, 4, 4),
64  fL5(kLHintsLeft|kLHintsExpandY|kLHintsExpandX, 0, 0, 2, 2),
65  fScrollBar(new TGVScrollBar(fBigFrame, 80, 5)),
66  fShowFrame(new TGHorizontalFrame(mf, 20, 20)),
67  fShowPositive(new TGCheckButton(fShowFrame, "Positives")),
68  fShowNegative(new TGCheckButton(fShowFrame, "Negatives")),
69  fShowNeutral(new TGCheckButton(fShowFrame, "Neutrals")),
70  fSim(0), fRaw(0), fReco(0)
71  {
72  fSim = new SimulationDrawer();
73  fRaw = new RawDataDrawer();
74  fReco = new RecoBaseDrawer();
75 
76  const char* gsPanelTitle[kNPanel] = {
77  "Particle",
78  "Mother",
79  "Track Id",
80  "Momentum (GeV/c)",
81  "Vertex (cm)",
82  "# of hits",
83  "Time of 1st Hit",
84  "Energy Deposited"
85  };
86 
87  const char* gsFuncName[kNPanel] = {
88  "SortParticle()",
89  "SortMother()",
90  "SortTrackId()",
91  "SortMomentum()",
92  "SortVtxZ()",
93  "SortNHit()",
94  "SortTime()",
95  "SortEDep()"
96  };
97 
98 
99  fShowNegative->Connect("Clicked()", "evd::MCTrueView",
100  this, "UpdateAndDraw()");
101  fShowNeutral->Connect("Clicked()", "evd::MCTrueView",
102  this, "UpdateAndDraw()");
103  fShowPositive->Connect("Clicked()", "evd::MCTrueView",
104  this, "UpdateAndDraw()");
105 
106  fShowPositive->SetState(kButtonDown);
107  fShowNegative->SetState(kButtonDown);
108  fShowNeutral->SetState(kButtonDown);
109 
110  fScrollBar->Connect("ProcessedEvent(Event_t*)", "evd::MCTrueView", this,
111  "HandleMouseWheel(Event_t*)");
112 
113  for (int i = 0; i < kNPanel; ++i) {
114  fPartFrame[i] = new TGVerticalFrame(fBigFrame, 20, 20);
115  fColumnLabel[i] = new TGTextButton(fPartFrame[i], gsPanelTitle[i]);
116  fPartFrame[i]->AddFrame(fColumnLabel[i], &fL1);
117  fColumnLabel[i]->Connect("Clicked()", "evd::MCTrueView",
118  this, gsFuncName[i]);
119  }
120 
121  // Build the show by particle type frame
122  fShowFrame->AddFrame(fShowNegative, &fL2);
123  fShowFrame->AddFrame(fShowNeutral, &fL2);
124  fShowFrame->AddFrame(fShowPositive, &fL2);
125 
126  // Layout the main frame
127  mf->AddFrame(fShowFrame, &fL1);
128  mf->AddFrame(fBigFrame, &fL4);
129 
130  fBigFrame->AddFrame(fScrollBar, &fL4);
131  fScrollBar->SetPosition(0);
132  for (int i = 0; i < kNPanel; ++i)
133  fBigFrame->AddFrame(fPartFrame[i], &fL4);
134 
135  // Add dummy check button frames
136  for (int i=0; i<kNPart; ++i) {
137  fDrawCheck[i] = new TGCheckButton(fPartFrame[0], "");
138  fDrawCheck[i]->Resize(120,8);
139  fDrawCheck[i]->Connect("Clicked()","evd::MCTrueView",this, "HiLite()");
140  fPartFrame[0]->AddFrame(fDrawCheck[i], &fL5);
141 
142  for (int j=1; j<kNPanel; ++j) {
143  fPartLabel[j][i] = new TGLabel(fPartFrame[j], "");
144  fPartLabel[j][i]->Resize(30,8);
145  fPartFrame[j]->AddFrame(fPartLabel[j][i], &fL5);
146  }
147  }
148 
149  Draw();
150  }
151 
152  //......................................................................
153 
155  {
156 
157  }
158 
159  //......................................................................
161  {
162  fPartList.clear();
163  gsPartList.clear();
164  gsNFLSHit.clear();
165  gsHiLite.clear();
166  gsPartMom.clear();
167  gsPartEDep.clear();
168  gsPartTime.clear();
169 
170  fFirstParticle = 0;
171 
172  // const art::Event evt;
173  // std::vector< std::vector< const simb::MCTruth*> > fMCTruth;
174  // fSim->GetMCTruth(evt,fMCTruth);
175 
176  std::vector< std::vector< const sim::FLSHitList*> > fHitList;
177  // fSim->GetFLSHits(evt,fHitList);
178 
180  const sim::ParticleNavigator& pnav = bt->ParticleNavigator();
181 
182  // loop thru the simulated particles
183  for (sim::ParticleNavigator::const_iterator i = pnav.begin(); i != pnav.end(); ++i) {
184  const sim::Particle* p = (*i).second;
185  int ipdg = p->PdgCode();
186 
187  int q = 0;
188  float mom = 0.;
189  TParticlePDG* pdg = TDatabasePDG::Instance()->GetParticle(ipdg);
190  if (pdg) {
191  q = (int)pdg->Charge();
192  mom = sqrt(p->E()*p->E()-pdg->Mass()*pdg->Mass());
193  }
194 
195  gsCharge[p->TrackId()] = q;
196  gsPartList.push_back(*p);
197  fPartList.push_back(p->TrackId());
198  gsNFLSHit[p->TrackId()] = 0;
199  gsPartMom[p->TrackId()] = mom;
200  gsPartEDep[p->TrackId()] = 0.;
201  gsPartTime[p->TrackId()] = 9.e9;
202 
203  }
204 
205  // now count number of FLS hits per track
206  for (unsigned int iv=0; iv<fHitList.size(); ++iv) {
207  for (unsigned int i=0; i<fHitList[iv].size(); ++i) {
208  for (unsigned int j=0; j<fHitList[iv][i]->fHits.size(); ++j) {
209  const sim::FLSHit& hit = fHitList[iv][i]->fHits[j];
210  for (unsigned int ii=0; ii<gsPartList.size(); ++ii) {
211  if (hit.GetTrackID() == gsPartList[ii].TrackId()) {
212  int id = gsPartList[ii].TrackId();
213  gsNFLSHit[id]++;
214  gsPartEDep[id] += hit.GetEdep();
215  if (hit.GetEntryT() < gsPartTime[id]) gsPartTime[id] = hit.GetEntryT();
216  break;
217  }
218  }
219  }
220  }
221  }
222  // fCurrEvent = evt.id().event();
223 
224  //sim::ParticleTree pt = util::EDMUtils::GetParticleTree(evt);
225 
226  //pt.Print();
227 
228  }
229 
230  //......................................................................
231 
233  {
234  fPartList.clear();
235 
236  for (unsigned int i=0; i<gsPartList.size(); ++i) {
237  sim::Particle p = gsPartList[i];
238 
239  // check charge information
240  int q = gsCharge[p.TrackId()];
241  if ( (fShowNegative->GetState() == kButtonUp && q<0) ||
242  (fShowPositive->GetState() == kButtonUp && q>0) ||
243  (fShowNeutral->GetState() == kButtonUp && q==0) ) {
244  continue;
245  }
246 
247  fPartList.push_back(p.TrackId());
248  }
249 
250  fScrollBar->SetRange(gsPartList.size(),kNPart);
251  fScrollBar->SetPosition(0);
252 
253  }
254 
255  //......................................................................
256 
258  {
259  Update();
260  Draw();
261  }
262 
263  //......................................................................
264 
265  void MCTrueView::Draw(const char* /*opt*/)
266  {
267  // const art::Event evt;
268  // if (evt.id().event() != fCurrEvent) {
269  // LoadEvent();
270  // Update();
271  // }
272 
273  evd::Style style;
274 
275  int npart = gsPartList.size();
276 
277  char buff[256];
278 
279  int imin = fFirstParticle;
280  int imax = kNPart;
281 
282  if (imin < 0) imin = 0;
283  if (imin+kNPart > npart)
284  imax = npart;
285 
286  for (int i=0; i<imax; ++i) {
287  sim::Particle& p = gsPartList[imin+i];
288 
289  // look to see if this particle is in list of good tracks
290  if (find(fPartList.begin(),fPartList.end(),p.TrackId()) ==
291  fPartList.end()) continue;
292 
293  fCheckMap[i] = &p;
294 
295  sprintf(buff,"%d: %s",imin+i, Style::LatexName(p.PdgCode()));
296  fDrawCheck[i]->SetText(buff);
297  if (gsHiLite[p.TrackId()])
298  fDrawCheck[i]->SetState(kButtonDown);
299  else
300  fDrawCheck[i]->SetState(kButtonUp);
301 
302  sprintf(buff,"%d",p.Mother());
303  fPartLabel[kMother][i]->SetText(buff);
304 
305  sprintf(buff,"%d",p.TrackId());
306  fPartLabel[kTrackId][i]->SetText(buff);
307 
308  sprintf(buff,"%6.4f",p.P());
309  fPartLabel[kMomentum][i]->SetText(buff);
310 
311  sprintf(buff,"%6.4f",p.Vz());
312  fPartLabel[kVtxZ][i]->SetText(buff);
313 
314  sprintf(buff,"%d",gsNFLSHit[p.TrackId()]);
315  fPartLabel[kNHit][i]->SetText(buff);
316 
317  sprintf(buff,"%6.4g",gsPartTime[p.TrackId()]);
318  fPartLabel[kTime][i]->SetText(buff);
319 
320  sprintf(buff,"%6.4f",gsPartEDep[p.TrackId()]);
321  fPartLabel[kEDep][i]->SetText(buff);
322 
323  unsigned int icolor = style.ColorFromPDG(p.PdgCode());
324 
325  fDrawCheck[i]->ChangeBackground(icolor);
326  fDrawCheck[i]->SetTextColor(0xFFFFFF);
327  for (int j=1; j<kNPanel; ++j) {
328  fPartLabel[j][i]->ChangeBackground(icolor);
329  fPartLabel[j][i]->SetTextColor(0xFFFFFF);
330  }
331  }
332 
333  for (int i=imax; i<kNPart; ++i) {
334  fDrawCheck[i]->SetText("");
335  fDrawCheck[i]->ChangeBackground(0xFFFFFF);
336  for (int j=1; j<kNPanel; ++j) {
337  fPartLabel[j][i]->SetText("");
338  fPartLabel[j][i]->ChangeBackground(0xFFFFFF);
339  }
340  }
341 
342  }
343 
344  //......................................................................
345 
347  {
348  static bool fwd = true;
349  if (fwd) {
350  sort(gsPartList.begin(), gsPartList.end(), CompParticle);
351  fwd = false;
352  }
353  else {
354  sort(gsPartList.rbegin(), gsPartList.rend(), CompParticle);
355  fwd = true;
356  }
357 
358  Draw();
359 
360  }
361 
362  //......................................................................
363 
365  {
366  return (a.PdgCode() < b.PdgCode());
367  }
368 
369  //......................................................................
370 
372  {
373  static bool fwd = true;
374  if (fwd) {
375  sort(gsPartList.begin(), gsPartList.end(), CompMother);
376  fwd = false;
377  }
378  else {
379  sort(gsPartList.rbegin(), gsPartList.rend(), CompMother);
380  fwd = true;
381  }
382 
383  Draw();
384 
385  }
386 
387  //......................................................................
388 
390  {
391  return (a.Mother() < b.Mother());
392  }
393 
394  //......................................................................
395 
397  {
398  static bool fwd = true;
399  if (fwd) {
400  sort(gsPartList.begin(), gsPartList.end(), CompMomentum);
401  fwd = false;
402  }
403  else {
404  sort(gsPartList.rbegin(), gsPartList.rend(), CompMomentum);
405  fwd = true;
406  }
407  Draw();
408  }
409 
410  //......................................................................
411 
413  {
414  return (gsPartMom[a.TrackId()] < gsPartMom[b.TrackId()]);
415  }
416 
417  //......................................................................
418 
420  {
421  static bool fwd = true;
422  if (fwd) {
423  sort(gsPartList.begin(), gsPartList.end(), CompTrackId);
424  fwd = false;
425  }
426  else {
427  sort(gsPartList.rbegin(), gsPartList.rend(), CompTrackId);
428  fwd = true;
429  }
430  Draw();
431  }
432 
433  //......................................................................
434 
436  {
437  return (a.TrackId() < b.TrackId());
438  }
439 
440  //......................................................................
441 
443  {
444  static bool fwd = true;
445  if (fwd) {
446  sort(gsPartList.begin(), gsPartList.end(), CompVtxZ);
447  fwd = false;
448  }
449  else {
450  sort(gsPartList.rbegin(), gsPartList.rend(), CompVtxZ);
451  fwd = true;
452  }
453 
454  Draw();
455 
456  }
457 
458  //......................................................................
459 
461  {
462  return (a.Vz() < b.Vz());
463  }
464 
465  //......................................................................
466 
468  {
469  static bool fwd = true;
470  if (fwd) {
471  sort(gsPartList.begin(), gsPartList.end(), CompNHit);
472  fwd = false;
473  }
474  else {
475  sort(gsPartList.rbegin(), gsPartList.rend(), CompNHit);
476  fwd = true;
477  }
478 
479  Draw();
480 
481  }
482 
483  //......................................................................
484 
486  {
487  return (gsNFLSHit[a.TrackId()] < gsNFLSHit[b.TrackId()]);
488  }
489 
490  //......................................................................
491 
493  {
494  static bool fwd = true;
495  if (fwd) {
496  sort(gsPartList.begin(), gsPartList.end(), CompTime);
497  fwd = false;
498  }
499  else {
500  sort(gsPartList.rbegin(), gsPartList.rend(), CompTime);
501  fwd = true;
502  }
503 
504  Draw();
505 
506  }
507 
508  //......................................................................
509 
511  {
512  return (gsPartTime[a.TrackId()] < gsPartTime[b.TrackId()]);
513  }
514 
515  //......................................................................
516 
518  {
519  static bool fwd = true;
520  if (fwd) {
521  sort(gsPartList.begin(), gsPartList.end(), CompEDep);
522  fwd = false;
523  }
524  else {
525  sort(gsPartList.rbegin(), gsPartList.rend(), CompEDep);
526  fwd = true;
527  }
528 
529  Draw();
530 
531  }
532 
533  //......................................................................
534 
536  {
537  return (gsPartEDep[a.TrackId()] < gsPartEDep[b.TrackId()]);
538  }
539 
540  //......................................................................
541 
542  void MCTrueView::HandleMouseWheel(Event_t */*event*/)
543  {
544  if (fFirstParticle != fScrollBar->GetPosition()) {
545  fFirstParticle = fScrollBar->GetPosition();
546  Draw();
547  }
548  }
549 
550  //......................................................................
551 
553  {
554  int imin = fFirstParticle;
555  int imax = kNPart;
556  int npart = gsPartList.size();
557 
558  if (imin < 0) imin = 0;
559  if (imin+kNPart > npart)
560  imax = npart;
561 
562  for (int i=0; i<imax; ++i) {
563  gsHiLite[fCheckMap[i]->TrackId()] = fDrawCheck[i]->IsDown();
564  fSim->HiLite(fCheckMap[i]->TrackId(), fDrawCheck[i]->IsDown());
565  }
566  // now we want to communicate to other windows to update...
567  // how best to do this?
568 
569  // evdb::IoModule::Instance()->Reload();
570 
571  }
572 
573 } // end namespace evd
574 ////////////////////////////////////////////////////////////////////////
double E(const int i=0) const
Definition: MCParticle.h:232
::xsd::cxx::tree::id< char, ncname > id
Definition: Database.h:165
SimulationDrawer * fSim
Definition: MCTrueView.h:114
TGVScrollBar * fScrollBar
Definition: MCTrueView.h:108
TGCompositeFrame * fBigFrame
Definition: MCTrueView.h:92
static bool CompTime(const sim::Particle &a, const sim::Particle &b)
Definition: MCTrueView.cxx:510
back track the reconstruction to the simulation
int PdgCode() const
Definition: MCParticle.h:211
A window that gives full list of MC particles, allowing user to turn hits on and off in other views...
TGCompositeFrame * fPartFrame[kNPanel]
Definition: MCTrueView.h:93
void HiLite(int trkId, bool hlt=true)
Aid in the rendering of RecoBase objects.
static std::map< int, float > gsPartEDep
Definition: MCTrueView.cxx:52
const sim::ParticleNavigator & ParticleNavigator() const
Get a reference to the ParticleNavigator.
Definition: BackTracker.h:744
Drawing pad for short summary of an MC event.
int Mother() const
Definition: MCParticle.h:212
const char * p
Definition: xmltok.h:285
TGCheckButton * fShowNegative
Definition: MCTrueView.h:111
T sqrt(T number)
Definition: d0nt_math.hpp:156
static std::map< int, float > gsPartMom
Definition: MCTrueView.cxx:51
list_type::const_iterator const_iterator
TGLayoutHints fL5
Definition: MCTrueView.h:95
TGCompositeFrame * fShowFrame
Definition: MCTrueView.h:109
RecoBaseDrawer * fReco
Definition: MCTrueView.h:116
A single unit of energy deposition in the liquid scintillator.
Definition: FLSHit.h:19
static std::map< int, int > gsCharge
Definition: MCTrueView.cxx:48
Manage all things related to colors for the event display.
Definition: Display3DPad.h:11
static bool CompMomentum(const sim::Particle &a, const sim::Particle &b)
Definition: MCTrueView.cxx:412
static std::map< int, float > gsPartTime
Definition: MCTrueView.cxx:53
int TrackId() const
Definition: MCParticle.h:209
std::vector< int > fPartList
Definition: MCTrueView.h:89
RawDataDrawer * fRaw
Definition: MCTrueView.h:115
Int_t npart
Definition: Style.C:7
TGLayoutHints fL1
Definition: MCTrueView.h:95
static bool CompParticle(const sim::Particle &a, const sim::Particle &b)
Definition: MCTrueView.cxx:364
nova event display
void Draw(const char *opt="u")
Definition: MCTrueView.cxx:265
MCTrueView(TGMainFrame *mf)
Definition: MCTrueView.cxx:55
static bool CompNHit(const sim::Particle &a, const sim::Particle &b)
Definition: MCTrueView.cxx:485
void UpdateAndDraw()
Definition: MCTrueView.cxx:257
static std::vector< sim::Particle > gsPartList
Definition: MCTrueView.cxx:47
const double a
double P(const int i=0) const
Definition: MCParticle.h:233
int ColorFromPDG(int pdgcode)
Definition: Style.cxx:98
const double j
Definition: BetheBloch.cxx:29
static std::map< int, bool > gsHiLite
Definition: MCTrueView.cxx:50
TGTextButton * fColumnLabel[kNPanel]
Definition: MCTrueView.h:99
Class to aid in the rendering of RecoBase objects.
static bool CompEDep(const sim::Particle &a, const sim::Particle &b)
Definition: MCTrueView.cxx:535
TGLabel * fPartLabel[kNPanel][kNPart]
Definition: MCTrueView.h:98
Class to aid in the rendering of RawData objects.
float GetEntryT() const
Definition: FLSHit.h:51
TGLayoutHints fL4
Definition: MCTrueView.h:95
void HandleMouseWheel(Event_t *event)
Definition: MCTrueView.cxx:542
static std::map< int, int > gsNFLSHit
Definition: MCTrueView.cxx:49
int GetTrackID() const
Track ID.
Definition: FLSHit.h:45
TGCheckButton * fShowPositive
Definition: MCTrueView.h:110
static bool CompVtxZ(const sim::Particle &a, const sim::Particle &b)
Definition: MCTrueView.cxx:460
Definition: event.h:1
static const char * LatexName(int pdgcode)
Convert PDG code to a latex string (root-style)
Definition: Style.cxx:16
TGCheckButton * fDrawCheck[kNPart]
Definition: MCTrueView.h:97
static bool CompTrackId(const sim::Particle &a, const sim::Particle &b)
Definition: MCTrueView.cxx:435
Render the objects from the Simulation package.
const hit & b
Definition: hits.cxx:21
Aid in the rendering of RawData objects.
Definition: RawDataDrawer.h:27
double Vz(const int i=0) const
Definition: MCParticle.h:222
const sim::Particle * fCheckMap[kNPart]
Definition: MCTrueView.h:87
float GetEdep() const
Get total Energy deposited into the cell for the whole FLSHit.
Definition: FLSHit.h:31
static bool CompMother(const sim::Particle &a, const sim::Particle &b)
Definition: MCTrueView.cxx:389
TGLayoutHints fL2
Definition: MCTrueView.h:95
TGCheckButton * fShowNeutral
Definition: MCTrueView.h:112