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