Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

SKZPWeightCalculator.cxx

Go to the documentation of this file.
00001 #include <cassert>
00002 #include <map>
00003 #include "DatabaseInterface/DbiConfigStream.h"
00004 #include "MCReweight/Zbeam.h"
00005 #include "MCReweight/Zfluk.h"
00006 #include "MCNtuple/NtpMCFluxInfo.h"
00007 #include "MCNtuple/NtpMCTruth.h"
00008 #include "MCReweight/SKZPWeightCalculator.h"
00009 #include "MessageService/MsgService.h"
00010 
00011 #include "Conventions/BeamType.h"
00012 #include "MCReweight/BeamSys.h"
00013 
00014 #include "TMath.h"
00015 
00016 using namespace std;
00017 
00018 CVSID("$Id: SKZPWeightCalculator.cxx,v 1.28 2010/02/06 11:12:03 med Exp $");
00019 
00020 const double SKZPWeightCalculator::XP=25.;
00021 
00022 SKZPWeightCalculator::SKZPWeightCalculator(Registry *stdconfig):
00023   WeightCalculator(stdconfig),
00024   MAXBSPARS(20),
00025   MAXHPPARS(20),
00026   MAXDETPARS(20),
00027   read_pars_from_db(false),
00028   cfgname(""),
00029   cfgnum(kUnknown),
00030   sampsel(kNotSpecified),
00031   runfrac()
00032 {
00033   vtsRunIEnd = new VldTimeStamp(2006,3,1,0,0,0);
00034   vtsRunIIEnd = new VldTimeStamp(2007,8,1,0,0,0);
00035   vtsRunIIIEnd = new VldTimeStamp(2009,8,1,0,0,0);
00036   zbeam = new Zbeam();
00037   zfluk = new Zfluk();
00038   nwc = 0; // hold off until needed // new NeugenWeightCalculator();
00039   mcr = &MCReweight::Instance();
00040   Config();
00041 }
00042 
00043 SKZPWeightCalculator::SKZPWeightCalculator(string cn, bool readfromdb, bool beamonly):
00044   WeightCalculator(0),
00045   MAXBSPARS(20),
00046   MAXHPPARS(20),
00047   MAXDETPARS(20),
00048   read_pars_from_db(readfromdb),
00049   cfgname(cn),
00050   cfgnum(kUnknown),
00051   sampsel(kNotSpecified),
00052   runfrac()
00053 {
00054   fBeamOnly = beamonly;
00055 
00056   vtsRunIEnd = new VldTimeStamp(2006,4,1,0,0,0);
00057   vtsRunIIEnd = new VldTimeStamp(2007,8,1,0,0,0);
00058   vtsRunIIIEnd = new VldTimeStamp(2009,8,1,0,0,0);
00059   zbeam = new Zbeam();
00060   zfluk = new Zfluk();
00061   nwc = 0; // hold off until needed // new NeugenWeightCalculator();
00062   mcr = &MCReweight::Instance();
00063   Config();
00064 }
00065 
00066 SKZPWeightCalculator::~SKZPWeightCalculator()
00067 {
00068 
00069   delete vtsRunIEnd;
00070   vtsRunIEnd=0;
00071   delete vtsRunIIEnd;
00072   vtsRunIIEnd=0;
00073   delete vtsRunIIIEnd;
00074   vtsRunIIIEnd=0;
00075   delete zbeam;
00076   zbeam=0;
00077   delete zfluk;
00078   zfluk=0;
00079   delete nwc;
00080   nwc=0;
00081 
00082 }
00083 
00084 void SKZPWeightCalculator::Config()
00085 {
00086   if(cfgname==""){
00087     cfgname="PRL";
00088     MSG("SKZPWeightCalculator",Msg::kInfo)<<"You did not specify a "
00089                                           <<"SKZPWeight configuration."
00090                                           <<" Setting ConfigName to :"
00091                                           <<cfgname<<endl;
00092     cfgnum=kPRL;
00093   }
00094   SetConfigNum(cfgname);
00095 
00096 
00097   if(!read_pars_from_db){
00098     MSG("SKZPWeightCalculator",Msg::kInfo)<<"You did not select to read in "
00099                                           <<"SKZP Fit parameters from the DB."
00100                                           <<" You must specify your "
00101                                           <<"own parameters"<<endl;
00102     return;
00103   }
00104 
00105   //retrieve appropriate constants from DB
00106   Registry reg;
00107   
00108   //  cout<<"Trying to get parameters from DB"<<endl;
00109   DbiConfigStream stream("SKZPWeights",cfgname.c_str());
00110   if(stream.IsEmpty()){
00111     MSG("SKZPWeightCalculator",Msg::kWarning)
00112       << "Could not find SKZP configuration: "
00113       << cfgname
00114       << " in database.  " << endl
00115       << "If you want to run without database access"
00116       << " construct the weight calculator"
00117       << " with false as second arg." << endl;
00118     MSG("SKZPWeightCalculator",Msg::kFatal) << "Now assert()" << endl;
00119     assert(false);
00120   }
00121   //  cout<<"made dbiconfigstream"<<endl;
00122   stream >> &reg;
00123 
00124   //  cout<<"Read registry from db, and it contains:"<<endl;
00125   //  reg.PrettyPrint(cout);
00126 
00127 
00128 
00129   //load information from registry to private data members
00130   double tmpd;
00131   for(int i=0;i<MAXBSPARS;i++){
00132     if(reg.Get(Form("bs_par_%d",i),tmpd)){
00133       bs_pars.push_back(tmpd);
00134     }
00135   }
00136 
00137   for(int i=0;i<MAXHPPARS;i++){
00138     if(reg.Get(Form("hp_par_%d",i),tmpd)){
00139       hp_pars.push_back(tmpd);
00140     }
00141   }
00142 
00143   for(int i=0;i<MAXDETPARS;i++){
00144     if(reg.Get(Form("det_par_%d",i),tmpd)){
00145       det_pars.push_back(tmpd);
00146     }
00147   }
00148 
00149   if(cfgnum==kPiMinus){
00150     zfluk->SetParameters(hp_pars);
00151   }
00152   if(cfgnum==kDetXs || cfgnum==kDogwood1_Daikon07 || cfgnum==kDogwood1_Daikon07_v2){
00153     zfluk->SetParameters(hp_pars);
00154 
00155     if(!fBeamOnly) {
00156       nwc = new NeugenWeightCalculator();
00157       nwc->SetOptimization(true);
00158       Registry *nwc_reg=new Registry;
00159       nwc_reg->UnLockValues();
00160       nwc_reg->UnLockKeys();
00161       nwc_reg->Clear();
00162       
00163       nwc_reg->Set("neugen:config_name","MODBYRS");
00164       nwc_reg->Set("neugen:config_no",4);
00165       nwc_reg->Set("neugen:use_scale_factors",1);
00166       nwc_reg->Set("neugen:ma_qe",1.1);
00167       nwc_reg->Set("neugen:ma_res",1.1); 
00168       
00169       // This is specific to MODBYRS v4 where we weight them 
00170       // by their 1 sigma error as given in docdb-2989
00171       
00172       double kno1_val=0.1; //for ri12 and ri42
00173       double kno2_val=0.3; //for ri22 and ri32
00174       double kno3_val=1.0; //for rij3 
00175     
00176       double kno1_err=0.1; //for rij2 
00177       double kno2_err=0.2; //for rij3
00178       
00179       double kno_shift=1;
00180       
00181       nwc_reg->Set("neugen:kno_r112",
00182                  (kno1_val+kno_shift*kno1_err)/(kno1_val));
00183       nwc_reg->Set("neugen:kno_r142",
00184                    (kno1_val+kno_shift*kno1_err)/(kno1_val));
00185       nwc_reg->Set("neugen:kno_r122",
00186                    (kno2_val+kno_shift*kno1_err)/(kno2_val));
00187       nwc_reg->Set("neugen:kno_r132",
00188                    (kno2_val+kno_shift*kno1_err)/(kno2_val));
00189       nwc_reg->Set("neugen:kno_r113",
00190                    (kno3_val+kno_shift*kno2_err)/(kno3_val));
00191       nwc_reg->Set("neugen:kno_r123",
00192                    (kno3_val+kno_shift*kno2_err)/(kno3_val));
00193       nwc_reg->Set("neugen:kno_r133",
00194                    (kno3_val+kno_shift*kno2_err)/(kno3_val));
00195       nwc_reg->Set("neugen:kno_r143",
00196                    (kno3_val+kno_shift*kno2_err)/(kno3_val));
00197       
00198       nwc_reg->LockValues();
00199       nwc_reg->LockKeys();
00200       nwc->SetReweightConfig(nwc_reg);
00201       mcr->AddWeightCalculator(nwc);
00202     }
00203   }
00204   string tmpcfgname=cfgname;
00205   if(tmpcfgname.find("PRL_Syst")!=string::npos){
00206     tmpcfgname="PRL";
00207   }
00208   zbeam->SetReweightConfig(tmpcfgname);
00209 }
00210 
00211 void SKZPWeightCalculator::SetSampleSelection(std::string ss)
00212 {
00213   if(ss=="numu"||ss=="NuMu"||ss=="CC"){
00214     sampsel=kNuMuCC;
00215   }
00216   else if(ss=="anumu"||ss=="antinumu"||ss=="numubar"||ss=="AntiNuMu"||ss=="NuMuBar"){
00217     sampsel=kAntiNuMu;
00218   }
00219   else if(ss=="nue"||ss=="Nue"){
00220     sampsel=kNue;
00221   }
00222 
00223 }
00224 
00225 double SKZPWeightCalculator::GetWeight(Registry *eventinfo)
00226 {
00227   //don't use me I'm slow.
00228   //the GetWeight function this version calls has been tested,
00229   //but reading the event info from the registry has not 
00230   //been tested (it should work, I just haven't tried it yet)
00231   bool gotallinfo=true;
00232   int det,ibeam,tptype,ccnc,inu;
00233   double pt, pz, true_enu, reco_emu, reco_eshw;
00234   double new_reco_emu, new_reco_eshw, beamweight, detweight;
00235   
00236   if(!eventinfo->Get("evt:det",det)) gotallinfo=false;
00237   if(!eventinfo->Get("evt:ibeam",ibeam)) gotallinfo=false;
00238   if(!eventinfo->Get("evt:tptype",tptype)) gotallinfo=false;
00239   if(!eventinfo->Get("evt:ccnc",ccnc)) gotallinfo=false;
00240   if(!eventinfo->Get("evt:inu",inu)) gotallinfo=false;
00241   if(!eventinfo->Get("evt:pt",pt)) gotallinfo=false;
00242   if(!eventinfo->Get("evt:pz",pz)) gotallinfo=false; 
00243   if(!eventinfo->Get("evt:true_enu",true_enu)) gotallinfo=false;  
00244   if(!eventinfo->Get("evt:reco_emu",reco_emu)) gotallinfo=false;  
00245   if(!eventinfo->Get("evt:reco_eshw",reco_eshw)) gotallinfo=false;
00246 
00247   if(!gotallinfo){
00248     MSG("SKZPWeightCalculator",Msg::kError)<<"Could not retrieve all necessary"
00249                                            <<" event information from "
00250                                            <<"eventinfo registry, returning 1."
00251                                            <<endl;
00252     return 1.;
00253   }
00254 
00255   GetWeight(det,ibeam,tptype,pt,pz,ccnc,
00256             true_enu,inu,reco_emu,reco_eshw,
00257             new_reco_emu,new_reco_eshw,beamweight,detweight);
00258 
00259   //put new reco energies and weights into registry;
00260   eventinfo->UnLockKeys();
00261   eventinfo->Set("evt:new_reco_emu",new_reco_emu);
00262   eventinfo->Set("evt:new_reco_eshw",new_reco_eshw);
00263   eventinfo->Set("evt:beamweight",beamweight);
00264   eventinfo->Set("evt:detweight",detweight);
00265   eventinfo->LockKeys();
00266 
00267   // this function returns only the beam weight, as that is 
00268   //what most people are encouraged to use, the detweight is
00269   //returned through the registry
00270   return beamweight;
00271 }
00272 
00273 double SKZPWeightCalculator::GetWeight(const NtpMCTruth *mc, int det, int Ibeam,
00274                                        double reco_emu, double reco_eshw, 
00275                                        double &new_reco_emu, double &new_reco_eshw,
00276                                        double &beamweight, double &detweight,
00277                                        RunPeriod_t rp,
00278                                        double true_eshw,MCEventInfo *ei)
00279 {
00280 
00281 
00282   //retrieve truth information on the neutrino interaction from
00283   //the NtpMCTruth object
00284   int ccnc = mc->iaction;
00285   double true_enu = 1.*mc->p4neu[3];
00286   int inu = mc->inu;
00287 
00288 
00289   //pass the truth info and the fluxinfo object to the next
00290   //form of GetWeight
00291   return GetWeight(&(mc->flux),det,Ibeam,
00292                    ccnc,true_enu,inu,
00293                    reco_emu,reco_eshw,
00294                    new_reco_emu,new_reco_eshw,
00295                    beamweight, detweight,rp,true_eshw,ei);
00296 
00297 }
00298 
00299 double SKZPWeightCalculator::GetWeight(const NtpMCFluxInfo *fi, int det, int Ibeam,
00300                                        int ccnc, double true_enu,int inu,
00301                                        double reco_emu, double reco_eshw, 
00302                                        double &new_reco_emu, double &new_reco_eshw,
00303                                        double &beamweight, double &detweight,
00304                                        RunPeriod_t rp,
00305                                        double true_eshw,MCEventInfo *ei)
00306 {
00307   int parenttype=-1;
00308   double parentpz=0.;
00309   double parentpx=0.;
00310   double parentpy=0.;
00311 
00312   //extract the flux weighting variables from the fluxinfo object
00313   //due to bug in v18 flux files, the tp* variables
00314   //(i.e. info pertaining to the particle created in the target)
00315   //are the same as the pp* variables
00316   //(i.e. the info pertaining to the particle leaving the target)
00317   //in v19 flux and beyond, this has been fixed.
00318   //In the future, we will probably want to weight based on the tp variables,
00319   //but to compare with what was done before, I want the option to 
00320   //use the pp* variables, which is why this if statement is here.
00321 
00322   if(cfgname=="v19fit"){  //this isn't a real config yet
00323     parenttype = fi->ptype;
00324     parentpz = 1.*fi->pppz;
00325     parentpy = 1.*fi->ppdydz*parentpz;
00326     parentpx = 1.*fi->ppdxdz*parentpz;
00327   }
00328   else{
00329     parenttype = fi->tptype;
00330     parentpz = 1.*fi->tpz;
00331     parentpy = 1.*fi->tpy;
00332     parentpx = 1.*fi->tpx;
00333   }
00334 
00335   double pt = sqrt(parentpy*parentpy+parentpx*parentpx);
00336 
00337   //pass the variables on to the next version of GetWeight
00338   return GetWeight(det,Ibeam,parenttype,pt,parentpz,ccnc,true_enu,inu,
00339                    reco_emu,reco_eshw,new_reco_emu,new_reco_eshw,beamweight,detweight,
00340                    rp,true_eshw,ei);
00341 
00342 }
00343   
00344 double SKZPWeightCalculator::GetWeight(int det, int Ibeam,
00345                                        int tptype, double pt, double pz,    
00346                                        int ccnc, double true_enu,int inu,
00347                                        double reco_emu, double reco_eshw,
00348                                        double &new_reco_emu, double &new_reco_eshw,
00349                                        double &beamweight, double &detweight,
00350                                        RunPeriod_t rp,
00351                                        double true_eshw,MCEventInfo *ei)
00352 {
00353   
00354   //do the beam weighting
00355   beamweight=GetBeamWeight(det,Ibeam,tptype,pt,pz,true_enu,inu,rp);
00356   //do the detector weighting
00357   detweight=GetDetWeight(ccnc,true_enu,inu,
00358                          reco_emu,reco_eshw,new_reco_emu,new_reco_eshw,true_eshw,ei);
00359 
00360   //return just the beam weight, as this is what 
00361   //most people will want
00362   //the value of the detweight is passed by reference
00363   //do not use the new values of new_reco_emu and new_reco_eshw
00364   //in the case of beam weighting only!!!!!
00365   return beamweight;
00366 
00367 }
00368 
00369 double SKZPWeightCalculator::GetBeamWeight(int det, int Ibeam,
00370                                            int tptype, double pt,
00371                                            double pz, double true_enu, int inu, 
00372                                            RunPeriod_t rp)
00373 {
00374   //do the flux reweighting
00375 
00376 
00377   double beamsysw=1.;
00378   double hadpw=1.;
00379   if(cfgnum==kPRL){
00380     //to let zbeam know I want the PRL version of 
00381     //of it's weights, I'm passing the beam systematic
00382     //parameters parameters one by one
00383 
00384     //reweight for spot size in me and he
00385     //now done in RunPeriodWeight
00386     //    beamsysw*=zbeam->GetWeight(det,Ibeam,6,0,true_enu);   
00387     //horn 1 offset
00388     beamsysw*=zbeam->GetWeight(det,Ibeam,1,bs_pars[0],true_enu);
00389     //baffle scraping
00390     beamsysw*=zbeam->GetWeight(det,Ibeam,2,bs_pars[1],true_enu);
00391     //pot
00392     beamsysw*=zbeam->GetWeight(det,Ibeam,3,bs_pars[2],true_enu);
00393     //horn current miscalibration
00394     beamsysw*=zbeam->GetWeight(det,Ibeam,4,bs_pars[3],true_enu);
00395     //horn current distribution
00396     beamsysw*=zbeam->GetWeight(det,Ibeam,5,bs_pars[4],true_enu);
00397 
00398     //now change pt and pz
00399     double hp[7]={hp_pars[0],hp_pars[1],hp_pars[2],hp_pars[3],
00400                   hp_pars[4],hp_pars[5],hp_pars[6]};
00401     //to let zfluk know I want the PRL version of it's weights
00402     //I'm passing the hadron production parameters as an array
00403     hadpw = zfluk->GetWeightPRL(tptype,pt,pz,hp);
00404   }  
00405   else if(cfgnum==kBoston){ 
00406     //Boston version of zbeam takes a vector of beam systematic parameters
00407      //first 5 are for numu's
00408      //second 5 are for antinumu's
00409      vector<double> tmp_bs_pars;
00410      if(inu>0){
00411         for(int i=0;i<5;i++){
00412            tmp_bs_pars.push_back(bs_pars[i]);
00413         }
00414      }
00415      else{
00416         for(int i=0;i<5;i++){
00417            tmp_bs_pars.push_back(bs_pars[i+5]);
00418         }
00419      }
00420      beamsysw=zbeam->GetWeight(det,Ibeam,tmp_bs_pars,inu,true_enu);     
00421 
00422      //reweight for spot size in me and he
00423      //now done in RunPeriodWeight
00424      //     beamsysw*=zbeam->GetWeight(det,Ibeam,6,0,true_enu);   
00425      
00426      //updated version of zbeam takes a vector of hadron production parameters
00427      hadpw=zfluk->GetWeightBoston(tptype,pt,pz,hp_pars);
00428   }
00429   else if(cfgnum==kPiMinus){
00430     //updated version of zbeam takes a vector of beam systematic parameters
00431     beamsysw=zbeam->GetWeight(det,Ibeam,bs_pars,inu,true_enu);
00432     //reweight for spot size in me and he
00433     //now done in RunPeriodWeight
00434     //    beamsysw*=zbeam->GetWeight(det,Ibeam,6,0,true_enu);   
00435 
00436     //pi minus version of fit has parameters set one time at the beginning,
00437     //the parameters are not reset each time in getweight
00438     hadpw = zfluk->GetWeight(tptype,pt,pz);
00439   }
00440   else if(cfgnum==kDetXs || cfgnum==kDogwood1_Daikon07){
00441 
00442     // Hadron Production weight
00443     hadpw = zfluk->GetWeight(tptype,pt,pz);
00444  
00445   }
00446   else if(cfgnum==kDogwood1_Daikon07_v2){
00447 
00448     Detector::Detector_t detector;
00449     if(det==1) detector=Detector::kNear;
00450     else if(det==2) detector=Detector::kFar;
00451     else if(det==3) detector=Detector::kUnknown;
00452     
00453     Zbeam::ZbeamData_t zdata;
00454     zdata.ntype    = inu;
00455     zdata.true_enu = true_enu;
00456     zdata.detector = detector;
00457     zdata.beam     =  BeamType::FromZarko(Ibeam);
00458     
00459     // Focusing alignment effects
00460     beamsysw *= zbeam->GetWeight(zdata,BeamSys::kHorn1Offset   ,bs_pars[0]);
00461     beamsysw *= zbeam->GetWeight(zdata,BeamSys::kBaffleScraping,bs_pars[1]);
00462     beamsysw *= zbeam->GetWeight(zdata,BeamSys::kPOT           ,bs_pars[2]);
00463     beamsysw *= zbeam->GetWeight(zdata,BeamSys::kHornIMiscal   ,bs_pars[3]);
00464     beamsysw *= zbeam->GetWeight(zdata,BeamSys::kHornIDist     ,bs_pars[4]);
00465     
00466     // Hadron production weight
00467     hadpw = zfluk->GetWeight(tptype,pt,pz);
00468 
00469   }
00470   else{ 
00471     //updated version of zbeam takes a vector of beam systematic parameters
00472     beamsysw=zbeam->GetWeight(det,Ibeam,bs_pars,inu,true_enu);
00473     //updated version of zbeam takes a vector of hadron production parameters
00474     hadpw=zfluk->GetWeight(tptype,pt,pz);
00475   }
00476 
00477   double rpw = GetRunPeriodWeight(rp,det,Ibeam,inu,true_enu);
00478   //  cout<<"run period "<<rp<<" weight "<<rpw<<endl;
00479   //return the product of beam systematic weights and had. prod. weights
00480   //  cout<<"inu "<<inu<<"hadpw "<<hadpw<<" beamsysw "<<beamsysw<<endl;
00481   return hadpw*beamsysw*rpw;
00482 }
00483 
00484 double SKZPWeightCalculator::GetDetWeight(int ccnc, double true_enu, int inu,
00485                                           double reco_emu, double reco_eshw,
00486                                           double &new_reco_emu, double &new_reco_eshw,
00487                                            double true_eshw,MCEventInfo *ei)
00488 {
00489 
00490   //computes the effect of the changing the detector parameters in the skzp fit
00491   //this function changes the reconstructed values of muon and shower energy,
00492   //so the new values are passed back to the calling function by reference as
00493   //part of the function parameter list
00494   double dw = 1.;
00495   new_reco_emu=reco_emu;
00496   new_reco_eshw=reco_eshw;
00497 
00498 
00499   if(cfgnum==kPRL){
00500     //right now this is the only version of detector weighting,
00501     //but this may evolve in the future
00502 
00503     //prl version of weights weights the NC component up or down by 1-fitparam
00504     if(ccnc==0){
00505       dw = 1.-det_pars[2];
00506     }
00507     
00508     //prl version of skzp changes the shower energy by an offset,
00509     //then changes the total neutrino energy (eshw+emu) by 
00510     //a multiplicative constant that is 1-fit parameter
00511     if(reco_eshw>0){
00512       new_reco_eshw = reco_eshw+det_pars[1];
00513     }
00514     if(new_reco_eshw<0){
00515       new_reco_eshw=0.;
00516     }
00517     
00518     new_reco_eshw*=(1-det_pars[0]);
00519     new_reco_emu=reco_emu*(1-det_pars[0]);
00520   }
00521   else if(cfgnum==kBoston){
00522     //boston version of weights weights the numu's and anumus separately
00523     if(ccnc==0){
00524        if(inu>0){
00525           dw = 1.-det_pars[2];
00526        }
00527        else{
00528           dw = 1.-det_pars[5];
00529        }
00530     }
00531     
00532     //boston version of skzp changes the shower energy by an offset,
00533     //then changes the total neutrino energy (eshw+emu) by 
00534     //a multiplicative constant that is 1-fit parameter
00535     if(reco_eshw>0){
00536        if(inu>0){
00537           new_reco_eshw = reco_eshw+det_pars[1];
00538        }
00539        else{
00540           new_reco_eshw = reco_eshw+det_pars[4];
00541        }
00542     }
00543     if(new_reco_eshw<0){
00544        new_reco_eshw=0.;
00545     }
00546     
00547     if(inu>0){
00548        new_reco_eshw*=(1-det_pars[0]);
00549        new_reco_emu=reco_emu*(1-det_pars[0]);
00550     }
00551     else{
00552        new_reco_eshw*=(1-det_pars[3]);
00553        new_reco_emu=reco_emu*(1-det_pars[3]);
00554     }
00555   }
00556   else if(cfgnum==kPiMinus){
00557     //Piminus version of weights weights the numu's and anumus separately
00558     if(ccnc==0){
00559       if(sampsel==kNuMuCC){
00560         //      cout<<"Found an NC, and I'm using the CC parameter"<<endl;
00561         dw = 1-det_pars[2];
00562       }
00563       else if(sampsel==kAntiNuMu){
00564         //      cout<<"Found an NC, and I'm using the Anti parameter"<<endl;
00565         dw = 1-det_pars[3];
00566       }
00567       else{//if a sample isn't specified, 
00568            //do it like I think you should.
00569        if(inu>0){
00570          dw = 1.-det_pars[2];
00571        }
00572        else{
00573          dw = 1.-det_pars[3];
00574        }
00575       }
00576     }
00577     
00578     //Piminus version of skzp changes the shower energy by an offset,
00579     //then changes the total neutrino energy (eshw+emu) by 
00580     //a multiplicative constant that is 1-fit parameter
00581     //it also treats nu's and anu's in the same way
00582     new_reco_eshw=reco_eshw;
00583     if(reco_eshw>0){
00584       new_reco_eshw = reco_eshw+det_pars[1];
00585     }
00586     if(new_reco_eshw<0){
00587       new_reco_eshw=0.;
00588     }
00589     
00590     if(inu==14||inu==-14){
00591       new_reco_eshw*=(1-det_pars[0]);
00592       new_reco_emu=reco_emu*(1-det_pars[0]);
00593     }
00594     else if(inu==12||inu==-12){
00595       new_reco_eshw*=(1-0.);
00596       new_reco_emu=reco_emu*(1-0.);
00597     }
00598     else{
00599       new_reco_eshw*=(1-0.);
00600       new_reco_emu=reco_emu*(1-0.);
00601     }
00602 
00603     //Piminus version of the fit has a scale for numubar xsec
00604     if(inu==-14){
00605       double xsw=1.;
00606       if(true_enu<XP){
00607         xsw = det_pars[4]+2.*(1.-det_pars[4])*true_enu/XP
00608           +(det_pars[4]-1.)*true_enu*true_enu/(XP*XP);
00609       }
00610       dw*=xsw;
00611     }
00612   }
00613   else if(cfgnum==kDetXs || cfgnum==kDogwood1_Daikon07){
00614 
00615     // You must give an MCEventInfo object to get the
00616     // correct detector weight
00617     if(fBeamOnly||ei==0) return dw;
00618 
00619     // Shower offset
00620     if(reco_eshw>0.) {
00621       new_reco_eshw = reco_eshw+det_pars[0];
00622     }
00623     if(new_reco_eshw<0){
00624       new_reco_eshw=0.;
00625     }
00626 
00627     // Shower energy scale from functional form
00628     double x0=10;
00629     double x = TMath::Min((double)true_eshw,x0);
00630     double err_a = 1.04/1.0 - 1.0;
00631     double err_b = (1.1+2.*(1-1.1)*(x/x0)+(1.1-1)*(x/x0)*(x/x0))/(1.0) - 1.0;
00632     double err_c = 0.057;
00633     double shw_scale=sqrt(pow(err_a,2)+pow(err_b,2)+pow(err_c,2));
00634     
00635     new_reco_eshw*=(1-det_pars[4]*shw_scale);
00636 
00637     // Scale muon energy 
00638     new_reco_emu=reco_emu*(1.-det_pars[5]);
00639     
00640     // NC parameters
00641     if(ei->iaction==0){
00642       if(sampsel==kNuMuCC)         dw*=(1-det_pars[1]);
00643       else if(sampsel==kAntiNuMu)  dw*=(1-det_pars[2]);
00644       else{
00645         if(inu==14)  dw = 1.-det_pars[1];
00646         if(inu==-14) dw = 1.-det_pars[2];
00647       }
00648     }
00649     else {
00650       // Cross Section Parameters
00651       if(ei!=0) {
00652         double gw=1;
00653         if(ei->iresonance!=1005) gw=mcr->ComputeWeight(ei)-1.0;
00654         
00655         if(ei->iresonance==1001) dw*=(1+det_pars[6]*gw);
00656         if(ei->iresonance==1002) dw*=(1+det_pars[7]*gw);
00657         //if(ei->iresonance==1003) dw*=(1+det_pars[8]*gw);
00658       }
00659     }
00660         
00661     //numubar xsec
00662     if(inu==-14){
00663       double xsw=1.;
00664       if(true_enu<XP){
00665         xsw = det_pars[3]+2.*(1.-det_pars[3])*true_enu/XP
00666           +(det_pars[3]-1.)*true_enu*true_enu/(XP*XP);
00667       }
00668       dw*=xsw;
00669     }
00670    
00671   }
00672   else if(cfgnum==kDogwood1_Daikon07_v2){
00673 
00674     // Similar to kDetXs but with parameters incremented
00675     // by 1 as new parameter 0 is the overall neutrino 
00676     // energy scale.
00677 
00678     // You must give an MCEventInfo object to get the
00679     // correct detector weight
00680     if(fBeamOnly||ei==0) return dw;
00681 
00682     // Shower offset
00683     if(reco_eshw>0.) {
00684       new_reco_eshw = reco_eshw+det_pars[1];
00685     }
00686     if(new_reco_eshw<0){
00687       new_reco_eshw=0.;
00688     }
00689 
00690     // Shower energy scale from functional form
00691     double x0=10;
00692     double x = TMath::Min((double)true_eshw,x0);
00693     double err_a = 1.04/1.0 - 1.0;
00694     double err_b = (1.1+2.*(1-1.1)*(x/x0)+(1.1-1)*(x/x0)*(x/x0))/(1.0) - 1.0;
00695     double err_c = 0.057;
00696     double shw_scale=sqrt(pow(err_a,2)+pow(err_b,2)+pow(err_c,2));
00697     
00698     new_reco_eshw*=(1-det_pars[5]*shw_scale);
00699 
00700     // Scale muon energy 
00701     new_reco_emu=reco_emu*(1.-det_pars[6]);
00702     
00703     // Now need to scale the overall neutrino energy BUT the current
00704     // weighting functions don't allow me to pass back a new value 
00705     // for the neutrino energy, just the muon and shower separately.
00706     // So I'm going to assume everyone will just add these two to
00707     // get the new neutrino energy and hence implement the neutrino
00708     // energy scale parameter by applying it to both the muon and
00709     // shower energy seperately:
00710 
00711     new_reco_eshw*=(1.-det_pars[0]);
00712     new_reco_emu*=(1.-det_pars[0]);
00713 
00714     // NC parameters
00715     if(ei->iaction==0){
00716       if(sampsel==kNuMuCC)         dw*=(1-det_pars[2]);
00717       else if(sampsel==kAntiNuMu)  dw*=(1-det_pars[3]);
00718       else{
00719         if(inu==14)  dw = 1.-det_pars[2];
00720         if(inu==-14) dw = 1.-det_pars[3];
00721       }
00722     }
00723     else {
00724       // Cross Section Parameters
00725       if(ei!=0) {
00726         double gw=1;
00727         if(ei->iresonance!=1005) gw=mcr->ComputeWeight(ei)-1.0;
00728         
00729         if(ei->iresonance==1001) dw*=(1+det_pars[7]*gw);
00730         if(ei->iresonance==1002) dw*=(1+det_pars[8]*gw);
00731       }
00732     }
00733         
00734     //numubar xsec
00735     if(inu==-14){
00736       double xsw=1.;
00737       if(true_enu<XP){
00738         xsw = det_pars[4]+2.*(1.-det_pars[4])*true_enu/XP
00739           +(det_pars[4]-1.)*true_enu*true_enu/(XP*XP);
00740       }
00741       dw*=xsw;
00742     }
00743 
00744   }
00745   else{
00746     //this does nothing for now, and 
00747     //should never be called,
00748     //but I want the structure
00749     MSG("SKZPWeightCalculator",Msg::kError)<<"You are in the else of DetWeighting!"
00750                                            <<"this should never happen!"
00751                                            <<"How did you get here?"<<endl;
00752   }
00753 
00754   /*
00755   if(new_reco_eshw+new_reco_emu<1.5){
00756     cout<<"Detetor weight "<<inu<<" ccnc "<<ccnc<<"true enu "<<true_enu<<" reco emu "<<reco_emu<<" new_reco_emu "<<new_reco_emu<<" reco eshw "<<reco_eshw<<" new_reco_eshw "<<new_reco_eshw<<" weight "<<dw<<endl;
00757   }
00758   */
00759   return dw;
00760 
00761 }
00762 
00763     
00764 
00765 void SKZPWeightCalculator::PrintReweightConfig(ostream &o)
00766 {
00767   o<<"Reweighting to : "<<cfgname<<endl;
00768   for(unsigned int i=0;i<bs_pars.size();i++){
00769     o<<"Beam Sys par "<<i<<" "<<bs_pars[i]<<endl;
00770   }
00771   for(unsigned int i=0;i<hp_pars.size();i++){
00772     o<<"Had. Prod par "<<i<<" "<<hp_pars[i]<<endl;
00773   }
00774   for(unsigned int i=0;i<det_pars.size();i++){
00775     o<<"Det par "<<i<<" "<<det_pars[i]<<endl;
00776   }
00777 }
00778 
00779 
00780 void SKZPWeightCalculator::ChangeParameters(vector<double> *bs, vector<double> *hp, vector<double> *det)
00781 {
00782   //this function is provided so that a user can compute weights for
00783   //many different szkp parameters.
00784   //it is provided for special studies, and I don't expect
00785   //most people will need this functionality.
00786 
00787   //clear anything that's already stored in the vectors
00788   bs_pars.clear();
00789   hp_pars.clear();
00790   det_pars.clear();
00791 
00792   //copy the function parameters into the private data members
00793   for(unsigned int i=0;i<bs->size();i++){
00794     double b=(*bs)[i];
00795     bs_pars.push_back(b);
00796   }
00797   for(unsigned int i=0;i<hp->size();i++){
00798     double h=(*hp)[i];
00799     hp_pars.push_back(h);
00800   }
00801   for(unsigned int i=0;i<det->size();i++){
00802     double d=(*det)[i];
00803     det_pars.push_back(d);
00804   }
00805 
00806   if(cfgnum==kPiMinus || cfgnum==kDetXs || cfgnum==kDogwood1_Daikon07){
00807     zfluk->SetParameters(hp_pars);
00808   }
00809   
00810 }
00811 
00812 void SKZPWeightCalculator::GetParameters(vector<double> &bs, vector<double> &hp, vector<double> &det)
00813 {
00814   //this function is provided so that a user can compute weights for
00815   //many different szkp parameters.
00816   //it is provided for special studies, and I don't expect
00817   //most people will need this functionality.
00818 
00819   //clear anything that's already stored in the vectors
00820   bs.clear();
00821   hp.clear();
00822   det.clear();
00823 
00824   //copy the private data members into the function parameters
00825   for(unsigned int i=0;i<bs_pars.size();i++){
00826     bs.push_back(bs_pars[i]);
00827   }
00828   for(unsigned int i=0;i<hp_pars.size();i++){
00829     hp.push_back(hp_pars[i]);
00830   }
00831   for(unsigned int i=0;i<det_pars.size();i++){
00832     det.push_back(det_pars[i]);
00833   }
00834 }
00835 
00836 void SKZPWeightCalculator::SetConfigNum(string c)
00837 {
00838   if(c=="PRL") cfgnum = kPRL;
00839   else if(c.find("PRL_Syst")!=string::npos) cfgnum = kPRL;
00840   else if(c=="Boston") cfgnum = kBoston;
00841   else if(c=="PiMinus") cfgnum = kPiMinus;
00842   else if(c=="PiMinus_CedarDaikon") cfgnum = kPiMinus;
00843   else if(c=="DetXs") cfgnum = kDetXs;
00844   else if(c=="Dogwood1_Daikon07") cfgnum = kDogwood1_Daikon07;
00845   else if(c=="Dogwood1_Daikon07_v2") cfgnum = kDogwood1_Daikon07_v2;
00846   else cfgnum = kUnknown;
00847 
00848 }
00849 
00850 double SKZPWeightCalculator::GetFluxError(int det, int Ibeam, 
00851                                           int inu, double true_enu, 
00852                                           FluxErrEffect_t neffect,double nsigma)
00853 {
00854  zbeam->SetReweightConfig(cfgname);
00855   
00856   // Add target z with different than nsigma weight
00857   if(cfgname=="DetXs" && neffect==kTotalErrorAfterTune) {
00858   
00859     double e=0;
00860  
00861     double weight=zbeam->GetWeight(det,Ibeam,BeamSys::kHorn1Offset,nsigma,inu,true_enu)-1;
00862     e+=weight*weight;
00863     weight=zbeam->GetWeight(det,Ibeam,BeamSys::kBaffleScraping,nsigma,inu,true_enu)-1;
00864     e+=weight*weight;
00865     weight=zbeam->GetWeight(det,Ibeam,BeamSys::kPOT,nsigma,inu,true_enu)-1;
00866     e+=weight*weight;
00867     weight=zbeam->GetWeight(det,Ibeam,BeamSys::kHornIMiscal,nsigma,inu,true_enu)-1;
00868     e+=weight*weight;
00869     weight=zbeam->GetWeight(det,Ibeam,BeamSys::kHornIDist,nsigma,inu,true_enu)-1;
00870     e+=weight*weight;
00871     weight=zbeam->GetWeight(det,Ibeam,BeamSys::kBeamWidth,nsigma,inu,true_enu)-1;
00872     e+=weight*weight;
00873     weight=zbeam->GetWeight(det,Ibeam,BeamSys::kHadProdAfter,nsigma,inu,true_enu)-1;
00874     e+=weight*weight;
00875         
00876     // add error from best fit for target z
00877 
00878     // le010 configurations
00879     if(Ibeam==2 || Ibeam==6 || Ibeam==7) {
00880       double targetz=TMath::Max(TMath::Abs(bs_pars[0]),TMath::Abs(bs_pars[4]));
00881       weight=zbeam->GetWeight(det,Ibeam,BeamSys::kTargetZ,targetz*nsigma,inu,true_enu)-1;
00882       e+=weight*weight;
00883     }
00884     // le100
00885     else if(Ibeam==3) {
00886       double targetz=TMath::Abs(bs_pars[1]);
00887       weight=zbeam->GetWeight(det,Ibeam,BeamSys::kTargetZ,targetz*nsigma,inu,true_enu)-1;
00888       e+=weight*weight;
00889     }
00890     // le250
00891     else if(Ibeam==4) {
00892       double targetz=TMath::Max(TMath::Abs(bs_pars[3]),TMath::Abs(bs_pars[5]));
00893       weight=zbeam->GetWeight(det,Ibeam,BeamSys::kTargetZ,targetz*nsigma,inu,true_enu)-1;
00894       e+=weight*weight;
00895     }
00896     // le150
00897     else if(Ibeam==9) {
00898       double targetz=TMath::Abs(bs_pars[2]);
00899       weight=zbeam->GetWeight(det,Ibeam,BeamSys::kTargetZ,targetz*nsigma,inu,true_enu)-1;
00900       e+=weight*weight;
00901     }
00902 
00903     return 1+sqrt(e);
00904   }
00905   else return zbeam->GetWeight(det,Ibeam,neffect,nsigma,inu,true_enu);
00906 
00907 }
00908 
00909 int SKZPWeightCalculator::RunPeriodIntFromValidity(VldContext vc)
00910 {
00911   int rp = 1; // default Run I
00912   VldTimeStamp ts = vc.GetTimeStamp();
00913   if(ts.GetDate()<(*vtsRunIEnd).GetDate()) rp = 1;
00914   else if(ts.GetDate()<(*vtsRunIIEnd).GetDate()) rp = 2;
00915   else if(ts.GetDate()<(*vtsRunIIIEnd).GetDate()) rp = 3;
00916   else rp = 4;
00917   return rp;
00918 }
00919 
00920 double SKZPWeightCalculator::GetRunPeriodWeight(RunPeriod_t rp,
00921                                                 int det, 
00922                                                 int Ibeam, 
00923                                                 int ntype, 
00924                                                 double Enu)
00925 {
00926   double weight=1.;
00927 
00928   if(cfgnum==kDetXs || cfgnum==kDogwood1_Daikon07){
00929 
00930     // Target z weighting comes from the fit parameters
00931     Detector::Detector_t detector = Detector::kUnknown;
00932     if      (det==1) detector=Detector::kNear;
00933     else if (det==2) detector=Detector::kFar;
00934     
00935     Zbeam::ZbeamData_t zdata;
00936     zdata.ntype    = ntype;
00937     zdata.true_enu = Enu;
00938     zdata.detector = detector;
00939     zdata.beam     = BeamType::FromZarko(Ibeam);
00940     
00941 
00942     if(rp==kRunI){ // both weighting schemes have same parameters
00943       
00944       // target z effects
00945       if ( zdata.beam == BeamType::kL010z170i || 
00946            zdata.beam == BeamType::kL010z185i || 
00947            zdata.beam == BeamType::kL010z200i) {
00948         weight *= zbeam->GetWeight(zdata,BeamSys::kTargetZ ,bs_pars[0]);
00949       } else if (zdata.beam == BeamType::kL100z200i) {
00950         weight *= zbeam->GetWeight(zdata,BeamSys::kTargetZ ,bs_pars[1]);
00951       } else if (zdata.beam == BeamType::kL150z200i) {
00952         weight *= zbeam->GetWeight(zdata,BeamSys::kTargetZ ,bs_pars[2]);
00953       } else if (zdata.beam == BeamType::kL250z200i) {
00954         weight *= zbeam->GetWeight(zdata,BeamSys::kTargetZ ,bs_pars[3]);
00955       }
00956       
00957       // spot size
00958       if (zdata.beam == BeamType::kL250z200i ||
00959           zdata.beam == BeamType::kL100z200i) {
00960         weight *= zbeam->GetWeight(zdata,BeamSys::kBeamWidth,0.);
00961       }
00962     }
00963     else if(rp==kRunII) {
00964       
00965       if (zdata.beam == BeamType::kL010z185i) {
00966         weight *= zbeam->GetWeight(zdata,BeamSys::kTargetZ ,bs_pars[4]);
00967       }
00968       else if (zdata.beam == BeamType::kL250z200i) {
00969         weight *= zbeam->GetWeight(zdata,BeamSys::kTargetZ ,bs_pars[5]);
00970       }
00971 
00972       if(cfgnum==kDogwood1_Daikon07){ // apply target decay weight
00973         weight *= GetTargetDecayWeight(det,Ibeam,ntype,Enu,bs_pars[7]);
00974       }
00975 
00976     }
00977 
00978     else if(rp==kRunIII && cfgnum==kDetXs) { // use Run II beam position and Helium weight
00979 
00980       if (zdata.beam == BeamType::kL010z185i) {
00981         weight *= zbeam->GetWeight(zdata,BeamSys::kTargetZ ,bs_pars[4]);
00982       }
00983       weight *= GetHeliumWeight(det,Ibeam,ntype,Enu);
00984 
00985       // DetXs target decay weight to be added when finalised
00986 
00987     }
00988 
00989     else if(rp==kRunIII && cfgnum==kDogwood1_Daikon07){
00990 
00991       if (zdata.beam == BeamType::kL010z185i) {
00992         weight *= zbeam->GetWeight(zdata,BeamSys::kTargetZ ,bs_pars[6]);
00993       }
00994       weight *= GetTargetDecayWeight(det,Ibeam,ntype,Enu,bs_pars[8]);
00995       // Don't need Helium weight for Daikon07
00996 
00997     }
00998 
00999   } // end if(DetXs or Dogwood1_Daikon07)
01000   else if(cfgnum==kDogwood1_Daikon07_v2){
01001 
01002     // Target z weighting comes from the fit parameters
01003     Detector::Detector_t detector = Detector::kUnknown;
01004     if      (det==1) detector=Detector::kNear;
01005     else if (det==2) detector=Detector::kFar;
01006     
01007     Zbeam::ZbeamData_t zdata;
01008     zdata.ntype    = ntype;
01009     zdata.true_enu = Enu;
01010     zdata.detector = detector;
01011     zdata.beam     = BeamType::FromZarko(Ibeam);
01012     
01013     if(rp==kRunI){
01014       
01015       // target z effects
01016       if ( zdata.beam == BeamType::kL010z170i || 
01017            zdata.beam == BeamType::kL010z185i || 
01018            zdata.beam == BeamType::kL010z200i) {
01019         weight *= zbeam->GetWeight(zdata,BeamSys::kTargetZ ,bs_pars[5]);
01020       } else if (zdata.beam == BeamType::kL100z200i) {
01021         weight *= zbeam->GetWeight(zdata,BeamSys::kTargetZ ,bs_pars[6]);
01022       } else if (zdata.beam == BeamType::kL150z200i) {
01023         weight *= zbeam->GetWeight(zdata,BeamSys::kTargetZ ,bs_pars[7]);
01024       } else if (zdata.beam == BeamType::kL250z200i) {
01025         weight *= zbeam->GetWeight(zdata,BeamSys::kTargetZ ,bs_pars[8]);
01026       }
01027       
01028       // spot size
01029       if (zdata.beam == BeamType::kL250z200i ||
01030           zdata.beam == BeamType::kL100z200i) {
01031         weight *= zbeam->GetWeight(zdata,BeamSys::kBeamWidth,0.);
01032       }
01033     }
01034     else if(rp==kRunII) {
01035       
01036       if (zdata.beam == BeamType::kL010z185i) {
01037         weight *= zbeam->GetWeight(zdata,BeamSys::kTargetZ ,bs_pars[9]);
01038       }
01039       else if (zdata.beam == BeamType::kL250z200i) {
01040         weight *= zbeam->GetWeight(zdata,BeamSys::kTargetZ ,bs_pars[10]);
01041       }
01042 
01043       // apply target decay weight
01044       weight *= GetTargetDecayWeight(det,Ibeam,ntype,Enu,bs_pars[12]);
01045 
01046     }
01047 
01048     else if(rp==kRunIII){
01049 
01050       if (zdata.beam == BeamType::kL010z185i) {
01051         weight *= zbeam->GetWeight(zdata,BeamSys::kTargetZ ,bs_pars[11]);
01052       }
01053 
01054       // apply target decay weight
01055       weight *= GetTargetDecayWeight(det,Ibeam,ntype,Enu,bs_pars[13]);
01056 
01057       // Don't need Helium weight for Daikon07
01058 
01059     }
01060 
01061   }
01062   else {
01063     if(rp==kRunI){
01064       // cout<<"on run I"<<endl;
01065       //RUN I
01066       //ME and HE runs were lower intensity, smaller spot size,  
01067       if(BeamType::FromZarko(Ibeam)==BeamType::kL100z200i||
01068          BeamType::FromZarko(Ibeam)==BeamType::kL250z200i){
01069         //GetWeight with effect 6 already takes care of the beam type "if's"
01070         //but I thought I should just make them explicit here too
01071         weight=zbeam->GetWeight(det,Ibeam,6,0,ntype,Enu);
01072         //      cout<<"in run I weight"<<endl;
01073       }
01074     }
01075     else if(rp==kRunII || rp==kRunIII){
01076       //RUN II
01077       //reweight le10 beam to le09 beam
01078       //    cout<<"in run II weight "<<endl;
01079       if(BeamType::FromZarko(Ibeam)==BeamType::kL010z185i||
01080          BeamType::FromZarko(Ibeam)==BeamType::kL010z000i){
01081         weight=zbeam->GetWeight(det,Ibeam,15,-1.,ntype,Enu);
01082         //      cout<<"in run II weight "<<endl;
01083       }
01084 
01085       if(rp==kRunII){
01086         // target decay weight to be added when finalised, 0.6 should give ~average effect
01087         weight *= GetTargetDecayWeight(det,Ibeam,ntype,Enu,0.6);
01088       }
01089       if(rp==kRunIII){
01090         weight *= GetHeliumWeight(det,Ibeam,ntype,Enu);
01091         // target decay weight to be added when finalised, 1.25 should give ~average effect
01092         weight *= GetTargetDecayWeight(det,Ibeam,ntype,Enu,1.25);
01093       }
01094 
01095     }
01096     //  cout<<"run perioud weight "<<weight<<endl;
01097   }
01098   return weight;
01099 }
01100 
01101 double SKZPWeightCalculator::GetRFWWeight(const NtpMCTruth *mc, int det, int Ibeam,
01102                                           double reco_emu, double reco_eshw, 
01103                                           double &new_reco_emu, double &new_reco_eshw,
01104                                           double &beamweight, double &detweight)
01105 {
01106   //retrieve truth information on the neutrino interaction from
01107   //the NtpMCTruth object
01108   int ccnc = mc->iaction;
01109   double true_enu = 1.*mc->p4neu[3];
01110   int inu = mc->inu;
01111 
01112   //pass the truth info and the fluxinfo object to the next
01113   //form of GetWeight
01114   return GetRFWWeight(&(mc->flux),det,Ibeam,
01115                       ccnc,true_enu,inu,
01116                       reco_emu,reco_eshw,
01117                       new_reco_emu,new_reco_eshw,
01118                       beamweight, detweight);
01119   
01120 }
01121 
01122 double SKZPWeightCalculator::GetRFWWeight(const NtpMCFluxInfo *fi, int det, int Ibeam,
01123                                           int ccnc, double true_enu, int inu,
01124                                           double reco_emu, double reco_eshw, 
01125                                           double &new_reco_emu, double &new_reco_eshw,
01126                                           double &beamweight, double &detweight)
01127 {
01128   int parenttype=-1;
01129   double parentpz=0.;
01130   double parentpx=0.;
01131   double parentpy=0.;
01132 
01133   parenttype = fi->tptype;
01134   parentpz = 1.*fi->tpz;
01135   parentpy = 1.*fi->tpy;
01136   parentpx = 1.*fi->tpx;
01137 
01138   double pt = sqrt(parentpy*parentpy+parentpx*parentpx);
01139 
01140   //pass the variables on to the next version of GetWeight
01141   return GetRFWWeight(det,Ibeam,parenttype,pt,parentpz,ccnc,true_enu,inu,
01142                       reco_emu,reco_eshw,new_reco_emu,
01143                       new_reco_eshw,beamweight,detweight);
01144 
01145 }
01146 
01147 double SKZPWeightCalculator::GetRFWWeight(int det, int Ibeam,
01148                                           int tptype, double pt, double pz,    
01149                                           int ccnc, double true_enu,int inu,
01150                                           double reco_emu, double reco_eshw,
01151                                           double &new_reco_emu, double &new_reco_eshw,
01152                                           double &beamweight, double &detweight)
01153 {
01154 
01155   //do the detector weighting
01156   detweight=GetDetWeight(ccnc,true_enu,inu,
01157                          reco_emu,reco_eshw,new_reco_emu,new_reco_eshw);
01158   beamweight=1.;
01159   if(runfrac.size()==0){
01160     MSG("SKZPWeightCalculator",Msg::kError)<<"You did not set the "
01161                                            <<"Run Period exposures."<<endl
01162                                            <<"I can not compute a "
01163                                            <<" fractional weight without "
01164                                            <<"knowing the relative exposures"<<endl;
01165     return 1.;
01166   }
01167     
01168 
01169   map<RunPeriod_t,double> beamc(runfrac.find(Ibeam)->second);
01170   map<RunPeriod_t,double>::iterator bcit(beamc.begin());
01171   double num=0.;
01172   double denom=0.;
01173   int i=0;
01174   while(bcit!=beamc.end()){
01175     RunPeriod_t rp = bcit->first;
01176     double pot = bcit->second;
01177     double w=GetBeamWeight(det,Ibeam,tptype,pt,pz,true_enu,inu,rp);
01178     num+=w*pot;
01179     denom+=pot;
01180     bcit++;
01181     //        cout<<"bcit->first "<<bcit->first<<endl;
01182     //    cout<<"bcit->second "<<bcit->second<<endl;
01183 
01184     //    cout<<"i "<<i<<" w "<<w<<" pot "<<pot<<" w*pot "<<w*pot<<" num "<<num<<" denom "<<denom<<endl;
01185     i++;
01186   }
01187     
01188     
01189   if(denom!=0){
01190     beamweight*=num/denom;
01191   }
01192 
01193 
01194   //return just the beam weight, as this is what 
01195   //most people will want
01196   //the value of the detweight is passed by reference
01197   //do not use the new values of new_reco_emu and new_reco_eshw
01198   //in the case of beam weighting only!!!!!
01199   return beamweight;
01200 }
01201 
01202 void SKZPWeightCalculator::SetRunFrac(int Ibeam, RunPeriod_t rp, double pot)
01203 {
01204 
01205   map<int, map<RunPeriod_t,double> >::iterator it(runfrac.find(Ibeam));
01206   if(it!=runfrac.end()){
01207     //already have an entry for this beam type, just insert (runnum,pot)
01208     if((it->second).find(rp)==it->second.end()){
01209       (it->second)[rp]=pot;
01210     }
01211     else{
01212       MSG("SKZPWeightCalculator",Msg::kError)<<"You already specified pot for "
01213                                              <<BeamType::AsString(BeamType::FromZarko(Ibeam))
01214                                              <<" beam, with run period "<<rp<<endl
01215                                              <<"I will not overwrite!!!"<<endl;
01216     } 
01217   }
01218   else{
01219     //don't have this Ibeam yet, make a new map
01220     map<RunPeriod_t, double> m;
01221     m[rp]=pot;
01222     runfrac[Ibeam]=m;
01223   }
01224 
01225 
01226 }
01227 
01228 //-----------------------------------------------------------------------------------
01229 Zbeam* SKZPWeightCalculator::GetZbeam()
01230 {
01231    return zbeam;
01232 }
01233 
01234 //-----------------------------------------------------------------------------------
01235 Zfluk* SKZPWeightCalculator::GetZfluk()
01236 {
01237    return zfluk;
01238 }
01239 
01240 
01241 
01242 // Target decay weighting function
01243 
01244 double SKZPWeightCalculator::GetTargetDecayWeight(int det, int Ibeam, int Ntype, double true_enu, double fin78fraction)
01245 {
01246 
01247   double weight78 = 1.0;
01248 
01249   if(det==1){ // ND
01250     if(Ibeam==2){ // L010z185i
01251       if(Ntype==56 || Ntype==14) weight78 = GetMissingFin78Weight_L010z185i_ND_Numu(true_enu);
01252       else if(Ntype==55 || Ntype==-14) weight78 = GetMissingFin78Weight_L010z185i_ND_Numubar(true_enu);
01253       else if(Ntype==53 || Ntype==12) weight78 = GetMissingFin78Weight_L010z185i_ND_Nue(true_enu);
01254       else if(Ntype==52 || Ntype==-12) weight78 = GetMissingFin78Weight_L010z185i_ND_Nuebar(true_enu);
01255       else weight78 = 1.0;
01256     }
01257     else if(Ibeam==8){ // L010z000i
01258       if(Ntype==56 || Ntype==14) weight78 = GetMissingFin78Weight_L010z000i_ND_Numu(true_enu);
01259       else if(Ntype==55 || Ntype==-14) weight78 = GetMissingFin78Weight_L010z000i_ND_Numubar(true_enu);
01260       else if(Ntype==53 || Ntype==12) weight78 = GetMissingFin78Weight_L010z000i_ND_Nue(true_enu);
01261       else if(Ntype==52 || Ntype==-12) weight78 = GetMissingFin78Weight_L010z000i_ND_Nuebar(true_enu);
01262       else weight78 = 1.0;
01263     }
01264     else weight78 = 1.0;
01265   }
01266   else if(det==2){ // FD
01267     if(Ibeam==2){ // L010z185i
01268       if(Ntype==56 || Ntype==14) weight78 = GetMissingFin78Weight_L010z185i_FD_Numu(true_enu);
01269       else if(Ntype==55 || Ntype==-14) weight78 = GetMissingFin78Weight_L010z185i_FD_Numubar(true_enu);
01270       else if(Ntype==53 || Ntype==12) weight78 = GetMissingFin78Weight_L010z185i_FD_Nue(true_enu);
01271       else if(Ntype==52 || Ntype==-12) weight78 = GetMissingFin78Weight_L010z185i_FD_Nuebar(true_enu);
01272       else weight78 = 1.0;
01273     }
01274     else if(Ibeam==8){ // L010z000i
01275       if(Ntype==56 || Ntype==14) weight78 = GetMissingFin78Weight_L010z000i_FD_Numu(true_enu);
01276       else if(Ntype==55 || Ntype==-14) weight78 = GetMissingFin78Weight_L010z000i_FD_Numubar(true_enu);
01277       else if(Ntype==53 || Ntype==12) weight78 = GetMissingFin78Weight_L010z000i_FD_Nue(true_enu);
01278       else if(Ntype==52 || Ntype==-12) weight78 = GetMissingFin78Weight_L010z000i_FD_Nuebar(true_enu);
01279       else weight78 = 1.0;
01280     }
01281     else weight78 = 1.0;
01282   }
01283   else weight78 = 1.0;
01284 
01285   // Now convert to fractional weight
01286   // eg: if want to remove 4 fins then double the distance from unity for the weight
01287 
01288   double weight = 1.;
01289 
01290   if(weight78<0.){
01291     weight = 1.0-(fin78fraction*(1.0-weight78));
01292   }
01293   else if(weight78>0.){
01294     weight = 1.0+(fin78fraction*(weight78-1.0));
01295   }
01296 
01297   return weight;
01298 
01299 }
01300 
01301 
01302 
01303 // Helium weighting function
01304 
01305 double SKZPWeightCalculator::GetHeliumWeight(int det, int Ibeam, int Ntype, double true_enu)
01306 {
01307   if(det==1){ // ND
01308     if(Ibeam==2){ // L010z185i
01309       if(Ntype==56 || Ntype==14) return GetHeliumWeight_L010z185i_ND_Numu(true_enu);
01310       else if(Ntype==55 || Ntype==-14) return GetHeliumWeight_L010z185i_ND_Numubar(true_enu);
01311       else if(Ntype==53 || Ntype==12) return GetHeliumWeight_L010z185i_ND_Nue(true_enu);
01312       else if(Ntype==52 || Ntype==-12) return GetHeliumWeight_L010z185i_ND_Nuebar(true_enu);
01313       else return 1.0;
01314     }
01315     else if(Ibeam==8){ // L010z000i
01316       if(Ntype==56 || Ntype==14) return GetHeliumWeight_L010z000i_ND_Numu(true_enu);
01317       else if(Ntype==55 || Ntype==-14) return GetHeliumWeight_L010z000i_ND_Numubar(true_enu);
01318       else if(Ntype==53 || Ntype==12) return GetHeliumWeight_L010z000i_ND_Nue(true_enu);
01319       else if(Ntype==52 || Ntype==-12) return GetHeliumWeight_L010z000i_ND_Nuebar(true_enu);
01320       else return 1.0;
01321     }
01322     else return 1.0;
01323   }
01324   else if(det==2){ // FD
01325     if(Ibeam==2){ // L010z185i
01326       if(Ntype==56 || Ntype==14) return GetHeliumWeight_L010z185i_FD_Numu(true_enu);
01327       else if(Ntype==55 || Ntype==-14) return GetHeliumWeight_L010z185i_FD_Numubar(true_enu);
01328       else if(Ntype==53 || Ntype==12) return GetHeliumWeight_L010z185i_FD_Nue(true_enu);
01329       else if(Ntype==52 || Ntype==-12) return GetHeliumWeight_L010z185i_FD_Nuebar(true_enu);
01330       else return 1.0;
01331     }
01332     else if(Ibeam==8){ // L010z000i
01333       if(Ntype==56 || Ntype==14) return GetHeliumWeight_L010z000i_FD_Numu(true_enu);
01334       else if(Ntype==55 || Ntype==-14) return GetHeliumWeight_L010z000i_FD_Numubar(true_enu);
01335       else if(Ntype==53 || Ntype==12) return GetHeliumWeight_L010z000i_FD_Nue(true_enu);
01336       else if(Ntype==52 || Ntype==-12) return GetHeliumWeight_L010z000i_FD_Nuebar(true_enu);
01337       else return 1.0;
01338     }
01339     else return 1.0;
01340   }
01341   else return 1.0;
01342 }
01343 
01344 double SKZPWeightCalculator::GetHeliumWeight_L010z185i_ND_Numu(double enu)
01345 {
01346   double weight = 1.;
01347   double par[19] = {
01348     1.10472,-0.0861419,0.0116673,0.0193203,0.230526,0.323048,-0.0434165,0.00189932,1.1483,
01349     -0.0322421,0.00224179,-4.51111e-05,0.818716,0.0177147,-0.000366594,2.1493e-06,1.20406,
01350     -0.00411679,2.18602e-05
01351   };
01352   if(enu<5.15){
01353     weight = par[0]+par[1]*enu+par[2]*enu*enu+par[3]*TMath::Log(enu);
01354   }
01355   else if(enu<7.25){
01356     weight = par[4]+par[5]*enu+par[6]*enu*enu+par[7]*enu*enu*enu;
01357   }
01358   else if(enu<18.0){
01359     weight = par[8]+par[9]*enu+par[10]*enu*enu+par[11]*enu*enu*enu;
01360   }
01361   else if(enu<53.5){
01362     weight = par[12]+par[13]*enu+par[14]*enu*enu+par[15]*enu*enu*enu;
01363   }
01364   else{
01365     weight = par[16]+par[17]*enu+par[18]*enu*enu;
01366   }
01367   return weight;
01368 }
01369 
01370 double SKZPWeightCalculator::GetHeliumWeight_L010z185i_ND_Numubar(double enu)
01371 {
01372   double weight = 1.;
01373   double par[15] = {
01374     1.06239,0.0342807,-0.00879299,0.000479629,-0.346922,0.267095,-0.016762,0.00033883,
01375     0.8,0.01,-0.0005,1e-06,1.03,0.0042195,0.000108851
01376   };
01377   if(enu<11.0){
01378     weight = par[0]+par[1]*enu+par[2]*enu*enu+par[3]*enu*enu*enu;
01379   }
01380   else if(enu<21.4){
01381     weight = par[4]+par[5]*enu+par[6]*enu*enu+par[7]*enu*enu*enu;
01382   }
01383   else if(enu<37.){
01384     weight = par[8]+par[9]*enu+par[10]*(enu-20.)*(enu-20.)+par[11]*(enu-20.)*(enu-20.)*(enu-20.);
01385   }
01386   else{
01387     weight = par[12]-par[13]*(enu-37.)+par[14]*(enu-37.)*(enu-37.);
01388   }
01389   return weight;
01390 }
01391 
01392 double SKZPWeightCalculator::GetHeliumWeight_L010z185i_ND_Nue(double enu)
01393 {
01394   double weight = 1.;
01395   double par[11] = {
01396     0.97709,0.0939192,-0.0536218,0.00805987,1.03,-0.0163451,0.00263497,
01397     -0.000118506,1.57655e-06,0.998,600
01398   };
01399   if(enu<2.43){
01400     weight = par[0]+par[1]*enu+par[2]*enu*enu+par[3]*enu*enu*enu;
01401   }
01402   else if(enu<23.0){
01403     weight = par[4]+par[5]*enu+par[6]*enu*enu+par[7]*enu*enu*enu+par[8]*enu*enu*enu*enu;
01404   }
01405   else{
01406     weight = par[9]+(par[10]/(enu*enu*enu));
01407   }
01408   return weight;
01409 
01410 }
01411 
01412 double SKZPWeightCalculator::GetHeliumWeight_L010z185i_ND_Nuebar(double enu)
01413 {
01414   double weight = 1.;
01415   double par[7] = {
01416     1.02113,0.0140663,-0.000791038,1.37577e-05,-7.48181e-08,0.9995,1150
01417   };
01418   if(enu<30.0){
01419     weight = par[0]+par[1]*enu+par[2]*enu*enu+par[3]*enu*enu*enu+par[4]*enu*enu*enu*enu;
01420   }
01421   else{
01422     weight = par[5]+(par[6]/(enu*enu*enu));
01423   }
01424   return weight;
01425 }
01426 
01427 double SKZPWeightCalculator::GetHeliumWeight_L010z185i_FD_Numu(double enu)
01428 {
01429   double weight = 1.;
01430   double par[14] = {
01431     1.04327,-0.0352661,0.0047907,0.00388763,0.88061,0.0321005,-0.00164144,
01432     -4.5869e-05,1.05352,-0.00869623,0.000390208,-4.45885e-06,0.997,5000
01433   };
01434   if(enu<4.4){
01435     weight = par[0]+par[1]*enu+par[2]*enu*enu+par[3]*TMath::Log(enu);
01436   }
01437   else if(enu<8.9){
01438     weight = par[4]+par[5]*enu+par[6]*enu*enu+par[7]*enu*enu*enu;
01439   }
01440   else if(enu<48.0){
01441     weight = par[8]+par[9]*enu+par[10]*enu*enu+par[11]*enu*enu*enu;
01442   }
01443   else{
01444     weight = par[12]+(par[13]/(enu*enu*enu));
01445   }
01446   return weight;
01447 }
01448 
01449 double SKZPWeightCalculator::GetHeliumWeight_L010z185i_FD_Numubar(double enu)
01450 {
01451   double weight = 1.;
01452   double par[10] = {
01453     1.04689,0.00226136,-0.000790701,2.61669e-05,-0.0744887,
01454     0.0847917,-0.00190558,1.21492e-05,0.99,4000
01455   };
01456   if(enu<21.9){
01457     weight = par[0]+par[1]*enu+par[2]*enu*enu+par[3]*enu*enu*enu;
01458   }
01459   else if(enu<38.0){
01460     weight = par[4]+par[5]*enu+par[6]*enu*enu+par[7]*enu*enu*enu;
01461   }
01462   else{
01463     weight = par[8]+(par[9]/(enu*enu*enu));
01464   }
01465   return weight;
01466 }
01467 
01468 double SKZPWeightCalculator::GetHeliumWeight_L010z185i_FD_Nue(double enu)
01469 {
01470   double weight = 1.;
01471   double par[8] = {
01472     1.00099,0.022962,-0.0106913,0.00153978,-6.74999e-05,1.021,-0.0018,1.5e-05
01473   };
01474   if(enu<11.0){
01475     weight = par[0]+par[1]*enu+par[2]*enu*enu+par[3]*enu*enu*enu+par[4]*enu*enu*enu*enu;
01476   }
01477   else{
01478     weight = par[5]+(par[6]*(enu-11.))+(par[7]*(enu-11.)*(enu-11.));
01479   }
01480   return weight;
01481 }
01482 
01483 double SKZPWeightCalculator::GetHeliumWeight_L010z185i_FD_Nuebar(double enu)
01484 {
01485   double weight = 1.;
01486   double par[7] = {
01487     1.02439,-0.000679498,0.000218119,-6.49776e-06,4.58303e-08,0.997,3300
01488   };
01489   if(enu<43.1){
01490     weight = par[0]+par[1]*enu+par[2]*enu*enu+par[3]*enu*enu*enu+par[4]*enu*enu*enu*enu;
01491   }
01492   else{
01493     weight = par[5]+(par[6]/(enu*enu*enu));
01494   }
01495   return weight;
01496 }
01497 
01498 double SKZPWeightCalculator::GetHeliumWeight_L010z000i_ND_Numu(double enu)
01499 {
01500   double weight = 1.;
01501   double par[10] = {
01502     1.08341,-0.00598166,-0.000644125,0.0153799,1.16251,
01503     -0.0259465,0.00130708,-1.8318e-05,1.03,1500
01504   };
01505   if(enu<7.4){
01506     weight = par[0]+par[1]*enu+par[2]*enu*enu+par[3]*TMath::Log(enu);
01507   }
01508   else if(enu<38.4){
01509     weight = par[4]+par[5]*enu+par[6]*enu*enu+par[7]*enu*enu*enu;
01510   }
01511   else{
01512     weight = par[8]+(par[9]/(enu*enu*enu));
01513   }
01514   return weight;
01515 }
01516 
01517 double SKZPWeightCalculator::GetHeliumWeight_L010z000i_ND_Numubar(double enu)
01518 {
01519   double weight = 1.;
01520   double par[15] = {
01521     1.06489,0.0137669,-0.00415539,0.000218168,0.923382,0.0108634,-0.000376271,
01522     3.86015e-06,0.8,0.01,-0.0005,1e-06,1.03,0.00883329,0.000347229
01523   };
01524   if(enu<11.0){
01525     weight = par[0]+par[1]*enu+par[2]*enu*enu+par[3]*enu*enu*enu;
01526   }
01527   else if(enu<21.4){
01528     weight = par[4]+par[5]*enu+par[6]*enu*enu+par[7]*enu*enu*enu+0.0014;
01529   }
01530   else if(enu<37.){
01531     weight = par[8]+par[9]*enu+par[10]*(enu-20.)*(enu-20.)+par[11]*(enu-20.)*(enu-20.)*(enu-20.)+0.0097;
01532   }
01533   else{
01534     weight = par[12]-par[13]*(enu-37.)+par[14]*(enu-37.)*(enu-37.)+0.0097;
01535   }
01536   return weight;
01537 }
01538 
01539 double SKZPWeightCalculator::GetHeliumWeight_L010z000i_ND_Nue(double enu)
01540 {
01541   double weight = 1.;
01542   double par[7] = {
01543     1.02614,0.0135056,-0.00151707,5.53927e-05,-6.55825e-07,0.978,1.
01544   };
01545   if(enu<20.45){
01546     weight = par[0]+par[1]*enu+par[2]*enu*enu+par[3]*enu*enu*enu+par[4]*enu*enu*enu*enu;
01547   }
01548   else{
01549     weight = par[5]+(par[6]/(enu));
01550   }
01551   return weight;
01552 }
01553 
01554 double SKZPWeightCalculator::GetHeliumWeight_L010z000i_ND_Nuebar(double enu)
01555 {
01556   double weight = 1.;
01557   double par[7] = {
01558     1.02609,0.0255862,-0.00296928,9.18715e-05,-7.22365e-07,1.101,-2500
01559   };
01560   if(enu<28.0){
01561     weight = par[0]+par[1]*enu+par[2]*enu*enu+par[3]*enu*enu*enu+par[4]*enu*enu*enu*enu;
01562   }
01563   else{
01564     weight = par[5]+(par[6]/(enu*enu*enu));
01565   }
01566   return weight;
01567 }
01568 
01569 double SKZPWeightCalculator::GetHeliumWeight_L010z000i_FD_Numu(double enu)
01570 {
01571   double weight = 1.;
01572   double par[10] = {
01573     1.04313,-0.00624758,0.000104616,0.00872899,1.12567,
01574     -0.0171559,0.000639488,-6.72704e-06,1.0197,1500
01575   };
01576   if(enu<10.0){
01577     weight = par[0]+par[1]*enu+par[2]*enu*enu+par[3]*TMath::Log(enu);
01578   }
01579   else if(enu<46.0){
01580     weight = par[4]+par[5]*enu+par[6]*enu*enu+par[7]*enu*enu*enu;
01581   }
01582   else{
01583     weight = par[8]+(par[9]/(enu*enu*enu));
01584   }
01585   return weight;
01586 }
01587 
01588 double SKZPWeightCalculator::GetHeliumWeight_L010z000i_FD_Numubar(double enu)
01589 {
01590   double weight = 1.;
01591   double par[11] = {
01592     1.0378,-0.000996055,-0.000280837,0.00197533,1.25837,-0.0519768,
01593     0.00349608,-9.25331e-05,8.19759e-07,1,-1.5e+07
01594   };
01595   if(enu<9.5){
01596     weight = par[0]+par[1]*enu+par[2]*enu*enu+par[3]*TMath::Log(enu);
01597   }
01598   else if(enu<49.3){
01599     weight = par[4]+par[5]*enu+par[6]*enu*enu+par[7]*enu*enu*enu+par[8]*enu*enu*enu*enu;
01600   }
01601   else{
01602     weight = par[9]+(par[10]/(enu*enu*enu*enu*enu));
01603   }
01604   return weight;
01605 }
01606 
01607 double SKZPWeightCalculator::GetHeliumWeight_L010z000i_FD_Nue(double enu)
01608 {
01609   double weight = 1.;
01610   double par[7] = {
01611     1.02653,-0.00287051,0.000666625,-4.19876e-05,7.69875e-07,0.99805,10
01612   };
01613   if(enu<20.0){
01614     weight = par[0]+par[1]*enu+par[2]*enu*enu+par[3]*enu*enu*enu+par[4]*enu*enu*enu*enu;
01615   }
01616   else{
01617     weight = par[5]+(par[6]/(enu*enu));
01618   }
01619   return weight;
01620 }
01621 
01622 double SKZPWeightCalculator::GetHeliumWeight_L010z000i_FD_Nuebar(double enu)
01623 {
01624   double weight = 1.;
01625   double par[7] = {
01626     1.02206,0.00932646,-0.00100526,2.37525e-05,-4.71822e-08,1.2,-180
01627   };
01628   if(enu<33.45){
01629     weight = par[0]+par[1]*enu+par[2]*enu*enu+par[3]*enu*enu*enu+par[4]*enu*enu*enu*enu;
01630   }
01631   else{
01632     weight = par[5]+(par[6]/(enu*enu));
01633   }
01634   return weight;
01635 }
01636 
01637 
01638 
01639 double SKZPWeightCalculator::GetMissingFin78Weight_L010z185i_ND_Numu(double enu)
01640 {
01641   double y;
01642 
01643   double par[20];
01644 
01645   par[0] =  9.91823e-01;
01646   par[1] =  8.14956e-02;
01647   par[2] = -1.44191e-01;
01648   par[3] =  7.80651e-02;
01649   par[4] = -1.29277e-02;
01650   par[5] = -1.41734e-04;
01651   par[6] =  3.62036e+00;
01652   par[7] = -8.98865e-01;
01653   par[8] =  9.61367e-02;
01654   par[9] = -2.44885e+00;
01655   par[10] =  6.81085e-01;
01656   par[11] =  9.40087e-02;
01657   par[12] = -6.50227e-03;
01658   par[13] = -2.86720e+00;
01659   par[14] = -1.14010e-01;
01660   par[15] =  1.06866e-03;
01661   par[16] =  1.77433e+00;
01662   par[17] =  8.30457e+00;
01663   par[18] =  1.018;
01664   par[19] =  0.005;
01665 
01666   if(enu<2.875){
01667     y = par[0]+par[1]*enu+par[2]*enu*enu+par[3]*enu*enu*enu+par[4]*enu*enu*enu*enu+par[5]*enu*enu*enu*enu*enu;
01668   }
01669   else if(enu<4.375){
01670     y = par[6]+par[7]*enu+par[8]*enu*enu+par[9]*(1./enu);
01671   }
01672   else if(enu<7.460){
01673     y = par[10]+par[11]*enu+par[12]*enu*enu;
01674   }
01675   else if(enu<15.15){
01676     y = par[13]+par[14]*enu+par[15]*enu*enu+par[16]*TMath::Log(enu)+par[17]*(1./enu);
01677   }
01678   else{
01679     y = par[18]+par[19]*(1./(enu-13.8));
01680   }
01681 
01682   return y;
01683 }
01684 
01685 double SKZPWeightCalculator::GetMissingFin78Weight_L010z185i_ND_Numubar(double enu)
01686 {
01687   double y;
01688 
01689   double par[11];
01690 
01691   par[0] = 1.01079;
01692   par[1] = 0.0163014;
01693   par[2] = -0.00951575;
01694   par[3] = 0.00189497;
01695   par[4] = -0.000114420;
01696   par[5] = 0.745891;
01697   par[6] = 0.0198691;
01698   par[7] = -0.000440386;
01699   par[8] = 1.22518;
01700   par[9] = 1.04;
01701   par[10] = -0.2;
01702 
01703   if(enu<8.6){
01704     y = par[0]+par[1]*enu+par[2]*enu*enu+par[3]*enu*enu*enu+par[4]*enu*enu*enu*enu;
01705   }
01706   else if(enu<15.5){
01707     y = par[5]+par[6]*enu+par[7]*enu*enu+par[8]*(1./enu);
01708   }
01709   else {
01710     y = par[9]+par[10]*(1./enu);
01711   }
01712 
01713   return y;
01714 }
01715 
01716 double SKZPWeightCalculator::GetMissingFin78Weight_L010z000i_ND_Numu(double enu)
01717 {
01718   double y;
01719 
01720   double par[7];
01721 
01722   par[0] = 1.01052;
01723   par[1] = 0.00135492;
01724   par[2] = 0.000352042;
01725   par[3] = -0.0000281668;
01726   par[4] = 0.000000465827;
01727   par[5] = 1.018;
01728   par[6] = 0.3;
01729 
01730   if(enu<17.2){
01731     y = par[0]+par[1]*enu+par[2]*enu*enu+par[3]*enu*enu*enu+par[4]*enu*enu*enu*enu;
01732   }
01733   else {
01734     y = par[5]+par[6]*(1./enu);
01735   }
01736 
01737   return y;
01738 }
01739 
01740 double SKZPWeightCalculator::GetMissingFin78Weight_L010z000i_ND_Numubar(double enu)
01741 {
01742   double y;
01743 
01744   double par[7];
01745 
01746   par[0] = 1.00806;
01747   par[1] = 0.00509031;
01748   par[2] = -0.000422559;
01749   par[3] = 0.0000180352;
01750   par[4] = -0.000000272726;
01751   par[5] = 1.018;
01752   par[6] = 0.85;
01753 
01754   if(enu<30.5){
01755     y = par[0]+par[1]*enu+par[2]*enu*enu+par[3]*enu*enu*enu+par[4]*enu*enu*enu*enu;
01756   }
01757   else {
01758     y = par[5]+par[6]*(1./enu);
01759   }
01760 
01761   return y;
01762 }
01763 
01764 double SKZPWeightCalculator::GetMissingFin78Weight_L010z185i_FD_Numu(double enu)
01765 {
01766   double y;
01767 
01768   double par[20];
01769 
01770   par[0] =   9.79176e-01;
01771   par[1] =   5.94877e-02;
01772   par[2] =  -6.33591e-02;
01773   par[3] =   1.24537e-02;
01774   par[4] =   6.85855e-03;
01775   par[5] =  -2.08938e-03;
01776   par[6] =   2.56824e+00;
01777   par[7] =  -5.16706e-01;
01778   par[8] =   5.21584e-02;
01779   par[9] =  -1.52990e+00;
01780   par[10] =   7.10491e-01;
01781   par[11] =   7.95342e-02;
01782   par[12] =  -5.11905e-03;
01783   par[13] =  -4.11699e+00;
01784   par[14] =  -1.27508e-01;
01785   par[15] =   1.08948e-03;
01786   par[16] =   2.22361e+00;
01787   par[17] =   1.17195e+01;
01788   par[18] = 1.018;
01789   par[19] = 0.005;
01790 
01791   if(enu<2.83){
01792     y = par[0]+par[1]*enu+par[2]*enu*enu+par[3]*enu*enu*enu+par[4]*enu*enu*enu*enu+par[5]*enu*enu*enu*enu*enu;
01793   }
01794   else if(enu<4.925){
01795     y = par[6]+par[7]*enu+par[8]*enu*enu+par[9]*(1./enu);
01796   }
01797   else if(enu<9.0){
01798     y = par[10]+par[11]*enu+par[12]*enu*enu;
01799   }
01800   else if(enu<17.6){
01801     y = par[13]+par[14]*enu+par[15]*enu*enu+par[16]*TMath::Log(enu)+par[17]*(1./enu);
01802   }
01803   else{
01804     y = par[18]+par[19]*(1./(enu-13.8));
01805   }
01806 
01807   return y;
01808 }
01809 
01810 double SKZPWeightCalculator::GetMissingFin78Weight_L010z185i_FD_Numubar(double enu)
01811 {
01812   double y;
01813 
01814   double par[11];
01815 
01816   par[0] = 0.992562;
01817   par[1] = 0.0301506;
01818   par[2] = -0.0129656;
01819   par[3] = 0.00215436;
01820   par[4] = -0.000115552;
01821   par[5] = 0.958894;
01822   par[6] = 0.00228454;
01823   par[7] = -0.0000164352;
01824   par[8] = 0.468619;
01825   par[9] = 1.04;
01826   par[10] = -0.2;
01827 
01828   if(enu<8.35){
01829     y = par[0]+par[1]*enu+par[2]*enu*enu+par[3]*enu*enu*enu+par[4]*enu*enu*enu*enu;
01830   }
01831   else if(enu<38.75){
01832     y = par[5]+par[6]*enu+par[7]*enu*enu+par[8]*(1./enu);
01833   }
01834   else {
01835     y = par[9]+par[10]*(1./enu);
01836   }
01837 
01838   return y;
01839 }
01840 
01841 double SKZPWeightCalculator::GetMissingFin78Weight_L010z000i_FD_Numu(double enu)
01842 {
01843   double y;
01844 
01845   double par[7];
01846 
01847   par[0] = 0.991629;
01848   par[1] = 0.0150514;
01849   par[2] = -0.00358913;
01850   par[3] = 0.000384422;
01851   par[4] = -0.0000136394;
01852   par[5] = 1.008;
01853   par[6] = 0.35;
01854 
01855   if(enu<13.38){
01856     y = par[0]+par[1]*enu+par[2]*enu*enu+par[3]*enu*enu*enu+par[4]*enu*enu*enu*enu;
01857   }
01858   else {
01859     y = par[5]+par[6]*(1./enu);
01860   }
01861 
01862   return y;
01863 }
01864 
01865 double SKZPWeightCalculator::GetMissingFin78Weight_L010z000i_FD_Numubar(double enu)
01866 {
01867   double y;
01868 
01869   double par[7];
01870 
01871   par[0] = 0.991063;
01872   par[1] = 0.0114890;
01873   par[2] = -0.00123288;
01874   par[3] = 0.0000558658;
01875   par[4] = -0.000000834802;
01876   par[5] = 1.056;
01877   par[6] = -0.35;
01878 
01879   if(enu<17.925){
01880     y = par[0]+par[1]*enu+par[2]*enu*enu+par[3]*enu*enu*enu+par[4]*enu*enu*enu*enu;
01881   }
01882   else {
01883     y = par[5]+par[6]*(1./enu);
01884   }
01885 
01886   return y;
01887 }
01888 
01889 
01890 
01891 double SKZPWeightCalculator::GetMissingFin78Weight_L010z185i_ND_Nue(double enu)
01892 {
01893   double y;
01894 
01895   double par[12];
01896 
01897   par[0] = 0.964536;
01898   par[1] = 0.0341348;
01899   par[2] = -0.0167779;
01900   par[3] = 0.00275733;
01901   par[4] = -0.000173092;
01902   par[5] = 0.00000364374;
01903   par[6] = 65.6200;
01904   par[7] = 1.55324;
01905   par[8] = -0.0132149;
01906   par[9] = -27.7156;
01907   par[10] = -147.925;
01908   par[11] = 1.11675;
01909 
01910   if(enu<15.70){
01911     y = par[0]+par[1]*enu+par[2]*enu*enu+par[3]*enu*enu*enu+par[4]*enu*enu*enu*enu+par[5]*enu*enu*enu*enu*enu;
01912   }
01913   else if(enu<29.8){
01914     y = -0.012+par[6]+par[7]*enu+par[8]*enu*enu+par[9]*TMath::Log(enu)+par[10]*(1./enu);
01915   }
01916   else{
01917     y = par[11];
01918   }
01919 
01920   return y;
01921 }
01922 
01923 double SKZPWeightCalculator::GetMissingFin78Weight_L010z185i_ND_Nuebar(double enu)
01924 {
01925   double y;
01926 
01927   double par[8];
01928 
01929   par[0] = 1.01535;
01930   par[1] = -0.0167946;
01931   par[2] = 0.00921187;
01932   par[3] = -0.00133391;
01933   par[4] = 0.0000684085;
01934   par[5] = -0.00000113447;
01935   par[6] = 0.9;
01936   par[7] = 1.0;
01937 
01938   if(enu<26.95){
01939     y = par[0]+par[1]*enu+par[2]*enu*enu+par[3]*enu*enu*enu+par[4]*enu*enu*enu*enu+par[5]*enu*enu*enu*enu*enu;
01940   }
01941   else {
01942     y = par[6]+par[7]*(1./(enu-22.));
01943   }
01944 
01945   return y;
01946 }
01947 
01948 double SKZPWeightCalculator::GetMissingFin78Weight_L010z000i_ND_Nue(double enu)
01949 {
01950   double y;
01951 
01952   double par[8];
01953 
01954   par[0] = 1.09927;
01955   par[1] = -0.0580560;
01956   par[2] = 0.00847919;
01957   par[3] = -0.000341542;
01958   par[4] = -0.00000545052;
01959   par[5] = 0.000000394652;
01960   par[6] = 1.15;
01961   par[7] = -1.0;
01962 
01963   if(enu<20.8){
01964     y = par[0]+par[1]*enu+par[2]*enu*enu+par[3]*enu*enu*enu+par[4]*enu*enu*enu*enu+par[5]*enu*enu*enu*enu*enu;
01965   }
01966   else {
01967     y = par[6]+par[7]*(1./(enu-14.));
01968   }
01969 
01970   return y;
01971 }
01972 
01973 double SKZPWeightCalculator::GetMissingFin78Weight_L010z000i_ND_Nuebar(double enu)
01974 {
01975   double y;
01976 
01977   double par[8];
01978 
01979   par[0] = 0.960938;
01980   par[1] = 0.169592;
01981   par[2] = -0.0611788;
01982   par[3] = 0.00782170;
01983   par[4] = -0.000416337;
01984   par[5] = 0.00000785160;
01985   par[6] = 1.12;
01986   par[7] = -1.0;
01987 
01988   if(enu<19.775){
01989     y = par[0]+par[1]*enu+par[2]*enu*enu+par[3]*enu*enu*enu+par[4]*enu*enu*enu*enu+par[5]*enu*enu*enu*enu*enu;
01990   }
01991   else {
01992     y = par[6]+par[7]*(1./(enu-13.8));
01993   }
01994 
01995   return y;
01996 }
01997 
01998 double SKZPWeightCalculator::GetMissingFin78Weight_L010z185i_FD_Nue(double enu)
01999 {
02000   double y;
02001 
02002   double par[8];
02003 
02004   par[0] = 0.976334;
02005   par[1] = 0.0146822;
02006   par[2] = -0.00805149;
02007   par[3] = 0.00132456;
02008   par[4] = -0.0000810696;
02009   par[5] = 0.00000166323;
02010   par[6] = 1.0851;
02011   par[7] = -1.0;
02012 
02013   if(enu<19.45){
02014     y = par[0]+par[1]*enu+par[2]*enu*enu+par[3]*enu*enu*enu+par[4]*enu*enu*enu*enu+par[5]*enu*enu*enu*enu*enu;
02015   }
02016   else{
02017     y = par[6]+par[7]*(1./(enu-9.));
02018   }
02019 
02020   return y;
02021 }
02022 
02023 double SKZPWeightCalculator::GetMissingFin78Weight_L010z185i_FD_Nuebar(double enu)
02024 {
02025   double y;
02026 
02027   double par[9];
02028 
02029   par[0] = 0.912223;
02030   par[1] = 0.106252;
02031   par[2] = -0.0341165;
02032   par[3] = 0.00490576;
02033   par[4] = -0.000344942;
02034   par[5] = 0.0000114327;
02035   par[6] = -0.000000142208;
02036   par[7] = 0.9;
02037   par[8] = 1.0;
02038 
02039   if(enu<27.55){
02040     y = par[0]+par[1]*enu+par[2]*enu*enu+par[3]*enu*enu*enu+par[4]*enu*enu*enu*enu+par[5]*enu*enu*enu*enu*enu+par[6]*enu*enu*enu*enu*enu*enu;
02041   }
02042   else {
02043     y = par[7]+par[8]*(1./(enu-22.));
02044   }
02045 
02046   return y;
02047 }
02048 
02049 double SKZPWeightCalculator::GetMissingFin78Weight_L010z000i_FD_Nue(double enu)
02050 {
02051   double y;
02052 
02053   double par[8];
02054 
02055   par[0] = 1.05046;
02056   par[1] = -0.0197051;
02057   par[2] = -0.000709986;
02058   par[3] = 0.000580179;
02059   par[4] = -0.0000443486;
02060   par[5] = 0.000000962613;
02061   par[6] = 0.92;
02062   par[7] = 0.6;
02063 
02064   if(enu<19.5){
02065     y = par[0]+par[1]*enu+par[2]*enu*enu+par[3]*enu*enu*enu+par[4]*enu*enu*enu*enu+par[5]*enu*enu*enu*enu*enu;
02066   }
02067   else {
02068     y = par[6]+par[7]*(1./(enu-12.));
02069   }
02070 
02071   return y;
02072 }
02073 
02074 double SKZPWeightCalculator::GetMissingFin78Weight_L010z000i_FD_Nuebar(double enu)
02075 {
02076   double y;
02077 
02078   double par[8];
02079 
02080   par[0] = 1.03867;
02081   par[1] = 0.0130506;
02082   par[2] = -0.00751797;
02083   par[3] = 0.00109883;
02084   par[4] = -0.0000639034;
02085   par[5] = 0.00000130481;
02086   par[6] = 1.04;
02087   par[7] = -0.2;
02088 
02089   if(enu<18.9){
02090     y = par[0]+par[1]*enu+par[2]*enu*enu+par[3]*enu*enu*enu+par[4]*enu*enu*enu*enu+par[5]*enu*enu*enu*enu*enu;
02091   }
02092   else {
02093     y = par[6]+par[7]*(1./(enu-12.));
02094   }
02095 
02096   return y;
02097 }
02098 

Generated on Mon Feb 15 11:07:38 2010 for loon by  doxygen 1.3.9.1