BmnRoot
26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Toggle main menu visibility
Loading...
Searching...
No Matches
miniDST.C
Go to the documentation of this file.
1
R__ADD_INCLUDE_PATH
($VMCWORKDIR)
2
#include <services/json.hpp>
3
4
using
json =
nlohmann::json
;
5
using namespace
ROOT
;
6
7
int
mdst_converter
(
TString
inFilePath,
8
TString
outFilePath =
""
,
9
TString
configFileName =
"mdst_config.json"
,
10
TString
outFormat =
"root"
,
11
Int_t
threadsNumber = -1)
12
{
13
TStopwatch
timer;
14
timer.
Start
();
15
16
// form output file path if it is empty or a directory
17
gSystem
->ExpandPathName(inFilePath);
18
if
(outFilePath ==
""
) {
19
outFilePath = inFilePath;
20
outFilePath.
ReplaceAll
(
"dst"
,
"mdst"
);
21
}
else
22
gSystem
->ExpandPathName(outFilePath);
23
if
(
BmnFunctionSet::isDirectory
(outFilePath))
24
outFilePath =
gSystem
->ConcatFileName(
25
outFilePath, ((
TString
)
gSystem
->BaseName(inFilePath.
Data
())).ReplaceAll(
"dst"
,
"mdst"
));
26
if
(outFilePath == inFilePath) {
27
cout <<
"[ERROR] Output file path is not set correctly: "
<< outFilePath << endl;
28
return
-1;
29
}
30
31
// read configuration variables
32
configFileName =
gSystem
->ExpandPathName(
"$VMCWORKDIR/config/"
+ configFileName);
33
ifstream configFile(configFileName.Data());
34
if
(!configFile.is_open()) {
35
cout <<
"[ERROR] Cannot open config file "
<< configFileName << endl;
36
return
-2;
37
}
38
json config;
39
try
{
40
configFile >> config;
41
}
catch
(
const
json::parse_error& ex) {
42
cout <<
"[ERROR] Wrong config file format: "
<< ex.what() << endl;
43
return
-3;
44
}
45
Int_t
minNTracks = config.value(
"minNTracks"
, 2);
46
Double_t
minZ = config.value(
"minZ"
, -
TMath::Infinity
());
47
Double_t
maxZ = config.value(
"maxZ"
,
TMath::Infinity
());
48
vector<string> excludedBranches = config.value(
"excludedBranches"
, vector<string>());
49
50
if
(outFormat !=
"root"
) {
51
cout <<
"[ERROR] Only \"root\" format is supported at the moment"
<< endl;
52
return
-4;
53
}
54
55
if
(threadsNumber >= 0)
56
ROOT::EnableImplicitMT
(threadsNumber);
57
58
TFile
* inFile =
TFile::Open
(inFilePath.
Data
());
59
if
(inFile ==
nullptr
) {
60
cout <<
"[ERROR] Cannot open input DST file "
<< inFilePath << endl;
61
return
-5;
62
}
63
TTree
* inTree = (
TTree
*)inFile->
Get
(
"bmndata"
);
64
if
(!inTree) {
65
cout <<
"[ERROR] Input file "
<< inFilePath <<
" does not contain \"bmndata\" tree"
<< endl;
66
return
-6;
67
}
68
69
// exclude branches
70
vector<string> branches;
71
for
(
TObject
* branch : *inTree->
GetListOfBranches
()) {
72
string
branchName = ((
TBranch
*)branch)->GetName();
73
if
(find(excludedBranches.begin(), excludedBranches.end(), branchName) == excludedBranches.end())
74
branches.push_back(branchName);
75
}
76
77
// lamda to filter events
78
auto
filter = [minNTracks, minZ, maxZ](
const
TClonesArray
& vertices) {
79
BmnVertex
* vtx =
static_cast<
BmnVertex
*
>
(vertices.UncheckedAt(0));
80
return
(vtx->
GetZ
() > minZ && vtx->
GetZ
() < maxZ && vtx->
GetNTracks
() >= minNTracks);
81
};
82
83
RDataFrame
data(*inTree);
84
auto
eventsCountBeforeFilter = data.
Count
();
85
auto
filteredData = data.
Filter
(filter, {
"BmnVertex"
});
86
auto
eventsCountAfterFilter = filteredData.Count();
87
88
if
(
BmnFunctionSet::CreateDirectoryTree
(outFilePath, 1) < 0) {
89
cout <<
"[ERROR] Output file "
<< outFilePath <<
" cannot be created"
<< endl;
90
return
-7;
91
}
92
filteredData.Snapshot(
"bmndata"
, outFilePath.Data(), branches);
93
94
cout <<
"Event number before filtering: "
<< *eventsCountBeforeFilter << endl;
95
cout <<
"Event number after filtering: "
<< *eventsCountAfterFilter << endl;
96
delete
inFile;
97
98
timer.
Stop
();
99
Double_t
rtime = timer.
RealTime
(), ctime = timer.
CpuTime
();
100
printf(
"RealTime=%f seconds, CpuTime=%f seconds\n"
, rtime, ctime);
101
return
0;
102
}
Int_t
int Int_t
Double_t
double Double_t
R__ADD_INCLUDE_PATH
#define R__ADD_INCLUDE_PATH(PATH)
gSystem
R__EXTERN TSystem * gSystem
BmnFunctionSet::CreateDirectoryTree
static int CreateDirectoryTree(TString &fileName, int iVerbose=0, EAccessMode mode=kWritePermission)
Definition
BmnFunctionSet.cxx:65
BmnFunctionSet::isDirectory
static bool isDirectory(TString path)
Definition
BmnFunctionSet.cxx:589
BmnVertex
Definition
BmnVertex.h:22
BmnVertex::GetNTracks
Int_t GetNTracks() const
Definition
BmnVertex.h:60
BmnVertex::GetZ
Double_t GetZ() const
Definition
BmnVertex.h:57
ROOT::RDF::RInterface::Count
RResultPtr< ULong64_t > Count()
ROOT::RDF::RInterface::Filter
RInterface< RDFDetail::RFilter< F, Proxied >, DS_t > Filter(F f, const ColumnNames_t &columns={}, std::string_view name="")
ROOT::RDataFrame
TBranch
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)
TObject
TStopwatch
TStopwatch::RealTime
Double_t RealTime()
TStopwatch::Start
void Start(Bool_t reset=kTRUE)
TStopwatch::CpuTime
Double_t CpuTime()
TStopwatch::Stop
void Stop()
TString
TString::Data
const char * Data() const
TString::ReplaceAll
TString & ReplaceAll(const char *s1, const char *s2)
TTree
TTree::GetListOfBranches
virtual TObjArray * GetListOfBranches()
mdst_converter
int mdst_converter(TString inFilePath, TString outFilePath="", TString configFileName="mdst_config.json", TString outFormat="root", Int_t threadsNumber=-1)
Definition
miniDST.C:7
ROOT
ROOT::EnableImplicitMT
void EnableImplicitMT(ROOT::EIMTConfig config)
TMath::Infinity
Double_t Infinity()
nlohmann::json
basic_json<> json
default specialization
Definition
json.hpp:3365
install
macro
run
miniDST.C
Generated on
for BmnRoot by
1.17.0