BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
ToF400DigitAnalysis_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: TestMacro.C
9 * Author: mikhailr
10 *
11 * Created on March 5, 2018, 5:14 PM
12 */
13
14#include "TStopwatch.h"
15
16#include <cstdlib>
17#include <ctime>
18
19using namespace std;
20
22
25const Int_t NDet = 20;
26
27void ToF400DigitAnalysis_period7(TString file = "/home/storage/digits/bmn_run2310_digi.root", Int_t nEvForRead = 0)
28{
29
30 gROOT->LoadMacro("$VMCWORKDIR/macro/run/bmnloadlibs.C");
31 bmnloadlibs(); // load BmnRoot libraries
32
33 BmnTOF1Detector* Plane[NDet];
34 TString name;
35 for (Int_t i = 0; i < NDet; i++) {
36 name = Form("Plane%d", i);
37 Plane[i] = new BmnTOF1Detector(i, 2);
38 // Plane[i]->SetCorrLR(CorrLR[i]);
39 Plane[i]->SetCorrLR("TOF400_LRcorr_RUN7.dat");
40 // Plane[i]->SetCorrSlewing("Tof400SlewingCorr_period6.root");
41 Plane[i]->SetGeoFile("geofile_full_RUN7.root");
42 // Plane[i]->SetGeoFile("geometry_run6.root");
43 }
44
45 TList* fList = new TList();
46 TList* fListTof = new TList();
47
48 TH2I* hCrosing = new TH2I("hCrosing", "hCrosing", 48, 0, 48, 48, 0, 48);
49 fList->Add(hCrosing);
50 TH1I* hCrosingDx = new TH1I("hCrosingDx", "hCrosingDx", 48, 0., 60.);
51 fList->Add(hCrosingDx);
52 TH1I* hCrosingDy = new TH1I("hCrosingDy", "hCrosingDy", 120, -30., 30.);
53 fList->Add(hCrosingDy);
54 TH1I* hCrosingDr = new TH1I("hCrosingDr", "hCrosingDr", 600, 0., 60.);
55 fList->Add(hCrosingDr);
56 TH1I* hCrosingDt = new TH1I("hCrosingDt", "hCrosingDt", 1024, -12., 12.);
57 fList->Add(hCrosingDt);
58 TH2I* hCrosingWidth_Width = new TH2I("hCrosingWidth_Width", "hCrosingWidth_Width", 1024, 12, 60, 1024, 12, 60);
59 fList->Add(hCrosingWidth_Width);
60 TH1I* hCrosingDwidth = new TH1I("hCrosingDwidth", "hCrosingDwidth", 512, -12., 12.);
61 fList->Add(hCrosingDwidth);
62
63 TH1I* hCrosingDtSt = new TH1I("hCrosingDtSt", "hCrosingDtSt", 1024, -12., 12.);
64 fList->Add(hCrosingDtSt);
65 TH2I* hCrosingDtSt_Width1 = new TH2I("hCrosingDtSt_Width1", "hCrosingDtSt_Width1", 1024, 12, 60, 1024, -12, 12);
66 fList->Add(hCrosingDtSt_Width1);
67 TH2I* hCrosingDtSt_Width2 = new TH2I("hCrosingDtSt_Width2", "hCrosingDtSt_Width2", 1024, 12, 60, 1024, -12, 12);
68 fList->Add(hCrosingDtSt_Width2);
69
70 TH2I* h_HitRPC = new TH2I("h_HitRPC", "h_HitRPC", 192, -96, 96, 5, 0, 5);
71 fListTof->Add(h_HitRPC);
72
73 TH2I* h_XYRPC = new TH2I("h_XYRPC", "h_XYRPC", 320, -200, 200, 120, -75, 75);
74 fListTof->Add(h_XYRPC);
75
76 TH2I* h_Time_vs_Angle = new TH2I("h_Time_vs_Angle", "h_Time_vs_Angle", 320, -200, 200, 1024, -6., 18.);
77 fListTof->Add(h_Time_vs_Angle);
78
79 TH1I* hdtPlane7 = new TH1I("hdtPlane7", "hdtPlane7", 1024, -5., 43.);
80 fList->Add(hdtPlane7);
81
82 TH2I* hdtPlane7_vs_AmpT0 = new TH2I("hdtPlane7_vs_AmpT0", "hdtPlane7_vs_AmpT0", 512, 0., 50., 512, -5., 43.);
83 fList->Add(hdtPlane7_vs_AmpT0);
84
85 TH2I* hdtPlane7_vs_AmpPlane7 =
86 new TH2I("hdtPlane7_vs_AmpPlane7", "hdtPlane7_vs_AmpPlane7", 512, 0., 50., 512, -5., 43.);
87 fList->Add(hdtPlane7_vs_AmpPlane7);
88
89 TH1I* hdtPlane12 = new TH1I("hdtPlane12", "hdtPlane12", 1024, -5., 43.);
90 fList->Add(hdtPlane12);
91
92 TH2I* hdtPlane12_vs_AmpT0 = new TH2I("hdtPlane12_vs_AmpT0", "hdtPlane12_vs_AmpT0", 512, 0., 50., 512, -5., 43.);
93 fList->Add(hdtPlane12_vs_AmpT0);
94
95 TH2I* hdtPlane12_vs_AmpPlane12 =
96 new TH2I("hdtPlane12_vs_AmpPlane12", "hdtPlane12_vs_AmpPlane12", 512, 0., 50., 512, -5., 43.);
97 fList->Add(hdtPlane12_vs_AmpPlane12);
98
99 TChain* eveTree = new TChain("cbmsim");
100 TString inName = Form("%s", file.Data());
101 // inName = file;
102 cout << "Open file " << inName << endl << endl;
103 eveTree->Add(inName);
104
105 TClonesArray* ToF400Digits;
106 eveTree->SetBranchAddress("TOF400", &ToF400Digits);
107
108 TClonesArray* T0Digits;
109 eveTree->SetBranchAddress("BC2", &T0Digits);
110
111 TClonesArray* VetoDigits;
112 eveTree->SetBranchAddress("VC", &VetoDigits);
113
114 TClonesArray* BDDigits;
115 eveTree->SetBranchAddress("BD", &BDDigits);
116
117 TClonesArray* SiDigits;
118 eveTree->SetBranchAddress("Si", &SiDigits);
119
120 Long64_t nEvents = eveTree->GetEntries();
121 if (nEvForRead == 0 || nEvForRead > nEvents)
122 nEvForRead = nEvents;
123 cout << "Will be read " << nEvForRead << " events from " << nEvents << endl;
124
125 for (Int_t iEv = 0; iEv < nEvForRead; iEv++) {
126
127 if (iEv % 1000 == 0)
128 cout << "EVENT: " << iEv << endl;
129 eveTree->GetEntry(iEv);
130
131 Int_t CountMod0 = 0, CountMod1 = 0;
132 for (Int_t i = 0; i < T0Digits->GetEntriesFast(); i++) {
133 BmnTrigDigit* digT0 = (BmnTrigDigit*)T0Digits->At(i);
134 if (digT0->GetMod() == 0)
135 CountMod0++;
136 if (digT0->GetMod() == 1)
137 CountMod1++;
138 }
139
140 if (CountMod0 == 1 && CountMod1 <= 0
141 //(T0Digits->GetEntriesFast()) >= 0
142 //&& (BC2Digits->GetEntriesFast()) >= 0
143 //&& (VetoDigits->GetEntriesFast()) == 0
144 //&& (BDDigits->GetEntriesFast()) >= 0
145 //&& (BDDigits->GetEntriesFast()) == 0
146 ) //*/
147 {
148
149 BmnTrigDigit* digT0 = NULL;
150 for (Int_t i = 0; i < T0Digits->GetEntriesFast(); i++) {
151 digT0 = (BmnTrigDigit*)T0Digits->At(i);
152 if (digT0->GetMod() == 0)
153 break;
154 }
155 if (digT0->GetAmp() >= 19.26 && digT0->GetAmp() <= 22.06) {
156
157 //--------------------------- RPC --------------------------------------------------
158 for (Int_t i = 0; i < NDet; i++)
159 Plane[i]->Clear();
160
161 // cout << "ToF400Digits->GetEntriesFast()=" << ToF400Digits->GetEntriesFast() << endl;
162 for (Int_t iDig = 0; iDig < ToF400Digits->GetEntriesFast(); ++iDig) {
163 FlagHit = kFALSE;
164 BmnTof1Digit* digTof = (BmnTof1Digit*)ToF400Digits->At(iDig);
165 FlagHit = Plane[digTof->GetPlane()]->SetDigit(digTof);
166 // cout << "SetDigit Plane#" << digTof->GetPlane() << " Strip#" << digTof->GetStrip() << " = " <<
167 // FlagHit << endl;
168 if (FlagHit == kTRUE) {
169 if (digTof->GetPlane() < 5) {
170 XforHit = digTof->GetStrip() * -1. - 48;
171 YforHit = 4 - digTof->GetPlane();
172 } else if (digTof->GetPlane() >= 5 && digTof->GetPlane() < 10) {
173 XforHit = digTof->GetStrip() * -1.;
174 YforHit = 4 - (digTof->GetPlane() - 5);
175 } else if (digTof->GetPlane() >= 10 && digTof->GetPlane() < 15) {
176 XforHit = 48 - digTof->GetStrip();
177 YforHit = 4 - (digTof->GetPlane() - 10);
178 } else if (digTof->GetPlane() >= 15 && digTof->GetPlane() < 20) {
179 XforHit = 96 - (digTof->GetStrip() + 48);
180 YforHit = 4 - (digTof->GetPlane() - 15);
181 }
182 // cout << "PlaneR = " << digTof->GetPlane() << "; StripR = " << digTof->GetStrip() << endl;
183 // cout << "Plane = " << YforHit << "; Strip = " << XforHit << endl;
184 // getchar();
185 h_HitRPC->Fill(XforHit, YforHit);
186 }
187 }
188 // getchar();
189
190 TVector3 XYZ;
191 XYZ.SetXYZ(0., 0., 0.);
192 Double_t ToF = 0;
193 FlagHit = kFALSE;
194 for (Int_t i = 0; i < NDet; i++) {
195 Plane[i]->FindHits(digT0);
196 for (Int_t s = 0; s < 47; s++) {
197 XYZ.SetXYZ(0., 0., 0.);
198 ToF = 0;
199 FlagHit = kFALSE;
200 FlagHit = Plane[i]->GetXYZTime(s, &XYZ, &ToF);
201 if (FlagHit == kTRUE) {
202 h_XYRPC->Fill(XYZ.x(), XYZ.y());
203 if (i == 7)
204 h_Time_vs_Angle->Fill(XYZ.x(), ToF);
205 }
206 if (ToF != 0 && i == 7 && s == 3) {
207 // cout << " Ev = " << iEv << "; Strip = " << s << "; ToF = " <<ToF << "; Amp = " <<
208 // Plane[i]->GetWidth(s) << endl;
209 hdtPlane7->Fill(ToF);
210 hdtPlane7_vs_AmpT0->Fill(digT0->GetAmp(), ToF);
211 hdtPlane7_vs_AmpPlane7->Fill(Plane[i]->GetWidth(s), ToF);
212 }
213 if (ToF != 0 && i == 12 && s == 45) {
214 // cout << " Ev = " << iEv << "; Strip = " << s << "; ToF = " <<ToF << "; Amp = " <<
215 // Plane[i]->GetWidth(s) << endl;
216 hdtPlane12->Fill(ToF);
217 hdtPlane12_vs_AmpT0->Fill(digT0->GetAmp(), ToF);
218 hdtPlane12_vs_AmpPlane12->Fill(Plane[i]->GetWidth(s), ToF);
219 }
220 }
221 }
222 CrossingDet(Plane[2], Plane[7], hCrosing, hCrosingDx, hCrosingDy, hCrosingDr, hCrosingDt, hCrosingDtSt,
223 hCrosingDtSt_Width1, hCrosingDtSt_Width2);
224
225 } // end if (digT0->GetAmp() >= 17.3 && digT0->GetAmp() <= 19.2)
226 } // end if ((T0Digits->GetEntriesFast()) == 1 && (VetoDigits->GetEntriesFast()) == 0 &&
227 // (BDDigits->GetEntriesFast()) >= 2)
228 } // end for (Int_t iEv = 0; iEv < nEvForRead; iEv++)
229
230 cout << "End Data Analysis" << endl;
231
232 TString outName = file;
233 Int_t Point = outName.First('.');
234 outName.Replace(Point, 15, "_TofAn7.root");
235 outName = Form("%s", outName.Data());
236 cout << "Save data to " << outName.Data() << endl;
237 TFile* fileout = new TFile(outName.Data(), "RECREATE");
238
239 TDirectory* Dir;
240 Dir = fileout->mkdir("ToF");
241 Dir->cd();
242 fListTof->Write();
243
244 TDirectory* DirPlane[NDet];
245 TDirectory* Dir1Plane[NDet];
246 TDirectory* Dir2Plane[NDet];
247 for (Int_t i = 0; i < NDet; i++) {
248 DirPlane[i] = Dir->mkdir(Plane[i]->GetName());
249 DirPlane[i]->cd();
250 Plane[i]->GetList(0)->Write();
251 Dir1Plane[i] = DirPlane[i]->mkdir("Detector");
252 Dir1Plane[i]->cd();
253 Plane[i]->GetList(1)->Write();
254 Dir2Plane[i] = DirPlane[i]->mkdir("ToF");
255 Dir2Plane[i]->cd();
256 Plane[i]->GetList(2)->Write();
257 }
258
259 fileout->cd();
260 fList->Write();
261 fileout->Close();
262}
263
265{
266 // Double_t dt = bd->GetTime() - t0->GetTime();
267 /* dt = dt - (14.55 + 0.1218 * bd->GetAmp()
268 - 0.02473 * bd->GetAmp() * bd->GetAmp()
269 + 0.0006237 * bd->GetAmp() * bd->GetAmp() * bd->GetAmp());
270 dt = dt - (1.947 - 0.5363 * t0->GetAmp()
271 + 0.03428 * t0->GetAmp() * t0->GetAmp()
272 - 0.0005853 * t0->GetAmp() * t0->GetAmp() * t0->GetAmp());
273 /* dt = dt - (-3.412 + 0.1866 * t0->GetAmp());//*/
274 // return dt;
275}
276
278{
279 // Double_t dt = timeBD - t0->GetTime();
280 /* dt = dt - (14.55 + 0.1218 * ampBD
281 - 0.02473 * ampBD * ampBD
282 + 0.0006237 * ampBD * ampBD * ampBD);
283 dt = dt - (1.947 - 0.5363 * t0->GetAmp()
284 + 0.03428 * t0->GetAmp() * t0->GetAmp()
285 - 0.0005853 * t0->GetAmp() * t0->GetAmp() * t0->GetAmp());
286 //dt = dt - (-3.412 + 0.1866 * t0->GetAmp());//*/
287 // return dt;
288}
289
291{
292 // Double_t dt = bc2->GetTime() - t0->GetTime();
293 /* dt = dt - (40.47
294 - 6.338 * bc2->GetAmp()
295 + 0.35 * bc2->GetAmp() * bc2->GetAmp()
296 - 0.006571 * bc2->GetAmp() * bc2->GetAmp() * bc2->GetAmp());
297 dt = dt - (1.947 - 0.5363 * t0->GetAmp()
298 + 0.03428 * t0->GetAmp() * t0->GetAmp()
299 - 0.0005853 * t0->GetAmp() * t0->GetAmp() * t0->GetAmp());
300 /* dt = dt - (0.4034 - 0.01599 * t0->GetAmp());
301 dt = dt + 0.001108; //zero for C 3.5 Gec/nuclon */
302 // return dt;
303}
304
306 BmnTOF1Detector* Det2,
307 TH2* hD1D2,
308 TH1* hDx,
309 TH1* hDy,
310 TH1* hDr,
311 TH1* hDt,
312 TH1* hDtSt,
313 TH2* hDtSt_W1,
314 TH2* hDtSt_W2)
315{
316 TVector3 XyzD1, XyzD2;
317 Double_t ToF1 = 0, ToF2 = 0, dT = 0.;
318 for (Int_t iD1 = 0; iD1 < 12; iD1++) {
319 XyzD1.SetXYZ(0., 0., 0.);
320 ToF1 = 0;
321 if (Det1->GetXYZTime(iD1, &XyzD1, &ToF1))
322 for (Int_t iD2 = 36; iD2 < 48; iD2++) {
323 XyzD2.SetXYZ(0., 0., 0.);
324 ToF2 = 0.;
325 if (Det2->GetXYZTime(iD2, &XyzD2, &ToF2)) {
326 hD1D2->Fill(iD1, iD2);
327 Double_t dX = XyzD1.x() - XyzD2.x();
328 Double_t dY = XyzD1.y() - XyzD2.y();
329 Double_t dR = TMath::Sqrt(dX * dX + dY * dY);
330 hDx->Fill(dX);
331 hDy->Fill(dY);
332 hDr->Fill(dR);
333 hDt->Fill(ToF1 - ToF2);
334 hCrosingWidth_Width->Fill(Det1->GetWidth(iD1), Det2->GetWidth(iD2));
335 hCrosingDwidth->Fill(Det1->GetWidth(iD1) - Det2->GetWidth(iD2));
336 if (iD1 == 2 && iD2 == 42) {
337 hDtSt->Fill(ToF1 - ToF2);
338 hDtSt_W1->Fill(Det1->GetWidth(iD1), ToF1 - ToF2);
339 hDtSt_W2->Fill(Det2->GetWidth(iD2), ToF1 - ToF2);
340 }
341 // cout << 3 << endl;
342 }
343 }
344 }
345}
int i
Definition P4_F32vec4.h:22
bool Bool_t
int Int_t
constexpr Bool_t kFALSE
double Double_t
long long Long64_t
constexpr Bool_t kTRUE
#define gROOT
char * Form(const char *fmt,...)
Bool_t GetXYZTime(Int_t Str, TVector3 *XYZ, Double_t *ToF)
Bool_t SetGeoFile(TString NameFile)
Bool_t SetCorrLR(TString NameFile)
Double_t GetWidth(Int_t Str)
TList * GetList(Int_t n)
Short_t GetPlane() const
Short_t GetStrip() const
Double_t GetAmp() const
Short_t GetMod() const
Int_t SetBranchAddress(const char *bname, T **add, TBranch **ptr=nullptr)
virtual Int_t Add(const char *name, Long64_t nentries=TTree::kMaxEntries)
Long64_t GetEntries() const override
Int_t GetEntry(Long64_t entry=0, Int_t getall=0) override
Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0) const override
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)
void Close(Option_t *option="") override
virtual Int_t Fill(const char *name, Double_t w)
virtual Int_t Fill(const char *namex, const char *namey, Double_t w)
void Add(TObject *obj) override
Int_t GetEntriesFast() const
TObject * At(Int_t idx) const override
TString & Replace(Ssiz_t pos, Ssiz_t n, const char *s)
Ssiz_t First(char c) const
const char * Data() const
void SetXYZ(Double_t x, Double_t y, Double_t z)
Double_t x() const
Double_t y() const
Double_t NHitBD
Double_t TimeBD
Double_t AmpBD
const Int_t NDet
void ToF400DigitAnalysis_period7(TString file="/home/storage/digits/bmn_run2310_digi.root", Int_t nEvForRead=0)
void CrossingDet(BmnTOF1Detector *Det1, BmnTOF1Detector *Det2, TH2 *hD1D2, TH1 *hDx, TH1 *hDy, TH1 *hDr, TH1 *hDt, TH1 *hDtSt, TH2 *hDtSt_W1, TH2 *hDtSt_W2)
Double_t CalculateDtT0BC2(BmnTrigDigit *bc2, BmnTrigDigit *t0)
Double_t CalculateDtT0BD(BmnTrigDigit *bd, BmnTrigDigit *t0)
Double_t Sqrt(Double_t x)
Definition json.hpp:4446