ATTPCROOT  0.3.0-alpha
A ROOT-based framework for analyzing data from active target detectors
AtTPCGammaDummyGenerator.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- Based on AtTPCGammaDummyGenerator source file -----
3 // ----- Created 11/01/21 by H. Alvarez -----
4 // -------------------------------------------------------------------------
5 
7 
8 #include <FairLogger.h>
9 #include <FairPrimaryGenerator.h>
10 
11 #include <TDatabasePDG.h>
12 #include <TMath.h>
13 #include <TParticlePDG.h>
14 #include <TRandom.h>
15 
16 #include <cmath>
17 #include <cstdio>
18 #include <memory>
19 
21  : fPDGType(0), fMult(0), fPDGMass(0), fPtMin(0), fPtMax(0), fPhiMin(0), fPhiMax(0), fEtaMin(0), fEtaMax(0), fYMin(0),
22  fYMax(0), fPMin(0), fPMax(0), fThetaMin(0), fThetaMax(0), fX(0), fY(0), fZ(0), fX1(0), fY1(0), fZ1(0), fX2(0),
23  fY2(0), fZ2(0), fEtaRangeIsSet(false), fYRangeIsSet(false), fThetaRangeIsSet(false), fCosThetaIsSet(false),
24  fPtRangeIsSet(false), fPRangeIsSet(false), fPointVtxIsSet(false), fBoxVtxIsSet(false), fDebug(false),
25  fGammasDefinedInNuclearDecay(0), fBetaOfEmittingFragment(0), fGammaFactor(1), fLorentzBoostIsSet(false),
26  fNuclearDecayChainIsSet(false)
27 {
28  // Default constructor
29 }
30 
32  : fPDGType(pdgid), fMult(mult), fPDGMass(0), fPtMin(0), fPtMax(0), fPhiMin(0), fPhiMax(0), fEtaMin(0), fEtaMax(0),
33  fYMin(0), fYMax(0), fPMin(0), fPMax(0), fThetaMin(0), fThetaMax(0), fX(0), fY(0), fZ(0), fX1(0), fY1(0), fZ1(0),
34  fX2(0), fY2(0), fZ2(0), fEtaRangeIsSet(false), fYRangeIsSet(false), fThetaRangeIsSet(false), fCosThetaIsSet(false),
35  fPtRangeIsSet(false), fPRangeIsSet(false), fPointVtxIsSet(false), fBoxVtxIsSet(false), fDebug(false),
36  fGammasDefinedInNuclearDecay(0), fBetaOfEmittingFragment(0), fGammaFactor(1), fLorentzBoostIsSet(false),
37  fNuclearDecayChainIsSet(false)
38 {
39  // Constructor. Set default kinematics limits
40  SetPhiRange();
41 }
42 
44 
46 {
47  // Initialize generator
48 
49  if (fPhiMax - fPhiMin > 360)
50  LOG(fatal) << "Init(): AtTPCGammaDummyGenerator: phi range is too wide: " << fPhiMin << "<phi<" << fPhiMax;
51  if (fPRangeIsSet && fPtRangeIsSet)
52  LOG(fatal) << "Init(): AtTPCGammaDummyGenerator: Cannot set P and Pt ranges simultaneously";
53  if (fPRangeIsSet && fYRangeIsSet)
54  LOG(fatal) << "Init(): AtTPCGammaDummyGenerator: Cannot set P and Y ranges simultaneously";
55  if ((fThetaRangeIsSet && fYRangeIsSet) || (fThetaRangeIsSet && fEtaRangeIsSet) || (fYRangeIsSet && fEtaRangeIsSet))
56  LOG(fatal) << "Init(): AtTPCGammaDummyGenerator: Cannot set Y, Theta or Eta ranges simultaneously";
57  if (fPointVtxIsSet && fBoxVtxIsSet)
58  LOG(fatal) << "Init(): AtTPCGammaDummyGenerator: Cannot set point and box vertices simultaneously";
59 
60  // APOLLO specifics
61  if (fBetaOfEmittingFragment > 1)
62  LOG(fatal) << "Init(): AtTPCGammaDummyGenerator: beta of fragment larger than 1!";
63 
64  Double32_t sumBranchingRatios = 0;
65  for (Int_t i = 0; i < fGammasDefinedInNuclearDecay; i++) {
66  if (fGammaBranchingRatios[i] > 1)
67  LOG(fatal) << "Init(): AtTPCGammaDummyGenerator: gamma branching ratio in position " << i << " larger than 1!";
68  sumBranchingRatios += fGammaBranchingRatios[i];
69  }
70  if (sumBranchingRatios > 1)
71  LOG(fatal) << "Init(): AtTPCGammaDummyGenerator: gamma branching ratio sum larger than 1!";
72 
73  // Check for particle type
74  TDatabasePDG *pdgBase = TDatabasePDG::Instance();
75  TParticlePDG *particle = pdgBase->GetParticle(fPDGType);
76  if (!particle)
77  LOG(fatal) << "AtTPCGammaDummyGenerator: PDG code " << fPDGType << " not defined.";
78  fPDGMass = particle->Mass(); // NOLINT
79  return kTRUE;
80 }
81 
82 Bool_t AtTPCGammaDummyGenerator::ReadEvent(FairPrimaryGenerator *primGen)
83 {
84  // Generate one event: produce primary particles emitted from one vertex.
85  // Primary particles are distributed uniformly along
86  // those kinematics variables which were limitted by setters.
87  // if SetCosTheta() function is used, the distribution will be uniform in
88  // cos(theta)
89 
90  Double32_t pabs = 0, phi, pt = 0, theta = 0, eta, y, mt, px, py, pz = 0;
91  Double32_t br = 0;
92  Bool_t doNotBoost = false;
93 
94  // Generate particles
95  for (Int_t k = 0; k < fMult; k++) {
96  phi = gRandom->Uniform(fPhiMin, fPhiMax) * TMath::DegToRad();
97 
98  if (fPRangeIsSet)
99  pabs = gRandom->Uniform(fPMin, fPMax);
100  else if (fPtRangeIsSet)
101  pt = gRandom->Uniform(fPtMin, fPtMax);
102 
103  if (fThetaRangeIsSet) {
104  if (fCosThetaIsSet)
105  theta = acos(gRandom->Uniform(cos(fThetaMin * TMath::DegToRad()), cos(fThetaMax * TMath::DegToRad())));
106  else
107  theta = gRandom->Uniform(fThetaMin, fThetaMax) * TMath::DegToRad();
108  } else if (fEtaRangeIsSet) {
109  eta = gRandom->Uniform(fEtaMin, fEtaMax);
110  theta = 2 * TMath::ATan(TMath::Exp(-eta));
111  } else if (fYRangeIsSet) {
112  y = gRandom->Uniform(fYMin, fYMax);
113  mt = TMath::Sqrt(fPDGMass * fPDGMass + pt * pt);
114  pz = mt * TMath::SinH(y);
115  }
116 
117  if (fThetaRangeIsSet || fEtaRangeIsSet) {
118  if (fPRangeIsSet) {
119  pz = pabs * TMath::Cos(theta);
120  pt = pabs * TMath::Sin(theta);
121  } else if (fPtRangeIsSet)
122  pz = pt / TMath::Tan(theta);
123  }
124 
125  px = pt * TMath::Cos(phi);
126  py = pt * TMath::Sin(phi);
127 
128  if (fBoxVtxIsSet) {
129  fX = gRandom->Uniform(fX1, fX2);
130  fY = gRandom->Uniform(fY1, fY2);
131  fZ = gRandom->Uniform(fZ1, fZ2);
132  }
133 
134  if (fNuclearDecayChainIsSet) {
135  if (fPDGType != 22)
136  LOG(fatal) << "AtTPCGammaDummyGenerator: PDG code " << fPDGType << " is not a gamma!";
137  br = gRandom->Uniform();
138  for (Int_t i = 0; i < fGammasDefinedInNuclearDecay; i++) {
139  if (br < fGammaBranchingRatios[i]) {
140  Double32_t gammaMomentum = TMath::Sqrt(px * px + py * py + pz * pz);
141  px = px * fGammaEnergies[i] / gammaMomentum;
142  py = py * fGammaEnergies[i] / gammaMomentum;
143  pz = pz * fGammaEnergies[i] / gammaMomentum;
144  break;
145  } else
146  br = br - fGammaBranchingRatios[i];
147  }
148  // if Sum(branchingRatios)<1, the leftover probability (up to 1) is defined as environmental noise
149  doNotBoost = true;
150  }
151  /*
152  if (fLorentzBoostIsSet && !doNotBoost){
153 
154  //Lorentz transformation Pz(lab) = gamma * Pz(cm) + gamma * beta * E
155  //As each Lorentz transformation can be performed sequencially,
156  //we can separate the gamma factor corresponding to each direction
157  Double32_t gammaMomentum=TMath::Sqrt(px*px+py*py+pz*pz);
158  pz = (pz + fBetaOfEmittingFragment * gammaMomentum) / fGammaFactor;
159  */
160 
161  if (fPDGType == 22 && fLorentzBoostIsSet && !doNotBoost) {
162  // Lorentz transformation Pz(lab) = gamma * Pz(cm) + gamma * beta * E
163  // As each Lorentz transformation can be performed sequencially,
164  // we can separate the gamma factor corresponding to each direction
165  Double32_t gammaMomentum = TMath::Sqrt(px * px + py * py + pz * pz);
166  pz = (pz + fBetaOfEmittingFragment * gammaMomentum) / fGammaFactor;
167  } else if (fLorentzBoostIsSet && !doNotBoost) {
168  // Lorentz transformation Pz(lab) = gamma * Pz(cm) + gamma * beta * E
169  // As each Lorentz transformation can be performed sequencially,
170  // we can separate the gamma factor corresponding to each direction
171  Double32_t particleEnergy = TMath::Sqrt(px * px + py * py + pz * pz + fPDGMass * fPDGMass);
172  pz = (pz + fBetaOfEmittingFragment * particleEnergy) / fGammaFactor;
173  }
174 
175  if (fDebug)
176  printf("CALIFAtestGen: kf=%d, p=(%.2f, %.2f, %.2f) GeV, x=(%.1f, %.1f, %.1f) cm\n", fPDGType, px, py, pz, fX,
177  fY, fZ);
178 
179  primGen->AddTrack(fPDGType, px, py, pz, fX, fY, fZ);
180  }
181  return kTRUE;
182 }
183 
185 {
186  // Sets the velocity and gamma factor of the fragment emitting the gammas
187  fBetaOfEmittingFragment = beta;
188  fGammaFactor = TMath::Sqrt(1 - fBetaOfEmittingFragment * fBetaOfEmittingFragment);
189 }
190 
191 void AtTPCGammaDummyGenerator::SetDecayChainPoint(Double32_t gammaEnergy, Double32_t branchingRatio)
192 {
193  //
194  //
195  //
196  if (fGammasDefinedInNuclearDecay > 7)
197  printf("CALIFAtestGen: Maximum number (8) of gammas defined in the chain\n");
198  else {
199  fGammaEnergies[fGammasDefinedInNuclearDecay] = gammaEnergy;
200  fGammaBranchingRatios[fGammasDefinedInNuclearDecay] = branchingRatio;
201  fGammasDefinedInNuclearDecay++;
202  }
203 }
204 
AtTPCGammaDummyGenerator::AtTPCGammaDummyGenerator
AtTPCGammaDummyGenerator()
Definition: AtTPCGammaDummyGenerator.cxx:20
AtTPCGammaDummyGenerator::SetPhiRange
void SetPhiRange(Double32_t phimin=0, Double32_t phimax=360)
Definition: AtTPCGammaDummyGenerator.h:54
AtTPCGammaDummyGenerator.h
ClassImp
ClassImp(AtFindVertex)
AtTPCGammaDummyGenerator::ReadEvent
virtual Bool_t ReadEvent(FairPrimaryGenerator *primGen)
Definition: AtTPCGammaDummyGenerator.cxx:82
y
const double * y
Definition: lmcurve.cxx:20
AtTPCGammaDummyGenerator::SetFragmentVelocity
void SetFragmentVelocity(Double32_t beta=0)
Definition: AtTPCGammaDummyGenerator.cxx:184
AtTPCGammaDummyGenerator::~AtTPCGammaDummyGenerator
virtual ~AtTPCGammaDummyGenerator()
AtTPCGammaDummyGenerator::Init
virtual Bool_t Init()
Definition: AtTPCGammaDummyGenerator.cxx:45
AtTPCGammaDummyGenerator
Definition: AtTPCGammaDummyGenerator.h:19
AtTPCGammaDummyGenerator::SetDecayChainPoint
void SetDecayChainPoint(Double32_t gammaEnergy=0, Double32_t branchingRatio=0)
Definition: AtTPCGammaDummyGenerator.cxx:191