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

#include <HNLPythia8Generator.h>

Inheritance diagram for HNLPythia8Generator:
Collaboration diagram for HNLPythia8Generator:

Public Member Functions

 HNLPythia8Generator ()
 
 ~HNLPythia8Generator () override
 
Bool_t ReadEvent (FairPrimaryGenerator *) override
 
void SetParameters (char *)
 
void Print ()
 
void List (int id)
 
Bool_t Init (const char *inFile) override
 
Bool_t Init (const char *inFile, int startEvent) override
 
Bool_t Init () override
 
void SetMom (Double_t mom)
 
void SetId (Double_t id)
 
void SetHNLId (Int_t id)
 
void SetLmin (Double_t z)
 
void SetLmax (Double_t z)
 
void SetSmearBeam (Double_t sb)
 
void SetPaintRadius (Double_t r)
 
void SetfFDs (Double_t z)
 
void UseRandom1 ()
 
void UseRandom3 ()
 
void UseDeepCopy ()
 
Int_t nrOfRetries ()
 
Pythia8::Pythia * getPythiaInstance ()
 
- Public Member Functions inherited from SHiP::Generator
 Generator ()
 
virtual ~Generator ()
 
virtual Bool_t Init (const char *, int)=0
 
virtual Bool_t Init (const char *)=0
 
virtual Bool_t Init (const std::vector< std::string > &inFiles, int startNumber)
 
virtual Bool_t Init (const std::vector< std::string > &inFiles)
 
virtual void UseExternalFile (std::string x, Int_t i)
 
virtual void UseExternalFile (std::vector< std::string > &inFiles, Int_t i)
 

Public Attributes

Pythia8::Pythia * fPythia
 

Protected Attributes

Double_t fMom
 
Int_t fHNL
 
Int_t fId
 
Bool_t fUseRandom1
 
Bool_t fUseRandom3
 
Double_t fLmin
 
Double_t fLmax
 
Int_t fnRetries
 
Double_t fctau
 
Double_t fFDs
 
Double_t fsmearBeam
 
Double_t fPaintBeam
 
TFile * fInputFile
 
TTree * fTree
 pointer to a file
 
Int_t fNevents
 
Int_t fn
 
Int_t fShipEventNr
 
Float_t hpx [1]
 
Float_t hpy [1]
 
Float_t hpz [1]
 
Float_t hE [1]
 
Float_t hM [1]
 
Float_t mpx [1]
 
Float_t mpy [1]
 
Float_t mpz [1]
 
Float_t mE [1]
 
Float_t hid [1]
 
Float_t mid [1]
 
Bool_t fDeepCopy
 
FairLogger * fLogger
 
- Protected Attributes inherited from SHiP::Generator
std::optional< std::string > fextFile
 
Int_t firstEvent = 0
 

Private Attributes

std::shared_ptr< Pythia8::RndmEngine > fRandomEngine
 

Detailed Description

Definition at line 42 of file HNLPythia8Generator.h.

Constructor & Destructor Documentation

◆ HNLPythia8Generator()

HNLPythia8Generator::HNLPythia8Generator ( )

default constructor

Definition at line 23 of file HNLPythia8Generator.cxx.

23 {
24 fId = 2212; // proton
25 fMom = 400; // proton
26 fHNL = 9900015; // HNL pdg code
27 fLmin = 5000. * cm; // mm minimum decay position z ROOT units !
28 fLmax = 12000. * cm; // mm maximum decay position z
29 fFDs = 7.7 / 10.4; // correction for Pythia6 to match measured Ds production
30 fsmearBeam = 8 * mm; // default value for smearing beam (8 mm)
31 fPaintBeam = 5 * cm; // default value for painting beam (5 cm)
32 fInputFile = nullptr;
33 fnRetries = 0;
34 fShipEventNr = 0;
35 fPythia = new Pythia8::Pythia();
36}
Double_t cm
Double_t mm
Pythia8::Pythia * fPythia

◆ ~HNLPythia8Generator()

HNLPythia8Generator::~HNLPythia8Generator ( )
override

destructor

Definition at line 94 of file HNLPythia8Generator.cxx.

94{}

Member Function Documentation

◆ getPythiaInstance()

