FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Pythia8Generator.cxx
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 // -------------------------------------------------------------------------
9 // ----- M. Al-Turany June 2014 -----
10 // -------------------------------------------------------------------------
11 
12 #include "FairPrimaryGenerator.h"
13 #include "Pythia8/Pythia.h"
14 
15 #include <TROOT.h>
16 #include <math.h>
17 //#include "FairGenerator.h"
18 
19 #include "Pythia8Generator.h"
20 
21 using namespace Pythia8;
22 
23 // ----- Default constructor -------------------------------------------
25  : FairGenerator()
26  , fPythia()
27  , fRandomEngine(nullptr)
28  , fMom(400.)
29  , fHNL(0)
30  , fId(2212)
31  , fUseRandom1(kFALSE)
32  , fUseRandom3(kTRUE)
33 {
34  /*
35  fUseRandom1 = kFALSE;
36  fUseRandom3 = kTRUE;
37  fId = 2212; // proton
38  fMom = 400; // proton
39  fHNL = 0; // HNL if set to !=0, for example 9900014, only track
40  */
41 }
42 // -------------------------------------------------------------------------
43 
44 // ----- Default constructor -------------------------------------------
46 {
47  if (fUseRandom1)
48  fRandomEngine = new PyTr1Rng();
49  if (fUseRandom3)
50  fRandomEngine = new PyTr3Rng();
51 
52  fPythia.setRndmEnginePtr(fRandomEngine);
53 
54  cout << "Beam Momentum " << fMom << endl;
55  // Set arguments in Settings database.
56  fPythia.settings.mode("Beams:idA", fId);
57  fPythia.settings.mode("Beams:idB", 2212);
58  fPythia.settings.mode("Beams:frameType", 3);
59  fPythia.settings.parm("Beams:pxA", 0.);
60  fPythia.settings.parm("Beams:pyA", 0.);
61  fPythia.settings.parm("Beams:pzA", fMom);
62  fPythia.settings.parm("Beams:pxB", 0.);
63  fPythia.settings.parm("Beams:pyB", 0.);
64  fPythia.settings.parm("Beams:pzB", 0.);
65  fPythia.init();
66  return kTRUE;
67 }
68 // -------------------------------------------------------------------------
69 
70 // ----- Destructor ----------------------------------------------------
72 // -------------------------------------------------------------------------
73 
74 // ----- Passing the event ---------------------------------------------
76 {
77  Int_t npart = 0;
78  while (npart == 0) {
79  fPythia.next();
80  for (int i = 0; i < fPythia.event.size(); i++) {
81  if (fPythia.event[i].isFinal()) {
82  // only send HNL decay products to G4
83  if (fHNL != 0) {
84  Int_t im = fPythia.event[i].mother1();
85  if (fPythia.event[im].id() == fHNL) {
86  // for the moment, hardcode 110m is maximum decay length
87  Double_t z = fPythia.event[i].zProd();
88  Double_t x = abs(fPythia.event[i].xProd());
89  Double_t y = abs(fPythia.event[i].yProd());
90  // cout<<"debug HNL decay pos "<<x<<" "<< y<<" "<< z <<endl;
91  if (z < 11000. && z > 7000. && x < 250. && y < 250.) {
92  npart++;
93  }
94  }
95  } else {
96  npart++;
97  }
98  };
99  };
100  // happens if a charm particle being produced which does decay without producing a HNL. Try another event.
101  // if (npart == 0){ fPythia.event.list();}
102  };
103  // cout<<"debug p8 event 0 " << fPythia.event[0].id()<< " "<< fPythia.event[1].id()<< " "<< fPythia.event[2].id()<<
104  // " "<< npart <<endl;
105  for (Int_t ii = 0; ii < fPythia.event.size(); ii++) {
106  if (fPythia.event[ii].isFinal()) {
107  Bool_t wanttracking = true;
108  if (fHNL != 0) {
109  Int_t im = fPythia.event[ii].mother1();
110  if (fPythia.event[im].id() != fHNL) {
111  wanttracking = false;
112  }
113  }
114  if (wanttracking) {
115  Double_t z = fPythia.event[ii].zProd();
116  Double_t x = fPythia.event[ii].xProd();
117  Double_t y = fPythia.event[ii].yProd();
118  Double_t pz = fPythia.event[ii].pz();
119  Double_t px = fPythia.event[ii].px();
120  Double_t py = fPythia.event[ii].py();
121  cpg->AddTrack((Int_t)fPythia.event[ii].id(),
122  px,
123  py,
124  pz,
125  x,
126  y,
127  z,
128  (Int_t)fPythia.event[ii].mother1(),
129  wanttracking);
130  // cout<<"debug p8->geant4 "<< wanttracking << " "<< ii << " " << fPythia.event[ii].id()<< " "<<
131  // fPythia.event[ii].mother1()<<" "<<x<<" "<< y<<" "<< z <<endl;
132  }
133  // virtual void AddTrack(Int_t pdgid, Double_t px, Double_t py, Double_t pz,
134  // Double_t vx, Double_t vy, Double_t vz, Int_t parent=-1,Bool_t
135  // wanttracking=true,Double_t e=-9e9);
136  };
137  if (fHNL != 0 && fPythia.event[ii].id() == fHNL) {
138  Int_t im = (Int_t)fPythia.event[ii].mother1();
139  Double_t z = fPythia.event[ii].zProd();
140  Double_t x = fPythia.event[ii].xProd();
141  Double_t y = fPythia.event[ii].yProd();
142  Double_t pz = fPythia.event[ii].pz();
143  Double_t px = fPythia.event[ii].px();
144  Double_t py = fPythia.event[ii].py();
145  cpg->AddTrack((Int_t)fPythia.event[im].id(), px, py, pz, x, y, z, 0, false);
146  cpg->AddTrack((Int_t)fPythia.event[ii].id(), px, py, pz, x, y, z, im, false);
147  // cout<<"debug p8->geant4 "<< 0 << " "<< ii << " " << fake<< " "<< fPythia.event[ii].mother1()<<endl;
148  };
149  }
150 
151  // make separate container ??
152  // FairRootManager *ioman =FairRootManager::Instance();
153 
154  return kTRUE;
155 }
156 // -------------------------------------------------------------------------
158 {
159  // Set Parameters
160  fPythia.readString(par);
161  cout << "fPythia.readString(\"" << par << "\")" << endl;
162 }
163 
164 // -------------------------------------------------------------------------
165 void Pythia8Generator::Print() { fPythia.settings.listAll(); }
166 // -------------------------------------------------------------------------
168 {
169  fPythia.particleData.list(arg);
170  cout << "canDecay " << fPythia.particleData.canDecay(arg) << " " << fPythia.particleData.mayDecay(arg) << endl;
171 }
172 // -------------------------------------------------------------------------
173 
virtual ~Pythia8Generator()
virtual Bool_t Init()
ClassImp(FairEventBuilder)
Bool_t ReadEvent(FairPrimaryGenerator *)
FairMQExParamsParOne * par
void SetParameters(char *)
virtual void AddTrack(Int_t pdgid, Double_t px, Double_t py, Double_t pz, Double_t vx, Double_t vy, Double_t vz, Int_t parent=-1, Bool_t wanttracking=true, Double_t e=-9e9, Double_t tof=0., Double_t weight=0., TMCProcess proc=kPPrimary)