ATTPCROOT  0.3.0-alpha
A ROOT-based framework for analyzing data from active target detectors
AtTPCIonGeneratorS800.cxx
Go to the documentation of this file.
2 
3 #include "AtVertexPropagator.h"
4 
5 #include <FairLogger.h>
6 
7 #include <TFile.h>
8 #include <TMath.h>
9 #include <TObject.h> // for TObject
10 #include <TRandom.h>
11 
12 #include <cmath> // for tan, sqrt, pow, atan, fabs
13 
15 
17 
18 AtTPCIonGeneratorS800::AtTPCIonGeneratorS800(const char *name, Int_t z, Int_t a, Int_t q, Int_t mult, Double_t px,
19  Double_t py, Double_t pz, Double_t Ex, Double_t m, Double_t ener,
20  Double_t eLoss, TString sata, TString sbta)
21  : AtTPCIonGenerator(name, z, a, q, mult, px, py, pz, Ex, m, eLoss), fAta(nullptr), fBta(nullptr)
22 
23 {
24 
25  TFile fileAta(sata, "READ");
26  TFile fileBta(sbta, "READ");
27  if (fileAta.IsZombie() || fileBta.IsZombie())
28  LOG(error) << "AtTPCIonGenerator - ata and bta distribution files (S800) not found";
29  else {
30  fAta = std::unique_ptr<TH1F>(dynamic_cast<TH1F *>(fileAta.Get("h")));
31  fBta = std::unique_ptr<TH1F>(dynamic_cast<TH1F *>(fileBta.Get("h1")));
32  fAta->SetDirectory(nullptr);
33  fBta->SetDirectory(nullptr);
34  }
35 
36  fPx0 = a * px;
37  fPy0 = a * py;
38  fPz0 = a * pz;
39 }
40 
41 void AtTPCIonGeneratorS800::SetBeamEmittance(Double32_t val1, Double32_t val2, Double32_t val3, Double32_t val4,
42  Double_t val5, Double_t val6, Double_t val7, Double_t val8, Double_t val9)
43 {
44  fWhmFocus = val1;
45  fDiv = val2;
46  fZFocus = val3;
47  fRHole = val4;
48  fMomAcc = val5;
49  fBeamAx = val6;
50  fBeamAy = val7;
51  fBeamOx = val8;
52  fBeamOy = val9;
53 }
54 
56 {
57  // TStopwatch timer;
58  // timer.Start();
59  gRandom->SetSeed(0);
60  Double_t x = 0., y = 0., xFocus = 0., yFocus = 0., Ax = 0., Ay = 0., BeamAx = 0., BeamAy = 0., BeamOx = 0.,
61  BeamOy = 0.;
62  Double_t ptot = sqrt(pow(fPx0, 2) + pow(fPy0, 2) + pow(fPz0, 2));
63  // ptot=gRandom->Uniform(ptot*(1.-fMomAcc),ptot*(1.+fMomAcc));
64  // following "do wile" for gaussian beam momentum distribution with boundaries
65  do {
66  ptot = gRandom->Gaus(ptot, ptot * fMomAcc / 2.355);
67  } while (ptot < ptot * (1. - 2. * fMomAcc) || ptot > ptot * (1. + 2. * fMomAcc));
68  BeamAx = fBeamAx * TMath::DegToRad();
69  BeamAy = fBeamAy * TMath::DegToRad();
70 
71  // x is a coordinate of beam particle at ATTPC entrance, xFocus is a coordinate at focus.
72  do {
73  xFocus = gRandom->Gaus(fBeamOx, fWhmFocus / 2.355) + fZFocus * tan(BeamAx);
74  yFocus = gRandom->Gaus(fBeamOy, fWhmFocus / 2.355) + fZFocus * tan(BeamAy);
75  } // beam spot smaller than the entrance hole
76  while (sqrt(pow((xFocus - fZFocus * tan(BeamAx)), 2) + pow((yFocus - fZFocus * tan(BeamAy)), 2)) > fRHole);
77 
78  if (fAta != nullptr && fBta != nullptr) { // with ata and bta distributions from S800 data
79  do {
80  Ax = fAta->GetRandom() + 0.0019; // offset between angle of the beam in tpc frame and S800 frame,
81  // Ax = fAta.GetRandom() + 0.0019; // offset between angle of the beam in tpc frame and S800 frame,
82  //(+) because angle more negative in S800 frame than in TPC frame. Needs to correct back this offset in this
83  // analysis
84  Ay = fBta->GetRandom();
85  // Ay = fBta.GetRandom();
86  x = xFocus - fZFocus * tan(Ax);
87  y = yFocus - fZFocus * tan(Ay);
88  } // beam at entrance smaller than the hole
89  while (sqrt(pow(x, 2) + pow(y, 2)) > fRHole);
90  } else {
91  do {
92  x = gRandom->Gaus(fBeamOx, fWhmFocus / 2.355 + fZFocus * tan(fDiv));
93  y = gRandom->Gaus(fBeamOy, fWhmFocus / 2.355 + fZFocus * tan(fDiv));
94  Ax = atan((xFocus - x) / fZFocus);
95  Ay = atan((yFocus - y) / fZFocus);
96  } while (sqrt(pow(x, 2) + pow(y, 2)) > fRHole ||
97  sqrt(pow(tan(Ax - BeamAx), 2) + pow(tan(Ay - BeamAy), 2)) > fabs(tan(fDiv)));
98  }
99 
100  fVx = x;
101  fVy = y;
102  fVz = 0.;
103 
104  // std::cout<<"ATTPCIonGenerator beam X,Y at entrance "<<x<<" "<<y<<" at focus "<<xFocus<<" "<<yFocus<<std::endl;
105 
106  fPz = ptot / sqrt(1. + pow(tan(Ax), 2) + pow(tan(Ay), 2));
107  fPx = fPz * tan(Ax);
108  fPy = fPz * tan(Ay);
109 
111 
112  // timer.Stop();
113  // Double_t rtime = timer.RealTime();
114  // Double_t ctime = timer.CpuTime();
115 
116  // std::cout << "Real time " << rtime << " s, CPU time " << ctime << "s" <<std::endl;
117 }
AtTPCIonGeneratorS800::fAta
std::unique_ptr< TH1F > fAta
beam angles distributions in dispersive and non dispersive direction(respectively to S800)[rad]
Definition: AtTPCIonGeneratorS800.h:26
AtTPCIonGeneratorS800::fBta
std::unique_ptr< TH1F > fBta
Definition: AtTPCIonGeneratorS800.h:26
AtTPCIonGeneratorS800::fRHole
Double32_t fRHole
Definition: AtTPCIonGeneratorS800.h:28
AtTPCIonGeneratorS800::SetVertexCoordinates
virtual void SetVertexCoordinates() override
Sets fVx, fVy, fVz depending on the type of ion generator.
Definition: AtTPCIonGeneratorS800.cxx:55
AtTPCIonGenerator::fPx
Double_t fPx
Definition: AtTPCIonGenerator.h:26
AtTPCIonGeneratorS800::fBeamOx
Double_t fBeamOx
Definition: AtTPCIonGeneratorS800.h:24
AtTPCIonGeneratorS800::fDiv
Double32_t fDiv
Definition: AtTPCIonGeneratorS800.h:28
AtTPCIonGeneratorS800::fBeamOy
Double_t fBeamOy
Definition: AtTPCIonGeneratorS800.h:24
AtTPCIonGenerator::fPz
Double_t fPz
Definition: AtTPCIonGenerator.h:26
AtTPCIonGeneratorS800::fZFocus
Double32_t fZFocus
Definition: AtTPCIonGeneratorS800.h:28
AtTPCIonGeneratorS800::fBeamAy
Double_t fBeamAy
Definition: AtTPCIonGeneratorS800.h:23
AtTPCIonGeneratorS800
Definition: AtTPCIonGeneratorS800.h:16
AtTPCIonGeneratorS800::fPz0
Double_t fPz0
Definition: AtTPCIonGeneratorS800.h:20
AtVertexPropagator::Setd2HeVtx
void Setd2HeVtx(TVector3 val)
Definition: AtVertexPropagator.cxx:169
AtTPCIonGeneratorS800::fPx0
Double_t fPx0
Definition: AtTPCIonGeneratorS800.h:20
y
const double * y
Definition: lmcurve.cxx:20
AtTPCIonGenerator::fVz
Double_t fVz
Definition: AtTPCIonGenerator.h:29
AtVertexPropagator.h
ClassImp
ClassImp(AtTPCIonGeneratorS800)
AtTPCIonGeneratorS800::fBeamAx
Double_t fBeamAx
Definition: AtTPCIonGeneratorS800.h:23
AtTPCIonGenerator::fPy
Double_t fPy
Definition: AtTPCIonGenerator.h:26
AtTPCIonGeneratorS800::AtTPCIonGeneratorS800
AtTPCIonGeneratorS800()
Definition: AtTPCIonGeneratorS800.cxx:16
AtTPCIonGenerator::fVx
Double_t fVx
Definition: AtTPCIonGenerator.h:29
AtTPCIonGenerator
Definition: AtTPCIonGenerator.h:22
AtTPCIonGenerator::fVy
Double_t fVy
Definition: AtTPCIonGenerator.h:29
AtTPCIonGeneratorS800.h
AtTPCIonGeneratorS800::fPy0
Double_t fPy0
Definition: AtTPCIonGeneratorS800.h:20
AtTPCIonGeneratorS800::fWhmFocus
Double32_t fWhmFocus
Beam whm at focus, beam divergence, z focus, radius of the pad plan hole.
Definition: AtTPCIonGeneratorS800.h:28
AtVertexPropagator::Instance
static AtVertexPropagator * Instance()
Definition: AtVertexPropagator.cxx:18
AtTPCIonGeneratorS800::SetBeamEmittance
void SetBeamEmittance(Double32_t val1=0, Double32_t val2=0, Double32_t val3=0, Double32_t val4=0, Double_t val5=0, Double_t val6=0, Double_t val7=0, Double_t val8=0, Double_t val9=0)
Definition: AtTPCIonGeneratorS800.cxx:41
AtTPCIonGeneratorS800::fMomAcc
Double_t fMomAcc
Definition: AtTPCIonGeneratorS800.h:22