Pythia8::Pythia * HNLPythia8Generator::getPythiaInstance ( )
inline

Definition at line 90 of file HNLPythia8Generator.h.

90{ return fPythia; };

◆ Init() [1/3]

Bool_t HNLPythia8Generator::Init ( )
override

Definition at line 40 of file HNLPythia8Generator.cxx.

40 {
41 if (debug) {
42 List(9900015);
43 }
44 if (fUseRandom1) fRandomEngine = std::make_shared<PyTr1Rng>();
45 if (fUseRandom3) fRandomEngine = std::make_shared<PyTr3Rng>();
46 fPythia->setRndmEnginePtr(fRandomEngine);
47 fn = 0;
48 if (fextFile) {
49 fInputFile = TFile::Open(fextFile->c_str());
50 LOG(info) << "Open external file with charm or beauty hadrons: "
51 << *fextFile;
52 if (!fInputFile) {
53 LOG(fatal) << "Error opening input file.";
54 return kFALSE;
55 }
56
57 fTree = fInputFile->Get<TTree>("pythia6");
58 fNevents = fTree->GetEntries();
59 fn = firstEvent;
60 fTree->SetBranchAddress("id", &hid); // particle id
61 fTree->SetBranchAddress("px", &hpx); // momentum
62 fTree->SetBranchAddress("py", &hpy);
63 fTree->SetBranchAddress("pz", &hpz);
64 fTree->SetBranchAddress("E", &hE);
65 fTree->SetBranchAddress("M", &hM);
66 fTree->SetBranchAddress("mid", &mid); // mother
67 fTree->SetBranchAddress("mpx", &mpx); // momentum
68 fTree->SetBranchAddress("mpy", &mpy);
69 fTree->SetBranchAddress("mpz", &mpz);
70 fTree->SetBranchAddress("mE", &mE);
71 } else {
72 LOG(debug) << "Beam Momentum " << fMom;
73 fPythia->settings.mode("Beams:idA", fId);
74 fPythia->settings.mode("Beams:idB", 2212);
75 fPythia->settings.mode("Beams:frameType", 2);
76 fPythia->settings.parm("Beams:eA", fMom); // codespell:ignore parm
77 fPythia->settings.parm("Beams:eB", 0.); // codespell:ignore parm
78 }
79 TDatabasePDG* pdgBase = TDatabasePDG::Instance();
80 Double_t root_ctau = pdgBase->GetParticle(fHNL)->Lifetime();
81 fctau = fPythia->particleData.tau0(fHNL); //* 3.3333e-12
82 LOG(debug) << "tau root " << root_ctau
83 << "[s] ctau root = " << root_ctau * 3e10 << "[cm]";
84 LOG(debug) << "ctau pythia " << fctau << "[mm]";
85 if (debug) {
86 List(9900015);
87 }
88 fPythia->init();
89 return kTRUE;
90}
const Int_t debug
TTree * fTree
pointer to a file
std::shared_ptr< Pythia8::RndmEngine > fRandomEngine
std::optional< std::string > fextFile
Definition: Generator.h:47
Int_t firstEvent
Definition: Generator.h:48

◆ Init() [2/3]

Bool_t HNLPythia8Generator::Init ( const char *  inFile)
inlineoverridevirtual

Implements SHiP::Generator.

Definition at line 58 of file HNLPythia8Generator.h.

58{ return Init(inFile, 0); };
Bool_t Init() override

◆ Init() [3/3]

Bool_t HNLPythia8Generator::Init ( const char *  inFile,
int  startEvent 
)
inlineoverridevirtual

Implements SHiP::Generator.

Definition at line 60 of file HNLPythia8Generator.h.

60 {
61 LOG(warning) << "Init with files not implemented for HNLPythia8Generator. "
62 "Using default Init() instead";
63 return Init();
64 };

◆ List()

void HNLPythia8Generator::List ( int  id)
inline

Definition at line 54 of file HNLPythia8Generator.h.

54{ fPythia->particleData.list(id); };

◆ nrOfRetries()

Int_t HNLPythia8Generator::nrOfRetries ( )
inline

Definition at line 89 of file HNLPythia8Generator.h.

89{ return fnRetries; };

◆ Print()

