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);
133 declareProperty(
"PrintFSFor",m_printfs=
"");
139 MsgStream log(messageService(), name());
140 system(
"cat $BESEVTGENROOT/share/phokhara_9.1.fferr>phokhara_9.1.fferr");
141 system(
"cat $BESEVTGENROOT/share/phokhara_9.1.ffwarn>phokhara_9.1.ffwarn");
143 if(m_truthFile!=
""){truth.open(m_truthFile.c_str());}
144 log << MSG::INFO <<
"EvtDecay initialize" << endreq;
145 static const bool CREATEIFNOTTHERE(
true);
146 StatusCode RndmStatus = service(
"BesRndmGenSvc", p_BesRndmGenSvc, CREATEIFNOTTHERE);
147 if (!RndmStatus.isSuccess() || 0 == p_BesRndmGenSvc)
149 log << MSG::ERROR <<
" Could not initialize Random Number Service" << endreq;
154 for(
int i=0;i<m_mystring.size();i++){
EvtGlobalSet::SV.push_back(m_mystring[i]);}
158 std::vector<std::vector<int> >myivv;
159 std::vector<std::vector<double> >mydvv;
163 myivv.push_back(m_cluster0);
164 myivv.push_back(m_cluster1);
165 myivv.push_back(m_cluster2);
167 mydvv.push_back(m_wind0);
168 mydvv.push_back(m_wind1);
169 mydvv.push_back(m_wind2);
171 for(
int i=0;i<myivv.size();i++){
172 std::vector<int> theivv;
173 for(
int j=0;j<myivv[i].size();j++){
174 theivv.push_back(myivv[i][j]);
179 for(
int i=0;i<mydvv.size();i++){
180 std::vector<double> thedvv;
181 for(
int j=0;j<mydvv[i].size();j++){
182 thedvv.push_back(mydvv[i][j]);
188 if(m_eBeamPolarization>1) {std::cout<<
"The e-beam polaziation should be in 0 to 1"<<std::endl;abort();}
191 m_ampscalflag =
true;
193 CLHEP::HepRandomEngine* engine = p_BesRndmGenSvc->
GetEngine(
"EVTGEN");
194 const long s = engine->getSeed();
198 m_seeds.push_back(
s);
203 if ( m_DecayDec ==
"") {
204 m_DecayDec=getenv(
"BESEVTGENROOT");
205 m_DecayDec +=
"/share/DECAY.DEC";
208 if ( m_PdtTable ==
"") {
209 m_PdtTable =getenv(
"BESEVTGENROOT");
210 m_PdtTable +=
"/share/pdt.table";
214 std::cout<<
"===================== user decay card ========================"<<std::endl;
215 strcpy(catcmd,
"cat ");
216 strcat(catcmd, userDecFileName.c_str());
225 if (status.isSuccess()) {
226 log << MSG::INFO <<
"got the DataInfoSvc" << endreq;
230 log << MSG::ERROR <<
"could not get the DataInfoSvc" << endreq;
231 return StatusCode::FAILURE;
237 m_Gen =
new EvtGen( m_DecayDec.c_str(), m_PdtTable.c_str(), m_RandomEngine );
239 if(userDecFileName ==
"NONE") log << MSG::INFO <<
"EvtDecay User did not define his Decay table EvtGen will use standart" << endreq;
240 if(!(userDecFileName ==
"NONE")) m_Gen->
readUDecay(userDecFileName.c_str());
242 if(!(m_DecayTop==
" ")) {
243 outfile.open(m_DecayTop.c_str());
250 NTuplePtr nt1(
ntupleSvc(),
"MYROOTFILE/Trk");
251 if(nt1) {m_tuple=nt1;}
253 m_tuple =
ntupleSvc()->book (
"MYROOTFILE/Trk", CLID_ColumnWiseTuple,
"Generator-trk-Ntuple");
255 status = m_tuple->addItem (
"TotNumTrk", TotNumTrk, 0,100);
256 status = m_tuple->addIndexedItem (
"Trk_index", TotNumTrk, m_Trk_index);
257 status = m_tuple->addIndexedItem (
"m_px_trk", TotNumTrk, m_px_trk);
258 status = m_tuple->addIndexedItem (
"m_py_trk", TotNumTrk, m_py_trk);
259 status = m_tuple->addIndexedItem (
"m_pz_trk", TotNumTrk, m_pz_trk);
260 status = m_tuple->addIndexedItem (
"m_en_trk", TotNumTrk, m_en_trk);
261 status = m_tuple->addIndexedItem (
"FST", TotNumTrk, m_fst);
263 status = m_tuple->addItem (
"nchr", m_nchr);
264 status = m_tuple->addItem (
"nchr_e", m_nchr_e);
265 status = m_tuple->addItem (
"nchr_mu", m_nchr_mu);
266 status = m_tuple->addItem (
"nchr_pi", m_nchr_pi);
267 status = m_tuple->addItem (
"nchr_k", m_nchr_k);
268 status = m_tuple->addItem (
"nchr_p", m_nchr_p);
269 status = m_tuple->addItem (
"N_gamma", m_gamma);
270 status = m_tuple->addItem (
"N_gammaFSR", m_gammaFSR);
271 status = m_tuple->addItem (
"Flag1", m_flag1);
273 log << MSG::ERROR <<
" Cannot book N-tuple:"<< long(m_tuple) << endmsg;
274 return StatusCode::FAILURE;
278 NTuplePtr nt2(
ntupleSvc(),
"MYROOTFILE/mass");
279 if(nt2) {mass_tuple=nt2;}
281 mass_tuple =
ntupleSvc()->book (
"MYROOTFILE/mass", CLID_ColumnWiseTuple,
"Generator-mass-Ntuple");
283 status = mass_tuple->addItem (
"m12", m_m12);
284 status = mass_tuple->addItem (
"m13", m_m13);
285 status = mass_tuple->addItem (
"m23", m_m23);
286 status = mass_tuple->addItem (
"m1", m_m1);
287 status = mass_tuple->addItem (
"m2", m_m2);
288 status = mass_tuple->addItem (
"m3", m_m3);
289 status = mass_tuple->addItem (
"costheta1", m_cos1);
290 status = mass_tuple->addItem (
"costheta2", m_cos2);
291 status = mass_tuple->addItem (
"costheta3", m_cos3);
292 status = mass_tuple->addItem (
"ichannel", m_ich);
294 log << MSG::ERROR <<
" Cannot book N-tuple:"<< long(m_tuple) << endmsg;
295 return StatusCode::FAILURE;
299 NTuplePtr nt3(
ntupleSvc(),
"MYROOTFILE/massGen");
300 if(nt3) {massgen_tuple=nt3;}
302 massgen_tuple =
ntupleSvc()->book (
"MYROOTFILE/massGen", CLID_ColumnWiseTuple,
"Generator-mass-Ntuple");
304 status = massgen_tuple->addItem (
"m12", _m12);
305 status = massgen_tuple->addItem (
"m13", _m13);
306 status = massgen_tuple->addItem (
"m23", _m23);
307 status = massgen_tuple->addItem (
"m1", _m1);
308 status = massgen_tuple->addItem (
"m2", _m2);
309 status = massgen_tuple->addItem (
"m3", _m3);
310 status = massgen_tuple->addItem (
"costheta1", _cos1);
311 status = massgen_tuple->addItem (
"costheta2", _cos2);
312 status = massgen_tuple->addItem (
"costheta3", _cos3);
313 status = massgen_tuple->addItem (
"ichannel", _ich);
315 log << MSG::ERROR <<
" Cannot book N-tuple:"<< long(m_tuple) << endmsg;
316 return StatusCode::FAILURE;
322 for(
int i=0;i<500;i++){br[i]=0;}
323 if(!(m_SB3File==
"" && m_SB3HT==
"")) {
324 const char *filename, *histitle;
325 filename=(
char*)m_SB3File.c_str();
326 histitle=(
char*)m_SB3HT.c_str();
327 SuperBody3decay.
setFile(filename);
329 SuperBody3decay.
init();
332 return StatusCode::SUCCESS;
338 MsgStream log(messageService(), name());
341 string key =
"GEN_EVENT";
343 SmartDataPtr<McGenEventCol> McEvtColl(eventSvc(),
"/Event/Gen");
348 if ( McEvtColl == 0 )
350 HepMC::GenEvent* evt=
new GenEvent();
351 evt->set_event_number(m_numberEvent);
354 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
355 int runNo=eventHeader->runNumber();
356 int event=eventHeader->eventNumber();
358 if(
runNo != 0 &&
runNo != m_runNo){m_runNo=
runNo;newRunFlag =
true;}
else{newRunFlag=
false;}
359 if(m_RdMeasuredEcms&& newRunFlag){
364 std::cout<<
"Read Ecms= "<<dbEcms<<std::endl;
366 std::cout<<
"INFO: Read the MeasuredEcms"<<std::endl;
369 std::cout<<
"ERROR: Can not read the MeasuredEcms, try to turn off the ReadEcmsDB"<<std::endl;
370 return StatusCode::FAILURE;
376 callBesEvtGen( evt );
377 if(!(m_DecayTop==
"")) evt->print(outfile);
382 mcColl->push_back(mcEvent);
383 StatusCode sc = eventSvc()->registerObject(
"/Event/Gen",mcColl);
384 if(sc != SUCCESS)
return StatusCode::FAILURE;
388 McGenEventCol::iterator mcItr;
389 for( mcItr = McEvtColl->begin(); mcItr != McEvtColl->end(); mcItr++ )
391 HepMC::GenEvent* hEvt = (*mcItr)->getGenEvt();
396 if(!(m_DecayTop==
"")) hEvt->print(outfile);
399 if(!(m_DecayRec==
"")) std::cout<<std::endl;
402 if( m_NtupleFile ){ m_tuple->write();}
403 return StatusCode::SUCCESS;
411StatusCode EvtDecay::callEvtGen( HepMC::GenEvent* hepMCevt )
413 MsgStream log(messageService(), name());
422 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
424 for (
int i=0;i<13;i++)
fst[i]=0;
425 HepMC::GenEvent::particle_const_iterator itp;
427 for( itp=hepMCevt->particles_begin(); itp!=hepMCevt->particles_end(); ++itp )
449 HepMC::GenParticle* hepMCpart=*itp;
450 int stat = hepMCpart->status();
453 if ( stat != 1 )
continue;
455 loop_to_select_eventsB:
456 int id = hepMCpart->pdg_id();
458 hepMCpart->set_status(899);
462 double en =(hepMCpart->momentum()).e();
463 double pex=(hepMCpart->momentum()).px();
464 double pey=(hepMCpart->momentum()).py();
465 double pez=(hepMCpart->momentum()).pz();
468 parentMass=p_init.mass();
474 bool parentFlag=
false;
476 if(m_polarization.size()>0) {
478 }
else if(m_eBeamPolarization>0){
486 int id = hepMCpart->pdg_id();
489 if(
id == 11 ) {
fst[1]++;}
else if(
id == -11){
fst[2]++;}
490 else if(
id == 13){
fst[3]++;}
491 else if(
id == -13){
fst[4]++;}
492 else if(
id == 211){
fst[5]++;}
493 else if(
id ==-211){
fst[6]++;}
494 else if(
id == 321){
fst[7]++;}
495 else if(
id ==-321){
fst[8]++;}
496 else if(
id ==2212){
fst[9]++;}
497 else if(
id ==-2212){
fst[10]++;}
498 else if(
id == 2112){
fst[11]++;}
499 else if(
id ==-2112){
fst[12]++;}
500 if( fabs(
id) == 11) {
nchr_e++;}
501 if( fabs(
id) == 13) {
nchr_mu++;}
502 if( fabs(
id) == 211) {
nchr_pi++;}
503 if( fabs(
id) == 321) {
nchr_k++;}
504 if( fabs(
id) == 2212) {
nchr_p++;}
507 if( m_NtupleFile==
true ){
508 m_Trk_index[AllTrk_index]=id;
509 m_px_trk[AllTrk_index]=pex;
510 m_py_trk[AllTrk_index]=pey;
511 m_pz_trk[AllTrk_index]=pez;
512 m_en_trk[AllTrk_index]=en ;
515 Trk_index[AllTrk_index]=0;
525 if(m_FDPparticle!=
""){
534 if(!(m_SB3File==
"" || m_SB3HT==
"") && parentFlag && first ){
535 SuperBody3decay_make(fdp_ppid, fdp_init );
538 loop_to_select_eventsA:
540 if(m_truthFile!=
"" && m_truthPart!=
""){
543 for(
int id=0;
id<ndaug;
id++){
546 truth<<son.
get(0)<<
" "<<son.
get(1)<<
" "<<son.
get(2)<<
" "<<son.
get(3)<<std::endl;
551 if(_mDIY && parentFlag && m_ampscalflag ) _amps_max=CalAmpsMax(part);
552 if(_mDIY && parentFlag) {
554 double amps=CalAmpsMDIY( part );
555 ratio=amps/_amps_max;
557 if(_mDIY && parentFlag && ratio<=rdm){
goto loop_to_select_eventsA;}
561 if(m_FDPparticle==
""){FDP_part=part;}
562 if(!(m_SB3File==
"" || m_SB3HT==
"") && parentFlag ){ accept=SuperBody3decay_judge( FDP_part); }
563 if(!(m_SB3File==
"" || m_SB3HT==
"") && parentFlag && !accept){
566 goto loop_to_select_eventsB;
567 }
else if(!(m_SB3File==
"" || m_SB3HT==
"") && parentFlag && accept){
568 countChannel(FDP_part);
571 if((m_Psi2openCharm || m_Psi4040OpenCharm) && parentFlag ){
572 if(getModel(part) ==
"OPENCHARM"){
573 std::cout<<
"OPENCHARM model need to set Psi2openCharm and Psi3SopenCharm to be false!"<<std::endl;
577 bool theDecay = opencharm.choseDecay();
581 goto loop_to_select_eventsB;
590 unsigned int modeTag, multiplicityTag;
591 modeTag = theTag.getModeTag();
592 if( getModel(part) ==
"OPENCHARM"||getModel(part) ==
"LUNDCHARM" && m_tagLundModel){
593 multiplicityTag = decayType(part);
597 multiplicityTag = theTag.getMultTag() + decayType(part);
601 if(eventHeader == 0) std::cout <<
"event header unavailable: " << std::endl;
602 if (eventHeader != 0) {
603 eventHeader->setFlag1(modeTag);
604 eventHeader->setFlag2(multiplicityTag);
609 if(!(m_DecayRec==
"")) mydecayrec=part->
writeTreeRec(m_DecayRec);
611 if(m_statDecays && parentFlag ) countChannel(part);
614 if ( log.level() <= MSG::DEBUG ) part->
printTree() ;
615 log << MSG::DEBUG <<
"Converting particles to HepMC" << endreq;
617 makeHepMC(part, hepMCevt, hepMCpart);
619 hepMCpart->set_status(999);
625 for(
int i=0;i<nds;i++){
628 std::cout<<
"vvpp "<<vp1.
get(0)<<
" "<<vp1.
get(1)<<
" "<<vp1.
get(2)<<
" "<<vp1.
get(3)<<std::endl;
632 if(m_ReadTruth.size())ReadTruth(part,m_ReadTruth);
637 for( itp=hepMCevt->particles_begin(); itp!=hepMCevt->particles_end(); ++itp )
639 if (!(*itp)->end_vertex() && ( (*itp)->status()==899 || (*itp)->status()==999 ))
640 (*itp)->set_status(1);
644 if(m_Ncharge ==
true ) {std::cout<<
"Multiplicity: TotoalCharge_e_mu_pi_K_p_gamma_gammaFSR: "
653 if(m_Ncharge ==
true ){std::cout<<
"FinalStates: "
666 <<
fst[12]<<std::endl;}
677 TotNumTrk = AllTrk_index;
681 return StatusCode::SUCCESS;
687StatusCode EvtDecay::callBesEvtGen( HepMC::GenEvent* hepMCevt )
689 MsgStream log(messageService(), name());
699 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
700 for (
int i=0;i<13;i++)
fst[i]=0;
701 HepMC::GenEvent::particle_const_iterator itp;
722 loop_to_select_eventsB:
725 if(m_RdMeasuredEcms && m_beamEnergySpread==0) {
728 }
else if(m_RdMeasuredEcms && m_beamEnergySpread!=0){
729 double cmssig=sqrt(2.)*m_beamEnergySpread;
733 }
else if( (!m_RdMeasuredEcms) && m_beamEnergySpread!=0){
735 double cmssig=sqrt(2.)*m_beamEnergySpread;
739 }
else if((!m_RdMeasuredEcms) && m_beamEnergySpread==0 ){
741 }
else {std::cout<<
"EvtDecay::callBesEvtGen:: bad option"<<std::endl; abort();}
752 HepMC::GenParticle* hepMCpart=
new GenParticle(HepLorentzVector(0,0,0,ppmass),pid,3);
754 bool parentFlag =
false;
757 if(m_polarization.size()>0) {
759 }
else if(m_eBeamPolarization>0){
771 if(m_FDPparticle!=
""){
780 if(!(m_SB3File==
"" || m_SB3HT==
"") && first ){ SuperBody3decay_make( fdp_ppid, fdp_init);}
783 loop_to_select_events:
784 m_Gen->
generateDecay(part);
if(m_numberEvent<=1){ std::cout<<
"after m_Gen->decay "<<std::endl; part->
printTree();}
787 if(_mDIY && m_ampscalflag ) _amps_max=CalAmpsMax(part);
790 for(
int myloop=0;myloop<100;myloop++){
792 double amps=CalAmpsMDIY( part);
793 ratio=amps/_amps_max;
795 if( !isNumber(amps) || !isNumber(_amps_max) || ratio<=0 ) {
799 }
else if( rdm<=ratio) {
805 if(m_truthFile!=
"" && m_truthPart!=
""){
808 for(
int id=0;
id<ndaug;
id++){
811 truth<<son.
get(0)<<
" "<<son.
get(1)<<
" "<<son.
get(2)<<
" "<<son.
get(3)<<std::endl;
817 if(m_FDPparticle==
""){FDP_part=part;}
818 if(!(m_SB3File==
"" || m_SB3HT==
"")){
819 accept=SuperBody3decay_judge( FDP_part);
821 if(!(m_SB3File==
"" || m_SB3HT==
"") && !accept) {
824 goto loop_to_select_eventsB;
825 }
else if(!(m_SB3File==
"" || m_SB3HT==
"") && parentFlag && accept){
826 countChannel(FDP_part);
831 if(m_statDecays && parentFlag) countChannel(part);
838 unsigned int modeTag, multiplicityTag;
839 modeTag = theTag.getModeTag();
840 if( getModel(part) ==
"OPENCHARM"|| getModel(part) ==
"LUNDCHARM" && m_tagLundModel ){
841 multiplicityTag = decayType(part);
844 }
else if(_RvalueTag){
845 multiplicityTag = decayType(part);
847 multiplicityTag = theTag.getMultTag() + decayType(part);
849 if(eventHeader == 0) std::cout <<
"event header unavailable: " << std::endl;
850 if (eventHeader != 0) {
851 eventHeader->setFlag1(modeTag);
852 eventHeader->setFlag2(multiplicityTag);
856 if(m_NtupleFile)m_flag1 = modeTag;
860 if(!(m_DecayRec==
"")) {mydecayrec=part->
writeTreeRec(m_DecayRec);std::cout<<std::endl;};
863 if ( log.level() <= MSG::DEBUG ) part->
printTree() ;
864 log << MSG::DEBUG <<
"Converting particles to HepMC" << endreq;
866 makeHepMC(part, hepMCevt, hepMCpart);
868 if(part->
getNDaug()!=0) hepMCpart->set_status(999);
873 std::cout<<
"_FinalState "<<myd;
874 for(
int ii=0;ii<myd;ii++) {
877 std::cout<<std::endl;
881 for( itp=hepMCevt->particles_begin(); itp!=hepMCevt->particles_end(); ++itp )
883 if (!(*itp)->end_vertex() && ( (*itp)->status()==899 || (*itp)->status()==999 ))
884 (*itp)->set_status(1);
886 HepMC::GenParticle* hepMCpart=*itp;
887 int stat = hepMCpart->status();
888 int id = hepMCpart->pdg_id();
889 if(
abs(
id)==411 ||
abs(
id)==413 ) { (*itp)->set_status(999);stat=999;}
891 if ( stat != 1 )
continue;
894 if(
id == 11 ) {
fst[1]++;}
895 else if(
id == -11) {
fst[2]++;}
896 else if(
id == 13 ) {
fst[3]++;}
897 else if(
id ==-13) {
fst[4]++;}
898 else if(
id==211) {
fst[5]++;}
899 else if(
id==-211) {
fst[6]++;}
900 else if(
id== 321) {
fst[7]++;}
901 else if(
id ==-321) {
fst[8]++;}
902 else if(
id ==2212) {
fst[9]++;}
903 else if(
id==-2212) {
fst[10]++;}
904 else if(
id == 2112){
fst[11]++;}
905 else if(
id==-2112) {
fst[12]++;}
906 if( fabs(
id) == 11) {
nchr_e++;}
907 if( fabs(
id) == 13) {
nchr_mu++;}
908 if( fabs(
id) == 211) {
nchr_pi++;}
909 if( fabs(
id) == 321) {
nchr_k++;}
910 if( fabs(
id) == 2212) {
nchr_p++;}
913 double en =(hepMCpart->momentum()).e();
914 double pex=(hepMCpart->momentum()).px();
915 double pey=(hepMCpart->momentum()).py();
916 double pez=(hepMCpart->momentum()).pz();
918 if( m_NtupleFile==
true &&
id!=0){
919 m_Trk_index[AllTrk_index]=id;
920 m_px_trk[AllTrk_index]=pex;
921 m_py_trk[AllTrk_index]=pey;
922 m_pz_trk[AllTrk_index]=pez;
923 m_en_trk[AllTrk_index]=en ;
935 itp=hepMCevt->particles_begin();
936 (*itp)->set_status(2);
940 if(m_Ncharge ==
true ) {std::cout<<
"Multiplicity: TotoalCharge_e_mu_pi_K_p_gamma_gammaFSR: "
949 if(m_Ncharge ==
true ){std::cout<<
"FinalStates: "
962 <<
fst[12]<<std::endl;}
974 TotNumTrk = AllTrk_index;
978 if(m_ReadTruth.size())ReadTruth(part,m_ReadTruth);
984 return StatusCode::SUCCESS;
999 std::cout<<
"Calculated helicity amplitude sqaured are:"<<std::endl;
1000 std::cout<<
"|H_{2}|^2=|H_{-2}|^2= "<<H2/nd<<
" +/- "<<sqrt(H2err/nd)<<endl;
1001 std::cout<<
"|H_{1}|^2=|H_{-1}|^2= "<<H1/nd<<
" +/- "<<sqrt(H1err/nd)<<endl;
1004 MsgStream log(messageService(), name());
1006 log << MSG::INFO <<
"EvtDecay finalized" << endreq;
1008 Forfile.open(
"fort.16",ios::in);
1010 strcpy(delcmd,
"rm -f ");
1011 strcat(delcmd,
"fort.16");
1015 Forfile2.open(
"fort.22",ios::in);
1016 strcpy(delcmd,
"rm -f ");
1017 strcat(delcmd,
"fort.22");
1027 if(!(m_SB3File==
"" || m_SB3HT==
"")){
1028 for(
int i=0;i<500;i++){totalEvt=totalEvt+br[i];}
1029 for(
int i=0;i<500;i++){
1030 double bi=1.0*br[i]/totalEvt;
1031 std::cout<<
"Branching fraction of channel "<<i<<
" is: "<<bi<<std::endl;
1038 for(
int i=0;i<=totalChannels;i++){totalEvt=totalEvt+br[i];}
1039 std::cout<<
"==================Statistical first chain decay ==============================="<<std::endl;
1040 std::cout<<
"i-th channel Events Generated Branching fraction generated "<<std::endl;
1041 for(
int i=0;i<=totalChannels;i++){
1042 std::cout<<
"| "<<i<<
" "<<br[i]<<
" "<<br[i]*1.0/totalEvt<<std::endl;
1045 std::cout<<
"--------------------------------------------------------------------------------"<<std::endl;
1046 std::cout<<
" sum: "<<totalEvt<<
" "<<
"1"<<std::endl;
1047 std::cout<<
"================== End of statistical first chain decay ========================"<<std::endl;
1050 return StatusCode::SUCCESS;
1054StatusCode EvtDecay::makeHepMC(
EvtParticle* part, HepMC::GenEvent* hEvt,
1055 HepMC::GenParticle* hPart)
1057 MsgStream log(messageService(), name());
1066 HepMC::GenVertex* end_vtx =
new HepMC::GenVertex(HepLorentzVector(x,y,z,ct));
1067 hEvt->add_vertex( end_vtx );
1068 end_vtx->add_particle_in(hPart);
1072 for(
int it=0;it<ndaug;it++)
1084 HepMC::GenParticle* prod_part =
new HepMC::GenParticle(HepLorentzVector(px,py,pz,e),
id,status);
1085 end_vtx->add_particle_out(prod_part);
1086 makeHepMC(part->
getDaug(it),hEvt,prod_part);
1090 if( log.level()<MSG::INFO )
1095 return StatusCode::SUCCESS;
1099void EvtDecay::MeVToGeV (HepMC::GenEvent* evt)
1101 for ( HepMC::GenEvent::particle_iterator p = evt->particles_begin(); p != evt->particles_end(); ++p ) {
1105 HepMC::FourVector tmpfv((*p)->momentum().x()/1000.,
1106 (*p)->momentum().y()/1000.,
1107 (*p)->momentum().z()/1000.,
1108 (*p)->momentum().t()/1000.
1111 (*p)->set_momentum( tmpfv );
1115void EvtDecay::GeVToMeV (HepMC::GenEvent* evt)
1117 for ( HepMC::GenEvent::particle_iterator p = evt->particles_begin(); p != evt->particles_end(); ++p ) {
1120 HepMC::FourVector tmpfv((*p)->momentum().x()*1000.,
1121 (*p)->momentum().y()*1000.,
1122 (*p)->momentum().z()*1000.,
1123 (*p)->momentum().t()*1000.
1126 (*p)->set_momentum( tmpfv );
1134 for(
int i=0;i<100000;i++){
1136 double amps=CalAmpsMDIY(part);
1137 if(amps > amps_max) amps_max=amps;
1139 amps_max=amps_max*1.05;
1140 m_ampscalflag =
false;
1149 m_engine->showStatus();
1158 double rdm= RandFlat::shoot(m_engine);
1166 double xmass2,ymass2;
1171 FinalState_make( ppid, p_init);
1174 for(
int i=0;i<100000;i++){
1177 HepMC::GenParticle* hepMCpart=
new GenParticle(HepLorentzVector(0,0,0,parentMass),parentPDGcode,3);
1185 FinalState_sort(part);
1192 xmass2=(pd1+pd2).mass2();
1193 ymass2=(pd1+pd3).mass2();
1196 double ylow=SuperBody3decay.
getYlow();
1197 double yup=SuperBody3decay.
getYup();
1198 if(xmass2<xlow || xmass2>
xup || ymass2<ylow || ymass2>yup) { part->
deleteTree();
goto regen;}
1199 SuperBody3decay.
HFill(xmass2,ymass2);
1206 m_m12=(pd1+pd2).
mass();
1207 m_m23=(pd2+pd3).
mass();
1208 m_m13=(pd1+pd3).
mass();
1212 mass_tuple->write();
1214 double m1=pd1.
mass();
double m2=pd2.
mass();
double m3=pd3.
mass();
1215 double mj=(pd2+pd3).
mass();
1225bool EvtDecay::SuperBody3decay_judge(
EvtParticle* part){
1226 double xmass2,ymass2;
1231 FinalState_sort( part);
1238 xmass2=(pd1+pd2).mass2();
1239 ymass2=(pd1+pd3).mass2();
1240 accept=SuperBody3decay.
AR(xmass2,ymass2);
1243 if(accept && m_NtupleFile) {
1248 _m12=(pd1+pd2).
mass();
1249 _m23=(pd2+pd3).
mass();
1250 _m13=(pd1+pd3).
mass();
1254 massgen_tuple->write();
1265 identical_flag=
true;
1267 for(
int i=1;i<10000;i++){
1269 HepMC::GenParticle* hepMCpart=
new GenParticle(HepLorentzVector(0,0,0,parentMass),parentPDGcode,3);
1274 if(nson == 2) {
continue;}
else
1276 EvtId xid0,xid1,xid2;
1286 if(pdg0==pdg1 && pdg1==pdg2) {multi=3;}
1287 else if(pdg0==pdg1 ){multi=2;}
1288 else if(pdg0==pdg2 ){multi=2;pdg=pdg1; pdg1=pdg2; pdg2=pdg;}
1289 else if(pdg1==pdg2) {multi=2;pdg=pdg0; pdg0=pdg1; pdg1=pdg2; pdg2=pdg;}
1293 std::cout<<
"No direct three body decay channel found in decay card, I stop run"<<std::endl;
1304 EvtId xid0,xid1,xid2;
1334 assign_momentum(id0,
pd0);
1335 assign_momentum(id1,pd1);
1336 assign_momentum(id2,pd2);
1337 }
else if(multi==2){
1338 assign_momentum2(id0,
pd0);
1339 assign_momentum2(id1,pd1);
1340 assign_momentum2(id2,pd2);
1341 if(son0.
get(0)>son1.
get(0)){son=son0;son0=son1;son1=son;}
1342 }
else if(multi==3){
1343 double En0=
pd0.get(0);
1344 double En1=pd1.
get(0);
1345 double En2=pd2.
get(0);
1346 if(En0 < En1 && En1 < En2) {son0=
pd0;son1=pd1;son2=pd2;}
1347 if(En0 < En2 && En2 < En1) {son0=
pd0;son1=pd2;son2=pd1;}
1348 if(En1 < En0 && En0 < En2) {son0=pd1;son1=
pd0;son2=pd2;}
1349 if(En1 < En2 && En2 < En0) {son0=pd1;son1=pd2;son2=
pd0;}
1350 if(En2 < En0 && En0 < En1) {son0=pd2;son1=
pd0;son2=pd1;}
1351 if(En2 < En1 && En1 < En0) {son0=pd2;son1=pd1;son2=
pd0;}
1358 if(id0==pdg0){son0=
pd0;}
1359 else if(id0==pdg1){son1=
pd0;}
1360 else if(id0==pdg2){son2=
pd0;}
1361 else {std::cout<<
"PID= "<<id0<<
" not machted, I stop"<<std::endl; ::abort();}
1365 if(id0==pdg0 && identical_flag){son0=
pd0;identical_flag=
false;}
1366 else if(id0==pdg1){son1=
pd0;identical_flag=
true;}
1367 else if(id0==pdg2){son2=
pd0;}
1368 else {std::cout<<
"PID not machted, I stop"<<std::endl; ::abort();}
1379 for(
int i=0;i<dn;i++){
1383 if(son_pdg == FDP_pdg){
1403 if(ich>totalChannels) totalChannels = ich;
1407bool EvtDecay::isCharmonium(
EvtId xid){
1423 std::vector<EvtId> Vid; Vid.clear();
1424 Vid.push_back(psi4415);
1425 Vid.push_back(psi4160);
1426 Vid.push_back(psi4040);
1427 Vid.push_back(psi3770);
1428 Vid.push_back(psiprim);
1429 Vid.push_back(jpsi);
1430 Vid.push_back(etac);
1431 Vid.push_back(etac2s);
1433 Vid.push_back(chic0);
1434 Vid.push_back(chic1);
1435 Vid.push_back(chic2);
1436 Vid.push_back(chic0p);
1437 Vid.push_back(chic1p);
1438 Vid.push_back(chic2p);
1441 for(
int i=0;i<Vid.size();i++){
if(xid == Vid[i])
return flag;}
1446bool EvtDecay::isCharm(
EvtId xid){
1464 std::vector<EvtId> Vid; Vid.clear();
1466 Vid.push_back(d0bar);
1471 Vid.push_back(dstp);
1472 Vid.push_back(dstm);
1474 Vid.push_back(ds0bar );
1475 Vid.push_back(dsp );
1476 Vid.push_back(dsm );
1477 Vid.push_back(dsstp );
1478 Vid.push_back(dsstm );
1479 Vid.push_back(ds0stp );
1480 Vid.push_back(ds0stm );
1483 for(
int i=0;i<Vid.size();i++){
if(xid == Vid[i])
return flag;}
1489 for(
int i=0;i<ndg;i++){
1508 if(_RvalueTag){
return Nchannel;}
1511 std::string model = getModel(par,Nchannel);
1512 if( model ==
"OPENCHARM" || model ==
"LUNDCHARM" && m_tagLundModel){
1519 for(
int i=0;i<ndg;i++){
1524 if( isRadecay(par) ){
1525 for(
int i=0;i<ndg;i++){
1527 if( isCharmonium(xid) )
return 1;
1535 if( isCharm(xd1) && isCharm(xd2) ) {
return 2;}
else
1536 if( !isCharmonium(xd1) && !isCharmonium(xd2) && !isCharm(xd1) && !isCharm(xd2) ){
1541 for(
int i=0;i<ndg;i++){
1543 if( isCharmonium(xid) ) {
flag =
true;
break;}
1544 if( isCharm(xid) ) {
flag =
true;
break;}
1546 if( !
flag ){
return 3;}
else {
return 4;}
1553std::string EvtDecay::getModel(
EvtParticle *par,
int mode){
1565void EvtDecay::ReadTruth(
EvtParticle* part,std::vector<std::vector<string> > mylist){
1566 if(mylist.size()<2) {std::cout<<
" Empty list"<<std::endl;abort();}
1568 for(
int k=0;k<mylist[0].size();k++){
1572 for(
int i=1;i<mylist.size();i++){
1574 for(
int j=0;j<mylist[i].size();j++){
1581 if( !isNumber(vp1.
get(0)) ) {part->
printTree(); abort();}
1582 std::cout<<
"truth "<<vp1.
get(0)<<
" "<<vp1.
get(1)<<
" "<<vp1.
get(2)<<
" "<<vp1.
get(3)<<std::endl;
1588int EvtDecay::isNumber(
double d){
return (d==d);}
1597 for(
int i=0;i<
n;i++){
1601 double eta=sqrt(
n*12.0)*(ri/12-0.5);
1602 double xsig= sigma*eta+mu;
1605 if(xsig<mx0 || xsig>mx1)
goto rloop;
1609#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