]>
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" | |
4a33c50d | 41 | #include "AliLog.h" |
fee5f683 | 42 | #include "AliGenEventHeader.h" |
43 | // | |
44 | ||
92a7e9c7 | 45 | ClassImp(AliGenTHnSparse) |
46 | ||
47 | //_______________________________________________________________________ | |
48 | AliGenTHnSparse::AliGenTHnSparse(): | |
49 | AliGenerator(), | |
50 | fHn(0), | |
51 | fFile(0), | |
fee5f683 | 52 | fIpart(0), |
53 | fBoth(kFALSE) | |
92a7e9c7 | 54 | { |
55 | // Default constructor | |
56 | SetNumberParticles(1); | |
57 | } | |
58 | ||
59 | //_______________________________________________________________________ | |
60 | AliGenTHnSparse::AliGenTHnSparse(const AliGenTHnSparse& func): | |
61 | AliGenerator(), | |
62 | fHn(func.fHn), | |
63 | fFile(func.fFile), | |
29e8465c | 64 | fIpart(func.fIpart), |
65 | fBoth(func.fBoth) | |
92a7e9c7 | 66 | { |
67 | // Copy constructor | |
68 | SetNumberParticles(1); | |
69 | } | |
70 | ||
71 | //_______________________________________________________________________ | |
72 | AliGenTHnSparse & AliGenTHnSparse::operator=(const AliGenTHnSparse& func) | |
73 | { | |
74 | // Assigment operator | |
75 | if(&func == this) return *this; | |
76 | fHn = func.fHn; | |
77 | fFile = func.fFile; | |
78 | fIpart = func.fIpart; | |
29e8465c | 79 | fBoth = func.fBoth; |
80 | ||
92a7e9c7 | 81 | return *this; |
82 | } | |
83 | ||
84 | //_______________________________________________________________________ | |
85 | AliGenTHnSparse::~AliGenTHnSparse() | |
86 | { | |
87 | // Destructor | |
88 | delete fFile; | |
89 | } | |
90 | ||
91 | //_______________________________________________________________________ | |
92 | void AliGenTHnSparse::Generate() | |
93 | { | |
92a7e9c7 | 94 | // Generate Npart of id Ipart |
4a33c50d | 95 | Int_t naccepted =0; |
92a7e9c7 | 96 | |
97 | Double_t rand[4]; // z, ptot, r, theta | |
98 | Float_t pos[3], phi, ptot, theta, pt, z, r; | |
99 | Float_t mom[3]; | |
100 | Int_t pdg = fIpart; | |
101 | ||
fee5f683 | 102 | for (Int_t ipart = 0; ipart < fNpart && naccepted<fNpart; ipart++) { |
92a7e9c7 | 103 | |
104 | fHn->GetRandom(rand); | |
105 | z=rand[0]; | |
106 | ptot=rand[1]; | |
107 | r=rand[2]; | |
108 | theta=rand[3]; | |
109 | ||
110 | // Phi: same for position and momemtum | |
111 | ||
112 | phi=(-180+gRandom->Rndm()*360)*TMath::Pi()/180; | |
113 | ||
114 | // position at production | |
115 | ||
116 | pos[0] = r*TMath::Cos(phi); | |
117 | pos[1] = r*TMath::Sin(phi); | |
118 | pos[2] = z; | |
119 | ||
120 | // momentum at production | |
121 | ||
122 | pt = ptot*TMath::Sin(theta); | |
123 | mom[0] = pt*TMath::Cos(phi); | |
124 | mom[1] = pt*TMath::Sin(phi); | |
125 | mom[2] = ptot*TMath::Cos(theta); | |
126 | ||
127 | // propagation | |
128 | ||
fee5f683 | 129 | Float_t polarization[3] = {0,0,0}; |
92a7e9c7 | 130 | Int_t nt; |
fee5f683 | 131 | |
132 | // Part and anti-part | |
133 | ||
134 | if(fBoth){ | |
135 | Double_t sign = gRandom->Rndm(); | |
136 | if(sign < 0.5) pdg = -fIpart; | |
137 | else pdg = fIpart; | |
138 | } | |
139 | ||
92a7e9c7 | 140 | PushTrack(fTrackIt,-1,pdg,mom, pos, polarization,0,kPPrimary,nt); |
fee5f683 | 141 | naccepted++; |
92a7e9c7 | 142 | } |
143 | ||
fee5f683 | 144 | AliGenEventHeader* header = new AliGenEventHeader("THn"); |
145 | gAlice->SetGenEventHeader(header); | |
92a7e9c7 | 146 | return; |
fee5f683 | 147 | |
92a7e9c7 | 148 | } |
149 | ||
150 | //_______________________________________________________________________ | |
151 | void AliGenTHnSparse::Init() | |
152 | { | |
153 | ||
154 | // Initialisation, check consistency of selected file | |
155 | printf("************ AliGenTHnSparse ****************\n"); | |
156 | printf("*********************************************\n"); | |
157 | if (!fHn){ | |
158 | AliFatal("THnSparse file not specified"); | |
159 | } | |
160 | ||
161 | return; | |
162 | } | |
163 | ||
164 | //_______________________________________________________________________ | |
165 | void AliGenTHnSparse::SetThnSparse(char *file_name, char *thn_name) | |
166 | { | |
167 | ||
168 | // Open the file and get object | |
224cb081 | 169 | fFile = new TFile(file_name); |
170 | fHn = (THnSparseF*)(fFile->Get(thn_name)); | |
92a7e9c7 | 171 | |
172 | } |