FairShip
Loading...
Searching...
No Matches
EvtCalcGenerator Class Reference

#include <EvtCalcGenerator.h>

Inheritance diagram for EvtCalcGenerator:
[legend]
Collaboration diagram for EvtCalcGenerator:
[legend]

Public Member Functions

 EvtCalcGenerator ()
 ~EvtCalcGenerator () override
Bool_t ReadEvent (FairPrimaryGenerator *) override
Bool_t Init (const char *, int) override
Bool_t Init (const char *) override
Int_t GetNevents ()
void SetPositions (Double_t zTa, Double_t zDV)
Double_t GetNdaughters (const std::unique_ptr< TTree > &) const
Double_t GetMotherPx (const std::unique_ptr< TTree > &) const
Double_t GetMotherPy (const std::unique_ptr< TTree > &) const
Double_t GetMotherPz (const std::unique_ptr< TTree > &) const
Double_t GetMotherE (const std::unique_ptr< TTree > &) const
Double_t GetVx (const std::unique_ptr< TTree > &) const
Double_t GetVy (const std::unique_ptr< TTree > &) const
Double_t GetVz (const std::unique_ptr< TTree > &) const
Double_t GetDecayProb (const std::unique_ptr< TTree > &) const
Double_t GetDauPx (const std::unique_ptr< TTree > &, int) const
Double_t GetDauPy (const std::unique_ptr< TTree > &, int) const
Double_t GetDauPz (const std::unique_ptr< TTree > &, int) const
Double_t GetDauE (const std::unique_ptr< TTree > &, int) const
Double_t GetDauPDG (const std::unique_ptr< TTree > &, int) const
virtual Bool_t Init (const std::vector< std::string > &inFiles, int startNumber)
virtual Bool_t Init (const std::vector< std::string > &inFiles)
Public Member Functions inherited from SHiP::Generator
 Generator ()=default
 ~Generator () override
virtual void UseExternalFile (std::string x, Int_t i)
virtual void UseExternalFile (std::vector< std::string > &inFiles, Int_t i)
void SetMaxTheta (Double_t thetaX, Double_t thetaY)
Int_t nrOfGeoRejections () const
Long64_t GetCounter (const std::string &name) const
void SetCounter (const std::string &name, Long64_t value)
void IncrementCounter (const std::string &name, Long64_t delta=1)

Protected Types

enum class  BranchIndices {
  MotherPx = 0 , MotherPy = 1 , MotherPz = 2 , MotherE = 3 ,
  DecayProb = 6 , Vx = 7 , Vy = 8 , Vz = 9
}

Protected Member Functions

Double_t GetBranchValue (const std::unique_ptr< TTree > &, unsigned) const
Double_t GetDaughterValue (const std::unique_ptr< TTree > &tree, int, int) const
Protected Member Functions inherited from SHiP::Generator
bool IsInVesselAcceptance (Double_t px, Double_t py, Double_t pz) const

Protected Attributes

Double_t ztarget
Double_t zDecayVolume
std::unique_ptr< TFile > fInputFile
std::unique_ptr< TTree > fTree
std::vector< double > branchVars
int fNevents
int fn
int nBranches
int Ndau
Protected Attributes inherited from SHiP::Generator
std::optional< std::string > fextFile
Int_t firstEvent = 0
Double_t fMaxThetaX = 0
Double_t fMaxThetaY = 0
bool fUseVesselAcceptance = false
Int_t fnGeoRejects = 0
std::unordered_map< std::string, int64_t > fCounters

Detailed Description

Definition at line 16 of file EvtCalcGenerator.h.

Member Enumeration Documentation

◆ BranchIndices

enum class EvtCalcGenerator::BranchIndices
strongprotected
Enumerator
MotherPx 
MotherPy 
MotherPz 
MotherE 
DecayProb 
Vx 
Vy 
Vz 

Definition at line 65 of file EvtCalcGenerator.h.

65 {
66 MotherPx = 0,
67 MotherPy = 1,
68 MotherPz = 2,
69 MotherE = 3,
70 DecayProb = 6,
71 Vx = 7,
72 Vy = 8,
73 Vz = 9
74 };

Constructor & Destructor Documentation

◆ EvtCalcGenerator()

EvtCalcGenerator::EvtCalcGenerator ( )
default

default constructor

◆ ~EvtCalcGenerator()

EvtCalcGenerator::~EvtCalcGenerator ( )
overridedefault

destructor

Member Function Documentation

◆ GetBranchValue()

Double_t EvtCalcGenerator::GetBranchValue ( const std::unique_ptr< TTree > & tree,
unsigned index ) const
protected

Definition at line 97 of file EvtCalcGenerator.cxx.

