BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
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
3void 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 Bool_t
int Int_t
double Double_t
long long Long64_t
BmnGlobalTrack.h.
Int_t GetGemTrackIndex() const
Accessors.
Float_t GetDCAInVertex()
Int_t GetTof1HitIndex() const
Float_t GetMass2(Int_t tofID) const
Double_t GetLength()
Definition BmnHit.h:33
TClonesArray * GetMCTracks() const
rot. around z-axis [rad]
FairTrackParam * GetParamFirst()
Definition BmnTrack.h:63
CbmMCTrack.h.
Definition CbmMCTrack.h:26
Double_t GetP() const
Definition CbmMCTrack.h:68
Int_t GetPdgCode() const
Accessors.
Definition CbmMCTrack.h:56
int FromVertex() const
Definition CbmStsTrack.h:76
int GetTrkID()
Definition CbmStsTrack.h:79
Int_t GetNStsHits() const
Accessors.
Definition CbmStsTrack.h:60
CbmVertex.h.
Definition CbmVertex.h:21
Double_t GetZ() const
Definition CbmVertex.h:60
Double_t GetX() const
Accessors.
Definition CbmVertex.h:58
Int_t GetNTracks() const
Definition CbmVertex.h:63
Double_t GetY() const
Definition CbmVertex.h:59
UInt_t GetEventId()
Get run ID for this run.
TString GetTarget()
UInt_t GetRunId()
Get run number for this run.
Double_t GetFieldScale()
TString GetBeam()
Float_t GetBeamEnergy()
UInt_t GetPeriodId()
Get period number for this run.
T * Get(const char *namecycle)
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Int_t GetEntriesFast() const
TObject * UncheckedAt(Int_t i) const
virtual void SetBranchStatus(const char *bname, bool status=true, UInt_t *found=nullptr)
virtual TBranch * GetBranch(const char *name)
virtual Int_t GetEntry(Long64_t entry, Int_t getall=0)
virtual Long64_t GetEntries() const
Int_t SetBranchAddress(const char *bname, T **add, TBranch **ptr=nullptr)
double beta(double x, double y)
Double_t Min(Double_t a, Double_t b)
Double_t Sqrt(Double_t x)
Double_t Abs(Double_t d)
void read_dst_example(TString dstFileName="bmndst.root", Int_t nPrint=3)