14#include <FairGenericStack.h>
15#include <FairMCEventHeader.h>
26 : FairPrimaryGenerator()
29 , fForceVertexInTarget(kTRUE)
30 , fForceVertexAtZ(kFALSE)
34 fName =
"EventGenerator";
59 std::cout << std::endl;
60 LOG(info) << GetName() <<
": Generate event " << ++fEventNr;
79 LOG(info) << GetName() <<
": Rotate event by " << fPhi <<
" rad";
84 TObject* item =
nullptr;
85 while ((item = fListIter->Next())) {
86 FairGenerator* generator =
dynamic_cast<FairGenerator*
>(item);
88 fMCIndexOffset = fNTracks;
89 if (!generator->ReadEvent(
this)) {
90 LOG(info) << GetName() <<
": ReadEvent failed for generator " << generator->GetName();
96 if (!fEvent->IsSet()) fEvent->SetEventID(fEventNr);
97 fEvent->SetNPrim(fNTracks);
98 fEvent->SetVertex(fVertex);
99 fEvent->SetRotX(fBeamAngleX);
100 fEvent->SetRotY(fBeamAngleY);
101 Double_t phiGen = fEvent->GetRotZ();
102 fEvent->SetRotZ(phiGen + fPhi);
104 LOG(info) << GetName() <<
": Event ID " << fEvent->GetEventID() <<
", tracks " << fNTracks <<
", vertex ("
105 << fVertex.X() <<
", " << fVertex.Y() <<
", " << fVertex.Z() <<
") cm";
106 LOG(info) << GetName() <<
": Beam angle (" << fBeamAngleX <<
", " << fBeamAngleY <<
") rad, event plane angle "
107 << fPhi <<
" rad (total " << fEvent->GetRotZ() <<
" rad) change";
110 fTotPrim += fNTracks;
134 std::unique_ptr<CbmBeam> beam;
137 TVector3 norm(0, 0., 1.);
138 fVertex = beam->ExtrapolateToPlane(point, norm);
139 fBeamAngleX = beam->GetThetaX();
140 fBeamAngleY = beam->GetThetaY();
141 fBeamDirection = beam->GetDirection();
150 std::unique_ptr<CbmBeam> beam;
152 fVertex = beam->GetPosition();
153 fBeamAngleX = beam->GetThetaX();
154 fBeamAngleY = beam->GetThetaY();
155 fBeamDirection = beam->GetDirection();
167 TVector3 surf1 =
fTarget->GetSurfaceCentreUp();
168 TVector3 surf2 =
fTarget->GetSurfaceCentreDown();
169 TVector3 norm =
fTarget->GetNormal();
177 Bool_t isInTarget = kFALSE;
179 std::unique_ptr<CbmBeam> beam;
180 while (!isInTarget) {
183 if (nSamples > 1000.)
184 LOG(fatal) << GetName() <<
": Aborting after " << nSamples <<
" beam samplings. Adjust beam and target.";
191 point1 = beam->ExtrapolateToPlane(surf1, norm);
192 point2 = beam->ExtrapolateToPlane(surf2, norm);
196 Bool_t check1 = ((point1 - surf1).Mag() < 0.5 *
fTarget->GetDiameter());
197 Bool_t check2 = ((point2 - surf2).Mag() < 0.5 *
fTarget->GetDiameter());
198 isInTarget = check1 && check2;
202 LOG(debug) << beam->ToString() <<
", generated after " << nSamples << (nSamples > 1 ?
" samplings: " :
" sampling");
205 Double_t scale = 0.5;
206 if (fSmearVertexZ) scale = gRandom->Uniform();
207 fVertex = point1 + scale * (point2 - point1);
210 fBeamAngleX = beam->GetThetaX();
211 fBeamAngleY = beam->GetThetaY();
212 fBeamDirection = beam->GetDirection();
223 LOG(info) <<
"Vertex smearing along beam " << (fSmearVertexZ ?
"ON" :
"OFF");
224 if (fEventPlane) LOG(info) <<
"Random event plane angle between " << fPhiMin <<
" and " << fPhiMax <<
" rad";
226 LOG(info) <<
"Fixed event plane angle = 0";
227 LOG(info) <<
"Number of generators " << fGenList->GetEntries();
228 for (Int_t iGen = 0; iGen < fGenList->GetEntries(); iGen++) {
229 fGenList->At(iGen)->Print();
237 Double_t sigmaThetaY)
ClassImp(CbmConverterManager)
void SetAngle(Double_t x0, Double_t y0, Double_t sigmaX=-1., Double_t sigmaY=-1.)
Set the parameters for the beam angle distribution.
void SetPosition(Double_t x0, Double_t y0, Double_t sigmaX=-1., Double_t sigmaY=-1., Double_t zF=0.)
Set the parameters for the beam position distribution.
std::string ToString() const
Info to string.
std::unique_ptr< CbmBeam > GenerateBeam()
Generate a beam trajectory.
virtual void Print(Option_t *opt="") const
Log output.
virtual Bool_t GenerateEvent(FairGenericStack *stack)
Generate the input event.
Double_t fVertexZ
forced z coordinate of event vertex
void SetBeamAngle(Double_t meanThetaX, Double_t meanThetaY, Double_t sigmaThetaX=-1., Double_t sigmaThetaY=-1.)
Set the beam angle in the focal plane.
CbmEventGenerator()
Default constructor
void MakeVertexAtZ()
Generate event vertex position at a given z.
Bool_t fForceVertexInTarget
Target properties.
virtual ~CbmEventGenerator()
Destructor
Bool_t fForceVertexAtZ
If set, vertex must be at given z.
void ForceVertexAtZ(Double_t zVertex)
Force event vertex to be at a given z.
virtual void MakeVertexInFocalPlane()
Generate event vertex position in the beam focal plane.
virtual void MakeVertex()
Generate event vertex position.
CbmBeamProfile fBeamProfile
Beam properties.
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.
std::shared_ptr< const CbmTarget > fTarget
virtual void MakeVertexInTarget()
Generate event vertex position in the target.