46#include "HepMC/GenEvent.h"
47#include "HepMC/GenVertex.h"
48#include "HepMC/GenParticle.h"
49#include "EventModel/EventHeader.h"
50#include "GaudiKernel/SmartDataPtr.h"
51#include "DataInfoSvc/IDataInfoSvc.h"
52#include "DataInfoSvc/DataInfoSvc.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"
60#include "BesKernel/IBesRndmGenSvc.h"
61#include "GeneratorObject/McGenEvent.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(
"ReadTruth",m_ReadTruth);
132 declareProperty(
"RvalueTag",_RvalueTag=
false);
138 MsgStream log(messageService(), name());
139 system(
"cat $BESEVTGENROOT/share/phokhara_9.1.fferr>phokhara_9.1.fferr");
140 system(
"cat $BESEVTGENROOT/share/phokhara_9.1.ffwarn>phokhara_9.1.ffwarn");
142 if(m_truthFile!=
""){truth.open(m_truthFile.c_str());}
143 log << MSG::INFO <<
"EvtDecay initialize" << endreq;
144 static const bool CREATEIFNOTTHERE(
true);
145 StatusCode RndmStatus = service(
"BesRndmGenSvc", p_BesRndmGenSvc, CREATEIFNOTTHERE);
146 if (!RndmStatus.isSuccess() || 0 == p_BesRndmGenSvc)
148 log << MSG::ERROR <<
" Could not initialize Random Number Service" << endreq;
153 for(
int i=0;i<m_mystring.size();i++){
EvtGlobalSet::SV.push_back(m_mystring[i]);}
157 std::vector<std::vector<int> >myivv;
158 std::vector<std::vector<double> >mydvv;
162 myivv.push_back(m_cluster0);
163 myivv.push_back(m_cluster1);
164 myivv.push_back(m_cluster2);
166 mydvv.push_back(m_wind0);
167 mydvv.push_back(m_wind1);
168 mydvv.push_back(m_wind2);
170 for(
int i=0;i<myivv.size();i++){
171 std::vector<int> theivv;
172 for(
int j=0;j<myivv[i].size();j++){
173 theivv.push_back(myivv[i][j]);
178 for(
int i=0;i<mydvv.size();i++){
179 std::vector<double> thedvv;
180 for(
int j=0;j<mydvv[i].size();j++){
181 thedvv.push_back(mydvv[i][j]);
187 if(m_eBeamPolarization>1) {std::cout<<
"The e-beam polaziation should be in 0 to 1"<<std::endl;abort();}
190 m_ampscalflag =
true;
192 CLHEP::HepRandomEngine* engine = p_BesRndmGenSvc->
GetEngine(
"EVTGEN");
193 const long s = engine->getSeed();
197 m_seeds.push_back(
s);
202 if ( m_DecayDec ==
"") {
203 m_DecayDec=getenv(
"BESEVTGENROOT");
204 m_DecayDec +=
"/share/DECAY.DEC";
207 if ( m_PdtTable ==
"") {
208 m_PdtTable =getenv(
"BESEVTGENROOT");
209 m_PdtTable +=
"/share/pdt.table";
213 std::cout<<
"===================== user decay card ========================"<<std::endl;
214 strcpy(catcmd,
"cat ");
215 strcat(catcmd, userDecFileName.c_str());
224 if (status.isSuccess()) {
225 log << MSG::INFO <<
"got the DataInfoSvc" << endreq;
229 log << MSG::ERROR <<
"could not get the DataInfoSvc" << endreq;
230 return StatusCode::FAILURE;
236 m_Gen =
new EvtGen( m_DecayDec.c_str(), m_PdtTable.c_str(), m_RandomEngine );
238 if(userDecFileName ==
"NONE") log << MSG::INFO <<
"EvtDecay User did not define his Decay table EvtGen will use standart" << endreq;
239 if(!(userDecFileName ==
"NONE")) m_Gen->
readUDecay(userDecFileName.c_str());
241 if(!(m_DecayTop==
" ")) {
242 outfile.open(m_DecayTop.c_str());
249 NTuplePtr nt1(
ntupleSvc(),
"MYROOTFILE/Trk");
250 if(nt1) {m_tuple=nt1;}
252 m_tuple =
ntupleSvc()->book (
"MYROOTFILE/Trk", CLID_ColumnWiseTuple,
"Generator-trk-Ntuple");
254 status = m_tuple->addItem (
"TotNumTrk", TotNumTrk, 0,100);
255 status = m_tuple->addIndexedItem (
"Trk_index", TotNumTrk, m_Trk_index);
256 status = m_tuple->addIndexedItem (
"m_px_trk", TotNumTrk, m_px_trk);
257 status = m_tuple->addIndexedItem (
"m_py_trk", TotNumTrk, m_py_trk);
258 status = m_tuple->addIndexedItem (
"m_pz_trk", TotNumTrk, m_pz_trk);
259 status = m_tuple->addIndexedItem (
"m_en_trk", TotNumTrk, m_en_trk);
260 status = m_tuple->addIndexedItem (
"FST", TotNumTrk, m_fst);
262 status = m_tuple->addItem (
"nchr", m_nchr);
263 status = m_tuple->addItem (
"nchr_e", m_nchr_e);
264 status = m_tuple->addItem (
"nchr_mu", m_nchr_mu);
265 status = m_tuple->addItem (
"nchr_pi", m_nchr_pi);
266 status = m_tuple->addItem (
"nchr_k", m_nchr_k);
267 status = m_tuple->addItem (
"nchr_p", m_nchr_p);
268 status = m_tuple->addItem (
"N_gamma", m_gamma);
269 status = m_tuple->addItem (
"N_gammaFSR", m_gammaFSR);
270 status = m_tuple->addItem (
"Flag1", m_flag1);
272 log << MSG::ERROR <<
" Cannot book N-tuple:"<< long(m_tuple) << endmsg;
273 return StatusCode::FAILURE;
277 NTuplePtr nt2(
ntupleSvc(),
"MYROOTFILE/mass");
278 if(nt2) {mass_tuple=nt2;}
280 mass_tuple =
ntupleSvc()->book (
"MYROOTFILE/mass", CLID_ColumnWiseTuple,
"Generator-mass-Ntuple");
282 status = mass_tuple->addItem (
"m12", m_m12);
283 status = mass_tuple->addItem (
"m13", m_m13);
284 status = mass_tuple->addItem (
"m23", m_m23);
285 status = mass_tuple->addItem (
"m1", m_m1);
286 status = mass_tuple->addItem (
"m2", m_m2);
287 status = mass_tuple->addItem (
"m3", m_m3);
288 status = mass_tuple->addItem (
"costheta1", m_cos1);
289 status = mass_tuple->addItem (
"costheta2", m_cos2);
290 status = mass_tuple->addItem (
"costheta3", m_cos3);
291 status = mass_tuple->addItem (
"ichannel", m_ich);
293 log << MSG::ERROR <<
" Cannot book N-tuple:"<< long(m_tuple) << endmsg;
294 return StatusCode::FAILURE;
298 NTuplePtr nt3(
ntupleSvc(),
"MYROOTFILE/massGen");
299 if(nt3) {massgen_tuple=nt3;}
301 massgen_tuple =
ntupleSvc()->book (
"MYROOTFILE/massGen", CLID_ColumnWiseTuple,
"Generator-mass-Ntuple");
303 status = massgen_tuple->addItem (
"m12", _m12);
304 status = massgen_tuple->addItem (
"m13", _m13);
305 status = massgen_tuple->addItem (
"m23", _m23);
306 status = massgen_tuple->addItem (
"m1", _m1);
307 status = massgen_tuple->addItem (
"m2", _m2);
308 status = massgen_tuple->addItem (
"m3", _m3);
309 status = massgen_tuple->addItem (
"costheta1", _cos1);
310 status = massgen_tuple->addItem (
"costheta2", _cos2);
311 status = massgen_tuple->addItem (
"costheta3", _cos3);
312 status = massgen_tuple->addItem (
"ichannel", _ich);
314 log << MSG::ERROR <<
" Cannot book N-tuple:"<< long(m_tuple) << endmsg;
315 return StatusCode::FAILURE;
321 for(
int i=0;i<500;i++){br[i]=0;}
322 if(!(m_SB3File==
"" && m_SB3HT==
"")) {
323 const char *filename, *histitle;
324 filename=(
char*)m_SB3File.c_str();
325 histitle=(
char*)m_SB3HT.c_str();
326 SuperBody3decay.
setFile(filename);
328 SuperBody3decay.
init();
331 return StatusCode::SUCCESS;
337 MsgStream log(messageService(), name());
340 string key =
"GEN_EVENT";
342 SmartDataPtr<McGenEventCol> McEvtColl(eventSvc(),
"/Event/Gen");
347 if ( McEvtColl == 0 )
349 HepMC::GenEvent* evt=
new GenEvent();
350 evt->set_event_number(m_numberEvent);
353 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
354 int runNo=eventHeader->runNumber();
355 int event=eventHeader->eventNumber();
357 if(
runNo != 0 &&
runNo != m_runNo){m_runNo=
runNo;newRunFlag =
true;}
else{newRunFlag=
false;}
358 if(m_RdMeasuredEcms&& newRunFlag){
363 std::cout<<
"Read Ecms= "<<dbEcms<<std::endl;
365 std::cout<<
"INFO: Read the MeasuredEcms"<<std::endl;
368 std::cout<<
"ERROR: Can not read the MeasuredEcms, try to turn off the ReadEcmsDB"<<std::endl;
369 return StatusCode::FAILURE;
375 callBesEvtGen( evt );
376 if(!(m_DecayTop==
"")) evt->print(outfile);
381 mcColl->push_back(mcEvent);
382 StatusCode sc = eventSvc()->registerObject(
"/Event/Gen",mcColl);
383 if(sc != SUCCESS)
return StatusCode::FAILURE;
387 McGenEventCol::iterator mcItr;
388 for( mcItr = McEvtColl->begin(); mcItr != McEvtColl->end(); mcItr++ )
390 HepMC::GenEvent* hEvt = (*mcItr)->getGenEvt();
395 if(!(m_DecayTop==
"")) hEvt->print(outfile);
398 if(!(m_DecayRec==
"")) std::cout<<std::endl;
401 if( m_NtupleFile ){ m_tuple->write();}
402 return StatusCode::SUCCESS;
410StatusCode EvtDecay::callEvtGen( HepMC::GenEvent* hepMCevt )
412 MsgStream log(messageService(), name());
421 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
423 for (
int i=0;i<13;i++)
fst[i]=0;
424 HepMC::GenEvent::particle_const_iterator itp;
426 for( itp=hepMCevt->particles_begin(); itp!=hepMCevt->particles_end(); ++itp )
448 HepMC::GenParticle* hepMCpart=*itp;
449 int stat = hepMCpart->status();
452 if ( stat != 1 )
continue;
454 loop_to_select_eventsB:
455 int id = hepMCpart->pdg_id();
457 hepMCpart->set_status(899);
461 double en =(hepMCpart->momentum()).e();
462 double pex=(hepMCpart->momentum()).px();
463 double pey=(hepMCpart->momentum()).py();
464 double pez=(hepMCpart->momentum()).pz();
467 parentMass=p_init.mass();
473 bool parentFlag=
false;
475 if(m_polarization.size()>0) {
477 }
else if(m_eBeamPolarization>0){
485 int id = hepMCpart->pdg_id();
488 if(
id == 11 ) {
fst[1]++;}
else if(
id == -11){
fst[2]++;}
489 else if(
id == 13){
fst[3]++;}
490 else if(
id == -13){
fst[4]++;}
491 else if(
id == 211){
fst[5]++;}
492 else if(
id ==-211){
fst[6]++;}
493 else if(
id == 321){
fst[7]++;}
494 else if(
id ==-321){
fst[8]++;}
495 else if(
id ==2212){
fst[9]++;}
496 else if(
id ==-2212){
fst[10]++;}
497 else if(
id == 2112){
fst[11]++;}
498 else if(
id ==-2112){
fst[12]++;}
499 if( fabs(
id) == 11) {
nchr_e++;}
500 if( fabs(
id) == 13) {
nchr_mu++;}
501 if( fabs(
id) == 211) {
nchr_pi++;}
502 if( fabs(
id) == 321) {
nchr_k++;}
503 if( fabs(
id) == 2212) {
nchr_p++;}
506 if( m_NtupleFile==
true ){
507 m_Trk_index[AllTrk_index]=id;
508 m_px_trk[AllTrk_index]=pex;
509 m_py_trk[AllTrk_index]=pey;
510 m_pz_trk[AllTrk_index]=pez;
511 m_en_trk[AllTrk_index]=en ;
514 Trk_index[AllTrk_index]=0;
524 if(m_FDPparticle!=
""){
533 if(!(m_SB3File==
"" || m_SB3HT==
"") && parentFlag && first ){
534 SuperBody3decay_make(fdp_ppid, fdp_init );
537 loop_to_select_eventsA:
539 if(m_truthFile!=
"" && m_truthPart!=
""){
542 for(
int id=0;
id<ndaug;
id++){
545 truth<<son.
get(0)<<
" "<<son.
get(1)<<
" "<<son.
get(2)<<
" "<<son.
get(3)<<std::endl;
550 if(_mDIY && parentFlag && m_ampscalflag ) _amps_max=CalAmpsMax(part);
551 if(_mDIY && parentFlag) {
553 double amps=CalAmpsMDIY( part );
554 ratio=amps/_amps_max;
556 if(_mDIY && parentFlag && ratio<=rdm){
goto loop_to_select_eventsA;}
560 if(m_FDPparticle==
""){FDP_part=part;}
561 if(!(m_SB3File==
"" || m_SB3HT==
"") && parentFlag ){ accept=SuperBody3decay_judge( FDP_part); }
562 if(!(m_SB3File==
"" || m_SB3HT==
"") && parentFlag && !accept){
565 goto loop_to_select_eventsB;
566 }
else if(!(m_SB3File==
"" || m_SB3HT==
"") && parentFlag && accept){
567 countChannel(FDP_part);
570 if((m_Psi2openCharm || m_Psi4040OpenCharm) && parentFlag ){
571 if(getModel(part) ==
"OPENCHARM"){
572 std::cout<<
"OPENCHARM model need to set Psi2openCharm and Psi3SopenCharm to be false!"<<std::endl;
576 bool theDecay = opencharm.choseDecay();
580 goto loop_to_select_eventsB;
589 unsigned int modeTag, multiplicityTag;
590 modeTag = theTag.getModeTag();
591 if( getModel(part) ==
"OPENCHARM"||getModel(part) ==
"LUNDCHARM" && m_tagLundModel){
592 multiplicityTag = decayType(part);
596 multiplicityTag = theTag.getMultTag() + decayType(part);
600 if(eventHeader == 0) std::cout <<
"event header unavailable: " << std::endl;
601 if (eventHeader != 0) {
602 eventHeader->setFlag1(modeTag);
603 eventHeader->setFlag2(multiplicityTag);
608 if(!(m_DecayRec==
"")) mydecayrec=part->
writeTreeRec(m_DecayRec);
610 if(m_statDecays && parentFlag ) countChannel(part);
613 if ( log.level() <= MSG::DEBUG ) part->
printTree() ;
614 log << MSG::DEBUG <<
"Converting particles to HepMC" << endreq;
616 makeHepMC(part, hepMCevt, hepMCpart);
618 hepMCpart->set_status(999);
624 for(
int i=0;i<nds;i++){
627 std::cout<<
"vvpp "<<vp1.
get(0)<<
" "<<vp1.
get(1)<<
" "<<vp1.
get(2)<<
" "<<vp1.
get(3)<<std::endl;
631 if(m_ReadTruth.size())ReadTruth(part,m_ReadTruth);
636 for( itp=hepMCevt->particles_begin(); itp!=hepMCevt->particles_end(); ++itp )
638 if (!(*itp)->end_vertex() && ( (*itp)->status()==899 || (*itp)->status()==999 ))
639 (*itp)->set_status(1);
643 if(m_Ncharge ==
true ) {std::cout<<
"Multiplicity: TotoalCharge_e_mu_pi_K_p_gamma_gammaFSR: "
652 if(m_Ncharge ==
true ){std::cout<<
"FinalStates: "
665 <<
fst[12]<<std::endl;}
676 TotNumTrk = AllTrk_index;
680 return StatusCode::SUCCESS;
686StatusCode EvtDecay::callBesEvtGen( HepMC::GenEvent* hepMCevt )
688 MsgStream log(messageService(), name());
698 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
699 for (
int i=0;i<13;i++)
fst[i]=0;
700 HepMC::GenEvent::particle_const_iterator itp;
721 loop_to_select_eventsB:
724 if(m_RdMeasuredEcms && m_beamEnergySpread==0) {
727 }
else if(m_RdMeasuredEcms && m_beamEnergySpread!=0){
728 double cmssig=sqrt(2.)*m_beamEnergySpread;
732 }
else if( (!m_RdMeasuredEcms) && m_beamEnergySpread!=0){
734 double cmssig=sqrt(2.)*m_beamEnergySpread;
738 }
else if((!m_RdMeasuredEcms) && m_beamEnergySpread==0 ){
740 }
else {std::cout<<
"EvtDecay::callBesEvtGen:: bad option"<<std::endl; abort();}
751 HepMC::GenParticle* hepMCpart=
new GenParticle(HepLorentzVector(0,0,0,ppmass),pid,3);
753 bool parentFlag =
false;
756 if(m_polarization.size()>0) {
758 }
else if(m_eBeamPolarization>0){
770 if(m_FDPparticle!=
""){
779 if(!(m_SB3File==
"" || m_SB3HT==
"") && first ){ SuperBody3decay_make( fdp_ppid, fdp_init);}
782 loop_to_select_events:
783 m_Gen->
generateDecay(part);
if(m_numberEvent<=1){ std::cout<<
"after m_Gen->decay "<<std::endl; part->
printTree();}
786 if(_mDIY && m_ampscalflag ) _amps_max=CalAmpsMax(part);
789 for(
int myloop=0;myloop<100;myloop++){
791 double amps=CalAmpsMDIY( part);
792 ratio=amps/_amps_max;
794 if( !isNumber(amps) || !isNumber(_amps_max) || ratio<=0 ) {
798 }
else if( rdm<=ratio) {
804 if(m_truthFile!=
"" && m_truthPart!=
""){
807 for(
int id=0;
id<ndaug;
id++){
810 truth<<son.
get(0)<<
" "<<son.
get(1)<<
" "<<son.
get(2)<<
" "<<son.
get(3)<<std::endl;
816 if(m_FDPparticle==
""){FDP_part=part;}
817 if(!(m_SB3File==
"" || m_SB3HT==
"")){
818 accept=SuperBody3decay_judge( FDP_part);
820 if(!(m_SB3File==
"" || m_SB3HT==
"") && !accept) {
823 goto loop_to_select_eventsB;
824 }
else if(!(m_SB3File==
"" || m_SB3HT==
"") && parentFlag && accept){
825 countChannel(FDP_part);
830 if(m_statDecays && parentFlag) countChannel(part);
837 unsigned int modeTag, multiplicityTag;
838 modeTag = theTag.getModeTag();
839 if( getModel(part) ==
"OPENCHARM"|| getModel(part) ==
"LUNDCHARM" && m_tagLundModel ){
840 multiplicityTag = decayType(part);
843 }
else if(_RvalueTag){
844 multiplicityTag = decayType(part);
846 multiplicityTag = theTag.getMultTag() + decayType(part);
848 if(eventHeader == 0) std::cout <<
"event header unavailable: " << std::endl;
849 if (eventHeader != 0) {
850 eventHeader->setFlag1(modeTag);
851 eventHeader->setFlag2(multiplicityTag);
855 if(m_NtupleFile)m_flag1 = modeTag;
859 if(!(m_DecayRec==
"")) {mydecayrec=part->
writeTreeRec(m_DecayRec);std::cout<<std::endl;};
862 if ( log.level() <= MSG::DEBUG ) part->
printTree() ;
863 log << MSG::DEBUG <<
"Converting particles to HepMC" << endreq;
865 makeHepMC(part, hepMCevt, hepMCpart);
867 if(part->
getNDaug()!=0) hepMCpart->set_status(999);
872 for( itp=hepMCevt->particles_begin(); itp!=hepMCevt->particles_end(); ++itp )
874 if (!(*itp)->end_vertex() && ( (*itp)->status()==899 || (*itp)->status()==999 ))
875 (*itp)->set_status(1);
877 HepMC::GenParticle* hepMCpart=*itp;
878 int stat = hepMCpart->status();
879 int id = hepMCpart->pdg_id();
880 if(
abs(
id)==411 ||
abs(
id)==413 ) { (*itp)->set_status(999);stat=999;}
882 if ( stat != 1 )
continue;
885 if(
id == 11 ) {
fst[1]++;}
886 else if(
id == -11) {
fst[2]++;}
887 else if(
id == 13 ) {
fst[3]++;}
888 else if(
id ==-13) {
fst[4]++;}
889 else if(
id==211) {
fst[5]++;}
890 else if(
id==-211) {
fst[6]++;}
891 else if(
id== 321) {
fst[7]++;}
892 else if(
id ==-321) {
fst[8]++;}
893 else if(
id ==2212) {
fst[9]++;}
894 else if(
id==-2212) {
fst[10]++;}
895 else if(
id == 2112){
fst[11]++;}
896 else if(
id==-2112) {
fst[12]++;}
897 if( fabs(
id) == 11) {
nchr_e++;}
898 if( fabs(
id) == 13) {
nchr_mu++;}
899 if( fabs(
id) == 211) {
nchr_pi++;}
900 if( fabs(
id) == 321) {
nchr_k++;}
901 if( fabs(
id) == 2212) {
nchr_p++;}
904 double en =(hepMCpart->momentum()).e();
905 double pex=(hepMCpart->momentum()).px();
906 double pey=(hepMCpart->momentum()).py();
907 double pez=(hepMCpart->momentum()).pz();
909 if( m_NtupleFile==
true &&
id!=0){
910 m_Trk_index[AllTrk_index]=id;
911 m_px_trk[AllTrk_index]=pex;
912 m_py_trk[AllTrk_index]=pey;
913 m_pz_trk[AllTrk_index]=pez;
914 m_en_trk[AllTrk_index]=en ;
926 itp=hepMCevt->particles_begin();
927 (*itp)->set_status(2);
931 if(m_Ncharge ==
true ) {std::cout<<
"Multiplicity: TotoalCharge_e_mu_pi_K_p_gamma_gammaFSR: "
940 if(m_Ncharge ==
true ){std::cout<<
"FinalStates: "
953 <<
fst[12]<<std::endl;}
965 TotNumTrk = AllTrk_index;
969 if(m_ReadTruth.size())ReadTruth(part,m_ReadTruth);
975 return StatusCode::SUCCESS;
990 std::cout<<
"Calculated helicity amplitude sqaured are:"<<std::endl;
991 std::cout<<
"|H_{2}|^2=|H_{-2}|^2= "<<H2/nd<<
" +/- "<<sqrt(H2err/nd)<<endl;
992 std::cout<<
"|H_{1}|^2=|H_{-1}|^2= "<<H1/nd<<
" +/- "<<sqrt(H1err/nd)<<endl;
995 MsgStream log(messageService(), name());
997 log << MSG::INFO <<
"EvtDecay finalized" << endreq;
999 Forfile.open(
"fort.16",ios::in);
1001 strcpy(delcmd,
"rm -f ");
1002 strcat(delcmd,
"fort.16");
1006 Forfile2.open(
"fort.22",ios::in);
1007 strcpy(delcmd,
"rm -f ");
1008 strcat(delcmd,
"fort.22");
1018 if(!(m_SB3File==
"" || m_SB3HT==
"")){
1019 for(
int i=0;i<500;i++){totalEvt=totalEvt+br[i];}
1020 for(
int i=0;i<500;i++){
1021 double bi=1.0*br[i]/totalEvt;
1022 std::cout<<
"Branching fraction of channel "<<i<<
" is: "<<bi<<std::endl;
1029 for(
int i=0;i<=totalChannels;i++){totalEvt=totalEvt+br[i];}
1030 std::cout<<
"==================Statistical first chain decay ==============================="<<std::endl;
1031 std::cout<<
"i-th channel Events Generated Branching fraction generated "<<std::endl;
1032 for(
int i=0;i<=totalChannels;i++){
1033 std::cout<<
"| "<<i<<
" "<<br[i]<<
" "<<br[i]*1.0/totalEvt<<std::endl;
1036 std::cout<<
"--------------------------------------------------------------------------------"<<std::endl;
1037 std::cout<<
" sum: "<<totalEvt<<
" "<<
"1"<<std::endl;
1038 std::cout<<
"================== End of statistical first chain decay ========================"<<std::endl;
1041 return StatusCode::SUCCESS;
1045StatusCode EvtDecay::makeHepMC(
EvtParticle* part, HepMC::GenEvent* hEvt,
1046 HepMC::GenParticle* hPart)
1048 MsgStream log(messageService(), name());
1057 HepMC::GenVertex* end_vtx =
new HepMC::GenVertex(HepLorentzVector(x,y,z,ct));
1058 hEvt->add_vertex( end_vtx );
1059 end_vtx->add_particle_in(hPart);
1063 for(
int it=0;it<ndaug;it++)
1075 HepMC::GenParticle* prod_part =
new HepMC::GenParticle(HepLorentzVector(px,py,pz,e),
id,status);
1076 end_vtx->add_particle_out(prod_part);
1077 makeHepMC(part->
getDaug(it),hEvt,prod_part);
1081 if( log.level()<MSG::INFO )
1086 return StatusCode::SUCCESS;
1090void EvtDecay::MeVToGeV (HepMC::GenEvent* evt)
1092 for ( HepMC::GenEvent::particle_iterator p = evt->particles_begin(); p != evt->particles_end(); ++p ) {
1096 HepMC::FourVector tmpfv((*p)->momentum().x()/1000.,
1097 (*p)->momentum().y()/1000.,
1098 (*p)->momentum().z()/1000.,
1099 (*p)->momentum().t()/1000.
1102 (*p)->set_momentum( tmpfv );
1106void EvtDecay::GeVToMeV (HepMC::GenEvent* evt)
1108 for ( HepMC::GenEvent::particle_iterator p = evt->particles_begin(); p != evt->particles_end(); ++p ) {
1111 HepMC::FourVector tmpfv((*p)->momentum().x()*1000.,
1112 (*p)->momentum().y()*1000.,
1113 (*p)->momentum().z()*1000.,
1114 (*p)->momentum().t()*1000.
1117 (*p)->set_momentum( tmpfv );
1125 for(
int i=0;i<100000;i++){
1127 double amps=CalAmpsMDIY(part);
1128 if(amps > amps_max) amps_max=amps;
1130 amps_max=amps_max*1.05;
1131 m_ampscalflag =
false;
1140 m_engine->showStatus();
1148 return RandFlat::shoot(m_engine);
1153 double xmass2,ymass2;
1158 FinalState_make( ppid, p_init);
1161 for(
int i=0;i<100000;i++){
1164 HepMC::GenParticle* hepMCpart=
new GenParticle(HepLorentzVector(0,0,0,parentMass),parentPDGcode,3);
1172 FinalState_sort(part);
1179 xmass2=(pd1+pd2).mass2();
1180 ymass2=(pd1+pd3).mass2();
1183 double ylow=SuperBody3decay.
getYlow();
1184 double yup=SuperBody3decay.
getYup();
1185 if(xmass2<xlow || xmass2>
xup || ymass2<ylow || ymass2>yup) { part->
deleteTree();
goto regen;}
1186 SuperBody3decay.
HFill(xmass2,ymass2);
1193 m_m12=(pd1+pd2).
mass();
1194 m_m23=(pd2+pd3).
mass();
1195 m_m13=(pd1+pd3).
mass();
1199 mass_tuple->write();
1201 double m1=pd1.
mass();
double m2=pd2.
mass();
double m3=pd3.
mass();
1202 double mj=(pd2+pd3).
mass();
1212bool EvtDecay::SuperBody3decay_judge(
EvtParticle* part){
1213 double xmass2,ymass2;
1218 FinalState_sort( part);
1225 xmass2=(pd1+pd2).mass2();
1226 ymass2=(pd1+pd3).mass2();
1227 accept=SuperBody3decay.
AR(xmass2,ymass2);
1230 if(accept && m_NtupleFile) {
1235 _m12=(pd1+pd2).
mass();
1236 _m23=(pd2+pd3).
mass();
1237 _m13=(pd1+pd3).
mass();
1241 massgen_tuple->write();
1252 identical_flag=
true;
1254 for(
int i=1;i<10000;i++){
1256 HepMC::GenParticle* hepMCpart=
new GenParticle(HepLorentzVector(0,0,0,parentMass),parentPDGcode,3);
1261 if(nson == 2) {
continue;}
else
1263 EvtId xid0,xid1,xid2;
1273 if(pdg0==pdg1 && pdg1==pdg2) {multi=3;}
1274 else if(pdg0==pdg1 ){multi=2;}
1275 else if(pdg0==pdg2 ){multi=2;pdg=pdg1; pdg1=pdg2; pdg2=pdg;}
1276 else if(pdg1==pdg2) {multi=2;pdg=pdg0; pdg0=pdg1; pdg1=pdg2; pdg2=pdg;}
1280 std::cout<<
"No direct three body decay channel found in decay card, I stop run"<<std::endl;
1291 EvtId xid0,xid1,xid2;
1321 assign_momentum(id0,
pd0);
1322 assign_momentum(id1,pd1);
1323 assign_momentum(id2,pd2);
1324 }
else if(multi==2){
1325 assign_momentum2(id0,
pd0);
1326 assign_momentum2(id1,pd1);
1327 assign_momentum2(id2,pd2);
1328 if(son0.
get(0)>son1.
get(0)){son=son0;son0=son1;son1=son;}
1329 }
else if(multi==3){
1330 double En0=
pd0.get(0);
1331 double En1=pd1.
get(0);
1332 double En2=pd2.
get(0);
1333 if(En0 < En1 && En1 < En2) {son0=
pd0;son1=pd1;son2=pd2;}
1334 if(En0 < En2 && En2 < En1) {son0=
pd0;son1=pd2;son2=pd1;}
1335 if(En1 < En0 && En0 < En2) {son0=pd1;son1=
pd0;son2=pd2;}
1336 if(En1 < En2 && En2 < En0) {son0=pd1;son1=pd2;son2=
pd0;}
1337 if(En2 < En0 && En0 < En1) {son0=pd2;son1=
pd0;son2=pd1;}
1338 if(En2 < En1 && En1 < En0) {son0=pd2;son1=pd1;son2=
pd0;}
1345 if(id0==pdg0){son0=
pd0;}
1346 else if(id0==pdg1){son1=
pd0;}
1347 else if(id0==pdg2){son2=
pd0;}
1348 else {std::cout<<
"PID= "<<id0<<
" not machted, I stop"<<std::endl; ::abort();}
1352 if(id0==pdg0 && identical_flag){son0=
pd0;identical_flag=
false;}
1353 else if(id0==pdg1){son1=
pd0;identical_flag=
true;}
1354 else if(id0==pdg2){son2=
pd0;}
1355 else {std::cout<<
"PID not machted, I stop"<<std::endl; ::abort();}
1366 for(
int i=0;i<dn;i++){
1370 if(son_pdg == FDP_pdg){
1390 if(ich>totalChannels) totalChannels = ich;
1394bool EvtDecay::isCharmonium(
EvtId xid){
1410 std::vector<EvtId> Vid; Vid.clear();
1411 Vid.push_back(psi4415);
1412 Vid.push_back(psi4160);
1413 Vid.push_back(psi4040);
1414 Vid.push_back(psi3770);
1415 Vid.push_back(psiprim);
1416 Vid.push_back(jpsi);
1417 Vid.push_back(etac);
1418 Vid.push_back(etac2s);
1420 Vid.push_back(chic0);
1421 Vid.push_back(chic1);
1422 Vid.push_back(chic2);
1423 Vid.push_back(chic0p);
1424 Vid.push_back(chic1p);
1425 Vid.push_back(chic2p);
1428 for(
int i=0;i<Vid.size();i++){
if(xid == Vid[i])
return flag;}
1433bool EvtDecay::isCharm(
EvtId xid){
1451 std::vector<EvtId> Vid; Vid.clear();
1453 Vid.push_back(d0bar);
1458 Vid.push_back(dstp);
1459 Vid.push_back(dstm);
1461 Vid.push_back(ds0bar );
1462 Vid.push_back(dsp );
1463 Vid.push_back(dsm );
1464 Vid.push_back(dsstp );
1465 Vid.push_back(dsstm );
1466 Vid.push_back(ds0stp );
1467 Vid.push_back(ds0stm );
1470 for(
int i=0;i<Vid.size();i++){
if(xid == Vid[i])
return flag;}
1476 for(
int i=0;i<ndg;i++){
1495 if(_RvalueTag){
return Nchannel;}
1498 std::string model = getModel(par,Nchannel);
1499 if( model ==
"OPENCHARM" || model ==
"LUNDCHARM" && m_tagLundModel){
1506 for(
int i=0;i<ndg;i++){
1511 if( isRadecay(par) ){
1512 for(
int i=0;i<ndg;i++){
1514 if( isCharmonium(xid) )
return 1;
1522 if( isCharm(xd1) && isCharm(xd2) ) {
return 2;}
else
1523 if( !isCharmonium(xd1) && !isCharmonium(xd2) && !isCharm(xd1) && !isCharm(xd2) ){
1528 for(
int i=0;i<ndg;i++){
1530 if( isCharmonium(xid) ) {
flag =
true;
break;}
1531 if( isCharm(xid) ) {
flag =
true;
break;}
1533 if( !
flag ){
return 3;}
else {
return 4;}
1540std::string EvtDecay::getModel(
EvtParticle *par,
int mode){
1552void EvtDecay::ReadTruth(
EvtParticle* part,std::vector<std::vector<string> > mylist){
1553 if(mylist.size()<2) {std::cout<<
" Empty list"<<std::endl;abort();}
1555 for(
int k=0;k<mylist[0].size();k++){
1558 for(
int i=1;i<mylist.size();i++){
1560 for(
int j=0;j<mylist[i].size();j++){
1567 if( !isNumber(vp1.
get(0)) ) {part->
printTree(); abort();}
1568 std::cout<<
"truth "<<vp1.
get(0)<<
" "<<vp1.
get(1)<<
" "<<vp1.
get(2)<<
" "<<vp1.
get(3)<<std::endl;
1574int EvtDecay::isNumber(
double d){
return (d==d);}
1583 for(
int i=0;i<
n;i++){
1587 double eta=sqrt(
n*12.0)*(ri/12-0.5);
1588 double xsig= sigma*eta+mu;
1591 if(xsig<mx0 || xsig>mx1)
goto rloop;
1595#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