er  dev
ERIonMixGenerator.cxx
1 /********************************************************************************
2  * Copyright (C) Joint Institute for Nuclear Research *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence version 3 (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 
9 #include "ERIonMixGenerator.h"
10 
11 #include <stdio.h> // for NULL, sprintf
12 #include <algorithm>
13 
14 #include <iosfwd> // for ostream
15 #include "TDatabasePDG.h" // for TDatabasePDG
16 #include "TObjArray.h" // for TObjArray
17 #include "TParticle.h" // for TParticle
18 #include "TParticlePDG.h" // for TParticlePDG
19 #include "TRandom.h"
20 #include "TMath.h"
21 
22 #include "FairIon.h" // for FairIon
23 #include "FairParticle.h" // for FairParticle
24 #include "FairPrimaryGenerator.h" // for FairPrimaryGenerator
25 #include "FairRunSim.h" // for FairRunSim
26 #include "FairLogger.h" // for logging
27 //-------------------------------------------------------------------------------------------------
29  : ERIonGenerator()
30 {
31 // LOG(WARNING) << "ERIonMixGenerator: "
32 // << " Please do not use the default constructor! "
33 // << FairLogger::endl;
34 }
35 //-------------------------------------------------------------------------------------------------
36 ERIonMixGenerator::ERIonMixGenerator(TString name, Int_t z, Int_t a, Int_t q, Int_t mult)
37  : ERIonGenerator(name, z, a, q, mult)
38 {
39  fBgIons.clear();
40 }
41 //-------------------------------------------------------------------------------------------------
43 {
44 // if (fIon) delete fIon;
45 }
46 //-------------------------------------------------------------------------------------------------
47 void ERIonMixGenerator::AddBackgroundIon(TString name, Int_t z, Int_t a, Int_t q, Double_t newIonProb)
48 {
49  SetPhiRange();
50 
51  if(fBgIons.size() == 0) {
52  fSumProbability = 0;
53  }
54  fSumProbability += newIonProb;
55  fBgIons.insert(std::make_pair(fSumProbability, name));
56  LOG(DEBUG) << "Prob " << fSumProbability << FairLogger::endl;
57  FairRunSim* run = FairRunSim::Instance();
58  if ( ! run ) {
59  LOG(ERROR) << "No FairRun instantised!"
60  << FairLogger::endl;
61  } else {
62  run->AddNewIon(new FairIon(name, z, a, q));
63  }
64 }
65 //-------------------------------------------------------------------------------------------------
66 Bool_t ERIonMixGenerator::ReadEvent(FairPrimaryGenerator* primGen)
67 {
68  Double_t randResult;
69  TString ionName;
70  Double_t rigidityMin;
71  Double_t rigidityMax;
72  Double_t gausRigidity, sigmaRigidity;
73  Double_t pMin = fPMin, pMax = fPMax;
74  Double_t pGaus = fGausP;
75  Double_t pSigma = fSigmaP;
76  // Generate particles
77  for (Int_t k = 0; k < fMult; k++) {
78 
79  randResult = gRandom->Uniform(0., 1.) * (fSumProbability + 1);
80 
81  auto it = std::find_if(fBgIons.begin(), fBgIons.end(),
82  [randResult](const std::pair<Double_t, TString> &t)->bool
83  {
84  return (t.first > randResult);
85  }
86  );
87  (it == fBgIons.end()) ? ionName = fIon->GetName() : ionName = it->second;
88 
89  TParticlePDG* thisPart =
90  TDatabasePDG::Instance()->GetParticle(ionName);
91  if ( ! thisPart ) {
92  LOG(WARNING) << "ERIonGenerator: Ion " << ionName
93  << " not found in database!" << FairLogger::endl;
94  return kFALSE;
95  }
96 
97  Double_t charge = thisPart->Charge();
98 
99  if(fPRangeIsSet) {
100  rigidityMin = pMin / fIon->GetZ() / 3;
101  rigidityMax = pMax / fIon->GetZ() / 3;
102  fPMin = rigidityMin * charge;
103  fPMax = rigidityMax * charge;
104  }
105 
106  if(fSigmaPIsSet) {
107  gausRigidity = pGaus / fIon->GetZ() / 3;
108  sigmaRigidity = fSigmaP / fIon->GetZ() / 3;
109  fGausP = gausRigidity * charge;
110  fSigmaP = sigmaRigidity * charge;
111  }
112  LOG(DEBUG) << "Pmin " << fPMin << " Pmax " << fPMax << " GausP " << fGausP << FairLogger::endl;
113 
115  int pdgType = thisPart->PdgCode();
116 
117  LOG(DEBUG) << "ERIonGenerator: Generating " << fMult << " ions of type "
118  << ionName << " (PDG code " << pdgType << ")"
119  << FairLogger::endl;
120  LOG(DEBUG) << " Momentum (" << fPx << ", " << fPy << ", " << fPz
121  << ") Gev from vertex (" << fX << ", " << fY
122  << ", " << fZ << ") cm" << FairLogger::endl;
123  primGen->AddTrack(pdgType, fPx, fPy, fPz, fX, fY, fZ);
124  }
125  fGausP = pGaus;
126  fPMin = pMin;
127  fPMax = pMax;
128  fSigmaP = pSigma;
129  return kTRUE;
130 }
131 //-------------------------------------------------------------------------------------------------
132 ClassImp(ERIonMixGenerator)
Double32_t fGausP
Amplitude value of momentum in Gauss distibution [GeV].
std::map< Double_t, TString > fBgIons
Background ion names with emegence probability.
Int_t fMult
Multiplicity per event.
Double32_t fZ
Point vertex coordinates [cm].
Bool_t fPRangeIsSet
True if abs momentum range is set.
Double_t fSumProbability
Background ions summary probability.
virtual ~ERIonMixGenerator()
Destructor.
Bool_t ReadEvent(FairPrimaryGenerator *primGen)
Method ReadEvent Generates <mult> of the specified ions and hands hem to the FairPrimaryGenerator.
FairIon * fIon
Pointer to the FairIon to be generated.
Class for the generation different ions during one simulation.
void SpreadingParameters(void)
Spreads parameters recieved by accessor methods.
Double32_t fPz
Momentum projection [GeV].
void AddBackgroundIon(TString name, Int_t z, Int_t a, Int_t q, Double_t newIonProb)
Adds background ions with probability of appearance in simulation. Probability of primary ion is 1...
Double32_t fPMax
Momentum range in lab system.
void SetPhiRange(Double32_t phimin=0, Double32_t phimax=360)
Defines uniform distribution boundaries of ion azimuth angle[degree].
Double32_t fSigmaP
Momentum normal deviation [GeV].
Class for the generation ion.
Bool_t fSigmaPIsSet
True if Gauss distribution for momentum is set.