Skip to content

Commit 16f18ba

Browse files
authored
Updates to GeneratorParam (#14)
* added kNParticles to enum Particle_t * included particle weights (by A. Morsch) * included weighting options kAnalog and kNonAnalog * PythiaDecayerConfig object to be passed from external generator
1 parent d6febf7 commit 16f18ba

File tree

3 files changed

+76
-18
lines changed

3 files changed

+76
-18
lines changed

GeneratorParam/GeneratorParam.cxx

Lines changed: 63 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
#include <TPythia6Decayer.h>
2727
#include <TROOT.h>
2828
#include <TRandom.h>
29-
#include <TVirtualMC.h>
30-
// #include <TPythia8Decayer.h>
3129
#include <vector>
3230

3331
#include "GeneratorParam.h"
@@ -43,7 +41,7 @@ ClassImp(GeneratorParam)
4341
GeneratorParam::GeneratorParam(Int_t npart,
4442
const GeneratorParamLibBase *Library,
4543
Int_t param, const char *tname)
46-
: TGenerator("GeneratorParam", "GeneratorParam"), fNpart(npart) {
44+
: TGenerator("GeneratorParam", "GeneratorParam"), fNpart(npart), fParam(param) {
4745
// Constructor using number of particles parameterisation id and library
4846
fName = "Param";
4947
fTitle = "Particle Generator using pT and y parameterisation";
@@ -152,12 +150,42 @@ void GeneratorParam::Init() {
152150
fdNdPhi->Delete();
153151
fdNdPhi = new TF1(name, "1+2*[0]*TMath::Cos(2*(x-[1]))", fPhiMin, fPhiMax);
154152
//
153+
//
154+
snprintf(name, 256, "pt-for-%s", GetName());
155+
TF1 ptPara(name ,fPtParaFunc, 0, 15, 0);
156+
snprintf(name, 256, "y-for-%s", GetName());
157+
TF1 yPara(name, fYParaFunc, -6, 6, 0);
158+
#if ROOT_VERSION_CODE < ROOT_VERSION(5,99,0)
159+
Float_t intYS = yPara.Integral(fYMin, fYMax,(Double_t*) 0x0,1.e-6);
160+
Float_t intPt0 = ptPara.Integral(0,15,(Double_t *) 0x0,1.e-6);
161+
Float_t intPtS = ptPara.Integral(fPtMin,fPtMax,(Double_t*) 0x0,1.e-6);
162+
#else
163+
Float_t intYS = yPara.Integral(fYMin, fYMax,1.e-6);
164+
Float_t intPt0 = ptPara.Integral(0,15,1.e-6);
165+
Float_t intPtS = ptPara.Integral(fPtMin,fPtMax,1.e-6);
166+
#endif
167+
Float_t phiWgt=(fPhiMax-fPhiMin)/TMath::TwoPi(); //TR: should probably be done differently in case of anisotropic phi...
168+
169+
// // dN/dy| y=0
170+
Double_t y1=0;
171+
Double_t y2=0;
172+
173+
fdNdy0=fYParaFunc(&y1,&y2);
174+
175+
fYWgt = intYS/fdNdy0;
176+
if (fAnalog == kAnalog) {
177+
fPtWgt = intPtS/intPt0;
178+
} else {
179+
fPtWgt = (fPtMax-fPtMin)/intPt0;
180+
}
181+
fParentWeight = fYWgt*fPtWgt*phiWgt/fNpart;
182+
//
183+
//
155184
// Initialize the decayer
156185
fDecayer->Init();
157186
// initialise selection of decay products
158187
InitChildSelect();
159-
PythiaDecayerConfig decayerconfig;
160-
decayerconfig.Init(fForceDecay);
188+
fDecayerConfig->Init(fForceDecay);
161189
}
162190

163191
void GeneratorParam::GenerateEvent() {
@@ -184,10 +212,11 @@ void GeneratorParam::GenerateEvent() {
184212
Int_t i, j;
185213
Double_t energy;
186214
Float_t time0;
187-
215+
Float_t wgtp, wgtch;
188216
std::vector<bool> vFlags;
189217
std::vector<bool> vSelected;
190218
std::vector<int> vParent;
219+
Double_t dummy;
191220

192221
// array to store decay products
193222
static TClonesArray *particles;
@@ -214,6 +243,7 @@ void GeneratorParam::GenerateEvent() {
214243
// custom pdg codes to destinguish direct photons
215244
if ((pdg >= 220000) && (pdg <= 220001))
216245
pdg = 22;
246+
fChildWeight=(fDecayerConfig->GetPartialBranchingRatio(pdg))*fParentWeight;
217247
TParticlePDG *particle = pDataBase->GetParticle(pdg);
218248
Float_t am = particle->Mass();
219249
gRandom->RndmArray(2, random);
@@ -235,7 +265,16 @@ void GeneratorParam::GenerateEvent() {
235265
ty = TMath::TanH(fYPara->GetRandom());
236266
//
237267
// pT
238-
pt = fPtPara->GetRandom();
268+
if (fAnalog == kAnalog) {
269+
pt = fPtPara->GetRandom();
270+
wgtp = fParentWeight;
271+
wgtch = fChildWeight;
272+
} else {
273+
pt=fPtMin+random[1]*(fPtMax-fPtMin);
274+
Double_t ptd=pt;
275+
wgtp=fParentWeight*fPtParaFunc(& ptd, &dummy);
276+
wgtch=fChildWeight*fPtParaFunc(& ptd, &dummy);
277+
}
239278
xmt = sqrt(pt * pt + am * am);
240279
if (TMath::Abs(ty) == 1.) {
241280
ty = 0.;
@@ -365,9 +404,12 @@ void GeneratorParam::GenerateEvent() {
365404
//
366405
// Parent
367406
// --- For Exodus --------------------------------//
368-
fParticles->Add(new TParticle(
369-
pdg, ((decayed) ? 11 : 1), -1, -1, -1, -1, p[0], p[1], p[2],
370-
energy, origin0[0], origin0[1], origin0[2], time0));
407+
auto particle = new TParticle(
408+
pdg, ((decayed) ? 11 : 1), -1, -1, -1, -1, p[0], p[1], p[2],
409+
energy, origin0[0], origin0[1], origin0[2], time0
410+
);
411+
particle->SetWeight(wgtp);
412+
fParticles->Add(particle);
371413
vParent[0] = nt;
372414
nt++;
373415
fNprimaries++;
@@ -387,7 +429,7 @@ void GeneratorParam::GenerateEvent() {
387429
auto kf = iparticle->GetPdgCode();
388430
auto ksc = iparticle->GetStatusCode();
389431
auto jpa = iparticle->GetFirstMother() + fIncFortran;
390-
432+
Double_t weight = iparticle->GetWeight();
391433
och[0] = origin0[0] + iparticle->Vx();
392434
och[1] = origin0[1] + iparticle->Vy();
393435
och[2] = origin0[2] + iparticle->Vz();
@@ -405,9 +447,13 @@ void GeneratorParam::GenerateEvent() {
405447
if (parentP->GetFirstDaughter() == -1)
406448
parentP->SetFirstDaughter(nt);
407449
parentP->SetLastDaughter(nt);
408-
fParticles->Add(new TParticle(kf, ksc, iparent, -1, -1, -1, pc[0],
450+
auto particle = new TParticle(kf, ksc, iparent, -1, -1, -1, pc[0],
409451
pc[1], pc[2], ec, och0[0], och0[1],
410-
och0[2], time0 + iparticle->T()));
452+
och0[2], time0 + iparticle->T()
453+
);
454+
particle->SetWeight(weight * wgtch);
455+
fParticles->Add(particle);
456+
411457
vParent[i] = nt;
412458
nt++;
413459
fNprimaries++;
@@ -422,9 +468,11 @@ void GeneratorParam::GenerateEvent() {
422468
} else {
423469
// nodecay option, so parent will be tracked by GEANT (pions, kaons,
424470
// eta, omegas, baryons)
425-
fParticles->Add(new TParticle(pdg, 1, -1, -1, -1, -1, p[0], p[1], p[2],
471+
auto particle = new TParticle(pdg, 1, -1, -1, -1, -1, p[0], p[1], p[2],
426472
energy, origin0[0], origin0[1],
427-
origin0[2], time0));
473+
origin0[2], time0);
474+
particle->SetWeight(wgtp);
475+
fParticles->Add(particle);
428476
ipa++;
429477
fNprimaries++;
430478
}

GeneratorParam/GeneratorParam.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ class GeneratorParam : public TGenerator {
9292
// force decay type
9393
virtual void SetDeltaPt(Float_t delta = 0.01) { fDeltaPt = delta; }
9494
virtual void SetDecayer(TVirtualMCDecayer *decayer) { fDecayer = decayer; }
95+
virtual void SetDecayerConfig(PythiaDecayerConfig *decayerconfig) {fDecayerConfig = decayerconfig; }
9596
virtual void SetForceGammaConversion(Bool_t force = kTRUE) {
9697
fForceConv = force;
9798
}
@@ -106,6 +107,8 @@ class GeneratorParam : public TGenerator {
106107
} // Prevent flagging(/skipping) of decay daughter particles; preserves
107108
// complete forced decay chain
108109

110+
virtual void SetWeighting(Weighting_t flag = kAnalog) {fAnalog = flag;}
111+
109112
virtual void Draw(const char *opt);
110113
TF1 *GetPt() { return fPtPara; }
111114
TF1 *GetY() { return fYPara; }
@@ -157,6 +160,7 @@ class GeneratorParam : public TGenerator {
157160
Bool_t fSelectAll = false; // Flag for transportation of Background while
158161
// using SetForceDecay()
159162
TVirtualMCDecayer *fDecayer = 0; // ! Pointer to virtual decyer
163+
PythiaDecayerConfig *fDecayerConfig = 0; // Pointer to decayer config
160164
Bool_t fForceConv = false; // force converson of gammas
161165
Bool_t fKeepParent =
162166
false; // Store parent even if it does not have childs within cuts
@@ -196,6 +200,13 @@ class GeneratorParam : public TGenerator {
196200
Float_t fChildThetaMax = 0.;
197201
Float_t fChildPhiMin = 0.;
198202
Float_t fChildPhiMax = 0.;
203+
Float_t fParentWeight = 1.;
204+
Float_t fChildWeight = 1.;
205+
Float_t fYWgt = 1.;
206+
Float_t fPtWgt = 1.;
207+
Float_t fdNdy0 = 1.;
208+
Weighting_t fAnalog = kAnalog;
209+
199210
TArrayI fChildSelect; //! Decay products to be selected
200211
enum {
201212
kThetaRange = BIT(14),
@@ -211,7 +222,6 @@ class GeneratorParam : public TGenerator {
211222
GeneratorParam(const GeneratorParam &Param);
212223
GeneratorParam &operator=(const GeneratorParam &rhs);
213224

214-
ClassDef(GeneratorParam,
215-
1) // Generator using parameterised pt- and y-distribution
225+
ClassDef(GeneratorParam, 2) // Generator using parameterised pt- and y-distribution
216226
};
217227
#endif

GeneratorParam/GeneratorParamEMlibV2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class GeneratorParamEMlibV2 : public GeneratorParamLibBase {
2121
kSigma0=7, kK0s=8, kDeltaPlPl=9, kDeltaPl=10, kDeltaMi=11, kDeltaZero=12,
2222
kRhoPl=13, kRhoMi=14, kK0star=15, kK0l=16, kLambda=17, kKPl=18, kKMi=19,
2323
kOmegaPl=20, kOmegaMi=21, kXiPl=22, kXiMi=23, kSigmaPl=24, kSigmaMi=25,
24-
kDirectRealGamma=26, kDirectVirtGamma=27};
24+
kDirectRealGamma=26, kDirectVirtGamma=27, kNParticles=28};
2525

2626
enum CollisionSystem_t {kpp900GeV=0x000, kpp2760GeV=0x64, kpp7TeV=0xC8, kpPb=0x12C, kPbPb=0x190};
2727

0 commit comments

Comments
 (0)