BmnRoot
Loading...
Searching...
No Matches
MpdHistoGenerator.cxx
Go to the documentation of this file.
1
7#include "MpdHistoGenerator.h"
8#include "FairMCEventHeader.h"
9#include "FairPrimaryGenerator.h"
10
11#include "TDatabasePDG.h"
12#include "TFile.h"
13#include "TH2D.h"
14#include "TLorentzVector.h"
15#include "TMath.h"
16#include "TRandom.h"
17#include "TVirtualMC.h"
18
19#include <fstream>
20#include <iostream>
21#include <iomanip>
22// #define debug_hsd
23
24using namespace std;
25
26// ------------------------------------------------------------------------
28 fPdgCode(-211), fMult(1), fHist(NULL)
29{
30 // Constructor
31
32 //gRandom->SetSeed(0); // change random seed
33
34 // Get histograms Pt vs Eta (He3)
35 TFile f("he3_eta_pt.root");
36 f.ReadAll();
37 fHist = (TH2D*) f.FindObject("hPtEta");
38 fHist->SetDirectory(0);
39}
40
41// ------------------------------------------------------------------------
42MpdHistoGenerator::MpdHistoGenerator(Int_t pdgid, Int_t mult) : FairGenerator(),
43 fPdgCode(pdgid), fMult(mult), fHist(NULL)
44{
45 // Constructor
46
47 //gRandom->SetSeed(0); // change random seed
48
49 // Get histograms Pt vs Eta (He3)
50 TFile f("he3_eta_pt.root");
51 f.ReadAll();
52 fHist = (TH2D*) f.FindObject("hPtEta");
53 fHist->SetDirectory(0);
54}
55
56// ------------------------------------------------------------------------
58{
59 // Destructor
60
61}
62
63//-------------------------------------------------------------------------
64Bool_t MpdHistoGenerator::ReadEvent(FairPrimaryGenerator* primGen)
65{
66 // Generate event
67
68 static Int_t first = 1;
69
70 if (first) {
71 first = 0;
72 //cout << " histo " << fHist << " " << fHist->GetNbinsX() << " " << fHist->GetNbinsY() << endl;
73 if (TDatabasePDG::Instance()->GetParticle(fPdgCode) == NULL) {
74 // Define particle with fPdgCode (take it from DCM-QGSM input file)
75 // To be done ...
76 }
77 }
78
79 Double_t pt, eta, phi;
80 TVector3 part;
81
82 for (Int_t i = 0; i < fMult; ++i) {
83 phi = gRandom->Uniform(TMath::TwoPi());
84 fHist->GetRandom2(eta, pt);
85
86 part.SetPtEtaPhi(pt, eta, phi);
87
88 //FairMCEventHeader* eventHeader = primGen->GetEvent();
89 /* Set event impact parameter in MCEvent if not yet done */
90 /*
91 if (eventHeader && (!eventHeader->IsSet()) ) {
92 eventHeader->SetB(fB);
93 eventHeader->MarkSet(kTRUE);
94 }
95 */
96
97 //primGen->AddTrack(1000020030, He3.Px(), He3.Py(), He3.Pz(), 0., 0., 0., -1);
98 primGen->AddTrack(fPdgCode, part.Px(), part.Py(), part.Pz(), 0., 0., 0., -1);
99 }
100
101 return kTRUE;
102}
103
104// ------------------------------------------------------------------------
105
int i
Definition P4_F32vec4.h:22
float f
Definition P4_F32vec4.h:21
virtual Bool_t ReadEvent(FairPrimaryGenerator *primGen)
STL namespace.