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