-
Notifications
You must be signed in to change notification settings - Fork 501
optional use of Geant4 fluence weighting added #15417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+198
−9
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d5972d7
optional use of Geant4 fluence weighting added
amorsch 85a758d
Update copyright notice in FluenceWeightCalculator.cxx
amorsch 7b9dd8d
Add copyright and license information to header
amorsch 8cd05bf
Update copyright and license information
amorsch 8a9cdab
Remove blank line before G4 VMC creation
amorsch 9b4c8a6
Refactor Eval calls to use nullptr instead of 0
amorsch 2c4c5d8
Remove blank line before G4 VMC creation
amorsch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
Common/SimConfig/include/SimConfig/FluenceWeightCalculator.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| // Copyright 2019-2026 CERN and copyright holders of ALICE O2. | ||
| // See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. | ||
| // All rights not expressly granted are reserved. | ||
| // | ||
| // This software is distributed under the terms of the GNU General Public | ||
| // License v3 (GPL Version 3), copied verbatim in the file "COPYING". | ||
| // | ||
| // In applying this license CERN does not waive the privileges and immunities | ||
| // granted to it by virtue of its status as an Intergovernmental Organization | ||
| // or submit itself to any jurisdiction. | ||
|
|
||
| #ifndef FluenceWeightCalculator_h | ||
| #define FluenceWeightCalculator_h | ||
| #include <vector> | ||
| #include <string> | ||
| #include <memory> | ||
| #include "TGraph.h" | ||
| // | ||
| // Static container class for damage weight funnctions in form of TGraphs | ||
| // The weights can be read from a csv file and stored in the graphs. | ||
| // | ||
| class FluenceWeightCalculator | ||
| { | ||
| public: | ||
| FluenceWeightCalculator() = delete; | ||
| static void InitWeights(const std::string& filename); | ||
| static void InitWeightsFromCSV(const std::string& filename); | ||
| static double GetWeight(const int pdg, const double ekin); | ||
|
|
||
| private: | ||
| static std::unique_ptr<TGraph> neutronG; | ||
| static std::unique_ptr<TGraph> protonG; | ||
| static std::unique_ptr<TGraph> pionG; | ||
| }; | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| // Copyright 2019-2020 CERN and copyright holders of ALICE O2. | ||
| // See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. | ||
| // All rights not expressly granted are reserved. | ||
| // | ||
| // This software is distributed under the terms of the GNU General Public | ||
| // License v3 (GPL Version 3), copied verbatim in the file "COPYING". | ||
| // | ||
| // In applying this license CERN does not waive the privileges and immunities | ||
| // granted to it by virtue of its status as an Intergovernmental Organization | ||
| // or submit itself to any jurisdiction. | ||
|
|
||
| #include "SimConfig/FluenceWeightCalculator.h" | ||
| #include <TFile.h> | ||
| #include <fstream> | ||
| #include <sstream> | ||
| #include <iostream> | ||
|
|
||
| std::unique_ptr<TGraph> FluenceWeightCalculator::neutronG; | ||
| std::unique_ptr<TGraph> FluenceWeightCalculator::protonG; | ||
| std::unique_ptr<TGraph> FluenceWeightCalculator::pionG; | ||
|
|
||
| double FluenceWeightCalculator::GetWeight(const int pdg, const double kineticEnergy) | ||
| { | ||
| // | ||
| // Obtain weight for given particle and kinetic energy | ||
| if (!neutronG || !protonG || !pionG) { | ||
| std::cerr << "FluenceWeightCalculator not initialized\n"; | ||
| return 0.; | ||
| } | ||
| switch (std::abs(pdg)) { | ||
| case 2112: { | ||
| return neutronG->Eval(kineticEnergy, nullptr, "S"); | ||
| } | ||
| case 2212: { | ||
| return ((kineticEnergy > 1e-3) ? protonG->Eval(kineticEnergy, nullptr, "S") : 0.); | ||
| } | ||
| case 211: { | ||
| return ((kineticEnergy > 10.) ? pionG->Eval(kineticEnergy, nullptr, "S") : 0.); | ||
| } | ||
| default: | ||
| return 0.0; | ||
| } | ||
| } | ||
|
|
||
| void FluenceWeightCalculator::InitWeights(const std::string& filename) | ||
| { | ||
| // | ||
| // Read graphs from file | ||
| TFile inFile(filename.c_str(), "READ"); | ||
| if (inFile.IsZombie()) { | ||
| std::cerr << "Cannot open " << filename << "\n"; | ||
| return; | ||
| } | ||
| // | ||
| TGraph* tmp = nullptr; | ||
| inFile.GetObject("neutronDW", tmp); | ||
| neutronG.reset(tmp ? static_cast<TGraph*>(tmp->Clone()) : nullptr); | ||
| if (!neutronG) { | ||
| std::cerr << "Missing graph neutronDW\n"; | ||
| return; | ||
| } | ||
| neutronG->SetBit(TGraph::kIsSortedX); | ||
| inFile.GetObject("protonDW", tmp); | ||
| protonG.reset(tmp ? static_cast<TGraph*>(tmp->Clone()) : nullptr); | ||
| if (!protonG) { | ||
| std::cerr << "Missing graph protonDW\n"; | ||
| return; | ||
| } | ||
| protonG->SetBit(TGraph::kIsSortedX); | ||
| inFile.GetObject("pionDW", tmp); | ||
| pionG.reset(tmp ? static_cast<TGraph*>(tmp->Clone()) : nullptr); | ||
| if (!pionG) { | ||
| std::cerr << "Missing graph pionDW\n"; | ||
| return; | ||
| } | ||
| pionG->SetBit(TGraph::kIsSortedX); | ||
| } | ||
|
|
||
| void FluenceWeightCalculator::InitWeightsFromCSV(const std::string& filename) | ||
| { | ||
| // | ||
| // read the NIEL weights from input file and store them as TGraphs | ||
| neutronG = std::make_unique<TGraph>(); | ||
| neutronG->SetName("neutronDW"); | ||
| auto neuN = 0; | ||
| protonG = std::make_unique<TGraph>(); | ||
| protonG->SetName("protonDW"); | ||
| auto proN = 0; | ||
| pionG = std::make_unique<TGraph>(); | ||
| pionG->SetName("pionDW"); | ||
| auto pioN = 0; | ||
|
|
||
| std::ifstream in(filename); | ||
| if (!in.is_open()) { | ||
| std::cerr << "Error: cannot open file with damage weights.\n"; | ||
| return; | ||
| } | ||
| std::string line; | ||
| while (std::getline(in, line)) { | ||
| if (line.empty() || line[0] == '#') { | ||
| continue; | ||
| } | ||
| std::istringstream ss(line); | ||
| std::string particle, e_str, w_str; | ||
| if (!std::getline(ss, particle, ',')) { | ||
| continue; | ||
| } | ||
| if (!std::getline(ss, e_str, ',')) { | ||
| continue; | ||
| } | ||
| if (!std::getline(ss, w_str, ',')) { | ||
| continue; | ||
| } | ||
| auto e = std::stod(e_str); | ||
| auto w = std::stod(w_str); | ||
| auto pdg = std::stoi(particle); | ||
| switch (pdg) { | ||
| case 2112: { | ||
| neutronG->SetPoint(neuN++, e, w); | ||
| break; | ||
| } | ||
| case 2212: { | ||
| protonG->SetPoint(proN++, e, w); | ||
| break; | ||
| } | ||
| case 211: { | ||
| pionG->SetPoint(pioN++, e, w); | ||
| break; | ||
| } | ||
| default:; | ||
| } | ||
| } | ||
| auto fout = new TFile("rd50_niel.root", "recreate"); | ||
| neutronG->Write(); | ||
| protonG->Write(); | ||
| pionG->Write(); | ||
| fout->Close(); | ||
| } | ||
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static_cast<TGraph*>(tmp->Clone())This is undefined behaviour.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I know, GetObject checks also that the type is correct and returns a null pointer if this is not the case.