void HNLPythia8Generator::Print ( )
inline

Definition at line 53 of file HNLPythia8Generator.h.

53{ fPythia->settings.listAll(); };

◆ ReadEvent()

Bool_t HNLPythia8Generator::ReadEvent ( FairPrimaryGenerator *  cpg)
override

public method ReadEvent

Definition at line 98 of file HNLPythia8Generator.cxx.

98 {
99 Double_t tp, tS, zp, xp, yp, zS, xS, yS, pz, px, py, e, w;
100 Double_t tm, zm, xm, ym, pmz, pmx, pmy, em;
101 Int_t im;
102 // take HNL decay of Pythia, move it to the SHiP decay region
103 // recalculate decay time
104 // weight event with exp(-t_ship/tau_HNL) / exp(-t_pythia/tau_HNL)
105
106 int iHNL = 0; // index of the chosen HNL (the 1st one), also ensures that at
107 // least 1 HNL is produced
108 std::vector<int>
109 dec_chain; // pythia indices of the particles to be stored on the stack
110 std::vector<int> hnls; // pythia indices of HNL particles
111 do {
112 if (fextFile) {
113 // take charm or beauty hadron from external file
114 // correct for too much Ds produced by pythia6
115 bool x = true;
116 while (x) {
117 if (fn == fNevents) {
118 LOG(warning) << "End of input file. Rewind.";
119 }
120 fTree->GetEntry(fn % fNevents);
121 fn++;
122 if (static_cast<int>(fabs(hid[0])) != 431) {
123 x = false;
124 } else {
125 Double_t rnr = gRandom->Uniform(0, 1);
126 if (rnr < fFDs) {
127 x = false;
128 };
129 // cout<<"what is x "<<x<<" id "<<int(fabs(hid[0]))<<" rnr " << rnr
130 // <<" "<< fFDs <<std::endl ;
131 }
132 }
133 fPythia->event.reset();
134 fPythia->event.append((Int_t)hid[0], 1, 0, 0, hpx[0], hpy[0], hpz[0],
135 hE[0], hM[0], 0., 9.);
136 }
137 fPythia->next();
138 for (int i = 0; i < fPythia->event.size(); i++) {
139 // find first HNL
140 if (abs(fPythia->event[i].id()) == fHNL) {
141 hnls.push_back(i);
142 }
143 }
144 iHNL = hnls.size();
145 if (iHNL == 0) {
146 // fLogger->Info(MESSAGE_ORIGIN,"Event without HNL. Retry.");
147 // fPythia->event.list();
148 fnRetries += 1; // can happen if phasespace does not allow charm hadron
149 // to decay to HNL
150 } else {
151 int r = static_cast<int>(gRandom->Uniform(0, iHNL));
152 // cout << " ----> debug 2 " << r << endl;
153 int i = hnls[r];
154 // production vertex
155 zp = fPythia->event[i].zProd();
156 xp = fPythia->event[i].xProd();
157 yp = fPythia->event[i].yProd();
158 tp = fPythia->event[i].tProd();
159 // momentum
160 pz = fPythia->event[i].pz();
161 px = fPythia->event[i].px();
162 py = fPythia->event[i].py();
163 e = fPythia->event[i].e();
164 // new decay vertex
165 Double_t LS = gRandom->Uniform(fLmin, fLmax); // mm, G4 and Pythia8 units
166 Double_t p = TMath::Sqrt(px * px + py * py + pz * pz);
167 Double_t lam = LS / p;
168 xS = xp + lam * px;
169 yS = yp + lam * py;
170 zS = zp + lam * pz;
171 Double_t gam = e / TMath::Sqrt(e * e - p * p);
172 Double_t beta = p / e;
173 tS = tp + LS / beta; // units ? [mm/c] + [mm/beta] (beta is dimensionless
174 // speed, and c=1 here) if one would use [s], then
175 // tS = tp/(cm*c_light) + (LS/cm)/(beta*c_light) =
176 // tS/(cm*c_light) i.e. units look consistent
177 w = TMath::Exp(-LS / (beta * gam * fctau)) *
178 ((fLmax - fLmin) / (beta * gam * fctau));
179 im = (Int_t)fPythia->event[i].mother1();
180 zm = fPythia->event[im].zProd();
181 xm = fPythia->event[im].xProd();
182 ym = fPythia->event[im].yProd();
183 pmz = fPythia->event[im].pz();
184 pmx = fPythia->event[im].px();
185 pmy = fPythia->event[im].py();
186 em = fPythia->event[im].e();
187 tm = fPythia->event[im].tProd();
188 // foresee finite beam size
190 if (fextFile) {
191 // take grand mother particle from input file, to know if primary or
192 // secondary production
193 cpg->AddTrack((Int_t)mid[0], mpx[0], mpy[0], mpz[0], xm / cm + dx / cm,
194 ym / cm + dy / cm, zm / cm, -1, false, mE[0], 0., 1.);
195 cpg->AddTrack(
196 (Int_t)fPythia->event[im].id(), pmx, pmy, pmz, xm / cm + dx / cm,
197 ym / cm + dy / cm, zm / cm, 0, false, em, tm / cm / c_light,
198 w); // convert pythia's (x,y,z[mm], t[mm/c]) to ([cm], [s])
199 cpg->AddTrack(fHNL, px, py, pz, xp / cm + dx / cm, yp / cm + dy / cm,
200 zp / cm, 1, false, e, tp / cm / c_light, w);
201 } else {
202 cpg->AddTrack(
203 (Int_t)fPythia->event[im].id(), pmx, pmy, pmz, xm / cm + dx / cm,
204 ym / cm + dy / cm, zm / cm, -1, false, em, tm / cm / c_light,
205 w); // convert pythia's (x,y,z[mm], t[mm/c]) to ([cm], [s])
206 cpg->AddTrack(fHNL, px, py, pz, xp / cm + dx / cm, yp / cm + dy / cm,
207 zp / cm, 0, false, e, tp / cm / c_light, w);
208 }
209 // bookkeep the indices of stored particles
210 dec_chain.push_back(im);
211 dec_chain.push_back(i);
212 // cout << endl << " insert mother pdg=" <<fPythia->event[im].id() << "
213 // pmz = " << pmz << " [GeV], zm = " << zm << " [mm] tm = " << tm << "
214 // [mm/c]" << endl; cout << " ----> insert HNL =" << fHNL << " pz = " <<
215 // pz << " [GeV] zp = " << zp << " [mm] tp = " << tp << " [mm/c]" << endl;
216 iHNL = i;
217 }
218 } while (iHNL ==
219 0); // ----------- avoid rare empty events w/o any HNL's produced
220
221 if (fShipEventNr % 100 == 0) {
222 LOGF(info, "ship event %i / pythia event-nr %i", fShipEventNr, fn);
223 }
224 fShipEventNr += 1;
225 // fill a container with pythia indices of the HNL decay chain
226 for (int k = 0; k < fPythia->event.size(); k++) {
227 // if daughter of HNL, copy
228 im = fPythia->event[k].mother1();
229 while (im > 0) {
230 if (im == iHNL) {
231 break;
232 } // pick the decay products of only 1 chosen HNL
233 // if ( abs(fPythia->event[im].id())==fHNL && im == iHNL ){break;}
234 else {
235 im = fPythia->event[im].mother1();
236 }
237 }
238 if (im < 1) {
239 continue;
240 }
241 dec_chain.push_back(k);
242 }
243
244 // go over daughters and store them on the stack, starting from 2 to account
245 // for HNL and its mother
246 for (std::vector<int>::iterator it = dec_chain.begin() + 2;
247 it != dec_chain.end(); ++it) {
248 // pythia index of the particle to store
249 int k = *it;
250 // find mother position on the output stack: impy -> im
251 int impy = fPythia->event[k].mother1();
252 std::vector<int>::iterator itm =
253 std::find(dec_chain.begin(), dec_chain.end(), impy);
254 im = -1; // safety
255 if (itm != dec_chain.end())
256 im = itm - dec_chain.begin(); // convert iterator into sequence number
257
258 Bool_t wanttracking = false;
259 if (fPythia->event[k].isFinal()) {
260 wanttracking = true;
261 }
262 pz = fPythia->event[k].pz();
263 px = fPythia->event[k].px();
264 py = fPythia->event[k].py();
265 e = fPythia->event[k].e();
266 if (fextFile) {
267 im += 1;
268 }
269 cpg->AddTrack((Int_t)fPythia->event[k].id(), px, py, pz, xS / cm, yS / cm,
270 zS / cm, im, wanttracking, e, tS / cm / c_light, w);
271 // std::cout <<k<< " insert pdg =" <<fPythia->event[k].id() << " pz = " <<
272 // pz << " [GeV] zS = " << zS << " [mm] tS = " << tS << "[mm/c]" << endl;
273 }
274 return kTRUE;
275}
std::pair< Double_t, Double_t > CalculateBeamOffset(Double_t smearBeam, Double_t paintBeam)
const Double_t c_light
int i
Definition: ShipAna.py:97
argparse beta
Definition: makeCascade.py:390
ROOT p
Definition: makeDecay.py:76
ROOT rnr
Definition: mergeMbias.py:16

