CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
AfterBurnerGenerator.cc
Go to the documentation of this file.
1 
2 /*
3  ________________________________________________________________________
4 
5  AfterBurnerVtxGenerator
6 
7  Giving flow modulation for the generated particles
8 
9  ________________________________________________________________________
10  */
11 
12 // Quan Wang
13 
14 
18 
24 
25 #include "CLHEP/Random/RandGaussQ.h"
26 #include "CLHEP/Random/RandFlat.h"
27 #include "CLHEP/Units/GlobalSystemOfUnits.h"
28 #include "CLHEP/Units/GlobalPhysicalConstants.h"
30 #include "HepMC/GenEvent.h"
31 #include "HepMC/GenParticle.h"
32 #include "HepMC/HeavyIon.h"
33 #include "HepMC/SimpleVector.h"
34 #include "TMatrixD.h"
35 #include "TF1.h"
36 
37 #include <iostream>
38 
39 using namespace edm;
40 using namespace std;
41 using namespace CLHEP;
42 
43 class RandGaussQ;
44 
45 
47  public:
49  virtual ~AfterBurnerGenerator();
50 
52  virtual void produce( edm::Event&, const edm::EventSetup& );
53 
54 
55  private:
60 
61 
62  CLHEP::HepRandomEngine* fEngine;
70 
71  int modmethod;
72  // 0, no mod
73  // 1, complete rnd, without non-flow
74  // 2, Newton method, with non-flow
75 
76  bool fixEP;
77  double fluct_v1;
78  double fluct_v2;
79  double fluct_v3;
80  double fluct_v4;
81  double fluct_v5;
82  double fluct_v6;
83 
84  TF1 * fv1;
85  TF1 * fv2;
86  TF1 * fv3;
87  TF1 * fv4;
88  TF1 * fv5;
89  TF1 * fv6;
90 
91  CLHEP::RandGaussQ* fRandom ;
92  CLHEP::RandFlat* fFlat;
93 
94  double GetV1(double);
95  double GetV2(double);
96  double GetV3(double);
97  double GetV4(double);
98  double GetV5(double);
99  double GetV6(double);
100 };
101 
102 
104  fEngine(0),
105  sourceLabel(p.getParameter<edm::InputTag>("src")),
106  fixEP(p.getUntrackedParameter<bool>("fixEP",true))
107 {
108 
110 
111  if ( ! rng.isAvailable()) {
112 
113  throw cms::Exception("Configuration")
114  << "The BaseEvtVtxGenerator requires the RandomNumberGeneratorService\n"
115  "which is not present in the configuration file. You must add the service\n"
116  "in the configuration file or remove the modules that require it.";
117  }
118 
119  CLHEP::HepRandomEngine& engine = rng->getEngine();
120  fEngine = &engine;
121  //cout << "AfterBurner seed = " << fEngine->getSeed() << endl;
122  fRandom = new CLHEP::RandGaussQ(*fEngine);
123  fFlat = new CLHEP::RandFlat(*fEngine);
124 
125  modv1 = p.getParameter<edm::InputTag>("modv1");
126  modv2 = p.getParameter<edm::InputTag>("modv2");
127  modv3 = p.getParameter<edm::InputTag>("modv3");
128  modv4 = p.getParameter<edm::InputTag>("modv4");
129  modv5 = p.getParameter<edm::InputTag>("modv5");
130  modv6 = p.getParameter<edm::InputTag>("modv6");
131 
132  modmethod = p.getParameter<int>("modmethod");
133 
134  fv1 = new TF1("fv1", modv1.label().c_str());
135  fv2 = new TF1("fv2", modv2.label().c_str());
136  fv3 = new TF1("fv3", modv3.label().c_str());
137  fv4 = new TF1("fv4", modv4.label().c_str());
138  fv5 = new TF1("fv5", modv5.label().c_str());
139  fv6 = new TF1("fv6", modv6.label().c_str());
140 
141  fluct_v1 = p.getParameter<double>("fluct_v1");
142  fluct_v2 = p.getParameter<double>("fluct_v2");
143  fluct_v3 = p.getParameter<double>("fluct_v3");
144  fluct_v4 = p.getParameter<double>("fluct_v4");
145  fluct_v5 = p.getParameter<double>("fluct_v5");
146  fluct_v6 = p.getParameter<double>("fluct_v6");
147 
148  produces<double>("v1");
149  produces<double>("v2");
150  produces<double>("v3");
151  produces<double>("v4");
152  produces<double>("v5");
153  produces<double>("v6");
154 
155  produces<double>("flucv1");
156  produces<double>("flucv2");
157  produces<double>("flucv3");
158  produces<double>("flucv4");
159  produces<double>("flucv5");
160  produces<double>("flucv6");
161 
162 }
163 
165 {
166  delete fRandom;
167  delete fFlat;
168 }
169 
170 
171 
173 {
174 
175 
176  Handle<HepMCProduct> HepMCEvt ;
177  evt.getByLabel( sourceLabel, HepMCEvt ) ;
178 
179  HepMC::GenEvent * genevt = (HepMC::GenEvent *)HepMCEvt->GetEvent();
180  HepMC::HeavyIon * hi = genevt->heavy_ion();
181  double ep = 0;
182  if ( hi ) {
183  ep = hi->event_plane_angle();
184  } else {
185  ep = 0;
186  }
187 
188  double meanv1 = 0;
189  double meanv2 = 0;
190  double meanv3 = 0;
191  double meanv4 = 0;
192  double meanv5 = 0;
193  double meanv6 = 0;
194 
195  double sigmav1 = 0;
196  double sigmav2 = 0;
197  double sigmav3 = 0;
198  double sigmav4 = 0;
199  double sigmav5 = 0;
200  double sigmav6 = 0;
201 
202  double v1 = -1;
203  double v2 = -1;
204  double v3 = -1;
205  double v4 = -1;
206  double v5 = -1;
207  double v6 = -1;
208 
209  int n = 0;
210  for ( HepMC::GenEvent::particle_iterator part = genevt->particles_begin();
211  part != genevt->particles_end(); ++part ) {
212  double E = (*part)->momentum().e();
213  double px = (*part)->momentum().x();
214  double py = (*part)->momentum().y();
215  double pz = (*part)->momentum().z();
216  double pt = sqrt(px*px+py*py);
217 
218  do { v1 = GetV1(pt); } while ( v1 < 0);
219  do { v2 = GetV2(pt); } while ( v2 < 0);
220  do { v3 = GetV3(pt); } while ( v3 < 0);
221  do { v4 = GetV4(pt); } while ( v4 < 0);
222  do { v5 = GetV5(pt); } while ( v5 < 0);
223  do { v6 = GetV6(pt); } while ( v6 < 0);
224 
225 
226  meanv1 += v1;
227  meanv2 += v2;
228  meanv3 += v3;
229  meanv4 += v4;
230  meanv5 += v5;
231  meanv6 += v6;
232 
233  sigmav1 += v1*v1;
234  sigmav2 += v2*v2;
235  sigmav3 += v3*v3;
236  sigmav4 += v4*v4;
237  sigmav5 += v5*v5;
238  sigmav6 += v6*v6;
239  n++;
240 
241  if ( modmethod == 0 ) continue;
242  if ( modmethod == 1 ) {
243  double phi;
244  double pmax = 1+2*fabs(v1)+2*fabs(v2)+2*fabs(v3)+2*fabs(v4)+2*fabs(v5)+2*fabs(v6);
245  double ptest = 0;
246  do {
247  phi = fFlat->fire(-CLHEP::pi, CLHEP::pi);
248  ptest = 1+2*v1*cos(phi) + 2*v2*cos(2*phi) + 2*v3*cos(3*phi) + 2*v4*cos(4*phi) + 2*v5*cos(5*phi) + 2*v6*cos(6*phi);
249  } while ( ptest < fFlat->fire(pmax) );
250  if (!fixEP) phi += ep;
251  px = pt*cos(phi);
252  py = pt*sin(phi);
253  (*part)->set_momentum(HepMC::FourVector(px, py, pz, E));
254  }
255  if ( modmethod == 2 ) {
256  HepMC::FourVector p = (*part)->momentum();
257  double phi1 = -999;
258  double dphi = 999;
259  double phi_RP = 0;
260  if ( !fixEP ) phi_RP = ep;
261  double phi0 = p.phi() - v2 * sin( 2*(p.phi() - phi_RP) );
262  phi1 = phi0 - v2*sin( 2*(phi0 - phi_RP) );
263  do {
264  double f = phi0 - p.phi() + 2*v1*sin( phi0 - phi_RP ) + v2 * sin( 2*(phi0-phi_RP) ) + 2./3.*v3*sin( 3*(phi0-phi_RP) ) + 0.5*v4*sin( 4*(phi0-phi_RP) ) + 0.4*v5*sin( 5*(phi0-phi_RP) ) + 1./3.*v6*sin( 6*(phi0-phi_RP) );
265  double fp = 1 + 2*v1*cos(phi0-phi_RP) + 2*v2*cos( 2*(phi0-phi_RP) ) + 2*v3*cos( 3*(phi0-phi_RP) ) + 2*v4*cos( 4*(phi0-phi_RP) ) + 2*v5*cos( 5*(phi0-phi_RP)) + 2*v5*cos( 6*(phi0-phi_RP) ) + 2*v6*cos( 6*(phi0-phi_RP) );
266  phi1 = phi0 - f / fp;
267  dphi = phi1 - phi0;
268  phi0 = phi1;
269  } while ( fabs(dphi)>0.01 );
270  px = pt * cos( phi1 );
271  py = pt * sin( phi1 );
272  (*part)->set_momentum(HepMC::FourVector(px, py, pz, E));
273  }
274 
275  }
276 
277  auto_ptr<double> ptr_v1(new double(meanv1/n)) ;
278  auto_ptr<double> ptr_v2(new double(meanv2/n)) ;
279  auto_ptr<double> ptr_v3(new double(meanv3/n)) ;
280  auto_ptr<double> ptr_v4(new double(meanv4/n)) ;
281  auto_ptr<double> ptr_v5(new double(meanv5/n)) ;
282  auto_ptr<double> ptr_v6(new double(meanv6/n)) ;
283  evt.put(ptr_v1, "v1");
284  evt.put(ptr_v2, "v2");
285  evt.put(ptr_v3, "v3");
286  evt.put(ptr_v4, "v4");
287  evt.put(ptr_v5, "v5");
288  evt.put(ptr_v6, "v6");
289  auto_ptr<double> ptr_fv1(new double(sigmav1/n)) ;
290  auto_ptr<double> ptr_fv2(new double(sigmav2/n)) ;
291  auto_ptr<double> ptr_fv3(new double(sigmav3/n)) ;
292  auto_ptr<double> ptr_fv4(new double(sigmav4/n)) ;
293  auto_ptr<double> ptr_fv5(new double(sigmav5/n)) ;
294  auto_ptr<double> ptr_fv6(new double(sigmav6/n)) ;
295  evt.put(ptr_fv1, "flucv1");
296  evt.put(ptr_fv2, "flucv2");
297  evt.put(ptr_fv3, "flucv3");
298  evt.put(ptr_fv4, "flucv4");
299  evt.put(ptr_fv5, "flucv5");
300  evt.put(ptr_fv6, "flucv6");
301  return ;
302 }
303 
304 double
306 {
307  return fRandom->fire(fv1->Eval(pt), fluct_v1);
308 }
309 
310 
311 double
313 {
314  return fRandom->fire(fv2->Eval(pt), fluct_v2);
315 }
316 
317 double
319 {
320  return fRandom->fire(fv3->Eval(pt), fluct_v3);
321 }
322 
323 double
325 {
326  return fRandom->fire(fv4->Eval(pt), fluct_v4);
327 }
328 
329 double
331 {
332  return fRandom->fire(fv5->Eval(pt), fluct_v5);
333 }
334 
335 double
337 {
338  return fRandom->fire(fv6->Eval(pt), fluct_v6);
339 }
340 
nocap nocap const skelname & operator=(const skelname &)
CLHEP::RandGaussQ * fRandom
T getParameter(std::string const &) const
AfterBurnerGenerator(const edm::ParameterSet &p)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
const Double_t pi
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
T sqrt(T t)
Definition: SSEVec.h:46
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
bool isAvailable() const
Definition: Service.h:47
CLHEP::HepRandomEngine * fEngine
double f[11][100]
virtual CLHEP::HepRandomEngine & getEngine() const =0
Use this to get the random number engine, this is the only function most users should call...
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
part
Definition: HCALResponse.h:21
std::string const & label() const
Definition: InputTag.h:25
virtual void produce(edm::Event &, const edm::EventSetup &)
return a new event vertex
Definition: DDAxes.h:10