GENIEGenerator
Loading...
Searching...
No Matches
gMakePhotonStrucFunc.cxx
Go to the documentation of this file.
1//____________________________________________________________________________
2/*!
3\program gmkspl
4\brief GENIE utility program building Structure Functions needed for HEDIS
5 package.
6 Syntax :
7 gmkphotonsf [-h]
8 Note :
9 [] marks optional arguments.
10 <> marks a list of arguments out of which only one can be
11 selected at any given time.
12 Options :
13 *** See the User Manual for more details and examples. ***
14\author Alfonso Garcia <aagarciasoto \at km3net.de>
15 Harvard University & IFIC
16\created Dev 8, 2020
17\cpright Copyright (c) 2003-2025, The GENIE Collaboration
18 For the full text of the license visit http://copyright.genie-mc.org
19 or see $GENIE/LICENSE
20*/
21//____________________________________________________________________________
22
27
28#include <TSystem.h>
29#include <TMath.h>
30#include <Math/IFunction.h>
31#include <Math/Integrator.h>
32
33#include <string>
34#include <iostream>
35#include <fstream>
36
37#ifdef __GENIE_APFEL_ENABLED__
38#include "APFEL/APFEL.h"
39#endif
40#include "LHAPDF/LHAPDF.h"
41#ifdef __GENIE_LHAPDF6_ENABLED__
42const LHAPDF::PDF* pdf_cache;
43#endif
44
45using namespace std;
46
47using namespace genie;
48using namespace genie::constants;
49
50int fNucPdg = 0;
51
52#ifdef __GENIE_APFEL_ENABLED__
53class PhotonConv: public ROOT::Math::IBaseFunctionOneDim
54{
55 public:
56 PhotonConv(double x, double q) : ROOT::Math::IBaseFunctionOneDim(),xmin(x),Qin(q){};
57 ~PhotonConv(){};
58 ROOT::Math::IBaseFunctionOneDim * Clone (void) const { return new PhotonConv(xmin,Qin); }
59 unsigned int NDim (void) const { return 1; }
60 double DoEval (double y) const { return 2. * ( TMath::Power(xmin/y,2)+TMath::Power( 1.-xmin/y, 2) ) * pdf_cache->xfxQ(22, y, Qin); }
61 void SetPar (double x, double q) { xmin=x; Qin=q; }
62
63 private:
64 double xmin,Qin;
65};
66
67extern "C" void externalsetapfellept_(double* x, double* q, int* irep, double* xl, double* xf);
68
69
70// Requires a global cache of pdf_cache LHAPDF::PDF
71void externalsetapfellept_(double* x, double* q, int* irep, double* xl, double* xf){
72 if (*x >= 1 || *x < 0) {
73 for ( int i=0; i<13; i++ ) xf[i] = 0.;
74 for ( int i=0; i<7; i++ ) xl[i] = 0.;
75 return;
76 }
77 else{
78 for ( int i=0; i<13; i++ ) {
79 xf[i] = pdf_cache->xfxQ(i-6, *x, *q);
80 if ( pdg::IsNeutron(fNucPdg) ) {
81 if ( i==4 ) xf[i] = pdf_cache->xfxQ(-1, *x, *q);
82 else if( i==5 ) xf[i] = pdf_cache->xfxQ(-2, *x, *q);
83 else if( i==7 ) xf[i] = pdf_cache->xfxQ( 2, *x, *q);
84 else if( i==8 ) xf[i] = pdf_cache->xfxQ( 1, *x, *q);
85 }
86 }
87 for ( int i=0; i<7; i++ ) {
88 if ( pdg::IsProton (fNucPdg) ) {
89 if (i==0 || i==6) xl[i] = 0.;
90 else if (i==3 ) xl[i] = pdf_cache->xfxQ(22, *x, *q);
91 else{
92 double mlep;
93 if (i==1 || i==5) mlep = kMuonMass;
94 else if (i==2 || i==4) mlep = kElectronMass;
95 ROOT::Math::IBaseFunctionOneDim * func = new PhotonConv(*x,*q);
96 ROOT::Math::IntegrationOneDim::Type ig_type = ROOT::Math::IntegrationOneDim::kADAPTIVE;
97 ROOT::Math::Integrator ig(*func,ig_type,1,0.01,100000);
98 double res = ig.Integral(*x,1.);
99 xl[i] = APFEL::AlphaQED(*q)/2./kPi*TMath::Log( *q/mlep ) * res;
100 }
101 }
102 else if ( pdg::IsNeutron(fNucPdg) ) xl[i] = 0.0;
103 }
104 }
105
106 return;
107}
108#endif
109
110//____________________________________________________________________________
111int main(int argc, char ** argv)
112{
113
114 string basedir = "";
115 if ( gSystem->Getenv("PHOTON_SF_DATA_PATH")==NULL ) basedir = string(gSystem->Getenv("GENIE")) + "/data/evgen/photon-sf";
116 else basedir = string(gSystem->Getenv("PHOTON_SF_DATA_PATH"));
117 LOG("gmkphotonsf", pERROR) << "Base directory: " << basedir;
118
119 if ( gSystem->AccessPathName( basedir.c_str(), kWritePermission ) ) {
120 LOG("gmkphotonsf", pFATAL) << "Base directory doesnt exist or you dont have write permission.";
121 LOG("gmkphotonsf", pFATAL) << "Remember!!!";
122 LOG("gmkphotonsf", pFATAL) << "Path to base directory is defined with the enviroment variable PHOTON_SF_DATA_PATH.";
123 LOG("gmkphotonsf", pFATAL) << "If not defined, default location is $GENIE/data/evgen/photon-sf";
124 assert(0);
125 }
126
127 const int nx = 1000.;
128
129 int nucs[2] = { kPdgProton, kPdgNeutron };
131
132#ifdef __GENIE_APFEL_ENABLED__
133 for (int k=0; k<2; k++) {
134
135 fNucPdg = nucs[k];
136
137 // initialising APFEL framework
138 LOG("gmkphotonsf", pINFO) << "Initialising APFEL..." ;
139 string pdfset;
140 if (pdg::IsProton (fNucPdg) ) pdfset = "NNPDF31_nnlo_as_0118_luxqed";
141 else if (pdg::IsNeutron(fNucPdg) ) pdfset = "NNPDF31_nnlo_as_0118";
142
143 const LHAPDF::PDFSet set(pdfset);
144 pdf_cache = LHAPDF::mkPDF(pdfset,0);
145
146 double xPDFmin,QPDFmin,QPDFmax,mc,mb,mt;
147 stringstream( set.get_entry("MCharm") ) >> mc;
148 stringstream( set.get_entry("MBottom") ) >> mb;
149 stringstream( set.get_entry("MTop") ) >> mt;
150 stringstream( set.get_entry("QMin") ) >> QPDFmin;
151 stringstream( set.get_entry("QMax") ) >> QPDFmax;
152 stringstream( set.get_entry("XMin") ) >> xPDFmin;
153 LOG("gmkphotonsf", pINFO) << "xPDFmin = " << xPDFmin;
154 LOG("gmkphotonsf", pINFO) << "QPDFmin = " << QPDFmin;
155 LOG("gmkphotonsf", pINFO) << "QPDFmax = " << QPDFmax;
156 LOG("gmkphotonsf", pINFO) << "mc = " << mc;
157 LOG("gmkphotonsf", pINFO) << "mb = " << mb;
158 LOG("gmkphotonsf", pINFO) << "mt = " << mt;
159
160 APFEL::CleanUp();
161
162 APFEL::SetPDFSet(pdfset);
163 APFEL::SetReplica(0);
164 APFEL::SetPerturbativeOrder(2);
165 APFEL::SetQLimits(QPDFmin,QPDFmax);
166 APFEL::SetMaxFlavourPDFs(6);
167 APFEL::SetMaxFlavourAlpha(6);
168 APFEL::SetNumberOfGrids(3);
169 APFEL::SetGridParameters(1,100,5,1e-9);
170 APFEL::SetGridParameters(2,40,3,1e-1);
171 APFEL::SetGridParameters(3,60,3,8e-1);
172 APFEL::SetGFermi(kGF);
173 APFEL::SetPoleMasses(mc,mb,mt);
174 APFEL::SetTheory("QUniD");
175 APFEL::EnableLeptonEvolution(true);
176 APFEL::SetFastEvolution(true);
177 APFEL::SetPDFSet("leptexternal");
178 APFEL::InitializeAPFEL();
179
180 LOG("gmkphotonsf", pWARN) << "Init EvolveAPFEL";
181 APFEL::EvolveAPFEL(QPDFmin,kMw);
182 LOG("gmkphotonsf", pWARN) << "End EvolveAPFEL";
183
184 // open file in which SF will be stored
185
186 double x[nx];
187 for ( int i=0; i<nx; i++ ) x[i] = TMath::Power( 10, TMath::Log10(xPDFmin) + i*(TMath::Log10(1.)-TMath::Log10(xPDFmin))/(1000.-1) );
188
189 for(int j=0; j<6; j++) {
190
191 string SFname = basedir + "/PhotonSF_hitnuc"+to_string(fNucPdg)+"_hitlep"+to_string(pdgs[j])+".dat";
192 std::ofstream sf_stream(SFname);
193 for ( int i=0; i<nx; i++ ) {
194 double tmp = 0;
195 if ( pdg::IsNuE (pdgs[j]) ) tmp = APFEL::xLepton( 1,x[i]);
196 else if ( pdg::IsAntiNuE (pdgs[j]) ) tmp = APFEL::xLepton(-1,x[i]);
197 else if ( pdg::IsNuMu (pdgs[j]) ) tmp = APFEL::xLepton( 2,x[i]);
198 else if ( pdg::IsAntiNuMu (pdgs[j]) ) tmp = APFEL::xLepton(-2,x[i]);
199 else if ( pdg::IsNuTau (pdgs[j]) ) tmp = APFEL::xLepton( 3,x[i]);
200 else if ( pdg::IsAntiNuTau(pdgs[j]) ) tmp = APFEL::xLepton(-3,x[i]);
201 LOG("gmkphotonsf", pWARN) << "SF " << pdgs[j] << " [x=" << x[i] << "] = " << tmp;
202 sf_stream << x[i] << " " << tmp << endl;
203 }
204 // Close file in which SF are stored
205 sf_stream.close();
206 }
207
208 }
209#endif
210
211}
double xPDFmin
#define pINFO
Definition Messenger.h:62
#define pERROR
Definition Messenger.h:59
#define pFATAL
Definition Messenger.h:56
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE,...
Definition Messenger.h:96
#define pWARN
Definition Messenger.h:60
Most commonly used PDG codes. A set of utility functions to handle PDG codes is provided in PDGUtils.
int main()
const double e
double func(double x, double y)
Basic constants.
bool IsAntiNuTau(int pdgc)
Definition PDGUtils.cxx:183
bool IsNuE(int pdgc)
Definition PDGUtils.cxx:158
bool IsAntiNuE(int pdgc)
Definition PDGUtils.cxx:173
bool IsAntiNuMu(int pdgc)
Definition PDGUtils.cxx:178
bool IsProton(int pdgc)
Definition PDGUtils.cxx:336
bool IsNuMu(int pdgc)
Definition PDGUtils.cxx:163
bool IsNeutron(int pdgc)
Definition PDGUtils.cxx:341
bool IsNuTau(int pdgc)
Definition PDGUtils.cxx:168
THE MAIN GENIE PROJECT NAMESPACE
Definition AlgCmp.h:25
const int kPdgProton
Definition PDGCodes.h:81
const int kPdgNeutron
Definition PDGCodes.h:83
const int kPdgAntiNuE
Definition PDGCodes.h:29
const int kPdgAntiNuTau
Definition PDGCodes.h:33
const int kPdgNuE
Definition PDGCodes.h:28
const int kPdgNuTau
Definition PDGCodes.h:32
const int kPdgAntiNuMu
Definition PDGCodes.h:31
const int kPdgNuMu
Definition PDGCodes.h:30