98 {
99 if (index < branchVars.size()) {
100 return branchVars[index];
101 } else {
102 throw std::out_of_range("Branch index out of range");
103 }
104}
std::vector< double > branchVars

◆ GetDauE()

Double_t EvtCalcGenerator::GetDauE ( const std::unique_ptr< TTree > & tree,
int dauID ) const

Definition at line 167 of file EvtCalcGenerator.cxx.

168 {
169 return GetDaughterValue(tree, dauID, 3);
170}
Double_t GetDaughterValue(const std::unique_ptr< TTree > &tree, int, int) const

◆ GetDaughterValue()

Double_t EvtCalcGenerator::GetDaughterValue ( const std::unique_ptr< TTree > & tree,
int dauID,
int offset ) const
protected

Definition at line 106 of file EvtCalcGenerator.cxx.

107 {
108 int baseIndex = 10 + (dauID * 6);
109 return GetBranchValue(tree, baseIndex + offset);
110}
Double_t GetBranchValue(const std::unique_ptr< TTree > &, unsigned) const

◆ GetDauPDG()

Double_t EvtCalcGenerator::GetDauPDG ( const std::unique_ptr< TTree > & tree,
int dauID ) const

Definition at line 171 of file EvtCalcGenerator.cxx.

172 {
173 return GetDaughterValue(tree, dauID, 5);
174}

◆ GetDauPx()

Double_t EvtCalcGenerator::GetDauPx ( const std::unique_ptr< TTree > & tree,
int dauID ) const

Definition at line 155 of file EvtCalcGenerator.cxx.

156 {
157 return GetDaughterValue(tree, dauID, 0);
158}

◆ GetDauPy()

Double_t EvtCalcGenerator::GetDauPy ( const std::unique_ptr< TTree > & tree,
int dauID ) const

Definition at line 159 of file EvtCalcGenerator.cxx.

160 {
161 return GetDaughterValue(tree, dauID, 1);
162}

◆ GetDauPz()

Double_t EvtCalcGenerator::GetDauPz ( const std::unique_ptr< TTree > & tree,
int dauID ) const

Definition at line 163 of file EvtCalcGenerator.cxx.

164 {
165 return GetDaughterValue(tree, dauID, 2);
166}

◆ GetDecayProb()

Double_t EvtCalcGenerator::GetDecayProb ( const std::unique_ptr< TTree > & tree) const

Definition at line 149 of file EvtCalcGenerator.cxx.

150 {
151 return GetBranchValue(tree, static_cast<int>(BranchIndices::DecayProb));
152}

◆ GetMotherE()

Double_t EvtCalcGenerator::GetMotherE ( const std::unique_ptr< TTree > & tree) const

Definition at line 132 of file EvtCalcGenerator.cxx.

133 {
134 return GetBranchValue(tree, static_cast<int>(BranchIndices::MotherE));
135}

◆ GetMotherPx()

Double_t EvtCalcGenerator::GetMotherPx ( const std::unique_ptr< TTree > & tree) const

Definition at line 120 of file EvtCalcGenerator.cxx.

121 {
122 return GetBranchValue(tree, static_cast<int>(BranchIndices::MotherPx));
123}

◆ GetMotherPy()

Double_t EvtCalcGenerator::GetMotherPy ( const std::unique_ptr< TTree > & tree) const

Definition at line 124 of file EvtCalcGenerator.cxx.

125 {
126 return GetBranchValue(tree, static_cast<int>(BranchIndices::MotherPy));
127}

◆ GetMotherPz()

Double_t EvtCalcGenerator::GetMotherPz ( const std::unique_ptr< TTree > & tree) const

Definition at line 128 of file EvtCalcGenerator.cxx.

129 {
130 return GetBranchValue(tree, static_cast<int>(BranchIndices::MotherPz));
131}

◆ GetNdaughters()

Double_t EvtCalcGenerator::GetNdaughters ( const std::unique_ptr< TTree > & tree) const

Definition at line 114 of file EvtCalcGenerator.cxx.

115 {
116 return GetBranchValue(tree, nBranches - 1);
117}

◆ GetNevents()

Int_t EvtCalcGenerator::GetNevents ( )
inline

Definition at line 30 of file EvtCalcGenerator.h.

30{ return fNevents; }

◆ GetVx()

Double_t EvtCalcGenerator::GetVx ( const std::unique_ptr< TTree > & tree) const

Definition at line 138 of file EvtCalcGenerator.cxx.

138 {
139 return GetBranchValue(tree, static_cast<int>(BranchIndices::Vx));
140}

◆ GetVy()

Double_t EvtCalcGenerator::GetVy ( const std::unique_ptr< TTree > & tree) const

