CGEM BOSS 6.6.5.i
BESIII Offline Software System
Loading...
Searching...
No Matches
EvtDecay.cxx
Go to the documentation of this file.
1//*****************************************************************************
2//
3// EvtDecay.cxx
4//
5// EvtDecay algorithm takes generated event from transient store, and decay
6// particles, including weak decays of its secondary particles.
7// EvtDecay can be used as a TopAlg in conjunction with algorithms Pythia,
8// KKMC or a SingleParticleGun.
9//
10// History:
11// Original LHCb code by Witold Pokorski and Patric Robbe.
12// August 2002: Malte Muller, adopted for ATHENA to work inside algorithm PythiaBModule (only private version within 3.0.0)
13// Sept 2003: James Catmore, adopted for 6.0.3 (not reeased in 6.0.3 ony private version) to work inside PythiaBModule.
14// Nov 2003: M.Smizanska, rewritten a) to be standalone EvtDecay algorithm so it can be combined
15// with any type of Pythia generator b) to match to new LHCb(CDF) code dedicated to LHC, c) to work in 7.3.0.
16// EvtDecay first time released in 7.3.0 20.Nov. 2003
17// Dec 2003: M.Smizanska: define user's input - decay table
18// Feb 2004 J Catmore, addition of random seed facility. TEMPORARY FIX
19// Oct 2005 A. Zhemchugov, adapted for BES3
20// May 2006 K.L He, set spin density matrix for e+e- -> V
21// Sept.2007, R.G.Ping, change to the BesEvtGen
22// Jan. 2008, R.G.Ping, to print McTruth table to the file DecayTopology when only doing generation, not simulation
23// Feb. 2008, R.G.Ping, add an option to only run the BesEvtGen
24// Mar. 2008, R.G. Ping, user options "DecayDecDir" and "PdtTableDir" are changed.
25// Mar. 2008-03, R.G. Ping, dump the user decay card to the bosslog file
26//*****************************************************************************
27
28// Header for this module:-
29#include "EvtDecay.h"
34#include "EvtGen.hh"
39
40// Framework Related Headers:-
41#include "HepMC/GenEvent.h"
42#include "HepMC/GenVertex.h"
43#include "HepMC/GenParticle.h"
45#include "GaudiKernel/SmartDataPtr.h"
48#include "GaudiKernel/MsgStream.h"
49#include "GaudiKernel/ISvcLocator.h"
50#include "GaudiKernel/AlgFactory.h"
51#include "GaudiKernel/DataSvc.h"
52#include "GaudiKernel/SmartDataPtr.h"
53#include "GaudiKernel/IPartPropSvc.h"
54
57#include "CLHEP/Random/Ranlux64Engine.h"
58#include "CLHEP/Random/RandFlat.h"
59
60#include <stdlib.h>
61#include <string.h>
62
63static string mydecayrec;
64static double _amps_max;
65int nchr = 0;
66int nchr_e = 0;
67int nchr_mu= 0;
68int nchr_pi= 0;
69int nchr_k = 0;
70int nchr_p = 0;
71int N_gamma=0;
72int N_gammaFSR = 0;
73int fst[50];
74
75EvtDecay::EvtDecay(const string& name, ISvcLocator* pSvcLocator):Algorithm( name, pSvcLocator )
76{
77
78
79
80 // these can be used to specify alternative locations or filenames
81 // for the EvtGen particle and channel definition files.
82
83 declareProperty("DecayDecDir", m_DecayDec = "");
84 declareProperty("PdtTableDir", m_PdtTable = "");
85 declareProperty("userDecayTableName", userDecFileName = "NONE");
86 declareProperty("DecayTopology", m_DecayTop = ""); // output decay topology to a file specified by user
87 declareProperty("DecayRecord", m_DecayRec = ""); // output decay topology of one particle specified by user to a file
88 declareProperty("ParentParticle", m_ParentPart = "NONE");// Mothor particle name in pdt.table for only running BesEvtGen
89 declareProperty("Multiplicity", m_Ncharge = false); // output ncharge number of an event
90 declareProperty("NutupleFile",m_NtupleFile = false); // output Ntuple file
91 declareProperty("mDIY",_mDIY= false); // mDIY model
92 declareProperty("FDPdata",m_SB3File = ""); // Fit Dalitz Plot (FDP) data file name (*.root)
93 declareProperty("FDPHisT",m_SB3HT = ""); // histogram title of Dalitz plot in data file
94 declareProperty("FDPpart",m_FDPparticle =""); //to assign the FDP parent particle name (string)
95 declareProperty("TruthFile",m_truthFile ="");
96 declareProperty("TruthPart",m_truthPart ="");
97 declareProperty("Psi3SopenCharm",m_Psi4040OpenCharm=false);
98 declareProperty("Psi2openCharm", m_Psi2openCharm=false);
99 declareProperty("statDecays",m_statDecays=false);
100 declareProperty("TagLundCharmModel", m_tagLundModel=false);
101 //for polarized charmonium production
102 m_polarization.clear();
103 declareProperty("polarization", m_polarization);
104}
105
106
108
109 MsgStream log(messageService(), name());
110 if(m_truthFile!=""){truth.open(m_truthFile.c_str());}
111 log << MSG::INFO << "EvtDecay initialize" << endreq;
112 static const bool CREATEIFNOTTHERE(true);
113 StatusCode RndmStatus = service("BesRndmGenSvc", p_BesRndmGenSvc, CREATEIFNOTTHERE);
114 if (!RndmStatus.isSuccess() || 0 == p_BesRndmGenSvc)
115 {
116 log << MSG::ERROR << " Could not initialize Random Number Service" << endreq;
117 return RndmStatus;
118 }
119
120 m_numberEvent=0;
121 first = true;
122 m_ampscalflag = true;
123 // Save the random number seeds in the event
124 CLHEP::HepRandomEngine* engine = p_BesRndmGenSvc->GetEngine("EVTGEN");
125 const long s = engine->getSeed();
126 p_BesRndmGenSvc->setGenseed(s+1);
127
128 m_seeds.clear();
129 m_seeds.push_back(s);
130 totalChannels = 0;
131
132 // open an interface to EvtGen
133
134 if ( m_DecayDec == "") { //use default DECAY.DEC and pdt.table if not defined by user
135 m_DecayDec=getenv("BESEVTGENROOT");
136 m_DecayDec +="/share/DECAY.DEC";
137 }
138
139 if ( m_PdtTable == "") {
140 m_PdtTable =getenv("BESEVTGENROOT");
141 m_PdtTable +="/share/pdt.table";
142 }
143
144 char catcmd[300]; //output user decay cards to log file
145 std::cout<<"===================== user decay card ========================"<<std::endl;
146 strcpy(catcmd, "cat ");
147 strcat(catcmd, userDecFileName.c_str());
148 system(catcmd);
149
152
153 // write decay cards to the root file: pingrg@2009-09-09
154 StatusCode status;
155 status = service("DataInfoSvc",tmpInfoSvc);
156 if (status.isSuccess()) {
157 log << MSG::INFO << "got the DataInfoSvc" << endreq;
158 dataInfoSvc=dynamic_cast<DataInfoSvc *>(tmpInfoSvc);
159 dataInfoSvc->setDecayCard(userDecFileName);
160 } else {
161 log << MSG::ERROR << "could not get the DataInfoSvc" << endreq;
162 return StatusCode::FAILURE;
163 }
164
165
166
167 m_RandomEngine = new EvtBesRandom(engine);
168 m_Gen = new EvtGen( m_DecayDec.c_str(), m_PdtTable.c_str(), m_RandomEngine );
169
170 if(userDecFileName =="NONE") log << MSG::INFO << "EvtDecay User did not define his Decay table EvtGen will use standart" << endreq;
171 if(!(userDecFileName =="NONE")) m_Gen->readUDecay(userDecFileName.c_str());
172
173 if(!(m_DecayTop==" ")) {
174 outfile.open(m_DecayTop.c_str());
175 }
176
177 //for output Ntuple file, pingrg-2009-09-07
178
179
180 if(m_NtupleFile) {
181 NTuplePtr nt1(ntupleSvc(),"MYROOTFILE/Trk");
182 if(nt1) {m_tuple=nt1;}
183 else {
184 m_tuple = ntupleSvc()->book ("MYROOTFILE/Trk", CLID_ColumnWiseTuple, "Generator-trk-Ntuple");
185 if(m_tuple){
186 status = m_tuple->addItem ("TotNumTrk", TotNumTrk, 0,1000);
187 status = m_tuple->addIndexedItem ("Trk_index", TotNumTrk, m_Trk_index);
188 status = m_tuple->addIndexedItem ("m_px_trk", TotNumTrk, m_px_trk);
189 status = m_tuple->addIndexedItem ("m_py_trk", TotNumTrk, m_py_trk);
190 status = m_tuple->addIndexedItem ("m_pz_trk", TotNumTrk, m_pz_trk);
191 status = m_tuple->addIndexedItem ("m_en_trk", TotNumTrk, m_en_trk);
192 status = m_tuple->addIndexedItem ("FST", TotNumTrk, m_fst);
193
194 status = m_tuple->addItem ("nchr", m_nchr);
195 status = m_tuple->addItem ("nchr_e", m_nchr_e);
196 status = m_tuple->addItem ("nchr_mu", m_nchr_mu);
197 status = m_tuple->addItem ("nchr_pi", m_nchr_pi);
198 status = m_tuple->addItem ("nchr_k", m_nchr_k);
199 status = m_tuple->addItem ("nchr_p", m_nchr_p);
200 status = m_tuple->addItem ("N_gamma", m_gamma);
201 status = m_tuple->addItem ("N_gammaFSR", m_gammaFSR);
202 } else {
203 log << MSG::ERROR << " Cannot book N-tuple:"<< long(m_tuple) << endmsg;
204 return StatusCode::FAILURE;
205 }
206 }
207
208 NTuplePtr nt2(ntupleSvc(),"MYROOTFILE/mass");
209 if(nt2) {mass_tuple=nt2;}
210 else {
211 mass_tuple = ntupleSvc()->book ("MYROOTFILE/mass", CLID_ColumnWiseTuple, "Generator-mass-Ntuple");
212 if(mass_tuple){
213 status = mass_tuple->addItem ("m12", m_m12);
214 status = mass_tuple->addItem ("m13", m_m13);
215 status = mass_tuple->addItem ("m23", m_m23);
216 status = mass_tuple->addItem ("m1", m_m1);
217 status = mass_tuple->addItem ("m2", m_m2);
218 status = mass_tuple->addItem ("m3", m_m3);
219 status = mass_tuple->addItem ("costheta1", m_cos1);
220 status = mass_tuple->addItem ("costheta2", m_cos2);
221 status = mass_tuple->addItem ("costheta3", m_cos3);
222 status = mass_tuple->addItem ("ichannel", m_ich);
223 } else {
224 log << MSG::ERROR << " Cannot book N-tuple:"<< long(m_tuple) << endmsg;
225 return StatusCode::FAILURE;
226 }
227 }
228
229 NTuplePtr nt3(ntupleSvc(),"MYROOTFILE/massGen");
230 if(nt3) {massgen_tuple=nt3;}
231 else {
232 massgen_tuple = ntupleSvc()->book ("MYROOTFILE/massGen", CLID_ColumnWiseTuple, "Generator-mass-Ntuple");
233 if(massgen_tuple){
234 status = massgen_tuple->addItem ("m12", _m12);
235 status = massgen_tuple->addItem ("m13", _m13);
236 status = massgen_tuple->addItem ("m23", _m23);
237 status = massgen_tuple->addItem ("m1", _m1);
238 status = massgen_tuple->addItem ("m2", _m2);
239 status = massgen_tuple->addItem ("m3", _m3);
240 status = massgen_tuple->addItem ("costheta1", _cos1);
241 status = massgen_tuple->addItem ("costheta2", _cos2);
242 status = massgen_tuple->addItem ("costheta3", _cos3);
243 status = massgen_tuple->addItem ("ichannel", _ich);
244 } else {
245 log << MSG::ERROR << " Cannot book N-tuple:"<< long(m_tuple) << endmsg;
246 return StatusCode::FAILURE;
247 }
248 }
249
250
251 }
252 for(int i=0;i<500;i++){br[i]=0;}
253 if(!(m_SB3File=="" && m_SB3HT=="")) {
254 const char *filename, *histitle;
255 filename=(char*)m_SB3File.c_str();
256 histitle=(char*)m_SB3HT.c_str();
257 SuperBody3decay.setFile(filename);
258 SuperBody3decay.setHTitle(histitle);
259 SuperBody3decay.init();
260 }
261
262 return StatusCode::SUCCESS;
263}
264
265StatusCode EvtDecay::execute()
266{
267
268 MsgStream log(messageService(), name());
269 // log << MSG::INFO << "EvtDecay executing" << endreq;
270 //------------------
271 string key = "GEN_EVENT";
272 // retrieve event from Transient Store (Storegate)
273 SmartDataPtr<McGenEventCol> McEvtColl(eventSvc(), "/Event/Gen");
274
275 m_numberEvent += 1;
276 writeFlag = 0;
277 //std::cout<<"EvtNumber= "<<m_numberEvent<<std::endl;
278 if ( McEvtColl == 0 )
279 {
280 HepMC::GenEvent* evt=new GenEvent();
281 evt->set_event_number(m_numberEvent);
282 callBesEvtGen( evt );
283 if(!(m_DecayTop=="")) evt->print(outfile);
284
285 //create a Transient store
286 McGenEventCol *mcColl = new McGenEventCol;
287 McGenEvent* mcEvent = new McGenEvent(evt);
288 mcColl->push_back(mcEvent);
289 StatusCode sc = eventSvc()->registerObject("/Event/Gen",mcColl);
290 if(sc != SUCCESS) return StatusCode::FAILURE;
291
292 } else // (McEvtColl != 0)
293 {
294 McGenEventCol::iterator mcItr;
295 for( mcItr = McEvtColl->begin(); mcItr != McEvtColl->end(); mcItr++ )
296 {
297 HepMC::GenEvent* hEvt = (*mcItr)->getGenEvt();
298 // MeVToGeV( hEvt );
299
300 callEvtGen( hEvt );
301
302 if(!(m_DecayTop=="")) hEvt->print(outfile);
303 // GeVToMeV( hEvt );
304 // if(!(m_DecayRec=="")) outfile2<<std::endl;
305 if(!(m_DecayRec=="")) std::cout<<std::endl;
306 };
307 }
308 if( m_NtupleFile ){ m_tuple->write();}
309 return StatusCode::SUCCESS;
310}
311
312// main procedure, loops over all particles in given event,
313// converts them to EvtGenParticles,
314// feeds them to EvtGen,
315// converts back to HepMC particles and puts them in the event.
316
317StatusCode EvtDecay::callEvtGen( HepMC::GenEvent* hepMCevt )
318{
319 MsgStream log(messageService(), name());
320 nchr = 0;
321 nchr_e = 0;
322 nchr_mu= 0;
323 nchr_pi= 0;
324 nchr_k = 0;
325 nchr_p = 0;
326 N_gamma=0;
327 N_gammaFSR = 0;
328 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
329
330 for (int i=0;i<13;i++) fst[i]=0;
331 HepMC::GenEvent::particle_const_iterator itp;
332 AllTrk_index=0;
333 for( itp=hepMCevt->particles_begin(); itp!=hepMCevt->particles_end(); ++itp )
334 {
335 // This is the main loop.
336 // We iterate over particles and we look for ones that
337 // should be decayed with EvtGen.
338 //
339 // status == 1 - undecayed Pythia particle (also for particles that are not supposed to decay)
340 // status == 999 - particle already decayed by EvtGen
341 // status == 899 - particle was supposed to decay by EvtGen - but found no model
342 // this may be also intentional - such events are then excluded from
343 // being written into persistent output.
344 // ISTHEP(IHEP):
345 // status code for entry IHEP, with the following meanings:
346 //
347 // = 0 : null entry.
348 // = 1 : an existing entry, which has not decayed or fragmented. This is the main class of entries, which represents the `final state' given by the generator.
349 // = 2 : an entry which has decayed or fragmented and is therefore not appearing in the final state, but is retained for event history information.
350 // = 3 : a documentation line, defined separately from the event history. This could include the two incoming reacting particles, etc.
351 // = 4 - 10 : undefined, but reserved for future standards.
352 // = 11 - 200 : at the disposal of each model builder for constructs specific to his program, but equivalent to a null line in the context of any other program.
353 // = 201 - : at the disposal of users, in particular for event tracking in the detector.
354
355 HepMC::GenParticle* hepMCpart=*itp;
356 int stat = hepMCpart->status();
357
358
359 if ( stat != 1 ) continue;
360
361 loop_to_select_eventsB:
362 int id = hepMCpart->pdg_id();
363 parentPDGcode=id;
364 hepMCpart->set_status(899);
366 string parentName=EvtPDL::name(eid);
367
368 double en =(hepMCpart->momentum()).e();
369 double pex=(hepMCpart->momentum()).px();
370 double pey=(hepMCpart->momentum()).py();
371 double pez=(hepMCpart->momentum()).pz();
372
373 EvtVector4R p_init(en,pex,pey,pez);
374 parentMass=p_init.mass();
375
377
378 // set spin density matrix for e+ e- -> V
379 bool parentFlag=false;
380 if( writeFlag==0 && part->getSpinType() == EvtSpinType::VECTOR) {
381 if(m_polarization.size()>0) {part->setPolarizedSpinDensity(m_polarization[0],m_polarization[1],m_polarization[2]);} else
382 part->setVectorSpinDensity();
383 parentFlag=true;
384 writeFlag++;
385 } else {
386 int id = hepMCpart->pdg_id();
387 if( id == 22 ) {N_gamma ++;fst[0]++;} //fst[0]:photon
388 if( id == -22 ){N_gammaFSR ++;}
389 if( id == 11 ) {fst[1]++;} else if(id == -11){fst[2]++;} // fst[1]: electron ; fst[]: positron
390 else if(id == 13){fst[3]++;} // fst[3]: mu-
391 else if(id == -13){fst[4]++;} // fst[4]: mu+
392 else if(id == 211){fst[5]++;} // fst[5]: pi+
393 else if(id ==-211){fst[6]++;} // fst[6]: pi-
394 else if(id == 321){fst[7]++;} // fst[7]: K+
395 else if(id ==-321){fst[8]++;} // fst[8]: K-
396 else if(id ==2212){fst[9]++;} // fst[9]: pronton
397 else if(id ==-2212){fst[10]++;} // fst[10]: anti-proton
398 else if(id == 2112){fst[11]++;} // fst[11]: nucleon
399 else if(id ==-2112){fst[12]++;} // fst[12]: ant-nucleon
400 if( fabs(id) == 11) {nchr_e++;}
401 if( fabs(id) == 13) {nchr_mu++;}
402 if( fabs(id) == 211) {nchr_pi++;}
403 if( fabs(id) == 321) {nchr_k++;}
404 if( fabs(id) == 2212) {nchr_p++;}
405
406 if( m_NtupleFile==true && id!=0 ){
407 m_Trk_index[AllTrk_index]=id;
408 m_px_trk[AllTrk_index]=pex;
409 m_py_trk[AllTrk_index]=pey;
410 m_pz_trk[AllTrk_index]=pez;
411 m_en_trk[AllTrk_index]=en ;
412
413 AllTrk_index++;
414
415 }
416
417
418 }
419
420 // for SuperBody3decay generator
421 // EvtVector4R pd1,pd2,pd3;
422 EvtVector4R fdp_init;
423 EvtId fdp_ppid;
424 if(m_FDPparticle!=""){
425 findPart(part);
426 fdp_ppid = FDP_id;
427 fdp_init = FDP_init;
428 } else{
429 fdp_ppid = eid;
430 fdp_init = p_init;
431 }
432
433 if(!(m_SB3File=="" || m_SB3HT=="") && parentFlag && first ){
434 SuperBody3decay_make(fdp_ppid, fdp_init );
435 }
436
437 loop_to_select_eventsA:
438 m_Gen->generateDecay(part);
439 if(m_truthFile!="" && m_truthPart!=""){
440 if(EvtPDL::name(part->getId())==m_truthPart ){
441 int ndaug = part->getNDaug();
442 for(int id=0;id<ndaug;id++){
443 EvtParticle* sonp=part->getDaug(id);
444 EvtVector4R son=sonp->getP4();
445 truth<<son.get(0)<<" "<<son.get(1)<<" "<<son.get(2)<<" "<<son.get(3)<<std::endl;
446 }
447 }
448 }
449 double ratio,rdm;
450 if(_mDIY && parentFlag && m_ampscalflag ) _amps_max=CalAmpsMax(part);
451 if(_mDIY && parentFlag) {
452 rdm=EvtRandom::Flat(0.0, 1.0);
453 double amps=CalAmpsMDIY( part );
454 ratio=amps/_amps_max;
455 }
456 if(_mDIY && parentFlag && ratio<=rdm){ goto loop_to_select_eventsA;}
457
458 //-------- For superbody3------------------------------
459 bool accept;
460 if(m_FDPparticle==""){FDP_part=part;}
461 if(!(m_SB3File=="" || m_SB3HT=="") && parentFlag ){ accept=SuperBody3decay_judge( FDP_part); }
462 if(!(m_SB3File=="" || m_SB3HT=="") && parentFlag && !accept){
463 part->deleteTree();
464 writeFlag=0;
465 goto loop_to_select_eventsB;
466 }else if(!(m_SB3File=="" || m_SB3HT=="") && parentFlag && accept){
467 countChannel(FDP_part);
468 }
469 //-------- for psi4040 open charm inclusive decay
470 if((m_Psi2openCharm || m_Psi4040OpenCharm) && parentFlag ){
471 if(getModel(part) == "OPENCHARM"){
472 std::cout<<"OPENCHARM model need to set Psi2openCharm and Psi3SopenCharm to be false!"<<std::endl;
473 abort();
474 }
475 EvtPsi3Sdecay opencharm(en, part);
476 bool theDecay = opencharm.choseDecay();
477 if(!theDecay ) {
478 part->deleteTree();
479 writeFlag=0;
480 goto loop_to_select_eventsB;
481 }
482 }
483 //------------- dump the decay tree to the event model
484 // if(Nchannel>=0) part->dumpTree();
485 // if(Nchannel>=0) part->printTree();
486
487 if(parentFlag){
488 EvtDecayTag theTag(part);
489 unsigned int modeTag, multiplicityTag;
490 modeTag = theTag.getModeTag();
491 if( getModel(part) == "OPENCHARM"||getModel(part) == "LUNDCHARM" && m_tagLundModel){
492 multiplicityTag = decayType(part);
493 //debugging
494 // std::cout<<"Opencharm Mode: "<<decayType(part)<<std::endl;
495 } else {
496 multiplicityTag = theTag.getMultTag() + decayType(part);
497 }
498
499 //std::cout<<"StdHep= "<<EvtPDL::getStdHep(part->getId())<<" getChannel "<<part->getChannel()<<" flag1,flag2= "<<modeTag<<" "<<multiplicityTag<<std::endl;
500 if(eventHeader == 0) std::cout << "event header unavailable: " << std::endl;
501 if (eventHeader != 0) {
502 eventHeader->setFlag1(modeTag);
503 eventHeader->setFlag2(multiplicityTag);
504 //std::cout<<"flag1,flag2= "<<modeTag<<" "<<multiplicityTag<<std::endl;
505 }
506 }
507
508 if(!(m_DecayRec=="")) mydecayrec=part->writeTreeRec(m_DecayRec);
509 //-- decay statistics
510 if(m_statDecays && parentFlag ) countChannel(part);
511 // ----------- pingrg 2008-03-25 ---------
512
513 if ( log.level() <= MSG::DEBUG ) part->printTree() ;
514 log << MSG::DEBUG << "Converting particles to HepMC" << endreq;
515
516 makeHepMC(part, hepMCevt, hepMCpart);
517 if(part->getNDaug()!=0)
518 hepMCpart->set_status(999);
519
520 part->deleteTree();
521 };
522
523 for( itp=hepMCevt->particles_begin(); itp!=hepMCevt->particles_end(); ++itp )
524 {
525 if (!(*itp)->end_vertex() && ( (*itp)->status()==899 || (*itp)->status()==999 ))
526 (*itp)->set_status(1);
527 }
529 if(m_Ncharge == true ) {std::cout<<"MultiplicityTotoalCharge_e_mu_pi_K_p_gamma_gammaFSR: "
530 <<nchr <<" "
531 <<nchr_e <<" "
532 << nchr_mu <<" "
533 << nchr_pi <<" "
534 << nchr_k <<" "
535 <<nchr_p <<" "
536 <<N_gamma <<" "
537 <<N_gammaFSR<<endl;}
538 if(m_Ncharge == true ){std::cout<<"FinalStates: "
539 <<fst[0]<<" "
540 <<fst[1]<<" "
541 <<fst[2]<<" "
542 <<fst[3]<<" "
543 <<fst[4]<<" "
544 <<fst[5]<<" "
545 <<fst[6]<<" "
546 <<fst[7]<<" "
547 <<fst[8]<<" "
548 <<fst[9]<<" "
549 <<fst[10]<<" "
550 <<fst[11]<<" "
551 <<fst[12]<<std::endl;}
552 if( m_NtupleFile ){
553 // TotNumTrk=500;
554 m_nchr = nchr;
555 m_nchr_e = nchr_e;
556 m_nchr_mu = nchr_mu;
557 m_nchr_pi = nchr_pi;
558 m_nchr_k = nchr_k;
559 m_nchr_p = nchr_p;
560 m_gamma=N_gamma;
561 m_gammaFSR=N_gammaFSR;
562 TotNumTrk = nchr + N_gamma + N_gammaFSR;
563 }
564
565 // std::cout<<"Flag= "<<eventHeader->flag1()<<" "<<eventHeader->flag2()<<std::endl;
566 return StatusCode::SUCCESS;
567}
568
569//****** CallBesEvtGen ************
570// This part is responsible for only ruuing BesEvtGen. //pingrg Feb. 3,2008
571//***************************************************
572StatusCode EvtDecay::callBesEvtGen( HepMC::GenEvent* hepMCevt )
573{
574 MsgStream log(messageService(), name());
575
576 nchr = -1;
577 nchr_e = 0;
578 nchr_mu= 0;
579 nchr_pi= 0;
580 nchr_k = 0;
581 nchr_p = 0;
582 N_gamma=0;
583 N_gammaFSR = 0;
584 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
585 for (int i=0;i<13;i++) fst[i]=0;
586 HepMC::GenEvent::particle_const_iterator itp;
587 // This is the main loop.
588 // We iterate over particles and we look for ones that
589 // should be decayed with EvtGen.
590 //
591 // status == 1 - undecayed Pythia particle (also for particles that are not supposed to decay)
592 // status == 999 - particle already decayed by EvtGen
593 // status == 899 - particle was supposed to decay by EvtGen - but found no model
594 // this may be also intentional - such events are then excluded from
595 // being written into persistent output.
596 // ISTHEP(IHEP):
597 // status code for entry IHEP, with the following meanings:
598 //
599 // = 0 : null entry.
600 // = 1 : an existing entry, which has not decayed or fragmented. This is the main class of entries, which represents the `final state' given by the generator.
601 // = 2 : an entry which has decayed or fragmented and is therefore not appearing in the final state, but is retained for event history information.
602 // = 3 : a documentation line, defined separately from the event history. This could include the two incoming reacting particles, etc.
603 // = 4 - 10 : undefined, but reserved for future standards.
604 // = 11 - 200 : at the disposal of each model builder for constructs specific to his program, but equivalent to a null line in the context of any other program.
605 // = 201 - : at the disposal of users, in particular for event tracking in the detector.
606
607 loop_to_select_eventsB:
608 EvtId ppid=EvtPDL::getId(m_ParentPart); //parent particle name
609 double ppmass=EvtPDL::getMass(ppid);
610 parentMass=ppmass;
611 int pid=EvtPDL::getStdHep(ppid);
612 parentPDGcode=pid;
613
614 EvtVector4R p_init(ppmass,0.0,0.0,0.0);
615
617 HepMC::GenParticle* hepMCpart=new GenParticle(HepLorentzVector(0,0,0,ppmass),pid,3);
618
619 bool parentFlag = false;
620 // set spin density matrix for e+ e- -> V
621 if(writeFlag ==0 && part->getSpinType() == EvtSpinType::VECTOR) {
622 part->setVectorSpinDensity();
623 parentFlag = true;
624 writeFlag++;
625 }
626
627 // for SuperBody3decay generator
628 EvtVector4R fdp_init;
629 EvtId fdp_ppid;
630 if(m_FDPparticle!=""){
631 findPart(part);
632 fdp_ppid = FDP_id;
633 fdp_init = FDP_init;
634 } else{
635 fdp_ppid = ppid;
636 fdp_init = p_init;
637 }
638
639 if(!(m_SB3File=="" || m_SB3HT=="") && first ){ SuperBody3decay_make( fdp_ppid, fdp_init);}
640 // -----------------------------------
641
642 loop_to_select_events:
643 m_Gen->generateDecay(part);
644 if(m_truthFile!="" && m_truthPart!=""){
645 if(EvtPDL::name(part->getId())==m_truthPart ){
646 int ndaug = part->getNDaug();
647 for(int id=0;id<ndaug;id++){
648 EvtParticle* sonp=part->getDaug(id);
649 EvtVector4R son=sonp->getP4();
650 truth<<son.get(0)<<" "<<son.get(1)<<" "<<son.get(2)<<" "<<son.get(3)<<std::endl;
651 }
652 }
653 }
654 double ratio,rdm;
655 if(_mDIY && m_ampscalflag ) _amps_max=CalAmpsMax(part);
656 if(_mDIY ) {
657 rdm=EvtRandom::Flat(0.0, 1.0);
658 double amps=CalAmpsMDIY( part );
659 ratio=amps/_amps_max;
660 }
661 if(_mDIY && ratio<=rdm) goto loop_to_select_events;
662
663//--------- For superbody3
664 bool accept;
665 if(m_FDPparticle==""){FDP_part=part;}
666 if(!(m_SB3File=="" || m_SB3HT=="")){
667 accept=SuperBody3decay_judge( FDP_part);
668 }
669 if(!(m_SB3File=="" || m_SB3HT=="") && !accept) {
670 delete hepMCpart;
671 part->deleteTree();
672 goto loop_to_select_eventsB;
673 }else if(!(m_SB3File=="" || m_SB3HT=="") && parentFlag && accept){
674 countChannel(FDP_part);
675 }
676
677 int Nchannel=part->getChannel();
678
679 if(m_statDecays && parentFlag) countChannel(part);
680 //------------- dump the decay tree to the event model
681 // int Nchannel=part->getChannel();
682 // if(Nchannel>=0) part->dumpTree();
683
684 if(parentFlag){
685 EvtDecayTag theTag(part);
686 unsigned int modeTag, multiplicityTag;
687 modeTag = theTag.getModeTag();
688 if( getModel(part) == "OPENCHARM"|| getModel(part) == "LUNDCHARM" && m_tagLundModel ){
689 multiplicityTag = decayType(part);
690 //debugging
691 // std::cout<<"Opencharm Mode: "<<decayType(part)<<std::endl;
692 } else {
693 multiplicityTag = theTag.getMultTag() + decayType(part);
694 }
695 if(eventHeader == 0) std::cout << "event header unavailable: " << std::endl;
696 if (eventHeader != 0) {
697 eventHeader->setFlag1(modeTag);
698 eventHeader->setFlag2(multiplicityTag);
699 }
700 }
701
702 if(!(m_DecayRec=="")) {mydecayrec=part->writeTreeRec(m_DecayRec);std::cout<<std::endl;};
703 // ----------- pingrg 2008-03-25 ---------
704
705 if ( log.level() <= MSG::DEBUG ) part->printTree() ;
706 log << MSG::DEBUG << "Converting particles to HepMC" << endreq;
707
708 makeHepMC(part, hepMCevt, hepMCpart);
709
710 if(part->getNDaug()!=0) hepMCpart->set_status(999);
711
712 part->deleteTree();
713
714 AllTrk_index=0;
715 for( itp=hepMCevt->particles_begin(); itp!=hepMCevt->particles_end(); ++itp )
716 {
717 if (!(*itp)->end_vertex() && ( (*itp)->status()==899 || (*itp)->status()==999 ))
718 (*itp)->set_status(1);
719 HepMC::GenParticle* hepMCpart=*itp;
720 int stat = hepMCpart->status();
721 int id = hepMCpart->pdg_id();
722
723 if ( stat != 1 ) continue;
724 if( id == 22 ) {N_gamma ++;fst[0]++;}
725 if( id == -22 ){N_gammaFSR ++;}
726 if( id == 11 ) {fst[1]++;} else if(id == -11) {fst[2]++;}
727 else if(id == 13 ) {fst[3]++;}
728 else if(id ==-13) {fst[4]++;}
729 else if(id==211) {fst[5]++;}
730 else if(id==-211) {fst[6]++;}
731 else if(id== 321) {fst[7]++;}
732 else if(id ==-321) {fst[8]++;}
733 else if(id ==2212) {fst[9]++;}
734 else if(id==-2212) {fst[10]++;}
735 else if(id == 2112){fst[11]++;}
736 else if(id==-2112) {fst[12]++;}
737 if( fabs(id) == 11) {nchr_e++;}
738 if( fabs(id) == 13) {nchr_mu++;}
739 if( fabs(id) == 211) {nchr_pi++;}
740 if( fabs(id) == 321) {nchr_k++;}
741 if( fabs(id) == 2212) {nchr_p++;}
742
743 //for Nuple
744 double en =(hepMCpart->momentum()).e();
745 double pex=(hepMCpart->momentum()).px();
746 double pey=(hepMCpart->momentum()).py();
747 double pez=(hepMCpart->momentum()).pz();
748
749 if( m_NtupleFile==true && id!=0){
750 m_Trk_index[AllTrk_index]=id;
751 m_px_trk[AllTrk_index]=pex;
752 m_py_trk[AllTrk_index]=pey;
753 m_pz_trk[AllTrk_index]=pez;
754 m_en_trk[AllTrk_index]=en ;/*
755 std::cout<<"trk# " <<AllTrk_index
756 <<" PID:" <<id
757 <<" px: " <<pex
758 <<" py: " <<pey
759 <<" pz: " <<pez
760 <<" E: " <<en<<std::endl;*/
761 AllTrk_index++;
762 }
763
764 }
765
766 itp=hepMCevt->particles_begin(); // parent decaying particle status set
767 (*itp)->set_status(2);
768
770 if(m_Ncharge == true ) {std::cout<<"MultiplicityTotoalCharge_e_mu_pi_K_p_gamma_gammaFSR: "
771 <<nchr<<" "
772 <<nchr_e<<" "
773 << nchr_mu <<" "
774 << nchr_pi <<" "
775 << nchr_k <<" "
776 <<nchr_p<<" "
777 <<N_gamma<<" "
778 <<N_gammaFSR<<endl;}
779 if(m_Ncharge == true ){std::cout<<"FinalStates: "
780 <<fst[0]<<" "
781 <<fst[1]<<" "
782 <<fst[2]<<" "
783 <<fst[3]<<" "
784 <<fst[4]<<" "
785 <<fst[5]<<" "
786 <<fst[6]<<" "
787 <<fst[7]<<" "
788 <<fst[8]<<" "
789 <<fst[9]<<" "
790 <<fst[10]<<" "
791 <<fst[11]<<" "
792 <<fst[12]<<std::endl;}
793
794 if( m_NtupleFile ){
795 m_nchr = nchr;
796 m_nchr_e = nchr_e;
797 m_nchr_mu = nchr_mu;
798 m_nchr_pi = nchr_pi;
799 m_nchr_k = nchr_k;
800 m_nchr_p = nchr_p;
801 m_gamma=N_gamma;
802 m_gammaFSR=N_gammaFSR;
803 TotNumTrk = nchr + N_gamma + N_gammaFSR;
804 }
805
806 //std::cout<<"Flag= "<<eventHeader->flag1()<<" "<<eventHeader->flag2()<<std::endl;
807 return StatusCode::SUCCESS;
808}
809
810//************ end of callBesEvtGen *********************
812{
813 MsgStream log(messageService(), name());
814 truth.close();
815 log << MSG::INFO << "EvtDecay finalized" << endreq;
816 fstream Forfile;
817 Forfile.open("fort.16",ios::in);
818 char delcmd[300];
819 strcpy(delcmd,"rm -f ");
820 strcat(delcmd,"fort.16");
821 // if(Forfile)system(delcmd);
822
823 fstream Forfile2;
824 Forfile2.open("fort.22",ios::in);
825 strcpy(delcmd,"rm -f ");
826 strcat(delcmd,"fort.22");
827 // if(Forfile2)system(delcmd);
828
829 // To get the branching fraction of the specified mode in Lundcharm Model
830 /*
831 EvtLundCharm lundcharmEvt;
832 int nevt=lundcharmEvt.getTotalEvt();
833 std::cout<<"The total number of the specified mode is "<<nevt<<std::endl;
834 */
835 int totalEvt=0;
836 if(!(m_SB3File=="" || m_SB3HT=="")){
837 for(int i=0;i<500;i++){totalEvt=totalEvt+br[i];}
838 for(int i=0;i<500;i++){
839 double bi=1.0*br[i]/totalEvt;
840 std::cout<<"Branching fraction of channel "<<i<<" is: "<<bi<<std::endl;
841 if(br[i]==0) break;
842 }
843 }
844
845 if(m_statDecays){
846 int totalEvt=0;
847 for(int i=0;i<=totalChannels;i++){totalEvt=totalEvt+br[i];}
848 std::cout<<"==================Statistical first chain decay ==============================="<<std::endl;
849 std::cout<<"i-th channel Events Generated Branching fraction generated "<<std::endl;
850 for(int i=0;i<=totalChannels;i++){
851 std::cout<<"| "<<i<<" "<<br[i]<<" "<<br[i]*1.0/totalEvt<<std::endl;
852
853 }
854 std::cout<<"--------------------------------------------------------------------------------"<<std::endl;
855 std::cout<<" sum: "<<totalEvt<<" "<<"1"<<std::endl;
856 std::cout<<"================== End of statistical first chain decay ========================"<<std::endl;
857 }
858
859 return StatusCode::SUCCESS;
860}
861
862
863StatusCode EvtDecay::makeHepMC(EvtParticle* part, HepMC::GenEvent* hEvt,
864 HepMC::GenParticle* hPart)
865{
866 MsgStream log(messageService(), name());
867
868 if(part->getNDaug()!=0)
869 {
870 double ct=(part->getDaug(0)->get4Pos()).get(0);
871 double x=(part->getDaug(0)->get4Pos()).get(1);
872 double y=(part->getDaug(0)->get4Pos()).get(2);
873 double z=(part->getDaug(0)->get4Pos()).get(3);
874
875 HepMC::GenVertex* end_vtx = new HepMC::GenVertex(HepLorentzVector(x,y,z,ct));
876 hEvt->add_vertex( end_vtx );
877 end_vtx->add_particle_in(hPart);
878
879 int ndaug=part->getNDaug();
880
881 for(int it=0;it<ndaug;it++)
882 {
883
884 double e=(part->getDaug(it)->getP4Lab()).get(0);
885 double px=(part->getDaug(it)->getP4Lab()).get(1);
886 double py=(part->getDaug(it)->getP4Lab()).get(2);
887 double pz=(part->getDaug(it)->getP4Lab()).get(3);
888 int id=EvtPDL::getStdHep(part->getDaug(it)->getId());
889 int status=1;
890
891 if(part->getDaug(it)->getNDaug()!=0) status=999;
892
893 HepMC::GenParticle* prod_part = new HepMC::GenParticle(HepLorentzVector(px,py,pz,e),id,status);
894 end_vtx->add_particle_out(prod_part);
895 makeHepMC(part->getDaug(it),hEvt,prod_part);
896
897
898
899 if( log.level()<MSG::INFO )
900 prod_part->print();
901 }
902 }
903
904 return StatusCode::SUCCESS;
905}
906
907
908void EvtDecay::MeVToGeV (HepMC::GenEvent* evt)
909{
910 for ( HepMC::GenEvent::particle_iterator p = evt->particles_begin(); p != evt->particles_end(); ++p ) {
911 // cout << " PDG, BAR " << (*p)->pdg_id() << " " << (*p)->barcode() << endl;
912 // (*p)->set_momentum( (*p)->momentum() / 1000. );
913
914 HepMC::FourVector tmpfv((*p)->momentum().x()/1000.,
915 (*p)->momentum().y()/1000.,
916 (*p)->momentum().z()/1000.,
917 (*p)->momentum().t()/1000.
918 );
919
920 (*p)->set_momentum( tmpfv );
921 }
922}
923
924void EvtDecay::GeVToMeV (HepMC::GenEvent* evt)
925{
926 for ( HepMC::GenEvent::particle_iterator p = evt->particles_begin(); p != evt->particles_end(); ++p ) {
927 // cout << " PDG, BAR " << (*p)->pdg_id() << " " << (*p)->barcode() << endl;
928 // (*p)->set_momentum( (*p)->momentum() * 1000. );
929 HepMC::FourVector tmpfv((*p)->momentum().x()*1000.,
930 (*p)->momentum().y()*1000.,
931 (*p)->momentum().z()*1000.,
932 (*p)->momentum().t()*1000.
933 );
934
935 (*p)->set_momentum( tmpfv );
936 }
937}
938
939
940double EvtDecay::CalAmpsMax( EvtParticle* part )
941{
942 double amps_max=0;
943 for(int i=0;i<100000;i++){
944 m_Gen->generateDecay(part);
945 double amps=CalAmpsMDIY(part);
946 if(amps > amps_max) amps_max=amps;
947 }
948 amps_max=amps_max*1.05;
949 m_ampscalflag = false;
950 return amps_max;
951}
952
953// EvtBesRandom class implementation, basically BesRandomSvc -> EvtGen random engine interface
954
955EvtBesRandom::EvtBesRandom(HepRandomEngine* engine)
956{
957 m_engine = engine;
958 m_engine->showStatus();
959}
960
963
965{
966 return RandFlat::shoot(m_engine);
967}
968
969
970void EvtDecay::SuperBody3decay_make(EvtId ppid, EvtVector4R p_init ){
971 double xmass2,ymass2;
972 bool accept;
973 EvtVector4R pd1,pd2,pd3;
974
975 //---- find out the pdg codes of final state and count the identical particles
976 FinalState_make( ppid, p_init);
977
978 //begin to loop with events
979 for(int i=0;i<100000;i++){
980 regen:
982 HepMC::GenParticle* hepMCpart=new GenParticle(HepLorentzVector(0,0,0,parentMass),parentPDGcode,3); //this line make the decay to select different channel
983
984 if(part->getSpinType() == EvtSpinType::VECTOR) {
985 part->setVectorSpinDensity();
986 }
987 m_Gen->generateDecay(part);
988
989
990 FinalState_sort(part);
991 pd1=son0;
992 pd2=son1;
993 pd3=son2;
994
995 // std::cout<<"multi, pdg, pi= "<<multi<<" "<<pdg0<<" "<<pdg1<<" "<<pdg2<<" "<<son0<<son1<<son2<<std::endl;
996
997 xmass2=(pd1+pd2).mass2(); // Dalitz plot m12^2 ~ m13^2
998 ymass2=(pd1+pd3).mass2();
999 double xlow=SuperBody3decay.getXlow();
1000 double xup=SuperBody3decay.getXup();
1001 double ylow=SuperBody3decay.getYlow();
1002 double yup=SuperBody3decay.getYup();
1003 if(xmass2<xlow || xmass2>xup || ymass2<ylow || ymass2>yup) { part->deleteTree();goto regen;}
1004 SuperBody3decay.HFill(xmass2,ymass2);
1005
1006 if( m_NtupleFile ){
1007 m_ich=part->getChannel();
1008 m_m1=pd1.mass();
1009 m_m2=pd2.mass();
1010 m_m3=pd3.mass();
1011 m_m12=(pd1+pd2).mass();
1012 m_m23=(pd2+pd3).mass();
1013 m_m13=(pd1+pd3).mass();
1014 m_cos1=pd1.get(3)/pd1.d3mag();
1015 m_cos2=pd2.get(3)/pd2.d3mag();
1016 m_cos3=pd3.get(3)/pd3.d3mag();
1017 mass_tuple->write();
1018 }
1019 double m1=pd1.mass(); double m2=pd2.mass();double m3=pd3.mass();
1020 double mj=(pd2+pd3).mass();
1021 // std::cout<<"mass 1 2 3 chicj <<=="<<m1<<" "<<m2<<" "<<m3<<" "<<mj<<std::endl;
1022 // delete hepMCpart;
1023 }
1024
1025 SuperBody3decay.HReweight(); //reweighting Dalitz plot
1026 SuperBody3decay.setZmax(); // find out the maximum value after reweighting
1027 first=false;
1028}
1029
1030bool EvtDecay::SuperBody3decay_judge(EvtParticle* part){
1031 double xmass2,ymass2;
1032 bool accept;
1033 EvtVector4R pd1,pd2,pd3;
1034
1035
1036 FinalState_sort( part);
1037
1038 pd1=son0;
1039 pd2=son1;
1040 pd3=son2;
1041
1042
1043 xmass2=(pd1+pd2).mass2(); // Dalitz plot m12^2 ~ m13^2
1044 ymass2=(pd1+pd3).mass2();
1045 accept=SuperBody3decay.AR(xmass2,ymass2);
1046
1047 //debugging
1048 if(accept && m_NtupleFile) {
1049 _ich=part->getChannel();
1050 _m1=pd1.mass();
1051 _m2=pd2.mass();
1052 _m3=pd3.mass();
1053 _m12=(pd1+pd2).mass();
1054 _m23=(pd2+pd3).mass();
1055 _m13=(pd1+pd3).mass();
1056 _cos1=pd1.get(3)/pd1.d3mag();
1057 _cos2=pd2.get(3)/pd2.d3mag();
1058 _cos3=pd3.get(3)/pd3.d3mag();
1059 massgen_tuple->write();
1060 }
1061 // std::cout<<"mass 1 2 3 chicj>> "<<_m1<<" "<<_m2<<" "<<_m3<<" "<<_m23<<std::endl;
1062
1063 return accept;
1064}
1065
1066
1067void EvtDecay:: FinalState_make(EvtId ppid, EvtVector4R p_init){
1068 // get the final state pdg cond and count the identicle particle
1069 multi=1;
1070 identical_flag=true;
1071
1072 for(int i=1;i<10000;i++){ //sigle out the final state
1074 HepMC::GenParticle* hepMCpart=new GenParticle(HepLorentzVector(0,0,0,parentMass),parentPDGcode,3);
1075
1076 m_Gen->generateDecay(part);
1077 int nson=part->getNDaug();
1078
1079 if(nson == 2) {continue;} else
1080 if(nson ==3){
1081 EvtId xid0,xid1,xid2;
1082 xid0=part->getDaug(0)->getId();
1083 xid1=part->getDaug(1)->getId();
1084 xid2=part->getDaug(2)->getId();
1085
1086//-- pdg code
1087 pdg0=EvtPDL::getStdHep(xid0);
1088 pdg1=EvtPDL::getStdHep(xid1);
1089 pdg2=EvtPDL::getStdHep(xid2);
1090
1091 if(pdg0==pdg1 && pdg1==pdg2) {multi=3;}
1092 else if(pdg0==pdg1 ){multi=2;} // two identical particle list as 0,1 index
1093 else if(pdg0==pdg2 ){multi=2;pdg=pdg1; pdg1=pdg2; pdg2=pdg;}
1094 else if(pdg1==pdg2) {multi=2;pdg=pdg0; pdg0=pdg1; pdg1=pdg2; pdg2=pdg;}
1095 else {multi=1;}
1096 break;
1097 } else{
1098 std::cout<<"No direct three body decay channel found in decay card, I stop run"<<std::endl;
1099 ::abort();
1100 }
1101 }
1102 // std::cout<<"pdg_i "<<pdg0<<" "<<pdg1<<" "<<pdg2<<std::endl;
1103 // std::cout<<"identical particle "<<multi<<std::endl;
1104}
1105
1106void EvtDecay::FinalState_sort(EvtParticle* part){
1107 // sort the momentum to aon0, son1, son2
1108 EvtVector4R pd0,pd1,pd2;
1109 EvtId xid0,xid1,xid2;
1110 int id0,id1,id2;
1111
1112 int nson=part->getNDaug();
1113 if(nson==2){
1114 pd0=part->getDaug(0)->getP4Lab();
1115 pd1=part->getDaug(1)->getDaug(0)->getP4Lab();
1116 pd2=part->getDaug(1)->getDaug(1)->getP4Lab();
1117
1118 xid0=part->getDaug(0)->getId();
1119 xid1=part->getDaug(1)->getDaug(0)->getId();
1120 xid2=part->getDaug(1)->getDaug(1)->getId();
1121
1122 } else if(nson==3){
1123 pd0=part->getDaug(0)->getP4Lab();
1124 pd1=part->getDaug(1)->getP4Lab();
1125 pd2=part->getDaug(2)->getP4Lab();
1126
1127 xid0=part->getDaug(0)->getId();
1128 xid1=part->getDaug(1)->getId();
1129 xid2=part->getDaug(2)->getId();
1130 }
1131 //-- pdg code
1132 id0=EvtPDL::getStdHep(xid0);
1133 id1=EvtPDL::getStdHep(xid1);
1134 id2=EvtPDL::getStdHep(xid2);
1135
1136 // std::cout<<"pid before match: "<<id0<<" "<<id1<<" "<<id2<<std::endl;
1137 //-- assign sons momentum
1138 if(multi==1){
1139 assign_momentum(id0,pd0);
1140 assign_momentum(id1,pd1);
1141 assign_momentum(id2,pd2);
1142 } else if(multi==2){
1143 assign_momentum2(id0,pd0);
1144 assign_momentum2(id1,pd1);
1145 assign_momentum2(id2,pd2);
1146 if(son0.get(0)>son1.get(0)){son=son0;son0=son1;son1=son;} // change into E_0 < E_1
1147 } else if(multi==3){ // sort sons according to energy E_0 < E_1 < E_2
1148 double En0=pd0.get(0);
1149 double En1=pd1.get(0);
1150 double En2=pd2.get(0);
1151 if(En0 < En1 && En1 < En2) {son0=pd0;son1=pd1;son2=pd2;}
1152 if(En0 < En2 && En2 < En1) {son0=pd0;son1=pd2;son2=pd1;}
1153 if(En1 < En0 && En0 < En2) {son0=pd1;son1=pd0;son2=pd2;}
1154 if(En1 < En2 && En2 < En0) {son0=pd1;son1=pd2;son2=pd0;}
1155 if(En2 < En0 && En0 < En1) {son0=pd2;son1=pd0;son2=pd1;}
1156 if(En2 < En1 && En1 < En0) {son0=pd2;son1=pd1;son2=pd0;}
1157 }
1158
1159}
1160
1161
1162void EvtDecay::assign_momentum(int id0, EvtVector4R pd0){
1163 if(id0==pdg0){son0=pd0;}
1164 else if(id0==pdg1){son1=pd0;}
1165 else if(id0==pdg2){son2=pd0;}
1166 else {std::cout<<"PID= "<<id0<<" not machted, I stop"<<std::endl; ::abort();}
1167}
1168
1169void EvtDecay::assign_momentum2(int id0, EvtVector4R pd0){ // for two identicle particle case
1170 if(id0==pdg0 && identical_flag){son0=pd0;identical_flag=false;}
1171 else if(id0==pdg1){son1=pd0;identical_flag=true;}
1172 else if(id0==pdg2){son2=pd0;}
1173 else {std::cout<<"PID not machted, I stop"<<std::endl; ::abort();}
1174}
1175
1176void EvtDecay::findPart(EvtParticle* part){
1177 FDP_id=EvtPDL::getId(m_FDPparticle);
1178 int FDP_pdg=EvtPDL::getStdHep(FDP_id);
1179
1180 m_Gen->generateDecay(part);
1181 int dn=part->getNDaug();
1182
1183 if(dn!=0){
1184 for(int i=0;i<dn;i++){
1185 EvtParticle* part1=part->getDaug(i);
1186 EvtId sonid=part1->getId();
1187 int son_pdg = EvtPDL::getStdHep(sonid);
1188 if(son_pdg == FDP_pdg){
1189 FDP_init=part1->getP4Lab();
1190 FDP_part=part1;
1191 return;
1192 } else{
1193 findPart(part1);
1194 }
1195 }
1196 } //if (dn block
1197
1198}
1199
1200void EvtDecay::countChannel(EvtParticle* part){
1201 int ich=part->getChannel();
1202
1203 //debuging
1204 //if(getModel(part,ich)=="OPENCHARM" &&EvtPDL::name( part->getId() )=="psi(4260)") ich = part->getGeneratorFlag();
1205 //std::cout<<"the channel is "<<ich<<std::endl;
1206
1207 br[ich]++;
1208 if(ich>totalChannels) totalChannels = ich;
1209 //std::cout<<"EVENT IN br_i "<<br[ich]<<std::endl;
1210}
1211
1212bool EvtDecay::isCharmonium(EvtId xid){
1213EvtId psi4415 = EvtPDL::getId(std::string("psi(4415)"));
1214EvtId psi4160 = EvtPDL::getId(std::string("psi(4160)"));
1215EvtId psi4040 = EvtPDL::getId(std::string("psi(4040)"));
1216EvtId psi3770 = EvtPDL::getId(std::string("psi(3770)"));
1217EvtId psiprim = EvtPDL::getId(std::string("psi(2S)"));
1218EvtId jpsi = EvtPDL::getId(std::string("J/psi"));
1219EvtId etac = EvtPDL::getId(std::string("eta_c"));
1220EvtId etac2s = EvtPDL::getId(std::string("eta_c(2S)"));
1221EvtId hc = EvtPDL::getId(std::string("h_c"));
1222EvtId chic0 = EvtPDL::getId(std::string("chi_c0"));
1223EvtId chic1 = EvtPDL::getId(std::string("chi_c1"));
1224EvtId chic2 = EvtPDL::getId(std::string("chi_c2"));
1225EvtId chic0p = EvtPDL::getId(std::string("chi_c0p"));
1226EvtId chic1p = EvtPDL::getId(std::string("chi_c1p"));
1227EvtId chic2p = EvtPDL::getId(std::string("chi_c1p"));
1228 std::vector<EvtId> Vid; Vid.clear();
1229 Vid.push_back(psi4415);
1230 Vid.push_back(psi4160);
1231 Vid.push_back(psi4040);
1232 Vid.push_back(psi3770);
1233 Vid.push_back(psiprim);
1234 Vid.push_back(jpsi);
1235 Vid.push_back(etac);
1236 Vid.push_back(etac2s);
1237 Vid.push_back(hc);
1238 Vid.push_back(chic0);
1239 Vid.push_back(chic1);
1240 Vid.push_back(chic2);
1241 Vid.push_back(chic0p);
1242 Vid.push_back(chic1p);
1243 Vid.push_back(chic2p);
1244
1245 bool flag=true;
1246 for(int i=0;i<Vid.size();i++){ if(xid == Vid[i]) return flag;}
1247 return false;
1248}
1249
1250
1251bool EvtDecay::isCharm(EvtId xid){
1252EvtId d0 = EvtPDL::getId(std::string("D0"));
1253EvtId d0bar = EvtPDL::getId(std::string("anti-D0"));
1254EvtId dp = EvtPDL::getId(std::string("D+"));
1255EvtId dm = EvtPDL::getId(std::string("D-"));
1256EvtId d0h = EvtPDL::getId(std::string("D0H"));
1257EvtId d0l = EvtPDL::getId(std::string("D0L"));
1258EvtId dstp = EvtPDL::getId(std::string("D*+"));
1259EvtId dstm = EvtPDL::getId(std::string("D*-"));
1260EvtId ds0 = EvtPDL::getId(std::string("D*0"));
1261EvtId ds0bar = EvtPDL::getId(std::string("anti-D*0"));
1262EvtId dsp = EvtPDL::getId(std::string("D_s+"));
1263EvtId dsm = EvtPDL::getId(std::string("D_s-"));
1264EvtId dsstp = EvtPDL::getId(std::string("D_s*+"));
1265EvtId dsstm = EvtPDL::getId(std::string("D_s*-"));
1266EvtId ds0stp = EvtPDL::getId(std::string("D_s0*+"));
1267EvtId ds0stm = EvtPDL::getId(std::string("D_s0*-"));
1268
1269 std::vector<EvtId> Vid; Vid.clear();
1270 Vid.push_back(d0);
1271 Vid.push_back(d0bar);
1272 Vid.push_back(dp);
1273 Vid.push_back(dm);
1274 Vid.push_back(d0h);
1275 Vid.push_back(d0l);
1276 Vid.push_back(dstp);
1277 Vid.push_back(dstm);
1278 Vid.push_back(ds0);
1279 Vid.push_back(ds0bar );
1280 Vid.push_back(dsp );
1281 Vid.push_back(dsm );
1282 Vid.push_back(dsstp );
1283 Vid.push_back(dsstm );
1284 Vid.push_back(ds0stp );
1285 Vid.push_back(ds0stm );
1286
1287 bool flag=true;
1288 for(int i=0;i<Vid.size();i++){ if(xid == Vid[i]) return flag;}
1289 return false;
1290}
1291
1292bool EvtDecay::isRadecay(EvtParticle *par){
1293 int ndg = par->getNDaug();
1294 for(int i=0;i<ndg;i++){
1295 EvtId xid = par->getDaug(i)->getId();
1296 if(EvtPDL::getStdHep(xid) == 22){return true;}
1297 }
1298 return false;
1299}
1300
1301int EvtDecay::decayType(EvtParticle *par){
1302 /*************************************
1303 * 0: gamma light_hadrons
1304 * 1: gamma charmonium
1305 * 2: DDbar (D0 D0bar or D+D-)
1306 * 3: ligh_hadrons
1307 * 4: others
1308 *************************************/
1309 int Nchannel=par->getChannel();
1310 int ndg = par->getNDaug();
1311 int nfsr=0;
1312
1313 std::string model = getModel(par,Nchannel);
1314 if( model == "OPENCHARM" || model == "LUNDCHARM" && m_tagLundModel){ // lundcharm model tag
1315 int ldm = par->getGeneratorFlag();
1316 // std::cout<<"LundCharmFlag = "<<ldm<<std::endl;
1317 return ldm;
1318 //return 9;
1319 }
1320
1321 for(int i=0;i<ndg;i++){ //remove the FSR photon
1322 EvtId xid =par->getDaug(i)->getId();
1323 if(EvtPDL::getStdHep(xid) == -22 ){nfsr++;}
1324 }
1325
1326 if( isRadecay(par) ){
1327 for(int i=0;i<ndg;i++){
1328 EvtId xid = par->getDaug(i)->getId();
1329 if( isCharmonium(xid) ) return 1;
1330 }
1331 return 0;
1332 } else{
1333 if(ndg-nfsr ==2 ){
1334 int ndg = par->getNDaug();
1335 EvtId xd1 = par->getDaug(0)->getId();
1336 EvtId xd2 = par->getDaug(1)->getId();
1337 if( isCharm(xd1) && isCharm(xd2) ) {return 2;} else
1338 if( !isCharmonium(xd1) && !isCharmonium(xd2) && !isCharm(xd1) && !isCharm(xd2) ){
1339 return 3;
1340 }
1341 } else{ // ndg>=3
1342 bool flag = false;
1343 for(int i=0;i<ndg;i++){
1344 EvtId xid = par->getDaug(i)->getId();
1345 if( isCharmonium(xid) ) {flag = true; break;}
1346 if( isCharm(xid) ) {flag = true; break;}
1347 } // for_i block
1348 if( !flag ){return 3;} else {return 4;}
1349 }// if_ndg block
1350 }
1351
1352}
1353
1354
1355std::string EvtDecay::getModel(EvtParticle *par, int mode){
1356 EvtDecayBase* thedecay = EvtDecayTable::gettheDecay(par->getId(),mode);
1357 return thedecay->getModelName();
1358}
1359
1360std::string EvtDecay::getModel(EvtParticle *par){
1361 int mode = par->getChannel();
1362 EvtDecayBase* thedecay = EvtDecayTable::gettheDecay(par->getId(),mode);
1363 return thedecay->getModelName();
1364}
1365
1366
double mass
Double_t x[10]
int fst[50]
Definition EvtDecay.cxx:73
int nchr
Definition EvtDecay.cxx:65
int nchr_mu
Definition EvtDecay.cxx:67
int nchr_pi
Definition EvtDecay.cxx:68
int N_gamma
Definition EvtDecay.cxx:71
int nchr_k
Definition EvtDecay.cxx:69
int N_gammaFSR
Definition EvtDecay.cxx:72
int nchr_p
Definition EvtDecay.cxx:70
int nchr_e
Definition EvtDecay.cxx:66
XmlRpcServer s
ObjectVector< McGenEvent > McGenEventCol
Definition McGenEvent.h:39
INTupleSvc * ntupleSvc()
*************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
Definition Taupair.h:42
void setDecayCard(string card)
double random()
Definition EvtDecay.cxx:964
EvtBesRandom(HepRandomEngine *engine)
Definition EvtDecay.cxx:955
virtual ~EvtBesRandom()
Definition EvtDecay.cxx:961
std::string getModelName()
static EvtDecayBase * gettheDecay(EvtId parent, int imode)
EvtDecay(const string &name, ISvcLocator *pSvcLocator)
Definition EvtDecay.cxx:75
DataInfoSvc * dataInfoSvc
Definition EvtDecay.h:74
IDataInfoSvc * tmpInfoSvc
Definition EvtDecay.h:73
StatusCode initialize()
Definition EvtDecay.cxx:107
StatusCode finalize()
Definition EvtDecay.cxx:811
StatusCode execute()
Definition EvtDecay.cxx:265
void readUDecay(const char *const udecay_name)
Definition EvtGen.cc:126
void generateDecay(int stdhepid, EvtVector4R P, EvtVector4R D, EvtStdHep *evtStdHep, EvtSpinDensity *spinDensity=0)
Definition EvtGen.cc:152
void HReweight()
Definition EvtHis2F.cc:137
void init()
Definition EvtHis2F.cc:98
double getYup()
Definition EvtHis2F.hh:69
bool AR(double xmass2, double ymass2)
Definition EvtHis2F.cc:205
void HFill(double xmass2, double ymass2)
Definition EvtHis2F.cc:129
void setHTitle(const char *htitle)
Definition EvtHis2F.cc:40
double getYlow()
Definition EvtHis2F.hh:67
void setZmax()
Definition EvtHis2F.cc:177
double getXup()
Definition EvtHis2F.hh:68
double getXlow()
Definition EvtHis2F.hh:66
void setFile(const char *dtfile)
Definition EvtHis2F.cc:35
Definition EvtId.hh:27
static int getStdHep(EvtId id)
Definition EvtPDL.hh:56
static EvtId evtIdFromStdHep(int stdhep)
Definition EvtPDL.cc:244
static std::string name(EvtId i)
Definition EvtPDL.hh:64
static double getMass(EvtId i)
Definition EvtPDL.hh:46
static EvtId getId(const std::string &name)
Definition EvtPDL.cc:287
static EvtParticle * particleFactory(EvtSpinType::spintype spinType)
EvtVector4R getP4Lab()
EvtId getId() const
void setVectorSpinDensity()
void setPolarizedSpinDensity(double r00, double r11, double r22)
EvtSpinType::spintype getSpinType() const
const EvtVector4R & getP4() const
void printTree() const
int getGeneratorFlag()
int getNDaug() const
EvtParticle * getDaug(int i)
int getChannel() const
std::string writeTreeRec(std::string) const
void deleteTree()
static double Flat()
Definition EvtRandom.cc:73
double mass() const
double get(int i) const
double d3mag() const
virtual void setGenseed(long)=0
virtual CLHEP::HepRandomEngine * GetEngine(const std::string &StreamName)=0
Interface to the CLHEP engine.
const double hc
Definition TConstant.h:41