44#include "HepMC/GenEvent.h"
45#include "HepMC/GenVertex.h"
46#include "HepMC/GenParticle.h"
47#include "EventModel/EventHeader.h"
48#include "GaudiKernel/SmartDataPtr.h"
49#include "DataInfoSvc/IDataInfoSvc.h"
50#include "DataInfoSvc/DataInfoSvc.h"
51#include "GaudiKernel/MsgStream.h"
52#include "GaudiKernel/ISvcLocator.h"
53#include "GaudiKernel/AlgFactory.h"
54#include "GaudiKernel/DataSvc.h"
55#include "GaudiKernel/SmartDataPtr.h"
56#include "GaudiKernel/IPartPropSvc.h"
58#include "BesKernel/IBesRndmGenSvc.h"
59#include "GeneratorObject/McGenEvent.h"
60#include "CLHEP/Random/Ranlux64Engine.h"
61#include "CLHEP/Random/RandFlat.h"
66static string mydecayrec;
67static double _amps_max;
77int EvtDecay::m_runNo=0;
87 declareProperty(
"DecayDecDir", m_DecayDec =
"");
88 declareProperty(
"PdtTableDir", m_PdtTable =
"");
89 declareProperty(
"userDecayTableName", userDecFileName =
"NONE");
90 declareProperty(
"DecayTopology", m_DecayTop =
"");
91 declareProperty(
"DecayRecord", m_DecayRec =
"");
92 declareProperty(
"ParentParticle", m_ParentPart =
"NONE");
93 declareProperty(
"Multiplicity", m_Ncharge =
false);
94 declareProperty(
"NutupleFile",m_NtupleFile =
false);
95 declareProperty(
"mDIY",_mDIY=
false);
96 declareProperty(
"FDPdata",m_SB3File =
"");
97 declareProperty(
"FDPHisT",m_SB3HT =
"");
98 declareProperty(
"FDPpart",m_FDPparticle =
"");
99 declareProperty(
"TruthFile",m_truthFile =
"");
100 declareProperty(
"TruthPart",m_truthPart =
"");
101 declareProperty(
"Psi3SopenCharm",m_Psi4040OpenCharm=
false);
102 declareProperty(
"Psi2openCharm", m_Psi2openCharm=
false);
103 declareProperty(
"statDecays",m_statDecays=
false);
104 declareProperty(
"TagLundCharmModel", m_tagLundModel=
false);
106 declareProperty(
"FileForTrackGen", m_mystring);
108 m_polarization.clear();
109 declareProperty(
"polarization", m_polarization);
110 declareProperty(
"eBeamPolarization", m_eBeamPolarization=-1);
111 m_cluster0.clear();m_wind0.clear();
112 m_cluster1.clear();m_wind1.clear();
113 m_cluster2.clear();m_wind2.clear();
114 declareProperty(
"cluster0",m_cluster0);
115 declareProperty(
"cluster1",m_cluster1);
116 declareProperty(
"cluster2",m_cluster2);
117 declareProperty(
"masswin0",m_wind0);
118 declareProperty(
"masswin1",m_wind1);
119 declareProperty(
"masswin2",m_wind2);
120 declareProperty(
"OutputP4",m_outputp4=
"");
121 declareProperty(
"ReadMeasuredEcms", m_RdMeasuredEcms =
false);
123 declareProperty(
"ReadTruth",m_ReadTruth);
131 MsgStream log(messageService(), name());
132 if(m_truthFile!=
""){truth.open(m_truthFile.c_str());}
133 log << MSG::INFO <<
"EvtDecay initialize" << endreq;
134 static const bool CREATEIFNOTTHERE(
true);
135 StatusCode RndmStatus = service(
"BesRndmGenSvc", p_BesRndmGenSvc, CREATEIFNOTTHERE);
136 if (!RndmStatus.isSuccess() || 0 == p_BesRndmGenSvc)
138 log << MSG::ERROR <<
" Could not initialize Random Number Service" << endreq;
143 for(
int i=0;i<m_mystring.size();i++){
EvtGlobalSet::SV.push_back(m_mystring[i]);}
147 std::vector<std::vector<int> >myivv;
148 std::vector<std::vector<double> >mydvv;
150 myivv.push_back(m_cluster0);
151 myivv.push_back(m_cluster1);
152 myivv.push_back(m_cluster2);
154 mydvv.push_back(m_wind0);
155 mydvv.push_back(m_wind1);
156 mydvv.push_back(m_wind2);
158 for(
int i=0;i<myivv.size();i++){
159 std::vector<int> theivv;
160 for(
int j=0;j<myivv[i].size();j++){
161 theivv.push_back(myivv[i][j]);
166 for(
int i=0;i<mydvv.size();i++){
167 std::vector<double> thedvv;
168 for(
int j=0;j<mydvv[i].size();j++){
169 thedvv.push_back(mydvv[i][j]);
175 if(m_eBeamPolarization>1) {std::cout<<
"The e-beam polaziation should be in 0 to 1"<<std::endl;abort();}
178 m_ampscalflag =
true;
180 CLHEP::HepRandomEngine* engine = p_BesRndmGenSvc->
GetEngine(
"EVTGEN");
181 const long s = engine->getSeed();
185 m_seeds.push_back(
s);
190 if ( m_DecayDec ==
"") {
191 m_DecayDec=getenv(
"BESEVTGENROOT");
192 m_DecayDec +=
"/share/DECAY.DEC";
195 if ( m_PdtTable ==
"") {
196 m_PdtTable =getenv(
"BESEVTGENROOT");
197 m_PdtTable +=
"/share/pdt.table";
201 std::cout<<
"===================== user decay card ========================"<<std::endl;
202 strcpy(catcmd,
"cat ");
203 strcat(catcmd, userDecFileName.c_str());
212 if (status.isSuccess()) {
213 log << MSG::INFO <<
"got the DataInfoSvc" << endreq;
217 log << MSG::ERROR <<
"could not get the DataInfoSvc" << endreq;
218 return StatusCode::FAILURE;
224 m_Gen =
new EvtGen( m_DecayDec.c_str(), m_PdtTable.c_str(), m_RandomEngine );
226 if(userDecFileName ==
"NONE") log << MSG::INFO <<
"EvtDecay User did not define his Decay table EvtGen will use standart" << endreq;
227 if(!(userDecFileName ==
"NONE")) m_Gen->
readUDecay(userDecFileName.c_str());
229 if(!(m_DecayTop==
" ")) {
230 outfile.open(m_DecayTop.c_str());
237 NTuplePtr nt1(
ntupleSvc(),
"MYROOTFILE/Trk");
238 if(nt1) {m_tuple=nt1;}
240 m_tuple =
ntupleSvc()->book (
"MYROOTFILE/Trk", CLID_ColumnWiseTuple,
"Generator-trk-Ntuple");
242 status = m_tuple->addItem (
"TotNumTrk", TotNumTrk, 0,100);
243 status = m_tuple->addIndexedItem (
"Trk_index", TotNumTrk, m_Trk_index);
244 status = m_tuple->addIndexedItem (
"m_px_trk", TotNumTrk, m_px_trk);
245 status = m_tuple->addIndexedItem (
"m_py_trk", TotNumTrk, m_py_trk);
246 status = m_tuple->addIndexedItem (
"m_pz_trk", TotNumTrk, m_pz_trk);
247 status = m_tuple->addIndexedItem (
"m_en_trk", TotNumTrk, m_en_trk);
248 status = m_tuple->addIndexedItem (
"FST", TotNumTrk, m_fst);
250 status = m_tuple->addItem (
"nchr", m_nchr);
251 status = m_tuple->addItem (
"nchr_e", m_nchr_e);
252 status = m_tuple->addItem (
"nchr_mu", m_nchr_mu);
253 status = m_tuple->addItem (
"nchr_pi", m_nchr_pi);
254 status = m_tuple->addItem (
"nchr_k", m_nchr_k);
255 status = m_tuple->addItem (
"nchr_p", m_nchr_p);
256 status = m_tuple->addItem (
"N_gamma", m_gamma);
257 status = m_tuple->addItem (
"N_gammaFSR", m_gammaFSR);
258 status = m_tuple->addItem (
"Flag1", m_flag1);
260 log << MSG::ERROR <<
" Cannot book N-tuple:"<< long(m_tuple) << endmsg;
261 return StatusCode::FAILURE;
265 NTuplePtr nt2(
ntupleSvc(),
"MYROOTFILE/mass");
266 if(nt2) {mass_tuple=nt2;}
268 mass_tuple =
ntupleSvc()->book (
"MYROOTFILE/mass", CLID_ColumnWiseTuple,
"Generator-mass-Ntuple");
270 status = mass_tuple->addItem (
"m12", m_m12);
271 status = mass_tuple->addItem (
"m13", m_m13);
272 status = mass_tuple->addItem (
"m23", m_m23);
273 status = mass_tuple->addItem (
"m1", m_m1);
274 status = mass_tuple->addItem (
"m2", m_m2);
275 status = mass_tuple->addItem (
"m3", m_m3);
276 status = mass_tuple->addItem (
"costheta1", m_cos1);
277 status = mass_tuple->addItem (
"costheta2", m_cos2);
278 status = mass_tuple->addItem (
"costheta3", m_cos3);
279 status = mass_tuple->addItem (
"ichannel", m_ich);
281 log << MSG::ERROR <<
" Cannot book N-tuple:"<< long(m_tuple) << endmsg;
282 return StatusCode::FAILURE;
286 NTuplePtr nt3(
ntupleSvc(),
"MYROOTFILE/massGen");
287 if(nt3) {massgen_tuple=nt3;}
289 massgen_tuple =
ntupleSvc()->book (
"MYROOTFILE/massGen", CLID_ColumnWiseTuple,
"Generator-mass-Ntuple");
291 status = massgen_tuple->addItem (
"m12", _m12);
292 status = massgen_tuple->addItem (
"m13", _m13);
293 status = massgen_tuple->addItem (
"m23", _m23);
294 status = massgen_tuple->addItem (
"m1", _m1);
295 status = massgen_tuple->addItem (
"m2", _m2);
296 status = massgen_tuple->addItem (
"m3", _m3);
297 status = massgen_tuple->addItem (
"costheta1", _cos1);
298 status = massgen_tuple->addItem (
"costheta2", _cos2);
299 status = massgen_tuple->addItem (
"costheta3", _cos3);
300 status = massgen_tuple->addItem (
"ichannel", _ich);
302 log << MSG::ERROR <<
" Cannot book N-tuple:"<< long(m_tuple) << endmsg;
303 return StatusCode::FAILURE;
309 for(
int i=0;i<500;i++){br[i]=0;}
310 if(!(m_SB3File==
"" && m_SB3HT==
"")) {
311 const char *filename, *histitle;
312 filename=(
char*)m_SB3File.c_str();
313 histitle=(
char*)m_SB3HT.c_str();
314 SuperBody3decay.
setFile(filename);
316 SuperBody3decay.
init();
319 return StatusCode::SUCCESS;
325 MsgStream log(messageService(), name());
328 string key =
"GEN_EVENT";
330 SmartDataPtr<McGenEventCol> McEvtColl(eventSvc(),
"/Event/Gen");
335 if ( McEvtColl == 0 )
337 HepMC::GenEvent* evt=
new GenEvent();
338 evt->set_event_number(m_numberEvent);
341 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
342 int runNo=eventHeader->runNumber();
343 int event=eventHeader->eventNumber();
345 if(
runNo != 0 &&
runNo != m_runNo){m_runNo=
runNo;newRunFlag =
true;}
else{newRunFlag=
false;}
346 if(m_RdMeasuredEcms&& newRunFlag){
351 std::cout<<
"Read Ecms= "<<dbEcms<<std::endl;
353 std::cout<<
"INFO: Read the MeasuredEcms"<<std::endl;
356 std::cout<<
"ERROR: Can not read the MeasuredEcms, try to turn off the ReadEcmsDB"<<std::endl;
357 return StatusCode::FAILURE;
363 callBesEvtGen( evt );
364 if(!(m_DecayTop==
"")) evt->print(outfile);
369 mcColl->push_back(mcEvent);
370 StatusCode sc = eventSvc()->registerObject(
"/Event/Gen",mcColl);
371 if(sc != SUCCESS)
return StatusCode::FAILURE;
375 McGenEventCol::iterator mcItr;
376 for( mcItr = McEvtColl->begin(); mcItr != McEvtColl->end(); mcItr++ )
378 HepMC::GenEvent* hEvt = (*mcItr)->getGenEvt();
383 if(!(m_DecayTop==
"")) hEvt->print(outfile);
386 if(!(m_DecayRec==
"")) std::cout<<std::endl;
389 if( m_NtupleFile ){ m_tuple->write();}
390 return StatusCode::SUCCESS;
398StatusCode EvtDecay::callEvtGen( HepMC::GenEvent* hepMCevt )
400 MsgStream log(messageService(), name());
409 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
411 for (
int i=0;i<13;i++)
fst[i]=0;
412 HepMC::GenEvent::particle_const_iterator itp;
414 for( itp=hepMCevt->particles_begin(); itp!=hepMCevt->particles_end(); ++itp )
436 HepMC::GenParticle* hepMCpart=*itp;
437 int stat = hepMCpart->status();
440 if ( stat != 1 )
continue;
442 loop_to_select_eventsB:
443 int id = hepMCpart->pdg_id();
445 hepMCpart->set_status(899);
449 double en =(hepMCpart->momentum()).e();
450 double pex=(hepMCpart->momentum()).px();
451 double pey=(hepMCpart->momentum()).py();
452 double pez=(hepMCpart->momentum()).pz();
455 parentMass=p_init.mass();
461 bool parentFlag=
false;
463 if(m_polarization.size()>0) {
465 }
else if(m_eBeamPolarization>0){
473 int id = hepMCpart->pdg_id();
476 if(
id == 11 ) {
fst[1]++;}
else if(
id == -11){
fst[2]++;}
477 else if(
id == 13){
fst[3]++;}
478 else if(
id == -13){
fst[4]++;}
479 else if(
id == 211){
fst[5]++;}
480 else if(
id ==-211){
fst[6]++;}
481 else if(
id == 321){
fst[7]++;}
482 else if(
id ==-321){
fst[8]++;}
483 else if(
id ==2212){
fst[9]++;}
484 else if(
id ==-2212){
fst[10]++;}
485 else if(
id == 2112){
fst[11]++;}
486 else if(
id ==-2112){
fst[12]++;}
487 if( fabs(
id) == 11) {
nchr_e++;}
488 if( fabs(
id) == 13) {
nchr_mu++;}
489 if( fabs(
id) == 211) {
nchr_pi++;}
490 if( fabs(
id) == 321) {
nchr_k++;}
491 if( fabs(
id) == 2212) {
nchr_p++;}
494 if( m_NtupleFile==
true ){
495 m_Trk_index[AllTrk_index]=id;
496 m_px_trk[AllTrk_index]=pex;
497 m_py_trk[AllTrk_index]=pey;
498 m_pz_trk[AllTrk_index]=pez;
499 m_en_trk[AllTrk_index]=en ;
502 Trk_index[AllTrk_index]=0;
512 if(m_FDPparticle!=
""){
521 if(!(m_SB3File==
"" || m_SB3HT==
"") && parentFlag && first ){
522 SuperBody3decay_make(fdp_ppid, fdp_init );
525 loop_to_select_eventsA:
527 if(m_truthFile!=
"" && m_truthPart!=
""){
530 for(
int id=0;
id<ndaug;
id++){
533 truth<<son.
get(0)<<
" "<<son.
get(1)<<
" "<<son.
get(2)<<
" "<<son.
get(3)<<std::endl;
538 if(_mDIY && parentFlag && m_ampscalflag ) _amps_max=CalAmpsMax(part);
539 if(_mDIY && parentFlag) {
541 double amps=CalAmpsMDIY( part );
542 ratio=amps/_amps_max;
544 if(_mDIY && parentFlag && ratio<=rdm){
goto loop_to_select_eventsA;}
548 if(m_FDPparticle==
""){FDP_part=part;}
549 if(!(m_SB3File==
"" || m_SB3HT==
"") && parentFlag ){ accept=SuperBody3decay_judge( FDP_part); }
550 if(!(m_SB3File==
"" || m_SB3HT==
"") && parentFlag && !accept){
553 goto loop_to_select_eventsB;
554 }
else if(!(m_SB3File==
"" || m_SB3HT==
"") && parentFlag && accept){
555 countChannel(FDP_part);
558 if((m_Psi2openCharm || m_Psi4040OpenCharm) && parentFlag ){
559 if(getModel(part) ==
"OPENCHARM"){
560 std::cout<<
"OPENCHARM model need to set Psi2openCharm and Psi3SopenCharm to be false!"<<std::endl;
564 bool theDecay = opencharm.choseDecay();
568 goto loop_to_select_eventsB;
577 unsigned int modeTag, multiplicityTag;
578 modeTag = theTag.getModeTag();
579 if( getModel(part) ==
"OPENCHARM"||getModel(part) ==
"LUNDCHARM" && m_tagLundModel){
580 multiplicityTag = decayType(part);
584 multiplicityTag = theTag.getMultTag() + decayType(part);
588 if(eventHeader == 0) std::cout <<
"event header unavailable: " << std::endl;
589 if (eventHeader != 0) {
590 eventHeader->setFlag1(modeTag);
591 eventHeader->setFlag2(multiplicityTag);
596 if(!(m_DecayRec==
"")) mydecayrec=part->
writeTreeRec(m_DecayRec);
598 if(m_statDecays && parentFlag ) countChannel(part);
601 if ( log.level() <= MSG::DEBUG ) part->
printTree() ;
602 log << MSG::DEBUG <<
"Converting particles to HepMC" << endreq;
604 makeHepMC(part, hepMCevt, hepMCpart);
606 hepMCpart->set_status(999);
612 for(
int i=0;i<nds;i++){
615 std::cout<<
"vvpp "<<vp1.
get(0)<<
" "<<vp1.
get(1)<<
" "<<vp1.
get(2)<<
" "<<vp1.
get(3)<<std::endl;
619 if(m_ReadTruth.size())ReadTruth(part,m_ReadTruth);
624 for( itp=hepMCevt->particles_begin(); itp!=hepMCevt->particles_end(); ++itp )
626 if (!(*itp)->end_vertex() && ( (*itp)->status()==899 || (*itp)->status()==999 ))
627 (*itp)->set_status(1);
631 if(m_Ncharge ==
true ) {std::cout<<
"Multiplicity: TotoalCharge_e_mu_pi_K_p_gamma_gammaFSR: "
640 if(m_Ncharge ==
true ){std::cout<<
"FinalStates: "
653 <<
fst[12]<<std::endl;}
664 TotNumTrk = AllTrk_index;
668 return StatusCode::SUCCESS;
674StatusCode EvtDecay::callBesEvtGen( HepMC::GenEvent* hepMCevt )
676 MsgStream log(messageService(), name());
686 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
687 for (
int i=0;i<13;i++)
fst[i]=0;
688 HepMC::GenEvent::particle_const_iterator itp;
709 loop_to_select_eventsB:
721 HepMC::GenParticle* hepMCpart=
new GenParticle(HepLorentzVector(0,0,0,ppmass),pid,3);
723 bool parentFlag =
false;
726 if(m_polarization.size()>0) {
728 }
else if(m_eBeamPolarization>0){
740 if(m_FDPparticle!=
""){
749 if(!(m_SB3File==
"" || m_SB3HT==
"") && first ){ SuperBody3decay_make( fdp_ppid, fdp_init);}
752 loop_to_select_events:
753 m_Gen->
generateDecay(part);
if(m_numberEvent<=1){ std::cout<<
"after m_Gen->decay "<<std::endl; part->
printTree();}
756 if(_mDIY && m_ampscalflag ) _amps_max=CalAmpsMax(part);
759 for(
int myloop=0;myloop<100;myloop++){
761 double amps=CalAmpsMDIY( part);
762 ratio=amps/_amps_max;
764 if( !isNumber(amps) || !isNumber(_amps_max) || ratio<=0 ) {
768 }
else if( rdm<=ratio) {
774 if(m_truthFile!=
"" && m_truthPart!=
""){
777 for(
int id=0;
id<ndaug;
id++){
780 truth<<son.
get(0)<<
" "<<son.
get(1)<<
" "<<son.
get(2)<<
" "<<son.
get(3)<<std::endl;
786 if(m_FDPparticle==
""){FDP_part=part;}
787 if(!(m_SB3File==
"" || m_SB3HT==
"")){
788 accept=SuperBody3decay_judge( FDP_part);
790 if(!(m_SB3File==
"" || m_SB3HT==
"") && !accept) {
793 goto loop_to_select_eventsB;
794 }
else if(!(m_SB3File==
"" || m_SB3HT==
"") && parentFlag && accept){
795 countChannel(FDP_part);
800 if(m_statDecays && parentFlag) countChannel(part);
807 unsigned int modeTag, multiplicityTag;
808 modeTag = theTag.getModeTag();
809 if( getModel(part) ==
"OPENCHARM"|| getModel(part) ==
"LUNDCHARM" && m_tagLundModel ){
810 multiplicityTag = decayType(part);
814 multiplicityTag = theTag.getMultTag() + decayType(part);
816 if(eventHeader == 0) std::cout <<
"event header unavailable: " << std::endl;
817 if (eventHeader != 0) {
818 eventHeader->setFlag1(modeTag);
819 eventHeader->setFlag2(multiplicityTag);
821 if(m_NtupleFile)m_flag1 = modeTag;
825 if(!(m_DecayRec==
"")) {mydecayrec=part->
writeTreeRec(m_DecayRec);std::cout<<std::endl;};
828 if ( log.level() <= MSG::DEBUG ) part->
printTree() ;
829 log << MSG::DEBUG <<
"Converting particles to HepMC" << endreq;
831 makeHepMC(part, hepMCevt, hepMCpart);
833 if(part->
getNDaug()!=0) hepMCpart->set_status(999);
838 for( itp=hepMCevt->particles_begin(); itp!=hepMCevt->particles_end(); ++itp )
840 if (!(*itp)->end_vertex() && ( (*itp)->status()==899 || (*itp)->status()==999 ))
841 (*itp)->set_status(1);
843 HepMC::GenParticle* hepMCpart=*itp;
844 int stat = hepMCpart->status();
845 int id = hepMCpart->pdg_id();
846 if(
abs(
id)==411 ||
abs(
id)==413 ) { (*itp)->set_status(999);stat=999;}
848 if ( stat != 1 )
continue;
851 if(
id == 11 ) {
fst[1]++;}
852 else if(
id == -11) {
fst[2]++;}
853 else if(
id == 13 ) {
fst[3]++;}
854 else if(
id ==-13) {
fst[4]++;}
855 else if(
id==211) {
fst[5]++;}
856 else if(
id==-211) {
fst[6]++;}
857 else if(
id== 321) {
fst[7]++;}
858 else if(
id ==-321) {
fst[8]++;}
859 else if(
id ==2212) {
fst[9]++;}
860 else if(
id==-2212) {
fst[10]++;}
861 else if(
id == 2112){
fst[11]++;}
862 else if(
id==-2112) {
fst[12]++;}
863 if( fabs(
id) == 11) {
nchr_e++;}
864 if( fabs(
id) == 13) {
nchr_mu++;}
865 if( fabs(
id) == 211) {
nchr_pi++;}
866 if( fabs(
id) == 321) {
nchr_k++;}
867 if( fabs(
id) == 2212) {
nchr_p++;}
870 double en =(hepMCpart->momentum()).e();
871 double pex=(hepMCpart->momentum()).px();
872 double pey=(hepMCpart->momentum()).py();
873 double pez=(hepMCpart->momentum()).pz();
875 if( m_NtupleFile==
true &&
id!=0){
876 m_Trk_index[AllTrk_index]=id;
877 m_px_trk[AllTrk_index]=pex;
878 m_py_trk[AllTrk_index]=pey;
879 m_pz_trk[AllTrk_index]=pez;
880 m_en_trk[AllTrk_index]=en ;
892 itp=hepMCevt->particles_begin();
893 (*itp)->set_status(2);
897 if(m_Ncharge ==
true ) {std::cout<<
"Multiplicity: TotoalCharge_e_mu_pi_K_p_gamma_gammaFSR: "
906 if(m_Ncharge ==
true ){std::cout<<
"FinalStates: "
919 <<
fst[12]<<std::endl;}
931 TotNumTrk = AllTrk_index;
935 if(m_ReadTruth.size())ReadTruth(part,m_ReadTruth);
940 return StatusCode::SUCCESS;
955 std::cout<<
"Calculated helicity amplitude sqaured are:"<<std::endl;
956 std::cout<<
"|H_{2}|^2=|H_{-2}|^2= "<<H2/nd<<
" +/- "<<sqrt(H2err/nd)<<endl;
957 std::cout<<
"|H_{1}|^2=|H_{-1}|^2= "<<H1/nd<<
" +/- "<<sqrt(H1err/nd)<<endl;
960 MsgStream log(messageService(), name());
962 log << MSG::INFO <<
"EvtDecay finalized" << endreq;
964 Forfile.open(
"fort.16",ios::in);
966 strcpy(delcmd,
"rm -f ");
967 strcat(delcmd,
"fort.16");
971 Forfile2.open(
"fort.22",ios::in);
972 strcpy(delcmd,
"rm -f ");
973 strcat(delcmd,
"fort.22");
983 if(!(m_SB3File==
"" || m_SB3HT==
"")){
984 for(
int i=0;i<500;i++){totalEvt=totalEvt+br[i];}
985 for(
int i=0;i<500;i++){
986 double bi=1.0*br[i]/totalEvt;
987 std::cout<<
"Branching fraction of channel "<<i<<
" is: "<<bi<<std::endl;
994 for(
int i=0;i<=totalChannels;i++){totalEvt=totalEvt+br[i];}
995 std::cout<<
"==================Statistical first chain decay ==============================="<<std::endl;
996 std::cout<<
"i-th channel Events Generated Branching fraction generated "<<std::endl;
997 for(
int i=0;i<=totalChannels;i++){
998 std::cout<<
"| "<<i<<
" "<<br[i]<<
" "<<br[i]*1.0/totalEvt<<std::endl;
1001 std::cout<<
"--------------------------------------------------------------------------------"<<std::endl;
1002 std::cout<<
" sum: "<<totalEvt<<
" "<<
"1"<<std::endl;
1003 std::cout<<
"================== End of statistical first chain decay ========================"<<std::endl;
1006 return StatusCode::SUCCESS;
1010StatusCode EvtDecay::makeHepMC(
EvtParticle* part, HepMC::GenEvent* hEvt,
1011 HepMC::GenParticle* hPart)
1013 MsgStream log(messageService(), name());
1022 HepMC::GenVertex* end_vtx =
new HepMC::GenVertex(HepLorentzVector(x,y,z,ct));
1023 hEvt->add_vertex( end_vtx );
1024 end_vtx->add_particle_in(hPart);
1028 for(
int it=0;it<ndaug;it++)
1040 HepMC::GenParticle* prod_part =
new HepMC::GenParticle(HepLorentzVector(px,py,pz,e),
id,status);
1041 end_vtx->add_particle_out(prod_part);
1042 makeHepMC(part->
getDaug(it),hEvt,prod_part);
1046 if( log.level()<MSG::INFO )
1051 return StatusCode::SUCCESS;
1055void EvtDecay::MeVToGeV (HepMC::GenEvent* evt)
1057 for ( HepMC::GenEvent::particle_iterator p = evt->particles_begin(); p != evt->particles_end(); ++p ) {
1061 HepMC::FourVector tmpfv((*p)->momentum().x()/1000.,
1062 (*p)->momentum().y()/1000.,
1063 (*p)->momentum().z()/1000.,
1064 (*p)->momentum().t()/1000.
1067 (*p)->set_momentum( tmpfv );
1071void EvtDecay::GeVToMeV (HepMC::GenEvent* evt)
1073 for ( HepMC::GenEvent::particle_iterator p = evt->particles_begin(); p != evt->particles_end(); ++p ) {
1076 HepMC::FourVector tmpfv((*p)->momentum().x()*1000.,
1077 (*p)->momentum().y()*1000.,
1078 (*p)->momentum().z()*1000.,
1079 (*p)->momentum().t()*1000.
1082 (*p)->set_momentum( tmpfv );
1090 for(
int i=0;i<100000;i++){
1092 double amps=CalAmpsMDIY(part);
1093 if(amps > amps_max) amps_max=amps;
1095 amps_max=amps_max*1.05;
1096 m_ampscalflag =
false;
1105 m_engine->showStatus();
1113 return RandFlat::shoot(m_engine);
1118 double xmass2,ymass2;
1123 FinalState_make( ppid, p_init);
1126 for(
int i=0;i<100000;i++){
1129 HepMC::GenParticle* hepMCpart=
new GenParticle(HepLorentzVector(0,0,0,parentMass),parentPDGcode,3);
1137 FinalState_sort(part);
1144 xmass2=(pd1+pd2).mass2();
1145 ymass2=(pd1+pd3).mass2();
1146 double xlow=SuperBody3decay.
getXlow();
1147 double xup=SuperBody3decay.
getXup();
1148 double ylow=SuperBody3decay.
getYlow();
1149 double yup=SuperBody3decay.
getYup();
1150 if(xmass2<xlow || xmass2>xup || ymass2<ylow || ymass2>yup) { part->
deleteTree();
goto regen;}
1151 SuperBody3decay.
HFill(xmass2,ymass2);
1158 m_m12=(pd1+pd2).
mass();
1159 m_m23=(pd2+pd3).
mass();
1160 m_m13=(pd1+pd3).
mass();
1164 mass_tuple->write();
1166 double m1=pd1.
mass();
double m2=pd2.
mass();
double m3=pd3.
mass();
1167 double mj=(pd2+pd3).
mass();
1177bool EvtDecay::SuperBody3decay_judge(
EvtParticle* part){
1178 double xmass2,ymass2;
1183 FinalState_sort( part);
1190 xmass2=(pd1+pd2).mass2();
1191 ymass2=(pd1+pd3).mass2();
1192 accept=SuperBody3decay.
AR(xmass2,ymass2);
1195 if(accept && m_NtupleFile) {
1200 _m12=(pd1+pd2).
mass();
1201 _m23=(pd2+pd3).
mass();
1202 _m13=(pd1+pd3).
mass();
1206 massgen_tuple->write();
1217 identical_flag=
true;
1219 for(
int i=1;i<10000;i++){
1221 HepMC::GenParticle* hepMCpart=
new GenParticle(HepLorentzVector(0,0,0,parentMass),parentPDGcode,3);
1226 if(nson == 2) {
continue;}
else
1228 EvtId xid0,xid1,xid2;
1238 if(pdg0==pdg1 && pdg1==pdg2) {multi=3;}
1239 else if(pdg0==pdg1 ){multi=2;}
1240 else if(pdg0==pdg2 ){multi=2;pdg=pdg1; pdg1=pdg2; pdg2=pdg;}
1241 else if(pdg1==pdg2) {multi=2;pdg=pdg0; pdg0=pdg1; pdg1=pdg2; pdg2=pdg;}
1245 std::cout<<
"No direct three body decay channel found in decay card, I stop run"<<std::endl;
1256 EvtId xid0,xid1,xid2;
1286 assign_momentum(id0,pd0);
1287 assign_momentum(id1,pd1);
1288 assign_momentum(id2,pd2);
1289 }
else if(multi==2){
1290 assign_momentum2(id0,pd0);
1291 assign_momentum2(id1,pd1);
1292 assign_momentum2(id2,pd2);
1293 if(son0.
get(0)>son1.
get(0)){son=son0;son0=son1;son1=son;}
1294 }
else if(multi==3){
1295 double En0=pd0.
get(0);
1296 double En1=pd1.
get(0);
1297 double En2=pd2.
get(0);
1298 if(En0 < En1 && En1 < En2) {son0=pd0;son1=pd1;son2=pd2;}
1299 if(En0 < En2 && En2 < En1) {son0=pd0;son1=pd2;son2=pd1;}
1300 if(En1 < En0 && En0 < En2) {son0=pd1;son1=pd0;son2=pd2;}
1301 if(En1 < En2 && En2 < En0) {son0=pd1;son1=pd2;son2=pd0;}
1302 if(En2 < En0 && En0 < En1) {son0=pd2;son1=pd0;son2=pd1;}
1303 if(En2 < En1 && En1 < En0) {son0=pd2;son1=pd1;son2=pd0;}
1309void EvtDecay::assign_momentum(
int id0,
EvtVector4R pd0){
1310 if(id0==pdg0){son0=pd0;}
1311 else if(id0==pdg1){son1=pd0;}
1312 else if(id0==pdg2){son2=pd0;}
1313 else {std::cout<<
"PID= "<<id0<<
" not machted, I stop"<<std::endl; ::abort();}
1316void EvtDecay::assign_momentum2(
int id0,
EvtVector4R pd0){
1317 if(id0==pdg0 && identical_flag){son0=pd0;identical_flag=
false;}
1318 else if(id0==pdg1){son1=pd0;identical_flag=
true;}
1319 else if(id0==pdg2){son2=pd0;}
1320 else {std::cout<<
"PID not machted, I stop"<<std::endl; ::abort();}
1331 for(
int i=0;i<dn;i++){
1335 if(son_pdg == FDP_pdg){
1355 if(ich>totalChannels) totalChannels = ich;
1359bool EvtDecay::isCharmonium(
EvtId xid){
1375 std::vector<EvtId> Vid; Vid.clear();
1376 Vid.push_back(psi4415);
1377 Vid.push_back(psi4160);
1378 Vid.push_back(psi4040);
1379 Vid.push_back(psi3770);
1380 Vid.push_back(psiprim);
1381 Vid.push_back(jpsi);
1382 Vid.push_back(etac);
1383 Vid.push_back(etac2s);
1385 Vid.push_back(chic0);
1386 Vid.push_back(chic1);
1387 Vid.push_back(chic2);
1388 Vid.push_back(chic0p);
1389 Vid.push_back(chic1p);
1390 Vid.push_back(chic2p);
1393 for(
int i=0;i<Vid.size();i++){
if(xid == Vid[i])
return flag;}
1398bool EvtDecay::isCharm(
EvtId xid){
1416 std::vector<EvtId> Vid; Vid.clear();
1418 Vid.push_back(d0bar);
1423 Vid.push_back(dstp);
1424 Vid.push_back(dstm);
1426 Vid.push_back(ds0bar );
1427 Vid.push_back(dsp );
1428 Vid.push_back(dsm );
1429 Vid.push_back(dsstp );
1430 Vid.push_back(dsstm );
1431 Vid.push_back(ds0stp );
1432 Vid.push_back(ds0stm );
1435 for(
int i=0;i<Vid.size();i++){
if(xid == Vid[i])
return flag;}
1441 for(
int i=0;i<ndg;i++){
1460 std::string model = getModel(par,Nchannel);
1461 if( model ==
"OPENCHARM" || model ==
"LUNDCHARM" && m_tagLundModel){
1468 for(
int i=0;i<ndg;i++){
1473 if( isRadecay(par) ){
1474 for(
int i=0;i<ndg;i++){
1476 if( isCharmonium(xid) )
return 1;
1484 if( isCharm(xd1) && isCharm(xd2) ) {
return 2;}
else
1485 if( !isCharmonium(xd1) && !isCharmonium(xd2) && !isCharm(xd1) && !isCharm(xd2) ){
1490 for(
int i=0;i<ndg;i++){
1492 if( isCharmonium(xid) ) {
flag =
true;
break;}
1493 if( isCharm(xid) ) {
flag =
true;
break;}
1495 if( !
flag ){
return 3;}
else {
return 4;}
1502std::string EvtDecay::getModel(
EvtParticle *par,
int mode){
1514void EvtDecay::ReadTruth(
EvtParticle* part,std::vector<std::vector<string> > mylist){
1515 if(mylist.size()<2) {std::cout<<
" Empty list"<<std::endl;abort();}
1517 for(
int k=0;k<mylist[0].size();k++){
1520 for(
int i=1;i<mylist.size();i++){
1522 for(
int j=0;j<mylist[i].size();j++){
1529 if( !isNumber(vp1.
get(0)) ) {part->
printTree(); abort();}
1530 std::cout<<
"truth "<<vp1.
get(0)<<
" "<<vp1.
get(1)<<
" "<<vp1.
get(2)<<
" "<<vp1.
get(3)<<std::endl;
1536int EvtDecay::isNumber(
double d){
return (d==d);}
1538#include "../user/Lenu.inc"
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.