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) BDSIM Collaboration, 2001 - 2026.
3
4This file is part of BDSIM.
5
6BDSIM is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published
8by the Free Software Foundation version 3 of the License.
9
10BDSIM is distributed in the hope that it will be useful, but
11WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
17*/
18#ifndef PERENTRYHISTOGRAMSET_H
19#define PERENTRYHISTOGRAMSET_H
20#include "HistogramDefSet.hh"
21#include "PerEntryHistogram.hh"
22#include "SpectraParticles.hh"
23
24#include "BDSOutputROOTEventSampler.hh"
25
26#include <map>
27#include <set>
28#include <string>
29#include <vector>
30
31class Event;
32class HistogramDef;
33class TChain;
34class TDirectory;
35class TH1;
36
37namespace BDS
38{
41 template<typename A, typename B>
42 std::pair<B, A> flip_pair(const std::pair<A, B> &p)
43 {return std::pair<B, A>(p.second, p.first);}
44
45 template<typename A, typename B>
46 std::multimap<B, A> flip_map(const std::map<A, B> &src)
47 {
48 std::multimap<B, A> dst;
49 std::transform(src.begin(), src.end(), std::inserter(dst, dst.begin()), flip_pair<A, B>);
50 return dst;
51 }
52}
53
61{
62public:
63 PerEntryHistogramSet(const HistogramDefSet* definitionIn,
64 Event* eventIn,
65 TChain* chainIn);
66 virtual ~PerEntryHistogramSet();
67
68 virtual void AccumulateCurrentEntry(long int entryNumber);
69 virtual void Terminate();
70 virtual void Write(TDirectory* dir = nullptr);
71
76 virtual void CheckSampler() = 0;
77
78protected:
81 virtual void GetPDGIDSetFromSampler(std::set<long long int>& setIn) const = 0;
82
83 inline bool IsIon(long long int pdgID) const {return pdgID > 100000000;}
84
85 void CreatePerEntryHistogram(long long int pdgID);
86
88 std::vector<long long int> TopUtility(const std::set<long long int>& s,
89 size_t n) const;
90
92 std::vector<long long int> TopNNonIons(int n) const;
93 std::vector<long long int> TopNIons(int n) const;
94 std::vector<long long int> TopN(int n) const;
96
97 HistogramDef* baseDefinition;
98 Event* event;
99 TChain* chain;
100 std::string branchName;
101 bool dynamicallyStoreParticles;
102 bool dynamicallyStoreIons;
103 long long int nEntries;
104 HistogramDefSet::writewhat what;
105 int topN;
106
107#ifdef __ROOTDOUBLE__
109#else
111#endif
112
113 std::set<long long int> allPDGIDs;
114 std::set<long long int> ions;
115 std::set<long long int> nonIons;
116 std::map<ParticleSpec, PerEntryHistogram*> histograms;
117 std::map<long long int, PerEntryHistogram*> histogramsByPDGID;
118 std::vector<PerEntryHistogram*> allPerEntryHistograms;
119
120 //ClassDef(PerEntryHistogramSet, 1);
121};
122
123#endif
Information stored per sampler per event.
Event loader.
Definition Event.hh:49
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)