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)
4341GeneratorParam::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
163191void 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 }
0 commit comments