BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
Tof400Identification.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#include "TCanvas.h"
8#include "TChain.h"
9#include "TClonesArray.h"
10#include "TDirectory.h"
11#include "TF1.h"
12#include "TFile.h"
13#include "TH1.h"
14#include "TH2.h"
15#include "TList.h"
16#include "TPad.h"
17#include "TVector3.h"
18
19#include <TMath.h>
20#include <ctime>
21#include <fstream>
22#include <iostream>
23#include <istream>
24#include <stdio.h>
25#include <vector>
26
27void Tof400Identification(TString NameFileIn = "bmndst.root", Int_t nEvForRead = 0)
28{
29
30 TStopwatch timer;
31 timer.Start();
32 Int_t nBytes = 0;
33
34 gROOT->LoadMacro("$VMCWORKDIR/macro/run/bmnloadlibs.C");
35 bmnloadlibs(); // load BmnRoot libraries
36 // gStyle->SetOptStat(kFALSE);
37
38 TH1I* hBetta = new TH1I("hBetta", "hBetta", 400, -2., 2.);
39 hBetta->GetXaxis()->SetTitle("beta ");
40 hBetta->SetMarkerStyle(8);
41 hBetta->SetMarkerColor(2);
42
43 TH2I* hMomentumBetta = new TH2I("hMomentumBeta", "hMomentumBeta", 1000, -10., 10., 400, -2., 2.);
44 hMomentumBetta->GetXaxis()->SetTitle("momentum, GeV/c ");
45 hMomentumBetta->GetYaxis()->SetTitle("beta ");
46
47 //--------Data Analysis-----------------------------------------------------------------
48
49 TChain* eveTree = new TChain("cbmsim");
50 TString inName = Form("$VMCWORKDIR/macro/run/%s", NameFileIn.Data());
51 // inName = file;
52 cout << "Open file " << inName << endl << endl;
53 eveTree->Add(inName);
54
55 TClonesArray* Tof400Hits;
56 eveTree->SetBranchAddress("BmnTof400Hit", &Tof400Hits);
57
58 TClonesArray* BmnGlobTr;
59 eveTree->SetBranchAddress("BmnGlobalTrack", &BmnGlobTr);
60
61 Long64_t nEvents = eveTree->GetEntries();
62 if (nEvForRead == 0 || nEvForRead > nEvents)
63 nEvForRead = nEvents;
64 cout << "Will be read " << nEvForRead << " events from " << nEvents << endl;
65
66 for (Int_t iEv = 0; iEv < nEvForRead; iEv++) {
67
68 if (iEv % 50000 == 0)
69 cout << "EVENT: " << iEv << endl;
70 nBytes = eveTree->GetEntry(iEv);
71
72 for (Int_t iGlobTrack = 0; iGlobTrack < BmnGlobTr->GetEntriesFast(); iGlobTrack++) {
73 BmnGlobalTrack* Track = (BmnGlobalTrack*)BmnGlobTr->At(iGlobTrack);
74 FairTrackParam parLast(*(Track->GetParamLast()));
75 FairTrackParam parFirst(*(Track->GetParamFirst()));
76 Int_t IndexTof1Hit = Track->GetTof1HitIndex();
77 if (IndexTof1Hit == -1)
78 continue;
79 // cout << "Event#" << iEv << endl;
80 BmnTofHit* hitTof400 = (BmnTofHit*)Tof400Hits->At(IndexTof1Hit);
81 Double_t Velocity = hitTof400->GetLength() / hitTof400->GetTimeStamp() / 10.; // * 10^8 m/s
82 Double_t Betta = Velocity / 2.99792458; //
83 hBetta->Fill(Betta);
84 Double_t Momentum = 1. / Track->GetParamLast()->GetQp();
85 hMomentumBetta->Fill(Momentum, Betta);
86
87 } // end for (Int_t iGlobTrack = 0; iGlobTrack < BmnGlobalTrack->GetEntriesFast(); iGlobTrack++)
88 } // end for (Int_t iEv = 0; iEv < nEvForRead; iEv++)
89
90 timer.Stop();
91 cout << "Readed " << nEvForRead << " events" << endl;
92 cout << "Time = " << timer.RealTime() << " s" << endl;
93 cout << "Time/Event = " << timer.RealTime() / (Double_t)nEvForRead * 1000. << " ms/Event" << endl;
94 cout << "TimeCPU = " << timer.CpuTime() << " s" << endl;
95 cout << "TimeCPU/Event = " << timer.CpuTime() / (Double_t)nEvForRead * 1000. << " ms/Event" << endl;
96
97 timer.Reset();
98 timer.Start();
99 TString outName = NameFileIn;
100 Int_t Point = outName.First('.');
101 outName.Replace(Point, 15, "_Identification.root");
102 outName = Form("/home/storage/analysis/%s", outName.Data());
103 cout << "Save data to " << outName.Data() << endl;
104 TFile* fileout = new TFile(outName.Data(), "RECREATE");
105
106 hBetta->Write();
107 hMomentumBetta->Write();
108
109 fileout->Close();
110
111 timer.Stop();
112
113 cout << "Time for write root = " << timer.RealTime() << " s" << endl;
114}
int Int_t
double Double_t
long long Long64_t
#define gROOT
char * Form(const char *fmt,...)
BmnGlobalTrack.h.
Int_t GetTof1HitIndex() const
Double_t GetLength()
Definition BmnHit.h:33
FairTrackParam * GetParamFirst()
Definition BmnTrack.h:63
FairTrackParam * GetParamLast()
Definition BmnTrack.h:65
virtual void SetMarkerColor(Color_t mcolor=1)
virtual void SetMarkerStyle(Style_t mstyle=1)
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
void Close(Option_t *option="") override
TAxis * GetXaxis()
TAxis * GetYaxis()
virtual Int_t Fill(const char *name, Double_t w)
virtual Int_t Fill(const char *namex, const char *namey, Double_t w)
virtual void SetTitle(const char *title="")
Int_t GetEntriesFast() const
TObject * At(Int_t idx) const override
virtual Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0)
Double_t RealTime()
void Start(Bool_t reset=kTRUE)
Double_t CpuTime()
void Stop()
void Reset()
TString & Replace(Ssiz_t pos, Ssiz_t n, const char *s)
Ssiz_t First(char c) const
const char * Data() const
void Tof400Identification(TString NameFileIn="bmndst.root", Int_t nEvForRead=0)