17 void InitGraphs(TNtuple *nt, TH1F *histo);
18 void Highlight3(TVirtualPad *pad, TObject *obj, Int_t xhb, Int_t yhb);
23 auto dir = gROOT->GetTutorialDir();
24 dir.Append(
"/hsimple.C");
25 dir.ReplaceAll(
"/./",
"/");
26 if (!gInterpreter->IsLoaded(dir.Data())) gInterpreter->LoadMacro(dir.Data());
27 auto file = (TFile*)gROOT->ProcessLineFast(
"hsimple(1)");
31 file->GetObject(
"ntuple", ntuple);
33 const char *cut =
"pz > 3.0";
35 TCanvas *Canvas1 =
new TCanvas(
"Canvas1",
"Canvas1", 0, 0, 700, 500);
36 Canvas1->Divide(1, 2);
37 TCanvas *Canvas2 =
new TCanvas(
"Canvas2",
"Canvas2", 705, 0, 500, 500);
41 ntuple->Draw(
"pz>>histo1(100, 2.0, 12.0)", cut);
42 auto histo1 = (TH1F *)gPad->FindObject(
"histo1");
43 auto info1 =
new TText(7.0, histo1->GetMaximum()*0.6,
44 "please move the mouse over the frame");
45 info1->SetTextColor(histo1->GetLineColor());
46 info1->SetBit(kCannotPick);
51 ntuple->Draw(
"(px*py*pz)>>histo2(100, -50.0, 50.0)", cut);
52 auto histo2 = (TH1F *)gPad->FindObject(
"histo2");
53 histo2->SetLineColor(kGreen+2);
54 auto info2 =
new TText(10.0, histo2->GetMaximum()*0.6, info1->GetTitle());
55 info2->SetTextColor(histo2->GetLineColor());
56 info2->SetBit(kCannotPick);
60 histo1->SetHighlight();
61 histo2->SetHighlight();
62 Canvas1->HighlightConnect(
"Highlight3(TVirtualPad*,TObject*,Int_t,Int_t)");
66 ntuple->Draw(
"px:py", cut);
67 auto gcommon = (TGraph *)gPad->FindObject(
"Graph");
68 gcommon->SetBit(kCanDelete, kFALSE);
69 auto htemp = (TH2F *)gPad->FindObject(
"htemp");
70 gcommon->SetTitle(htemp->GetTitle());
71 gcommon->GetXaxis()->SetTitle(htemp->GetXaxis()->GetTitle());
72 gcommon->GetYaxis()->SetTitle(htemp->GetYaxis()->GetTitle());
76 ntuple->Draw(
"px:py:pz", cut,
"goff");
77 histo1->SetUniqueID(1);
78 histo2->SetUniqueID(2);
79 InitGraphs(ntuple, histo1);
80 InitGraphs(ntuple, histo2);
84 void InitGraphs(TNtuple *nt, TH1F *histo)
86 Long64_t nev = nt->GetSelectedRows();
87 Double_t *px = nt->GetV1();
88 Double_t *py = nt->GetV2();
89 Double_t *pz = nt->GetV3();
91 auto list =
new TList();
92 if (histo->GetUniqueID() == 1) list1 = list;
93 else if (histo->GetUniqueID() == 2) list2 = list;
96 Int_t nbins = histo->GetNbinsX();
99 for (bin = 0; bin < nbins; bin++) {
101 g->SetName(TString::Format(
"g%sbin_%d", histo->GetName(), bin+1));
102 g->SetBit(kCannotPick);
103 g->SetMarkerStyle(25);
104 g->SetMarkerColor(histo->GetLineColor());
108 Double_t value = 0.0;
109 for (Long64_t ie = 0; ie < nev; ie++) {
110 if (histo->GetUniqueID() == 1) value = pz[ie];
111 if (histo->GetUniqueID() == 2) value = px[ie]*py[ie]*pz[ie];
112 bin = histo->FindBin(value) - 1;
113 g = (TGraph *)list->At(bin);
115 g->SetPoint(g->GetN(), py[ie], px[ie]);
120 void Highlight3(TVirtualPad *pad, TObject *obj, Int_t xhb, Int_t yhb)
122 auto histo = (TH1F *)obj;
125 TCanvas *Canvas2 = (TCanvas *)gROOT->GetListOfCanvases()->FindObject(
"Canvas2");
126 if (!Canvas2)
return;
127 TGraph *gcommon = (TGraph *)Canvas2->FindObject(
"Graph");
128 if (!gcommon)
return;
131 if (histo->GetUniqueID() == 1) list = list1;
132 else if (histo->GetUniqueID() == 2) list = list2;
134 TGraph *g = (TGraph *)list->At(xhb);
137 TVirtualPad *savepad = gPad;
141 if (histo->IsHighlight())
142 if (g->GetN() > 0) g->Draw(
"P");