Definition at line 141 of file EvtCalcGenerator.cxx.

141 {
142 return GetBranchValue(tree, static_cast<int>(BranchIndices::Vy));
143}

◆ GetVz()

Double_t EvtCalcGenerator::GetVz ( const std::unique_ptr< TTree > & tree) const

Definition at line 144 of file EvtCalcGenerator.cxx.

144 {
145 return GetBranchValue(tree, static_cast<int>(BranchIndices::Vz));
146}

◆ Init() [1/4]

Bool_t EvtCalcGenerator::Init ( const char * fileName)
overridevirtual

Implements SHiP::Generator.

Definition at line 20 of file EvtCalcGenerator.cxx.

20 {
21 return Init(fileName, 0);
22}
Bool_t Init(const char *, int) override

◆ Init() [2/4]

Bool_t EvtCalcGenerator::Init ( const char * fileName,
int startEvent )
overridevirtual

Implements SHiP::Generator.

Definition at line 24 of file EvtCalcGenerator.cxx.

24 {
25 if (startEvent < 0) {
26 LOG(error) << "EvtCalcGenerator: startEvent must be >= 0, got "
27 << startEvent;
28 return kFALSE;
29 }
30 fInputFile = std::unique_ptr<TFile>(TFile::Open(fileName, "read"));
31 LOGF(info, "Info EvtCalcGenerator: Opening input file %s", fileName);
32 if (!fInputFile) {
33 LOG(error) << "EvtCalcGenerator: error opening input file " << fileName;
34 fInputFile.reset();
35 return kFALSE;
36 }
37
38 fTree =
39 std::unique_ptr<TTree>(dynamic_cast<TTree*>(fInputFile->Get("LLP_tree")));
40 if (!fTree) {
41 LOG(error) << "EvtCalcGenerator: cannot find tree LLP_tree in file "
42 << fileName;
43 fInputFile.reset();
44 return kFALSE;
45 }
46 fNevents = fTree->GetEntries();
47 if (startEvent >= fNevents) {
48 LOG(error) << "EvtCalcGenerator: startEvent " << startEvent
49 << " is out of range for " << fNevents << " entries";
50 fTree.reset();
51 fInputFile.reset();
52 return kFALSE;
53 }
54 fn = startEvent;
55
56 auto* branches = fTree->GetListOfBranches();
57 if (!branches) {
58 LOG(error) << "EvtCalcGenerator: failed to access tree branches";
59 fTree.reset();
60 fInputFile.reset();
61 return kFALSE;
62 }
63 nBranches = branches->GetEntries();
64 if (nBranches <= 0) {
65 LOG(error) << "EvtCalcGenerator: tree LLP_tree has no branches";
66 fTree.reset();
67 fInputFile.reset();
68 return kFALSE;
69 }
70 branchVars.resize(nBranches);
71
72 for (int i = 0; i < nBranches; ++i) {
73 auto* branch = dynamic_cast<TBranch*>(branches->At(i));
74 if (!branch) {
75 LOG(error) << "EvtCalcGenerator: encountered an invalid branch entry";
76 fTree.reset();
77 fInputFile.reset();
78 return kFALSE;
79 }
80 if (fTree->FindBranch(branch->GetName())) {
81 if (fTree->SetBranchAddress(branch->GetName(), &branchVars[i]) < 0) {
82 LOG(error) << "EvtCalcGenerator: failed to bind branch "
83 << branch->GetName();
84 fTree.reset();
85 fInputFile.reset();
86 return kFALSE;
87 }
88 }
89 }
90
91 return kTRUE;
92}
std::unique_ptr< TFile > fInputFile
std::unique_ptr< TTree > fTree
int i
Definition ShipAna.py:108

◆ Init() [3/4]

virtual Bool_t SHiP::Generator::Init ( const std::vector< std::string > & inFiles)
inlinevirtual

public method ReadEvent

Reimplemented from SHiP::Generator.

Definition at line 33 of file Generator.h.

33 {
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 };

◆ Init() [4/4]

virtual Bool_t SHiP::Generator::Init ( const std::vector< std::string > & inFiles,
int startNumber )
inlinevirtual

public method ReadEvent

Reimplemented from SHiP::Generator.

Definition at line 27 of file Generator.h.

28 {
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 };

◆ ReadEvent()

Bool_t EvtCalcGenerator::ReadEvent ( FairPrimaryGenerator * cpg)
override

Definition at line 177 of file EvtCalcGenerator.cxx.

