Belle II Software  release-08-01-10
BHWide.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #include <generators/bhwide/BHWide.h>
10 #include <framework/gearbox/Unit.h>
11 
12 #include <TDatabasePDG.h>
13 #include <Math/Vector4D.h>
14 #include <TRandom.h>
15 
16 using namespace std;
17 using namespace Belle2;
18 
19 //Declaration of the BHWide FORTRAN methods and common blocks.
20 extern "C" {
21 
22  extern struct {
23  double p1[4];
24  double q1[4];
25  double p2[4];
26  double q2[4];
27  double phit[4][100];
28  int nphot;
29  } momset_;
30 
31  void bhwide_(int* mode, double* xpar, int* npar);
32  void glimit_(int* number);
33 
39  void varran_(double* drvec, const int* lengt)
40  {
41  for (int i = 0; i < *lengt; ++i) {
42  do {
43  //BHWide does not want 1 for some reason, at least they are rejected in
44  //the original VARRAN subroutine so we do it here as well
45  drvec[i] = gRandom->Rndm();
46  } while (drvec[i] >= 1.0);
47  }
48  }
53  void ranmar_(double* rvec)
54  {
55  *rvec = gRandom->Rndm();
56  }
57 }
58 
59 
60 BHWide::BHWide()
61 {
62  for (int i = 0; i < 100; ++i) {
63  m_npar[i] = 0;
64  m_xpar[i] = 0.0;
65  }
66 
67  m_crossSection = 0.;
68  m_crossSectionError = 0.;
69 
70  setDefaultSettings();
71 }
72 
73 
74 BHWide::~BHWide()
75 {
76 
77 }
78 
79 
80 void BHWide::setDefaultSettings()
81 {
82 
83  m_zContribution = true;
84  m_channel = CH_BOTH;
85  m_weighted = false;
86  m_randomGenerator = RG_RANMAR;
87  m_weakCorrections = true;
88  m_ewCorrectionLib = EC_ALIBABA;
89  m_hardBremsModel = HM_CALKUL;
90  m_photonVacPol = PP_BURKHARDT;
91 
92  m_cmsEnergy = 10.58 * Unit::GeV;
93  m_ScatteringAngleRangePositron = make_pair(17.0, 150.0); //in [deg]
94  m_ScatteringAngleRangeElectron = make_pair(17.0, 150.0); //in [deg]
95  m_minEnergyFinalStatePos = 0.2 * Unit::GeV;
96  m_minEnergyFinalStateElc = 0.2 * Unit::GeV;
97  m_maxAcollinearity = 10.0;
98  m_infCutCMSEnergy = 1e-5;
99  m_maxRejectionWeight = 3.0;
100  m_massZ = 91.1882 * Unit::GeV;
101  m_widthZ = 2.4952;
102  m_sinW2 = 0.22225;
103  m_massTop = 174.3 * Unit::GeV;
104  m_massHiggs = 115.0 * Unit::GeV;
105 }
106 
107 
108 void BHWide::init()
109 {
110  int number = 50000;
111  glimit_(&number);
112  applySettings();
113 }
114 
115 
116 void BHWide::generateEvent(MCParticleGraph& mcGraph, ROOT::Math::XYZVector vertex, ROOT::Math::LorentzRotation boost)
117 {
118  //Generate event
119  int mode = 0;
120  bhwide_(&mode, m_xpar, m_npar);
121 
122  //Store the initial particles as virtual particles into the MCParticleGraph
123  storeParticle(mcGraph, momset_.q1, 11, vertex, boost, true);
124  storeParticle(mcGraph, momset_.p1, -11, vertex, boost, true);
125 
126  //Store the final state positron and electron into the MCParticleGraph
127  storeParticle(mcGraph, momset_.q2, 11, vertex, boost);
128  storeParticle(mcGraph, momset_.p2, -11, vertex, boost);
129 
130  //Store the real photons into the MCParticleGraph
131  for (int iPhot = 0; iPhot < momset_.nphot; ++iPhot) {
132  double photMom[4] = {momset_.phit[0][iPhot], momset_.phit[1][iPhot], momset_.phit[2][iPhot], momset_.phit[3][iPhot]};
133  storeParticle(mcGraph, photMom, 22, vertex, boost);
134  }
135 }
136 
137 
138 void BHWide::term()
139 {
140  int mode = 2;
141  bhwide_(&mode, m_xpar, m_npar);
142 
143  //Get the cross section
144  m_crossSection = m_xpar[9];
145  m_crossSectionError = m_xpar[10];
146 }
147 
148 //=========================================================================
149 // Protected methods
150 //=========================================================================
151 
152 void BHWide::applySettings()
153 {
154  //--------------------
155  // Integer parameters
156  //--------------------
157  int keyZof;
158  if (m_zContribution) keyZof = 0;
159  else keyZof = 1;
160  m_npar[0] = (1000 * keyZof) + (100 * m_channel) + (10 * m_weighted) + m_randomGenerator;
161  m_npar[1] = (1000 * m_weakCorrections) + (100 * m_ewCorrectionLib) + (10 * m_hardBremsModel) + m_photonVacPol;
162 
163  //--------------------
164  // Double parameters
165  //--------------------
166  m_xpar[0] = m_cmsEnergy;
167  m_xpar[1] = m_ScatteringAngleRangePositron.first;
168  m_xpar[2] = m_ScatteringAngleRangePositron.second;
169  m_xpar[3] = m_ScatteringAngleRangeElectron.first;
170  m_xpar[4] = m_ScatteringAngleRangeElectron.second;
171  m_xpar[5] = m_minEnergyFinalStatePos;
172  m_xpar[6] = m_minEnergyFinalStateElc;
173  m_xpar[7] = m_maxAcollinearity;
174  m_xpar[8] = m_infCutCMSEnergy;
175  m_xpar[9] = m_maxRejectionWeight;
176  m_xpar[10] = m_massZ;
177  m_xpar[11] = m_widthZ;
178  m_xpar[12] = m_sinW2;
179  m_xpar[13] = m_massTop;
180  m_xpar[14] = m_massHiggs;
181 
182  int mode = -1;
183  bhwide_(&mode, m_xpar, m_npar);
184 }
185 
186 
187 void BHWide::storeParticle(MCParticleGraph& mcGraph, const double* mom, int pdg, ROOT::Math::XYZVector vertex,
188  ROOT::Math::LorentzRotation boost,
189  bool isVirtual, bool isInitial)
190 {
191  // //Create particle
192  //MCParticleGraph::GraphParticle& part = mcGraph.addParticle();
193  //if (!isVirtual) {
194  // part.setStatus(MCParticle::c_PrimaryParticle);
195  //} else {
196  // part.setStatus(MCParticle::c_IsVirtual);
197  //}
198  //Create particle
199  // RG 6/25/14 Add new flag for ISR "c_Initial"
201  if (isVirtual) {
202  part.setStatus(MCParticle::c_IsVirtual);
203  } else if (isInitial) {
204  part.setStatus(MCParticle::c_Initial);
205  }
206 
207  // every particle from a generator is primary
208  part.addStatus(MCParticle::c_PrimaryParticle);
209 
210  // all particles produced by BHWIDE are stable
211  part.addStatus(MCParticle::c_StableInGenerator);
212 
213  // all photons from BHWIDE are ISR or FSR
214  if (pdg == 22 && !isVirtual) {
215  part.addStatus(MCParticle::c_IsISRPhoton);
216  part.addStatus(MCParticle::c_IsFSRPhoton);
217  }
218 
219  part.setPDG(pdg);
220  part.setFirstDaughter(0);
221  part.setLastDaughter(0);
222  part.setMomentum(ROOT::Math::XYZVector(mom[0], mom[1], mom[2]));
223  part.setMass(TDatabasePDG::Instance()->GetParticle(pdg)->Mass());
224  part.setEnergy(mom[3]);
225 
226  //boost
227  ROOT::Math::PxPyPzEVector p4 = part.get4Vector();
228  p4.SetPz(-1.0 * p4.Pz()); //BHWIDE uses other direction convention
229  p4 = boost * p4;
230  part.set4Vector(p4);
231 
232  //set vertex
233  if (!isInitial) {
234  ROOT::Math::XYZVector v3 = part.getProductionVertex();
235  v3 = v3 + vertex;
236  part.setProductionVertex(v3);
237  part.setValidVertex(true);
238  }
239 }
Class to represent Particle data in graph.
Class to build, validate and sort a particle decay chain.
GraphParticle & addParticle()
Add new particle to the graph.
Abstract base class for different kinds of events.