forked from AliceO2Group/O2DPG
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeneratorLFStrangenessInJetsTriggered_gap4.C
More file actions
58 lines (53 loc) · 1.66 KB
/
GeneratorLFStrangenessInJetsTriggered_gap4.C
File metadata and controls
58 lines (53 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
int External()
{
std::string path{"o2sim_Kine.root"};
int numberOfInjectedSignalsPerEvent{1};
std::vector<int> injectedPDGs = {
3334,
-3334,
3312,
-3312};
auto nInjection = injectedPDGs.size();
TFile file(path.c_str(), "READ");
if (file.IsZombie()) {
std::cerr << "Cannot open ROOT file " << path << "\n";
return 1;
}
auto tree = (TTree*)file.Get("o2sim");
if (!tree) {
std::cerr << "Cannot find tree o2sim in file " << path << "\n";
return 1;
}
std::vector<o2::MCTrack>* tracks{};
tree->SetBranchAddress("MCTrack", &tracks);
std::vector<int> nSignal;
for (int i = 0; i < nInjection; i++) {
nSignal.push_back(0);
}
auto nEvents = tree->GetEntries();
for (int i = 0; i < nEvents; i++) {
auto check = tree->GetEntry(i);
for (int idxMCTrack = 0; idxMCTrack < tracks->size(); ++idxMCTrack) {
auto track = tracks->at(idxMCTrack);
auto pdg = track.GetPdgCode();
auto it = std::find(injectedPDGs.begin(), injectedPDGs.end(), pdg);
int index = std::distance(injectedPDGs.begin(), it); // index of injected PDG
if (it != injectedPDGs.end()) // found
{
// count signal PDG
nSignal[index]++;
}
}
}
std::cout << "--------------------------------\n";
std::cout << "# Events: " << nEvents << "\n";
for (int i = 0; i < nInjection; i++) {
std::cout << "# Injected nuclei \n";
std::cout << injectedPDGs[i] << ": " << nSignal[i] << "\n";
if (nSignal[i] == 0) {
std::cerr << "No generated: " << injectedPDGs[i] << "\n";
return 1; // At least one of the injected particles should be generated
}
}
return 0;
}