177 {
178 if (fn == fNevents) {
179 LOG(warning) << "End of input file. Rewind.";
180 fn = 0;
181 }
182
183 fTree->GetEntry(fn);
184 fn++;
185 if (fn % 100 == 0) LOGF(info, "Info EvtCalcGenerator: event nr %d", fn);
186
188 // Vertex coordinates in the SHiP reference frame, expressed in [cm]
189 Double_t space_unit_conv = 100.; // m to cm
190 Double_t vx_transf = GetVx(fTree) * space_unit_conv; // units cm
191 Double_t vy_transf = GetVy(fTree) * space_unit_conv; // units cm
192 Double_t vz_transf = GetVz(fTree) * space_unit_conv + ztarget; // units cm
193
194 Double_t tof = TMath::Sqrt(vx_transf * vx_transf + vy_transf * vy_transf +
195 vz_transf * vz_transf) /
197 Double_t decay_prob = GetDecayProb(fTree);
198 Double_t pdg_dau = 0;
199
200 // Mother LLP
201 Bool_t wanttracking = false;
202 Double_t pdg_llp = 999; // Geantino, placeholder
203
204 cpg->AddTrack(pdg_llp, GetMotherPx(fTree), GetMotherPy(fTree),
205 GetMotherPz(fTree), vx_transf, vy_transf, vz_transf, -1.,
206 wanttracking, GetMotherE(fTree), tof, decay_prob);
207
208 wanttracking = true;
209
210 // Secondaries
211 for (int iPart = 0; iPart < Ndau; ++iPart) {
212 pdg_dau = GetDauPDG(fTree, iPart);
213 if (pdg_dau != -999) {
214 cpg->AddTrack(pdg_dau, GetDauPx(fTree, iPart), GetDauPy(fTree, iPart),
215 GetDauPz(fTree, iPart), vx_transf, vy_transf, vz_transf, 0.,
216 wanttracking, GetDauE(fTree, iPart), tof, decay_prob);
217 }
218 }
219
220 return kTRUE;
221}
Double_t GetDauPDG(const std::unique_ptr< TTree > &, int) const
Double_t GetNdaughters(const std::unique_ptr< TTree > &) const
Double_t GetDauE(const std::unique_ptr< TTree > &, int) const
Double_t GetMotherE(const std::unique_ptr< TTree > &) const
Double_t GetDauPx(const std::unique_ptr< TTree > &, int) const
Double_t GetDecayProb(const std::unique_ptr< TTree > &) const
Double_t GetDauPz(const std::unique_ptr< TTree > &, int) const
Double_t GetMotherPy(const std::unique_ptr< TTree > &) const
Double_t GetMotherPz(const std::unique_ptr< TTree > &) const
Double_t GetMotherPx(const std::unique_ptr< TTree > &) const
Double_t GetVz(const std::unique_ptr< TTree > &) const
Double_t GetDauPy(const std::unique_ptr< TTree > &, int) const
Double_t GetVx(const std::unique_ptr< TTree > &) const
Double_t GetVy(const std::unique_ptr< TTree > &) const
constexpr double c_light
Definition ShipUnit.h:44
constexpr double s
Definition ShipUnit.h:31

◆ SetPositions()

void EvtCalcGenerator::SetPositions ( Double_t zTa,
Double_t zDV )
inline

Definition at line 31 of file EvtCalcGenerator.h.

31 {
32 ztarget = zTa; // units cm (midpoint)
33 zDecayVolume = zDV; // units cm (midpoint)
34 }

Member Data Documentation

◆ branchVars

std::vector<double> EvtCalcGenerator::branchVars
protected

Definition at line 63 of file EvtCalcGenerator.h.

◆ fInputFile

std::unique_ptr<TFile> EvtCalcGenerator::fInputFile
protected

Definition at line 61 of file EvtCalcGenerator.h.

◆ fn

int EvtCalcGenerator::fn
protected

Definition at line 77 of file EvtCalcGenerator.h.

◆ fNevents

int EvtCalcGenerator::fNevents
protected

Definition at line 76 of file EvtCalcGenerator.h.

◆ fTree

std::unique_ptr<TTree> EvtCalcGenerator::fTree
protected

Definition at line 62 of file EvtCalcGenerator.h.

◆ nBranches

int EvtCalcGenerator::nBranches
protected

Definition at line 78 of file EvtCalcGenerator.h.

◆ Ndau

int EvtCalcGenerator::Ndau
protected

Definition at line 79 of file EvtCalcGenerator.h.

◆ zDecayVolume

Double_t EvtCalcGenerator::zDecayVolume
protected

Definition at line 60 of file EvtCalcGenerator.h.

◆ ztarget

Double_t EvtCalcGenerator::ztarget
protected

Definition at line 60 of file EvtCalcGenerator.h.


The documentation for this class was generated from the following files: