CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PtYDistributor.cc
Go to the documentation of this file.
1 
3 //#include "FWCore/ParameterSet/interface/FileInPath.h"
5 #include "TFile.h"
6 #include "TGraph.h"
7 
8 using namespace gen;
9 
10 PtYDistributor::PtYDistributor(edm::FileInPath fip, CLHEP::HepRandomEngine& fRandomEngine,
11  double ptmax = 100, double ptmin = 0,
12  double ymax = 10, double ymin = -10,
13  int ptbins = 1000, int ybins = 50)
14  : ptmax_(ptmax),ptmin_(ptmin),ymax_(ymax),ymin_(ymin), ptbins_(ptbins), ybins_(ybins)
15 {
16  // edm::FileInPath f1(input);
17  std::string fDataFile = fip.fullPath();
18 
19  std::cout<<" File from "<<fDataFile <<std::endl;
20  TFile f(fDataFile.c_str(),"READ");
21  TGraph* yfunc = (TGraph*)f.Get("rapidity");
22  TGraph* ptfunc = (TGraph*)f.Get("pt");
23 
24  if( !yfunc )
25  throw edm::Exception(edm::errors::NullPointerError,"PtYDistributor")
26  <<"Rapidity distribution could not be found in file "<<fDataFile;
27 
28  if( !ptfunc )
29  throw edm::Exception(edm::errors::NullPointerError,"PtYDistributor")
30  <<"Pt distribution could not be found in file "<<fDataFile;
31 
32  if(ptbins_ > 100000){
33  ptbins_ = 100000;
34  }
35 
36  if(ybins_ > 100000){
37  ybins_ = 100000;
38  }
39 
40  double aProbFunc1[100000];
41  double aProbFunc2[100000];
42 
43  for(int i = 0; i < ybins_; ++i){
44  double xy = ymin_+i*(ymax_-ymin_)/ybins_;
45  double yy = yfunc->Eval(xy);
46  aProbFunc1[i] = yy;
47  }
48 
49  for(int ip = 0; ip < ptbins_; ++ip){
50  double xpt = ptmin_+ip*(ptmax_-ptmin_)/ptbins_;
51  double ypt = ptfunc->Eval(xpt);
52  aProbFunc2[ip] = ypt;
53  }
54 
55  fYGenerator = new CLHEP::RandGeneral(fRandomEngine,aProbFunc1,ybins_);
56  fPtGenerator = new CLHEP::RandGeneral(fRandomEngine,aProbFunc2,ptbins_);
57 
58  f.Close();
59 
60 } // from file
61 
62 double
64  return fireY(ymin_,ymax_);
65 }
66 
67 double
69  return firePt(ptmin_,ptmax_);
70 }
71 
72 double
73 PtYDistributor::fireY(double ymin, double ymax){
74 
75  double y = -999;
76 
77  if(fYGenerator){
78  while(y < ymin || y > ymax)
79  y = ymin_+(ymax_-ymin_)*fYGenerator->fire();
80  }else{
81  throw edm::Exception(edm::errors::NullPointerError,"PtYDistributor")
82  <<"Random y requested but Random Number Generator for y not Initialized!";
83  }
84  return y;
85 }
86 
87 double
88 PtYDistributor::firePt(double ptmin, double ptmax){
89 
90  double pt = -999;
91 
92  if(fPtGenerator){
93  while(pt < ptmin || pt > ptmax)
94  pt = ptmin_+(ptmax_-ptmin_)*fPtGenerator->fire();
95  }else{
96  throw edm::Exception(edm::errors::NullPointerError,"PtYDistributor")
97  <<"Random pt requested but Random Number Generator for pt not Initialized!";
98  }
99  return pt;
100 }
int i
Definition: DBlmapReader.cc:9
double f[11][100]
CLHEP::RandGeneral * fYGenerator
CLHEP::RandGeneral * fPtGenerator
double ptmin
Definition: HydjetWrapper.h:86
tuple cout
Definition: gather_cfg.py:121
std::string fullPath() const
Definition: FileInPath.cc:171