Project
Loading...
Searching...
No Matches
FluenceWeightCalculator.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
13#include <TFile.h>
14#include <algorithm>
15#include <fstream>
16#include <sstream>
17#include <iostream>
18
19std::unique_ptr<TGraph> FluenceWeightCalculator::neutronG;
20std::unique_ptr<TGraph> FluenceWeightCalculator::protonG;
21std::unique_ptr<TGraph> FluenceWeightCalculator::pionG;
22std::unique_ptr<TGraph> FluenceWeightCalculator::electronG;
23
24namespace
25{
26// Damage weight at an energy clamped to the tabulated range
27double evalClamped(const TGraph& g, double kineticEnergy)
28{
29 if (g.GetN() == 0) {
30 return 0.;
31 }
32 const double e = std::clamp(kineticEnergy, g.GetX()[0], g.GetX()[g.GetN() - 1]);
33 return g.Eval(e, nullptr, "S");
34}
35} // namespace
36
37double FluenceWeightCalculator::GetWeight(const int pdg, const double kineticEnergy)
38{
39 //
40 // Obtain weight for given particle and kinetic energy
41 if (!neutronG || !protonG || !pionG) {
42 std::cerr << "FluenceWeightCalculator not initialized\n";
43 return 0.;
44 }
45 const int apdg = std::abs(pdg);
46 if (pdg == 2112) {
47 return evalClamped(*neutronG, kineticEnergy);
48 }
49 if (apdg == 11) {
50 return electronG ? evalClamped(*electronG, kineticEnergy) : 0.;
51 }
52 // other (anti)baryons use the proton weights
53 if (apdg >= 1000 && apdg < 10000) {
54 return ((kineticEnergy > 1e-3) ? evalClamped(*protonG, kineticEnergy) : 0.);
55 }
56 // mesons use the pion weights
57 if (apdg >= 100 && apdg < 1000) {
58 return ((kineticEnergy > 10.) ? evalClamped(*pionG, kineticEnergy) : 0.);
59 }
60 return 0.;
61}
62
64{
65 //
66 // Read graphs from file
67 TFile inFile(filename.c_str(), "READ");
68 if (inFile.IsZombie()) {
69 std::cerr << "Cannot open " << filename << "\n";
70 return;
71 }
72 //
73 TGraph* tmp = nullptr;
74 inFile.GetObject("neutronDW", tmp);
75 neutronG.reset(tmp ? static_cast<TGraph*>(tmp->Clone()) : nullptr);
76 if (!neutronG) {
77 std::cerr << "Missing graph neutronDW\n";
78 return;
79 }
80 neutronG->SetBit(TGraph::kIsSortedX);
81 inFile.GetObject("protonDW", tmp);
82 protonG.reset(tmp ? static_cast<TGraph*>(tmp->Clone()) : nullptr);
83 if (!protonG) {
84 std::cerr << "Missing graph protonDW\n";
85 return;
86 }
87 protonG->SetBit(TGraph::kIsSortedX);
88 inFile.GetObject("pionDW", tmp);
89 pionG.reset(tmp ? static_cast<TGraph*>(tmp->Clone()) : nullptr);
90 if (!pionG) {
91 std::cerr << "Missing graph pionDW\n";
92 return;
93 }
94 pionG->SetBit(TGraph::kIsSortedX);
95 // electron weights are optional
96 tmp = nullptr;
97 inFile.GetObject("electronDW", tmp);
98 electronG.reset(tmp ? static_cast<TGraph*>(tmp->Clone()) : nullptr);
99 if (electronG) {
100 electronG->SetBit(TGraph::kIsSortedX);
101 }
102}
103
105{
106 //
107 // read the NIEL weights from input file and store them as TGraphs
108 neutronG = std::make_unique<TGraph>();
109 neutronG->SetName("neutronDW");
110 auto neuN = 0;
111 protonG = std::make_unique<TGraph>();
112 protonG->SetName("protonDW");
113 auto proN = 0;
114 pionG = std::make_unique<TGraph>();
115 pionG->SetName("pionDW");
116 auto pioN = 0;
117 electronG = std::make_unique<TGraph>();
118 electronG->SetName("electronDW");
119 auto eleN = 0;
120
121 std::ifstream in(filename);
122 if (!in.is_open()) {
123 std::cerr << "Error: cannot open file with damage weights.\n";
124 return;
125 }
126 std::string line;
127 while (std::getline(in, line)) {
128 if (line.empty() || line[0] == '#') {
129 continue;
130 }
131 std::istringstream ss(line);
132 std::string particle, e_str, w_str;
133 if (!std::getline(ss, particle, ',')) {
134 continue;
135 }
136 if (!std::getline(ss, e_str, ',')) {
137 continue;
138 }
139 if (!std::getline(ss, w_str, ',')) {
140 continue;
141 }
142 auto e = std::stod(e_str);
143 auto w = std::stod(w_str);
144 auto pdg = std::stoi(particle);
145 switch (pdg) {
146 case 2112: {
147 neutronG->SetPoint(neuN++, e, w);
148 break;
149 }
150 case 2212: {
151 protonG->SetPoint(proN++, e, w);
152 break;
153 }
154 case 211: {
155 pionG->SetPoint(pioN++, e, w);
156 break;
157 }
158 case 11: {
159 electronG->SetPoint(eleN++, e, w);
160 break;
161 }
162 default:;
163 }
164 }
165 neutronG->Sort();
166 protonG->Sort();
167 pionG->Sort();
168 electronG->Sort();
169 auto fout = new TFile("rd50_niel.root", "recreate");
170 neutronG->Write();
171 protonG->Write();
172 pionG->Write();
173 electronG->Write();
174 fout->Close();
175}
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 First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char e
static double GetWeight(const int pdg, const double ekin)
static void InitWeightsFromCSV(const std::string &filename)
static void InitWeights(const std::string &filename)
GLboolean GLboolean g
Definition glcorearb.h:1233
GLubyte GLubyte GLubyte GLubyte w
Definition glcorearb.h:852
std::string filename()