BmnRoot 26.10.0-19-g6979a6c6
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
Tof400LRcorrection_period6.C
Go to the documentation of this file.
1/*
2 * To change this license header, choose License Headers in Project Properties.
3 * To change this template file, choose Tools | Templates
4 * and open the template in the editor.
5 */
6const Int_t minimum[10] = {70, 100, 100, 12, 26, 130, 180, 200, 180, 35};
7
9{
10
11 gROOT->LoadMacro("$VMCWORKDIR/macro/run/bmnloadlibs.C");
12 bmnloadlibs(); // load BmnRoot libraries
13
14 TH1I* hMean = new TH1I("hMean", "hMean", 2048, -12, 12);
15 TH1I* hdMean = new TH1I("hdMean", "hdMean", 2048, -6., 6.);
16 TH2I* hdMean_vs_Strip = new TH2I("hdMean_vs_Strip", "hdMean_vs_Strip", 460, 0, 460, 400, -2., 2.);
17
18 TString inName;
19 inName = file;
20 cout << "Open file " << inName << endl << endl;
21
22 TFile* FileIn = new TFile(inName.Data(), "RAED");
23 if (!FileIn) {
24 cout << "File " << inName.Data() << " is not found" << endl;
25 break;
26 }
27
28 TString Name1, Name2;
29 TH1I*** hDtLR = new TH1I**[10];
30 TH1I*** hDifDtLR = new TH1I**[10];
31
32 FileIn->cd("ToF");
33 for (Int_t Plane = 0; Plane < 10; Plane++) {
34 hDtLR[Plane] = new TH1I*[48];
35 hDifDtLR[Plane] = new TH1I*[48];
36 Name1.Clear();
37 Name1 = Form("Plane%d", Plane);
38 FileIn->cd(Form("ToF/Plane%d/Detector", Plane));
39 gDirectory->pwd();
40 // gDirectory->ls();
41 for (Int_t Str = 0; Str < 48; Str++) {
42 Name2.Clear();
43 Name2 = Form("Hist_dtLR_%s_str%d", Name1.Data(), Str);
44 // hDtLR[Plane][Str] = new TH1I(Name2.Data(), Name2.Data(), 1024, 0, 48);
45 // hDtLR[Plane][Str] = (TH1I*) FileIn->GetObjectChecked(Name2.Data(), "TH1I");
46 hDtLR[Plane][Str] = (TH1I*)gDirectory->Get(Name2.Data());
47 Int_t nBins = hDtLR[Plane][Str]->GetNbinsX();
48
49 Name2 = Form("Hist_DiffdtLR_%s_str%d", Name1.Data(), Str);
50 hDifDtLR[Plane][Str] = new TH1I(Name2.Data(), Name2.Data(), 1024, -12., 12.);
51
52 for (Int_t i = 2; i < nBins; i++) {
53 if (hDtLR[Plane][Str]->GetBinContent(i) > minimum[Plane])
54 hDtLR[Plane][Str]->SetBinContent(i, minimum[Plane]);
55 if (hDtLR[Plane][Str]->GetBinContent(i) < minimum[Plane])
56 hDtLR[Plane][Str]->SetBinContent(i, 0);
57 hDifDtLR[Plane][Str]->SetBinContent(i, hDtLR[Plane][Str]->GetBinContent(i)
58 - hDtLR[Plane][Str]->GetBinContent(i - 1));
59 }
60 }
61 }
62
63 TString outName = file;
64 Int_t Point = outName.First('.');
65 outName.Replace(Point, 15, "_LRcorr.root");
66 TFile* fileout = new TFile(outName.Data(), "RECREATE");
67
68 ofstream f_call;
69 TString NameCallFile = "Tof400LRcorr.dat";
70 // TString NameCallFile = file;
71 // Point = NameCallFile.First('.');
72 // NameCallFile.Replace(Point, 15, "_LRcorr.dat");
73 cout << "Write call to " << NameCallFile.Data() << endl;
74 f_call.open(NameCallFile.Data());
75 f_call << "Plane\tStrip\tMeanFit\tMean" << endl << "==========================" << endl;
76
77 TDirectory* DirPlane[10];
78 TDirectory* Dir2Plane[10];
79 TF1* MyGaus = new TF1("MyGaus", "gaus", -24., 24.);
80 for (Int_t Plane = 0; Plane < 10; Plane++) {
81 Name1.Clear();
82 Name1 = Form("Plane%d", Plane);
83 DirPlane[Plane] = fileout->mkdir(Name1.Data());
84
85 Dir2Plane[Plane] = DirPlane[Plane]->mkdir("Diff");
86 Dir2Plane[Plane]->cd();
87 for (Int_t Str = 0; Str < 48; Str++)
88 hDifDtLR[Plane][Str]->Write();
89
90 DirPlane[Plane]->cd();
91 for (Int_t Str = 0; Str < 48; Str++) {
92 Double_t left = hDtLR[Plane][Str]->GetMaximumBin() * hDtLR[Plane][Str]->GetBinWidth(1)
93 + hDtLR[Plane][Str]->GetXaxis()->GetBinLowEdge(1);
94 MyGaus->SetParameters(minimum[Plane] * 1.2, left + 0.9, 5.0);
95 MyGaus->SetParLimits(2, 0.1, 7);
96 MyGaus->SetParLimits(1, left + 0.5, left + 1.4);
97 if (Str > 0 && Str < 47) {
98 hDtLR[Plane][Str]->Fit("MyGaus", "QB", "");
99 f_call << Plane << "\t" << Str << "\t" << MyGaus->GetParameter(1) << "\t"
100 << hDtLR[Plane][Str]->GetMean() << endl;
101 hMean->Fill(MyGaus->GetParameter(1));
102 hdMean->Fill(MyGaus->GetParameter(1) - hDtLR[Plane][Str]->GetMean());
103 hdMean_vs_Strip->Fill(Plane * 48 + Str, MyGaus->GetParameter(1) - hDtLR[Plane][Str]->GetMean());
104 } else
105 f_call << Plane << "\t" << Str << "\t" << 0 << "\t" << left << endl;
106 hDtLR[Plane][Str]->Write();
107 // cout << " GetMaximumBin " << left << endl;
108 // getchar();
109 }
110 }
111
112 f_call.close();
113
114 fileout->cd();
115 hMean->Write();
116 hdMean->Write();
117 hdMean_vs_Strip->Write();
118 fileout->Close();
119 FileIn->Close();
120}
121
123{
124 TH1I* hTest = new TH1I("hTest", "hTest", 400, 0, 10);
125 for (Int_t i = 165; i <= 235; i++)
126 hTest->Fill(i * 0.025, 10);
127 hTest->Fit("gaus");
128 TCanvas* c1 = new TCanvas("c1", "c1", 50, 50, 550, 550);
129 hTest->Draw();
130}
int i
Definition P4_F32vec4.h:22
int Int_t
double Double_t
#define gDirectory
#define gROOT
char * Form(const char *fmt,...)
void Tof400LRcorrection_period6(TString file="")
void TestFitGaus()
const Int_t minimum[10]
virtual Double_t GetBinLowEdge(Int_t bin) const
Bool_t cd() override
TDirectory * mkdir(const char *name, const char *title="", Bool_t returnExistingDirectory=kFALSE) override
virtual Bool_t cd()
virtual TDirectory * mkdir(const char *name, const char *title="", Bool_t returnExistingDirectory=kFALSE)
virtual Double_t GetParameter(const TString &name) const
virtual void SetParLimits(Int_t ipar, Double_t parmin, Double_t parmax)
virtual void SetParameters(const Double_t *params)
void Close(Option_t *option="") override
virtual Double_t GetMean(Int_t axis=1) const
TAxis * GetXaxis()
virtual TFitResultPtr Fit(const char *formula, Option_t *option="", Option_t *goption="", Double_t xmin=0, Double_t xmax=0)
virtual Int_t GetNbinsX() const
void Draw(Option_t *option="") override
virtual Int_t Fill(const char *name, Double_t w)
virtual void SetBinContent(Int_t bin, Double_t content)
virtual Int_t GetMaximumBin() const
virtual Double_t GetBinWidth(Int_t bin) const
virtual Int_t Fill(const char *namex, const char *namey, Double_t w)
virtual Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0)
void Clear()
TString & Replace(Ssiz_t pos, Ssiz_t n, const char *s)
Ssiz_t First(char c) const
const char * Data() const