]>
Commit | Line | Data |
---|---|---|
92a7e9c7 | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
15 | ||
16 | //----------------------------------------------------------------------- | |
17 | // Particle generator according to 4 correlated variables : here | |
18 | // z, ptot, r, theta. The input is a THnSparse object included in | |
19 | // the root file (path and name to be set via the SetTHnSparse method). | |
20 | // This class is similar to AliGenFunction. | |
21 | //----------------------------------------------------------------------- | |
22 | // Author : X. Lopez - LPC Clermont (fr) | |
23 | //----------------------------------------------------------------------- | |
24 | /* | |
25 | Example for generation : | |
92a7e9c7 | 26 | AliGenTHnSparse *gener = new AliGenTHnSparse(); |
27 | gener->SetNumberParticles(10); | |
fee5f683 | 28 | gener->SetPart(13,kTRUE); // for generating id 13 and -13 |
92a7e9c7 | 29 | gener->SetThnSparse("file_name","thn_name"); |
30 | gener->Init(); | |
31 | */ | |
32 | ||
33 | #include <TRandom.h> | |
34 | #include <TFile.h> | |
35 | #include "THnSparse.h" | |
36 | ||
37 | #include "AliGenTHnSparse.h" | |
38 | ||
fee5f683 | 39 | // NEW |
40 | #include "AliRun.h" | |
41 | #include "AliGenEventHeader.h" | |
42 | // | |
43 | ||
92a7e9c7 | 44 | ClassImp(AliGenTHnSparse) |
45 | ||
46 | //_______________________________________________________________________ | |
47 | AliGenTHnSparse::AliGenTHnSparse(): | |
48 | AliGenerator(), | |
49 | fHn(0), | |
50 | fFile(0), | |
fee5f683 | 51 | fIpart(0), |
52 | fBoth(kFALSE) | |
92a7e9c7 | 53 | { |
54 | // Default constructor | |
55 | SetNumberParticles(1); | |
56 | } | |
57 | ||
58 | //_______________________________________________________________________ | |
59 | AliGenTHnSparse::AliGenTHnSparse(const AliGenTHnSparse& func): | |
60 | AliGenerator(), | |
61 | fHn(func.fHn), | |
62 | fFile(func.fFile), | |
63 | fIpart(func.fIpart) | |
64 | { | |
65 | // Copy constructor | |
66 | SetNumberParticles(1); | |
67 | } | |
68 | ||
69 | //_______________________________________________________________________ | |
70 | AliGenTHnSparse & AliGenTHnSparse::operator=(const AliGenTHnSparse& func) | |
71 | { | |
72 | // Assigment operator | |
73 | if(&func == this) return *this; | |
74 | fHn = func.fHn; | |
75 | fFile = func.fFile; | |
76 | fIpart = func.fIpart; | |
77 | return *this; | |
78 | } | |
79 | ||
80 | //_______________________________________________________________________ | |
81 | AliGenTHnSparse::~AliGenTHnSparse() | |
82 | { | |
83 | // Destructor | |
84 | delete fFile; | |
85 | } | |
86 | ||
87 | //_______________________________________________________________________ | |
88 | void AliGenTHnSparse::Generate() | |
89 | { | |
fee5f683 | 90 | Int_t naccepted =0; |
91 | ||
92a7e9c7 | 92 | // Generate Npart of id Ipart |
93 | ||
94 | Double_t rand[4]; // z, ptot, r, theta | |
95 | Float_t pos[3], phi, ptot, theta, pt, z, r; | |
96 | Float_t mom[3]; | |
97 | Int_t pdg = fIpart; | |
98 | ||
fee5f683 | 99 | for (Int_t ipart = 0; ipart < fNpart && naccepted<fNpart; ipart++) { |
92a7e9c7 | 100 | |
101 | fHn->GetRandom(rand); | |
102 | z=rand[0]; | |
103 | ptot=rand[1]; | |
104 | r=rand[2]; | |
105 | theta=rand[3]; | |
106 | ||
107 | // Phi: same for position and momemtum | |
108 | ||
109 | phi=(-180+gRandom->Rndm()*360)*TMath::Pi()/180; | |
110 | ||
111 | // position at production | |
112 | ||
113 | pos[0] = r*TMath::Cos(phi); | |
114 | pos[1] = r*TMath::Sin(phi); | |
115 | pos[2] = z; | |
116 | ||
117 | // momentum at production | |
118 | ||
119 | pt = ptot*TMath::Sin(theta); | |
120 | mom[0] = pt*TMath::Cos(phi); | |
121 | mom[1] = pt*TMath::Sin(phi); | |
122 | mom[2] = ptot*TMath::Cos(theta); | |
123 | ||
124 | // propagation | |
125 | ||
fee5f683 | 126 | Float_t polarization[3] = {0,0,0}; |
92a7e9c7 | 127 | Int_t nt; |
fee5f683 | 128 | |
129 | // Part and anti-part | |
130 | ||
131 | if(fBoth){ | |
132 | Double_t sign = gRandom->Rndm(); | |
133 | if(sign < 0.5) pdg = -fIpart; | |
134 | else pdg = fIpart; | |
135 | } | |
136 | ||
92a7e9c7 | 137 | PushTrack(fTrackIt,-1,pdg,mom, pos, polarization,0,kPPrimary,nt); |
fee5f683 | 138 | naccepted++; |
92a7e9c7 | 139 | } |
140 | ||
fee5f683 | 141 | AliGenEventHeader* header = new AliGenEventHeader("THn"); |
142 | gAlice->SetGenEventHeader(header); | |
92a7e9c7 | 143 | return; |
fee5f683 | 144 | |
92a7e9c7 | 145 | } |
146 | ||
147 | //_______________________________________________________________________ | |
148 | void AliGenTHnSparse::Init() | |
149 | { | |
150 | ||
151 | // Initialisation, check consistency of selected file | |
152 | printf("************ AliGenTHnSparse ****************\n"); | |
153 | printf("*********************************************\n"); | |
154 | if (!fHn){ | |
155 | AliFatal("THnSparse file not specified"); | |
156 | } | |
157 | ||
158 | return; | |
159 | } | |
160 | ||
161 | //_______________________________________________________________________ | |
162 | void AliGenTHnSparse::SetThnSparse(char *file_name, char *thn_name) | |
163 | { | |
164 | ||
165 | // Open the file and get object | |
224cb081 | 166 | fFile = new TFile(file_name); |
167 | fHn = (THnSparseF*)(fFile->Get(thn_name)); | |
92a7e9c7 | 168 | |
169 | } |