55 Double_t vy, Double_t vz,
Int_t parent,
Bool_t wanttracking, Double_t e, Double_t tof,
56 Double_t weight, TMCProcess proc)
63 TVector3 mom(px_raw, py_raw, pz_raw);
66 if (fEventPlane) mom.RotateZ(fPhi);
72 TVector3 axis(-fBeamDirection.Unit().Y(), fBeamDirection.Unit().X(), 0);
73 auto angle = TMath::ACos(fBeamDirection.Unit().Z());
74 mom.Rotate(angle, axis);
78 if (pdgid == 311 || pdgid == -311) {
79 Double_t test = gRandom->Uniform(0., 1.);
89 TDatabasePDG* pdgBase = TDatabasePDG::Instance();
91 Fatal(
"CbmEventGenerator",
"No TDatabasePDG instantiated");
94 TParticlePDG* pdgPart = pdgBase->GetParticle(pdgid);
97 cerr <<
"\033[5m\033[31m -E CbmEventGenerator: PDG code " << pdgid <<
" not found in database.\033[0m " << endl;
98 cerr <<
"\033[5m\033[31m -E CbmEventGenerator: Discarding particle "
101 cerr <<
"\033[5m\033[31m -E CbmEventGenerator: now MC Index is "
107 cout <<
"\033[5m\033[31m -W CbmEventGenerator: PDG code " << pdgid
108 <<
" not found in database. This warning can be savely "
116 Double_t mass = pdgBase->GetParticle(pdgid)->Mass();
117 e = TMath::Sqrt(mom.Mag2() + mass * mass);
121 Int_t doTracking = 0;
122 if (fdoTracking && wanttracking) {
125 Int_t dummyparent = -1;
133 parent += fMCIndexOffset;
136 fStack->PushTrack(doTracking, dummyparent, pdgid, mom.X(), mom.Y(), mom.Z(), e, vx, vy, vz, tof, polx, poly, polz,
137 proc, ntr, weight, status, parent);
157 std::cout << std::endl;
158 LOG(info) << GetName() <<
": Generate event " << ++fEventNr;
177 LOG(info) << GetName() <<
": Rotate event by " << fPhi <<
" rad";
182 TObject* item =
nullptr;
183 while ((item = fListIter->Next())) {
184 FairGenerator* generator =
dynamic_cast<FairGenerator*
>(item);
186 fMCIndexOffset = fNTracks;
187 if (!generator->ReadEvent(
this)) {
188 LOG(info) << GetName() <<
": ReadEvent failed for generator " << generator->GetName();
194 if (!fEvent->IsSet()) fEvent->SetEventID(fEventNr);
195 fEvent->SetNPrim(fNTracks);
196 fEvent->SetVertex(fVertex);
197 fEvent->SetRotX(fBeamAngleX);
198 fEvent->SetRotY(fBeamAngleY);
199 Double_t phiGen = fEvent->GetRotZ();
200 fEvent->SetRotZ(phiGen + fPhi);
202 LOG(info) << GetName() <<
": Event ID " << fEvent->GetEventID() <<
", tracks " << fNTracks <<
", vertex ("
203 << fVertex.X() <<
", " << fVertex.Y() <<
", " << fVertex.Z() <<
") cm";
204 LOG(info) << GetName() <<
": Beam angle (" << fBeamAngleX <<
", " << fBeamAngleY <<
") rad, event plane angle "
205 << fPhi <<
" rad (total " << fEvent->GetRotZ() <<
" rad) change";
208 fTotPrim += fNTracks;
235 std::unique_ptr<CbmBeam> beam;
238 TVector3 norm(0, 0., 1.);
239 fVertex = beam->ExtrapolateToPlane(point, norm);
240 fBeamAngleX = beam->GetThetaX();
241 fBeamAngleY = beam->GetThetaY();
242 fBeamDirection = beam->GetDirection();
268 TVector3 surf1 =
fTarget->GetSurfaceCentreUp();
269 TVector3 surf2 =
fTarget->GetSurfaceCentreDown();
270 TVector3 norm =
fTarget->GetNormal();
278 Bool_t isInTarget = kFALSE;
280 std::unique_ptr<CbmBeam> beam;
281 while (!isInTarget) {
284 if (nSamples > 1000.)
285 LOG(fatal) << GetName() <<
": Aborting after " << nSamples <<
" beam samplings. Adjust beam and target.";
292 point1 = beam->ExtrapolateToPlane(surf1, norm);
293 point2 = beam->ExtrapolateToPlane(surf2, norm);
297 Bool_t check1 = ((point1 - surf1).Mag() < 0.5 *
fTarget->GetDiameter());
298 Bool_t check2 = ((point2 - surf2).Mag() < 0.5 *
fTarget->GetDiameter());
299 isInTarget = check1 && check2;
303 LOG(debug) << beam->ToString() <<
", generated after " << nSamples << (nSamples > 1 ?
" samplings: " :
" sampling");
306 Double_t scale = 0.5;
307 if (fSmearVertexZ) scale = gRandom->Uniform();
308 fVertex = point1 + scale * (point2 - point1);
311 fBeamAngleX = beam->GetThetaX();
312 fBeamAngleY = beam->GetThetaY();
313 fBeamDirection = beam->GetDirection();
virtual void AddTrack(Int_t pdgid, Double_t px, Double_t py, Double_t pz, Double_t vx, Double_t vy, Double_t vz, Int_t parent=-1, Bool_t wanttracking=true, Double_t e=-9e9, Double_t tof=0., Double_t weight=0., TMCProcess proc=kPPrimary)
Add a track to the stack to be transported.
void SetBeamPosition(Double_t meanX, Double_t meanY, Double_t sigmaX=-1., Double_t sigmaY=-1., Double_t zF=0.)
Set the beam position in the focal plane.