ARTEMIS-CRIB
 
Loading...
Searching...
No Matches
TCmdXblow.cc
Go to the documentation of this file.
1/**
2 * @file TCmdXblow.cc
3 * @brief
4 * @author Kodai Okawa <okawa@cns.s.u-tokyo.ac.jp>
5 * @date 2023-06-13 17:46:27
6 * @note last modified: 2024-08-23 21:40:12
7 * @details
8 */
9
10#include "TCmdXblow.h"
11
12#include <TCatCmdXval.h>
13#include <TCatHistManager.h>
14#include <TF1.h>
15#include <TH2.h>
16#include <TPad.h>
17
19
21
22const char *TCmdXblow::kFuncNameBase = "f";
23const char *TCmdXblow::kLabelNameBase = "l";
24
26 SetName("xblow");
27 SetTitle("Crop 1D histogram (using mouse)");
28}
29
31
32Long_t TCmdXblow::Cmd(vector<TString> args) {
33 const TString opt = args.size() > 2 ? args[2] : "";
34
35 if (gPad == nullptr) {
36 Info("Cmd", "warning: no pad");
37 return 1;
38 }
39
40 TObject *hist_now = gPad->GetPrimitive("htemp");
41 if (!hist_now) {
42 hist_now = TCatHistManager::Instance()->GetCurrent();
43 if (!hist_now || !hist_now->InheritsFrom("TH1")) {
44 Info("Cmd", "warning: no hist, please check using ls command");
45 return 1;
46 }
47 }
48
49 if (hist_now->InheritsFrom(TH2::Class())) {
50 Info("Cmd", "warning: The current hist does not inherit from TH1 class (TH2)");
51 return 1;
52 }
53
54 Int_t nid = (gDirectory->GetList())->GetEntries();
55 Run((TH1 *)hist_now);
56 Info("Run", "id = %d hist is created", nid);
57 TCatHistManager::Instance()->DrawObject(nid);
58
59 return 1;
60}
61
62TH1 *TCmdXblow::Run(TH1 *h1) {
63
64 Double_t x1 = 0., y1 = 0., x2 = 0., y2 = 0.;
65 Info("Run", "click on the lowest edge: ");
66 TCatCmdXval::Instance()->Run(&x1, &y1);
67
68 Info("Run", "click on the highest edge: ");
69 TCatCmdXval::Instance()->Run(&x2, &y2);
70
71 Double_t temp;
72 if (x1 > x2) {
73 temp = x1;
74 x1 = x2;
75 x2 = temp;
76 }
77 Info("Run", "X1: %g, X2: %g", x1, x2);
78
79 Int_t x1bin, x2bin, nbinsx;
80 Float_t bc, btotal;
81
82 const TString namesuffix = " blo", titlesuffix = " blo";
83
84 x1bin = h1->GetXaxis()->FindBin(x1);
85 x2bin = h1->GetXaxis()->FindBin(x2);
86
87 nbinsx = (x2bin - x1bin) + 1;
88
89 TH1F *hnew = new TH1F("name", "title", nbinsx, x1, x2);
90
91 btotal = 0.;
92 for (Int_t nx = x1bin; nx <= x2bin; nx++) {
93 bc = h1->GetBinContent(nx);
94 hnew->SetBinContent(nx - x1bin, bc);
95 btotal += bc;
96 }
97
98 hnew->SetName(TString(h1->GetName()) + namesuffix);
99 hnew->SetTitle(TString(h1->GetTitle()) + titlesuffix);
100 hnew->SetEntries(btotal);
101
102 return hnew;
103}
104
106 std::cout << "crop some part of the histogram" << std::endl;
107}
ClassImp(TCmdXblow)
void Help() override
Definition TCmdXblow.cc:105
static const char * kFuncNameBase
Definition TCmdXblow.h:26
Long_t Cmd(vector< TString >) override
Definition TCmdXblow.cc:32
static const char * kLabelNameBase
Definition TCmdXblow.h:27
~TCmdXblow() override
Definition TCmdXblow.cc:30
TH1 * Run(TH1 *h1)
Definition TCmdXblow.cc:62
return to the guide