1 //--------------------------------------------------------------------------
4 // This software is part of the EvtGen package developed jointly
5 // for the BaBar and CLEO collaborations. If you use all or part
6 // of it, please give an appropriate acknowledgement.
8 // Copyright Information: See EvtGen/COPYRIGHT
9 // Copyright (C) 1998 Caltech, UCSB
11 // Module: EvtDecayBase.cc
13 // Description: Store decay parameters for one decay.
15 // Modification history:
17 // RYD September 30, 1997 Module created
19 //------------------------------------------------------------------------
21 #include "EvtGenBase/EvtPatches.hh"
26 #include "EvtGenBase/EvtStatus.hh"
27 #include "EvtGenBase/EvtDecayBase.hh"
28 #include "EvtGenBase/EvtParticle.hh"
29 #include "EvtGenBase/EvtPDL.hh"
30 #include "EvtGenBase/EvtReport.hh"
31 #include "EvtGenBase/EvtSpinType.hh"
35 void EvtDecayBase::checkQ() {
40 //If there are no daughters (jetset etc) then we do not
41 //want to do this test. Why? Because sometimes the parent
42 //will have a nonzero charge.
45 for(i=0; i<_ndaug; i++ ) {
46 q += EvtPDL::chg3(_daug[i]);
48 qpar = EvtPDL::chg3(_parent);
51 report(ERROR,"EvtGen") <<_modelname.c_str()<< " generator expected "
52 << " charge to be conserved, found:"<<endl;
53 report(ERROR,"EvtGen") << "Parent charge of "<<(qpar/3)<<endl;
54 report(ERROR,"EvtGen") << "Sum of daughter charge of "<<(q/3)<<endl;
55 report(ERROR,"EvtGen") << "The parent is "<< EvtPDL::name(_parent).c_str()<<endl;
56 for(i=0; i<_ndaug; i++ ) {
57 report(ERROR,"EvtGen") << "Daughter "<< EvtPDL::name(_daug[i]).c_str()<<endl;
59 report(ERROR,"EvtGen") << "Will terminate execution!"<<endl;
67 double EvtDecayBase::getProbMax( double prob ) {
73 if (prob>max_prob) max_prob=prob;
76 if ( defaultprobmax && ntimes_prob<=500 ) {
77 //We are building up probmax with this iteration
79 if ( prob > probmax ) { probmax = prob;}
80 if (ntimes_prob==500) {
83 return 1000000.0*prob;
86 if ( prob> probmax*1.0001) {
88 report(INFO,"EvtGen") << "prob > probmax:("<<prob<<">"<<probmax<<")";
89 report(INFO,"") << "("<<_modelname.c_str()<<") ";
90 report(INFO,"") << EvtPDL::name(_parent).c_str()<<" -> ";
91 for(i=0;i<_ndaug;i++){
92 report(INFO,"") << EvtPDL::name(_daug[i]).c_str() << " ";
94 report(INFO,"") << endl;
96 if (defaultprobmax) probmax = prob;
108 double EvtDecayBase::resetProbMax(double prob) {
110 report(INFO,"EvtGen") << "Reseting prob max\n";
111 report(INFO,"EvtGen") << "prob > probmax:("<<prob<<">"<<probmax<<")";
112 report(INFO,"") << "("<<_modelname.c_str()<<")";
113 report(INFO,"") << EvtPDL::getStdHep(_parent)<<"->";
115 for( int i=0;i<_ndaug;i++){
116 report(INFO,"") << EvtPDL::getStdHep(_daug[i]) << " ";
118 report(INFO,"") << endl;
129 std::string EvtDecayBase::commandName(){
130 return std::string("");
133 void EvtDecayBase::command(std::string){
134 report(ERROR,"EvtGen") << "Should never call EvtDecayBase::command"<<endl;
140 void EvtDecayBase::init() {
142 //This default version of init does nothing;
143 //A specialized version of this function can be
144 //supplied for each decay model to do initialization.
150 void EvtDecayBase::initProbMax() {
152 //This function is called if the decay does not have a
153 //specialized initialization.
154 //The default is to set the maximum
155 //probability to 0 and the number of times called to 0
156 //and defaultprobmax to 1 such that the decay will be
157 //generated many many times
158 //in order to generate a reasonable maximum probability
168 void EvtDecayBase::saveDecayInfo(EvtId ipar, int ndaug, EvtId *daug,
169 int narg,std::vector<std::string>& args,
183 _daug=new EvtId [_ndaug];
184 for(i=0;i<_ndaug;i++){
186 _dsum+=daug[i].getAlias();
194 _args=new std::string[_narg+1];
195 for(i=0;i<_narg;i++){
214 report(INFO,"EvtGen") << "No default probmax for ";
215 report(INFO,"") << "("<<_modelname.c_str()<<") ";
216 report(INFO,"") << EvtPDL::name(_parent).c_str()<<" -> ";
217 for(i=0;i<_ndaug;i++){
218 report(INFO,"") << EvtPDL::name(_daug[i]).c_str() << " ";
220 report(INFO,"") << endl;
221 report(INFO,"") << "This is fine for development, but must be provided for production."<<endl;
222 report(INFO,"EvtGen") << "Never fear though - the decay will use the \n";
223 report(INFO,"EvtGen") << "500 iterations to build up a good probmax \n";
224 report(INFO,"EvtGen") << "before accepting a decay. "<<endl;
229 EvtDecayBase::EvtDecayBase() {
231 //the default is that the user module does _not_ set
240 _parent=EvtId(-1,-1);
246 _modelname="**********";
248 //Default is to check that charge is conserved
251 //statistics collection!
260 void EvtDecayBase::printSummary() const {
263 report(INFO,"EvtGen") << "Calls = "<<ntimes_prob<<" eff: "<<
264 sum_prob/(probmax*ntimes_prob)<<" frac. max:"<<max_prob/probmax;
265 report(INFO,"") <<" probmax:"<<probmax<<" max:"<<max_prob<<" : ";
272 void EvtDecayBase::printInfo() const {
273 report(INFO,"") << EvtPDL::name(_parent).c_str()<<" -> ";
274 for(int i=0;i<_ndaug;i++){
275 report(INFO,"") << EvtPDL::name(_daug[i]).c_str() << " ";
277 report(INFO,"") << " ("<<_modelname.c_str()<<")"<< endl;
281 EvtDecayBase::~EvtDecayBase() {
298 void EvtDecayBase::setProbMax(double prbmx){
305 void EvtDecayBase::noProbMax(){
312 double EvtDecayBase::findMaxMass(EvtParticle *p) {
315 double maxOkMass=EvtPDL::getMaxMass(p->getId());
317 //protect against vphotons
318 if ( maxOkMass < 0.0000000001 ) return 10000000.;
319 //and against already determined masses
320 if ( p->hasValidP4() ) maxOkMass=p->mass();
322 EvtParticle *par=p->getParent();
324 double maxParMass=findMaxMass(par);
326 double minDaugMass=0.;
327 for(i=0;i<par->getNDaug();i++){
328 EvtParticle *dau=par->getDaug(i);
330 // it might already have a mass
331 if ( dau->isInitialized() || dau->hasValidP4() )
332 minDaugMass+=dau->mass();
334 //give it a bit of phase space
335 minDaugMass+=1.000001*EvtPDL::getMinMass(dau->getId());
338 if ( maxOkMass>(maxParMass-minDaugMass)) maxOkMass=maxParMass-minDaugMass;
344 // given list of daughters ( by number ) returns a
345 // list of viable masses.
347 void EvtDecayBase::findMass(EvtParticle *p) {
349 //Need to also check that this mass does not screw
351 //This code assumes that for the ith daughter, 0..i-1
352 //already have a mass
353 double maxOkMass=findMaxMass(p);
361 if ( count > 10000 ) {
362 report(INFO,"EvtGen") << "Can not find a valid mass for: " << EvtPDL::name(p->getId()).c_str() <<endl;
363 report(INFO,"EvtGen") << "Now printing parent and/or grandparent tree\n";
364 if ( p->getParent() ) {
365 if ( p->getParent()->getParent() ) {
366 p->getParent()->getParent()->printTree();
367 report(INFO,"EvtGen") << p->getParent()->getParent()->mass() <<endl;
368 report(INFO,"EvtGen") << p->getParent()->mass() <<endl;
371 p->getParent()->printTree();
372 report(INFO,"EvtGen") << p->getParent()->mass() <<endl;
376 report(INFO,"EvtGen") << "maxokmass=" << maxOkMass << " " << EvtPDL::getMinMass(p->getId()) << " " << EvtPDL::getMaxMass(p->getId())<<endl;
377 if ( p->getNDaug() ) {
378 for (i=0; i<p->getNDaug(); i++) {
379 report(INFO,"EvtGen") << p->getDaug(i)->mass()<<" ";
381 report(INFO,"EvtGen") << endl;
383 if ( maxOkMass >= EvtPDL::getMinMass(p->getId()) ) {
384 report(INFO,"EvtGen") << "taking a default value\n";
385 p->setMass(maxOkMass);
390 mass = EvtPDL::getMass(p->getId());
391 //Just need to check that this mass is > than
392 //the mass of all daughters
394 if ( p->getNDaug() ) {
395 for (i=0; i<p->getNDaug(); i++) {
396 massSum+= p->getDaug(i)->mass();
399 //some special cases are handled with 0 (stable) or 1 (k0->ks/kl) daughters
400 if (p->getNDaug()<2) massOk=true;
401 if ( p->getParent() ) {
402 if ( p->getParent()->getNDaug()==1 ) massOk=true;
405 if (massSum < mass) massOk=true;
406 if ( mass> maxOkMass) massOk=false;
415 void EvtDecayBase::findMasses(EvtParticle *p, int ndaugs,
416 EvtId daugs[10], double masses[10]) {
423 if (!( p->firstornot() )) {
424 for (i = 0; i < ndaugs; i++ ) {
425 masses[i] = p->getDaug(i)->mass();
430 // if only one daughter do it
437 //until we get a combo whose masses are less than _parent mass.
441 for (i = 0; i < ndaugs; i++ ) {
442 masses[i] = EvtPDL::getMass(daugs[i]);
443 mass_sum = mass_sum + masses[i];
450 report(ERROR,"EvtGen") <<"Decaying particle:"<<
451 EvtPDL::name(p->getId()).c_str()<<" (m="<<p->mass()<<")"<<endl;
452 report(ERROR,"EvtGen") <<"To the following daugthers"<<endl;
453 for (i = 0; i < ndaugs; i++ ) {
454 report(ERROR,"EvtGen") <<
455 EvtPDL::name(daugs[i]).c_str() << endl;
457 report(ERROR,"EvtGen") << "Has been rejected "<<count
458 << " times, will now take minimal masses "
459 << " of daugthers"<<endl;
462 for (i = 0; i < ndaugs; i++ ) {
463 masses[i] = EvtPDL::getMinMass(daugs[i]);
464 mass_sum = mass_sum + masses[i];
466 if (mass_sum > p->mass()){
467 report(ERROR,"EvtGen") << "Parent mass="<<p->mass()
468 << "to light for daugthers."<<endl
469 << "Will throw the event away."<<endl;
470 //dont terminate - start over on the event.
471 EvtStatus::setRejectFlag();
477 } while ( mass_sum > p->mass());
483 void EvtDecayBase::checkNArg(int a1, int a2, int a3, int a4) {
485 if ( _narg != a1 && _narg != a2 && _narg != a3 && _narg != a4 ) {
486 report(ERROR,"EvtGen") << _modelname.c_str() << " generator expected "<<endl;
487 report(ERROR,"EvtGen") << a1<<endl;;
489 report(ERROR,"EvtGen") << " or " << a2<<endl;
492 report(ERROR,"EvtGen") << " or " << a3<<endl;
495 report(ERROR,"EvtGen") << " or " << a4<<endl;
497 report(ERROR,"EvtGen") << " arguments but found:"<< _narg << endl;
499 report(ERROR,"EvtGen") << "Will terminate execution!"<<endl;
505 void EvtDecayBase::checkNDaug(int d1, int d2){
507 if ( _ndaug != d1 && _ndaug != d2 ) {
508 report(ERROR,"EvtGen") << _modelname.c_str() << " generator expected ";
509 report(ERROR,"EvtGen") << d1;
511 report(ERROR,"EvtGen") << " or " << d2;
513 report(ERROR,"EvtGen") << " daughters but found:"<< _ndaug << endl;
515 report(ERROR,"EvtGen") << "Will terminate execution!"<<endl;
521 void EvtDecayBase::checkSpinParent(EvtSpinType::spintype sp) {
523 EvtSpinType::spintype parenttype = EvtPDL::getSpinType(getParentId());
524 if ( parenttype != sp ) {
525 report(ERROR,"EvtGen") << _modelname.c_str()
526 << " did not get the correct parent spin\n";
528 report(ERROR,"EvtGen") << "Will terminate execution!"<<endl;
534 void EvtDecayBase::checkSpinDaughter(int d1, EvtSpinType::spintype sp) {
536 EvtSpinType::spintype parenttype = EvtPDL::getSpinType(getDaug(d1));
537 if ( parenttype != sp ) {
538 report(ERROR,"EvtGen") << _modelname.c_str()
539 << " did not get the correct daughter spin d="
542 report(ERROR,"EvtGen") << "Will terminate execution!"<<endl;
548 double* EvtDecayBase::getArgs() {
550 if ( _argsD ) return _argsD;
551 //The user has asked for a list of doubles - the arguments
552 //better all be doubles...
553 if ( _narg==0 ) return _argsD;
555 _argsD = new double[_narg];
559 for(i=0;i<_narg;i++) {
560 _argsD[i] = strtod(_args[i].c_str(),&tc);
565 double EvtDecayBase::getArg(unsigned int j) {
569 if (getParentId().getId() == 25) {
574 const char* str = _args[j].c_str();
577 if (isalpha(str[i]) && str[i]!='e') {
579 report(INFO,"EvtGen") << "String " << str << " is not a number" << endl;
586 double result = strtod(_args[j].c_str(),tc);
588 if (_storedArgs.size() < j+1 ){ // then store the argument's value
589 _storedArgs.push_back(result);
599 bool EvtDecayBase::matchingDecay(const EvtDecayBase &other) const {
601 if ( _ndaug != other._ndaug) return false;
602 if ( _parent != other._parent) return false;
604 std::vector<int> useDs;
605 for ( int i=0; i<_ndaug; i++) useDs.push_back(0);
607 for ( int i=0; i<_ndaug; i++) {
609 for ( int j=0; j<_ndaug; j++) {
610 if ( useDs[j] == 1 ) continue;
611 if ( _daug[i] == other._daug[j] && _daug[i].getAlias() == other._daug[j].getAlias()) {
617 if ( foundIt==false) return false;
619 for ( int i=0; i<_ndaug; i++) if ( useDs[i]==0) return false;