BmnRoot 26.10.0-19-g6979a6c6
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
Tof400LRcorrection_period7.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 */
6
7/*
8 * File: Tof400LRCorrection_period7.C
9 * Author: mikhailr
10 *
11 * Created on March 10, 2018, 9:55 AM
12 */
13const Int_t nDet = 20;
14
15/*const Double_t LR[nDet] = {0.07, -0.01, 2.18, 6.64, 6.57, -0.05, 0.03, 2.12, 6.49, 6.49,
16 0.093, 0.055, 2.21, 6.59, 6.51, 0.00, -0.03, 2.07, 6.47, 6.52};*/
17
18const Int_t minimum[nDet] = {40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40};
19
21{
22
23 /* ofstream f_call;
24 TString NameCallFile = "Tof400LRcorr_RUN7.dat";
25 //TString NameCallFile = file;
26 //Point = NameCallFile.First('.');
27 //NameCallFile.Replace(Point, 15, "_LRcorr.dat");
28 cout << "Write call to " << NameCallFile.Data() << endl;
29 f_call.open(NameCallFile.Data());
30 f_call << "Plane\tStrip\tMeanFit\tMean" << endl << "==========================" << endl;
31
32 for (Int_t Plane = 0; Plane < 20; Plane++) {
33 for (Int_t Str = 0; Str < 48; Str++)
34 f_call << Plane << "\t" << Str << "\t" << LR[Plane] << "\t" << LR[Plane] << endl;
35 }//*/
36
37 gROOT->LoadMacro("$VMCWORKDIR/macro/run/bmnloadlibs.C");
38 bmnloadlibs(); // load BmnRoot libraries
39
40 TH1I* hMean = new TH1I("hMean", "hMean", 2048, -12, 12);
41 TH1I* hdMean = new TH1I("hdMean", "hdMean", 2048, -6., 6.);
42 TH2I* hdMean_vs_Strip = new TH2I("hdMean_vs_Strip", "hdMean_vs_Strip", 460, 0, 460, 400, -2., 2.);
43
44 TString inName;
45 inName = file;
46 cout << "Open file " << inName << endl << endl;
47
48 TFile* FileIn = new TFile(inName.Data(), "RAED");
49 if (!FileIn) {
50 cout << "File " << inName.Data() << " is not found" << endl;
51 break;
52 }
53
54 TString Name1, Name2;
55 TH1I*** hDtLR = new TH1I**[nDet];
56 TH1I*** hDifDtLR = new TH1I**[nDet];
57
58 FileIn->cd("ToF");
59 for (Int_t Plane = 0; Plane < nDet; Plane++) {
60 // cout << "Plane = " << Plane << endl;
61 hDtLR[Plane] = new TH1I*[48];
62 hDifDtLR[Plane] = new TH1I*[48];
63 Name1.Clear();
64 Name1 = Form("Plane_%d", Plane);
65 FileIn->cd(Form("ToF/Plane_%d/Detector", Plane));
66 gDirectory->pwd();
67 // gDirectory->ls();
68 for (Int_t Str = 0; Str < 48; Str++) {
69 Name2.Clear();
70 Name2 = Form("Hist_dtLR_%s_str%d", Name1.Data(), Str);
71 // hDtLR[Plane][Str] = new TH1I(Name2.Data(), Name2.Data(), 1024, 0, 48);
72 // hDtLR[Plane][Str] = (TH1I*) FileIn->GetObjectChecked(Name2.Data(), "TH1I");
73 hDtLR[Plane][Str] = (TH1I*)gDirectory->Get(Name2.Data());
74 Int_t nBins = hDtLR[Plane][Str]->GetNbinsX();
75
76 Name2 = Form("Hist_DiffdtLR_%s_str%d", Name1.Data(), Str);
77 hDifDtLR[Plane][Str] = new TH1I(Name2.Data(), Name2.Data(), 1024, -12., 12.);
78
79 for (Int_t i = 2; i < nBins; i++) {
80 if (hDtLR[Plane][Str]->GetBinContent(i) > minimum[Plane])
81 hDtLR[Plane][Str]->SetBinContent(i, minimum[Plane]);
82 if (hDtLR[Plane][Str]->GetBinContent(i) < minimum[Plane])
83 hDtLR[Plane][Str]->SetBinContent(i, 0);
84 hDifDtLR[Plane][Str]->SetBinContent(i, hDtLR[Plane][Str]->GetBinContent(i)
85 - hDtLR[Plane][Str]->GetBinContent(i - 1));
86 }
87 }
88 }
89
90 TString outName = file;
91 Int_t Point = outName.First('.');
92 outName.Replace(Point, 15, "_LRcorr_RUN7.root");
93 TFile* fileout = new TFile(outName.Data(), "RECREATE");
94
95 ofstream f_call;
96 TString NameCallFile = "Tof400LRcorr_RUN7.dat";
97 // TString NameCallFile = file;
98 // Point = NameCallFile.First('.');
99 // NameCallFile.Replace(Point, 15, "_LRcorr.dat");
100 cout << "Write call to " << NameCallFile.Data() << endl;
101 f_call.open(NameCallFile.Data());
102 f_call << "Plane\tStrip\tMeanFit\tMean" << endl << "==========================" << endl;
103
104 TDirectory* DirPlane[nDet];
105 TDirectory* Dir2Plane[nDet];
106 TF1* MyGaus = new TF1("MyGaus", "gaus", -24., 24.);
107 for (Int_t Plane = 0; Plane < nDet; Plane++) {
108 Name1.Clear();
109 Name1 = Form("Plane%d", Plane);
110 DirPlane[Plane] = fileout->mkdir(Name1.Data());
111
112 Dir2Plane[Plane] = DirPlane[Plane]->mkdir("Diff");
113 Dir2Plane[Plane]->cd();
114 for (Int_t Str = 0; Str < 48; Str++)
115 hDifDtLR[Plane][Str]->Write();
116
117 DirPlane[Plane]->cd();
118 for (Int_t Str = 0; Str < 48; Str++) {
119 Double_t left = hDtLR[Plane][Str]->GetMaximumBin() * hDtLR[Plane][Str]->GetBinWidth(1)
120 + hDtLR[Plane][Str]->GetXaxis()->GetBinLowEdge(1);
121 MyGaus->SetParameters(minimum[Plane] * 1.2, left + 0.9, 5.0);
122 MyGaus->SetParLimits(2, 0.1, 7);
123 MyGaus->SetParLimits(1, left + 0.5, left + 1.4);
124 if (Str >= 0 && Str <= 47) {
125 hDtLR[Plane][Str]->Fit("MyGaus", "QB", "");
126 f_call << Plane << "\t" << Str << "\t" << MyGaus->GetParameter(1) << "\t"
127 << hDtLR[Plane][Str]->GetMean() << endl;
128 hMean->Fill(MyGaus->GetParameter(1));
129 hdMean->Fill(MyGaus->GetParameter(1) - hDtLR[Plane][Str]->GetMean());
130 hdMean_vs_Strip->Fill(Plane * 48 + Str, MyGaus->GetParameter(1) - hDtLR[Plane][Str]->GetMean());
131 } else
132 f_call << Plane << "\t" << Str << "\t" << 0 << "\t" << left << endl;
133 hDtLR[Plane][Str]->Write();
134 // cout << " GetMaximumBin " << left << endl;
135 // getchar();
136 }
137 }
138
139 f_call.close();
140
141 fileout->cd();
142 hMean->Write();
143 hdMean->Write();
144 hdMean_vs_Strip->Write();
145 fileout->Close();
146 FileIn->Close();
147 //*/
148}
149
151{
152 TH1I* hTest = new TH1I("hTest", "hTest", 400, 0, 10);
153 for (Int_t i = 165; i <= 235; i++)
154 hTest->Fill(i * 0.025, 10);
155 hTest->Fit("gaus");
156 TCanvas* c1 = new TCanvas("c1", "c1", 50, 50, 550, 550);
157 hTest->Draw();
158}
int i
Definition P4_F32vec4.h:22
int Int_t
double Double_t
#define gDirectory
#define gROOT
char * Form(const char *fmt,...)
const Int_t nDet
void TestFitGaus()
void Tof400LRcorrection_period7(TString file="")
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