diff --git a/BEMEWS_example.py b/BEMEWS_example.py index f96efa7..ffe1b7f 100644 --- a/BEMEWS_example.py +++ b/BEMEWS_example.py @@ -45,6 +45,10 @@ help='Maximum energy ax MeV') p.add_argument('--accuracy', type=float, help='Accuracy of Runge-Kutta solver') + p.add_argument('--output', action='store_true', + help='Output calculations to file(s)') + p.add_argument('--ecsvformat', action='store_true', + help='Output using astropy-compatible ECSV format') p.add_argument('--stepcounterlimit', type=int, help='Output every N steps through the Earth (higher = less output)') @@ -57,9 +61,7 @@ for k in config.keys(): defaults.update(dict(config[k])) settings = defaults - settings.update({k: v for k, v in args.items() if v is not None}) - - print(settings) + settings.update({k: v for k, v in args.items() if v is not None and v is not False}) # skycoordinates of neutrino source source = SkyCoord.from_name(settings['source']) @@ -103,8 +105,9 @@ # if set to True the BEMEWS module will output files in the 'out' directory # The stepcounterlimit controls how often output is written. The larger the number, the less often it happens. ID.outputflag = settings['output'] in ['True', 'true'] + ID.ecsvformat = settings['ecsvformat'] if isinstance(settings['ecsvformat'], bool) else settings['ecsvformat'] in ['True', 'true'] ID.stepcounterlimit = int(settings['stepcounterlimit']) - + if ID.outputflag: os.makedirs('out', exist_ok=True) diff --git a/config.ini b/config.ini index 2e6b58b..0d1ec67 100644 --- a/config.ini +++ b/config.ini @@ -23,4 +23,5 @@ Emin = 1 Emax = 60 accuracy = 1.01e-9 output = True +ecsvformat = False stepcounterlimit = 1 diff --git a/src/BEMEWS/_ext/BEMEWS.cpp b/src/BEMEWS/_ext/BEMEWS.cpp index f63bfec..1776bdf 100644 --- a/src/BEMEWS/_ext/BEMEWS.cpp +++ b/src/BEMEWS/_ext/BEMEWS.cpp @@ -92,6 +92,7 @@ PYBIND11_MODULE(_ext, m) .def_readwrite("accuracy", &InputDataBEMEWS::accuracy) .def_readwrite("stepcounterlimit", &InputDataBEMEWS::stepcounterlimit) .def_readwrite("NE", &InputDataBEMEWS::NE) + .def_readwrite("ecsvformat", &InputDataBEMEWS::ecsvformat) .def_readwrite("outputflag", &InputDataBEMEWS::outputflag) ; @@ -162,7 +163,7 @@ vector > > > Run(InputDataBEMEWS ID) ofstream fHvslambda; // a file for anything else ofstream fSvsE; - if(ID.outputflag==true){ Initialize_Output(outputfilenamestem,fPvslambda,fHvslambda);} + if(ID.outputflag==true){ Initialize_Output(outputfilenamestem,fPvslambda,fHvslambda,ID);} // ***************************************************** // ***************************************************** @@ -330,14 +331,14 @@ vector > > > Run(InputDataBEMEWS ID) if(ID.outputflag==true){ output=true;} if(output==true){ if(firsttime==true){ - Output_Pvslambda(firsttime,lasttime,fPvslambda,lambdamin,Y,Scumulative); - Output_Hvslambda(firsttime,lasttime,fHvslambda,lambdamin,Y,Scumulative); + Output_Pvslambda(firsttime,lasttime,fPvslambda,lambdamin,Y,Scumulative,ID); + Output_Hvslambda(firsttime,lasttime,fHvslambda,lambdamin,Y,Scumulative,ID); } firsttime = false; - Output_Pvslambda(firsttime,lasttime,fPvslambda,lambdamin,Y,Scumulative); - Output_Hvslambda(firsttime,lasttime,fHvslambda,lambdamin,Y,Scumulative); + Output_Pvslambda(firsttime,lasttime,fPvslambda,lambdamin,Y,Scumulative,ID); + Output_Hvslambda(firsttime,lasttime,fHvslambda,lambdamin,Y,Scumulative,ID); output = false; } @@ -454,9 +455,9 @@ vector > > > Run(InputDataBEMEWS ID) if(output==true) { cout<<"\nOutput at\t"< > > > Run(InputDataBEMEWS ID) else{ // output at the end of the code if(ID.outputflag==true){ output = true;} if(output==true){ - Output_Pvslambda(firsttime,lasttime,fPvslambda,lambdamax,Y,Scumulative); - Output_Hvslambda(firsttime,lasttime,fHvslambda,lambdamax,Y,Scumulative); + Output_Pvslambda(firsttime,lasttime,fPvslambda,lambdamax,Y,Scumulative,ID); + Output_Hvslambda(firsttime,lasttime,fHvslambda,lambdamax,Y,Scumulative,ID); lasttime = true; - Output_Pvslambda(firsttime,lasttime,fPvslambda,lambdamax,Y,Scumulative); - Output_Hvslambda(firsttime,lasttime,fHvslambda,lambdamax,Y,Scumulative); - Output_PvsE(lasttime,fPvsE,outputfilenamestem,lambdamax,Y,Scumulative); + Output_Pvslambda(firsttime,lasttime,fPvslambda,lambdamax,Y,Scumulative,ID); + Output_Hvslambda(firsttime,lasttime,fHvslambda,lambdamax,Y,Scumulative,ID); + Output_PvsE(lasttime,fPvsE,outputfilenamestem,lambdamax,Y,Scumulative,ID); output = false; } diff --git a/src/BEMEWS/_ext/input_class.h b/src/BEMEWS/_ext/input_class.h index 8339828..1cb067e 100644 --- a/src/BEMEWS/_ext/input_class.h +++ b/src/BEMEWS/_ext/input_class.h @@ -28,6 +28,7 @@ struct InputDataBEMEWS double accuracy; double stepcounterlimit; // how often it outputs data bool outputflag; // whether the code outputs data as it does the integration + bool ecsvformat; // whether the output is in ECSV or tab-separated text files InputDataBEMEWS(void) {;} }; diff --git a/src/BEMEWS/_ext/output.BEMEWS.cpp b/src/BEMEWS/_ext/output.BEMEWS.cpp index d9151a9..81e3570 100644 --- a/src/BEMEWS/_ext/output.BEMEWS.cpp +++ b/src/BEMEWS/_ext/output.BEMEWS.cpp @@ -18,21 +18,27 @@ using namespace prefixes; std::vector fPvslambdafilename; -void Initialize_Output(string outputfilenamestem,ofstream &fPvslambda,ofstream &fHvslambda) +void Initialize_Output(string outputfilenamestem,ofstream &fPvslambda,ofstream &fHvslambda, const InputDataBEMEWS &id) { stringstream filename; fPvslambdafilename=vector(NE); for(int i=0;i<=NE-1;i++) { filename.str(""); - if(NE>1){ filename << outputfilenamestem << string(":E=") << ((NE-1.-i)*EminMeV+i*EmaxMeV)/(NE-1.) << string("MeV:Pvslambda.dat");} - else{ filename << outputfilenamestem << string(":E=") << EminMeV << string("MeV:Pvslambda.dat");} + if(NE>1){ + filename << outputfilenamestem << string(":E=") << ((NE-1.-i)*EminMeV+i*EmaxMeV)/(NE-1.) + << (id.ecsvformat ? string("MeV:Pvslambda.ecsv") : string("MeV:Pvslambda.dat")); + } + else{ + filename << outputfilenamestem << string(":E=") << EminMeV + << (id.ecsvformat ? string("MeV:Pvslambda.ecsv") : string("MeV:Pvslambda.dat")); + } fPvslambdafilename[i]=filename.str(); fPvslambda.open(fPvslambdafilename[i].c_str()); fPvslambda.close(); // clears the file - } + } filename.str(""); - filename << outputfilenamestem < > > &Y,vector,NF,NF> > > &Scumulative) +void Output_Pvslambda(bool firsttime,bool lasttime,ofstream &fPvslambda,double lambda,vector > > &Y,vector,NF,NF> > > &Scumulative, const InputDataBEMEWS &id) { array,NF,NF>,NM> VfMSW, dVfMSWdlambda; double r = sqrt( RE*RE + lambda*lambda - 2.*RE*lambda*sin(-altitude) ); - if(r > RE){ r = RE;} + if(r > RE){ r = RE;} double rrho=rho(r); double YYe=Ye(r); VfMSW[nu][e][e]=Ve(rrho,YYe); VfMSW[nu][mu][mu]=Vmu(rrho,YYe); VfMSW[nu][tau][tau]=Vtau(rrho,YYe); - VfMSW[antinu]=-VfMSW[nu]; + VfMSW[antinu]=-VfMSW[nu]; - vector,NF,NF> > > Hf(NM,vector,NF,NF> >(NE)); - vector,NF,NF> > > UU(NM,vector,NF,NF> >(NE)); - vector,NF,NF> > > Sa(NM,vector,NF,NF> >(NE)), Sm(NM,vector,NF,NF> >(NE)), Smf(NM,vector,NF,NF> >(NE)), Sfm(NM,vector,NF,NF> >(NE)), Sf(NM,vector,NF,NF> >(NE)); + vector,NF,NF> > > Hf(NM,vector,NF,NF> >(NE)); + vector,NF,NF> > > UU(NM,vector,NF,NF> >(NE)); + vector,NF,NF> > > Sa(NM,vector,NF,NF> >(NE)), Sm(NM,vector,NF,NF> >(NE)), Smf(NM,vector,NF,NF> >(NE)), Sfm(NM,vector,NF,NF> >(NE)), Sf(NM,vector,NF,NF> >(NE)); vector > > kk(NM,vector >(NE)); vector > > dkk(NM,vector >(NE)); + + const string delimiter = id.ecsvformat ? string(" ") : string("\t"); int i; #pragma omp parallel for schedule(static) for(i=0;i<=NE-1;i++) { Hf[nu][i]=HfV[nu][i] + VfMSW[nu]; kk[nu][i]=k(Hf[nu][i]); - dkk[nu][i]=deltak(kk[nu][i]); - UU[nu][i]=MixingMatrix(Hf[nu][i],kk[nu][i],dkk[nu][i]); + dkk[nu][i]=deltak(kk[nu][i]); + UU[nu][i]=MixingMatrix(Hf[nu][i],kk[nu][i],dkk[nu][i]); - Sa[nu][i] = W(Y[nu][i]) * B(Y[nu][i]); + Sa[nu][i] = W(Y[nu][i]) * B(Y[nu][i]); - if(firsttime==false && lasttime==false){ Sm[nu][i] = Sa[nu][i] * Scumulative[nu][i];} - else{ Sm[nu][i] = Adjoint(UV[nu])*UU[nu][i] * Sa[nu][i] * Scumulative[nu][i];} - + if(firsttime==false && lasttime==false){ Sm[nu][i] = Sa[nu][i] * Scumulative[nu][i];} + else{ Sm[nu][i] = Adjoint(UV[nu])*UU[nu][i] * Sa[nu][i] * Scumulative[nu][i];} + Smf[nu][i]= Sm[nu][i] * Adjoint(UV[nu]); - if(lasttime==false){ - Sfm[nu][i] = UU[nu][i] * Sm[nu][i]; - Sf[nu][i] = UU[nu][i] * Smf[nu][i]; - } + if(lasttime==false){ + Sfm[nu][i] = UU[nu][i] * Sm[nu][i]; + Sf[nu][i] = UU[nu][i] * Smf[nu][i]; + } else{ Sfm[nu][i] = UV[nu] * Sm[nu][i]; - Sf[nu][i] = UV[nu] * Smf[nu][i]; - } + Sf[nu][i] = UV[nu] * Smf[nu][i]; + } // ******* Hf[antinu][i]=HfV[antinu][i] + VfMSW[antinu]; - kk[antinu][i]=kbar(Hf[antinu][i]); - dkk[antinu][i]=deltakbar(kk[antinu][i]); - UU[antinu][i]=MixingMatrix(Hf[antinu][i],kk[antinu][i],dkk[antinu][i]); + kk[antinu][i]=kbar(Hf[antinu][i]); + dkk[antinu][i]=deltakbar(kk[antinu][i]); + UU[antinu][i]=MixingMatrix(Hf[antinu][i],kk[antinu][i],dkk[antinu][i]); - Sa[antinu][i] = W(Y[antinu][i]) * B(Y[antinu][i]); + Sa[antinu][i] = W(Y[antinu][i]) * B(Y[antinu][i]); - if(firsttime==false && lasttime==false){ Sm[antinu][i] = Sa[antinu][i] * Scumulative[antinu][i];} - else{ Sm[antinu][i] = Adjoint(UV[antinu])*UU[antinu][i] * Sa[antinu][i] * Scumulative[antinu][i];} - + if(firsttime==false && lasttime==false){ Sm[antinu][i] = Sa[antinu][i] * Scumulative[antinu][i];} + else{ Sm[antinu][i] = Adjoint(UV[antinu])*UU[antinu][i] * Sa[antinu][i] * Scumulative[antinu][i];} + Smf[antinu][i]= Sm[antinu][i] * Adjoint(UV[antinu]); - if(lasttime==false) - { Sfm[antinu][i] = UU[antinu][i] * Sm[antinu][i]; - Sf[antinu][i] = UU[antinu][i] * Smf[antinu][i]; - } + if(lasttime==false) + { Sfm[antinu][i] = UU[antinu][i] * Sm[antinu][i]; + Sf[antinu][i] = UU[antinu][i] * Smf[antinu][i]; + } else{ Sfm[antinu][i] = UV[antinu] * Sm[antinu][i]; - Sf[antinu][i] = UV[antinu] * Smf[antinu][i]; - } - } + Sf[antinu][i] = UV[antinu] * Smf[antinu][i]; + } + } - for(i=0;i<=NE-1;i++) + for(i=0;i<=NE-1;i++) { fPvslambda.open(fPvslambdafilename[i].c_str(),std::ofstream::app); fPvslambda.precision(12); if(firsttime==true){ - fPvslambda<<"lambda [cm] \t r [cm]"; - - fPvslambda<<"\t P11 \t P12 \t P13 \t P21 \t P22 \t P23 \t P31 \t P32 \t P33"; - fPvslambda<<"\t Pbar11 \t Pbar12 \t Pbar13 \t Pbar21 \t Pbar22 \t Pbar23 \t Pbar31 \t Pbar32 \t Pbar33"; - - fPvslambda<<"\t Pe1 \t Pe2 \t Pe3 \t Pmu1 \t Pmu2 \t Pmu3 \t Ptau1 \t Ptau2 \t Ptau3"; - fPvslambda<<"\t Pbare1 \t Pbare2 \t Pbare3 \t Pbarmu1 \t Pbarmu2 \t Pbarmu3 \t Pbartau1 \t Pbartau2 \t Pbartau3"; - - fPvslambda<<"\t Pee \t Pemu \t Petau \t Pmue \t Pmumu \t Pmutau \t Ptaue \t Ptaumu \t Ptautau"; - fPvslambda<<"\t Pbaree \t Pbaremu \t Pbaretau \t Pbarmue \t Pbarmumu \t Pbarmutau \t Pbartaue \t Pbartaumu \t Pbartautau"; + if (id.ecsvformat) { + // ECSV YAML header + fPvslambda << "# %ECSV 1.0\n# ---\n# datatype:\n" + << "# - {name: lambda, unit: cm, datatype: float64, description: path length}\n" + << "# - {name: r, unit: cm, datatype: float64, description: radial distance}\n"; + + const char* pcl[2] = { "", "bar" }; + const char* flavor[3] = { "e", "mu", "tau" }; + + // Mass-mass transitions + for (int j=0; j<2; ++j) + for (int k=1; k<=3; ++k) + for (int l=1; l<=3; ++l) + fPvslambda << "# - {name: P" << pcl[j] << k << l << ", datatype: float64, description: " << k << "->" << l << " transition probability}\n"; + + // Flavor-mass transitions + for (int j=0; j<2; ++j) + for (int k=0; k<=2; ++k) + for (int l=1; l<=3; ++l) + fPvslambda << "# - {name: P" << pcl[j] << flavor[k] << l << ", datatype: float64, description: " << flavor[k] << "->" << l << " transition probability}\n"; + + // Flavor-flavor transitions + for (int j=0; j<2; ++j) + for (int k=0; k<=2; ++k) + for (int l=0; l<=2; ++l) + fPvslambda << "# - {name: P" << pcl[j] << flavor[k] << flavor[l] << ", datatype: float64, description: " << flavor[k] << "->" << flavor[l] << " transition probability}\n"; + + // Simulation settings metadata + fPvslambda << "# meta: !!omap\n" + << "# - settings:\n" + << "# - {Ebins: " << id.NE << ", description: number of energy bins}\n" + << "# - {Emin: " << id.Emin << ", unit: MeV, description: minimum energy}\n" + << "# - {Emax: " << id.Emax << ", unit: MeV, description: maximum energy}\n" + << "# - {deltam_21: " << id.deltam_21 << ", unit: eV2, description: 2->1 mass splitting}\n" + << "# - {deltam_32: " << id.deltam_32 << ", unit: eV2, description: 3->2 mass splitting}\n" + << "# - {theta_12: " << id.theta12 << ", unit: deg, description: 1->2 mixing angle}\n" + << "# - {theta_13: " << id.theta13 << ", unit: deg, description: 1->3 mixing angle}\n" + << "# - {theta_23: " << id.theta23 << ", unit: deg, description: 2->3 mixing angle}\n" + << "# - {delta_CP: " << id.deltaCP << ", unit: deg, description: CP violating phase}\n" + << "# - {accuracy: " << id.accuracy << ", description: accuracy of Runge-Kutta solver}\n" + << "# - {stepcounterlimit: " << id.stepcounterlimit << ", description: output data every N steps}\n"; + + // First-line column names + fPvslambda<<"lambda r"; + + fPvslambda<<" P11 P12 P13 P21 P22 P23 P31 P32 P33"; + fPvslambda<<" Pbar11 Pbar12 Pbar13 Pbar21 Pbar22 Pbar23 Pbar31 Pbar32 Pbar33"; + + fPvslambda<<" Pe1 Pe2 Pe3 Pmu1 Pmu2 Pmu3 Ptau1 Ptau2 Ptau3"; + fPvslambda<<" Pbare1 Pbare2 Pbare3 Pbarmu1 Pbarmu2 Pbarmu3 Pbartau1 Pbartau2 Pbartau3"; + + fPvslambda<<" Pee Pemu Petau Pmue Pmumu Pmutau Ptaue Ptaumu Ptautau"; + fPvslambda<<" Pbaree Pbaremu Pbaretau Pbarmue Pbarmumu Pbarmutau Pbartaue Pbartaumu Pbartautau"; + } + else { + fPvslambda<<"lambda [cm] \t r [cm]"; + + fPvslambda<<"\t P11 \t P12 \t P13 \t P21 \t P22 \t P23 \t P31 \t P32 \t P33"; + fPvslambda<<"\t Pbar11 \t Pbar12 \t Pbar13 \t Pbar21 \t Pbar22 \t Pbar23 \t Pbar31 \t Pbar32 \t Pbar33"; + + fPvslambda<<"\t Pe1 \t Pe2 \t Pe3 \t Pmu1 \t Pmu2 \t Pmu3 \t Ptau1 \t Ptau2 \t Ptau3"; + fPvslambda<<"\t Pbare1 \t Pbare2 \t Pbare3 \t Pbarmu1 \t Pbarmu2 \t Pbarmu3 \t Pbartau1 \t Pbartau2 \t Pbartau3"; + + fPvslambda<<"\t Pee \t Pemu \t Petau \t Pmue \t Pmumu \t Pmutau \t Ptaue \t Ptaumu \t Ptautau"; + fPvslambda<<"\t Pbaree \t Pbaremu \t Pbaretau \t Pbarmue \t Pbarmumu \t Pbarmutau \t Pbartaue \t Pbartaumu \t Pbartautau"; } + } - if(firsttime==true){ fPvslambda<<"\n"< > > &Y,vector,NF,NF> > > &Scumulative) - { string cmdotdat("cm.dat"); +void Output_PvsE(bool lasttime,ofstream &fPvsE,string outputfilenamestem,double lambda,vector > > &Y,vector,NF,NF> > > &Scumulative, const InputDataBEMEWS &id) + { string cmdotdat = id.ecsvformat ? string("cm.ecsv") : string("cm.dat"); stringstream filename; - if(lasttime==false){ filename.str(""); filename<" << l << " transition probability}\n"; + + // Flavor-mass transitions + for (int j=0; j<2; ++j) + for (int k=0; k<=2; ++k) + for (int l=1; l<=3; ++l) + fPvsE << "# - {name: P" << pcl[j] << flavor[k] << l << ", datatype: float64, description: " << flavor[k] << "->" << l << " transition probability}\n"; + + // Flavor-flavor transitions + for (int j=0; j<2; ++j) + for (int k=0; k<=2; ++k) + for (int l=0; l<=2; ++l) + fPvsE << "# - {name: P" << pcl[j] << flavor[k] << flavor[l] << ", datatype: float64, description: " << flavor[k] << "->" << flavor[l] << " transition probability}\n"; + + // Simulation settings metadata + fPvsE << "# meta: !!omap\n" + << "# - settings:\n" + << "# - {Ebins: " << id.NE << ", description: number of energy bins}\n" + << "# - {Emin: " << id.Emin << ", unit: MeV, description: minimum energy}\n" + << "# - {Emax: " << id.Emax << ", unit: MeV, description: maximum energy}\n" + << "# - {deltam_21: " << id.deltam_21 << ", unit: eV2, description: 2->1 mass splitting}\n" + << "# - {deltam_32: " << id.deltam_32 << ", unit: eV2, description: 3->2 mass splitting}\n" + << "# - {theta_12: " << id.theta12 << ", unit: deg, description: 1->2 mixing angle}\n" + << "# - {theta_13: " << id.theta13 << ", unit: deg, description: 1->3 mixing angle}\n" + << "# - {theta_23: " << id.theta23 << ", unit: deg, description: 2->3 mixing angle}\n" + << "# - {delta_CP: " << id.deltaCP << ", unit: deg, description: CP violating phase}\n" + << "# - {accuracy: " << id.accuracy << ", description: accuracy of Runge-Kutta solver}\n" + << "# - {stepcounterlimit: " << id.stepcounterlimit << ", description: output data every N steps}\n"; + + // First line: column names + fPvsE<<"E"; + + fPvsE<<" P11 P12 P13 P21 P22 P23 P31 P32 P33"; + fPvsE<<" Pbar11 Pbar12 Pbar13 Pbar21 Pbar22 Pbar23 Pbar31 Pbar32 Pbar33"; + + fPvsE<<" Pe1 Pe2 Pe3 Pmu1 Pmu2 Pmu3 Ptau1 Ptau2 Ptau3"; + fPvsE<<" Pbare1 Pbare2 Pbare3 Pbarmu1 Pbarmu2 Pbarmu3 Pbartau1 Pbartau2 Pbartau3"; + + fPvsE<<" Pee Pemu Petau Pmue Pmumu Pmutau Ptaue Ptaumu Ptautau"; + fPvsE<<" Pbaree Pbaremu Pbaretau Pbarmue Pbarmumu Pbarmutau Pbartaue Pbartaumu Pbartautau"; + } + else { + fPvsE<<"E [MeV]"; + + fPvsE<<"\t P11 \t P12 \t P13 \t P21 \t P22 \t P23 \t P31 \t P32 \t P33"; + fPvsE<<"\t Pbar11 \t Pbar12 \t Pbar13 \t Pbar21 \t Pbar22 \t Pbar23 \t Pbar31 \t Pbar32 \t Pbar33"; - fPvsE<<"\t P11 \t P12 \t P13 \t P21 \t P22 \t P23 \t P31 \t P32 \t P33"; - fPvsE<<"\t Pbar11 \t Pbar12 \t Pbar13 \t Pbar21 \t Pbar22 \t Pbar23 \t Pbar31 \t Pbar32 \t Pbar33"; + fPvsE<<"\t Pe1 \t Pe2 \t Pe3 \t Pmu1 \t Pmu2 \t Pmu3 \t Ptau1 \t Ptau2 \t Ptau3"; + fPvsE<<"\t Pbare1 \t Pbare2 \t Pbare3 \t Pbarmu1 \t Pbarmu2 \t Pbarmu3 \t Pbartau1 \t Pbartau2 \t Pbartau3"; - fPvsE<<"\t Pe1 \t Pe2 \t Pe3 \t Pmu1 \t Pmu2 \t Pmu3 \t Ptau1 \t Ptau2 \t Ptau3"; - fPvsE<<"\t Pbare1 \t Pbare2 \t Pbare3 \t Pbarmu1 \t Pbarmu2 \t Pbarmu3 \t Pbartau1 \t Pbartau2 \t Pbartau3"; + fPvsE<<"\t Pee \t Pemu \t Petau \t Pmue \t Pmumu \t Pmutau \t Ptaue \t Ptaumu \t Ptautau"; + fPvsE<<"\t Pbaree \t Pbaremu \t Pbaretau \t Pbarmue \t Pbarmumu \t Pbarmutau \t Pbartaue \t Pbartaumu \t Pbartautau"; + } - fPvsE<<"\t Pee \t Pemu \t Petau \t Pmue \t Pmumu \t Pmutau \t Ptaue \t Ptaumu \t Ptautau"; - fPvsE<<"\t Pbaree \t Pbaremu \t Pbaretau \t Pbarmue \t Pbarmumu \t Pbarmutau \t Pbartaue \t Pbartaumu \t Pbartautau"; + const string delimiter = id.ecsvformat ? string(" ") : string("\t"); - for(i=0;i<=NE-1;i++) - { fPvsE<<"\n"< > > &Y,vector,NF,NF> > > &Scumulative) +void Output_Hvslambda(bool firsttime,bool lasttime,ofstream &fHvslambda,double lambda,vector > > &Y,vector,NF,NF> > > &Scumulative, const InputDataBEMEWS &id) { MATRIX,NF,NF> VfMSW,VfMSWbar; double r, rrho, YYe; // ************* r = sqrt( RE*RE + lambda*lambda - 2.*RE*lambda*sin(-altitude) ); - if(r > RE){ r = RE;} + if(r > RE){ r = RE;} rrho=YYe=0.; // **************** @@ -310,16 +441,46 @@ void Output_Hvslambda(bool firsttime,bool lasttime,ofstream &fHvslambda,double l } // ************** + const string delimiter = id.ecsvformat ? string(" ") : string("\t"); if(firsttime==true){ - fHvslambda<<"lambda [cm] \t r [cm] \t rho [g/cm^3] \t Ye [] \t HMSW_ee [erg]"; - } + if (id.ecsvformat) { + // YAML header with datatypes + fHvslambda << "# %ECSV 1.0\n# ---\n# datatype:\n" + << "# - {name: lambda, unit: cm, datatype: float64, description: path length}\n" + << "# - {name: r, unit: cm, datatype: float64, description: radial distance}\n" + << "# - {name: rho, unit: g / cm3, datatype: float64, description: density}\n" + << "# - {name: Ye, datatype: float64, description: electron fraction}\n" + << "# - {name: HMSW_ee, unit: erg, datatype: float64, description: MSW potential}\n"; + + // Simulation settings metadata + fHvslambda << "# meta: !!omap\n" + << "# - settings:\n" + << "# - {Ebins: " << id.NE << ", description: number of energy bins}\n" + << "# - {Emin: " << id.Emin << ", unit: MeV, description: minimum energy}\n" + << "# - {Emax: " << id.Emax << ", unit: MeV, description: maximum energy}\n" + << "# - {deltam_21: " << id.deltam_21 << ", unit: eV2, description: 2->1 mass splitting}\n" + << "# - {deltam_32: " << id.deltam_32 << ", unit: eV2, description: 3->2 mass splitting}\n" + << "# - {theta_12: " << id.theta12 << ", unit: deg, description: 1->2 mixing angle}\n" + << "# - {theta_13: " << id.theta13 << ", unit: deg, description: 1->3 mixing angle}\n" + << "# - {theta_23: " << id.theta23 << ", unit: deg, description: 2->3 mixing angle}\n" + << "# - {delta_CP: " << id.deltaCP << ", unit: deg, description: CP violating phase}\n" + << "# - {accuracy: " << id.accuracy << ", description: accuracy of Runge-Kutta solver}\n" + << "# - {stepcounterlimit: " << id.stepcounterlimit << ", description: output data every N steps}\n"; + + // First line with column names + fHvslambda << "lambda r rho Ye HMSW_ee"; + } + else { + fHvslambda << "lambda [cm] \t r [cm] \t rho [g/cm^3] \t Ye [] \t HMSW_ee [erg]"; + } + } - if(firsttime==true){ fHvslambda<<"\n"< fPvsrfilename; -void Initialize_Output(std::string outputfilenamestem,std::ofstream &fPvslambda,std::ofstream &fHvslambda); +void Initialize_Output(std::string outputfilenamestem, std::ofstream &fPvslambda, std::ofstream &fHvslambda, const InputDataBEMEWS &id); void Close_Output(std::ofstream &fHvslambda); -void Output_Pvslambda(bool firsttime,bool lasttime,std::ofstream &fPvslambda,double lambda,std::vector > > &Y,std::vector,NF,NF> > > &Scumulative); +void Output_Pvslambda(bool firsttime, bool lasttime, std::ofstream &fPvslambda, double lambda, std::vector > > &Y, std::vector, NF, NF> > > &Scumulative, const InputDataBEMEWS &id); -void Output_PvsE(bool lasttime,std::ofstream &fPvsE,std::string outputfilenamestem,double lambda,std::vector > > &Y,std::vector,NF,NF> > > &Scumulative); +void Output_PvsE(bool lasttime, std::ofstream &fPvsE, std::string outputfilenamestem, double lambda, std::vector > > &Y, std::vector, NF, NF> > > &Scumulative, const InputDataBEMEWS &id); -void Output_Hvslambda(bool firsttime,bool lasttime,std::ofstream &fHvslambda,double lambda,std::vector > > &Y,std::vector,NF,NF> > > &Scumulative); +void Output_Hvslambda(bool firsttime, bool lasttime, std::ofstream &fHvslambda, double lambda, std::vector > > &Y, std::vector, NF, NF> > > &Scumulative, const InputDataBEMEWS &id); #endif diff --git a/src/BEMEWS/_ext/output_matrix.BEMEWS.cpp b/src/BEMEWS/_ext/output_matrix.BEMEWS.cpp index ea8207f..dcfa57f 100644 --- a/src/BEMEWS/_ext/output_matrix.BEMEWS.cpp +++ b/src/BEMEWS/_ext/output_matrix.BEMEWS.cpp @@ -16,7 +16,7 @@ void Pfm(double lambda,vector > > &Y,vector RE){ r = RE;} + if(r > RE){ r = RE;} rrho=rho(r); YYe=Ye(r); @@ -25,53 +25,53 @@ void Pfm(double lambda,vector > > &Y,vector,NF,NF> > > Hf(NM,vector,NF,NF> >(NE)); - vector,NF,NF> > > UU(NM,vector,NF,NF> >(NE)); - vector,NF,NF> > > Sa(NM,vector,NF,NF> >(NE)), Sm(NM,vector,NF,NF> >(NE)), Sfm(NM,vector,NF,NF> >(NE)); + vector,NF,NF> > > Hf(NM,vector,NF,NF> >(NE)); + vector,NF,NF> > > UU(NM,vector,NF,NF> >(NE)); + vector,NF,NF> > > Sa(NM,vector,NF,NF> >(NE)), Sm(NM,vector,NF,NF> >(NE)), Sfm(NM,vector,NF,NF> >(NE)); vector > > kk(NM,vector >(NE)); vector > > dkk(NM,vector >(NE)); int i; #pragma omp parallel for schedule(static) - for(i=0;i<=NE-1;i++) + for(i=0;i<=NE-1;i++) { Hf[nu][i]=HfV[nu][i] + VfMSW[nu]; kk[nu][i]=k(Hf[nu][i]); - dkk[nu][i]=deltak(kk[nu][i]); + dkk[nu][i]=deltak(kk[nu][i]); UU[nu][i] = MixingMatrix(Hf[nu][i],kk[nu][i],dkk[nu][i]); - Sa[nu][i] = W(Y[nu][i]) * B(Y[nu][i]); + Sa[nu][i] = W(Y[nu][i]) * B(Y[nu][i]); // take into account the density jump from Earth matter back to vacuum - Sm[nu][i] = Adjoint(UV[nu])*UU[nu][i] * Sa[nu][i] * Scumulative[nu][i]; + Sm[nu][i] = Adjoint(UV[nu])*UU[nu][i] * Sa[nu][i] * Scumulative[nu][i]; Sfm[nu][i]= UV[nu] * Sm[nu][i]; - // ********* - Hf[antinu][i]=HfV[antinu][i] + VfMSW[antinu]; - kk[antinu][i]=kbar(Hf[antinu][i]); - dkk[antinu][i]=deltakbar(kk[antinu][i]); - UU[antinu][i]=MixingMatrix(Hf[antinu][i],kk[antinu][i],dkk[antinu][i]); + // ********* + Hf[antinu][i]=HfV[antinu][i] + VfMSW[antinu]; + kk[antinu][i]=kbar(Hf[antinu][i]); + dkk[antinu][i]=deltakbar(kk[antinu][i]); + UU[antinu][i]=MixingMatrix(Hf[antinu][i],kk[antinu][i],dkk[antinu][i]); - Sa[antinu][i] = W(Y[antinu][i]) * B(Y[antinu][i]); + Sa[antinu][i] = W(Y[antinu][i]) * B(Y[antinu][i]); // take into account the density jump from Earth matter back to vacuum - Sm[antinu][i] = Adjoint(UV[antinu])*UU[antinu][i] * Sa[antinu][i] * Scumulative[antinu][i]; + Sm[antinu][i] = Adjoint(UV[antinu])*UU[antinu][i] * Sa[antinu][i] * Scumulative[antinu][i]; Sfm[antinu][i]= UV[antinu] * Sm[antinu][i]; - } + } // ******* - for(i=0;i<=NE-1;i++) + for(i=0;i<=NE-1;i++) { PPfm[nu][i][e][0]=norm(Sfm[nu][i][e][0]); PPfm[nu][i][e][1]=norm(Sfm[nu][i][e][1]); PPfm[nu][i][e][2]=norm(Sfm[nu][i][e][2]); - PPfm[nu][i][mu][0]=norm(Sfm[nu][i][mu][0]); PPfm[nu][i][mu][1]=norm(Sfm[nu][i][mu][1]); PPfm[nu][i][mu][2]=norm(Sfm[nu][i][mu][2]); - PPfm[nu][i][tau][0]=norm(Sfm[nu][i][tau][0]); PPfm[nu][i][tau][1]=norm(Sfm[nu][i][tau][1]); PPfm[nu][i][tau][2]=norm(Sfm[nu][i][tau][2]); + PPfm[nu][i][mu][0]=norm(Sfm[nu][i][mu][0]); PPfm[nu][i][mu][1]=norm(Sfm[nu][i][mu][1]); PPfm[nu][i][mu][2]=norm(Sfm[nu][i][mu][2]); + PPfm[nu][i][tau][0]=norm(Sfm[nu][i][tau][0]); PPfm[nu][i][tau][1]=norm(Sfm[nu][i][tau][1]); PPfm[nu][i][tau][2]=norm(Sfm[nu][i][tau][2]); - PPfm[antinu][i][e][0]=norm(Sfm[antinu][i][e][0]); PPfm[antinu][i][e][1]=norm(Sfm[antinu][i][e][1]); PPfm[antinu][i][e][2]=norm(Sfm[antinu][i][e][2]); - PPfm[antinu][i][mu][0]=norm(Sfm[antinu][i][mu][0]); PPfm[antinu][i][mu][1]=norm(Sfm[antinu][i][mu][1]); PPfm[antinu][i][mu][2]=norm(Sfm[antinu][i][mu][2]); + PPfm[antinu][i][e][0]=norm(Sfm[antinu][i][e][0]); PPfm[antinu][i][e][1]=norm(Sfm[antinu][i][e][1]); PPfm[antinu][i][e][2]=norm(Sfm[antinu][i][e][2]); + PPfm[antinu][i][mu][0]=norm(Sfm[antinu][i][mu][0]); PPfm[antinu][i][mu][1]=norm(Sfm[antinu][i][mu][1]); PPfm[antinu][i][mu][2]=norm(Sfm[antinu][i][mu][2]); PPfm[antinu][i][tau][0]=norm(Sfm[antinu][i][tau][0]); PPfm[antinu][i][tau][1]=norm(Sfm[antinu][i][tau][1]); PPfm[antinu][i][tau][2]=norm(Sfm[antinu][i][tau][2]); - } + } //return PPfm; }