BmnRoot
26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Toggle main menu visibility
Loading...
Searching...
No Matches
read_dst_example.C
Go to the documentation of this file.
1
// read_dst_example.C: loop over DST events and print basic information on vertices and global tracks
2
// works with simulated and experimental DSTs; MC information is read only if it is present in the file
3
void
read_dst_example
(
TString
dstFileName =
"bmndst.root"
,
Int_t
nPrint = 3)
4
{
5
// run-level information is stored once per file
6
TFile
* file =
TFile::Open
(dstFileName);
7
DstRunHeader
* runHeader = (
DstRunHeader
*)file->
Get
(
"DstRunHeader"
);
8
cout <<
"Period "
<< runHeader->
GetPeriodId
() <<
", run "
<< runHeader->
GetRunId
() <<
": "
<< runHeader->
GetBeam
()
9
<<
" + "
<< runHeader->
GetTarget
() <<
" at "
<< runHeader->
GetBeamEnergy
() <<
" AGeV, field scale "
10
<< runHeader->
GetFieldScale
() << endl;
11
12
TTree
* tree = (
TTree
*)file->
Get
(
"bmndata"
);
13
tree->
SetBranchStatus
(
"*Cluster*"
, 0);
// skip the heavy cluster branches, they are not used here
14
15
DstEventHeader
* eventHeader =
nullptr
;
16
CbmVertex
* vertex =
nullptr
;
17
TClonesArray
*globalTracks =
nullptr
, *innerTracks =
nullptr
, *tof400Hits =
nullptr
;
18
tree->
SetBranchAddress
(
"DstEventHeader."
, &eventHeader);
19
tree->
SetBranchAddress
(
"MpdVertex."
, &vertex);
20
tree->
SetBranchAddress
(
"BmnGlobalTrack"
, &globalTracks);
21
tree->
SetBranchAddress
(
"StsVector"
, &innerTracks);
22
tree->
SetBranchAddress
(
"BmnTof400Hit"
, &tof400Hits);
23
24
// MC information exists only in simulated DSTs
25
BmnMCInfoDst
* mcInfo =
nullptr
;
26
Bool_t
isSimulation = (tree->
GetBranch
(
"BmnMCInfo."
) !=
nullptr
);
27
if
(isSimulation)
28
tree->
SetBranchAddress
(
"BmnMCInfo."
, &mcInfo);
29
30
for
(
Long64_t
iEvent = 0; iEvent <
TMath::Min
(tree->
GetEntries
(), (
Long64_t
)nPrint); iEvent++) {
31
tree->
GetEntry
(iEvent);
32
printf(
"Event %u: vertex (%.2f, %.2f, %.2f) cm from %d tracks, %d global tracks\n"
, eventHeader->
GetEventId
(),
33
vertex->
GetX
(), vertex->
GetY
(), vertex->
GetZ
(), vertex->
GetNTracks
(), globalTracks->
GetEntriesFast
());
34
if
(vertex->
GetNTracks
() < 2)
35
continue
;
36
37
for
(
Int_t
iTrack = 0; iTrack <
TMath::Min
(globalTracks->
GetEntriesFast
(), 3); iTrack++) {
38
BmnGlobalTrack
* track = (
BmnGlobalTrack
*)globalTracks->
UncheckedAt
(iTrack);
39
CbmStsTrack
* inner = (
CbmStsTrack
*)innerTracks->UncheckedAt(track->
GetGemTrackIndex
());
40
41
FairTrackParam* par = track->
GetParamFirst
();
// at the z of MpdVertex
42
Double_t
p = 1. /
TMath::Abs
(par->GetQp());
// momentum for |Z| = 1, rigidity p/|Z| otherwise
43
Int_t
charge = (par->GetQp() > 0) ? +1 : -1;
44
Double_t
pz = p /
TMath::Sqrt
(1. + par->GetTx() * par->GetTx() + par->GetTy() * par->GetTy());
45
Double_t
pt = pz *
TMath::Sqrt
(par->GetTx() * par->GetTx() + par->GetTy() * par->GetTy());
46
47
printf(
" track %d: q = %+d, p = %.3f, pt = %.3f GeV/c, hits = %d, in vertex = %d, DCA = %.2f cm"
, iTrack,
48
charge, p, pt, inner->
GetNStsHits
(), inner->
FromVertex
() ? 1 : 0, track->
GetDCAInVertex
());
49
if
(track->
GetTof1HitIndex
() >= 0) {
50
BmnTofHit
* hit = (
BmnTofHit
*)tof400Hits->UncheckedAt(track->
GetTof1HitIndex
());
51
Double_t
beta
= hit->
GetLength
() / hit->GetTimeStamp() / 29.9792458;
// length in cm, time in ns
52
printf(
", TOF400: t = %.2f ns, beta = %.3f, m2 = %.3f"
, hit->GetTimeStamp(),
beta
, track->
GetMass2
(1));
53
}
54
// the matched MC track is stored in the inner track
55
if
(isSimulation && inner->
GetTrkID
() >= 0) {
56
CbmMCTrack
* mcTrack = (
CbmMCTrack
*)mcInfo->
GetMCTracks
()->
UncheckedAt
(inner->
GetTrkID
());
57
printf(
", MC: pdg = %d, p = %.3f"
, mcTrack->
GetPdgCode
(), mcTrack->
GetP
());
58
}
59
printf(
"\n"
);
60
}
61
}
62
}
Bool_t
bool Bool_t
Int_t
int Int_t
Double_t
double Double_t
Long64_t
long long Long64_t
BmnGlobalTrack
BmnGlobalTrack.h.
Definition
BmnGlobalTrack.h:14
BmnGlobalTrack::GetGemTrackIndex
Int_t GetGemTrackIndex() const
Accessors.
Definition
BmnGlobalTrack.h:34
BmnGlobalTrack::GetDCAInVertex
Float_t GetDCAInVertex()
Definition
BmnGlobalTrack.h:80
BmnGlobalTrack::GetTof1HitIndex
Int_t GetTof1HitIndex() const
Definition
BmnGlobalTrack.h:36
BmnGlobalTrack::GetMass2
Float_t GetMass2(Int_t tofID) const
Definition
BmnGlobalTrack.h:43
BmnHit::GetLength
Double_t GetLength()
Definition
BmnHit.h:33
BmnMCInfoDst
Definition
BmnMCInfoDst.h:12
BmnMCInfoDst::GetMCTracks
TClonesArray * GetMCTracks() const
rot. around z-axis [rad]
Definition
BmnMCInfoDst.h:35
BmnTofHit
Definition
BmnTofHit.h:22
BmnTrack::GetParamFirst
FairTrackParam * GetParamFirst()
Definition
BmnTrack.h:63
CbmMCTrack
CbmMCTrack.h.
Definition
CbmMCTrack.h:26
CbmMCTrack::GetP
Double_t GetP() const
Definition
CbmMCTrack.h:68
CbmMCTrack::GetPdgCode
Int_t GetPdgCode() const
Accessors.
Definition
CbmMCTrack.h:56
CbmStsTrack
Definition
CbmStsTrack.h:28
CbmStsTrack::FromVertex
int FromVertex() const
Definition
CbmStsTrack.h:76
CbmStsTrack::GetTrkID
int GetTrkID()
Definition
CbmStsTrack.h:79
CbmStsTrack::GetNStsHits
Int_t GetNStsHits() const
Accessors.
Definition
CbmStsTrack.h:60
CbmVertex
CbmVertex.h.
Definition
CbmVertex.h:21
CbmVertex::GetZ
Double_t GetZ() const
Definition
CbmVertex.h:60
CbmVertex::GetX
Double_t GetX() const
Accessors.
Definition
CbmVertex.h:58
CbmVertex::GetNTracks
Int_t GetNTracks() const
Definition
CbmVertex.h:63
CbmVertex::GetY
Double_t GetY() const
Definition
CbmVertex.h:59
DstEventHeader
Definition
DstEventHeader.h:10
DstEventHeader::GetEventId
UInt_t GetEventId()
Get run ID for this run.
Definition
DstEventHeader.h:53
DstRunHeader
Definition
DstRunHeader.h:9
DstRunHeader::GetTarget
TString GetTarget()
Definition
DstRunHeader.h:45
DstRunHeader::GetRunId
UInt_t GetRunId()
Get run number for this run.
Definition
DstRunHeader.h:38
DstRunHeader::GetFieldScale
Double_t GetFieldScale()
Definition
DstRunHeader.h:49
DstRunHeader::GetBeam
TString GetBeam()
Definition
DstRunHeader.h:41
DstRunHeader::GetBeamEnergy
Float_t GetBeamEnergy()
Definition
DstRunHeader.h:44
DstRunHeader::GetPeriodId
UInt_t GetPeriodId()
Get period number for this run.
Definition
DstRunHeader.h:36
TClonesArray
TDirectoryFile::Get
T * Get(const char *namecycle)
TFile
TFile::Open
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
TObjArray::GetEntriesFast
Int_t GetEntriesFast() const
TObjArray::UncheckedAt
TObject * UncheckedAt(Int_t i) const
TString
TTree
TTree::SetBranchStatus
virtual void SetBranchStatus(const char *bname, bool status=true, UInt_t *found=nullptr)
TTree::GetBranch
virtual TBranch * GetBranch(const char *name)
TTree::GetEntry
virtual Int_t GetEntry(Long64_t entry, Int_t getall=0)
TTree::GetEntries
virtual Long64_t GetEntries() const
TTree::SetBranchAddress
Int_t SetBranchAddress(const char *bname, T **add, TBranch **ptr=nullptr)
beta
double beta(double x, double y)
TMath::Min
Double_t Min(Double_t a, Double_t b)
TMath::Sqrt
Double_t Sqrt(Double_t x)
TMath::Abs
Double_t Abs(Double_t d)
read_dst_example
void read_dst_example(TString dstFileName="bmndst.root", Int_t nPrint=3)
Definition
read_dst_example.C:3
services
format_docs
dst
read_dst_example.C
Generated on
for BmnRoot by
1.17.0