BmnRoot
26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Toggle main menu visibility
Loading...
Searching...
No Matches
read_digi_example.C
Go to the documentation of this file.
1
// read_digi_example.C: loop over the events of a DIGI file and print the event header, the GEM digits per station,
2
// the FHCal signal and, for simulated files, the MC particle of the first GEM digit
3
// works with simulated and experimental DIGI files: the branch names are chosen by the type of the file
4
void
read_digi_example
(
TString
digiFileName =
"bmnsim.root"
,
Int_t
nPrint = 3)
5
{
6
TFile
* file =
TFile::Open
(digiFileName);
7
TTree
* tree = (
TTree
*)file->
Get
(
"bmndata"
);
8
Bool_t
isSimulation = (tree->
GetBranch
(
"MCTrack"
) !=
nullptr
);
9
10
// run information is stored only in experimental files
11
DigiRunHeader
* runHeader = (
DigiRunHeader
*)file->
Get
(
"DigiRunHeader"
);
12
if
(runHeader)
13
cout <<
"Period "
<< runHeader->
GetPeriodId
() <<
", run "
<< runHeader->
GetRunId
() << endl;
14
15
// the same detector data are stored in branches with different names in simulated and experimental files
16
TString
gemName = isSimulation ?
"BmnGemStripDigit"
:
"GEM"
;
17
TString
fhcalName = isSimulation ?
"FHCalDigit"
:
"FHCalDigi"
;
18
vector<TString> branches = {gemName, fhcalName};
19
if
(isSimulation)
20
branches.insert(branches.end(), {
"MCEventHeader."
,
"BmnGemStripDigitMatch"
,
"StsPoint"
,
"MCTrack"
});
21
else
22
branches.push_back(
"BmnEventHeader."
);
23
tree->
SetBranchStatus
(
"*"
, 0);
// read only the needed branches
24
for
(
auto
& name : branches)
25
tree->
SetBranchStatus
(name +
"*"
, 1);
26
27
TClonesArray
*gemDigits =
nullptr
, *fhcalDigits =
nullptr
;
28
tree->
SetBranchAddress
(gemName, &gemDigits);
29
tree->
SetBranchAddress
(fhcalName, &fhcalDigits);
30
BmnEventHeader
* eventHeader =
nullptr
;
// experimental files
31
FairMCEventHeader
* mcHeader =
nullptr
;
// simulated files
32
TClonesArray
*gemMatches =
nullptr
, *gemPoints =
nullptr
, *mcTracks =
nullptr
;
33
if
(isSimulation) {
34
tree->
SetBranchAddress
(
"MCEventHeader."
, &mcHeader);
35
tree->
SetBranchAddress
(
"BmnGemStripDigitMatch"
, &gemMatches);
36
tree->
SetBranchAddress
(
"StsPoint"
, &gemPoints);
// MC points of the GEM detectors
37
tree->
SetBranchAddress
(
"MCTrack"
, &mcTracks);
38
}
else
39
tree->
SetBranchAddress
(
"BmnEventHeader."
, &eventHeader);
40
41
for
(
Long64_t
iEvent = 0; iEvent <
TMath::Min
(tree->
GetEntries
(), (
Long64_t
)nPrint); iEvent++) {
42
tree->
GetEntry
(iEvent);
43
if
(isSimulation)
44
printf(
"Event %u (b = %.1f fm):"
, mcHeader->GetEventID(), mcHeader->GetB());
45
else
46
printf(
"Event %u (%s):"
, eventHeader->
GetEventId
(), eventHeader->
GetEventTimeTS
().
AsString
(
"s"
));
47
48
// GEM: number of strip digits per station
49
map<Int_t, Int_t> nGemDigits;
50
for
(
Int_t
i
= 0;
i
< gemDigits->
GetEntriesFast
();
i
++)
51
nGemDigits[((
BmnStripDigit
*)gemDigits->
UncheckedAt
(
i
))->GetStation()]++;
52
printf(
" GEM digits per station:"
);
53
for
(
auto
& [station,
n
] : nGemDigits)
54
printf(
" %d"
,
n
);
55
56
// FHCal: the digit classes of both file types derive from BmnFHCalDigit
57
Double_t
fhcalSignal = 0;
58
for
(
Int_t
i
= 0;
i
< fhcalDigits->GetEntriesFast();
i
++)
59
fhcalSignal += ((
BmnFHCalDigit
*)fhcalDigits->UncheckedAt(
i
))->GetSignal();
60
printf(
"; FHCal: %d digits, total signal %.1f"
, fhcalDigits->GetEntriesFast(), fhcalSignal);
61
62
// simulated files: MC particle with the largest contribution to the first GEM digit
63
if
(isSimulation && gemMatches->
GetEntriesFast
() > 0) {
64
BmnMatch
*
match
= (
BmnMatch
*)gemMatches->
UncheckedAt
(0);
65
if
(
match
->GetNofLinks() > 0) {
66
FairMCPoint
* point = (
FairMCPoint
*)gemPoints->UncheckedAt(
match
->GetMatchedLink().GetIndex());
67
CbmMCTrack
* track = (
CbmMCTrack
*)mcTracks->UncheckedAt(point->GetTrackID());
68
printf(
"; first GEM digit: PDG %d"
, track->
GetPdgCode
());
69
}
70
}
71
printf(
"\n"
);
72
}
73
}
i
int i
Definition
P4_F32vec4.h:22
Bool_t
bool Bool_t
Int_t
int Int_t
Double_t
double Double_t
Long64_t
long long Long64_t
BmnEventHeader
Definition
BmnEventHeader.h:24
BmnEventHeader::GetEventId
UInt_t GetEventId()
Get the event ID for this event.
Definition
BmnEventHeader.h:89
BmnEventHeader::GetEventTimeTS
TTimeStamp GetEventTimeTS()
Get the time for this event.
Definition
BmnEventHeader.h:95
BmnFHCalDigit
Definition
BmnFHCalDigit.h:14
BmnMatch
Definition
BmnMatch.h:25
BmnStripDigit
Class BmnStripDigit Base class for strip detector digits.
Definition
BmnStripDigit.h:14
CbmMCTrack
CbmMCTrack.h.
Definition
CbmMCTrack.h:26
CbmMCTrack::GetPdgCode
Int_t GetPdgCode() const
Accessors.
Definition
CbmMCTrack.h:56
DigiRunHeader
Definition
DigiRunHeader.h:21
DigiRunHeader::GetPeriodId
uint64_t GetPeriodId()
Get the period ID for this run.
Definition
DigiRunHeader.h:75
DigiRunHeader::GetRunId
uint64_t GetRunId()
Get the run ID.
Definition
DigiRunHeader.h:77
FairMCEventHeader
FairMCPoint
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
TTimeStamp::AsString
const char * AsString(const Option_t *option="") const
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)
read_digi_example
void read_digi_example(TString digiFileName="bmnsim.root", Int_t nPrint=3)
Definition
read_digi_example.C:4
n
*brief user defined string literal for JSON values *sa std::size_t n
Definition
json.hpp:20362
TMath::Min
Double_t Min(Double_t a, Double_t b)
match
Definition
BmnMwpcTrackFinder.cxx:27
install
services
format_docs
digi
read_digi_example.C
Generated on
for BmnRoot by
1.17.0