BOSS 8.0.0
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
13// private version within 3.0.0) Sept 2003: James Catmore, adopted for 6.0.3 (not reeased
14// in 6.0.3 ony private version) to work inside PythiaBModule. Nov 2003: M.Smizanska, rewritten
15// a) to be standalone EvtDecay algorithm so it can be combined with any type of Pythia
16// generator b) to match to new LHCb(CDF) code dedicated to LHC, c) to work in 7.3.0. EvtDecay
17// first time released in 7.3.0 20.Nov. 2003 Dec 2003: M.Smizanska: define user's input -
18// decay table Feb 2004 J Catmore, addition of random seed facility. TEMPORARY FIX Oct 2005 A.
19// Zhemchugov, adapted for BES3 May 2006 K.L He, set spin density matrix for e+e- -> V
20// Sept.2007, R.G.Ping, change to the BesEvtGen Jan. 2008, R.G.Ping, to print McTruth table to
21// the file DecayTopology when only doing generation, not simulation Feb. 2008, R.G.Ping, add
22// an option to only run the BesEvtGen Mar. 2008, R.G. Ping, user options "DecayDecDir" and
23// "PdtTableDir" are changed. Mar. 2008-03, R.G. Ping, dump the user decay card to the bosslog
24// file
25//*****************************************************************************
26
27// Header for this module:-
28#include "EvtDecay.h"
29#include "EvtGen/EvtGen.hh"
42#include "ReadME.h"
43
44// Framework Related Headers:-
45#include "DataInfoSvc/IDataInfoSvc.h"
46#include "EventModel/EventHeader.h"
47#include "GaudiKernel/SmartDataPtr.h"
48#include "HepMC/GenEvent.h"
49#include "HepMC/GenParticle.h"
50#include "HepMC/GenVertex.h"
51// #include "DataInfoSvc/DataInfoSvc.h"
52// #include "GaudiKernel/AlgFactory.h"
53#include "GaudiKernel/DataSvc.h"
54#include "GaudiKernel/IPartPropSvc.h"
55#include "GaudiKernel/ISvcLocator.h"
56#include "GaudiKernel/MsgStream.h"
57#include "GaudiKernel/SmartDataPtr.h"
58
59#include "BesRndmGenSvc/IBesRndmGenSvc.h"
60#include "CLHEP/Random/RandFlat.h"
61#include "CLHEP/Random/Ranlux64Engine.h"
63#include "GeneratorObject/McGenEvent.h"
64
65#include <stdlib.h>
66#include <string.h>
67
68static string mydecayrec;
69static double _amps_max;
70int nchr = 0;
71int nchr_e = 0;
72int nchr_mu = 0;
73int nchr_pi = 0;
74int nchr_k = 0;
75int nchr_p = 0;
76int N_gamma = 0;
77int N_gammaFSR = 0;
78int fst[50];
79int EvtDecay::m_runNo = 0;
80// double EvtConExc::SetMthr = 0; // moved to EvtConExc.cc by mrli, 2024-08-26
81
82//////these three are allocate memory for EvtParticle //new modified
83// moved to EvtParticle.cc by mrli, 2024-08-26
84// int EvtParticle::_NextLevelDauNum = 0;
85// EvtId EvtParticle::_NextLevelId[20];
86// EvtVector4R EvtParticle::_NextLevelP4[20];
87
89
90EvtDecay::EvtDecay( const string& name, ISvcLocator* pSvcLocator )
91 : Algorithm( name, pSvcLocator ) {
92
93 // these can be used to specify alternative locations or filenames
94 // for the EvtGen particle and channel definition files.
95
96 declareProperty( "DecayDecDir", m_DecayDec = "" );
97 declareProperty( "PdtTableDir", m_PdtTable = "" );
98 declareProperty( "userDecayTableName", userDecFileName = "NONE" );
99 declareProperty( "DecayTopology",
100 m_DecayTop = "" ); // output decay topology to a file specified by user
101 declareProperty( "DecayRecord",
102 m_DecayRec = "" ); // output decay topology of one particle specified by
103 // user to a file
104 declareProperty( "ParentParticle",
105 m_ParentPart = "NONE" ); // Mothor particle name in pdt.table for only
106 // running BesEvtGen
107 declareProperty( "Multiplicity", m_Ncharge = false ); // output ncharge number of an event
108 declareProperty( "NutupleFile", m_NtupleFile = false ); // output Ntuple file
109 declareProperty( "mDIY", _mDIY = false ); // mDIY model
110 declareProperty( "FDPdata",
111 m_SB3File = "" ); // Fit Dalitz Plot (FDP) data file name (*.root)
112 declareProperty( "FDPHisT", m_SB3HT = "" ); // histogram title of Dalitz plot in data file
113 declareProperty( "FDPpart",
114 m_FDPparticle = "" ); // to assign the FDP parent particle name (string)
115 declareProperty( "TruthFile", m_truthFile = "" );
116 declareProperty( "TruthPart", m_truthPart = "" );
117 declareProperty( "Psi3SopenCharm", m_Psi4040OpenCharm = false );
118 declareProperty( "Psi2openCharm", m_Psi2openCharm = false );
119 declareProperty( "SetMthrForConExc", m_SetMthr = 0.0 );
120 declareProperty( "statDecays", m_statDecays = false );
121 declareProperty( "TagLundCharmModel", m_tagLundModel = false );
122 m_mystring.clear();
123 declareProperty( "FileForTrackGen", m_mystring );
124 // for polarized charmonium production
125 m_polarization.clear(); //= diag{1+Pe, 0, 1-Pe} with electron polarization Pe
126 declareProperty( "polarization", m_polarization );
127 declareProperty( "eBeamPolarization", m_eBeamPolarization = -1 );
128 m_cluster0.clear();
129 m_wind0.clear();
130 m_cluster1.clear();
131 m_wind1.clear();
132 m_cluster2.clear();
133 m_wind2.clear();
134 declareProperty( "cluster0", m_cluster0 );
135 declareProperty( "cluster1", m_cluster1 );
136 declareProperty( "cluster2", m_cluster2 );
137 declareProperty( "masswin0", m_wind0 );
138 declareProperty( "masswin1", m_wind1 );
139 declareProperty( "masswin2", m_wind2 );
140 declareProperty( "OutputP4", m_outputp4 = "" );
141 declareProperty( "ReadMeasuredEcms", m_RdMeasuredEcms = false );
142 declareProperty( "beamEnergySpread", m_beamEnergySpread = 0 );
143 m_ReadTruth.clear();
144 declareProperty( "ReadTruthAtCM", _truthAtCM = false );
145 declareProperty( "ReadTruth", m_ReadTruth );
146 // ReadTruth={{"ParentName"},{"i0","i1","i2"},{"j0","j1","j2","j3"}}, where the first part.
147 // is Parent->getDaug(i0)->getDaug(i1)->getDaug(i2), and second particle is Parent
148 // ->getDaug(j0)->getDaug(j1)->getDaug(j2)->getDaug(j3);
149 declareProperty( "RvalueTag", _RvalueTag = false );
150 declareProperty( "PrintFSFor", m_printfs = "" );
151}
152
154
155 MsgStream log( msgSvc(), name() );
156 // system("cat $BESEVTGENROOT/share/phokhara_9.1.fferr>phokhara_9.1.fferr");
157 // system("cat $BESEVTGENROOT/share/phokhara_9.1.ffwarn>phokhara_9.1.ffwarn");
158 system( "cat $BESEVTGENROOT/share/phokhara_10.0.fferr>phokhara_10.0.fferr" ); // modified by
159 // luojiashun
160 // 2022.2.21
161 system( "cat $BESEVTGENROOT/share/phokhara_10.0.ffwarn>phokhara_10.0.ffwarn" ); // modified
162 // by
163 // luojiashun
164 // 2022.2.21
165
166 if ( m_truthFile != "" ) { truth.open( m_truthFile.c_str() ); }
167 log << MSG::INFO << "EvtDecay initialize" << endmsg;
168 static const bool CREATEIFNOTTHERE( true );
169 StatusCode RndmStatus = service( "BesRndmGenSvc", p_BesRndmGenSvc, CREATEIFNOTTHERE );
170 if ( !RndmStatus.isSuccess() || 0 == p_BesRndmGenSvc )
171 {
172 log << MSG::ERROR << " Could not initialize Random Number Service" << endmsg;
173 return RndmStatus;
174 }
175
176 EvtGlobalSet::SV.clear();
177 for ( int i = 0; i < m_mystring.size(); i++ )
178 { EvtGlobalSet::SV.push_back( m_mystring[i] ); }
179
180 EvtGlobalSet::iVV.clear();
181 EvtGlobalSet::dVV.clear();
182 std::vector<std::vector<int>> myivv;
183 std::vector<std::vector<double>> mydvv;
184
185 EvtConExc::SetMthr = m_SetMthr;
186
187 myivv.push_back( m_cluster0 );
188 myivv.push_back( m_cluster1 );
189 myivv.push_back( m_cluster2 );
190
191 mydvv.push_back( m_wind0 );
192 mydvv.push_back( m_wind1 );
193 mydvv.push_back( m_wind2 );
194
195 for ( int i = 0; i < myivv.size(); i++ )
196 {
197 std::vector<int> theivv;
198 for ( int j = 0; j < myivv[i].size(); j++ ) { theivv.push_back( myivv[i][j] ); }
199 if ( theivv.size() ) EvtGlobalSet::iVV.push_back( theivv );
200 }
201
202 for ( int i = 0; i < mydvv.size(); i++ )
203 {
204 std::vector<double> thedvv;
205 for ( int j = 0; j < mydvv[i].size(); j++ ) { thedvv.push_back( mydvv[i][j] ); }
206 if ( thedvv.size() ) EvtGlobalSet::dVV.push_back( thedvv );
207 }
208
209 if ( m_eBeamPolarization > 1 )
210 {
211 std::cout << "The e-beam polaziation should be in 0 to 1" << std::endl;
212 abort();
213 }
214 m_numberEvent = 0;
215 first = true;
216 m_ampscalflag = true;
217 // Save the random number seeds in the event
218 CLHEP::HepRandomEngine* engine = p_BesRndmGenSvc->GetEngine( "EVTGEN" );
219 const long s = engine->getSeed();
220 p_BesRndmGenSvc->setGenseed( s + 1 );
221
222 m_seeds.clear();
223 m_seeds.push_back( s );
224 totalChannels = 0;
225
226 // open an interface to EvtGen
227
228 if ( m_DecayDec == "" )
229 { // use default DECAY.DEC and pdt.table if not defined by user
230 m_DecayDec = getenv( "BESEVTGENROOT" );
231 m_DecayDec += "/share/DECAY.DEC";
232 }
233
234 if ( m_PdtTable == "" )
235 {
236 m_PdtTable = getenv( "BESEVTGENROOT" );
237 m_PdtTable += "/share/pdt.table";
238 }
239
240 char catcmd[300]; // output user decay cards to log file
241 std::cout << "===================== user decay card ========================" << std::endl;
242 strcpy( catcmd, "cat " );
243 strcat( catcmd, userDecFileName.c_str() );
244 system( catcmd );
245
247
248 // write decay cards to the root file: pingrg@2009-09-09
249 StatusCode status;
250 status = service( "DataInfoSvc", dataInfoSvc );
251 if ( status.isSuccess() )
252 {
253 log << MSG::INFO << "got the DataInfoSvc" << endmsg;
254 dataInfoSvc->setDecayCard( userDecFileName );
255 }
256 else
257 {
258 log << MSG::ERROR << "could not get the DataInfoSvc" << endmsg;
259 return StatusCode::FAILURE;
260 }
261
262 m_RandomEngine = new EvtBesRandom( engine );
263 m_Gen = new EvtGen( m_DecayDec.c_str(), m_PdtTable.c_str(), m_RandomEngine );
264
265 if ( userDecFileName == "NONE" )
266 log << MSG::INFO << "EvtDecay User did not define his Decay table EvtGen will use standart"
267 << endmsg;
268 if ( !( userDecFileName == "NONE" ) ) m_Gen->readUDecay( userDecFileName.c_str() );
269
270 if ( !( m_DecayTop == " " ) ) { outfile.open( m_DecayTop.c_str() ); }
271
272 // for output Ntuple file, pingrg-2009-09-07
273
274 if ( m_NtupleFile )
275 {
276 NTuplePtr nt1( ntupleSvc(), "MYROOTFILE/Trk" );
277 if ( nt1 ) { m_tuple = nt1; }
278 else
279 {
280 m_tuple =
281 ntupleSvc()->book( "MYROOTFILE/Trk", CLID_ColumnWiseTuple, "Generator-trk-Ntuple" );
282 if ( m_tuple )
283 {
284 status = m_tuple->addItem( "TotNumTrk", TotNumTrk, 0, 100 );
285 status = m_tuple->addIndexedItem( "Trk_index", TotNumTrk, m_Trk_index );
286 status = m_tuple->addIndexedItem( "m_px_trk", TotNumTrk, m_px_trk );
287 status = m_tuple->addIndexedItem( "m_py_trk", TotNumTrk, m_py_trk );
288 status = m_tuple->addIndexedItem( "m_pz_trk", TotNumTrk, m_pz_trk );
289 status = m_tuple->addIndexedItem( "m_en_trk", TotNumTrk, m_en_trk );
290 status = m_tuple->addIndexedItem( "FST", TotNumTrk, m_fst );
291
292 status = m_tuple->addItem( "nchr", m_nchr );
293 status = m_tuple->addItem( "nchr_e", m_nchr_e );
294 status = m_tuple->addItem( "nchr_mu", m_nchr_mu );
295 status = m_tuple->addItem( "nchr_pi", m_nchr_pi );
296 status = m_tuple->addItem( "nchr_k", m_nchr_k );
297 status = m_tuple->addItem( "nchr_p", m_nchr_p );
298 status = m_tuple->addItem( "N_gamma", m_gamma );
299 status = m_tuple->addItem( "N_gammaFSR", m_gammaFSR );
300 status = m_tuple->addItem( "Flag1", m_flag1 );
301 }
302 else
303 {
304 log << MSG::ERROR << " Cannot book N-tuple:" << long( m_tuple ) << endmsg;
305 return StatusCode::FAILURE;
306 }
307 }
308
309 NTuplePtr nt2( ntupleSvc(), "MYROOTFILE/mass" );
310 if ( nt2 ) { mass_tuple = nt2; }
311 else
312 {
313 mass_tuple = ntupleSvc()->book( "MYROOTFILE/mass", CLID_ColumnWiseTuple,
314 "Generator-mass-Ntuple" );
315 if ( mass_tuple )
316 {
317 status = mass_tuple->addItem( "m12", m_m12 );
318 status = mass_tuple->addItem( "m13", m_m13 );
319 status = mass_tuple->addItem( "m23", m_m23 );
320 status = mass_tuple->addItem( "m1", m_m1 );
321 status = mass_tuple->addItem( "m2", m_m2 );
322 status = mass_tuple->addItem( "m3", m_m3 );
323 status = mass_tuple->addItem( "costheta1", m_cos1 );
324 status = mass_tuple->addItem( "costheta2", m_cos2 );
325 status = mass_tuple->addItem( "costheta3", m_cos3 );
326 status = mass_tuple->addItem( "ichannel", m_ich );
327 }
328 else
329 {
330 log << MSG::ERROR << " Cannot book N-tuple:" << long( m_tuple ) << endmsg;
331 return StatusCode::FAILURE;
332 }
333 }
334
335 NTuplePtr nt3( ntupleSvc(), "MYROOTFILE/massGen" );
336 if ( nt3 ) { massgen_tuple = nt3; }
337 else
338 {
339 massgen_tuple = ntupleSvc()->book( "MYROOTFILE/massGen", CLID_ColumnWiseTuple,
340 "Generator-mass-Ntuple" );
341 if ( massgen_tuple )
342 {
343 status = massgen_tuple->addItem( "m12", _m12 );
344 status = massgen_tuple->addItem( "m13", _m13 );
345 status = massgen_tuple->addItem( "m23", _m23 );
346 status = massgen_tuple->addItem( "m1", _m1 );
347 status = massgen_tuple->addItem( "m2", _m2 );
348 status = massgen_tuple->addItem( "m3", _m3 );
349 status = massgen_tuple->addItem( "costheta1", _cos1 );
350 status = massgen_tuple->addItem( "costheta2", _cos2 );
351 status = massgen_tuple->addItem( "costheta3", _cos3 );
352 status = massgen_tuple->addItem( "ichannel", _ich );
353 }
354 else
355 {
356 log << MSG::ERROR << " Cannot book N-tuple:" << long( m_tuple ) << endmsg;
357 return StatusCode::FAILURE;
358 }
359 }
360 }
361 for ( int i = 0; i < 500; i++ ) { br[i] = 0; }
362 if ( !( m_SB3File == "" && m_SB3HT == "" ) )
363 {
364 const char *filename, *histitle;
365 filename = (char*)m_SB3File.c_str();
366 histitle = (char*)m_SB3HT.c_str();
367 SuperBody3decay.setFile( filename );
368 SuperBody3decay.setHTitle( histitle );
369 SuperBody3decay.init();
370 }
371
372 return StatusCode::SUCCESS;
373}
374
375StatusCode EvtDecay::execute() {
376 // new Added
377 EvtParticle::_NextLevelDauNum = 0; //////////add for Model:FromParent
378
379 MsgStream log( msgSvc(), name() );
380 // log << MSG::INFO << "EvtDecay executing" << endmsg;
381 //------------------
382 string key = "GEN_EVENT";
383 // retrieve event from Transient Store (Storegate)
384 SmartDataPtr<McGenEventCol> McEvtColl( eventSvc(), "/Event/Gen" );
385
386 m_numberEvent += 1;
387 writeFlag = 0;
388 if ( McEvtColl == 0 )
389 {
390 // std::cout<<"McEvtColl == 0 INFO: Using the callBesEvtGen!!"<<std::endl;
391 HepMC::GenEvent* evt = new GenEvent();
392 evt->set_event_number( m_numberEvent );
393
394 // read Ecms from the database
395 SmartDataPtr<Event::EventHeader> eventHeader( eventSvc(), "/Event/EventHeader" );
396 int runNo = eventHeader->runNumber();
397 int event = eventHeader->eventNumber();
398 bool newRunFlag = 0;
399 if ( runNo != 0 && runNo != m_runNo )
400 {
401 m_runNo = runNo;
402 newRunFlag = true;
403 }
404 else { newRunFlag = false; }
405 if ( m_RdMeasuredEcms && newRunFlag )
406 { // using cms energy of beam read from database
407 runNo = std::abs( runNo );
408 ReadME theME( runNo );
409 if ( theME.isRunNoValid() )
410 {
411 dbEcms = theME.getEcms();
412 std::cout << "Read Ecms= " << dbEcms << std::endl;
413 if ( dbEcms != 0 ) { std::cout << "INFO: Read the MeasuredEcms" << std::endl; }
414 else
415 {
416 std::cout << "ERROR: Can not read the MeasuredEcms, try to turn off the ReadEcmsDB"
417 << std::endl;
418 return StatusCode::FAILURE;
419 }
420 }
421 }
422 // end of read Ecms
423
424 callBesEvtGen( evt );
425 if ( !( m_DecayTop == "" ) ) evt->print( outfile );
426
427 // create a Transient store
428 McGenEventCol* mcColl = new McGenEventCol;
429 McGenEvent* mcEvent = new McGenEvent( evt );
430 mcColl->push_back( mcEvent );
431 StatusCode sc = eventSvc()->registerObject( "/Event/Gen", mcColl );
432 if ( sc != StatusCode::SUCCESS ) return StatusCode::FAILURE;
433 }
434 else // (McEvtColl != 0)
435 {
436
437 // std::cout<<"McEvtColl == 1 INFO: Using the callEvtGen!!"<<std::endl;
438 McGenEventCol::iterator mcItr;
439 for ( mcItr = McEvtColl->begin(); mcItr != McEvtColl->end(); mcItr++ )
440 {
441 HepMC::GenEvent* hEvt = ( *mcItr )->getGenEvt();
442 // MeVToGeV( hEvt );
443
444 callEvtGen( hEvt );
445
446 if ( !( m_DecayTop == "" ) ) hEvt->print( outfile );
447 // GeVToMeV( hEvt );
448 // if(!(m_DecayRec=="")) outfile2<<std::endl;
449 if ( !( m_DecayRec == "" ) ) std::cout << std::endl;
450 };
451 }
452 if ( m_NtupleFile ) { m_tuple->write(); }
453
454 if ( _mDIY )
455 {
456 std::cout << "helangs ";
457 for ( int i = 0; i < m_vangs.size(); i++ ) std::cout << m_vangs[i] << " ";
458 std::cout << std::endl;
459 }
460 return StatusCode::SUCCESS;
461}
462
463// main procedure, loops over all particles in given event,
464// converts them to EvtGenParticles,
465// feeds them to EvtGen,
466// converts back to HepMC particles and puts them in the event.
467
468StatusCode EvtDecay::callEvtGen( HepMC::GenEvent* hepMCevt ) {
469 MsgStream log( msgSvc(), name() );
470 nchr = 0;
471 nchr_e = 0;
472 nchr_mu = 0;
473 nchr_pi = 0;
474 nchr_k = 0;
475 nchr_p = 0;
476 N_gamma = 0;
477 N_gammaFSR = 0;
478 SmartDataPtr<Event::EventHeader> eventHeader( eventSvc(), "/Event/EventHeader" );
479
480 for ( int i = 0; i < 13; i++ ) fst[i] = 0;
481 HepMC::GenEvent::particle_const_iterator itp;
482 AllTrk_index = 0;
483
484 for ( itp = hepMCevt->particles_begin(); itp != hepMCevt->particles_end(); itp++ )
485 {
486 // This is the main loop.
487 // We iterate over particles and we look for ones that
488 // should be decayed with EvtGen.
489 //
490 // status == 1 - undecayed Pythia particle (also for particles that are not supposed to
491 // decay) status == 999 - particle already decayed by EvtGen status == 899 - particle
492 // was supposed to decay by EvtGen - but found no model
493 // this may be also intentional - such events are then excluded from
494 // being written into persistent output.
495 // ISTHEP(IHEP):
496 // status code for entry IHEP, with the following meanings:
497 //
498 // = 0 : null entry.
499 // = 1 : an existing entry, which has not decayed or fragmented. This is the main class of
500 // entries, which represents the `final state' given by the generator. = 2 : an entry
501 // which has decayed or fragmented and is therefore not appearing in the final state, but
502 // is retained for event history information. = 3 : a documentation line, defined
503 // separately from the event history. This could include the two incoming reacting
504 // particles, etc. = 4 - 10 : undefined, but reserved for future standards. = 11 - 200 :
505 // at the disposal of each model builder for constructs specific to his program, but
506 // equivalent to a null line in the context of any other program. = 201 - : at the
507 // disposal of users, in particular for event tracking in the detector.
508
509 HepMC::GenParticle* hepMCpart = *itp;
510 int stat = hepMCpart->status();
511
512 if ( stat != 1 ) continue;
513
514 loop_to_select_eventsB:
515 int id = hepMCpart->pdg_id();
516 parentPDGcode = id;
517 hepMCpart->set_status( 899 );
518 EvtId eid = EvtPDL::evtIdFromStdHep( id );
519 string parentName = EvtPDL::name( eid );
520
521 double en = ( hepMCpart->momentum() ).e();
522 double pex = ( hepMCpart->momentum() ).px();
523 double pey = ( hepMCpart->momentum() ).py();
524 double pez = ( hepMCpart->momentum() ).pz();
525
526 EvtVector4R p_init( en, pex, pey, pez );
527 parentMass = p_init.mass();
528 EvtPDL::reSetMass( eid, parentMass );
529
531
532 // set spin density matrix for e+ e- -> V
533 bool parentFlag = false;
534 if ( writeFlag == 0 && part->getSpinType() == EvtSpinType::VECTOR )
535 {
536 if ( m_polarization.size() > 0 )
537 {
538 part->setPolarizedSpinDensity( m_polarization[0], m_polarization[1],
539 m_polarization[2] );
540 }
541 else if ( m_eBeamPolarization > 0 )
542 { part->setPolarizedSpinDensity( 1 + m_eBeamPolarization, 0, 1 - m_eBeamPolarization ); }
543 else { part->setVectorSpinDensity(); }
544 parentFlag = true;
545 writeFlag++;
546 }
547 else
548 {
549 int id = hepMCpart->pdg_id();
550 if ( id == 22 )
551 {
552 N_gamma++;
553 fst[0]++;
554 } // fst[0]:photon
555 if ( id == -22 ) { N_gammaFSR++; }
556 if ( id == 11 ) { fst[1]++; }
557 else if ( id == -11 ) { fst[2]++; } // fst[1]: electron ; fst[]: positron
558 else if ( id == 13 ) { fst[3]++; } // fst[3]: mu-
559 else if ( id == -13 ) { fst[4]++; } // fst[4]: mu+
560 else if ( id == 211 ) { fst[5]++; } // fst[5]: pi+
561 else if ( id == -211 ) { fst[6]++; } // fst[6]: pi-
562 else if ( id == 321 ) { fst[7]++; } // fst[7]: K+
563 else if ( id == -321 ) { fst[8]++; } // fst[8]: K-
564 else if ( id == 2212 ) { fst[9]++; } // fst[9]: pronton
565 else if ( id == -2212 ) { fst[10]++; } // fst[10]: anti-proton
566 else if ( id == 2112 ) { fst[11]++; } // fst[11]: nucleon
567 else if ( id == -2112 ) { fst[12]++; } // fst[12]: ant-nucleon
568 if ( fabs( id ) == 11 ) { nchr_e++; }
569 if ( fabs( id ) == 13 ) { nchr_mu++; }
570 if ( fabs( id ) == 211 ) { nchr_pi++; }
571 if ( fabs( id ) == 321 ) { nchr_k++; }
572 if ( fabs( id ) == 2212 ) { nchr_p++; }
573
574 // std::cout<<"id= "<<id<<" AllTrk_index= "<<AllTrk_index<<std::endl;
575 if ( m_NtupleFile == true )
576 {
577 m_Trk_index[AllTrk_index] = id;
578 m_px_trk[AllTrk_index] = pex;
579 m_py_trk[AllTrk_index] = pey;
580 m_pz_trk[AllTrk_index] = pez;
581 m_en_trk[AllTrk_index] = en;
582
583 AllTrk_index++;
584 Trk_index[AllTrk_index] = 0;
585 }
586 }
587
588 // for SuperBody3decay generator
589 // EvtVector4R pd1,pd2,pd3;
590 EvtVector4R fdp_init;
591 EvtId fdp_ppid;
592 if ( m_FDPparticle != "" )
593 {
594 findPart( part );
595 fdp_ppid = FDP_id;
596 fdp_init = FDP_init;
597 }
598 else
599 {
600 fdp_ppid = eid;
601 fdp_init = p_init;
602 }
603
604 if ( !( m_SB3File == "" || m_SB3HT == "" ) && parentFlag && first )
605 { SuperBody3decay_make( fdp_ppid, fdp_init ); }
606
607 loop_to_select_eventsA:
608 m_Gen->generateDecay( part );
609 if ( m_truthFile != "" && m_truthPart != "" )
610 {
611 if ( EvtPDL::name( part->getId() ) == m_truthPart )
612 {
613 int ndaug = part->getNDaug();
614 for ( int id = 0; id < ndaug; id++ )
615 {
616 EvtParticle* sonp = part->getDaug( id );
617 EvtVector4R son = sonp->getP4();
618 truth << son.get( 0 ) << " " << son.get( 1 ) << " " << son.get( 2 ) << " "
619 << son.get( 3 ) << std::endl;
620 }
621 }
622 }
623 double ratio, rdm;
624 if ( _mDIY && parentFlag && m_ampscalflag ) _amps_max = CalAmpsMax( part );
625 if ( _mDIY && parentFlag )
626 {
627 rdm = EvtRandom::Flat( 0.0, 1.0 );
628 double amps = CalAmpsMDIY( part );
629 ratio = amps / _amps_max;
630 }
631 if ( _mDIY && parentFlag && ratio <= rdm ) { goto loop_to_select_eventsA; }
632
633 // std::cout<<"m_vangs.size= "<<m_vangs.size()<<std::endl;
634 //-------- For superbody3------------------------------
635 bool accept;
636 if ( m_FDPparticle == "" ) { FDP_part = part; }
637 if ( !( m_SB3File == "" || m_SB3HT == "" ) && parentFlag )
638 { accept = SuperBody3decay_judge( FDP_part ); }
639 if ( !( m_SB3File == "" || m_SB3HT == "" ) && parentFlag && !accept )
640 {
641 part->deleteTree();
642 writeFlag = 0;
643 goto loop_to_select_eventsB;
644 }
645 else if ( !( m_SB3File == "" || m_SB3HT == "" ) && parentFlag && accept )
646 { countChannel( FDP_part ); }
647 //-------- for psi4040 open charm inclusive decay
648 if ( ( m_Psi2openCharm || m_Psi4040OpenCharm ) && parentFlag )
649 {
650 if ( getModel( part ) == "OPENCHARM" )
651 {
652 std::cout
653 << "OPENCHARM model need to set Psi2openCharm and Psi3SopenCharm to be false!"
654 << std::endl;
655 abort();
656 }
657 EvtPsi3Sdecay opencharm( en, part );
658 bool theDecay = opencharm.choseDecay();
659 if ( !theDecay )
660 {
661 part->deleteTree();
662 writeFlag = 0;
663 goto loop_to_select_eventsB;
664 }
665 }
666 //------------- dump the decay tree to the event model
667 // if(Nchannel>=0) part->dumpTree();
668 // part->printTree();
669
670 if ( parentFlag )
671 {
672 EvtDecayTag theTag( part );
673 unsigned int modeTag, multiplicityTag;
674 modeTag = theTag.getModeTag();
675 if ( getModel( part ) == "OPENCHARM" ||
676 getModel( part ) == "LUNDCHARM" && m_tagLundModel )
677 {
678 multiplicityTag = decayType( part );
679 // debugging
680 // std::cout<<"Opencharm Mode: "<<decayType(part)<<std::endl;
681 }
682 else { multiplicityTag = theTag.getMultTag() + decayType( part ); }
683
684 // std::cout<<"StdHep= "<<EvtPDL::getStdHep(part->getId())<<" getChannel
685 // "<<part->getChannel()<<" flag1,flag2=
686 // "<<modeTag<<" "<<multiplicityTag<<std::endl;
687 if ( eventHeader == 0 ) std::cout << "event header unavailable: " << std::endl;
688 if ( eventHeader != 0 )
689 {
690 eventHeader->setFlag1( modeTag );
691 eventHeader->setFlag2( multiplicityTag );
692 // std::cout<<"flag1,flag2= "<<modeTag<<" "<<multiplicityTag<<std::endl;
693 }
694 }
695
696 if ( !( m_DecayRec == "" ) ) mydecayrec = part->writeTreeRec( m_DecayRec );
697 //-- decay statistics
698 if ( m_statDecays && parentFlag ) countChannel( part );
699 // ----------- pingrg 2008-03-25 ---------
700
701 if ( log.level() <= MSG::DEBUG ) part->printTree();
702 log << MSG::DEBUG << "Converting particles to HepMC" << endmsg;
703
704 makeHepMC( part, hepMCevt, hepMCpart );
705 if ( part->getNDaug() != 0 ) hepMCpart->set_status( 999 );
706
707 // debug
708
709 if ( part->getId() == EvtPDL::getId( m_outputp4 ) )
710 {
711 int nds = part->getNDaug();
712 for ( int i = 0; i < nds; i++ )
713 {
714 if ( EvtPDL::name( part->getDaug( i )->getId() ) == "gammaFSR" ) continue;
715 EvtVector4R vp1 = part->getDaug( i )->getP4Lab();
716 std::cout << "vvpp " << vp1.get( 0 ) << " " << vp1.get( 1 ) << " " << vp1.get( 2 )
717 << " " << vp1.get( 3 ) << std::endl;
718 }
719 }
720
721 if ( m_ReadTruth.size() ) ReadTruth( part, m_ReadTruth );
722 // if(part->getId()==EvtPDL::getId("psi(4260)")) std::cout<<"mydebug
723 // "<<part->getP4().mass()<<std::endl;
724 part->deleteTree();
725 };
726
727 for ( itp = hepMCevt->particles_begin(); itp != hepMCevt->particles_end(); ++itp )
728 {
729 if ( !( *itp )->end_vertex() &&
730 ( ( *itp )->status() == 899 || ( *itp )->status() == 999 ) )
731 ( *itp )->set_status( 1 );
732 }
733 // nchr = nchr_e + nchr_mu + nchr_pi + nchr_k +nchr_p;
735 if ( m_Ncharge == true )
736 {
737 std::cout << "Multiplicity: TotoalCharge_e_mu_pi_K_p_gamma_gammaFSR: " << nchr << " "
738 << nchr_e << " " << nchr_mu << " " << nchr_pi << " " << nchr_k << " " << nchr_p
739 << " " << N_gamma << " " << N_gammaFSR << endl;
740 }
741 if ( m_Ncharge == true )
742 {
743 std::cout << "FinalStates: " << fst[0] << " " << fst[1] << " " << fst[2] << " " << fst[3]
744 << " " << fst[4] << " " << fst[5] << " " << fst[6] << " " << fst[7] << " "
745 << fst[8] << " " << fst[9] << " " << fst[10] << " " << fst[11] << " " << fst[12]
746 << std::endl;
747 }
748 if ( m_NtupleFile )
749 {
750 // TotNumTrk=500;
751 m_nchr = nchr;
752 m_nchr_e = nchr_e;
753 m_nchr_mu = nchr_mu;
754 m_nchr_pi = nchr_pi;
755 m_nchr_k = nchr_k;
756 m_nchr_p = nchr_p;
757 m_gamma = N_gamma;
758 m_gammaFSR = N_gammaFSR;
759 TotNumTrk = AllTrk_index; // nchr + N_gamma + N_gammaFSR;
760 }
761 // std::cout<<"Flag= "<<eventHeader->flag1()<<" "<<eventHeader->flag2()<<std::endl;
762
763 return StatusCode::SUCCESS;
764}
765
766//****** CallBesEvtGen ************
767// This part is responsible for only ruuing BesEvtGen. //pingrg Feb. 3,2008
768//***************************************************
769StatusCode EvtDecay::callBesEvtGen( HepMC::GenEvent* hepMCevt ) {
770 MsgStream log( msgSvc(), name() );
771
772 nchr = -1;
773 nchr_e = 0;
774 nchr_mu = 0;
775 nchr_pi = 0;
776 nchr_k = 0;
777 nchr_p = 0;
778 N_gamma = 0;
779 N_gammaFSR = 0;
780 SmartDataPtr<Event::EventHeader> eventHeader( eventSvc(), "/Event/EventHeader" );
781 for ( int i = 0; i < 13; i++ ) fst[i] = 0;
782 HepMC::GenEvent::particle_const_iterator itp;
783 // This is the main loop.
784 // We iterate over particles and we look for ones that
785 // should be decayed with EvtGen.
786 //
787 // status == 1 - undecayed Pythia particle (also for particles that are not supposed to
788 // decay) status == 999 - particle already decayed by EvtGen status == 899 - particle was
789 // supposed to decay by EvtGen - but found no model
790 // this may be also intentional - such events are then excluded from
791 // being written into persistent output.
792 // ISTHEP(IHEP):
793 // status code for entry IHEP, with the following meanings:
794 //
795 // = 0 : null entry.
796 // = 1 : an existing entry, which has not decayed or fragmented. This is the main class of
797 // entries, which represents the `final state' given by the generator. = 2 : an entry which
798 // has decayed or fragmented and is therefore not appearing in the final state, but is
799 // retained for event history information. = 3 : a documentation line, defined separately
800 // from the event history. This could include the two incoming reacting particles, etc. = 4
801 // - 10 : undefined, but reserved for future standards. = 11 - 200 : at the disposal of each
802 // model builder for constructs specific to his program, but equivalent to a null line in
803 // the context of any other program. = 201 - : at the disposal of users, in particular for
804 // event tracking in the detector.
805
806loop_to_select_eventsB:
807 EvtId ppid = EvtPDL::getId( m_ParentPart ); // parent particle name
808 double ppmass = 0;
809 if ( m_RdMeasuredEcms && m_beamEnergySpread == 0 )
810 { // read Ecms, no energy spread
811 EvtPDL::reSetMass( ppid, dbEcms );
812 ppmass = EvtPDL::getMass( ppid );
813 }
814 else if ( m_RdMeasuredEcms && m_beamEnergySpread != 0 )
815 { // read Ecms, with nergy spread
816 double cmssig = sqrt( 2. ) * m_beamEnergySpread;
817 double myppmass = energySpread( dbEcms, cmssig );
818 EvtPDL::reSetMass( ppid, myppmass );
819 ppmass = EvtPDL::getMass( ppid );
820 }
821 else if ( ( !m_RdMeasuredEcms ) && m_beamEnergySpread != 0 )
822 { // not read Ecms, with energy spread
823 if ( m_numberEvent == 1 ) dbEcms = EvtPDL::getMass( ppid );
824 double cmssig = sqrt( 2. ) * m_beamEnergySpread;
825 double myppmass = energySpread( dbEcms, cmssig );
826 EvtPDL::reSetMass( ppid, myppmass );
827 ppmass = EvtPDL::getMass( ppid );
828 }
829 else if ( ( !m_RdMeasuredEcms ) && m_beamEnergySpread == 0 )
830 { // not read Ecms, no energy spread
831 ppmass = EvtPDL::getMass( ppid );
832 }
833 else
834 {
835 std::cout << "EvtDecay::callBesEvtGen:: bad option" << std::endl;
836 abort();
837 }
838
839 // std::cout<<"testMass "<<ppmass<<std::endl;
840 // using Ecms from data base, for XYZ data sets
841 parentMass = ppmass;
842 int pid = EvtPDL::getStdHep( ppid );
843 parentPDGcode = pid;
844
845 EvtVector4R p_init( ppmass, 0.0, 0.0, 0.0 );
846
847 EvtParticle* part = EvtParticleFactory::particleFactory( ppid, p_init );
848 HepMC::GenParticle* hepMCpart =
849 new GenParticle( HepLorentzVector( 0, 0, 0, ppmass ), pid, 3 );
850
851 bool parentFlag = false;
852 // set spin density matrix for e+ e- -> V
853 if ( writeFlag == 0 && part->getSpinType() == EvtSpinType::VECTOR )
854 {
855 if ( m_polarization.size() > 0 )
856 {
857 part->setPolarizedSpinDensity( m_polarization[0], m_polarization[1], m_polarization[2] );
858 }
859 else if ( m_eBeamPolarization > 0 )
860 { part->setPolarizedSpinDensity( 1 + m_eBeamPolarization, 0, 1 - m_eBeamPolarization ); }
861 else { part->setVectorSpinDensity(); }
862 parentFlag = true;
863 writeFlag++;
864 }
865
866 // for SuperBody3decay generator
867 EvtVector4R fdp_init;
868 EvtId fdp_ppid;
869 if ( m_FDPparticle != "" )
870 {
871 findPart( part );
872 fdp_ppid = FDP_id;
873 fdp_init = FDP_init;
874 }
875 else
876 {
877 fdp_ppid = ppid;
878 fdp_init = p_init;
879 }
880
881 if ( !( m_SB3File == "" || m_SB3HT == "" ) && first )
882 { SuperBody3decay_make( fdp_ppid, fdp_init ); }
883 // -----------------------------------
884
885loop_to_select_events:
886 m_Gen->generateDecay( part );
887 if ( m_numberEvent <= 1 )
888 {
889 std::cout << "after m_Gen->decay " << std::endl;
890 part->printTree();
891 }
892
893 double ratio, rdm;
894 if ( _mDIY && m_ampscalflag ) _amps_max = CalAmpsMax( part );
895
896 if ( _mDIY )
897 {
898 for ( int myloop = 0; myloop < 100; myloop++ )
899 {
900 m_Gen->generateDecay( part );
901 double amps = CalAmpsMDIY( part );
902 ratio = amps / _amps_max;
903 rdm = EvtRandom::Flat( 0.0, 1.0 );
904 if ( !isNumber( amps ) || !isNumber( _amps_max ) || ratio <= 0 )
905 {
906 part->deleteTree();
907 part = EvtParticleFactory::particleFactory( ppid, p_init );
908 continue;
909 }
910 else if ( rdm <= ratio ) { break; }
911 }
912 }
913
914 if ( m_truthFile != "" && m_truthPart != "" )
915 {
916 if ( EvtPDL::name( part->getId() ) == m_truthPart )
917 {
918 int ndaug = part->getNDaug();
919 for ( int id = 0; id < ndaug; id++ )
920 {
921 EvtParticle* sonp = part->getDaug( id );
922 EvtVector4R son = sonp->getP4();
923 truth << son.get( 0 ) << " " << son.get( 1 ) << " " << son.get( 2 ) << " "
924 << son.get( 3 ) << std::endl;
925 }
926 }
927 }
928 //--------- For superbody3
929 bool accept;
930 if ( m_FDPparticle == "" ) { FDP_part = part; }
931 if ( !( m_SB3File == "" || m_SB3HT == "" ) ) { accept = SuperBody3decay_judge( FDP_part ); }
932 if ( !( m_SB3File == "" || m_SB3HT == "" ) && !accept )
933 {
934 delete hepMCpart;
935 part->deleteTree();
936 goto loop_to_select_eventsB;
937 }
938 else if ( !( m_SB3File == "" || m_SB3HT == "" ) && parentFlag && accept )
939 { countChannel( FDP_part ); }
940
941 int Nchannel = part->getChannel();
942
943 if ( m_statDecays && parentFlag ) countChannel( part );
944 //------------- dump the decay tree to the event model
945 // int Nchannel=part->getChannel();
946 // if(Nchannel>=0) part->dumpTree();
947
948 if ( parentFlag )
949 {
950 EvtDecayTag theTag( part );
951 unsigned int modeTag, multiplicityTag;
952 modeTag = theTag.getModeTag();
953 if ( getModel( part ) == "OPENCHARM" || getModel( part ) == "LUNDCHARM" && m_tagLundModel )
954 {
955 multiplicityTag = decayType( part );
956 // debugging
957 // std::cout<<"Opencharm Mode: "<<decayType(part)<<std::endl;
958 }
959 else if ( _RvalueTag ) { multiplicityTag = decayType( part ); }
960 else { multiplicityTag = theTag.getMultTag() + decayType( part ); }
961 if ( eventHeader == 0 ) std::cout << "event header unavailable: " << std::endl;
962 if ( eventHeader != 0 )
963 {
964 eventHeader->setFlag1( modeTag );
965 eventHeader->setFlag2( multiplicityTag );
966 }
967 // debugg
968 // std::cout<<modeTag<<" "<<multiplicityTag<<std::endl;
969 if ( m_NtupleFile ) m_flag1 = modeTag;
970 // std::cout<<"Flag1 "<<modeTag<<std::endl;
971 }
972
973 if ( !( m_DecayRec == "" ) )
974 {
975 mydecayrec = part->writeTreeRec( m_DecayRec );
976 std::cout << std::endl;
977 };
978 // ----------- pingrg 2008-03-25 ---------
979
980 if ( log.level() <= MSG::DEBUG ) part->printTree();
981 log << MSG::DEBUG << "Converting particles to HepMC" << endmsg;
982
983 makeHepMC( part, hepMCevt, hepMCpart );
984
985 if ( part->getNDaug() != 0 ) hepMCpart->set_status( 999 );
986
987 //-------------
988 if ( EvtPDL::getId( m_printfs ) == part->getId() )
989 {
990 int myd = part->getNDaug();
991 std::cout << "_FinalState " << myd;
992 for ( int ii = 0; ii < myd; ii++ )
993 { std::cout << " " << EvtPDL::name( part->getDaug( ii )->getId() ); }
994 std::cout << std::endl;
995 }
996
997 AllTrk_index = 0;
998 for ( itp = hepMCevt->particles_begin(); itp != hepMCevt->particles_end(); ++itp )
999 {
1000 if ( !( *itp )->end_vertex() &&
1001 ( ( *itp )->status() == 899 || ( *itp )->status() == 999 ) )
1002 ( *itp )->set_status( 1 );
1003
1004 HepMC::GenParticle* hepMCpart = *itp;
1005 int stat = hepMCpart->status();
1006 int id = hepMCpart->pdg_id();
1007 if ( abs( id ) == 411 || abs( id ) == 413 )
1008 {
1009 ( *itp )->set_status( 999 );
1010 stat = 999;
1011 }
1012
1013 if ( stat != 1 ) continue;
1014 if ( id == 22 )
1015 {
1016 N_gamma++;
1017 fst[0]++;
1018 }
1019 if ( id == -22 ) { N_gammaFSR++; }
1020 if ( id == 11 ) { fst[1]++; }
1021 else if ( id == -11 ) { fst[2]++; }
1022 else if ( id == 13 ) { fst[3]++; }
1023 else if ( id == -13 ) { fst[4]++; }
1024 else if ( id == 211 ) { fst[5]++; }
1025 else if ( id == -211 ) { fst[6]++; }
1026 else if ( id == 321 ) { fst[7]++; }
1027 else if ( id == -321 ) { fst[8]++; }
1028 else if ( id == 2212 ) { fst[9]++; }
1029 else if ( id == -2212 ) { fst[10]++; }
1030 else if ( id == 2112 ) { fst[11]++; }
1031 else if ( id == -2112 ) { fst[12]++; }
1032 if ( fabs( id ) == 11 ) { nchr_e++; }
1033 if ( fabs( id ) == 13 ) { nchr_mu++; }
1034 if ( fabs( id ) == 211 ) { nchr_pi++; }
1035 if ( fabs( id ) == 321 ) { nchr_k++; }
1036 if ( fabs( id ) == 2212 ) { nchr_p++; }
1037
1038 // for Nuple
1039 double en = ( hepMCpart->momentum() ).e();
1040 double pex = ( hepMCpart->momentum() ).px();
1041 double pey = ( hepMCpart->momentum() ).py();
1042 double pez = ( hepMCpart->momentum() ).pz();
1043
1044 if ( m_NtupleFile == true && id != 0 )
1045 {
1046 m_Trk_index[AllTrk_index] = id;
1047 m_px_trk[AllTrk_index] = pex;
1048 m_py_trk[AllTrk_index] = pey;
1049 m_pz_trk[AllTrk_index] = pez;
1050 m_en_trk[AllTrk_index] = en; /*
1051 std::cout<<"trk# " <<AllTrk_index
1052 <<" PID:" <<id
1053 <<" px: " <<pex
1054 <<" py: " <<pey
1055 <<" pz: " <<pez
1056 <<" E: " <<en<<std::endl; */
1057 AllTrk_index++;
1058 }
1059 }
1060
1061 itp = hepMCevt->particles_begin(); // parent decaying particle status set
1062 ( *itp )->set_status( 2 );
1063
1064 // nchr = nchr_e + nchr_mu + nchr_pi + nchr_k +nchr_p;
1065 nchr = nchr_pi + nchr_k + nchr_p;
1066 if ( m_Ncharge == true )
1067 {
1068 std::cout << "Multiplicity: TotoalCharge_e_mu_pi_K_p_gamma_gammaFSR: " << nchr << " "
1069 << nchr_e << " " << nchr_mu << " " << nchr_pi << " " << nchr_k << " " << nchr_p
1070 << " " << N_gamma << " " << N_gammaFSR << endl;
1071 }
1072 if ( m_Ncharge == true )
1073 {
1074 std::cout << "FinalStates: " << fst[0] << " " << fst[1] << " " << fst[2] << " " << fst[3]
1075 << " " << fst[4] << " " << fst[5] << " " << fst[6] << " " << fst[7] << " "
1076 << fst[8] << " " << fst[9] << " " << fst[10] << " " << fst[11] << " " << fst[12]
1077 << std::endl;
1078 }
1079
1080 // if(nchr==3) part->printTree();
1081 if ( m_NtupleFile )
1082 {
1083 m_nchr = nchr;
1084 m_nchr_e = nchr_e;
1085 m_nchr_mu = nchr_mu;
1086 m_nchr_pi = nchr_pi;
1087 m_nchr_k = nchr_k;
1088 m_nchr_p = nchr_p;
1089 m_gamma = N_gamma;
1090 m_gammaFSR = N_gammaFSR;
1091 TotNumTrk = AllTrk_index; // nchr + N_gamma + N_gammaFSR;
1092 }
1093
1094 // debug
1095 if ( m_ReadTruth.size() ) ReadTruth( part, m_ReadTruth );
1096
1097 // if(part->getId()==EvtPDL::getId("psi(4260)")) std::cout<<"mydebug
1098 // "<<part->getP4().mass()<<std::endl;
1099
1100 part->deleteTree();
1101 return StatusCode::SUCCESS;
1102}
1103
1104//************ end of callBesEvtGen *********************
1106
1107 if ( EvtCalHelAmp::nevt > 0 )
1108 {
1109 double H2 = EvtCalHelAmp::_H2;
1110 double H1 = EvtCalHelAmp::_H1;
1111 double H0 = EvtCalHelAmp::_H0;
1112 double H2err = EvtCalHelAmp::_H2err;
1113 double H1err = EvtCalHelAmp::_H1err;
1114 double H0err = EvtCalHelAmp::_H0err;
1115 int nd = EvtCalHelAmp::nevt;
1116 std::cout << "Calculated helicity amplitude sqaured are:" << std::endl;
1117 std::cout << "|H_{2}|^2=|H_{-2}|^2= " << H2 / nd << " +/- " << sqrt( H2err / nd ) << endl;
1118 std::cout << "|H_{1}|^2=|H_{-1}|^2= " << H1 / nd << " +/- " << sqrt( H1err / nd ) << endl;
1119 // std::cout<<"|H_{0}|^2= "<<H0/nd <<" +/- "<<sqrt(H0err/nd)<<endl;
1120 }
1121 MsgStream log( msgSvc(), name() );
1122 truth.close();
1123 log << MSG::INFO << "EvtDecay finalized" << endmsg;
1124 fstream Forfile;
1125 Forfile.open( "fort.16", ios::in );
1126 char delcmd[300];
1127 strcpy( delcmd, "rm -f " );
1128 strcat( delcmd, "fort.16" );
1129 // if(Forfile)system(delcmd);
1130
1131 fstream Forfile2;
1132 Forfile2.open( "fort.22", ios::in );
1133 strcpy( delcmd, "rm -f " );
1134 strcat( delcmd, "fort.22" );
1135 // if(Forfile2)system(delcmd);
1136
1137 // To get the branching fraction of the specified mode in Lundcharm Model
1138 /*
1139 EvtLundCharm lundcharmEvt;
1140 int nevt=lundcharmEvt.getTotalEvt();
1141 std::cout<<"The total number of the specified mode is "<<nevt<<std::endl;
1142 */
1143 int totalEvt = 0;
1144 if ( !( m_SB3File == "" || m_SB3HT == "" ) )
1145 {
1146 for ( int i = 0; i < 500; i++ ) { totalEvt = totalEvt + br[i]; }
1147 for ( int i = 0; i < 500; i++ )
1148 {
1149 double bi = 1.0 * br[i] / totalEvt;
1150 std::cout << "Branching fraction of channel " << i << " is: " << bi << std::endl;
1151 if ( br[i] == 0 ) break;
1152 }
1153 }
1154
1155 if ( m_statDecays )
1156 {
1157 int totalEvt = 0;
1158 for ( int i = 0; i <= totalChannels; i++ ) { totalEvt = totalEvt + br[i]; }
1159 std::cout
1160 << "==================Statistical first chain decay ==============================="
1161 << std::endl;
1162 std::cout
1163 << "i-th channel Events Generated Branching fraction generated "
1164 << std::endl;
1165 for ( int i = 0; i <= totalChannels; i++ )
1166 {
1167 std::cout << "| " << i << " " << br[i] << " "
1168 << br[i] * 1.0 / totalEvt << std::endl;
1169 }
1170 std::cout
1171 << "--------------------------------------------------------------------------------"
1172 << std::endl;
1173 std::cout << " sum: " << totalEvt << " "
1174 << "1" << std::endl;
1175 std::cout
1176 << "================== End of statistical first chain decay ========================"
1177 << std::endl;
1178 }
1179
1180 return StatusCode::SUCCESS;
1181}
1182
1183StatusCode EvtDecay::makeHepMC( EvtParticle* part, HepMC::GenEvent* hEvt,
1184 HepMC::GenParticle* hPart ) {
1185 MsgStream log( msgSvc(), name() );
1186
1187 if ( part->getNDaug() != 0 )
1188 {
1189 double ct = ( part->getDaug( 0 )->get4Pos() ).get( 0 );
1190 double x = ( part->getDaug( 0 )->get4Pos() ).get( 1 );
1191 double y = ( part->getDaug( 0 )->get4Pos() ).get( 2 );
1192 double z = ( part->getDaug( 0 )->get4Pos() ).get( 3 );
1193
1194 HepMC::GenVertex* end_vtx = new HepMC::GenVertex( HepLorentzVector( x, y, z, ct ) );
1195 hEvt->add_vertex( end_vtx );
1196 end_vtx->add_particle_in( hPart );
1197
1198 int ndaug = part->getNDaug();
1199
1200 for ( int it = 0; it < ndaug; it++ )
1201 {
1202
1203 double e = ( part->getDaug( it )->getP4Lab() ).get( 0 );
1204 double px = ( part->getDaug( it )->getP4Lab() ).get( 1 );
1205 double py = ( part->getDaug( it )->getP4Lab() ).get( 2 );
1206 double pz = ( part->getDaug( it )->getP4Lab() ).get( 3 );
1207 int id = EvtPDL::getStdHep( part->getDaug( it )->getId() );
1208 int status = 1;
1209
1210 if ( id == 0 )
1211 {
1212 std::cout << "EvtDecay::makeHepMC: id=0, skip this particle" << std::endl;
1213 continue;
1214 }
1215
1216 if ( part->getDaug( it )->getNDaug() != 0 ) status = 999;
1217
1218 HepMC::GenParticle* prod_part =
1219 new HepMC::GenParticle( HepLorentzVector( px, py, pz, e ), id, status );
1220 end_vtx->add_particle_out( prod_part );
1221 makeHepMC( part->getDaug( it ), hEvt, prod_part );
1222
1223 if ( log.level() < MSG::INFO ) prod_part->print();
1224 }
1225 }
1226
1227 return StatusCode::SUCCESS;
1228}
1229
1230void EvtDecay::MeVToGeV( HepMC::GenEvent* evt ) {
1231 for ( HepMC::GenEvent::particle_iterator p = evt->particles_begin();
1232 p != evt->particles_end(); ++p )
1233 {
1234 // cout << " PDG, BAR " << (*p)->pdg_id() << " " << (*p)->barcode() << endl;
1235 // (*p)->set_momentum( (*p)->momentum() / 1000. );
1236
1237 HepMC::FourVector tmpfv( ( *p )->momentum().x() / 1000., ( *p )->momentum().y() / 1000.,
1238 ( *p )->momentum().z() / 1000., ( *p )->momentum().t() / 1000. );
1239
1240 ( *p )->set_momentum( tmpfv );
1241 }
1242}
1243
1244void EvtDecay::GeVToMeV( HepMC::GenEvent* evt ) {
1245 for ( HepMC::GenEvent::particle_iterator p = evt->particles_begin();
1246 p != evt->particles_end(); ++p )
1247 {
1248 // cout << " PDG, BAR " << (*p)->pdg_id() << " " << (*p)->barcode() << endl;
1249 // (*p)->set_momentum( (*p)->momentum() * 1000. );
1250 HepMC::FourVector tmpfv( ( *p )->momentum().x() * 1000., ( *p )->momentum().y() * 1000.,
1251 ( *p )->momentum().z() * 1000., ( *p )->momentum().t() * 1000. );
1252
1253 ( *p )->set_momentum( tmpfv );
1254 }
1255}
1256
1257double EvtDecay::CalAmpsMax( EvtParticle* part ) {
1258 double amps_max = 0;
1259 for ( int i = 0; i < 100000; i++ )
1260 {
1261 m_Gen->generateDecay( part );
1262 double amps = CalAmpsMDIY( part );
1263 if ( amps > amps_max ) amps_max = amps;
1264 }
1265 amps_max = amps_max * 1.05;
1266 m_ampscalflag = false;
1267 return amps_max;
1268}
1269
1270// EvtBesRandom class implementation, basically BesRandomSvc -> EvtGen random engine interface
1271
1272EvtBesRandom::EvtBesRandom( HepRandomEngine* engine ) {
1273 m_engine = engine;
1274 m_engine->showStatus();
1275}
1276
1278
1280 // double rdm=EvtRandom::Flat(0.0, 1.0);;
1281 double rdm = RandFlat::shoot( m_engine );
1282 // std::cout<<"rdm= "<<rdm<<std::endl;
1283 return rdm;
1284 // return RandFlat::shoot(m_engine);
1285}
1286
1287void EvtDecay::SuperBody3decay_make( EvtId ppid, EvtVector4R p_init ) {
1288 double xmass2, ymass2;
1289 bool accept;
1290 EvtVector4R pd1, pd2, pd3;
1291
1292 //---- find out the pdg codes of final state and count the identical particles
1293 FinalState_make( ppid, p_init );
1294
1295 // begin to loop with events
1296 for ( int i = 0; i < 100000; i++ )
1297 {
1298 regen:
1299 EvtParticle* part = EvtParticleFactory::particleFactory( ppid, p_init );
1300 HepMC::GenParticle* hepMCpart =
1301 new GenParticle( HepLorentzVector( 0, 0, 0, parentMass ), parentPDGcode,
1302 3 ); // this line make the decay to select different channel
1303
1304 if ( part->getSpinType() == EvtSpinType::VECTOR ) { part->setVectorSpinDensity(); }
1305 m_Gen->generateDecay( part );
1306
1307 FinalState_sort( part );
1308 pd1 = son0;
1309 pd2 = son1;
1310 pd3 = son2;
1311
1312 // std::cout<<"multi, pdg, pi= "<<multi<<" "<<pdg0<<" "<<pdg1<<" "<<pdg2<<"
1313 // "<<son0<<son1<<son2<<std::endl;
1314
1315 xmass2 = ( pd1 + pd2 ).mass2(); // Dalitz plot m12^2 ~ m13^2
1316 ymass2 = ( pd1 + pd3 ).mass2();
1317 double xlow = SuperBody3decay.getXlow();
1318 double xup = SuperBody3decay.getXup();
1319 double ylow = SuperBody3decay.getYlow();
1320 double yup = SuperBody3decay.getYup();
1321 if ( xmass2 < xlow || xmass2 > xup || ymass2 < ylow || ymass2 > yup )
1322 {
1323 part->deleteTree();
1324 goto regen;
1325 }
1326 SuperBody3decay.HFill( xmass2, ymass2 );
1327
1328 if ( m_NtupleFile )
1329 {
1330 m_ich = part->getChannel();
1331 m_m1 = pd1.mass();
1332 m_m2 = pd2.mass();
1333 m_m3 = pd3.mass();
1334 m_m12 = ( pd1 + pd2 ).mass();
1335 m_m23 = ( pd2 + pd3 ).mass();
1336 m_m13 = ( pd1 + pd3 ).mass();
1337 m_cos1 = pd1.get( 3 ) / pd1.d3mag();
1338 m_cos2 = pd2.get( 3 ) / pd2.d3mag();
1339 m_cos3 = pd3.get( 3 ) / pd3.d3mag();
1340 mass_tuple->write();
1341 }
1342 double m1 = pd1.mass();
1343 double m2 = pd2.mass();
1344 double m3 = pd3.mass();
1345 double mj = ( pd2 + pd3 ).mass();
1346 // std::cout<<"mass 1 2 3 chicj <<=="<<m1<<" "<<m2<<" "<<m3<<" "<<mj<<std::endl;
1347 // delete hepMCpart;
1348 }
1349
1350 SuperBody3decay.HReweight(); // reweighting Dalitz plot
1351 SuperBody3decay.setZmax(); // find out the maximum value after reweighting
1352 first = false;
1353}
1354
1355bool EvtDecay::SuperBody3decay_judge( EvtParticle* part ) {
1356 double xmass2, ymass2;
1357 bool accept;
1358 EvtVector4R pd1, pd2, pd3;
1359
1360 FinalState_sort( part );
1361
1362 pd1 = son0;
1363 pd2 = son1;
1364 pd3 = son2;
1365
1366 xmass2 = ( pd1 + pd2 ).mass2(); // Dalitz plot m12^2 ~ m13^2
1367 ymass2 = ( pd1 + pd3 ).mass2();
1368 accept = SuperBody3decay.AR( xmass2, ymass2 );
1369
1370 // debugging
1371 if ( accept && m_NtupleFile )
1372 {
1373 _ich = part->getChannel();
1374 _m1 = pd1.mass();
1375 _m2 = pd2.mass();
1376 _m3 = pd3.mass();
1377 _m12 = ( pd1 + pd2 ).mass();
1378 _m23 = ( pd2 + pd3 ).mass();
1379 _m13 = ( pd1 + pd3 ).mass();
1380 _cos1 = pd1.get( 3 ) / pd1.d3mag();
1381 _cos2 = pd2.get( 3 ) / pd2.d3mag();
1382 _cos3 = pd3.get( 3 ) / pd3.d3mag();
1383 massgen_tuple->write();
1384 }
1385 // std::cout<<"mass 1 2 3 chicj>> "<<_m1<<" "<<_m2<<" "<<_m3<<" "<<_m23<<std::endl;
1386
1387 return accept;
1388}
1389
1390void EvtDecay::FinalState_make( EvtId ppid, EvtVector4R p_init ) {
1391 // get the final state pdg cond and count the identicle particle
1392 multi = 1;
1393 identical_flag = true;
1394
1395 for ( int i = 1; i < 10000; i++ )
1396 { // sigle out the final state
1397 EvtParticle* part = EvtParticleFactory::particleFactory( ppid, p_init );
1398 HepMC::GenParticle* hepMCpart =
1399 new GenParticle( HepLorentzVector( 0, 0, 0, parentMass ), parentPDGcode, 3 );
1400
1401 m_Gen->generateDecay( part );
1402 int nson = part->getNDaug();
1403
1404 if ( nson == 2 ) { continue; }
1405 else if ( nson == 3 )
1406 {
1407 EvtId xid0, xid1, xid2;
1408 xid0 = part->getDaug( 0 )->getId();
1409 xid1 = part->getDaug( 1 )->getId();
1410 xid2 = part->getDaug( 2 )->getId();
1411
1412 //-- pdg code
1413 pdg0 = EvtPDL::getStdHep( xid0 );
1414 pdg1 = EvtPDL::getStdHep( xid1 );
1415 pdg2 = EvtPDL::getStdHep( xid2 );
1416
1417 if ( pdg0 == pdg1 && pdg1 == pdg2 ) { multi = 3; }
1418 else if ( pdg0 == pdg1 ) { multi = 2; } // two identical particle list as 0,1 index
1419 else if ( pdg0 == pdg2 )
1420 {
1421 multi = 2;
1422 pdg = pdg1;
1423 pdg1 = pdg2;
1424 pdg2 = pdg;
1425 }
1426 else if ( pdg1 == pdg2 )
1427 {
1428 multi = 2;
1429 pdg = pdg0;
1430 pdg0 = pdg1;
1431 pdg1 = pdg2;
1432 pdg2 = pdg;
1433 }
1434 else { multi = 1; }
1435 break;
1436 }
1437 else
1438 {
1439 std::cout << "No direct three body decay channel found in decay card, I stop run"
1440 << std::endl;
1441 ::abort();
1442 }
1443 }
1444 // std::cout<<"pdg_i "<<pdg0<<" "<<pdg1<<" "<<pdg2<<std::endl;
1445 // std::cout<<"identical particle "<<multi<<std::endl;
1446}
1447
1448void EvtDecay::FinalState_sort( EvtParticle* part ) {
1449 // sort the momentum to aon0, son1, son2
1450 EvtVector4R pd0, pd1, pd2;
1451 EvtId xid0, xid1, xid2;
1452 int id0, id1, id2;
1453
1454 int nson = part->getNDaug();
1455 if ( nson == 2 )
1456 {
1457 pd0 = part->getDaug( 0 )->getP4Lab();
1458 pd1 = part->getDaug( 1 )->getDaug( 0 )->getP4Lab();
1459 pd2 = part->getDaug( 1 )->getDaug( 1 )->getP4Lab();
1460
1461 xid0 = part->getDaug( 0 )->getId();
1462 xid1 = part->getDaug( 1 )->getDaug( 0 )->getId();
1463 xid2 = part->getDaug( 1 )->getDaug( 1 )->getId();
1464 }
1465 else if ( nson == 3 )
1466 {
1467 pd0 = part->getDaug( 0 )->getP4Lab();
1468 pd1 = part->getDaug( 1 )->getP4Lab();
1469 pd2 = part->getDaug( 2 )->getP4Lab();
1470
1471 xid0 = part->getDaug( 0 )->getId();
1472 xid1 = part->getDaug( 1 )->getId();
1473 xid2 = part->getDaug( 2 )->getId();
1474 }
1475 //-- pdg code
1476 id0 = EvtPDL::getStdHep( xid0 );
1477 id1 = EvtPDL::getStdHep( xid1 );
1478 id2 = EvtPDL::getStdHep( xid2 );
1479
1480 // std::cout<<"pid before match: "<<id0<<" "<<id1<<" "<<id2<<std::endl;
1481 //-- assign sons momentum
1482 if ( multi == 1 )
1483 {
1484 assign_momentum( id0, pd0 );
1485 assign_momentum( id1, pd1 );
1486 assign_momentum( id2, pd2 );
1487 }
1488 else if ( multi == 2 )
1489 {
1490 assign_momentum2( id0, pd0 );
1491 assign_momentum2( id1, pd1 );
1492 assign_momentum2( id2, pd2 );
1493 if ( son0.get( 0 ) > son1.get( 0 ) )
1494 {
1495 son = son0;
1496 son0 = son1;
1497 son1 = son;
1498 } // change into E_0 < E_1
1499 }
1500 else if ( multi == 3 )
1501 { // sort sons according to energy E_0 < E_1 < E_2
1502 double En0 = pd0.get( 0 );
1503 double En1 = pd1.get( 0 );
1504 double En2 = pd2.get( 0 );
1505 if ( En0 < En1 && En1 < En2 )
1506 {
1507 son0 = pd0;
1508 son1 = pd1;
1509 son2 = pd2;
1510 }
1511 if ( En0 < En2 && En2 < En1 )
1512 {
1513 son0 = pd0;
1514 son1 = pd2;
1515 son2 = pd1;
1516 }
1517 if ( En1 < En0 && En0 < En2 )
1518 {
1519 son0 = pd1;
1520 son1 = pd0;
1521 son2 = pd2;
1522 }
1523 if ( En1 < En2 && En2 < En0 )
1524 {
1525 son0 = pd1;
1526 son1 = pd2;
1527 son2 = pd0;
1528 }
1529 if ( En2 < En0 && En0 < En1 )
1530 {
1531 son0 = pd2;
1532 son1 = pd0;
1533 son2 = pd1;
1534 }
1535 if ( En2 < En1 && En1 < En0 )
1536 {
1537 son0 = pd2;
1538 son1 = pd1;
1539 son2 = pd0;
1540 }
1541 }
1542}
1543
1544void EvtDecay::assign_momentum( int id0, EvtVector4R pd0 ) {
1545 if ( id0 == pdg0 ) { son0 = pd0; }
1546 else if ( id0 == pdg1 ) { son1 = pd0; }
1547 else if ( id0 == pdg2 ) { son2 = pd0; }
1548 else
1549 {
1550 std::cout << "PID= " << id0 << " not machted, I stop" << std::endl;
1551 ::abort();
1552 }
1553}
1554
1555void EvtDecay::assign_momentum2( int id0,
1556 EvtVector4R pd0 ) { // for two identicle particle case
1557 if ( id0 == pdg0 && identical_flag )
1558 {
1559 son0 = pd0;
1560 identical_flag = false;
1561 }
1562 else if ( id0 == pdg1 )
1563 {
1564 son1 = pd0;
1565 identical_flag = true;
1566 }
1567 else if ( id0 == pdg2 ) { son2 = pd0; }
1568 else
1569 {
1570 std::cout << "PID not machted, I stop" << std::endl;
1571 ::abort();
1572 }
1573}
1574
1575void EvtDecay::findPart( EvtParticle* part ) {
1576 FDP_id = EvtPDL::getId( m_FDPparticle );
1577 int FDP_pdg = EvtPDL::getStdHep( FDP_id );
1578
1579 m_Gen->generateDecay( part );
1580 int dn = part->getNDaug();
1581
1582 if ( dn != 0 )
1583 {
1584 for ( int i = 0; i < dn; i++ )
1585 {
1586 EvtParticle* part1 = part->getDaug( i );
1587 EvtId sonid = part1->getId();
1588 int son_pdg = EvtPDL::getStdHep( sonid );
1589 if ( son_pdg == FDP_pdg )
1590 {
1591 FDP_init = part1->getP4Lab();
1592 FDP_part = part1;
1593 return;
1594 }
1595 else { findPart( part1 ); }
1596 }
1597 } // if (dn block
1598}
1599
1600void EvtDecay::countChannel( EvtParticle* part ) {
1601 int ich = part->getChannel();
1602
1603 // debuging
1604 // if(getModel(part,ich)=="OPENCHARM" &&EvtPDL::name( part->getId() )=="psi(4260)") ich =
1605 // part->getGeneratorFlag(); std::cout<<"the channel is "<<ich<<std::endl;
1606
1607 br[ich]++;
1608 if ( ich > totalChannels ) totalChannels = ich;
1609 // std::cout<<"EVENT IN br_i "<<br[ich]<<std::endl;
1610}
1611
1612bool EvtDecay::isCharmonium( EvtId xid ) {
1613 EvtId psi4415 = EvtPDL::getId( std::string( "psi(4415)" ) );
1614 EvtId psi4160 = EvtPDL::getId( std::string( "psi(4160)" ) );
1615 EvtId psi4040 = EvtPDL::getId( std::string( "psi(4040)" ) );
1616 EvtId psi3770 = EvtPDL::getId( std::string( "psi(3770)" ) );
1617 EvtId psiprim = EvtPDL::getId( std::string( "psi(2S)" ) );
1618 EvtId jpsi = EvtPDL::getId( std::string( "J/psi" ) );
1619 EvtId etac = EvtPDL::getId( std::string( "eta_c" ) );
1620 EvtId etac2s = EvtPDL::getId( std::string( "eta_c(2S)" ) );
1621 EvtId hc = EvtPDL::getId( std::string( "h_c" ) );
1622 EvtId chic0 = EvtPDL::getId( std::string( "chi_c0" ) );
1623 EvtId chic1 = EvtPDL::getId( std::string( "chi_c1" ) );
1624 EvtId chic2 = EvtPDL::getId( std::string( "chi_c2" ) );
1625 EvtId chic0p = EvtPDL::getId( std::string( "chi_c0p" ) );
1626 EvtId chic1p = EvtPDL::getId( std::string( "chi_c1p" ) );
1627 EvtId chic2p = EvtPDL::getId( std::string( "chi_c1p" ) );
1628 std::vector<EvtId> Vid;
1629 Vid.clear();
1630 Vid.push_back( psi4415 );
1631 Vid.push_back( psi4160 );
1632 Vid.push_back( psi4040 );
1633 Vid.push_back( psi3770 );
1634 Vid.push_back( psiprim );
1635 Vid.push_back( jpsi );
1636 Vid.push_back( etac );
1637 Vid.push_back( etac2s );
1638 Vid.push_back( hc );
1639 Vid.push_back( chic0 );
1640 Vid.push_back( chic1 );
1641 Vid.push_back( chic2 );
1642 Vid.push_back( chic0p );
1643 Vid.push_back( chic1p );
1644 Vid.push_back( chic2p );
1645
1646 bool flag = true;
1647 for ( int i = 0; i < Vid.size(); i++ )
1648 {
1649 if ( xid == Vid[i] ) return flag;
1650 }
1651 return false;
1652}
1653
1654bool EvtDecay::isCharm( EvtId xid ) {
1655 EvtId d0 = EvtPDL::getId( std::string( "D0" ) );
1656 EvtId d0bar = EvtPDL::getId( std::string( "anti-D0" ) );
1657 EvtId dp = EvtPDL::getId( std::string( "D+" ) );
1658 EvtId dm = EvtPDL::getId( std::string( "D-" ) );
1659 EvtId d0h = EvtPDL::getId( std::string( "D0H" ) );
1660 EvtId d0l = EvtPDL::getId( std::string( "D0L" ) );
1661 EvtId dstp = EvtPDL::getId( std::string( "D*+" ) );
1662 EvtId dstm = EvtPDL::getId( std::string( "D*-" ) );
1663 EvtId ds0 = EvtPDL::getId( std::string( "D*0" ) );
1664 EvtId ds0bar = EvtPDL::getId( std::string( "anti-D*0" ) );
1665 EvtId dsp = EvtPDL::getId( std::string( "D_s+" ) );
1666 EvtId dsm = EvtPDL::getId( std::string( "D_s-" ) );
1667 EvtId dsstp = EvtPDL::getId( std::string( "D_s*+" ) );
1668 EvtId dsstm = EvtPDL::getId( std::string( "D_s*-" ) );
1669 EvtId ds0stp = EvtPDL::getId( std::string( "D_s0*+" ) );
1670 EvtId ds0stm = EvtPDL::getId( std::string( "D_s0*-" ) );
1671
1672 std::vector<EvtId> Vid;
1673 Vid.clear();
1674 Vid.push_back( d0 );
1675 Vid.push_back( d0bar );
1676 Vid.push_back( dp );
1677 Vid.push_back( dm );
1678 Vid.push_back( d0h );
1679 Vid.push_back( d0l );
1680 Vid.push_back( dstp );
1681 Vid.push_back( dstm );
1682 Vid.push_back( ds0 );
1683 Vid.push_back( ds0bar );
1684 Vid.push_back( dsp );
1685 Vid.push_back( dsm );
1686 Vid.push_back( dsstp );
1687 Vid.push_back( dsstm );
1688 Vid.push_back( ds0stp );
1689 Vid.push_back( ds0stm );
1690
1691 bool flag = true;
1692 for ( int i = 0; i < Vid.size(); i++ )
1693 {
1694 if ( xid == Vid[i] ) return flag;
1695 }
1696 return false;
1697}
1698
1699bool EvtDecay::isRadecay( EvtParticle* par ) {
1700 int ndg = par->getNDaug();
1701 for ( int i = 0; i < ndg; i++ )
1702 {
1703 EvtId xid = par->getDaug( i )->getId();
1704 if ( EvtPDL::getStdHep( xid ) == 22 ) { return true; }
1705 }
1706 return false;
1707}
1708
1709int EvtDecay::decayType( EvtParticle* par ) {
1710 /*************************************
1711 * 0: gamma light_hadrons
1712 * 1: gamma charmonium
1713 * 2: DDbar (D0 D0bar or D+D-)
1714 * 3: ligh_hadrons
1715 * 4: others
1716 *************************************/
1717 int Nchannel = par->getChannel();
1718 int ndg = par->getNDaug();
1719 int nfsr = 0;
1720
1721 if ( _RvalueTag ) { return Nchannel; }
1722 // std::cout<<"decayType= "<<Nchannel<<std::endl;
1723
1724 std::string model = getModel( par, Nchannel );
1725 if ( model == "OPENCHARM" || model == "LUNDCHARM" && m_tagLundModel )
1726 { // lundcharm model tag
1727 int ldm = par->getGeneratorFlag();
1728 // std::cout<<"LundCharmFlag = "<<ldm<<std::endl;
1729 return ldm;
1730 // return 9;
1731 }
1732
1733 for ( int i = 0; i < ndg; i++ )
1734 { // remove the FSR photon
1735 EvtId xid = par->getDaug( i )->getId();
1736 if ( EvtPDL::getStdHep( xid ) == -22 ) { nfsr++; }
1737 }
1738
1739 if ( isRadecay( par ) )
1740 {
1741 for ( int i = 0; i < ndg; i++ )
1742 {
1743 EvtId xid = par->getDaug( i )->getId();
1744 if ( isCharmonium( xid ) ) return 1;
1745 }
1746 return 0;
1747 }
1748 else
1749 {
1750 if ( ndg - nfsr == 2 )
1751 {
1752 int ndg = par->getNDaug();
1753 EvtId xd1 = par->getDaug( 0 )->getId();
1754 EvtId xd2 = par->getDaug( 1 )->getId();
1755 if ( isCharm( xd1 ) && isCharm( xd2 ) ) { return 2; }
1756 else if ( !isCharmonium( xd1 ) && !isCharmonium( xd2 ) && !isCharm( xd1 ) &&
1757 !isCharm( xd2 ) )
1758 { return 3; }
1759 else { return -1; }
1760 }
1761 else
1762 { // ndg>=3
1763 bool flag = false;
1764 for ( int i = 0; i < ndg; i++ )
1765 {
1766 EvtId xid = par->getDaug( i )->getId();
1767 if ( isCharmonium( xid ) )
1768 {
1769 flag = true;
1770 break;
1771 }
1772 if ( isCharm( xid ) )
1773 {
1774 flag = true;
1775 break;
1776 }
1777 } // for_i block
1778 if ( !flag ) { return 3; }
1779 else { return 4; }
1780 } // if_ndg block
1781 }
1782}
1783
1784std::string EvtDecay::getModel( EvtParticle* par, int mode ) {
1785 EvtDecayBase* thedecay = EvtDecayTable::gettheDecay( par->getId(), mode );
1786 return thedecay->getModelName();
1787}
1788
1789std::string EvtDecay::getModel( EvtParticle* par ) {
1790 int mode = par->getChannel();
1791 EvtDecayBase* thedecay = EvtDecayTable::gettheDecay( par->getId(), mode );
1792 return thedecay->getModelName();
1793}
1794
1795void EvtDecay::ReadTruth( EvtParticle* part, std::vector<std::vector<string>> mylist ) {
1796 if ( mylist.size() < 2 )
1797 {
1798 std::cout << " Empty list" << std::endl;
1799 abort();
1800 }
1801 EvtVector4R vp1;
1802 for ( int k = 0; k < mylist[0].size(); k++ )
1803 {
1804 if ( part->getId() == EvtPDL::getId( mylist[0][k] ) )
1805 {
1806 if ( part->getDaug( 1 )->getId() == EvtPDL::getId( "vhdr" ) )
1807 {
1808 part = part->getDaug( 1 );
1809 continue;
1810 }
1811 if ( part->getDaug( 0 )->getId() == EvtPDL::getId( "vgam" ) )
1812 {
1813 part = part->getDaug( 1 );
1814 continue;
1815 }
1816 for ( int i = 1; i < mylist.size(); i++ )
1817 {
1818 EvtParticle* mypart = part;
1819 for ( int j = 0; j < mylist[i].size(); j++ )
1820 {
1821 mypart = mypart->getDaug( atoi( mylist[i][j].c_str() ) );
1822 // std::cout<<atoi(mylist[i][j].c_str());
1823 }
1824 // std::cout<<std::endl;
1825 std::cout << EvtPDL::name( mypart->getId() ) << std::endl;
1826 if ( _truthAtCM ) { vp1 = mypart->getP4(); }
1827 else { vp1 = mypart->getP4Lab(); }
1828 if ( !isNumber( vp1.get( 0 ) ) )
1829 {
1830 part->printTree();
1831 abort();
1832 }
1833 // std::cout<<"truth "<<vp1.get(0)<<" "<<vp1.get(1)<<" "<<vp1.get(2)<<"
1834 // "<<vp1.get(3)<<std::endl;
1835 printf( "truth %.12lf %.12lf %.12lf %.12lf \n", vp1.get( 0 ), vp1.get( 1 ),
1836 vp1.get( 2 ), vp1.get( 3 ) );
1837 }
1838 }
1839 }
1840}
1841
1842int EvtDecay::isNumber( double d ) {
1843 return ( d == d );
1844} // if d=nan, return 0, otherwise, return 1
1845
1846double EvtDecay::energySpread( double mu, double sigma ) {
1847 // mu: mean value in Gaussian
1848 // sigma: variance in Gaussian
1849rloop:
1850 int n = 12;
1851 double ri = 0;
1852 for ( int i = 0; i < n; i++ )
1853 {
1854 double pm = EvtRandom::Flat( 0., 1 );
1855 ri += pm;
1856 }
1857 double eta = sqrt( n * 12.0 ) * ( ri / 12 - 0.5 );
1858 double xsig = sigma * eta + mu;
1859 double mx0 = EvtConExc::mlow;
1860 double mx1 = EvtConExc::mup;
1861 if ( xsig < mx0 || xsig > mx1 ) goto rloop;
1862 return xsig;
1863}
1864
1865#include "../user/Lenu.inc"
DECLARE_COMPONENT(BesBdkRc)
double mass
int runNo
Definition DQA_TO_DB.cxx:13
const Int_t n
ObjectVector< McGenEvent > McGenEventCol
int fst[50]
Definition EvtDecay.cxx:78
int nchr
Definition EvtDecay.cxx:70
int nchr_mu
Definition EvtDecay.cxx:72
int nchr_pi
Definition EvtDecay.cxx:73
int N_gamma
Definition EvtDecay.cxx:76
int nchr_k
Definition EvtDecay.cxx:74
int N_gammaFSR
Definition EvtDecay.cxx:77
int nchr_p
Definition EvtDecay.cxx:75
int nchr_e
Definition EvtDecay.cxx:71
DOUBLE_PRECISION xup[20]
DOUBLE_PRECISION xlow[20]
XmlRpcServer s
INTupleSvc * ntupleSvc()
IMessageSvc * msgSvc()
*************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
double random()
EvtBesRandom(HepRandomEngine *engine)
virtual ~EvtBesRandom()
static double _H0err
static double _H1err
static double _H0
static int nevt
static double _H1
static double _H2
static double _H2err
static double SetMthr
Definition EvtConExc.hh:194
static double mlow
Definition EvtConExc.hh:239
static double mup
Definition EvtConExc.hh:239
std::string getModelName()
static EvtDecayBase * gettheDecay(EvtId parent, int imode)
EvtDecay(const string &name, ISvcLocator *pSvcLocator)
Definition EvtDecay.cxx:90
IDataInfoSvc * dataInfoSvc
Definition EvtDecay.h:72
double energySpread(double mu, double sigma)
StatusCode initialize()
Definition EvtDecay.cxx:153
StatusCode finalize()
StatusCode execute()
Definition EvtDecay.cxx:375
static std::vector< std::string > SV
static std::vector< std::vector< double > > dVV
static std::vector< std::vector< int > > iVV
Definition EvtId.hh:27
static int getStdHep(EvtId id)
Definition EvtPDL.hh:61
static void reSetMass(EvtId i, double mass)
Definition EvtPDL.hh:74
static EvtId evtIdFromStdHep(int stdhep)
Definition EvtPDL.cc:232
static std::string name(EvtId i)
Definition EvtPDL.hh:70
static double getMass(EvtId i)
Definition EvtPDL.hh:44
static EvtId getId(const std::string &name)
Definition EvtPDL.cc:272
static EvtParticle * particleFactory(EvtSpinType::spintype spinType)
EvtVector4R getP4Lab()
EvtId getId() const
void setVectorSpinDensity()
static int _NextLevelDauNum
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:69
double mass() const
double get(int i) const
double d3mag() const
double getEcms()
bool isRunNoValid()
char * c_str(Index i)
const double hc
Definition TConstant.h:41
double double * m2
Definition qcdloop1.h:83
double * m1
Definition qcdloop1.h:83