BOSS 7.0.7
BESIII Offline Software System
Loading...
Searching...
No Matches
EvtTauola.cc
Go to the documentation of this file.
1//--------------------------------------------------------------------------
2//
3// Environment:
4// This software is part of models developed at BES collaboration
5// based on the EvtGen framework. If you use all or part
6// of it, please give an appropriate acknowledgement.
7//
8// Copyright Information: See EvtGen/BesCopyright
9// Copyright (A) 2006 Ping Rong-Gang
10//
11// Module: EvtTauola.cc
12// the necessary file: tauola2.4.F
13//
14// Description: interface to the tauola package
15//
16// Modification history:
17//
18// Ping R.-G. 2008-07-13 Module created
19//
20//------------------------------------------------------------------------
21//
27#include "EvtGenBase/EvtPDL.hh"
31#include <string>
32#include "EvtGenBase/EvtId.hh"
33#include <iostream>
34#include <iomanip>
35#include <fstream>
36#include <string.h>
37#include <stdlib.h>
38#include <unistd.h>
39#include <stdio.h>
40using std::endl;
41using std::fstream;
42using std::ios;
43using std::ofstream;
44using std::resetiosflags;
45using std::setiosflags;
46using std::setw;
47
48
49int EvtTauola::ntauoladecays=0;
50 EvtDecayBasePtr* EvtTauola::tauoladecays=0;
51int EvtTauola::ntable=0;
52
53int EvtTauola::ncommand=0;
54int EvtTauola::lcommand=0;
55std::string* EvtTauola::commands=0;
56
57
58extern "C" {
59 extern void dectes_(int *, int *,int *,int *,int *,
60 double *,double *,double *,double *);
61}
62
63
65
67
68
69 int i;
70
71
72 //the deletion of commands is really uggly!
73
74 if (ntauoladecays==0) {
75 delete [] commands;
76 commands=0;
77 return;
78 }
79
80 for(i=0;i<ntauoladecays;i++){
81 if (tauoladecays[i]==this){
82 tauoladecays[i]=tauoladecays[ntauoladecays-1];
83 ntauoladecays--;
84 if (ntauoladecays==0) {
85 delete [] commands;
86 commands=0;
87 }
88 return;
89 }
90 }
91
92 report(ERROR,"EvtGen") << "Error in destroying Tauola model!"<<endl;
93
94}
95
96
97void EvtTauola::getName(std::string& model_name){
98
99 model_name="TAUOLA";
100
101}
102
104
105 return new EvtTauola;
106
107}
108
109
111
112 noProbMax();
113
114}
115
116
118
119// checkNArg(1);
120
121
122 if (getParentId().isAlias()){
123
124 report(ERROR,"EvtGen") << "EvtTauola finds that you are decaying the"<<endl
125 << " aliased particle "
126 << EvtPDL::name(getParentId()).c_str()
127 << " with the Tauola model"<<endl
128 << " this does not work, please modify decay table."
129 << endl;
130 report(ERROR,"EvtGen") << "Will terminate execution!"<<endl;
131 ::abort();
132
133 }
134
135 store(this);
136 // std::cout<<"Tauola initialization"<<std::endl;
137
138}
139
140
142
143 return std::string("TauolaPar");
144
145}
146
147void EvtTauola::command(std::string cmd){
148
149 if (ncommand==lcommand){
150
151 lcommand=10+2*lcommand;
152
153 std::string* newcommands=new std::string[lcommand];
154
155 int i;
156
157 for(i=0;i<ncommand;i++){
158 newcommands[i]=commands[i];
159 }
160
161 delete [] commands;
162
163 commands=newcommands;
164
165 }
166
167 commands[ncommand]=cmd;
168
169 ncommand++;
170
171}
172
173
174
176
177 static int iniflag=0;
178
179 static EvtId STRNG=EvtPDL::getId("string");
180
181 int istdheppar=EvtPDL::getStdHep(p->getId());
182
183/*
184 if (pycomp_(&istdheppar)==0){
185 report(ERROR,"EvtGen") << "Tauola can not decay:"
186 <<EvtPDL::name(p->getId()).c_str()<<endl;
187 return;
188 }
189*/
190
191 EvtVector4R p4[20];
192
193
194 int i,more;
195 int idtau=EvtPDL::getStdHep(p->getId());
196 int ndaugjs;
197 static int kf[20];
198 EvtId evtnumstable[20],evtnumparton[20];
199 int stableindex[20],partonindex[20];
200 int numstable;
201 int numparton;
202 static int km[20];
203 EvtId type[MAX_DAUG];
204
205 static double px[20],py[20],pz[20],e[20];
206
207 // std::cout<<"cc: inifag,idtau,taup,polt"<<iniflag<<"; "<<idtau<<"; "<<taup[0]<<"; "<<polt[3]<<endl;
208 if (iniflag==0) dectes_(&iniflag,&idtau,&ndaugjs,kf,km,px,py,pz,e);
209 //std::cout<<"Tauola initialized"<<endl;
210 if ( p->getNDaug() != 0 ) { p->deleteDaughters(true);}
211
212 int count=0;
213
214 do{
215 //report(INFO,"EvtGen") << "calling tauola " << idtau<< " " << mp <<endl;
216 iniflag=iniflag+1; //to count the event number
217 dectes_(&iniflag,&idtau,&ndaugjs,kf,km,px,py,pz,e);
218
219 numstable=0;
220 numparton=0;
221 // report(INFO,"EvtGen") << "found some daughters " << ndaugjs << endl;
222 for(i=0;i<ndaugjs;i++){
223 //std::cout<<"ndaugjs,kf,km,px,py,pz,e: "<<i<<", "<<km[i]<<", "<<kf[i]<<", "<<px[i]<<" ,"<<py[i]<<", "<<pz[i]<<", "<<e[i]<<std::endl; //for debugging
224
225 if (EvtPDL::evtIdFromStdHep(kf[i])==EvtId(-1,-1)) {
226 report(ERROR,"EvtGen") << "Tauola returned particle:"<<kf[i]<<endl;
227 report(ERROR,"EvtGen") << "This can not be translated to evt number"<<endl;
228 report(ERROR,"EvtGen") << "and the decay will be rejected!"<<endl;
229 report(ERROR,"EvtGen") << "The decay was of particle:"<<idtau<<endl;
230
231 }
232
233 //sort out the partons
234 if (abs(kf[i])<=6||kf[i]==21){
235 partonindex[numparton]=i;
236 evtnumparton[numparton]=EvtPDL::evtIdFromStdHep(kf[i]);
237 numparton++;
238 }
239 else{
240 stableindex[numstable]=i;
241 evtnumstable[numstable]=EvtPDL::evtIdFromStdHep(kf[i]);
242 numstable++;
243 }
244
245
246 // have to protect against negative mass^2 for massless particles
247 // i.e. neutrinos and photons.
248 // this is uggly but I need to fix it right now....
249
250 if (px[i]*px[i]+py[i]*py[i]+pz[i]*pz[i]>=e[i]*e[i]){
251
252 e[i]=sqrt(px[i]*px[i]+py[i]*py[i]+pz[i]*pz[i])+0.0000000001;
253
254 }
255
256 p4[i].set(e[i],px[i],py[i],pz[i]);
257
258
259 }
260
261 int channel=EvtDecayTable::inChannelList(p->getId(),numstable,evtnumstable);
262
263
264 more=(channel!=-1);
265
266
267 count++;
268
269 }while( more && (count<10000) );
270
271 if (count>9999) {
272 report(INFO,"EvtGen") << "Too many loops in EvtTauola!!!"<<endl;
273 report(INFO,"EvtGen") << "Parent:"<<EvtPDL::name(getParentId()).c_str()<<endl;
274 for(i=0;i<numstable;i++){
275 report(INFO,"EvtGen") << "Daug("<<i<<")"<<EvtPDL::name(evtnumstable[i]).c_str()<<endl;
276 }
277
278 }
279
280
281
282 if (numparton==0){
283
284 p->makeDaughters(numstable,evtnumstable);
285 int ndaugFound=0;
286 for(i=0;i<numstable;i++){
287 p->getDaug(i)->init(evtnumstable[i],p4[stableindex[i]]);
288 ndaugFound++;
289 }
290 if ( ndaugFound == 0 ) {
291 report(ERROR,"EvtGen") << "Tauola has failed to do a decay ";
292 report(ERROR,"EvtGen") << EvtPDL::name(p->getId()).c_str() << " " << p->mass()<<endl;
293 assert(0);
294 }
295
296 fixPolarizations(p);
297
298 return ;
299
300 }
301 else{
302
303 //have partons in TAUOLA
304
305 EvtVector4R p4string(0.0,0.0,0.0,0.0);
306
307 for(i=0;i<numparton;i++){
308 p4string+=p4[partonindex[i]];
309 }
310
311 int nprimary=1;
312 type[0]=STRNG;
313 for(i=0;i<numstable;i++){
314 if (km[stableindex[i]]==0){
315 type[nprimary++]=evtnumstable[i];
316 }
317 }
318
319 p->makeDaughters(nprimary,type);
320
321 p->getDaug(0)->init(STRNG,p4string);
322
323 EvtVector4R p4partons[10];
324
325 for(i=0;i<numparton;i++){
326 p4partons[i]=p4[partonindex[i]];
327 }
328
329 ((EvtStringParticle*)p->getDaug(0))->initPartons(numparton,p4partons,evtnumparton);
330
331
332
333 nprimary=1;
334
335 for(i=0;i<numstable;i++){
336
337 if (km[stableindex[i]]==0){
338 p->getDaug(nprimary++)->init(evtnumstable[i],p4[stableindex[i]]);
339 }
340 }
341
342
343 int nsecond=0;
344 for(i=0;i<numstable;i++){
345 if (km[stableindex[i]]!=0){
346 type[nsecond++]=evtnumstable[i];
347 }
348 }
349
350
351 p->getDaug(0)->makeDaughters(nsecond,type);
352
353 EvtVector4R p4stringboost(p4string.get(0),-p4string.get(1),
354 -p4string.get(2),-p4string.get(3));
355
356 nsecond=0;
357 for(i=0;i<numstable;i++){
358 if (km[stableindex[i]]!=0){
359 p4[stableindex[i]]=boostTo(p4[stableindex[i]],p4stringboost);
360 p->getDaug(0)->getDaug(nsecond)->init(evtnumstable[i],p4[stableindex[i]]);
361 p->getDaug(0)->getDaug(nsecond)->setDiagonalSpinDensity();
362 p->getDaug(0)->getDaug(nsecond)->decay();
363 nsecond++;
364 }
365 }
366
367 if ( nsecond == 0 ) {
368 report(ERROR,"EvtGen") << "Jetset has failed to do a decay ";
369 report(ERROR,"EvtGen") << EvtPDL::name(p->getId()).c_str() << " " << p->mass() <<endl;
370 assert(0);
371 }
372
373 fixPolarizations(p);
374
375 return ;
376
377 }
378
379}
380
381void EvtTauola::fixPolarizations(EvtParticle *p){
382
383 //special case for now to handle the tau polarization
384
385 int ndaug=p->getNDaug();
386
387 int i;
388
389 // static EvtId tau=EvtPDL::getId("tau-");
390 static EvtId tau=getParentId();
391
392 for(i=0;i<ndaug;i++){
393 if(p->getDaug(i)->getId()==tau){
394
395 EvtSpinDensity rho;
396
397 rho.SetDim(2);
398 rho.Set(0,0,1.0);
399 rho.Set(0,1,0.0);
400
401 rho.Set(1,0,0.0);
402 rho.Set(1,1,1.0);
403
404
405 EvtVector4R p4Psi=p->getDaug(i)->getP4();
406
407 double alpha=atan2(p4Psi.get(2),p4Psi.get(1));
408 double beta=acos(p4Psi.get(3)/p4Psi.d3mag());
409
410
413
414 }
415 }
416
417}
418
419void EvtTauola::store(EvtDecayBase* jsdecay){
420
421 if (ntauoladecays==ntable){
422
423 EvtDecayBasePtr* newtauoladecays=new EvtDecayBasePtr[2*ntable+10];
424 int i;
425 for(i=0;i<ntable;i++){
426 newtauoladecays[i]=tauoladecays[i];
427 }
428 ntable=2*ntable+10;
429 delete [] tauoladecays;
430 tauoladecays=newtauoladecays;
431 }
432
433 tauoladecays[ntauoladecays++]=jsdecay;
434
435
436
437}
438
439
EvtDiracSpinor boostTo(const EvtDiracSpinor &sp, const EvtVector4R p4)
const int MAX_DAUG
Definition: EvtParticle.hh:38
DOUBLE_PRECISION count[3]
ostream & report(Severity severity, const char *facility)
Definition: EvtReport.cc:36
@ ERROR
Definition: EvtReport.hh:49
@ INFO
Definition: EvtReport.hh:52
void dectes_(int *, int *, int *, int *, int *, double *, double *, double *, double *)
const double alpha
void noProbMax()
EvtId getParentId()
Definition: EvtDecayBase.hh:60
void setDaughterSpinDensity(int daughter)
static int inChannelList(EvtId parent, int ndaug, EvtId *daugs)
Definition: EvtId.hh:27
static int getStdHep(EvtId id)
Definition: EvtPDL.hh:56
static EvtId evtIdFromStdHep(int stdhep)
Definition: EvtPDL.cc:244
static std::string name(EvtId i)
Definition: EvtPDL.hh:64
static EvtId getId(const std::string &name)
Definition: EvtPDL.cc:287
void setSpinDensityForwardHelicityBasis(const EvtSpinDensity &rho)
Definition: EvtParticle.cc:178
void makeDaughters(int ndaug, EvtId *id)
virtual void init(EvtId part_n, const EvtVector4R &p4)=0
void decay()
Definition: EvtParticle.cc:404
EvtId getId() const
Definition: EvtParticle.cc:113
void setDiagonalSpinDensity()
Definition: EvtParticle.cc:133
const EvtVector4R & getP4() const
Definition: EvtParticle.cc:121
int getNDaug() const
Definition: EvtParticle.cc:125
EvtParticle * getDaug(int i)
Definition: EvtParticle.cc:85
void deleteDaughters(bool keepChannel=false)
Definition: EvtParticle.cc:540
double mass() const
Definition: EvtParticle.cc:127
void Set(int i, int j, const EvtComplex &rhoij)
void SetDim(int n)
void init()
Definition: EvtTauola.cc:117
std::string commandName()
Definition: EvtTauola.cc:141
void getName(std::string &name)
Definition: EvtTauola.cc:97
void command(std::string cmd)
Definition: EvtTauola.cc:147
EvtDecayBase * clone()
Definition: EvtTauola.cc:103
void decay(EvtParticle *p)
Definition: EvtTauola.cc:175
virtual ~EvtTauola()
Definition: EvtTauola.cc:66
void initProbMax()
Definition: EvtTauola.cc:110
double get(int i) const
Definition: EvtVector4R.hh:179
double d3mag() const
Definition: EvtVector4R.cc:186
void set(int i, double d)
Definition: EvtVector4R.hh:183