Belle II Software development
AAFHInterface Class Reference

Class to inferface AAFH/DIAG36 Generator written in Fortran. More...

#include <AAFHInterface.h>

Public Types

enum  EMode {
  c_MuonParticle = 1 ,
  c_MuonMuon = 2 ,
  c_ElectonMuon = 3 ,
  c_ElectronParticle = 4 ,
  c_ElectonElectron = 5
}
 Generation mode. More...
 
enum  ERejection {
  c_Once = 1 ,
  c_Twice = 2
}
 Rejection mode. More...
 

Public Member Functions

 AAFHInterface ()=default
 Default Constructor.
 
void setMaxTries (int tries)
 Set the maximum number of tries to generate an event.
 
void setGeneratorWeights (const std::vector< double > &weights)
 Set the relative weights for the sub generators.
 
void setMaxWeights (double subgeneratorWeight, double finalWeight)
 Set the maximum expected weights for the rejection method.
 
void setSupressionLimits (std::vector< double > limits)
 Set the suppression limits when calculation the matrix elements.
 
void setMinimumMass (double minMass)
 Set the minimum invariant mass for the generated event.
 
void setParticle (const std::string &particle)
 Set the particle type for modes c_MuonParticle and c_ElectronParticle.
 
int getMaxTries () const
 Get the maximum number of tries to generate an event.
 
std::vector< double > getGeneratorWeights () const
 Get the relative weights for the sub generators.
 
double getMaxSubGeneratorWeight () const
 Get the maximum expected final weight for the rejection method.
 
double getMaxFinalWeight () const
 Get the maximum expected subgenerator weight for the rejection method.
 
std::vector< double > getSuppressionLimits () const
 Get suppression limits.
 
double getMinimumMass () const
 Get the minimum invariant mass for the generated event.
 
std::string getParticle () const
 Get the particle type for modes c_MuonParticle and c_ElectronParticle.
 
double getTotalCrossSection () const
 Return total cross section.
 
double getTotalCrossSectionError () const
 Return error on the total cross section.
 
void initialize (double beamEnergy, EMode mode, ERejection rejection)
 initialize the generator
 
void generateEvent (MCParticleGraph &mpg)
 generate one event and add it to the graph in CMS
 
void finish ()
 calculate total cross section
 

Private Member Functions

void updateParticle (MCParticleGraph::GraphParticle &p, double *q, int pdg, bool isInitial=false)
 update particle with generated values
 

Private Attributes

double m_minMass {0}
 minimum invariant mass
 
std::string m_particle {"tau-"}
 name of the particle for modes c_MuonParticle and c_ElectronParticle
 
int m_particlePDG {0}
 pdg of the particle for modes c_MuonParticle and c_ElectronParticle, gets set in initialize()
 

Detailed Description

Class to inferface AAFH/DIAG36 Generator written in Fortran.

Almost all parameters can be set using this class. First all parameters should be set, then call initialize(), an arbitary number of generateEvent() and then finish(). After finish(), the total cross section can be obained using getTotalCrossSection()

Definition at line 29 of file AAFHInterface.h.

Member Enumeration Documentation

◆ EMode

enum EMode

Generation mode.

Enumerator
c_MuonParticle 

E+E- -> Mu+Mu-L+L- where L can be anything, defaults to tau.

c_MuonMuon 

E+E- -> Mu+Mu-Mu+Mu-.

c_ElectonMuon 

E+E- -> E+E-Mu+Mu-.

c_ElectronParticle 

E+E- -> E+E-L+L- where L can be anything, defaults to tau.

c_ElectonElectron 

E+E- -> E+E-E+E-.

Definition at line 32 of file AAFHInterface.h.

32 {
36 c_MuonMuon = 2,
38 c_ElectonMuon = 3,
43 };
@ c_ElectonElectron
E+E- -> E+E-E+E-.
Definition: AAFHInterface.h:42
@ c_ElectonMuon
E+E- -> E+E-Mu+Mu-.
Definition: AAFHInterface.h:38
@ c_MuonParticle
E+E- -> Mu+Mu-L+L- where L can be anything, defaults to tau.
Definition: AAFHInterface.h:34
@ c_MuonMuon
E+E- -> Mu+Mu-Mu+Mu-.
Definition: AAFHInterface.h:36
@ c_ElectronParticle
E+E- -> E+E-L+L- where L can be anything, defaults to tau.
Definition: AAFHInterface.h:40

◆ ERejection

enum ERejection

Rejection mode.

Enumerator
c_Once 

Apply rejection only once for the final event.

c_Twice 

Apply rejection first for each sub generator and then for the final event.

Definition at line 46 of file AAFHInterface.h.

