BmnRoot
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
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#include "PParticle.h"
17
18#include <iostream>
19
20const Double_t kProtonMass = 0.938271998;
21const Double_t kElectronMass = 0.00051098892;
22
23// ----- Default constructor ------------------------------------------
25 :FairGenerator(),
26 iEvent(0),
27 fEkin(0),
28 fFileName(NULL),
29 fInputFile(NULL),
30 fInputTree(NULL),
31 fParticles(NULL)
32{
33}
34// ------------------------------------------------------------------------
35
36
37// ----- Standard constructor -----------------------------------------
38MpdPlutoGenerator::MpdPlutoGenerator(const Char_t* fileName, Double_t ekin = 25.0)
39 :FairGenerator(),
40 iEvent(0),
41 fFileName(fileName),
42 fInputFile(new TFile(fileName)),
43 fInputTree(NULL),
44 fParticles(new TClonesArray("PParticle",100))
45{
46 fEkin = ekin;
47 fInputTree = (TTree*) fInputFile->Get("data");
48 fInputTree->SetBranchAddress("Particles", &fParticles);
49}
50// ------------------------------------------------------------------------
51
52
53// ----- Destructor ---------------------------------------------------
57// ------------------------------------------------------------------------
58
59
60// ----- Public method ReadEvent --------------------------------------
61Bool_t MpdPlutoGenerator::ReadEvent(FairPrimaryGenerator* primGen) {
62
63 // Check for input file
64 if ( ! fInputFile ) {
65 cout << "-E MpdPlutoGenerator: Input file nor open!" << endl;
66 return kFALSE;
67 }
68
69 // Check for number of events in input file
70 if ( iEvent > fInputTree->GetEntries() ) {
71 cout << "-E MpdPlutoGenerator: No more events in input file!" << endl;
72 CloseInput();
73 return kFALSE;
74 }
75 TFile *g=gFile;
76 fInputFile->cd();
77 fInputTree->GetEntry(iEvent++);
78 g->cd();
79
80 // Get PDG database
81 TDatabasePDG* dataBase = TDatabasePDG::Instance();
82
83 // Get number of particle in TClonesrray
84 Int_t nParts = fParticles->GetEntriesFast();
85
86 // Loop over particles in TClonesArray
87 for (Int_t iPart=0; iPart < nParts; iPart++) {
88 PParticle* part = (PParticle*) fParticles->At(iPart);
89 Int_t pdgType = dataBase->ConvertGeant3ToPdg( part->ID() );
90
91 // Check if particle type is known to database
92 if ( ! pdgType ) {
93 cout << "-W MpdPlutoGenerator: Unknown type " << part->ID()
94 << ", skipping particle." << endl;
95 continue;
96 }
97
98 TLorentzVector mom = part->Vect4();
99 Double_t px = mom.Px();
100 Double_t py = mom.Py();
101 Double_t pz = mom.Pz();
102
103 TVector3 vertex = part->getVertex();
104 Double_t vx = vertex.x();
105 Double_t vy = vertex.y();
106 Double_t vz = vertex.z();
107
108 // ---> Calculate beta and gamma for Lorentztransformation
109 Double_t eBeam = fEkin + kProtonMass;
110 Double_t pBeam = TMath::Sqrt(eBeam*eBeam - kProtonMass*kProtonMass);
111 Double_t betaCM = pBeam / (eBeam + kProtonMass);
112 Double_t gammaCM = TMath::Sqrt( 1. / ( 1. - betaCM*betaCM) );
113
114 //AZ Double_t mass = kElectronMass;
115 Double_t mass = dataBase->GetParticle(pdgType)->Mass();
116 Double_t e = sqrt( mass*mass + px*px + py*py + pz*pz );
117 pz = gammaCM * ( pz - betaCM * e );
118
119
120 // Give track to PrimaryGenerator
121 //primGen->AddTrack(pdgType, px, py, pz, vx, vy, vz);
122 //AZ - keep track of parents
123 Int_t parentIndx = part->GetParentIndex();
124 primGen->AddTrack(pdgType, px, py, pz, vx, vy, vz, -parentIndx-10);
125 //AZ
126
127 } // Loop over particle in event
128
129 return kTRUE;
130
131}
132// ------------------------------------------------------------------------
133
134// ----- Public method SkipEvents --------------------------------------
135
136Bool_t MpdPlutoGenerator::SkipEvents(Int_t count) {
137 if (count<=0) return kTRUE;
138
139 iEvent = count;
140
141 std::cout << "-I MpdPlutoGenerator: Skipped " << count << " Events!" << std::endl;
142
143 return kTRUE;
144}
145
146
147
148
149// ----- Private method CloseInput ------------------------------------
150void MpdPlutoGenerator::CloseInput() {
151 if ( fInputFile ) {
152 cout << "-I MpdPlutoGenerator: Closing input file " << fFileName
153 << endl;
154 fInputFile->Close();
155 delete fInputFile;
156 }
157 fInputFile = NULL;
158}
159// ------------------------------------------------------------------------
const Double_t kProtonMass
const Double_t kProtonMass
const Double_t kElectronMass
friend F32vec4 sqrt(const F32vec4 &a)
Definition P4_F32vec4.h:34
Bool_t SkipEvents(Int_t count)
virtual Bool_t ReadEvent(FairPrimaryGenerator *primGen)