7 #include "TLorentzVector.h"
11 #include "TGenPhaseSpace.h"
53 const string header(
" ************************************\n * simulating decay into K- pi+ pi- *\n ************************************\n");
106 const double pz = pBeam / sqrt(1 + dxdz * dxdz + dydz * dydz);
107 const double px = dxdz * pz;
108 const double py = dydz * pz;
110 return TLorentzVector(px, py, pz, EBeam);
128 const TLorentzVector& beam,
129 TGenPhaseSpace&
event)
132 cerr <<
"Output stream is not writable." << endl;
139 out << setprecision(numeric_limits<double>::digits10 + 1)
140 <<
geantIds[2] <<
" " <<
charges[2] <<
" " << beam.Px() <<
" " << beam.Py() <<
" " << beam.Pz() <<
" " << beam.E() << endl;
141 for (
unsigned int i = 0;
i < 3; ++
i) {
142 TLorentzVector* hadron =
event.GetDecay(
i);
144 cerr <<
"genbod returns NULL pointer to Lorentz vector for daughter " <<
i <<
"." << endl;
148 out << setprecision(numeric_limits<double>::digits10 + 1)
149 <<
geantIds[
i] <<
" " <<
charges[
i] <<
" " << hadron->Px() <<
" " << hadron->Py() <<
" " << hadron->Pz() <<
" " << hadron->E() << endl;
157 const TLorentzVector& beam,
158 TGenPhaseSpace&
event,
159 const TVector3& vertexpos,
160 const TLorentzVector& recoilproton,
161 bool formated =
true)
164 cerr <<
"Output stream is not writable." << endl;
173 out << vertexpos.Z() <<
" " << vertexpos.X() <<
" " << vertexpos.Y() << endl;
175 out << setprecision(numeric_limits<double>::digits10 + 1)
176 <<
"44 " << -beam.Pz() <<
" " << -beam.Px() <<
" " << -beam.Py() << endl;
178 out << setprecision(numeric_limits<double>::digits10 + 1)
179 <<
"14 " << recoilproton.Pz() <<
" " << recoilproton.Px() <<
" " << recoilproton.Py() << endl;
182 for (
unsigned int i = 0;
i < 3; ++
i) {
183 TLorentzVector* hadron =
event.GetDecay(
i);
185 cerr <<
"genbod returns NULL pointer to Lorentz vector for daughter " <<
i <<
"." << endl;
189 out << setprecision(numeric_limits<double>::digits10 + 1)
190 <<
geantIds[
i] <<
" " << hadron->Pz() <<
" " << hadron->Px() <<
" " << hadron->Py() << endl;
199 const int nmbSteps = 10,
202 const double step = nmbTotal / (double)nmbSteps;
203 if ((nmbTotal >= 0) && ((
int)(currentPos / step) - (
int)((currentPos - 1) / step) != 0)){
204 out <<
"\x1B[2K" <<
"\x1B[0E" <<
" " << setw(3) << (
int)(currentPos / step) * nmbSteps <<
"%";
214 const TLorentzVector& beam,
215 TGenPhaseSpace&
event,
217 const TLorentzVector& recoilproton){
220 TLorentzVector hadrons(0.,0.,0.,0.);
221 for (
unsigned int i = 0;
i < 3; ++
i) {
222 TLorentzVector* hadron =
event.GetDecay(
i);
224 cerr <<
"genbod returns NULL pointer to Lorentz vector for daughter " <<
i <<
"." << endl;
230 result = fabs(recoilproton.DeltaPhi(hadrons))-TMath::Pi();
235 Calc_t_prime(
const TLorentzVector& particle_In,
const TLorentzVector& particle_Out){
238 result = (particle_Out.M2()-particle_In.M2());
240 result = pow(result,2);
241 result /= 4*pow(particle_In.P(),2);
243 result = fabs((particle_In-particle_Out).
M2())-fabs(result);
258 const double xMassMax = 2.140,
259 const TString& outFileName =
"2100.2140.genbod.evt",
261 const TString& thetaHistFileName =
"./hTheta.root",
262 const int nmbEvent = 2000,
263 const bool plot =
true,
264 const TString& outFileNameComGeant =
""
269 gRandom->SetSeed(12345);
280 TFile temp(
"/tmp/buffer.root",
"RECREATE");
281 TTree* values =
new TTree(
"values",
"values");
296 values->Branch(
"t", &t,
"t/D");
297 values->Branch(
"tprime", &tprime,
"tprime/D");
298 values->Branch(
"M123", &M123,
"M123/D");
299 values->Branch(
"M12", &M12,
"M12/D");
300 values->Branch(
"M13", &M13,
"M13/D");
301 values->Branch(
"M23", &M23,
"M23/D");
302 values->Branch(
"theta", &theta,
"theta/D");
303 values->Branch(
"dphi", &dphi,
"dphi/D");
304 values->Branch(
"Vx", &Vx,
"Vx/D");
305 values->Branch(
"Vy", &Vy,
"Vy/D");
306 values->Branch(
"Vz", &Vz,
"Vz/D");
307 values->Branch(
"dxdz", &dxdz,
"dxdz/D");
308 values->Branch(
"dydz", &dydz,
"dydz/D");
309 values->Branch(
"E", &E,
"E/D");
322 double _xMassMin = xMassMin;
325 for (
int i = 0;
i < 3;
i++){
328 cout <<
" calculating the invariant mass bin to be " << _xMassMin;
332 TString _outFileName = outFileName;
333 if (_outFileName ==
""){
334 stringstream _filename;
335 _filename << trunc(_xMassMin*1e3) <<
"." << trunc(xMassMax*1e3) <<
".genbod.26";
336 cout <<
" created genbot events filename: " << _filename.str() << endl;
337 _outFileName = _filename.str();
341 ofstream outFile(_outFileName);
344 TString _outFileNameComGeant = outFileNameComGeant;
345 if (_outFileNameComGeant ==
""){
346 stringstream _filename;
347 _filename << trunc(_xMassMin*1e3) <<
"." << trunc(xMassMax*1e3) <<
".genbod.fort.26";
348 cout <<
" created ComGeantevents filename: " << _filename.str() << endl;
349 _outFileNameComGeant = _filename.str();
352 ofstream outFileComGeant(_outFileNameComGeant);
355 cout <<
"Writing " << nmbEvent <<
" events to file " << _outFileName <<
" and " << _outFileNameComGeant <<
"." << endl;
358 TH1* thetaDist = NULL;
360 TFile* thetaHistFile = TFile::Open(thetaHistFileName,
"READ");
361 if (!thetaHistFile || thetaHistFile->IsZombie()) {
362 cerr <<
"Cannot open histogram file '" << thetaHistFileName <<
"'. exiting." << endl;
365 thetaHistFile->GetObject(
"h1", thetaDist);
367 cerr <<
"Cannot find theta histogram in file '" << thetaHistFileName <<
"'. exiting." << endl;
374 int tenpercent = (
int)(nmbEvent * 0.1);
375 while (countEvent < nmbEvent) {
380 const TLorentzVector beam =
makeBeam();
383 theta = thetaDist->GetRandom();
384 const double xMass = gRandom->Uniform(_xMassMin, xMassMax);
385 const double xMass2 = xMass * xMass;
387 const double Ea = beam.E();
390 const double epso = 1 - eps;
391 const double eat = Ea * theta;
394 const double e = Ea - 1 / (2 *
gProtonMass * epso) * (eat * eat + mpeps * mpeps);
395 const double pw = sqrt(e * e - xMass2);
396 const double phi= gRandom->Uniform(0., TMath::TwoPi());
398 TVector3 p3(1, 0, 0);
399 p3.SetMagThetaPhi(pw, theta, phi);
401 p3.RotateUz(beam.Vect().Unit());
404 TLorentzVector X(p3, e);
405 const TLorentzVector
q = beam - X;
408 const double tGen = -q.M2();
413 TGenPhaseSpace phaseSpace;
417 cerr <<
"Decay of M = " << X.M() <<
" into 3 particles is not allowed!" << endl;
420 double maxWeight = phaseSpace.GetWtMax();
421 double weight = phaseSpace.Generate();
423 if (weight / maxWeight < gRandom->Uniform())
434 TLorentzVector partout = (
435 *(phaseSpace.GetDecay(0)) +
436 *(phaseSpace.GetDecay(1)) +
437 *(phaseSpace.GetDecay(2)));
440 M12 = ( *(phaseSpace.GetDecay(0)) +
441 *(phaseSpace.GetDecay(1))).M();
442 M13 = ( *(phaseSpace.GetDecay(0)) +
443 *(phaseSpace.GetDecay(2))).M();
444 M23 = ( *(phaseSpace.GetDecay(1)) +
445 *(phaseSpace.GetDecay(2))).M();
447 dphi =
GetPhi(beam, phaseSpace, q);
451 dxdz = beam.X()/beam.Z();
452 dydz = beam.Y()/beam.Z();
461 cout << endl <<
"Needed " << attempts <<
" attempts to generate " << countEvent <<
" events." << endl;
463 outFileComGeant.close();
466 gROOT->SetStyle(
"Plain");
467 gStyle->SetPalette(1);
469 TCanvas* c =
new TCanvas(
"c",
"c", 10, 10, 1000, 1000);
472 values->Draw(
"M123");
484 values->Draw(
"tprime");
486 values->Draw(
"theta");
488 values->Draw(
"dphi");
492 values->Draw(
"Vx:Vy",
"",
"COLZ");
496 values->Draw(
"M12:M13",
"",
"COLZ");
498 values->Draw(
"M12:M23",
"",
"COLZ");
500 values->Draw(
"M13:M23",
"",
"COLZ");
502 values->Draw(
"dxdz");
504 values->Draw(
"dydz");
506 c->Print(
"event_properties.pdf");