1919std::unique_ptr<TGraph> FluenceWeightCalculator::neutronG;
2020std::unique_ptr<TGraph> FluenceWeightCalculator::protonG;
2121std::unique_ptr<TGraph> FluenceWeightCalculator::pionG;
22+ std::unique_ptr<TGraph> FluenceWeightCalculator::electronG;
2223
2324namespace
2425{
@@ -41,19 +42,22 @@ double FluenceWeightCalculator::GetWeight(const int pdg, const double kineticEne
4142 std::cerr << " FluenceWeightCalculator not initialized\n " ;
4243 return 0 .;
4344 }
44- switch (std::abs (pdg)) {
45- case 2112 : {
46- return evalClamped (*neutronG, kineticEnergy);
47- }
48- case 2212 : {
49- return ((kineticEnergy > 1e-3 ) ? evalClamped (*protonG, kineticEnergy) : 0 .);
50- }
51- case 211 : {
52- return ((kineticEnergy > 10 .) ? evalClamped (*pionG, kineticEnergy) : 0 .);
53- }
54- default :
55- return 0.0 ;
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 .);
5655 }
56+ // mesons use the pion weights
57+ if (apdg >= 100 && apdg < 1000 ) {
58+ return ((kineticEnergy > 10 .) ? evalClamped (*pionG, kineticEnergy) : 0 .);
59+ }
60+ return 0 .;
5761}
5862
5963void FluenceWeightCalculator::InitWeights (const std::string& filename)
@@ -88,6 +92,13 @@ void FluenceWeightCalculator::InitWeights(const std::string& filename)
8892 return ;
8993 }
9094 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+ }
91102}
92103
93104void FluenceWeightCalculator::InitWeightsFromCSV (const std::string& filename)
@@ -103,6 +114,9 @@ void FluenceWeightCalculator::InitWeightsFromCSV(const std::string& filename)
103114 pionG = std::make_unique<TGraph>();
104115 pionG->SetName (" pionDW" );
105116 auto pioN = 0 ;
117+ electronG = std::make_unique<TGraph>();
118+ electronG->SetName (" electronDW" );
119+ auto eleN = 0 ;
106120
107121 std::ifstream in (filename);
108122 if (!in.is_open ()) {
@@ -141,15 +155,21 @@ void FluenceWeightCalculator::InitWeightsFromCSV(const std::string& filename)
141155 pionG->SetPoint (pioN++, e, w);
142156 break ;
143157 }
158+ case 11 : {
159+ electronG->SetPoint (eleN++, e, w);
160+ break ;
161+ }
144162 default :;
145163 }
146164 }
147165 neutronG->Sort ();
148166 protonG->Sort ();
149167 pionG->Sort ();
168+ electronG->Sort ();
150169 auto fout = new TFile (" rd50_niel.root" , " recreate" );
151170 neutronG->Write ();
152171 protonG->Write ();
153172 pionG->Write ();
173+ electronG->Write ();
154174 fout->Close ();
155175}
0 commit comments