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 - 2023.
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
75 void CheckSampler();
76
77protected:
78 inline bool IsIon(long long int pdgID) const {return pdgID > 100000000;}
79
80 void CreatePerEntryHistogram(long long int pdgID);
81
83 std::vector<long long int> TopUtility(const std::set<long long int>& s,
84 size_t n) const;
85
87 std::vector<long long int> TopNNonIons(int n) const;
88 std::vector<long long int> TopNIons(int n) const;
89 std::vector<long long int> TopN(int n) const;
91
92 HistogramDef* baseDefinition;
93 Event* event;
94 TChain* chain;
95 std::string branchName;
96 bool dynamicallyStoreParticles;
97 bool dynamicallyStoreIons;
98 long long int nEntries;
99 HistogramDefSet::writewhat what;
100 int topN;
101
102#ifdef __ROOTDOUBLE__
104#else
106#endif
107
108 std::set<long long int> allPDGIDs;
109 std::set<long long int> ions;
110 std::set<long long int> nonIons;
111 std::map<ParticleSpec, PerEntryHistogram*> histograms;
112 std::map<long long int, PerEntryHistogram*> histogramsByPDGID;
113 std::vector<PerEntryHistogram*> allPerEntryHistograms;
114
115 //ClassDef(PerEntryHistogramSet, 1);
116};
117
118#endif
Information stored per sampler per event.
Event loader.
Definition: Event.hh:50
Specification for a set of histograms.
Common specification for a histogram.
Definition: HistogramDef.hh:34
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 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)