46 {
48 c_Once = 1,
51 c_Twice = 2,
52 };
@ c_Twice
Apply rejection first for each sub generator and then for the final event.
Definition: AAFHInterface.h:51
@ c_Once
Apply rejection only once for the final event.
Definition: AAFHInterface.h:48

Member Function Documentation

◆ finish()

void finish ( )

calculate total cross section

Definition at line 319 of file AAFHInterface.cc.

320{
321 aafhdiag36_finish_();
322 // The following code just prints the results. If B2RESULT has been compiled
323 // out this is unneccesary and cppcheck complains so we enclose this in an
324 // ifdef to only be executed if B2RESULT might actually be shown
325#ifndef LOG_NO_B2RESULT
326 B2RESULT("AAFH Generation finished.");
327 B2RESULT("Final cross section: "
328 << std::setprecision(3) << output_.crosec << "+-"
329 << std::setprecision(3) << output_.ercros << " nb");
330 B2RESULT("Minimum invariant mass: "
331 << sqrt(bound_.w2min)*input_.eb << " GeV");
332 B2RESULT("Maximum invariant mass: "
333 << sqrt(bound_.w2max)*input_.eb << " GeV");
334 B2RESULT("Maximum subgenerator weight: " << westat_.maxwe << " ("
335 << westat_.mwe[0] << ", "
336 << westat_.mwe[1] << ", "
337 << westat_.mwe[2] << ", "
338 << westat_.mwe[3] << ")");
339 B2RESULT("Maximum final weight: " << ftstat_.ftmax);
340 //The fortran source says that it's advisable if all subgenerators have the
341 //same probability to account for all peaks in the differental cross section
342 //and that it runs with the highest efficiency when the maximum weights in
343 //all sub generators are equal. So let's calculate appropriate subgenerator
344 //weights by looking how many events were generated per sub generator or the
345 //maximum weights
346 std::array<double, 4> idealWAP;
347 std::array<double, 4> idealWBP;
348 //find the first non-zero weight
349 int reference = 0;
350 for (int i = 0; i < 4; ++i) {
351 if (input_.wap[i] != 0) {
352 reference = i;
353 break;
354 }
355 }
356 //and use that es reference
357 const double w0 = westat_.mwe[reference] * input_.wbp[reference];
358 const double n0 = westat_.iwe[reference] / input_.wap[reference];
359 //now calculate the relative weights we need to get
360 //1) same maximum weight which is inversely proportional to to wbp
361 //2) same number of generated events which is proportional to wap
362 for (int i = 0; i < 4; ++i) {
363 if (input_.wap[i] == 0) {
364 idealWBP[i] = input_.wbp[i];
365 idealWAP[i] = 0;
366 } else {
367 idealWBP[i] = (westat_.mwe[i] * input_.wbp[i]) / w0;
368 idealWAP[i] = n0 * input_.wap[i] / westat_.iwe[i];
369 //and normalize to 1.0
370 idealWAP[i] /= idealWAP[reference];
371 }
372 }
373
374 B2RESULT("To get the same maximum event weight and chance for each sub "
375 "generator use these parameters:");
376 B2RESULT(" 'maxFinalWeight': " << std::setprecision(3)
377 << ftstat_.ftmax * 1.1 << ",");
378 B2RESULT(" 'maxSubgeneratorWeight': " << std::setprecision(3)
379 << westat_.maxwe * 1.1 << ",");
380 B2RESULT(" 'subgeneratorWeights': [" << std::scientific
381 << std::setprecision(3) << idealWAP[0] << ", "
382 << std::setprecision(3) << idealWAP[1] << ", "
383 << std::setprecision(3) << idealWAP[2] << ", "
384 << std::setprecision(3) << idealWAP[3] << ", ");
385 B2RESULT(" " << std::scientific
386 << std::setprecision(3) << idealWBP[0] << ", "
387 << std::setprecision(3) << idealWBP[1] << ", "
388 << std::setprecision(3) << idealWBP[2] << ", "
389 << std::setprecision(3) << idealWBP[3] << "],");
390#endif
391}
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28

◆ generateEvent()

void generateEvent ( MCParticleGraph mpg)

generate one event and add it to the graph in CMS

Definition at line 272 of file AAFHInterface.cc.

