BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
extractVertAppr.C
Go to the documentation of this file.
1R__ADD_INCLUDE_PATH($VMCWORKDIR)
2#include "macro/run/bmnloadlibs.C"
3
4#include <TMath.h>
5
6using namespace std;
7using namespace TMath;
8
10
11void extractVertAppr(TString filename = "")
12{
13 bmnloadlibs(); // load BmnRoot libraries
14
15 TChain* out = new TChain("cbmsim");
16 out->Add(filename.Data());
17 cout << "#recorded entries = " << out->GetEntries() << " in file" << endl;
18
19 TClonesArray* vertex = NULL;
20
21 out->SetBranchAddress("BmnVertex", &vertex);
22 const UInt_t nEvs = out->GetEntries();
23
24 TH1F* x = new TH1F("X", "X", 100, -10., +10.);
25 TH1F* y = new TH1F("Y", "Y", 100, -10., +10.);
26 TH1F* z = new TH1F("Z", "Z", 100, -10., +10.);
27
28 Double_t roughX = 0.0;
29 Double_t roughY = 0.0;
30 Double_t roughZ = 0.0;
31
32 for (Int_t iEv = 0; iEv < out->GetEntries(); iEv++) {
33 out->GetEntry(iEv);
34 if (iEv % 1000 == 0)
35 cout << " Ev# " << iEv << endl;
36
37 CbmVertex* Vp = (CbmVertex*)vertex->UncheckedAt(0);
38 x->Fill(Vp->GetX());
39 y->Fill(Vp->GetY());
40 z->Fill(Vp->GetZ());
41
42 if (iEv == 0) {
43 roughX = Vp->GetRoughX();
44 roughY = Vp->GetRoughY();
45 roughZ = Vp->GetRoughZ();
46 }
47 }
48
49 Int_t intX = computeIntegral(x, -1., +1.);
50 Int_t intY = computeIntegral(y, -5., -3.);
51 Int_t intZ = computeIntegral(z, -3., 0.);
52
53 if (intX != 0 && intY != 0 && intZ != 0) {
54 TFitResultPtr fitX = x->Fit("gaus", "SQ", "", -1., +1.);
55 TFitResultPtr fitY = y->Fit("gaus", "SQ", "", -5., -3.);
56 TFitResultPtr fitZ = z->Fit("gaus", "SQ", "", -3., 0.);
57
58 if (Abs(roughX - fitX->Parameter(1)) < 5. && Abs(roughY - fitY->Parameter(1)) < 5.
59 && Abs(roughZ - fitZ->Parameter(1)) < 5.)
60 {
61 FILE* f = fopen("fitParams.txt", "w");
62 fprintf(f, "%G %G %G", fitX->Parameter(1), fitY->Parameter(1), fitZ->Parameter(1));
63 fclose(f);
64 }
65 }
66 delete out;
67}
68
69//------------------------------------------------------------
71{
72 TAxis* axis = h->GetXaxis();
73 Int_t bmin = axis->FindBin(xmin);
74 Int_t bmax = axis->FindBin(xmax);
75 return h->Integral(bmin, bmax);
76}
int Int_t
unsigned int UInt_t
double Double_t
#define R__ADD_INCLUDE_PATH(PATH)
CbmVertex.h.
Definition CbmVertex.h:21
Double_t GetZ() const
Definition CbmVertex.h:60
Double_t GetX() const
Accessors.
Definition CbmVertex.h:58
Double_t GetY() const
Definition CbmVertex.h:59
double Parameter(unsigned int i) const
virtual Int_t FindBin(const char *label)
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
TAxis * GetXaxis()
virtual Double_t Integral(Int_t binx1, Int_t binx2, Option_t *option="") const
TObject * UncheckedAt(Int_t i) const
void extractVertAppr(TString filename="")
Int_t computeIntegral(TH1F *, Double_t, Double_t)
Double_t Abs(Double_t d)
Definition json.hpp:4446