00001 #include <cassert>
00002 #include<iostream>
00003 #include<fstream>
00004 #include "TSystem.h"
00005 #include "MCReweight/Kfluk.h"
00006 #include "MCNtuple/NtpMCFluxInfo.h"
00007 #include "MessageService/MsgService.h"
00008
00009 CVSID("$Id: Kfluk.cxx,v 1.3 2006/12/03 02:31:45 gmieg Exp $");
00010
00011
00012 using namespace std;
00013
00014 Kfluk::Kfluk(const char* pathname):
00015 ELO(),
00016 EHI(),
00017 CK0E3(),
00018 CK0M3(),
00019 CKE3(),
00020 CKM3()
00021 {
00022
00023
00024
00025 std::string topDir=pathname;
00026 if(topDir=="") {
00027 topDir="MCReweight/data";
00028 std::string base="";
00029 base=getenv("SRT_PRIVATE_CONTEXT");
00030 if (base!="" && base!="."){
00031
00032 std::string path = base + "/" + topDir;
00033 void *dir_ptr = gSystem -> OpenDirectory(path.c_str());
00034 if(!dir_ptr){
00035 base=getenv("SRT_PUBLIC_CONTEXT");
00036 }
00037 }
00038 else{
00039 base=getenv("SRT_PUBLIC_CONTEXT");
00040 }
00041
00042
00043 if(base=="") {
00044 MSG("MCReweight",Msg::kFatal)<<"No SRT_PUBLIC_CONTEXT set"<<std::endl;
00045 assert(false);
00046 }
00047 topDir = base+ "/" + topDir;
00048 }
00049
00050 MSG("Kfluk",Msg::kDebug) <<"Kfluk reading files from: "<<topDir<<std::endl;
00051
00052 float low, high, val;
00053 ifstream in1((topDir+"/k0m3.vec").c_str());
00054 if(in1.is_open()){
00055 in1>>low;
00056 while(!in1.eof()){
00057 in1>>high>>val;
00058 ELO.push_back(low);
00059 EHI.push_back(high);
00060 CK0M3.push_back(val);
00061
00062 in1>>low;
00063 }
00064 in1.close();
00065 }
00066 else{
00067 MSG("Kfluk",Msg::kError)<<"Could not open "<<topDir+"/k0m3.vec"<<endl;
00068 }
00069
00070 ifstream in2((topDir+"/k0e3.vec").c_str());
00071 if(in2.is_open()){
00072 in2>>low;
00073 while(!in2.eof()){
00074 in2>>high>>val;
00075 CK0E3.push_back(val);
00076 in2>>low;
00077 }
00078 in2.close();
00079 }
00080 else{
00081 MSG("Kfluk",Msg::kError)<<"Could not open "<<topDir+"/k0e3.vec"<<endl;
00082 }
00083
00084 ifstream in3((topDir+"/km3.vec").c_str());
00085 if(in3.is_open()){
00086 in3>>low;
00087 while(!in3.eof()){
00088 in3>>high>>val;
00089 CKM3.push_back(val);
00090 in3>>low;
00091 }
00092 in3.close();
00093 }
00094 else{
00095 MSG("Kfluk",Msg::kError)<<"Could not open "<<topDir+"/km3.vec"<<endl;
00096 }
00097
00098
00099 ifstream in4((topDir+"/ke3.vec").c_str());
00100 if(in4.is_open()){
00101 in4>>low;
00102 while(!in4.eof()){
00103 in4>>high>>val;
00104 CKE3.push_back(val);
00105 in4>>low;
00106 }
00107 in4.close();
00108 }
00109 else{
00110 MSG("Kfluk",Msg::kError)<<"Could not open "<<topDir+"/ke3.vec"<<endl;
00111 }
00112
00113 bool sizematch=true;
00114 if(ELO.size()!=EHI.size()) sizematch=false;
00115 if(ELO.size()!=CK0E3.size()) sizematch=false;
00116 if(ELO.size()!=CK0M3.size()) sizematch=false;
00117 if(ELO.size()!=CKE3.size()) sizematch=false;
00118 if(ELO.size()!=CKM3.size()) sizematch=false;
00119
00120 if(!sizematch){
00121 MSG("Kfluk",Msg::kError) <<"Sizes of vectors do not match!"
00122 <<"Can not continue"<<std::endl;
00123 assert(false);
00124 }
00125
00126 }
00127
00128 Kfluk::~Kfluk()
00129 {}
00130
00131 double Kfluk::GetWeight(NtpMCFluxInfo *fluxinfo)
00132 {
00133 return GetWeight(fluxinfo->ndecay,fluxinfo->necm);
00134 }
00135
00136 double Kfluk::GetWeight(int ndecay, float ecm)
00137 {
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151 double corrk3 = 1.;
00152 if(ndecay==5) return corrk3;
00153 if(ndecay==8) return corrk3;
00154 if(ndecay>=11) return corrk3;
00155
00156 unsigned int i = 0;
00157 while(ecm>EHI[i]&&i<EHI.size()){
00158 i = i+1;
00159 }
00160 if(i>=EHI.size()){
00161 i = EHI.size()-1;
00162 }
00163
00164
00165
00166 if(ndecay==1||ndecay==2){
00167 corrk3 = CK0E3[i]*(40.67/38.70);
00168 }
00169 else if(ndecay==3||ndecay==4){
00170 corrk3 = CK0M3[i];
00171 }
00172 else if(ndecay==6||ndecay==9){
00173 corrk3 = CKE3[i]*(5.13/4.82);
00174 }
00175 else if(ndecay==7||ndecay==10){
00176 corrk3 = CKM3[i];
00177 }
00178
00179 return corrk3;
00180
00181 }