◆ SetfFDs()

void HNLPythia8Generator::SetfFDs ( Double_t  z)
inline

Definition at line 78 of file HNLPythia8Generator.h.

78{ fFDs = z; };

◆ SetHNLId()

void HNLPythia8Generator::SetHNLId ( Int_t  id)
inline

Definition at line 69 of file HNLPythia8Generator.h.

69{ fHNL = id; };

◆ SetId()

void HNLPythia8Generator::SetId ( Double_t  id)
inline

Definition at line 68 of file HNLPythia8Generator.h.

68{ fId = id; };

◆ SetLmax()

void HNLPythia8Generator::SetLmax ( Double_t  z)
inline

Definition at line 71 of file HNLPythia8Generator.h.

71{ fLmax = z * 10; }; // Conversion from cm to mm

◆ SetLmin()

void HNLPythia8Generator::SetLmin ( Double_t  z)
inline

Definition at line 70 of file HNLPythia8Generator.h.

70{ fLmin = z * 10; }; // Conversion from cm to mm

◆ SetMom()

void HNLPythia8Generator::SetMom ( Double_t  mom)
inline

Definition at line 67 of file HNLPythia8Generator.h.

67{ fMom = mom; };

◆ SetPaintRadius()

void HNLPythia8Generator::SetPaintRadius ( Double_t  r)
inline

