Skip to content

Commit 3fb6e4d

Browse files
committed
Extend simulation example: Show access to MCKinematics
1 parent 38ec29f commit 3fb6e4d

2 files changed

Lines changed: 90 additions & 3 deletions

File tree

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/// Toy example of how to use MClabels and how to read
2+
/// MC tracks using a digitization context and labels
3+
4+
void exampleMCTrackAnalysis(const char* itsdigitfilename) {
5+
// initialize the kinematics reader
6+
o2::steer::MCKinematicsReader reader("collisioncontext.root");
7+
8+
TFile digitfile(itsdigitfilename,"OPEN");
9+
// tree
10+
auto tree = (TTree*)digitfile.Get("o2sim");
11+
if (!tree) {
12+
return;
13+
}
14+
15+
// digitbranch
16+
auto dbr = tree->GetBranch("ITSDigit");
17+
if (!dbr) {
18+
return;
19+
}
20+
21+
// read digits
22+
std::vector<o2::itsmft::Digit> *digits = nullptr;
23+
dbr->SetAddress(&digits);
24+
dbr->GetEntry(0);
25+
if (!digits) {
26+
return;
27+
}
28+
29+
// read the labels
30+
o2::dataformats::MCTruthContainer<o2::MCCompLabel> *labelcontainer = nullptr;
31+
auto labelbr = tree->GetBranch("ITSDigitMCTruth");
32+
if (!labelbr) {
33+
return;
34+
}
35+
36+
labelbr->SetAddress(&labelcontainer);
37+
labelbr->GetEntry(0);
38+
if (!labelcontainer) {
39+
return;
40+
}
41+
42+
// MCTracks: exemplary access and analysis
43+
int MCdigits = 0;
44+
int purenoisedigits = 0;
45+
int secondarydigits = 0;
46+
int primarydigits = 0;
47+
for (int pos = 0; pos < digits->size(); ++pos) {
48+
auto& digit = (*digits)[pos];
49+
bool noisecontrib = false;
50+
bool MCcontrib = false;
51+
bool primarycontrib = false;
52+
bool secondarycontrib = false;
53+
for (auto& label : labelcontainer->getLabels(pos)) {
54+
if (!label.isNoise()) {
55+
auto track = reader.getTrack(label);
56+
if (track->isSecondary()) {
57+
secondarycontrib = true;
58+
}
59+
else {
60+
primarycontrib = true;
61+
}
62+
MCcontrib = true;
63+
}
64+
else {
65+
noisecontrib = true;
66+
}
67+
}
68+
if (noisecontrib && !MCcontrib) {
69+
purenoisedigits++;
70+
}
71+
if (MCcontrib) {
72+
MCdigits++;
73+
}
74+
if (secondarycontrib) {
75+
secondarydigits++;
76+
}
77+
if (primarycontrib) {
78+
primarydigits++;
79+
}
80+
}
81+
// print a summary
82+
std::cout << "Total digits: " << digits->size() << "\n";
83+
std::cout << "Pure noise digits: " << purenoisedigits << "\n";
84+
std::cout << "MC contrib digits: " << MCdigits << "\n";
85+
std::cout << "Digits with primary track contrib: " << primarydigits << "\n";
86+
std::cout << "Digits with secondary track contrib: " << secondarydigits << "\n";
87+
}

run/SimExamples/Jet_Embedding_Pythia8/run.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ set -x
1313
# PART a)
1414
NBGR=5
1515
o2-sim -j 20 -n ${NBGR} -g pythia8hi -m PIPE ITS TPC -o bkg --configKeyValue \
16-
"Diamond.position[2]=0.1;Diamond.width[2]=0.02"
16+
"Diamond.position[2]=0.1;Diamond.width[2]=0.05"
1717

1818
# PART b)
1919
# produce hard jets using a pythia8 configuration given in a file 'pythia8_hard.cfg'; event selection is done by a user hook specified
@@ -26,5 +26,5 @@ o2-sim -j 20 -n ${NSGN} -g pythia8 -m PIPE ITS TPC --configKeyValue "Pythia8.con
2626
o2-sim-digitizer-workflow --sims bkg,sgn --tpc-lanes 4 -b --run
2727

2828
# PART d)
29-
# Simple analysis: read ITS digits and analyse some properties of MC tracks leaving a digit
30-
# TOBEDONE
29+
# Simple analysis: read ITS digits and analyse some properties of digits and MC tracks leaving a digit
30+
root -q -b -l exampleMCTrackAnalysis.macro("itsdigits.root")

0 commit comments

Comments
 (0)