BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
MpdPlutoGenerator.cxx
Go to the documentation of this file.
1// -------------------------------------------------------------------------
2// ----- MpdPlutoGenerator source file -----
3// ----- Created 13/07/04 by V. Friese / D.Bertini -----
4// ----- Modified from FairPlutoGenerator for MPD by V. Zhezher -----
5// -------------------------------------------------------------------------
6#include "MpdPlutoGenerator.h"
7
8#include "FairPrimaryGenerator.h"
9#include "PParticle.h"
10#include "TClonesArray.h"
11#include "TDatabasePDG.h"
12#include "TFile.h"
13#include "TLorentzVector.h"
14#include "TTree.h"
15#include "TVector3.h"
16
17#include <iostream>
18
19const Double_t kProtonMass = 0.938271998;
20const Double_t kElectronMass = 0.00051098892;
21
22// ----- Default constructor ------------------------------------------
25 , iEvent(0)
26 , fEkin(0)
27 , fFileName(NULL)
28 , fInputFile(NULL)
29 , fInputTree(NULL)
30 , fParticles(NULL)
31{}
32// ------------------------------------------------------------------------
33
34// ----- Standard constructor -----------------------------------------
37 , iEvent(0)
38 , fFileName(fileName)
39 , fInputFile(new TFile(fileName))
40 , fInputTree(NULL)
41 , fParticles(new TClonesArray("PParticle", 100))
42{
43 fEkin = ekin;
44 fInputTree = (TTree*)fInputFile->Get("data");
45 fInputTree->SetBranchAddress("Particles", &fParticles);
46}
47// ------------------------------------------------------------------------
48
49// ----- Destructor ---------------------------------------------------
54// ------------------------------------------------------------------------
55
56// ----- Public method ReadEvent --------------------------------------
57Bool_t MpdPlutoGenerator::ReadEvent(FairPrimaryGenerator* primGen)
58{
59
60 // Check for input file
61 if (!fInputFile) {
62 cout << "-E MpdPlutoGenerator: Input file nor open!" << endl;
63 return kFALSE;
64 }
65
66 // Check for number of events in input file
67 if (iEvent > fInputTree->GetEntries()) {
68 cout << "-E MpdPlutoGenerator: No more events in input file!" << endl;
69 CloseInput();
70 return kFALSE;
71 }
72 TFile* g = gFile;
73 fInputFile->cd();
74 fInputTree->GetEntry(iEvent++);
75 g->cd();
76
77 // Get PDG database
79
80 // Get number of particle in TClonesrray
81 Int_t nParts = fParticles->GetEntriesFast();
82
83 // Loop over particles in TClonesArray
84 for (Int_t iPart = 0; iPart < nParts; iPart++) {
85 PParticle* part = (PParticle*)fParticles->At(iPart);
86 Int_t pdgType = dataBase->ConvertGeant3ToPdg(part->ID());
87
88 // Check if particle type is known to database
89 if (!pdgType) {
90 cout << "-W MpdPlutoGenerator: Unknown type " << part->ID() << ", skipping particle." << endl;
91 continue;
92 }
93
94 TLorentzVector mom = part->Vect4();
95 Double_t px = mom.Px();
96 Double_t py = mom.Py();
97 Double_t pz = mom.Pz();
98
99 TVector3 vertex = part->getVertex();
100 Double_t vx = vertex.x();
101 Double_t vy = vertex.y();
102 Double_t vz = vertex.z();
103
104 // ---> Calculate beta and gamma for Lorentztransformation
105 Double_t eBeam = fEkin + kProtonMass;
106 Double_t pBeam = TMath::Sqrt(eBeam * eBeam - kProtonMass * kProtonMass);
107 Double_t betaCM = pBeam / (eBeam + kProtonMass);
108 Double_t gammaCM = TMath::Sqrt(1. / (1. - betaCM * betaCM));
109
110 // AZ Double_t mass = kElectronMass;
111 Double_t mass = dataBase->GetParticle(pdgType)->Mass();
112 Double_t e = sqrt(mass * mass + px * px + py * py + pz * pz);
113 pz = gammaCM * (pz - betaCM * e);
114
115 // Give track to PrimaryGenerator
116 // primGen->AddTrack(pdgType, px, py, pz, vx, vy, vz);
117 // AZ - keep track of parents
118 Int_t parentIndx = part->GetParentIndex();
119 primGen->AddTrack(pdgType, px, py, pz, vx, vy, vz, -parentIndx - 10);
120 // AZ
121
122 } // Loop over particle in event
123
124 return kTRUE;
125}
126// ------------------------------------------------------------------------
127
128// ----- Public method SkipEvents --------------------------------------
129
131{
132 if (count <= 0)
133 return kTRUE;
134
135 iEvent = count;
136
137 std::cout << "-I MpdPlutoGenerator: Skipped " << count << " Events!" << std::endl;
138
139 return kTRUE;
140}
141
142// ----- Private method CloseInput ------------------------------------
144{
145 if (fInputFile) {
146 cout << "-I MpdPlutoGenerator: Closing input file " << fFileName << endl;
147 fInputFile->Close();
148 delete fInputFile;
149 }
150 fInputFile = NULL;
151}
152// ------------------------------------------------------------------------
const Double_t kProtonMass
const Double_t kElectronMass
bool Bool_t
int Int_t
char Char_t
constexpr Bool_t kFALSE
double Double_t
constexpr Bool_t kTRUE
#define gFile
TClonesArray * fParticles
Pointer to input tree.
Double_t fEkin
Event number.
TTree * fInputTree
Pointer to input file.
MpdPlutoGenerator()
Default constructor (should not be used).
void CloseInput()
Particle array from PLUTO.
Bool_t SkipEvents(Int_t count)
virtual ~MpdPlutoGenerator()
Destructor.
const Char_t * fFileName
Target energy in lab system.
TFile * fInputFile
Input file name.
virtual Bool_t ReadEvent(FairPrimaryGenerator *primGen)
Reads on event from the input file and pushes the tracks onto the stack.
static TDatabasePDG * Instance()
virtual Int_t ConvertGeant3ToPdg(Int_t Geant3Number) const
TParticlePDG * GetParticle(const char *name) const
Bool_t cd() override
Double_t Px() const
Double_t Pz() const
Double_t Py() const
Double_t Mass() const
Double_t z() const
Double_t x() const
Double_t y() const
RVec< PromoteType< T > > sqrt(const RVec< T > &v)
Double_t Sqrt(Double_t x)