evtgen is hosted by Hepforge, IPPP Durham
EvtGen  2.0.0
Monte Carlo generator of particle decays, in particular the weak decays of heavy flavour particles such as B mesons.
EvtPDL.cpp
Go to the documentation of this file.
1 
2 /***********************************************************************
3 * Copyright 1998-2020 CERN for the benefit of the EvtGen authors *
4 * *
5 * This file is part of EvtGen. *
6 * *
7 * EvtGen is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 3 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * EvtGen is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with EvtGen. If not, see <https://www.gnu.org/licenses/>. *
19 ***********************************************************************/
20 
21 #include "EvtGenBase/EvtPDL.hh"
22 
23 #include "EvtGenBase/EvtId.hh"
26 #include "EvtGenBase/EvtPatches.hh"
27 #include "EvtGenBase/EvtReport.hh"
28 
29 #include <ctype.h>
30 #include <fstream>
31 #include <iostream>
32 #include <stdlib.h>
33 #include <string.h>
34 using std::endl;
35 using std::fstream;
36 using std::ifstream;
37 
38 static int first = 1;
39 
40 unsigned int EvtPDL::_firstAlias;
42 
43 std::map<std::string, int> EvtPDL::_particleNameLookup;
44 
46 {
47  if ( first != 0 ) {
48  first = 0;
49  _nentries = 0;
50  _firstAlias = 999999;
51  }
52 }
53 
54 void EvtPDL::read( const std::string& fname )
55 {
56  std::ifstream pdtIn( fname );
57  if ( !pdtIn ) {
58  EvtGenReport( EVTGEN_ERROR, "EvtGen" )
59  << "Could not open:" << fname << "EvtPDL" << endl;
60  return;
61  }
62  readPDT( pdtIn );
63  pdtIn.close();
64 }
65 
66 void EvtPDL::readPDT( std::istream& indec )
67 {
68  char cmnd[100];
69  char xxxx[100];
70 
71  char pname[100];
72  int stdhepid;
73  double mass;
74  double pwidth;
75  double pmaxwidth;
76  int chg3;
77  int spin2;
78  double ctau;
79  int lundkc;
80  EvtId i;
81 
82  indec.seekg( 0, std::ios::beg );
83 
84  do {
85  char ch, ch1;
86 
87  do {
88  indec.get( ch );
89  if ( ch == '\n' )
90  indec.get( ch );
91  if ( ch != '*' ) {
92  indec.putback( ch );
93  } else {
94  while ( indec.get( ch1 ), ch1 != '\n' )
95  ;
96  }
97  } while ( ch == '*' );
98 
99  indec >> cmnd;
100 
101  if ( strcmp( cmnd, "end" ) ) {
102  if ( !strcmp( cmnd, "add" ) ) {
103  indec >> xxxx;
104  indec >> xxxx;
105  indec >> pname;
106  indec >> stdhepid;
107  indec >> mass;
108  indec >> pwidth;
109  indec >> pmaxwidth;
110  indec >> chg3;
111  indec >> spin2;
112  indec >> ctau;
113  indec >> lundkc;
114 
115  i = EvtId( _nentries, _nentries );
116 
117  EvtPartProp tmp;
118 
120 
121  if ( spin2 == 0 )
123  if ( spin2 == 1 )
125  if ( spin2 == 2 )
127  if ( spin2 == 3 )
129  if ( spin2 == 4 )
131  if ( spin2 == 5 )
133  if ( spin2 == 6 )
135  if ( spin2 == 7 )
137  if ( spin2 == 8 )
139  if ( spin2 == 2 && mass < 0.0001 )
141  if ( spin2 == 1 && mass < 0.0001 )
143 
144  if ( !strcmp( pname, "string" ) ) {
146  }
147 
148  if ( !strcmp( pname, "vpho" ) ) {
150  }
151 
152  tmp.setId( i );
153  tmp.setIdChgConj( EvtId( -1, -1 ) );
154  tmp.setStdHep( stdhepid );
155  tmp.setLundKC( lundkc );
156  tmp.setName( pname );
157  if ( _particleNameLookup.find( std::string( pname ) ) !=
158  _particleNameLookup.end() ) {
159  EvtGenReport( EVTGEN_ERROR, "EvtGen" )
160  << "The particle name:" << pname
161  << " is already defined." << endl;
162  EvtGenReport( EVTGEN_ERROR, "EvtGen" )
163  << "Will terminate execution.";
164  ::abort();
165  }
166  _particleNameLookup[std::string( pname )] = _nentries;
167  tmp.setctau( ctau );
168  tmp.setChg3( chg3 );
169 
170  tmp.initLineShape( mass, pwidth, pmaxwidth );
171 
172  partlist().push_back( tmp );
173  _nentries++;
174  }
175 
176  // if find a set read information and discard it
177 
178  if ( !strcmp( cmnd, "set" ) ) {
179  indec >> xxxx;
180  indec >> xxxx;
181  indec >> xxxx;
182  indec >> xxxx;
183  }
184  }
185 
186  } while ( strcmp( cmnd, "end" ) );
187 
188  setUpConstsPdt();
189 }
190 
192 {
193  if ( EvtPDL::chargeConj( EvtId( a.getId(), a.getId() ) ) !=
194  EvtId( abar.getId(), abar.getId() ) ) {
195  EvtGenReport( EVTGEN_ERROR, "EvtGen" )
196  << "Can't charge conjugate the two aliases:"
197  << EvtPDL::name( a ).c_str() << " and "
198  << EvtPDL::name( abar ).c_str() << endl;
199 
200  ::abort();
201  }
202 
203  partlist()[a.getAlias()].setIdChgConj( abar );
204  partlist()[abar.getAlias()].setIdChgConj( a );
205 }
206 
208 {
209  // EvtId idchg=partlist()[id.getAlias()].getIdChgConj();
210  int index = id.getAlias();
211  EvtId idchg;
212  if ( index > -1 ) {
213  idchg = partlist()[id.getAlias()].getIdChgConj();
214  }
215 
216  if ( idchg != EvtId( -1, -1 ) )
217  return idchg;
218 
219  if ( id.getId() != id.getAlias() ) {
220  if ( chargeConj( EvtId( id.getId(), id.getId() ) ) ==
221  EvtId( id.getId(), id.getId() ) ) {
222  partlist()[id.getAlias()].setIdChgConj( id );
223  return id;
224  }
225  }
226 
227  if ( id.getAlias() != id.getId() ) {
228  EvtGenReport( EVTGEN_ERROR, "EvtGen" )
229  << "Trying to charge conjugate alias particle:" << name( id ).c_str()
230  << " without defining the alias!" << endl;
231 
232  ::abort();
233  }
234 
235  for ( size_t i = 0; i < partlist().size(); i++ ) {
236  if ( partlist()[i].getStdHep() == -partlist()[id.getId()].getStdHep() ) {
237  partlist()[id.getId()].setIdChgConj( partlist()[i].getId() );
238  return partlist()[i].getId();
239  }
240  }
241 
242  partlist()[id.getId()].setIdChgConj( id );
243  return id;
244 }
245 
247 {
248  for ( size_t i = 0; i < partlist().size(); i++ ) {
249  if ( partlist()[i].getStdHep() == stdhep )
250  return partlist()[i].getId();
251  }
252 
253  return EvtId( -1, -1 );
254 }
255 
256 void EvtPDL::alias( EvtId num, const std::string& newname )
257 {
258  if ( _firstAlias < partlist().size() ) {
259  for ( size_t i = _firstAlias; i < partlist().size(); i-- ) {
260  if ( newname == partlist()[i].getName() ) {
261  EvtGenReport( EVTGEN_WARNING, "EvtGen" )
262  << "Redefining alias:" << newname.c_str()
263  << " will be ignored!" << endl;
264  return;
265  }
266  }
267  } else {
268  _firstAlias = partlist().size();
269  }
270 
271  partlist().push_back( partlist()[num.getId()] );
272  int entry = partlist().size() - 1;
273  partlist()[entry].setName( newname );
274  if ( _particleNameLookup.find( std::string( newname ) ) !=
275  _particleNameLookup.end() ) {
276  EvtGenReport( EVTGEN_ERROR, "EvtGen" )
277  << "The particle name:" << newname << " is already defined." << endl;
278  EvtGenReport( EVTGEN_ERROR, "EvtGen" ) << "Will terminate execution.";
279  ::abort();
280  }
281  _particleNameLookup[std::string( newname )] = entry;
282  partlist()[entry].setId( EvtId( num.getId(), entry ) );
283  //Lange - Dec7, 2003. Unset the charge conjugate.
284  partlist()[entry].setIdChgConj( EvtId( -1, -1 ) );
285 }
286 
287 EvtId EvtPDL::getId( const std::string& name )
288 {
289  std::map<std::string, int>::iterator it = _particleNameLookup.find(
290  std::string( name ) );
291  if ( it == _particleNameLookup.end() )
292  return EvtId( -1, -1 );
293 
294  return partlist()[it->second].getId();
295 }
296 
298 {
299 }
300 
301 // Function to get EvtId from LundKC ( == Pythia Hep Code , KF )
303 {
304  unsigned int i;
305 
306  for ( i = 0; i < partlist().size(); i++ ) {
307  if ( partlist()[i].getLundKC() == pythiaId )
308  return partlist()[i].getId();
309  }
310 
311  return EvtId( -1, -1 );
312 }
313 
315 {
316  return partlist()[i.getId()].getMass();
317 }
318 
320 {
321  return partlist()[i.getId()].rollMass();
322 }
323 
324 double EvtPDL::getRandMass( EvtId i, EvtId* parId, int nDaug, EvtId* dauId,
325  EvtId* othDaugId, double maxMass, double* dauMasses )
326 {
327  return partlist()[i.getId()].getRandMass( parId, nDaug, dauId, othDaugId,
328  maxMass, dauMasses );
329 }
330 
331 double EvtPDL::getMassProb( EvtId i, double mass, double massPar, int nDaug,
332  double* massDau )
333 {
334  return partlist()[i.getId()].getMassProb( mass, massPar, nDaug, massDau );
335 }
336 
338 {
339  return partlist()[i.getId()].getMassMax();
340 }
341 
343 {
344  return partlist()[i.getId()].getMassMin();
345 }
346 
348 {
349  return partlist()[i.getId()].getMaxRange();
350 }
351 
353 {
354  return partlist()[i.getId()].getWidth();
355 }
356 
358 {
359  return partlist()[i.getId()].getctau();
360 }
361 
363 {
364  return partlist()[id.getId()].getStdHep();
365 }
366 
368 {
369  return partlist()[id.getId()].getLundKC();
370 }
371 
373 {
374  return partlist()[i.getId()].getChg3();
375 }
376 
378 {
379  return partlist()[i.getId()].getSpinType();
380 }
381 
382 std::string EvtPDL::name( EvtId i )
383 {
384  return partlist()[i.getAlias()].getName();
385 }
386 
388 {
389  return partlist().size();
390 }
391 
393 {
394  return partlist()[i].getId();
395 }
396 
397 void EvtPDL::reSetMass( EvtId i, double mass )
398 {
399  partlist()[i.getId()].reSetMass( mass );
400 }
401 
402 void EvtPDL::reSetWidth( EvtId i, double width )
403 {
404  partlist()[i.getId()].reSetWidth( width );
405 }
406 
407 void EvtPDL::reSetMassMin( EvtId i, double mass )
408 {
409  partlist()[i.getId()].reSetMassMin( mass );
410 }
411 
412 void EvtPDL::reSetMassMax( EvtId i, double mass )
413 {
414  partlist()[i.getId()].reSetMassMax( mass );
415 }
416 
417 void EvtPDL::reSetBlatt( EvtId i, double blatt )
418 {
419  partlist()[i.getId()].reSetBlatt( blatt );
420 }
421 
422 void EvtPDL::reSetBlattBirth( EvtId i, double blatt )
423 {
424  partlist()[i.getId()].reSetBlattBirth( blatt );
425 }
426 
427 void EvtPDL::includeBirthFactor( EvtId i, bool yesno )
428 {
429  partlist()[i.getId()].includeBirthFactor( yesno );
430 }
431 
432 void EvtPDL::includeDecayFactor( EvtId i, bool yesno )
433 {
434  partlist()[i.getId()].includeDecayFactor( yesno );
435 }
436 
437 void EvtPDL::changeLS( EvtId i, std::string& newLS )
438 {
439  partlist()[i.getId()].newLineShape( newLS );
440 }
441 
442 void EvtPDL::setPWForDecay( EvtId i, int spin, EvtId d1, EvtId d2 )
443 {
444  partlist()[i.getId()].setPWForDecay( spin, d1, d2 );
445 }
446 
447 void EvtPDL::setPWForBirthL( EvtId i, int spin, EvtId par, EvtId othD )
448 {
449  partlist()[i.getId()].setPWForBirthL( spin, par, othD );
450 }
void setStdHep(int stdhep)
Definition: EvtPartProp.hh:72
static unsigned int _firstAlias
Definition: EvtPDL.hh:87
static void reSetMass(EvtId i, double mass)
Definition: EvtPDL.cpp:397
static std::string name(EvtId i)
Definition: EvtPDL.cpp:382
static int _nentries
Definition: EvtPDL.hh:88
static std::vector< EvtPartProp > & partlist()
Definition: EvtPDL.hh:90
static void reSetMassMin(EvtId i, double mass)
Definition: EvtPDL.cpp:407
static EvtId evtIdFromLundKC(int pythiaId)
Definition: EvtPDL.cpp:302
static EvtId getEntry(int i)
Definition: EvtPDL.cpp:392
static EvtSpinType::spintype getSpinType(EvtId i)
Definition: EvtPDL.cpp:377
void setUpConstsPdt()
Definition: EvtPDL.cpp:297
void setChg3(int c3)
Definition: EvtPartProp.hh:57
void read(const std::string &fname)
Definition: EvtPDL.cpp:54
static void reSetWidth(EvtId i, double width)
Definition: EvtPDL.cpp:402
void setctau(double tau)
Definition: EvtPartProp.hh:54
std::ostream & EvtGenReport(EvtGenSeverity severity, const char *facility=0)
Definition: EvtReport.cpp:33
static double getMassProb(EvtId i, double mass, double massPar, int nDaug, double *massDau)
Definition: EvtPDL.cpp:331
static int getLundKC(EvtId id)
Definition: EvtPDL.cpp:367
static void setPWForDecay(EvtId i, int spin, EvtId d1, EvtId d2)
Definition: EvtPDL.cpp:442
static std::map< std::string, int > _particleNameLookup
Definition: EvtPDL.hh:96
static double getctau(EvtId i)
Definition: EvtPDL.cpp:357
static void reSetBlatt(EvtId i, double blatt)
Definition: EvtPDL.cpp:417
static void includeDecayFactor(EvtId i, bool yesno)
Definition: EvtPDL.cpp:432
static double getMeanMass(EvtId i)
Definition: EvtPDL.cpp:314
void readPDT(std::istream &data)
Definition: EvtPDL.cpp:66
void setIdChgConj(EvtId idchgconj)
Definition: EvtPartProp.hh:69
static void alias(EvtId num, const std::string &newname)
Definition: EvtPDL.cpp:256
static int chg3(EvtId i)
Definition: EvtPDL.cpp:372
static void reSetBlattBirth(EvtId i, double blatt)
Definition: EvtPDL.cpp:422
void setSpinType(EvtSpinType::spintype stype)
Definition: EvtPartProp.hh:60
Definition: EvtId.hh:27
void setName(std::string pname)
Definition: EvtPartProp.cpp:57
static double getMinMass(EvtId i)
Definition: EvtPDL.cpp:342
static size_t entries()
Definition: EvtPDL.cpp:387
static EvtId evtIdFromStdHep(int stdhep)
Definition: EvtPDL.cpp:246
static void changeLS(EvtId i, std::string &newLS)
Definition: EvtPDL.cpp:437
static EvtId getId(const std::string &name)
Definition: EvtPDL.cpp:287
int getId() const
Definition: EvtId.hh:42
static double getWidth(EvtId i)
Definition: EvtPDL.cpp:352
EvtPDL()
Definition: EvtPDL.cpp:45
static void aliasChgConj(EvtId a, EvtId abar)
Definition: EvtPDL.cpp:191
static void reSetMassMax(EvtId i, double mass)
Definition: EvtPDL.cpp:412
static double getMaxRange(EvtId i)
Definition: EvtPDL.cpp:347
static void setPWForBirthL(EvtId i, int spin, EvtId par, EvtId othD)
Definition: EvtPDL.cpp:447
static int first
Definition: EvtPDL.cpp:38
int getAlias() const
Definition: EvtId.hh:44
static double getMass(EvtId i)
Definition: EvtPDL.cpp:319
static EvtId chargeConj(EvtId id)
Definition: EvtPDL.cpp:207
static int getStdHep(EvtId id)
Definition: EvtPDL.cpp:362
void setLundKC(int lundkc)
Definition: EvtPartProp.hh:75
static double getMaxMass(EvtId i)
Definition: EvtPDL.cpp:337
static void includeBirthFactor(EvtId i, bool yesno)
Definition: EvtPDL.cpp:427
void initLineShape(double mass, double width, double maxRange)
Definition: EvtPartProp.cpp:73
void setId(EvtId id)
Definition: EvtPartProp.hh:66
static double getRandMass(EvtId i, EvtId *parId, int nDaug, EvtId *dauId, EvtId *othDaugId, double maxMass, double *dauMasses)
Definition: EvtPDL.cpp:324