FairRoot/PandaRoot
detectors/hyp/hypTools/PndHypBupGenerator.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- PndHypBupGenerator source file -----
3 // ----- Created by A. Sanchez -----
4 // -------------------------------------------------------------------------
5 
6 
7 #include <iostream>
8 #include "TClonesArray.h"
9 
10 #include "TFile.h"
11 #include "TF1.h"
12 #include "TRandom.h"
13 #include "TLorentzVector.h"
14 #include "TTree.h"
15 #include "TVector3.h"
16 #include "../hyp/THParticle.h"
17 #include "PndHypBupGenerator.h"
18 #include "FairPrimaryGenerator.h"
19 
20 using namespace std;
21 
22 
23 
24 // ----- Default constructor ------------------------------------------
26 fThetaMin(0),fThetaMax(0),fPhiMin(0),fPhiMax(0),
27 fThetaRangeIsSet(0),fPRangeIsSet(0),fGamOn(0) {
28  iEvent = 0;
29  fInputFile = NULL;
30  fInputTree = NULL;
31 }
32 // ------------------------------------------------------------------------
33 
34 
35 
36 // ----- Standard constructor -----------------------------------------
38 fThetaMin(0),fThetaMax(0),fPhiMin(0),fPhiMax(0),
39 fThetaRangeIsSet(0),fPRangeIsSet(0),fGamOn(0){
40 
41 
42  fFileName = fileName;
43  iEvent = 0;
44  fInputFile = new TFile(fFileName);
45  fInputTree = (TTree*) fInputFile->Get("data");
46  fParticles = new TClonesArray("THParticle",100);
47  fInputTree->SetBranchAddress("Particles", &fParticles);
48 
49 
50 
51 }
52 // ------------------------------------------------------------------------
53 
54 
55 
56 // ----- Destructor ---------------------------------------------------
58  CloseInput();
59 }
60 // ------------------------------------------------------------------------
61 
62 
63 
64 // ----- Public method ReadEvent --------------------------------------
66 
67  // Check for input file
68  if ( ! fInputFile ) {
69  cout << "-E- PndHypBupGenerator: Input file not open!" << endl;
70  return kFALSE;
71  }
72  // Check for number of events in input file
73  if ( iEvent > fInputTree->GetEntries() ) {
74  cout << "-E PndDpmGenerator: No more events in input file!" << endl;
75  CloseInput();
76  return kFALSE;
77  }
78 
79  // Defining kinematics variables, angle is expressed in degrees.
80  Double_t phi, p=0.0,theta=0.0;
81 
82  TFile *g=gFile;
83  fInputFile->cd();
84  fInputTree->GetEntry(iEvent++);
85  g->cd();
86 
87  // Get number of particle in TClonesrray
88  Int_t nParts = fParticles->GetEntriesFast();
89 
90  // Loop over particles in TClonesArray
91 
92  for (Int_t iPart=0; iPart < nParts; iPart++) {
93  THParticle* part = (THParticle*) fParticles->At(iPart);
94  Int_t pdgType = part->GetPdgCode();
95 
96  // Check if particle type is known to database
97  if ( ! pdgType ) {
98  cout << "-W PndDpmGenerator: Unknown type " << part->GetPdgCode()
99  << ", skipping particle." << endl;
100  continue;
101  }
102 
103  Double_t px = 0.;
104  Double_t py = 0.;
105  Double_t pz = 0.;
106 
107  Double_t vx ;
108  Double_t vy ;
109  Double_t vz ;
110 
111  if(fGamOn){
112 
113  phi = gRandom->Uniform(0,360)* TMath::DegToRad();
114  p = gRandom->Uniform(fPMin,fPMax);
115  theta = acos(gRandom->Uniform(cos(fThetaMin* TMath::DegToRad()),cos(fThetaMax* TMath::DegToRad())));
116 
117  pz = p*TMath::Cos(theta);
118  py = p*TMath::Sin(theta)*TMath::Sin(phi);
119  px = p*TMath::Sin(theta)*TMath::Cos(phi);
120 
121  vx = part->Vx();
122  vy = part->Vy();
123  vz = part->Vz();
124 
125 
126  cout<<" Secondary vertex for stopping Xi - gammas "<<vx<<" "
127  <<vy<<" "<<vz<<endl;
128 
129  // Give track to PrimaryGenerator
130 
131 
132  primGen->AddTrack(22, px, py, pz, vx, vy,vz);
133 
134 
135 
136  }else
137  {
138  px= part->Px();
139  py= part->Py();
140  pz= part->Pz();
141 
142 
143  vx = part->Vx();
144  vy = part->Vy();
145  vz = part->Vz();
146 
147 
148  cout<<" Secondary vertex for stopping Xi - "<<pdgType<<" "<<vx<<" "
149  <<vy<<" "<<vz<<endl;
150 
151  // Give track to PrimaryGenerator
152 
153 
154  primGen->AddTrack(pdgType, px, py, pz, vx, vy,vz);
155  }
156 
157 
158  }
159 
160 
161  return kTRUE;
162 }
163 // ------------------------------------------------------------------------
164 
165 
166 
167 // ----- Private method CloseInput ------------------------------------
169 
170  if ( fInputFile) {
171  cout << "-I- CbmHypBupGenerator: Closing input file "
172  << fFileName << endl;
173  fInputFile->Close();
174 
175  delete fInputFile;
176  }
177 
178  fInputFile = NULL;
179  }
180 
181 // ------------------------------------------------------------------------
182 
183 
184 
185 // ------------------------------------------------------------------------
187 
friend F32vec4 acos(const F32vec4 &a)
Definition: P4_F32vec4.h:113
Double_t p
Definition: anasim.C:58
const Char_t * fFileName
Event number.
friend F32vec4 cos(const F32vec4 &a)
Definition: P4_F32vec4.h:112
TTree * fInputTree
Pointer to input file.
Double_t Vy() const
Definition: THParticle.h:70
Double_t Vz() const
Definition: THParticle.h:71
static T Sin(const T &x)
Definition: PndCAMath.h:42
TFile * g
static T Cos(const T &x)
Definition: PndCAMath.h:43
Double_t fThetaMin
Definition: run_full.C:19
Double_t fPMin
Definition: run_full.C:16
FairPrimaryGenerator * primGen
Definition: sim_emc_apd.C:81
virtual Bool_t ReadEvent(FairPrimaryGenerator *primGen)
TClonesArray * fParticles
Pointer to input tree.
Double_t
Double32_t fThetaMin
Azimuth angle range [degree].
Double_t fPMax
Definition: run_full.C:18
Double_t Vx() const
Definition: THParticle.h:69
ClassImp(PndAnaContFact)
Int_t GetPdgCode() const
Definition: THParticle.h:60
Double_t fThetaMax
Definition: run_full.C:21
double pz[39]
Definition: pipisigmas.h:14