ARTEMIS-CRIB
 
Loading...
Searching...
No Matches
TTreeBeamGenerator.cc
Go to the documentation of this file.
1/**
2 * @file TTreeBeamGenerator.cc
3 * @brief
4 * @author Kodai Okawa<okawa@cns.s.u-tokyo.ac.jp>
5 * @date 2023-06-09 15:57:01
6 * @note last modified: 2025-01-09 21:03:47
7 * @details
8 */
9
10#include "TTreeBeamGenerator.h"
11
12#include "TParticleInfo.h"
13#include <Mass.h> // TSrim library
14#include <TRandom.h>
15
17
18namespace art::crib {
20 RegisterInputCollection("InputCollection", "input track collection name", fInputColName, TString("track"));
21 RegisterOutputCollection("OutputCollection", "simulation result collection", fOutputColName, TString("beam"));
22
23 RegisterProcessorParameter("MassNum", "beam mass number", fMassNum, 0);
24 RegisterProcessorParameter("AtomicNum", "beam atomic number", fAtmNum, 0);
25 RegisterProcessorParameter("ChargeNum", "beam charge number", fChargeNum, 0);
26 RegisterProcessorParameter("IniEnergy", "beam energy (MeV)", fBeamEnergy, 100.0);
27
28 RegisterProcessorParameter("Esigma", "dispersion of beam energy (MeV)", fEsigma, 1.0);
29}
30
35
36void TTreeBeamGenerator::Init(TEventCollection *col) {
37 Info("Init", "%s => %s", fInputColName.Data(), fOutputColName.Data());
38
39 /// using TSrim library
40 fMass = amdc::Mass(fAtmNum, fMassNum) * amdc::amu; // MeV
41 Info("Init", "beam: (Z, A, M) = (%d, %d, %.5lf)", fAtmNum, fMassNum, fMass / amdc::amu);
42
43 fInData = reinterpret_cast<TClonesArray **>(col->GetObjectRef(fInputColName.Data()));
44 if (!fInData) {
45 SetStateError(TString::Format("input not found: %s", fInputColName.Data()));
46 return;
47 }
48 const TClass *const cl = (*fInData)->GetClass();
49 if (!cl->InheritsFrom(art::TTrack::Class())) {
50 SetStateError("contents of input array must inherit from art::TTrack");
51 }
52
53 fOutData = new TClonesArray("art::crib::TParticleInfo");
54 fOutData->SetName(fOutputColName);
55 col->Add(fOutputColName, fOutData, fOutputIsTransparent);
56
57 gRandom->SetSeed(time(nullptr));
58}
59
61 fOutData->Clear("C");
62
63 if ((*fInData)->GetEntriesFast() != 1) {
64 return;
65 }
66
67 const TDataObject *const inData = static_cast<TDataObject *>((*fInData)->At(0));
68 const TTrack *const Data = dynamic_cast<const TTrack *>(inData);
69
70 TParticleInfo *outData = static_cast<TParticleInfo *>(fOutData->ConstructedAt(0));
71 outData->SetMassNumber(fMassNum);
72 outData->SetAtomicNumber(fAtmNum);
73 outData->SetCharge(fChargeNum);
74
75 Double_t energy = gRandom->Gaus(fBeamEnergy, fEsigma);
76 outData->SetEnergy(energy);
77
78 Double_t angx = Data->GetA();
79 Double_t angy = Data->GetB();
80
81 Double_t beta = TMath::Sqrt(1.0 - TMath::Power(fMass / (fMass + energy), 2)); // kinematics
82 Double_t norm =
83 TMath::Sqrt(TMath::Tan(angx) * TMath::Tan(angx) + TMath::Tan(angy) * TMath::Tan(angy) + 1.0); // kinematics
84 Double_t beta_x = beta * TMath::Tan(angx) / norm;
85 Double_t beta_y = beta * TMath::Tan(angy) / norm;
86 Double_t beta_z = beta * 1.0 / norm;
87
88 TLorentzVector beam(0., 0., 0., fMass);
89 beam.Boost(beta_x, beta_y, beta_z);
90
91 outData->SetID(0);
92 outData->SetLorentzVector(beam);
93 outData->SetCurrentZ(0.);
94 outData->SetZeroTime();
95 outData->SetTrack(Data->GetX(), Data->GetY(), 0., angx, angy);
96}
97} // namespace art::crib
particle information class
ClassImp(art::crib::TTreeBeamGenerator)
void SetTrack(Double_t x, Double_t y, Double_t z, Double_t a, Double_t b)
void SetMassNumber(Int_t val)
void SetLorentzVector(Double_t x, Double_t y, Double_t z, Double_t t)
void SetCurrentZ(Double_t val)
void SetCharge(Int_t val)
void SetAtomicNumber(Int_t val)
void SetEnergy(Double_t val)
void Init(TEventCollection *) override
return to the guide