273{
274 int status {0};
275 aafhdiag36_event_(&status);
276 if (status != 0) {
277 B2ERROR("Failed to generate event after " << status << " tries, giving up");
278 return;
279 }
280
281 //initial beam particles
282 auto& p1 = mpg.addParticle();
283 auto& p2 = mpg.addParticle();
284
285 //generated particles
286 auto& p3 = mpg.addParticle();
287 auto& p4 = mpg.addParticle();
288 auto& p5 = mpg.addParticle();
289 auto& p6 = mpg.addParticle();
290
291 //array of generated particle pdg codes depends on generated mode
292 std::array<int, 4> pdg {{0}};
293 switch (input2_.iproc) {
294 case c_MuonParticle:
295 pdg = {{m_particlePDG, -m_particlePDG, 13, -13}};
296 break;
297 case c_MuonMuon:
298 pdg = {{13, -13, 13, -13}};
299 break;
300 case c_ElectonMuon:
301 pdg = {{11, -11, 13, -13}};
302 break;
304 pdg = {{11, -11, m_particlePDG, -m_particlePDG}};
305 break;
307 pdg = {{11, -11, 11, -11}};
308 break;
309 }
310
311 updateParticle(p1, momenz_.q1, 11, true);
312 updateParticle(p2, momenz_.q2, -11, true);
313 updateParticle(p3, momenz_.q3, pdg[0]);
314 updateParticle(p4, momenz_.q4, pdg[1]);
315 updateParticle(p5, momenz_.q5, pdg[2]);
316 updateParticle(p6, momenz_.q6, pdg[3]);
317}
int m_particlePDG
pdg of the particle for modes c_MuonParticle and c_ElectronParticle, gets set in initialize()
void updateParticle(MCParticleGraph::GraphParticle &p, double *q, int pdg, bool isInitial=false)
update particle with generated values
GraphParticle & addParticle()
Add new particle to the graph.

◆ getGeneratorWeights()

std::vector< double > getGeneratorWeights ( ) const

Get the relative weights for the sub generators.

Definition at line 197 of file AAFHInterface.cc.

198{
199 std::vector<double> weights(8);
200 std::copy_n(input_.wap, 4, weights.begin());
201 std::copy_n(input_.wbp, 4, weights.begin() + 4);
202 return weights;
203}

◆ getMaxFinalWeight()

double getMaxFinalWeight ( ) const

Get the maximum expected subgenerator weight for the rejection method.

Definition at line 210 of file AAFHInterface.cc.

211{
212 return input_.esft;
213}

◆ getMaxSubGeneratorWeight()

double getMaxSubGeneratorWeight ( ) const

Get the maximum expected final weight for the rejection method.

Definition at line 205 of file AAFHInterface.cc.

206{
207 return input_.eswe;
208}

◆ getMaxTries()

int getMaxTries ( ) const

Get the maximum number of tries to generate an event.

Definition at line 192 of file AAFHInterface.cc.

193{
194 return input2_.itot;
195}

◆ getMinimumMass()

double getMinimumMass ( ) const
inline

Get the minimum invariant mass for the generated event.

Definition at line 85 of file AAFHInterface.h.

85{ return m_minMass; }
double m_minMass
minimum invariant mass

◆ getParticle()

std::string getParticle ( ) const
inline

Get the particle type for modes c_MuonParticle and c_ElectronParticle.

Definition at line 87 of file AAFHInterface.h.

87{ return m_particle; }
std::string m_particle
name of the particle for modes c_MuonParticle and c_ElectronParticle

◆ getSuppressionLimits()

std::vector< double > getSuppressionLimits ( ) const

Get suppression limits.

Definition at line 215 of file AAFHInterface.cc.

216{
217 return {factor_.face, factor_.facm, factor_.facl, factor_.proc};
218}

◆ getTotalCrossSection()

double getTotalCrossSection ( ) const

Return total cross section.

Definition at line 220 of file AAFHInterface.cc.

221{
222 return output_.crosec * Unit::nb;
223}
static const double nb
[nanobarn]
Definition: Unit.h:84

◆ getTotalCrossSectionError()

double getTotalCrossSectionError ( ) const

Return error on the total cross section.

Definition at line 225 of file AAFHInterface.cc.

226{
227 return output_.ercros * Unit::nb;
228}

◆ initialize()

void initialize ( double  beamEnergy,
EMode  mode,
ERejection  rejection 
)

initialize the generator

Definition at line 230 of file AAFHInterface.cc.

231{
232 input_.eb = beamEnergy;
233 //minimum invariant mass is in units of beam energy and needs to be squared
234 bound_.w2min = (m_minMass / beamEnergy) * (m_minMass / beamEnergy);
235 //set mode and rejection scheme
236 input2_.iproc = mode;
237 input2_.irejec = rejection;
238
239 //initialize the L
240 auto* part = TDatabasePDG::Instance()->GetParticle(m_particle.c_str());
241 if (!part) {
242 B2ERROR("AAFH: Particle '" << m_particle << "' does not exist");
243 return;
244 }
245 //set the mass in units of beam energy
246 masses_.xml = part->Mass() / beamEnergy;
247 //set the charge but with opposite sign
248 charge_.qcharg = -part->Charge() / 3.0;
249 //and remember pdg code
250 m_particlePDG = part->PdgCode();
251
252 aafhdiag36_init_();
253}

