show_event.C
Go to the documentation of this file.
1 #include "TBox.h"
2 #include "TCanvas.h"
3 #include "TFile.h"
4 #include "TH2.h"
5 #include "TSystem.h"
6 
7 #include "LEM/func/Library.h"
8 using namespace lem;
9 
10 #include <iostream>
11 
12 int gIdx = 0;
13 bool gFlipEven = false;
14 bool gFlipOdd = false;
15 bool gIdxs = false;
16 
18 TTree* gTree = 0;
19 TCanvas* gCanv = 0;
20 
21 void refresh()
22 {
23  std::cout << "Displaying event " << gIdx << std::endl;
24 
25  TH2* h[2] = {new TH2F("", ";plane;cell", 128, 0, 128, 128, 64, 192),
26  new TH2F("", ";plane;cell", 128, 0, 128, 128, 64, 192)};
27 
28  // even view first then odd view
29  const MatchableEvent& sum = gLib ? gLib->Event(gIdx) : MatchableEvent(EventSummary::FromTree(gTree, gIdx, false));
30  sum.FillHists(h[0], h[1], gFlipEven, gFlipOdd, gIdxs);
31 
32  // printf("Total PE: %2.2f\n", sum.totalPE);
33 
34  for(int v = 0; v < 2; ++v){
35  gCanv->cd(v+1);
36  h[v]->Draw("colz");
37 
38  TBox* b = new TBox(lem::kVertexPlane, lem::kVertexCell,
40  b->SetLineColor(kRed);
41  b->SetFillStyle(0);
42  b->SetLineWidth(2);
43  b->SetLineStyle(7);
44  b->Draw();
45 
46  const int trueCell = (sum.trueVtxPlane%2 == v) ? sum.trueVtxCellOther : sum.trueVtxCell;
47  TBox* b2 = new TBox(sum.trueVtxPlane, trueCell,
48  sum.trueVtxPlane+1, trueCell+1);
49  b2->SetLineColor(kGreen+2);
50  b2->SetFillStyle(0);
51  b2->SetLineWidth(2);
52  b2->SetLineStyle(7);
53  b2->Draw();
54  }
55 }
56 
57 void show_event(TString libPath, int idx = 0, bool flipEven = false, bool flipOdd = false, bool idxs = false)
58 {
59  gIdx = idx;
60  gFlipEven = flipEven;
61  gFlipOdd = flipOdd;
62  gIdxs = idxs;
63 
64  if(libPath.EndsWith(".root")){
65  TFile* f = new TFile(libPath);
66  gTree = (TTree*)f->Get("makelib/tree");
67  assert(gTree);
69  }
70  else{
71  gLib = Library::FromMMap(libPath.Data(), false);
72  }
73 
74  gCanv = new TCanvas("a", "LEM", 1200, 600);
75  gCanv->Divide(2, 1);
76 
77  std::cout << "next() or n() for the next event" << std::endl;
78  std::cout << "prev() or p() for the prev event" << std::endl;
79  std::cout << "go(idx) to jump to a specific event" << std::endl;
80 
81  refresh();
82 }
83 
84 void next()
85 {
86  ++gIdx;
87  refresh();
88 }
89 void n(){next();}
90 
91 void prev()
92 {
93  if(gIdx == 0){
94  std::cout << "Can't back up from event 0" << std::endl;
95  return;
96  }
97 
98  --gIdx;
99  refresh();
100 }
101 void p(){prev();}
102 
103 void go(int idx)
104 {
105  gIdx = idx;
106  refresh();
107 }
TTree * gTree
Definition: show_event.C:18
Attach some information used in matching to an EventSummary.
void n()
Definition: show_event.C:89
Collection of events for matching.
Collection of events for matching.
Definition: Library.h:18
const int kVertexPlane
Definition: EventSummary.h:22
int gIdx
Definition: show_event.C:12
Library * gLib
Definition: show_event.C:17
static void InitFromTree(TTree *tr)
void show_event(TString libPath, int idx=0, bool flipEven=false, bool flipOdd=false, bool idxs=false)
Definition: show_event.C:57
PID
Definition: FillPIDs.h:14
void prev()
Definition: show_event.C:91
bool gIdxs
Definition: show_event.C:15
const int kVertexCell
Definition: EventSummary.h:23
static EventSummary FromTree(TTree *tr, int evtIdx, bool enrich)
OStream cout
Definition: OStream.cxx:6
bool gFlipEven
Definition: show_event.C:13
void p()
Definition: show_event.C:101
TCanvas * gCanv
Definition: show_event.C:19
const MatchableEvent & Event(int i) const
Definition: Library.h:32
const hit & b
Definition: hits.cxx:21
assert(nhit_max >=nhit_nbins)
bool gFlipOdd
Definition: show_event.C:14
static Library * FromMMap(const std::string &libPath, bool touchAll)
Definition: Library.cxx:62
Double_t sum
Definition: plot.C:31
void go(int idx)
Definition: show_event.C:103
void next()
Definition: show_event.C:84
void FillHists(TH2 *h1, TH2 *h2, bool flipEven=false, bool flipOdd=false, bool idxs=false) const
void refresh()
Definition: show_event.C:21