9 #include <FairGenericStack.h>
10 #include <FairLogger.h>
11 #include <FairMCEventHeader.h>
20 : FairPrimaryGenerator()
23 , fForceVertexInTarget(kTRUE)
24 , fForceVertexAtZ(kFALSE)
27 fName =
"EventGenerator";
50 std::cout << std::endl;
51 LOG(info) << GetName() <<
": Generate event " << ++fEventNr;
70 LOG(info) << GetName() <<
": Rotate event by " << fPhi <<
" rad";
75 TObject* item =
nullptr;
76 while ((item = fListIter->Next())) {
77 FairGenerator* generator =
dynamic_cast<FairGenerator*
>(item);
79 fMCIndexOffset = fNTracks;
80 if (!generator->ReadEvent(
this)) {
81 LOG(info) << GetName() <<
": ReadEvent failed for generator "
82 << generator->GetName();
88 if (!fEvent->IsSet()) fEvent->SetEventID(fEventNr);
89 fEvent->SetNPrim(fNTracks);
90 fEvent->SetVertex(fVertex);
91 fEvent->SetRotX(fBeamAngleX);
92 fEvent->SetRotY(fBeamAngleY);
93 Double_t phiGen = fEvent->GetRotZ();
94 fEvent->SetRotZ(phiGen + fPhi);
97 LOG(info) << GetName() <<
": Event ID " << fEvent->GetEventID() <<
", tracks "
98 << fNTracks <<
", vertex (" << fVertex.X() <<
", " << fVertex.Y()
99 <<
", " << fVertex.Z() <<
") cm";
100 LOG(info) << GetName() <<
": Beam angle (" << fBeamAngleX <<
", "
101 << fBeamAngleY <<
") rad, event plane angle " << fPhi
102 <<
" rad (total " << fEvent->GetRotZ() <<
" rad)";
105 fTotPrim += fNTracks;
128 std::unique_ptr<CbmBeam> beam;
131 TVector3 norm(0, 0., 1.);
132 fVertex = beam->ExtrapolateToPlane(point, norm);
133 fBeamAngleX = beam->GetThetaX();
134 fBeamAngleY = beam->GetThetaY();
135 fBeamDirection = beam->GetDirection();
143 std::unique_ptr<CbmBeam> beam;
145 fVertex = beam->GetPosition();
146 fBeamAngleX = beam->GetThetaX();
147 fBeamAngleY = beam->GetThetaY();
148 fBeamDirection = beam->GetDirection();
159 TVector3 surf1 =
fTarget->GetSurfaceCentreUp();
160 TVector3 surf2 =
fTarget->GetSurfaceCentreDown();
161 TVector3 norm =
fTarget->GetNormal();
169 Bool_t isInTarget = kFALSE;
171 std::unique_ptr<CbmBeam> beam;
172 while (!isInTarget) {
175 if (nSamples > 1000.)
176 LOG(fatal) << GetName() <<
": Aborting after " << nSamples
177 <<
" beam samplings. Adjust beam and target.";
184 point1 = beam->ExtrapolateToPlane(surf1, norm);
185 point2 = beam->ExtrapolateToPlane(surf2, norm);
189 Bool_t check1 = ((point1 - surf1).Mag() < 0.5 *
fTarget->GetDiameter());
190 Bool_t check2 = ((point2 - surf2).Mag() < 0.5 *
fTarget->GetDiameter());
191 isInTarget = check1 && check2;
195 LOG(debug) << beam->ToString() <<
", generated after " << nSamples
196 << (nSamples > 1 ?
" samplings: " :
" sampling");
199 Double_t scale = 0.5;
200 if (fSmearVertexZ) scale = gRandom->Uniform();
201 fVertex = point1 + scale * (point2 - point1);
204 fBeamAngleX = beam->GetThetaX();
205 fBeamAngleY = beam->GetThetaY();
206 fBeamDirection = beam->GetDirection();
216 LOG(info) <<
"Vertex smearing along beam " << (fSmearVertexZ ?
"ON" :
"OFF");
218 LOG(info) <<
"Random event plane angle between " << fPhiMin <<
" and "
219 << fPhiMax <<
" rad";
221 LOG(info) <<
"Fixed event plane angle = 0";
222 LOG(info) <<
"Number of generators " << fGenList->GetEntries();
223 for (Int_t iGen = 0; iGen < fGenList->GetEntries(); iGen++) {
224 fGenList->At(iGen)->Print();
233 Double_t sigmaThetaX,
234 Double_t sigmaThetaY) {