◆ setGeneratorWeights()

void setGeneratorWeights ( const std::vector< double > &  weights)

Set the relative weights for the sub generators.

Definition at line 151 of file AAFHInterface.cc.

152{
153 if (weights.size() > 8) {
154 B2WARNING("AAFH: more than 8 generator weights supplied, "
155 "ignoring the extra weights");
156 } else if (weights.size() > 4 && weights.size() < 8) {
157 B2WARNING("AAFH: more than 4 but less than 8 generator weights supplied, "
158 "ignoring everything afer the first four");
159 } else if (weights.size() < 4) {
160 B2ERROR("AAFH: not enough generator weights, need exactly four or eight values");
161 }
162 std::copy_n(weights.begin(), 4, input_.wap);
163 if (weights.size() >= 8) {
164 std::copy_n(weights.begin() + 4, 4, input_.wbp);
165 }
166}

◆ setMaxTries()

void setMaxTries ( int  tries)

Set the maximum number of tries to generate an event.

Definition at line 146 of file AAFHInterface.cc.

147{
148 input2_.itot = tries;
149}

◆ setMaxWeights()

void setMaxWeights ( double  subgeneratorWeight,
double  finalWeight 
)

Set the maximum expected weights for the rejection method.

If the weights are to large generation will be ineffective, if they are to small it will generate Error messages

Definition at line 168 of file AAFHInterface.cc.

169{
170 input_.eswe = subgeneratorWeight;
171 input_.esft = finalWeight;
172}

◆ setMinimumMass()

void setMinimumMass ( double  minMass)
inline

Set the minimum invariant mass for the generated event.

Definition at line 67 of file AAFHInterface.h.

67{ m_minMass = minMass; }

◆ setParticle()

void setParticle ( const std::string &  particle)
inline

Set the particle type for modes c_MuonParticle and c_ElectronParticle.

Definition at line 69 of file AAFHInterface.h.

70 {
71 m_particle = particle;
72 }

◆ setSupressionLimits()

void setSupressionLimits ( std::vector< double >  limits)

Set the suppression limits when calculation the matrix elements.

Definition at line 174 of file AAFHInterface.cc.

175{
176 if (limits.size() == 1) {
177 B2WARNING("AAFH: Only one suppression limit supplied, using same value for all limits");
178 factor_.face = limits[0];
179 factor_.facm = limits[0];
180 factor_.facl = limits[0];
181 factor_.proc = limits[0];
182 } else if (limits.size() == 4) {
183 factor_.face = limits[0];
184 factor_.facm = limits[1];
185 factor_.facl = limits[2];
186 factor_.proc = limits[3];
187 } else {
188 B2ERROR("AAFH: Wrong number of suppression limits: supply either one or 4 values");
189 }
190}

◆ updateParticle()

void updateParticle ( MCParticleGraph::GraphParticle p,
double *  q,
int  pdg,
bool  isInitial = false 
)
private

update particle with generated values

Parameters
pMCParticle to be updated
q4-Vector + mass from the generator
pdgpdgcode of the particle
isInitialincoming beam particles

Definition at line 255 of file AAFHInterface.cc.

256{
257 // all values in q are in units of beam energy
258 // z-direction inversed since AAFH uses different convention
259 ROOT::Math::PxPyPzEVector vec(-q[0]*input_.eb, -q[1]*input_.eb, -q[2]*input_.eb, q[3]*input_.eb);
260 p.set4Vector(vec);
261
262 // mass is multiplied by charge sign so take the absolute
263 p.setMass(fabs(q[4])*input_.eb);
264 p.setPDG(pdg);
266
267 if (isInitial) {
268 p.addStatus(MCParticle::c_Initial);
269 }
270}
@ c_Initial
bit 5: Particle is initial such as e+ or e- and not going to Geant4
Definition: MCParticle.h:57
@ c_PrimaryParticle
bit 0: Particle is primary particle.
Definition: MCParticle.h:47
@ c_StableInGenerator
bit 1: Particle is stable, i.e., not decaying in the generator.
Definition: MCParticle.h:49

Member Data Documentation

◆ m_minMass

double m_minMass {0}
private

minimum invariant mass

Definition at line 108 of file AAFHInterface.h.

◆ m_particle

std::string m_particle {"tau-"}
private

name of the particle for modes c_MuonParticle and c_ElectronParticle

Definition at line 110 of file AAFHInterface.h.

◆ m_particlePDG

int m_particlePDG {0}
private

pdg of the particle for modes c_MuonParticle and c_ElectronParticle, gets set in initialize()

Definition at line 113 of file AAFHInterface.h.


The documentation for this class was generated from the following files: