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