GFlavorMap.cxx
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*!
3  Copyright (c) 2003-2020, The GENIE Collaboration
4  For the full text of the license visit http://copyright.genie-mc.org
5 
6  Robert Hatcher <rhatcher@fnal.gov>
7  Fermi National Accelerator Laboratory
8 */
9 //____________________________________________________________________________
10 
11 #include <iostream>
12 #include <iomanip>
13 #include <cassert>
14 #include <cstdlib>
15 
16 #include "Tools/Flux/GFlavorMap.h"
18 // self register with the factory
20 
21 #include "Framework/Messenger/Messenger.h"
22 #define LOG_BEGIN(a,b) LOG(a,b)
23 #define LOG_END ""
24 
25 // GENIE includes
27 
28 namespace genie {
29 namespace flux {
30 //____________________________________________________________________________
32 {
33  // Initialize with identity matrix
34  size_t jin, jout;
35  for (jin=0; jin<7; ++jin) {
36  for (jout=0; jout<7; ++jout ) {
37  fProb[jin][jout] = ( (jin==jout) ? 1. : 0. );
38  }
39  }
40 }
41 
43 
44 //____________________________________________________________________________
46 {
48  LOG_BEGIN("FluxBlender", pINFO)
49  << "GFlavorMap::Config \"" << config << "\"" << LOG_END;
50 
51  if ( config.find("swap") == 0 ||
52  config.find("map") == 0 ||
53  config.find("genie::flux::GFlavorMap") == 0 ) {
54  ParseMapString(config);
55  } else if ( config.find("fixedfrac") == 0 ) {
56  ParseFixedfracString(config);
57  } else {
58  LOG_BEGIN("FluxBlender", pWARN)
59  << "GFlavorMap::Config don't know how to parse \""
60  << config << "\"" << LOG_END;
61  LOG_BEGIN("FluxBlender", pWARN)
62  << " ... will attempt \"map\" strategy" << LOG_END;
63 
64  }
65 
66 }
67 
68 //____________________________________________________________________________
70 {
71  LOG_BEGIN("FluxBlender", pINFO)
72  << "GFlavorMap::ParseMapString \"" << config << "\"" << LOG_END;
73  vector<string> tokens = genie::utils::str::Split(config," ");
74  for (unsigned int jtok = 0; jtok < tokens.size(); ++jtok ) {
75  string tok1 = tokens[jtok];
76  if ( tok1 == "" ) continue;
77  if ( tok1 == "swap" || tok1 == "map" ) continue;
78  if ( tok1 == "genie::flux::GFlavorMap" ) continue;
79  // should have the form <int>:<int>
80  vector<string> pair = genie::utils::str::Split(tok1,":");
81  if ( pair.size() != 2 ) {
82  LOG_BEGIN("FluxBlender", pWARN)
83  << "could not parse " << tok1 << " split size=" << pair.size()
84  << LOG_END;
85  continue;
86  }
87  int pdg_in = strtol(pair[0].c_str(),NULL,0);
88  int indx_in = PDG2Indx(pdg_in);
89  int pdg_out = strtol(pair[1].c_str(),NULL,0);
90  int indx_out = PDG2Indx(pdg_out);
91  for (int jout = 0; jout < 7; ++jout ) {
92  fProb[indx_in][jout] = ( ( jout == indx_out ) ? 1 : 0 );
93  }
94 
95  }
96 }
97 
98 //____________________________________________________________________________
100 {
101  LOG_BEGIN("FluxBlender", pINFO)
102  << "GFlavorMap::ParseFixedFracString \"" << config << "\"" << LOG_END;
103  vector<string> tokens = genie::utils::str::Split(config,"{}");
104  for (unsigned int jtok = 0; jtok< tokens.size(); ++jtok ) {
105  string tok1 = genie::utils::str::TrimSpaces(tokens[jtok]);
106  if ( tok1 == "" ) continue;
107  if ( tok1 == "fixedfrac" ) continue;
108  // should have the form pdg:f0,f12,f14,f16,f-12,f-14,f-16
109  vector<string> pair = genie::utils::str::Split(tok1,":");
110  if ( pair.size() != 2 ) {
111  LOG_BEGIN("FluxBlender", pWARN)
112  << "could not parse \"" << tok1 << "\" split size=" << pair.size()
113  << LOG_END;
114  continue;
115  }
116  int pdg_in = strtol(pair[0].c_str(),NULL,0);
117  int indx_in = PDG2Indx(pdg_in);
118  vector<string> fracs = genie::utils::str::Split(pair[1],",");
119  if ( fracs.size() != 7 ) {
120  LOG_BEGIN("FluxBlender", pWARN)
121  << "could not parse frac list \"" << pair[1] << "\" split size=" << fracs.size()
122  << LOG_END;
123  continue;
124  }
125  // set each value
126  double psum = 0;
127  for (int indx_out = 0; indx_out < 7; ++indx_out ) {
128  double p = strtod(fracs[indx_out].c_str(),NULL);
129  psum += p;
130  fProb[indx_in][indx_out] = p;
131  }
132  if ( psum > 0 ) {
133  // normalize to 1.0
134  for (int indx_out = 0; indx_out < 7; ++indx_out )
135  fProb[indx_in][indx_out] /= psum;
136  }
137  }
138 }
139 
140 //____________________________________________________________________________
141 double GFlavorMap::Probability(int pdg_initial, int pdg_final,
142  double /* energy */ , double /* dist */ )
143 {
144  double prob = fProb[PDG2Indx(pdg_initial)][PDG2Indx(pdg_final)];
145  if ( false ) {
146  LOG_BEGIN("FluxBlender", pINFO)
147  << "Probability " << pdg_initial << "=>" << pdg_final
148  << " = " << prob << LOG_END;
149  }
150  return prob;
151 }
152 
153 //____________________________________________________________________________
154 void GFlavorMap::PrintConfig(bool /* verbose */)
155 {
156  size_t jin, jout;
157  LOG_BEGIN("FluxBlender", pINFO)
158  << "GFlavorMap::PrintConfig():" << LOG_END;
159 
160  // 1234567890[xxx]:
161  std::cout << " in \\ out ";
162  for (jout=0; jout<7; ++jout )
163  std::cout << " " << std::setw(3) << Indx2PDG(jout) << " ";
164  std::cout << std::endl;
165 
166  std::cout << "----------------+";
167  for (jout=0; jout<7; ++jout ) std::cout << "----------";
168  std::cout << std::endl;
169 
170  for (jin=0; jin<7; ++jin) {
171  std::cout << std::setw(10) << IndxName(jin)
172  << "[" << std::setw(3) << Indx2PDG(jin) << "] | ";
173  for (jout=0; jout<7; ++jout )
174  std::cout << std::setw(8) << fProb[jin][jout] << " ";
175  std::cout << std::endl;
176  }
177 
178 }
179 //____________________________________________________________________________
180 const char* GFlavorMap::IndxName(int indx)
181 {
182  static const char* name[] = { "sterile",
183  "nu_e", "nu_mu", "nu_tau",
184  "nu_e_bar", "nu_mu_bar", "nu_tau_bar" };
185  return name[indx];
186 
187 }
188 
189 //____________________________________________________________________________
190 } // namespace flux
191 } // namespace genie
static QCString name
Definition: declinfo.cpp:673
THE MAIN GENIE PROJECT NAMESPACE
Definition: AlgCmp.h:25
double Probability(int pdg_initial, int pdg_final, double energy, double dist)
Definition: GFlavorMap.cxx:141
int PDG2Indx(int pdg)
Definition: GFlavorMap.h:104
std::string string
Definition: nybbler.cc:12
GENIE interface for flavor modification.
Definition: GFlavorMap.h:51
#define LOG_END
Definition: GFlavorMap.cxx:23
#define FLAVORMIXREG4(_nsa, _nsb, _name, _fqname)
#define LOG_BEGIN(a, b)
Definition: GFlavorMap.cxx:22
static Config * config
Definition: config.cpp:1054
const char * IndxName(int indx)
Definition: GFlavorMap.cxx:180
void ParseMapString(std::string config)
Definition: GFlavorMap.cxx:69
p
Definition: test.py:223
#define pINFO
Definition: Messenger.h:62
void Config(std::string config)
Definition: GFlavorMap.cxx:45
double fProb[7][7]
Definition: GFlavorMap.h:87
#define pWARN
Definition: Messenger.h:60
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
string TrimSpaces(string input)
Definition: StringUtils.cxx:18
void ParseFixedfracString(std::string config)
Definition: GFlavorMap.cxx:99
vector< string > Split(string input, string delim)
Definition: StringUtils.cxx:36
int Indx2PDG(int indx)
Definition: GFlavorMap.h:117
void PrintConfig(bool verbose=true)
provide a means of printing the configuration
Definition: GFlavorMap.cxx:154
QTextStream & endl(QTextStream &s)