ARTEMIS-CRIB
 
Loading...
Searching...
No Matches
TCmdXfitg.cc
Go to the documentation of this file.
1/**
2 * @file TCmdXfitg.cc
3 * @brief
4 * @author Kodai Okawa <okawa@cns.s.u-tokyo.ac.jp>
5 * @date 2023-06-13 17:51:08
6 * @note last modified: 2024-08-23 21:42:52
7 * @details
8 */
9
10#include "TCmdXfitg.h"
11
12#include <TCatCmdXval.h>
13#include <TCatHistManager.h>
14#include <TCmdComment.h>
15#include <TF1.h>
16#include <TH2.h>
17#include <TPad.h>
18
20
22
23const char *TCmdXfitg::kFuncNameBase = "f";
24const char *TCmdXfitg::kLabelNameBase = "l";
25
27 SetName("xfitg");
28 SetTitle("fit using gausian (using mouse)");
29}
30
32
33Long_t TCmdXfitg::Cmd(vector<TString>) {
34 if (gPad == nullptr) {
35 Info("Cmd", "warning: no pad");
36 return 1;
37 }
38
39 // K.Okawa 2022/9/27 add
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 // std::cout << " warning: no hist, please check using ls command" << std::endl;
46 return 1;
47 }
48 }
49
50 if (hist_now->InheritsFrom(TH2::Class())) {
51 Info("Cmd", "warning: The current hist does not inherit from TH1 class (TH2)");
52 // std::cout << " warning: The current hist does not inherit from TH1 class (TH2)" << std::endl;
53 return 1;
54 }
55
56 Double_t x1 = 0., y1 = 0., x2 = 0., y2 = 0.;
57 Info("Cmd", "click on the lowest edge: ");
58 TCatCmdXval::Instance()->Run(&x1, &y1);
59
60 // static TLine *line = nullptr;
61 // line = new TLine(x1, gPad->GetUymin(), x1, gPad->GetUymax());
62 // line->SetLineColor(kBlack);
63 // line->Draw();
64
65 Info("Cmd", "click on the highest edge: ");
66 TCatCmdXval::Instance()->Run(&x2, &y2);
67
68 Double_t temp;
69 if (x1 > x2) {
70 temp = x1;
71 x1 = x2;
72 x2 = temp;
73 }
74 Info("Cmd", "X1: %g, X2: %g", x1, x2);
75 // std::cout << " X1: " << x1 << ", X2: " << x2 << std::endl;
76
77 // if(line) delete line;
78
79 TF1 *func = new TF1(hist_now->GetName(), "gaus(0)", x1, x2);
80 func->SetParameters(((y1 + y2) / 2) * (x2 - x1), (x1 + x2) / 2., (x2 - x1) / 4.);
81 func->SetParLimits(2, 0, 1000. * (x2 - x1));
82 dynamic_cast<TH1 *>(hist_now)->Fit(func, "", "", x1, x2);
83 func->Draw("same");
84
85 TCmdComment::Instance()->Run(
86 TString::Format("[xfitg] mean=%g: FWHM=%g", func->GetParameter(1), 2.35 * func->GetParameter(2)));
87 // K.Okawa end
88
89 return 1;
90}
91
93 std::cout << "this fit method use x1 x2 value and also use y1 y2 value to determine the first fitting "
94 "parameters.\nso if the fitting does not work, please try to click around the center of y axis"
95 << std::endl;
96}
ClassImp(TCmdXfitg)
static const char * kFuncNameBase
Definition TCmdXfitg.h:26
Long_t Cmd(vector< TString >) override
Definition TCmdXfitg.cc:33
static const char * kLabelNameBase
Definition TCmdXfitg.h:27
void Help() override
Definition TCmdXfitg.cc:92
~TCmdXfitg() override
Definition TCmdXfitg.cc:31
return to the guide