Definition at line 75 of file HNLPythia8Generator.h.

75 {
76 fPaintBeam = r * 10;
77 }; // Conversion from cm to mm

◆ SetParameters()

void HNLPythia8Generator::SetParameters ( char *  par)

Definition at line 277 of file HNLPythia8Generator.cxx.

277 {
278 // Set Parameters
279 fPythia->readString(par);
280 LOG(debug) << "fPythia->readString(\"" << par << "\")";
281}
ROOT par
Definition: makeDecay.py:143

◆ SetSmearBeam()

void HNLPythia8Generator::SetSmearBeam ( Double_t  sb)
inline

Definition at line 72 of file HNLPythia8Generator.h.

72 {
73 fsmearBeam = sb * 10;
74 }; // Conversion from cm to mm

◆ UseDeepCopy()

void HNLPythia8Generator::UseDeepCopy ( )
inline

Definition at line 88 of file HNLPythia8Generator.h.

88{ fDeepCopy = kTRUE; };

◆ UseRandom1()

void HNLPythia8Generator::UseRandom1 ( )
inline

Definition at line 79 of file HNLPythia8Generator.h.

79 {
80 fUseRandom1 = kTRUE;
81 fUseRandom3 = kFALSE;
82 };

◆ UseRandom3()

void HNLPythia8Generator::UseRandom3 ( )
inline

Definition at line 83 of file HNLPythia8Generator.h.

83 {
84 fUseRandom1 = kFALSE;
85 fUseRandom3 = kTRUE;
86 };

Member Data Documentation

◆ fctau

Double_t HNLPythia8Generator::fctau
protected

Definition at line 104 of file HNLPythia8Generator.h.

◆ fDeepCopy

Bool_t HNLPythia8Generator::fDeepCopy
protected

Definition at line 113 of file HNLPythia8Generator.h.

◆ fFDs

Double_t HNLPythia8Generator::fFDs
protected

Definition at line 105 of file HNLPythia8Generator.h.

