BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
readDst.C
Go to the documentation of this file.
1// @(#)bmnroot/macro/howTo:$Id$
2////////////////////////////////////////////////////////////////////////////////
3// //
4// readDst.C //
5// //
6// An example how to read reconstructed data (DST) from bmndst.root //
7// //
8////////////////////////////////////////////////////////////////////////////////
9#include <RtypesCore.h>
10#include <fairlogger/Logger.h>
11
17
18int readDst(TString dstFilePath = "", enumTracking tracking = VectorFinder)
19{
20 if (dstFilePath == "") {
21 LOG(error) << "DST file not specified!";
22 return -1;
23 }
24
25 // check DST file exists
26 if (!BmnFunctionSet::CheckFileExist(dstFilePath, 1))
27 return -2;
28
29 // open DST file with 'bmndata' tree
30 TChain* dataChain = new TChain("bmndata");
31 dataChain->Add(dstFilePath.Data());
32 LOG(info) << "Event Number = " << dataChain->GetEntries();
33 // load the first tree of the chain: its file and branches are used below
34 if (dataChain->LoadTree(0) < 0) {
35 LOG(error) << "No events in the DST file, exiting...";
36 return -13;
37 }
38
39 // read DST Run Header if present
40 DstRunHeader* run_header = (DstRunHeader*)dataChain->GetCurrentFile()->Get("DstRunHeader");
41 if (run_header) {
42 Int_t run_period = run_header->GetPeriodId();
43 Double_t fieldScale = run_header->GetFieldScale();
44 cout << "|||||||||||| DST RUN SUMMARY |||||||||||||||" << endl;
45 cout << "||\t\t\t\t\t ||" << endl;
46 cout << "|| Period: " << run_period << "\t\t\t ||" << endl;
47 cout << "|| Number: " << run_header->GetRunId() << "\t\t\t ||" << endl;
48 cout << "|| Start Time: " << run_header->GetStartTime().AsString("s") << "\t ||" << endl;
49 cout << "|| End Time: " << run_header->GetFinishTime().AsString("s") << "\t ||" << endl;
50 cout << "|| Beam: A = " << run_header->GetBeamA() << ", Z = " << run_header->GetBeamZ() << "\t ||"
51 << endl;
52 cout << "|| Beam energy: " << run_header->GetBeamEnergy() << " GeV\t\t ||" << endl;
53 cout << "|| Target: A = " << run_header->GetTargetA() << ", Z = " << run_header->GetTargetZ()
54 << "\t ||" << endl;
55 cout << "|| Field scale: " << setprecision(4) << fieldScale << "\t\t\t ||" << endl;
56 cout << "||\t\t\t\t\t ||" << endl;
57 cout << "||||||||||||||||||||||||||||||||||||||||||||" << endl << endl;
58 }
59
60 // magnetic field used in the reconstruction, it is needed, e.g., to extrapolate tracks
61 Double_t field_scale = 0.;
62 Int_t field_type = -1;
63 FairField* magField = BmnFunctionAna::GetDSTField(dstFilePath, field_scale, field_type);
64 if (magField == nullptr)
65 LOG(warn) << "The magnetic field was not obtained from the DST file";
66
67 /** assign TClonesArrays to DST tree branches **/
68 // assign event header class to the DST event header
69 DstEventHeader* event_header = nullptr;
70 dataChain->SetBranchAddress("DstEventHeader.", &event_header);
71 if (event_header == nullptr) {
72 LOG(error) << "'DstEventHeader.' branch was not found, please, check the structure of the DST file, exiting...";
73 return -3;
74 }
75
76 // assign CbmVertex object to the branch with reconstructed primary vertex
77 CbmVertex* primaryVertex = nullptr;
78 dataChain->SetBranchAddress("PrimaryVertex.", &primaryVertex);
79 if (primaryVertex == nullptr) {
80 LOG(error) << "'PrimaryVertex.' branch was not found, please, check the structure of the DST file, exiting...";
81 return -4;
82 }
83
84 // assign TClonesArray to the branch with reconstructed global tracks
85 TClonesArray* globalTracks = nullptr;
86 dataChain->SetBranchAddress("BmnGlobalTrack", &globalTracks);
87 if (globalTracks == nullptr) {
88 LOG(error) << "'BmnGlobalTrack' branch was not found, please, check the structure of the DST file, exiting...";
89 return -5;
90 }
91
92 // assign TClonesArrays to branches with local segments of tracks in the detectors and their hits
93 // TClonesArray* gemTracks = nullptr;
94 // dataChain->SetBranchAddress("BmnGemTrack", &gemTracks);
95 // if (gemTracks == nullptr)
96 //{
97 // LOG(error)<<"'BmnGemTrack' branch was not found, please, check the structure of the DST file, exiting...";
98 // return -6;
99 //}
100 // TClonesArray* gemHits = nullptr;
101 // dataChain->SetBranchAddress("BmnGemStripHit", &gemHits);
102 // if (gemHits == nullptr)
103 //{
104 // LOG(error)<<"'BmnGemStripHit' branch was not found, please, check the structure of the DST file, exiting...";
105 // return -7;
106 //}
107
108 TString stsBranchName = "StsVector";
109 if (tracking == L1Tracking)
110 stsBranchName = "StsTrack";
111 TClonesArray* stsTracks = nullptr;
112 dataChain->SetBranchAddress(stsBranchName, &stsTracks);
113 if (stsTracks == nullptr) {
114 LOG(error) << "'StsTrack' branch was not found, please, check the structure of the DST file, exiting...";
115 return -8;
116 }
117 TClonesArray* stsHits = nullptr;
118 dataChain->SetBranchAddress("StsHit", &stsHits);
119 if (stsHits == nullptr) {
120 LOG(error) << "'StsHit' branch was not found, please, check the structure of the DST file, exiting...";
121 return -9;
122 }
123
124 TClonesArray* tof400Hits = nullptr;
125 dataChain->SetBranchAddress("BmnTof400Hit", &tof400Hits);
126 if (tof400Hits == nullptr) {
127 LOG(error) << "'BmnTof400Hit' branch was not found, please, check the structure of the DST file, exiting...";
128 return -10;
129 }
130
131 TClonesArray* tof700Hits = nullptr;
132 dataChain->SetBranchAddress("BmnTof700Hit", &tof700Hits);
133 if (tof700Hits == nullptr) {
134 LOG(error) << "'BmnTof700Hit' branch was not found, please, check the structure of the DST file, exiting...";
135 return -11;
136 }
137
138 TClonesArray* cscHits = nullptr;
139 dataChain->SetBranchAddress("BmnCSCHit", &cscHits);
140 if (cscHits == nullptr) {
141 LOG(error) << "'BmnCSCHit' branch was not found, please, check the structure of the DST file, exiting...";
142 return -12;
143 }
144
145 TClonesArray* dchTracks = nullptr;
146 dataChain->SetBranchAddress("BmnDchTrack", &dchTracks);
147 if (dchTracks == nullptr) {
148 LOG(warn)
149 << "'BmnDchTrack' branch was not found"; //, please, check the structure of the DST file, exiting...";
150 // return -13;
151 }
152
153 // and other necessary detector track segments and hits in a similar way...
154
155 // event loop
156 for (Int_t iEvent = 0; iEvent < dataChain->GetEntries(); iEvent++) {
157 LOG(info) << "Event# " << iEvent;
158
159 // Next Event
160 dataChain->GetEntry(iEvent);
161
162 // Getting DST event header
163 if (event_header) {
164 cout << "|||||||||||| DST EVENT SUMMARY |||||||||||||" << endl;
165 cout << "||\t\t\t\t\t ||" << endl;
166 cout << "|| Event number: " << event_header->GetEventId() << "\t\t ||" << endl;
167 cout << "|| Impact parameter: " << event_header->GetB() << " fm\t\t ||" << endl;
168 cout << "||\t\t\t\t\t ||" << endl;
169 cout << "||||||||||||||||||||||||||||||||||||||||||||" << endl;
170
171 // See $VMCWORKDIR/base/header/BmnEventHeader.h to get more ...
172 }
173
174 if (primaryVertex) {
175 LOG(info) << "VERTEX INFO (X:Y:Z) = "
176 << TString::Format("%.3f : %.3f : %.3f\n", primaryVertex->GetX(), primaryVertex->GetY(),
177 primaryVertex->GetZ());
178
179 // See $VMCWORKDIR/base/cbm/CbmVertex.h to get more ...
180 }
181
182 // Getting vertices in the event: 0 -- primary, 1 -- secondary
183 // for (Int_t iVertex = 0; iVertex < vertices->GetEntriesFast(); iVertex++) {
184 // BmnVertex* vertex = (BmnVertex*) vertices->UncheckedAt(iVertex);
185
186 // See $VMCWORKDIR/base/data/BmnVertex.h to get more ...
187 //}
188
189 // Getting "local" tracks, i.e. the segments of the global tracks in the detectors
190 for (Int_t iTrack = 0; iTrack < stsTracks->GetEntriesFast(); iTrack++) {
191 CbmStsTrack* track = (CbmStsTrack*)stsTracks->UncheckedAt(iTrack);
192
193 // See $VMCWORKDIR/base/cbm/CbmStsTrack.h to get more ...
194 }
195
196 // Getting global tracks and their corresponding components
197 for (Int_t iTrack = 0; iTrack < globalTracks->GetEntriesFast(); iTrack++) {
198 BmnGlobalTrack* track = (BmnGlobalTrack*)globalTracks->UncheckedAt(iTrack);
199
200 // Getting track params. predicted by Kalman filter ...
201 FairTrackParam* parFirst = track->GetParamFirst();
202 FairTrackParam* parLast = track->GetParamLast();
203
204 // See YOUR_FAIRROOT_INSTALATION/include/FairTrackParam.h to get more ...
205
206 // inner (STS) track of the global track: GetGemTrackIndex() is the index in the inner track branch
207 if (track->GetGemTrackIndex() != -1) {
208 CbmStsTrack* stsTr = (CbmStsTrack*)stsTracks->UncheckedAt(track->GetGemTrackIndex());
209
210 // Hits on STS track
211 for (Int_t iHit = 0; iHit < stsTr->GetNStsHits(); iHit++) {
212 CbmStsHit* hit = (CbmStsHit*)stsHits->UncheckedAt(stsTr->GetStsHitIndex(iHit));
213
214 // See $VMCWORKDIR/detectors/sts/CbmStsHit.h to get more ...
215 }
216 }
217
218 // TOF400 matched hit ...
219 if (track->GetTof1HitIndex() != -1) {
220 BmnTofHit* hit = (BmnTofHit*)tof400Hits->UncheckedAt(track->GetTof1HitIndex());
221
222 // See $VMCWORKDIR/bmnd/BmnTofHit.h to get more ...
223 }
224
225 // TOF700 matched hit ...
226 if (track->GetTof2HitIndex() != -1) {
227 BmnTofHit* hit = (BmnTofHit*)tof700Hits->UncheckedAt(track->GetTof2HitIndex());
228
229 // See $VMCWORKDIR/detectprs/tof/BmnTofHit.h to get more ...
230 }
231
232 // CSC matched hits ...
233 for (Int_t indHit : track->GetVectorCscHitIndices())
234 if (indHit != -1) {
235 BmnCSCHit* hit = (BmnCSCHit*)cscHits->UncheckedAt(indHit);
236
237 // See $VMCWORKDIR/detectors/csc/BmnCSCHit.h to get more ...
238 }
239
240 // DCH matched track
241 if (track->GetDchTrackIndex() != -1) {
242 BmnDchTrack* dchTrack = (BmnDchTrack*)dchTracks->UncheckedAt(track->GetDchTrackIndex());
243
244 // See $VMCWORKDIR/detectors/dch/BmnDchTrack.h to get more ...
245
246 FairTrackParam* parFirstDch = dchTrack->GetParamFirst();
247
248 // See YOUR_FAIRROOT_INSTALATION/include/FairTrackParam.h to get more ...
249 }
250 } // for (Int_t iTrack = 0; iTrack < globalTracks->GetEntriesFast(); iTrack++)
251 } // for (Int_t iEvent = 0; iEvent < out->GetEntries(); iEvent++)
252
253 return 0;
254}
int Int_t
double Double_t
enumTracking
@ L1Tracking
Definition readDst.C:12
@ VectorFinder
static FairField * GetDSTField(TString fileName, Double_t &fieldScale, Int_t &fieldType, TString *beam=nullptr, TString *target=nullptr, Double_t *beam_energy=nullptr, Int_t *beam_a=nullptr, Int_t *beam_z=nullptr, Int_t *target_a=nullptr, Int_t *target_z=nullptr)
static int CheckFileExist(TString &fileName, int iVerbose=0, EAccessMode mode=kFileExists)
BmnGlobalTrack.h.
Int_t GetTof2HitIndex() const
Int_t GetGemTrackIndex() const
Accessors.
Int_t GetTof1HitIndex() const
FairTrackParam * GetParamFirst()
Definition BmnTrack.h:63
FairTrackParam * GetParamLast()
Definition BmnTrack.h:65
Int_t GetNStsHits() const
Accessors.
Definition CbmStsTrack.h:60
Int_t GetStsHitIndex(Int_t iHit) const
Definition CbmStsTrack.h:62
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_t GetB()
Get impact parameter - b, fm.
UInt_t GetEventId()
Get run ID for this run.
TTimeStamp GetFinishTime()
Int_t GetTargetA()
TTimeStamp GetStartTime()
UInt_t GetRunId()
Get run number for this run.
Double_t GetFieldScale()
Int_t GetTargetZ()
Int_t GetBeamA()
Int_t GetBeamZ()
Float_t GetBeamEnergy()
UInt_t GetPeriodId()
Get period number for this run.
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 LoadTree(Long64_t entry) override
Long64_t GetEntries() const override
Int_t GetEntry(Long64_t entry=0, Int_t getall=0) override
T * Get(const char *namecycle)
Int_t GetEntriesFast() const
TObject * UncheckedAt(Int_t i) const
static TString Format(const char *fmt,...)
const char * AsString(const Option_t *option="") const
TFile * GetCurrentFile() const
int readDst(TString dstFilePath="", enumTracking tracking=VectorFinder)
Definition readDst.C:18