Project
Loading...
Searching...
No Matches
nist_export_all.cxx
Go to the documentation of this file.
1// Copyright 2019-2026 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.
13
14#include <fstream>
15#include <iostream>
16#include <iomanip>
17#include <string>
18#include <vector>
19#include <algorithm>
20
21// Geant4
22#include "G4NistManager.hh"
23#include "G4Material.hh"
24#include "G4Element.hh"
25#include "G4SystemOfUnits.hh"
26
27static std::string json_escape(const std::string& s)
28{
29 std::string out;
30 out.reserve(s.size() + 8);
31 for (char c : s) {
32 switch (c) {
33 case '\\':
34 out += "\\\\";
35 break;
36 case '"':
37 out += "\\\"";
38 break;
39 case '\n':
40 out += "\\n";
41 break;
42 case '\r':
43 out += "\\r";
44 break;
45 case '\t':
46 out += "\\t";
47 break;
48 default:
49 out += c;
50 break;
51 }
52 }
53 return out;
54}
55
56int main(int argc, char** argv)
57{
58 if (argc < 2) {
59 std::cerr << "Usage:\n " << argv[0] << " out.json\n";
60 return 2;
61 }
62
63 const std::string out_json = argv[1];
64
65 auto* nist = G4NistManager::Instance();
66
67 // This returns all known NIST material names.
68 std::vector<G4String> names = nist->GetNistMaterialNames();
69 std::sort(names.begin(), names.end());
70
71 std::ofstream out(out_json);
72 if (!out) {
73 std::cerr << "Cannot write: " << out_json << "\n";
74 return 2;
75 }
76
77 out << std::fixed << std::setprecision(10);
78 out << "{\n"
79 << " \"schema\": \"g4_nist_export_v1\",\n"
80 << " \"count_requested\": " << names.size() << ",\n"
81 << " \"materials\": {\n";
82
83 bool first_mat = true;
84 size_t built_ok = 0;
85 size_t built_fail = 0;
86
87 for (const auto& g4name : names) {
88 // Build the material (some may fail depending on Geant4 build/config).
89 G4Material* mat = nist->FindOrBuildMaterial(g4name, /*warning=*/false, /*isotopes=*/false);
90 if (!mat) {
91 ++built_fail;
92 continue;
93 }
94 ++built_ok;
95
96 const std::string name = g4name; // convert G4String -> std::string
97
98 // Export in convenient units
99 const double density_g_cm3 = mat->GetDensity() / (g / cm3);
100 const double radlen_cm = mat->GetRadlen() / cm;
101 const double intlen_cm = mat->GetNuclearInterLength() / cm;
102
103 const size_t ne = mat->GetNumberOfElements();
104 const auto* elems = mat->GetElementVector();
105 const auto* fracs = mat->GetFractionVector(); // mass fractions (nullptr for some edge cases)
106
107 if (!first_mat)
108 out << ",\n";
109 first_mat = false;
110
111 out << " \"" << json_escape(name) << "\": {\n";
112 out << " \"name\": \"" << json_escape(name) << "\",\n";
113 out << " \"density_g_cm3\": " << density_g_cm3 << ",\n";
114 out << " \"radlen_cm\": " << radlen_cm << ",\n";
115 out << " \"intlen_cm\": " << intlen_cm << ",\n";
116 out << " \"elements\": [\n";
117
118 for (size_t i = 0; i < ne; ++i) {
119 const G4Element* el = (*elems)[i];
120 const int Z = static_cast<int>(el->GetZ());
121 const double A_g_mol = el->GetA() / (g / mole);
122 const double w = fracs ? fracs[i] : 0.0;
123
124 out << " {"
125 << "\"symbol\": \"" << json_escape(el->GetSymbol()) << "\", "
126 << "\"Z\": " << Z << ", "
127 << "\"A_g_mol\": " << A_g_mol << ", "
128 << "\"mass_fraction\": " << w
129 << "}";
130
131 if (i + 1 != ne)
132 out << ",";
133 out << "\n";
134 }
135
136 out << " ]\n";
137 out << " }";
138 }
139
140 out << "\n },\n"
141 << " \"count_built_ok\": " << built_ok << ",\n"
142 << " \"count_built_fail\": " << built_fail << "\n"
143 << "}\n";
144
145 std::cerr << "Wrote: " << out_json << "\n"
146 << "NIST names: " << names.size() << ", built ok: " << built_ok
147 << ", failed: " << built_fail << "\n";
148 return 0;
149}
int32_t i
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error s
configStandalone Reconstruction rec_tpc multiplier for the combined cluster track error during track following area in cm for the search of for z only used if decrease removal by when above this local occupancy rowx Shift of TPC revert cluster flag edge bit distance to edge exceeds this ZOffset for secondary multiple of radius max P of electron K BB bands crossing max P of electron p BB bands crossing max P of electron d BB bands crossing max P of electron t BB bands crossing min accepted dEdxMaxTPC of the track Additive extra cluster error for Y2 if edge flag set Additive extra cluster error for Y2 if single set Additive extra cluster error for Y2 if or single set Additive extra cluster error for Z2 if or single set Extra errors to add to track when crossing depending on addErrorsCECrossing Inner portion of y range in sector that is not used in searching for extrapolated track candidates factor2YS for track merging factor2K for track merging Margin in cm of Y position when rejecting edge clusters based on uncorrected track Y Max fraction of shared clusters for tracklet Except pad from cluster finding if total number of charges in a fragment is above this Except pad from cluster finding if number of consecutive charges in a fragment is above this Threshold where a timebin is considered disabling the noisy pad check for that pad Treat signal above this minimum as saturated Smoothing factor for the exponential Highly Ionising Particle tail filter Number of timebins to use for the averaging Add additional custom track errors when crossing relative as fraction of Do N fit passes in final fit of< 0:reject at max -n hits") AddOptionRTC(rejectIFCLowRadiusCluster, uint8_t, 1, "", 0, "Reject clusters that get the IFC mask error during refit") AddOptionRTC(dEdxTruncLow, uint8_t, 2, "", 0, "Low truncation threshold, fraction of 128") AddOptionRTC(dEdxTruncHigh, uint8_t, 77, "", 0, "High truncation threshold, fraction of 128") AddOptionRTC(extrapolationTracking, int8_t, 1, "", 0, "Enable Extrapolation Tracking(prolong tracks to adjacent sectors to find short segments)") AddOptionRTC(disableRefitAttachment, uint8_t, 0, "", 0, "Bitmask to disable certain attachment steps during refit(1:attachment, 2:propagation, 4:loop following, 8:mirroring)") AddOptionRTC(rejectionStrategy, uint8_t, o2::gpu::GPUSettings::RejectionStrategyA, "", 0, "Enable rejection of TPC clusters for compression(0=no, 1=strategy A, 2=strategy B)") AddOptionRTC(mergeLoopersAfterburner, uint8_t, 1, "", 0, "Run afterburner for additional looper merging") AddOptionRTC(compressionTypeMask, uint8_t, o2::gpu::GPUSettings::CompressionFull, "", 0, "TPC Compression mode bits(1=truncate charge/width LSB, 2=differences, 4=track-model)") AddOptionRTC(compressionSortOrder, uint8_t, o2::gpu::GPUSettings::SortTime, "", 0, "Sort order of TPC compression(0=time, 1=pad, 2=Z-time-pad, 3=Z-pad-time, 4=no sorting(use incoming order))") AddOptionRTC(sigBitsCharge, uint8_t, 4, "", 0, "Number of significant bits for TPC cluster charge in compression mode 1") AddOptionRTC(sigBitsWidth, uint8_t, 3, "", 0, "Number of significant bits for TPC cluster width in compression mode 1") AddOptionRTC(dropLoopers, uint8_t, 0, "", 0, "Drop looping tracks starting from second loop") AddOptionRTC(mergerInterpolateErrors, uint8_t, 1, "", 0, "Use interpolation instead of extrapolation for chi2 based cluster rejection") AddOptionRTC(mergerInterpolateRejectAlsoOnCurrentPosition, uint8_t, 1, "", 0, "When using mergerInterpolateErrors, reject based on chi2 twice computed with interpolated and current track position starting from NDF > mergerNonInterpolateRejectMinNDF Merge tracks accross the central electrode Enable PID response Add sub threshold clusters in TPC dEdx computation OR mask of TPC flags that will reject the cluster in alternative dEdx Reject edge clusters based on uncorrected track Y during track fit Increase decrease removal by when on this number of pads from the edge h configStandalone Reconstruction rec_trd Max chi2 for TRD tracklets to be matched to a track Chi2 cut for strict matching mode Number of sigmas for ITS TPC track time error estimate Addition to search road around track prolongation along Y in cm Optimal tracklet rphi resolution in cm(in case phi of track=lorentz angle)") AddOptionRTC(trkltResVsTanPhiMisalign
uint32_t c
Definition RawData.h:2
GLboolean GLboolean g
Definition glcorearb.h:1233
GLuint const GLchar * name
Definition glcorearb.h:781
GLubyte GLubyte GLubyte GLubyte w
Definition glcorearb.h:852
#define main