◆ fHNL

Int_t HNLPythia8Generator::fHNL
protected

Definition at line 97 of file HNLPythia8Generator.h.

◆ fId

Int_t HNLPythia8Generator::fId
protected

Definition at line 98 of file HNLPythia8Generator.h.

◆ fInputFile

TFile* HNLPythia8Generator::fInputFile
protected

Definition at line 108 of file HNLPythia8Generator.h.

◆ fLmax

Double_t HNLPythia8Generator::fLmax
protected

Definition at line 102 of file HNLPythia8Generator.h.

◆ fLmin

Double_t HNLPythia8Generator::fLmin
protected

Definition at line 101 of file HNLPythia8Generator.h.

◆ fLogger

FairLogger* HNLPythia8Generator::fLogger
protected

Definition at line 114 of file HNLPythia8Generator.h.

◆ fMom

Double_t HNLPythia8Generator::fMom
protected

Definition at line 96 of file HNLPythia8Generator.h.

◆ fn

Int_t HNLPythia8Generator::fn
protected

Definition at line 110 of file HNLPythia8Generator.h.

◆ fNevents

Int_t HNLPythia8Generator::fNevents
protected

Definition at line 110 of file HNLPythia8Generator.h.

◆ fnRetries

Int_t HNLPythia8Generator::fnRetries
protected

Definition at line 103 of file HNLPythia8Generator.h.

◆ fPaintBeam

Double_t HNLPythia8Generator::fPaintBeam
protected

Definition at line 107 of file HNLPythia8Generator.h.

◆ fPythia

Pythia8::Pythia* HNLPythia8Generator::fPythia

Definition at line 91 of file HNLPythia8Generator.h.

◆ fRandomEngine

std::shared_ptr<Pythia8::RndmEngine> HNLPythia8Generator::fRandomEngine
private

Definition at line 93 of file HNLPythia8Generator.h.

◆ fShipEventNr

Int_t HNLPythia8Generator::fShipEventNr
protected

Definition at line 110 of file HNLPythia8Generator.h.

◆ fsmearBeam

Double_t HNLPythia8Generator::fsmearBeam
protected

Definition at line 106 of file HNLPythia8Generator.h.

◆ fTree

TTree* HNLPythia8Generator::fTree
protected

pointer to a file

Definition at line 109 of file HNLPythia8Generator.h.

◆ fUseRandom1

Bool_t HNLPythia8Generator::fUseRandom1
protected

Definition at line 99 of file HNLPythia8Generator.h.

◆ fUseRandom3

Bool_t HNLPythia8Generator::fUseRandom3
protected

Definition at line 100 of file HNLPythia8Generator.h.

◆ hE

Float_t HNLPythia8Generator::hE[1]
protected

Definition at line 111 of file HNLPythia8Generator.h.

◆ hid

Float_t HNLPythia8Generator::hid[1]
protected

Definition at line 112 of file HNLPythia8Generator.h.

◆ hM

Float_t HNLPythia8Generator::hM[1]
protected

Definition at line 111 of file HNLPythia8Generator.h.

◆ hpx

Float_t HNLPythia8Generator::hpx[1]
protected

Definition at line 111 of file HNLPythia8Generator.h.

◆ hpy

Float_t HNLPythia8Generator::hpy[1]
protected

Definition at line 111 of file HNLPythia8Generator.h.

◆ hpz

Float_t HNLPythia8Generator::hpz[1]
protected

Definition at line 111 of file HNLPythia8Generator.h.

◆ mE

Float_t HNLPythia8Generator::mE[1]
protected

Definition at line 111 of file HNLPythia8Generator.h.

◆ mid

Float_t HNLPythia8Generator::mid[1]
protected

Definition at line 112 of file HNLPythia8Generator.h.

◆ mpx

Float_t HNLPythia8Generator::mpx[1]
protected

Definition at line 111 of file HNLPythia8Generator.h.

◆ mpy

Float_t HNLPythia8Generator::mpy[1]
protected

Definition at line 111 of file HNLPythia8Generator.h.

◆ mpz

Float_t HNLPythia8Generator::mpz[1]
protected

Definition at line 111 of file HNLPythia8Generator.h.


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