46#include "HepMC/GenEvent.h"
47#include "HepMC/GenVertex.h"
48#include "HepMC/GenParticle.h"
50#include "GaudiKernel/SmartDataPtr.h"
53#include "GaudiKernel/MsgStream.h"
54#include "GaudiKernel/ISvcLocator.h"
55#include "GaudiKernel/AlgFactory.h"
56#include "GaudiKernel/DataSvc.h"
57#include "GaudiKernel/SmartDataPtr.h"
58#include "GaudiKernel/IPartPropSvc.h"
62#include "CLHEP/Random/Ranlux64Engine.h"
63#include "CLHEP/Random/RandFlat.h"
69static string mydecayrec;
70static double _amps_max;
80int EvtDecay::m_runNo=0;
88EvtDecay::
EvtDecay(const
string& name, ISvcLocator* pSvcLocator):Algorithm( name, pSvcLocator )
96 declareProperty(
"DecayDecDir", m_DecayDec =
"");
97 declareProperty(
"PdtTableDir", m_PdtTable =
"");
98 declareProperty(
"userDecayTableName", userDecFileName =
"NONE");
99 declareProperty(
"DecayTopology", m_DecayTop =
"");
100 declareProperty(
"DecayRecord", m_DecayRec =
"");
101 declareProperty(
"ParentParticle", m_ParentPart =
"NONE");
102 declareProperty(
"Multiplicity", m_Ncharge =
false);
103 declareProperty(
"NutupleFile",m_NtupleFile =
false);
104 declareProperty(
"mDIY",_mDIY=
false);
105 declareProperty(
"FDPdata",m_SB3File =
"");
106 declareProperty(
"FDPHisT",m_SB3HT =
"");
107 declareProperty(
"FDPpart",m_FDPparticle =
"");
108 declareProperty(
"TruthFile",m_truthFile =
"");
109 declareProperty(
"TruthPart",m_truthPart =
"");
110 declareProperty(
"Psi3SopenCharm",m_Psi4040OpenCharm=
false);
111 declareProperty(
"Psi2openCharm", m_Psi2openCharm=
false);
112 declareProperty(
"SetMthrForConExc",m_SetMthr=0.0);
113 declareProperty(
"statDecays",m_statDecays=
false);
114 declareProperty(
"TagLundCharmModel", m_tagLundModel=
false);
116 declareProperty(
"FileForTrackGen", m_mystring);
118 m_polarization.clear();
119 declareProperty(
"polarization", m_polarization);
120 declareProperty(
"eBeamPolarization", m_eBeamPolarization=-1);
121 m_cluster0.clear();m_wind0.clear();
122 m_cluster1.clear();m_wind1.clear();
123 m_cluster2.clear();m_wind2.clear();
124 declareProperty(
"cluster0",m_cluster0);
125 declareProperty(
"cluster1",m_cluster1);
126 declareProperty(
"cluster2",m_cluster2);
127 declareProperty(
"masswin0",m_wind0);
128 declareProperty(
"masswin1",m_wind1);
129 declareProperty(
"masswin2",m_wind2);
130 declareProperty(
"OutputP4",m_outputp4=
"");
131 declareProperty(
"ReadMeasuredEcms", m_RdMeasuredEcms =
false);
132 declareProperty(
"beamEnergySpread", m_beamEnergySpread = 0);
134 declareProperty(
"ReadTruthAtCM",_truthAtCM=
false);
135 declareProperty(
"ReadTruth",m_ReadTruth);
138 declareProperty(
"RvalueTag",_RvalueTag=
false);
139 declareProperty(
"PrintFSFor",m_printfs=
"");
145 MsgStream log(messageService(), name());
148 system(
"cat $BESEVTGENROOT/share/phokhara_10.0.fferr>phokhara_10.0.fferr");
149 system(
"cat $BESEVTGENROOT/share/phokhara_10.0.ffwarn>phokhara_10.0.ffwarn");
151 if(m_truthFile!=
""){truth.open(m_truthFile.c_str());}
152 log << MSG::INFO <<
"EvtDecay initialize" << endreq;
153 static const bool CREATEIFNOTTHERE(
true);
154 StatusCode RndmStatus = service(
"BesRndmGenSvc", p_BesRndmGenSvc, CREATEIFNOTTHERE);
155 if (!RndmStatus.isSuccess() || 0 == p_BesRndmGenSvc)
157 log << MSG::ERROR <<
" Could not initialize Random Number Service" << endreq;
162 for(
int i=0;i<m_mystring.size();i++){
EvtGlobalSet::SV.push_back(m_mystring[i]);}
166 std::vector<std::vector<int> >myivv;
167 std::vector<std::vector<double> >mydvv;
171 myivv.push_back(m_cluster0);
172 myivv.push_back(m_cluster1);
173 myivv.push_back(m_cluster2);
175 mydvv.push_back(m_wind0);
176 mydvv.push_back(m_wind1);
177 mydvv.push_back(m_wind2);
179 for(
int i=0;i<myivv.size();i++){
180 std::vector<int> theivv;
181 for(
int j=0;j<myivv[i].size();j++){
182 theivv.push_back(myivv[i][j]);
187 for(
int i=0;i<mydvv.size();i++){
188 std::vector<double> thedvv;
189 for(
int j=0;j<mydvv[i].size();j++){
190 thedvv.push_back(mydvv[i][j]);
196 if(m_eBeamPolarization>1) {std::cout<<
"The e-beam polaziation should be in 0 to 1"<<std::endl;abort();}
199 m_ampscalflag =
true;
201 CLHEP::HepRandomEngine* engine = p_BesRndmGenSvc->
GetEngine(
"EVTGEN");
202 const long s = engine->getSeed();
206 m_seeds.push_back(
s);
211 if ( m_DecayDec ==
"") {
212 m_DecayDec=getenv(
"BESEVTGENROOT");
213 m_DecayDec +=
"/share/DECAY.DEC";
216 if ( m_PdtTable ==
"") {
217 m_PdtTable =getenv(
"BESEVTGENROOT");
218 m_PdtTable +=
"/share/pdt.table";
222 std::cout<<
"===================== user decay card ========================"<<std::endl;
223 strcpy(catcmd,
"cat ");
224 strcat(catcmd, userDecFileName.c_str());
233 if (status.isSuccess()) {
234 log << MSG::INFO <<
"got the DataInfoSvc" << endreq;
238 log << MSG::ERROR <<
"could not get the DataInfoSvc" << endreq;
239 return StatusCode::FAILURE;
245 m_Gen =
new EvtGen( m_DecayDec.c_str(), m_PdtTable.c_str(), m_RandomEngine );
247 if(userDecFileName ==
"NONE") log << MSG::INFO <<
"EvtDecay User did not define his Decay table EvtGen will use standart" << endreq;
248 if(!(userDecFileName ==
"NONE")) m_Gen->
readUDecay(userDecFileName.c_str());
250 if(!(m_DecayTop==
" ")) {
251 outfile.open(m_DecayTop.c_str());
258 NTuplePtr nt1(
ntupleSvc(),
"MYROOTFILE/Trk");
259 if(nt1) {m_tuple=nt1;}
261 m_tuple =
ntupleSvc()->book (
"MYROOTFILE/Trk", CLID_ColumnWiseTuple,
"Generator-trk-Ntuple");
263 status = m_tuple->addItem (
"TotNumTrk", TotNumTrk, 0,100);
264 status = m_tuple->addIndexedItem (
"Trk_index", TotNumTrk, m_Trk_index);
265 status = m_tuple->addIndexedItem (
"m_px_trk", TotNumTrk, m_px_trk);
266 status = m_tuple->addIndexedItem (
"m_py_trk", TotNumTrk, m_py_trk);
267 status = m_tuple->addIndexedItem (
"m_pz_trk", TotNumTrk, m_pz_trk);
268 status = m_tuple->addIndexedItem (
"m_en_trk", TotNumTrk, m_en_trk);
269 status = m_tuple->addIndexedItem (
"FST", TotNumTrk, m_fst);
271 status = m_tuple->addItem (
"nchr", m_nchr);
272 status = m_tuple->addItem (
"nchr_e", m_nchr_e);
273 status = m_tuple->addItem (
"nchr_mu", m_nchr_mu);
274 status = m_tuple->addItem (
"nchr_pi", m_nchr_pi);
275 status = m_tuple->addItem (
"nchr_k", m_nchr_k);
276 status = m_tuple->addItem (
"nchr_p", m_nchr_p);
277 status = m_tuple->addItem (
"N_gamma", m_gamma);
278 status = m_tuple->addItem (
"N_gammaFSR", m_gammaFSR);
279 status = m_tuple->addItem (
"Flag1", m_flag1);
281 log << MSG::ERROR <<
" Cannot book N-tuple:"<< long(m_tuple) << endmsg;
282 return StatusCode::FAILURE;
286 NTuplePtr nt2(
ntupleSvc(),
"MYROOTFILE/mass");
287 if(nt2) {mass_tuple=nt2;}
289 mass_tuple =
ntupleSvc()->book (
"MYROOTFILE/mass", CLID_ColumnWiseTuple,
"Generator-mass-Ntuple");
291 status = mass_tuple->addItem (
"m12", m_m12);
292 status = mass_tuple->addItem (
"m13", m_m13);
293 status = mass_tuple->addItem (
"m23", m_m23);
294 status = mass_tuple->addItem (
"m1", m_m1);
295 status = mass_tuple->addItem (
"m2", m_m2);
296 status = mass_tuple->addItem (
"m3", m_m3);
297 status = mass_tuple->addItem (
"costheta1", m_cos1);
298 status = mass_tuple->addItem (
"costheta2", m_cos2);
299 status = mass_tuple->addItem (
"costheta3", m_cos3);
300 status = mass_tuple->addItem (
"ichannel", m_ich);
302 log << MSG::ERROR <<
" Cannot book N-tuple:"<< long(m_tuple) << endmsg;
303 return StatusCode::FAILURE;
307 NTuplePtr nt3(
ntupleSvc(),
"MYROOTFILE/massGen");
308 if(nt3) {massgen_tuple=nt3;}
310 massgen_tuple =
ntupleSvc()->book (
"MYROOTFILE/massGen", CLID_ColumnWiseTuple,
"Generator-mass-Ntuple");
312 status = massgen_tuple->addItem (
"m12", _m12);
313 status = massgen_tuple->addItem (
"m13", _m13);
314 status = massgen_tuple->addItem (
"m23", _m23);
315 status = massgen_tuple->addItem (
"m1", _m1);
316 status = massgen_tuple->addItem (
"m2", _m2);
317 status = massgen_tuple->addItem (
"m3", _m3);
318 status = massgen_tuple->addItem (
"costheta1", _cos1);
319 status = massgen_tuple->addItem (
"costheta2", _cos2);
320 status = massgen_tuple->addItem (
"costheta3", _cos3);
321 status = massgen_tuple->addItem (
"ichannel", _ich);
323 log << MSG::ERROR <<
" Cannot book N-tuple:"<< long(m_tuple) << endmsg;
324 return StatusCode::FAILURE;
330 for(
int i=0;i<500;i++){br[i]=0;}
331 if(!(m_SB3File==
"" && m_SB3HT==
"")) {
332 const char *filename, *histitle;
333 filename=(
char*)m_SB3File.c_str();
334 histitle=(
char*)m_SB3HT.c_str();
335 SuperBody3decay.
setFile(filename);
337 SuperBody3decay.
init();
340 return StatusCode::SUCCESS;
348 MsgStream log(messageService(), name());
351 string key =
"GEN_EVENT";
353 SmartDataPtr<McGenEventCol> McEvtColl(eventSvc(),
"/Event/Gen");
358 if ( McEvtColl == 0 )
361 HepMC::GenEvent* evt=
new GenEvent();
362 evt->set_event_number(m_numberEvent);
365 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
366 int runNo=eventHeader->runNumber();
367 int event=eventHeader->eventNumber();
369 if(
runNo != 0 &&
runNo != m_runNo){m_runNo=
runNo;newRunFlag =
true;}
else{newRunFlag=
false;}
370 if(m_RdMeasuredEcms&& newRunFlag){
375 std::cout<<
"Read Ecms= "<<dbEcms<<std::endl;
377 std::cout<<
"INFO: Read the MeasuredEcms"<<std::endl;
380 std::cout<<
"ERROR: Can not read the MeasuredEcms, try to turn off the ReadEcmsDB"<<std::endl;
381 return StatusCode::FAILURE;
387 callBesEvtGen( evt );
388 if(!(m_DecayTop==
"")) evt->print(outfile);
393 mcColl->push_back(mcEvent);
394 StatusCode sc = eventSvc()->registerObject(
"/Event/Gen",mcColl);
395 if(sc != SUCCESS)
return StatusCode::FAILURE;
401 McGenEventCol::iterator mcItr;
402 for( mcItr = McEvtColl->begin(); mcItr != McEvtColl->end(); mcItr++ )
404 HepMC::GenEvent* hEvt = (*mcItr)->getGenEvt();
409 if(!(m_DecayTop==
"")) hEvt->print(outfile);
412 if(!(m_DecayRec==
"")) std::cout<<std::endl;
415 if( m_NtupleFile ){ m_tuple->write();}
418 std::cout<<
"helangs ";
419 for(
int i=0;i<m_vangs.size();i++) std::cout<<m_vangs[i]<<
" ";
420 std::cout<<std::endl;
422 return StatusCode::SUCCESS;
430StatusCode EvtDecay::callEvtGen( HepMC::GenEvent* hepMCevt )
432 MsgStream log(messageService(), name());
441 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
443 for (
int i=0;i<13;i++)
fst[i]=0;
444 HepMC::GenEvent::particle_const_iterator itp;
446 for( itp=hepMCevt->particles_begin(); itp!=hepMCevt->particles_end(); ++itp )
468 HepMC::GenParticle* hepMCpart=*itp;
469 int stat = hepMCpart->status();
472 if ( stat != 1 )
continue;
474 loop_to_select_eventsB:
475 int id = hepMCpart->pdg_id();
477 hepMCpart->set_status(899);
481 double en =(hepMCpart->momentum()).e();
482 double pex=(hepMCpart->momentum()).px();
483 double pey=(hepMCpart->momentum()).py();
484 double pez=(hepMCpart->momentum()).pz();
487 parentMass=p_init.mass();
493 bool parentFlag=
false;
495 if(m_polarization.size()>0) {
497 }
else if(m_eBeamPolarization>0){
505 int id = hepMCpart->pdg_id();
508 if(
id == 11 ) {
fst[1]++;}
else if(
id == -11){
fst[2]++;}
509 else if(
id == 13){
fst[3]++;}
510 else if(
id == -13){
fst[4]++;}
511 else if(
id == 211){
fst[5]++;}
512 else if(
id ==-211){
fst[6]++;}
513 else if(
id == 321){
fst[7]++;}
514 else if(
id ==-321){
fst[8]++;}
515 else if(
id ==2212){
fst[9]++;}
516 else if(
id ==-2212){
fst[10]++;}
517 else if(
id == 2112){
fst[11]++;}
518 else if(
id ==-2112){
fst[12]++;}
519 if( fabs(
id) == 11) {
nchr_e++;}
520 if( fabs(
id) == 13) {
nchr_mu++;}
521 if( fabs(
id) == 211) {
nchr_pi++;}
522 if( fabs(
id) == 321) {
nchr_k++;}
523 if( fabs(
id) == 2212) {
nchr_p++;}
526 if( m_NtupleFile==
true ){
527 m_Trk_index[AllTrk_index]=id;
528 m_px_trk[AllTrk_index]=pex;
529 m_py_trk[AllTrk_index]=pey;
530 m_pz_trk[AllTrk_index]=pez;
531 m_en_trk[AllTrk_index]=en ;
534 Trk_index[AllTrk_index]=0;
544 if(m_FDPparticle!=
""){
553 if(!(m_SB3File==
"" || m_SB3HT==
"") && parentFlag && first ){
554 SuperBody3decay_make(fdp_ppid, fdp_init );
557 loop_to_select_eventsA:
559 if(m_truthFile!=
"" && m_truthPart!=
""){
562 for(
int id=0;
id<ndaug;
id++){
565 truth<<son.
get(0)<<
" "<<son.
get(1)<<
" "<<son.
get(2)<<
" "<<son.
get(3)<<std::endl;
570 if(_mDIY && parentFlag && m_ampscalflag ) _amps_max=CalAmpsMax(part);
571 if(_mDIY && parentFlag) {
573 double amps=CalAmpsMDIY( part );
574 ratio=amps/_amps_max;
576 if(_mDIY && parentFlag && ratio<=rdm){
goto loop_to_select_eventsA;}
581 if(m_FDPparticle==
""){FDP_part=part;}
582 if(!(m_SB3File==
"" || m_SB3HT==
"") && parentFlag ){ accept=SuperBody3decay_judge( FDP_part); }
583 if(!(m_SB3File==
"" || m_SB3HT==
"") && parentFlag && !accept){
586 goto loop_to_select_eventsB;
587 }
else if(!(m_SB3File==
"" || m_SB3HT==
"") && parentFlag && accept){
588 countChannel(FDP_part);
591 if((m_Psi2openCharm || m_Psi4040OpenCharm) && parentFlag ){
592 if(getModel(part) ==
"OPENCHARM"){
593 std::cout<<
"OPENCHARM model need to set Psi2openCharm and Psi3SopenCharm to be false!"<<std::endl;
597 bool theDecay = opencharm.choseDecay();
601 goto loop_to_select_eventsB;
610 unsigned int modeTag, multiplicityTag;
611 modeTag = theTag.getModeTag();
612 if( getModel(part) ==
"OPENCHARM"||getModel(part) ==
"LUNDCHARM" && m_tagLundModel){
613 multiplicityTag = decayType(part);
617 multiplicityTag = theTag.getMultTag() + decayType(part);
621 if(eventHeader == 0) std::cout <<
"event header unavailable: " << std::endl;
622 if (eventHeader != 0) {
623 eventHeader->setFlag1(modeTag);
624 eventHeader->setFlag2(multiplicityTag);
629 if(!(m_DecayRec==
"")) mydecayrec=part->
writeTreeRec(m_DecayRec);
631 if(m_statDecays && parentFlag ) countChannel(part);
634 if ( log.level() <= MSG::DEBUG ) part->
printTree() ;
635 log << MSG::DEBUG <<
"Converting particles to HepMC" << endreq;
637 makeHepMC(part, hepMCevt, hepMCpart);
639 hepMCpart->set_status(999);
645 for(
int i=0;i<nds;i++){
648 std::cout<<
"vvpp "<<vp1.
get(0)<<
" "<<vp1.
get(1)<<
" "<<vp1.
get(2)<<
" "<<vp1.
get(3)<<std::endl;
652 if(m_ReadTruth.size())ReadTruth(part,m_ReadTruth);
657 for( itp=hepMCevt->particles_begin(); itp!=hepMCevt->particles_end(); ++itp )
659 if (!(*itp)->end_vertex() && ( (*itp)->status()==899 || (*itp)->status()==999 ))
660 (*itp)->set_status(1);
664 if(m_Ncharge ==
true ) {std::cout<<
"Multiplicity: TotoalCharge_e_mu_pi_K_p_gamma_gammaFSR: "
673 if(m_Ncharge ==
true ){std::cout<<
"FinalStates: "
686 <<
fst[12]<<std::endl;}
697 TotNumTrk = AllTrk_index;
701 return StatusCode::SUCCESS;
707StatusCode EvtDecay::callBesEvtGen( HepMC::GenEvent* hepMCevt )
709 MsgStream log(messageService(), name());
719 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
720 for (
int i=0;i<13;i++)
fst[i]=0;
721 HepMC::GenEvent::particle_const_iterator itp;
742 loop_to_select_eventsB:
745 if(m_RdMeasuredEcms && m_beamEnergySpread==0) {
748 }
else if(m_RdMeasuredEcms && m_beamEnergySpread!=0){
749 double cmssig=sqrt(2.)*m_beamEnergySpread;
753 }
else if( (!m_RdMeasuredEcms) && m_beamEnergySpread!=0){
755 double cmssig=sqrt(2.)*m_beamEnergySpread;
759 }
else if((!m_RdMeasuredEcms) && m_beamEnergySpread==0 ){
761 }
else {std::cout<<
"EvtDecay::callBesEvtGen:: bad option"<<std::endl; abort();}
772 HepMC::GenParticle* hepMCpart=
new GenParticle(HepLorentzVector(0,0,0,ppmass),pid,3);
774 bool parentFlag =
false;
777 if(m_polarization.size()>0) {
779 }
else if(m_eBeamPolarization>0){
791 if(m_FDPparticle!=
""){
800 if(!(m_SB3File==
"" || m_SB3HT==
"") && first ){ SuperBody3decay_make( fdp_ppid, fdp_init);}
803 loop_to_select_events:
804 m_Gen->
generateDecay(part);
if(m_numberEvent<=1){ std::cout<<
"after m_Gen->decay "<<std::endl; part->
printTree();}
807 if(_mDIY && m_ampscalflag ) _amps_max=CalAmpsMax(part);
810 for(
int myloop=0;myloop<100;myloop++){
812 double amps=CalAmpsMDIY( part);
813 ratio=amps/_amps_max;
815 if( !isNumber(amps) || !isNumber(_amps_max) || ratio<=0 ) {
819 }
else if( rdm<=ratio) {
825 if(m_truthFile!=
"" && m_truthPart!=
""){
828 for(
int id=0;
id<ndaug;
id++){
831 truth<<son.
get(0)<<
" "<<son.
get(1)<<
" "<<son.
get(2)<<
" "<<son.
get(3)<<std::endl;
837 if(m_FDPparticle==
""){FDP_part=part;}
838 if(!(m_SB3File==
"" || m_SB3HT==
"")){
839 accept=SuperBody3decay_judge( FDP_part);
841 if(!(m_SB3File==
"" || m_SB3HT==
"") && !accept) {
844 goto loop_to_select_eventsB;
845 }
else if(!(m_SB3File==
"" || m_SB3HT==
"") && parentFlag && accept){
846 countChannel(FDP_part);
851 if(m_statDecays && parentFlag) countChannel(part);
858 unsigned int modeTag, multiplicityTag;
859 modeTag = theTag.getModeTag();
860 if( getModel(part) ==
"OPENCHARM"|| getModel(part) ==
"LUNDCHARM" && m_tagLundModel ){
861 multiplicityTag = decayType(part);
864 }
else if(_RvalueTag){
865 multiplicityTag = decayType(part);
867 multiplicityTag = theTag.getMultTag() + decayType(part);
869 if(eventHeader == 0) std::cout <<
"event header unavailable: " << std::endl;
870 if (eventHeader != 0) {
871 eventHeader->setFlag1(modeTag);
872 eventHeader->setFlag2(multiplicityTag);
876 if(m_NtupleFile)m_flag1 = modeTag;
880 if(!(m_DecayRec==
"")) {mydecayrec=part->
writeTreeRec(m_DecayRec);std::cout<<std::endl;};
883 if ( log.level() <= MSG::DEBUG ) part->
printTree() ;
884 log << MSG::DEBUG <<
"Converting particles to HepMC" << endreq;
886 makeHepMC(part, hepMCevt, hepMCpart);
888 if(part->
getNDaug()!=0) hepMCpart->set_status(999);
893 std::cout<<
"_FinalState "<<myd;
894 for(
int ii=0;ii<myd;ii++) {
897 std::cout<<std::endl;
901 for( itp=hepMCevt->particles_begin(); itp!=hepMCevt->particles_end(); ++itp )
903 if (!(*itp)->end_vertex() && ( (*itp)->status()==899 || (*itp)->status()==999 ))
904 (*itp)->set_status(1);
906 HepMC::GenParticle* hepMCpart=*itp;
907 int stat = hepMCpart->status();
908 int id = hepMCpart->pdg_id();
909 if(
abs(
id)==411 ||
abs(
id)==413 ) { (*itp)->set_status(999);stat=999;}
911 if ( stat != 1 )
continue;
914 if(
id == 11 ) {
fst[1]++;}
915 else if(
id == -11) {
fst[2]++;}
916 else if(
id == 13 ) {
fst[3]++;}
917 else if(
id ==-13) {
fst[4]++;}
918 else if(
id==211) {
fst[5]++;}
919 else if(
id==-211) {
fst[6]++;}
920 else if(
id== 321) {
fst[7]++;}
921 else if(
id ==-321) {
fst[8]++;}
922 else if(
id ==2212) {
fst[9]++;}
923 else if(
id==-2212) {
fst[10]++;}
924 else if(
id == 2112){
fst[11]++;}
925 else if(
id==-2112) {
fst[12]++;}
926 if( fabs(
id) == 11) {
nchr_e++;}
927 if( fabs(
id) == 13) {
nchr_mu++;}
928 if( fabs(
id) == 211) {
nchr_pi++;}
929 if( fabs(
id) == 321) {
nchr_k++;}
930 if( fabs(
id) == 2212) {
nchr_p++;}
933 double en =(hepMCpart->momentum()).e();
934 double pex=(hepMCpart->momentum()).px();
935 double pey=(hepMCpart->momentum()).py();
936 double pez=(hepMCpart->momentum()).pz();
938 if( m_NtupleFile==
true &&
id!=0){
939 m_Trk_index[AllTrk_index]=id;
940 m_px_trk[AllTrk_index]=pex;
941 m_py_trk[AllTrk_index]=pey;
942 m_pz_trk[AllTrk_index]=pez;
943 m_en_trk[AllTrk_index]=en ;
955 itp=hepMCevt->particles_begin();
956 (*itp)->set_status(2);
960 if(m_Ncharge ==
true ) {std::cout<<
"Multiplicity: TotoalCharge_e_mu_pi_K_p_gamma_gammaFSR: "
969 if(m_Ncharge ==
true ){std::cout<<
"FinalStates: "
982 <<
fst[12]<<std::endl;}
994 TotNumTrk = AllTrk_index;
998 if(m_ReadTruth.size())ReadTruth(part,m_ReadTruth);
1004 return StatusCode::SUCCESS;
1019 std::cout<<
"Calculated helicity amplitude sqaured are:"<<std::endl;
1020 std::cout<<
"|H_{2}|^2=|H_{-2}|^2= "<<H2/nd<<
" +/- "<<sqrt(H2err/nd)<<endl;
1021 std::cout<<
"|H_{1}|^2=|H_{-1}|^2= "<<H1/nd<<
" +/- "<<sqrt(H1err/nd)<<endl;
1024 MsgStream log(messageService(), name());
1026 log << MSG::INFO <<
"EvtDecay finalized" << endreq;
1028 Forfile.open(
"fort.16",ios::in);
1030 strcpy(delcmd,
"rm -f ");
1031 strcat(delcmd,
"fort.16");
1035 Forfile2.open(
"fort.22",ios::in);
1036 strcpy(delcmd,
"rm -f ");
1037 strcat(delcmd,
"fort.22");
1047 if(!(m_SB3File==
"" || m_SB3HT==
"")){
1048 for(
int i=0;i<500;i++){totalEvt=totalEvt+br[i];}
1049 for(
int i=0;i<500;i++){
1050 double bi=1.0*br[i]/totalEvt;
1051 std::cout<<
"Branching fraction of channel "<<i<<
" is: "<<bi<<std::endl;
1058 for(
int i=0;i<=totalChannels;i++){totalEvt=totalEvt+br[i];}
1059 std::cout<<
"==================Statistical first chain decay ==============================="<<std::endl;
1060 std::cout<<
"i-th channel Events Generated Branching fraction generated "<<std::endl;
1061 for(
int i=0;i<=totalChannels;i++){
1062 std::cout<<
"| "<<i<<
" "<<br[i]<<
" "<<br[i]*1.0/totalEvt<<std::endl;
1065 std::cout<<
"--------------------------------------------------------------------------------"<<std::endl;
1066 std::cout<<
" sum: "<<totalEvt<<
" "<<
"1"<<std::endl;
1067 std::cout<<
"================== End of statistical first chain decay ========================"<<std::endl;
1070 return StatusCode::SUCCESS;
1074StatusCode EvtDecay::makeHepMC(
EvtParticle* part, HepMC::GenEvent* hEvt,
1075 HepMC::GenParticle* hPart)
1077 MsgStream log(messageService(), name());
1081 double ct=(part->
getDaug(0)->get4Pos()).get(0);
1082 double x=(part->
getDaug(0)->get4Pos()).get(1);
1083 double y=(part->
getDaug(0)->get4Pos()).get(2);
1084 double z=(part->
getDaug(0)->get4Pos()).get(3);
1086 HepMC::GenVertex* end_vtx =
new HepMC::GenVertex(HepLorentzVector(x,
y,z,ct));
1087 hEvt->add_vertex( end_vtx );
1088 end_vtx->add_particle_in(hPart);
1092 for(
int it=0;it<ndaug;it++)
1095 double e=(part->
getDaug(it)->getP4Lab()).get(0);
1096 double px=(part->
getDaug(it)->getP4Lab()).get(1);
1097 double py=(part->
getDaug(it)->getP4Lab()).get(2);
1098 double pz=(part->
getDaug(it)->getP4Lab()).get(3);
1104 HepMC::GenParticle* prod_part =
new HepMC::GenParticle(HepLorentzVector(px,py,pz,e),
id,status);
1105 end_vtx->add_particle_out(prod_part);
1106 makeHepMC(part->
getDaug(it),hEvt,prod_part);
1110 if( log.level()<MSG::INFO )
1115 return StatusCode::SUCCESS;
1119void EvtDecay::MeVToGeV (HepMC::GenEvent* evt)
1121 for ( HepMC::GenEvent::particle_iterator p = evt->particles_begin(); p != evt->particles_end(); ++p ) {
1125 HepMC::FourVector tmpfv((*p)->momentum().x()/1000.,
1126 (*p)->momentum().y()/1000.,
1127 (*p)->momentum().z()/1000.,
1128 (*p)->momentum().t()/1000.
1131 (*p)->set_momentum( tmpfv );
1135void EvtDecay::GeVToMeV (HepMC::GenEvent* evt)
1137 for ( HepMC::GenEvent::particle_iterator p = evt->particles_begin(); p != evt->particles_end(); ++p ) {
1140 HepMC::FourVector tmpfv((*p)->momentum().x()*1000.,
1141 (*p)->momentum().y()*1000.,
1142 (*p)->momentum().z()*1000.,
1143 (*p)->momentum().t()*1000.
1146 (*p)->set_momentum( tmpfv );
1154 for(
int i=0;i<100000;i++){
1156 double amps=CalAmpsMDIY(part);
1157 if(amps > amps_max) amps_max=amps;
1159 amps_max=amps_max*1.05;
1160 m_ampscalflag =
false;
1169 m_engine->showStatus();
1178 double rdm= RandFlat::shoot(m_engine);
1186 double xmass2,ymass2;
1191 FinalState_make( ppid, p_init);
1194 for(
int i=0;i<100000;i++){
1197 HepMC::GenParticle* hepMCpart=
new GenParticle(HepLorentzVector(0,0,0,parentMass),parentPDGcode,3);
1205 FinalState_sort(part);
1212 xmass2=(pd1+pd2).mass2();
1213 ymass2=(pd1+pd3).mass2();
1216 double ylow=SuperBody3decay.
getYlow();
1217 double yup=SuperBody3decay.
getYup();
1218 if(xmass2<xlow || xmass2>
xup || ymass2<ylow || ymass2>yup) { part->
deleteTree();
goto regen;}
1219 SuperBody3decay.
HFill(xmass2,ymass2);
1226 m_m12=(pd1+pd2).
mass();
1227 m_m23=(pd2+pd3).
mass();
1228 m_m13=(pd1+pd3).
mass();
1232 mass_tuple->write();
1235 double mj=(pd2+pd3).
mass();
1245bool EvtDecay::SuperBody3decay_judge(
EvtParticle* part){
1246 double xmass2,ymass2;
1251 FinalState_sort( part);
1258 xmass2=(pd1+pd2).mass2();
1259 ymass2=(pd1+pd3).mass2();
1260 accept=SuperBody3decay.
AR(xmass2,ymass2);
1263 if(accept && m_NtupleFile) {
1268 _m12=(pd1+pd2).
mass();
1269 _m23=(pd2+pd3).
mass();
1270 _m13=(pd1+pd3).
mass();
1274 massgen_tuple->write();
1285 identical_flag=
true;
1287 for(
int i=1;i<10000;i++){
1289 HepMC::GenParticle* hepMCpart=
new GenParticle(HepLorentzVector(0,0,0,parentMass),parentPDGcode,3);
1294 if(nson == 2) {
continue;}
else
1296 EvtId xid0,xid1,xid2;
1306 if(pdg0==pdg1 && pdg1==pdg2) {multi=3;}
1307 else if(pdg0==pdg1 ){multi=2;}
1308 else if(pdg0==pdg2 ){multi=2;pdg=pdg1; pdg1=pdg2; pdg2=pdg;}
1309 else if(pdg1==pdg2) {multi=2;pdg=pdg0; pdg0=pdg1; pdg1=pdg2; pdg2=pdg;}
1313 std::cout<<
"No direct three body decay channel found in decay card, I stop run"<<std::endl;
1324 EvtId xid0,xid1,xid2;
1354 assign_momentum(id0,
pd0);
1355 assign_momentum(id1,pd1);
1356 assign_momentum(id2,pd2);
1357 }
else if(multi==2){
1358 assign_momentum2(id0,
pd0);
1359 assign_momentum2(id1,pd1);
1360 assign_momentum2(id2,pd2);
1361 if(son0.
get(0)>son1.
get(0)){son=son0;son0=son1;son1=son;}
1362 }
else if(multi==3){
1363 double En0=
pd0.get(0);
1364 double En1=pd1.
get(0);
1365 double En2=pd2.
get(0);
1366 if(En0 < En1 && En1 < En2) {son0=
pd0;son1=pd1;son2=pd2;}
1367 if(En0 < En2 && En2 < En1) {son0=
pd0;son1=pd2;son2=pd1;}
1368 if(En1 < En0 && En0 < En2) {son0=pd1;son1=
pd0;son2=pd2;}
1369 if(En1 < En2 && En2 < En0) {son0=pd1;son1=pd2;son2=
pd0;}
1370 if(En2 < En0 && En0 < En1) {son0=pd2;son1=
pd0;son2=pd1;}
1371 if(En2 < En1 && En1 < En0) {son0=pd2;son1=pd1;son2=
pd0;}
1378 if(id0==pdg0){son0=
pd0;}
1379 else if(id0==pdg1){son1=
pd0;}
1380 else if(id0==pdg2){son2=
pd0;}
1381 else {std::cout<<
"PID= "<<id0<<
" not machted, I stop"<<std::endl; ::abort();}
1385 if(id0==pdg0 && identical_flag){son0=
pd0;identical_flag=
false;}
1386 else if(id0==pdg1){son1=
pd0;identical_flag=
true;}
1387 else if(id0==pdg2){son2=
pd0;}
1388 else {std::cout<<
"PID not machted, I stop"<<std::endl; ::abort();}
1399 for(
int i=0;i<dn;i++){
1403 if(son_pdg == FDP_pdg){
1423 if(ich>totalChannels) totalChannels = ich;
1427bool EvtDecay::isCharmonium(
EvtId xid){
1443 std::vector<EvtId> Vid; Vid.clear();
1444 Vid.push_back(psi4415);
1445 Vid.push_back(psi4160);
1446 Vid.push_back(psi4040);
1447 Vid.push_back(psi3770);
1448 Vid.push_back(psiprim);
1449 Vid.push_back(jpsi);
1450 Vid.push_back(etac);
1451 Vid.push_back(etac2s);
1453 Vid.push_back(chic0);
1454 Vid.push_back(chic1);
1455 Vid.push_back(chic2);
1456 Vid.push_back(chic0p);
1457 Vid.push_back(chic1p);
1458 Vid.push_back(chic2p);
1461 for(
int i=0;i<Vid.size();i++){
if(xid == Vid[i])
return flag;}
1466bool EvtDecay::isCharm(
EvtId xid){
1484 std::vector<EvtId> Vid; Vid.clear();
1486 Vid.push_back(d0bar);
1491 Vid.push_back(dstp);
1492 Vid.push_back(dstm);
1494 Vid.push_back(ds0bar );
1495 Vid.push_back(dsp );
1496 Vid.push_back(dsm );
1497 Vid.push_back(dsstp );
1498 Vid.push_back(dsstm );
1499 Vid.push_back(ds0stp );
1500 Vid.push_back(ds0stm );
1503 for(
int i=0;i<Vid.size();i++){
if(xid == Vid[i])
return flag;}
1509 for(
int i=0;i<ndg;i++){
1528 if(_RvalueTag){
return Nchannel;}
1531 std::string model = getModel(par,Nchannel);
1532 if( model ==
"OPENCHARM" || model ==
"LUNDCHARM" && m_tagLundModel){
1539 for(
int i=0;i<ndg;i++){
1544 if( isRadecay(par) ){
1545 for(
int i=0;i<ndg;i++){
1547 if( isCharmonium(xid) )
return 1;
1555 if( isCharm(xd1) && isCharm(xd2) ) {
return 2;}
else
1556 if( !isCharmonium(xd1) && !isCharmonium(xd2) && !isCharm(xd1) && !isCharm(xd2) ){
1561 for(
int i=0;i<ndg;i++){
1563 if( isCharmonium(xid) ) {
flag =
true;
break;}
1564 if( isCharm(xid) ) {
flag =
true;
break;}
1566 if( !
flag ){
return 3;}
else {
return 4;}
1573std::string EvtDecay::getModel(
EvtParticle *par,
int mode){
1585void EvtDecay::ReadTruth(
EvtParticle* part,std::vector<std::vector<string> > mylist){
1586 if(mylist.size()<2) {std::cout<<
" Empty list"<<std::endl;abort();}
1588 for(
int k=0;k<mylist[0].size();k++){
1592 for(
int i=1;i<mylist.size();i++){
1594 for(
int j=0;j<mylist[i].size();j++){
1601 vp1=mypart->
getP4();
1605 if( !isNumber(vp1.
get(0)) ) {part->
printTree(); abort();}
1607 printf(
"truth %.12lf %.12lf %.12lf %.12lf \n",vp1.
get(0),vp1.
get(1),vp1.
get(2),vp1.
get(3) );
1613int EvtDecay::isNumber(
double d){
return (d==d);}
1622 for(
int i=0;i<
n;i++){
1626 double eta=sqrt(
n*12.0)*(ri/12-0.5);
1627 double xsig=
sigma*eta+mu;
1630 if(xsig<mx0 || xsig>mx1)
goto rloop;
1634#include "../user/Lenu.inc"
DOUBLE_PRECISION xlow[20]
ObjectVector< McGenEvent > McGenEventCol
*************DOUBLE PRECISION m_pi *DOUBLE PRECISION m_HvecTau2 DOUBLE PRECISION m_HvClone2 DOUBLE PRECISION m_gamma1 DOUBLE PRECISION m_gamma2 DOUBLE PRECISION m_thet1 DOUBLE PRECISION m_thet2 INTEGER m_IFPHOT *COMMON c_Taupair $ !Spin Polarimeter vector first Tau $ !Spin Polarimeter vector second Tau $ !Clone Spin Polarimeter vector first Tau $ !Clone Spin Polarimeter vector second Tau $ !Random Euler angle for cloning st tau $ !Random Euler angle for cloning st tau $ !Random Euler angle for cloning st tau $ !Random Euler angle for cloning nd tau $ !Random Euler angle for cloning nd tau $ !Random Euler angle for cloning nd tau $ !phi of HvecTau1 $ !theta of HvecTau1 $ !phi of HvecTau2 $ !theta of HvecTau2 $ !super key
void setDecayCard(string card)
EvtBesRandom(HepRandomEngine *engine)
std::string getModelName()
static EvtDecayBase * gettheDecay(EvtId parent, int imode)
DataInfoSvc * dataInfoSvc
IDataInfoSvc * tmpInfoSvc
double energySpread(double mu, double sigma)
void readUDecay(const char *const udecay_name)
void generateDecay(int stdhepid, EvtVector4R P, EvtVector4R D, EvtStdHep *evtStdHep, EvtSpinDensity *spinDensity=0)
static std::vector< std::string > SV
static std::vector< std::vector< double > > dVV
static std::vector< std::vector< int > > iVV
bool AR(double xmass2, double ymass2)
void HFill(double xmass2, double ymass2)
void setHTitle(const char *htitle)
void setFile(const char *dtfile)
static int getStdHep(EvtId id)
static void reSetMass(EvtId i, double mass)
static EvtId evtIdFromStdHep(int stdhep)
static std::string name(EvtId i)
static double getMass(EvtId i)
static EvtId getId(const std::string &name)
static EvtParticle * particleFactory(EvtSpinType::spintype spinType)
static EvtId _NextLevelId[20]
void setVectorSpinDensity()
static int _NextLevelDauNum
void setPolarizedSpinDensity(double r00, double r11, double r22)
EvtSpinType::spintype getSpinType() const
const EvtVector4R & getP4() const
EvtParticle * getDaug(int i)
static EvtVector4R _NextLevelP4[20]
std::string writeTreeRec(std::string) const
virtual void setGenseed(long)=0
virtual CLHEP::HepRandomEngine * GetEngine(const std::string &StreamName)=0
Interface to the CLHEP engine.
double complex pa0 double complex pb0ij double complex pc0ijk double complex pd0
double double double double double * m3