Project
Loading...
Searching...
No Matches
g4DetermineUnknownPdgProperties.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#include <iostream>
13#include <string>
14#include <fstream>
15#include <vector>
16
17#include "G4ParticleTable.hh"
18#include "G4IonTable.hh"
19
20#include "TGeant4.h"
21#include "TG4RunConfiguration.h"
22#include "TG4G3Units.h"
23
24#include "SimConfig/G4Params.h"
27
28void removeDuplicates(std::vector<int>& vec)
29{
30 // quick helper to erase duplicates from vectors
31 std::sort(vec.begin(), vec.end());
32 vec.erase(std::unique(vec.begin(), vec.end()), vec.end());
33}
34
35int main(int argc, char** argv)
36{
37 // Takes a single text file as input. Expect simply single column with PDGs to be searched.
38 if (argc != 2) {
39 std::cerr << "Exactly one argument required containing the PDGs to look up.\n";
40 return 1;
41 }
42
43 std::ifstream is{argv[1]};
44 if (!is.is_open()) {
45 std::cerr << "Cannot open " << argv[1] << "\n";
46 return 1;
47 }
48
49 // We use our O2 VMC setup to make sure we are in line with our physics definition.
50 // need a dummy VMC App
52 // setup G4 as we usually do
54 auto runConfiguration = new TG4RunConfiguration("geomRoot", physicsSetup);
55 auto vmc = new TGeant4("TGeant4", "The Geant4 Monte Carlo", runConfiguration);
56 // needs to be initialised to have particle and ion tables / physics entirely ready
57 vmc->Init();
58
59 // G4 ion table
60 auto g4IonTable = G4ParticleTable::GetParticleTable()->GetIonTable();
61 // a new instance of TDatabasePDG to be filled
62 auto pdgDB = o2::O2DatabasePDG::Instance();
63
64 // Keep some basic stats for final output
65 // Use these maps instead of vectors to avoid double counting - no need to to sort and .
66 std::vector<int> stillUnknown;
67 std::vector<int> checkedIons;
68 std::vector<int> addedIons;
69
70 std::string line;
71 while (std::getline(is, line)) {
72 if (line.empty()) {
73 continue;
74 }
75
76 // Save the PDG...
77 auto pdg = std::stoi(line);
78 checkedIons.push_back(pdg);
79 // ...and since we cannot look for isomeres, set the last digit to 0.
80 // In that case we will get at least the approximate PDG properties if found in the G4 ion table.
81 auto pdgToLookFor = pdg / 10 * 10;
82 auto particle = g4IonTable->GetIon(pdgToLookFor);
83 if (!particle) {
84 stillUnknown.push_back(pdg);
85 continue;
86 }
87 if (pdgDB->GetParticle(pdg) || pdgDB->GetParticle(pdgToLookFor)) {
88 // here we can look if we have it already
89 continue;
90 }
91 auto name = particle->GetParticleName();
92 // add only the ground state for now. If needed, we can take care of isomers later on
93 pdgDB->AddParticle(name.c_str(), name.c_str(), particle->GetPDGMass() / TG4G3Units::Energy(), particle->GetPDGStable(), particle->GetPDGWidth() / TG4G3Units::Energy(), particle->GetPDGCharge() * 3, "Ion", pdgToLookFor);
94 addedIons.push_back(pdgToLookFor);
95 }
96 is.close();
97
98 // remove potential duplicates that came from the input
99 removeDuplicates(stillUnknown);
100 removeDuplicates(checkedIons);
101 removeDuplicates(addedIons);
102
103 std::cout << "Ran over " << checkedIons.size() << " different PDGs"
104 << "\nout of which " << addedIons.size() << " ground states were added."
105 << "\nStill unkown (probably originating from event generator) " << stillUnknown.size() << "\n";
106 for (auto& it : stillUnknown) {
107 std::cout << " " << it << "\n";
108 }
109
110 std::string pdgTableOut{"newPDGTable.dat"};
111 pdgDB->WritePDGTable(pdgTableOut.c_str());
112 std::cout << "New PDG table written to " << pdgTableOut << "\n";
113
114 return 0;
115}
static TDatabasePDG * Instance()
void removeDuplicates(std::vector< int > &vec)
GLuint const GLchar * name
Definition glcorearb.h:781
std::string const & getPhysicsConfigString() const
Definition G4Params.cxx:32
#define main
std::vector< o2::ctf::BufferType > vec