Skip to content

Commit eca0412

Browse files
authored
Update GeneratorHF_Non_Hfe.C
Remove quark level information
1 parent 24328aa commit eca0412

File tree

1 file changed

+55
-145
lines changed

1 file changed

+55
-145
lines changed
Lines changed: 55 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -1,158 +1,68 @@
1-
int External() {
2-
std::string path{"o2sim_Kine.root"};
3-
4-
int checkPdgDecayElectron = 11;
5-
int checkPdgQuarkOne = 1; // d quark
6-
int checkPdgQuarkTwo = 2; // u quark
7-
int checkPdgQuarkThree = 3; // s quark
8-
float ratioTrigger = 1. / 5; // one event triggered out of 5
1+
#include <TFile.h>
2+
#include <TTree.h>
3+
#include <vector>
4+
#include <iostream>
5+
#include <cmath>
6+
#include "DataFormats/MCTrack.h"
97

8+
int External() {
9+
std::string path{"o2sim_Kine.root"};
1010

11-
TFile file(path.c_str(), "READ");
12-
if (file.IsZombie()) {
13-
std::cerr << "Cannot open ROOT file" << path << "\n";
14-
return 1;
15-
}
16-
17-
auto tree = (TTree *)file.Get("o2sim");
18-
if (!tree) {
19-
std::cerr << "Cannot find tree o2sim in file" << path << "\n";
20-
return 1;
21-
}
11+
const int pdgPi0 = 111;
12+
const int pdgEta = 221;
13+
const double yMin = -1.5;
14+
const double yMax = 1.5;
15+
const int minNb = 1;
2216

23-
std::vector<o2::MCTrack> *tracks{};
24-
tree->SetBranchAddress("MCTrack", &tracks);
25-
o2::dataformats::MCEventHeader *eventHeader = nullptr;
26-
tree->SetBranchAddress("MCEventHeader.", &eventHeader);
17+
TFile file(path.c_str(), "READ");
18+
if (file.IsZombie()) {
19+
std::cerr << "Cannot open ROOT file " << path << "\n";
20+
return 1;
21+
}
2722

28-
int nEventsMB{}, nEventsInjOne{}, nEventsInjTwo{}, nEventsInjThree{};
29-
int nQuarksOne{}, nQuarksTwo{}, nQuarksThree{};
30-
int nElectrons{};
31-
auto nEvents = tree->GetEntries();
23+
auto tree = (TTree*)file.Get("o2sim");
24+
if (!tree) {
25+
std::cerr << "Cannot find tree o2sim\n";
26+
return 1;
27+
}
3228

33-
for (int i = 0; i < nEvents; i++) {
34-
tree->GetEntry(i);
29+
std::vector<o2::MCTrack>* tracks{};
30+
tree->SetBranchAddress("MCTrack", &tracks);
3531

36-
// check subgenerator information
37-
if (eventHeader->hasInfo(o2::mcgenid::GeneratorProperty::SUBGENERATORID)) {
38-
bool isValid = false;
39-
int subGeneratorId = eventHeader->getInfo<int>(
40-
o2::mcgenid::GeneratorProperty::SUBGENERATORID, isValid);
41-
if (subGeneratorId == 0) {
42-
nEventsMB++;
43-
} else if (subGeneratorId == checkPdgQuarkOne) {
44-
nEventsInjOne++;
45-
} else if (subGeneratorId == checkPdgQuarkTwo) {
46-
nEventsInjTwo++;
47-
} else if (subGeneratorId == checkPdgQuarkThree) {
48-
nEventsInjThree++;
49-
}
50-
} // if event header
32+
int nEvents = tree->GetEntries();
33+
int nAccepted = 0;
34+
int totalPi0 = 0, totalEta = 0;
5135

52-
int nelectronsev = 0;
36+
for (int i = 0; i < nEvents; ++i) {
37+
tree->GetEntry(i);
5338

54-
for (auto &track : *tracks) {
55-
auto pdg = track.GetPdgCode();
56-
if (std::abs(pdg) == checkPdgQuarkOne) {
57-
nQuarksOne++;
58-
continue;
59-
}
60-
if (std::abs(pdg) == checkPdgQuarkTwo) {
61-
nQuarksTwo++;
62-
continue;
63-
}
64-
if (std::abs(pdg) == checkPdgQuarkThree) {
65-
nQuarksThree++;
66-
continue;
67-
}
39+
int count = 0;
40+
for (auto& track : *tracks) {
41+
int pdg = std::abs(track.GetPdgCode());
42+
double y = track.GetRapidity();
6843

44+
if ((pdg == pdgPi0 || pdg == pdgEta) && y >= yMin && y <= yMax) {
45+
count++;
46+
if (pdg == pdgPi0) totalPi0++;
47+
if (pdg == pdgEta) totalEta++;
48+
}
49+
}
6950

70-
auto y = track.GetRapidity();
71-
if (std::abs(pdg) == checkPdgDecayElectron) {
72-
int igmother = track.getMotherTrackId();
73-
auto gmTrack = (*tracks)[igmother];
74-
int gmpdg = gmTrack.GetPdgCode();
75-
if (int(std::abs(gmpdg) / 100.) == 1 ||
76-
int(std::abs(gmpdg) / 1000.) == 1 ||
77-
int(std::abs(gmpdg) / 100.) == 2 ||
78-
int(std::abs(gmpdg) / 1000.) == 2 ||
79-
int(std::abs(gmpdg) / 100.) == 3 ||
80-
int(std::abs(gmpdg) / 1000.) == 3) {
81-
nElectrons++;
82-
nelectronsev++;
83-
} // gmpdg
84-
} // pdgdecay
85-
} // loop track
86-
// std::cout << "#electrons per event: " << nelectronsev << "\n";
87-
}
51+
if (count < minNb) {
52+
std::cerr << " Trigger violation in event " << i
53+
<< " (found " << count << " π0/η in rapidity window)\n";
54+
return 1;
55+
}
8856

89-
std::cout << "--------------------------------\n";
90-
std::cout << "# Events: " << nEvents << "\n";
91-
std::cout << "# MB events: " << nEventsMB << "\n";
92-
std::cout << Form("# events injected with %d quark pair: ", checkPdgQuarkOne)
93-
<< nEventsInjOne << "\n";
94-
std::cout << Form("# events injected with %d quark pair: ", checkPdgQuarkTwo)
95-
<< nEventsInjTwo << "\n";
96-
std::cout << Form("# events injected with %d quark pair: ", checkPdgQuarkThree)
97-
<< nEventsInjThree << "\n";
98-
std::cout << Form("# %d (anti)quarks: ", checkPdgQuarkOne) << nQuarksOne
99-
<< "\n";
100-
std::cout << Form("# %d (anti)quarks: ", checkPdgQuarkTwo) << nQuarksTwo
101-
<< "\n";
102-
std::cout << Form("# %d (anti)quarks: ", checkPdgQuarkThree) << nQuarksThree
103-
<< "\n";
57+
nAccepted++;
58+
}
10459

105-
if (nEventsMB < nEvents * (1 - ratioTrigger) * 0.90 ||
106-
nEventsMB > nEvents * (1 - ratioTrigger) *
107-
1.1) { // we put some tolerance since the number of
108-
// generated events is small
109-
std::cerr << "Number of generated MB events different than expected\n";
110-
return 1;
111-
}
112-
constexpr float nInjectedSpecies = 3.f;
113-
if (nEventsInjOne < nEvents * ratioTrigger * 1.0/nInjectedSpecies * 0.90 ||
114-
nEventsInjOne > nEvents * ratioTrigger * 1.0/nInjectedSpecies * 1.1) {
115-
std::cerr << "Number of generated events injected with " << checkPdgQuarkOne
116-
<< " different than expected\n";
117-
return 1;
118-
}
119-
if (nEventsInjTwo < nEvents * ratioTrigger * 1.0/nInjectedSpecies * 0.90 ||
120-
nEventsInjTwo > nEvents * ratioTrigger * 1.0/nInjectedSpecies * 1.1) {
121-
std::cerr << "Number of generated events injected with " << checkPdgQuarkTwo
122-
<< " different than expected\n";
123-
return 1;
124-
}
125-
if (nEventsInjThree < nEvents * ratioTrigger * 1.0/nInjectedSpecies * 0.90 ||
126-
nEventsInjThree > nEvents * ratioTrigger * 1.0/nInjectedSpecies * 1.1) {
127-
std::cerr << "Number of generated events injected with " << checkPdgQuarkThree
128-
<< " different than expected\n";
129-
return 1;
130-
}
131-
if (nQuarksOne <
132-
nEvents *
133-
ratioTrigger) { // we expect anyway more because the same quark is
134-
// repeated several time, after each gluon radiation
135-
std::cerr << "Number of generated (anti)quarks " << checkPdgQuarkOne
136-
<< " lower than expected\n";
137-
return 1;
138-
}
139-
if (nQuarksTwo <
140-
nEvents *
141-
ratioTrigger) { // we expect anyway more because the same quark is
142-
// repeated several time, after each gluon radiation
143-
std::cerr << "Number of generated (anti)quarks " << checkPdgQuarkTwo
144-
<< " lower than expected\n";
145-
return 1;
146-
}
147-
if (nQuarksThree <
148-
nEvents *
149-
ratioTrigger) { // we expect anyway more because the same quark is
150-
// repeated several time, after each gluon radiation
151-
std::cerr << "Number of generated (anti)quarks " << checkPdgQuarkThree
152-
<< " lower than expected\n";
153-
return 1;
154-
}
155-
std::cout << "#electrons: " << nElectrons << "\n";
60+
std::cout << "--------------------------------------\n";
61+
std::cout << "Trigger test: π0/η within rapidity window\n";
62+
std::cout << "Events tested: " << nEvents << "\n";
63+
std::cout << "Events accepted: " << nAccepted << "\n";
64+
std::cout << "# π0: " << totalPi0 << ", # η: " << totalEta << "\n";
65+
std::cout << "Trigger test PASSED\n";
15666

157-
return 0;
158-
} // external
67+
return 0;
68+
}

0 commit comments

Comments
 (0)