Belle II Software  release-06-00-14
Photos.cc
1 #include <stdarg.h>
2 #include <iostream>
3 #include <vector>
4 
5 #include "PhotosRandom.h"
6 #include "PhotosEvent.h"
7 #include "Photos.h"
8 #include "Log.h"
9 using std::vector;
10 using std::cout;
11 using std::endl;
12 using std::ios_base;
13 
14 namespace Photospp {
15 
16  Photos Photos::_instance;
17 
18  vector<vector<int>* >* Photos::supBremList = 0;
19  vector<vector<int>* >* Photos::forceBremList = 0;
20  vector<pair<int, double>* >* Photos::forceMassList = 0;
21  vector<int>* Photos::ignoreStatusCodeList = 0;
22  bool Photos::isSuppressed = false;
23  bool Photos::massFrom4Vector = true;
25  bool Photos::meCorrectionWtForZ = false;
26  bool Photos::meCorrectionWtForW = false;
28  bool Photos::isCreateHistoryEntries = false;
30  bool Photos::IfPair = false;
31  bool Photos::IfPhot = true;
32  int Photos::EventNo = 0;
33  double (*Photos::randomDouble)() = PhotosRandom::randomReal;
34 
35  Photos::MomentumUnits Photos::momentumUnit = Photos::DEFAULT_MOMENTUM;
36 
37  Photos::Photos()
38  {
39  setAlphaQED(0.00729735039);
40  setInfraredCutOff(0.01);
41  setInterference(true);
42  setDoubleBrem(true);
43  setQuatroBrem(false);
45  setCorrectionWtForW(true);
46 
47  // setExponentiation(true) moved to initialize() due to communication
48  // problems with Fortran under MacOS.
49  phokey.iexp = 1;
50  }
51 
53  {
54 // Should return if already initialized?
55 
56  /*******************************************************************************
57  All the following parameter setters can be called after PHOINI.
58  Initialization of kinematic correction against rounding errors.
59  The set values will be used later if called with zero.
60  Default parameter is 1 (no correction) optionally 2, 3, 4
61  In case of exponentiation new version 5 is needed in most cases.
62  Definition given here will be thus overwritten in such a case
63  below in routine PHOCIN
64  *******************************************************************************/
65  if (!phokey.iexp) initializeKinematicCorrections(1);
66  else setExponentiation(true);
67 
68 // Initialize status counter for warning messages
69  for (int i = 0; i < 10; i++) phosta.status[i] = 0;
70 // elementary security level, should remain 1 but we may want to have a method to change.
71  phosta.ifstop = 1;
72 
73  pholun.phlun = 6; // Logical output unit for printing error messages
74 
75 // Further initialization done automatically
76 // see places with - VARIANT A - VARIANT B - all over to switch between options
77 
78 #ifndef VARIANTB
79 //----------- SLOWER VARIANT A, but stable ------------------
80 //--- it is limiting choice for small XPHCUT in fixed orer
81 //--- modes of operation
82 
83 // Best choice is if FINT=2**N where N+1 is maximal number
84 // of charged daughters
85 // see report on overweihted events
86  if (phokey.interf) maxWtInterference(2.0);
87  else maxWtInterference(1.0);
88 #else
89 
90 //----------- FASTER VARIANT B ------------------
91 //-- it is good for tests of fixed order and small XPHCUT
92 //-- but is less promising for more complex cases of interference
93 //-- sometimes fails because of that
94 
95  if (phokey.interf) maxWtInterference(1.8);
96  else maxWtInterference(0.0);
97 #endif
98 //------------END VARIANTS A B -----------------------
99 
100 //------------------------------------------------------------------------------
101 // Print PHOTOS header
102 //------------------------------------------------------------------------------
103  int coutPrec = cout.precision(6);
104  ios_base::fmtflags flags = cout.setf(ios_base::scientific, ios_base::floatfield);
105  cout << endl;
106  cout << "********************************************************************************" << endl << endl;
107 
108  cout << " =========================" << endl;
109  cout << " PHOTOS, Version: " << VER_MAJOR << "." << VER_MINOR << endl;
110  cout << " Released at: " << DAT_DAY << "/" << DAT_MONTH << "/" << DAT_YEAR << endl;
111  cout << " =========================" << endl << endl;
112 
113  cout << " Photos QED corrections in Particle Decays" << endl << endl;
114 
115  cout << " Monte Carlo Program - by E. Barberio, B. van Eijk and Z. Was" << endl;
116  cout << " From version 2.09 - by P. Golonka and Z. Was" << endl;
117  cout << " From version 3.00 - by N. Davidson, T. Przedzinski and Z. Was" << endl;
118 
119  cout << "********************************************************************************" << endl << endl;
120 
121  cout << " Internal (default) input parameters: " << endl << endl;
122  cout << " INTERF= " << phokey.interf << " ISEC= " << phokey.isec << " ITRE= " << phokey.itre
123  << " IEXP= " << phokey.iexp << " IFTOP= " << phokey.iftop << " IFW= " << phokey.ifw << endl;
124  cout << " ALPHA_QED= " << phocop.alpha << " XPHCUT= " << phocop.xphcut << endl << endl;
125 
126  if (phokey.interf) cout << " Option with interference is active" << endl;
127  if (phokey.isec) cout << " Option with double photons is active" << endl;
128  if (phokey.itre) cout << " Option with triple/quatric photons is active" << endl;
129  if (phokey.iexp) cout << " Option with exponentiation is active EPSEXP=" << phokey.expeps << endl;
130  if (phokey.iftop) cout << " Emision in t tbar production is active" << endl;
131  if (phokey.ifw) cout << " Correction wt in decay of W is active" << endl;
132  if (meCorrectionWtForZ) cout << " ME in decay of Z is active" << endl;
133  if (meCorrectionWtForW) cout << " ME in decay of W is active" << endl;
134  if (IfPair) cout << " emission of pairs is active" << endl;
135  if (!IfPhot) cout << " emission of photons is inactive" << endl;
136 
137  cout << endl << " WARNING: /HEPEVT/ is not anymore used." << endl << endl;
138  /*
139  cout<<endl<<" WARNING (1): /HEPEVT/ is not anymore the standard common block"<<endl<<endl;
140 
141  cout<<" PHOTOS expects /HEPEVT/ to have REAL*8 variables. To change to"<<endl;
142  cout<<" REAL*4 modify its declaration in subr. PHOTOS_GET PHOTOS_SET:"<<endl;
143  cout<<" REAL*8 d_h_phep, d_h_vhep"<<endl;
144  cout<<" WARNING (2): check dims. of /hepevt/ /phoqed/ /ph_hepevt/."<<endl;
145  cout<<" HERE: d_h_nmxhep=10000 and NMXHEP=10000"<<endl<<endl;
146  */
147  cout << "********************************************************************************" << endl;
148  // Revert output stream flags and precision
149  cout.precision(coutPrec);
150  cout.flags(flags);
151 
152  // Add reggeon, pomeron and its diffractive states to the list
153  // of decays where bremsstrahlung is suppressed
156  Photos::suppressBremForDecay(0, 9902110);
157  Photos::suppressBremForDecay(0, 9902210);
158  Photos::suppressBremForDecay(0, 9900110);
159  Photos::suppressBremForDecay(0, 9900210);
160  Photos::suppressBremForDecay(0, 9900220);
161  Photos::suppressBremForDecay(0, 9900330);
162  Photos::suppressBremForDecay(0, 9900440);
163 
164  // Set suppression of all pi0 decays and K_L -> gamma e+ e- ...
165  // Previously initialization in Fortran IPHEKL(i) routine and used in PHOCHK
166  // i=1 was emission allowed, i=2 was blocked 0 was when the option was used.
167  // now in IPHEKL_setPi0KLnoEmmision we have only 1 to allow emissions
168  // and 2 to block.
169  // Can be overriden by using 'Photos::IPHEKL_setPi0KLnoEmmision(0)'
170  // method several times use Photos::forceBremForDecay() and can be
171  // over-ruled in part.
172 
173  Photos::IPHEKL_setPi0KLnoEmission(2); // Blocks emission in pi0 and in Kl to gamma e+ e- if parameter is !1 (enables otherwise)
174  Photos::IPHQRK_setQarknoEmission(1, 0);// Blocks emission from quarks if buf=1 (default); enables if buf=2
175  // option 2 is not realistic and for tests only
176 
177 // Initialize Marsaglia and Zaman random number generator
178  PhotosRandom::initialize();
179  }
181  {
182 // prints infomation like Photos::initialize; may be called after reinitializations.
183 
184  /*******************************************************************************
185  Once parameter setters are called after PHOINI one may want to know and write
186  into output info including all reinitializations.
187  *******************************************************************************/
188 
189 
190 //------------------------------------------------------------------------------
191 // Print PHOTOS header again
192 //------------------------------------------------------------------------------
193  int coutPrec = cout.precision(6);
194  ios_base::fmtflags flags = cout.setf(ios_base::scientific, ios_base::floatfield);
195  cout << endl;
196  cout << "********************************************************************************" << endl << endl;
197  cout << " =========================================" << endl;
198  cout << " PHOTOS, information routine" << endl;
199  cout << " Input parameters after reinitialization: " << endl << endl;
200  cout << " =========================================" << endl << endl;
201  cout << "********************************************************************************" << endl << endl;
202  cout << " INTERF= " << phokey.interf << " ISEC= " << phokey.isec << " ITRE= " << phokey.itre
203  << " IEXP= " << phokey.iexp << " IFTOP= " << phokey.iftop << " IFW= " << phokey.ifw << endl;
204  cout << " ALPHA_QED= " << phocop.alpha << " XPHCUT= " << phocop.xphcut << endl << endl;
205 
206  if (phokey.interf) cout << " Option with interference is active" << endl;
207  if (phokey.isec) cout << " Option with double photons is active" << endl;
208  if (phokey.itre) cout << " Option with triple/quatric photons is active" << endl;
209  if (phokey.iexp) cout << " Option with exponentiation is active EPSEXP=" << phokey.expeps << endl;
210  if (phokey.iftop) cout << " Emision in t tbar production is active" << endl;
211  if (phokey.ifw) cout << " Correction wt in decay of W is active" << endl;
212  if (meCorrectionWtForZ) cout << " ME in decay of Z is active" << endl;
213  if (meCorrectionWtForW) cout << " ME in decay of W is active" << endl;
214  if (meCorrectionWtForScalar) cout << " ME in decay of Scalar is active" << endl;
215  if (IfPair) cout << " emission of pairs is active" << endl;
216  if (!IfPhot) cout << " emission of photons is inactive" << endl;
217 
218  cout << endl << " WARNING: /HEPEVT/ is not anymore used." << endl << endl;
219  // Revert output stream flags and precision
220  cout.precision(coutPrec);
221  cout.flags(flags);
222  }
223 
225  {
226  PhotosBranch b(p);
227  if (!b.getSuppressionStatus()) b.process();
228  }
229 
231  {
232  vector<PhotosParticle*> particles = p->getDecayTree();
233  vector<PhotosBranch*> branches = PhotosBranch::createBranches(particles);
234  for (int i = 0; i < (int)branches.size(); i++) branches.at(i)->process();
235  }
236 
237  void Photos::suppressBremForDecay(int count, int motherID, ...)
238  {
239  va_list arg;
240  va_start(arg, motherID);
241  vector<int>* v = new vector<int>();
242  v->push_back(motherID);
243  for (int i = 0; i < count; i++) {
244  v->push_back(va_arg(arg, int));
245  }
246  va_end(arg);
247  v->push_back(0);
248  if (!supBremList) supBremList = new vector< vector<int>* >();
249  supBremList->push_back(v);
250  }
251 
252  void Photos::suppressBremForBranch(int count, int motherID, ...)
253  {
254  va_list arg;
255  va_start(arg, motherID);
256  vector<int>* v = new vector<int>();
257  v->push_back(motherID);
258  for (int i = 0; i < count; i++) {
259  v->push_back(va_arg(arg, int));
260  }
261  va_end(arg);
262  v->push_back(1);
263  if (!supBremList) supBremList = new vector< vector<int>* >();
264  supBremList->push_back(v);
265  }
266 
267  void Photos::forceBremForDecay(int count, int motherID, ...)
268  {
269  va_list arg;
270  va_start(arg, motherID);
271  vector<int>* v = new vector<int>();
272  v->push_back(motherID);
273  for (int i = 0; i < count; i++) {
274  v->push_back(va_arg(arg, int));
275  }
276  va_end(arg);
277  v->push_back(0);
278  if (!forceBremList) forceBremList = new vector< vector<int>* >();
279  forceBremList->push_back(v);
280  }
281 
282  void Photos::forceBremForBranch(int count, int motherID, ...)
283  {
284  va_list arg;
285  va_start(arg, motherID);
286  vector<int>* v = new vector<int>();
287  v->push_back(motherID);
288  for (int i = 0; i < count; i++) {
289  v->push_back(va_arg(arg, int));
290  }
291  va_end(arg);
292  v->push_back(1);
293  if (!forceBremList) forceBremList = new vector< vector<int>* >();
294  forceBremList->push_back(v);
295  }
296 
297  // Previously this functionality was encoded in FORTRAN routine
298  // PHOCHK which was having some other functionality as well
300  {
301  if (m == 1) {
302  cout << "MODOP=1 -- enables emission in pi0 to gamma e+e- : TEST " << endl ;
303  cout << "MODOP=1 -- enables emission in Kl to gamma e+e- : TEST " << endl ;
305  Photos::forceBremForDecay(3, 130, 22, 11, -11);
306  Photos::forceBremForDecay(3, -130, 22, 11, -11);
307  } else if (m != 1) {
308  cout << "MODOP=2 -- blocks emission in Kl to gamma e+e-: DEFAULT" << endl ;
309  cout << "MODOP=2 -- blocks emission in pi0 to gamma e+e-: DEFAULT" << endl ;
311  Photos::suppressBremForDecay(3, 130, 22, 11, -11);
312  Photos::suppressBremForDecay(3, -130, 22, 11, -11);
313  }
314  }
315 
316  // Previously this functionality was encoded in FORTRAN routine
317  // PHOCHK which was having some other functionality as well
318  bool Photos::IPHQRK_setQarknoEmission(int MODCOR, int PDGID)
319  {
320  static int IPHQRK_MODOP = -1;
321  if (IPHQRK_MODOP == -1 && MODCOR == 0) {
322  cout << "stop from IPHQRK_setQarknoEmission lack of initialization" << endl ;
323  exit(-1);
324  } else if (MODCOR != 0) {
325  IPHQRK_MODOP = MODCOR;
326  if (MODCOR == 1) cout << " IPHQRK_setQarknoEmission MODOP=1 -- blocks emission from light quarks: DEFAULT" << endl ;
327  if (MODCOR != 1) cout << " IPHQRK_setQarknoEmission MODOP=2 -- emission from light quarks allowed: TEST " << endl ;
328  }
329  if (IPHQRK_MODOP != 1) return true;
330 
331  return PDGID > 9;
332  }
333 
334  void Photos::createHistoryEntries(bool flag, int status)
335  {
336  if (status < 3) {
337  Log::Warning() << "Photos::createHistoryEntries: status must be >=3" << endl;
338  return;
339  }
340 
341  isCreateHistoryEntries = flag;
342  historyEntriesStatus = status;
343  ignoreParticlesOfStatus(status);
344  }
345 
347  {
348  if (status < 3) {
349  Log::Warning() << "Photos::ignoreParticlesOfStatus: status must be >=3" << endl;
350  return;
351  }
352 
353  if (!ignoreStatusCodeList) ignoreStatusCodeList = new vector<int>();
354 
355  // Do not add duplicate entries to the list
356  for (unsigned int i = 0; i < ignoreStatusCodeList->size(); i++)
357  if (status == ignoreStatusCodeList->at(i)) return;
358 
359  ignoreStatusCodeList->push_back(status);
360  }
361 
363  {
364  if (!ignoreStatusCodeList) return;
365 
366  for (unsigned int i = 0; i < ignoreStatusCodeList->size(); i++) {
367  if (status == ignoreStatusCodeList->at(i)) {
368  ignoreStatusCodeList->erase(ignoreStatusCodeList->begin() + i);
369  return;
370  }
371  }
372  }
373 
375  {
376  if (!ignoreStatusCodeList) return false;
377 
378  for (unsigned int i = 0; i < ignoreStatusCodeList->size(); i++)
379  if (status == ignoreStatusCodeList->at(i)) return true;
380 
381  return false;
382  }
383 
384  void Photos::setRandomGenerator(double (*gen)())
385  {
386  if (gen == NULL) randomDouble = PhotosRandom::randomReal;
387  else randomDouble = gen;
388  }
389 
391  {
392  phokey.iexp = (int) expo;
393  if (expo) {
394  setDoubleBrem(false);
395  setQuatroBrem(false);
396  setInfraredCutOff(0.0000001);
398  phokey.expeps = 0.0001;
399  }
400  }
401 
402  void Photos::setPairEmission(bool corr)
403  {
404  IfPair = corr;
405  }
406 
408  {
409  IfPhot = corr;
410  }
411 
413  {
414  meCorrectionWtForW = corr;
415  }
416 
418  {
419  meCorrectionWtForZ = corr;
420  }
422  {
424  }
425 
426  void Photos::setStopAtCriticalError(bool stop)
427  {
428  phosta.ifstop = (int)stop;
429  if (!stop) {
430  Log::Info() << "PHOTOS production mode. Elementary test of data flow from event record disabled. " << endl
431  << "Prior checks of the complete configuration " << endl
432  << "(for the particular set of input parameters) must have been done! " << endl;
433  }
434  }
435 
436 
438  {
439  if (!forceMassList) forceMassList = new vector<pair<int, double>* >();
440  forceMassList->push_back(new pair<int, double>(pdgid, -1.0));
441  }
442 
443  void Photos::forceMass(int pdgid, double mass)
444  {
445  if (mass < 0.0) {
446  Log::Warning() << "Photos::forceMass: Mass must be > 0.0" << endl;
447  return;
448  }
449 
450  if (!forceMassList) forceMassList = new vector<pair<int, double>* >();
451  forceMassList->push_back(new pair<int, double>(pdgid, mass));
452  }
453 
454 } // namespace Photospp
Controls the configuration and initialization of Photos.
static vector< PhotosBranch * > createBranches(vector< PhotosParticle * > particles)
Create branches from particles list.
Definition: PhotosBranch.cc:93
static bool meCorrectionWtForZ
Flag for complete effects of matrix element (in leptonic Z decays)
Definition: Photos.h:207
static void forceBremForDecay(int count, int motherID,...)
Force processing of a single decay.
Definition: Photos.cc:267
static void setQuatroBrem(bool quatroBrem)
Set bremsstrahlung generation up to multiplicity of 4.
Definition: Photos.h:110
static vector< pair< int, double > * > * forceMassList
List of forced mass values.
Definition: Photos.h:195
static void forceMass(int pdgid, double mass)
When particles with PDGID and -PDGID will be processed by Photos, their mass value will be given by u...
Definition: Photos.cc:443
static void initialize()
Initalize Photos with the parameters previously set via the setter methods.
Definition: Photos.cc:52
static bool isStatusCodeIgnored(int status)
Returns 'true' if status code is ignored.
Definition: Photos.cc:374
static vector< vector< int > * > * supBremList
List of suppressed decays.
Definition: Photos.h:189
static void suppressBremForBranch(int count, int motherID,...)
Suppress processing of whole decay branch.
Definition: Photos.cc:252
static vector< vector< int > * > * forceBremList
List of forced decays.
Definition: Photos.h:192
static void setMeCorrectionWtForW(bool corr)
Switch for complete effects of matrix element (in leptonic W decays)
Definition: Photos.cc:412
static int EventNo
Is event No.
Definition: Photos.h:180
static void setRandomGenerator(double(*gen)())
Substitute build-in generator with external one.
Definition: Photos.cc:384
static bool isSuppressed
Is in suppressed mode.
Definition: Photos.h:183
static void suppressBremForDecay(int count, int motherID,...)
Suppress processing of a single decay.
Definition: Photos.cc:237
static void createHistoryEntries(bool flag, int status)
If event record allows it, create history entries of particles before Photos processing.
Definition: Photos.cc:334
static bool IfPhot
Flag for generating emission of photons.
Definition: Photos.h:219
static double momentum_conservation_threshold
Threshold for momentum conservation check.
Definition: Photos.h:201
static void setExponentiation(bool expo)
Set exponentiation mode.
Definition: Photos.cc:390
static bool isCreateHistoryEntries
Flag for creating historic entries.
Definition: Photos.h:213
static void setInfraredCutOff(double cut_off)
Minimal energy (in units of decaying particle mass) for photons to be explicitly generated.
Definition: Photos.h:98
static void forceBremForBranch(int count, int motherID,...)
Force processing of a whole decay branch.
Definition: Photos.cc:282
static void setTopProcessRadiation(bool top)
Set photon emission in top pair production in quark (gluon) pair annihilation.
Definition: Photos.h:134
static void setInterference(bool interference)
Key for interference, matrix element weight.
Definition: Photos.h:104
static void ignoreParticlesOfStatus(int status)
Ignore particles with given status code.
Definition: Photos.cc:346
static vector< int > * ignoreStatusCodeList
List of ignored status codes.
Definition: Photos.h:198
static void forceMassFromEventRecord(int pdgid)
When particles with PDGID and -PDGID will be processed by Photos, their mass value will be taken from...
Definition: Photos.cc:437
static void maxWtInterference(double interference)
Maximum interference weight.
Definition: Photos.h:95
static void setMeCorrectionWtForZ(bool corr)
Switch for complete effects of matrix element (in leptonic Z decays)
Definition: Photos.cc:417
static void setPhotonEmission(bool ifphot)
Set photon emission.
Definition: Photos.cc:407
static bool meCorrectionWtForScalar
Flag for complete effects of matrix element (in scalars decays)
Definition: Photos.h:204
static void setMeCorrectionWtForScalar(bool corr)
Switch for complete effects of matrix element (in scalar to 2 scalars decays)
Definition: Photos.cc:421
static void IPHEKL_setPi0KLnoEmission(int m)
Block emissions id decays pi0 and K_L -> gamma e+ e- 1 = no suppression 2 (default) = suppressed emis...
Definition: Photos.cc:299
MomentumUnits
Units.
Definition: Photos.h:36
static void processBranch(PhotosParticle *p)
Process decay of whole decay branch starting from given particle.
Definition: Photos.cc:230
static double(* randomDouble)()
Pointer to random generator function.
Definition: Photos.h:226
static bool massFrom4Vector
Is mass from 4-vector or from event record.
Definition: Photos.h:186
static void processParticle(PhotosParticle *p)
Process decay of single particle.
Definition: Photos.cc:224
static void setPairEmission(bool ifpair)
Set pair emission.
Definition: Photos.cc:402
static void setDoubleBrem(bool doub)
Set double bremsstrahlung generation.
Definition: Photos.h:107
static int historyEntriesStatus
Status of history entries.
Definition: Photos.h:223
static void initializeKinematicCorrections(int flag)
Initialize kinematic corrections.
Definition: Photos.h:147
static void iniInfo()
Prints info on Photos initialization (reinitialization) status.
Definition: Photos.cc:180
static void deIgnoreParticlesOfStatus(int status)
Remove 'status' from the list of ignored status codes.
Definition: Photos.cc:362
static bool meCorrectionWtForW
Flag for complete effects of matrix element (in leptonic W decays)
Definition: Photos.h:210
static bool IfPair
Flag for generating emission of pairs.
Definition: Photos.h:216
static void setAlphaQED(double alpha)
Coupling constant alpha QED.
Definition: Photos.h:101