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;
91 declareProperty(
"DecayDecDir", m_DecayDec =
"");
92 declareProperty(
"PdtTableDir", m_PdtTable =
"");
93 declareProperty(
"userDecayTableName", userDecFileName =
"NONE");
94 declareProperty(
"DecayTopology", m_DecayTop =
"");
95 declareProperty(
"DecayRecord", m_DecayRec =
"");
96 declareProperty(
"ParentParticle", m_ParentPart =
"NONE");
97 declareProperty(
"Multiplicity", m_Ncharge =
false);
98 declareProperty(
"NutupleFile",m_NtupleFile =
false);
99 declareProperty(
"mDIY",_mDIY=
false);
100 declareProperty(
"FDPdata",m_SB3File =
"");
101 declareProperty(
"FDPHisT",m_SB3HT =
"");
102 declareProperty(
"FDPpart",m_FDPparticle =
"");
103 declareProperty(
"TruthFile",m_truthFile =
"");
104 declareProperty(
"TruthPart",m_truthPart =
"");
105 declareProperty(
"Psi3SopenCharm",m_Psi4040OpenCharm=
false);
106 declareProperty(
"Psi2openCharm", m_Psi2openCharm=
false);
107 declareProperty(
"SetMthrForConExc",m_SetMthr=0.0);
108 declareProperty(
"statDecays",m_statDecays=
false);
109 declareProperty(
"TagLundCharmModel", m_tagLundModel=
false);
111 declareProperty(
"FileForTrackGen", m_mystring);
113 m_polarization.clear();
114 declareProperty(
"polarization", m_polarization);
115 declareProperty(
"eBeamPolarization", m_eBeamPolarization=-1);
116 m_cluster0.clear();m_wind0.clear();
117 m_cluster1.clear();m_wind1.clear();
118 m_cluster2.clear();m_wind2.clear();
119 declareProperty(
"cluster0",m_cluster0);
120 declareProperty(
"cluster1",m_cluster1);
121 declareProperty(
"cluster2",m_cluster2);
122 declareProperty(
"masswin0",m_wind0);
123 declareProperty(
"masswin1",m_wind1);
124 declareProperty(
"masswin2",m_wind2);
125 declareProperty(
"OutputP4",m_outputp4=
"");
126 declareProperty(
"ReadMeasuredEcms", m_RdMeasuredEcms =
false);
127 declareProperty(
"beamEnergySpread", m_beamEnergySpread = 0);
129 declareProperty(
"ReadTruthAtCM",_truthAtCM=
false);
130 declareProperty(
"ReadTruth",m_ReadTruth);
133 declareProperty(
"RvalueTag",_RvalueTag=
false);
134 declareProperty(
"PrintFSFor",m_printfs=
"");
140 MsgStream log(messageService(), name());
141 system(
"cat $BESEVTGENROOT/share/phokhara_9.1.fferr>phokhara_9.1.fferr");
142 system(
"cat $BESEVTGENROOT/share/phokhara_9.1.ffwarn>phokhara_9.1.ffwarn");
144 if(m_truthFile!=
""){truth.open(m_truthFile.c_str());}
145 log << MSG::INFO <<
"EvtDecay initialize" << endreq;
146 static const bool CREATEIFNOTTHERE(
true);
147 StatusCode RndmStatus = service(
"BesRndmGenSvc", p_BesRndmGenSvc, CREATEIFNOTTHERE);
148 if (!RndmStatus.isSuccess() || 0 == p_BesRndmGenSvc)
150 log << MSG::ERROR <<
" Could not initialize Random Number Service" << endreq;
155 for(
int i=0;i<m_mystring.size();i++){
EvtGlobalSet::SV.push_back(m_mystring[i]);}
159 std::vector<std::vector<int> >myivv;
160 std::vector<std::vector<double> >mydvv;
164 myivv.push_back(m_cluster0);
165 myivv.push_back(m_cluster1);
166 myivv.push_back(m_cluster2);
168 mydvv.push_back(m_wind0);
169 mydvv.push_back(m_wind1);
170 mydvv.push_back(m_wind2);
172 for(
int i=0;i<myivv.size();i++){
173 std::vector<int> theivv;
174 for(
int j=0;j<myivv[i].size();j++){
175 theivv.push_back(myivv[i][j]);
180 for(
int i=0;i<mydvv.size();i++){
181 std::vector<double> thedvv;
182 for(
int j=0;j<mydvv[i].size();j++){
183 thedvv.push_back(mydvv[i][j]);
189 if(m_eBeamPolarization>1) {std::cout<<
"The e-beam polaziation should be in 0 to 1"<<std::endl;abort();}
192 m_ampscalflag =
true;
194 CLHEP::HepRandomEngine* engine = p_BesRndmGenSvc->
GetEngine(
"EVTGEN");
195 const long s = engine->getSeed();
199 m_seeds.push_back(
s);
204 if ( m_DecayDec ==
"") {
205 m_DecayDec=getenv(
"BESEVTGENROOT");
206 m_DecayDec +=
"/share/DECAY.DEC";
209 if ( m_PdtTable ==
"") {
210 m_PdtTable =getenv(
"BESEVTGENROOT");
211 m_PdtTable +=
"/share/pdt.table";
215 std::cout<<
"===================== user decay card ========================"<<std::endl;
216 strcpy(catcmd,
"cat ");
217 strcat(catcmd, userDecFileName.c_str());
226 if (status.isSuccess()) {
227 log << MSG::INFO <<
"got the DataInfoSvc" << endreq;
231 log << MSG::ERROR <<
"could not get the DataInfoSvc" << endreq;
232 return StatusCode::FAILURE;
238 m_Gen =
new EvtGen( m_DecayDec.c_str(), m_PdtTable.c_str(), m_RandomEngine );
240 if(userDecFileName ==
"NONE") log << MSG::INFO <<
"EvtDecay User did not define his Decay table EvtGen will use standart" << endreq;
241 if(!(userDecFileName ==
"NONE")) m_Gen->
readUDecay(userDecFileName.c_str());
243 if(!(m_DecayTop==
" ")) {
244 outfile.open(m_DecayTop.c_str());
251 NTuplePtr nt1(
ntupleSvc(),
"MYROOTFILE/Trk");
252 if(nt1) {m_tuple=nt1;}
254 m_tuple =
ntupleSvc()->book (
"MYROOTFILE/Trk", CLID_ColumnWiseTuple,
"Generator-trk-Ntuple");
256 status = m_tuple->addItem (
"TotNumTrk", TotNumTrk, 0,100);
257 status = m_tuple->addIndexedItem (
"Trk_index", TotNumTrk, m_Trk_index);
258 status = m_tuple->addIndexedItem (
"m_px_trk", TotNumTrk, m_px_trk);
259 status = m_tuple->addIndexedItem (
"m_py_trk", TotNumTrk, m_py_trk);
260 status = m_tuple->addIndexedItem (
"m_pz_trk", TotNumTrk, m_pz_trk);
261 status = m_tuple->addIndexedItem (
"m_en_trk", TotNumTrk, m_en_trk);
262 status = m_tuple->addIndexedItem (
"FST", TotNumTrk, m_fst);
264 status = m_tuple->addItem (
"nchr", m_nchr);
265 status = m_tuple->addItem (
"nchr_e", m_nchr_e);
266 status = m_tuple->addItem (
"nchr_mu", m_nchr_mu);
267 status = m_tuple->addItem (
"nchr_pi", m_nchr_pi);
268 status = m_tuple->addItem (
"nchr_k", m_nchr_k);
269 status = m_tuple->addItem (
"nchr_p", m_nchr_p);
270 status = m_tuple->addItem (
"N_gamma", m_gamma);
271 status = m_tuple->addItem (
"N_gammaFSR", m_gammaFSR);
272 status = m_tuple->addItem (
"Flag1", m_flag1);
274 log << MSG::ERROR <<
" Cannot book N-tuple:"<< long(m_tuple) << endmsg;
275 return StatusCode::FAILURE;
279 NTuplePtr nt2(
ntupleSvc(),
"MYROOTFILE/mass");
280 if(nt2) {mass_tuple=nt2;}
282 mass_tuple =
ntupleSvc()->book (
"MYROOTFILE/mass", CLID_ColumnWiseTuple,
"Generator-mass-Ntuple");
284 status = mass_tuple->addItem (
"m12", m_m12);
285 status = mass_tuple->addItem (
"m13", m_m13);
286 status = mass_tuple->addItem (
"m23", m_m23);
287 status = mass_tuple->addItem (
"m1", m_m1);
288 status = mass_tuple->addItem (
"m2", m_m2);
289 status = mass_tuple->addItem (
"m3", m_m3);
290 status = mass_tuple->addItem (
"costheta1", m_cos1);
291 status = mass_tuple->addItem (
"costheta2", m_cos2);
292 status = mass_tuple->addItem (
"costheta3", m_cos3);
293 status = mass_tuple->addItem (
"ichannel", m_ich);
295 log << MSG::ERROR <<
" Cannot book N-tuple:"<< long(m_tuple) << endmsg;
296 return StatusCode::FAILURE;
300 NTuplePtr nt3(
ntupleSvc(),
"MYROOTFILE/massGen");
301 if(nt3) {massgen_tuple=nt3;}
303 massgen_tuple =
ntupleSvc()->book (
"MYROOTFILE/massGen", CLID_ColumnWiseTuple,
"Generator-mass-Ntuple");
305 status = massgen_tuple->addItem (
"m12", _m12);
306 status = massgen_tuple->addItem (
"m13", _m13);
307 status = massgen_tuple->addItem (
"m23", _m23);
308 status = massgen_tuple->addItem (
"m1", _m1);
309 status = massgen_tuple->addItem (
"m2", _m2);
310 status = massgen_tuple->addItem (
"m3", _m3);
311 status = massgen_tuple->addItem (
"costheta1", _cos1);
312 status = massgen_tuple->addItem (
"costheta2", _cos2);
313 status = massgen_tuple->addItem (
"costheta3", _cos3);
314 status = massgen_tuple->addItem (
"ichannel", _ich);
316 log << MSG::ERROR <<
" Cannot book N-tuple:"<< long(m_tuple) << endmsg;
317 return StatusCode::FAILURE;
323 for(
int i=0;i<500;i++){br[i]=0;}
324 if(!(m_SB3File==
"" && m_SB3HT==
"")) {
325 const char *filename, *histitle;
326 filename=(
char*)m_SB3File.c_str();
327 histitle=(
char*)m_SB3HT.c_str();
328 SuperBody3decay.
setFile(filename);
330 SuperBody3decay.
init();
333 return StatusCode::SUCCESS;
339 MsgStream log(messageService(), name());
342 string key =
"GEN_EVENT";
344 SmartDataPtr<McGenEventCol> McEvtColl(eventSvc(),
"/Event/Gen");
349 if ( McEvtColl == 0 )
351 HepMC::GenEvent* evt=
new GenEvent();
352 evt->set_event_number(m_numberEvent);
355 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
356 int runNo=eventHeader->runNumber();
357 int event=eventHeader->eventNumber();
359 if(
runNo != 0 &&
runNo != m_runNo){m_runNo=
runNo;newRunFlag =
true;}
else{newRunFlag=
false;}
360 if(m_RdMeasuredEcms&& newRunFlag){
365 std::cout<<
"Read Ecms= "<<dbEcms<<std::endl;
367 std::cout<<
"INFO: Read the MeasuredEcms"<<std::endl;
370 std::cout<<
"ERROR: Can not read the MeasuredEcms, try to turn off the ReadEcmsDB"<<std::endl;
371 return StatusCode::FAILURE;
377 callBesEvtGen( evt );
378 if(!(m_DecayTop==
"")) evt->print(outfile);
383 mcColl->push_back(mcEvent);
384 StatusCode sc = eventSvc()->registerObject(
"/Event/Gen",mcColl);
385 if(sc != SUCCESS)
return StatusCode::FAILURE;
389 McGenEventCol::iterator mcItr;
390 for( mcItr = McEvtColl->begin(); mcItr != McEvtColl->end(); mcItr++ )
392 HepMC::GenEvent* hEvt = (*mcItr)->getGenEvt();
397 if(!(m_DecayTop==
"")) hEvt->print(outfile);
400 if(!(m_DecayRec==
"")) std::cout<<std::endl;
403 if( m_NtupleFile ){ m_tuple->write();}
406 std::cout<<
"helangs ";
407 for(
int i=0;i<m_vangs.size();i++) std::cout<<m_vangs[i]<<
" ";
408 std::cout<<std::endl;
410 return StatusCode::SUCCESS;
418StatusCode EvtDecay::callEvtGen( HepMC::GenEvent* hepMCevt )
420 MsgStream log(messageService(), name());
429 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
431 for (
int i=0;i<13;i++)
fst[i]=0;
432 HepMC::GenEvent::particle_const_iterator itp;
434 for( itp=hepMCevt->particles_begin(); itp!=hepMCevt->particles_end(); ++itp )
456 HepMC::GenParticle* hepMCpart=*itp;
457 int stat = hepMCpart->status();
460 if ( stat != 1 )
continue;
462 loop_to_select_eventsB:
463 int id = hepMCpart->pdg_id();
465 hepMCpart->set_status(899);
469 double en =(hepMCpart->momentum()).e();
470 double pex=(hepMCpart->momentum()).px();
471 double pey=(hepMCpart->momentum()).py();
472 double pez=(hepMCpart->momentum()).pz();
475 parentMass=p_init.mass();
481 bool parentFlag=
false;
483 if(m_polarization.size()>0) {
485 }
else if(m_eBeamPolarization>0){
493 int id = hepMCpart->pdg_id();
496 if(
id == 11 ) {
fst[1]++;}
else if(
id == -11){
fst[2]++;}
497 else if(
id == 13){
fst[3]++;}
498 else if(
id == -13){
fst[4]++;}
499 else if(
id == 211){
fst[5]++;}
500 else if(
id ==-211){
fst[6]++;}
501 else if(
id == 321){
fst[7]++;}
502 else if(
id ==-321){
fst[8]++;}
503 else if(
id ==2212){
fst[9]++;}
504 else if(
id ==-2212){
fst[10]++;}
505 else if(
id == 2112){
fst[11]++;}
506 else if(
id ==-2112){
fst[12]++;}
507 if( fabs(
id) == 11) {
nchr_e++;}
508 if( fabs(
id) == 13) {
nchr_mu++;}
509 if( fabs(
id) == 211) {
nchr_pi++;}
510 if( fabs(
id) == 321) {
nchr_k++;}
511 if( fabs(
id) == 2212) {
nchr_p++;}
514 if( m_NtupleFile==
true ){
515 m_Trk_index[AllTrk_index]=id;
516 m_px_trk[AllTrk_index]=pex;
517 m_py_trk[AllTrk_index]=pey;
518 m_pz_trk[AllTrk_index]=pez;
519 m_en_trk[AllTrk_index]=en ;
522 Trk_index[AllTrk_index]=0;
532 if(m_FDPparticle!=
""){
541 if(!(m_SB3File==
"" || m_SB3HT==
"") && parentFlag && first ){
542 SuperBody3decay_make(fdp_ppid, fdp_init );
545 loop_to_select_eventsA:
547 if(m_truthFile!=
"" && m_truthPart!=
""){
550 for(
int id=0;
id<ndaug;
id++){
553 truth<<son.
get(0)<<
" "<<son.
get(1)<<
" "<<son.
get(2)<<
" "<<son.
get(3)<<std::endl;
558 if(_mDIY && parentFlag && m_ampscalflag ) _amps_max=CalAmpsMax(part);
559 if(_mDIY && parentFlag) {
561 double amps=CalAmpsMDIY( part );
562 ratio=amps/_amps_max;
564 if(_mDIY && parentFlag && ratio<=rdm){
goto loop_to_select_eventsA;}
569 if(m_FDPparticle==
""){FDP_part=part;}
570 if(!(m_SB3File==
"" || m_SB3HT==
"") && parentFlag ){ accept=SuperBody3decay_judge( FDP_part); }
571 if(!(m_SB3File==
"" || m_SB3HT==
"") && parentFlag && !accept){
574 goto loop_to_select_eventsB;
575 }
else if(!(m_SB3File==
"" || m_SB3HT==
"") && parentFlag && accept){
576 countChannel(FDP_part);
579 if((m_Psi2openCharm || m_Psi4040OpenCharm) && parentFlag ){
580 if(getModel(part) ==
"OPENCHARM"){
581 std::cout<<
"OPENCHARM model need to set Psi2openCharm and Psi3SopenCharm to be false!"<<std::endl;
585 bool theDecay = opencharm.choseDecay();
589 goto loop_to_select_eventsB;
598 unsigned int modeTag, multiplicityTag;
599 modeTag = theTag.getModeTag();
600 if( getModel(part) ==
"OPENCHARM"||getModel(part) ==
"LUNDCHARM" && m_tagLundModel){
601 multiplicityTag = decayType(part);
605 multiplicityTag = theTag.getMultTag() + decayType(part);
609 if(eventHeader == 0) std::cout <<
"event header unavailable: " << std::endl;
610 if (eventHeader != 0) {
611 eventHeader->setFlag1(modeTag);
612 eventHeader->setFlag2(multiplicityTag);
617 if(!(m_DecayRec==
"")) mydecayrec=part->
writeTreeRec(m_DecayRec);
619 if(m_statDecays && parentFlag ) countChannel(part);
622 if ( log.level() <= MSG::DEBUG ) part->
printTree() ;
623 log << MSG::DEBUG <<
"Converting particles to HepMC" << endreq;
625 makeHepMC(part, hepMCevt, hepMCpart);
627 hepMCpart->set_status(999);
633 for(
int i=0;i<nds;i++){
636 std::cout<<
"vvpp "<<vp1.
get(0)<<
" "<<vp1.
get(1)<<
" "<<vp1.
get(2)<<
" "<<vp1.
get(3)<<std::endl;
640 if(m_ReadTruth.size())ReadTruth(part,m_ReadTruth);
645 for( itp=hepMCevt->particles_begin(); itp!=hepMCevt->particles_end(); ++itp )
647 if (!(*itp)->end_vertex() && ( (*itp)->status()==899 || (*itp)->status()==999 ))
648 (*itp)->set_status(1);
652 if(m_Ncharge ==
true ) {std::cout<<
"Multiplicity: TotoalCharge_e_mu_pi_K_p_gamma_gammaFSR: "
661 if(m_Ncharge ==
true ){std::cout<<
"FinalStates: "
674 <<
fst[12]<<std::endl;}
685 TotNumTrk = AllTrk_index;
689 return StatusCode::SUCCESS;
695StatusCode EvtDecay::callBesEvtGen( HepMC::GenEvent* hepMCevt )
697 MsgStream log(messageService(), name());
707 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
708 for (
int i=0;i<13;i++)
fst[i]=0;
709 HepMC::GenEvent::particle_const_iterator itp;
730 loop_to_select_eventsB:
733 if(m_RdMeasuredEcms && m_beamEnergySpread==0) {
736 }
else if(m_RdMeasuredEcms && m_beamEnergySpread!=0){
737 double cmssig=sqrt(2.)*m_beamEnergySpread;
741 }
else if( (!m_RdMeasuredEcms) && m_beamEnergySpread!=0){
743 double cmssig=sqrt(2.)*m_beamEnergySpread;
747 }
else if((!m_RdMeasuredEcms) && m_beamEnergySpread==0 ){
749 }
else {std::cout<<
"EvtDecay::callBesEvtGen:: bad option"<<std::endl; abort();}
760 HepMC::GenParticle* hepMCpart=
new GenParticle(HepLorentzVector(0,0,0,ppmass),pid,3);
762 bool parentFlag =
false;
765 if(m_polarization.size()>0) {
767 }
else if(m_eBeamPolarization>0){
779 if(m_FDPparticle!=
""){
788 if(!(m_SB3File==
"" || m_SB3HT==
"") && first ){ SuperBody3decay_make( fdp_ppid, fdp_init);}
791 loop_to_select_events:
792 m_Gen->
generateDecay(part);
if(m_numberEvent<=1){ std::cout<<
"after m_Gen->decay "<<std::endl; part->
printTree();}
795 if(_mDIY && m_ampscalflag ) _amps_max=CalAmpsMax(part);
798 for(
int myloop=0;myloop<100;myloop++){
800 double amps=CalAmpsMDIY( part);
801 ratio=amps/_amps_max;
803 if( !isNumber(amps) || !isNumber(_amps_max) || ratio<=0 ) {
807 }
else if( rdm<=ratio) {
813 if(m_truthFile!=
"" && m_truthPart!=
""){
816 for(
int id=0;
id<ndaug;
id++){
819 truth<<son.
get(0)<<
" "<<son.
get(1)<<
" "<<son.
get(2)<<
" "<<son.
get(3)<<std::endl;
825 if(m_FDPparticle==
""){FDP_part=part;}
826 if(!(m_SB3File==
"" || m_SB3HT==
"")){
827 accept=SuperBody3decay_judge( FDP_part);
829 if(!(m_SB3File==
"" || m_SB3HT==
"") && !accept) {
832 goto loop_to_select_eventsB;
833 }
else if(!(m_SB3File==
"" || m_SB3HT==
"") && parentFlag && accept){
834 countChannel(FDP_part);
839 if(m_statDecays && parentFlag) countChannel(part);
846 unsigned int modeTag, multiplicityTag;
847 modeTag = theTag.getModeTag();
848 if( getModel(part) ==
"OPENCHARM"|| getModel(part) ==
"LUNDCHARM" && m_tagLundModel ){
849 multiplicityTag = decayType(part);
852 }
else if(_RvalueTag){
853 multiplicityTag = decayType(part);
855 multiplicityTag = theTag.getMultTag() + decayType(part);
857 if(eventHeader == 0) std::cout <<
"event header unavailable: " << std::endl;
858 if (eventHeader != 0) {
859 eventHeader->setFlag1(modeTag);
860 eventHeader->setFlag2(multiplicityTag);
864 if(m_NtupleFile)m_flag1 = modeTag;
868 if(!(m_DecayRec==
"")) {mydecayrec=part->
writeTreeRec(m_DecayRec);std::cout<<std::endl;};
871 if ( log.level() <= MSG::DEBUG ) part->
printTree() ;
872 log << MSG::DEBUG <<
"Converting particles to HepMC" << endreq;
874 makeHepMC(part, hepMCevt, hepMCpart);
876 if(part->
getNDaug()!=0) hepMCpart->set_status(999);
881 std::cout<<
"_FinalState "<<myd;
882 for(
int ii=0;ii<myd;ii++) {
885 std::cout<<std::endl;
889 for( itp=hepMCevt->particles_begin(); itp!=hepMCevt->particles_end(); ++itp )
891 if (!(*itp)->end_vertex() && ( (*itp)->status()==899 || (*itp)->status()==999 ))
892 (*itp)->set_status(1);
894 HepMC::GenParticle* hepMCpart=*itp;
895 int stat = hepMCpart->status();
896 int id = hepMCpart->pdg_id();
897 if(
abs(
id)==411 ||
abs(
id)==413 ) { (*itp)->set_status(999);stat=999;}
899 if ( stat != 1 )
continue;
902 if(
id == 11 ) {
fst[1]++;}
903 else if(
id == -11) {
fst[2]++;}
904 else if(
id == 13 ) {
fst[3]++;}
905 else if(
id ==-13) {
fst[4]++;}
906 else if(
id==211) {
fst[5]++;}
907 else if(
id==-211) {
fst[6]++;}
908 else if(
id== 321) {
fst[7]++;}
909 else if(
id ==-321) {
fst[8]++;}
910 else if(
id ==2212) {
fst[9]++;}
911 else if(
id==-2212) {
fst[10]++;}
912 else if(
id == 2112){
fst[11]++;}
913 else if(
id==-2112) {
fst[12]++;}
914 if( fabs(
id) == 11) {
nchr_e++;}
915 if( fabs(
id) == 13) {
nchr_mu++;}
916 if( fabs(
id) == 211) {
nchr_pi++;}
917 if( fabs(
id) == 321) {
nchr_k++;}
918 if( fabs(
id) == 2212) {
nchr_p++;}
921 double en =(hepMCpart->momentum()).e();
922 double pex=(hepMCpart->momentum()).px();
923 double pey=(hepMCpart->momentum()).py();
924 double pez=(hepMCpart->momentum()).pz();
926 if( m_NtupleFile==
true &&
id!=0){
927 m_Trk_index[AllTrk_index]=id;
928 m_px_trk[AllTrk_index]=pex;
929 m_py_trk[AllTrk_index]=pey;
930 m_pz_trk[AllTrk_index]=pez;
931 m_en_trk[AllTrk_index]=en ;
943 itp=hepMCevt->particles_begin();
944 (*itp)->set_status(2);
948 if(m_Ncharge ==
true ) {std::cout<<
"Multiplicity: TotoalCharge_e_mu_pi_K_p_gamma_gammaFSR: "
957 if(m_Ncharge ==
true ){std::cout<<
"FinalStates: "
970 <<
fst[12]<<std::endl;}
982 TotNumTrk = AllTrk_index;
986 if(m_ReadTruth.size())ReadTruth(part,m_ReadTruth);
992 return StatusCode::SUCCESS;
1007 std::cout<<
"Calculated helicity amplitude sqaured are:"<<std::endl;
1008 std::cout<<
"|H_{2}|^2=|H_{-2}|^2= "<<H2/nd<<
" +/- "<<sqrt(H2err/nd)<<endl;
1009 std::cout<<
"|H_{1}|^2=|H_{-1}|^2= "<<H1/nd<<
" +/- "<<sqrt(H1err/nd)<<endl;
1012 MsgStream log(messageService(), name());
1014 log << MSG::INFO <<
"EvtDecay finalized" << endreq;
1016 Forfile.open(
"fort.16",ios::in);
1018 strcpy(delcmd,
"rm -f ");
1019 strcat(delcmd,
"fort.16");
1023 Forfile2.open(
"fort.22",ios::in);
1024 strcpy(delcmd,
"rm -f ");
1025 strcat(delcmd,
"fort.22");
1035 if(!(m_SB3File==
"" || m_SB3HT==
"")){
1036 for(
int i=0;i<500;i++){totalEvt=totalEvt+br[i];}
1037 for(
int i=0;i<500;i++){
1038 double bi=1.0*br[i]/totalEvt;
1039 std::cout<<
"Branching fraction of channel "<<i<<
" is: "<<bi<<std::endl;
1046 for(
int i=0;i<=totalChannels;i++){totalEvt=totalEvt+br[i];}
1047 std::cout<<
"==================Statistical first chain decay ==============================="<<std::endl;
1048 std::cout<<
"i-th channel Events Generated Branching fraction generated "<<std::endl;
1049 for(
int i=0;i<=totalChannels;i++){
1050 std::cout<<
"| "<<i<<
" "<<br[i]<<
" "<<br[i]*1.0/totalEvt<<std::endl;
1053 std::cout<<
"--------------------------------------------------------------------------------"<<std::endl;
1054 std::cout<<
" sum: "<<totalEvt<<
" "<<
"1"<<std::endl;
1055 std::cout<<
"================== End of statistical first chain decay ========================"<<std::endl;
1058 return StatusCode::SUCCESS;
1062StatusCode EvtDecay::makeHepMC(
EvtParticle* part, HepMC::GenEvent* hEvt,
1063 HepMC::GenParticle* hPart)
1065 MsgStream log(messageService(), name());
1074 HepMC::GenVertex* end_vtx =
new HepMC::GenVertex(HepLorentzVector(x,
y,z,ct));
1075 hEvt->add_vertex( end_vtx );
1076 end_vtx->add_particle_in(hPart);
1080 for(
int it=0;it<ndaug;it++)
1092 HepMC::GenParticle* prod_part =
new HepMC::GenParticle(HepLorentzVector(px,py,pz,e),
id,status);
1093 end_vtx->add_particle_out(prod_part);
1094 makeHepMC(part->
getDaug(it),hEvt,prod_part);
1098 if( log.level()<MSG::INFO )
1103 return StatusCode::SUCCESS;
1107void EvtDecay::MeVToGeV (HepMC::GenEvent* evt)
1109 for ( HepMC::GenEvent::particle_iterator p = evt->particles_begin(); p != evt->particles_end(); ++p ) {
1113 HepMC::FourVector tmpfv((*p)->momentum().x()/1000.,
1114 (*p)->momentum().y()/1000.,
1115 (*p)->momentum().z()/1000.,
1116 (*p)->momentum().t()/1000.
1119 (*p)->set_momentum( tmpfv );
1123void EvtDecay::GeVToMeV (HepMC::GenEvent* evt)
1125 for ( HepMC::GenEvent::particle_iterator p = evt->particles_begin(); p != evt->particles_end(); ++p ) {
1128 HepMC::FourVector tmpfv((*p)->momentum().x()*1000.,
1129 (*p)->momentum().y()*1000.,
1130 (*p)->momentum().z()*1000.,
1131 (*p)->momentum().t()*1000.
1134 (*p)->set_momentum( tmpfv );
1142 for(
int i=0;i<100000;i++){
1144 double amps=CalAmpsMDIY(part);
1145 if(amps > amps_max) amps_max=amps;
1147 amps_max=amps_max*1.05;
1148 m_ampscalflag =
false;
1157 m_engine->showStatus();
1166 double rdm= RandFlat::shoot(m_engine);
1174 double xmass2,ymass2;
1179 FinalState_make( ppid, p_init);
1182 for(
int i=0;i<100000;i++){
1185 HepMC::GenParticle* hepMCpart=
new GenParticle(HepLorentzVector(0,0,0,parentMass),parentPDGcode,3);
1193 FinalState_sort(part);
1200 xmass2=(pd1+pd2).mass2();
1201 ymass2=(pd1+pd3).mass2();
1204 double ylow=SuperBody3decay.
getYlow();
1205 double yup=SuperBody3decay.
getYup();
1206 if(xmass2<xlow || xmass2>
xup || ymass2<ylow || ymass2>yup) { part->
deleteTree();
goto regen;}
1207 SuperBody3decay.
HFill(xmass2,ymass2);
1214 m_m12=(pd1+pd2).
mass();
1215 m_m23=(pd2+pd3).
mass();
1216 m_m13=(pd1+pd3).
mass();
1220 mass_tuple->write();
1222 double m1=pd1.
mass();
double m2=pd2.
mass();
double m3=pd3.
mass();
1223 double mj=(pd2+pd3).
mass();
1233bool EvtDecay::SuperBody3decay_judge(
EvtParticle* part){
1234 double xmass2,ymass2;
1239 FinalState_sort( part);
1246 xmass2=(pd1+pd2).mass2();
1247 ymass2=(pd1+pd3).mass2();
1248 accept=SuperBody3decay.
AR(xmass2,ymass2);
1251 if(accept && m_NtupleFile) {
1256 _m12=(pd1+pd2).
mass();
1257 _m23=(pd2+pd3).
mass();
1258 _m13=(pd1+pd3).
mass();
1262 massgen_tuple->write();
1273 identical_flag=
true;
1275 for(
int i=1;i<10000;i++){
1277 HepMC::GenParticle* hepMCpart=
new GenParticle(HepLorentzVector(0,0,0,parentMass),parentPDGcode,3);
1282 if(nson == 2) {
continue;}
else
1284 EvtId xid0,xid1,xid2;
1294 if(pdg0==pdg1 && pdg1==pdg2) {multi=3;}
1295 else if(pdg0==pdg1 ){multi=2;}
1296 else if(pdg0==pdg2 ){multi=2;pdg=pdg1; pdg1=pdg2; pdg2=pdg;}
1297 else if(pdg1==pdg2) {multi=2;pdg=pdg0; pdg0=pdg1; pdg1=pdg2; pdg2=pdg;}
1301 std::cout<<
"No direct three body decay channel found in decay card, I stop run"<<std::endl;
1312 EvtId xid0,xid1,xid2;
1342 assign_momentum(id0,
pd0);
1343 assign_momentum(id1,pd1);
1344 assign_momentum(id2,pd2);
1345 }
else if(multi==2){
1346 assign_momentum2(id0,
pd0);
1347 assign_momentum2(id1,pd1);
1348 assign_momentum2(id2,pd2);
1349 if(son0.
get(0)>son1.
get(0)){son=son0;son0=son1;son1=son;}
1350 }
else if(multi==3){
1351 double En0=
pd0.get(0);
1352 double En1=pd1.
get(0);
1353 double En2=pd2.
get(0);
1354 if(En0 < En1 && En1 < En2) {son0=
pd0;son1=pd1;son2=pd2;}
1355 if(En0 < En2 && En2 < En1) {son0=
pd0;son1=pd2;son2=pd1;}
1356 if(En1 < En0 && En0 < En2) {son0=pd1;son1=
pd0;son2=pd2;}
1357 if(En1 < En2 && En2 < En0) {son0=pd1;son1=pd2;son2=
pd0;}
1358 if(En2 < En0 && En0 < En1) {son0=pd2;son1=
pd0;son2=pd1;}
1359 if(En2 < En1 && En1 < En0) {son0=pd2;son1=pd1;son2=
pd0;}
1366 if(id0==pdg0){son0=
pd0;}
1367 else if(id0==pdg1){son1=
pd0;}
1368 else if(id0==pdg2){son2=
pd0;}
1369 else {std::cout<<
"PID= "<<id0<<
" not machted, I stop"<<std::endl; ::abort();}
1373 if(id0==pdg0 && identical_flag){son0=
pd0;identical_flag=
false;}
1374 else if(id0==pdg1){son1=
pd0;identical_flag=
true;}
1375 else if(id0==pdg2){son2=
pd0;}
1376 else {std::cout<<
"PID not machted, I stop"<<std::endl; ::abort();}
1387 for(
int i=0;i<dn;i++){
1391 if(son_pdg == FDP_pdg){
1411 if(ich>totalChannels) totalChannels = ich;
1415bool EvtDecay::isCharmonium(
EvtId xid){
1431 std::vector<EvtId> Vid; Vid.clear();
1432 Vid.push_back(psi4415);
1433 Vid.push_back(psi4160);
1434 Vid.push_back(psi4040);
1435 Vid.push_back(psi3770);
1436 Vid.push_back(psiprim);
1437 Vid.push_back(jpsi);
1438 Vid.push_back(etac);
1439 Vid.push_back(etac2s);
1441 Vid.push_back(chic0);
1442 Vid.push_back(chic1);
1443 Vid.push_back(chic2);
1444 Vid.push_back(chic0p);
1445 Vid.push_back(chic1p);
1446 Vid.push_back(chic2p);
1449 for(
int i=0;i<Vid.size();i++){
if(xid == Vid[i])
return flag;}
1454bool EvtDecay::isCharm(
EvtId xid){
1472 std::vector<EvtId> Vid; Vid.clear();
1474 Vid.push_back(d0bar);
1479 Vid.push_back(dstp);
1480 Vid.push_back(dstm);
1482 Vid.push_back(ds0bar );
1483 Vid.push_back(dsp );
1484 Vid.push_back(dsm );
1485 Vid.push_back(dsstp );
1486 Vid.push_back(dsstm );
1487 Vid.push_back(ds0stp );
1488 Vid.push_back(ds0stm );
1491 for(
int i=0;i<Vid.size();i++){
if(xid == Vid[i])
return flag;}
1497 for(
int i=0;i<ndg;i++){
1516 if(_RvalueTag){
return Nchannel;}
1519 std::string model = getModel(par,Nchannel);
1520 if( model ==
"OPENCHARM" || model ==
"LUNDCHARM" && m_tagLundModel){
1527 for(
int i=0;i<ndg;i++){
1532 if( isRadecay(par) ){
1533 for(
int i=0;i<ndg;i++){
1535 if( isCharmonium(xid) )
return 1;
1543 if( isCharm(xd1) && isCharm(xd2) ) {
return 2;}
else
1544 if( !isCharmonium(xd1) && !isCharmonium(xd2) && !isCharm(xd1) && !isCharm(xd2) ){
1549 for(
int i=0;i<ndg;i++){
1551 if( isCharmonium(xid) ) {
flag =
true;
break;}
1552 if( isCharm(xid) ) {
flag =
true;
break;}
1554 if( !
flag ){
return 3;}
else {
return 4;}
1561std::string EvtDecay::getModel(
EvtParticle *par,
int mode){
1573void EvtDecay::ReadTruth(
EvtParticle* part,std::vector<std::vector<string> > mylist){
1574 if(mylist.size()<2) {std::cout<<
" Empty list"<<std::endl;abort();}
1576 for(
int k=0;k<mylist[0].size();k++){
1580 for(
int i=1;i<mylist.size();i++){
1582 for(
int j=0;j<mylist[i].size();j++){
1589 vp1=mypart->
getP4();
1593 if( !isNumber(vp1.
get(0)) ) {part->
printTree(); abort();}
1595 printf(
"truth %.12lf %.12lf %.12lf %.12lf \n",vp1.
get(0),vp1.
get(1),vp1.
get(2),vp1.
get(3) );
1601int EvtDecay::isNumber(
double d){
return (d==d);}
1610 for(
int i=0;i<n;i++){
1614 double eta=sqrt(n*12.0)*(ri/12-0.5);
1615 double xsig=
sigma*eta+mu;
1618 if(xsig<mx0 || xsig>mx1)
goto rloop;
1622#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)
EvtDecay(const string &name, ISvcLocator *pSvcLocator)
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)
void setVectorSpinDensity()
void setPolarizedSpinDensity(double r00, double r11, double r22)
EvtSpinType::spintype getSpinType() const
const EvtVector4R & getP4() const
EvtParticle * getDaug(int i)
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