BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
PerEntryHistogramSet.hh
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) Royal Holloway,
3University of London 2001 - 2024.
4
5This file is part of BDSIM.
6
7BDSIM is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published
9by the Free Software Foundation version 3 of the License.
10
11BDSIM is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
18*/
19#ifndef PERENTRYHISTOGRAMSET_H
20#define PERENTRYHISTOGRAMSET_H
21#include "HistogramDefSet.hh"
22#include "PerEntryHistogram.hh"
23#include "SpectraParticles.hh"
24
25#include "BDSOutputROOTEventSampler.hh"
26
27#include <map>
28#include <set>
29#include <string>
30#include <vector>
31
32class Event;
33class HistogramDef;
34class TChain;
35class TDirectory;
36class TH1;
37
38namespace BDS
39{
42 template<typename A, typename B>
43 std::pair<B, A> flip_pair(const std::pair<A, B> &p)
44 {return std::pair<B, A>(p.second, p.first);}
45
46 template<typename A, typename B>
47 std::multimap<B, A> flip_map(const std::map<A, B> &src)
48 {
49 std::multimap<B, A> dst;
50 std::transform(src.begin(), src.end(), std::inserter(dst, dst.begin()), flip_pair<A, B>);
51 return dst;
52 }
53}
54
62{
63public:
64 PerEntryHistogramSet(const HistogramDefSet* definitionIn,
65 Event* eventIn,
66 TChain* chainIn);
67 virtual ~PerEntryHistogramSet();
68
69 virtual void AccumulateCurrentEntry(long int entryNumber);
70 virtual void Terminate();
71 virtual void Write(TDirectory* dir = nullptr);
72
77 virtual void CheckSampler() = 0;
78
79protected:
82 virtual void GetPDGIDSetFromSampler(std::set<long long int>& setIn) const = 0;
83
84 inline bool IsIon(long long int pdgID) const {return pdgID > 100000000;}
85
86 void CreatePerEntryHistogram(long long int pdgID);
87
89 std::vector<long long int> TopUtility(const std::set<long long int>& s,
90 size_t n) const;
91
93 std::vector<long long int> TopNNonIons(int n) const;
94 std::vector<long long int> TopNIons(int n) const;
95 std::vector<long long int> TopN(int n) const;
97
98 HistogramDef* baseDefinition;
99 Event* event;
100 TChain* chain;
101 std::string branchName;
102 bool dynamicallyStoreParticles;
103 bool dynamicallyStoreIons;
104 long long int nEntries;
105 HistogramDefSet::writewhat what;
106 int topN;
107
108#ifdef __ROOTDOUBLE__
110#else
112#endif
113
114 std::set<long long int> allPDGIDs;
115 std::set<long long int> ions;
116 std::set<long long int> nonIons;
117 std::map<ParticleSpec, PerEntryHistogram*> histograms;
118 std::map<long long int, PerEntryHistogram*> histogramsByPDGID;
119 std::vector<PerEntryHistogram*> allPerEntryHistograms;
120
121 //ClassDef(PerEntryHistogramSet, 1);
122};
123
124#endif
Information stored per sampler per event.
Event loader.
Definition Event.hh:50
Specification for a set of histograms.
Common specification for a histogram.
Histogram over a set of integers not number line.
virtual void Write(TDirectory *dir=nullptr)
virtual void AccumulateCurrentEntry(long int entryNumber)
std::vector< long long int > TopN(int n) const
Get top part of set. Sorted in descending order of integral.
std::vector< long long int > TopNIons(int n) const
Get top part of set. Sorted in descending order of integral.
virtual void GetPDGIDSetFromSampler(std::set< long long int > &setIn) const =0
virtual void CheckSampler()=0
virtual void Terminate()
Terminate the accumulator and save the result to the result member variable.
std::vector< long long int > TopNNonIons(int n) const
Get top part of set. Sorted in descending order of integral.
std::vector< long long int > TopUtility(const std::set< long long int > &s, size_t n) const
Utility function to find top N in set s. Sorted in descending order of integral.
Holder for information to calculate per entry histograms.
Return either G4Tubs or G4CutTubs depending on flat face.
std::pair< B, A > flip_pair(const std::pair< A, B > &p)