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"
68static string mydecayrec;
69static double _amps_max;
79int EvtDecay::m_runNo=0;
90 declareProperty(
"DecayDecDir", m_DecayDec =
"");
91 declareProperty(
"PdtTableDir", m_PdtTable =
"");
92 declareProperty(
"userDecayTableName", userDecFileName =
"NONE");
93 declareProperty(
"DecayTopology", m_DecayTop =
"");
94 declareProperty(
"DecayRecord", m_DecayRec =
"");
95 declareProperty(
"ParentParticle", m_ParentPart =
"NONE");
96 declareProperty(
"Multiplicity", m_Ncharge =
false);
97 declareProperty(
"NutupleFile",m_NtupleFile =
false);
98 declareProperty(
"mDIY",_mDIY=
false);
99 declareProperty(
"FDPdata",m_SB3File =
"");
100 declareProperty(
"FDPHisT",m_SB3HT =
"");
101 declareProperty(
"FDPpart",m_FDPparticle =
"");
102 declareProperty(
"TruthFile",m_truthFile =
"");
103 declareProperty(
"TruthPart",m_truthPart =
"");
104 declareProperty(
"Psi3SopenCharm",m_Psi4040OpenCharm=
false);
105 declareProperty(
"Psi2openCharm", m_Psi2openCharm=
false);
106 declareProperty(
"SetMthrForConExc",m_SetMthr=0.0);
107 declareProperty(
"statDecays",m_statDecays=
false);
108 declareProperty(
"TagLundCharmModel", m_tagLundModel=
false);
110 declareProperty(
"FileForTrackGen", m_mystring);
112 m_polarization.clear();
113 declareProperty(
"polarization", m_polarization);
114 declareProperty(
"eBeamPolarization", m_eBeamPolarization=-1);
115 m_cluster0.clear();m_wind0.clear();
116 m_cluster1.clear();m_wind1.clear();
117 m_cluster2.clear();m_wind2.clear();
118 declareProperty(
"cluster0",m_cluster0);
119 declareProperty(
"cluster1",m_cluster1);
120 declareProperty(
"cluster2",m_cluster2);
121 declareProperty(
"masswin0",m_wind0);
122 declareProperty(
"masswin1",m_wind1);
123 declareProperty(
"masswin2",m_wind2);
124 declareProperty(
"OutputP4",m_outputp4=
"");
125 declareProperty(
"ReadMeasuredEcms", m_RdMeasuredEcms =
false);
127 declareProperty(
"ReadTruth",m_ReadTruth);
135 MsgStream log(messageService(), name());
136 if(m_truthFile!=
""){truth.open(m_truthFile.c_str());}
137 log << MSG::INFO <<
"EvtDecay initialize" << endreq;
138 static const bool CREATEIFNOTTHERE(
true);
139 StatusCode RndmStatus = service(
"BesRndmGenSvc", p_BesRndmGenSvc, CREATEIFNOTTHERE);
140 if (!RndmStatus.isSuccess() || 0 == p_BesRndmGenSvc)
142 log << MSG::ERROR <<
" Could not initialize Random Number Service" << endreq;
147 for(
int i=0;i<m_mystring.size();i++){
EvtGlobalSet::SV.push_back(m_mystring[i]);}
151 std::vector<std::vector<int> >myivv;
152 std::vector<std::vector<double> >mydvv;
156 myivv.push_back(m_cluster0);
157 myivv.push_back(m_cluster1);
158 myivv.push_back(m_cluster2);
160 mydvv.push_back(m_wind0);
161 mydvv.push_back(m_wind1);
162 mydvv.push_back(m_wind2);
164 for(
int i=0;i<myivv.size();i++){
165 std::vector<int> theivv;
166 for(
int j=0;j<myivv[i].size();j++){
167 theivv.push_back(myivv[i][j]);
172 for(
int i=0;i<mydvv.size();i++){
173 std::vector<double> thedvv;
174 for(
int j=0;j<mydvv[i].size();j++){
175 thedvv.push_back(mydvv[i][j]);
181 if(m_eBeamPolarization>1) {std::cout<<
"The e-beam polaziation should be in 0 to 1"<<std::endl;abort();}
184 m_ampscalflag =
true;
186 CLHEP::HepRandomEngine* engine = p_BesRndmGenSvc->
GetEngine(
"EVTGEN");
187 const long s = engine->getSeed();
191 m_seeds.push_back(
s);
196 if ( m_DecayDec ==
"") {
197 m_DecayDec=getenv(
"BESEVTGENROOT");
198 m_DecayDec +=
"/share/DECAY.DEC";
201 if ( m_PdtTable ==
"") {
202 m_PdtTable =getenv(
"BESEVTGENROOT");
203 m_PdtTable +=
"/share/pdt.table";
207 std::cout<<
"===================== user decay card ========================"<<std::endl;
208 strcpy(catcmd,
"cat ");
209 strcat(catcmd, userDecFileName.c_str());
218 if (status.isSuccess()) {
219 log << MSG::INFO <<
"got the DataInfoSvc" << endreq;
223 log << MSG::ERROR <<
"could not get the DataInfoSvc" << endreq;
224 return StatusCode::FAILURE;
230 m_Gen =
new EvtGen( m_DecayDec.c_str(), m_PdtTable.c_str(), m_RandomEngine );
232 if(userDecFileName ==
"NONE") log << MSG::INFO <<
"EvtDecay User did not define his Decay table EvtGen will use standart" << endreq;
233 if(!(userDecFileName ==
"NONE")) m_Gen->
readUDecay(userDecFileName.c_str());
235 if(!(m_DecayTop==
" ")) {
236 outfile.open(m_DecayTop.c_str());
243 NTuplePtr nt1(
ntupleSvc(),
"MYROOTFILE/Trk");
244 if(nt1) {m_tuple=nt1;}
246 m_tuple =
ntupleSvc()->book (
"MYROOTFILE/Trk", CLID_ColumnWiseTuple,
"Generator-trk-Ntuple");
248 status = m_tuple->addItem (
"TotNumTrk", TotNumTrk, 0,100);
249 status = m_tuple->addIndexedItem (
"Trk_index", TotNumTrk, m_Trk_index);
250 status = m_tuple->addIndexedItem (
"m_px_trk", TotNumTrk, m_px_trk);
251 status = m_tuple->addIndexedItem (
"m_py_trk", TotNumTrk, m_py_trk);
252 status = m_tuple->addIndexedItem (
"m_pz_trk", TotNumTrk, m_pz_trk);
253 status = m_tuple->addIndexedItem (
"m_en_trk", TotNumTrk, m_en_trk);
254 status = m_tuple->addIndexedItem (
"FST", TotNumTrk, m_fst);
256 status = m_tuple->addItem (
"nchr", m_nchr);
257 status = m_tuple->addItem (
"nchr_e", m_nchr_e);
258 status = m_tuple->addItem (
"nchr_mu", m_nchr_mu);
259 status = m_tuple->addItem (
"nchr_pi", m_nchr_pi);
260 status = m_tuple->addItem (
"nchr_k", m_nchr_k);
261 status = m_tuple->addItem (
"nchr_p", m_nchr_p);
262 status = m_tuple->addItem (
"N_gamma", m_gamma);
263 status = m_tuple->addItem (
"N_gammaFSR", m_gammaFSR);
264 status = m_tuple->addItem (
"Flag1", m_flag1);
266 log << MSG::ERROR <<
" Cannot book N-tuple:"<< long(m_tuple) << endmsg;
267 return StatusCode::FAILURE;
271 NTuplePtr nt2(
ntupleSvc(),
"MYROOTFILE/mass");
272 if(nt2) {mass_tuple=nt2;}
274 mass_tuple =
ntupleSvc()->book (
"MYROOTFILE/mass", CLID_ColumnWiseTuple,
"Generator-mass-Ntuple");
276 status = mass_tuple->addItem (
"m12", m_m12);
277 status = mass_tuple->addItem (
"m13", m_m13);
278 status = mass_tuple->addItem (
"m23", m_m23);
279 status = mass_tuple->addItem (
"m1", m_m1);
280 status = mass_tuple->addItem (
"m2", m_m2);
281 status = mass_tuple->addItem (
"m3", m_m3);
282 status = mass_tuple->addItem (
"costheta1", m_cos1);
283 status = mass_tuple->addItem (
"costheta2", m_cos2);
284 status = mass_tuple->addItem (
"costheta3", m_cos3);
285 status = mass_tuple->addItem (
"ichannel", m_ich);
287 log << MSG::ERROR <<
" Cannot book N-tuple:"<< long(m_tuple) << endmsg;
288 return StatusCode::FAILURE;
292 NTuplePtr nt3(
ntupleSvc(),
"MYROOTFILE/massGen");
293 if(nt3) {massgen_tuple=nt3;}
295 massgen_tuple =
ntupleSvc()->book (
"MYROOTFILE/massGen", CLID_ColumnWiseTuple,
"Generator-mass-Ntuple");
297 status = massgen_tuple->addItem (
"m12", _m12);
298 status = massgen_tuple->addItem (
"m13", _m13);
299 status = massgen_tuple->addItem (
"m23", _m23);
300 status = massgen_tuple->addItem (
"m1", _m1);
301 status = massgen_tuple->addItem (
"m2", _m2);
302 status = massgen_tuple->addItem (
"m3", _m3);
303 status = massgen_tuple->addItem (
"costheta1", _cos1);
304 status = massgen_tuple->addItem (
"costheta2", _cos2);
305 status = massgen_tuple->addItem (
"costheta3", _cos3);
306 status = massgen_tuple->addItem (
"ichannel", _ich);
308 log << MSG::ERROR <<
" Cannot book N-tuple:"<< long(m_tuple) << endmsg;
309 return StatusCode::FAILURE;
315 for(
int i=0;i<500;i++){br[i]=0;}
316 if(!(m_SB3File==
"" && m_SB3HT==
"")) {
317 const char *filename, *histitle;
318 filename=(
char*)m_SB3File.c_str();
319 histitle=(
char*)m_SB3HT.c_str();
320 SuperBody3decay.
setFile(filename);
322 SuperBody3decay.
init();
325 return StatusCode::SUCCESS;
331 MsgStream log(messageService(), name());
334 string key =
"GEN_EVENT";
336 SmartDataPtr<McGenEventCol> McEvtColl(eventSvc(),
"/Event/Gen");
341 if ( McEvtColl == 0 )
343 HepMC::GenEvent* evt=
new GenEvent();
344 evt->set_event_number(m_numberEvent);
347 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
348 int runNo=eventHeader->runNumber();
349 int event=eventHeader->eventNumber();
351 if(
runNo != 0 &&
runNo != m_runNo){m_runNo=
runNo;newRunFlag =
true;}
else{newRunFlag=
false;}
352 if(m_RdMeasuredEcms&& newRunFlag){
357 std::cout<<
"Read Ecms= "<<dbEcms<<std::endl;
359 std::cout<<
"INFO: Read the MeasuredEcms"<<std::endl;
362 std::cout<<
"ERROR: Can not read the MeasuredEcms, try to turn off the ReadEcmsDB"<<std::endl;
363 return StatusCode::FAILURE;
369 callBesEvtGen( evt );
370 if(!(m_DecayTop==
"")) evt->print(outfile);
375 mcColl->push_back(mcEvent);
376 StatusCode sc = eventSvc()->registerObject(
"/Event/Gen",mcColl);
377 if(sc != SUCCESS)
return StatusCode::FAILURE;
381 McGenEventCol::iterator mcItr;
382 for( mcItr = McEvtColl->begin(); mcItr != McEvtColl->end(); mcItr++ )
384 HepMC::GenEvent* hEvt = (*mcItr)->getGenEvt();
389 if(!(m_DecayTop==
"")) hEvt->print(outfile);
392 if(!(m_DecayRec==
"")) std::cout<<std::endl;
395 if( m_NtupleFile ){ m_tuple->write();}
396 return StatusCode::SUCCESS;
404StatusCode EvtDecay::callEvtGen( HepMC::GenEvent* hepMCevt )
406 MsgStream log(messageService(), name());
415 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
417 for (
int i=0;i<13;i++)
fst[i]=0;
418 HepMC::GenEvent::particle_const_iterator itp;
420 for( itp=hepMCevt->particles_begin(); itp!=hepMCevt->particles_end(); ++itp )
442 HepMC::GenParticle* hepMCpart=*itp;
443 int stat = hepMCpart->status();
446 if ( stat != 1 )
continue;
448 loop_to_select_eventsB:
449 int id = hepMCpart->pdg_id();
451 hepMCpart->set_status(899);
455 double en =(hepMCpart->momentum()).e();
456 double pex=(hepMCpart->momentum()).px();
457 double pey=(hepMCpart->momentum()).py();
458 double pez=(hepMCpart->momentum()).pz();
461 parentMass=p_init.mass();
467 bool parentFlag=
false;
469 if(m_polarization.size()>0) {
471 }
else if(m_eBeamPolarization>0){
479 int id = hepMCpart->pdg_id();
482 if(
id == 11 ) {
fst[1]++;}
else if(
id == -11){
fst[2]++;}
483 else if(
id == 13){
fst[3]++;}
484 else if(
id == -13){
fst[4]++;}
485 else if(
id == 211){
fst[5]++;}
486 else if(
id ==-211){
fst[6]++;}
487 else if(
id == 321){
fst[7]++;}
488 else if(
id ==-321){
fst[8]++;}
489 else if(
id ==2212){
fst[9]++;}
490 else if(
id ==-2212){
fst[10]++;}
491 else if(
id == 2112){
fst[11]++;}
492 else if(
id ==-2112){
fst[12]++;}
493 if( fabs(
id) == 11) {
nchr_e++;}
494 if( fabs(
id) == 13) {
nchr_mu++;}
495 if( fabs(
id) == 211) {
nchr_pi++;}
496 if( fabs(
id) == 321) {
nchr_k++;}
497 if( fabs(
id) == 2212) {
nchr_p++;}
500 if( m_NtupleFile==
true ){
501 m_Trk_index[AllTrk_index]=id;
502 m_px_trk[AllTrk_index]=pex;
503 m_py_trk[AllTrk_index]=pey;
504 m_pz_trk[AllTrk_index]=pez;
505 m_en_trk[AllTrk_index]=en ;
508 Trk_index[AllTrk_index]=0;
518 if(m_FDPparticle!=
""){
527 if(!(m_SB3File==
"" || m_SB3HT==
"") && parentFlag && first ){
528 SuperBody3decay_make(fdp_ppid, fdp_init );
531 loop_to_select_eventsA:
533 if(m_truthFile!=
"" && m_truthPart!=
""){
536 for(
int id=0;
id<ndaug;
id++){
539 truth<<son.
get(0)<<
" "<<son.
get(1)<<
" "<<son.
get(2)<<
" "<<son.
get(3)<<std::endl;
544 if(_mDIY && parentFlag && m_ampscalflag ) _amps_max=CalAmpsMax(part);
545 if(_mDIY && parentFlag) {
547 double amps=CalAmpsMDIY( part );
548 ratio=amps/_amps_max;
550 if(_mDIY && parentFlag && ratio<=rdm){
goto loop_to_select_eventsA;}
554 if(m_FDPparticle==
""){FDP_part=part;}
555 if(!(m_SB3File==
"" || m_SB3HT==
"") && parentFlag ){ accept=SuperBody3decay_judge( FDP_part); }
556 if(!(m_SB3File==
"" || m_SB3HT==
"") && parentFlag && !accept){
559 goto loop_to_select_eventsB;
560 }
else if(!(m_SB3File==
"" || m_SB3HT==
"") && parentFlag && accept){
561 countChannel(FDP_part);
564 if((m_Psi2openCharm || m_Psi4040OpenCharm) && parentFlag ){
565 if(getModel(part) ==
"OPENCHARM"){
566 std::cout<<
"OPENCHARM model need to set Psi2openCharm and Psi3SopenCharm to be false!"<<std::endl;
570 bool theDecay = opencharm.choseDecay();
574 goto loop_to_select_eventsB;
583 unsigned int modeTag, multiplicityTag;
584 modeTag = theTag.getModeTag();
585 if( getModel(part) ==
"OPENCHARM"||getModel(part) ==
"LUNDCHARM" && m_tagLundModel){
586 multiplicityTag = decayType(part);
590 multiplicityTag = theTag.getMultTag() + decayType(part);
594 if(eventHeader == 0) std::cout <<
"event header unavailable: " << std::endl;
595 if (eventHeader != 0) {
596 eventHeader->setFlag1(modeTag);
597 eventHeader->setFlag2(multiplicityTag);
602 if(!(m_DecayRec==
"")) mydecayrec=part->
writeTreeRec(m_DecayRec);
604 if(m_statDecays && parentFlag ) countChannel(part);
607 if ( log.level() <= MSG::DEBUG ) part->
printTree() ;
608 log << MSG::DEBUG <<
"Converting particles to HepMC" << endreq;
610 makeHepMC(part, hepMCevt, hepMCpart);
612 hepMCpart->set_status(999);
618 for(
int i=0;i<nds;i++){
621 std::cout<<
"vvpp "<<vp1.
get(0)<<
" "<<vp1.
get(1)<<
" "<<vp1.
get(2)<<
" "<<vp1.
get(3)<<std::endl;
625 if(m_ReadTruth.size())ReadTruth(part,m_ReadTruth);
630 for( itp=hepMCevt->particles_begin(); itp!=hepMCevt->particles_end(); ++itp )
632 if (!(*itp)->end_vertex() && ( (*itp)->status()==899 || (*itp)->status()==999 ))
633 (*itp)->set_status(1);
637 if(m_Ncharge ==
true ) {std::cout<<
"Multiplicity: TotoalCharge_e_mu_pi_K_p_gamma_gammaFSR: "
646 if(m_Ncharge ==
true ){std::cout<<
"FinalStates: "
659 <<
fst[12]<<std::endl;}
670 TotNumTrk = AllTrk_index;
674 return StatusCode::SUCCESS;
680StatusCode EvtDecay::callBesEvtGen( HepMC::GenEvent* hepMCevt )
682 MsgStream log(messageService(), name());
692 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
693 for (
int i=0;i<13;i++)
fst[i]=0;
694 HepMC::GenEvent::particle_const_iterator itp;
715 loop_to_select_eventsB:
727 HepMC::GenParticle* hepMCpart=
new GenParticle(HepLorentzVector(0,0,0,ppmass),pid,3);
729 bool parentFlag =
false;
732 if(m_polarization.size()>0) {
734 }
else if(m_eBeamPolarization>0){
746 if(m_FDPparticle!=
""){
755 if(!(m_SB3File==
"" || m_SB3HT==
"") && first ){ SuperBody3decay_make( fdp_ppid, fdp_init);}
758 loop_to_select_events:
759 m_Gen->
generateDecay(part);
if(m_numberEvent<=1){ std::cout<<
"after m_Gen->decay "<<std::endl; part->
printTree();}
762 if(_mDIY && m_ampscalflag ) _amps_max=CalAmpsMax(part);
765 for(
int myloop=0;myloop<100;myloop++){
767 double amps=CalAmpsMDIY( part);
768 ratio=amps/_amps_max;
770 if( !isNumber(amps) || !isNumber(_amps_max) || ratio<=0 ) {
774 }
else if( rdm<=ratio) {
780 if(m_truthFile!=
"" && m_truthPart!=
""){
783 for(
int id=0;
id<ndaug;
id++){
786 truth<<son.
get(0)<<
" "<<son.
get(1)<<
" "<<son.
get(2)<<
" "<<son.
get(3)<<std::endl;
792 if(m_FDPparticle==
""){FDP_part=part;}
793 if(!(m_SB3File==
"" || m_SB3HT==
"")){
794 accept=SuperBody3decay_judge( FDP_part);
796 if(!(m_SB3File==
"" || m_SB3HT==
"") && !accept) {
799 goto loop_to_select_eventsB;
800 }
else if(!(m_SB3File==
"" || m_SB3HT==
"") && parentFlag && accept){
801 countChannel(FDP_part);
806 if(m_statDecays && parentFlag) countChannel(part);
813 unsigned int modeTag, multiplicityTag;
814 modeTag = theTag.getModeTag();
815 if( getModel(part) ==
"OPENCHARM"|| getModel(part) ==
"LUNDCHARM" && m_tagLundModel ){
816 multiplicityTag = decayType(part);
820 multiplicityTag = theTag.getMultTag() + decayType(part);
822 if(eventHeader == 0) std::cout <<
"event header unavailable: " << std::endl;
823 if (eventHeader != 0) {
824 eventHeader->setFlag1(modeTag);
825 eventHeader->setFlag2(multiplicityTag);
827 if(m_NtupleFile)m_flag1 = modeTag;
831 if(!(m_DecayRec==
"")) {mydecayrec=part->
writeTreeRec(m_DecayRec);std::cout<<std::endl;};
834 if ( log.level() <= MSG::DEBUG ) part->
printTree() ;
835 log << MSG::DEBUG <<
"Converting particles to HepMC" << endreq;
837 makeHepMC(part, hepMCevt, hepMCpart);
839 if(part->
getNDaug()!=0) hepMCpart->set_status(999);
844 for( itp=hepMCevt->particles_begin(); itp!=hepMCevt->particles_end(); ++itp )
846 if (!(*itp)->end_vertex() && ( (*itp)->status()==899 || (*itp)->status()==999 ))
847 (*itp)->set_status(1);
849 HepMC::GenParticle* hepMCpart=*itp;
850 int stat = hepMCpart->status();
851 int id = hepMCpart->pdg_id();
852 if(
abs(
id)==411 ||
abs(
id)==413 ) { (*itp)->set_status(999);stat=999;}
854 if ( stat != 1 )
continue;
857 if(
id == 11 ) {
fst[1]++;}
858 else if(
id == -11) {
fst[2]++;}
859 else if(
id == 13 ) {
fst[3]++;}
860 else if(
id ==-13) {
fst[4]++;}
861 else if(
id==211) {
fst[5]++;}
862 else if(
id==-211) {
fst[6]++;}
863 else if(
id== 321) {
fst[7]++;}
864 else if(
id ==-321) {
fst[8]++;}
865 else if(
id ==2212) {
fst[9]++;}
866 else if(
id==-2212) {
fst[10]++;}
867 else if(
id == 2112){
fst[11]++;}
868 else if(
id==-2112) {
fst[12]++;}
869 if( fabs(
id) == 11) {
nchr_e++;}
870 if( fabs(
id) == 13) {
nchr_mu++;}
871 if( fabs(
id) == 211) {
nchr_pi++;}
872 if( fabs(
id) == 321) {
nchr_k++;}
873 if( fabs(
id) == 2212) {
nchr_p++;}
876 double en =(hepMCpart->momentum()).e();
877 double pex=(hepMCpart->momentum()).px();
878 double pey=(hepMCpart->momentum()).py();
879 double pez=(hepMCpart->momentum()).pz();
881 if( m_NtupleFile==
true &&
id!=0){
882 m_Trk_index[AllTrk_index]=id;
883 m_px_trk[AllTrk_index]=pex;
884 m_py_trk[AllTrk_index]=pey;
885 m_pz_trk[AllTrk_index]=pez;
886 m_en_trk[AllTrk_index]=en ;
898 itp=hepMCevt->particles_begin();
899 (*itp)->set_status(2);
903 if(m_Ncharge ==
true ) {std::cout<<
"Multiplicity: TotoalCharge_e_mu_pi_K_p_gamma_gammaFSR: "
912 if(m_Ncharge ==
true ){std::cout<<
"FinalStates: "
925 <<
fst[12]<<std::endl;}
937 TotNumTrk = AllTrk_index;
941 if(m_ReadTruth.size())ReadTruth(part,m_ReadTruth);
946 return StatusCode::SUCCESS;
961 std::cout<<
"Calculated helicity amplitude sqaured are:"<<std::endl;
962 std::cout<<
"|H_{2}|^2=|H_{-2}|^2= "<<H2/nd<<
" +/- "<<sqrt(H2err/nd)<<endl;
963 std::cout<<
"|H_{1}|^2=|H_{-1}|^2= "<<H1/nd<<
" +/- "<<sqrt(H1err/nd)<<endl;
966 MsgStream log(messageService(), name());
968 log << MSG::INFO <<
"EvtDecay finalized" << endreq;
970 Forfile.open(
"fort.16",ios::in);
972 strcpy(delcmd,
"rm -f ");
973 strcat(delcmd,
"fort.16");
977 Forfile2.open(
"fort.22",ios::in);
978 strcpy(delcmd,
"rm -f ");
979 strcat(delcmd,
"fort.22");
989 if(!(m_SB3File==
"" || m_SB3HT==
"")){
990 for(
int i=0;i<500;i++){totalEvt=totalEvt+br[i];}
991 for(
int i=0;i<500;i++){
992 double bi=1.0*br[i]/totalEvt;
993 std::cout<<
"Branching fraction of channel "<<i<<
" is: "<<bi<<std::endl;
1000 for(
int i=0;i<=totalChannels;i++){totalEvt=totalEvt+br[i];}
1001 std::cout<<
"==================Statistical first chain decay ==============================="<<std::endl;
1002 std::cout<<
"i-th channel Events Generated Branching fraction generated "<<std::endl;
1003 for(
int i=0;i<=totalChannels;i++){
1004 std::cout<<
"| "<<i<<
" "<<br[i]<<
" "<<br[i]*1.0/totalEvt<<std::endl;
1007 std::cout<<
"--------------------------------------------------------------------------------"<<std::endl;
1008 std::cout<<
" sum: "<<totalEvt<<
" "<<
"1"<<std::endl;
1009 std::cout<<
"================== End of statistical first chain decay ========================"<<std::endl;
1012 return StatusCode::SUCCESS;
1016StatusCode EvtDecay::makeHepMC(
EvtParticle* part, HepMC::GenEvent* hEvt,
1017 HepMC::GenParticle* hPart)
1019 MsgStream log(messageService(), name());
1028 HepMC::GenVertex* end_vtx =
new HepMC::GenVertex(HepLorentzVector(x,y,z,ct));
1029 hEvt->add_vertex( end_vtx );
1030 end_vtx->add_particle_in(hPart);
1034 for(
int it=0;it<ndaug;it++)
1046 HepMC::GenParticle* prod_part =
new HepMC::GenParticle(HepLorentzVector(px,py,pz,e),
id,status);
1047 end_vtx->add_particle_out(prod_part);
1048 makeHepMC(part->
getDaug(it),hEvt,prod_part);
1052 if( log.level()<MSG::INFO )
1057 return StatusCode::SUCCESS;
1061void EvtDecay::MeVToGeV (HepMC::GenEvent* evt)
1063 for ( HepMC::GenEvent::particle_iterator p = evt->particles_begin(); p != evt->particles_end(); ++p ) {
1067 HepMC::FourVector tmpfv((*p)->momentum().x()/1000.,
1068 (*p)->momentum().y()/1000.,
1069 (*p)->momentum().z()/1000.,
1070 (*p)->momentum().t()/1000.
1073 (*p)->set_momentum( tmpfv );
1077void EvtDecay::GeVToMeV (HepMC::GenEvent* evt)
1079 for ( HepMC::GenEvent::particle_iterator p = evt->particles_begin(); p != evt->particles_end(); ++p ) {
1082 HepMC::FourVector tmpfv((*p)->momentum().x()*1000.,
1083 (*p)->momentum().y()*1000.,
1084 (*p)->momentum().z()*1000.,
1085 (*p)->momentum().t()*1000.
1088 (*p)->set_momentum( tmpfv );
1096 for(
int i=0;i<100000;i++){
1098 double amps=CalAmpsMDIY(part);
1099 if(amps > amps_max) amps_max=amps;
1101 amps_max=amps_max*1.05;
1102 m_ampscalflag =
false;
1111 m_engine->showStatus();
1119 return RandFlat::shoot(m_engine);
1124 double xmass2,ymass2;
1129 FinalState_make( ppid, p_init);
1132 for(
int i=0;i<100000;i++){
1135 HepMC::GenParticle* hepMCpart=
new GenParticle(HepLorentzVector(0,0,0,parentMass),parentPDGcode,3);
1143 FinalState_sort(part);
1150 xmass2=(pd1+pd2).mass2();
1151 ymass2=(pd1+pd3).mass2();
1154 double ylow=SuperBody3decay.
getYlow();
1155 double yup=SuperBody3decay.
getYup();
1156 if(xmass2<xlow || xmass2>
xup || ymass2<ylow || ymass2>yup) { part->
deleteTree();
goto regen;}
1157 SuperBody3decay.
HFill(xmass2,ymass2);
1164 m_m12=(pd1+pd2).
mass();
1165 m_m23=(pd2+pd3).
mass();
1166 m_m13=(pd1+pd3).
mass();
1170 mass_tuple->write();
1172 double m1=pd1.
mass();
double m2=pd2.
mass();
double m3=pd3.
mass();
1173 double mj=(pd2+pd3).
mass();
1183bool EvtDecay::SuperBody3decay_judge(
EvtParticle* part){
1184 double xmass2,ymass2;
1189 FinalState_sort( part);
1196 xmass2=(pd1+pd2).mass2();
1197 ymass2=(pd1+pd3).mass2();
1198 accept=SuperBody3decay.
AR(xmass2,ymass2);
1201 if(accept && m_NtupleFile) {
1206 _m12=(pd1+pd2).
mass();
1207 _m23=(pd2+pd3).
mass();
1208 _m13=(pd1+pd3).
mass();
1212 massgen_tuple->write();
1223 identical_flag=
true;
1225 for(
int i=1;i<10000;i++){
1227 HepMC::GenParticle* hepMCpart=
new GenParticle(HepLorentzVector(0,0,0,parentMass),parentPDGcode,3);
1232 if(nson == 2) {
continue;}
else
1234 EvtId xid0,xid1,xid2;
1244 if(pdg0==pdg1 && pdg1==pdg2) {multi=3;}
1245 else if(pdg0==pdg1 ){multi=2;}
1246 else if(pdg0==pdg2 ){multi=2;pdg=pdg1; pdg1=pdg2; pdg2=pdg;}
1247 else if(pdg1==pdg2) {multi=2;pdg=pdg0; pdg0=pdg1; pdg1=pdg2; pdg2=pdg;}
1251 std::cout<<
"No direct three body decay channel found in decay card, I stop run"<<std::endl;
1262 EvtId xid0,xid1,xid2;
1292 assign_momentum(id0,pd0);
1293 assign_momentum(id1,pd1);
1294 assign_momentum(id2,pd2);
1295 }
else if(multi==2){
1296 assign_momentum2(id0,pd0);
1297 assign_momentum2(id1,pd1);
1298 assign_momentum2(id2,pd2);
1299 if(son0.
get(0)>son1.
get(0)){son=son0;son0=son1;son1=son;}
1300 }
else if(multi==3){
1301 double En0=pd0.
get(0);
1302 double En1=pd1.
get(0);
1303 double En2=pd2.
get(0);
1304 if(En0 < En1 && En1 < En2) {son0=pd0;son1=pd1;son2=pd2;}
1305 if(En0 < En2 && En2 < En1) {son0=pd0;son1=pd2;son2=pd1;}
1306 if(En1 < En0 && En0 < En2) {son0=pd1;son1=pd0;son2=pd2;}
1307 if(En1 < En2 && En2 < En0) {son0=pd1;son1=pd2;son2=pd0;}
1308 if(En2 < En0 && En0 < En1) {son0=pd2;son1=pd0;son2=pd1;}
1309 if(En2 < En1 && En1 < En0) {son0=pd2;son1=pd1;son2=pd0;}
1315void EvtDecay::assign_momentum(
int id0,
EvtVector4R pd0){
1316 if(id0==pdg0){son0=pd0;}
1317 else if(id0==pdg1){son1=pd0;}
1318 else if(id0==pdg2){son2=pd0;}
1319 else {std::cout<<
"PID= "<<id0<<
" not machted, I stop"<<std::endl; ::abort();}
1322void EvtDecay::assign_momentum2(
int id0,
EvtVector4R pd0){
1323 if(id0==pdg0 && identical_flag){son0=pd0;identical_flag=
false;}
1324 else if(id0==pdg1){son1=pd0;identical_flag=
true;}
1325 else if(id0==pdg2){son2=pd0;}
1326 else {std::cout<<
"PID not machted, I stop"<<std::endl; ::abort();}
1337 for(
int i=0;i<dn;i++){
1341 if(son_pdg == FDP_pdg){
1361 if(ich>totalChannels) totalChannels = ich;
1365bool EvtDecay::isCharmonium(
EvtId xid){
1381 std::vector<EvtId> Vid; Vid.clear();
1382 Vid.push_back(psi4415);
1383 Vid.push_back(psi4160);
1384 Vid.push_back(psi4040);
1385 Vid.push_back(psi3770);
1386 Vid.push_back(psiprim);
1387 Vid.push_back(jpsi);
1388 Vid.push_back(etac);
1389 Vid.push_back(etac2s);
1391 Vid.push_back(chic0);
1392 Vid.push_back(chic1);
1393 Vid.push_back(chic2);
1394 Vid.push_back(chic0p);
1395 Vid.push_back(chic1p);
1396 Vid.push_back(chic2p);
1399 for(
int i=0;i<Vid.size();i++){
if(xid == Vid[i])
return flag;}
1404bool EvtDecay::isCharm(
EvtId xid){
1422 std::vector<EvtId> Vid; Vid.clear();
1424 Vid.push_back(d0bar);
1429 Vid.push_back(dstp);
1430 Vid.push_back(dstm);
1432 Vid.push_back(ds0bar );
1433 Vid.push_back(dsp );
1434 Vid.push_back(dsm );
1435 Vid.push_back(dsstp );
1436 Vid.push_back(dsstm );
1437 Vid.push_back(ds0stp );
1438 Vid.push_back(ds0stm );
1441 for(
int i=0;i<Vid.size();i++){
if(xid == Vid[i])
return flag;}
1447 for(
int i=0;i<ndg;i++){
1466 std::string model = getModel(par,Nchannel);
1467 if( model ==
"OPENCHARM" || model ==
"LUNDCHARM" && m_tagLundModel){
1474 for(
int i=0;i<ndg;i++){
1479 if( isRadecay(par) ){
1480 for(
int i=0;i<ndg;i++){
1482 if( isCharmonium(xid) )
return 1;
1490 if( isCharm(xd1) && isCharm(xd2) ) {
return 2;}
else
1491 if( !isCharmonium(xd1) && !isCharmonium(xd2) && !isCharm(xd1) && !isCharm(xd2) ){
1496 for(
int i=0;i<ndg;i++){
1498 if( isCharmonium(xid) ) {
flag =
true;
break;}
1499 if( isCharm(xid) ) {
flag =
true;
break;}
1501 if( !
flag ){
return 3;}
else {
return 4;}
1508std::string EvtDecay::getModel(
EvtParticle *par,
int mode){
1520void EvtDecay::ReadTruth(
EvtParticle* part,std::vector<std::vector<string> > mylist){
1521 if(mylist.size()<2) {std::cout<<
" Empty list"<<std::endl;abort();}
1523 for(
int k=0;k<mylist[0].size();k++){
1526 for(
int i=1;i<mylist.size();i++){
1528 for(
int j=0;j<mylist[i].size();j++){
1535 if( !isNumber(vp1.
get(0)) ) {part->
printTree(); abort();}
1536 std::cout<<
"truth "<<vp1.
get(0)<<
" "<<vp1.
get(1)<<
" "<<vp1.
get(2)<<
" "<<vp1.
get(3)<<std::endl;
1542int EvtDecay::isNumber(
double d){
return (d==d);}
1544#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
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.