Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4MergeMode.hh
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26
27// Author: Ivana Hrivnacova, 04/07/2012 ([email protected])
28
29#ifndef G4MergeMode_h
30#define G4MergeMode_h 1
31
32#include "globals.hh"
33
34#include <functional>
35#include <cmath>
36
37// Enumeration for definition available binning schemes
38
39enum class G4MergeMode {
40 kAddition, // "Or" if boolean type
41 kMultiplication, // "And" if boolean type
42 kMaximum, // "Or" if boolean type
43 kMinimum // "And" if boolean type
44};
45
46// Generic merge function
47template <typename T>
48using G4MergeFunction = std::function<T(const T&, const T&)>;
49
50// Utility functions
51namespace G4Accumulables {
52
53G4MergeMode GetMergeMode(const G4String& mergeModeName);
54
55template <typename T>
57{
58 switch ( mergeMode ) {
59 case G4MergeMode::kAddition:
60 // return std::bind([](const T& x, const T& y) { return x + y; });
61 return [](const T& x, const T& y) { return x + y; };
62
63 case G4MergeMode::kMultiplication:
64 return [](const T& x, const T& y) { return x * y; };
65
66 case G4MergeMode::kMaximum:
67 // return std::bind([](const T& x, const T& y) { return std::max(x,y);});
68 return [](const T& x, const T& y) { return std::max(x,y); };
69
70 case G4MergeMode::kMinimum:
71 // return std::bind([](const T& x, const T& y) { return std::min(x,y);});
72 return [](const T& x, const T& y) { return std::min(x,y); };
73
74 default:
75 return [](const T&, const T&) { return 0.0; };
76 }
77}
78
79template <G4bool>
81{
82 switch ( mergeMode ) {
83 case G4MergeMode::kAddition:
84 case G4MergeMode::kMaximum:
85 // return std::bind([](const T& x, const T& y) { return x + y; });
86 return [](const G4bool& x, const G4bool& y) { return x || y; };
87
88 case G4MergeMode::kMultiplication:
89 case G4MergeMode::kMinimum:
90 return [](const G4bool& x, const G4bool& y) { return x && y; };
91 }
92}
93
94}
95
96#endif
G4MergeMode
Definition: G4MergeMode.hh:39
std::function< T(const T &, const T &)> G4MergeFunction
Definition: G4MergeMode.hh:48
bool G4bool
Definition: G4Types.hh:86
G4MergeFunction< T > GetMergeFunction(G4MergeMode mergeMode)
Definition: G4MergeMode.hh:56
G4MergeMode GetMergeMode(const G4String &mergeModeName)
Definition: G4MergeMode.cc:35