FairShip
Loading...
Searching...
No Matches
Generator.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2// SPDX-FileCopyrightText: Copyright CERN for the benefit of the SHiP
3// Collaboration
4
5#ifndef SHIPGEN_GENERATOR_H_
6#define SHIPGEN_GENERATOR_H_
7
8#include <cmath>
9#include <optional>
10#include <string>
11#include <unordered_map>
12#include <utility>
13#include <vector>
14
15#include "FairGenerator.h"
16#include "FairLogger.h"
17
18namespace SHiP {
19class Generator : public FairGenerator {
20 public:
21 using FairGenerator::Init;
22 Generator() = default;
23 ~Generator() override;
24
25 virtual Bool_t Init(const char*, int) = 0;
26 virtual Bool_t Init(const char*) = 0;
27 virtual Bool_t Init(const std::vector<std::string>& inFiles,
28 int startNumber) {
29 LOG(warning) << "Multiple input files not implemented for this generator "
30 "- only taking the first!";
31 return Init(inFiles.at(0).c_str(), startNumber);
32 };
33 virtual Bool_t Init(const std::vector<std::string>& inFiles) {
34 LOG(warning) << "Multiple input files not implemented for this generator "
35 "- only taking the first!";
36 return Init(inFiles.at(0).c_str(), 0);
37 };
38
39 virtual void UseExternalFile(std::string x, Int_t i) {
40 fextFile = std::move(x);
41 firstEvent = i;
42 };
43
44 virtual void UseExternalFile(std::vector<std::string>& inFiles, Int_t i) {
45 LOG(warning) << "Multiple external files not implemented for this "
46 "generator - only taking the first!";
47 UseExternalFile(inFiles.at(0).c_str(), i);
48 }
49
52 void SetMaxTheta(Double_t thetaX, Double_t thetaY) {
53 fMaxThetaX = thetaX;
54 fMaxThetaY = thetaY;
56 };
57 Int_t nrOfGeoRejections() const { return fnGeoRejects; }
58 Long64_t GetCounter(const std::string& name) const {
59 auto it = fCounters.find(name);
60 return it == fCounters.end() ? 0 : it->second;
61 }
62 void SetCounter(const std::string& name, Long64_t value) {
63 fCounters[name] = value;
64 }
65 void IncrementCounter(const std::string& name, Long64_t delta = 1) {
66 fCounters[name] += delta;
67 }
68
69 protected:
70 bool IsInVesselAcceptance(Double_t px, Double_t py, Double_t pz) const {
71 if (!fUseVesselAcceptance) return true;
72 if (pz <= 0) return false;
73 return std::abs(px / pz) < fMaxThetaX && std::abs(py / pz) < fMaxThetaY;
74 }
75
76 std::optional<std::string> fextFile;
77 Int_t firstEvent = 0;
78 Double_t fMaxThetaX = 0;
79 Double_t fMaxThetaY = 0;
81 Int_t fnGeoRejects = 0;
82 std::unordered_map<std::string, int64_t> fCounters;
83};
84} // namespace SHiP
85#endif // SHIPGEN_GENERATOR_H_
virtual void UseExternalFile(std::vector< std::string > &inFiles, Int_t i)
Definition Generator.h:44
void IncrementCounter(const std::string &name, Long64_t delta=1)
Definition Generator.h:65
virtual Bool_t Init(const std::vector< std::string > &inFiles)
Definition Generator.h:33
virtual Bool_t Init(const std::vector< std::string > &inFiles, int startNumber)
Definition Generator.h:27
virtual void UseExternalFile(std::string x, Int_t i)
Definition Generator.h:39
bool IsInVesselAcceptance(Double_t px, Double_t py, Double_t pz) const
Definition Generator.h:70
Int_t fnGeoRejects
Definition Generator.h:81
std::optional< std::string > fextFile
Definition Generator.h:76
void SetCounter(const std::string &name, Long64_t value)
Definition Generator.h:62
Int_t nrOfGeoRejections() const
Definition Generator.h:57
void SetMaxTheta(Double_t thetaX, Double_t thetaY)
Definition Generator.h:52
virtual Bool_t Init(const char *, int)=0
virtual Bool_t Init(const char *)=0
std::unordered_map< std::string, int64_t > fCounters
Definition Generator.h:82
Double_t fMaxThetaX
Definition Generator.h:78
~Generator() override
Long64_t GetCounter(const std::string &name) const
Definition Generator.h:58
bool fUseVesselAcceptance
Definition Generator.h:80
Double_t fMaxThetaY
Definition Generator.h:79
Generator()=default