46 #include "genRootDecayChain.hh"
48 #include "EvtGen/EvtGen.hh"
49 #include "EvtGenBase/EvtRandomEngine.hh"
50 #include "EvtGenBase/EvtAbsRadCorr.hh"
51 #include "EvtGenBase/EvtDecayBase.hh"
52 #include "EvtGenBase/EvtParticle.hh"
53 #include "EvtGenBase/EvtParticleFactory.hh"
54 #include "EvtGenBase/EvtPatches.hh"
55 #include "EvtGenBase/EvtPDL.hh"
56 #include "EvtGenBase/EvtSimpleRandomEngine.hh"
57 #include "EvtGenBase/EvtMTRandomEngine.hh"
59 #ifdef EVTGEN_EXTERNAL
60 #include "EvtGenExternal/EvtExternalGenList.hh"
74 genRootDecayChain::genRootDecayChain(
const string& decayFileName,
75 const string& rootFileName,
76 const string& parentName,
77 int nEvents,
bool storeMtmXYZ) :
78 _decayFileName(decayFileName),
79 _rootFileName(rootFileName),
80 _parentName(parentName),
82 _storeMtmXYZ(storeMtmXYZ),
88 _theFile =
new TFile(rootFileName.c_str(),
"recreate");
89 _theTree =
new TTree(
"Data",
"Data");
90 _theTree->SetDirectory(_theFile);
92 gROOT->SetStyle(
"Plain");
93 gStyle->SetOptStat(0);
95 _theCanvas =
new TCanvas(
"theCanvas",
"", 900, 700);
97 _theCanvas->UseCurrentStyle();
101 genRootDecayChain::~genRootDecayChain() {
108 void genRootDecayChain::run() {
111 this->generateEvents();
115 void genRootDecayChain::initTree() {
120 _dVtx = 0, _pVtx = 0, _daug = 0;
121 _px = 0.0, _py = 0.0, _pz = 0.0;
122 _p = 0.0, _E = 0.0, _m = 0.0, _t = 0.0;
125 _theTree->Branch(
"eventId", &_eventId,
"eventId/I");
126 _theTree->Branch(
"PDGId", &_PDGId,
"PDGId/I");
127 _theTree->Branch(
"dVtx", &_dVtx,
"dVtx/I");
128 _theTree->Branch(
"pVtx", &_pVtx,
"pVtx/I");
129 _theTree->Branch(
"daug", &_daug,
"daug/I");
130 _theTree->Branch(
"p", &_p,
"p/D");
131 _theTree->Branch(
"E", &_E,
"E/D");
132 _theTree->Branch(
"pL", &_pL,
"pL/D");
133 _theTree->Branch(
"EL", &_EL,
"EL/D");
134 _theTree->Branch(
"m", &_m,
"m/D");
139 _theTree->Branch(
"px", &_px,
"px/D");
140 _theTree->Branch(
"py", &_py,
"py/D");
141 _theTree->Branch(
"pz", &_pz,
"pz/D");
142 _theTree->Branch(
"pxL", &_pxL,
"pxL/D");
143 _theTree->Branch(
"pyL", &_pyL,
"pyL/D");
144 _theTree->Branch(
"pzL", &_pzL,
"pzL/D");
149 _theTree->Branch(
"t", &_t,
"t/D");
153 void genRootDecayChain::writeTree() {
160 void genRootDecayChain::generateEvents() {
164 std::list<EvtDecayBase*> extraModels;
169 randomEngine =
new EvtMTRandomEngine();
177 #ifdef EVTGEN_EXTERNAL
178 bool useEvtGenRandom(
false);
180 radCorrEngine = genList.getPhotosModel();
181 extraModels = genList.getListOfModels();
187 EvtGen evtGen(_decayFileName.c_str(),
"../evt.pdl", randomEngine,
188 radCorrEngine, &extraModels, mixingType, useXml);
192 EvtId theId = EvtPDL::getId(_parentName);
193 if (theId.getId() == -1 && theId.getAlias() == -1) {
194 cout<<
"Error. Could not find valid EvtId for "<<_parentName<<endl;
200 for (i = 0; i < _nEvents; i++) {
203 EvtVector4R pInit(EvtPDL::getMass(theId), 0.0, 0.0, 0.0);
207 if (i%1000 == 0) {cout<<
"Event number = "<<i+1<<
" out of "<<_nEvents<<std::endl;}
209 theParent = EvtParticleFactory::particleFactory(theId, pInit);
210 if (theParent->getSpinStates() == 3) {theParent->setVectorSpinDensity();}
213 evtGen.generateDecay(theParent);
216 theParent->setAttribute(
"dVtx", 0);
218 theParent->setAttribute(
"pVtx", 0);
220 theParent->setAttribute(
"daug", 0);
222 int nDaug = theParent->getNDaug();
225 storeTreeInfo(theParent);
234 for (iDaug = 0; iDaug < nDaug; iDaug++) {
238 daug->setAttribute(
"dVtx", 1);
240 daug->setAttribute(
"pVtx", 0);
242 daug->setAttribute(
"daug", iDaug+1);
245 this->storeDaughterInfo(daug);
249 theParent->deleteTree();
257 void genRootDecayChain::storeDaughterInfo(
EvtParticle* theParticle) {
259 if (!theParticle) {
return;}
262 storeTreeInfo(theParticle);
266 int nDaug = theParticle->
getNDaug();
270 if (nDaug > 0) {_vertexNo++;}
274 int parentVtx = theParticle->getAttribute(
"dVtx");
278 for (iDaug = 0; iDaug < nDaug; iDaug++) {
283 daug->setAttribute(
"dVtx", _vertexNo);
284 daug->setAttribute(
"pVtx", parentVtx);
285 daug->setAttribute(
"daug", iDaug+1);
291 for (iDaug = 0; iDaug < nDaug; iDaug++) {
294 storeDaughterInfo(daug);
300 void genRootDecayChain::storeTreeInfo(
EvtParticle* theParticle) {
302 if (!theParticle) {
return;}
306 _dVtx = theParticle->getAttribute(
"dVtx");
307 _pVtx = theParticle->getAttribute(
"pVtx");
308 _daug = theParticle->getAttribute(
"daug");
317 _PDGId = EvtPDL::getStdHep(theParticle->
getId());
324 _p = sqrt(_px*_px + _py*_py + _pz*_pz);
331 _pL = sqrt(_pxL*_pxL + _pyL*_pyL + _pzL*_pzL);
334 _m = theParticle->
mass();
342 int main(
int argc,
char** argv) {
345 string decayFileName(
"BKstarGamma.dec");
347 if (argc > 1) {decayFileName = argv[1];}
348 cout<<
"Decay file name is "<<decayFileName<<endl;
350 string rootFileName(
"BKstarGamma.root");
352 if (argc > 2) {rootFileName = argv[2];}
353 cout<<
"Root file name is "<<rootFileName<<endl;
355 string parentName(
"B0");
357 if (argc > 3) {parentName = argv[3];}
358 cout<<
"Parent name is "<<parentName<<endl;
361 if (argc > 4) {nEvents = atoi(argv[4]);}
363 bool storeMtmXYZ =
true;
365 genRootDecayChain myGen(decayFileName, rootFileName, parentName, nEvents, storeMtmXYZ);
const EvtVector4R & getP4() const
EvtParticle * getDaug(int i)
EvtVector4R getP4Lab() const