ATTPCROOT  0.3.0-alpha
A ROOT-based framework for analyzing data from active target detectors
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 version 3 (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 
14 #include <TROOT.h>
15 
16 #include "Pythia.h"
17 #include <math.h>
18 //#include <FairGenerator.h>
19 
20 #include "Pythia8Generator.h"
21 
22 using namespace Pythia8;
23 
24 // ----- Default constructor -------------------------------------------
26 {
27  fUseRandom1 = kFALSE;
28  fUseRandom3 = kTRUE;
29  fId = 2212; // proton
30  fMom = 400; // proton
31  fHNL = 0; // HNL if set to !=0, for example 9900014, only track
32 }
33 // -------------------------------------------------------------------------
34 
35 // ----- Default constructor -------------------------------------------
37 {
38  if (fUseRandom1)
39  fRandomEngine = new PyTr1Rng();
40  if (fUseRandom3)
41  fRandomEngine = new PyTr3Rng();
42 
43  fPythia.setRndmEnginePtr(fRandomEngine);
44 
45  cout << "Beam Momentum " << fMom << endl;
46  fPythia.init(fId, 2212, 0., 0., fMom, 0., 0., 0.);
47  return kTRUE;
48 }
49 // -------------------------------------------------------------------------
50 
51 // ----- Destructor ----------------------------------------------------
53 // -------------------------------------------------------------------------
54 
55 // ----- Passing the event ---------------------------------------------
56 Bool_t Pythia8Generator::ReadEvent(FairPrimaryGenerator *cpg)
57 {
58  Int_t npart = 0;
59  while (npart == 0) {
60  fPythia.next();
61  for (int i = 0; i < fPythia.event.size(); i++) {
62  if (fPythia.event[i].isFinal()) {
63  // only send HNL decay products to G4
64  if (fHNL != 0) {
65  Int_t im = fPythia.event[i].mother1();
66  if (fPythia.event[im].id() == fHNL) {
67  // for the moment, hardcode 110m is maximum decay length
68  Double_t z = fPythia.event[i].zProd();
69  Double_t x = abs(fPythia.event[i].xProd());
70  Double_t y = abs(fPythia.event[i].yProd());
71  // cout<<"debug HNL decay pos "<<x<<" "<< y<<" "<< z <<endl;
72  if (z < 11000. && z > 7000. && x < 250. && y < 250.) {
73  npart++;
74  }
75  }
76  } else {
77  npart++;
78  }
79  };
80  };
81  // happens if a charm particle being produced which does decay without producing a HNL. Try another event.
82  // if (npart == 0){ fPythia.event.list();}
83  };
84  // cout<<"debug p8 event 0 " << fPythia.event[0].id()<< " "<< fPythia.event[1].id()<< " "<< fPythia.event[2].id()<< "
85  // "<< npart <<endl;
86  for (Int_t ii = 0; ii < fPythia.event.size(); ii++) {
87  if (fPythia.event[ii].isFinal()) {
88  Bool_t wanttracking = true;
89  if (fHNL != 0) {
90  Int_t im = fPythia.event[ii].mother1();
91  if (fPythia.event[im].id() != fHNL) {
92  wanttracking = false;
93  }
94  }
95  if (wanttracking) {
96  Double_t z = fPythia.event[ii].zProd();
97  Double_t x = fPythia.event[ii].xProd();
98  Double_t y = fPythia.event[ii].yProd();
99  Double_t pz = fPythia.event[ii].pz();
100  Double_t px = fPythia.event[ii].px();
101  Double_t py = fPythia.event[ii].py();
102  cpg->AddTrack((Int_t)fPythia.event[ii].id(), px, py, pz, x, y, z, (Int_t)fPythia.event[ii].mother1(),
103  wanttracking);
104  // cout<<"debug p8->geant4 "<< wanttracking << " "<< ii << " " << fPythia.event[ii].id()<< " "<<
105  // fPythia.event[ii].mother1()<<" "<<x<<" "<< y<<" "<< z <<endl;
106  }
107  // virtual void AddTrack(Int_t pdgid, Double_t px, Double_t py, Double_t pz,
108  // Double_t vx, Double_t vy, Double_t vz, Int_t parent=-1,Bool_t
109  // wanttracking=true,Double_t e=-9e9);
110  };
111  if (fHNL != 0 && fPythia.event[ii].id() == fHNL) {
112  Int_t im = (Int_t)fPythia.event[ii].mother1();
113  Double_t z = fPythia.event[ii].zProd();
114  Double_t x = fPythia.event[ii].xProd();
115  Double_t y = fPythia.event[ii].yProd();
116  Double_t pz = fPythia.event[ii].pz();
117  Double_t px = fPythia.event[ii].px();
118  Double_t py = fPythia.event[ii].py();
119  cpg->AddTrack((Int_t)fPythia.event[im].id(), px, py, pz, x, y, z, 0, false);
120  cpg->AddTrack((Int_t)fPythia.event[ii].id(), px, py, pz, x, y, z, im, false);
121  // cout<<"debug p8->geant4 "<< 0 << " "<< ii << " " << fake<< " "<< fPythia.event[ii].mother1()<<endl;
122  };
123  }
124 
125  // make separate container ??
126  // FairRootManager *ioman =FairRootManager::Instance();
127 
128  return kTRUE;
129 }
130 // -------------------------------------------------------------------------
132 {
133  // Set Parameters
134  fPythia.readString(par);
135  cout << "fPythia.readString(\"" << par << "\")" << endl;
136 }
137 
138 // -------------------------------------------------------------------------
140 {
141  fPythia.settings.listAll();
142 }
143 // -------------------------------------------------------------------------
145 {
146  fPythia.particleData.list(arg);
147  cout << "canDecay " << fPythia.particleData.canDecay(arg) << " " << fPythia.particleData.mayDecay(arg) << endl;
148 }
149 // -------------------------------------------------------------------------
150 
Pythia8Generator::GetPythiaInstance
void GetPythiaInstance(int)
Definition: Pythia8Generator.cxx:144
Pythia8Generator::~Pythia8Generator
virtual ~Pythia8Generator()
Definition: Pythia8Generator.cxx:52
Pythia8Generator
Definition: Pythia8Generator.h:48
ClassImp
ClassImp(AtFindVertex)
Pythia8Generator::ReadEvent
Bool_t ReadEvent(FairPrimaryGenerator *)
Definition: Pythia8Generator.cxx:56
y
const double * y
Definition: lmcurve.cxx:20
Pythia8Generator.h
Pythia8Generator::Pythia8Generator
Pythia8Generator()
Definition: Pythia8Generator.cxx:25
PyTr1Rng
Definition: Pythia8Generator.h:26
Pythia8Generator::Print
void Print()
Definition: Pythia8Generator.cxx:139
Pythia8Generator::SetParameters
void SetParameters(char *)
Definition: Pythia8Generator.cxx:131
PyTr3Rng
Definition: Pythia8Generator.h:37
Pythia8Generator::Init
virtual Bool_t Init()
Definition: Pythia8Generator.cxx:36